1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
|
/*
* Copyright (c) 2017 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file parc_KeyStore.h
* @ingroup security
* @brief A container of Key Store information.
*
* A Key Store is a repository of key information typically accessable
* through some authentication and authorisation system.
* The PARCKeyStore type contains the necessary information to successfully
* gain access to a Key Store.
*
*/
#ifndef libparc_parc_KeyStore_h
#define libparc_parc_KeyStore_h
#include <parc/algol/parc_Object.h>
#include <parc/algol/parc_Buffer.h>
#include <parc/security/parc_CryptoHash.h>
#include <parc/security/parc_SigningAlgorithm.h>
struct parc_key_store;
typedef struct parc_key_store PARCKeyStore;
/**
* The hash of the signer's public key (or secret key for HMAC).
*
* Try using `parcSigner_CreateKeyId` for a sinterfaceer interface.
* You must destroy the returned PARCCryptoHash.
* For public key, its the SHA256 digest of the public key.
* For HMAC, its the SHA256 digest of the secret key.
*
* Equivalent of (for rsa/sha256):
* openssl rsa -in test_rsa_key.pem -outform DER -pubout -out test_rsa_pub.der
* openssl sha256 -out test_rsa_pub_sha256.bin -sha256 -binary < test_rsa_pub.der
*
* @param [in] interfaceContext A pointer to a concrete PARCKeyStore instance.
*
* @return A PARCCryptoHash value.
*/
typedef PARCCryptoHash *(PARCKeyStoreGetVerifierKeyDigest)(const void *interfaceContext);
/**
* Returns a copy of the the certificate digest.
* Returns NULL for symmetric keystores.
*
* Equivalent of (for rsa/sha256):
* openssl x509 -outform DER -out test_rsa_crt.der -in test_rsa.crt
* openssl sha256 -out test_rsa_crt_sha256.bin -sha256 -binary < test_rsa_crt.der
* Which is also the same as (but not in der format)
* openssl x509 -in test_rsa.crt -fingerprint -sha256
*
* @param [in] interfaceContext A pointer to a concrete PARCKeyStore instance.
*
* @return A `PARCCryptoHash` instance which internally contains a hash digest of the certificate used by the signer.
*/
typedef PARCCryptoHash *(PARCKeyStoreGetCertificateDigest)(const void *interfaceContext);
/**
* Returns a copy of the DER encoded certificate.
* Returns NULL for symmetric keystores.
*
* Equivalent of:
* openssl x509 -outform DER -out test_rsa_crt.der -in test_rsa.crt
*
* @param [in] interfaceContextPtr A pointer to a concrete PARCKeyStore instance.
*
* @return A pointer to a PARCBuffer containing the encoded certificate.
*/
typedef PARCBuffer *(PARCKeyStoreGetDEREncodedCertificate)(const void *interfaceContext);
/**
* Returns a copy of the encoded public key in Distinguished Encoding Rules (DER) form.
*
* Equivalent of (for rsa/sha256):
* `openssl rsa -in test_rsa_key.pem -outform DER -pubout -out test_rsa_pub.der`
*
* @param [in] interfaceContextPtr A pointer to a concrete PARCKeyStore instance.
*
* @return A pointer to a PARCBuffer containing the encoded public key.
*/
typedef PARCBuffer *(PARCKeyStoreGetDEREncodedPublicKey)(const void *interfaceContext);
/**
* Returns a copy of the encoded private key in Distinguished Encoding Rules (DER) form.
*
* Equivalent of (for rsa/sha256):
* `openssl rsa -in test_rsa_key.pem -outform DER -out test_rsa.der`
*
* @param [in] interfaceContextPtr A pointer to a concrete PARCKeyStore instance.
*
* @return A pointer to a PARCBuffer containing the encoded private key.
*/
typedef PARCBuffer *(PARCKeyStoreGetDEREncodedPrivateKey)(const void *interfaceContext);
/**
* Returns the signing algorithm from the key type store in the keystore
*
*
* @param [in] interfaceContextPtr A pointer to a concrete PARCKeyStore instance.
*
* @return A pointer to a PARCBuffer containing the encoded private key.
*/
typedef PARCSigningAlgorithm (PARCKeyStoreGetSigningAlgorithm)(const void *interfaceContext);
typedef struct parc_keystore_interface {
/**
* The hash of the signer's public key (or secret key for HMAC).
*
* Try using `parcSigner_CreateKeyId` for a sinterfaceer interface.
* You must destroy the returned PARCCryptoHash.
* For public key, its the SHA256 digest of the public key.
* For HMAC, its the SHA256 digest of the secret key.
*
* Equivalent of (for rsa/sha256):
* openssl rsa -in test_rsa_key.pem -outform DER -pubout -out test_rsa_pub.der
* openssl sha256 -out test_rsa_pub_sha256.bin -sha256 -binary < test_rsa_pub.der
*
* @param [in] interfaceContext A pointer to a concrete PARCKeyStore instance.
*
* @return A PARCCryptoHash value.
*/
PARCKeyStoreGetVerifierKeyDigest *getVerifierKeyDigest;
/**
* Returns a copy of the the certificate digest.
* Returns NULL for symmetric keystores.
*
* Equivalent of (for rsa/sha256):
* openssl x509 -outform DER -out test_rsa_crt.der -in test_rsa.crt
* openssl sha256 -out test_rsa_crt_sha256.bin -sha256 -binary < test_rsa_crt.der
* Which is also the same as (but not in der format)
* openssl x509 -in test_rsa.crt -fingerprint -sha256
*
* @param [in] interfaceContext A pointer to a concrete PARCKeyStore instance.
*
* @return A `PARCCryptoHash` instance which internally contains a hash digest of the certificate used by the signer.
*/
PARCKeyStoreGetCertificateDigest *getCertificateDigest;
/**
* Returns a copy of the DER encoded certificate.
* Returns NULL for symmetric keystores.
*
* Equivalent of:
* openssl x509 -outform DER -out test_rsa_crt.der -in test_rsa.crt
*
* @param [in] interfaceContextPtr A pointer to a concrete PARCKeyStore instance.
*
* @return A pointer to a PARCBuffer containing the encoded certificate.
*/
PARCKeyStoreGetDEREncodedCertificate *getDEREncodedCertificate;
/**
* Returns a copy of the encoded public key in Distinguished Encoding Rules (DER) form.
*
* Equivalent of (for rsa/sha256):
* `openssl rsa -in test_rsa_key.pem -outform DER -pubout -out test_rsa_pub.der`
*
* @param [in] interfaceContextPtr A pointer to a concrete PARCKeyStore instance.
*
* @return A pointer to a PARCBuffer containing the encoded public key.
*/
PARCKeyStoreGetDEREncodedPublicKey *getDEREncodedPublicKey;
/**
* Returns a copy of the encoded private key in Distinguished Encoding Rules (DER) form.
*
* Equivalent of (for rsa/sha256):
* `openssl rsa -in test_rsa_key.pem -outform DER -out test_rsa.der`
*
* @param [in] interfaceContextPtr A pointer to a concrete PARCKeyStore instance.
*
* @return A pointer to a PARCBuffer containing the encoded private key.
*/
PARCKeyStoreGetDEREncodedPrivateKey *getDEREncodedPrivateKey;
/**
* Returns the signing algorithm from the key type store in the keystore
*
*
* @param [in] interfaceContextPtr A pointer to a concrete PARCKeyStore instance.
*
* @return A pointer to a PARCBuffer containing the encoded private key.
*/
PARCKeyStoreGetSigningAlgorithm *getSigningAlgorithm;
} PARCKeyStoreInterface;
/**
* Create a `PARCKeyStore` from a filename.
*
* @param [in] instance A concrete instance of a `PARCKeyStore.`
* @param [in] interface The interface for the `PARCKeyStore.`
*
* @return A pointer to the new `PARCKeyStore`
*
* Example:
* @code
* {
* }
* @endcode
*/
PARCKeyStore *parcKeyStore_Create(PARCObject *instance, const PARCKeyStoreInterface *interface);
/**
* Increase the number of references to an instance of this object.
*
* Note that new instance is not created, only that the given instance's reference count
* is incremented. Discard the reference by invoking `parcKeyStore_Release()`.
*
* @param [in] keyStore A pointer to the original instance.
*
* @return The value of the input parameter @p instance.
*
* Example:
* @code
* {
* ...
*
* PARCKeyStore *keyStore = parcKeyStore_Acquire(keyStoreInstance);
*
* parcKeyStore_Release(&keyStore);
* }
* @endcode
*
* @see parcKey_Release
*/
PARCKeyStore *parcKeyStore_Acquire(const PARCKeyStore *keyStore);
/**
* Release a previously acquired reference to the specified instance,
* decrementing the reference count for the instance.
*
* The pointer to the instance is set to NULL as a side-effect of this function.
*
* If the invocation causes the last reference to the instance to be released,
* the instance is deallocated and the instance's implementation will perform
* additional cleanup and release other privately held references.
*
* @param [in] keyStorePtr A pointer to a pointer to the instance to release.
*
* Example:
* @code
* {
* ...
*
* PARCKeyStore *keyStore = parcKeyStore_Acquire(keyStoreInstance);
*
* parcKeyStore_Release(&keyStore);
* }
* @endcode
*/
void parcKeyStore_Release(PARCKeyStore **keyStorePtr);
/**
* The hash of the signer's public key (or secret key for HMAC).
*
* Try using `parcSigner_CreateKeyId` for a sinterfaceer interface.
* You must destroy the returned PARCCryptoHash.
* For public key, its the SHA256 digest of the public key.
* For HMAC, its the SHA256 digest of the secret key.
*
* Equivalent of (for rsa/sha256):
* openssl rsa -in test_rsa_key.pem -outform DER -pubout -out test_rsa_pub.der
* openssl sha256 -out test_rsa_pub_sha256.bin -sha256 -binary < test_rsa_pub.der
*
* @param [in] interfaceContext A pointer to a concrete PARCKeyStore instance.
*
* @return A PARCCryptoHash value.
*
* Example:
* @code
* {
* }
* @endcode
*/
PARCCryptoHash *parcKeyStore_GetVerifierKeyDigest(const PARCKeyStore *interfaceContext);
/**
* Returns a copy of the the certificate digest.
* Returns NULL for symmetric keystores.
*
* Equivalent of (for rsa/sha256):
* openssl x509 -outform DER -out test_rsa_crt.der -in test_rsa.crt
* openssl sha256 -out test_rsa_crt_sha256.bin -sha256 -binary < test_rsa_crt.der
* Which is also the same as (but not in der format)
* openssl x509 -in test_rsa.crt -fingerprint -sha256
*
* @param [in] interfaceContext A pointer to a concrete PARCKeyStore instance.
*
* @return A `PARCCryptoHash` instance which internally contains a hash digest of the certificate used by the signer.
*
* Example:
* @code
* {
* }
* @endcode
*/
PARCCryptoHash *parcKeyStore_GetCertificateDigest(const PARCKeyStore *interfaceContext);
/**
* Returns a copy of the DER encoded certificate.
* Returns NULL for symmetric keystores.
*
* Equivalent of:
* openssl x509 -outform DER -out test_rsa_crt.der -in test_rsa.crt
*
* @param [in] interfaceContext A pointer to a concrete PARCKeyStore instance.
*
* @return A pointer to a PARCBuffer containing the encoded certificate.
*
* Example:
* @code
* {
* }
* @endcode
*/
PARCBuffer *parcKeyStore_GetDEREncodedCertificate(const PARCKeyStore *interfaceContext);
/**
* Returns a copy of the encoded public key in Distinguished Encoding Rules (DER) form.
*
* Equivalent of (for rsa/sha256):
* `openssl rsa -in test_rsa_key.pem -outform DER -pubout -out test_rsa_pub.der`
*
* @param [in] interfaceContext A pointer to a concrete PARCKeyStore instance.
*
* @return A pointer to a PARCBuffer containing the encoded public key.
*
* Example:
* @code
* {
* }
* @endcode
*/
PARCBuffer *parcKeyStore_GetDEREncodedPublicKey(const PARCKeyStore *interfaceContext);
/**
* Returns a copy of the encoded private key in Distinguished Encoding Rules (DER) form.
*
* Equivalent of (for rsa/sha256):
* `openssl rsa -in test_rsa_key.pem -outform DER -out test_rsa.der`
*
* @param [in] interfaceContext A pointer to a concrete PARCKeyStore instance.
*
* @return A pointer to a PARCBuffer containing the encoded private key.
*
* Example:
* @code
* {
* }
* @endcode
*/
PARCBuffer *parcKeyStore_GetDEREncodedPrivateKey(const PARCKeyStore *interfaceContext);
/**
* Returns the signing algorithm from the key type store in the keystore
*
*
* @param [in] interfaceContextPtr A pointer to a concrete PARCKeyStore instance.
*
* @return A pointer to a PARCBuffer containing the encoded private key.
*/
PARCSigningAlgorithm parcKeyStore_getSigningAlgorithm(const PARCKeyStore *interfaceContext);
#endif // libparc_parc_KeyStore_h
|