Skip to content

Commit f049756

Browse files
authored
Merge commit from fork
fix(security): Timing Attack Vulnerability
2 parents 5aa0076 + e0b0cf9 commit f049756

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

checks/forbiddenapis.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
java.util.Arrays#equals(byte[],byte[]) @ Replace with java.security.MessageDigest#isEqual(byte[],byte[])

scram-common/src/main/java/com/ongres/scram/common/ScramFunctions.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
import static java.nio.charset.StandardCharsets.UTF_8;
99

10+
import java.security.MessageDigest;
1011
import java.security.SecureRandom;
11-
import java.util.Arrays;
1212

1313
import com.ongres.scram.common.util.Preconditions;
1414
import org.jetbrains.annotations.NotNull;
@@ -190,8 +190,7 @@ public static boolean verifyClientProof(
190190
byte[] clientSignature = clientSignature(scramMechanism, storedKey, authMessage);
191191
byte[] clientKey = CryptoUtil.xor(clientSignature, clientProof);
192192
byte[] computedStoredKey = hash(scramMechanism, clientKey);
193-
194-
return Arrays.equals(storedKey, computedStoredKey);
193+
return MessageDigest.isEqual(storedKey, computedStoredKey);
195194
}
196195

197196
/**
@@ -205,7 +204,8 @@ public static boolean verifyClientProof(
205204
*/
206205
public static boolean verifyServerSignature(
207206
ScramMechanism scramMechanism, byte[] serverKey, String authMessage, byte[] serverSignature) {
208-
return Arrays.equals(serverSignature(scramMechanism, serverKey, authMessage), serverSignature);
207+
byte[] computedServerSignature = serverSignature(scramMechanism, serverKey, authMessage);
208+
return MessageDigest.isEqual(serverSignature, computedServerSignature);
209209
}
210210

211211
/**

scram-parent/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,9 @@
521521
<!-- don't allow System.out or System.err: -->
522522
<bundledSignature>jdk-system-out</bundledSignature>
523523
</bundledSignatures>
524+
<signaturesFiles>
525+
<signaturesFile>${checks.location}/forbiddenapis.txt</signaturesFile>
526+
</signaturesFiles>
524527
</configuration>
525528
<executions>
526529
<execution>

0 commit comments

Comments
 (0)