7 #ifndef NDN_SECURITY_VALIDATOR_CONFIG_HPP
8 #define NDN_SECURITY_VALIDATOR_CONFIG_HPP
35 const int stepLimit = 10);
42 const int stepLimit = 10);
50 load(
const std::string& filename);
53 load(
const std::string& input,
const std::string& filename);
56 load(std::istream& input,
const std::string& filename);
60 const std::string& filename);
68 std::vector<shared_ptr<ValidationRequest> >& nextSteps);
75 std::vector<shared_ptr<ValidationRequest> >& nextSteps);
78 template<
class Packet,
class OnVal
idated,
class OnFailed>
80 checkSignature(
const Packet& packet,
83 const OnValidated& onValidated,
84 const OnFailed& onValidationFailed,
85 std::vector<shared_ptr<ValidationRequest> >& nextSteps);
87 template<
class Packet,
class OnVal
idated,
class OnFailed>
89 onCertValidated(
const shared_ptr<const Data>& signCertificate,
90 const shared_ptr<const Packet>& packet,
91 const OnValidated& onValidated,
92 const OnFailed& onValidationFailed);
94 template<
class Packet,
class OnFailed>
96 onCertFailed(
const shared_ptr<const Data>& signCertificate,
97 const std::string& failureInfo,
98 const shared_ptr<const Packet>& packet,
99 const OnFailed& onValidationFailed);
103 const std::string& filename);
107 const std::string& filename);
112 typedef std::vector<shared_ptr<InterestRule> > InterestRuleList;
113 typedef std::vector<shared_ptr<DataRule> > DataRuleList;
114 typedef std::map<Name, shared_ptr<IdentityCertificate> > AnchorList;
117 shared_ptr<CertificateCache> m_certificateCache;
119 InterestRuleList m_interestRules;
120 DataRuleList m_dataRules;
121 AnchorList m_anchors;
124 template<
class Packet,
class OnVal
idated,
class OnFailed>
126 ValidatorConfig::checkSignature(
const Packet& packet,
127 const Signature& signature,
129 const OnValidated& onValidated,
130 const OnFailed& onValidationFailed,
131 std::vector<shared_ptr<ValidationRequest> >& nextSteps)
135 SignatureSha256 sigSha256(signature);
138 return onValidated(packet.shared_from_this());
140 return onValidationFailed(packet.shared_from_this(),
141 "Sha256 Signature cannot be verified!");
147 Name keyLocatorName = sigSha256Rsa.getKeyLocator().getName();
149 shared_ptr<const Certificate> trustedCert;
151 AnchorList::const_iterator it = m_anchors.find(keyLocatorName);
152 if (m_anchors.end() == it)
153 trustedCert = m_certificateCache->getCertificate(keyLocatorName);
155 trustedCert = it->second;
157 if (static_cast<bool>(trustedCert))
159 if (
verifySignature(packet, sigSha256Rsa, trustedCert->getPublicKeyInfo()))
160 return onValidated(packet.shared_from_this());
162 return onValidationFailed(packet.shared_from_this(),
163 "Cannot verify signature");
168 bind(&ValidatorConfig::onCertValidated<Packet, OnValidated, OnFailed>,
169 this, _1, packet.shared_from_this(), onValidated, onValidationFailed);
172 bind(&ValidatorConfig::onCertFailed<Packet, OnFailed>,
173 this, _1, _2, packet.shared_from_this(), onValidationFailed);
175 Interest certInterest(keyLocatorName);
177 shared_ptr<ValidationRequest> nextStep =
178 make_shared<ValidationRequest>(boost::cref(certInterest),
180 onCertValidationFailed,
183 nextSteps.push_back(nextStep);
187 return onValidationFailed(packet.shared_from_this(),
"Unsupported Signature Type!");
190 template<
class Packet,
class OnVal
idated,
class OnFailed>
192 ValidatorConfig::onCertValidated(
const shared_ptr<const Data>& signCertificate,
193 const shared_ptr<const Packet>& packet,
194 const OnValidated& onValidated,
195 const OnFailed& onValidationFailed)
197 shared_ptr<IdentityCertificate> certificate =
198 make_shared<IdentityCertificate>(boost::cref(*signCertificate));
200 if (!certificate->isTooLate() && !certificate->isTooEarly())
202 m_certificateCache->insertCertificate(certificate);
205 return onValidated(packet);
207 return onValidationFailed(packet,
208 "Cannot verify signature: " +
209 packet->getName().toUri());
213 return onValidationFailed(packet,
214 "Signing certificate " +
215 signCertificate->getName().toUri() +
216 " is no longer valid.");
220 template<
class Packet,
class OnFailed>
222 ValidatorConfig::onCertFailed(
const shared_ptr<const Data>& signCertificate,
223 const std::string& failureInfo,
224 const shared_ptr<const Packet>& packet,
225 const OnFailed& onValidationFailed)
227 onValidationFailed(packet, failureInfo);
232 #endif // NDN_SECURITY_VALIDATOR_CONFIG_HPP
void load(const std::string &filename)
ValidatorConfig(Face &face, const shared_ptr< CertificateCache > &certificateCache=DEFAULT_CERTIFICATE_CACHE, const int stepLimit=10)
An Interest holds a Name and other fields for an interest.
virtual void checkPolicy(const Data &data, int nSteps, const OnDataValidated &onValidated, const OnDataValidationFailed &onValidationFailed, std::vector< shared_ptr< ValidationRequest > > &nextSteps)
Check the Data against policy and return the next validation step if necessary.
virtual ~ValidatorConfig()
Error(const std::string &what)
function< void(const shared_ptr< const Data > &)> OnDataValidated
Callback to report a successful Data validation.
function< void(const shared_ptr< const Data > &, const std::string &)> OnDataValidationFailed
Callback to report a failed Data validation.
Abstraction to communicate with local or remote NDN forwarder.
static const shared_ptr< CertificateCache > DEFAULT_CERTIFICATE_CACHE
function< void(const shared_ptr< const Interest > &, const std::string &)> OnInterestValidationFailed
Callback to report a failed Interest validation.
boost::property_tree::ptree ConfigSection
static bool verifySignature(const Data &data, const PublicKey &publicKey)
Verify the data using the publicKey.
Validator is one of the main classes of the security library.
function< void(const shared_ptr< const Interest > &)> OnInterestValidated
Callback to report a successful Interest validation.
A Signature is storage for the signature-related information (info and value) in a Data packet...