Support for push preauth

This commit is contained in:
Moxie Marlinspike
2019-06-06 17:31:07 -07:00
parent 18037bb484
commit 4fdbe9b9ff
22 changed files with 391 additions and 103 deletions

View File

@@ -2,6 +2,8 @@ package org.whispersystems.textsecuregcm.auth;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.whispersystems.textsecuregcm.util.Util;
import java.security.MessageDigest;
import java.util.concurrent.TimeUnit;
@@ -13,11 +15,15 @@ public class StoredVerificationCode {
@JsonProperty
private long timestamp;
@JsonProperty
private String pushCode;
public StoredVerificationCode() {}
public StoredVerificationCode(String code, long timestamp) {
public StoredVerificationCode(String code, long timestamp, String pushCode) {
this.code = code;
this.timestamp = timestamp;
this.pushCode = pushCode;
}
public String getCode() {
@@ -28,8 +34,16 @@ public class StoredVerificationCode {
return timestamp;
}
public String getPushCode() {
return pushCode;
}
public boolean isValid(String theirCodeString) {
if (timestamp + TimeUnit.MINUTES.toMillis(30) < System.currentTimeMillis()) {
if (timestamp + TimeUnit.MINUTES.toMillis(10) < System.currentTimeMillis()) {
return false;
}
if (Util.isEmpty(code) || Util.isEmpty(theirCodeString)) {
return false;
}
@@ -38,4 +52,5 @@ public class StoredVerificationCode {
return MessageDigest.isEqual(ourCode, theirCode);
}
}