blob: a49124ff9081a6c2c4f72ea0911a6db61576b037 [file] [log] [blame]
Yingdi Yu1ec26de2013-10-22 16:59:43 -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 INVITATION_POLICY_MANAGER_H
12#define INVITATION_POLICY_MANAGER_H
13
Yingdi Yu76dd8002013-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>
17#include <ndn-cpp-et/regex/regex.hpp>
Yingdi Yu1ec26de2013-10-22 16:59:43 -070018#include <map>
19
Yingdi Yu978b3ae2013-10-23 11:50:51 -070020#include "endorse-certificate.h"
Yingdi Yu7989eb22013-10-31 17:38:22 -070021#include "chat-policy-rule.h"
Yingdi Yu978b3ae2013-10-23 11:50:51 -070022
Yingdi Yu76dd8002013-12-24 11:16:32 +080023class InvitationPolicyManager : public ndn::PolicyManager
Yingdi Yu1ec26de2013-10-22 16:59:43 -070024{
25public:
Yingdi Yu7989eb22013-10-31 17:38:22 -070026 InvitationPolicyManager(const std::string& chatroomName,
Yingdi Yue35bdb82013-11-07 11:32:40 -080027 const ndn::Name& signingIdentity,
Yingdi Yu76dd8002013-12-24 11:16:32 +080028 int stepLimit = 10);
Yingdi Yu7989eb22013-10-31 17:38:22 -070029
30 virtual
31 ~InvitationPolicyManager();
Yingdi Yu1ec26de2013-10-22 16:59:43 -070032
Yingdi Yu1ec26de2013-10-22 16:59:43 -070033 bool
Yingdi Yu7989eb22013-10-31 17:38:22 -070034 skipVerifyAndTrust (const ndn::Data& data);
Yingdi Yu1ec26de2013-10-22 16:59:43 -070035
Yingdi Yu1ec26de2013-10-22 16:59:43 -070036 bool
Yingdi Yu7989eb22013-10-31 17:38:22 -070037 requireVerify (const ndn::Data& data);
Yingdi Yu1ec26de2013-10-22 16:59:43 -070038
Yingdi Yu76dd8002013-12-24 11:16:32 +080039 ndn::ptr_lib::shared_ptr<ndn::ValidationRequest>
40 checkVerificationPolicy(const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
41 int stepCount,
42 const ndn::OnVerified& onVerified,
43 const ndn::OnVerifyFailed& onVerifyFailed);
Yingdi Yu1ec26de2013-10-22 16:59:43 -070044
Yingdi Yu1ec26de2013-10-22 16:59:43 -070045 bool
Yingdi Yu7989eb22013-10-31 17:38:22 -070046 checkSigningPolicy(const ndn::Name& dataName,
47 const ndn::Name& certificateName);
48
Yingdi Yu978b3ae2013-10-23 11:50:51 -070049 ndn::Name
Yingdi Yu7989eb22013-10-31 17:38:22 -070050 inferSigningIdentity(const ndn::Name& dataName);
Yingdi Yu1ec26de2013-10-22 16:59:43 -070051
Yingdi Yu1ec26de2013-10-22 16:59:43 -070052 void
Yingdi Yu978b3ae2013-10-23 11:50:51 -070053 addTrustAnchor(const EndorseCertificate& selfEndorseCertificate);
Yingdi Yu7989eb22013-10-31 17:38:22 -070054
55 // void
56 // addChatDataRule(const ndn::Name& prefix,
57 // const ndn::security::IdentityCertificate identityCertificate);
Yingdi Yu1ec26de2013-10-22 16:59:43 -070058
Yingdi Yu76dd8002013-12-24 11:16:32 +080059 ndn::ptr_lib::shared_ptr<ndn::IdentityCertificate>
Yingdi Yu7989eb22013-10-31 17:38:22 -070060 getValidatedDskCertificate(const ndn::Name& certName);
Yingdi Yu1ec26de2013-10-22 16:59:43 -070061
62private:
Yingdi Yu7989eb22013-10-31 17:38:22 -070063 void
Yingdi Yu76dd8002013-12-24 11:16:32 +080064 onDskCertificateVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& certData,
65 ndn::ptr_lib::shared_ptr<ndn::Data> originalData,
66 const ndn::OnVerified& onVerified,
67 const ndn::OnVerifyFailed& onVerifyFailed);
Yingdi Yu7989eb22013-10-31 17:38:22 -070068
69 void
Yingdi Yu76dd8002013-12-24 11:16:32 +080070 onDskCertificateVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& certData,
71 ndn::ptr_lib::shared_ptr<ndn::Data> originalData,
72 const ndn::OnVerifyFailed& onVerifyFailed);
73
74 static bool
75 isSameKey(const ndn::Blob& keyA, const ndn::Blob& keyB);
Yingdi Yu7989eb22013-10-31 17:38:22 -070076
77private:
78 std::string m_chatroomName;
Yingdi Yue35bdb82013-11-07 11:32:40 -080079 ndn::Name m_signingIdentity;
Yingdi Yu7989eb22013-10-31 17:38:22 -070080
Yingdi Yu1ec26de2013-10-22 16:59:43 -070081 int m_stepLimit;
Yingdi Yu7989eb22013-10-31 17:38:22 -070082
Yingdi Yu76dd8002013-12-24 11:16:32 +080083 ndn::TTLCertificateCache m_certificateCache;
Yingdi Yu7989eb22013-10-31 17:38:22 -070084
Yingdi Yu76dd8002013-12-24 11:16:32 +080085 ndn::ptr_lib::shared_ptr<ndn::IdentityPolicyRule> m_invitationPolicyRule;
86 ndn::ptr_lib::shared_ptr<ndn::IdentityPolicyRule> m_dskRule;
87 std::map<ndn::Name, ChatPolicyRule, ndn::Name::BreadthFirstLess> m_chatDataRules;
Yingdi Yu7989eb22013-10-31 17:38:22 -070088
Yingdi Yu76dd8002013-12-24 11:16:32 +080089 ndn::ptr_lib::shared_ptr<ndn::Regex> m_kskRegex;
90 ndn::ptr_lib::shared_ptr<ndn::Regex> m_keyNameRegex;
Yingdi Yu7989eb22013-10-31 17:38:22 -070091
Yingdi Yu76dd8002013-12-24 11:16:32 +080092 std::map<ndn::Name, ndn::PublicKey, ndn::Name::BreadthFirstLess> m_trustAnchors;
Yingdi Yu7989eb22013-10-31 17:38:22 -070093
Yingdi Yu76dd8002013-12-24 11:16:32 +080094 std::map<ndn::Name, ndn::ptr_lib::shared_ptr<ndn::IdentityCertificate>, ndn::Name::BreadthFirstLess> m_dskCertificates;
Yingdi Yu7989eb22013-10-31 17:38:22 -070095
Yingdi Yu1ec26de2013-10-22 16:59:43 -070096};
97
Yingdi Yu7989eb22013-10-31 17:38:22 -070098#endif //CHATROOM_POLICY_MANAGER_H