From patchwork Mon Nov 2 13:49:10 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 5549 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:3119:b0:118:2077:975e with SMTP id e25csp5431506laa; Mon, 2 Nov 2026 05:49:29 -0800 (PST) X-Forwarded-Encrypted: i=2; AKwUvBz4Olc1TBH6LCoKbq420POa79Zjz9fBWt4Fz+NguZU0codqjPwQTBo3Wk8sYKN0vEXYPryC/cTVHYY=@openvpn.net X-Received: by 2002:a05:701b:428b:20b0:1a3:dfb6:e593 with SMTP id a92af1059eb24-1ac5eea3690mr15734808c88.27.1793627368633; Mon, 02 Nov 2026 05:49:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1793627368; cv=none; d=google.com; s=arc-20260327; b=Pa3pU06BiFIvEiEDvs0gIhNMPc54hzwYD3iRvfBX5xV9SRyDksSEY8XXtGT8yImLLU HoFDHuazjfoOhbshqFUMNZ36cf/d6vpo3pENbDx8CaySMR4cOPX2nU6wwk7J3e9WNE1U 40u8PK/kdlDNqwhwl/9jKOvxE5qc5PxB8QQXNYElai5b/aD1OFu/6O8w/e3KGRJFTDaI H2gAq4hFHtl6OLrNrIuZCvaaLrauQMOq04k/C0UmbgppIrxRXPp0WxTtn4cLmijC+AVs 5kvUjLKpxeUjVb9wtFlXadL/3ItfPTri3KTNXBqZtKy8xFL3LPqoGUcQ8i7wJN5jry4m v51g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; 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:dkim-signature; bh=vDxRQKRaONegmFgQvoAPTnaWIC0AD44jmi56SaJjYj8=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=c3vaQV/AVehfWXCNy3l/VoqG0kFTugW0uLsbDY2JlM7LkeW/ovws3hj4oXZZPHuhPV TfqeI/Mnz5TyNlq8uYffpXzQwcpvRCVvFF387wTT7+jvacIf4KJd/nVOOnk83JTBT7wf rurl3gQUbMidfMC+sKBDi7kalybz9+gruFtLAfKYVQbpls5rabw7TQNWcu5/C5MhFmbS +j99AHuTYvsEEDoLrup9DKe1hCHlB7SW71BswQlr9VhrCfkgqPYtZ8nk5QPFrTAzAdH8 8T6S/6bBepgXONIa5LeSGhljEtxY8hNA6IQrA8AIaRzWjuJZGlYzAF2D8itqKClbUMh4 esKw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=gZOE157J; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=nPxT5yaI; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=jJ8flYZM; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id a92af1059eb24-1ac19797af4si29875283c88.52.2026.11.02.05.49.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Nov 2026 05:49:28 -0800 (PST) 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=pass header.i=@lists.sourceforge.net header.s=beta header.b=gZOE157J; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=nPxT5yaI; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=jJ8flYZM; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=vDxRQKRaONegmFgQvoAPTnaWIC0AD44jmi56SaJjYj8=; b=gZOE157JIKisWt dUOq2zXK65ab2YU4+xPXvoYLNdvmQLAnMFBwcd2JzOOAxJE/nFRh1Jzrw+BubjgjglXEseKGvmnip uUyMEx2652S9hAztcfmaUt4QXk3YLNsZixgVK7rjTlKmF5rJZdAOlIKED1iFfyQnFyFZZCDB0Ljei T2k=; Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.100.1) (envelope-from ) id 1xNsPf-000000006sB-1zQV; Mon, 02 Nov 2026 13:49:27 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xNsPd-000000006s2-3M4c for openvpn-devel@lists.sourceforge.net; Mon, 02 Nov 2026 13:49:25 +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-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=cs93Z8+HH8jVaIOEsk9OCsdJtkW6Ow440PUl2Kb14fc=; b=nPxT5yaINtOua7C3wZ7jXOXwkK vsRno0ViHATYTlBwmIrrriccFk9+HAHO8ufat2pzvyzpv0un5KUTIv2s2D+LRA/4mExS2GTTc1kf5 8ykR8/NfcFo2negacSMUoHna89dpL1fqxCHH0yJTsU1BezBDVZVXcScvb2b1S03w6j1Q=; 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-Unsubscribe-Post: List-Subscribe:List-Post:List-Owner:List-Archive; bh=cs93Z8+HH8jVaIOEsk9OCsdJtkW6Ow440PUl2Kb14fc=; b=jJ8flYZMQNypjkanTOMnMXPB5/ bgnM8BPWZXx/zNjoTaDveJPaMjgbekKcyt65jHbcq3UT3V/Jz5HJXmjy4eUrtjRwszuB2U5YT+V0E 0h4g7BsKdnKHCThVAGarhK6p2uTI+tQu6YwDks5XqdaNNAeyX7lEBv09Lo7x3tDu30hM=; Received: from [193.149.48.129] (helo=blue.greenie.muc.de) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xNsPb-000000000S6-0Paq for openvpn-devel@lists.sourceforge.net; Mon, 02 Nov 2026 13:49:23 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.18.1/8.18.1) with ESMTP id 6A2DnGIs026617 for ; Mon, 2 Nov 2026 14:49:16 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.2/8.18.1/Submit) id 6A2DnGax026616 for openvpn-devel@lists.sourceforge.net; Mon, 2 Nov 2026 14:49:16 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Mon, 2 Nov 2026 14:49:10 +0100 Message-ID: <20261102134915.26599-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.55.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: 1.3 (+) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-2.hosts.colo.sdot.me", 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: From: Arne Schwabe These methods only check for zero keys after weak DES checks were removed. Simplify all this to always the first 32 bytes of key and hmac and ensure that they are not zero. Content analysis details: (1.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-Headers-End: 1xNsPb-000000000S6-0Paq Subject: [Openvpn-devel] [PATCH v3] Clean up weak key check 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: 1880754611977173781 X-GMAIL-MSGID: 1880754611977173781 From: Arne Schwabe These methods only check for zero keys after weak DES checks were removed. Simplify all this to always the first 32 bytes of key and hmac and ensure that they are not zero. This now always raises a FATAL alert instead of handling this error gracefully but a all zeros keys should never ever happen. Change-Id: Ic5cf5ef723a33ad304b080ef19db2e4a0f4bb2eb Signed-off-by: Arne Schwabe Acked-by: Steffan Karger Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2080 --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2080 This mail reflects revision 3 of this Change. Acked-by according to Gerrit (reflected above): Steffan Karger diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c index 3d3ab0c..ff17b22 100644 --- a/src/openvpn/crypto.c +++ b/src/openvpn/crypto.c @@ -1104,40 +1104,6 @@ ctx->initialized = false; } -static bool -key_is_zero(const struct key *key, const struct key_type *kt) -{ - size_t cipher_length = cipher_kt_key_size(kt->cipher); - for (size_t i = 0; i < cipher_length; ++i) - { - if (key->cipher[i]) - { - return false; - } - } - msg(D_CRYPT_ERRORS, "CRYPTO INFO: WARNING: zero key detected"); - return true; -} - -/* - * Make sure that cipher key is a valid key for current key_type. - */ -bool -check_key(const struct key *key, const struct key_type *kt) -{ - if (cipher_defined(kt->cipher)) - { - /* - * Check for zero key - */ - if (key_is_zero(key, kt)) - { - return false; - } - } - return true; -} - /* * Generate a random key. */ @@ -1307,8 +1273,8 @@ print_key_filename(key_file, key_inline)); } - /* check for and fix highly unlikely key problems */ - verify_fix_key2(&key2, key_type, key_file); + /* check for highly unlikely key problems */ + check_key2(&key2); /* handle key direction */ key_direction_state_init(&kds, key_direction); @@ -1708,18 +1674,19 @@ } void -verify_fix_key2(struct key2 *key2, const struct key_type *kt, const char *shared_secret_file) +check_key2(struct key2 *key2) { - int i; + /* Check the first 128 bit of every key slot to be not 0. This is + * not a comprehensive check, but no valid key should fail this check */ - for (i = 0; i < key2->n; ++i) + uint8_t zero_key[16] = { 0 }; + + if (memcmp_constant_time(key2->keys[0].cipher, zero_key, sizeof(zero_key)) == 0 + || memcmp_constant_time(key2->keys[1].cipher, zero_key, sizeof(zero_key)) == 0 + || memcmp_constant_time(key2->keys[0].hmac, zero_key, sizeof(zero_key)) == 0 + || memcmp_constant_time(key2->keys[1].hmac, zero_key, sizeof(zero_key)) == 0) { - /* This should be a very improbable failure */ - if (!check_key(&key2->keys[i], kt)) - { - msg(M_FATAL, "Key #%d in '%s' is bad. Try making a new key with --genkey.", i + 1, - shared_secret_file); - } + msg(M_FATAL, "One key in static key/generated key is all zero."); } } diff --git a/src/openvpn/crypto.h b/src/openvpn/crypto.h index e3c1c6a..dbe0802 100644 --- a/src/openvpn/crypto.h +++ b/src/openvpn/crypto.h @@ -414,8 +414,6 @@ */ int write_key_file(const int nkeys, const char *filename); -bool check_key(const struct key *key, const struct key_type *kt); - /** * Initialize a key_type structure with. * @@ -621,7 +619,7 @@ void key_direction_state_init(struct key_direction_state *kds, int key_direction); -void verify_fix_key2(struct key2 *key2, const struct key_type *kt, const char *shared_secret_file); +void check_key2(struct key2 *key2); void must_have_n_keys(const char *filename, const char *option, const struct key2 *key2, int n); diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index 086a6fc..ddee3eb 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -1583,15 +1583,7 @@ key2_print(&key2, &session->opt->key_type, "Master Encrypt", "Master Decrypt"); /* check for weak keys */ - for (int i = 0; i < 2; ++i) - { - if (!check_key(&key2.keys[i], &session->opt->key_type)) - { - msg(D_TLS_ERRORS, "TLS Error: Bad dynamic key generated"); - goto exit; - } - } - + check_key2(&key2); ret = init_key_contexts(ks, multi, &session->opt->key_type, server, &key2, session->opt->dco_enabled);