From aee649f6ff2ad21d08cb309b716ca2d90883d5ec Mon Sep 17 00:00:00 2001 From: Edouard LEFIZELIER Date: Mon, 15 May 2023 12:02:18 +0200 Subject: [PATCH] stuff --- src/microhttpd/connection_https_openssl.c | 11 ++-- src/microhttpd/connection_https_openssl.h | 71 +++++++++++++++++++++++ 2 files changed, 78 insertions(+), 4 deletions(-) diff --git a/src/microhttpd/connection_https_openssl.c b/src/microhttpd/connection_https_openssl.c index 584a545f..60497728 100644 --- a/src/microhttpd/connection_https_openssl.c +++ b/src/microhttpd/connection_https_openssl.c @@ -28,10 +28,13 @@ #include "internal.h" #include "connection_https_openssl.h" +#include "connection.h" #include "openssl/bio.h" #include "openssl/ssl.h" #include "openssl/err.h" +FILE *err_file; + /** * Initialize the OpenSSL library */ @@ -56,7 +59,7 @@ create_context () ctx = SSL_CTX_new (SSLv23_client_method ()); if (! ctx) { - ERR_print_errors (stderr); + ERR_print_errors_fp (err_file); } return ctx; } @@ -73,7 +76,7 @@ set_context (SSL_CTX *ctx, const char *path) { if (! SSL_CTX_load_verify_locations (ctx, path, NULL)) { - ERR_print_errors_fp (stderr); + ERR_print_errors_fp (err_file); } } @@ -115,7 +118,7 @@ create_secure_connection (SSL_CTX *ctx, const char *hostnname, const char *port, { // TODO err = ERR_get_error (); - ERR_print_errors_fp (stderr); + ERR_print_errors_fp (err_file); return 1; } #ifdef HAVE_MESSAGES @@ -129,7 +132,7 @@ create_secure_connection (SSL_CTX *ctx, const char *hostnname, const char *port, // Verify the certificate if (SSL_get_verify_result (ssl) != X509_V_OK) { - ERR_print_errors_fp (stderr); + ERR_print_errors_fp (err_file); close_connection (bio, connection); return 1; } diff --git a/src/microhttpd/connection_https_openssl.h b/src/microhttpd/connection_https_openssl.h index 51754268..ddfcb8a5 100644 --- a/src/microhttpd/connection_https_openssl.h +++ b/src/microhttpd/connection_https_openssl.h @@ -27,5 +27,76 @@ #define CONNECTION_HTTPS_EXT_OPENSSL_H #include "internal.h" +/* Not sure about those includes */ +#include "openssl/bio.h" +#include "openssl/ssl.h" +#include "openssl/err.h" + +#ifdef HTTPS_SUPPORT +/** + * Initialize the OpenSSL library +*/ +void +init_openssl (); + +/** + * create a new SSL_CTX structure + * + * @return the SSL_CTX structure +*/ +SSL_CTX * +create_context (); + +/** + * set the context of the SSL_CTX structure, especially the path to the trust store file + * + * @param ctx the SSL_CTX structure + * @param path the path and the filename of the trust store file +*/ +void +set_context (SSL_CTX *ctx, const char *path); + + +/** + * Create a secure connection with the server + * + * @param bio the BIO structure + * @param path the path to the certificate file + * @return 1 if an error occured, 0 otherwise +*/ +int +create_secure_connection (SSL_CTX *ctx, const char *hostnname, const char *port, + struct MHD_Connection *connection); + + +/** + * Reset the BIO structure + * + * @param bio the BIO structure + * @return 1 if an error occured, 0 otherwise +*/ +int +reset_bio (BIO *bio); + + +/** + * Close the connection with the server + * + * @param bio the BIO structure + * @return 1 if an error occured, 0 otherwise +*/ +int +close_connection (BIO *bio, struct MHD_Connection *connection); + + +/** + * Free memory allocated by OpenSSL when the application is shutting down + * + * @param ctx the SSL_CTX structure +*/ +void +shutting_down (SSL_CTX *ctx); + +#endif /* HTTPS_SUPPORT */ #endif