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 | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 25 | #ifndef NDN_SECURITY_VALIDATOR_HPP |
| 26 | #define NDN_SECURITY_VALIDATOR_HPP |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 27 | |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 28 | #include "../face.hpp" |
| 29 | #include "public-key.hpp" |
| 30 | #include "signature-sha256-with-rsa.hpp" |
Yingdi Yu | c8f883c | 2014-06-20 23:25:22 -0700 | [diff] [blame] | 31 | #include "signature-sha256-with-ecdsa.hpp" |
Yingdi Yu | bf6a281 | 2014-06-17 15:32:11 -0700 | [diff] [blame] | 32 | #include "digest-sha256.hpp" |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 33 | #include "validation-request.hpp" |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 34 | #include "identity-certificate.hpp" |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 35 | |
| 36 | namespace ndn { |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 37 | |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 38 | /** |
Junxiao Shi | 198c381 | 2016-08-12 19:24:18 +0000 | [diff] [blame^] | 39 | * @brief provides the interfaces for packet validation. |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 40 | */ |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame] | 41 | class Validator |
| 42 | { |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 43 | public: |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 44 | class Error : public std::runtime_error |
| 45 | { |
| 46 | public: |
| 47 | explicit |
| 48 | Error(const std::string& what) |
| 49 | : std::runtime_error(what) |
| 50 | { |
| 51 | } |
| 52 | }; |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 53 | |
Yingdi Yu | 4e9b069 | 2014-11-04 16:13:56 -0800 | [diff] [blame] | 54 | /** |
| 55 | * @brief Validator constructor |
| 56 | * |
| 57 | * @param face Pointer to face through which validator may retrieve certificates. |
| 58 | * Passing a null pointer implies the validator is in offline mode. |
| 59 | * |
| 60 | * @note Make sure the lifetime of the passed Face is longer than validator. |
| 61 | */ |
| 62 | explicit |
| 63 | Validator(Face* face = nullptr); |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 64 | |
Yingdi Yu | 4e9b069 | 2014-11-04 16:13:56 -0800 | [diff] [blame] | 65 | /// @deprecated Use the constructor taking Face* as parameter. |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 66 | explicit |
Yingdi Yu | 96e6406 | 2014-04-15 19:57:33 -0700 | [diff] [blame] | 67 | Validator(Face& face); |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 68 | |
| 69 | /** |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 70 | * @brief Validate Data and call either onValidated or onValidationFailed. |
| 71 | * |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 72 | * @param data The Data with the signature to check. |
| 73 | * @param onValidated If the Data is validated, this calls onValidated(data). |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 74 | * @param onValidationFailed If validation fails, this calls onValidationFailed(data). |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 75 | */ |
| 76 | void |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 77 | validate(const Data& data, |
| 78 | const OnDataValidated& onValidated, |
| 79 | const OnDataValidationFailed& onValidationFailed) |
| 80 | { |
| 81 | validate(data, onValidated, onValidationFailed, 0); |
| 82 | } |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 83 | |
| 84 | /** |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 85 | * @brief Validate Interest and call either onValidated or onValidationFailed. |
| 86 | * |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 87 | * @param interest The Interest with the signature to check. |
| 88 | * @param onValidated If the Interest is validated, this calls onValidated(interest). |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 89 | * @param onValidationFailed If validation fails, this calls onValidationFailed(interest). |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 90 | */ |
| 91 | void |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 92 | validate(const Interest& interest, |
| 93 | const OnInterestValidated& onValidated, |
| 94 | const OnInterestValidationFailed& onValidationFailed) |
| 95 | { |
| 96 | validate(interest, onValidated, onValidationFailed, 0); |
| 97 | } |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 98 | |
| 99 | /***************************************** |
| 100 | * verifySignature method set * |
| 101 | *****************************************/ |
| 102 | |
| 103 | /// @brief Verify the data using the publicKey. |
| 104 | static bool |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 105 | verifySignature(const Data& data, const PublicKey& publicKey); |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 106 | |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 107 | /** |
| 108 | * @brief Verify the signed Interest using the publicKey. |
| 109 | * |
| 110 | * (Note the signature covers the first n-2 name components). |
| 111 | */ |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 112 | static bool |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 113 | verifySignature(const Interest& interest, const PublicKey& publicKey); |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 114 | |
| 115 | /// @brief Verify the blob using the publicKey against the signature. |
| 116 | static bool |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 117 | verifySignature(const Buffer& blob, const Signature& sig, const PublicKey& publicKey) |
Yingdi Yu | c8f883c | 2014-06-20 23:25:22 -0700 | [diff] [blame] | 118 | { |
| 119 | return verifySignature(blob.buf(), blob.size(), sig, publicKey); |
| 120 | } |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 121 | |
| 122 | /// @brief Verify the data using the publicKey against the SHA256-RSA signature. |
| 123 | static bool |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 124 | verifySignature(const Data& data, |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 125 | const Signature& sig, |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 126 | const PublicKey& publicKey) |
| 127 | { |
| 128 | return verifySignature(data.wireEncode().value(), |
| 129 | data.wireEncode().value_size() - data.getSignature().getValue().size(), |
| 130 | sig, publicKey); |
| 131 | } |
| 132 | |
| 133 | /** @brief Verify the interest using the publicKey against the SHA256-RSA signature. |
| 134 | * |
| 135 | * (Note the signature covers the first n-2 name components). |
| 136 | */ |
| 137 | static bool |
| 138 | verifySignature(const Interest& interest, |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 139 | const Signature& sig, |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 140 | const PublicKey& publicKey) |
| 141 | { |
| 142 | if (interest.getName().size() < 2) |
| 143 | return false; |
| 144 | |
Yingdi Yu | 3cca4ab | 2014-04-11 12:46:53 -0700 | [diff] [blame] | 145 | const Name& name = interest.getName(); |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 146 | |
Yingdi Yu | 3cca4ab | 2014-04-11 12:46:53 -0700 | [diff] [blame] | 147 | return verifySignature(name.wireEncode().value(), |
| 148 | name.wireEncode().value_size() - name[-1].size(), |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 149 | sig, publicKey); |
| 150 | } |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 151 | |
| 152 | /// @brief Verify the blob using the publicKey against the SHA256-RSA signature. |
| 153 | static bool |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 154 | verifySignature(const uint8_t* buf, |
| 155 | const size_t size, |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 156 | const Signature& sig, |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 157 | const PublicKey& publicKey); |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 158 | |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 159 | |
| 160 | /// @brief Verify the data against the SHA256 signature. |
| 161 | static bool |
Yingdi Yu | bf6a281 | 2014-06-17 15:32:11 -0700 | [diff] [blame] | 162 | verifySignature(const Data& data, const DigestSha256& sig) |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 163 | { |
| 164 | return verifySignature(data.wireEncode().value(), |
| 165 | data.wireEncode().value_size() - |
| 166 | data.getSignature().getValue().size(), |
| 167 | sig); |
| 168 | } |
| 169 | |
| 170 | /** @brief Verify the interest against the SHA256 signature. |
| 171 | * |
| 172 | * (Note the signature covers the first n-2 name components). |
| 173 | */ |
| 174 | static bool |
Yingdi Yu | bf6a281 | 2014-06-17 15:32:11 -0700 | [diff] [blame] | 175 | verifySignature(const Interest& interest, const DigestSha256& sig) |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 176 | { |
| 177 | if (interest.getName().size() < 2) |
| 178 | return false; |
| 179 | |
Yingdi Yu | 6ab6781 | 2014-11-27 15:00:34 -0800 | [diff] [blame] | 180 | const Name& name = interest.getName(); |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 181 | |
Yingdi Yu | 6ab6781 | 2014-11-27 15:00:34 -0800 | [diff] [blame] | 182 | return verifySignature(name.wireEncode().value(), |
| 183 | name.wireEncode().value_size() - name[-1].size(), |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 184 | sig); |
| 185 | } |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 186 | |
| 187 | /// @brief Verify the blob against the SHA256 signature. |
| 188 | static bool |
Yingdi Yu | bf6a281 | 2014-06-17 15:32:11 -0700 | [diff] [blame] | 189 | verifySignature(const Buffer& blob, const DigestSha256& sig) |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 190 | { |
| 191 | return verifySignature (blob.buf(), blob.size(), sig); |
| 192 | } |
| 193 | |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 194 | /// @brief Verify the blob against the SHA256 signature. |
| 195 | static bool |
Yingdi Yu | bf6a281 | 2014-06-17 15:32:11 -0700 | [diff] [blame] | 196 | verifySignature(const uint8_t* buf, const size_t size, const DigestSha256& sig); |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 197 | |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 198 | protected: |
| 199 | /** |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 200 | * @brief Check the Data against policy and return the next validation step if necessary. |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 201 | * |
| 202 | * If there is no next validation step, that validation MUST have been done. |
| 203 | * i.e., either onValidated or onValidationFailed callback is invoked. |
| 204 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 205 | * @param data The Data to check. |
| 206 | * @param nSteps The number of validation steps that have been done. |
| 207 | * @param onValidated If the Data is validated, this calls onValidated(data) |
| 208 | * @param onValidationFailed If validation fails, this calls onValidationFailed(data) |
| 209 | * @param nextSteps On return, contains the next validation step |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 210 | */ |
| 211 | virtual void |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 212 | checkPolicy(const Data& data, |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 213 | int nSteps, |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 214 | const OnDataValidated& onValidated, |
| 215 | const OnDataValidationFailed& onValidationFailed, |
| 216 | std::vector<shared_ptr<ValidationRequest> >& nextSteps) = 0; |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 217 | |
| 218 | /** |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 219 | * @brief Check the Interest against validation policy and return the next validation step |
| 220 | * if necessary. |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 221 | * |
| 222 | * If there is no next validation step, that validation MUST have been done. |
| 223 | * i.e., either onValidated or onValidationFailed callback is invoked. |
| 224 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 225 | * @param interest The Interest to check. |
| 226 | * @param nSteps The number of validation steps that have been done. |
| 227 | * @param onValidated If the Interest is validated, this calls onValidated(data) |
| 228 | * @param onValidationFailed If validation fails, this calls onValidationFailed(data) |
| 229 | * @param nextSteps On return, contains the next validation step |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 230 | */ |
| 231 | virtual void |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 232 | checkPolicy(const Interest& interest, |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 233 | int nSteps, |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 234 | const OnInterestValidated& onValidated, |
| 235 | const OnInterestValidationFailed& onValidationFailed, |
| 236 | std::vector<shared_ptr<ValidationRequest> >& nextSteps) = 0; |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 237 | |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 238 | typedef function<void(const std::string&)> OnFailure; |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 239 | |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 240 | /// @brief Process the received certificate. |
| 241 | void |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 242 | onData(const Interest& interest, |
| 243 | const Data& data, |
| 244 | const shared_ptr<ValidationRequest>& nextStep); |
| 245 | |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 246 | void |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 247 | validate(const Data& data, |
| 248 | const OnDataValidated& onValidated, |
| 249 | const OnDataValidationFailed& onValidationFailed, |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 250 | int nSteps); |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 251 | |
| 252 | void |
Yingdi Yu | 48e8c0c | 2014-03-19 12:01:55 -0700 | [diff] [blame] | 253 | validate(const Interest& interest, |
| 254 | const OnInterestValidated& onValidated, |
| 255 | const OnInterestValidationFailed& onValidationFailed, |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 256 | int nSteps); |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 257 | |
Yingdi Yu | d9006e7 | 2014-06-23 19:10:44 -0700 | [diff] [blame] | 258 | /// Hooks |
| 259 | |
| 260 | /** |
| 261 | * @brief trigger before validating requested certificate. |
| 262 | * |
| 263 | * The Data: |
| 264 | * - matches the interest in the validation-request. |
| 265 | * - may be certificate or a data encapsulating certificate. |
| 266 | * |
| 267 | * This method returns a data (actually certificate) that is will be passed as Data into: |
| 268 | * Validator::validate(const Data& data, |
| 269 | * const OnDataValidated& onValidated, |
| 270 | * const OnDataValidationFailed& onValidationFailed, |
| 271 | * int nSteps); |
| 272 | */ |
| 273 | virtual shared_ptr<const Data> |
| 274 | preCertificateValidation(const Data& data) |
| 275 | { |
| 276 | return data.shared_from_this(); |
| 277 | } |
| 278 | |
| 279 | /** |
Teng Liang | e6f8751 | 2016-07-26 22:14:19 -0700 | [diff] [blame] | 280 | * @brief trigger when interest retrieves a Nack. |
| 281 | * |
| 282 | * Validator can decide how to handle a Nack, either call onFailure, or retry. |
| 283 | * |
| 284 | * @param interest The interest that retrieves a Nack. |
| 285 | * @param nack The Nack that is retrieved. |
| 286 | * @param nRemainingRetries The number of retries left. |
| 287 | * @param onFailure Failure callback when there is no more retries remaining. |
| 288 | * @param validationRequest The validationRequest containing the context of the interest. |
| 289 | */ |
| 290 | virtual void |
| 291 | onNack(const Interest& interest, |
| 292 | const lp::Nack& nack, |
| 293 | int nRemainingRetries, |
| 294 | const OnFailure& onFailure, |
| 295 | const shared_ptr<ValidationRequest>& validationRequest); |
| 296 | |
| 297 | /** |
Yingdi Yu | d9006e7 | 2014-06-23 19:10:44 -0700 | [diff] [blame] | 298 | * @brief trigger when interest for certificate times out. |
| 299 | * |
| 300 | * Validator can decide how to handle the timeout, either call onFailure, or retry. |
| 301 | * |
| 302 | * @param interest The interest that times out. |
| 303 | * @param nRemainingRetries The number of retries left. |
| 304 | * @param onFailure Failure callback when there is no more retries remaining. |
| 305 | * @param validationRequest The validationRequest containing the context of the interest. |
| 306 | */ |
Yingdi Yu | d9006e7 | 2014-06-23 19:10:44 -0700 | [diff] [blame] | 307 | virtual void |
| 308 | onTimeout(const Interest& interest, |
| 309 | int nRemainingRetries, |
| 310 | const OnFailure& onFailure, |
| 311 | const shared_ptr<ValidationRequest>& validationRequest); |
| 312 | |
| 313 | /** |
| 314 | * @brief trigger after checkPolicy is done. |
| 315 | * |
| 316 | * Validator can decide how to handle the set of validation requests according to |
| 317 | * the trust model. |
| 318 | * |
| 319 | * @param nextSteps A set of validation request made by checkPolicy. |
| 320 | * @param onFailure Failure callback when errors happen in processing nextSteps. |
| 321 | */ |
| 322 | virtual void |
| 323 | afterCheckPolicy(const std::vector<shared_ptr<ValidationRequest> >& nextSteps, |
| 324 | const OnFailure& onFailure); |
| 325 | |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 326 | protected: |
Yingdi Yu | 4e9b069 | 2014-11-04 16:13:56 -0800 | [diff] [blame] | 327 | Face* m_face; |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 328 | }; |
| 329 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 330 | } // namespace ndn |
Yingdi Yu | 6ac9798 | 2014-01-30 14:49:21 -0800 | [diff] [blame] | 331 | |
Yingdi Yu | 4e9b069 | 2014-11-04 16:13:56 -0800 | [diff] [blame] | 332 | #endif // NDN_SECURITY_VALIDATOR_HPP |