]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: jwt: use CRYPTO_memcmp() to compare HMACs
authorWilly Tarreau <w@1wt.eu>
Fri, 15 Oct 2021 09:52:41 +0000 (11:52 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 15 Oct 2021 09:54:04 +0000 (11:54 +0200)
As Tim reported in github issue #1414, we ought to use a constant-time
memcmp() when comparing hashes to avoid time-based attacks. Let's use
CRYPTO_memcmp() since this code already depends on openssl.

No backport is needed, this was just merged into 2.5.

src/jwt.c

index 0e233059f616631c7dba1533eeaa7217f691101d..24459b0665955cfeee8df3920ddc0a9d9e1d6102 100644 (file)
--- a/src/jwt.c
+++ b/src/jwt.c
@@ -205,7 +205,7 @@ jwt_jwsverify_hmac(const struct jwt_ctx *ctx, const struct buffer *decoded_signa
                        ctx->jose.length + ctx->claims.length + 1, signature, &signature_length);
 
        if (hmac_res && signature_length == decoded_signature->data &&
-                 (memcmp(decoded_signature->area, signature, signature_length) == 0))
+                 (CRYPTO_memcmp(decoded_signature->area, signature, signature_length) == 0))
                retval = JWT_VRFY_OK;
 
        free_trash_chunk(trash);