All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
certificate-storage.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
23 #ifndef NDN_CERTIFICATE_STORAGE_HPP
24 #define NDN_CERTIFICATE_STORAGE_HPP
25 
26 #include "certificate-cache-v2.hpp"
27 #include "trust-anchor-container.hpp"
28 
29 namespace ndn {
30 
36 public:
38  : verifiedCertificateCache_(3600 * 1000.0),
39  unverifiedCertificateCache_(300 * 1000.0)
40  {
41  }
42 
49  ptr_lib::shared_ptr<CertificateV2>
50  findTrustedCertificate(const Interest& interestForCertificate);
51 
58  bool
59  isCertificateKnown(const Name& certificatePrefix);
60 
65  void
67  {
68  unverifiedCertificateCache_.insert(certificate);
69  }
70 
76  getTrustAnchors() const { return trustAnchors_; }
77 
82  const CertificateCacheV2&
83  getVerifiedCertificateCache() const { return verifiedCertificateCache_; }
84 
89  const CertificateCacheV2&
90  getUnverifiedCertificateCache() const { return unverifiedCertificateCache_; }
91 
99  void
100  loadAnchor(const std::string& groupId, const CertificateV2& certificate)
101  {
102  trustAnchors_.insert(groupId, certificate);
103  }
104 
119  void
120  loadAnchor
121  (const std::string& groupId, const std::string& path,
122  Milliseconds refreshPeriod, bool isDirectory = false)
123  {
124  trustAnchors_.insert(groupId, path, refreshPeriod, isDirectory);
125  }
126 
130  void
131  resetAnchors() { trustAnchors_.clear(); }
132 
137  void
139  {
140  verifiedCertificateCache_.insert(certificate);
141  }
142 
146  void
147  resetVerifiedCertificates() { verifiedCertificateCache_.clear(); }
148 
154  void
156  {
157  verifiedCertificateCache_.setNowOffsetMilliseconds_(nowOffsetMilliseconds);
158  unverifiedCertificateCache_.setNowOffsetMilliseconds_(nowOffsetMilliseconds);
159  }
160 
161 private:
162  // Disable the copy constructor and assignment operator.
164  CertificateStorage& operator=(const CertificateStorage& other);
165 
166 protected:
167  TrustAnchorContainer trustAnchors_;
168  CertificateCacheV2 verifiedCertificateCache_;
169  CertificateCacheV2 unverifiedCertificateCache_;
170 };
171 
172 }
173 
174 #endif
double Milliseconds
A time interval represented as the number of milliseconds.
Definition: common.hpp:114
void cacheVerifiedCertificate(const CertificateV2 &certificate)
Cache the verified certificate a period of time (1 hour).
Definition: certificate-storage.hpp:138
void resetAnchors()
Remove any previously loaded static or dynamic trust anchors.
Definition: certificate-storage.hpp:131
void setCacheNowOffsetMilliseconds_(Milliseconds nowOffsetMilliseconds)
Set the offset when the cache insert() and refresh() get the current time, which should only be used ...
Definition: certificate-storage.hpp:155
void insert(const std::string &groupId, const CertificateV2 &certificate)
Insert a static trust anchor.
const CertificateCacheV2 & getUnverifiedCertificateCache() const
Get the unverified certificate cache.
Definition: certificate-storage.hpp:90
CertificateV2 represents a certificate following the certificate format naming convention.
Definition: certificate-v2.hpp:81
void cacheUnverifiedCertificate(const CertificateV2 &certificate)
Cache the unverified certificate for a period of time (5 minutes).
Definition: certificate-storage.hpp:66
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:40
const CertificateCacheV2 & getVerifiedCertificateCache() const
Get the verified certificate cache.
Definition: certificate-storage.hpp:83
An Interest holds a Name and other fields for an interest.
Definition: interest.hpp:43
The CertificateStorage class stores trusted anchors and has a verified certificate cache...
Definition: certificate-storage.hpp:35
void insert(const CertificateV2 &certificate)
Insert the certificate into the cache.
Definition: certificate-cache-v2.cpp:42
A CertificateCacheV2 holds other user's verified certificates in security v2 format CertificateV2...
Definition: certificate-cache-v2.hpp:38
void clear()
Remove all static and dynamic anchors.
Definition: trust-anchor-container.hpp:94
void setNowOffsetMilliseconds_(Milliseconds nowOffsetMilliseconds)
Set the offset when insert() and refresh() get the current time, which should only be used for testin...
Definition: certificate-cache-v2.hpp:109
void clear()
Clear all certificates from the cache.
Definition: certificate-cache-v2.hpp:90
void loadAnchor(const std::string &groupId, const CertificateV2 &certificate)
Load a static trust anchor.
Definition: certificate-storage.hpp:100
void resetVerifiedCertificates()
Remove any cached verified certificates.
Definition: certificate-storage.hpp:147
bool isCertificateKnown(const Name &certificatePrefix)
Check if the certificate with the given name prefix exists in the verified cache, the unverified cach...
Definition: certificate-storage.cpp:43
ptr_lib::shared_ptr< CertificateV2 > findTrustedCertificate(const Interest &interestForCertificate)
Find a trusted certificate in the trust anchor container or in the verified cache.
Definition: certificate-storage.cpp:31
A TrustAnchorContainer represents a container for trust anchors.
Definition: trust-anchor-container.hpp:49
const TrustAnchorContainer & getTrustAnchors() const
Get the trust anchor container.
Definition: certificate-storage.hpp:76