blob: d6b9b1d624af1ed0e9942402bbf31ef0d75b535a [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
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 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)
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080063 { onValidationFailed(interest.shared_from_this()); }
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
72 onCertificateValidationFailed(const shared_ptr<const Data> &signCertificate,
73 const shared_ptr<const Data> &data,
74 const OnDataValidationFailed &onValidationFailed);
75
76protected:
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
87void
88ValidatorRegex::addDataVerificationRule (shared_ptr<SecRuleRelative> rule)
89{ rule->isPositive() ? m_verifyPolicies.push_back(rule) : m_mustFailVerify.push_back(rule); }
90
91void
92ValidatorRegex::addTrustAnchor(shared_ptr<IdentityCertificate> certificate)
93{ m_trustAnchors[certificate->getName().getPrefix(-1)] = certificate; }
94
95}//ndn
96
97#endif