From 66b0b0a5a07422b2e4a7a75f32a82d254f57371f Mon Sep 17 00:00:00 2001 From: chinglee-iot <61685396+chinglee-iot@users.noreply.github.com> Date: Tue, 16 Apr 2024 14:11:57 +0800 Subject: [PATCH] Update corePKCS11 submodule pointer (#1208) * Update corePKCS11 submodule pointer * Fix corePKCS11 MQTT mutual authenticated demo * Sync with other demo to wait for network up. * Fix compiler warning. --- .../PKCS11_Mqtt_MutualAuthDemo.c | 15 +++++++++++++++ .../main.c | 2 ++ .../network_transport/mbedtls_pk_pkcs11.c | 10 +++++----- .../network_transport/transport_mbedtls_pkcs11.c | 5 ++--- FreeRTOS-Plus/Source/corePKCS11 | 2 +- .../corePKCS11/corePKCS11.vcxproj | 8 ++++---- manifest.yml | 2 +- 7 files changed, 30 insertions(+), 14 deletions(-) diff --git a/FreeRTOS-Plus/Demo/corePKCS11_MQTT_Mutual_Auth_Windows_Simulator/PKCS11_Mqtt_MutualAuthDemo.c b/FreeRTOS-Plus/Demo/corePKCS11_MQTT_Mutual_Auth_Windows_Simulator/PKCS11_Mqtt_MutualAuthDemo.c index 2ecde1989..c403a6396 100644 --- a/FreeRTOS-Plus/Demo/corePKCS11_MQTT_Mutual_Auth_Windows_Simulator/PKCS11_Mqtt_MutualAuthDemo.c +++ b/FreeRTOS-Plus/Demo/corePKCS11_MQTT_Mutual_Auth_Windows_Simulator/PKCS11_Mqtt_MutualAuthDemo.c @@ -304,6 +304,10 @@ static MQTTStatus_t prvProcessLoopWithTimeout( MQTTContext_t * pMqttContext, /*-----------------------------------------------------------*/ +extern BaseType_t xPlatformIsNetworkUp( void ); + +/*-----------------------------------------------------------*/ + /* @brief Static buffer used to hold MQTT messages being sent and received. */ static uint8_t ucSharedBuffer[ democonfigNETWORK_BUFFER_SIZE ]; @@ -416,7 +420,18 @@ static void prvMQTTDemoTask( void * pvParameters ) for( ; ; ) { LogInfo( ( "---------STARTING DEMO---------\r\n" ) ); + /****************************** Connect. ******************************/ + /* Wait for Networking */ + if( xPlatformIsNetworkUp() == pdFALSE ) + { + LogInfo( ( "Waiting for the network link up event..." ) ); + + while( xPlatformIsNetworkUp() == pdFALSE ) + { + vTaskDelay( pdMS_TO_TICKS( 1000U ) ); + } + } /* Establish a TLS connection with the MQTT broker. This example connects * to the MQTT broker as specified by democonfigMQTT_BROKER_ENDPOINT and diff --git a/FreeRTOS-Plus/Demo/corePKCS11_MQTT_Mutual_Auth_Windows_Simulator/main.c b/FreeRTOS-Plus/Demo/corePKCS11_MQTT_Mutual_Auth_Windows_Simulator/main.c index 5ac4da7cc..7c1e0b91c 100644 --- a/FreeRTOS-Plus/Demo/corePKCS11_MQTT_Mutual_Auth_Windows_Simulator/main.c +++ b/FreeRTOS-Plus/Demo/corePKCS11_MQTT_Mutual_Auth_Windows_Simulator/main.c @@ -52,6 +52,8 @@ extern void vPlatformInitIpStack( void ); +extern void vStartPKCSMutualAuthDemo( void ); + /*-----------------------------------------------------------*/ int main( void ) diff --git a/FreeRTOS-Plus/Source/Application-Protocols/network_transport/mbedtls_pk_pkcs11.c b/FreeRTOS-Plus/Source/Application-Protocols/network_transport/mbedtls_pk_pkcs11.c index d7fae482e..1cea0e9d7 100644 --- a/FreeRTOS-Plus/Source/Application-Protocols/network_transport/mbedtls_pk_pkcs11.c +++ b/FreeRTOS-Plus/Source/Application-Protocols/network_transport/mbedtls_pk_pkcs11.c @@ -849,7 +849,7 @@ static int p11_ecdsa_check_pair( const void * pvPub, }; unsigned char pucTestSignature[ MBEDTLS_ECDSA_MAX_SIG_LEN( 256 ) ] = { 0 }; size_t uxSigLen = 0; - lResult = p11_ecdsa_sign( pxMbedtlsPkCtx, MBEDTLS_MD_SHA256, + lResult = p11_ecdsa_sign( ( mbedtls_pk_context * ) pxMbedtlsPkCtx, MBEDTLS_MD_SHA256, pucTestHash, sizeof( pucTestHash ), pucTestSignature, sizeof( pucTestSignature ), &uxSigLen, NULL, NULL ); @@ -883,7 +883,7 @@ static size_t p11_rsa_get_bitlen( const mbedtls_pk_context * pxMbedtlsPkCtx ) configASSERT( mbedtls_rsa_info.get_bitlen ); - return mbedtls_rsa_info.get_bitlen( pxMbedtlsPkCtx ); + return mbedtls_rsa_info.get_bitlen( ( mbedtls_pk_context * ) pxMbedtlsPkCtx ); } /*-----------------------------------------------------------*/ @@ -1009,8 +1009,8 @@ static int p11_rsa_check_pair( const void * pvPub, { configASSERT( mbedtls_rsa_info.check_pair_func ); - return mbedtls_rsa_info.check_pair_func( pvPub, - pxMbedtlsPkCtx, + return mbedtls_rsa_info.check_pair_func( ( void * ) pvPub, + ( mbedtls_pk_context * ) pxMbedtlsPkCtx, lFRng, pvPRng ); } @@ -1112,7 +1112,7 @@ static void p11_rsa_debug( const mbedtls_pk_context * pxMbedtlsPkCtx, { configASSERT( mbedtls_rsa_info.debug_func ); - mbedtls_rsa_info.debug_func( pxMbedtlsPkCtx, pxItems ); + mbedtls_rsa_info.debug_func( ( mbedtls_pk_context * ) pxMbedtlsPkCtx, pxItems ); } /*-----------------------------------------------------------*/ diff --git a/FreeRTOS-Plus/Source/Application-Protocols/network_transport/transport_mbedtls_pkcs11.c b/FreeRTOS-Plus/Source/Application-Protocols/network_transport/transport_mbedtls_pkcs11.c index 8056e95fa..10d826c65 100644 --- a/FreeRTOS-Plus/Source/Application-Protocols/network_transport/transport_mbedtls_pkcs11.c +++ b/FreeRTOS-Plus/Source/Application-Protocols/network_transport/transport_mbedtls_pkcs11.c @@ -569,7 +569,7 @@ static CK_RV readCertificateIntoContext( SSLContext_t * pSslContext, /* Get the handle of the certificate. */ xResult = xFindObjectWithLabelAndClass( pSslContext->xP11Session, - pcLabelName, + ( char * ) pcLabelName, strnlen( pcLabelName, pkcs11configMAX_LABEL_LENGTH ), xClass, @@ -643,7 +643,6 @@ static CK_RV initializeClientKeys( SSLContext_t * pxCtx, CK_RV xResult = CKR_OK; CK_SLOT_ID * pxSlotIds = NULL; CK_ULONG xCount = 0; - CK_ATTRIBUTE xTemplate[ 2 ]; mbedtls_pk_type_t xKeyAlgo = ( mbedtls_pk_type_t ) ~0; /* Get the PKCS #11 module/token slot count. */ @@ -686,7 +685,7 @@ static CK_RV initializeClientKeys( SSLContext_t * pxCtx, { /* Get the handle of the device private key. */ xResult = xFindObjectWithLabelAndClass( pxCtx->xP11Session, - pcLabelName, + ( char * ) pcLabelName, strnlen( pcLabelName, pkcs11configMAX_LABEL_LENGTH ), CKO_PRIVATE_KEY, diff --git a/FreeRTOS-Plus/Source/corePKCS11 b/FreeRTOS-Plus/Source/corePKCS11 index cb865c1a2..59875a9aa 160000 --- a/FreeRTOS-Plus/Source/corePKCS11 +++ b/FreeRTOS-Plus/Source/corePKCS11 @@ -1 +1 @@ -Subproject commit cb865c1a25de899c598b1ca47571f9f74b60a118 +Subproject commit 59875a9aa3f08a95eb8cdc0ba345b38dc49134ab diff --git a/FreeRTOS-Plus/VisualStudio_StaticProjects/corePKCS11/corePKCS11.vcxproj b/FreeRTOS-Plus/VisualStudio_StaticProjects/corePKCS11/corePKCS11.vcxproj index 6f12f846a..00cd8b5bf 100644 --- a/FreeRTOS-Plus/VisualStudio_StaticProjects/corePKCS11/corePKCS11.vcxproj +++ b/FreeRTOS-Plus/VisualStudio_StaticProjects/corePKCS11/corePKCS11.vcxproj @@ -43,11 +43,11 @@ - ..\..\Source\corePKCS11\source\include;..\..\Source\corePKCS11\source\dependency\3rdparty\mbedtls_utils;..\..\Source\corePKCS11\source\dependency\3rdparty\pkcs11;.\ + ..\..\Source\corePKCS11\source\include;..\..\Source\corePKCS11\source\dependency\3rdparty\mbedtls_utils;..\..\Source\corePKCS11\source\dependency\3rdparty\pkcs11\published\2-40-errata-1;.\ true - ..\..\Source\corePKCS11\source\include;..\..\Source\corePKCS11\source\dependency\3rdparty\mbedtls_utils;..\..\Source\corePKCS11\source\dependency\3rdparty\pkcs11;.\ + ..\..\Source\corePKCS11\source\include;..\..\Source\corePKCS11\source\dependency\3rdparty\mbedtls_utils;..\..\Source\corePKCS11\source\dependency\3rdparty\pkcs11\published\2-40-errata-1;.\ true @@ -56,7 +56,7 @@ true WIN32;WIN32_LEAN_AND_MEAN;MBEDTLS_CONFIG_FILE="mbedtls_config_v3.5.1.h";_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - ..\..\Source\corePKCS11\source\include;..\..\Source\corePKCS11\source\portable\os;..\..\Source\corePKCS11\source\portable\os\freertos_winsim;..\..\Source\corePKCS11\source\dependency\3rdparty\mbedtls_utils;..\..\Source\corePKCS11\source\dependency\3rdparty\pkcs11;.\;%(AdditionalIncludeDirectories) + ..\..\Source\corePKCS11\source\include;..\..\Source\corePKCS11\source\portable\os;..\..\Source\corePKCS11\source\portable\os\freertos_winsim;..\..\Source\corePKCS11\source\dependency\3rdparty\mbedtls_utils;..\..\Source\corePKCS11\source\dependency\3rdparty\pkcs11\published\2-40-errata-1;.\;%(AdditionalIncludeDirectories) true @@ -70,7 +70,7 @@ true MBEDTLS_CONFIG_FILE="mbedtls_config_v3.5.1.h";WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - ..\..\Source\corePKCS11\source\include;..\..\Source\corePKCS11\source\portable\os;..\..\Source\corePKCS11\source\portable\os\freertos_winsim;..\..\Source\corePKCS11\source\dependency\3rdparty\mbedtls_utils;..\..\Source\corePKCS11\source\dependency\3rdparty\pkcs11;.\;%(AdditionalIncludeDirectories) + ..\..\Source\corePKCS11\source\include;..\..\Source\corePKCS11\source\portable\os;..\..\Source\corePKCS11\source\portable\os\freertos_winsim;..\..\Source\corePKCS11\source\dependency\3rdparty\mbedtls_utils;..\..\Source\corePKCS11\source\dependency\3rdparty\pkcs11\published\2-40-errata-1;.\;%(AdditionalIncludeDirectories) true diff --git a/manifest.yml b/manifest.yml index 6f38faab0..931b1b069 100644 --- a/manifest.yml +++ b/manifest.yml @@ -54,7 +54,7 @@ dependencies: path: "FreeRTOS-Plus/Source/Application-Protocols/coreMQTT-Agent" - name: "corePKCS11" - version: "cb865c1" + version: "59875a9" repository: type: "git" url: "https://github.com/FreeRTOS/corePKCS11.git"