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