public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH common v2 0/2] ticket: sign RSA tickets with SHA-256, opt-in
@ 2026-11-13  3:06 Mark Atwood
  2026-11-13  3:06 ` [PATCH common v2 1/2] ticket: accept RSA tickets signed with SHA-256 Mark Atwood
  2026-11-13  3:06 ` [PATCH common v2 2/2] ticket: allow signing RSA tickets " Mark Atwood
  0 siblings, 2 replies; 5+ messages in thread
From: Mark Atwood @ 2026-11-13  3:06 UTC (permalink / raw)
  To: pve-devel

Let PVE::Ticket verify RSA tickets signed with SHA-256, and optionally sign
with it, so that PVE and PMG work with crypto providers that refuse SHA-1
signatures, e.g. FIPS ones. Signing with SHA-256 stays opt-in: callers pass a
new, optional hash parameter, and the default is still SHA-1.

This also affects Proxmox Mail Gateway, which uses PVE::Ticket for its
tickets. The pve-common patches state it in their commit messages. SHA-256
signing stays off there unless PMG passes the new parameter.

Apply order across the repositories, all three are part of this series:
1. pve-common (2 patches)
2. pve-cluster (adds the datacenter.cfg option)
3. pve-access-control (reads the option and signs with it)
pve-common and pve-cluster are independent of each other. pve-access-control
needs both, but is harmless without them: it then keeps signing with SHA-1.

Mixed clusters: nodes without pve-common 1/2 reject SHA-256 tickets, so the
option must only be set to 'sha256' once every node has that patch. The option
description says so. I did not add an automatic check against the node
versions (the new helpers in pve-cluster, 679cf2c, would allow one), as it
needs the release number that will contain 1/2. Happy to add one in
pve-manager's datacenter options update once that number is known.

Tested on a PVE 9.2 node with wolfProvider (FIPS) set up for pvedaemon: with the
option unset, logins fail as before, and with 'sha256', API and web logins work
and the tickets verify with SHA-256 only.

Changes since v1:
- rebased onto current master, which has the new ticket tests (0163eaf,
  0f928d5, 0b3129a); the v1 patches did not apply any more
- tests are now part of the existing test/ticket_test.pl instead of a new
  test file
- 1/2: added the TODO to remove the SHA-1 fallback once SHA-256 signed tickets
  are the default across PMG and PVE for at least one major release
- 1/2: $rsa_pub is now reset unconditionally to the library default (SHA-1)
  after verifying, instead of keeping whichever hash matched; the commit
  message explains why this was preferred over documenting it
- 1/2: the eval no longer swallows all errors; it only ignores the refusal of
  SHA-1 (wolfProvider's "RSA.xs:1007: OpenSSL error: (null)", seen when
  signing) and warns about anything else
- 1/2: added a test that verification succeeds without $noerr; the tests use
  tickets signed with the openssl command line as the reference
- 1/2, 2/2: the commit messages mention PMG
- 2/2: SHA-256 signing is opt-in through an optional parameter of
  assemble_rsa_ticket() with unchanged default, instead of switching to
  SHA-256 and using the PVE_TICKET_SIGN_SHA1 environment variable; the option
  itself is in the pve-cluster and pve-access-control patches

v1: <CALkZksWBSdQa5AsvhmANGAJigcZ7FHPtgRgdu3JsRt9NX6vwSg@mail.gmail.com>
This is sent as a new thread, as is usual for a new version of a series.

Thanks to Shannon Sterz for the review of v1.

Mark Atwood (2):
  ticket: accept RSA tickets signed with SHA-256
  ticket: allow signing RSA tickets with SHA-256

 src/PVE/Ticket.pm   |  49 +++++++++++++++++-
 test/ticket_test.pl | 123 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 170 insertions(+), 2 deletions(-)


base-commit: 7193a0019937de6da53a3078e67f524fabcbf91a



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH common v2 1/2] ticket: accept RSA tickets signed with SHA-256
  2026-11-13  3:06 [PATCH common v2 0/2] ticket: sign RSA tickets with SHA-256, opt-in Mark Atwood
