Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2013-2014, Regents of the University of California. |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 7 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 8 | * |
| 9 | * This file licensed under New BSD License. See COPYING for detailed information about |
| 10 | * ndn-cxx library copyright, permissions, and redistribution restrictions. |
| 11 | * |
| 12 | * @author Jeff Thompson <jefft0@remap.ucla.edu> |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 13 | */ |
| 14 | |
Alexander Afanasyev | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 15 | #include "common.hpp" |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 16 | |
Alexander Afanasyev | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 17 | #include "sec-public-info-memory.hpp" |
| 18 | #include "identity-certificate.hpp" |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 19 | |
| 20 | using namespace std; |
| 21 | |
| 22 | namespace ndn { |
| 23 | |
| 24 | SecPublicInfoMemory::~SecPublicInfoMemory() |
| 25 | { |
| 26 | } |
| 27 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 28 | bool |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 29 | SecPublicInfoMemory::doesIdentityExist(const Name& identityName) |
| 30 | { |
| 31 | string identityUri = identityName.toUri(); |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 32 | return find(m_identityStore.begin(), m_identityStore.end(), identityUri) != m_identityStore.end(); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | void |
| 36 | SecPublicInfoMemory::addIdentity(const Name& identityName) |
| 37 | { |
| 38 | string identityUri = identityName.toUri(); |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 39 | if (find(m_identityStore.begin(), m_identityStore.end(), identityUri) != m_identityStore.end()) |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 40 | return; |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 41 | |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 42 | m_identityStore.push_back(identityUri); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 43 | } |
| 44 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 45 | bool |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 46 | SecPublicInfoMemory::revokeIdentity() |
| 47 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 48 | throw Error("SecPublicInfoMemory::revokeIdentity not implemented"); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 49 | } |
| 50 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 51 | bool |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 52 | SecPublicInfoMemory::doesPublicKeyExist(const Name& keyName) |
| 53 | { |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 54 | return m_keyStore.find(keyName.toUri()) != m_keyStore.end(); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 55 | } |
| 56 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 57 | void |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 58 | SecPublicInfoMemory::addPublicKey(const Name& keyName, KeyType keyType, const PublicKey& publicKey) |
| 59 | { |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 60 | Name identityName = keyName.getPrefix(-1); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 61 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 62 | addIdentity(identityName); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 63 | |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 64 | m_keyStore[keyName.toUri()] = make_shared<KeyRecord>(keyType, boost::cref(publicKey)); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 65 | } |
| 66 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 67 | shared_ptr<PublicKey> |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 68 | SecPublicInfoMemory::getPublicKey(const Name& keyName) |
| 69 | { |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 70 | KeyStore::iterator record = m_keyStore.find(keyName.toUri()); |
| 71 | if (record == m_keyStore.end()) |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 72 | throw Error("SecPublicInfoMemory::getPublicKey " + keyName.toUri()); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 73 | |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 74 | return make_shared<PublicKey>(record->second->getKey()); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | bool |
| 78 | SecPublicInfoMemory::doesCertificateExist(const Name& certificateName) |
| 79 | { |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 80 | return m_certificateStore.find(certificateName.toUri()) != m_certificateStore.end(); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 83 | void |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 84 | SecPublicInfoMemory::addCertificate(const IdentityCertificate& certificate) |
| 85 | { |
| 86 | const Name& certificateName = certificate.getName(); |
| 87 | const Name& keyName = certificate.getPublicKeyName(); |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 88 | const Name& identity = keyName.getPrefix(-1); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 89 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 90 | addIdentity(identity); |
| 91 | addPublicKey(keyName, KEY_TYPE_RSA, certificate.getPublicKeyInfo()); |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 92 | m_certificateStore[certificateName.toUri()] = make_shared<IdentityCertificate>(certificate); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 93 | } |
| 94 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 95 | shared_ptr<IdentityCertificate> |
Yingdi Yu | 88663af | 2014-01-15 15:21:38 -0800 | [diff] [blame] | 96 | SecPublicInfoMemory::getCertificate(const Name& certificateName) |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 97 | { |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 98 | CertificateStore::iterator record = m_certificateStore.find(certificateName.toUri()); |
| 99 | if (record == m_certificateStore.end()) |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 100 | throw Error("SecPublicInfoMemory::getCertificate " + certificateName.toUri()); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 101 | |
| 102 | return record->second; |
| 103 | } |
| 104 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 105 | Name |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 106 | SecPublicInfoMemory::getDefaultIdentity() |
| 107 | { |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 108 | return Name(m_defaultIdentity); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 109 | } |
| 110 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 111 | void |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 112 | SecPublicInfoMemory::setDefaultIdentityInternal(const Name& identityName) |
| 113 | { |
| 114 | string identityUri = identityName.toUri(); |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 115 | if (find(m_identityStore.begin(), m_identityStore.end(), identityUri) != m_identityStore.end()) |
| 116 | m_defaultIdentity = identityUri; |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 117 | else |
| 118 | // The identity doesn't exist, so clear the default. |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 119 | m_defaultIdentity.clear(); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 120 | } |
| 121 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 122 | Name |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 123 | SecPublicInfoMemory::getDefaultKeyNameForIdentity(const Name& identityName) |
| 124 | { |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 125 | return m_defaultKeyName; |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 126 | } |
| 127 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 128 | void |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 129 | SecPublicInfoMemory::setDefaultKeyNameForIdentityInternal(const Name& keyName) |
| 130 | { |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 131 | m_defaultKeyName = keyName; |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 132 | } |
| 133 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 134 | Name |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 135 | SecPublicInfoMemory::getDefaultCertificateNameForKey(const Name& keyName) |
| 136 | { |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 137 | return m_defaultCert; |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 138 | } |
| 139 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 140 | void |
| 141 | SecPublicInfoMemory::setDefaultCertificateNameForKeyInternal(const Name& certificateName) |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 142 | { |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 143 | m_defaultCert = certificateName; |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 144 | } |
| 145 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 146 | void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 147 | SecPublicInfoMemory::getAllIdentities(std::vector<Name>& nameList, bool isDefault) |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 148 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 149 | throw Error("SecPublicInfoMemory::getAllIdentities not implemented"); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 150 | } |
| 151 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 152 | void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 153 | SecPublicInfoMemory::getAllKeyNames(std::vector<Name>& nameList, bool isDefault) |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 154 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 155 | throw Error("SecPublicInfoMemory::getAllKeyNames not implemented"); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 156 | } |
| 157 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 158 | void |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 159 | SecPublicInfoMemory::getAllKeyNamesOfIdentity(const Name& identity, |
| 160 | std::vector<Name>& nameList, |
| 161 | bool isDefault) |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 162 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 163 | throw Error("SecPublicInfoMemory::getAllKeyNamesOfIdentity not implemented"); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 164 | } |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 165 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 166 | void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 167 | SecPublicInfoMemory::getAllCertificateNames(std::vector<Name>& nameList, bool isDefault) |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 168 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 169 | throw Error("SecPublicInfoMemory::getAllCertificateNames not implemented"); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 170 | } |
| 171 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 172 | void |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 173 | SecPublicInfoMemory::getAllCertificateNamesOfKey(const Name& keyName, |
| 174 | std::vector<Name>& nameList, |
| 175 | bool isDefault) |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 176 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 177 | throw Error("SecPublicInfoMemory::getAllCertificateNamesOfKey not implemented"); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 178 | } |
| 179 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 180 | void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 181 | SecPublicInfoMemory::deleteCertificateInfo(const Name& certName) |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 182 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 183 | throw Error("SecPublicInfoMemory::deleteCertificateInfo not implemented"); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 187 | SecPublicInfoMemory::deletePublicKeyInfo(const Name& keyName) |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 188 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 189 | throw Error("SecPublicInfoMemory::deletePublicKeyInfo not implemented"); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 193 | SecPublicInfoMemory::deleteIdentityInfo(const Name& identityName) |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 194 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 195 | throw Error("SecPublicInfoMemory::deleteIdentityInfo not implemented"); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 196 | } |
| 197 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 198 | } // namespace ndn |