From 6af9d0e9b9206286b4961a5964d3db1d573ad18c Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Tue, 3 Mar 2026 12:51:47 +0100 Subject: [PATCH] Fix timing side-channel in check_peer_pubkey strcmp() at line 315 short-circuits on first differing byte, leaking timing info about trusted fingerprints. Replace with constant-time comparison using memcmp and bitwise OR accumulation across all trusted entries. Fixes GH #239 --- pclsync/pssl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pclsync/pssl.c b/pclsync/pssl.c index 172070e..1a7a638 100644 --- a/pclsync/pssl.c +++ b/pclsync/pssl.c @@ -311,9 +311,11 @@ static int check_peer_pubkey(ssl_connection_t *conn) { mbedtls_sha256(buff + sizeof(buff) - i, i, sigbin, 0); psync_binhex(sighex, sigbin, 32); sighex[64] = 0; + int match = 0; for (i = 0; i < ARRAY_SIZE(psync_ssl_trusted_pk_sha256); i++) - if (!strcmp(sighex, psync_ssl_trusted_pk_sha256[i])) - return 0; + match |= (memcmp(sighex, psync_ssl_trusted_pk_sha256[i], 64) == 0); + if (match) + return 0; pdbg_logf(D_ERROR, "got sha256hex of public key %s that does not match any approved " "fingerprint",