blob: 87d93fd6a6b4a37d2e7f39af6e5798366c87ce7c [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"
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080014#include "../certificate/public-key.hpp"
Jeff Thompson6c314bc2013-09-23 18:09:38 -070015
16namespace ndn {
17
18class Certificate;
Jeff Thompsonc69163b2013-10-12 13:49:50 -070019class IdentityCertificate;
Jeff Thompson6c314bc2013-09-23 18:09:38 -070020class Data;
21
22/**
23 * IdentityStorage is a base class for the storage of identity, public keys and certificates.
24 * Private keys are stored in PrivateKeyStorage.
25 * This is an abstract base class. A subclass must implement the methods.
26 */
27class IdentityStorage {
28public:
Alexander Afanasyev64a3d812014-01-05 23:35:05 -080029 struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
30
Jeff Thompson6c314bc2013-09-23 18:09:38 -070031 /**
32 * The virtual Destructor.
33 */
34 virtual
35 ~IdentityStorage() {}
36
37 /**
38 * Check if the specified identity already exists.
39 * @param identityName The identity name.
40 * @return true if the identity exists, otherwise false.
41 */
42 virtual bool
43 doesIdentityExist(const Name& identityName) = 0;
44
45 /**
46 * Add a new identity. An exception will be thrown if the identity already exists.
47 * @param identityName The identity name to be added.
48 */
49 virtual void
50 addIdentity(const Name& identityName) = 0;
51
52 /**
53 * Revoke the identity.
54 * @return true if the identity was revoked, false if not.
55 */
56 virtual bool
57 revokeIdentity() = 0;
58
59 /**
60 * Generate a name for a new key belonging to the identity.
61 * @param identityName The identity name.
62 * @param useKsk If true, generate a KSK name, otherwise a DSK name.
63 * @return The generated key name.
64 */
Jeff Thompson22285ec2013-10-22 17:43:02 -070065 Name
66 getNewKeyName(const Name& identityName, bool useKsk);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070067
68 /**
69 * Check if the specified key already exists.
70 * @param keyName The name of the key.
71 * @return true if the key exists, otherwise false.
72 */
73 virtual bool
74 doesKeyExist(const Name& keyName) = 0;
75
76 /**
Jeff Thompson6c314bc2013-09-23 18:09:38 -070077 * Add a public key to the identity storage.
78 * @param keyName The name of the public key to be added.
79 * @param keyType Type of the public key to be added.
80 * @param publicKeyDer A blob of the public key DER to be added.
81 */
82 virtual void
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080083 addKey(const Name& keyName, KeyType keyType, const PublicKey& publicKeyDer) = 0;
Jeff Thompson6c314bc2013-09-23 18:09:38 -070084
85 /**
86 * Get the public key DER blob from the identity storage.
87 * @param keyName The name of the requested public key.
Jeff Thompsonabcea7d2013-10-02 15:03:21 -070088 * @return The DER Blob. If not found, return a Blob with a null pointer.
Jeff Thompson6c314bc2013-09-23 18:09:38 -070089 */
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080090 virtual ptr_lib::shared_ptr<PublicKey>
Jeff Thompson6c314bc2013-09-23 18:09:38 -070091 getKey(const Name& keyName) = 0;
92
93 /**
94 * Activate a key. If a key is marked as inactive, its private part will not be used in packet signing.
95 * @param keyName name of the key
96 */
97 virtual void
98 activateKey(const Name& keyName) = 0;
99
100 /**
101 * Deactivate a key. If a key is marked as inactive, its private part will not be used in packet signing.
102 * @param keyName name of the key
103 */
104 virtual void
105 deactivateKey(const Name& keyName) = 0;
106
107 /**
108 * Check if the specified certificate already exists.
109 * @param certificateName The name of the certificate.
110 * @return true if the certificate exists, otherwise false.
111 */
112 virtual bool
113 doesCertificateExist(const Name& certificateName) = 0;
114
115 /**
116 * Add a certificate to the identity storage.
Jeff Thompsonc69163b2013-10-12 13:49:50 -0700117 * @param certificate The certificate to be added. This makes a copy of the certificate.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700118 */
119 virtual void
Jeff Thompsonc69163b2013-10-12 13:49:50 -0700120 addCertificate(const IdentityCertificate& certificate) = 0;
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700121
122 /**
123 * Get a certificate from the identity storage.
124 * @param certificateName The name of the requested certificate.
125 * @param allowAny If false, only a valid certificate will be returned, otherwise validity is disregarded.
Jeff Thompsonabcea7d2013-10-02 15:03:21 -0700126 * @return The requested certificate. If not found, return a shared_ptr with a null pointer.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700127 */
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -0800128 virtual ptr_lib::shared_ptr<IdentityCertificate>
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700129 getCertificate(const Name &certificateName, bool allowAny = false) = 0;
130
131
132 /*****************************************
133 * Get/Set Default *
134 *****************************************/
135
136 /**
137 * Get the default identity.
Jeff Thompson81842272013-09-25 16:12:33 -0700138 * @param return The name of default identity, or an empty name if there is no default.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700139 */
140 virtual Name
141 getDefaultIdentity() = 0;
142
143 /**
144 * Get the default key name for the specified identity.
145 * @param identityName The identity name.
146 * @return The default key name.
147 */
148 virtual Name
149 getDefaultKeyNameForIdentity(const Name& identityName) = 0;
150
151 /**
152 * Get the default certificate name for the specified identity.
153 * @param identityName The identity name.
154 * @return The default certificate name.
155 */
156 Name
Jeff Thompson22285ec2013-10-22 17:43:02 -0700157 getDefaultCertificateNameForIdentity(const Name& identityName);
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700158
159 /**
160 * Get the default certificate name for the specified key.
161 * @param keyName The key name.
162 * @return The default certificate name.
163 */
164 virtual Name
165 getDefaultCertificateNameForKey(const Name& keyName) = 0;
166
167 /**
Jeff Thompson81842272013-09-25 16:12:33 -0700168 * Set the default identity. If the identityName does not exist, then clear the default identity
169 * so that getDefaultIdentity() returns an empty name.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700170 * @param identityName The default identity name.
171 */
172 virtual void
173 setDefaultIdentity(const Name& identityName) = 0;
174
175 /**
176 * Set the default key name for the specified identity.
177 * @param keyName The key name.
Jeff Thompsonabcea7d2013-10-02 15:03:21 -0700178 * @param identityNameCheck (optional) The identity name to check the keyName.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700179 */
180 virtual void
Jeff Thompsonabcea7d2013-10-02 15:03:21 -0700181 setDefaultKeyNameForIdentity(const Name& keyName, const Name& identityNameCheck = Name()) = 0;
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700182
183 /**
184 * Set the default key name for the specified identity.
185 * @param keyName The key name.
186 * @param certificateName The certificate name.
187 */
188 virtual void
189 setDefaultCertificateNameForKey(const Name& keyName, const Name& certificateName) = 0;
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800190
191
192 virtual std::vector<Name>
193 getAllIdentities(bool isDefault) = 0;
194
195 virtual std::vector<Name>
196 getAllKeyNames(bool isDefault) = 0;
197
198 virtual std::vector<Name>
199 getAllKeyNamesOfIdentity(const Name& identity, bool isDefault) = 0;
200
201 virtual std::vector<Name>
202 getAllCertificateNames(bool isDefault) = 0;
203
204 virtual std::vector<Name>
205 getAllCertificateNamesOfKey(const Name& keyName, bool isDefault) = 0;
206
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700207};
208
209}
210
211#endif