blob: db6ab0e73eb610b186fd3141510eda689c458974 [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.
Jeff Thompsonabcea7d2013-10-02 15:03:21 -070091 * @return The DER Blob. If not found, return a Blob with a null pointer.
Jeff Thompson6c314bc2013-09-23 18:09:38 -070092 */
93 virtual Blob
94 getKey(const Name& keyName) = 0;
95
96 /**
97 * Activate a key. If a key is marked as inactive, its private part will not be used in packet signing.
98 * @param keyName name of the key
99 */
100 virtual void
101 activateKey(const Name& keyName) = 0;
102
103 /**
104 * Deactivate a key. If a key is marked as inactive, its private part will not be used in packet signing.
105 * @param keyName name of the key
106 */
107 virtual void
108 deactivateKey(const Name& keyName) = 0;
109
110 /**
111 * Check if the specified certificate already exists.
112 * @param certificateName The name of the certificate.
113 * @return true if the certificate exists, otherwise false.
114 */
115 virtual bool
116 doesCertificateExist(const Name& certificateName) = 0;
117
118 /**
119 * Add a certificate to the identity storage.
120 * @param certificate The certificate to be added.
121 */
122 virtual void
123 addCertificate(const Certificate& certificate) = 0;
124
125 /**
126 * Get a certificate from the identity storage.
127 * @param certificateName The name of the requested certificate.
128 * @param allowAny If false, only a valid certificate will be returned, otherwise validity is disregarded.
Jeff Thompsonabcea7d2013-10-02 15:03:21 -0700129 * @return The requested certificate. If not found, return a shared_ptr with a null pointer.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700130 */
Jeff Thompsona6fd6382013-09-24 15:23:37 -0700131 virtual ptr_lib::shared_ptr<Certificate>
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700132 getCertificate(const Name &certificateName, bool allowAny = false) = 0;
133
134
135 /*****************************************
136 * Get/Set Default *
137 *****************************************/
138
139 /**
140 * Get the default identity.
Jeff Thompson81842272013-09-25 16:12:33 -0700141 * @param return The name of default identity, or an empty name if there is no default.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700142 */
143 virtual Name
144 getDefaultIdentity() = 0;
145
146 /**
147 * Get the default key name for the specified identity.
148 * @param identityName The identity name.
149 * @return The default key name.
150 */
151 virtual Name
152 getDefaultKeyNameForIdentity(const Name& identityName) = 0;
153
154 /**
155 * Get the default certificate name for the specified identity.
156 * @param identityName The identity name.
157 * @return The default certificate name.
158 */
159 Name
160 getDefaultCertificateNameForIdentity(const Name& identityName)
161 {
162 return getDefaultCertificateNameForKey(getDefaultKeyNameForIdentity(identityName));
163 }
164
165 /**
166 * Get the default certificate name for the specified key.
167 * @param keyName The key name.
168 * @return The default certificate name.
169 */
170 virtual Name
171 getDefaultCertificateNameForKey(const Name& keyName) = 0;
172
173 /**
Jeff Thompson81842272013-09-25 16:12:33 -0700174 * Set the default identity. If the identityName does not exist, then clear the default identity
175 * so that getDefaultIdentity() returns an empty name.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700176 * @param identityName The default identity name.
177 */
178 virtual void
179 setDefaultIdentity(const Name& identityName) = 0;
180
181 /**
182 * Set the default key name for the specified identity.
183 * @param keyName The key name.
Jeff Thompsonabcea7d2013-10-02 15:03:21 -0700184 * @param identityNameCheck (optional) The identity name to check the keyName.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700185 */
186 virtual void
Jeff Thompsonabcea7d2013-10-02 15:03:21 -0700187 setDefaultKeyNameForIdentity(const Name& keyName, const Name& identityNameCheck = Name()) = 0;
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700188
189 /**
190 * Set the default key name for the specified identity.
191 * @param keyName The key name.
192 * @param certificateName The certificate name.
193 */
194 virtual void
195 setDefaultCertificateNameForKey(const Name& keyName, const Name& certificateName) = 0;
196};
197
198}
199
200#endif