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_PANEL_H |
| 12 | #define CHRONOS_VALIDATOR_PANEL_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/sec-rule-relative.hpp> |
| 16 | #include <ndn-cxx/security/certificate-cache.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 ValidatorPanel : public ndn::Validator |
| 24 | { |
| 25 | public: |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 26 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 27 | static const ndn::shared_ptr<ndn::CertificateCache> DEFAULT_CERT_CACHE; |
| 28 | |
| 29 | ValidatorPanel(int stepLimit = 10, |
| 30 | const ndn::shared_ptr<ndn::CertificateCache> certificateCache = DEFAULT_CERT_CACHE); |
| 31 | |
| 32 | ~ValidatorPanel() |
| 33 | {} |
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 | inline void |
| 36 | addTrustAnchor(const EndorseCertificate& selfEndorseCertificate); |
| 37 | |
| 38 | inline void |
| 39 | removeTrustAnchor(const ndn::Name& keyName); |
| 40 | |
| 41 | protected: |
| 42 | virtual void |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 43 | checkPolicy (const ndn::Data& data, |
| 44 | int stepCount, |
| 45 | const ndn::OnDataValidated& onValidated, |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 46 | const ndn::OnDataValidationFailed& onValidationFailed, |
| 47 | std::vector<ndn::shared_ptr<ndn::ValidationRequest> >& nextSteps); |
| 48 | |
| 49 | virtual void |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 50 | checkPolicy (const ndn::Interest& interest, |
| 51 | int stepCount, |
| 52 | const ndn::OnInterestValidated& onValidated, |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 53 | const ndn::OnInterestValidationFailed& onValidationFailed, |
| 54 | std::vector<ndn::shared_ptr<ndn::ValidationRequest> >& nextSteps) |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 55 | { |
| 56 | onValidationFailed(interest.shared_from_this(), |
| 57 | "No rules for interest."); |
| 58 | } |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 59 | |
| 60 | private: |
| 61 | int m_stepLimit; |
| 62 | ndn::shared_ptr<ndn::CertificateCache> m_certificateCache; |
| 63 | ndn::shared_ptr<ndn::SecRuleRelative> m_endorseeRule; |
| 64 | std::map<ndn::Name, ndn::PublicKey> m_trustAnchors; |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 65 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 66 | }; |
| 67 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 68 | inline void |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 69 | ValidatorPanel::addTrustAnchor(const EndorseCertificate& cert) |
| 70 | { m_trustAnchors[cert.getPublicKeyName()] = cert.getPublicKeyInfo(); } |
| 71 | |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 72 | inline void |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 73 | ValidatorPanel::removeTrustAnchor(const ndn::Name& keyName) |
| 74 | { m_trustAnchors.erase(keyName); } |
| 75 | |
| 76 | }//chronos |
| 77 | |
| 78 | #endif |