Cherry-pick PR#89 to m241 branch . Adding original ipcom_key_db.c, ipcrypto_key_db_example_keys.c for FTP build. NOTE This commit will NOT compile (#90)
Reviewed-on: http://13.234.246.121:3000/Neominds/ossl35vx69/pulls/89 Co-authored-by: siddhant <siddhant.singh@neominds.in> Co-committed-by: siddhant <siddhant.singh@neominds.in> Co-authored-by: siddhant <siddhant.singh@neominds.in> Reviewed-on: http://13.234.246.121:3000/Neominds/ossl35vx69/pulls/90 Co-authored-by: Neelima P S <neelima.ps@neominds.in> Co-committed-by: Neelima P S <neelima.ps@neominds.in>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,479 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2014, 2017-2018, 2020-2021 Wind River Systems, Inc.
|
|
||||||
*
|
|
||||||
* The right to copy, distribute, modify or otherwise make use
|
|
||||||
* of this software may be licensed only pursuant to the terms
|
|
||||||
* of an applicable Wind River license agreement.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
****************************************************************************
|
|
||||||
* 1 DESCRIPTION
|
|
||||||
****************************************************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
****************************************************************************
|
|
||||||
* 2 CONFIGURATION
|
|
||||||
****************************************************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <ipcom_key_db.h>
|
|
||||||
|
|
||||||
#ifdef IPCOM_USE_KEY_DB
|
|
||||||
|
|
||||||
/*
|
|
||||||
****************************************************************************
|
|
||||||
* 3 INCLUDE FILES
|
|
||||||
****************************************************************************
|
|
||||||
*/
|
|
||||||
#include <ipcom_type.h>
|
|
||||||
#include <ipcom_cstyle.h>
|
|
||||||
#include <ipcom_clib.h>
|
|
||||||
#include <ipcom_sysvar.h>
|
|
||||||
#include <ipcom_syslog.h>
|
|
||||||
#include <ipcom_err.h>
|
|
||||||
#include <ipcom_file.h>
|
|
||||||
|
|
||||||
#include <vxWorks.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <taskLib.h>
|
|
||||||
#include <sysLib.h>
|
|
||||||
#include <secSecret.h>
|
|
||||||
#include <secKeyStore.h>
|
|
||||||
#include <private/secSecretP.h>
|
|
||||||
#include <private/secKeyStoreP.h>
|
|
||||||
|
|
||||||
/*
|
|
||||||
****************************************************************************
|
|
||||||
* 4 DEFINES
|
|
||||||
****************************************************************************
|
|
||||||
*/
|
|
||||||
#ifndef IPCOM_KEY_DB_MAX_PATH
|
|
||||||
#define IPCOM_KEY_DB_MAX_PATH 128
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef IPCOM_KEY_DB_MAX_SECRET
|
|
||||||
#define IPCOM_KEY_DB_MAX_SECRET 32
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define IPCOM_KEY_DB_TYPE_PKEY 1
|
|
||||||
#define IPCOM_KEY_DB_TYPE_BUF 2
|
|
||||||
|
|
||||||
#define IPCOM_KEY_DB_MODE_READ 1
|
|
||||||
#define IPCOM_KEY_DB_MODE_WRITE 2
|
|
||||||
|
|
||||||
#define IPCOM_SYSLOG_PRIORITY IPCOM_SYSLOG_IPCOM_PRIORITY
|
|
||||||
#define IPCOM_SYSLOG_FACILITY IPCOM_LOG_IPCOM_KEY_DB
|
|
||||||
|
|
||||||
#define MAX_BLOCK_SIZE 16
|
|
||||||
|
|
||||||
#ifdef EVP_MAX_KEY_LENGTH
|
|
||||||
#define IPCOM_KEY_DB_MAX_KEY_LENGTH EVP_MAX_KEY_LENGTH
|
|
||||||
#else
|
|
||||||
#define IPCOM_KEY_DB_MAX_KEY_LENGTH 32
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef EVP_MAX_IV_LENGTH
|
|
||||||
#define IPCOM_KEY_DB_MAX_IV_LENGTH EVP_MAX_IV_LENGTH
|
|
||||||
#else
|
|
||||||
#define IPCOM_KEY_DB_MAX_IV_LENGTH 16
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
****************************************************************************
|
|
||||||
* 5 TYPES
|
|
||||||
****************************************************************************
|
|
||||||
*/
|
|
||||||
struct evp_pkey_st;
|
|
||||||
typedef struct evp_pkey_st EVP_PKEY;
|
|
||||||
/*
|
|
||||||
****************************************************************************
|
|
||||||
* 6 EXTERN PROTOTYPES
|
|
||||||
****************************************************************************
|
|
||||||
*/
|
|
||||||
extern void keydb_configure(void);
|
|
||||||
|
|
||||||
/*
|
|
||||||
****************************************************************************
|
|
||||||
* 7 LOCAL PROTOTYPES
|
|
||||||
****************************************************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
****************************************************************************
|
|
||||||
* 8 DATA
|
|
||||||
****************************************************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
****************************************************************************
|
|
||||||
* 9 STATIC FUNCTIONS
|
|
||||||
****************************************************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
****************************************************************************
|
|
||||||
* 11 PUBLIC FUNCTIONS
|
|
||||||
****************************************************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
*===========================================================================
|
|
||||||
* ipcom_key_db_pkey_get
|
|
||||||
*===========================================================================
|
|
||||||
* Description:
|
|
||||||
* Parameters:
|
|
||||||
* Returns:
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
IP_PUBLIC EVP_PKEY*
|
|
||||||
ipcom_key_db_pkey_get(const char* key_id)
|
|
||||||
{
|
|
||||||
if (!key_id || ipcom_strlen(key_id) > IPCOM_KEY_DB_MAX_ID)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
return secKeyStoreGet(key_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
*===========================================================================
|
|
||||||
* ipcom_key_db_pkey_import
|
|
||||||
*===========================================================================
|
|
||||||
* Description:
|
|
||||||
* Parameters:
|
|
||||||
* Returns:
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
IP_PUBLIC Ip_err
|
|
||||||
ipcom_key_db_pkey_import(const char* key_id, EVP_PKEY* key)
|
|
||||||
{
|
|
||||||
STATUS rc;
|
|
||||||
|
|
||||||
if (!key || !key_id || ipcom_strlen(key_id) > IPCOM_KEY_DB_MAX_ID)
|
|
||||||
return IPCOM_ERR_INVALID_ARG;
|
|
||||||
|
|
||||||
rc = secKeyStoreImport(key_id, key);
|
|
||||||
if (rc != OK)
|
|
||||||
switch (errno)
|
|
||||||
{
|
|
||||||
case EEXIST:
|
|
||||||
return IPCOM_ERR_ALREADY_INSTALLED;
|
|
||||||
default:
|
|
||||||
return IPCOM_ERR_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
return IPCOM_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
*===========================================================================
|
|
||||||
* ipcom_key_db_pkey_get2
|
|
||||||
*===========================================================================
|
|
||||||
* Description:
|
|
||||||
* Parameters:
|
|
||||||
* Returns:
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
IP_PUBLIC EVP_PKEY*
|
|
||||||
ipcom_key_db_pkey_get2(struct x509_st* x509, char* key_id, int* key_id_len)
|
|
||||||
{
|
|
||||||
return secKeyStoreX509Get(x509, key_id, key_id_len);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
*===========================================================================
|
|
||||||
* ipcom_key_db_pkey_opendb
|
|
||||||
*===========================================================================
|
|
||||||
* Description:
|
|
||||||
* Parameters:
|
|
||||||
* Returns:
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
IP_PUBLIC void*
|
|
||||||
ipcom_key_db_pkey_opendb(void)
|
|
||||||
{
|
|
||||||
return secKeyStoreOpen();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
*===========================================================================
|
|
||||||
* ipcom_key_db_pkey_readdb
|
|
||||||
*===========================================================================
|
|
||||||
* Description:
|
|
||||||
* Parameters:
|
|
||||||
* Returns:
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
IP_PUBLIC Ip_err
|
|
||||||
ipcom_key_db_pkey_readdb(void* handle, char* name, int name_len)
|
|
||||||
{
|
|
||||||
STATUS rc;
|
|
||||||
if (!handle || !name)
|
|
||||||
return IPCOM_ERR_INVALID_ARG;
|
|
||||||
|
|
||||||
rc = secKeyStoreRead(handle, name, name_len);
|
|
||||||
if (rc != OK)
|
|
||||||
switch (errno)
|
|
||||||
{
|
|
||||||
case EINVAL:
|
|
||||||
return IPCOM_ERR_INVALID_ARG;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return IPCOM_ERR_END;
|
|
||||||
}
|
|
||||||
return IPCOM_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
*===========================================================================
|
|
||||||
* ipcom_key_db_pkey_closedb
|
|
||||||
*===========================================================================
|
|
||||||
* Description:
|
|
||||||
* Parameters:
|
|
||||||
* Returns:
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
IP_PUBLIC Ip_err
|
|
||||||
ipcom_key_db_pkey_closedb(void* handle)
|
|
||||||
{
|
|
||||||
if (secKeyStoreClose(handle) != OK)
|
|
||||||
return IPCOM_ERR_FAILED;
|
|
||||||
|
|
||||||
return IPCOM_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
*===========================================================================
|
|
||||||
* ipcom_key_db_pkey_del
|
|
||||||
*===========================================================================
|
|
||||||
* Description:
|
|
||||||
* Parameters:
|
|
||||||
* Returns:
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
IP_PUBLIC Ip_err
|
|
||||||
ipcom_key_db_pkey_del(const char* key_id)
|
|
||||||
{
|
|
||||||
STATUS rc;
|
|
||||||
|
|
||||||
rc = secKeyStoreDel(key_id);
|
|
||||||
if (rc != OK)
|
|
||||||
switch (errno)
|
|
||||||
{
|
|
||||||
case EINVAL:
|
|
||||||
return IPCOM_ERR_INVALID_ARG;
|
|
||||||
case ENOENT:
|
|
||||||
return IPCOM_ERR_NOT_FOUND;
|
|
||||||
default:
|
|
||||||
return IPCOM_ERR_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
return IPCOM_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
*===========================================================================
|
|
||||||
* ipcom_key_db_buf_import
|
|
||||||
*===========================================================================
|
|
||||||
* Description:
|
|
||||||
* Parameters:
|
|
||||||
* Returns:
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
IP_PUBLIC Ip_err
|
|
||||||
ipcom_key_db_buf_import(const char* key_id, const UINT8* key, int key_len)
|
|
||||||
{
|
|
||||||
STATUS status;
|
|
||||||
|
|
||||||
if (!key_id || ipcom_strlen(key_id) > IPCOM_KEY_DB_MAX_ID ||
|
|
||||||
!key ||
|
|
||||||
key_len > IPCOM_KEY_DB_MAX_BUF)
|
|
||||||
return IPCOM_ERR_INVALID_ARG;
|
|
||||||
|
|
||||||
status = secSecretImport(key_id, (const char*) key, key_len);
|
|
||||||
if (status != OK)
|
|
||||||
switch (errno)
|
|
||||||
{
|
|
||||||
case EEXIST:
|
|
||||||
return IPCOM_ERR_ALREADY_INSTALLED;
|
|
||||||
default:
|
|
||||||
return IPCOM_ERR_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
return IPCOM_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
*===========================================================================
|
|
||||||
* ipcom_key_db_buf_get
|
|
||||||
*===========================================================================
|
|
||||||
* Description:
|
|
||||||
* Parameters:
|
|
||||||
* Returns:
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
IP_PUBLIC Ip_err
|
|
||||||
ipcom_key_db_buf_get(const char* key_id, UINT8* buf, int* buf_len)
|
|
||||||
{
|
|
||||||
STATUS rc;
|
|
||||||
|
|
||||||
if (!key_id || ipcom_strlen(key_id) > IPCOM_KEY_DB_MAX_ID ||
|
|
||||||
!buf_len)
|
|
||||||
{
|
|
||||||
return IPCOM_ERR_INVALID_ARG;
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = secSecretGet(key_id, (char*) buf, buf_len);
|
|
||||||
if (rc != OK)
|
|
||||||
switch (errno)
|
|
||||||
{
|
|
||||||
case ENOENT:
|
|
||||||
return IPCOM_ERR_NOT_FOUND;
|
|
||||||
default:
|
|
||||||
return IPCOM_ERR_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
return IPCOM_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
*===========================================================================
|
|
||||||
* ipcom_key_db_buf_del
|
|
||||||
*===========================================================================
|
|
||||||
* Description:
|
|
||||||
* Parameters:
|
|
||||||
* Returns:
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
IP_PUBLIC Ip_err
|
|
||||||
ipcom_key_db_buf_del(const char* key_id)
|
|
||||||
{
|
|
||||||
STATUS status;
|
|
||||||
|
|
||||||
if (!key_id || ipcom_strlen(key_id) > IPCOM_KEY_DB_MAX_ID)
|
|
||||||
{
|
|
||||||
return IPCOM_ERR_INVALID_ARG;
|
|
||||||
}
|
|
||||||
|
|
||||||
status = secSecretDel(key_id);
|
|
||||||
if (status != OK)
|
|
||||||
return IPCOM_ERR_FAILED;
|
|
||||||
|
|
||||||
return IPCOM_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
*===========================================================================
|
|
||||||
* ipcom_key_db_buf_opendb
|
|
||||||
*===========================================================================
|
|
||||||
* Description:
|
|
||||||
* Parameters:
|
|
||||||
* Returns:
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
IP_PUBLIC void*
|
|
||||||
ipcom_key_db_buf_opendb(void)
|
|
||||||
{
|
|
||||||
return secSecretOpen();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
*===========================================================================
|
|
||||||
* ipcom_key_db_buf_readdb
|
|
||||||
*===========================================================================
|
|
||||||
* Description:
|
|
||||||
* Parameters:
|
|
||||||
* Returns:
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
IP_PUBLIC Ip_err
|
|
||||||
ipcom_key_db_buf_readdb(void* handle, char* name, int name_len)
|
|
||||||
{
|
|
||||||
STATUS rc;
|
|
||||||
rc = secSecretRead(handle, name, name_len);
|
|
||||||
|
|
||||||
if (rc != OK)
|
|
||||||
switch (errno)
|
|
||||||
{
|
|
||||||
case EINVAL:
|
|
||||||
return IPCOM_ERR_INVALID_ARG;
|
|
||||||
default:
|
|
||||||
return IPCOM_ERR_END;
|
|
||||||
}
|
|
||||||
|
|
||||||
return IPCOM_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
*===========================================================================
|
|
||||||
* ipcom_key_db_buf_closedb
|
|
||||||
*===========================================================================
|
|
||||||
* Description:
|
|
||||||
* Parameters:
|
|
||||||
* Returns:
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
IP_PUBLIC Ip_err
|
|
||||||
ipcom_key_db_buf_closedb(void* handle)
|
|
||||||
{
|
|
||||||
if (secSecretClose(handle) != OK)
|
|
||||||
return IPCOM_ERR_FAILED;
|
|
||||||
|
|
||||||
return IPCOM_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
*===========================================================================
|
|
||||||
* ipcom_key_db_file_ready
|
|
||||||
*===========================================================================
|
|
||||||
* Description:
|
|
||||||
* Parameters:
|
|
||||||
* Returns:
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
IP_GLOBAL void
|
|
||||||
ipcom_key_db_file_ready(void)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
while (secKeyStoreReadyCheck() != OK)
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
if (i >= 10)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
(void) taskDelay (sysClkRateGet()/10);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
int ipcom_key_db_empty_file;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
****************************************************************************
|
|
||||||
* END OF FILE
|
|
||||||
****************************************************************************
|
|
||||||
*/
|
|
||||||
Reference in New Issue
Block a user