certificate-storage.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2023 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
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.
20  */
21 
23 
24 namespace ndn::security {
25 
27  : m_verifiedCertCache(1_h)
28  , m_unverifiedCertCache(5_min)
29 {
30 }
31 
32 const Certificate*
33 CertificateStorage::findTrustedCert(const Interest& interestForCert) const
34 {
35  if (auto cert = m_trustAnchors.find(interestForCert); cert != nullptr) {
36  return cert;
37  }
38  return m_verifiedCertCache.find(interestForCert);
39 }
40 
41 bool
42 CertificateStorage::isCertKnown(const Name& certName) const
43 {
44  return m_trustAnchors.find(certName) != nullptr ||
45  m_verifiedCertCache.find(certName) != nullptr ||
46  m_unverifiedCertCache.find(certName) != nullptr;
47 }
48 
49 void
50 CertificateStorage::loadAnchor(const std::string& groupId, Certificate&& cert)
51 {
52  m_trustAnchors.insert(groupId, std::move(cert));
53 }
54 
55 void
56 CertificateStorage::loadAnchor(const std::string& groupId, const std::string& certfilePath,
57  time::nanoseconds refreshPeriod, bool isDir)
58 {
59  m_trustAnchors.insert(groupId, certfilePath, refreshPeriod, isDir);
60 }
61 
62 void
64 {
66 }
67 
68 void
70 {
71  m_verifiedCertCache.insert(std::move(cert));
72 }
73 
74 void
76 {
78 }
79 
80 void
82 {
83  m_unverifiedCertCache.insert(std::move(cert));
84 }
85 
88 {
89  return m_trustAnchors;
90 }
91 
92 const CertificateCache&
94 {
95  return m_verifiedCertCache;
96 }
97 
98 const CertificateCache&
100 {
101  return m_unverifiedCertCache;
102 }
103 
104 } // namespace ndn::security
Represents an Interest packet.
Definition: interest.hpp:50
Represents an absolute name.
Definition: name.hpp:45
Represents a container for verified certificates.
void insert(const Certificate &cert)
Insert certificate into cache.
const Certificate * find(const Name &certPrefix) const
Get certificate given key name.
void clear()
Remove all certificates from cache.
const Certificate * findTrustedCert(const Interest &interestForCert) const
Find a trusted certificate in trust anchor container or in verified cache.
void cacheUnverifiedCert(Certificate &&cert)
Cache unverified certificate for a period of time (5 minutes).
const TrustAnchorContainer & getTrustAnchors() const
void resetAnchors()
Remove any previously loaded static or dynamic trust anchor.
void cacheVerifiedCert(Certificate &&cert)
Cache verified certificate a period of time (1 hour).
bool isCertKnown(const Name &certPrefix) const
Check if certificate exists in the verified/unverified cache or in the set of trust anchors.
const CertificateCache & getVerifiedCertCache() const
void loadAnchor(const std::string &groupId, Certificate &&cert)
Load static trust anchor.
void resetVerifiedCerts()
Remove any cached verified certificates.
const CertificateCache & getUnverifiedCertCache() const
Represents an NDN certificate.
Definition: certificate.hpp:58
const Certificate * find(const Name &keyName) const
Search for certificate across all groups (longest prefix match).
void insert(const std::string &groupId, Certificate &&cert)
Insert a static trust anchor.
void clear()
Remove all static or dynamic anchors.
Contains the ndn-cxx security framework.
::boost::chrono::nanoseconds nanoseconds
Definition: time.hpp:54