Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [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 | |
| 11 | #ifndef CHRONOS_VALIDATOR_INVITATION_H |
| 12 | #define CHRONOS_VALIDATOR_INVITATION_H |
| 13 | |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame^] | 14 | #include <ndn-cxx/security/validator.hpp> |
| 15 | #include <ndn-cxx/security/certificate-cache.hpp> |
| 16 | #include <ndn-cxx/security/sec-rule-relative.hpp> |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 17 | #include <map> |
| 18 | |
| 19 | #include "endorse-certificate.h" |
| 20 | |
| 21 | namespace chronos{ |
| 22 | |
| 23 | class ValidatorInvitation : public ndn::Validator |
| 24 | { |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 25 | typedef ndn::function< void (const std::string&) > OnValidationFailed; |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 26 | typedef ndn::function< void () > OnValidated; |
| 27 | |
| 28 | public: |
| 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 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 33 | ValidatorInvitation(); |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame^] | 34 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 35 | virtual |
| 36 | ~ValidatorInvitation() {}; |
| 37 | |
| 38 | void |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 39 | addTrustAnchor(const ndn::Name& keyName, const ndn::PublicKey& key) |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame^] | 40 | { |
| 41 | m_trustAnchors[keyName] = key; |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 42 | } |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 43 | |
| 44 | void |
| 45 | removeTrustAnchor(const ndn::Name& keyName) |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame^] | 46 | { |
| 47 | m_trustAnchors.erase(keyName); |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 48 | } |
| 49 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 50 | void |
| 51 | cleanTrustAnchor() |
| 52 | { |
| 53 | m_trustAnchors.clear(); |
| 54 | } |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame^] | 55 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 56 | protected: |
| 57 | void |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame^] | 58 | checkPolicy(const ndn::Data& data, |
| 59 | int stepCount, |
| 60 | const ndn::OnDataValidated& onValidated, |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 61 | const ndn::OnDataValidationFailed& onValidationFailed, |
| 62 | std::vector<ndn::shared_ptr<ndn::ValidationRequest> >& nextSteps); |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame^] | 63 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 64 | void |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame^] | 65 | checkPolicy(const ndn::Interest& interest, |
| 66 | int stepCount, |
| 67 | const ndn::OnInterestValidated& onValidated, |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 68 | const ndn::OnInterestValidationFailed& onValidationFailed, |
| 69 | std::vector<ndn::shared_ptr<ndn::ValidationRequest> >& nextSteps); |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 70 | |
| 71 | private: |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 72 | void |
| 73 | internalCheck(const uint8_t* buf, size_t size, |
| 74 | const ndn::SignatureSha256WithRsa& sig, |
| 75 | const ndn::Data& innerData, |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame^] | 76 | const OnValidated& onValidated, |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 77 | const OnValidationFailed& onValidationFailed); |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 78 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 79 | private: |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 80 | typedef std::map<ndn::Name, ndn::PublicKey> TrustAnchors; |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 81 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 82 | ndn::SecRuleRelative m_invitationReplyRule; |
| 83 | ndn::Regex m_invitationInterestRule; |
| 84 | ndn::Regex m_innerKeyRegex; |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 85 | TrustAnchors m_trustAnchors; |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | }//chronos |
| 89 | |
| 90 | #endif //CHRONOS_VALIDATOR_INVITATION_H |