@ 2026-11-13  3:06 ` Mark Atwood
  2026-11-17 16:05   ` Shannon Sterz
  2026-11-13  3:06 ` [PATCH common v2 2/2] ticket: allow signing RSA tickets " Mark Atwood
  1 sibling, 1 reply; 5+ messages in thread
From: Mark Atwood @ 2026-11-13  3:06 UTC (permalink / raw)
  To: pve-devel

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 <mark@wolfssl.com>
---
 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();



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH common v2 2/2] ticket: allow signing RSA tickets with SHA-256
  2026-11-13  3:06 [PATCH common v2 0/2] ticket: sign RSA tickets with SHA-256, opt-in Mark Atwood
  2026-11-13  3:06 ` [PATCH common v2 1/2] ticket: accept RSA tickets signed with SHA-256 Mark Atwood
@ 2026-11-13  3:06 ` Mark Atwood
  2026-11-17 16:05   ` Shannon Sterz
  1 sibling, 1 reply; 5+ messages in thread
From: Mark Atwood @ 2026-11-13  3:06 UTC (permalink / raw)
  To: pve-devel

Add an optional hash parameter to assemble_rsa_ticket(), either 'sha1'
or 'sha256'. It defaults to 'sha1', so existing callers get the same
tickets as before. Callers that need SHA-256 signatures, like for
running with providers that refuse SHA-1, can opt in. This also
affects Proxmox Mail Gateway, which uses PVE::Ticket too, but only for
callers that pass the parameter.

Nodes that do not accept SHA-256 tickets yet, i.e. without the previous
patch, reject them, so callers should only pass 'sha256' once all
nodes that verify the tickets accept them.

The digest is set on the private key object explicitly on every call,
as it is state of the object that earlier calls would otherwise leak
into later ones.

The tests check the digest that was used by verifying the signatures
with a public key that only accepts a single one.

Signed-off-by: Mark Atwood <mark@wolfssl.com>
---
 src/PVE/Ticket.pm   | 14 +++++++++++++-
 test/ticket_test.pl | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/src/PVE/Ticket.pm b/src/PVE/Ticket.pm
index f20ab5d..a4a593b 100644
--- a/src/PVE/Ticket.pm
+++ b/src/PVE/Ticket.pm
@@ -50,8 +50,14 @@ sub verify_csrf_prevention_token {
 }
 
 # Note: data may not contain white spaces (verify fails in that case)
