From patchwork Fri Jan 19 22:42:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steffan Karger X-Patchwork-Id: 203 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director2.mail.ord1d.rsapps.net ([172.28.255.1]) by backend31.mail.ord1d.rsapps.net (Dovecot) with LMTP id AzmTGtkPY1qUYAAAgoeIoA for ; Sat, 20 Jan 2018 04:46:01 -0500 Received: from director7.mail.ord1c.rsapps.net ([172.28.255.1]) by director2.mail.ord1d.rsapps.net (Dovecot) with LMTP id a3jpBtkPY1ogLQAAgYhSiA ; Sat, 20 Jan 2018 04:46:01 -0500 Received: from smtp3.gate.ord1c ([172.28.255.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by director7.mail.ord1c.rsapps.net (Dovecot) with LMTP id PzF4BdkPY1paIwAAqdfm7w ; Sat, 20 Jan 2018 04:46:01 -0500 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.34.181.88] Authentication-Results: smtp3.gate.ord1c.rsapps.net; iprev=pass policy.iprev="216.34.181.88"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dkim=fail (signature verification failed) header.d=karger-me.20150623.gappssmtp.com; dmarc=none (p=nil; dis=none) header.from=karger.me X-Classification-ID: b917df88-fdc6-11e7-b048-842b2b47481a-1-1 Received: from [216.34.181.88] ([216.34.181.88:18643] helo=lists.sourceforge.net) by smtp3.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.1.56364 r(Core:4.2.1.14)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 13/5B-28327-8DF036A5; Sat, 20 Jan 2018 04:46:01 -0500 Received: from localhost ([127.0.0.1] helo=sfs-ml-4.v29.ch3.sourceforge.com) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.89) (envelope-from ) id 1ecpfi-0001no-6n; Sat, 20 Jan 2018 09:42:46 +0000 Received: from sfi-mx-4.v28.ch3.sourceforge.com ([172.29.28.194] helo=mx.sourceforge.net) by sfs-ml-4.v29.ch3.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1ecpfh-0001ni-AC for openvpn-devel@lists.sourceforge.net; Sat, 20 Jan 2018 09:42:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=B3NiNWV7OoLlLGjEKOxwbXNptQzRC0v8yANR5o1kYZA=; b=CouY9yYxWpWppVq2pKtN6a3gyx +1YEd9VytlTnSBAilgL6JfS/XV05Hee8lZPnCGj1OAIFyl4S182gF+OzVOBmopgnGf16iaNBDgecd HKJ9/PJBOxIPazwQsQMlECLaF4jAvukEjFlZEMZ4/VBGSDrMQZ/mXlWCehzQC8LOVcWM=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To :MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=B3NiNWV7OoLlLGjEKOxwbXNptQzRC0v8yANR5o1kYZA=; b=A/lIs4DBCA73jFoS6MxxwYjIZA ddKHfb5XBc0MewB/fNtZ1AQA4z/AxYelTyINdBNR1oOQadUDmh/oygQ2qRM01SWtKjX1gNMUpYhSM zZ2UG4kdXleiXJlJtwgk8ELwc6NK/hfNWWmCdc9qr7IPpVzYaMeQRM6wHEA1A+25XVFI=; Received: from mail-wm0-f65.google.com ([74.125.82.65]) by sfi-mx-4.v28.ch3.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.89) id 1ecpfe-00025B-Tp for openvpn-devel@lists.sourceforge.net; Sat, 20 Jan 2018 09:42:45 +0000 Received: by mail-wm0-f65.google.com with SMTP id i186so7596579wmi.4 for ; Sat, 20 Jan 2018 01:42:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=karger-me.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=B3NiNWV7OoLlLGjEKOxwbXNptQzRC0v8yANR5o1kYZA=; b=SiFRv4qEs5gZSivJtVZjy1mGdOE2jCnRL1s/GdsazZUKKECfSHCjgMevdQWGgWftEP FPbleX5CIZ7zc7sOz6xQ4Az3cUJ1xlUm7+PuHVWIzl3FdpI4DRPuRAtpB4WuTzJz7Pl0 kY70rAacT59LY4K5Pe35AvVzJ2IgUCxOar1SrJscAeP2ZjBFyAp1BddJsc6UXZ89Lmca LTtx/JpOUIzQQvN58qpbqqUuoVbHKPzIhTnEup47b9CRSTcOc1bQRKiTaZyoXpZQqYjY rI6LKLyuAgzT9Hd3yHJrV5IAk/7op4felrBWYwSu6dBmhO5nGQgEzrgZwGDUm7a32ZFc CbpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=B3NiNWV7OoLlLGjEKOxwbXNptQzRC0v8yANR5o1kYZA=; b=IktizdtUlxLaiflAV1DAULMWqeCe0vRGabJFezhCA7sBqgTxVruWoJvHAPVg3vNvd3 LeDujt8te1ZRHxYyZufGL4uuSRcAebQe72BwaZlzY/V/JyNbeJlrBBPJwOmpGXR5v379 NfpNexWtKcIv9YC5pVVFn1fEDhz2YFkAu77V7kJvnQoXN7DLlU+nwoPB8jLREtIRFuoT bf+elY0dHu0tMZQXlyX+O3GrAG73mJw88DhVcEPV6WA6MtP2hAe54KYrmbW+myYp+R8O B6VZG84DFTZ2I1aI/+9ZjUQDgElC8yMoWKa6zLVMBb66ah6psGMznfho55fcph6/xq0w McKA== X-Gm-Message-State: AKwxytcEjW85S5ax2KxIJgHlnRdqmhZ3wvVF9THbExT/LzCVbdyH86JU 4FNBR5wOnUQiSzEcBTr9UG6+ZDcdBZw= X-Google-Smtp-Source: AH8x225SThsdK9D2IlE9fHp1c1r3c20t7WWmgkv5w6yn+jEEGfiZehM7uPNAOkfDP98BucbUXnR90A== X-Received: by 10.80.215.91 with SMTP id i27mr2756431edj.95.1516441356549; Sat, 20 Jan 2018 01:42:36 -0800 (PST) Received: from vesta.fritz.box ([2001:985:e54:1:b14e:834e:d73e:5c7]) by smtp.gmail.com with ESMTPSA id q6sm7729379edb.85.2018.01.20.01.42.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 20 Jan 2018 01:42:35 -0800 (PST) From: Steffan Karger To: openvpn-devel@lists.sourceforge.net Date: Sat, 20 Jan 2018 10:42:28 +0100 Message-Id: <20180120094228.13285-1-steffan@karger.me> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180119212721.25177-1-steffan@karger.me> References: <20180119212721.25177-1-steffan@karger.me> X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [74.125.82.65 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1ecpfe-00025B-Tp Subject: [Openvpn-devel] [PATCH (2.4)] Fix --tls-version-min and --tls-version-max for OpenSSL 1.1+ X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox As described in <80e6b449-c536-dc87-7215-3693872bce5a@birkenwald.de> on the openvpn-devel mailing list, --tls-version-min no longer works with OpenSSL 1.1. Kurt Roeckx posted in a debian bug report: "This is marked as important because if you switch to openssl 1.1.0 the defaults minimum version in Debian is currently TLS 1.2 and you can't override it with the options that you're currently using (and are deprecated)." This patch is loosely based on the original patch by Kurt, but solves the issue by adding functions to openssl-compat.h, like we also did for all other openssl 1.1. breakage. This results in not having to add more ifdefs in ssl_openssl.c and thus cleaner code. Signed-off-by: Steffan Karger Acked-by: Gert Doering --- Note: This is cherry-pick to release/2.4 of the v4 patch for master. Tested to compile and work against OpenSSL 0.9.8 (for as far as possible; 0.9.8 only does TLS 1.0). src/openvpn/openssl_compat.h | 67 ++++++++++++++++++++++++++++ src/openvpn/ssl.c | 5 ++- src/openvpn/ssl_backend.h | 4 +- src/openvpn/ssl_mbedtls.c | 3 +- src/openvpn/ssl_openssl.c | 102 +++++++++++++++++++++++++++---------------- 5 files changed, 141 insertions(+), 40 deletions(-) diff --git a/src/openvpn/openssl_compat.h b/src/openvpn/openssl_compat.h index 05ec4e95..9f1e92a1 100644 --- a/src/openvpn/openssl_compat.h +++ b/src/openvpn/openssl_compat.h @@ -661,4 +661,71 @@ EC_GROUP_order_bits(const EC_GROUP *group) #define RSA_F_RSA_OSSL_PRIVATE_ENCRYPT RSA_F_RSA_EAY_PRIVATE_ENCRYPT #endif +#ifndef SSL_CTX_get_min_proto_version +/** Dummy SSL_CTX_get_min_proto_version for OpenSSL < 1.1 (not really needed) */ +static inline int +SSL_CTX_get_min_proto_version(SSL_CTX *ctx) +{ + return 0; +} +#endif /* SSL_CTX_get_min_proto_version */ + +#ifndef SSL_CTX_set_min_proto_version +/** Mimics SSL_CTX_set_min_proto_version for OpenSSL < 1.1 */ +static inline int +SSL_CTX_set_min_proto_version(SSL_CTX *ctx, long tls_ver_min) +{ + long sslopt = SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3; /* Never do < TLS 1.0 */ + + if (tls_ver_min > TLS1_VERSION) + { + sslopt |= SSL_OP_NO_TLSv1; + } +#ifdef SSL_OP_NO_TLSv1_1 + if (tls_ver_min > TLS1_1_VERSION) + { + sslopt |= SSL_OP_NO_TLSv1_1; + } +#endif +#ifdef SSL_OP_NO_TLSv1_2 + if (tls_ver_min > TLS1_2_VERSION) + { + sslopt |= SSL_OP_NO_TLSv1_2; + } +#endif + SSL_CTX_set_options(ctx, sslopt); + + return 1; +} +#endif /* SSL_CTX_set_min_proto_version */ + +#ifndef SSL_CTX_set_max_proto_version +/** Mimics SSL_CTX_set_max_proto_version for OpenSSL < 1.1 */ +static inline int +SSL_CTX_set_max_proto_version(SSL_CTX *ctx, long tls_ver_max) +{ + long sslopt = 0; + + if (tls_ver_max < TLS1_VERSION) + { + sslopt |= SSL_OP_NO_TLSv1; + } +#ifdef SSL_OP_NO_TLSv1_1 + if (tls_ver_max < TLS1_1_VERSION) + { + sslopt |= SSL_OP_NO_TLSv1_1; + } +#endif +#ifdef SSL_OP_NO_TLSv1_2 + if (tls_ver_max < TLS1_2_VERSION) + { + sslopt |= SSL_OP_NO_TLSv1_2; + } +#endif + SSL_CTX_set_options(ctx, sslopt); + + return 1; +} +#endif /* SSL_CTX_set_max_proto_version */ + #endif /* OPENSSL_COMPAT_H_ */ diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index 08e4b121..0841cd09 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -624,7 +624,10 @@ init_ssl(const struct options *options, struct tls_root_ctx *new_ctx) * cipher restrictions before loading certificates */ tls_ctx_restrict_ciphers(new_ctx, options->cipher_list); - tls_ctx_set_options(new_ctx, options->ssl_flags); + if (!tls_ctx_set_options(new_ctx, options->ssl_flags)) + { + goto err; + } if (options->pkcs12_file) { diff --git a/src/openvpn/ssl_backend.h b/src/openvpn/ssl_backend.h index f588110c..bdef634a 100644 --- a/src/openvpn/ssl_backend.h +++ b/src/openvpn/ssl_backend.h @@ -164,8 +164,10 @@ bool tls_ctx_initialised(struct tls_root_ctx *ctx); * * @param ctx TLS context to set options on * @param ssl_flags SSL flags to set + * + * @return true on success, false otherwise. */ -void tls_ctx_set_options(struct tls_root_ctx *ctx, unsigned int ssl_flags); +bool tls_ctx_set_options(struct tls_root_ctx *ctx, unsigned int ssl_flags); /** * Restrict the list of ciphers that can be used within the TLS context. diff --git a/src/openvpn/ssl_mbedtls.c b/src/openvpn/ssl_mbedtls.c index 09829ebb..2752a4e0 100644 --- a/src/openvpn/ssl_mbedtls.c +++ b/src/openvpn/ssl_mbedtls.c @@ -206,9 +206,10 @@ key_state_export_keying_material(struct key_state_ssl *ssl, { } -void +bool tls_ctx_set_options(struct tls_root_ctx *ctx, unsigned int ssl_flags) { + return true; } static const char * diff --git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c index 8338800e..5e869f2c 100644 --- a/src/openvpn/ssl_openssl.c +++ b/src/openvpn/ssl_openssl.c @@ -206,16 +206,65 @@ info_callback(INFO_CALLBACK_SSL_CONST SSL *s, int where, int ret) int tls_version_max(void) { -#if defined(SSL_OP_NO_TLSv1_2) +#if defined(TLS1_2_VERSION) || defined(SSL_OP_NO_TLSv1_2) return TLS_VER_1_2; -#elif defined(SSL_OP_NO_TLSv1_1) +#elif defined(TLS1_1_VERSION) || defined(SSL_OP_NO_TLSv1_1) return TLS_VER_1_1; #else return TLS_VER_1_0; #endif } -void +/** Convert internal version number to openssl version number */ +static int +openssl_tls_version(int ver) +{ + if (ver == TLS_VER_1_0) + { + return TLS1_VERSION; + } + else if (ver == TLS_VER_1_1) + { + return TLS1_1_VERSION; + } + else if (ver == TLS_VER_1_2) + { + return TLS1_2_VERSION; + } + return 0; +} + +static bool +tls_ctx_set_tls_versions(struct tls_root_ctx *ctx, unsigned int ssl_flags) +{ + int tls_ver_min = openssl_tls_version( + (ssl_flags >> SSLF_TLS_VERSION_MIN_SHIFT) & SSLF_TLS_VERSION_MIN_MASK); + int tls_ver_max = openssl_tls_version( + (ssl_flags >> SSLF_TLS_VERSION_MAX_SHIFT) & SSLF_TLS_VERSION_MAX_MASK); + + if (!tls_ver_min) + { + /* Enforce at least TLS 1.0 */ + int cur_min = SSL_CTX_get_min_proto_version(ctx->ctx); + tls_ver_min = cur_min < TLS1_VERSION ? TLS1_VERSION : cur_min; + } + + if (!SSL_CTX_set_min_proto_version(ctx->ctx, tls_ver_min)) + { + msg(D_TLS_ERRORS, "%s: failed to set minimum TLS version", __func__); + return false; + } + + if (tls_ver_max && !SSL_CTX_set_max_proto_version(ctx->ctx, tls_ver_max)) + { + msg(D_TLS_ERRORS, "%s: failed to set maximum TLS version", __func__); + return false; + } + + return true; +} + +bool tls_ctx_set_options(struct tls_root_ctx *ctx, unsigned int ssl_flags) { ASSERT(NULL != ctx); @@ -223,44 +272,21 @@ tls_ctx_set_options(struct tls_root_ctx *ctx, unsigned int ssl_flags) /* default certificate verification flags */ int flags = SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT; - /* process SSL options including minimum TLS version we will accept from peer */ - { - long sslopt = SSL_OP_SINGLE_DH_USE | SSL_OP_NO_TICKET | SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3; - int tls_ver_max = TLS_VER_UNSPEC; - const int tls_ver_min = - (ssl_flags >> SSLF_TLS_VERSION_MIN_SHIFT) & SSLF_TLS_VERSION_MIN_MASK; - - tls_ver_max = - (ssl_flags >> SSLF_TLS_VERSION_MAX_SHIFT) & SSLF_TLS_VERSION_MAX_MASK; - if (tls_ver_max <= TLS_VER_UNSPEC) - { - tls_ver_max = tls_version_max(); - } - - if (tls_ver_min > TLS_VER_1_0 || tls_ver_max < TLS_VER_1_0) - { - sslopt |= SSL_OP_NO_TLSv1; - } -#ifdef SSL_OP_NO_TLSv1_1 - if (tls_ver_min > TLS_VER_1_1 || tls_ver_max < TLS_VER_1_1) - { - sslopt |= SSL_OP_NO_TLSv1_1; - } -#endif -#ifdef SSL_OP_NO_TLSv1_2 - if (tls_ver_min > TLS_VER_1_2 || tls_ver_max < TLS_VER_1_2) - { - sslopt |= SSL_OP_NO_TLSv1_2; - } -#endif + /* process SSL options */ + long sslopt = SSL_OP_SINGLE_DH_USE | SSL_OP_NO_TICKET; #ifdef SSL_OP_CIPHER_SERVER_PREFERENCE - sslopt |= SSL_OP_CIPHER_SERVER_PREFERENCE; + sslopt |= SSL_OP_CIPHER_SERVER_PREFERENCE; #endif #ifdef SSL_OP_NO_COMPRESSION - /* Disable compression - flag not available in OpenSSL 0.9.8 */ - sslopt |= SSL_OP_NO_COMPRESSION; + /* Disable compression - flag not available in OpenSSL 0.9.8 */ + sslopt |= SSL_OP_NO_COMPRESSION; #endif - SSL_CTX_set_options(ctx->ctx, sslopt); + + SSL_CTX_set_options(ctx->ctx, sslopt); + + if (!tls_ctx_set_tls_versions(ctx, ssl_flags)) + { + return false; } #ifdef SSL_MODE_RELEASE_BUFFERS @@ -283,6 +309,8 @@ tls_ctx_set_options(struct tls_root_ctx *ctx, unsigned int ssl_flags) SSL_CTX_set_verify(ctx->ctx, flags, verify_callback); SSL_CTX_set_info_callback(ctx->ctx, info_callback); + + return true; } void