blob: 9caa380af9b7fcfa857f317fcc97e6390f597025 [file] [log] [blame]
Yingdi Yu6ac97982014-01-30 14:49:21 -08001/* -*- 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 Yufc40d872014-02-18 12:56:04 -08008#ifndef NDN_SECURITY_VALIDATOR_REGEX_HPP
9#define NDN_SECURITY_VALIDATOR_REGEX_HPP
Yingdi Yu6ac97982014-01-30 14:49:21 -080010
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 Yu6ac97982014-01-30 14:49:21 -080017namespace ndn {
18
19class ValidatorRegex : public Validator
20{
21public:
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
49protected:
50 virtual void
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080051 checkPolicy (const Data& data,
Yingdi Yu6ac97982014-01-30 14:49:21 -080052 int stepCount,
53 const OnDataValidated &onValidated,
54 const OnDataValidationFailed &onValidationFailed,
55 std::vector<shared_ptr<ValidationRequest> > &nextSteps);
56
Yingdi Yu9a335352014-01-31 11:57:46 -080057 virtual void
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080058 checkPolicy (const Interest& interest,
Yingdi Yu9a335352014-01-31 11:57:46 -080059 int stepCount,
60 const OnInterestValidated &onValidated,
61 const OnInterestValidationFailed &onValidationFailed,
62 std::vector<shared_ptr<ValidationRequest> > &nextSteps)
Yingdi Yu40587c02014-02-21 16:40:48 -080063 { onValidationFailed(interest.shared_from_this(), "No policy for signed interest checking"); }
Yingdi Yu9a335352014-01-31 11:57:46 -080064
Yingdi Yu6ac97982014-01-30 14:49:21 -080065 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
Yingdi Yu40587c02014-02-21 16:40:48 -080072 onCertificateValidationFailed(const shared_ptr<const Data> &signCertificate,
73 const std::string& failureInfo,
Yingdi Yu6ac97982014-01-30 14:49:21 -080074 const shared_ptr<const Data> &data,
75 const OnDataValidationFailed &onValidationFailed);
76
77protected:
78 typedef std::vector< shared_ptr<SecRuleRelative> > RuleList;
79 typedef std::vector< shared_ptr<Regex> > RegexList;
80
81 int m_stepLimit;
82 shared_ptr<CertificateCache> m_certificateCache;
83 RuleList m_mustFailVerify;
84 RuleList m_verifyPolicies;
85 std::map<Name, shared_ptr<IdentityCertificate> > m_trustAnchors;
86};
87
Yingdi Yuf8fc8de2014-02-25 15:45:39 -080088inline void
Yingdi Yu6ac97982014-01-30 14:49:21 -080089ValidatorRegex::addDataVerificationRule (shared_ptr<SecRuleRelative> rule)
90{ rule->isPositive() ? m_verifyPolicies.push_back(rule) : m_mustFailVerify.push_back(rule); }
91
Yingdi Yuf8fc8de2014-02-25 15:45:39 -080092inline void
Yingdi Yu6ac97982014-01-30 14:49:21 -080093ValidatorRegex::addTrustAnchor(shared_ptr<IdentityCertificate> certificate)
94{ m_trustAnchors[certificate->getName().getPrefix(-1)] = certificate; }
95
Yingdi Yufc40d872014-02-18 12:56:04 -080096} // namespace ndn
Yingdi Yu6ac97982014-01-30 14:49:21 -080097
Yingdi Yufc40d872014-02-18 12:56:04 -080098#endif //NDN_SECURITY_VALIDATOR_REGEX_HPP