Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

Commit 53b496f

Browse files
supreetd21dan4thewin
authored andcommitted
feat/espressif_jitp_cert_fix: Fixes the handline of JITP certs (#1520)
Description: In the PAL layer(iot_pkcs_pal.c) adding the handling for fetching the JITP certificate from NVS.
1 parent 3367c26 commit 53b496f

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

vendors/espressif/boards/esp32/ports/pkcs11/iot_pkcs11_pal.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,16 @@ static const char *TAG = "PKCS11";
4444
#define pkcs11palFILE_NAME_CLIENT_CERTIFICATE "P11_Cert"
4545
#define pkcs11palFILE_NAME_KEY "P11_Key"
4646
#define pkcs11palFILE_CODE_SIGN_PUBLIC_KEY "P11_CSK"
47+
#define pkcs11palFILE_JITP_CERTIFICATE "P11_JITP"
4748

4849
enum eObjectHandles
4950
{
5051
eInvalidHandle = 0, /* According to PKCS #11 spec, 0 is never a valid object handle. */
5152
eAwsDevicePrivateKey = 1,
5253
eAwsDevicePublicKey,
5354
eAwsDeviceCertificate,
54-
eAwsCodeSigningKey
55+
eAwsCodeSigningKey,
56+
eAwsJITPCertificate
5557
};
5658
/*-----------------------------------------------------------*/
5759

@@ -86,6 +88,7 @@ static void initialize_nvs_partition()
8688

8789
esp_err_t ret = nvs_flash_secure_init_partition(NVS_PART_NAME, &cfg);
8890
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
91+
ESP_LOGW(TAG, "Error initialising the NVS partition [%d]. Erasing the partition.", ret);
8992
ESP_ERROR_CHECK(nvs_flash_erase_partition(NVS_PART_NAME));
9093
ret = nvs_flash_secure_init_partition(NVS_PART_NAME, &cfg);
9194
}
@@ -94,6 +97,7 @@ static void initialize_nvs_partition()
9497
#endif // CONFIG_NVS_ENCRYPTION
9598
esp_err_t ret = nvs_flash_init_partition(NVS_PART_NAME);
9699
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
100+
ESP_LOGW(TAG, "Error initialising the NVS partition [%d]. Erasing the partition.", ret);
97101
ESP_ERROR_CHECK(nvs_flash_erase_partition(NVS_PART_NAME));
98102
ret = nvs_flash_init_partition(NVS_PART_NAME);
99103
}
@@ -143,6 +147,13 @@ void prvLabelToFilenameHandle( uint8_t * pcLabel,
143147
*pcFileName = pkcs11palFILE_CODE_SIGN_PUBLIC_KEY;
144148
*pHandle = eAwsCodeSigningKey;
145149
}
150+
else if( 0 == memcmp( pcLabel,
151+
pkcs11configLABEL_JITP_CERTIFICATE,
152+
strlen( (char*)pkcs11configLABEL_JITP_CERTIFICATE ) ) )
153+
{
154+
*pcFileName = pkcs11palFILE_JITP_CERTIFICATE;
155+
*pHandle = eAwsJITPCertificate;
156+
}
146157
else
147158
{
148159
*pcFileName = NULL;
@@ -300,6 +311,11 @@ CK_RV PKCS11_PAL_GetObjectValue( CK_OBJECT_HANDLE xHandle,
300311
pcFileName = pkcs11palFILE_CODE_SIGN_PUBLIC_KEY;
301312
*pIsPrivate = CK_FALSE;
302313
}
314+
else if( xHandle == eAwsJITPCertificate )
315+
{
316+
pcFileName = pkcs11palFILE_JITP_CERTIFICATE;
317+
*pIsPrivate = CK_FALSE;
318+
}
303319
else
304320
{
305321
ulReturn = CKR_OBJECT_HANDLE_INVALID;

0 commit comments

Comments
 (0)