Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * @author: Yingdi Yu <yingdi@cs.ucla.edu> |
| 5 | * See COPYING for copyright and distribution information. |
| 6 | */ |
| 7 | |
| 8 | #ifndef NDN_VALIDATOR_REGEX_HPP |
| 9 | #define NDN_VALIDATOR_REGEX_HPP |
| 10 | |
| 11 | #include "validator.hpp" |
| 12 | #include "identity-certificate.hpp" |
| 13 | #include "sec-rule-relative.hpp" |
| 14 | #include "certificate-cache.hpp" |
| 15 | #include "../util/regex.hpp" |
| 16 | |
| 17 | #include <map> |
| 18 | |
| 19 | |
| 20 | namespace ndn { |
| 21 | |
| 22 | class ValidatorRegex : public Validator |
| 23 | { |
| 24 | public: |
| 25 | struct Error : public Validator::Error { Error(const std::string &what) : Validator::Error(what) {} }; |
| 26 | |
| 27 | static const shared_ptr<CertificateCache> DefaultCertificateCache; |
| 28 | |
| 29 | ValidatorRegex(shared_ptr<Face> face, |
| 30 | shared_ptr<CertificateCache> certificateCache = DefaultCertificateCache, |
| 31 | const int stepLimit = 3); |
| 32 | |
| 33 | virtual |
| 34 | ~ValidatorRegex() {} |
| 35 | |
| 36 | /** |
| 37 | * @brief Add a rule for data verification. |
| 38 | * |
| 39 | * @param policy The verification rule |
| 40 | */ |
| 41 | inline void |
| 42 | addDataVerificationRule (shared_ptr<SecRuleRelative> rule); |
| 43 | |
| 44 | /** |
| 45 | * @brief Add a trust anchor |
| 46 | * |
| 47 | * @param certificate The trust anchor |
| 48 | */ |
| 49 | inline void |
| 50 | addTrustAnchor(shared_ptr<IdentityCertificate> certificate); |
| 51 | |
| 52 | protected: |
| 53 | virtual void |
Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame^] | 54 | checkPolicy (const shared_ptr<const Data>& data, |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 55 | int stepCount, |
| 56 | const OnDataValidated &onValidated, |
| 57 | const OnDataValidationFailed &onValidationFailed, |
| 58 | std::vector<shared_ptr<ValidationRequest> > &nextSteps); |
| 59 | |
Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame^] | 60 | virtual void |
| 61 | checkPolicy (const shared_ptr<const Interest>& interest, |
| 62 | int stepCount, |
| 63 | const OnInterestValidated &onValidated, |
| 64 | const OnInterestValidationFailed &onValidationFailed, |
| 65 | std::vector<shared_ptr<ValidationRequest> > &nextSteps) |
| 66 | { onValidationFailed(interest); } |
| 67 | |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 68 | void |
| 69 | onCertificateValidated(const shared_ptr<const Data> &signCertificate, |
| 70 | const shared_ptr<const Data> &data, |
| 71 | const OnDataValidated &onValidated, |
| 72 | const OnDataValidationFailed &onValidationFailed); |
| 73 | |
| 74 | void |
| 75 | onCertificateValidationFailed(const shared_ptr<const Data> &signCertificate, |
| 76 | const shared_ptr<const Data> &data, |
| 77 | const OnDataValidationFailed &onValidationFailed); |
| 78 | |
| 79 | protected: |
| 80 | typedef std::vector< shared_ptr<SecRuleRelative> > RuleList; |
| 81 | typedef std::vector< shared_ptr<Regex> > RegexList; |
| 82 | |
| 83 | int m_stepLimit; |
| 84 | shared_ptr<CertificateCache> m_certificateCache; |
| 85 | RuleList m_mustFailVerify; |
| 86 | RuleList m_verifyPolicies; |
| 87 | std::map<Name, shared_ptr<IdentityCertificate> > m_trustAnchors; |
| 88 | }; |
| 89 | |
| 90 | void |
| 91 | ValidatorRegex::addDataVerificationRule (shared_ptr<SecRuleRelative> rule) |
| 92 | { rule->isPositive() ? m_verifyPolicies.push_back(rule) : m_mustFailVerify.push_back(rule); } |
| 93 | |
| 94 | void |
| 95 | ValidatorRegex::addTrustAnchor(shared_ptr<IdentityCertificate> certificate) |
| 96 | { m_trustAnchors[certificate->getName().getPrefix(-1)] = certificate; } |
| 97 | |
| 98 | }//ndn |
| 99 | |
| 100 | #endif |