From 4a53fc339e323b4a415996db5c57940f2530c5f3 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 28 Oct 2019 18:28:11 -0700 Subject: [PATCH] Don't use "phutil_hashes_are_identical()" to compare public keys Summary: Ref T13436. There's no real security value to doing this comparison, it just wards off evil "security researchers" who get upset if you ever compare two strings with a non-constant-time algorithm. In practice, SSH public keys are pretty long, pretty public, and have pretty similar lengths. This leads to a relatively large amount of work to do constant-time comparisons on them (we frequently can't abort early after identifying differing string length). Test Plan: Ran `bin/ssh-auth --sshd-key ...` on `secure` with ~1K keys, saw runtime drop by ~50% (~400ms to ~200ms) with `===`. Maniphest Tasks: T13436 Differential Revision: https://secure.phabricator.com/D20875 --- scripts/ssh/ssh-auth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ssh/ssh-auth.php b/scripts/ssh/ssh-auth.php index 2a27329d4a..19b1cc46b4 100755 --- a/scripts/ssh/ssh-auth.php +++ b/scripts/ssh/ssh-auth.php @@ -109,7 +109,7 @@ if ($authstruct === null) { if ($sshd_key !== null) { $matches = array(); foreach ($authstruct['keys'] as $key => $key_struct) { - if (phutil_hashes_are_identical($key_struct['key'], $sshd_key)) { + if ($key_struct['key'] === $sshd_key) { $matches[$key] = $key_struct; } }