Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [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 | * Yingdi Yu |
| 5 | * |
| 6 | * BSD license, See the LICENSE file for more information |
| 7 | * |
| 8 | * Author: Yingdi Yu <yingdi@cs.ucla.edu> |
| 9 | */ |
| 10 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame^] | 11 | #ifndef CHRONOCHAT_VALIDATOR_INVITATION_HPP |
| 12 | #define CHRONOCHAT_VALIDATOR_INVITATION_HPP |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 13 | |
| 14 | #include "common.hpp" |
| 15 | |
| 16 | #include <ndn-cxx/security/validator.hpp> |
| 17 | #include <ndn-cxx/security/certificate-cache.hpp> |
| 18 | #include <ndn-cxx/security/sec-rule-relative.hpp> |
| 19 | |
| 20 | #include "endorse-certificate.hpp" |
| 21 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame^] | 22 | namespace chronochat { |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 23 | |
| 24 | class ValidatorInvitation : public ndn::Validator |
| 25 | { |
| 26 | typedef function<void(const std::string&)> OnValidationFailed; |
| 27 | typedef function<void()> OnValidated; |
| 28 | |
| 29 | public: |
| 30 | class Error : public ndn::Validator::Error |
| 31 | { |
| 32 | public: |
| 33 | Error(const std::string& what) |
| 34 | : ndn::Validator::Error(what) |
| 35 | { |
| 36 | } |
| 37 | }; |
| 38 | |
| 39 | static const shared_ptr<ndn::CertificateCache> DefaultCertificateCache; |
| 40 | |
| 41 | ValidatorInvitation(); |
| 42 | |
| 43 | virtual |
| 44 | ~ValidatorInvitation() |
| 45 | { |
| 46 | } |
| 47 | |
| 48 | void |
| 49 | addTrustAnchor(const Name& keyName, const ndn::PublicKey& key); |
| 50 | |
| 51 | void |
| 52 | removeTrustAnchor(const Name& keyName); |
| 53 | |
| 54 | void |
| 55 | cleanTrustAnchor(); |
| 56 | |
| 57 | protected: |
| 58 | void |
| 59 | checkPolicy(const Data& data, |
| 60 | int stepCount, |
| 61 | const ndn::OnDataValidated& onValidated, |
| 62 | const ndn::OnDataValidationFailed& onValidationFailed, |
| 63 | std::vector<shared_ptr<ndn::ValidationRequest> >& nextSteps); |
| 64 | |
| 65 | void |
| 66 | checkPolicy(const Interest& interest, |
| 67 | int stepCount, |
| 68 | const ndn::OnInterestValidated& onValidated, |
| 69 | const ndn::OnInterestValidationFailed& onValidationFailed, |
| 70 | std::vector<shared_ptr<ndn::ValidationRequest> >& nextSteps); |
| 71 | |
| 72 | private: |
| 73 | void |
| 74 | internalCheck(const uint8_t* buf, size_t size, |
| 75 | const Signature& sig, |
| 76 | const Name& keyLocatorName, |
| 77 | const Data& innerData, |
| 78 | const OnValidated& onValidated, |
| 79 | const OnValidationFailed& onValidationFailed); |
| 80 | |
| 81 | private: |
| 82 | typedef std::map<Name, ndn::PublicKey> TrustAnchors; |
| 83 | |
| 84 | ndn::SecRuleRelative m_invitationReplyRule; |
| 85 | ndn::Regex m_invitationInterestRule; |
| 86 | ndn::Regex m_innerKeyRegex; |
| 87 | TrustAnchors m_trustAnchors; |
| 88 | }; |
| 89 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame^] | 90 | } // namespace chronochat |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 91 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame^] | 92 | #endif // CHRONOCHAT_VALIDATOR_INVITATION_HPP |