NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
sec-public-info.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #include "sec-public-info.hpp"
23 
24 namespace ndn {
25 namespace security {
26 
27 SecPublicInfo::SecPublicInfo(const std::string& location)
28  : m_location(location)
29 {
30 }
31 
33 {
34 }
35 
36 std::string
38 {
39  return this->getScheme() + ":" + m_location;
40 }
41 
42 void
43 SecPublicInfo::addPublicKey(const Name& keyName, KeyType keyType, const v1::PublicKey& publicKey)
44 {
45  addKey(keyName, publicKey);
46 }
47 
48 void
50 {
51  setDefaultIdentityInternal(identityName);
53 }
54 
55 void
57 {
60 }
61 
62 void
64 {
67 }
68 
69 Name
71 {
73 }
74 
75 Name
77 {
78  if (m_defaultCertificate == nullptr)
80 
81  if (m_defaultCertificate == nullptr)
82  BOOST_THROW_EXCEPTION(Error("No default certificate is set"));
83 
84  return m_defaultCertificate->getName();
85 }
86 
87 Name
88 SecPublicInfo::getNewKeyName(const Name& identityName, bool useKsk)
89 {
90  std::ostringstream oss;
91 
92  if (useKsk)
93  oss << "ksk-";
94  else
95  oss << "dsk-";
96 
98 
99  Name keyName = Name(identityName).append(oss.str());
100 
101  if (doesPublicKeyExist(keyName))
102  BOOST_THROW_EXCEPTION(Error("Key name already exists: " + keyName.toUri()));
103 
104  return keyName;
105 }
106 
107 void
109 {
110  addCertificate(certificate);
113 }
114 
115 void
117 {
118  addCertificate(certificate);
119  Name certName = certificate.getName();
124 }
125 
126 void
128 {
129  addCertificate(certificate);
130  Name certName = certificate.getName();
136 }
137 
138 shared_ptr<v1::IdentityCertificate>
139 SecPublicInfo::defaultCertificate()
140 {
141  return getDefaultCertificate();
142 }
143 
144 shared_ptr<v1::IdentityCertificate>
146 {
147  return m_defaultCertificate;
148 }
149 
150 void
152 {
153  try {
156  }
157  catch (SecPublicInfo::Error&) {
158  m_defaultCertificate.reset();
159  }
160 }
161 
162 } // namespace security
163 } // namespace ndn
SecPublicInfo(const std::string &location)
PartialName getPrefix(ssize_t nComponents) const
Extract a prefix (PartialName) of the name, containing first nComponents components.
Definition: name.hpp:241
static Name certificateNameToPublicKeyName(const Name &certificateName)
Get the public key name from the full certificate name.
Copyright (c) 2011-2015 Regents of the University of California.
std::string toUri() const
Encode this name as a URI.
Definition: name.cpp:171
virtual Name getDefaultCertificateNameForKey(const Name &keyName)=0
Get name of the default certificate name for the specified key.
virtual shared_ptr< v1::IdentityCertificate > getCertificate(const Name &certificateName)=0
Get a shared pointer to identity certificate object from the identity storage.
void addCertificateAsSystemDefault(const v1::IdentityCertificate &certificate)
Add a certificate into the public key identity storage and set the certificate as the default one of ...
void addCertificateAsKeyDefault(const v1::IdentityCertificate &certificate)
Add a certificate and set the certificate as the default one of its corresponding key...
virtual void setDefaultIdentityInternal(const Name &identityName)=0
Set the default identity.
const Name & getName() const
Get name of the Data packet.
Definition: data.hpp:318
virtual std::string getScheme()=0
return the scheme of the PibLocator
virtual ~SecPublicInfo()
The virtual Destructor.
Name getNewKeyName(const Name &identityName, bool useKsk)
Generate a key name for the identity.
static time_point now() noexcept
Definition: time.cpp:45
void addCertificateAsIdentityDefault(const v1::IdentityCertificate &certificate)
Add a certificate into the public key identity storage and set the certificate as the default one of ...
shared_ptr< v1::IdentityCertificate > getDefaultCertificate()
Get cached default certificate of the default identity.
virtual void addKey(const Name &keyName, const v1::PublicKey &publicKey)=0
Add a public key to the identity storage.
std::string getPibLocator()
Get PIB Locator.
shared_ptr< v1::IdentityCertificate > m_defaultCertificate
void setDefaultIdentity(const Name &identityName)
Set the default identity.
virtual void addCertificate(const v1::IdentityCertificate &certificate)=0
Add a certificate to the identity storage.
Name getDefaultCertificateName()
Get the default certificate name of the default identity.
Name abstraction to represent an absolute name.
Definition: name.hpp:46
virtual bool doesPublicKeyExist(const Name &keyName)=0
Check if the specified key already exists.
Name getDefaultCertificateNameForIdentity(const Name &identityName)
Get the default certificate name for the specified identity.
milliseconds toUnixTimestamp(const system_clock::TimePoint &point)
Convert system_clock::TimePoint to UNIX timestamp.
Definition: time.cpp:118
virtual Name getDefaultIdentity()=0
Get name of the default identity.
void refreshDefaultCertificate()
try to get the default certificate of the default identity from the public info
virtual void setDefaultKeyNameForIdentityInternal(const Name &keyName)=0
Set the default key name for the corresponding identity.
virtual Name getDefaultKeyNameForIdentity(const Name &identityName)=0
Get name of the default key name for the specified identity.
virtual void setDefaultCertificateNameForKeyInternal(const Name &certificateName)=0
Set the default certificate name for the corresponding key.
void setDefaultCertificateNameForKey(const Name &certificateName)
Set the default certificate name for the corresponding key.
void setDefaultKeyNameForIdentity(const Name &keyName)
Set the default key name for the corresponding identity.