blob: 712f9e52fb3b75e213f81c3f9c4f9175c6663728 [file] [log] [blame]
Yingdi Yu42f66462013-10-31 17:38:22 -07001/* -*- 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 PANEL_POLICY_MANAGER_H
12#define PANEL_POLICY_MANAGER_H
13
Yingdi Yu64206112013-12-24 11:16:32 +080014#include <ndn-cpp/security/policy/policy-manager.hpp>
15#include <ndn-cpp-et/policy-manager/identity-policy-rule.hpp>
16#include <ndn-cpp-et/cache/ttl-certificate-cache.hpp>
Yingdi Yu42f66462013-10-31 17:38:22 -070017#include <map>
18
19#include "endorse-certificate.h"
20
Yingdi Yu64206112013-12-24 11:16:32 +080021class PanelPolicyManager : public ndn::PolicyManager
Yingdi Yu42f66462013-10-31 17:38:22 -070022{
23public:
Yingdi Yu64206112013-12-24 11:16:32 +080024 PanelPolicyManager(const int & stepLimit = 10);
Yingdi Yu42f66462013-10-31 17:38:22 -070025
26 ~PanelPolicyManager()
27 {}
28
29 /**
30 * @brief check if the received data packet can escape from verification
31 * @param data the received data packet
32 * @return true if the data does not need to be verified, otherwise false
33 */
34 bool
35 skipVerifyAndTrust (const ndn::Data & data);
36
37 /**
38 * @brief check if PolicyManager has the verification rule for the received data
39 * @param data the received data packet
40 * @return true if the data must be verified, otherwise false
41 */
42 bool
43 requireVerify (const ndn::Data & data);
44
45 /**
46 * @brief check whether received data packet complies with the verification policy, and get the indication of next verification step
47 * @param data the received data packet
48 * @param stepCount the number of verification steps that have been done, used to track the verification progress
49 * @param verifiedCallback the callback function that will be called if the received data packet has been validated
50 * @param unverifiedCallback the callback function that will be called if the received data packet cannot be validated
51 * @return the indication of next verification step, NULL if there is no further step
52 */
Yingdi Yu64206112013-12-24 11:16:32 +080053 ndn::ptr_lib::shared_ptr<ndn::ValidationRequest>
54 checkVerificationPolicy(const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
55 int stepCount,
56 const ndn::OnVerified& onVerified,
57 const ndn::OnVerifyFailed& onVerifyFailed);
Yingdi Yu42f66462013-10-31 17:38:22 -070058
59
60 /**
61 * @brief check if the signing certificate name and data name satify the signing policy
62 * @param dataName the name of data to be signed
63 * @param certificateName the name of signing certificate
64 * @return true if the signing certificate can be used to sign the data, otherwise false
65 */
66 bool
67 checkSigningPolicy(const ndn::Name & dataName, const ndn::Name & certificateName);
68
69 /**
70 * @brief Infer signing identity name according to policy, if the signing identity cannot be inferred, it should return empty name
71 * @param dataName, the name of data to be signed
72 * @return the signing identity.
73 */
74 ndn::Name
75 inferSigningIdentity(const ndn::Name & dataName);
76
77
78 void
79 addTrustAnchor(const EndorseCertificate& selfEndorseCertificate);
80
Yingdi Yu6ea54e42013-11-12 17:50:21 -080081 void
82 removeTrustAnchor(const ndn::Name& keyName);
83
Yingdi Yu64206112013-12-24 11:16:32 +080084 ndn::ptr_lib::shared_ptr<ndn::PublicKey>
Yingdi Yu6b56f092013-11-10 11:54:02 -080085 getTrustedKey(const ndn::Name& inviterCertName);
86
Yingdi Yu42f66462013-10-31 17:38:22 -070087private:
Yingdi Yu64206112013-12-24 11:16:32 +080088 static bool
89 isSameKey(const ndn::Blob& keyA, const ndn::Blob& keyB);
90
91private:
Yingdi Yu42f66462013-10-31 17:38:22 -070092 int m_stepLimit;
Yingdi Yu64206112013-12-24 11:16:32 +080093 ndn::TTLCertificateCache m_certificateCache;
94 ndn::ptr_lib::shared_ptr<ndn::Regex> m_localPrefixRegex;
95 ndn::ptr_lib::shared_ptr<ndn::IdentityPolicyRule> m_invitationDataSigningRule;
96 ndn::ptr_lib::shared_ptr<ndn::Regex> m_kskRegex;
97 ndn::ptr_lib::shared_ptr<ndn::IdentityPolicyRule> m_dskRule;
98 ndn::ptr_lib::shared_ptr<ndn::IdentityPolicyRule> m_endorseeRule;
99 ndn::ptr_lib::shared_ptr<ndn::Regex> m_keyNameRegex;
100 ndn::ptr_lib::shared_ptr<ndn::Regex> m_signingCertificateRegex;
101 std::map<ndn::Name, ndn::PublicKey, ndn::Name::BreadthFirstLess> m_trustAnchors;
Yingdi Yu42f66462013-10-31 17:38:22 -0700102
103};
104
105#endif