Skip to content

Commit

Permalink
Add at_hash validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Sep 5, 2024
1 parent 5ed7fc2 commit 975a14e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion cups/oauth.c
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,7 @@ cupsOAuthGetTokens(
// Validate the JWT
cups_json_t *jwks; // JWT key set
bool valid; // Valid id_token?
const char *at_hash; // at_hash claim value

jwt = cupsJWTImportString(id_value, CUPS_JWS_FORMAT_COMPACT);
jnonce = cupsJWTGetClaimString(jwt, "nonce");
Expand All @@ -1076,7 +1077,22 @@ cupsOAuthGetTokens(
if (!valid)
goto done;

// TODO: Validate at_hash claim string against access_token value
// Validate the at_hash claim string against access_token value
if (access_value && (at_hash = cupsJWTGetClaimString(jwt, "at_hash")) != NULL)
{
unsigned char sha256[32], // Hash of the access_token value
at_hash_buffer[32]; // at_hash bytes
size_t at_hash_bytes = sizeof(at_hash_buffer);
// Number of at_hash bytes

cupsHashData("sha2-256", access_value, strlen(access_value), sha256, sizeof(sha256));
httpDecode64((char *)at_hash_buffer, &at_hash_bytes, at_hash, /*end*/NULL);
if (at_hash_bytes != 16 || memcmp(sha256, at_hash_buffer, 16))
{
DEBUG_puts("1cupsOAuthGetTokens: at_hash doesn't match SHA-256 of access_token.");
goto done;
}
}
}

if (expires_in > 0.0)
Expand Down

0 comments on commit 975a14e

Please sign in to comment.