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

Commit

Permalink
feat/espressif_jitp_cert_fix: Fixes the handline of JITP certs (#1520)
Browse files Browse the repository at this point in the history
Description:
In the PAL layer(iot_pkcs_pal.c) adding the handling for fetching the JITP certificate from NVS.
  • Loading branch information
supreetd21 authored and dan4thewin committed Dec 2, 2019
1 parent 3367c26 commit 53b496f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion vendors/espressif/boards/esp32/ports/pkcs11/iot_pkcs11_pal.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ static const char *TAG = "PKCS11";
#define pkcs11palFILE_NAME_CLIENT_CERTIFICATE "P11_Cert"
#define pkcs11palFILE_NAME_KEY "P11_Key"
#define pkcs11palFILE_CODE_SIGN_PUBLIC_KEY "P11_CSK"
#define pkcs11palFILE_JITP_CERTIFICATE "P11_JITP"

enum eObjectHandles
{
eInvalidHandle = 0, /* According to PKCS #11 spec, 0 is never a valid object handle. */
eAwsDevicePrivateKey = 1,
eAwsDevicePublicKey,
eAwsDeviceCertificate,
eAwsCodeSigningKey
eAwsCodeSigningKey,
eAwsJITPCertificate
};
/*-----------------------------------------------------------*/

Expand Down Expand Up @@ -86,6 +88,7 @@ static void initialize_nvs_partition()

esp_err_t ret = nvs_flash_secure_init_partition(NVS_PART_NAME, &cfg);
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_LOGW(TAG, "Error initialising the NVS partition [%d]. Erasing the partition.", ret);
ESP_ERROR_CHECK(nvs_flash_erase_partition(NVS_PART_NAME));
ret = nvs_flash_secure_init_partition(NVS_PART_NAME, &cfg);
}
Expand All @@ -94,6 +97,7 @@ static void initialize_nvs_partition()
#endif // CONFIG_NVS_ENCRYPTION
esp_err_t ret = nvs_flash_init_partition(NVS_PART_NAME);
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_LOGW(TAG, "Error initialising the NVS partition [%d]. Erasing the partition.", ret);
ESP_ERROR_CHECK(nvs_flash_erase_partition(NVS_PART_NAME));
ret = nvs_flash_init_partition(NVS_PART_NAME);
}
Expand Down Expand Up @@ -143,6 +147,13 @@ void prvLabelToFilenameHandle( uint8_t * pcLabel,
*pcFileName = pkcs11palFILE_CODE_SIGN_PUBLIC_KEY;
*pHandle = eAwsCodeSigningKey;
}
else if( 0 == memcmp( pcLabel,
pkcs11configLABEL_JITP_CERTIFICATE,
strlen( (char*)pkcs11configLABEL_JITP_CERTIFICATE ) ) )
{
*pcFileName = pkcs11palFILE_JITP_CERTIFICATE;
*pHandle = eAwsJITPCertificate;
}
else
{
*pcFileName = NULL;
Expand Down Expand Up @@ -300,6 +311,11 @@ CK_RV PKCS11_PAL_GetObjectValue( CK_OBJECT_HANDLE xHandle,
pcFileName = pkcs11palFILE_CODE_SIGN_PUBLIC_KEY;
*pIsPrivate = CK_FALSE;
}
else if( xHandle == eAwsJITPCertificate )
{
pcFileName = pkcs11palFILE_JITP_CERTIFICATE;
*pIsPrivate = CK_FALSE;
}
else
{
ulReturn = CKR_OBJECT_HANDLE_INVALID;
Expand Down

0 comments on commit 53b496f

Please sign in to comment.