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,227 +0,0 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* 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