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

Commit

Permalink
Fix OTA PAL test for Nordic (#1444)
Browse files Browse the repository at this point in the history
* Fix OTA PAL test for Nordic

* Uncrustify
  • Loading branch information
ravibhagavandas authored and pavanmr94 committed Oct 22, 2019
1 parent 0252630 commit 9076d94
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 54 deletions.
95 changes: 51 additions & 44 deletions libraries/freertos_plus/aws/ota/test/aws_test_ota_pal.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@
#include "aws_ota_pal_test_access_declare.h"
#include "aws_ota_pal.h"
#include "aws_iot_ota_agent.h"
#include "iot_pkcs11.h"
#include "iot_pkcs11_config.h"

#if ( otatestpalREAD_CERTIFICATE_FROM_NVM_WITH_PKCS11 == 1 )
#include "iot_pkcs11.h"
#include "iot_pkcs11_config.h"
#include "aws_dev_mode_key_provisioning.h"
#endif

#include "aws_ota_codesigner_certificate.h"
#include "aws_test_ota_config.h"
#include "aws_dev_mode_key_provisioning.h"


/* The Texas Instruments CC3220SF has special requirements on its file system security.
* We enable code specially for testing the OTA PAL layer for this device. */
Expand Down Expand Up @@ -229,54 +234,56 @@ TEST( Full_OTA_PAL, prvPAL_CloseFile_ValidSignature )
TEST_ASSERT_EQUAL_INT( kOTA_Err_None, xOtaStatus );
}
}

CK_RV prvImportCodeSigningCertificate( const uint8_t * pucCertificate,
size_t xCertificateLength,
uint8_t * pucLabel )
{
/* Find the certificate */
CK_OBJECT_HANDLE xHandle;
CK_RV xResult;
CK_FUNCTION_LIST_PTR xFunctionList;
CK_SLOT_ID xSlotId;
CK_ULONG xCount = 1;
CK_SESSION_HANDLE xSession;
CK_BBOOL xSessionOpen = CK_FALSE;

xResult = C_GetFunctionList( &xFunctionList );

if( CKR_OK == xResult )
#if ( otatestpalREAD_CERTIFICATE_FROM_NVM_WITH_PKCS11 == 1 )
CK_RV prvImportCodeSigningCertificate( const uint8_t * pucCertificate,
size_t xCertificateLength,
uint8_t * pucLabel )
{
xResult = xInitializePKCS11();
}
/* Find the certificate */
CK_OBJECT_HANDLE xHandle;
CK_RV xResult;
CK_FUNCTION_LIST_PTR xFunctionList;
CK_SLOT_ID xSlotId;
CK_ULONG xCount = 1;
CK_SESSION_HANDLE xSession;
CK_BBOOL xSessionOpen = CK_FALSE;

if( ( CKR_OK == xResult ) || ( CKR_CRYPTOKI_ALREADY_INITIALIZED == xResult ) )
{
xResult = xFunctionList->C_GetSlotList( CK_TRUE, &xSlotId, &xCount );
}
xResult = C_GetFunctionList( &xFunctionList );

if( CKR_OK == xResult )
{
xResult = xFunctionList->C_OpenSession( xSlotId, CKF_SERIAL_SESSION, NULL, NULL, &xSession );
}
if( CKR_OK == xResult )
{
xResult = xInitializePKCS11();
}

if( CKR_OK == xResult )
{
xSessionOpen = CK_TRUE;
xResult = xProvisionCertificate( xSession,
( uint8_t * ) pucCertificate,
xCertificateLength,
pucLabel,
&xHandle );
}
if( ( CKR_OK == xResult ) || ( CKR_CRYPTOKI_ALREADY_INITIALIZED == xResult ) )
{
xResult = xFunctionList->C_GetSlotList( CK_TRUE, &xSlotId, &xCount );
}

if( xSessionOpen == CK_TRUE )
{
xResult = xFunctionList->C_CloseSession( xSession );
if( CKR_OK == xResult )
{
xResult = xFunctionList->C_OpenSession( xSlotId, CKF_SERIAL_SESSION, NULL, NULL, &xSession );
}

if( CKR_OK == xResult )
{
xSessionOpen = CK_TRUE;
xResult = xProvisionCertificate( xSession,
( uint8_t * ) pucCertificate,
xCertificateLength,
pucLabel,
&xHandle );
}

if( xSessionOpen == CK_TRUE )
{
xResult = xFunctionList->C_CloseSession( xSession );
}

return xResult;
}

return xResult;
}
#endif /* if ( otatestpalREAD_CERTIFICATE_FROM_NVM_WITH_PKCS11 == 1 ) */

/**
* @brief Test prvPAL_CloseFile with a valid signature and signature verification
Expand Down
10 changes: 0 additions & 10 deletions vendors/nordic/boards/nrf52840-dk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -331,18 +331,9 @@ set(
"${nrf5_sdk}/components"
"${nrf5_sdk}/components/ble/common"
"${nrf5_sdk}/components/boards"
"${nrf5_sdk}/components/device"
"${nrf5_sdk}/components/drivers_nrf/clock"
"${nrf5_sdk}/components/drivers_nrf/common"
"${nrf5_sdk}/components/drivers_nrf/delay"
"${nrf5_sdk}/components/drivers_nrf/gpiote"
"${nrf5_sdk}/components/ble/nrf_ble_gatt"
"${nrf5_sdk}/components/ble/ble_services/ble_nus"
"${nrf5_sdk}/components/ble/nrf_ble_qwr"
"${nrf5_sdk}/components/drivers_nrf/hal"
"${nrf5_sdk}/components/drivers_nrf/rng"
"${nrf5_sdk}/components/drivers_nrf/timer"
"${nrf5_sdk}/components/drivers_nrf/wdt"
"${nrf5_sdk}/components/libraries/atomic"
"${nrf5_sdk}/components/libraries/balloc"
"${nrf5_sdk}/components/libraries/bsp"
Expand Down Expand Up @@ -450,7 +441,6 @@ target_link_libraries(
AFR::ota::mcu_port
INTERFACE
AFR::crypto
AFR::pkcs11
)

# POSIX
Expand Down

0 comments on commit 9076d94

Please sign in to comment.