blob: a4708b45aeef8191b188a866b7dc6214fa1c94ed [file] [log] [blame]
Vince Lehmanc2acdcb2015-04-29 11:14:35 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyev0ad01f32020-06-03 14:12:58 -04002/*
Davide Pesaventob6adfe12024-07-05 13:03:15 -04003 * Copyright (c) 2014-2024, The University of Memphis,
Vince Lehmanc2acdcb2015-04-29 11:14:35 -05004 * 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 Afanasyev0ad01f32020-06-03 14:12:58 -040020 */
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050021
22#ifndef NLSR_CERTIFICATE_STORE_HPP
23#define NLSR_CERTIFICATE_STORE_HPP
24
Davide Pesaventob6adfe12024-07-05 13:03:15 -040025#include <ndn-cxx/face.hpp>
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050026#include <ndn-cxx/interest.hpp>
Alexander Afanasyev0ad01f32020-06-03 14:12:58 -040027#include <ndn-cxx/security/certificate.hpp>
Saurab Dulal427e0122019-11-28 11:58:02 -060028#include <ndn-cxx/security/validator-config.hpp>
Davide Pesaventob6adfe12024-07-05 13:03:15 -040029#include <ndn-cxx/util/signal/scoped-connection.hpp>
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050030
31namespace nlsr {
Davide Pesaventob6adfe12024-07-05 13:03:15 -040032
Saurab Dulal427e0122019-11-28 11:58:02 -060033class ConfParameter;
Davide Pesaventob6adfe12024-07-05 13:03:15 -040034class Lsdb;
35
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050036namespace security {
37
Davide Pesaventob6adfe12024-07-05 13:03:15 -040038/*! \brief Store certificates for names.
Nick Gordond0a7df32017-05-30 16:44:34 -050039 *
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 Lehmanc2acdcb2015-04-29 11:14:35 -050045class CertificateStore
46{
47public:
Saurab Dulal427e0122019-11-28 11:58:02 -060048 CertificateStore(ndn::Face& face, ConfParameter& confParam, Lsdb& lsdb);
49
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050050 void
Alexander Afanasyev0ad01f32020-06-03 14:12:58 -040051 insert(const ndn::security::Certificate& certificate);
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050052
Junxiao Shib032fcb2022-04-28 01:28:50 +000053 /*!
54 * \brief Find a certificate
55 * \param name Either key name or certificate name.
Saurab Dulal427e0122019-11-28 11:58:02 -060056 *
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 Shib032fcb2022-04-28 01:28:50 +000062 */
Alexander Afanasyev0ad01f32020-06-03 14:12:58 -040063 const ndn::security::Certificate*
Junxiao Shib032fcb2022-04-28 01:28:50 +000064 find(const ndn::Name& name) const;
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050065
Saurab Dulal427e0122019-11-28 11:58:02 -060066 /*! \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 Lehmanc2acdcb2015-04-29 11:14:35 -050072
Davide Pesaventob6adfe12024-07-05 13:03:15 -040073private:
Junxiao Shib032fcb2022-04-28 01:28:50 +000074 const ndn::security::Certificate*
75 findByKeyName(const ndn::Name& keyName) const;
76
77 const ndn::security::Certificate*
78 findByCertName(const ndn::Name& certName) const;
79
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050080 void
Davide Pesaventob6adfe12024-07-05 13:03:15 -040081 setInterestFilter(const ndn::Name& prefix);
Saurab Dulal427e0122019-11-28 11:58:02 -060082
83 void
84 registerKeyPrefixes();
85
86 void
87 onKeyInterest(const ndn::Name& name, const ndn::Interest& interest);
88
89 void
90 onKeyPrefixRegSuccess(const ndn::Name& name);
91
92 void
93 registrationFailed(const ndn::Name& name);
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050094
95private:
Davide Pesaventob6adfe12024-07-05 13:03:15 -040096 std::map<ndn::Name, ndn::security::Certificate> m_certificates;
Saurab Dulal427e0122019-11-28 11:58:02 -060097 ndn::Face& m_face;
98 ConfParameter& m_confParam;
Saurab Dulal427e0122019-11-28 11:58:02 -060099 ndn::security::ValidatorConfig& m_validator;
Davide Pesaventob6adfe12024-07-05 13:03:15 -0400100 ndn::signal::ScopedConnection m_afterSegmentValidatedConn;
Vince Lehmanc2acdcb2015-04-29 11:14:35 -0500101};
102
103} // namespace security
104} // namespace nlsr
105
106#endif // NLSR_CERTIFICATE_STORE_HPP