mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-08-19 09:38:32 -04:00
Prepare for V7.2.0 release.
This commit is contained in:
parent
73ad4387e2
commit
e0bab5981a
1071 changed files with 8726 additions and 2457 deletions
|
@ -63,6 +63,25 @@
|
|||
#endif
|
||||
|
||||
|
||||
static void Usage(void)
|
||||
{
|
||||
printf("server " LIBCYASSL_VERSION_STRING
|
||||
" NOTE: All files relative to CyaSSL home dir\n");
|
||||
printf("-? Help, print this usage\n");
|
||||
printf("-p <num> Port to listen on, default %d\n", yasslPort);
|
||||
printf("-v <num> SSL version [0-3], SSLv3(0) - TLS1.2(3)), default %d\n",
|
||||
SERVER_DEFAULT_VERSION);
|
||||
printf("-l <str> Cipher list\n");
|
||||
printf("-c <file> Certificate file, default %s\n", svrCert);
|
||||
printf("-k <file> Key file, default %s\n", svrKey);
|
||||
printf("-A <file> Certificate Authority file, default %s\n", cliCert);
|
||||
printf("-d Disable client cert check\n");
|
||||
printf("-b Bind to any interface instead of localhost only\n");
|
||||
printf("-s Use pre Shared keys\n");
|
||||
printf("-u Use UDP DTLS\n");
|
||||
}
|
||||
|
||||
|
||||
THREAD_RETURN CYASSL_THREAD server_test(void* args)
|
||||
{
|
||||
SOCKET_T sockfd = 0;
|
||||
|
@ -72,85 +91,194 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
|
|||
SSL_CTX* ctx = 0;
|
||||
SSL* ssl = 0;
|
||||
|
||||
char msg[] = "I hear you fa shizzle!";
|
||||
char input[1024];
|
||||
int idx;
|
||||
|
||||
char msg[] = "I hear you fa shizzle!";
|
||||
char input[1024];
|
||||
int idx;
|
||||
int ch;
|
||||
int version = SERVER_DEFAULT_VERSION;
|
||||
int doCliCertCheck = 1;
|
||||
int useAnyAddr = 0;
|
||||
int port = yasslPort;
|
||||
int usePsk = 0;
|
||||
int doDTLS = 0;
|
||||
int useNtruKey = 0;
|
||||
char* cipherList = NULL;
|
||||
char* verifyCert = (char*)cliCert;
|
||||
char* ourCert = (char*)svrCert;
|
||||
char* ourKey = (char*)svrKey;
|
||||
int argc = ((func_args*)args)->argc;
|
||||
char** argv = ((func_args*)args)->argv;
|
||||
|
||||
((func_args*)args)->return_code = -1; /* error state */
|
||||
#if defined(CYASSL_DTLS)
|
||||
method = DTLSv1_server_method();
|
||||
#elif !defined(NO_TLS)
|
||||
method = SSLv23_server_method();
|
||||
#else
|
||||
method = SSLv3_server_method();
|
||||
|
||||
while ((ch = mygetopt(argc, argv, "?dbsnup:v:l:A:c:k:")) != -1) {
|
||||
switch (ch) {
|
||||
case '?' :
|
||||
Usage();
|
||||
exit(EXIT_SUCCESS);
|
||||
|
||||
case 'd' :
|
||||
doCliCertCheck = 0;
|
||||
break;
|
||||
|
||||
case 'b' :
|
||||
useAnyAddr = 1;
|
||||
break;
|
||||
|
||||
case 's' :
|
||||
usePsk = 1;
|
||||
break;
|
||||
|
||||
case 'n' :
|
||||
useNtruKey = 1;
|
||||
break;
|
||||
|
||||
case 'u' :
|
||||
doDTLS = 1;
|
||||
version = -1; /* DTLS flag */
|
||||
break;
|
||||
|
||||
case 'p' :
|
||||
port = atoi(myoptarg);
|
||||
break;
|
||||
|
||||
case 'v' :
|
||||
version = atoi(myoptarg);
|
||||
if (version < 0 || version > 3) {
|
||||
Usage();
|
||||
exit(MY_EX_USAGE);
|
||||
}
|
||||
if (doDTLS)
|
||||
version = -1; /* stay with DTLS */
|
||||
break;
|
||||
|
||||
case 'l' :
|
||||
cipherList = myoptarg;
|
||||
break;
|
||||
|
||||
case 'A' :
|
||||
verifyCert = myoptarg;
|
||||
break;
|
||||
|
||||
case 'c' :
|
||||
ourCert = myoptarg;
|
||||
break;
|
||||
|
||||
case 'k' :
|
||||
ourKey = myoptarg;
|
||||
break;
|
||||
|
||||
default:
|
||||
Usage();
|
||||
exit(MY_EX_USAGE);
|
||||
}
|
||||
}
|
||||
|
||||
argc -= myoptind;
|
||||
argv += myoptind;
|
||||
myoptind = 0; /* reset for test cases */
|
||||
|
||||
switch (version) {
|
||||
case 0:
|
||||
method = SSLv3_server_method();
|
||||
break;
|
||||
|
||||
case 1:
|
||||
method = TLSv1_server_method();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
method = TLSv1_1_server_method();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
method = TLSv1_2_server_method();
|
||||
break;
|
||||
|
||||
#ifdef CYASSL_DTLS
|
||||
case -1:
|
||||
method = DTLSv1_server_method();
|
||||
break;
|
||||
#endif
|
||||
ctx = SSL_CTX_new(method);
|
||||
|
||||
default:
|
||||
err_sys("Bad SSL version");
|
||||
}
|
||||
|
||||
if (method == NULL)
|
||||
err_sys("unable to get method");
|
||||
|
||||
ctx = SSL_CTX_new(method);
|
||||
if (ctx == NULL)
|
||||
err_sys("unable to get ctx");
|
||||
|
||||
if (cipherList)
|
||||
if (SSL_CTX_set_cipher_list(ctx, cipherList) != SSL_SUCCESS)
|
||||
err_sys("can't set cipher list");
|
||||
|
||||
if (SSL_CTX_use_certificate_file(ctx, ourCert, SSL_FILETYPE_PEM)
|
||||
!= SSL_SUCCESS)
|
||||
err_sys("can't load server cert file, check file and run from"
|
||||
" CyaSSL home dir");
|
||||
|
||||
|
||||
#ifdef HAVE_NTRU
|
||||
if (useNtruKey) {
|
||||
if (CyaSSL_CTX_use_NTRUPrivateKey_file(ctx, ourKey)
|
||||
!= SSL_SUCCESS)
|
||||
err_sys("can't load ntru key file, "
|
||||
"Please run from CyaSSL home dir");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!useNtruKey) {
|
||||
if (SSL_CTX_use_PrivateKey_file(ctx, ourKey, SSL_FILETYPE_PEM)
|
||||
!= SSL_SUCCESS)
|
||||
err_sys("can't load server cert file, check file and run from"
|
||||
" CyaSSL home dir");
|
||||
}
|
||||
|
||||
#ifndef NO_PSK
|
||||
/* do PSK */
|
||||
SSL_CTX_set_psk_server_callback(ctx, my_psk_server_cb);
|
||||
SSL_CTX_use_psk_identity_hint(ctx, "cyassl server");
|
||||
SSL_CTX_set_cipher_list(ctx, "PSK-AES256-CBC-SHA");
|
||||
#else
|
||||
/* not using PSK, verify peer with certs */
|
||||
SSL_CTX_set_verify(ctx,SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT,0);
|
||||
if (usePsk) {
|
||||
SSL_CTX_set_psk_server_callback(ctx, my_psk_server_cb);
|
||||
SSL_CTX_use_psk_identity_hint(ctx, "cyassl server");
|
||||
if (cipherList == NULL)
|
||||
if (SSL_CTX_set_cipher_list(ctx,"PSK-AES256-CBC-SHA") !=SSL_SUCCESS)
|
||||
err_sys("can't set cipher list");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* if not using PSK, verify peer with certs */
|
||||
if (doCliCertCheck && usePsk == 0) {
|
||||
SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER |
|
||||
SSL_VERIFY_FAIL_IF_NO_PEER_CERT,0);
|
||||
if (SSL_CTX_load_verify_locations(ctx, verifyCert, 0) != SSL_SUCCESS)
|
||||
err_sys("can't load ca file, Please run from CyaSSL home dir");
|
||||
}
|
||||
|
||||
#ifdef OPENSSL_EXTRA
|
||||
SSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
|
||||
#endif
|
||||
|
||||
#ifndef NO_FILESYSTEM
|
||||
/* for client auth */
|
||||
if (SSL_CTX_load_verify_locations(ctx, cliCert, 0) != SSL_SUCCESS)
|
||||
err_sys("can't load ca file, Please run from CyaSSL home dir");
|
||||
|
||||
#ifdef HAVE_ECC
|
||||
if (SSL_CTX_use_certificate_file(ctx, eccCert, SSL_FILETYPE_PEM)
|
||||
!= SSL_SUCCESS)
|
||||
err_sys("can't load server ecc cert file, "
|
||||
"Please run from CyaSSL home dir");
|
||||
|
||||
if (SSL_CTX_use_PrivateKey_file(ctx, eccKey, SSL_FILETYPE_PEM)
|
||||
!= SSL_SUCCESS)
|
||||
err_sys("can't load server ecc key file, "
|
||||
"Please run from CyaSSL home dir");
|
||||
/* for client auth */
|
||||
if (SSL_CTX_load_verify_locations(ctx, cliEccCert, 0) != SSL_SUCCESS)
|
||||
err_sys("can't load ecc ca file, Please run from CyaSSL home dir");
|
||||
|
||||
#elif HAVE_NTRU
|
||||
if (SSL_CTX_use_certificate_file(ctx, ntruCert, SSL_FILETYPE_PEM)
|
||||
!= SSL_SUCCESS)
|
||||
err_sys("can't load ntru cert file, "
|
||||
"Please run from CyaSSL home dir");
|
||||
|
||||
if (CyaSSL_CTX_use_NTRUPrivateKey_file(ctx, ntruKey)
|
||||
!= SSL_SUCCESS)
|
||||
err_sys("can't load ntru key file, "
|
||||
"Please run from CyaSSL home dir");
|
||||
#else /* normal */
|
||||
if (SSL_CTX_use_certificate_file(ctx, svrCert, SSL_FILETYPE_PEM)
|
||||
!= SSL_SUCCESS)
|
||||
err_sys("can't load server cert chain file, "
|
||||
"Please run from CyaSSL home dir");
|
||||
|
||||
if (SSL_CTX_use_PrivateKey_file(ctx, svrKey, SSL_FILETYPE_PEM)
|
||||
!= SSL_SUCCESS)
|
||||
err_sys("can't load server key file, "
|
||||
"Please run from CyaSSL home dir");
|
||||
#endif /* NTRU */
|
||||
#else
|
||||
load_buffer(ctx, cliCert, CYASSL_CA);
|
||||
load_buffer(ctx, svrCert, CYASSL_CERT);
|
||||
load_buffer(ctx, svrKey, CYASSL_KEY);
|
||||
#endif /* NO_FILESYSTEM */
|
||||
#if defined(CYASSL_SNIFFER) && !defined(HAVE_NTRU) && !defined(HAVE_ECC)
|
||||
/* don't use EDH, can't sniff tmp keys */
|
||||
if (SSL_CTX_set_cipher_list(ctx, "AES256-SHA") != SSL_SUCCESS)
|
||||
err_sys("can't set cipher list");
|
||||
#endif
|
||||
|
||||
ssl = SSL_new(ctx);
|
||||
tcp_accept(&sockfd, &clientfd, (func_args*)args);
|
||||
#ifndef CYASSL_DTLS
|
||||
CloseSocket(sockfd);
|
||||
if (ssl == NULL)
|
||||
err_sys("unable to get SSL");
|
||||
|
||||
#ifdef HAVE_CRL
|
||||
CyaSSL_EnableCRL(ssl, 0);
|
||||
CyaSSL_LoadCRL(ssl, crlPemDir, SSL_FILETYPE_PEM, CYASSL_CRL_MONITOR |
|
||||
CYASSL_CRL_START_MON);
|
||||
CyaSSL_SetCRL_Cb(ssl, CRL_CallBack);
|
||||
#endif
|
||||
tcp_accept(&sockfd, &clientfd, (func_args*)args, port, useAnyAddr, doDTLS);
|
||||
if (!doDTLS)
|
||||
CloseSocket(sockfd);
|
||||
|
||||
SSL_set_fd(ssl, clientfd);
|
||||
#ifdef NO_PSK
|
||||
|
@ -222,6 +350,9 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
|
|||
return args.return_code;
|
||||
}
|
||||
|
||||
int myoptind = 0;
|
||||
char* myoptarg = NULL;
|
||||
|
||||
#endif /* NO_MAIN_DRIVER */
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue