From patchwork Thu Jun 29 21:56:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 3263 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7301:3c07:b0:d9:b492:11d6 with SMTP id ki7csp2113010dyb; Thu, 29 Jun 2023 14:57:16 -0700 (PDT) X-Google-Smtp-Source: APBJJlGHn73HxGbg7A+zrJjBV9AnFKpdw7acY9T/p2mRfRWHKM1MRltc3nmJS50Pp0dNrTlf7Rt4 X-Received: by 2002:a17:90a:e60f:b0:262:e742:f40a with SMTP id j15-20020a17090ae60f00b00262e742f40amr524013pjy.44.1688075835810; Thu, 29 Jun 2023 14:57:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688075835; cv=none; d=google.com; s=arc-20160816; b=UKcN6W/wDHWe4kVBmAH/r0yjLpsrq7D8h4zxJcGZLOK6X67S1EKYXO0lJXltIhreD+ iNvN+0i+Z6Hmsy0Ew7eQRaVvWqAzUzC0jyBbtHO7/6SSlxSRkVqo6g163vVJPi3Tzjwb UJdWm/EFSabYUILhL/qwOUpotCZjte3HFsC2lq8bUS6hQtr+WTDTkczzBf8SapYscY/I pCYiBYgvsLmlixW52LSIS/sHqbe9bSeL+/QKM/sh941WS965eQcf0LiQ5+dp7Mq1/gse w2vsdChmZmA4PWPB+CLWFGuNbOeNMQRKxNADQRJcWarSu+8KMPTC9GzuQ6254DrOr00g 5qbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature; bh=Nbvf85Z+1wE3DqWeQK5+/jqz7/vtC1oUPg62YL/1L7w=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=K5ZmNFl8QGvacQp7UhPpCQeFNNUYAnyoM+hBfZ74NJ66j2AdZA0dI9z3+jNhRsfdhJ AvO+yF01GrKzH5xTy6MwNRoSvCNCcFwNSl6iIPoimsCwNOU9ydWVH3ikUYgCYUYdken+ 2u7Jixt+dvRa3hsXHGeZRJlTruQkxnkfvtsfGGrYQLmg+ZLPnW3ozQrRMUTGeYpE1SSA 2R4t3tZOg8flMhS/O08wzsGMuKzKydRkQp6sp2Cjgsy8/exwYrTQtWIJo+KN1BpR0bKX RRAk2VwpFXWfIx0DAuDPr2Yywd76vw4k8qYHPGxH6IsYV55Afi8w5KTKEQNgXOtSM+QQ Wreg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=bp4e33bm; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=BzCdgQF0; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id v1-20020a17090a898100b0025c238650d1si11475645pjn.174.2023.06.29.14.57.15 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Jun 2023 14:57:15 -0700 (PDT) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=bp4e33bm; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=BzCdgQF0; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1qEzcl-0005nV-83; Thu, 29 Jun 2023 21:56:23 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1qEzcj-0005nL-8p for openvpn-devel@lists.sourceforge.net; Thu, 29 Jun 2023 21:56:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: 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=eaJ9yG4hWjzU+HBpcoLbiBRjotvF1M25/QtsDETnpyI=; b=bp4e33bmYh6nwRuqb9o72jSgiW xkwyONpECVkt7cjyhG/6yNVgYhB2G5aEMs8akDOrJjy0LeAWOyiHRUtB3Zoy4Evy3tu1qVfVuxROR 3rbUouISTxFqCxB22gAf2qWZDx1tVAvhGr1TyOdLT1gpxKgd6Kuiul2JpJ0MEnpMjVr8=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: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=eaJ9yG4hWjzU+HBpcoLbiBRjotvF1M25/QtsDETnpyI=; b=BzCdgQF0FiiWyz0Iw8TB1yF4ZA lMpUNmkK7UVzZHFyun1WILeit7Lq1MrSUjlb1afCjAMaq1vbRfk2dtUMDT3tJRsDV4hIIgyf07zuv Q6kZNymiUUBf8mZdtfD5yPArDhFCx9zxNbCTc3wU00VlJY47uvokrMVQubiaH6GjYiPU=; Received: from mail.blinkt.de ([192.26.174.232]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1qEzcg-001Ohp-Ti for openvpn-devel@lists.sourceforge.net; Thu, 29 Jun 2023 21:56:20 +0000 Received: from kamera.blinkt.de ([2001:638:502:390:20c:29ff:fec8:535c]) by mail.blinkt.de with smtp (Exim 4.95 (FreeBSD)) (envelope-from ) id 1qEzcZ-0004WX-GW for openvpn-devel@lists.sourceforge.net; Thu, 29 Jun 2023 23:56:11 +0200 Received: (nullmailer pid 3292842 invoked by uid 10006); Thu, 29 Jun 2023 21:56:11 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Thu, 29 Jun 2023 23:56:09 +0200 Message-Id: <20230629215611.3292788-4-arne@rfc2549.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230629215611.3292788-1-arne@rfc2549.org> References: <20230629215611.3292788-1-arne@rfc2549.org> MIME-Version: 1.0 X-Spam-Score: 0.2 (/) X-Spam-Report: Spam detection software, running on the system "util-spamd-2.v13.lw.sourceforge.com", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: This is implements --peer-fingerprint command to support OpenVPN authentication without involving a PKI. The current implementation in OpenVPN for peer fingerprint has been already extensively rewritten from the original submission from Jason [1]. The commit preserved the original author since it was bas [...] Content analysis details: (0.2 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 T_SCC_BODY_TEXT_LINE No description available. X-Headers-End: 1qEzcg-001Ohp-Ti Subject: [Openvpn-devel] [PATCH 2/2] Implement using --peer-fingerprint without CA certificates 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: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1770075807300981147?= X-GMAIL-MSGID: =?utf-8?q?1770075807300981147?= This is implements --peer-fingerprint command to support OpenVPN authentication without involving a PKI. The current implementation in OpenVPN for peer fingerprint has been already extensively rewritten from the original submission from Jason [1]. The commit preserved the original author since it was based on Jason code/idea. The current code uses two commits to prepare the --peer-fingerprint solution as which choose to use a simple to use --peer-fingerprint directive instead of using using a --tls-verify script like the v1 of the patch proposed. The two commit preparing this are: - Extend verify-hash to allow multiple hashes - Implement peer-fingerprint to check fingerprint of peer certificate This perparing patches make this actual patch quite short. There are some lines in this patch that bear some similarity to the ones like if (!preverify_ok && !session->opt->verify_hash_no_ca) vs if (!preverify_ok && !session->opt->ca_file_none) But these similarities are one line fragments and dictated by the surrounding style and program flow, so even a complete black box implementation will likely end up with the same lines. [1] https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg16781.html Change-Id: Ie74c3d606c5429455c293c367462244566a936e3 Signed-off-by: Arne Schwabe --- src/openvpn/init.c | 1 + src/openvpn/options.c | 26 +++++++++++++------------- src/openvpn/options.h | 1 + src/openvpn/ssl_common.h | 1 + src/openvpn/ssl_verify_mbedtls.c | 16 ++++++++++++++++ src/openvpn/ssl_verify_openssl.c | 2 +- 6 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/openvpn/init.c b/src/openvpn/init.c index c023b33c6..d358ad003 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -3347,6 +3347,7 @@ do_init_crypto_tls(struct context *c, const unsigned int flags) to.verify_hash = options->verify_hash; to.verify_hash_algo = options->verify_hash_algo; to.verify_hash_depth = options->verify_hash_depth; + to.verify_hash_no_ca = options->verify_hash_no_ca; #ifdef ENABLE_X509ALTUSERNAME memcpy(to.x509_username_field, options->x509_username_field, sizeof(to.x509_username_field)); #else diff --git a/src/openvpn/options.c b/src/openvpn/options.c index fe9285384..e4c596b89 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -2991,21 +2991,11 @@ options_postprocess_verify_ce(const struct options *options, else { #ifdef ENABLE_CRYPTO_MBEDTLS - if (!(options->ca_file)) - { - msg(M_USAGE, "You must define CA file (--ca)"); - } - if (options->ca_path) { msg(M_USAGE, "Parameter --capath cannot be used with the mbed TLS version version of OpenVPN."); } -#else /* ifdef ENABLE_CRYPTO_MBEDTLS */ - if ((!(options->ca_file)) && (!(options->ca_path))) - { - msg(M_USAGE, "You must define CA file (--ca) or CA path (--capath)"); - } -#endif +#endif /* ifdef ENABLE_CRYPTO_MBEDTLS */ if (pull) { @@ -3737,6 +3727,13 @@ options_postprocess_mutate(struct options *o, struct env_set *es) options_postprocess_http_proxy_override(o); } #endif + if (!o->ca_file && !o->ca_path && o->verify_hash + && o->verify_hash_depth == 0) + { + msg(M_INFO, "Using certificate fingerprint to verify peer (no CA " + "option set). "); + o->verify_hash_no_ca = true; + } if (o->config && streq(o->config, "stdin") && o->remap_sigusr1 == SIGHUP) { @@ -4032,8 +4029,11 @@ options_postprocess_filechecks(struct options *options) errs |= check_file_access_inline(options->dh_file_inline, CHKACC_FILE, options->dh_file, R_OK, "--dh"); - errs |= check_file_access_inline(options->ca_file_inline, CHKACC_FILE, - options->ca_file, R_OK, "--ca"); + if (!options->verify_hash_no_ca) + { + errs |= check_file_access_inline(options->ca_file_inline, CHKACC_FILE, + options->ca_file, R_OK, "--ca"); + } errs |= check_file_access_chroot(options->chroot_dir, CHKACC_FILE, options->ca_path, R_OK, "--capath"); diff --git a/src/openvpn/options.h b/src/openvpn/options.h index 95f1158a4..f5890b90f 100644 --- a/src/openvpn/options.h +++ b/src/openvpn/options.h @@ -604,6 +604,7 @@ struct options struct verify_hash_list *verify_hash; hash_algo_type verify_hash_algo; int verify_hash_depth; + bool verify_hash_no_ca; unsigned int ssl_flags; /* set to SSLF_x flags from ssl.h */ #ifdef ENABLE_PKCS11 diff --git a/src/openvpn/ssl_common.h b/src/openvpn/ssl_common.h index c0b3caa71..27b029479 100644 --- a/src/openvpn/ssl_common.h +++ b/src/openvpn/ssl_common.h @@ -345,6 +345,7 @@ struct tls_options const char *remote_cert_eku; struct verify_hash_list *verify_hash; int verify_hash_depth; + bool verify_hash_no_ca; hash_algo_type verify_hash_algo; #ifdef ENABLE_X509ALTUSERNAME char *x509_username_field[MAX_PARMS]; diff --git a/src/openvpn/ssl_verify_mbedtls.c b/src/openvpn/ssl_verify_mbedtls.c index c9ef7a171..e3437f740 100644 --- a/src/openvpn/ssl_verify_mbedtls.c +++ b/src/openvpn/ssl_verify_mbedtls.c @@ -62,6 +62,22 @@ verify_callback(void *session_obj, mbedtls_x509_crt *cert, int cert_depth, struct buffer cert_fingerprint = x509_get_sha256_fingerprint(cert, &gc); cert_hash_remember(session, cert_depth, &cert_fingerprint); + if (session->opt->verify_hash_no_ca) + { + /* + * If we decide to verify the peer certificate based on the fingerprint + * we ignore wrong dates and the certificate not being trusted. + * Any other problem with the certificate (wrong key, bad cert,...) + * will still trigger an error. + * Clearing these flags relies on verify_cert will later rejecting a + * certificate that has no matching fingerprint. + */ + uint32_t flags_ignore = MBEDTLS_X509_BADCERT_NOT_TRUSTED + | MBEDTLS_X509_BADCERT_EXPIRED + | MBEDTLS_X509_BADCERT_FUTURE; + *flags = *flags & ~flags_ignore; + } + /* did peer present cert which was signed by our root cert? */ if (*flags != 0) { diff --git a/src/openvpn/ssl_verify_openssl.c b/src/openvpn/ssl_verify_openssl.c index ac36f09db..e24ce4e4a 100644 --- a/src/openvpn/ssl_verify_openssl.c +++ b/src/openvpn/ssl_verify_openssl.c @@ -67,7 +67,7 @@ verify_callback(int preverify_ok, X509_STORE_CTX *ctx) cert_hash_remember(session, X509_STORE_CTX_get_error_depth(ctx), &cert_hash); /* did peer present cert which was signed by our root cert? */ - if (!preverify_ok) + if (!preverify_ok && !session->opt->verify_hash_no_ca) { /* get the X509 name */ char *subject = x509_get_subject(current_cert, &gc);