Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 2 | /** |
Teng Liang | e6f8751 | 2016-07-26 22:14:19 -0700 | [diff] [blame] | 3 | * Copyright (c) 2013-2016 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 20 | * |
| 21 | * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/> |
| 22 | * @author Jeff Thompson <jefft0@remap.ucla.edu> |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 23 | */ |
| 24 | |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 25 | #include "validator.hpp" |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 26 | #include "../util/crypto.hpp" |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 27 | |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 28 | #include "v1/cryptopp.hpp" |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 29 | |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 30 | namespace ndn { |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 31 | namespace security { |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 32 | |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 33 | static Oid SECP256R1("1.2.840.10045.3.1.7"); |
| 34 | static Oid SECP384R1("1.3.132.0.34"); |
Yingdi Yu | c8f883c | 2014-06-20 23:25:22 -0700 | [diff] [blame] | 35 | |
Yingdi Yu | 4e9b069 | 2014-11-04 16:13:56 -0800 | [diff] [blame] | 36 | Validator::Validator(Face* face) |
| 37 | : m_face(face) |
Yingdi Yu | 96e6406 | 2014-04-15 19:57:33 -0700 | [diff] [blame] | 38 | { |
| 39 | } |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 40 | |
Yingdi Yu | 96e6406 | 2014-04-15 19:57:33 -0700 | [diff] [blame] | 41 | Validator::Validator(Face& face) |
Yingdi Yu | 4e9b069 | 2014-11-04 16:13:56 -0800 | [diff] [blame] | 42 | : m_face(&face) |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 43 | { |
| 44 | } |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 45 | |
Davide Pesavento | c152e6f | 2016-08-14 02:54:48 +0200 | [diff] [blame] | 46 | Validator::~Validator() = default; |
| 47 | |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 48 | void |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 49 | Validator::validate(const Interest& interest, |
| 50 | const OnInterestValidated& onValidated, |
| 51 | const OnInterestValidationFailed& onValidationFailed, |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 52 | int nSteps) |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 53 | { |
Yingdi Yu | c8f883c | 2014-06-20 23:25:22 -0700 | [diff] [blame] | 54 | std::vector<shared_ptr<ValidationRequest> > nextSteps; |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 55 | checkPolicy(interest, nSteps, onValidated, onValidationFailed, nextSteps); |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 56 | |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 57 | if (nextSteps.empty()) { |
| 58 | // If there is no nextStep, |
| 59 | // that means InterestPolicy has already been able to verify the Interest. |
| 60 | // No more further processes. |
| 61 | return; |
| 62 | } |
Yingdi Yu | d9006e7 | 2014-06-23 19:10:44 -0700 | [diff] [blame] | 63 | |
Yingdi Yu | d9006e7 | 2014-06-23 19:10:44 -0700 | [diff] [blame] | 64 | OnFailure onFailure = bind(onValidationFailed, interest.shared_from_this(), _1); |
| 65 | afterCheckPolicy(nextSteps, onFailure); |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | void |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 69 | Validator::validate(const Data& data, |
| 70 | const OnDataValidated& onValidated, |
| 71 | const OnDataValidationFailed& onValidationFailed, |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 72 | int nSteps) |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 73 | { |
Yingdi Yu | c8f883c | 2014-06-20 23:25:22 -0700 | [diff] [blame] | 74 | std::vector<shared_ptr<ValidationRequest> > nextSteps; |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 75 | checkPolicy(data, nSteps, onValidated, onValidationFailed, nextSteps); |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 76 | |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 77 | if (nextSteps.empty()) { |
| 78 | // If there is no nextStep, |
| 79 | // that means Data Policy has already been able to verify the Interest. |
| 80 | // No more further processes. |
| 81 | return; |
| 82 | } |
Yingdi Yu | d9006e7 | 2014-06-23 19:10:44 -0700 | [diff] [blame] | 83 | |
Yingdi Yu | d9006e7 | 2014-06-23 19:10:44 -0700 | [diff] [blame] | 84 | OnFailure onFailure = bind(onValidationFailed, data.shared_from_this(), _1); |
| 85 | afterCheckPolicy(nextSteps, onFailure); |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | void |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 89 | Validator::onData(const Interest& interest, |
| 90 | const Data& data, |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 91 | const shared_ptr<ValidationRequest>& nextStep) |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 92 | { |
Yingdi Yu | d9006e7 | 2014-06-23 19:10:44 -0700 | [diff] [blame] | 93 | shared_ptr<const Data> certificateData = preCertificateValidation(data); |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 94 | |
Yingdi Yu | d9006e7 | 2014-06-23 19:10:44 -0700 | [diff] [blame] | 95 | if (!static_cast<bool>(certificateData)) |
| 96 | return nextStep->m_onDataValidationFailed(data.shared_from_this(), |
| 97 | "Cannot decode cert: " + data.getName().toUri()); |
| 98 | |
| 99 | validate(*certificateData, |
| 100 | nextStep->m_onDataValidated, nextStep->m_onDataValidationFailed, |
| 101 | nextStep->m_nSteps); |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | bool |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 105 | Validator::verifySignature(const Data& data, const v1::PublicKey& key) |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 106 | { |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 107 | if (!data.getSignature().hasKeyLocator()) |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 108 | return false; |
| 109 | |
| 110 | return verifySignature(data.wireEncode().value(), |
| 111 | data.wireEncode().value_size() - |
| 112 | data.getSignature().getValue().size(), |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 113 | data.getSignature(), key); |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | bool |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 117 | Validator::verifySignature(const Interest& interest, const v1::PublicKey& key) |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 118 | { |
Junxiao Shi | 198c381 | 2016-08-12 19:24:18 +0000 | [diff] [blame] | 119 | const Name& name = interest.getName(); |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 120 | |
Junxiao Shi | 198c381 | 2016-08-12 19:24:18 +0000 | [diff] [blame] | 121 | if (name.size() < signed_interest::MIN_LENGTH_SIG_ONLY) |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 122 | return false; |
| 123 | |
Junxiao Shi | 198c381 | 2016-08-12 19:24:18 +0000 | [diff] [blame] | 124 | Signature sig; |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 125 | try { |
Junxiao Shi | 198c381 | 2016-08-12 19:24:18 +0000 | [diff] [blame] | 126 | sig.setInfo(name[signed_interest::POS_SIG_INFO].blockFromValue()); |
| 127 | sig.setValue(name[signed_interest::POS_SIG_VALUE].blockFromValue()); |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 128 | } |
Junxiao Shi | 198c381 | 2016-08-12 19:24:18 +0000 | [diff] [blame] | 129 | catch (const tlv::Error&) { |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 130 | return false; |
| 131 | } |
Junxiao Shi | 198c381 | 2016-08-12 19:24:18 +0000 | [diff] [blame] | 132 | |
| 133 | if (!sig.hasKeyLocator()) |
| 134 | return false; |
| 135 | |
| 136 | const Block& nameWire = name.wireEncode(); |
| 137 | return verifySignature(nameWire.value(), |
| 138 | nameWire.value_size() - name[signed_interest::POS_SIG_VALUE].size(), |
| 139 | sig, key); |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | bool |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 143 | Validator::verifySignature(const uint8_t* buf, |
| 144 | const size_t size, |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 145 | const Signature& sig, |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 146 | const v1::PublicKey& key) |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 147 | { |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 148 | try { |
| 149 | using namespace CryptoPP; |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 150 | |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 151 | switch (sig.getType()) { |
| 152 | case tlv::SignatureSha256WithRsa: { |
| 153 | if (key.getKeyType() != KeyType::RSA) |
Yingdi Yu | c8f883c | 2014-06-20 23:25:22 -0700 | [diff] [blame] | 154 | return false; |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 155 | |
| 156 | RSA::PublicKey publicKey; |
| 157 | ByteQueue queue; |
| 158 | |
| 159 | queue.Put(reinterpret_cast<const byte*>(key.get().buf()), key.get().size()); |
| 160 | publicKey.Load(queue); |
| 161 | |
| 162 | RSASS<PKCS1v15, SHA256>::Verifier verifier(publicKey); |
| 163 | return verifier.VerifyMessage(buf, size, |
| 164 | sig.getValue().value(), sig.getValue().value_size()); |
| 165 | } |
| 166 | |
| 167 | case tlv::SignatureSha256WithEcdsa: { |
| 168 | if (key.getKeyType() != KeyType::EC) |
| 169 | return false; |
| 170 | |
| 171 | ECDSA<ECP, SHA256>::PublicKey publicKey; |
| 172 | ByteQueue queue; |
| 173 | |
| 174 | queue.Put(reinterpret_cast<const byte*>(key.get().buf()), key.get().size()); |
| 175 | publicKey.Load(queue); |
| 176 | |
| 177 | ECDSA<ECP, SHA256>::Verifier verifier(publicKey); |
| 178 | |
| 179 | uint32_t length = 0; |
| 180 | StringSource src(key.get().buf(), key.get().size(), true); |
| 181 | BERSequenceDecoder subjectPublicKeyInfo(src); |
| 182 | { |
| 183 | BERSequenceDecoder algorithmInfo(subjectPublicKeyInfo); |
| 184 | { |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 185 | Oid algorithm; |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 186 | algorithm.decode(algorithmInfo); |
| 187 | |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 188 | Oid curveId; |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 189 | curveId.decode(algorithmInfo); |
| 190 | |
| 191 | if (curveId == SECP256R1) |
| 192 | length = 256; |
| 193 | else if (curveId == SECP384R1) |
| 194 | length = 384; |
| 195 | else |
| 196 | return false; |
| 197 | } |
Yingdi Yu | c8f883c | 2014-06-20 23:25:22 -0700 | [diff] [blame] | 198 | } |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 199 | |
| 200 | switch (length) { |
| 201 | case 256: { |
| 202 | uint8_t buffer[64]; |
| 203 | size_t usedSize = DSAConvertSignatureFormat(buffer, sizeof(buffer), DSA_P1363, |
| 204 | sig.getValue().value(), |
| 205 | sig.getValue().value_size(), |
| 206 | DSA_DER); |
| 207 | return verifier.VerifyMessage(buf, size, buffer, usedSize); |
| 208 | } |
| 209 | |
| 210 | case 384: { |
| 211 | uint8_t buffer[96]; |
| 212 | size_t usedSize = DSAConvertSignatureFormat(buffer, sizeof(buffer), DSA_P1363, |
| 213 | sig.getValue().value(), |
| 214 | sig.getValue().value_size(), |
| 215 | DSA_DER); |
| 216 | return verifier.VerifyMessage(buf, size, buffer, usedSize); |
| 217 | } |
| 218 | |
| 219 | default: |
| 220 | return false; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | default: |
| 225 | // Unsupported sig type |
| 226 | return false; |
Yingdi Yu | 40587c0 | 2014-02-21 16:40:48 -0800 | [diff] [blame] | 227 | } |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 228 | } |
| 229 | catch (const CryptoPP::Exception& e) { |
| 230 | return false; |
| 231 | } |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 232 | } |
| 233 | |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 234 | bool |
Yingdi Yu | bf6a281 | 2014-06-17 15:32:11 -0700 | [diff] [blame] | 235 | Validator::verifySignature(const uint8_t* buf, const size_t size, const DigestSha256& sig) |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 236 | { |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 237 | try { |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 238 | ConstBufferPtr buffer = crypto::computeSha256Digest(buf, size); |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 239 | const Block& sigValue = sig.getValue(); |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 240 | |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 241 | if (buffer != nullptr && |
| 242 | buffer->size() == sigValue.value_size() && |
| 243 | buffer->size() == crypto::SHA256_DIGEST_SIZE) { |
| 244 | const uint8_t* p1 = buffer->buf(); |
| 245 | const uint8_t* p2 = sigValue.value(); |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 246 | |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 247 | return 0 == memcmp(p1, p2, crypto::SHA256_DIGEST_SIZE); |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 248 | } |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 249 | else |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 250 | return false; |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 251 | } |
| 252 | catch (const CryptoPP::Exception& e) { |
| 253 | return false; |
| 254 | } |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 255 | } |
| 256 | |
Yingdi Yu | d9006e7 | 2014-06-23 19:10:44 -0700 | [diff] [blame] | 257 | void |
Teng Liang | e6f8751 | 2016-07-26 22:14:19 -0700 | [diff] [blame] | 258 | Validator::onNack(const Interest& interest, |
| 259 | const lp::Nack& nack, |
| 260 | int remainingRetries, |
| 261 | const OnFailure& onFailure, |
| 262 | const shared_ptr<ValidationRequest>& validationRequest) |
| 263 | { |
| 264 | if (remainingRetries > 0) { |
| 265 | Interest newInterest = Interest(interest); |
| 266 | newInterest.refreshNonce(); |
| 267 | |
| 268 | //Express the same interest with different nonce and decremented remainingRetries. |
| 269 | m_face->expressInterest(newInterest, |
| 270 | bind(&Validator::onData, this, _1, _2, validationRequest), |
| 271 | bind(&Validator::onNack, this, _1, _2, |
| 272 | remainingRetries - 1, onFailure, validationRequest), |
| 273 | bind(&Validator::onTimeout, this, _1, |
| 274 | remainingRetries - 1, onFailure, validationRequest)); |
| 275 | } |
| 276 | else { |
| 277 | onFailure("Cannot fetch cert: " + interest.getName().toUri()); |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | void |
Yingdi Yu | d9006e7 | 2014-06-23 19:10:44 -0700 | [diff] [blame] | 282 | Validator::onTimeout(const Interest& interest, |
| 283 | int remainingRetries, |
| 284 | const OnFailure& onFailure, |
| 285 | const shared_ptr<ValidationRequest>& validationRequest) |
| 286 | { |
Teng Liang | e6f8751 | 2016-07-26 22:14:19 -0700 | [diff] [blame] | 287 | if (remainingRetries > 0) { |
| 288 | Interest newInterest = Interest(interest); |
| 289 | newInterest.refreshNonce(); |
| 290 | |
| 291 | // Express the same interest with different nonce and decremented remainingRetries. |
| 292 | m_face->expressInterest(newInterest, |
Yingdi Yu | 4e9b069 | 2014-11-04 16:13:56 -0800 | [diff] [blame] | 293 | bind(&Validator::onData, this, _1, _2, validationRequest), |
Teng Liang | e6f8751 | 2016-07-26 22:14:19 -0700 | [diff] [blame] | 294 | bind(&Validator::onNack, this, _1, _2, |
| 295 | remainingRetries - 1, onFailure, validationRequest), |
Yingdi Yu | 4e9b069 | 2014-11-04 16:13:56 -0800 | [diff] [blame] | 296 | bind(&Validator::onTimeout, this, _1, |
| 297 | remainingRetries - 1, onFailure, validationRequest)); |
Teng Liang | e6f8751 | 2016-07-26 22:14:19 -0700 | [diff] [blame] | 298 | } |
| 299 | else { |
Yingdi Yu | d9006e7 | 2014-06-23 19:10:44 -0700 | [diff] [blame] | 300 | onFailure("Cannot fetch cert: " + interest.getName().toUri()); |
Teng Liang | e6f8751 | 2016-07-26 22:14:19 -0700 | [diff] [blame] | 301 | } |
Yingdi Yu | d9006e7 | 2014-06-23 19:10:44 -0700 | [diff] [blame] | 302 | } |
| 303 | |
Yingdi Yu | d9006e7 | 2014-06-23 19:10:44 -0700 | [diff] [blame] | 304 | void |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 305 | Validator::afterCheckPolicy(const std::vector<shared_ptr<ValidationRequest>>& nextSteps, |
Yingdi Yu | d9006e7 | 2014-06-23 19:10:44 -0700 | [diff] [blame] | 306 | const OnFailure& onFailure) |
| 307 | { |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 308 | if (m_face == nullptr) { |
| 309 | onFailure("Require more information to validate the packet!"); |
| 310 | return; |
| 311 | } |
Yingdi Yu | 4e9b069 | 2014-11-04 16:13:56 -0800 | [diff] [blame] | 312 | |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 313 | for (shared_ptr<ValidationRequest> step : nextSteps) { |
| 314 | m_face->expressInterest(step->m_interest, |
| 315 | bind(&Validator::onData, this, _1, _2, step), |
| 316 | bind(&Validator::onNack, this, _1, _2, |
| 317 | step->m_nRetries, onFailure, step), |
| 318 | bind(&Validator::onTimeout, |
| 319 | this, _1, step->m_nRetries, |
| 320 | onFailure, |
| 321 | step)); |
| 322 | } |
Yingdi Yu | d9006e7 | 2014-06-23 19:10:44 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 325 | } // namespace security |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 326 | } // namespace ndn |