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 namespace v1 {
27 
28 SecPublicInfo::SecPublicInfo(const std::string& location)
29  : m_location(location)
30 {
31 }
32 
34 {
35 }
36 
37 std::string
39 {
40  return this->getScheme() + ":" + m_location;
41 }
42 
43 void
44 SecPublicInfo::addPublicKey(const Name& keyName, KeyType keyType, const PublicKey& publicKey)
45 {
46  addKey(keyName, publicKey);
47 }
48 
49 void
51 {
52  setDefaultIdentityInternal(identityName);
54 }
55 
56 void
58 {
61 }
62 
63 void
65 {
68 }
69 
70 Name
72 {
74 }
75 
76 Name
78 {
79  if (m_defaultCertificate == nullptr)
81 
82  if (m_defaultCertificate == nullptr)
83  BOOST_THROW_EXCEPTION(Error("No default certificate is set"));
84 
85  return m_defaultCertificate->getName();
86 }
87 
88 Name
89 SecPublicInfo::getNewKeyName(const Name& identityName, bool useKsk)
90 {
91  std::ostringstream oss;
92 
93  if (useKsk)
94  oss << "ksk-";
95  else
96  oss << "dsk-";
97 
99 
100  Name keyName = Name(identityName).append(oss.str());
101 
102  if (doesPublicKeyExist(keyName))
103  BOOST_THROW_EXCEPTION(Error("Key name already exists: " + keyName.toUri()));
104 
105  return keyName;
106 }
107 
108 void
110 {
111  addCertificate(certificate);
114 }
115 
116 void
118 {
119  addCertificate(certificate);
120  Name certName = certificate.getName();
125 }
126 
127 void
129 {
130  addCertificate(certificate);
131  Name certName = certificate.getName();
137 }
138 
139 shared_ptr<IdentityCertificate>
141 {
142  return getDefaultCertificate();
143 }
144 
145 shared_ptr<IdentityCertificate>
147 {
148  return m_defaultCertificate;
149 }
150 
151 void
153 {
154  try {
157  }
158  catch (SecPublicInfo::Error&) {
159  m_defaultCertificate.reset();
160  }
161 }
162 
163 } // namespace v1
164 } // namespace security
165 } // namespace ndn
shared_ptr< IdentityCertificate > defaultCertificate()
Get cached default certificate of the default identity.
shared_ptr< IdentityCertificate > m_defaultCertificate
virtual Name getDefaultKeyNameForIdentity(const Name &identityName)=0
Get name of the default key name for the specified identity.
virtual Name getDefaultCertificateNameForKey(const Name &keyName)=0
Get name of the default certificate name for the specified key.
static Name certificateNameToPublicKeyName(const Name &certificateName)
Get the public key name from the full certificate name.
Copyright (c) 2013-2016 Regents of the University of California.
Definition: common.hpp:74
virtual void setDefaultIdentityInternal(const Name &identityName)=0
Set the default identity.
Name getDefaultCertificateName()
Get the default certificate name of the default identity.
virtual ~SecPublicInfo()
The virtual Destructor.
std::string getPibLocator()
Get PIB Locator.
virtual void addCertificate(const IdentityCertificate &certificate)=0
Add a certificate to the identity storage.
static time_point now() noexcept
Definition: time.cpp:45
virtual Name getDefaultIdentity()=0
Get name of the default identity.
void addCertificateAsSystemDefault(const IdentityCertificate &certificate)
Add a certificate into the public key identity storage and set the certificate as the default one of ...
const Name & getName() const
Get name of the Data packet.
Definition: data.hpp:318
void setDefaultCertificateNameForKey(const Name &certificateName)
Set the default certificate name for the corresponding key.
virtual bool doesPublicKeyExist(const Name &keyName)=0
Check if the specified key already exists.
std::string toUri() const
Encode this name as a URI.
Definition: name.cpp:171
void setDefaultIdentity(const Name &identityName)
Set the default identity.
virtual shared_ptr< IdentityCertificate > getCertificate(const Name &certificateName)=0
Get a shared pointer to identity certificate object from the identity storage.
void refreshDefaultCertificate()
try to get the default certificate of the default identity from the public info
Name getDefaultCertificateNameForIdentity(const Name &identityName)
Get the default certificate name for the specified identity.
SecPublicInfo(const std::string &location)
virtual std::string getScheme()=0
return the scheme of the PibLocator
void addPublicKey(const Name &keyName, KeyType keyType, const PublicKey &publicKey)
Add a public key to the identity storage.
virtual void addKey(const Name &keyName, const PublicKey &publicKey)=0
Add a public key to the identity storage.
Name abstraction to represent an absolute name.
Definition: name.hpp:46
virtual void setDefaultKeyNameForIdentityInternal(const Name &keyName)=0
Set the default key name for the corresponding identity.
void addCertificateAsKeyDefault(const IdentityCertificate &certificate)
Add a certificate and set the certificate as the default one of its corresponding key...
void addCertificateAsIdentityDefault(const IdentityCertificate &certificate)
Add a certificate into the public key identity storage and set the certificate as the default one of ...
milliseconds toUnixTimestamp(const system_clock::TimePoint &point)
Convert system_clock::TimePoint to UNIX timestamp.
Definition: time.cpp:118
virtual void setDefaultCertificateNameForKeyInternal(const Name &certificateName)=0
Set the default certificate name for the corresponding key.
shared_ptr< IdentityCertificate > getDefaultCertificate()
Get cached default certificate of the default identity.
PartialName getPrefix(ssize_t nComponents) const
Extract a prefix (PartialName) of the name, containing first nComponents components.
Definition: name.hpp:241
Name getNewKeyName(const Name &identityName, bool useKsk)
Generate a key name for the identity.
void setDefaultKeyNameForIdentity(const Name &keyName)
Set the default key name for the corresponding identity.