forked from signalapp/Signal-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add storage capability and return KBS creds on rereg w/ storage set
- Loading branch information
1 parent
bb7433a
commit 3c8e7c6
Showing
9 changed files
with
175 additions
and
86 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
service/src/main/java/org/whispersystems/textsecuregcm/auth/StoredRegistrationLock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.whispersystems.textsecuregcm.auth; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import org.whispersystems.textsecuregcm.util.Util; | ||
|
||
import javax.annotation.Nullable; | ||
import java.security.MessageDigest; | ||
import java.util.Optional; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@SuppressWarnings("OptionalUsedAsFieldOrParameterType") | ||
public class StoredRegistrationLock { | ||
|
||
private final Optional<String> registrationLock; | ||
|
||
private final Optional<String> registrationLockSalt; | ||
|
||
private final Optional<String> deprecatedPin; | ||
|
||
private final long lastSeen; | ||
|
||
public StoredRegistrationLock(Optional<String> registrationLock, Optional<String> registrationLockSalt, Optional<String> deprecatedPin, long lastSeen) { | ||
this.registrationLock = registrationLock; | ||
this.registrationLockSalt = registrationLockSalt; | ||
this.deprecatedPin = deprecatedPin; | ||
this.lastSeen = lastSeen; | ||
} | ||
|
||
public boolean requiresClientRegistrationLock() { | ||
return ((registrationLock.isPresent() && registrationLockSalt.isPresent()) || deprecatedPin.isPresent()) && System.currentTimeMillis() - lastSeen < TimeUnit.DAYS.toMillis(7); | ||
} | ||
|
||
public boolean needsFailureCredentials() { | ||
return registrationLock.isPresent() && registrationLockSalt.isPresent(); | ||
} | ||
|
||
public long getTimeRemaining() { | ||
return TimeUnit.DAYS.toMillis(7) - (System.currentTimeMillis() - lastSeen); | ||
} | ||
|
||
public boolean verify(@Nullable String clientRegistrationLock, @Nullable String clientDeprecatedPin) { | ||
if (Util.isEmpty(clientRegistrationLock) && Util.isEmpty(clientDeprecatedPin)) { | ||
return false; | ||
} | ||
|
||
if (registrationLock.isPresent() && registrationLockSalt.isPresent() && !Util.isEmpty(clientRegistrationLock)) { | ||
return new AuthenticationCredentials(registrationLock.get(), registrationLockSalt.get()).verify(clientRegistrationLock); | ||
} else if (deprecatedPin.isPresent() && !Util.isEmpty(clientDeprecatedPin)) { | ||
return MessageDigest.isEqual(deprecatedPin.get().getBytes(), clientDeprecatedPin.getBytes()); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
@VisibleForTesting | ||
public StoredRegistrationLock forTime(long timestamp) { | ||
return new StoredRegistrationLock(registrationLock, registrationLockSalt, deprecatedPin, timestamp); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.