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:
@@ -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
|
||||
****************************************************************************
|
||||
*/
|
||||
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* INTERPEAK CONFIGURATION SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipcrypto_key_db_example_keys.c,v $ $Revision: 1.5.16.1 $
|
||||
* $Source: /home/interpeak/CVSRoot/ipcrypto/config/ipcrypto_key_db_example_keys.c,v $
|
||||
* $Author: svc-cmnet $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Roger Boden <roger.boden@windriver.com>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_config.h>
|
||||
#include "ipcrypto_config.h"
|
||||
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
#include <ipcom_err.h>
|
||||
#include <ipcom_sysvar.h>
|
||||
#include <ipcom_shell.h>
|
||||
#include <ipcom_syslog.h>
|
||||
#include <ipcom_os.h>
|
||||
#include <ipcom_file.h>
|
||||
#include <ipcom_key_db.h>
|
||||
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/pem.h>
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
#define IPCOM_SYSLOG_PRIORITY IPCRYPTO_SYSLOG_PRIORITY
|
||||
#define IPCOM_SYSLOG_FACILITY IPCOM_LOG_IPCRYPTO
|
||||
|
||||
#define IPCRYPTO_KEY_DB_EXAMPLE_DSA_KEY \
|
||||
"-----BEGIN DSA PRIVATE KEY-----\n" \
|
||||
"MIH5AgEAAkEA/UNXOgmhyXWRcOBZLun6hspiuS/Q/N/Ku0stYrD5kQr7vTcNrCNZ\n" \
|
||||
"DYDnCVFfrC6/xyBQGP0fhUBpRUc7eoJpMwIVAOLUu3B5ClDwieTcsYqmu517ABBX\n" \
|
||||
"AkEAgTfPLQcVxAiqkTowSvA/tVyXwCPovs3nBBK8S9nFW+ZzGm9oR2Rccrbfuln0\n" \
|
||||
"AkaoUVmacGBxvD+z9qhhHgiNjQJAeBvdcIgYEly7EUl0bb1KxTGe97hxdM31vhJn\n" \
|
||||
"zGkgrzlyEhf2+d1V756A0mArKvnkq1MKlaFj4vxnqqGVypRfngIVAN/UwBqwgIP2\n" \
|
||||
"IOnHijeFIH2NQF7G\n" \
|
||||
"-----END DSA PRIVATE KEY-----\n"
|
||||
|
||||
#define IPCRYPTO_KEY_DB_EXAMPLE_RSA_KEY \
|
||||
"-----BEGIN RSA PRIVATE KEY-----\n" \
|
||||
"MIICXQIBAAKBgQCgdPfA8zN8csXArrNTdhCeIO4fUCw00rR0lVLp/xxihv0svIzG\n" \
|
||||
"iLvpl7s59mDs61O+xfArReY5edihGOVv9Gu9M5Sd1cnQOG1gLInI//5xX/EIdkb6\n" \
|
||||
"daQnsA3ABvXi4fb1qc94hFamaDr01x7x7epvuKleCQ3uQrkKyxN2xvoz1wIDAQAB\n" \
|
||||
"AoGAY8ATfYozibw4H877gHk3X3aNUj4fHT+YG5nxD7MezEmq/rLAuXOrjk5bgG8g\n" \
|
||||
"Vmj9iO24ns43j6el+pBlojHK/7nmd9TcCg8ONpVj2V+JKkY2guGftKOnH+ZpENAQ\n" \
|
||||
"ZS2wrcschvIblpz9etrWqNDFlaQDELr4iS/GE2rtA50RbHECQQDTddxeipxyZErV\n" \
|
||||
"0ebey93+oSmY1KCdPX6Frhh6PLn2HUFMk5TntOX5ZlnGJ9AhVocdZ6JOp2SBxvw/\n" \
|
||||
"P3+8u/NlAkEAwkDzr/MQ+BACjcIu8T0ruEUYB+tHym2ZvH7M1BuwYRNAZfdGCBzw\n" \
|
||||
"uU0fhOxNMjdZ1i2vOU44XlzrCdiS2zYciwJBAI+YgcVRq1ui746zs2uoVWAMYQr/\n" \
|
||||
"mPIuSDTPPKAFjOKsiyNNNNkD5wetkVkWwCdjcu1s6rMuyPm3/qOUo1Gu8GECQQDA\n" \
|
||||
"q8HI0/MRyHdv+Zmr5zt1Avsp56EGVB03TCGHhIs2Te0C9fc9Vs8hTDCmG+cZlrMB\n" \
|
||||
"b8CruzzHw6vQ0UIgMZSvAkBYSA9oFV7GuKuIL884yve03iCuuPIDRizNtwZWg0gC\n" \
|
||||
"MiAyDEnduD/fo8BV5eBpvEGSmlcYPoxS6heNh/bPRl5l\n" \
|
||||
"-----END RSA PRIVATE KEY-----\n"
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
extern const char* ipcom_key_db_file_root;
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
IP_GLOBAL void ipcrypto_key_db_install_example_keys(void);
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 STATIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipcrypto_key_db_install_example_key
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC void
|
||||
ipcrypto_key_db_install_example_key(const char* key_id, const char* key)
|
||||
{
|
||||
Ip_size_t len = ipcom_strlen(key);
|
||||
IP_FILE* fp;
|
||||
char* path = IP_NULL;
|
||||
const char* tmp_filename = "tmp_default";
|
||||
EVP_PKEY* pkey = IP_NULL;
|
||||
Ip_bool success = IP_FALSE;
|
||||
|
||||
path = ipcom_malloc(ipcom_strlen(ipcom_key_db_file_root)+ipcom_strlen(tmp_filename)+2);
|
||||
if (!path)
|
||||
return;
|
||||
ipcom_strcpy(path, ipcom_key_db_file_root);
|
||||
if (path[ipcom_strlen(path)-1] != '/')
|
||||
ipcom_strcat(path, "/");
|
||||
ipcom_strcat(path, tmp_filename);
|
||||
|
||||
fp = ipcom_fopen(path, "w+");
|
||||
if (!fp)
|
||||
{
|
||||
IPCOM_LOG1(ERR, "ipcrypto_key_db_install_example_key :: failed to create file: %s", path);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (ipcom_fwrite(key, 1, len, fp) != (Ip_size_t)len)
|
||||
{
|
||||
IPCOM_LOG1(ERR, "ipcrypto_key_db_install_example_key :: failed to write to file: %s", path);
|
||||
goto cleanup;
|
||||
}
|
||||
if (ipcom_fseek(fp, 0, IP_SEEK_SET)<0)
|
||||
{
|
||||
IPCOM_LOG1(ERR, "ipcrypto_key_db_install_example_key :: lseek failed: errno=%d", ipcom_errno);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
pkey = PEM_read_PrivateKey(fp, IP_NULL, IP_NULL, IP_NULL);
|
||||
if (!pkey)
|
||||
{
|
||||
IPCOM_LOG1(ERR, "ipcrypto_key_db_install_example_key :: failed to read key from file: %s", path);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (ipcom_key_db_pkey_import(key_id, pkey) != IPCOM_SUCCESS)
|
||||
goto cleanup;
|
||||
|
||||
success = IP_TRUE;
|
||||
|
||||
cleanup:
|
||||
if (fp)
|
||||
(void)ipcom_fclose(fp);
|
||||
if (path)
|
||||
{
|
||||
(void)ipcom_unlink(path);
|
||||
ipcom_free(path);
|
||||
}
|
||||
if (pkey)
|
||||
EVP_PKEY_free(pkey);
|
||||
|
||||
if (success)
|
||||
IPCOM_LOG1(INFO, "Key Database :: created example key: id=%s", key_id);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipcrypto_key_db_install_example_keys
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL void
|
||||
ipcrypto_key_db_install_example_keys(void)
|
||||
{
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
ipcrypto_key_db_install_example_key("default_rsa", IPCRYPTO_KEY_DB_EXAMPLE_RSA_KEY);
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
ipcrypto_key_db_install_example_key("default_dsa", IPCRYPTO_KEY_DB_EXAMPLE_DSA_KEY);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user