blob: d7b827681fc592424b906ae9978b534c0ac00cde [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
Yingdi Yufa0b6a02014-04-30 14:26:42 -070014#include <ndn-cxx/security/validator.hpp>
15#include <ndn-cxx/security/certificate-cache.hpp>
16#include <ndn-cxx/security/sec-rule-relative.hpp>
Yingdi Yufa4ce792014-02-06 18:09:22 -080017#include <map>
18
19#include "endorse-certificate.h"
20
21namespace chronos{
22
23class ValidatorInvitation : public ndn::Validator
24{
Yingdi Yu348f5ea2014-03-01 14:47:25 -080025 typedef ndn::function< void (const std::string&) > OnValidationFailed;
Yingdi Yufa4ce792014-02-06 18:09:22 -080026 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
Yingdi Yu348f5ea2014-03-01 14:47:25 -080033 ValidatorInvitation();
Yingdi Yufa0b6a02014-04-30 14:26:42 -070034
Yingdi Yufa4ce792014-02-06 18:09:22 -080035 virtual
36 ~ValidatorInvitation() {};
37
38 void
Yingdi Yu348f5ea2014-03-01 14:47:25 -080039 addTrustAnchor(const ndn::Name& keyName, const ndn::PublicKey& key)
Yingdi Yufa0b6a02014-04-30 14:26:42 -070040 {
41 m_trustAnchors[keyName] = key;
Yingdi Yu348f5ea2014-03-01 14:47:25 -080042 }
Yingdi Yufa4ce792014-02-06 18:09:22 -080043
44 void
45 removeTrustAnchor(const ndn::Name& keyName)
Yingdi Yufa0b6a02014-04-30 14:26:42 -070046 {
47 m_trustAnchors.erase(keyName);
Yingdi Yufa4ce792014-02-06 18:09:22 -080048 }
49
Yingdi Yu348f5ea2014-03-01 14:47:25 -080050 void
51 cleanTrustAnchor()
52 {
53 m_trustAnchors.clear();
54 }
Yingdi Yufa0b6a02014-04-30 14:26:42 -070055
Yingdi Yufa4ce792014-02-06 18:09:22 -080056protected:
57 void
Yingdi Yufa0b6a02014-04-30 14:26:42 -070058 checkPolicy(const ndn::Data& data,
59 int stepCount,
60 const ndn::OnDataValidated& onValidated,
Yingdi Yu348f5ea2014-03-01 14:47:25 -080061 const ndn::OnDataValidationFailed& onValidationFailed,
62 std::vector<ndn::shared_ptr<ndn::ValidationRequest> >& nextSteps);
Yingdi Yufa0b6a02014-04-30 14:26:42 -070063
Yingdi Yufa4ce792014-02-06 18:09:22 -080064 void
Yingdi Yufa0b6a02014-04-30 14:26:42 -070065 checkPolicy(const ndn::Interest& interest,
66 int stepCount,
67 const ndn::OnInterestValidated& onValidated,
Yingdi Yu348f5ea2014-03-01 14:47:25 -080068 const ndn::OnInterestValidationFailed& onValidationFailed,
69 std::vector<ndn::shared_ptr<ndn::ValidationRequest> >& nextSteps);
Yingdi Yufa4ce792014-02-06 18:09:22 -080070
71private:
Yingdi Yu348f5ea2014-03-01 14:47:25 -080072 void
73 internalCheck(const uint8_t* buf, size_t size,
74 const ndn::SignatureSha256WithRsa& sig,
75 const ndn::Data& innerData,
Yingdi Yufa0b6a02014-04-30 14:26:42 -070076 const OnValidated& onValidated,
Yingdi Yu348f5ea2014-03-01 14:47:25 -080077 const OnValidationFailed& onValidationFailed);
Yingdi Yufa4ce792014-02-06 18:09:22 -080078
Yingdi Yu348f5ea2014-03-01 14:47:25 -080079private:
Yingdi Yufa4ce792014-02-06 18:09:22 -080080 typedef std::map<ndn::Name, ndn::PublicKey> TrustAnchors;
Yingdi Yufa4ce792014-02-06 18:09:22 -080081
Yingdi Yu348f5ea2014-03-01 14:47:25 -080082 ndn::SecRuleRelative m_invitationReplyRule;
83 ndn::Regex m_invitationInterestRule;
84 ndn::Regex m_innerKeyRegex;
Yingdi Yufa4ce792014-02-06 18:09:22 -080085 TrustAnchors m_trustAnchors;
Yingdi Yufa4ce792014-02-06 18:09:22 -080086};
87
88}//chronos
89
90#endif //CHRONOS_VALIDATOR_INVITATION_H