+#
+# $hash selects the digest of the RSA signature, either 'sha1' (default) or 'sha256'. The digest is
+# set explicitly on every call, as it is state of the $rsa_priv object.
 sub assemble_rsa_ticket {
-    my ($rsa_priv, $prefix, $data, $secret_data) = @_;
+    my ($rsa_priv, $prefix, $data, $secret_data, $hash) = @_;
+
+    $hash //= 'sha1';
+    die "unsupported ticket signature hash '$hash'\n" if $hash ne 'sha1' && $hash ne 'sha256';
 
     my $timestamp = sprintf("%08X", time());
 
@@ -66,6 +72,12 @@ sub assemble_rsa_ticket {
 
     my $full = defined($secret_data) ? "$plain:$secret_data" : $plain;
 
+    if ($hash eq 'sha256') {
+        $rsa_priv->use_sha256_hash();
+    } else {
+        $rsa_priv->use_sha1_hash();
+    }
+
     my $ticket = $plain . "::" . encode_base64($rsa_priv->sign($full), '');
 
     return $ticket;
diff --git a/test/ticket_test.pl b/test/ticket_test.pl
index ee4212a..eb495b8 100755
--- a/test/ticket_test.pl
+++ b/test/ticket_test.pl
@@ -92,6 +92,42 @@ for my $hash ('sha1', 'sha256') {
 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");
 
+# which digest was used when signing, checked by verifying with the digest forced
+my sub signed_with($ticket, $hash) {
+    my $pub = Crypt::OpenSSL::RSA->new_public_key($rsa_pub->get_public_key_string());
+    $hash eq 'sha256' ? $pub->use_sha256_hash() : $pub->use_sha1_hash();
+    my ($plain, $sig) = $ticket =~ m/^(\S+)::(\S+)$/;
+    return $pub->verify($plain, decode_base64($sig)) ? 1 : 0;
+}
+
+my $sha1_ticket = PVE::Ticket::assemble_rsa_ticket($rsa_priv, 'PVE', 'root@pam');
+my $default_ticket = PVE::Ticket::assemble_rsa_ticket($rsa_priv, 'PVE', 'root@pam', undef, undef);
+my $sha256_ticket = PVE::Ticket::assemble_rsa_ticket($rsa_priv, 'PVE', 'root@pam', undef, 'sha256');
+# the digest set on the key by the previous call must not leak into the next one
+my $sha1_again = PVE::Ticket::assemble_rsa_ticket($rsa_priv, 'PVE', 'root@pam', undef, 'sha1');
+
+is(signed_with($sha1_ticket, 'sha1'), 1, "default is a SHA-1 signature");
+is(signed_with($default_ticket, 'sha1'), 1, "undef hash is a SHA-1 signature");
+is(signed_with($sha256_ticket, 'sha256'), 1, "sha256 is a SHA-256 signature");
+is(signed_with($sha256_ticket, 'sha1'), 0, "sha256 is not a SHA-1 signature");
+is(signed_with($sha1_again, 'sha1'), 1, "sha1 after sha256 is a SHA-1 signature");
+
+for my $ticket ($sha1_ticket, $sha256_ticket) {
+    is(verify($ticket), 'root@pam', "accepts ticket of either digest");
+    is(
+        PVE::Ticket::verify_rsa_ticket($rsa_pub, 'PVE', $ticket, undef, -20, 7200),
+        'root@pam',
+        "accepts ticket without noerr",
+    );
+}
+
+my $secret_ticket = PVE::Ticket::assemble_rsa_ticket($rsa_priv, 'PVE', undef, 'secret', 'sha256');
+is(verify($secret_ticket, 'secret'), 1, "sha256 ticket with secret data");
+is(verify($secret_ticket, 'other'), undef, "sha256 ticket with wrong secret data");
+
+eval { PVE::Ticket::assemble_rsa_ticket($rsa_priv, 'PVE', 'root@pam', undef, 'md5') };
+like($@, qr/unsupported ticket signature hash 'md5'/, "unknown hash is refused");
+
 my sub verify_refusing($hash, $error) {
     my $pub = RefusingSha1->new(Crypt::OpenSSL::RSA->new_public_key($fixed_pub_pem), $error);
     my @warnings;



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH common v2 1/2] ticket: accept RSA tickets signed with SHA-256
  2026-11-13  3:06 ` [PATCH common v2 1/2] ticket: accept RSA tickets signed with SHA-256 Mark Atwood
@ 2026-11-17 16:05   ` Shannon Sterz
  0 siblings, 0 replies; 5+ messages in thread
From: Shannon Sterz @ 2026-11-17 16:05 UTC (permalink / raw)
  To: Mark Atwood, pve-devel

On Fri Nov 13, 2026 at 4:06 AM CET, Mark Atwood wrote:
> 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 <mark@wolfssl.com>
> ---
>  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 /;

not sure whether this is ideal. the check seems fairly brittle to me.
maybe it be better to warn about all errors?

alternatively maybe wolfProvider could put a message on OpenSSL's error
stack that we could check here, though that would still require
wolfProvider (and potentially other providers) to never change that
message, so im not sure if that's ideal either.

also if i understand the commit message here correctly, verify will
never output this error for wolfProvider as wolfProvider only errors out
when signing?

-->8 snip 8<--




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH common v2 2/2] ticket: allow signing RSA tickets with SHA-256
  2026-11-13  3:06 ` [PATCH common v2 2/2] ticket: allow signing RSA tickets " Mark Atwood
@ 2026-11-17 16:05   ` Shannon Sterz
  0 siblings, 0 replies; 5+ messages in thread
From: Shannon Sterz @ 2026-11-17 16:05 UTC (permalink / raw)
  To: Mark Atwood, pve-devel

On Fri Nov 13, 2026 at 4:06 AM CET, Mark Atwood wrote:
> Add an optional hash parameter to assemble_rsa_ticket(), either 'sha1'
> or 'sha256'. It defaults to 'sha1', so existing callers get the same
> tickets as before. Callers that need SHA-256 signatures, like for
> running with providers that refuse SHA-1, can opt in. This also
> affects Proxmox Mail Gateway, which uses PVE::Ticket too, but only for
> callers that pass the parameter.
>
> Nodes that do not accept SHA-256 tickets yet, i.e. without the previous
> patch, reject them, so callers should only pass 'sha256' once all
> nodes that verify the tickets accept them.
>
> The digest is set on the private key object explicitly on every call,
> as it is state of the object that earlier calls would otherwise leak
> into later ones.
>
> The tests check the digest that was used by verifying the signatures
> with a public key that only accepts a single one.
>
> Signed-off-by: Mark Atwood <mark@wolfssl.com>
> ---
>  src/PVE/Ticket.pm   | 14 +++++++++++++-
>  test/ticket_test.pl | 36 ++++++++++++++++++++++++++++++++++++
>  2 files changed, 49 insertions(+), 1 deletion(-)
>
> diff --git a/src/PVE/Ticket.pm b/src/PVE/Ticket.pm
> index f20ab5d..a4a593b 100644
> --- a/src/PVE/Ticket.pm
> +++ b/src/PVE/Ticket.pm
> @@ -50,8 +50,14 @@ sub verify_csrf_prevention_token {
>  }
>
>  # Note: data may not contain white spaces (verify fails in that case)
> +#
> +# $hash selects the digest of the RSA signature, either 'sha1' (default) or 'sha256'. The digest is
> +# set explicitly on every call, as it is state of the $rsa_priv object.
>  sub assemble_rsa_ticket {
> -    my ($rsa_priv, $prefix, $data, $secret_data) = @_;
> +    my ($rsa_priv, $prefix, $data, $secret_data, $hash) = @_;
> +
> +    $hash //= 'sha1';
> +    die "unsupported ticket signature hash '$hash'\n" if $hash ne 'sha1' && $hash ne 'sha256';
>
>      my $timestamp = sprintf("%08X", time());
>
> @@ -66,6 +72,12 @@ sub assemble_rsa_ticket {
>
>      my $full = defined($secret_data) ? "$plain:$secret_data" : $plain;
>
> +    if ($hash eq 'sha256') {
> +        $rsa_priv->use_sha256_hash();
> +    } else {
> +        $rsa_priv->use_sha1_hash();
> +    }
> +
>      my $ticket = $plain . "::" . encode_base64($rsa_priv->sign($full), '');
>
>      return $ticket;
> diff --git a/test/ticket_test.pl b/test/ticket_test.pl
> index ee4212a..eb495b8 100755
> --- a/test/ticket_test.pl
> +++ b/test/ticket_test.pl
> @@ -92,6 +92,42 @@ for my $hash ('sha1', 'sha256') {
>  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");
>
> +# which digest was used when signing, checked by verifying with the digest forced
> +my sub signed_with($ticket, $hash) {
> +    my $pub = Crypt::OpenSSL::RSA->new_public_key($rsa_pub->get_public_key_string());
> +    $hash eq 'sha256' ? $pub->use_sha256_hash() : $pub->use_sha1_hash();
> +    my ($plain, $sig) = $ticket =~ m/^(\S+)::(\S+)$/;
> +    return $pub->verify($plain, decode_base64($sig)) ? 1 : 0;
> +}
> +
> +my $sha1_ticket = PVE::Ticket::assemble_rsa_ticket($rsa_priv, 'PVE', 'root@pam');
> +my $default_ticket = PVE::Ticket::assemble_rsa_ticket($rsa_priv, 'PVE', 'root@pam', undef, undef);

nit: maybe the first should be `$default_ticket` and the second
`$undef_ticket` so that the variable name reflects the parameters passed
to `assemble_rsa_ticket()`. it would also allow to call `$sha1_again`
`$sha1_ticket`.

-->8 snip 8<--




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-17 16:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13  3:06 [PATCH common v2 0/2] ticket: sign RSA tickets with SHA-256, opt-in Mark Atwood
2026-11-13  3:06 ` [PATCH common v2 1/2] ticket: accept RSA tickets signed with SHA-256 Mark Atwood
2026-11-17 16:05   ` Shannon Sterz
2026-11-13  3:06 ` [PATCH common v2 2/2] ticket: allow signing RSA tickets " Mark Atwood
2026-11-17 16:05   ` Shannon Sterz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal