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