Skip to content

Commit

Permalink
Removed dependency of FreeRTOS Kernel (#5)
Browse files Browse the repository at this point in the history
Steps to accomplish this:
1. Remove kernel dependency in unit tests.
1. Update functions to not consume the kernel directly
  • Loading branch information
lundinc2 authored Sep 21, 2020
1 parent 40c9897 commit 6724b71
Show file tree
Hide file tree
Showing 21 changed files with 3,290 additions and 947 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@
[submodule "3rdparty/pkcs11"]
path = 3rdparty/pkcs11
url = https://github.com/amazon-freertos/pkcs11.git
[submodule "FreeRTOS-Kernel"]
path = FreeRTOS-Kernel
url = https://github.com/FreeRTOS/FreeRTOS-Kernel.git
1 change: 0 additions & 1 deletion FreeRTOS-Kernel
Submodule FreeRTOS-Kernel deleted from 82fdc1
11 changes: 7 additions & 4 deletions source/include/iot_pki_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#ifndef _IOT_PKI_UTILS_H_
#define _IOT_PKI_UTILS_H_

#include <stdint.h>
#include <stddef.h>

/**
* @file iot_pki_utils.h
* @brief Helper functions for PKCS #11
Expand All @@ -50,8 +53,8 @@
* \return 0 on success, -1 on failure.
*/
/* @[declare_pkcs11_utils_pkimbedtlssignaturetopkcs11signature] */
BaseType_t PKI_mbedTLSSignatureToPkcs11Signature( uint8_t * pxSignaturePKCS,
const uint8_t * pxMbedSignature );
int8_t PKI_mbedTLSSignatureToPkcs11Signature( uint8_t * pxSignaturePKCS,
const uint8_t * pxMbedSignature );
/* @[declare_pkcs11_utils_pkimbedtlssignaturetopkcs11signature] */


Expand Down Expand Up @@ -79,7 +82,7 @@ BaseType_t PKI_mbedTLSSignatureToPkcs11Signature( uint8_t * pxSignaturePKCS,
*
*/
/* @[declare_pkcs11_utils_pkipkcs11signaturetombedtlssignature] */
BaseType_t PKI_pkcs11SignatureTombedTLSSignature( uint8_t * pucSig,
size_t * pxSigLen );
int8_t PKI_pkcs11SignatureTombedTLSSignature( uint8_t * pucSig,
size_t * pxSigLen );
/* @[declare_pkcs11_utils_pkipkcs11signaturetombedtlssignature] */
#endif /* ifndef _IOT_PKI_UTILS_H_ */
13 changes: 6 additions & 7 deletions source/iot_pkcs11.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

#include "iot_pkcs11_config.h"
#include "iot_pkcs11.h"
#include "FreeRTOS.h"

/* C runtime includes. */
#include <stdio.h>
Expand Down Expand Up @@ -89,7 +88,7 @@ CK_RV xGetSlotList( CK_SLOT_ID ** ppxSlotId,
if( xResult == CKR_OK )
{
/* Allocate memory for the slot list. */
pxSlotId = pvPortMalloc( sizeof( CK_SLOT_ID ) * ( *pxSlotCount ) );
pxSlotId = PKCS11_MALLOC( sizeof( CK_SLOT_ID ) * ( *pxSlotCount ) );

if( pxSlotId == NULL )
{
Expand All @@ -108,7 +107,7 @@ CK_RV xGetSlotList( CK_SLOT_ID ** ppxSlotId,

if( ( xResult != CKR_OK ) && ( pxSlotId != NULL ) )
{
vPortFree( pxSlotId );
PKCS11_FREE( pxSlotId );
}

return xResult;
Expand Down Expand Up @@ -176,7 +175,7 @@ CK_RV xInitializePkcs11Token( void )
( NULL != pxFunctionList->C_InitToken ) )
{
/* Check if the token requires further initialization. */
pxTokenInfo = pvPortMalloc( sizeof( CK_TOKEN_INFO ) );
pxTokenInfo = PKCS11_MALLOC( sizeof( CK_TOKEN_INFO ) );

if( pxTokenInfo != NULL )
{
Expand Down Expand Up @@ -208,12 +207,12 @@ CK_RV xInitializePkcs11Token( void )

if( pxTokenInfo != NULL )
{
vPortFree( pxTokenInfo );
PKCS11_FREE( pxTokenInfo );
}

if( pxSlotId != NULL )
{
vPortFree( pxSlotId );
PKCS11_FREE( pxSlotId );
}

return xResult;
Expand Down Expand Up @@ -262,7 +261,7 @@ CK_RV xInitializePkcs11Session( CK_SESSION_HANDLE * pxSession )
xResult = prvOpenSession( pxSession, pxSlotId[ 0 ] );

/* Free the memory allocated by xGetSlotList. */
vPortFree( pxSlotId );
PKCS11_FREE( pxSlotId );
}

if( ( xResult == CKR_OK ) && ( pxFunctionList->C_Login != NULL ) )
Expand Down
14 changes: 7 additions & 7 deletions source/iot_pki_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
* @file iot_pki_utils.h
* @brief Helper functions for PKCS #11
*/
#include "FreeRTOS.h"
#include "iot_pki_utils.h"

/* CRT includes. */
#include <stdint.h>
#include <string.h>

#define FAILURE ( -1 )
Expand All @@ -41,10 +41,10 @@

/* Convert the EC signature from DER encoded to PKCS #11 format. */
/* @[declare pkcs11_utils_pkipkcs11signaturetombedtlssignature] */
BaseType_t PKI_mbedTLSSignatureToPkcs11Signature( uint8_t * pxSignaturePKCS,
const uint8_t * pxMbedSignature )
int8_t PKI_mbedTLSSignatureToPkcs11Signature( uint8_t * pxSignaturePKCS,
const uint8_t * pxMbedSignature )
{
BaseType_t xReturn = 0;
int8_t xReturn = 0;
const uint8_t * pxNextLength;
uint8_t ucSigComponentLength;

Expand Down Expand Up @@ -118,10 +118,10 @@ BaseType_t PKI_mbedTLSSignatureToPkcs11Signature( uint8_t * pxSignaturePKCS,

/* Convert an EC signature from PKCS #11 format to DER encoded. */
/* @[declare pkcs11_utils_pkimbedtlssignaturetopkcs11signature] */
BaseType_t PKI_pkcs11SignatureTombedTLSSignature( uint8_t * pucSig,
size_t * pxSigLen )
int8_t PKI_pkcs11SignatureTombedTLSSignature( uint8_t * pucSig,
size_t * pxSigLen )
{
BaseType_t xReturn = 0;
int8_t xReturn = 0;
uint8_t * pucSigPtr;
uint8_t ucTemp[ 64 ] = { 0 }; /* A temporary buffer for the pre-formatted signature. */

Expand Down
Loading

0 comments on commit 6724b71

Please sign in to comment.