blob: a4d91906abb4ff8233af2d37879eaf32cee1fd86 [file] [log] [blame]
Yingdi Yu3715f8d2014-01-30 00:32:20 -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_SEC_POLICY_REGEX_HPP
9#define NDN_SEC_POLICY_REGEX_HPP
10
11#include "sec-policy.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
21
22namespace ndn {
23
24class SecPolicyRegex : public SecPolicy
25{
26public:
27 struct Error : public SecPolicy::Error { Error(const std::string &what) : SecPolicy::Error(what) {} };
28
29 SecPolicyRegex(shared_ptr<CertificateCache> certificateCache, const int stepLimit = 10);
30
31 virtual
32 ~SecPolicyRegex() {}
33
34 virtual shared_ptr<ValidationRequest>
35 checkVerificationPolicy(const shared_ptr<Data>& data,
36 int stepCount,
37 const OnVerified& onVerified,
38 const OnVerifyFailed& onVerifyFailed);
39
40 /**
41 * @brief add a rule to check whether the data name and signing certificate name comply with the policy
42 * @param policy the verification policy
43 */
44 inline virtual void
45 addVerificationPolicyRule (shared_ptr<SecRuleRelative> rule);
46
47 /**
48 * @brief add a trust anchor
49 * @param certificate the trust anchor
50 */
51 inline virtual void
52 addTrustAnchor(shared_ptr<IdentityCertificate> certificate);
53
54protected:
55 virtual void
56 onCertificateVerified(shared_ptr<Data> certificate,
57 shared_ptr<Data> data,
58 const OnVerified& onVerified,
59 const OnVerifyFailed& onVerifyFailed);
60
61 virtual void
62 onCertificateVerifyFailed(shared_ptr<Data>signCertificate,
63 shared_ptr<Data>data,
64 const OnVerifyFailed& onVerifyFailed);
65
66protected:
67 typedef std::vector< shared_ptr<SecRuleRelative> > RuleList;
68 typedef std::vector< shared_ptr<Regex> > RegexList;
69
70 int m_stepLimit;
71 shared_ptr<CertificateCache> m_certificateCache;
72 RuleList m_mustFailVerify;
73 RuleList m_verifyPolicies;
74 std::map<Name, shared_ptr<IdentityCertificate> > m_trustAnchors;
75};
76
77void
78SecPolicyRegex::addVerificationPolicyRule (shared_ptr<SecRuleRelative> rule)
79{ rule->isPositive() ? m_verifyPolicies.push_back(rule) : m_mustFailVerify.push_back(rule); }
80
81void
82SecPolicyRegex::addTrustAnchor(shared_ptr<IdentityCertificate> certificate)
83{ m_trustAnchors[certificate->getName().getPrefix(-1)] = certificate; }
84
85}//ndn
86
87#endif