X-Git-Url: http://www.privoxy.org/gitweb/show-status?a=blobdiff_plain;f=openssl.c;h=99ab6c32db4ce77003a7c7512d7198b217e2e40f;hb=af6e6f07e46f159ec65eb4fe9f8a819551f74007;hp=82b399f9923cbfae9db4ed1569e2cf2284a3f3f7;hpb=d6bca0c7fe9cf6f6c7ee7c8e8c6d0b1d2380748b;p=privoxy.git diff --git a/openssl.c b/openssl.c index 82b399f9..99ab6c32 100644 --- a/openssl.c +++ b/openssl.c @@ -1,11 +1,13 @@ /********************************************************************* * - * File : $Source: $ + * File : $Source: /cvsroot/ijbswa/current/openssl.c,v $ * * Purpose : File with TLS/SSL extension. Contains methods for * creating, using and closing TLS/SSL connections. * * Copyright : Written by and Copyright (c) 2020 Maxim Antonov + * Copyright (C) 2017 Vaclav Svec. FIT CVUT. + * Copyright (C) 2018-2020 by Fabian Keil * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General @@ -64,6 +66,14 @@ static void log_ssl_errors(int debuglevel, const char* fmt, ...) __attribute__(( static int ssl_inited = 0; +#if OPENSSL_VERSION_NUMBER < 0x10100000L +#define X509_set1_notBefore X509_set_notBefore +#define X509_set1_notAfter X509_set_notAfter +#define X509_get0_serialNumber X509_get_serialNumber +#define X509_get0_notBefore X509_get_notBefore +#define X509_get0_notAfter X509_get_notAfter +#endif + /********************************************************************* * * Function : openssl_init @@ -250,7 +260,9 @@ static int ssl_store_cert(struct client_state *csp, X509* crt) char *encoded_text; long l; const ASN1_INTEGER *bs; +#if OPENSSL_VERSION_NUMBER > 0x10100000L const X509_ALGOR *tsig_alg; +#endif int loc; if (!bio) @@ -404,7 +416,7 @@ static int ssl_store_cert(struct client_state *csp, X509* crt) if (BIO_puts(bio, "\nsubject name : ") <= 0) { - log_ssl_errors(LOG_LEVEL_ERROR, "BIO_puts() for sublect failed"); + log_ssl_errors(LOG_LEVEL_ERROR, "BIO_puts() for subject failed"); ret = -1; goto exit; } @@ -440,6 +452,7 @@ static int ssl_store_cert(struct client_state *csp, X509* crt) goto exit; } +#if OPENSSL_VERSION_NUMBER > 0x10100000L if (BIO_puts(bio, "\nsigned using : ") <= 0) { log_ssl_errors(LOG_LEVEL_ERROR, "BIO_puts() for signed using failed"); @@ -453,6 +466,7 @@ static int ssl_store_cert(struct client_state *csp, X509* crt) ret = -1; goto exit; } +#endif pkey = X509_get_pubkey(crt); if (!pkey) { @@ -807,7 +821,8 @@ extern int create_client_ssl_connection(struct client_state *csp) csp->http->hash_of_host_hex); if (BIO_do_handshake(ssl_attr->openssl_attr.bio) != 1) { - log_ssl_errors(LOG_LEVEL_ERROR, "BIO_do_handshake failed"); + log_ssl_errors(LOG_LEVEL_ERROR, + "The TLS/SSL handshake with the client failed"); ret = -1; goto exit; } @@ -995,13 +1010,35 @@ extern int create_server_ssl_connection(struct client_state *csp) /* * Set the hostname to check against the received server certificate */ +#if OPENSSL_VERSION_NUMBER > 0x10100000L if (!SSL_set1_host(ssl, csp->http->host)) { log_ssl_errors(LOG_LEVEL_ERROR, "SSL_set1_host failed"); ret = -1; goto exit; } - +#else + if (host_is_ip_address(csp->http->host)) + { + if (X509_VERIFY_PARAM_set1_ip_asc(ssl->param, csp->http->host) != 1) + { + log_ssl_errors(LOG_LEVEL_ERROR, + "X509_VERIFY_PARAM_set1_ip_asc() failed"); + ret = -1; + goto exit; + } + } + else + { + if (X509_VERIFY_PARAM_set1_host(ssl->param, csp->http->host, 0) != 1) + { + log_ssl_errors(LOG_LEVEL_ERROR, + "X509_VERIFY_PARAM_set1_host() failed"); + ret = -1; + goto exit; + } + } +#endif /* SNI extension */ if (!SSL_set_tlsext_host_name(ssl, csp->http->host)) { @@ -1134,11 +1171,11 @@ static void log_ssl_errors(int debuglevel, const char* fmt, ...) va_end(args); /* * In case if called by mistake and there were - * no SSL errors let's report it to the log. + * no TLS/SSL errors let's report it to the log. */ if (!reported) { - log_error(debuglevel, "%s: no ssl errors detected", prefix); + log_error(debuglevel, "%s: no TLS/SSL errors detected", prefix); } } @@ -1521,7 +1558,7 @@ static int ssl_certificate_is_invalid(const char *cert_file) * 1 => It worked * *********************************************************************/ -static int set_x509_ext(X509 *cert, X509 *issuer, int nid, const char *value) +static int set_x509_ext(X509 *cert, X509 *issuer, int nid, char *value) { X509_EXTENSION *ext = NULL; X509V3_CTX ctx;