Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Bug] Vulnerable to Timing Attack Against PIN Validation #58

Open
terryschmidt opened this issue Feb 24, 2021 · 0 comments
Open

Comments

@terryschmidt
Copy link

Describe the bug
A cursory review of the PFLockScreen-Android revealed that the PIN check was vulnerable to timing attack due to not being time constant.

To Reproduce
Steps to reproduce the behavior:
See checkPin() function here:

public void checkPin(Context context, String encodedPin, String pin, PFPinCodeHelperCallback<Boolean> callback) {

The clear-text PIN will be checked against the decrypted PIN using String.equals(), which is vulnerable to timing attack. The equals function stops comparing the strings as soon as one-character mismatches.

Expected behavior
Remediation: First, PFLockScreen-Android should use hashing instead of encrypting the PIN of the user. For instance, the library could be using bcrypt or argon2id to create a strong hash of the PIN combined with a random unique salt. A timing attack will not reveal any information when comparing two hashes.
Additionally, the checkPin function could implement a time-constant comparison check using a XOR sum. Below is the implementation from OpenJDK:
// OpenJDK: https://github.com/openjdk-mirror/jdk7u-jdk/blob/master/s⌋ 􏰀→ rc/share/classes/java/security/MessageDigest.java#L430
public static boolean isEqual(byte[] digesta, byte[] digestb) { if (digesta.length != digestb.length) {
return false;
int result = 0;
// time-constant comparison
for (int i = 0; i < digesta.length; i++) {
result |= digesta[i] ^ digestb[i];
}
return result == 0; }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant