public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Mark Atwood <mark@wolfssl.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH common v2 2/2] ticket: allow signing RSA tickets with SHA-256
Date: Fri, 13 Nov 2026 03:06:39 +0000	[thread overview]
Message-ID: <20261113030639.3514-3-mark@wolfssl.com> (raw)
In-Reply-To: <20261113030639.3514-1-mark@wolfssl.com>

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;



  parent reply	other threads:[~2026-11-13  3:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Mark Atwood [this message]
2026-11-17 16:05   ` [PATCH common v2 2/2] ticket: allow signing RSA tickets " Shannon Sterz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261113030639.3514-3-mark@wolfssl.com \
    --to=mark@wolfssl.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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