From patchwork Sun Oct 7 10:58:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 502 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director11.mail.ord1d.rsapps.net ([172.28.255.1]) by backend30.mail.ord1d.rsapps.net with LMTP id UEWWKc2BulvuKgAAIUCqbw for ; Sun, 07 Oct 2018 17:59:41 -0400 Received: from proxy1.mail.ord1c.rsapps.net ([172.28.255.1]) by director11.mail.ord1d.rsapps.net with LMTP id 8JJiKc2Bulu2RgAAvGGmqA ; Sun, 07 Oct 2018 17:59:41 -0400 Received: from smtp24.gate.ord1c ([172.28.255.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy1.mail.ord1c.rsapps.net with LMTP id gAY3Kc2BulvuWwAA2VeTtA ; Sun, 07 Oct 2018 17:59:41 -0400 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.105.38.7] Authentication-Results: smtp24.gate.ord1c.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; 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; dmarc=none (p=nil; dis=none) header.from=rfc2549.org X-Suspicious-Flag: YES X-Classification-ID: 4a3ca318-ca7c-11e8-8255-b8ca3a674470-1-1 Received: from [216.105.38.7] ([216.105.38.7:12676] helo=lists.sourceforge.net) by smtp24.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 83/23-45501-DC18ABB5; Sun, 07 Oct 2018 17:59:41 -0400 Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1g9H4b-0005nK-Dd; Sun, 07 Oct 2018 21:58:49 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1g9H4a-0005nE-Dc for openvpn-devel@lists.sourceforge.NET; Sun, 07 Oct 2018 21:58:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc: MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=JX6ssO+znlhhfC8sTkmx9YP3TB7niWewivbpxpb5sD4=; b=GNZ0h10s+W/0zkNfx1Zzpqcf/c rycxQz1NbMJMTI8bREVQuCQzxzF3rgdsdKx80v2LrsgMeV6perrjyMMzoIDTXA+e0k2tIEmGBiKNm c3k7HK6F/HPCYKHDnTJJCTzUbej7TlyGyQ8bzuklHmuUz0DFs1pckZ8cynuNWqZS4WwM=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc:MIME-Version: Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=JX6ssO+znlhhfC8sTkmx9YP3TB7niWewivbpxpb5sD4=; b=MPxrAHFa3lpdB9U8zEhsuTAzHv 9G5VEyMg+PrjGB8HLdv7sAGuAaGEf/ENZW1P3/JvTFTQM6yF3xJapIhE8ur+YBW4LJbFGO5zsi+V7 YhxHEfLU6IM1d/bxRWQw4bRd4cVswSEeQ6t8XCymFPxZPGnJ4KNb1B0VEgjE6CXJXuGI=; Received: from mail.blinkt.de ([192.26.174.232]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) id 1g9H4Y-002jPZ-L8 for openvpn-devel@lists.sourceforge.NET; Sun, 07 Oct 2018 21:58:48 +0000 Received: from kamera.blinkt.de ([2001:638:502:390:20c:29ff:fec8:535c]) by mail.blinkt.de with smtp (Exim 4.91 (FreeBSD)) (envelope-from ) id 1g9H4P-00080g-KW for openvpn-devel@lists.sourceforge.net; Sun, 07 Oct 2018 23:58:37 +0200 Received: (nullmailer pid 538 invoked by uid 10006); Sun, 07 Oct 2018 21:58:37 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Sun, 7 Oct 2018 23:58:37 +0200 Message-Id: <20181007215837.489-1-arne@rfc2549.org> X-Mailer: git-send-email 2.17.1 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different 0.1 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1g9H4Y-002jPZ-L8 Subject: [Openvpn-devel] [PATCH] Add support for OpenSSL TLS 1.3 when using management-external-key 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 For TLS 1.0 to 1.2 OpenSSL calls us and requires a PKCS1 padded response, for TLS 1.3 it requires to an unpadded response. Since we can PCKS1 pad an unpadded response, we prefer to always query for an unpadded response from the management interface and add the PCKS1 padding ourselves when needed. This patch adds an 'unpadded' parameter to the management-external-key option to signal that it is uses the new unpadded API. Since we cannot support TLS 1.3 without unpadded queries we disable TLS 1.3 otherwise. We also do the same for cryptoapi since it uses the same API. Using the management api client version instead might seem like the more logical way but since we only now that version very late, it would extra logic and complexity to deal with this asynchronous behaviour . --- doc/management-notes.txt | 7 ++++- src/openvpn/manage.h | 9 ++++--- src/openvpn/options.c | 54 ++++++++++++++++++++++++++++++++++++++- src/openvpn/ssl_openssl.c | 26 ++++++++++++++----- 4 files changed, 83 insertions(+), 13 deletions(-) diff --git a/doc/management-notes.txt b/doc/management-notes.txt index 17645c1d..7e61ff50 100644 --- a/doc/management-notes.txt +++ b/doc/management-notes.txt @@ -832,7 +832,12 @@ END Base 64 encoded output of RSA_private_encrypt for RSA or ECDSA_sign() for EC using OpenSSL or mbedtls_pk_sign() using mbed TLS will provide a -correct signature. +correct signature. With the 'nopadding' argument to the +external-management-interface the interface expects unpadded signatures +(RSA_NO_PADDING in OpenSSL). When the 'nopadding' keyword is missing the +interfaces expects PKCS1 padded signatures for RSA keys (RSA_PKCS1_PADDING). +EC signatures are always unpadded. To support TLS 1.3 using unpadded +signatures is required. This capability is intended to allow the use of arbitrary cryptographic service providers with OpenVPN via the management interface. diff --git a/src/openvpn/manage.h b/src/openvpn/manage.h index ff143fc1..03d46456 100644 --- a/src/openvpn/manage.h +++ b/src/openvpn/manage.h @@ -348,11 +348,12 @@ struct management *management_init(void); #define MF_UNIX_SOCK (1<<8) #ifdef MANAGMENT_EXTERNAL_KEY #define MF_EXTERNAL_KEY (1<<9) +#define MF_EXTERNAL_KEY_NOPADDING (1<<10) #endif -#define MF_UP_DOWN (1<<10) -#define MF_QUERY_REMOTE (1<<11) -#define MF_QUERY_PROXY (1<<12) -#define MF_EXTERNAL_CERT (1<<13) +#define MF_UP_DOWN (1<<11) +#define MF_QUERY_REMOTE (1<<12) +#define MF_QUERY_PROXY (1<<13) +#define MF_EXTERNAL_CERT (1<<14) bool management_open(struct management *man, const char *addr, diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 891468bd..52ec6582 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -3024,6 +3024,34 @@ options_postprocess_verify(const struct options *o) options_postprocess_verify_ce(o, &o->ce); } } +#if defined(ENABLE_CRYPTOAPI) || (defined(ENABLE_CRYPTO_OPENSSL) && defined(MANAGMENT_EXTERNAL_KEY)) +static void +disable_tls13_if_avilable(struct options *o, const char* msg) +{ +#if OPENSSL_VERSION_NUMBER >= 0x10100000L + const int tls_version_max = + (o->ssl_flags >> SSLF_TLS_VERSION_MAX_SHIFT) & + SSLF_TLS_VERSION_MAX_MASK; + + /* + * The library we are *linked* against is OpenSSL 1.1.1 and therefore support TLS 1.3 + * this need to be a runtime version check since we can be compiled against 1.1.0 and + * then the library can be upgraded to 1.1.1 + */ + if (OpenSSL_version_num() > 0x1010100fL && + (tls_version_max == TLS_VER_UNSPEC || tls_version_max > TLS_VER_1_2)) + { + msg(M_WARN, "%s Setting maximum TLS version to 1.2 ", msg); + o->ssl_flags &= ~(SSLF_TLS_VERSION_MAX_MASK << + SSLF_TLS_VERSION_MAX_SHIFT); + o->ssl_flags |= (TLS_VER_1_1 << SSLF_TLS_VERSION_MAX_SHIFT); + + } +#else + return; +#endif +} +#endif static void options_postprocess_mutate(struct options *o) @@ -3105,6 +3133,26 @@ options_postprocess_mutate(struct options *o) } #endif +#if defined(ENABLE_CRYPTO_MBEDTLS) && defined(MANAGMENT_EXTERNAL_KEY) + if (o->management_flags & MF_EXTERNAL_KEY_NOPADDING) + { + msg(M_FATAL, "mbed TLS does not support the 'nopadding' argument for the --management-external-key option"); + } +#endif + +#if defined(ENABLE_CRYPTOAPI) + if (o->cryptoapi_cert) + { + disable_tls13_if_avilable(o, "Warning: cryptapicert used."); + } +#endif +#if defined(ENABLE_CRYPTO_OPENSSL) + if ((o->management_flags & MF_EXTERNAL_KEY) && !(o->management_flags & MF_EXTERNAL_KEY_NOPADDING)) + { + disable_tls13_if_avilable(o, "Warning: Using management-external-key " + "without nopadding option."); + } +#endif #if P2MP /* * Save certain parms before modifying options via --pull @@ -5178,9 +5226,13 @@ add_option(struct options *options, options->management_write_peer_info_file = p[1]; } #ifdef MANAGMENT_EXTERNAL_KEY - else if (streq(p[0], "management-external-key") && !p[1]) + else if (streq(p[0], "management-external-key") && !p[2]) { VERIFY_PERMISSION(OPT_P_GENERAL); + if (p[1] && streq(p[1], "nopadding")) + { + options->management_flags |= MF_EXTERNAL_KEY_NOPADDING; + } options->management_flags |= MF_EXTERNAL_KEY; } else if (streq(p[0], "management-external-cert") && p[1] && !p[2]) diff --git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c index 813ef616..81c5fd4c 100644 --- a/src/openvpn/ssl_openssl.c +++ b/src/openvpn/ssl_openssl.c @@ -1099,15 +1099,27 @@ openvpn_extkey_rsa_finish(RSA *rsa) */ static int get_sig_from_man(const unsigned char *dgst, unsigned int dgstlen, - unsigned char *sig, unsigned int siglen) + unsigned char *sig, unsigned int siglen, bool pkcs1pad) { char *in_b64 = NULL; char *out_b64 = NULL; int len = -1; + int bencret = -1; - /* convert 'dgst' to base64 */ - if (management - && openvpn_base64_encode(dgst, dgstlen, &in_b64) > 0) + if ((management->settings.flags & MF_EXTERNAL_KEY_NOPADDING) > 2 && pkcs1pad) + { + /* + * Add PKCS1 signature and replace input with it + * Use our output buffer also als temporary buffer + */ + RSA_padding_add_PKCS1_type_1(sig, siglen, dgst, dgstlen); + bencret = openvpn_base64_encode(sig, siglen, &in_b64); + } + else + { + bencret = openvpn_base64_encode(dgst, dgstlen, &in_b64); + } + if (management && bencret > 0) { out_b64 = management_query_pk_sig(management, in_b64); } @@ -1128,13 +1140,13 @@ rsa_priv_enc(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, i unsigned int len = RSA_size(rsa); int ret = -1; - if (padding != RSA_PKCS1_PADDING) + if (padding != RSA_PKCS1_PADDING && padding != RSA_NO_PADDING) { RSAerr(RSA_F_RSA_OSSL_PRIVATE_ENCRYPT, RSA_R_UNKNOWN_PADDING_TYPE); return -1; } - ret = get_sig_from_man(from, flen, to, len); + ret = get_sig_from_man(from, flen, to, len, padding == RSA_PKCS1_PADDING); return (ret == len)? ret : -1; } @@ -1228,7 +1240,7 @@ ecdsa_sign(int type, const unsigned char *dgst, int dgstlen, unsigned char *sig, unsigned int *siglen, const BIGNUM *kinv, const BIGNUM *r, EC_KEY *ec) { int capacity = ECDSA_size(ec); - int len = get_sig_from_man(dgst, dgstlen, sig, capacity); + int len = get_sig_from_man(dgst, dgstlen, sig, capacity, false); if (len > 0) {