blob: 0e22432fd0603d7745dbc4bd30cf42b5d61844f6 [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: Yingdi Yu <yingdi@cs.ucla.edu>
5 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
6 * See COPYING for copyright and distribution information.
7 */
8
9#ifndef NDN_IDENTITY_STORAGE_HPP
10#define NDN_IDENTITY_STORAGE_HPP
11
12#include "../../name.hpp"
13#include "../security-common.hpp"
14
15namespace ndn {
16
17class Certificate;
18class Data;
19
20/**
21 * IdentityStorage is a base class for the storage of identity, public keys and certificates.
22 * Private keys are stored in PrivateKeyStorage.
23 * This is an abstract base class. A subclass must implement the methods.
24 */
25class IdentityStorage {
26public:
27 /**
28 * The virtual Destructor.
29 */
30 virtual
31 ~IdentityStorage() {}
32
33 /**
34 * Check if the specified identity already exists.
35 * @param identityName The identity name.
36 * @return true if the identity exists, otherwise false.
37 */
38 virtual bool
39 doesIdentityExist(const Name& identityName) = 0;
40
41 /**
42 * Add a new identity. An exception will be thrown if the identity already exists.
43 * @param identityName The identity name to be added.
44 */
45 virtual void
46 addIdentity(const Name& identityName) = 0;
47
48 /**
49 * Revoke the identity.
50 * @return true if the identity was revoked, false if not.
51 */
52 virtual bool
53 revokeIdentity() = 0;
54
55 /**
56 * Generate a name for a new key belonging to the identity.
57 * @param identityName The identity name.
58 * @param useKsk If true, generate a KSK name, otherwise a DSK name.
59 * @return The generated key name.
60 */
61 virtual Name
62 getNewKeyName(const Name& identityName, bool useKsk) = 0;
63
64 /**
65 * Check if the specified key already exists.
66 * @param keyName The name of the key.
67 * @return true if the key exists, otherwise false.
68 */
69 virtual bool
70 doesKeyExist(const Name& keyName) = 0;
71
72 /**
73 * Extract the key name from the certificate name.
74 * @param certificateName The certificate name to be processed.
75 */
76 virtual Name
77 getKeyNameForCertificate(const Name& certificateName) = 0;
78
79 /**
80 * Add a public key to the identity storage.
81 * @param keyName The name of the public key to be added.
82 * @param keyType Type of the public key to be added.
83 * @param publicKeyDer A blob of the public key DER to be added.
84 */
85 virtual void
Jeff Thompsonbd04b072013-09-27 15:14:09 -070086 addKey(const Name& keyName, KeyType keyType, const Blob& publicKeyDer) = 0;
Jeff Thompson6c314bc2013-09-23 18:09:38 -070087
88 /**
89 * Get the public key DER blob from the identity storage.
90 * @param keyName The name of the requested public key.
91 */
92 virtual Blob
93 getKey(const Name& keyName) = 0;
94
95 /**
96 * Activate a key. If a key is marked as inactive, its private part will not be used in packet signing.
97 * @param keyName name of the key
98 */
99 virtual void
100 activateKey(const Name& keyName) = 0;
101
102 /**
103 * Deactivate a key. If a key is marked as inactive, its private part will not be used in packet signing.
104 * @param keyName name of the key
105 */
106 virtual void
107 deactivateKey(const Name& keyName) = 0;
108
109 /**
110 * Check if the specified certificate already exists.
111 * @param certificateName The name of the certificate.
112 * @return true if the certificate exists, otherwise false.
113 */
114 virtual bool
115 doesCertificateExist(const Name& certificateName) = 0;
116
117 /**
118 * Add a certificate to the identity storage.
119 * @param certificate The certificate to be added.
120 */
121 virtual void
122 addCertificate(const Certificate& certificate) = 0;
123
124 /**
125 * Get a certificate from the identity storage.
126 * @param certificateName The name of the requested certificate.
127 * @param allowAny If false, only a valid certificate will be returned, otherwise validity is disregarded.
128 * @return The requested certificate.
129 */
Jeff Thompsona6fd6382013-09-24 15:23:37 -0700130 virtual ptr_lib::shared_ptr<Certificate>
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700131 getCertificate(const Name &certificateName, bool allowAny = false) = 0;
132
133
134 /*****************************************
135 * Get/Set Default *
136 *****************************************/
137
138 /**
139 * Get the default identity.
Jeff Thompson81842272013-09-25 16:12:33 -0700140 * @param return The name of default identity, or an empty name if there is no default.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700141 */
142 virtual Name
143 getDefaultIdentity() = 0;
144
145 /**
146 * Get the default key name for the specified identity.
147 * @param identityName The identity name.
148 * @return The default key name.
149 */
150 virtual Name
151 getDefaultKeyNameForIdentity(const Name& identityName) = 0;
152
153 /**
154 * Get the default certificate name for the specified identity.
155 * @param identityName The identity name.
156 * @return The default certificate name.
157 */
158 Name
159 getDefaultCertificateNameForIdentity(const Name& identityName)
160 {
161 return getDefaultCertificateNameForKey(getDefaultKeyNameForIdentity(identityName));
162 }
163
164 /**
165 * Get the default certificate name for the specified key.
166 * @param keyName The key name.
167 * @return The default certificate name.
168 */
169 virtual Name
170 getDefaultCertificateNameForKey(const Name& keyName) = 0;
171
172 /**
Jeff Thompson81842272013-09-25 16:12:33 -0700173 * Set the default identity. If the identityName does not exist, then clear the default identity
174 * so that getDefaultIdentity() returns an empty name.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700175 * @param identityName The default identity name.
176 */
177 virtual void
178 setDefaultIdentity(const Name& identityName) = 0;
179
180 /**
181 * Set the default key name for the specified identity.
182 * @param keyName The key name.
183 * @param identityName (optional) The identity name to check the keyName.
184 */
185 virtual void
186 setDefaultKeyNameForIdentity(const Name& keyName, const Name& identityName = Name()) = 0;
187
188 /**
189 * Set the default key name for the specified identity.
190 * @param keyName The key name.
191 * @param certificateName The certificate name.
192 */
193 virtual void
194 setDefaultCertificateNameForKey(const Name& keyName, const Name& certificateName) = 0;
195};
196
197}
198
199#endif