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 | |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 17 | namespace ndn { |
| 18 | |
| 19 | class ValidatorRegex : public Validator |
| 20 | { |
| 21 | public: |
| 22 | struct Error : public Validator::Error { Error(const std::string &what) : Validator::Error(what) {} }; |
| 23 | |
| 24 | static const shared_ptr<CertificateCache> DefaultCertificateCache; |
| 25 | |
| 26 | ValidatorRegex(shared_ptr<Face> face, |
| 27 | shared_ptr<CertificateCache> certificateCache = DefaultCertificateCache, |
| 28 | const int stepLimit = 3); |
| 29 | |
| 30 | virtual |
| 31 | ~ValidatorRegex() {} |
| 32 | |
| 33 | /** |
| 34 | * @brief Add a rule for data verification. |
| 35 | * |
| 36 | * @param policy The verification rule |
| 37 | */ |
| 38 | inline void |
| 39 | addDataVerificationRule (shared_ptr<SecRuleRelative> rule); |
| 40 | |
| 41 | /** |
| 42 | * @brief Add a trust anchor |
| 43 | * |
| 44 | * @param certificate The trust anchor |
| 45 | */ |
| 46 | inline void |
| 47 | addTrustAnchor(shared_ptr<IdentityCertificate> certificate); |
| 48 | |
| 49 | protected: |
| 50 | virtual void |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 51 | checkPolicy (const Data& data, |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 52 | int stepCount, |
| 53 | const OnDataValidated &onValidated, |
| 54 | const OnDataValidationFailed &onValidationFailed, |
| 55 | std::vector<shared_ptr<ValidationRequest> > &nextSteps); |
| 56 | |
Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame] | 57 | virtual void |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 58 | checkPolicy (const Interest& interest, |
Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame] | 59 | int stepCount, |
| 60 | const OnInterestValidated &onValidated, |
| 61 | const OnInterestValidationFailed &onValidationFailed, |
| 62 | std::vector<shared_ptr<ValidationRequest> > &nextSteps) |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 63 | { onValidationFailed(interest.shared_from_this()); } |
Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame] | 64 | |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 65 | void |
| 66 | onCertificateValidated(const shared_ptr<const Data> &signCertificate, |
| 67 | const shared_ptr<const Data> &data, |
| 68 | const OnDataValidated &onValidated, |
| 69 | const OnDataValidationFailed &onValidationFailed); |
| 70 | |
| 71 | void |
| 72 | onCertificateValidationFailed(const shared_ptr<const Data> &signCertificate, |
| 73 | const shared_ptr<const Data> &data, |
| 74 | const OnDataValidationFailed &onValidationFailed); |
| 75 | |
| 76 | protected: |
| 77 | typedef std::vector< shared_ptr<SecRuleRelative> > RuleList; |
| 78 | typedef std::vector< shared_ptr<Regex> > RegexList; |
| 79 | |
| 80 | int m_stepLimit; |
| 81 | shared_ptr<CertificateCache> m_certificateCache; |
| 82 | RuleList m_mustFailVerify; |
| 83 | RuleList m_verifyPolicies; |
| 84 | std::map<Name, shared_ptr<IdentityCertificate> > m_trustAnchors; |
| 85 | }; |
| 86 | |
| 87 | void |
| 88 | ValidatorRegex::addDataVerificationRule (shared_ptr<SecRuleRelative> rule) |
| 89 | { rule->isPositive() ? m_verifyPolicies.push_back(rule) : m_mustFailVerify.push_back(rule); } |
| 90 | |
| 91 | void |
| 92 | ValidatorRegex::addTrustAnchor(shared_ptr<IdentityCertificate> certificate) |
| 93 | { m_trustAnchors[certificate->getName().getPrefix(-1)] = certificate; } |
| 94 | |
| 95 | }//ndn |
| 96 | |
| 97 | #endif |