From ca776ee103e304a9ca8a55a489c3f8849b0cf969 Mon Sep 17 00:00:00 2001 From: Lammert Bies Date: Sun, 11 Dec 2016 21:12:52 +0100 Subject: [PATCH] Moved SSL lookup tables to own file --- Makefile | 1 + src/extern_ssl_lut.c | 100 +++++++++++++++++++++++++++++++++++++++++++ src/libhttp.c | 73 ------------------------------- 3 files changed, 101 insertions(+), 73 deletions(-) create mode 100644 src/extern_ssl_lut.c diff --git a/Makefile b/Makefile index c29fb0af..f35d5a89 100644 --- a/Makefile +++ b/Makefile @@ -44,6 +44,7 @@ BUILD_DIRS = $(BUILD_DIR) $(BUILD_DIR)/src $(BUILD_DIR)/resources LIB_SOURCES = src/libhttp.c \ src/extern_md5.c \ src/extern_sha1.c \ + src/extern_ssl_lut.c \ src/httplib_accept_new_connection.c \ src/httplib_addenv.c \ src/httplib_atomic_dec.c \ diff --git a/src/extern_ssl_lut.c b/src/extern_ssl_lut.c new file mode 100644 index 00000000..21b1fcd3 --- /dev/null +++ b/src/extern_ssl_lut.c @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2016 Lammert Bies + * Copyright (c) 2013-2016 the Civetweb developers + * Copyright (c) 2004-2013 Sergey Lyubka + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + + +#include "libhttp-private.h" + + + +#if !defined(NO_SSL) && !defined(NO_SSL_DL) + +/* XX_httplib_set_ssl_option() function updates this array. + * It loads SSL library dynamically and changes NULLs to the actual addresses + * of respective functions. The macros above (like SSL_connect()) are really + * just calling these functions indirectly via the pointer. */ +struct ssl_func XX_httplib_ssl_sw[] = { + { "SSL_free", NULL }, + { "SSL_accept", NULL }, + { "SSL_connect", NULL }, + { "SSL_read", NULL }, + { "SSL_write", NULL }, + { "SSL_get_error", NULL }, + { "SSL_set_fd", NULL }, + { "SSL_new", NULL }, + { "SSL_CTX_new", NULL }, + { "SSLv23_server_method", NULL }, + { "SSL_library_init", NULL }, + { "SSL_CTX_use_PrivateKey_file", NULL }, + { "SSL_CTX_use_certificate_file", NULL }, + { "SSL_CTX_set_default_passwd_cb", NULL }, + { "SSL_CTX_free", NULL }, + { "SSL_load_error_strings", NULL }, + { "SSL_CTX_use_certificate_chain_file", NULL }, + { "SSLv23_client_method", NULL }, + { "SSL_pending", NULL }, + { "SSL_CTX_set_verify", NULL }, + { "SSL_shutdown", NULL }, + { "SSL_CTX_load_verify_locations", NULL }, + { "SSL_CTX_set_default_verify_paths", NULL }, + { "SSL_CTX_set_verify_depth", NULL }, + { "SSL_get_peer_certificate", NULL }, + { "SSL_get_version", NULL }, + { "SSL_get_current_cipher", NULL }, + { "SSL_CIPHER_get_name", NULL }, + { "SSL_CTX_check_private_key", NULL }, + { "SSL_CTX_set_session_id_context", NULL }, + { "SSL_CTX_ctrl", NULL }, + { "SSL_CTX_set_cipher_list", NULL }, + { NULL, NULL } +}; + + +/* Similar array as XX_httplib_ssl_sw. These functions could be located in different + * lib. */ +struct ssl_func XX_httplib_crypto_sw[] = { + { "CRYPTO_num_locks", NULL }, + { "CRYPTO_set_locking_callback", NULL }, + { "CRYPTO_set_id_callback", NULL }, + { "ERR_get_error", NULL }, + { "ERR_error_string", NULL }, + { "ERR_remove_state", NULL }, + { "ERR_free_strings", NULL }, + { "ENGINE_cleanup", NULL }, + { "CONF_modules_unload", NULL }, + { "CRYPTO_cleanup_all_ex_data", NULL }, + { "EVP_cleanup", NULL }, + { "X509_free", NULL }, + { "X509_get_subject_name", NULL }, + { "X509_get_issuer_name", NULL }, + { "X509_NAME_oneline", NULL }, + { "X509_get_serialNumber", NULL }, + { "i2c_ASN1_INTEGER", NULL }, + { "EVP_get_digestbyname", NULL }, + { "ASN1_digest", NULL }, + { "i2d_X509", NULL }, + { NULL, NULL } +}; + +#endif /* !defined(NO_SSL) && !defined(NO_SSL_DL) */ diff --git a/src/libhttp.c b/src/libhttp.c index 84423f82..ca9aef39 100644 --- a/src/libhttp.c +++ b/src/libhttp.c @@ -280,79 +280,6 @@ typedef int socklen_t; #define _DARWIN_UNLIMITED_SELECT -#if !defined(NO_SSL) && !defined(NO_SSL_DL) - -/* XX_httplib_set_ssl_option() function updates this array. - * It loads SSL library dynamically and changes NULLs to the actual addresses - * of respective functions. The macros above (like SSL_connect()) are really - * just calling these functions indirectly via the pointer. */ -struct ssl_func XX_httplib_ssl_sw[] = { - { "SSL_free", NULL }, - { "SSL_accept", NULL }, - { "SSL_connect", NULL }, - { "SSL_read", NULL }, - { "SSL_write", NULL }, - { "SSL_get_error", NULL }, - { "SSL_set_fd", NULL }, - { "SSL_new", NULL }, - { "SSL_CTX_new", NULL }, - { "SSLv23_server_method", NULL }, - { "SSL_library_init", NULL }, - { "SSL_CTX_use_PrivateKey_file", NULL }, - { "SSL_CTX_use_certificate_file", NULL }, - { "SSL_CTX_set_default_passwd_cb", NULL }, - { "SSL_CTX_free", NULL }, - { "SSL_load_error_strings", NULL }, - { "SSL_CTX_use_certificate_chain_file", NULL }, - { "SSLv23_client_method", NULL }, - { "SSL_pending", NULL }, - { "SSL_CTX_set_verify", NULL }, - { "SSL_shutdown", NULL }, - { "SSL_CTX_load_verify_locations", NULL }, - { "SSL_CTX_set_default_verify_paths", NULL }, - { "SSL_CTX_set_verify_depth", NULL }, - { "SSL_get_peer_certificate", NULL }, - { "SSL_get_version", NULL }, - { "SSL_get_current_cipher", NULL }, - { "SSL_CIPHER_get_name", NULL }, - { "SSL_CTX_check_private_key", NULL }, - { "SSL_CTX_set_session_id_context", NULL }, - { "SSL_CTX_ctrl", NULL }, - { "SSL_CTX_set_cipher_list", NULL }, - { NULL, NULL } -}; - - -/* Similar array as XX_httplib_ssl_sw. These functions could be located in different - * lib. */ -struct ssl_func XX_httplib_crypto_sw[] = { - { "CRYPTO_num_locks", NULL }, - { "CRYPTO_set_locking_callback", NULL }, - { "CRYPTO_set_id_callback", NULL }, - { "ERR_get_error", NULL }, - { "ERR_error_string", NULL }, - { "ERR_remove_state", NULL }, - { "ERR_free_strings", NULL }, - { "ENGINE_cleanup", NULL }, - { "CONF_modules_unload", NULL }, - { "CRYPTO_cleanup_all_ex_data", NULL }, - { "EVP_cleanup", NULL }, - { "X509_free", NULL }, - { "X509_get_subject_name", NULL }, - { "X509_get_issuer_name", NULL }, - { "X509_NAME_oneline", NULL }, - { "X509_get_serialNumber", NULL }, - { "i2c_ASN1_INTEGER", NULL }, - { "EVP_get_digestbyname", NULL }, - { "ASN1_digest", NULL }, - { "i2d_X509", NULL }, - { NULL, NULL } -}; - -#endif /* !defined(NO_SSL) && !defined(NO_SSL_DL) */ - - - pthread_key_t XX_httplib_sTlsKey; /* Thread local storage index */ int XX_httplib_sTlsInit = 0; int XX_httplib_thread_idx_max = 0;