blob: 3c298c8e17ec0472a2709e4ccdc4808c3d4bcf49 [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
Jeff Thompsone589c3f2013-10-12 17:30:50 -070010#define NDN_IDENTITY_STORAGE_HPP
Jeff Thompson6c314bc2013-09-23 18:09:38 -070011
12#include "../../name.hpp"
13#include "../security-common.hpp"
14
15namespace ndn {
16
17class Certificate;
Jeff Thompsonc69163b2013-10-12 13:49:50 -070018class IdentityCertificate;
Jeff Thompson6c314bc2013-09-23 18:09:38 -070019class Data;
20
21/**
22 * IdentityStorage is a base class for the storage of identity, public keys and certificates.
23 * Private keys are stored in PrivateKeyStorage.
24 * This is an abstract base class. A subclass must implement the methods.
25 */
26class IdentityStorage {
27public:
28 /**
29 * The virtual Destructor.
30 */
31 virtual
32 ~IdentityStorage() {}
33
34 /**
35 * Check if the specified identity already exists.
36 * @param identityName The identity name.
37 * @return true if the identity exists, otherwise false.
38 */
39 virtual bool
40 doesIdentityExist(const Name& identityName) = 0;
41
42 /**
43 * Add a new identity. An exception will be thrown if the identity already exists.
44 * @param identityName The identity name to be added.
45 */
46 virtual void
47 addIdentity(const Name& identityName) = 0;
48
49 /**
50 * Revoke the identity.
51 * @return true if the identity was revoked, false if not.
52 */
53 virtual bool
54 revokeIdentity() = 0;
55
56 /**
57 * Generate a name for a new key belonging to the identity.
58 * @param identityName The identity name.
59 * @param useKsk If true, generate a KSK name, otherwise a DSK name.
60 * @return The generated key name.
61 */
Jeff Thompson22285ec2013-10-22 17:43:02 -070062 Name
63 getNewKeyName(const Name& identityName, bool useKsk);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070064
65 /**
66 * Check if the specified key already exists.
67 * @param keyName The name of the key.
68 * @return true if the key exists, otherwise false.
69 */
70 virtual bool
71 doesKeyExist(const Name& keyName) = 0;
72
73 /**
Jeff Thompson6c314bc2013-09-23 18:09:38 -070074 * Add a public key to the identity storage.
75 * @param keyName The name of the public key to be added.
76 * @param keyType Type of the public key to be added.
77 * @param publicKeyDer A blob of the public key DER to be added.
78 */
79 virtual void
Jeff Thompsonbd04b072013-09-27 15:14:09 -070080 addKey(const Name& keyName, KeyType keyType, const Blob& publicKeyDer) = 0;
Jeff Thompson6c314bc2013-09-23 18:09:38 -070081
82 /**
83 * Get the public key DER blob from the identity storage.
84 * @param keyName The name of the requested public key.
Jeff Thompsonabcea7d2013-10-02 15:03:21 -070085 * @return The DER Blob. If not found, return a Blob with a null pointer.
Jeff Thompson6c314bc2013-09-23 18:09:38 -070086 */
87 virtual Blob
88 getKey(const Name& keyName) = 0;
89
90 /**
91 * Activate a key. If a key is marked as inactive, its private part will not be used in packet signing.
92 * @param keyName name of the key
93 */
94 virtual void
95 activateKey(const Name& keyName) = 0;
96
97 /**
98 * Deactivate a key. If a key is marked as inactive, its private part will not be used in packet signing.
99 * @param keyName name of the key
100 */
101 virtual void
102 deactivateKey(const Name& keyName) = 0;
103
104 /**
105 * Check if the specified certificate already exists.
106 * @param certificateName The name of the certificate.
107 * @return true if the certificate exists, otherwise false.
108 */
109 virtual bool
110 doesCertificateExist(const Name& certificateName) = 0;
111
112 /**
113 * Add a certificate to the identity storage.
Jeff Thompsonc69163b2013-10-12 13:49:50 -0700114 * @param certificate The certificate to be added. This makes a copy of the certificate.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700115 */
116 virtual void
Jeff Thompsonc69163b2013-10-12 13:49:50 -0700117 addCertificate(const IdentityCertificate& certificate) = 0;
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700118
119 /**
120 * Get a certificate from the identity storage.
121 * @param certificateName The name of the requested certificate.
122 * @param allowAny If false, only a valid certificate will be returned, otherwise validity is disregarded.
Jeff Thompsonabcea7d2013-10-02 15:03:21 -0700123 * @return The requested certificate. If not found, return a shared_ptr with a null pointer.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700124 */
Jeff Thompson3bd90bc2013-10-19 16:40:14 -0700125 virtual ptr_lib::shared_ptr<Data>
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700126 getCertificate(const Name &certificateName, bool allowAny = false) = 0;
127
128
129 /*****************************************
130 * Get/Set Default *
131 *****************************************/
132
133 /**
134 * Get the default identity.
Jeff Thompson81842272013-09-25 16:12:33 -0700135 * @param return The name of default identity, or an empty name if there is no default.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700136 */
137 virtual Name
138 getDefaultIdentity() = 0;
139
140 /**
141 * Get the default key name for the specified identity.
142 * @param identityName The identity name.
143 * @return The default key name.
144 */
145 virtual Name
146 getDefaultKeyNameForIdentity(const Name& identityName) = 0;
147
148 /**
149 * Get the default certificate name for the specified identity.
150 * @param identityName The identity name.
151 * @return The default certificate name.
152 */
153 Name
Jeff Thompson22285ec2013-10-22 17:43:02 -0700154 getDefaultCertificateNameForIdentity(const Name& identityName);
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700155
156 /**
157 * Get the default certificate name for the specified key.
158 * @param keyName The key name.
159 * @return The default certificate name.
160 */
161 virtual Name
162 getDefaultCertificateNameForKey(const Name& keyName) = 0;
163
164 /**
Jeff Thompson81842272013-09-25 16:12:33 -0700165 * Set the default identity. If the identityName does not exist, then clear the default identity
166 * so that getDefaultIdentity() returns an empty name.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700167 * @param identityName The default identity name.
168 */
169 virtual void
170 setDefaultIdentity(const Name& identityName) = 0;
171
172 /**
173 * Set the default key name for the specified identity.
174 * @param keyName The key name.
Jeff Thompsonabcea7d2013-10-02 15:03:21 -0700175 * @param identityNameCheck (optional) The identity name to check the keyName.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700176 */
177 virtual void
Jeff Thompsonabcea7d2013-10-02 15:03:21 -0700178 setDefaultKeyNameForIdentity(const Name& keyName, const Name& identityNameCheck = Name()) = 0;
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700179
180 /**
181 * Set the default key name for the specified identity.
182 * @param keyName The key name.
183 * @param certificateName The certificate name.
184 */
185 virtual void
186 setDefaultCertificateNameForKey(const Name& keyName, const Name& certificateName) = 0;
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800187
188
189 virtual std::vector<Name>
190 getAllIdentities(bool isDefault) = 0;
191
192 virtual std::vector<Name>
193 getAllKeyNames(bool isDefault) = 0;
194
195 virtual std::vector<Name>
196 getAllKeyNamesOfIdentity(const Name& identity, bool isDefault) = 0;
197
198 virtual std::vector<Name>
199 getAllCertificateNames(bool isDefault) = 0;
200
201 virtual std::vector<Name>
202 getAllCertificateNamesOfKey(const Name& keyName, bool isDefault) = 0;
203
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700204};
205
206}
207
208#endif