Skip to content

Commit

Permalink
Not going to do the weird thing of an empty body ifndef just for MISR…
Browse files Browse the repository at this point in the history
…A, just going to add a log message instead. Include the mbedtls config file if defined in core_pkcs11_mbedtls.c. Change the winsock2.h include method to mirror the way it's being done in the rest of the FreeRTOS repos
  • Loading branch information
Skptak committed Nov 28, 2023
1 parent 13db56c commit 4e30cbd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
1 change: 0 additions & 1 deletion source/core_pkcs11.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <stdint.h>
#include <string.h>


/**
* @file core_pkcs11.c
* @brief corePKCS11 Interface.
Expand Down
33 changes: 22 additions & 11 deletions source/portable/mbedtls/core_pkcs11_mbedtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@
*/
#define MBEDTLS_ALLOW_PRIVATE_ACCESS

/* mbedTLS includes. */
/* MbedTLS includes. */
#if defined( MBEDTLS_CONFIG_FILE )
#include MBEDTLS_CONFIG_FILE
#else
#include "mbedtls/mbedtls_config.h"
#endif

#include "mbedtls/pk.h"
#include "mbedtls/x509_crt.h"
#include "mbedtls/ctr_drbg.h"
Expand Down Expand Up @@ -496,19 +502,24 @@ static CK_RV prvMbedTLS_Initialize( void )
if( lMbedTLSResult != PSA_SUCCESS )
{
LogError( ( "Could not initialize PKCS #11. Failed to initialize PSA: MBedTLS error = %s : %s.",
mbedtlsHighLevelCodeOrDefault( lMbedTLSResult ),
mbedtlsLowLevelCodeOrDefault( lMbedTLSResult ) ) );
mbedtlsHighLevelCodeOrDefault( lMbedTLSResult ),
mbedtlsLowLevelCodeOrDefault( lMbedTLSResult ) ) );
xResult = CKR_FUNCTION_FAILED;
/* MISRA Ref 10.5.1 [Essential type casting] */
/* More details at: https://github.com/FreeRTOS/corePKCS11/blob/main/MISRA.md#rule-105 */
/* coverity[misra_c_2012_rule_10_5_violation] */
xP11Context.xIsInitialized = ( CK_BBOOL ) CK_FALSE;
}
else{
LogDebug( ( "MbedTLS PSA module was successfully initialized." ) );
}
else
#endif /* MBEDTLS_USE_PSA_CRYPTO */
{
/* MISRA Ref 10.5.1 [Essential type casting] */
/* More details at: https://github.com/FreeRTOS/corePKCS11/blob/main/MISRA.md#rule-105 */
/* coverity[misra_c_2012_rule_10_5_violation] */
xP11Context.xIsInitialized = ( CK_BBOOL ) CK_TRUE;
LogDebug( ( "PKCS #11 module was successfully initialized." ) );
}

/* MISRA Ref 10.5.1 [Essential type casting] */
/* More details at: https://github.com/FreeRTOS/corePKCS11/blob/main/MISRA.md#rule-105 */
/* coverity[misra_c_2012_rule_10_5_violation] */
xP11Context.xIsInitialized = ( CK_BBOOL ) CK_TRUE;
LogDebug( ( "PKCS #11 module was successfully initialized." ) );
}

return xResult;
Expand Down
25 changes: 12 additions & 13 deletions source/portable/os/freertos_winsim/core_pkcs11_pal.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,25 @@

/*-----------------------------------------------------------*/

/* System Includes */
#include <stdio.h>
#include <string.h>

#ifdef WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#ifdef WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#else
#include <winsock.h>
#endif /* WIN32_LEAN_AND_MEAN */
#endif /* WIN32 */

#include <winsock2.h>
#include <windows.h>
#endif


/* FreeRTOS Includes */
#include "FreeRTOS.h"

/* corePKCS11 Includes */
#include "core_pkcs11.h"
#include "core_pkcs11_config.h"
#include "core_pkcs11_config_defaults.h"


/* C runtime includes. */
#include <stdio.h>
#include <string.h>

#include "core_pkcs11_pal_utils.h"

/*-----------------------------------------------------------*/
Expand Down

0 comments on commit 4e30cbd

Please sign in to comment.