This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
/
iot_pkcs11_secure_element.c
563 lines (509 loc) · 20.3 KB
/
iot_pkcs11_secure_element.c
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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
/*
* FreeRTOS PKCS #11 V2.1.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/**
* @file iot_pkcs11_mbedtls.c
* @brief mbedTLS-based PKCS#11 implementation for software keys. This
* file deviates from the FreeRTOS style standard for some function names and
* data types in order to maintain compliance with the PKCS #11 standard.
*/
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "iot_pkcs11_config.h"
#include "iot_crypto.h"
#include "iot_pkcs11.h"
#include "iot_pkcs11_pal.h"
#include "iot_pki_utils.h"
#include <string.h>
#ifdef AMAZON_FREERTOS_ENABLE_UNIT_TESTS
#include "iot_test_pkcs11_config.h"
#endif
/* Credential includes. */
#include "aws_clientcredential.h"
#include "aws_clientcredential_keys.h"
#include "iot_default_root_certificates.h"
#if ( pkcs11configOTA_SUPPORTED == 1 )
#include "aws_ota_codesigner_certificate.h"
#endif
/* Microchip Secure Element */
#include "atca_config.h"
#include "atca_cert_chain.h"
#include "pkcs11_config.h"
#include "pkcs11/pkcs11_object.h"
#include "pkcs11/pkcs11_slot.h"
/*
* PKCS#11 module implementation.
*/
/**
* @brief PKCS#11 interface functions implemented by this Cryptoki module.
*/
CK_FUNCTION_LIST pkcs11FunctionList =
{
{ CRYPTOKI_VERSION_MAJOR, CRYPTOKI_VERSION_MINOR },
C_Initialize,
C_Finalize,
NULL, /*C_GetInfo */
C_GetFunctionList,
C_GetSlotList,
NULL, /*C_GetSlotInfo*/
C_GetTokenInfo,
NULL, /*C_GetMechanismList*/
C_GetMechanismInfo,
C_InitToken,
NULL, /*C_InitPIN*/
NULL, /*C_SetPIN*/
C_OpenSession,
C_CloseSession,
NULL, /*C_CloseAllSessions*/
NULL, /*C_GetSessionInfo*/
NULL, /*C_GetOperationState*/
NULL, /*C_SetOperationState*/
C_Login, /*C_Login*/
NULL, /*C_Logout*/
C_CreateObject,
NULL, /*C_CopyObject*/
C_DestroyObject,
NULL, /*C_GetObjectSize*/
C_GetAttributeValue,
NULL, /*C_SetAttributeValue*/
C_FindObjectsInit,
C_FindObjects,
C_FindObjectsFinal,
NULL, /*C_EncryptInit*/
NULL, /*C_Encrypt*/
NULL, /*C_EncryptUpdate*/
NULL, /*C_EncryptFinal*/
NULL, /*C_DecryptInit*/
NULL, /*C_Decrypt*/
NULL, /*C_DecryptUpdate*/
NULL, /*C_DecryptFinal*/
C_DigestInit,
NULL, /*C_Digest*/
C_DigestUpdate,
NULL, /* C_DigestKey*/
C_DigestFinal,
C_SignInit,
C_Sign,
NULL, /*C_SignUpdate*/
NULL, /*C_SignFinal*/
NULL, /*C_SignRecoverInit*/
NULL, /*C_SignRecover*/
C_VerifyInit,
C_Verify,
NULL, /*C_VerifyUpdate*/
NULL, /*C_VerifyFinal*/
NULL, /*C_VerifyRecoverInit*/
NULL, /*C_VerifyRecover*/
NULL, /*C_DigestEncryptUpdate*/
NULL, /*C_DecryptDigestUpdate*/
NULL, /*C_SignEncryptUpdate*/
NULL, /*C_DecryptVerifyUpdate*/
NULL, /*C_GenerateKey*/
C_GenerateKeyPair,
NULL, /*C_WrapKey*/
NULL, /*C_UnwrapKey*/
NULL, /*C_DeriveKey*/
NULL, /*C_SeedRandom*/
C_GenerateRandom,
NULL, /*C_GetFunctionStatus*/
NULL, /*C_CancelFunction*/
NULL /*C_WaitForSlotEvent*/
};
static char gcPkcs11ThingNameCache[ 33 ];
const char * pcPkcs11GetThingName( void )
{
if( 0 == gcPkcs11ThingNameCache[ 0 ] )
{
CK_RV xResult;
CK_FUNCTION_LIST_PTR pxFunctionList;
CK_SLOT_ID * pxSlotId = NULL;
CK_ULONG xSlotCount;
CK_TOKEN_INFO_PTR pxTokenInfo = NULL;
xResult = C_GetFunctionList( &pxFunctionList );
if( xResult == CKR_OK )
{
xResult = xInitializePKCS11();
}
if( ( xResult == CKR_OK ) || ( xResult == CKR_CRYPTOKI_ALREADY_INITIALIZED ) )
{
xResult = xGetSlotList( &pxSlotId, &xSlotCount );
}
if( xResult == CKR_OK )
{
/* Check if token is initialized */
pxTokenInfo = pvPortMalloc( sizeof( CK_TOKEN_INFO ) );
if( pxTokenInfo != NULL )
{
/* We will take the first slot available.
* If your application has multiple slots, insert logic
* for selecting an appropriate slot here.
* TODO: Consider a define here instead.
*/
xResult = pxFunctionList->C_GetTokenInfo( pxSlotId[ 0 ], pxTokenInfo );
}
else
{
xResult = CKR_HOST_MEMORY;
}
}
if( 0 == xResult )
{
CK_CHAR_PTR end = memchr( pxTokenInfo->label, ' ', sizeof( pxTokenInfo->label ) );
memcpy( gcPkcs11ThingNameCache, pxTokenInfo->label, end - pxTokenInfo->label );
}
if( pxTokenInfo != NULL )
{
vPortFree( pxTokenInfo );
}
if( pxSlotId != NULL )
{
vPortFree( pxSlotId );
}
}
return gcPkcs11ThingNameCache;
}
#ifdef ATCA_HAL_I2C
/** \brief default configuration for an ECCx08A device */
ATCAIfaceCfg cfg_ateccx08a_i2c_default =
{
.iface_type = ATCA_I2C_IFACE,
.devtype = ATECC608A,
.atcai2c.slave_address = 0xC0,
.atcai2c.bus = 1,
.atcai2c.baud = 400000,
.wake_delay = 1500,
.rx_retries = 20
};
#endif /* ifdef ATCA_HAL_I2C */
#ifdef ATCA_HAL_KIT_HID
/** \brief default configuration for Kit protocol over the device's async interface */
ATCAIfaceCfg cfg_ateccx08a_kithid_default =
{
.iface_type = ATCA_HID_IFACE,
.devtype = ATECC608A,
.atcahid.idx = 0,
.atcahid.vid = 0x03EB,
.atcahid.pid = 0x2312,
.atcahid.packetsize = 64,
.atcahid.guid = { 0x4d, 0x1e,0x55, 0xb2, 0xf1, 0x6f, 0x11, 0xcf, 0x88, 0xcb, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 },
};
#endif /* ifdef ATCA_HAL_KIT_HID */
#ifdef AMAZON_FREERTOS_ENABLE_UNIT_TESTS
/* This configuration is only suitable for testing of a device and does not enforce good
* security policies that should be practiced in production */
const uint8_t atecc608_config[] =
{
0x01, 0x23, 0x00, 0x00, /* SN03 */
0x00, 0x00, 0x60, 0x01, /* RevNum */
0x00, 0x00, 0x00, 0x00, /* SN47 */
0xEE, /* SN8 */
0x01, /* AES_Enable */
0x01, /* I2C */
0x00, /* Reserved */
ATCA_I2C_ECC_ADDRESS, /* I2C Address */
0x00, /* Reserved 2 */
0x00, /* Count match */
0x01, /* Chip mode */
0x85, 0x66, /* SlotConfig 0 */
0x82, 0x00, /*1 */
0x85, 0x66, /*2 */
0x85, 0x20, /*3 */
0x85, 0x20, /*4 */
0xC6, 0x46, /*5 */
0x8F, 0x0F, /*6 */
0x9F, 0x8F, /*7 */
0x0F, 0x0F, /*8 */
0x8F, 0x0F, /*9 */
0x0F, 0x0F, /*10 */
0x0F, 0x0F, /*11 */
0x0F, 0x0F, /*12 */
0x0F, 0x0F, /*13 */
0x0D, 0x1F, /*14 */
0x0F, 0x0F, /*15 */
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, /* Counter0 */
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, /* Counter1 */
0x00, /* Use Lock */
0x00, /* Volatile Key Permission */
0x03, 0xF7,
0x00,
0x69, 0x76,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Reserve3 */
0x00, /* User Extra */
0x00, /* UserExtraAdd */
0x55, /* Lock Value */
0x55, /* Lock Config */
0xFF, 0xFF, /* Slot locked. */
0x0E, 0x60, /* Chip options */
0x00, 0x00, 0x00, 0x00, /* X509 Format */
0x53, 0x00, /* KeyConfig[0] */
0x53, 0x00, /*1 */
0x53, 0x00, /*2 */
0x73, 0x00, /*3 */
0x73, 0x00, /*4 */
0x38, 0x00, /*5 */
0x7C, 0x00, /*6 */
0x1C, 0x00, /*7 */
0x3C, 0x00, /*8 */
0x1A, 0x00, /*9 */
0x3C, 0x00, /*10 */
0x30, 0x00, /*11 */
0x3C, 0x00, /*12 */
0x30, 0x00, /*13 */
0x12, 0x00, /*14 */
0x30, 0x00 /*15 */
};
#else /* ifdef AMAZON_FREERTOS_ENABLE_UNIT_TESTS */
/** Standard Configuration Structure for ATECC608A devices */
const uint8_t atecc608_config[] =
{
0x01, 0x23, 0x00, 0x00, 0x00, 0x00, 0x60, 0x01, 0x00, 0x00, 0x00, 0x00, 0xEE, 0x01, 0x01, 0x00,
ATCA_I2C_ECC_ADDRESS, 0x00, 0x00, 0x01, 0x8F, 0x20, 0xC4, 0x44, 0x87, 0x20, 0x87, 0x20, 0x8F, 0x0F, 0xC4, 0x36,
0x9F, 0x0F, 0x82, 0x20, 0x0F, 0x0F, 0xC4, 0x44, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
0x0F, 0x0F, 0x0F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x33, 0x00, 0x1C, 0x00, 0x13, 0x00, 0x13, 0x00, 0x7C, 0x00, 0x1C, 0x00, 0x3C, 0x00, 0x33, 0x00,
0x3C, 0x00, 0x3C, 0x00, 0x3C, 0x00, 0x30, 0x00, 0x3C, 0x00, 0x3C, 0x00, 0x3C, 0x00, 0x30, 0x00,
};
#endif /* ifdef AMAZON_FREERTOS_ENABLE_UNIT_TESTS */
/* Helper function to assign the proper fields to an certificate object from a cert def */
CK_RV pkcs11_config_cert( pkcs11_lib_ctx_ptr pLibCtx,
pkcs11_slot_ctx_ptr pSlot,
pkcs11_object_ptr pObject,
CK_ATTRIBUTE_PTR pLabel )
{
CK_RV rv = CKR_OK;
size_t len;
( void ) pLibCtx;
( void ) pSlot;
if( !pObject || !pLabel )
{
return CKR_ARGUMENTS_BAD;
}
if( pLabel->ulValueLen >= PKCS11_MAX_LABEL_SIZE )
{
return CKR_ARGUMENTS_BAD;
}
if( !strncmp( pkcs11configLABEL_DEVICE_CERTIFICATE_FOR_TLS, ( char * ) pLabel->pValue, pLabel->ulValueLen ) )
{
/* Slot 10 - Device Cert for Slot 0*/
pkcs11_config_init_cert( pObject, pLabel->pValue, pLabel->ulValueLen );
pObject->slot = 10;
pObject->class_type = CK_CERTIFICATE_CATEGORY_TOKEN_USER;
pObject->size = g_cert_def_2_device.cert_template_size;
pObject->data = &g_cert_def_2_device;
#ifdef AMAZON_FREERTOS_ENABLE_UNIT_TESTS
pObject->flags = PKCS11_OBJECT_FLAG_DESTROYABLE;
#endif
}
else if( !strncmp( pkcs11configLABEL_JITP_CERTIFICATE, ( char * ) pLabel->pValue, pLabel->ulValueLen ) )
{
/* Slot 12 - Signer Cert for Slot 10 */
pkcs11_config_init_cert( pObject, pLabel->pValue, pLabel->ulValueLen );
pObject->slot = 12;
pObject->class_type = CK_CERTIFICATE_CATEGORY_AUTHORITY;
pObject->size = g_cert_def_1_signer.cert_template_size;
pObject->data = &g_cert_def_1_signer;
#ifdef AMAZON_FREERTOS_ENABLE_UNIT_TESTS
pObject->flags = PKCS11_OBJECT_FLAG_DESTROYABLE;
#endif
}
#ifdef pkcs11testLABEL_DEVICE_CERTIFICATE_FOR_TLS
else if( !strncmp( pkcs11testLABEL_DEVICE_CERTIFICATE_FOR_TLS, ( char * ) pLabel->pValue, pLabel->ulValueLen ) )
{
/* Slot 10 - Device Cert for Slot 0*/
pkcs11_config_init_cert( pObject, pLabel->pValue, pLabel->ulValueLen );
pObject->slot = 2;
pObject->class_type = CK_CERTIFICATE_CATEGORY_TOKEN_USER;
pObject->size = g_cert_def_3_test.cert_template_size;
pObject->data = &g_cert_def_3_test;
pObject->flags = PKCS11_OBJECT_FLAG_DESTROYABLE;
}
#endif /* ifdef pkcs11testLABEL_DEVICE_CERTIFICATE_FOR_TLS */
else
{
rv = CKR_ARGUMENTS_BAD;
}
return rv;
}
/* Helper function to assign the proper fields to a key object */
CK_RV pkcs11_config_key( pkcs11_lib_ctx_ptr pLibCtx,
pkcs11_slot_ctx_ptr pSlot,
pkcs11_object_ptr pObject,
CK_ATTRIBUTE_PTR pLabel )
{
CK_RV rv = CKR_OK;
size_t len;
( void ) pLibCtx;
if( !pObject || !pLabel || !pSlot )
{
return CKR_ARGUMENTS_BAD;
}
if( pLabel->ulValueLen >= PKCS11_MAX_LABEL_SIZE )
{
return CKR_ARGUMENTS_BAD;
}
if( !strncmp( pkcs11configLABEL_DEVICE_PRIVATE_KEY_FOR_TLS, ( char * ) pLabel->pValue, pLabel->ulValueLen ) )
{
/* Slot 0 - Device Private Key */
pkcs11_config_init_private( pObject, pLabel->pValue, pLabel->ulValueLen );
pObject->slot = 0;
pObject->config = &pSlot->cfg_zone;
#ifdef AMAZON_FREERTOS_ENABLE_UNIT_TESTS
pObject->flags = PKCS11_OBJECT_FLAG_DESTROYABLE;
#endif
}
else if( !strncmp( pkcs11configLABEL_DEVICE_PUBLIC_KEY_FOR_TLS, ( char * ) pLabel->pValue, pLabel->ulValueLen ) )
{
/* Slot 0 - Device Private Key */
pkcs11_config_init_public( pObject, pLabel->pValue, pLabel->ulValueLen );
pObject->slot = 0;
pObject->config = &pSlot->cfg_zone;
#ifdef AMAZON_FREERTOS_ENABLE_UNIT_TESTS
pObject->flags = PKCS11_OBJECT_FLAG_DESTROYABLE;
#endif
}
#ifdef pkcs11testLABEL_DEVICE_PRIVATE_KEY_FOR_TLS
else if( !strncmp( pkcs11testLABEL_DEVICE_PRIVATE_KEY_FOR_TLS, ( char * ) pLabel->pValue, pLabel->ulValueLen ) )
{
/* Slot 0 - Device Private Key */
pkcs11_config_init_private( pObject, pLabel->pValue, pLabel->ulValueLen );
pObject->slot = 2;
pObject->config = &pSlot->cfg_zone;
pObject->flags = PKCS11_OBJECT_FLAG_DESTROYABLE;
}
#endif
#ifdef pkcs11testLABEL_DEVICE_PUBLIC_KEY_FOR_TLS
else if( !strncmp( pkcs11testLABEL_DEVICE_PUBLIC_KEY_FOR_TLS, ( char * ) pLabel->pValue, pLabel->ulValueLen ) )
{
/* Slot 0 - Device Private Key */
pkcs11_config_init_public( pObject, pLabel->pValue, pLabel->ulValueLen );
pObject->slot = 2;
pObject->config = &pSlot->cfg_zone;
pObject->flags = PKCS11_OBJECT_FLAG_DESTROYABLE;
}
#endif
else
{
rv = CKR_ARGUMENTS_BAD;
}
return rv;
}
CK_RV pkcs11_config_load_objects( pkcs11_slot_ctx_ptr pSlot )
{
pkcs11_object_ptr pObject;
CK_RV rv = CKR_OK;
CK_ATTRIBUTE xLabel;
if( CKR_OK == rv )
{
rv = pkcs11_object_alloc( &pObject );
if( pObject )
{
/* Slot 0 - Device Private Key */
xLabel.pValue = pkcs11configLABEL_DEVICE_PRIVATE_KEY_FOR_TLS;
xLabel.ulValueLen = strlen( xLabel.pValue );
xLabel.type = CKA_LABEL;
pkcs11_config_key( NULL, pSlot, pObject, &xLabel );
}
}
if( CKR_OK == rv )
{
rv = pkcs11_object_alloc( &pObject );
if( pObject )
{
/* Slot 0 - Device Public Key */
xLabel.pValue = pkcs11configLABEL_DEVICE_PUBLIC_KEY_FOR_TLS;
xLabel.ulValueLen = strlen( xLabel.pValue );
xLabel.type = CKA_LABEL;
pkcs11_config_key( NULL, pSlot, pObject, &xLabel );
}
}
if( CKR_OK == rv )
{
rv = pkcs11_object_alloc( &pObject );
if( pObject )
{
/* Slot 0 - Device Public Key */
xLabel.pValue = pkcs11configLABEL_DEVICE_CERTIFICATE_FOR_TLS;
xLabel.ulValueLen = strlen( xLabel.pValue );
xLabel.type = CKA_LABEL;
pkcs11_config_cert( NULL, pSlot, pObject, &xLabel );
}
}
if( CKR_OK == rv )
{
rv = pkcs11_object_alloc( &pObject );
if( pObject )
{
/* Slot 0 - Device Public Key */
xLabel.pValue = pkcs11configLABEL_JITP_CERTIFICATE;
xLabel.ulValueLen = strlen( xLabel.pValue );
xLabel.type = CKA_LABEL;
pkcs11_config_cert( NULL, pSlot, pObject, &xLabel );
}
}
#ifdef pkcs11testLABEL_DEVICE_PRIVATE_KEY_FOR_TLS
if( CKR_OK == rv )
{
rv = pkcs11_object_alloc( &pObject );
if( pObject )
{
/* Slot 0 - Device Private Key */
xLabel.pValue = pkcs11testLABEL_DEVICE_PRIVATE_KEY_FOR_TLS;
xLabel.ulValueLen = strlen( xLabel.pValue );
xLabel.type = CKA_LABEL;
pkcs11_config_key( NULL, pSlot, pObject, &xLabel );
}
}
#endif /* ifdef pkcs11testLABEL_DEVICE_PRIVATE_KEY_FOR_TLS */
#ifdef pkcs11testLABEL_DEVICE_PUBLIC_KEY_FOR_TLS
if( CKR_OK == rv )
{
rv = pkcs11_object_alloc( &pObject );
if( pObject )
{
/* Slot 0 - Device Public Key */
xLabel.pValue = pkcs11testLABEL_DEVICE_PUBLIC_KEY_FOR_TLS;
xLabel.ulValueLen = strlen( xLabel.pValue );
xLabel.type = CKA_LABEL;
pkcs11_config_key( NULL, pSlot, pObject, &xLabel );
}
}
#endif /* ifdef pkcs11testLABEL_DEVICE_PUBLIC_KEY_FOR_TLS */
#ifdef pkcs11testLABEL_DEVICE_CERTIFICATE_FOR_TLS
if( CKR_OK == rv )
{
rv = pkcs11_object_alloc( &pObject );
if( pObject )
{
/* Slot 0 - Device Public Key */
xLabel.pValue = pkcs11testLABEL_DEVICE_CERTIFICATE_FOR_TLS;
xLabel.ulValueLen = strlen( xLabel.pValue );
xLabel.type = CKA_LABEL;
pkcs11_config_cert( NULL, pSlot, pObject, &xLabel );
}
}
#endif /* ifdef pkcs11testLABEL_DEVICE_CERTIFICATE_FOR_TLS */
return rv;
}