Files
HiSTBLinuxV100R005C00SPC060/sample/openssl/server/openssl_server_test.c
T
2024-08-25 22:59:44 +08:00

124 lines
3.1 KiB
C
Executable File

/******************************************************************************
Copyright (C), 2016-2026, Hisilicon Tech. Co., Ltd.
******************************************************************************
File Name : openssl_server_test.c
Version : Initial Draft
Author : Hisilicon security software group
Created : 2016/04/13
Description :
History :
1.Date : 2016/04/13
Author : security team
Modification: Created file
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <pthread.h>
#include <math.h>
#include <assert.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include "openssl/ssl.h"
#include "openssl/err.h"
#include "hi_type.h"
#include "hi_common.h"
#include "openssl_adp.h"
extern HI_S32 OpenSSL_ServerTest(HI_OPENSSL_CTX_S *pSslCtx);
static int server_password_cb(char *buf, int num, int rwflag,void *userdata);
#define SERVER_PRIVATE_KEY_PASSWD "789456"
static void usage()
{
printf("Usage: openssl_server_test\n");
printf("Example:./openssl_server_test \n");
return;
}
HI_S32 main(HI_S32 argc,HI_CHAR *argv[])
{
HI_S32 Ret;
Hi_SSL_INIT_PARAMETERS InitParamers;
HI_OPENSSL_CTX_S SslCtx;
char RootCert[] = "./key/ca.crt";
char ServerCert[] = "./key/server.crt";
char ServerPrivatekey[] = "./key/server.key";
//char cipherList[]= "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH";
char cipherList[]= "TLSv1.2:!eNULL:!aNULL:!aDH:!RC4:!AECDH:!ADH:@STRENGTH";
if (argc > 1)
{
usage();
return HI_FAILURE;
}
//HI_SYS_Init();
InitParamers.bIdentityAuth = HI_TRUE;
InitParamers.rootCaCertPath = RootCert;
InitParamers.certPath = ServerCert;
InitParamers.privKeyPath = ServerPrivatekey;
InitParamers.cipherList = cipherList;
InitParamers.eSSLVersion = SSL_VERSION_TLS_V1_1;
InitParamers.funPasswdCb = server_password_cb;
InitParamers.bIsServer = HI_TRUE;
printf("Start open server side!!!!!!!!!\n");
Ret = HI_OpenSSL_Init(&InitParamers, &SslCtx);
if (Ret != HI_SUCCESS)
{
printf("Fail to call HI_OpenSSL_Init!!!!!!!!!\n");
goto __SSL_EXIT__;
}
OpenSSL_ServerTest(&SslCtx);
printf("SSL TEST END!!!!!!!!!\n");
__SSL_EXIT__:
HI_OpenSSL_UnInit(&SslCtx);
//HI_SYS_DeInit();
return Ret;
}
/*If the private key is encrypted, the call function will be called*/
static int server_password_cb(char *buf, int num, int rwflag,void *userdata)
{
int len;
//printf("%s: Enter this function \n", __FUNCTION__);
//printf("num= %d rwflag=%d\n",num,rwflag);
//printf("userdata= %s\n",(char*)userdata);
strncpy(buf, SERVER_PRIVATE_KEY_PASSWD, num);
buf[num - 1] = '\0';
len = strlen(SERVER_PRIVATE_KEY_PASSWD);
return len;
}