24 #include "../security-common.hpp" 31 : m_hasDefaultIdentity(false)
38 static std::string scheme =
"pib-memory";
45 m_tpmLocator = tpmLocator;
57 return (m_identities.count(identity) > 0);
63 m_identities.insert(identity);
65 if (!m_hasDefaultIdentity) {
66 m_defaultIdentity = identity;
67 m_hasDefaultIdentity =
true;
74 m_identities.erase(identity);
75 if (identity == m_defaultIdentity) {
76 m_hasDefaultIdentity =
false;
77 m_defaultIdentity.
clear();
81 for (
const Name& keyName : keyNames) {
89 m_hasDefaultIdentity =
false;
90 m_defaultIdentity.
clear();
92 m_defaultKeys.clear();
94 m_defaultCerts.clear();
108 m_defaultIdentity = identityName;
109 m_hasDefaultIdentity =
true;
115 if (m_hasDefaultIdentity) {
116 return m_defaultIdentity;
119 BOOST_THROW_EXCEPTION(
Pib::Error(
"No default identity"));
125 return (m_keys.count(keyName) > 0);
130 const uint8_t* key,
size_t keyLen)
134 m_keys[keyName] =
Buffer(key, keyLen);
136 if (m_defaultKeys.count(identity) == 0) {
137 m_defaultKeys[identity] = keyName;
146 m_keys.erase(keyName);
147 m_defaultKeys.erase(identity);
150 for (
const auto& certName : certNames) {
159 BOOST_THROW_EXCEPTION(
Pib::Error(
"Key `" + keyName.
toUri() +
"` not found"));
162 auto key = m_keys.find(keyName);
163 BOOST_ASSERT(key != m_keys.end());
171 for (
const auto& key : m_keys) {
173 ids.insert(key.first);
183 BOOST_THROW_EXCEPTION(
Pib::Error(
"Key `" + keyName.
toUri() +
"` not found"));
186 m_defaultKeys[identity] = keyName;
192 auto defaultKey = m_defaultKeys.find(identity);
193 if (defaultKey == m_defaultKeys.end()) {
194 BOOST_THROW_EXCEPTION(
Pib::Error(
"No default key for identity `" + identity.
toUri() +
"`"));
197 return defaultKey->second;
203 return (m_certs.count(certName) > 0);
215 m_certs[certName] = certificate;
216 if (m_defaultCerts.count(keyName) == 0) {
217 m_defaultCerts[keyName] = certName;
224 m_certs.erase(certName);
226 if (defaultCert != m_defaultCerts.end() && defaultCert->second == certName) {
227 m_defaultCerts.erase(defaultCert);
235 BOOST_THROW_EXCEPTION(
Pib::Error(
"Certificate `" + certName.
toUri() +
"` does not exist"));
238 auto it = m_certs.find(certName);
245 std::set<Name> certNames;
246 for (
const auto& it : m_certs) {
248 certNames.insert(it.first);
258 BOOST_THROW_EXCEPTION(
Pib::Error(
"Certificate `" + certName.
toUri() +
"` does not exist"));
261 m_defaultCerts[keyName] = certName;
267 auto it = m_defaultCerts.find(keyName);
268 if (it == m_defaultCerts.end()) {
269 BOOST_THROW_EXCEPTION(
Pib::Error(
"No default certificate for key `" + keyName.
toUri() +
"`"));
272 auto certIt = m_certs.find(it->second);
273 BOOST_ASSERT(certIt != m_certs.end());
274 return certIt->second;
bool hasIdentity(const Name &identity) const override
Check the existence of an identity.
Copyright (c) 2013-2017 Regents of the University of California.
The certificate following the certificate format naming convention.
represents a semantic error
Name getDefaultKeyOfIdentity(const Name &identity) const override
Name getKeyName() const
Get key name.
void clearIdentities() override
Erasing all certificates, keys, and identities.
static const std::string & getScheme()
void removeKey(const Name &keyName) override
Remove a key with keyName and related certificates.
void removeIdentity(const Name &identity) override
Remove an identity and related keys and certificates.
void addCertificate(const v2::Certificate &certificate) override
Add a certificate.
std::string getTpmLocator() const override
Get TPM Locator.
Name extractKeyNameFromCertName(const Name &certName)
Extract key name from the certificate name certName.
void setDefaultCertificateOfKey(const Name &keyName, const Name &certName) override
Set a cert with name certName as the default of a key with keyName.
std::set< Name > getIdentities() const override
Get the name of all the identities.
bool hasKey(const Name &keyName) const override
Check the existence of a key with keyName.
PibMemory(const std::string &location="")
Create memory based PIB backend.
void setTpmLocator(const std::string &tpmLocator) override
Set the corresponding TPM information to tpmLocator.
std::string toUri() const
Get URI representation of the name.
void setDefaultKeyOfIdentity(const Name &identity, const Name &keyName) override
Set an key with keyName as the default key of an identity with name identity.
void removeCertificate(const Name &certName) override
Remove a certificate with name certName.
Name getDefaultIdentity() const override
Get the default identity.
void addKey(const Name &identity, const Name &keyName, const uint8_t *key, size_t keyLen) override
Add a key.
Name getIdentity() const
Get identity name.
Represents an absolute name.
size_t value_size() const
Get size of TLV-VALUE aka TLV-LENGTH.
const Name & getName() const
Get name.
v2::Certificate getCertificate(const Name &certName) const override
Get a certificate with name certName.
void setDefaultIdentity(const Name &identityName) override
Set an identity with name identityName as the default identity.
const Block & getContent() const
Get Content.
bool hasCertificate(const Name &certName) const override
Check the existence of a certificate with name certName.
void addIdentity(const Name &identity) override
Add an identity.
const uint8_t * value() const
Get pointer to TLV-VALUE.
v2::Certificate getDefaultCertificateOfKey(const Name &keyName) const override
Buffer getKeyBits(const Name &keyName) const override
Get the key bits of a key with name keyName.
Name extractIdentityFromKeyName(const Name &keyName)
Extract identity namespace from the key name keyName.
General-purpose automatically managed/resized buffer.
void clear()
Remove all components.
std::set< Name > getKeysOfIdentity(const Name &identity) const override
Get all the key names of an identity with name identity.
std::set< Name > getCertificatesOfKey(const Name &keyName) const override
Get a list of certificate names of a key with id keyName.