blob: c01e59ba3837cf8c0232bee5985700fca9c2c2ae [file] [log] [blame]
Yingdi Yu87581582014-01-14 14:28:39 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
5 * See COPYING for copyright and distribution information.
6 */
7
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -08008#include "common.hpp"
Yingdi Yu87581582014-01-14 14:28:39 -08009
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080010#include "sec-public-info-memory.hpp"
11#include "identity-certificate.hpp"
Yingdi Yu87581582014-01-14 14:28:39 -080012
13using namespace std;
14
15namespace ndn {
16
17SecPublicInfoMemory::~SecPublicInfoMemory()
18{
19}
20
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070021bool
Yingdi Yu87581582014-01-14 14:28:39 -080022SecPublicInfoMemory::doesIdentityExist(const Name& identityName)
23{
24 string identityUri = identityName.toUri();
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070025 return find(m_identityStore.begin(), m_identityStore.end(), identityUri) != m_identityStore.end();
Yingdi Yu87581582014-01-14 14:28:39 -080026}
27
28void
29SecPublicInfoMemory::addIdentity(const Name& identityName)
30{
31 string identityUri = identityName.toUri();
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070032 if (find(m_identityStore.begin(), m_identityStore.end(), identityUri) != m_identityStore.end())
Yingdi Yu2e57a582014-02-20 23:34:43 -080033 return;
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070034
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070035 m_identityStore.push_back(identityUri);
Yingdi Yu87581582014-01-14 14:28:39 -080036}
37
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070038bool
Yingdi Yu87581582014-01-14 14:28:39 -080039SecPublicInfoMemory::revokeIdentity()
40{
Yingdi Yu2e57a582014-02-20 23:34:43 -080041 throw Error("SecPublicInfoMemory::revokeIdentity not implemented");
Yingdi Yu87581582014-01-14 14:28:39 -080042}
43
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070044bool
Yingdi Yu87581582014-01-14 14:28:39 -080045SecPublicInfoMemory::doesPublicKeyExist(const Name& keyName)
46{
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070047 return m_keyStore.find(keyName.toUri()) != m_keyStore.end();
Yingdi Yu87581582014-01-14 14:28:39 -080048}
49
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070050void
Yingdi Yu87581582014-01-14 14:28:39 -080051SecPublicInfoMemory::addPublicKey(const Name& keyName, KeyType keyType, const PublicKey& publicKey)
52{
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070053 Name identityName = keyName.getPrefix(-1);
Yingdi Yu87581582014-01-14 14:28:39 -080054
Yingdi Yu2e57a582014-02-20 23:34:43 -080055 addIdentity(identityName);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070056
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070057 m_keyStore[keyName.toUri()] = make_shared<KeyRecord>(keyType, boost::cref(publicKey));
Yingdi Yu87581582014-01-14 14:28:39 -080058}
59
Yingdi Yu2e57a582014-02-20 23:34:43 -080060shared_ptr<PublicKey>
Yingdi Yu87581582014-01-14 14:28:39 -080061SecPublicInfoMemory::getPublicKey(const Name& keyName)
62{
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070063 KeyStore::iterator record = m_keyStore.find(keyName.toUri());
64 if (record == m_keyStore.end())
Yingdi Yu2e57a582014-02-20 23:34:43 -080065 throw Error("SecPublicInfoMemory::getPublicKey " + keyName.toUri());
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070066
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070067 return make_shared<PublicKey>(record->second->getKey());
Yingdi Yu87581582014-01-14 14:28:39 -080068}
69
70bool
71SecPublicInfoMemory::doesCertificateExist(const Name& certificateName)
72{
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070073 return m_certificateStore.find(certificateName.toUri()) != m_certificateStore.end();
Yingdi Yu87581582014-01-14 14:28:39 -080074}
75
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070076void
Yingdi Yu87581582014-01-14 14:28:39 -080077SecPublicInfoMemory::addCertificate(const IdentityCertificate& certificate)
78{
79 const Name& certificateName = certificate.getName();
80 const Name& keyName = certificate.getPublicKeyName();
Yingdi Yu2e57a582014-02-20 23:34:43 -080081 const Name& identity = keyName.getPrefix(-1);
Yingdi Yu87581582014-01-14 14:28:39 -080082
Yingdi Yu2e57a582014-02-20 23:34:43 -080083 addIdentity(identity);
84 addPublicKey(keyName, KEY_TYPE_RSA, certificate.getPublicKeyInfo());
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070085 m_certificateStore[certificateName.toUri()] = make_shared<IdentityCertificate>(certificate);
Yingdi Yu87581582014-01-14 14:28:39 -080086}
87
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070088shared_ptr<IdentityCertificate>
Yingdi Yu88663af2014-01-15 15:21:38 -080089SecPublicInfoMemory::getCertificate(const Name& certificateName)
Yingdi Yu87581582014-01-14 14:28:39 -080090{
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070091 CertificateStore::iterator record = m_certificateStore.find(certificateName.toUri());
92 if (record == m_certificateStore.end())
Yingdi Yu2e57a582014-02-20 23:34:43 -080093 throw Error("SecPublicInfoMemory::getCertificate " + certificateName.toUri());
Yingdi Yu87581582014-01-14 14:28:39 -080094
95 return record->second;
96}
97
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070098Name
Yingdi Yu87581582014-01-14 14:28:39 -080099SecPublicInfoMemory::getDefaultIdentity()
100{
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700101 return Name(m_defaultIdentity);
Yingdi Yu87581582014-01-14 14:28:39 -0800102}
103
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700104void
Yingdi Yu87581582014-01-14 14:28:39 -0800105SecPublicInfoMemory::setDefaultIdentityInternal(const Name& identityName)
106{
107 string identityUri = identityName.toUri();
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700108 if (find(m_identityStore.begin(), m_identityStore.end(), identityUri) != m_identityStore.end())
109 m_defaultIdentity = identityUri;
Yingdi Yu87581582014-01-14 14:28:39 -0800110 else
111 // The identity doesn't exist, so clear the default.
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700112 m_defaultIdentity.clear();
Yingdi Yu87581582014-01-14 14:28:39 -0800113}
114
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700115Name
Yingdi Yu87581582014-01-14 14:28:39 -0800116SecPublicInfoMemory::getDefaultKeyNameForIdentity(const Name& identityName)
117{
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700118 return m_defaultKeyName;
Yingdi Yu87581582014-01-14 14:28:39 -0800119}
120
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700121void
Yingdi Yu87581582014-01-14 14:28:39 -0800122SecPublicInfoMemory::setDefaultKeyNameForIdentityInternal(const Name& keyName)
123{
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700124 m_defaultKeyName = keyName;
Yingdi Yu87581582014-01-14 14:28:39 -0800125}
126
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700127Name
Yingdi Yu87581582014-01-14 14:28:39 -0800128SecPublicInfoMemory::getDefaultCertificateNameForKey(const Name& keyName)
129{
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700130 return m_defaultCert;
Yingdi Yu87581582014-01-14 14:28:39 -0800131}
132
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700133void
134SecPublicInfoMemory::setDefaultCertificateNameForKeyInternal(const Name& certificateName)
Yingdi Yu87581582014-01-14 14:28:39 -0800135{
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700136 m_defaultCert = certificateName;
Yingdi Yu87581582014-01-14 14:28:39 -0800137}
138
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800139void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700140SecPublicInfoMemory::getAllIdentities(std::vector<Name>& nameList, bool isDefault)
Yingdi Yu87581582014-01-14 14:28:39 -0800141{
Yingdi Yu2e57a582014-02-20 23:34:43 -0800142 throw Error("SecPublicInfoMemory::getAllIdentities not implemented");
Yingdi Yu87581582014-01-14 14:28:39 -0800143}
144
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800145void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700146SecPublicInfoMemory::getAllKeyNames(std::vector<Name>& nameList, bool isDefault)
Yingdi Yu87581582014-01-14 14:28:39 -0800147{
Yingdi Yu2e57a582014-02-20 23:34:43 -0800148 throw Error("SecPublicInfoMemory::getAllKeyNames not implemented");
Yingdi Yu87581582014-01-14 14:28:39 -0800149}
150
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800151void
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700152SecPublicInfoMemory::getAllKeyNamesOfIdentity(const Name& identity,
153 std::vector<Name>& nameList,
154 bool isDefault)
Yingdi Yu87581582014-01-14 14:28:39 -0800155{
Yingdi Yu2e57a582014-02-20 23:34:43 -0800156 throw Error("SecPublicInfoMemory::getAllKeyNamesOfIdentity not implemented");
Yingdi Yu87581582014-01-14 14:28:39 -0800157}
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700158
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800159void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700160SecPublicInfoMemory::getAllCertificateNames(std::vector<Name>& nameList, bool isDefault)
Yingdi Yu87581582014-01-14 14:28:39 -0800161{
Yingdi Yu2e57a582014-02-20 23:34:43 -0800162 throw Error("SecPublicInfoMemory::getAllCertificateNames not implemented");
Yingdi Yu87581582014-01-14 14:28:39 -0800163}
164
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800165void
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700166SecPublicInfoMemory::getAllCertificateNamesOfKey(const Name& keyName,
167 std::vector<Name>& nameList,
168 bool isDefault)
Yingdi Yu87581582014-01-14 14:28:39 -0800169{
Yingdi Yu2e57a582014-02-20 23:34:43 -0800170 throw Error("SecPublicInfoMemory::getAllCertificateNamesOfKey not implemented");
Yingdi Yu87581582014-01-14 14:28:39 -0800171}
172
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800173void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700174SecPublicInfoMemory::deleteCertificateInfo(const Name& certName)
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800175{
Yingdi Yu2e57a582014-02-20 23:34:43 -0800176 throw Error("SecPublicInfoMemory::deleteCertificateInfo not implemented");
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800177}
178
179void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700180SecPublicInfoMemory::deletePublicKeyInfo(const Name& keyName)
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800181{
Yingdi Yu2e57a582014-02-20 23:34:43 -0800182 throw Error("SecPublicInfoMemory::deletePublicKeyInfo not implemented");
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800183}
184
185void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700186SecPublicInfoMemory::deleteIdentityInfo(const Name& identityName)
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800187{
Yingdi Yu2e57a582014-02-20 23:34:43 -0800188 throw Error("SecPublicInfoMemory::deleteIdentityInfo not implemented");
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800189}
190
Yingdi Yufc40d872014-02-18 12:56:04 -0800191} // namespace ndn