Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 8 | #include "common.hpp" |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 9 | |
Alexander Afanasyev | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 10 | #include "sec-public-info-memory.hpp" |
| 11 | #include "identity-certificate.hpp" |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 12 | |
| 13 | using namespace std; |
| 14 | |
| 15 | namespace ndn { |
| 16 | |
| 17 | SecPublicInfoMemory::~SecPublicInfoMemory() |
| 18 | { |
| 19 | } |
| 20 | |
| 21 | bool |
| 22 | SecPublicInfoMemory::doesIdentityExist(const Name& identityName) |
| 23 | { |
| 24 | string identityUri = identityName.toUri(); |
| 25 | return find(identityStore_.begin(), identityStore_.end(), identityUri) != identityStore_.end(); |
| 26 | } |
| 27 | |
| 28 | void |
| 29 | SecPublicInfoMemory::addIdentity(const Name& identityName) |
| 30 | { |
| 31 | string identityUri = identityName.toUri(); |
| 32 | if (find(identityStore_.begin(), identityStore_.end(), identityUri) != identityStore_.end()) |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 33 | return; |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 34 | |
| 35 | identityStore_.push_back(identityUri); |
| 36 | } |
| 37 | |
| 38 | bool |
| 39 | SecPublicInfoMemory::revokeIdentity() |
| 40 | { |
| 41 | #if 1 |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 42 | throw Error("SecPublicInfoMemory::revokeIdentity not implemented"); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 43 | #endif |
| 44 | } |
| 45 | |
| 46 | bool |
| 47 | SecPublicInfoMemory::doesPublicKeyExist(const Name& keyName) |
| 48 | { |
| 49 | return keyStore_.find(keyName.toUri()) != keyStore_.end(); |
| 50 | } |
| 51 | |
| 52 | void |
| 53 | SecPublicInfoMemory::addPublicKey(const Name& keyName, KeyType keyType, const PublicKey& publicKey) |
| 54 | { |
| 55 | Name identityName = keyName.getSubName(0, keyName.size() - 1); |
| 56 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 57 | addIdentity(identityName); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 58 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 59 | keyStore_[keyName.toUri()] = make_shared<KeyRecord>(keyType, publicKey); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 60 | } |
| 61 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 62 | shared_ptr<PublicKey> |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 63 | SecPublicInfoMemory::getPublicKey(const Name& keyName) |
| 64 | { |
| 65 | KeyStore::iterator record = keyStore_.find(keyName.toUri()); |
| 66 | if (record == keyStore_.end()) |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 67 | throw Error("SecPublicInfoMemory::getPublicKey " + keyName.toUri()); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 68 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 69 | return make_shared<PublicKey> (record->second->getKey()); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | bool |
| 73 | SecPublicInfoMemory::doesCertificateExist(const Name& certificateName) |
| 74 | { |
| 75 | return certificateStore_.find(certificateName.toUri()) != certificateStore_.end(); |
| 76 | } |
| 77 | |
| 78 | void |
| 79 | SecPublicInfoMemory::addCertificate(const IdentityCertificate& certificate) |
| 80 | { |
| 81 | const Name& certificateName = certificate.getName(); |
| 82 | const Name& keyName = certificate.getPublicKeyName(); |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 83 | const Name& identity = keyName.getPrefix(-1); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 84 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 85 | addIdentity(identity); |
| 86 | addPublicKey(keyName, KEY_TYPE_RSA, certificate.getPublicKeyInfo()); |
| 87 | certificateStore_[certificateName.toUri()] = make_shared<IdentityCertificate> (certificate); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 88 | } |
| 89 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 90 | shared_ptr<IdentityCertificate> |
Yingdi Yu | 88663af | 2014-01-15 15:21:38 -0800 | [diff] [blame] | 91 | SecPublicInfoMemory::getCertificate(const Name& certificateName) |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 92 | { |
| 93 | CertificateStore::iterator record = certificateStore_.find(certificateName.toUri()); |
| 94 | if (record == certificateStore_.end()) |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 95 | throw Error("SecPublicInfoMemory::getCertificate " + certificateName.toUri()); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 96 | |
| 97 | return record->second; |
| 98 | } |
| 99 | |
| 100 | Name |
| 101 | SecPublicInfoMemory::getDefaultIdentity() |
| 102 | { |
| 103 | return Name(defaultIdentity_); |
| 104 | } |
| 105 | |
| 106 | void |
| 107 | SecPublicInfoMemory::setDefaultIdentityInternal(const Name& identityName) |
| 108 | { |
| 109 | string identityUri = identityName.toUri(); |
| 110 | if (find(identityStore_.begin(), identityStore_.end(), identityUri) != identityStore_.end()) |
| 111 | defaultIdentity_ = identityUri; |
| 112 | else |
| 113 | // The identity doesn't exist, so clear the default. |
| 114 | defaultIdentity_.clear(); |
| 115 | } |
| 116 | |
| 117 | Name |
| 118 | SecPublicInfoMemory::getDefaultKeyNameForIdentity(const Name& identityName) |
| 119 | { |
| 120 | return defaultKeyName_; |
| 121 | } |
| 122 | |
| 123 | void |
| 124 | SecPublicInfoMemory::setDefaultKeyNameForIdentityInternal(const Name& keyName) |
| 125 | { |
| 126 | defaultKeyName_ = keyName; |
| 127 | } |
| 128 | |
| 129 | Name |
| 130 | SecPublicInfoMemory::getDefaultCertificateNameForKey(const Name& keyName) |
| 131 | { |
| 132 | return defaultCert_; |
| 133 | } |
| 134 | |
| 135 | void |
| 136 | SecPublicInfoMemory::setDefaultCertificateNameForKeyInternal(const Name& certificateName) |
| 137 | { |
| 138 | defaultCert_ = certificateName; |
| 139 | } |
| 140 | |
| 141 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 142 | void |
| 143 | SecPublicInfoMemory::getAllIdentities(std::vector<Name> &nameList, bool isDefault) |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 144 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 145 | throw Error("SecPublicInfoMemory::getAllIdentities not implemented"); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 146 | } |
| 147 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 148 | void |
| 149 | SecPublicInfoMemory::getAllKeyNames(std::vector<Name> &nameList, bool isDefault) |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 150 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 151 | throw Error("SecPublicInfoMemory::getAllKeyNames not implemented"); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 152 | } |
| 153 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 154 | void |
| 155 | SecPublicInfoMemory::getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name> &nameList, bool isDefault) |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 156 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 157 | throw Error("SecPublicInfoMemory::getAllKeyNamesOfIdentity not implemented"); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 158 | } |
| 159 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 160 | void |
| 161 | SecPublicInfoMemory::getAllCertificateNames(std::vector<Name> &nameList, 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::getAllCertificateNames not implemented"); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 164 | } |
| 165 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 166 | void |
| 167 | SecPublicInfoMemory::getAllCertificateNamesOfKey(const Name& keyName, 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::getAllCertificateNamesOfKey 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 |
| 173 | SecPublicInfoMemory::deleteCertificateInfo(const Name &certName) |
| 174 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 175 | throw Error("SecPublicInfoMemory::deleteCertificateInfo not implemented"); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | void |
| 179 | SecPublicInfoMemory::deletePublicKeyInfo(const Name &keyName) |
| 180 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 181 | throw Error("SecPublicInfoMemory::deletePublicKeyInfo not implemented"); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | void |
| 185 | SecPublicInfoMemory::deleteIdentityInfo(const Name &identityName) |
| 186 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 187 | throw Error("SecPublicInfoMemory::deleteIdentityInfo not implemented"); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 188 | } |
| 189 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 190 | } // namespace ndn |