Java

Java : Timing attack

Classification

Overview

The method of string comparison is used that does not protect against timing attacks.

Common methods of string comparison terminate the operation after handling the first non-equal pair of characters. Thus, the operating time of the method depends on the length of the matching prefixes. An attacker can use this information to compromise valuable data. When working with the valuable data, such as encryption keys, secure methods of comparison must be used.

In Java for secure string comparison use MessageDigest.isEqual() (the implementation is protected from timing attacks starting with Java 6 Update 17) or implement your own method. Typical idea of secure comparison: compute XOR for each pair of elements of the two arrays and return true if the resulting vector consists of zeros. This comparison takes the same amount of time regardless of the values of the arguments.

In Play Framework, use the constantTimeEquals method.

CRITICAL

DerScanner Severity Score

Check your Java code for this vulnerability, free

Request a free pilot of DerScanner. We give you access and help with the first scan. It works in the cloud and on-premise.

Try it on your code, free

By submitting this form, I acknowledge that DerScanner may process my personal data I provided above for purposes explained above. More details about the processing.