blob: ede1799bbe5700cd1556bd17703474d5a3410e40 [file] [log] [blame]
Yingdi Yufa4ce792014-02-06 18:09:22 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 * Yingdi Yu
5 *
6 * BSD license, See the LICENSE file for more information
7 *
8 * Author: Yingdi Yu <yingdi@cs.ucla.edu>
9 */
10
11#ifndef CHRONOS_VALIDATOR_INVITATION_H
12#define CHRONOS_VALIDATOR_INVITATION_H
13
14#include <ndn-cpp-dev/security/validator.hpp>
15#include <ndn-cpp-dev/security/certificate-cache.hpp>
16#include <ndn-cpp-dev/security/sec-rule-relative.hpp>
17#include <map>
18
19#include "endorse-certificate.h"
20
21namespace chronos{
22
23class ValidatorInvitation : public ndn::Validator
24{
25 typedef ndn::function< void () > OnValidationFailed;
26 typedef ndn::function< void () > OnValidated;
27
28public:
29 struct Error : public Validator::Error { Error(const std::string &what) : Validator::Error(what) {} };
30
31 static const ndn::shared_ptr<ndn::CertificateCache> DefaultCertificateCache;
32
33 ValidatorInvitation(ndn::shared_ptr<ndn::Face> face,
34 const std::string& chatroomName,
35 const ndn::Name& signingIdentity,
36 ndn::shared_ptr<ndn::CertificateCache> certificateCache = DefaultCertificateCache,
37 int stepLimit = 10);
38
39 virtual
40 ~ValidatorInvitation() {};
41
42 void
43 addTrustAnchor(const EndorseCertificate& cert)
44 { m_trustAnchors[cert.getPublicKeyName()] = cert.getPublicKeyInfo(); }
45
46 void
47 removeTrustAnchor(const ndn::Name& keyName)
48 { m_trustAnchors.erase(keyName); }
49
50 ndn::shared_ptr<ndn::IdentityCertificate>
51 getValidatedDskCertificate(const ndn::Name& certName)
52 {
53 ValidatedCertifcates::iterator it = m_dskCertificates.find(certName);
54 if(m_dskCertificates.end() != it)
55 return it->second;
56 else
57 return ndn::shared_ptr<ndn::IdentityCertificate>();
58 }
59
60
61protected:
62 void
63 checkPolicy (const ndn::shared_ptr<const ndn::Data>& data,
64 int stepCount,
65 const ndn::OnDataValidated& onValidated,
66 const ndn::OnDataValidationFailed& onValidationFailed,
67 std::vector<ndn::shared_ptr<ndn::ValidationRequest> >& nextSteps);
68
69 void
70 checkPolicy (const ndn::shared_ptr<const ndn::Interest>& interest,
71 int stepCount,
72 const ndn::OnInterestValidated& onValidated,
73 const ndn::OnInterestValidationFailed& onValidationFailed,
74 std::vector<ndn::shared_ptr<ndn::ValidationRequest> >& nextSteps);
75
76private:
77 void
78 onDskKeyLocatorValidated(const ndn::shared_ptr<const ndn::Data>& certData,
79 const uint8_t* buf,
80 const size_t size,
81 const ndn::SignatureSha256WithRsa& signature,
82 const OnValidated& onValidated,
83 const OnValidationFailed& onValidationFailed);
84
85 void
86 onDskKeyLocatorValidationFailed(const ndn::shared_ptr<const ndn::Data>& certData,
87 const OnValidationFailed& onValidationFailed);
88
89 void
90 processSignature (const uint8_t* buf,
91 const size_t size,
92 const ndn::SignatureSha256WithRsa& signature,
93 const ndn::Name& keyLocatorName,
94 const OnValidated& onValidated,
95 const OnValidationFailed& onValidationFailed,
96 int stepCount,
97 std::vector<ndn::shared_ptr<ndn::ValidationRequest> >& nextSteps);
98
99 void
100 processFinalSignature (const uint8_t* buf,
101 const size_t size,
102 const ndn::SignatureSha256WithRsa& signature,
103 const ndn::Name& keyLocatorName,
104 const OnValidated& onValidated,
105 const OnValidationFailed& onValidationFailed);
106
107private:
108
109 typedef std::map<ndn::Name, ndn::PublicKey> TrustAnchors;
110 typedef std::map<ndn::Name, ndn::shared_ptr<ndn::IdentityCertificate> > ValidatedCertifcates;
111
112 int m_stepLimit;
113 ndn::shared_ptr<ndn::CertificateCache> m_certificateCache;
114
115 std::string m_chatroomName;
116 ndn::Name m_signingIdentity;
117
118 ndn::shared_ptr<ndn::SecRuleRelative> m_invitationRule;
119 ndn::shared_ptr<ndn::SecRuleRelative> m_dskRule;
120
121 ndn::shared_ptr<ndn::Regex> m_kskRegex;
122 ndn::shared_ptr<ndn::Regex> m_keyNameRegex;
123
124 TrustAnchors m_trustAnchors;
125
126 ValidatedCertifcates m_dskCertificates;
127
128};
129
130}//chronos
131
132#endif //CHRONOS_VALIDATOR_INVITATION_H