Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Nick Gordon | c6a8522 | 2017-01-03 16:54:34 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, The University of Memphis, |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 6 | * |
| 7 | * This file is part of NLSR (Named-data Link State Routing). |
| 8 | * See AUTHORS.md for complete list of NLSR authors and contributors. |
| 9 | * |
| 10 | * NLSR is free software: you can redistribute it and/or modify it under the terms |
| 11 | * of the GNU General Public License as published by the Free Software Foundation, |
| 12 | * either version 3 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE. See the GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 20 | **/ |
| 21 | |
| 22 | #ifndef NLSR_VALIDATOR_HPP |
| 23 | #define NLSR_VALIDATOR_HPP |
| 24 | |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 25 | #include "common.hpp" |
| 26 | #include "security/certificate-store.hpp" |
| 27 | |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 28 | #include <ndn-cxx/security/validator-config.hpp> |
| 29 | |
| 30 | namespace nlsr { |
| 31 | |
| 32 | class Validator : public ndn::ValidatorConfig |
| 33 | { |
| 34 | public: |
| 35 | class Error : public ndn::ValidatorConfig::Error |
| 36 | { |
| 37 | public: |
| 38 | explicit |
| 39 | Error(const std::string& what) |
| 40 | : ndn::ValidatorConfig::Error(what) |
| 41 | { |
| 42 | } |
| 43 | }; |
| 44 | |
| 45 | explicit |
| 46 | Validator(ndn::Face& face, |
| 47 | const ndn::Name broadcastPrefix, |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 48 | const std::shared_ptr<ndn::CertificateCache>& cache, |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 49 | security::CertificateStore& certStore, |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 50 | const int stepLimit = 10) |
Yingdi Yu | e024803 | 2014-06-19 14:06:13 -0700 | [diff] [blame] | 51 | : ndn::ValidatorConfig(face, cache, ndn::ValidatorConfig::DEFAULT_GRACE_INTERVAL, stepLimit) |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 52 | , m_shouldValidate(true) |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 53 | , m_broadcastPrefix(broadcastPrefix) |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 54 | , m_certStore(certStore) |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 55 | { |
| 56 | m_broadcastPrefix.append("KEYS"); |
| 57 | } |
| 58 | |
| 59 | virtual |
| 60 | ~Validator() |
| 61 | { |
| 62 | } |
| 63 | |
| 64 | const ndn::Name& |
| 65 | getBroadcastPrefix() |
| 66 | { |
| 67 | return m_broadcastPrefix; |
| 68 | } |
| 69 | |
| 70 | void |
| 71 | setBroadcastPrefix(const ndn::Name& broadcastPrefix) |
| 72 | { |
| 73 | m_broadcastPrefix = broadcastPrefix; |
| 74 | } |
| 75 | |
| 76 | protected: |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 77 | typedef std::vector<std::shared_ptr<ndn::ValidationRequest>> NextSteps; |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 78 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 79 | void |
| 80 | checkPolicy(const ndn::Data& data, |
| 81 | int nSteps, |
| 82 | const ndn::OnDataValidated& onValidated, |
| 83 | const ndn::OnDataValidationFailed& onValidationFailed, |
| 84 | std::vector<shared_ptr<ndn::ValidationRequest>>& nextSteps) override; |
| 85 | |
| 86 | void |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 87 | afterCheckPolicy(const NextSteps& nextSteps, |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 88 | const OnFailure& onFailure) override; |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 89 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 90 | std::shared_ptr<const ndn::Data> |
| 91 | preCertificateValidation(const ndn::Data& data) override; |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 92 | |
Nick Gordon | d5c1a37 | 2016-10-31 13:56:23 -0500 | [diff] [blame] | 93 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 94 | bool m_shouldValidate; |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 95 | |
| 96 | private: |
| 97 | ndn::Name m_broadcastPrefix; |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 98 | security::CertificateStore& m_certStore; |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 99 | }; |
| 100 | |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 101 | } // namespace nlsr |
| 102 | |
| 103 | #endif // NLSR_VALIDATOR_HPP |