NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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 
26 SecPublicInfo::SecPublicInfo(const std::string& location)
27  : m_location(location)
28 {
29 }
30 
32 {
33 }
34 
35 std::string
37 {
38  return this->getScheme() + ":" + m_location;
39 }
40 
41 void
42 SecPublicInfo::addPublicKey(const Name& keyName, KeyType keyType, const PublicKey& publicKey)
43 {
44  addKey(keyName, publicKey);
45 }
46 
47 void
49 {
50  setDefaultIdentityInternal(identityName);
52 }
53 
54 void
56 {
59 }
60 
61 void
63 {
66 }
67 
68 Name
70 {
72 }
73 
74 Name
76 {
77  if (m_defaultCertificate == nullptr)
79 
80  if (m_defaultCertificate == nullptr)
81  BOOST_THROW_EXCEPTION(Error("No default certificate is set"));
82 
83  return m_defaultCertificate->getName();
84 }
85 
86 Name
87 SecPublicInfo::getNewKeyName(const Name& identityName, bool useKsk)
88 {
89  std::ostringstream oss;
90 
91  if (useKsk)
92  oss << "ksk-";
93  else
94  oss << "dsk-";
95 
97 
98  Name keyName = Name(identityName).append(oss.str());
99 
100  if (doesPublicKeyExist(keyName))
101  BOOST_THROW_EXCEPTION(Error("Key name already exists: " + keyName.toUri()));
102 
103  return keyName;
104 }
105 
106 void
108 {
109  addCertificate(certificate);
112 }
113 
114 void
116 {
117  addCertificate(certificate);
118  Name certName = certificate.getName();
123 }
124 
125 void
127 {
128  addCertificate(certificate);
129  Name certName = certificate.getName();
135 }
136 
137 shared_ptr<IdentityCertificate>
138 SecPublicInfo::defaultCertificate()
139 {
140  return getDefaultCertificate();
141 }
142 
143 shared_ptr<IdentityCertificate>
145 {
146  return m_defaultCertificate;
147 }
148 
149 void
151 {
152  try {
155  }
156  catch (SecPublicInfo::Error&) {
157  m_defaultCertificate.reset();
158  }
159 }
160 
161 } // namespace ndn
Name getDefaultCertificateNameForIdentity(const Name &identityName)
Get the default certificate name for the specified identity.
PartialName getPrefix(ssize_t nComponents) const
Extract a prefix (PartialName) of the name, containing first nComponents components.
Definition: name.hpp:249
Copyright (c) 2011-2015 Regents of the University of California.
std::string toUri() const
Encode this name as a URI.
Definition: name.cpp:183
virtual void addCertificate(const IdentityCertificate &certificate)=0
Add a certificate to the identity storage.
virtual Name getDefaultCertificateNameForKey(const Name &keyName)=0
Get name of the default certificate name for the specified key.
const Name & getName() const
Get name of the Data packet.
Definition: data.hpp:360
void setDefaultKeyNameForIdentity(const Name &keyName)
Set the default key name for the corresponding identity.
static Name certificateNameToPublicKeyName(const Name &certificateName)
Get the public key name from the full certificate name.
virtual void setDefaultIdentityInternal(const Name &identityName)=0
Set the default identity.
static time_point now() noexcept
Definition: time.cpp:45
virtual void addKey(const Name &keyName, const PublicKey &publicKey)=0
Add a public key to the identity storage.
void setDefaultCertificateNameForKey(const Name &certificateName)
Set the default certificate name for the corresponding key.
Name getNewKeyName(const Name &identityName, bool useKsk)
Generate a key name for the identity.
void addCertificateAsIdentityDefault(const IdentityCertificate &certificate)
Add a certificate into the public key identity storage and set the certificate as the default one of ...
void addCertificateAsSystemDefault(const IdentityCertificate &certificate)
Add a certificate into the public key identity storage and set the certificate as the default one of ...
shared_ptr< IdentityCertificate > getDefaultCertificate()
Get cached default certificate of the default identity.
virtual bool doesPublicKeyExist(const Name &keyName)=0
Check if the specified key already exists.
virtual void setDefaultKeyNameForIdentityInternal(const Name &keyName)=0
Set the default key name for the corresponding identity.
std::string getPibLocator()
Get PIB Locator.
virtual shared_ptr< IdentityCertificate > getCertificate(const Name &certificateName)=0
Get a shared pointer to identity certificate object from the identity storage.
Name abstraction to represent an absolute name.
Definition: name.hpp:46
virtual std::string getScheme()=0
return the scheme of the PibLocator
virtual ~SecPublicInfo()
The virtual Destructor.
SecPublicInfo(const std::string &location)
shared_ptr< IdentityCertificate > m_defaultCertificate
void refreshDefaultCertificate()
try to get the default certificate of the default identity from the public info
void setDefaultIdentity(const Name &identityName)
Set the default identity.
milliseconds toUnixTimestamp(const system_clock::TimePoint &point)
Convert system_clock::TimePoint to UNIX timestamp.
Definition: time.cpp:118
void addCertificateAsKeyDefault(const IdentityCertificate &certificate)
Add a certificate and set the certificate as the default one of its corresponding key...
Name getDefaultCertificateName()
Get the default certificate name of the default identity.
virtual Name getDefaultKeyNameForIdentity(const Name &identityName)=0
Get name of the default key name for the specified identity.
virtual Name getDefaultIdentity()=0
Get name of the default identity.
virtual void setDefaultCertificateNameForKeyInternal(const Name &certificateName)=0
Set the default certificate name for the corresponding key.