blob: 9b7dd5ffe907be042a1d5ae1a105bfe7087a700a [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
8#ifndef NDN_MEMORY_IDENTITY_STORAGE_HPP
Jeff Thompsone589c3f2013-10-12 17:30:50 -07009#define NDN_MEMORY_IDENTITY_STORAGE_HPP
Jeff Thompson6c314bc2013-09-23 18:09:38 -070010
Jeff Thompson81842272013-09-25 16:12:33 -070011#include <vector>
Jeff Thompson6c314bc2013-09-23 18:09:38 -070012#include "identity-storage.hpp"
13
14namespace ndn {
15
16/**
17 * MemoryIdentityStorage extends IdentityStorage and implements its methods to store identity, public key and certificate objects in memory.
18 * The application must get the objects through its own means and add the objects to the MemoryIdentityStorage object.
19 * To use permanent file-based storage, see BasicIdentityStorage.
20 */
21class MemoryIdentityStorage : public IdentityStorage {
22public:
23 /**
24 * The virtual Destructor.
25 */
26 virtual
27 ~MemoryIdentityStorage();
28
29 /**
30 * Check if the specified identity already exists.
31 * @param identityName The identity name.
32 * @return true if the identity exists, otherwise false.
33 */
34 virtual bool
35 doesIdentityExist(const Name& identityName);
36
37 /**
38 * Add a new identity. An exception will be thrown if the identity already exists.
39 * @param identityName The identity name to be added.
40 */
41 virtual void
42 addIdentity(const Name& identityName);
43
44 /**
45 * Revoke the identity.
46 * @return true if the identity was revoked, false if not.
47 */
48 virtual bool
49 revokeIdentity();
50
51 /**
52 * Generate a name for a new key belonging to the identity.
53 * @param identityName The identity name.
54 * @param useKsk If true, generate a KSK name, otherwise a DSK name.
55 * @return The generated key name.
56 */
57 virtual Name
58 getNewKeyName(const Name& identityName, bool useKsk);
59
60 /**
61 * Check if the specified key already exists.
62 * @param keyName The name of the key.
63 * @return true if the key exists, otherwise false.
64 */
65 virtual bool
66 doesKeyExist(const Name& keyName);
67
68 /**
69 * Extract the key name from the certificate name.
70 * @param certificateName The certificate name to be processed.
71 */
72 virtual Name
73 getKeyNameForCertificate(const Name& certificateName);
74
75 /**
76 * Add a public key to the identity storage.
77 * @param keyName The name of the public key to be added.
78 * @param keyType Type of the public key to be added.
79 * @param publicKeyDer A blob of the public key DER to be added.
80 */
81 virtual void
Jeff Thompsonbd04b072013-09-27 15:14:09 -070082 addKey(const Name& keyName, KeyType keyType, const Blob& publicKeyDer);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070083
84 /**
85 * Get the public key DER blob from the identity storage.
86 * @param keyName The name of the requested public key.
Jeff Thompsonabcea7d2013-10-02 15:03:21 -070087 * @return The DER Blob. If not found, return a Blob with a null pointer.
Jeff Thompson6c314bc2013-09-23 18:09:38 -070088 */
89 virtual Blob
90 getKey(const Name& keyName);
91
92 /**
93 * Activate a key. If a key is marked as inactive, its private part will not be used in packet signing.
94 * @param keyName name of the key
95 */
96 virtual void
97 activateKey(const Name& keyName);
98
99 /**
100 * Deactivate a key. If a key is marked as inactive, its private part will not be used in packet signing.
101 * @param keyName name of the key
102 */
103 virtual void
104 deactivateKey(const Name& keyName);
105
106 /**
107 * Check if the specified certificate already exists.
108 * @param certificateName The name of the certificate.
109 * @return true if the certificate exists, otherwise false.
110 */
111 virtual bool
112 doesCertificateExist(const Name& certificateName);
113
114 /**
115 * Add a certificate to the identity storage.
Jeff Thompsonc69163b2013-10-12 13:49:50 -0700116 * @param certificate The certificate to be added. This makes a copy of the certificate.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700117 */
118 virtual void
Jeff Thompsonc69163b2013-10-12 13:49:50 -0700119 addCertificate(const IdentityCertificate& certificate);
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700120
121 /**
122 * Get a certificate from the identity storage.
123 * @param certificateName The name of the requested certificate.
124 * @param allowAny If false, only a valid certificate will be returned, otherwise validity is disregarded.
Jeff Thompsonabcea7d2013-10-02 15:03:21 -0700125 * @return The requested certificate. If not found, return a shared_ptr with a null pointer.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700126 */
Jeff Thompsona6fd6382013-09-24 15:23:37 -0700127 virtual ptr_lib::shared_ptr<Certificate>
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700128 getCertificate(const Name &certificateName, bool allowAny = false);
129
130
131 /*****************************************
132 * Get/Set Default *
133 *****************************************/
134
135 /**
136 * Get the default identity.
Jeff Thompson81842272013-09-25 16:12:33 -0700137 * @param return The name of default identity, or an empty name if there is no default.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700138 */
139 virtual Name
140 getDefaultIdentity();
141
142 /**
143 * Get the default key name for the specified identity.
144 * @param identityName The identity name.
145 * @return The default key name.
146 */
147 virtual Name
148 getDefaultKeyNameForIdentity(const Name& identityName);
149
150 /**
151 * Get the default certificate name for the specified key.
152 * @param keyName The key name.
153 * @return The default certificate name.
154 */
155 virtual Name
156 getDefaultCertificateNameForKey(const Name& keyName);
157
158 /**
Jeff Thompson81842272013-09-25 16:12:33 -0700159 * Set the default identity. If the identityName does not exist, then clear the default identity
160 * so that getDefaultIdentity() returns an empty name.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700161 * @param identityName The default identity name.
162 */
163 virtual void
164 setDefaultIdentity(const Name& identityName);
165
166 /**
167 * Set the default key name for the specified identity.
168 * @param keyName The key name.
Jeff Thompsonabcea7d2013-10-02 15:03:21 -0700169 * @param identityNameCheck (optional) The identity name to check the keyName.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700170 */
171 virtual void
Jeff Thompsonabcea7d2013-10-02 15:03:21 -0700172 setDefaultKeyNameForIdentity(const Name& keyName, const Name& identityNameCheck = Name());
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700173
174 /**
175 * Set the default key name for the specified identity.
176 * @param keyName The key name.
177 * @param certificateName The certificate name.
178 */
179 virtual void
180 setDefaultCertificateNameForKey(const Name& keyName, const Name& certificateName);
Jeff Thompson81842272013-09-25 16:12:33 -0700181
182private:
183 std::vector<std::string> identityStore_; /**< A list of name URI. */
184 std::string defaultIdentity_; /**< The default identity in identityStore_, or "" if not defined. */
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700185};
186
187}
188
189#endif