Cleanups for DTLS 1.3 client/server examples.
parent
f707ad83da
commit
eaa8e8e022
|
@ -53,12 +53,15 @@ android/wolfssljni-ndk-sample/proguard-project.txt
|
|||
/dtls/client-dtls-resume
|
||||
/dtls/client-dtls-shared
|
||||
/dtls/client-dtls
|
||||
/dtls/client-dtls13
|
||||
/dtls/client-udp
|
||||
/dtls/server-dtls-callback
|
||||
/dtls/server-dtls-ipv6
|
||||
/dtls/server-dtls-nonblocking
|
||||
/dtls/server-dtls-threaded
|
||||
/dtls/server-dtls
|
||||
/dtls/server-dtls13
|
||||
/dtls/server-dtls13-event
|
||||
/dtls/server-udp
|
||||
|
||||
/psk/client-psk-bio-custom
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* client-dtls13.c
|
||||
*
|
||||
* Copyright (C) 2006-2022 wolfSSL Inc.
|
||||
* Copyright (C) 2006-2024 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSL. (formerly known as CyaSSL)
|
||||
*
|
||||
|
@ -29,7 +29,9 @@
|
|||
* Define USE_DTLS12 to use DTLS 1.2 instead of DTLS 1.3
|
||||
*/
|
||||
|
||||
#ifndef WOLFSSL_USER_SETTINGS
|
||||
#include <wolfssl/options.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#include <wolfssl/ssl.h>
|
||||
#include <netdb.h>
|
||||
|
@ -45,7 +47,7 @@
|
|||
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
/* standard variables used in a dtls client*/
|
||||
/* standard variables used in a dtls client */
|
||||
int n = 0;
|
||||
int sockfd = INVALID_SOCKET;
|
||||
int err;
|
||||
|
@ -65,14 +67,14 @@ int main (int argc, char** argv)
|
|||
|
||||
/* Initialize wolfSSL before assigning ctx */
|
||||
if (wolfSSL_Init() != WOLFSSL_SUCCESS) {
|
||||
fprintf(stderr, "wolfSSL_CTX_new error.\n");
|
||||
fprintf(stderr, "wolfSSL_Init error.\n");
|
||||
return exitVal;
|
||||
}
|
||||
|
||||
|
||||
/* No-op when debugging is not compiled in */
|
||||
wolfSSL_Debugging_ON();
|
||||
|
||||
if ( (ctx = wolfSSL_CTX_new(
|
||||
if ((ctx = wolfSSL_CTX_new(
|
||||
#ifdef WOLFSSL_DTLS13
|
||||
wolfDTLSv1_3_client_method()
|
||||
#else
|
||||
|
@ -84,8 +86,8 @@ int main (int argc, char** argv)
|
|||
}
|
||||
|
||||
/* Load certificates into ctx variable */
|
||||
if (wolfSSL_CTX_load_verify_locations(ctx, caCertLoc, 0)
|
||||
!= SSL_SUCCESS) {
|
||||
if (wolfSSL_CTX_load_verify_locations(ctx, caCertLoc, NULL)
|
||||
!= WOLFSSL_SUCCESS) {
|
||||
fprintf(stderr, "Error loading %s, please check the file.\n", caCertLoc);
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -112,7 +114,7 @@ int main (int argc, char** argv)
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
if ( (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
|
||||
if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
|
||||
perror("socket()");
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -124,7 +126,7 @@ int main (int argc, char** argv)
|
|||
}
|
||||
|
||||
/* Perform SSL connection */
|
||||
if (wolfSSL_connect(ssl) != SSL_SUCCESS) {
|
||||
if (wolfSSL_connect(ssl) != WOLFSSL_SUCCESS) {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
fprintf(stderr, "err = %d, %s\n", err, wolfSSL_ERR_reason_error_string(err));
|
||||
fprintf(stderr, "wolfSSL_connect failed\n");
|
||||
|
@ -145,7 +147,8 @@ int main (int argc, char** argv)
|
|||
/* Send sendLine to the server */
|
||||
if (wolfSSL_write(ssl, sendLine, strlen(sendLine)) != strlen(sendLine)) {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
fprintf(stderr, "err = %d, %s\n", err, wolfSSL_ERR_reason_error_string(err));
|
||||
fprintf(stderr, "err = %d, %s\n", err,
|
||||
wolfSSL_ERR_reason_error_string(err));
|
||||
fprintf(stderr, "wolfSSL_write failed\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -160,7 +163,8 @@ int main (int argc, char** argv)
|
|||
}
|
||||
else {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
fprintf(stderr, "err = %d, %s\n", err, wolfSSL_ERR_reason_error_string(err));
|
||||
fprintf(stderr, "err = %d, %s\n", err,
|
||||
wolfSSL_ERR_reason_error_string(err));
|
||||
fprintf(stderr, "wolfSSL_read failed\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -177,7 +181,8 @@ cleanup:
|
|||
ret = wolfSSL_shutdown(ssl);
|
||||
if (ret != WOLFSSL_SUCCESS) {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
fprintf(stderr, "err = %d, %s\n", err, wolfSSL_ERR_reason_error_string(err));
|
||||
fprintf(stderr, "err = %d, %s\n", err,
|
||||
wolfSSL_ERR_reason_error_string(err));
|
||||
fprintf(stderr, "wolfSSL_shutdown failed\n");
|
||||
}
|
||||
wolfSSL_free(ssl);
|
||||
|
|
|
@ -58,7 +58,7 @@ typedef struct conn_ctx {
|
|||
WOLFSSL* ssl;
|
||||
struct event* readEv;
|
||||
struct event* writeEv;
|
||||
char waitingOnData:1;
|
||||
unsigned char waitingOnData:1;
|
||||
} conn_ctx;
|
||||
|
||||
WOLFSSL_CTX* ctx = NULL;
|
||||
|
@ -109,7 +109,7 @@ int main(int argc, char** argv)
|
|||
goto cleanup;
|
||||
}
|
||||
/* Load server certificates */
|
||||
if (wolfSSL_CTX_use_certificate_file(ctx, servCertLoc, SSL_FILETYPE_PEM) !=
|
||||
if (wolfSSL_CTX_use_certificate_file(ctx, servCertLoc, SSL_FILETYPE_PEM) !=
|
||||
SSL_SUCCESS) {
|
||||
fprintf(stderr, "Error loading %s, please check the file.\n", servCertLoc);
|
||||
goto cleanup;
|
||||
|
@ -286,7 +286,7 @@ static void newConn(evutil_socket_t fd, short events, void* arg)
|
|||
static void setHsTimeout(WOLFSSL* ssl, struct timeval *tv)
|
||||
{
|
||||
int timeout = wolfSSL_dtls_get_current_timeout(ssl);
|
||||
#ifndef USE_DTLS12
|
||||
#ifdef WOLFSSL_DTLS13
|
||||
if (wolfSSL_dtls13_use_quick_timeout(ssl)) {
|
||||
if (timeout >= QUICK_MULT)
|
||||
tv->tv_sec = timeout / QUICK_MULT;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* server-dtls13.c
|
||||
*
|
||||
* Copyright (C) 2006-2022 wolfSSL Inc.
|
||||
* Copyright (C) 2006-2024 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSL. (formerly known as CyaSSL)
|
||||
*
|
||||
|
@ -26,7 +26,9 @@
|
|||
* Define USE_DTLS12 to use DTLS 1.2 instead of DTLS 1.3
|
||||
*/
|
||||
|
||||
#ifndef WOLFSSL_USER_SETTINGS
|
||||
#include <wolfssl/options.h>
|
||||
#endif
|
||||
#include <stdio.h> /* standard in/out procedures */
|
||||
#include <stdlib.h> /* defines system calls */
|
||||
#include <string.h> /* necessary for memset */
|
||||
|
@ -83,19 +85,19 @@ int main(int argc, char** argv)
|
|||
}
|
||||
/* Load CA certificates */
|
||||
if (wolfSSL_CTX_load_verify_locations(ctx,caCertLoc,0) !=
|
||||
SSL_SUCCESS) {
|
||||
WOLFSSL_SUCCESS) {
|
||||
fprintf(stderr, "Error loading %s, please check the file.\n", caCertLoc);
|
||||
goto cleanup;
|
||||
}
|
||||
/* Load server certificates */
|
||||
if (wolfSSL_CTX_use_certificate_file(ctx, servCertLoc, SSL_FILETYPE_PEM) !=
|
||||
SSL_SUCCESS) {
|
||||
if (wolfSSL_CTX_use_certificate_file(ctx, servCertLoc,
|
||||
WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
|
||||
fprintf(stderr, "Error loading %s, please check the file.\n", servCertLoc);
|
||||
goto cleanup;
|
||||
}
|
||||
/* Load server Keys */
|
||||
if (wolfSSL_CTX_use_PrivateKey_file(ctx, servKeyLoc,
|
||||
SSL_FILETYPE_PEM) != SSL_SUCCESS) {
|
||||
WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
|
||||
fprintf(stderr, "Error loading %s, please check the file.\n", servKeyLoc);
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -153,9 +155,10 @@ int main(int argc, char** argv)
|
|||
break;
|
||||
}
|
||||
|
||||
if (wolfSSL_accept(ssl) != SSL_SUCCESS) {
|
||||
if (wolfSSL_accept(ssl) != WOLFSSL_SUCCESS) {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
fprintf(stderr, "error = %d, %s\n", err, wolfSSL_ERR_reason_error_string(err));
|
||||
fprintf(stderr, "error = %d, %s\n", err,
|
||||
wolfSSL_ERR_reason_error_string(err));
|
||||
fprintf(stderr, "SSL_accept failed.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -171,14 +174,16 @@ int main(int argc, char** argv)
|
|||
err = wolfSSL_get_error(ssl, 0);
|
||||
if (err == WOLFSSL_ERROR_ZERO_RETURN) /* Received shutdown */
|
||||
break;
|
||||
fprintf(stderr, "error = %d, %s\n", err, wolfSSL_ERR_reason_error_string(err));
|
||||
fprintf(stderr, "error = %d, %s\n", err,
|
||||
wolfSSL_ERR_reason_error_string(err));
|
||||
fprintf(stderr, "SSL_read failed.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
printf("Sending reply.\n");
|
||||
if (wolfSSL_write(ssl, ack, sizeof(ack)) < 0) {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
fprintf(stderr, "error = %d, %s\n", err, wolfSSL_ERR_reason_error_string(err));
|
||||
fprintf(stderr, "error = %d, %s\n", err,
|
||||
wolfSSL_ERR_reason_error_string(err));
|
||||
fprintf(stderr, "wolfSSL_write failed.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -192,7 +197,8 @@ int main(int argc, char** argv)
|
|||
ret = wolfSSL_shutdown(ssl);
|
||||
if (ret != WOLFSSL_SUCCESS) {
|
||||
err = wolfSSL_get_error(ssl, 0);
|
||||
fprintf(stderr, "err = %d, %s\n", err, wolfSSL_ERR_reason_error_string(err));
|
||||
fprintf(stderr, "err = %d, %s\n", err,
|
||||
wolfSSL_ERR_reason_error_string(err));
|
||||
fprintf(stderr, "wolfSSL_shutdown failed\n");
|
||||
}
|
||||
wolfSSL_free(ssl);
|
||||
|
@ -200,7 +206,7 @@ int main(int argc, char** argv)
|
|||
|
||||
printf("Awaiting new connection\n");
|
||||
}
|
||||
|
||||
|
||||
exitVal = 0;
|
||||
cleanup:
|
||||
free_resources();
|
||||
|
|
Loading…
Reference in New Issue