blob: c4f2a19fd405dca19c110e830f52da5a0041a918 [file] [log] [blame]
Yingdi Yu20e3a6e2014-05-26 23:16:10 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonc6a85222017-01-03 16:54:34 -06003 * Copyright (c) 2014-2017, The University of Memphis,
Vince Lehmanc2acdcb2015-04-29 11:14:35 -05004 * Regents of the University of California,
5 * Arizona Board of Regents.
Yingdi Yu20e3a6e2014-05-26 23:16:10 -07006 *
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 Yu20e3a6e2014-05-26 23:16:10 -070020 **/
21
22#ifndef NLSR_VALIDATOR_HPP
23#define NLSR_VALIDATOR_HPP
24
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050025#include "common.hpp"
26#include "security/certificate-store.hpp"
27
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070028#include <ndn-cxx/security/validator-config.hpp>
29
30namespace nlsr {
31
32class Validator : public ndn::ValidatorConfig
33{
34public:
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,
dmcoomes9f936662017-03-02 10:33:09 -060048 const std::shared_ptr<ndn::CertificateCache>& cache,
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050049 security::CertificateStore& certStore,
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070050 const int stepLimit = 10)
Yingdi Yue0248032014-06-19 14:06:13 -070051 : ndn::ValidatorConfig(face, cache, ndn::ValidatorConfig::DEFAULT_GRACE_INTERVAL, stepLimit)
Nick Gordond5c1a372016-10-31 13:56:23 -050052 , m_shouldValidate(true)
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070053 , m_broadcastPrefix(broadcastPrefix)
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050054 , m_certStore(certStore)
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070055 {
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
76protected:
dmcoomes9f936662017-03-02 10:33:09 -060077 typedef std::vector<std::shared_ptr<ndn::ValidationRequest>> NextSteps;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070078
Nick Gordond5c1a372016-10-31 13:56:23 -050079 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 Lehmanc2acdcb2015-04-29 11:14:35 -050087 afterCheckPolicy(const NextSteps& nextSteps,
Nick Gordond5c1a372016-10-31 13:56:23 -050088 const OnFailure& onFailure) override;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070089
Nick Gordond5c1a372016-10-31 13:56:23 -050090 std::shared_ptr<const ndn::Data>
91 preCertificateValidation(const ndn::Data& data) override;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070092
Nick Gordond5c1a372016-10-31 13:56:23 -050093PUBLIC_WITH_TESTS_ELSE_PRIVATE:
94 bool m_shouldValidate;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070095
96private:
97 ndn::Name m_broadcastPrefix;
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050098 security::CertificateStore& m_certStore;
Yingdi Yu20e3a6e2014-05-26 23:16:10 -070099};
100
Yingdi Yu20e3a6e2014-05-26 23:16:10 -0700101} // namespace nlsr
102
103#endif // NLSR_VALIDATOR_HPP