diff --git a/src/network/network.c b/src/network/network.c index 1001811..f9b983f 100644 --- a/src/network/network.c +++ b/src/network/network.c @@ -49,7 +49,11 @@ int net_initialize() } #endif /* WINSOCK */ - if (!net_backend_init()) + if (!net_backend_init() +#ifdef SSL_SUPPORT + || !net_ssl_library_init() +#endif + ) { #ifdef WINSOCK WSACleanup(); @@ -57,15 +61,6 @@ int net_initialize() return -1; } net_stats_initialize(); - -#ifdef SSL_SUPPORT -#ifdef SSL_USE_OPENSSL - LOG_TRACE("Initializing OpenSSL..."); - SSL_library_init(); - SSL_load_error_strings(); -#endif /* SSL_USE_OPENSSL */ -#endif /* SSL_SUPPORT */ - net_initialized = 1; return 0; } @@ -102,11 +97,7 @@ int net_destroy() net_backend_shutdown(); #ifdef SSL_SUPPORT -#ifdef SSL_USE_OPENSSL - ERR_free_strings(); - EVP_cleanup(); - CRYPTO_cleanup_all_ex_data(); -#endif /* SSL_USE_OPENSSL */ + net_ssl_library_shutdown(); #endif /* SSL_SUPPORT */ #ifdef WINSOCK diff --git a/src/network/openssl.c b/src/network/openssl.c index 78f6a5d..52beca0 100644 --- a/src/network/openssl.c +++ b/src/network/openssl.c @@ -52,6 +52,31 @@ const char* net_ssl_get_provider() return OPENSSL_VERSION_TEXT; } +int net_ssl_library_init() +{ + LOG_TRACE("Initializing OpenSSL..."); + SSL_library_init(); + SSL_load_error_strings(); + return 1; +} + +int net_ssl_library_shutdown() +{ + ERR_clear_error(); + ERR_remove_state(0); + + ENGINE_cleanup(); + CONF_modules_unload(1); + + ERR_free_strings(); + EVP_cleanup(); + CRYPTO_cleanup_all_ex_data(); + + // sk_SSL_COMP_free(SSL_COMP_get_compression_methods()); + return 1; +} + + /** * Create a new SSL context. @@ -302,4 +327,5 @@ void net_ssl_callback(struct net_connection* con, int events) #endif /* SSL_USE_OPENSSL */ -#endif /* SSL_SUPPORT */ \ No newline at end of file +#endif /* SSL_SUPPORT */ + diff --git a/src/network/tls.h b/src/network/tls.h index 25391a4..e40a558 100644 --- a/src/network/tls.h +++ b/src/network/tls.h @@ -50,6 +50,12 @@ struct ssl_context_handle; */ extern const char* net_ssl_get_provider(); +/** + * return 0 if error, 1 on success. + */ +extern int net_ssl_library_init(); +extern int net_ssl_library_shutdown(); + /** * Create a new SSL context. */ @@ -91,11 +97,8 @@ extern void net_ssl_callback(struct net_connection* con, int events); extern ssize_t net_con_ssl_handshake(struct net_connection* con, enum net_con_ssl_mode, struct ssl_context_handle* ssl_ctx); -extern SSL* net_con_get_ssl(struct net_connection* con); -#ifdef SSL_USE_OPENSSL -extern void net_con_set_ssl(struct net_connection* con, SSL*); -#endif // SSL_USE_OPENSSL extern int net_con_is_ssl(struct net_connection* con); #endif /* SSL_SUPPORT */ -#endif /* HAVE_UHUB_NETWORK_TLS_H */ \ No newline at end of file +#endif /* HAVE_UHUB_NETWORK_TLS_H */ +