blob: 442e5220521cc72ad6baba6d79218eed02a32844 [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:
Alexander Afanasyev64a3d812014-01-05 23:35:05 -080028 struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
29
Jeff Thompson6c314bc2013-09-23 18:09:38 -070030 /**
31 * The virtual Destructor.
32 */
33 virtual
34 ~IdentityStorage() {}
35
36 /**
37 * Check if the specified identity already exists.
38 * @param identityName The identity name.
39 * @return true if the identity exists, otherwise false.
40 */
41 virtual bool
42 doesIdentityExist(const Name& identityName) = 0;
43
44 /**
45 * Add a new identity. An exception will be thrown if the identity already exists.
46 * @param identityName The identity name to be added.
47 */
48 virtual void
49 addIdentity(const Name& identityName) = 0;
50
51 /**
52 * Revoke the identity.
53 * @return true if the identity was revoked, false if not.
54 */
55 virtual bool
56 revokeIdentity() = 0;
57
58 /**
59 * Generate a name for a new key belonging to the identity.
60 * @param identityName The identity name.
61 * @param useKsk If true, generate a KSK name, otherwise a DSK name.
62 * @return The generated key name.
63 */
Jeff Thompson22285ec2013-10-22 17:43:02 -070064 Name
65 getNewKeyName(const Name& identityName, bool useKsk);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070066
67 /**
68 * Check if the specified key already exists.
69 * @param keyName The name of the key.
70 * @return true if the key exists, otherwise false.
71 */
72 virtual bool
73 doesKeyExist(const Name& keyName) = 0;
74
75 /**
Jeff Thompson6c314bc2013-09-23 18:09:38 -070076 * Add a public key to the identity storage.
77 * @param keyName The name of the public key to be added.
78 * @param keyType Type of the public key to be added.
79 * @param publicKeyDer A blob of the public key DER to be added.
80 */
81 virtual void
Alexander Afanasyev64a3d812014-01-05 23:35:05 -080082 addKey(const Name& keyName, KeyType keyType, const Buffer& publicKeyDer) = 0;
Jeff Thompson6c314bc2013-09-23 18:09:38 -070083
84 /**
85 * Get the public key DER blob from the identity storage.
86 * @param keyName The name of the requested public key.
Jeff Thompsonabcea7d2013-10-02 15:03:21 -070087 * @return The DER Blob. If not found, return a Blob with a null pointer.
Jeff Thompson6c314bc2013-09-23 18:09:38 -070088 */
Alexander Afanasyev64a3d812014-01-05 23:35:05 -080089 virtual Buffer
Jeff Thompson6c314bc2013-09-23 18:09:38 -070090 getKey(const Name& keyName) = 0;
91
92 /**
93 * Activate a key. If a key is marked as inactive, its private part will not be used in packet signing.
94 * @param keyName name of the key
95 */
96 virtual void
97 activateKey(const Name& keyName) = 0;
98
99 /**
100 * Deactivate a key. If a key is marked as inactive, its private part will not be used in packet signing.
101 * @param keyName name of the key
102 */
103 virtual void
104 deactivateKey(const Name& keyName) = 0;
105
106 /**
107 * Check if the specified certificate already exists.
108 * @param certificateName The name of the certificate.
109 * @return true if the certificate exists, otherwise false.
110 */
111 virtual bool
112 doesCertificateExist(const Name& certificateName) = 0;
113
114 /**
115 * Add a certificate to the identity storage.
Jeff Thompsonc69163b2013-10-12 13:49:50 -0700116 * @param certificate The certificate to be added. This makes a copy of the certificate.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700117 */
118 virtual void
Jeff Thompsonc69163b2013-10-12 13:49:50 -0700119 addCertificate(const IdentityCertificate& certificate) = 0;
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700120
121 /**
122 * Get a certificate from the identity storage.
123 * @param certificateName The name of the requested certificate.
124 * @param allowAny If false, only a valid certificate will be returned, otherwise validity is disregarded.
Jeff Thompsonabcea7d2013-10-02 15:03:21 -0700125 * @return The requested certificate. If not found, return a shared_ptr with a null pointer.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700126 */
Jeff Thompson3bd90bc2013-10-19 16:40:14 -0700127 virtual ptr_lib::shared_ptr<Data>
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700128 getCertificate(const Name &certificateName, bool allowAny = false) = 0;
129
130
131 /*****************************************
132 * Get/Set Default *
133 *****************************************/
134
135 /**
136 * Get the default identity.
Jeff Thompson81842272013-09-25 16:12:33 -0700137 * @param return The name of default identity, or an empty name if there is no default.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700138 */
139 virtual Name
140 getDefaultIdentity() = 0;
141
142 /**
143 * Get the default key name for the specified identity.
144 * @param identityName The identity name.
145 * @return The default key name.
146 */
147 virtual Name
148 getDefaultKeyNameForIdentity(const Name& identityName) = 0;
149
150 /**
151 * Get the default certificate name for the specified identity.
152 * @param identityName The identity name.
153 * @return The default certificate name.
154 */
155 Name
Jeff Thompson22285ec2013-10-22 17:43:02 -0700156 getDefaultCertificateNameForIdentity(const Name& identityName);
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700157
158 /**
159 * Get the default certificate name for the specified key.
160 * @param keyName The key name.
161 * @return The default certificate name.
162 */
163 virtual Name
164 getDefaultCertificateNameForKey(const Name& keyName) = 0;
165
166 /**
Jeff Thompson81842272013-09-25 16:12:33 -0700167 * Set the default identity. If the identityName does not exist, then clear the default identity
168 * so that getDefaultIdentity() returns an empty name.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700169 * @param identityName The default identity name.
170 */
171 virtual void
172 setDefaultIdentity(const Name& identityName) = 0;
173
174 /**
175 * Set the default key name for the specified identity.
176 * @param keyName The key name.
Jeff Thompsonabcea7d2013-10-02 15:03:21 -0700177 * @param identityNameCheck (optional) The identity name to check the keyName.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700178 */
179 virtual void
Jeff Thompsonabcea7d2013-10-02 15:03:21 -0700180 setDefaultKeyNameForIdentity(const Name& keyName, const Name& identityNameCheck = Name()) = 0;
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700181
182 /**
183 * Set the default key name for the specified identity.
184 * @param keyName The key name.
185 * @param certificateName The certificate name.
186 */
187 virtual void
188 setDefaultCertificateNameForKey(const Name& keyName, const Name& certificateName) = 0;
Alexander Afanasyev0c632112013-12-30 15:59:31 -0800189
190
191 virtual std::vector<Name>
192 getAllIdentities(bool isDefault) = 0;
193
194 virtual std::vector<Name>
195 getAllKeyNames(bool isDefault) = 0;
196
197 virtual std::vector<Name>
198 getAllKeyNamesOfIdentity(const Name& identity, bool isDefault) = 0;
199
200 virtual std::vector<Name>
201 getAllCertificateNames(bool isDefault) = 0;
202
203 virtual std::vector<Name>
204 getAllCertificateNamesOfKey(const Name& keyName, bool isDefault) = 0;
205
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700206};
207
208}
209
210#endif