Skip to content

Commit 3e35a90

Browse files
committed
Fix cupsJWTSign for EC with GNU TLS.
1 parent 9843444 commit 3e35a90

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

cups/jwt.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// JSON Web Token API implementation for CUPS.
33
//
4-
// Copyright © 2023-2024 by OpenPrinting.
4+
// Copyright © 2023-2025 by OpenPrinting.
55
//
66
// Licensed under Apache License v2.0. See the file "LICENSE" for more
77
// information.
@@ -1426,6 +1426,8 @@ cupsJWTSign(cups_jwt_t *jwt, // I - JWT object
14261426
cups_json_t *sigx5c = NULL; // X.509 certificate chain, if any
14271427

14281428

1429+
DEBUG_printf("cupsJWTSign(jwt=%p, alg=%d, jwk=%p)", (void *)jwt, alg, (void *)jwk);
1430+
14291431
// Range check input...
14301432
if (!jwt || alg <= CUPS_JWA_NONE || alg >= CUPS_JWA_MAX || !jwk)
14311433
{
@@ -1466,10 +1468,15 @@ cupsJWTSign(cups_jwt_t *jwt, // I - JWT object
14661468

14671469
free(jwt->jose_string);
14681470
jwt->jose_string = cupsJSONExportString(jwt->jose);
1469-
make_signature(jwt, alg, jwk, signature, &sigsize, &sigkid, NULL);
1471+
1472+
if (!make_signature(jwt, alg, jwk, signature, &sigsize, &sigkid, NULL))
1473+
{
1474+
DEBUG_puts("2cupsJWTSign: Unable to create X5C signature.");
1475+
return (false);
1476+
}
14701477
}
14711478

1472-
DEBUG_printf("1cupsJWTSign: jose_string=\"%s\"", jwt->jose_string);
1479+
DEBUG_printf("1cupsJWTSign: jose_string=\"%s\", sigkid=\"%s\", sigsize=%u", jwt->jose_string, sigkid, (unsigned)sigsize);
14731480

14741481
// Save the key ID and signature values...
14751482
if (sigkid)
@@ -2146,7 +2153,7 @@ make_signature(cups_jwt_t *jwt, // I - JWT
21462153
sig_datum.data = NULL;
21472154
sig_datum.size = 0;
21482155

2149-
if (!gnutls_privkey_sign_data(key, algs[alg - CUPS_JWA_RS256], 0, &text_datum, &sig_datum) && sig_datum.size <= *sigsize)
2156+
if (!gnutls_privkey_sign_data(key, algs[alg - CUPS_JWA_ES256], 0, &text_datum, &sig_datum))
21502157
{
21512158
gnutls_datum_t r, s; // Signature coordinates
21522159
unsigned sig_len;
@@ -2170,7 +2177,7 @@ make_signature(cups_jwt_t *jwt, // I - JWT
21702177
}
21712178
else
21722179
{
2173-
DEBUG_printf("4make_signature: EC signing failed, sig_datum=%d bytes.", (int)sig_datum.size);
2180+
DEBUG_printf("4make_signature: EC signing failed, sig_datum=%d bytes, sigsize=%d.", (int)sig_datum.size, (int)*sigsize);
21742181
}
21752182
gnutls_free(sig_datum.data);
21762183
gnutls_privkey_deinit(key);

0 commit comments

Comments
 (0)