blob: c786c9f2ec9d2cf7c3de32cab768df948c270bfb [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_PANEL_H
12#define CHRONOS_VALIDATOR_PANEL_H
13
Yingdi Yufa0b6a02014-04-30 14:26:42 -070014#include <ndn-cxx/security/validator.hpp>
15#include <ndn-cxx/security/sec-rule-relative.hpp>
16#include <ndn-cxx/security/certificate-cache.hpp>
Yingdi Yufa4ce792014-02-06 18:09:22 -080017#include <map>
18
19#include "endorse-certificate.h"
20
21namespace chronos{
22
23class ValidatorPanel : public ndn::Validator
24{
25public:
Yingdi Yufa0b6a02014-04-30 14:26:42 -070026
Yingdi Yufa4ce792014-02-06 18:09:22 -080027 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 Yufa0b6a02014-04-30 14:26:42 -070034
Yingdi Yufa4ce792014-02-06 18:09:22 -080035 inline void
36 addTrustAnchor(const EndorseCertificate& selfEndorseCertificate);
37
38 inline void
39 removeTrustAnchor(const ndn::Name& keyName);
40
41protected:
42 virtual void
Yingdi Yufa0b6a02014-04-30 14:26:42 -070043 checkPolicy (const ndn::Data& data,
44 int stepCount,
45 const ndn::OnDataValidated& onValidated,
Yingdi Yufa4ce792014-02-06 18:09:22 -080046 const ndn::OnDataValidationFailed& onValidationFailed,
47 std::vector<ndn::shared_ptr<ndn::ValidationRequest> >& nextSteps);
48
49 virtual void
Yingdi Yufa0b6a02014-04-30 14:26:42 -070050 checkPolicy (const ndn::Interest& interest,
51 int stepCount,
52 const ndn::OnInterestValidated& onValidated,
Yingdi Yufa4ce792014-02-06 18:09:22 -080053 const ndn::OnInterestValidationFailed& onValidationFailed,
54 std::vector<ndn::shared_ptr<ndn::ValidationRequest> >& nextSteps)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080055 {
56 onValidationFailed(interest.shared_from_this(),
57 "No rules for interest.");
58 }
Yingdi Yufa4ce792014-02-06 18:09:22 -080059
60private:
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 Yufa0b6a02014-04-30 14:26:42 -070065
Yingdi Yufa4ce792014-02-06 18:09:22 -080066};
67
Yingdi Yu348f5ea2014-03-01 14:47:25 -080068inline void
Yingdi Yufa4ce792014-02-06 18:09:22 -080069ValidatorPanel::addTrustAnchor(const EndorseCertificate& cert)
70{ m_trustAnchors[cert.getPublicKeyName()] = cert.getPublicKeyInfo(); }
71
Yingdi Yufa0b6a02014-04-30 14:26:42 -070072inline void
Yingdi Yufa4ce792014-02-06 18:09:22 -080073ValidatorPanel::removeTrustAnchor(const ndn::Name& keyName)
74{ m_trustAnchors.erase(keyName); }
75
76}//chronos
77
78#endif