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