certificate-storage.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #include "certificate-storage.hpp"
23 
24 namespace ndn {
25 namespace security {
26 namespace v2 {
27 
29  : m_verifiedCertCache(time::hours(1))
30  , m_unverifiedCertCache(time::minutes(5))
31 {
32 }
33 
34 const Certificate*
35 CertificateStorage::findTrustedCert(const Interest& interestForCert) const
36 {
37  auto cert = m_trustAnchors.find(interestForCert);
38  if (cert != nullptr) {
39  return cert;
40  }
41 
42  cert = m_verifiedCertCache.find(interestForCert);
43  return cert;
44 }
45 
46 bool
47 CertificateStorage::isCertKnown(const Name& certName) const
48 {
49  return (m_trustAnchors.find(certName) != nullptr ||
50  m_verifiedCertCache.find(certName) != nullptr ||
51  m_unverifiedCertCache.find(certName) != nullptr);
52 }
53 
54 void
55 CertificateStorage::loadAnchor(const std::string& groupId, Certificate&& cert)
56 {
57  m_trustAnchors.insert(groupId, std::move(cert));
58 }
59 
60 void
61 CertificateStorage::loadAnchor(const std::string& groupId, const std::string& certfilePath,
62  time::nanoseconds refreshPeriod, bool isDir)
63 {
64  m_trustAnchors.insert(groupId, certfilePath, refreshPeriod, isDir);
65 }
66 
67 void
69 {
70  m_verifiedCertCache.insert(std::move(cert));
71 }
72 
73 void
75 {
76  m_unverifiedCertCache.insert(std::move(cert));
77 }
78 
81 {
82  return m_trustAnchors;
83 }
84 
85 const CertificateCache&
87 {
88  return m_verifiedCertCache;
89 }
90 
91 const CertificateCache&
93 {
94  return m_unverifiedCertCache;
95 }
96 
97 } // namespace v2
98 } // namespace security
99 } // namespace ndn
const CertificateCache & getVerifiedCertCache() const
void loadAnchor(const std::string &groupId, Certificate &&cert)
load static trust anchor.
Copyright (c) 2013-2016 Regents of the University of California.
Definition: common.hpp:74
The certificate following the certificate format naming convention.
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.
const TrustAnchorContainer & getTrustAnchors() const
void cacheUnverifiedCert(Certificate &&cert)
Cache unverified certificate for a period of time (5 minutes)
represents an Interest packet
Definition: interest.hpp:42
bool isCertKnown(const Name &certPrefix) const
Check if certificate exists in verified, unverified cache, or in the set of trust anchors...
const Certificate * find(const Name &certPrefix) const
Get certificate given key name.
Represents a container for verified certificates.
represents a container for trust anchors.
const CertificateCache & getUnverifiedCertCache() const
void cacheVerifiedCert(Certificate &&cert)
Cache verified certificate a period of time (1 hour)
const Certificate * findTrustedCert(const Interest &interestForCert) const
Find a trusted certificate in trust anchor container or in verified cache.
Name abstraction to represent an absolute name.
Definition: name.hpp:46
void insert(const Certificate &cert)
Insert certificate into cache.