Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [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 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 8 | #ifndef NDN_SECURITY_SEC_PUBLIC_INFO_MEMORY_HPP |
| 9 | #define NDN_SECURITY_SEC_PUBLIC_INFO_MEMORY_HPP |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 10 | |
Alexander Afanasyev | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 11 | #include "../common.hpp" |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 12 | #include "sec-public-info.hpp" |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 13 | |
| 14 | namespace ndn { |
| 15 | |
| 16 | /** |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 17 | * @brief SecPublicInfoMemory extends SecPublicInfo and implements its methods to store identity, public key and certificate objects in memory. |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 18 | */ |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 19 | class SecPublicInfoMemory : public SecPublicInfo { |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 20 | public: |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 21 | class Error : public SecPublicInfo::Error |
| 22 | { |
| 23 | public: |
| 24 | explicit |
| 25 | Error(const std::string& what) |
| 26 | : SecPublicInfo::Error(what) |
| 27 | { |
| 28 | } |
| 29 | }; |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 30 | |
Alexander Afanasyev | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 31 | virtual |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 32 | ~SecPublicInfoMemory(); |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 33 | |
Alexander Afanasyev | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 34 | virtual bool |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 35 | doesIdentityExist(const Name& identityName); |
| 36 | |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 37 | virtual void |
| 38 | addIdentity(const Name& identityName); |
| 39 | |
Alexander Afanasyev | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 40 | virtual bool |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 41 | revokeIdentity(); |
| 42 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 43 | virtual bool |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 44 | doesPublicKeyExist(const Name& keyName); |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 45 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 46 | virtual void |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 47 | addPublicKey(const Name& keyName, KeyType keyType, const PublicKey& publicKeyDer); |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 48 | |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 49 | virtual ptr_lib::shared_ptr<PublicKey> |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 50 | getPublicKey(const Name& keyName); |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 51 | |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 52 | virtual bool |
| 53 | doesCertificateExist(const Name& certificateName); |
| 54 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 55 | virtual void |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 56 | addCertificate(const IdentityCertificate& certificate); |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 57 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 58 | virtual ptr_lib::shared_ptr<IdentityCertificate> |
| 59 | getCertificate(const Name& certificateName); |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 60 | |
| 61 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 62 | virtual Name |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 63 | getDefaultIdentity(); |
| 64 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 65 | virtual Name |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 66 | getDefaultKeyNameForIdentity(const Name& identityName); |
| 67 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 68 | virtual Name |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 69 | getDefaultCertificateNameForKey(const Name& keyName); |
| 70 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 71 | virtual void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 72 | getAllIdentities(std::vector<Name>& nameList, bool isDefault); |
Alexander Afanasyev | 0c63211 | 2013-12-30 15:59:31 -0800 | [diff] [blame] | 73 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 74 | virtual void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 75 | getAllKeyNames(std::vector<Name>& nameList, bool isDefault); |
Alexander Afanasyev | 0c63211 | 2013-12-30 15:59:31 -0800 | [diff] [blame] | 76 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 77 | virtual void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 78 | getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name>& nameList, bool isDefault); |
Alexander Afanasyev | 0c63211 | 2013-12-30 15:59:31 -0800 | [diff] [blame] | 79 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 80 | virtual void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 81 | getAllCertificateNames(std::vector<Name>& nameList, bool isDefault); |
| 82 | |
| 83 | virtual void |
| 84 | getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name>& nameList, bool isDefault); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 85 | |
| 86 | protected: |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 87 | virtual void |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 88 | setDefaultIdentityInternal(const Name& identityName); |
| 89 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 90 | virtual void |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 91 | setDefaultKeyNameForIdentityInternal(const Name& keyName); |
| 92 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 93 | virtual void |
| 94 | setDefaultCertificateNameForKeyInternal(const Name& certificateName); |
Yingdi Yu | 8758158 | 2014-01-14 14:28:39 -0800 | [diff] [blame] | 95 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 96 | virtual void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 97 | deleteCertificateInfo(const Name& certificateName); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 98 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 99 | virtual void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 100 | deletePublicKeyInfo(const Name& keyName); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 101 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 102 | virtual void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 103 | deleteIdentityInfo(const Name& identity); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 104 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 105 | |
Jeff Thompson | 8184227 | 2013-09-25 16:12:33 -0700 | [diff] [blame] | 106 | private: |
Jeff Thompson | 61805e9 | 2013-10-23 15:19:39 -0700 | [diff] [blame] | 107 | class KeyRecord { |
| 108 | public: |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 109 | KeyRecord(KeyType keyType, const PublicKey& key) |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 110 | : keyType_(keyType), key_(key) |
Jeff Thompson | 61805e9 | 2013-10-23 15:19:39 -0700 | [diff] [blame] | 111 | { |
| 112 | } |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 113 | |
Jeff Thompson | 61805e9 | 2013-10-23 15:19:39 -0700 | [diff] [blame] | 114 | const KeyType getKeyType() const { return keyType_; } |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 115 | |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 116 | const PublicKey& getKey() { return key_; } |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 117 | |
Jeff Thompson | 61805e9 | 2013-10-23 15:19:39 -0700 | [diff] [blame] | 118 | private: |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 119 | KeyType keyType_; |
| 120 | PublicKey key_; |
Jeff Thompson | 61805e9 | 2013-10-23 15:19:39 -0700 | [diff] [blame] | 121 | }; |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 122 | |
Jeff Thompson | 8184227 | 2013-09-25 16:12:33 -0700 | [diff] [blame] | 123 | std::vector<std::string> identityStore_; /**< A list of name URI. */ |
| 124 | std::string defaultIdentity_; /**< The default identity in identityStore_, or "" if not defined. */ |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 125 | Name defaultKeyName_; |
| 126 | Name defaultCert_; |
| 127 | |
| 128 | typedef std::map< std::string, ptr_lib::shared_ptr<KeyRecord> > KeyStore; /**< The map key is the keyName.toUri() */ |
| 129 | typedef std::map< std::string, ptr_lib::shared_ptr<IdentityCertificate> > CertificateStore; /**< The map key is the certificateName.toUri() */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 130 | |
| 131 | KeyStore keyStore_; |
| 132 | CertificateStore certificateStore_; |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 133 | }; |
| 134 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 135 | } // namespace ndn |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 136 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 137 | #endif //NDN_SECURITY_SEC_PUBLIC_INFO_MEMORY_HPP |