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