Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [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 | #include "invitation-policy-manager.h" |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 12 | #include "null-ptrs.h" |
| 13 | #include <ndn-cpp/sha256-with-rsa-signature.hpp> |
| 14 | #include <ndn-cpp/security/signature/sha256-with-rsa-handler.hpp> |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 15 | |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 16 | #include "logging.h" |
| 17 | |
| 18 | using namespace std; |
| 19 | using namespace ndn; |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 20 | using namespace ndn::ptr_lib; |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 21 | |
| 22 | INIT_LOGGER("InvitationPolicyManager"); |
| 23 | |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 24 | InvitationPolicyManager::InvitationPolicyManager(const string& chatroomName, |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 25 | const Name& signingIdentity, |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 26 | int stepLimit) |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 27 | : m_chatroomName(chatroomName) |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 28 | , m_signingIdentity(signingIdentity) |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 29 | , m_stepLimit(stepLimit) |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 30 | { |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 31 | m_invitationPolicyRule = make_shared<IdentityPolicyRule>("^<ndn><broadcast><chronos><invitation>([^<chatroom>]*)<chatroom>", |
| 32 | "^([^<KEY>]*)<KEY>(<>*)[<dsk-.*><ksk-.*>]<ID-CERT>$", |
| 33 | "==", "\\1", "\\1\\2", true); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 34 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 35 | m_kskRegex = make_shared<Regex>("^([^<KEY>]*)<KEY>(<>*<ksk-.*>)<ID-CERT><>$", "\\1\\2"); |
Yingdi Yu | 9b34b1f | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 36 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 37 | m_dskRule = make_shared<IdentityPolicyRule>("^([^<KEY>]*)<KEY><dsk-.*><ID-CERT><>$", |
| 38 | "^([^<KEY>]*)<KEY>(<>*)<ksk-.*><ID-CERT>$", |
| 39 | "==", "\\1", "\\1\\2", true); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 40 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 41 | m_keyNameRegex = make_shared<Regex>("^([^<KEY>]*)<KEY>(<>*<ksk-.*>)<ID-CERT>$", "\\1\\2"); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 42 | } |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 43 | |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 44 | InvitationPolicyManager::~InvitationPolicyManager() |
| 45 | {} |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 46 | |
| 47 | bool |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 48 | InvitationPolicyManager::skipVerifyAndTrust (const Data& data) |
| 49 | { return false; } |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 50 | |
| 51 | bool |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 52 | InvitationPolicyManager::requireVerify (const Data& data) |
| 53 | { return true; } |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 54 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 55 | shared_ptr<ValidationRequest> |
| 56 | InvitationPolicyManager::checkVerificationPolicy(const shared_ptr<Data>& data, |
| 57 | int stepCount, |
| 58 | const OnVerified& onVerified, |
| 59 | const OnVerifyFailed& onVerifyFailed) |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 60 | { |
| 61 | if(m_stepLimit == stepCount) |
| 62 | { |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 63 | _LOG_ERROR("Reach the maximum steps of verification!"); |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 64 | onVerifyFailed(data); |
| 65 | return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR; |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 68 | const Sha256WithRsaSignature* sha256sig = dynamic_cast<const Sha256WithRsaSignature*> (data->getSignature()); |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 69 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 70 | if(ndn_KeyLocatorType_KEYNAME != sha256sig->getKeyLocator().getType()) |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 71 | { |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 72 | _LOG_ERROR("KeyLocator is not name!"); |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 73 | onVerifyFailed(data); |
| 74 | return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR; |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | const Name & keyLocatorName = sha256sig->getKeyLocator().getKeyName(); |
| 78 | |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 79 | if(m_invitationPolicyRule->satisfy(*data)) |
| 80 | { |
Yingdi Yu | 9b34b1f | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 81 | // Name keyName = IdentityCertificate::certificateNameToPublicKeyName(keyLocatorName); |
Yingdi Yu | 6eabbd7 | 2013-12-27 08:44:12 +0800 | [diff] [blame^] | 82 | // map<Name, PublicKey>::iterator it = m_trustAnchors.find(keyName); |
Yingdi Yu | 9b34b1f | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 83 | // if(m_trustAnchors.end() != it) |
| 84 | // { |
Yingdi Yu | 6eabbd7 | 2013-12-27 08:44:12 +0800 | [diff] [blame^] | 85 | // if(Sha256WithRsaHandler::verifySignature(*data, it->second)) |
| 86 | // onVerified(data); |
Yingdi Yu | 9b34b1f | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 87 | // else |
Yingdi Yu | 6eabbd7 | 2013-12-27 08:44:12 +0800 | [diff] [blame^] | 88 | // onVerifyFailed(data); |
Yingdi Yu | 9b34b1f | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 89 | |
Yingdi Yu | 6eabbd7 | 2013-12-27 08:44:12 +0800 | [diff] [blame^] | 90 | // return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR; |
Yingdi Yu | 9b34b1f | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 91 | // } |
| 92 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 93 | shared_ptr<const Certificate> trustedCert = m_certificateCache.getCertificate(keyLocatorName); |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 94 | |
Yingdi Yu | 6eabbd7 | 2013-12-27 08:44:12 +0800 | [diff] [blame^] | 95 | if(trustedCert != ndn::TCC_NULL_CERTIFICATE_PTR){ |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 96 | if(Sha256WithRsaHandler::verifySignature(*data, trustedCert->getPublicKeyInfo())) |
| 97 | onVerified(data); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 98 | else |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 99 | onVerifyFailed(data); |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 100 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 101 | return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR; |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 102 | } |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 103 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 104 | OnVerified recursiveVerifiedCallback = boost::bind(&InvitationPolicyManager::onDskCertificateVerified, |
| 105 | this, |
| 106 | _1, |
| 107 | data, |
| 108 | onVerified, |
| 109 | onVerifyFailed); |
Yingdi Yu | 9b34b1f | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 110 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 111 | OnVerifyFailed recursiveUnverifiedCallback = boost::bind(&InvitationPolicyManager::onDskCertificateVerifyFailed, |
| 112 | this, |
| 113 | _1, |
| 114 | data, |
| 115 | onVerifyFailed); |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 116 | |
| 117 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 118 | shared_ptr<Interest> interest = make_shared<Interest>(keyLocatorName); |
Yingdi Yu | 9b34b1f | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 119 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 120 | shared_ptr<ValidationRequest> nextStep = make_shared<ValidationRequest>(interest, |
| 121 | recursiveVerifiedCallback, |
| 122 | recursiveUnverifiedCallback, |
| 123 | 0, |
| 124 | stepCount + 1); |
Yingdi Yu | 9b34b1f | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 125 | return nextStep; |
| 126 | } |
| 127 | |
| 128 | if(m_kskRegex->match(data->getName())) |
| 129 | { |
Yingdi Yu | 9b34b1f | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 130 | Name keyName = m_kskRegex->expand(); |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 131 | map<Name, PublicKey>::iterator it = m_trustAnchors.find(keyName); |
Yingdi Yu | 9b34b1f | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 132 | if(m_trustAnchors.end() != it) |
| 133 | { |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 134 | IdentityCertificate identityCertificate(*data); |
| 135 | if(isSameKey(it->second.getKeyDer(), identityCertificate.getPublicKeyInfo().getKeyDer())) |
Yingdi Yu | 9b34b1f | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 136 | { |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 137 | onVerified(data); |
Yingdi Yu | 9b34b1f | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 138 | } |
| 139 | else |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 140 | onVerifyFailed(data); |
Yingdi Yu | 9b34b1f | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 141 | } |
| 142 | else |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 143 | onVerifyFailed(data); |
Yingdi Yu | 9b34b1f | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 144 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 145 | return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR; |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 146 | } |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 147 | |
| 148 | if(m_dskRule->satisfy(*data)) |
| 149 | { |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 150 | m_keyNameRegex->match(keyLocatorName); |
| 151 | Name keyName = m_keyNameRegex->expand(); |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 152 | |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 153 | if(m_trustAnchors.end() != m_trustAnchors.find(keyName)) |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 154 | if(Sha256WithRsaHandler::verifySignature(*data, m_trustAnchors[keyName])) |
| 155 | onVerified(data); |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 156 | else |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 157 | onVerifyFailed(data); |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 158 | else |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 159 | onVerifyFailed(data); |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 160 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 161 | return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR; |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 162 | } |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 163 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 164 | onVerifyFailed(data); |
| 165 | return CHRONOCHAT_NULL_VALIDATIONREQUEST_PTR; |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 168 | bool |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 169 | InvitationPolicyManager::checkSigningPolicy(const Name& dataName, |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 170 | const Name& certificateName) |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 171 | { |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 172 | return true; |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 173 | } |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 174 | |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 175 | Name |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 176 | InvitationPolicyManager::inferSigningIdentity(const Name& dataName) |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 177 | { |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 178 | return m_signingIdentity; |
Yingdi Yu | 1ec26de | 2013-10-22 16:59:43 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | void |
Yingdi Yu | 978b3ae | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 182 | InvitationPolicyManager::addTrustAnchor(const EndorseCertificate& selfEndorseCertificate) |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 183 | { m_trustAnchors.insert(pair <Name, PublicKey > (selfEndorseCertificate.getPublicKeyName(), selfEndorseCertificate.getPublicKeyInfo())); } |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 184 | |
| 185 | |
| 186 | // void |
| 187 | // InvitationPolicyManager::addChatDataRule(const Name& prefix, |
| 188 | // const IdentityCertificate identityCertificate) |
| 189 | // { |
| 190 | // Name dataPrefix = prefix; |
| 191 | // dataPrefix.append("chronos").append(m_chatroomName); |
| 192 | // Ptr<Regex> dataRegex = Regex::fromName(prefix); |
| 193 | // Name certName = identityCertificate.getName(); |
| 194 | // Name signerName = certName.getPrefix(certName.size()-1); |
| 195 | // Ptr<Regex> signerRegex = Regex::fromName(signerName, true); |
| 196 | |
| 197 | // ChatPolicyRule rule(dataRegex, signerRegex); |
| 198 | // map<Name, ChatPolicyRule>::iterator it = m_chatDataRules.find(dataPrefix); |
| 199 | // if(it != m_chatDataRules.end()) |
| 200 | // it->second = rule; |
| 201 | // else |
| 202 | // m_chatDataRules.insert(pair <Name, ChatPolicyRule > (dataPrefix, rule)); |
| 203 | // } |
| 204 | |
| 205 | |
| 206 | void |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 207 | InvitationPolicyManager::onDskCertificateVerified(const shared_ptr<Data>& certData, |
| 208 | shared_ptr<Data> originalData, |
| 209 | const OnVerified& onVerified, |
| 210 | const OnVerifyFailed& onVerifyFailed) |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 211 | { |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 212 | shared_ptr<IdentityCertificate> certificate = make_shared<IdentityCertificate>(*certData); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 213 | |
| 214 | if(!certificate->isTooLate() && !certificate->isTooEarly()) |
| 215 | { |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 216 | Name certName = certificate->getName().getPrefix(-1); |
| 217 | map<Name, shared_ptr<IdentityCertificate> >::iterator it = m_dskCertificates.find(certName); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 218 | if(it == m_dskCertificates.end()) |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 219 | m_dskCertificates.insert(pair <Name, shared_ptr<IdentityCertificate> > (certName, certificate)); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 220 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 221 | if(Sha256WithRsaHandler::verifySignature(*originalData, certificate->getPublicKeyInfo())) |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 222 | { |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 223 | onVerified(originalData); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 224 | return; |
| 225 | } |
| 226 | } |
| 227 | else |
| 228 | { |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 229 | onVerifyFailed(originalData); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 230 | return; |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | void |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 235 | InvitationPolicyManager::onDskCertificateVerifyFailed(const shared_ptr<Data>& certData, |
| 236 | shared_ptr<Data> originalData, |
| 237 | const OnVerifyFailed& onVerifyFailed) |
| 238 | { onVerifyFailed(originalData); } |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 239 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 240 | shared_ptr<IdentityCertificate> |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 241 | InvitationPolicyManager::getValidatedDskCertificate(const ndn::Name& certName) |
| 242 | { |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 243 | map<Name, shared_ptr<IdentityCertificate> >::iterator it = m_dskCertificates.find(certName); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 244 | if(m_dskCertificates.end() != it) |
| 245 | return it->second; |
| 246 | else |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 247 | return CHRONOCHAT_NULL_IDENTITYCERTIFICATE_PTR; |
| 248 | } |
| 249 | |
| 250 | |
| 251 | bool |
| 252 | InvitationPolicyManager::isSameKey(const Blob& keyA, const Blob& keyB) |
| 253 | { |
| 254 | size_t size = keyA.size(); |
| 255 | |
| 256 | if(size != keyB.size()) |
| 257 | return false; |
| 258 | |
| 259 | const uint8_t* ap = keyA.buf(); |
| 260 | const uint8_t* bp = keyB.buf(); |
| 261 | |
| 262 | for(int i = 0; i < size; i++) |
| 263 | { |
| 264 | if(ap[i] != bp[i]) |
| 265 | return false; |
| 266 | } |
| 267 | |
| 268 | return true; |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 269 | } |