blob: 1df05fe84852aa083bc230cfeba701369c65b9a3 [file] [log] [blame]
Jeff Thompson7ca11f22013-10-04 19:01:30 -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 * See COPYING for copyright and distribution information.
6 */
7
8#ifndef NDN_BASIC_IDENTITY_STORAGE_H
9#define NDN_BASIC_IDENTITY_STORAGE_H
10
11// Only compile if config.h defines HAVE_SQLITE3.
12#include "../../c/common.h"
13#if 0 // temporarily disable.
14//#ifdef HAVE_SQLITE3
15
16#include <sqlite3.h>
17#include "../../common.hpp"
18#include "identity-storage.hpp"
19
20namespace ndn
21{
22
23/**
24 * BasicIdentityStorage extends IdentityStorage to implement a basic storage of identity, public keys and certificates
25 * using SQLite.
26 */
27class BasicIdentityStorage : public IdentityStorage {
28public:
29 BasicIdentityStorage();
30
31 /**
32 * The virtual Destructor.
33 */
34 virtual
35 ~BasicIdentityStorage();
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);
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);
51
52 /**
53 * Revoke the identity.
54 * @return true if the identity was revoked, false if not.
55 */
56 virtual bool
57 revokeIdentity();
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 */
65 virtual Name
66 getNewKeyName(const Name& identityName, bool useKsk);
67
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);
75
76 /**
77 * Extract the key name from the certificate name.
78 * @param certificateName The certificate name to be processed.
79 */
80 virtual Name
81 getKeyNameForCertificate(const Name& certificateName);
82
83 /**
84 * Add a public key to the identity storage.
85 * @param keyName The name of the public key to be added.
86 * @param keyType Type of the public key to be added.
87 * @param publicKeyDer A blob of the public key DER to be added.
88 */
89 virtual void
90 addKey(const Name& keyName, KeyType keyType, const Blob& publicKeyDer);
91
92 /**
93 * Get the public key DER blob from the identity storage.
94 * @param keyName The name of the requested public key.
95 * @return The DER Blob. If not found, return a Blob with a null pointer.
96 */
97 virtual Blob
98 getKey(const Name& keyName);
99
100 /**
101 * Activate 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 activateKey(const Name& keyName);
106
107 /**
108 * Deactivate a key. If a key is marked as inactive, its private part will not be used in packet signing.
109 * @param keyName name of the key
110 */
111 virtual void
112 deactivateKey(const Name& keyName);
113
114 /**
115 * Check if the specified certificate already exists.
116 * @param certificateName The name of the certificate.
117 * @return true if the certificate exists, otherwise false.
118 */
119 virtual bool
120 doesCertificateExist(const Name& certificateName);
121
122 /**
123 * Add a certificate in to the identity storage without checking if the identity and key exists.
124 * @param certificate The certificate to be added.
125 */
126 void
127 addAnyCertificate (const Certificate& certificate);
128
129 /**
130 * Add a certificate to the identity storage.
131 * @param certificate The certificate to be added.
132 */
133 virtual void
134 addCertificate(const Certificate& certificate);
135
136 /**
137 * Get a certificate from the identity storage.
138 * @param certificateName The name of the requested certificate.
139 * @param allowAny If false, only a valid certificate will be returned, otherwise validity is disregarded.
140 * @return The requested certificate. If not found, return a shared_ptr with a null pointer.
141 */
142 virtual ptr_lib::shared_ptr<Certificate>
143 getCertificate(const Name &certificateName, bool allowAny = false);
144
145
146 /*****************************************
147 * Get/Set Default *
148 *****************************************/
149
150 /**
151 * Get the default identity.
152 * @param return The name of default identity, or an empty name if there is no default.
153 */
154 virtual Name
155 getDefaultIdentity();
156
157 /**
158 * Get the default key name for the specified identity.
159 * @param identityName The identity name.
160 * @return The default key name.
161 */
162 virtual Name
163 getDefaultKeyNameForIdentity(const Name& identityName);
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);
172
173 /**
174 * Set the default identity. If the identityName does not exist, then clear the default identity
175 * so that getDefaultIdentity() returns an empty name.
176 * @param identityName The default identity name.
177 */
178 virtual void
179 setDefaultIdentity(const Name& identityName);
180
181 /**
182 * Set the default key name for the specified identity.
183 * @param keyName The key name.
184 * @param identityNameCheck (optional) The identity name to check the keyName.
185 */
186 virtual void
187 setDefaultKeyNameForIdentity(const Name& keyName, const Name& identityNameCheck = Name());
188
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);
196
197private:
198
199 virtual void
200 updateKeyStatus(const Name& keyName, bool isActive);
201
202 sqlite3 *database_;
203#if 0
204 Time lastUpdated_;
205#endif
206};
207
208}
209
210#endif // HAVE_SQLITE3
211
212#endif