blob: 4cbceac2bf8a1b98f8f8e3d7fccbc399e1ba6514 [file] [log] [blame]
Jeff Thompson6c314bc2013-09-23 18:09:38 -07001/* -*- 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 Yufc40d872014-02-18 12:56:04 -08008#ifndef NDN_SECURITY_SEC_PUBLIC_INFO_MEMORY_HPP
9#define NDN_SECURITY_SEC_PUBLIC_INFO_MEMORY_HPP
Jeff Thompson6c314bc2013-09-23 18:09:38 -070010
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080011#include "../common.hpp"
Yingdi Yu87581582014-01-14 14:28:39 -080012#include "sec-public-info.hpp"
Jeff Thompson6c314bc2013-09-23 18:09:38 -070013
14namespace ndn {
15
16/**
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070017 * @brief SecPublicInfoMemory extends SecPublicInfo and implements its methods to store identity,
18 * public key and certificate objects in memory.
Jeff Thompson6c314bc2013-09-23 18:09:38 -070019 */
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070020class SecPublicInfoMemory : public SecPublicInfo
21{
Jeff Thompson6c314bc2013-09-23 18:09:38 -070022public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070023 class Error : public SecPublicInfo::Error
24 {
25 public:
26 explicit
27 Error(const std::string& what)
28 : SecPublicInfo::Error(what)
29 {
30 }
31 };
Alexander Afanasyeve64788e2014-01-05 22:38:21 -080032
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080033 virtual
Yingdi Yu87581582014-01-14 14:28:39 -080034 ~SecPublicInfoMemory();
Jeff Thompson6c314bc2013-09-23 18:09:38 -070035
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080036 virtual bool
Jeff Thompson6c314bc2013-09-23 18:09:38 -070037 doesIdentityExist(const Name& identityName);
38
Jeff Thompson6c314bc2013-09-23 18:09:38 -070039 virtual void
40 addIdentity(const Name& identityName);
41
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080042 virtual bool
Jeff Thompson6c314bc2013-09-23 18:09:38 -070043 revokeIdentity();
44
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070045 virtual bool
Yingdi Yu87581582014-01-14 14:28:39 -080046 doesPublicKeyExist(const Name& keyName);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070047
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070048 virtual void
Yingdi Yu87581582014-01-14 14:28:39 -080049 addPublicKey(const Name& keyName, KeyType keyType, const PublicKey& publicKeyDer);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070050
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070051 virtual shared_ptr<PublicKey>
Yingdi Yu87581582014-01-14 14:28:39 -080052 getPublicKey(const Name& keyName);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070053
Jeff Thompson6c314bc2013-09-23 18:09:38 -070054 virtual bool
55 doesCertificateExist(const Name& certificateName);
56
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070057 virtual void
Jeff Thompsonc69163b2013-10-12 13:49:50 -070058 addCertificate(const IdentityCertificate& certificate);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070059
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070060 virtual shared_ptr<IdentityCertificate>
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070061 getCertificate(const Name& certificateName);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070062
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070063 virtual Name
Jeff Thompson6c314bc2013-09-23 18:09:38 -070064 getDefaultIdentity();
65
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070066 virtual Name
Jeff Thompson6c314bc2013-09-23 18:09:38 -070067 getDefaultKeyNameForIdentity(const Name& identityName);
68
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070069 virtual Name
Jeff Thompson6c314bc2013-09-23 18:09:38 -070070 getDefaultCertificateNameForKey(const Name& keyName);
71
Yingdi Yu28fd32f2014-01-28 19:03:03 -080072 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070073 getAllIdentities(std::vector<Name>& nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -080074
Yingdi Yu28fd32f2014-01-28 19:03:03 -080075 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070076 getAllKeyNames(std::vector<Name>& nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -080077
Yingdi Yu28fd32f2014-01-28 19:03:03 -080078 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070079 getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name>& nameList, bool isDefault);
Alexander Afanasyev0c632112013-12-30 15:59:31 -080080
Yingdi Yu28fd32f2014-01-28 19:03:03 -080081 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070082 getAllCertificateNames(std::vector<Name>& nameList, bool isDefault);
83
84 virtual void
85 getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name>& nameList, bool isDefault);
Yingdi Yu87581582014-01-14 14:28:39 -080086
87protected:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070088 virtual void
Yingdi Yu87581582014-01-14 14:28:39 -080089 setDefaultIdentityInternal(const Name& identityName);
90
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070091 virtual void
Yingdi Yu87581582014-01-14 14:28:39 -080092 setDefaultKeyNameForIdentityInternal(const Name& keyName);
93
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070094 virtual void
95 setDefaultCertificateNameForKeyInternal(const Name& certificateName);
Yingdi Yu87581582014-01-14 14:28:39 -080096
Yingdi Yu28fd32f2014-01-28 19:03:03 -080097 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070098 deleteCertificateInfo(const Name& certificateName);
Yingdi Yu28fd32f2014-01-28 19:03:03 -080099
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800100 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700101 deletePublicKeyInfo(const Name& keyName);
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800102
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800103 virtual void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700104 deleteIdentityInfo(const Name& identity);
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800105
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700106
Jeff Thompson81842272013-09-25 16:12:33 -0700107private:
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -0700108 class KeyRecord
109 {
Jeff Thompson61805e92013-10-23 15:19:39 -0700110 public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700111 KeyRecord(KeyType keyType, const PublicKey& key)
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700112 : m_keyType(keyType), m_key(key)
Jeff Thompson61805e92013-10-23 15:19:39 -0700113 {
114 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700115
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700116 const KeyType
117 getKeyType() const
118 {
119 return m_keyType;
120 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700121
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700122 const PublicKey&
123 getKey()
124 {
125 return m_key;
126 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700127
Jeff Thompson61805e92013-10-23 15:19:39 -0700128 private:
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700129 KeyType m_keyType;
130 PublicKey m_key;
Jeff Thompson61805e92013-10-23 15:19:39 -0700131 };
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700132
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700133 std::vector<std::string> m_identityStore; // A list of name URI.
134 std::string m_defaultIdentity; // The default identity in m_identityStore, or "" if not defined.
135 Name m_defaultKeyName;
136 Name m_defaultCert;
Alexander Afanasyeve64788e2014-01-05 22:38:21 -0800137
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700138 // The map key is the keyName.toUri()
139 typedef std::map<std::string, shared_ptr<KeyRecord> > KeyStore;
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700140
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700141 // The map key is the certificateName.toUri()
142 typedef std::map<std::string, shared_ptr<IdentityCertificate> > CertificateStore;
143
144 KeyStore m_keyStore;
145 CertificateStore m_certificateStore;
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700146};
147
Yingdi Yufc40d872014-02-18 12:56:04 -0800148} // namespace ndn
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700149
Yingdi Yufc40d872014-02-18 12:56:04 -0800150#endif //NDN_SECURITY_SEC_PUBLIC_INFO_MEMORY_HPP