Skip to content

Commit 975a14e

Browse files
committed
Add at_hash validation.
1 parent 5ed7fc2 commit 975a14e

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

cups/oauth.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,7 @@ cupsOAuthGetTokens(
10571057
// Validate the JWT
10581058
cups_json_t *jwks; // JWT key set
10591059
bool valid; // Valid id_token?
1060+
const char *at_hash; // at_hash claim value
10601061

10611062
jwt = cupsJWTImportString(id_value, CUPS_JWS_FORMAT_COMPACT);
10621063
jnonce = cupsJWTGetClaimString(jwt, "nonce");
@@ -1076,7 +1077,22 @@ cupsOAuthGetTokens(
10761077
if (!valid)
10771078
goto done;
10781079

1079-
// TODO: Validate at_hash claim string against access_token value
1080+
// Validate the at_hash claim string against access_token value
1081+
if (access_value && (at_hash = cupsJWTGetClaimString(jwt, "at_hash")) != NULL)
1082+
{
1083+
unsigned char sha256[32], // Hash of the access_token value
1084+
at_hash_buffer[32]; // at_hash bytes
1085+
size_t at_hash_bytes = sizeof(at_hash_buffer);
1086+
// Number of at_hash bytes
1087+
1088+
cupsHashData("sha2-256", access_value, strlen(access_value), sha256, sizeof(sha256));
1089+
httpDecode64((char *)at_hash_buffer, &at_hash_bytes, at_hash, /*end*/NULL);
1090+
if (at_hash_bytes != 16 || memcmp(sha256, at_hash_buffer, 16))
1091+
{
1092+
DEBUG_puts("1cupsOAuthGetTokens: at_hash doesn't match SHA-256 of access_token.");
1093+
goto done;
1094+
}
1095+
}
10801096
}
10811097

10821098
if (expires_in > 0.0)

0 commit comments

Comments
 (0)