blob: fdf3d0cf5e474f9057a88d1bbb27f8679c620572 [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 */
62 virtual Name
63 getNewKeyName(const Name& identityName, bool useKsk) = 0;
64
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 /**
74 * Extract the key name from the certificate name.
75 * @param certificateName The certificate name to be processed.
76 */
77 virtual Name
78 getKeyNameForCertificate(const Name& certificateName) = 0;
79
80 /**
81 * Add a public key to the identity storage.
82 * @param keyName The name of the public key to be added.
83 * @param keyType Type of the public key to be added.
84 * @param publicKeyDer A blob of the public key DER to be added.
85 */
86 virtual void
Jeff Thompsonbd04b072013-09-27 15:14:09 -070087 addKey(const Name& keyName, KeyType keyType, const Blob& publicKeyDer) = 0;
Jeff Thompson6c314bc2013-09-23 18:09:38 -070088
89 /**
90 * Get the public key DER blob from the identity storage.
91 * @param keyName The name of the requested public key.
Jeff Thompsonabcea7d2013-10-02 15:03:21 -070092 * @return The DER Blob. If not found, return a Blob with a null pointer.
Jeff Thompson6c314bc2013-09-23 18:09:38 -070093 */
94 virtual Blob
95 getKey(const Name& keyName) = 0;
96
97 /**
98 * Activate 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 activateKey(const Name& keyName) = 0;
103
104 /**
105 * Deactivate a key. If a key is marked as inactive, its private part will not be used in packet signing.
106 * @param keyName name of the key
107 */
108 virtual void
109 deactivateKey(const Name& keyName) = 0;
110
111 /**
112 * Check if the specified certificate already exists.
113 * @param certificateName The name of the certificate.
114 * @return true if the certificate exists, otherwise false.
115 */
116 virtual bool
117 doesCertificateExist(const Name& certificateName) = 0;
118
119 /**
120 * Add a certificate to the identity storage.
Jeff Thompsonc69163b2013-10-12 13:49:50 -0700121 * @param certificate The certificate to be added. This makes a copy of the certificate.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700122 */
123 virtual void
Jeff Thompsonc69163b2013-10-12 13:49:50 -0700124 addCertificate(const IdentityCertificate& certificate) = 0;
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700125
126 /**
127 * Get a certificate from the identity storage.
128 * @param certificateName The name of the requested certificate.
129 * @param allowAny If false, only a valid certificate will be returned, otherwise validity is disregarded.
Jeff Thompsonabcea7d2013-10-02 15:03:21 -0700130 * @return The requested certificate. If not found, return a shared_ptr with a null pointer.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700131 */
Jeff Thompson3bd90bc2013-10-19 16:40:14 -0700132 virtual ptr_lib::shared_ptr<Data>
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700133 getCertificate(const Name &certificateName, bool allowAny = false) = 0;
134
135
136 /*****************************************
137 * Get/Set Default *
138 *****************************************/
139
140 /**
141 * Get the default identity.
Jeff Thompson81842272013-09-25 16:12:33 -0700142 * @param return The name of default identity, or an empty name if there is no default.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700143 */
144 virtual Name
145 getDefaultIdentity() = 0;
146
147 /**
148 * Get the default key name for the specified identity.
149 * @param identityName The identity name.
150 * @return The default key name.
151 */
152 virtual Name
153 getDefaultKeyNameForIdentity(const Name& identityName) = 0;
154
155 /**
156 * Get the default certificate name for the specified identity.
157 * @param identityName The identity name.
158 * @return The default certificate name.
159 */
160 Name
161 getDefaultCertificateNameForIdentity(const Name& identityName)
162 {
163 return getDefaultCertificateNameForKey(getDefaultKeyNameForIdentity(identityName));
164 }
165
166 /**
167 * Get the default certificate name for the specified key.
168 * @param keyName The key name.
169 * @return The default certificate name.
170 */
171 virtual Name
172 getDefaultCertificateNameForKey(const Name& keyName) = 0;
173
174 /**
Jeff Thompson81842272013-09-25 16:12:33 -0700175 * Set the default identity. If the identityName does not exist, then clear the default identity
176 * so that getDefaultIdentity() returns an empty name.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700177 * @param identityName The default identity name.
178 */
179 virtual void
180 setDefaultIdentity(const Name& identityName) = 0;
181
182 /**
183 * Set the default key name for the specified identity.
184 * @param keyName The key name.
Jeff Thompsonabcea7d2013-10-02 15:03:21 -0700185 * @param identityNameCheck (optional) The identity name to check the keyName.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700186 */
187 virtual void
Jeff Thompsonabcea7d2013-10-02 15:03:21 -0700188 setDefaultKeyNameForIdentity(const Name& keyName, const Name& identityNameCheck = Name()) = 0;
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700189
190 /**
191 * Set the default key name for the specified identity.
192 * @param keyName The key name.
193 * @param certificateName The certificate name.
194 */
195 virtual void
196 setDefaultCertificateNameForKey(const Name& keyName, const Name& certificateName) = 0;
197};
198
199}
200
201#endif