From 8991567af06eb8a07a6d5512653f5fb3f93d6eae Mon Sep 17 00:00:00 2001 From: Nathan French Date: Tue, 22 Jan 2019 13:16:20 -0500 Subject: [PATCH 01/11] Add htp__evbuffer_add_iovec_ helper for libevent < 2.1 --- evhtp.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/evhtp.c b/evhtp.c index 5a4915a..2e70918 100644 --- a/evhtp.c +++ b/evhtp.c @@ -2013,6 +2013,34 @@ htp__request_parse_fini_(htparser * p) return 0; } /* htp__request_parse_fini_ */ +static size_t +htp__evbuffer_add_iovec_(struct evbuffer * buf, struct evbuffer_iovec * vec, int n_vec) +{ +#if LIBEVENT_VERSION_NUMBER < 0x02010000 + int n; + size_t res; + size_t to_alloc; + + res = to_alloc = 0; + + for (n = 0; n < n_vec; n++) { + to_alloc += vec[n].iov_len; + } + + evbuffer_expand(buf, to_alloc); + + for (n = 0; n < n_vec; n++) { + evbuffer_add(buf, vec[n].iov_base, vec[n].iov_len); + + res += vec[n].iov_len; + } + + return res; +#else + return evbuffer_add_iovec(buf, vec, n_vec); +#endif +} + static int htp__create_headers_(evhtp_header_t * header, void * arg) { @@ -2031,7 +2059,7 @@ htp__create_headers_(evhtp_header_t * header, void * arg) iov[3].iov_base = "\r\n"; iov[3].iov_len = 2; - evbuffer_add_iovec(buf, iov, 4); + htp__evbuffer_add_iovec_(buf, iov, 4); return 0; } @@ -2180,7 +2208,7 @@ htp__create_reply_(evhtp_request_t * request, evhtp_res code) iov[8].iov_base = "\r\n"; iov[8].iov_len = 2; - evbuffer_add_iovec(buf, iov, 9); + htp__evbuffer_add_iovec_(buf, iov, 9); } evhtp_headers_for_each(request->headers_out, htp__create_headers_, buf); From 78e8e41bdbd360dacb7671d3326d566330182b3e Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 18 Jan 2019 13:13:47 -0800 Subject: [PATCH 02/11] Fix compilation without deprecated OpenSSL 1.1 APIs All threading APIs are gone with 1.1. dh.h header does not get included with ssl.h automatically when deprecated APIs are disabled. X509_getBefore/After were replaced with get0 and getm variants. Switched to the former as it can be const. --- evhtp.c | 5 +++++ include/evhtp/evhtp.h | 1 + sslutils.c | 29 +++++++++++++++++------------ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/evhtp.c b/evhtp.c index ee869c0..141a04c 100644 --- a/evhtp.c +++ b/evhtp.c @@ -2827,6 +2827,7 @@ htp__accept_cb_(struct evconnlistener * serv, int fd, struct sockaddr * s, int s #ifndef EVHTP_DISABLE_SSL #ifndef EVHTP_DISABLE_EVTHR +#if OPENSSL_VERSION_NUMBER < 0x10100000L static #if OPENSSL_VERSION_NUMBER >= 0x10000000L void @@ -2854,6 +2855,8 @@ htp__ssl_get_thread_id_( #else return tid; #endif + +#endif } static void @@ -4692,6 +4695,7 @@ evhtp_set_post_accept_cb(evhtp_t * htp, evhtp_post_accept_cb cb, void * arg) #ifndef EVHTP_DISABLE_SSL #ifndef EVHTP_DISABLE_EVTHR +#if OPENSSL_VERSION_NUMBER < 0x10100000L int evhtp_ssl_use_threads(void) { @@ -4724,6 +4728,7 @@ evhtp_ssl_use_threads(void) return 0; } +#endif #endif int diff --git a/include/evhtp/evhtp.h b/include/evhtp/evhtp.h index ff63bc8..735e07f 100644 --- a/include/evhtp/evhtp.h +++ b/include/evhtp/evhtp.h @@ -26,6 +26,7 @@ #ifndef EVHTP_DISABLE_SSL #include +#include #include #include #include diff --git a/sslutils.c b/sslutils.c index 9c0e480..9f724d6 100644 --- a/sslutils.c +++ b/sslutils.c @@ -10,6 +10,11 @@ #include "evhtp/sslutils.h" #include "internal.h" +#if OPENSSL_VERSION_NUMBER < 0x10100000L +#define X509_get0_notBefore X509_get_notBefore +#define X509_get0_notAfter X509_get_notAfter +#endif + unsigned char * htp_sslutil_subject_tostr(evhtp_ssl_t * ssl) { unsigned char * subj_str; @@ -78,11 +83,11 @@ htp_sslutil_issuer_tostr(evhtp_ssl_t * ssl) { unsigned char * htp_sslutil_notbefore_tostr(evhtp_ssl_t * ssl) { - BIO * bio; - X509 * cert; - ASN1_TIME * time; - size_t len; - unsigned char * time_str; + BIO * bio; + X509 * cert; + const ASN1_TIME * time; + size_t len; + unsigned char * time_str; if (!ssl) { return NULL; @@ -92,7 +97,7 @@ htp_sslutil_notbefore_tostr(evhtp_ssl_t * ssl) { return NULL; } - if (!(time = X509_get_notBefore(cert))) { + if (!(time = X509_get0_notBefore(cert))) { X509_free(cert); return NULL; } @@ -128,11 +133,11 @@ htp_sslutil_notbefore_tostr(evhtp_ssl_t * ssl) { unsigned char * htp_sslutil_notafter_tostr(evhtp_ssl_t * ssl) { - BIO * bio; - X509 * cert; - ASN1_TIME * time; - size_t len; - unsigned char * time_str; + BIO * bio; + X509 * cert; + const ASN1_TIME * time; + size_t len; + unsigned char * time_str; if (!ssl) { return NULL; @@ -142,7 +147,7 @@ htp_sslutil_notafter_tostr(evhtp_ssl_t * ssl) { return NULL; } - if (!(time = X509_get_notAfter(cert))) { + if (!(time = X509_get0_notAfter(cert))) { X509_free(cert); return NULL; } From 8e543fe0aaacc4665a3869db6db8d629bc127b88 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Tue, 22 Jan 2019 17:28:51 -0800 Subject: [PATCH 03/11] Reorganize OpenSSL < 1.0.0 compatibility for greater readability. --- evhtp.c | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/evhtp.c b/evhtp.c index 141a04c..0592a57 100644 --- a/evhtp.c +++ b/evhtp.c @@ -2828,36 +2828,28 @@ htp__accept_cb_(struct evconnlistener * serv, int fd, struct sockaddr * s, int s #ifndef EVHTP_DISABLE_SSL #ifndef EVHTP_DISABLE_EVTHR #if OPENSSL_VERSION_NUMBER < 0x10100000L -static -#if OPENSSL_VERSION_NUMBER >= 0x10000000L -void -#else -unsigned long -#endif -htp__ssl_get_thread_id_( -#if OPENSSL_VERSION_NUMBER >= 0x10000000L - CRYPTO_THREADID * id -#else - void -#endif - ) -{ - unsigned long tid; #ifndef WIN32 - tid = (unsigned long)pthread_self(); +#define tid (unsigned long)pthread_self() #else - tid = pthread_self().p; +#define tid pthread_self().p #endif -#if OPENSSL_VERSION_NUMBER >= 0x10000000L - CRYPTO_THREADID_set_numeric(id, tid); +#if OPENSSL_VERSION_NUMBER < 0x10000000L +static unsigned long +htp__ssl_get_thread_id_(void) +{ + return tid; +} #else - return tid; +static void +htp__ssl_get_thread_id_(CRYPTO_THREADID *id) +{ + CRYPTO_THREADID_set_numeric(id, tid); +} #endif #endif -} static void htp__ssl_thread_lock_(int mode, int type, const char * file, int line) From 6a74ec7a8747c09d77d4fed6feda2530feca5d5c Mon Sep 17 00:00:00 2001 From: maxice8 Date: Wed, 23 Jan 2019 01:37:29 -0200 Subject: [PATCH 04/11] add missing include for ssize_t --- parser.c | 1 + 1 file changed, 1 insertion(+) diff --git a/parser.c b/parser.c index a4e3d78..3e3e25f 100644 --- a/parser.c +++ b/parser.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "internal.h" #include "evhtp/parser.h" From 32575fc3a3711bf58ac4e1a0a226906d6a83fe34 Mon Sep 17 00:00:00 2001 From: Nathan French Date: Wed, 23 Jan 2019 12:15:51 -0500 Subject: [PATCH 05/11] [#123] check for sys/types.h --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e08acb3..4f625af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,7 @@ check_include_files(stdarg.h HAVE_STDARG_PROTOTYPES) check_include_files(sys/tree.h HAVE_SYS_TREE) check_include_files(sys/queue.h HAVE_SYS_QUEUE) check_include_files(sys/un.h HAVE_SYS_UN) +check_include_files(sys/types.h HAVE_SYS_TYPES_H) check_type_size("int" SIZEOF_INT) check_type_size("long" SIZEOF_LONG) @@ -126,6 +127,10 @@ if(has_c99) target_compile_definitions(evhtp PUBLIC EVHTP_HAS_C99) endif() +if (HAVE_SYS_TYPES_H) + target_compile_definitions(evhtp PUBLIC EVHTP_HAS_SYS_TYPES) +endif() + if(NOT HAVE_SYS_TREE) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/compat/sys/tree.h.in From 0839f8e7befdc1725765b57d2168960a63129113 Mon Sep 17 00:00:00 2001 From: Nathan French Date: Wed, 23 Jan 2019 12:18:48 -0500 Subject: [PATCH 06/11] [#123] include sys/types only if EVHTP_HAS_SYS_TYPES is set --- parser.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/parser.c b/parser.c index 3e3e25f..2bb84a1 100644 --- a/parser.c +++ b/parser.c @@ -2,7 +2,10 @@ #include #include #include + +#ifdef EVHTP_HAS_SYS_TYPES #include +#endif #include "internal.h" #include "evhtp/parser.h" From 7d0fd5d50ece4a41a02d44c0335486839281a156 Mon Sep 17 00:00:00 2001 From: Nathan French Date: Thu, 24 Jan 2019 10:43:13 -0500 Subject: [PATCH 07/11] [#122] cleanup for ssl locking changes --- evhtp.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/evhtp.c b/evhtp.c index 0592a57..6a1c44c 100644 --- a/evhtp.c +++ b/evhtp.c @@ -2827,27 +2827,27 @@ htp__accept_cb_(struct evconnlistener * serv, int fd, struct sockaddr * s, int s #ifndef EVHTP_DISABLE_SSL #ifndef EVHTP_DISABLE_EVTHR -#if OPENSSL_VERSION_NUMBER < 0x10100000L #ifndef WIN32 -#define tid (unsigned long)pthread_self() +#define _HTP_tid (unsigned long)pthread_self() #else -#define tid pthread_self().p +#define _HTP_tid pthread_self().p #endif #if OPENSSL_VERSION_NUMBER < 0x10000000L static unsigned long htp__ssl_get_thread_id_(void) { - return tid; + return _HTP_tid; } + #else + static void -htp__ssl_get_thread_id_(CRYPTO_THREADID *id) +htp__ssl_get_thread_id_(CRYPTO_THREADID * id) { - CRYPTO_THREADID_set_numeric(id, tid); + CRYPTO_THREADID_set_numeric(id, _HTP_tid); } -#endif #endif @@ -4687,7 +4687,6 @@ evhtp_set_post_accept_cb(evhtp_t * htp, evhtp_post_accept_cb cb, void * arg) #ifndef EVHTP_DISABLE_SSL #ifndef EVHTP_DISABLE_EVTHR -#if OPENSSL_VERSION_NUMBER < 0x10100000L int evhtp_ssl_use_threads(void) { @@ -4720,7 +4719,6 @@ evhtp_ssl_use_threads(void) return 0; } -#endif #endif int From 8ae5cddb9b6e9ed1acf3c3f3f0bab31d29a03972 Mon Sep 17 00:00:00 2001 From: Nathan French Date: Tue, 29 Jan 2019 12:06:58 -0500 Subject: [PATCH 08/11] better get0_notBefore ssl defs --- sslutils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sslutils.c b/sslutils.c index 9f724d6..87568c6 100644 --- a/sslutils.c +++ b/sslutils.c @@ -11,8 +11,8 @@ #include "internal.h" #if OPENSSL_VERSION_NUMBER < 0x10100000L -#define X509_get0_notBefore X509_get_notBefore -#define X509_get0_notAfter X509_get_notAfter +#define X509_get0_notBefore(x) X509_get_notBefore(x) +#define X509_get0_notAfter(x) X509_get_notAfter(x) #endif unsigned char * From 718c406fd206aa4ca37f3c67f1b3a52702928bbb Mon Sep 17 00:00:00 2001 From: Nathan French Date: Tue, 29 Jan 2019 19:19:11 -0500 Subject: [PATCH 09/11] update test_client with new addr --- examples/test_client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/test_client.c b/examples/test_client.c index 8a5983c..aa5ac4c 100644 --- a/examples/test_client.c +++ b/examples/test_client.c @@ -52,7 +52,7 @@ main(int argc, char ** argv) evhtp_request_t * request; evbase = event_base_new(); - conn = evhtp_connection_new(evbase, "75.126.169.52", 80); + conn = evhtp_connection_new(evbase, "104.27.150.225", 80); request = evhtp_request_new(request_cb, evbase); evhtp_request_set_hook(request, evhtp_hook_on_read, print_data, evbase); From 874a225ddcec9a514e782539e4df3c36d5fea82f Mon Sep 17 00:00:00 2001 From: Nathan French Date: Tue, 29 Jan 2019 19:35:29 -0500 Subject: [PATCH 10/11] cleanup / optimization for iovec operations --- evhtp.c | 70 +++++++++++++++------------------------------------------ 1 file changed, 18 insertions(+), 52 deletions(-) diff --git a/evhtp.c b/evhtp.c index ca76c98..8d34676 100644 --- a/evhtp.c +++ b/evhtp.c @@ -2044,20 +2044,13 @@ htp__evbuffer_add_iovec_(struct evbuffer * buf, struct evbuffer_iovec * vec, int static int htp__create_headers_(evhtp_header_t * header, void * arg) { - struct evbuffer * buf = arg; - struct evbuffer_iovec iov[4]; - - iov[0].iov_base = header->key; - iov[0].iov_len = header->klen; - - iov[1].iov_base = ": "; - iov[1].iov_len = 2; - - iov[2].iov_base = header->val; - iov[2].iov_len = header->vlen; - - iov[3].iov_base = "\r\n"; - iov[3].iov_len = 2; + struct evbuffer * buf = arg; + struct evbuffer_iovec iov[4] = { + { header->key, header->klen }, + { ": ", 2 }, + { header->val, header->vlen }, + { "\r\n", 2 } + }; htp__evbuffer_add_iovec_(buf, iov, 4); @@ -2168,45 +2161,18 @@ htp__create_reply_(evhtp_request_t * request, evhtp_res code) * of the header. */ { - struct evbuffer_iovec iov[9]; const char * status_str = status_code_to_str(code); - - /* data == "HTTP/" */ - iov[0].iov_base = "HTTP/"; - iov[0].iov_len = 5; - - /* data == "HTTP/X" */ - iov[1].iov_base = (void *)&major; - iov[1].iov_len = 1; - - /* data == "HTTP/X." */ - iov[2].iov_base = "."; - iov[2].iov_len = 1; - - /* data == "HTTP/X.X" */ - iov[3].iov_base = (void *)&minor; - iov[3].iov_len = 1; - - - /* data == "HTTP/X.X " */ - iov[4].iov_base = " "; - iov[4].iov_len = 1; - - /* data == "HTTP/X.X YYY" */ - iov[5].iov_base = out_buf; - iov[5].iov_len = strlen(out_buf); - - /* data == "HTTP/X.X YYY " */ - iov[6].iov_base = " "; - iov[6].iov_len = 1; - - /* data == "HTTP/X.X YYY ZZZ" */ - iov[7].iov_base = (void *)status_str; - iov[7].iov_len = strlen(status_str); - - /* data == "HTTP/X.X YYY ZZZ\r\n" */ - iov[8].iov_base = "\r\n"; - iov[8].iov_len = 2; + struct evbuffer_iovec iov[9] = { + { "HTTP/1", 5 }, /* data == "HTTP/" */ + { (void *)&major, 1 }, /* data == "HTTP/X */ + { ".", 1 }, /* data == "HTTP/X." */ + { (void *)&minor, 1 }, /* data == "HTTP/X.X" */ + { " ", 1 }, /* data == "HTTP/X.X " */ + { out_buf, strlen(out_buf) }, /* data = "HTTP/X.X YYY" */ + { " ", 1 }, /* data = "HTTP/X.X YYY " */ + { (void *)status_str, strlen(status_str) }, /* data = "HTTP/X.X YYY ZZZ" */ + { "\r\n", 2 }, /* data = "HTTP/X.X YYY ZZZ\r\n" */ + }; htp__evbuffer_add_iovec_(buf, iov, 9); } From 01ad044edf966a3a3a29d744024c8b3b7b0d5ae6 Mon Sep 17 00:00:00 2001 From: Nathan French Date: Wed, 6 Feb 2019 11:46:03 -0500 Subject: [PATCH 11/11] Release v1.2.18, see ChangeLog for details --- CMakeLists.txt | 2 +- ChangeLog | 12 +++++++++++- include/evhtp/evhtp.h | 4 ++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f625af..481ddd0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.1) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) -project(libevhtp VERSION "1.2.17") +project(libevhtp VERSION "1.2.18") # For us YCM users. set(CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/ChangeLog b/ChangeLog index 2a4491e..7b4d906 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,14 @@ -v1.2.17 +v1.2.18 + o Add htp__evbuffer_add_iovec_ helper for libevent < 2.1 (8991567 Nathan French) + o [#122] Fix compilation without deprecated OpenSSL 1.1 APIs (78e8e41 Rosen Penev) + o [#122] Reorganize OpenSSL < 1.0.0 compatibility for greater readability. (8e543fe Rosen Penev) + o [#123] add missing include for ssize_t (6a74ec7 maxice8) + o [#123] include sys/types only if EVHTP_HAS_SYS_TYPES is set (0839f8e Nathan French) + o [#122] cleanup for ssl locking changes (7d0fd5d Nathan French) + o better get0_notBefore ssl defs (8ae5cdd Nathan French) + o cleanup / optimization for iovec operations (874a225 Nathan French) + +v1.2.17 (alpha/beta) o [#111] assert frontends not compiled with -DNDEBUG (07d6f5f Nathan French) o [#111] Remove asserts for alloc functions. (#112) (114bf53 Nathan French) o [#108] do not include content-length with chunked (#113) (73255df Nathan French) diff --git a/include/evhtp/evhtp.h b/include/evhtp/evhtp.h index 33372fe..9bcee44 100644 --- a/include/evhtp/evhtp.h +++ b/include/evhtp/evhtp.h @@ -189,10 +189,10 @@ typedef evhtp_ssl_sess_t * (* evhtp_ssl_scache_get)(evhtp_connection_t * connect typedef void * (* evhtp_ssl_scache_init)(evhtp_t *); #endif -#define EVHTP_VERSION "1.2.17" +#define EVHTP_VERSION "1.2.18" #define EVHTP_VERSION_MAJOR 1 #define EVHTP_VERSION_MINOR 2 -#define EVHTP_VERSION_PATCH 17 +#define EVHTP_VERSION_PATCH 18 #define evhtp_headers_iterator evhtp_kvs_iterator