use constant-time comparison for HMAC in cupsJWTHasValidSignature - #1680
Closed
aizu-m wants to merge 1 commit into
Closed
use constant-time comparison for HMAC in cupsJWTHasValidSignature#1680aizu-m wants to merge 1 commit into
aizu-m wants to merge 1 commit into
Conversation
Member
|
Please sign your commits... WRT the changes, while I understand the concern here, given the number of variables in such an attack, the (small) size of the signatures being compared, and the introspection that is typically used for OAuth access tokens, it is highly unlikely that this is more than a theoretical issue. That said, your changes are small and take advantage of existing APIs in GNU TLS and OpenSSL so I have no problem incorporating them here and in libcups. |
Member
|
CUPS 2.5: [master 9d7134d5c] Use constant-time memcmp for HMACs (Issue #1680) libcups 3.0: [master 2b2786a67] Use constant-time memcmp for HMACs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Was reading through the JOSE signature paths in jwt.c. The HMAC branch stood out:
signaturehere is the HMAC recomputed from the shared secret;jwt->signatureis the value off the wire. memcmp returns at the first differing byte, so the compare time tracks how many leading bytes of the supplied tag are correct. That is a byte-at-a-time timing oracle: an attacker can recover a valid HMAC one byte at a time without ever knowing the key.cupsJWTHasValidSignature is a public API and gets called on OIDC id_tokens from oauth.c, so both the token and its signature are attacker-controlled. The RS/ES branches verify through RSA_verify / ECDSA_do_verify (public key, no secret) so they are fine as they stand. Only the symmetric branch compares a secret-derived value, so only it needs a constant-time compare.
Swapped memcmp for CRYPTO_memcmp on OpenSSL and gnutls_memcmp on GnuTLS. Result is identical for valid and invalid tokens; testjwt passes on both backends.