This commit is contained in:
Edouard LEFIZELIER
2023-05-15 12:02:18 +02:00
parent 13d50a6a2d
commit aee649f6ff
2 changed files with 78 additions and 4 deletions
+7 -4
View File
@@ -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;
}
+71
View File
@@ -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