Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | 0ad01f3 | 2020-06-03 14:12:58 -0400 | [diff] [blame] | 2 | /* |
Junxiao Shi | b032fcb | 2022-04-28 01:28:50 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, 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. |
| 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/>. |
Alexander Afanasyev | 0ad01f3 | 2020-06-03 14:12:58 -0400 | [diff] [blame] | 20 | */ |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 21 | |
| 22 | #ifndef NLSR_CERTIFICATE_STORE_HPP |
| 23 | #define NLSR_CERTIFICATE_STORE_HPP |
| 24 | |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 25 | #include "common.hpp" |
| 26 | #include "test-access-control.hpp" |
| 27 | #include "lsdb.hpp" |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 28 | |
| 29 | #include <ndn-cxx/interest.hpp> |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 30 | #include <ndn-cxx/mgmt/nfd/controller.hpp> |
Alexander Afanasyev | 0ad01f3 | 2020-06-03 14:12:58 -0400 | [diff] [blame] | 31 | #include <ndn-cxx/security/certificate.hpp> |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 32 | #include <ndn-cxx/security/validator-config.hpp> |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 33 | |
| 34 | namespace nlsr { |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 35 | class ConfParameter; |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 36 | namespace security { |
| 37 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 38 | /*! \brief Store certificates for names |
| 39 | * |
| 40 | * Stores certificates that this router claims to be authoritative |
| 41 | * for. That is, this stores only the certificates that we will reply |
| 42 | * to KEY interests with, e.g. when other routers are verifying data |
| 43 | * we have sent. |
| 44 | */ |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 45 | class CertificateStore |
| 46 | { |
| 47 | public: |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 48 | CertificateStore(ndn::Face& face, ConfParameter& confParam, Lsdb& lsdb); |
| 49 | |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 50 | void |
Alexander Afanasyev | 0ad01f3 | 2020-06-03 14:12:58 -0400 | [diff] [blame] | 51 | insert(const ndn::security::Certificate& certificate); |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 52 | |
Junxiao Shi | b032fcb | 2022-04-28 01:28:50 +0000 | [diff] [blame] | 53 | /*! |
| 54 | * \brief Find a certificate |
| 55 | * \param name Either key name or certificate name. |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 56 | * |
| 57 | * Find a certificate that NLSR has. First it checks against the |
| 58 | * certificates this NLSR claims to be authoritative for, usually |
| 59 | * something like this specific router's certificate, and then |
| 60 | * checks the cache of certificates it has already fetched. If none |
| 61 | * can be found, it will return an null pointer. |
Junxiao Shi | b032fcb | 2022-04-28 01:28:50 +0000 | [diff] [blame] | 62 | */ |
Alexander Afanasyev | 0ad01f3 | 2020-06-03 14:12:58 -0400 | [diff] [blame] | 63 | const ndn::security::Certificate* |
Junxiao Shi | b032fcb | 2022-04-28 01:28:50 +0000 | [diff] [blame] | 64 | find(const ndn::Name& name) const; |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 65 | |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 66 | /*! \brief Retrieves the chain of certificates from Validator's cache and |
| 67 | * store them in Nlsr's own CertificateStore. |
| 68 | * \param keyName Name of the first key in the certificate chain. |
| 69 | */ |
| 70 | void |
| 71 | publishCertFromCache(const ndn::Name& keyName); |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 72 | |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 73 | void |
| 74 | afterFetcherSignalEmitted(const ndn::Data& lsaSegment); |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 75 | |
| 76 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Junxiao Shi | b032fcb | 2022-04-28 01:28:50 +0000 | [diff] [blame] | 77 | const ndn::security::Certificate* |
| 78 | findByKeyName(const ndn::Name& keyName) const; |
| 79 | |
| 80 | const ndn::security::Certificate* |
| 81 | findByCertName(const ndn::Name& certName) const; |
| 82 | |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 83 | void |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 84 | clear(); |
| 85 | |
| 86 | void |
| 87 | setInterestFilter(const ndn::Name& prefix, const bool loopback = false); |
| 88 | |
| 89 | void |
| 90 | registerKeyPrefixes(); |
| 91 | |
| 92 | void |
| 93 | onKeyInterest(const ndn::Name& name, const ndn::Interest& interest); |
| 94 | |
| 95 | void |
| 96 | onKeyPrefixRegSuccess(const ndn::Name& name); |
| 97 | |
| 98 | void |
| 99 | registrationFailed(const ndn::Name& name); |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 100 | |
| 101 | private: |
Alexander Afanasyev | 0ad01f3 | 2020-06-03 14:12:58 -0400 | [diff] [blame] | 102 | typedef std::map<ndn::Name, ndn::security::Certificate> CertMap; |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 103 | CertMap m_certificates; |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 104 | ndn::Face& m_face; |
| 105 | ConfParameter& m_confParam; |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 106 | ndn::security::ValidatorConfig& m_validator; |
| 107 | ndn::util::signal::ScopedConnection m_afterSegmentValidatedConnection; |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | } // namespace security |
| 111 | } // namespace nlsr |
| 112 | |
| 113 | #endif // NLSR_CERTIFICATE_STORE_HPP |