From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 257231FF0B7 for ; Fri, 13 Nov 2026 04:34:11 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 25D6B21D2D; Fri, 13 Nov 2026 04:22:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wolfssl-com.20260707.gappssmtp.com; s=20260707; t=1794539206; x=1795144006; darn=lists.proxmox.com; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=eHQdZ9ZDQ2LbihwXRE1N+sR0QKLi41t3i7kdqLnjo7U=; b=DUZJOC0ghL8fPxEkCyjNa4n5hFaDJ9lDJshUYwwPiIpEfZRMKcW1eQPPkk9CjlBSSw 1OKRsHd0mZcep5FYxcxPxQ1KkIsjt3kYxOZqUUjNiS+8dU3qMx495vIOphmDWwQ+GQkG vR9nSlz8BCZz45/IgVoDnR5K/L9lLjuJwTPRVCNvY2J8T9CT4eULRNcF6wVBbg7LbVGg FQLkAcUt7V002pgqWsbHAjJGiiI4x/30qtEVveYWUHWkpwKDqrMGXUscdFZVCOkVBdn0 WN3Rel8bznX/pc0B11uFRmCQvYaa70T1Hq9L1Gu3OncgFHClvErCgRlFr+MGCLuX92EU WT3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794539206; x=1795144006; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=eHQdZ9ZDQ2LbihwXRE1N+sR0QKLi41t3i7kdqLnjo7U=; b=ZV1EBonS1N7KSUXWlpFfBqdkotupDLUsFP4HOI2nH2viiF+JGMfUZ6cm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I5yd1F9IBIi+jTXPPSn8qdfFAe6AgR5qn85ZhmY2h496m Xl3YqlhomwIOf3Px2OjHI49uWuG2uQKusXxzOYOF+EDFh0FqljbCYhXd9rmdT1jYJGWXSAwx3A/ PpjSUX/jfZcEFJq+JYUcdXXhDAVBKuHPg7mOnIAWuVyexkdC4cQW3BgKtv1W1yQURhiA6qbaiju 8ttVudJNA== X-Received: by 2002:a05:6820:f035:b0:6f6:96f1:1b5 with SMTP id 006d021491bc7-71ab4f8c70amr865488eaf.18.1794539205587; Thu, 12 Nov 2026 19:06:45 -0800 (PST) From: Mark Atwood To: pve-devel@lists.proxmox.com Subject: [PATCH common v2 1/2] ticket: accept RSA tickets signed with SHA-256 Date: Fri, 13 Nov 2026 03:06:38 +0000 Message-ID: <20261113030639.3514-2-mark@wolfssl.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261113030639.3514-1-mark@wolfssl.com> References: <20261113030639.3514-1-mark@wolfssl.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DMARC_PASS -0.1 DMARC pass policy RCVD_IN_DNSWL_NONE -0.0001 Sender listed at https://www.dnswl.org/, no trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: HNWGPZLTF54ZRCDQIHTG7LMR3RFO4MGZ X-Message-ID-Hash: HNWGPZLTF54ZRCDQIHTG7LMR3RFO4MGZ X-MailFrom: mark@wolfssl.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Verification only accepted tickets with an RSA signature made with SHA-1, the default digest of Crypt::OpenSSL::RSA. Providers that refuse SHA-1 signatures, such as FIPS ones, cannot create or check such tickets. As a first step towards signing with SHA-256, accept tickets signed with either SHA-256 or SHA-1, trying SHA-256 first. Accepting SHA-256 first lets nodes that verify tickets be upgraded ahead of the ones that sign with SHA-256, so it needs to be rolled out before any signing change. This also affects Proxmox Mail Gateway, which uses PVE::Ticket for its tickets too. A mismatching signature makes the library return false. A provider that refuses SHA-1 makes it die instead, for example wolfProvider when signing: "RSA.xs:1007: OpenSSL error: (null)". Treat exactly that kind of message as the signature not matching for SHA-1, and warn about all other errors, so they do not go unnoticed. wolfProvider still verifies SHA-1 signatures, so there SHA-1 tickets from nodes that are not upgraded yet keep working. Verifying switches the digest of the public key object, which is state that callers can see. Always reset it to the library default, SHA-1, after verifying, regardless of which digest matched or whether an error happened. This leaves the object as it was before and does not leave a digest behind that depends on the last ticket seen. Documenting the left-over state instead would have made every caller depend on it. The tests use tickets signed with the openssl command line, so they do not rely on the signing code. They also cover that verification works without the noerr parameter, and the handling of provider errors. Signed-off-by: Mark Atwood --- src/PVE/Ticket.pm | 35 +++++++++++++++++- test/ticket_test.pl | 87 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+), 1 deletion(-) diff --git a/src/PVE/Ticket.pm b/src/PVE/Ticket.pm index 5bd06fc..f20ab5d 100644 --- a/src/PVE/Ticket.pm +++ b/src/PVE/Ticket.pm @@ -71,6 +71,39 @@ sub assemble_rsa_ticket { return $ticket; } +# Checks the signature of a ticket, accepting SHA-256 and SHA-1 signatures. Returns true if one of +# them matches. +# +# TODO: Remove SHA-1 fallback once SHA-256 signed tickets are the default across PMG and PVE for at +# least one major release. +# +# Note: Always leaves $rsa_pub with the library default digest (SHA-1), as it was before it got +# used here, no matter which one matched. +my sub verify_rsa_signature { + my ($rsa_pub, $full, $sig) = @_; + + my $valid = 0; + for my $hash ('sha256', 'sha1') { + # A mismatch returns false. A provider that refuses to use SHA-1 makes the library die with + # a message without any OpenSSL error text, e.g. "RSA.xs:1007: OpenSSL error: (null)". + # That is the expected outcome for SHA-1 in FIPS mode and just means no match. + $valid = eval { + $hash eq 'sha256' ? $rsa_pub->use_sha256_hash() : $rsa_pub->use_sha1_hash(); + $rsa_pub->verify($full, $sig); + }; + if (my $err = $@) { + # anything else is unexpected and should not go unnoticed + warn "unexpected error verifying $hash ticket signature - $err" + if $hash ne 'sha1' || $err !~ m/^RSA\.xs:\d+: OpenSSL error: \(null\) at /; + } + last if $valid; + } + + $rsa_pub->use_sha1_hash(); + + return $valid; +} + sub verify_rsa_ticket { my ($rsa_pub, $prefix, $ticket, $secret_data, $min_age, $max_age, $noerr) = @_; @@ -80,7 +113,7 @@ sub verify_rsa_ticket { my $full = defined($secret_data) ? "$plain:$secret_data" : $plain; - if ($rsa_pub->verify($full, decode_base64($sig))) { + if (verify_rsa_signature($rsa_pub, $full, decode_base64($sig))) { if ($plain =~ m/^\Q$prefix\E:(?:(\S+):)?([A-Z0-9]{8})$/) { my $data = $1; # Note: not all tickets contains data my $timestamp = $2; diff --git a/test/ticket_test.pl b/test/ticket_test.pl index e10ab97..ee4212a 100755 --- a/test/ticket_test.pl +++ b/test/ticket_test.pl @@ -10,6 +10,19 @@ use Test::More; use PVE::Ticket; +# A verifier that, like a FIPS provider, dies when asked to verify with SHA-1, and that tracks the +# digest that was set last. +package RefusingSha1 { + sub new($class, $real, $error) { return bless { real => $real, error => $error }, $class } + sub use_sha1_hash($self) { $self->{hash} = 'sha1'; $self->{real}->use_sha1_hash() } + sub use_sha256_hash($self) { $self->{hash} = 'sha256'; $self->{real}->use_sha256_hash() } + + sub verify($self, @args) { + die $self->{error} if $self->{hash} eq 'sha1'; + return $self->{real}->verify(@args); + } +} + my $rsa_priv = Crypt::OpenSSL::RSA->generate_key(2048); my $rsa_pub = Crypt::OpenSSL::RSA->new_public_key($rsa_priv->get_public_key_string()); @@ -42,4 +55,78 @@ for my $data ('a%41b@pve', 'a%6fb@pve') { is(verify($ticket), undef, "ticket without percent escape for '$data' is rejected"); } +# Tickets signed by OpenSSL's command line for the key below ('PVE:root@pam:00000001', signed with +# 'openssl dgst -sha1|-sha256 -sign'), so the verification does not depend on our own signing. +my $fixed_pub_pem = <<'EOF_PEM'; +-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoCOvd4Gtfa8X3sqIrKa3 +EbmtxvPhV9A0Ik9m3rveZ6rW8RkZdcXAB5lA21+ix/LPz40AGqHHTCIPXv6/uddv +Os0DXXOM+vyqVfiqTQ3hpaXzzdM0Ip7bFOECuu7UON7haXvBij2Vnxs6kf1vBU7P +BkDPsOo91OS2Lr1y8yRxEEPdT0CG2MF77cwQQHGufkXr13AvYaweFFASCTKVf+aG +s09W5VasJYf8HOXfptmDxgn+DHAfwHOyBTu6f+pRQXFy82aQOIB3FPSR8877CM4w +XaC4t0uZPQqwGVojJxRGbnhXru7/JgRbnZXcoF+QyaqDXpWp+t9iMzVQAnWk3XKh +5wIDAQAB +-----END PUBLIC KEY----- +EOF_PEM + +my $fixed_sig = { + sha1 => + 'lH/tsT8EXCANTltNawgHdXMkjvsywEluoIK4rDVcDGtURSCy7XOo4IMx1tBycEafD8IDESBhlk08kO35Np2CebUHd49dTJOYg1rVm1Hl4QmT0kGmMCuPz4OttEID8UZ9UHGn+VQmmVFz2hyOoliQB80usiEo6moG3eN3ZJE8yJN9vZTJHsyg+DFgIf9YPOQFYSLnjOrIiWXsm2TQqp7MvICUewC/tQqHuLj1f4ZmKhI5rbQXOSp4/L6BGTJ5sgRP4Rdc3djyOuKlJmx48jtVVlK2RgpgnZXR2YVqACkK2R2mK3/JUgYCw2ZMRgu7hs5upx5gXigHPLZCF+FroGDMEg==', + sha256 => + 'mejkKQiURn2A9A49QwyfBqSW/oSgEq1YMD8YKXbmYp6kLY/VYwntVKogMrNZcEj9sWwkGiSXnx77defwbNfsHpWpBCalIJtH5m267Pkuk2j4p2bKG656wcBrU+Dscev+uuPDIwWke9QhrpyoFHODE7oJuWxrn3D1Cnlj+tZ2ps66a+XGyNVCznrCZFJuTcPuRvarkLYgBOOsjBOg2tsSw7Bee8xF+bDFF0TkyLRhizRPY10qKJnEyaLlEtvTZ51AcGCQPaMhLk9xJlflN8sqa3V8TUQdDBTox5HQMHR+n+H74xFR9UkXhI2sUmrk+ar0Az72Yy2Dzxe+IQZMCatLJg==', +}; + +# the ticket is from 1970, so use a huge maximum age +my sub verify_fixed($hash, $pub, $noerr = 1) { + my $ticket = "PVE:root\@pam:00000001::$fixed_sig->{$hash}"; + return PVE::Ticket::verify_rsa_ticket($pub, 'PVE', $ticket, undef, -20, 1e12, $noerr); +} + +my $fixed_pub = Crypt::OpenSSL::RSA->new_public_key($fixed_pub_pem); +for my $hash ('sha1', 'sha256') { + is(verify_fixed($hash, $fixed_pub), 'root@pam', "$hash signed ticket from openssl is accepted"); + # without $noerr, a valid ticket must not die either + is(verify_fixed($hash, $fixed_pub, 0), 'root@pam', + "$hash signed ticket accepted without noerr"); +} +is(eval { verify_fixed('sha256', $rsa_pub, 0) }, undef, "ticket of other key is rejected"); +like($@, qr/invalid PVE ticket/, "ticket of other key raises without noerr"); + +my sub verify_refusing($hash, $error) { + my $pub = RefusingSha1->new(Crypt::OpenSSL::RSA->new_public_key($fixed_pub_pem), $error); + my @warnings; + local $SIG{__WARN__} = sub { push @warnings, @_ }; + my $res = verify_fixed($hash, $pub); + return ($res, \@warnings, $pub->{hash}); +} + +my ($res, $warnings, $last_hash) = + verify_refusing('sha256', "RSA.xs:1: OpenSSL error: (null) at x.pl line 1.\n"); +is($res, 'root@pam', "sha256 ticket is accepted if SHA-1 is refused"); +is_deeply($warnings, [], "no warning if SHA-256 matched"); + +($res, $warnings, $last_hash) = + verify_refusing('sha1', "RSA.xs:1: OpenSSL error: (null) at x.pl line 1.\n"); +is($res, undef, "sha1 ticket is rejected if SHA-1 is refused"); +is_deeply($warnings, [], "no warning for the expected SHA-1 refusal"); +is($last_hash, 'sha1', "verifier is left with the default digest after a refusal"); + +($res, $warnings, $last_hash) = verify_refusing('sha1', "out of memory\n"); +is($res, undef, "sha1 ticket is rejected on unexpected error"); +is(scalar(@$warnings), 1, "unexpected error is warned about"); +like($warnings->[0] // '', qr/out of memory/, "warning has the error"); + +($res, $warnings, $last_hash) = verify_refusing( + 'sha1', + "RSA.xs:1: OpenSSL error: error:02000064:rsa routines::bad signature at x.pl line 1.\n", +); +is(scalar(@$warnings), 1, "other OpenSSL errors are warned about too"); + +# the digest left on the verifier must not depend on which one matched +for my $hash ('sha1', 'sha256') { + ($res, $warnings, $last_hash) = + verify_refusing($hash, "RSA.xs:1: OpenSSL error: (null) at x.pl line 1.\n"); + is($last_hash, 'sha1', "verifier is left with the default digest for $hash ticket"); +} + done_testing();