mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-21 10:17:59 +01:00
Reuse registration sessions if possible when requesting pre-auth codes
This commit is contained in:
committed by
Jon Chambers
parent
95237a22a9
commit
e1ea3795bb
@@ -226,10 +226,27 @@ public class AccountController {
|
||||
throw new BadRequestException("Bad phone number");
|
||||
}
|
||||
|
||||
final String pushChallenge = generatePushChallenge();
|
||||
final byte[] sessionId = createRegistrationSession(phoneNumber);
|
||||
final StoredVerificationCode storedVerificationCode =
|
||||
new StoredVerificationCode(null, clock.millis(), pushChallenge, sessionId);
|
||||
final StoredVerificationCode storedVerificationCode;
|
||||
{
|
||||
final Optional<StoredVerificationCode> maybeStoredVerificationCode = pendingAccounts.getCodeForNumber(number);
|
||||
|
||||
if (maybeStoredVerificationCode.isPresent()) {
|
||||
final StoredVerificationCode existingStoredVerificationCode = maybeStoredVerificationCode.get();
|
||||
|
||||
if (StringUtils.isBlank(existingStoredVerificationCode.pushCode())) {
|
||||
storedVerificationCode = new StoredVerificationCode(
|
||||
existingStoredVerificationCode.code(),
|
||||
existingStoredVerificationCode.timestamp(),
|
||||
generatePushChallenge(),
|
||||
existingStoredVerificationCode.sessionId());
|
||||
} else {
|
||||
storedVerificationCode = existingStoredVerificationCode;
|
||||
}
|
||||
} else {
|
||||
final byte[] sessionId = createRegistrationSession(phoneNumber);
|
||||
storedVerificationCode = new StoredVerificationCode(null, clock.millis(), generatePushChallenge(), sessionId);
|
||||
}
|
||||
}
|
||||
|
||||
pendingAccounts.store(number, storedVerificationCode);
|
||||
pushNotificationManager.sendRegistrationChallengeNotification(pushToken, tokenType, storedVerificationCode.pushCode());
|
||||
|
||||
Reference in New Issue
Block a user