Skip to content

Commit

Permalink
Remove KBS restore after set check.
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-signal authored and greyson-signal committed Feb 14, 2020
1 parent 23e55ac commit 7f867a6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,29 +209,23 @@ protected void onPreExecute() {
@Override
protected Boolean doInBackground(Void... voids) {
try {
Log.i(TAG, "Setting pin on KBS");
Log.i(TAG, "Setting pin on KBS - dialog");

KbsValues kbsValues = SignalStore.kbsValues();
MasterKey masterKey = kbsValues.getOrCreateMasterKey();
KeyBackupService keyBackupService = ApplicationDependencies.getKeyBackupService();
KeyBackupService.PinChangeSession pinChangeSession = keyBackupService.newPinChangeSession();
HashedPin hashedPin = PinHashing.hashPin(pinValue, pinChangeSession);
RegistrationLockData kbsData = pinChangeSession.setPin(hashedPin, masterKey);
RegistrationLockData restoredData = keyBackupService.newRestoreSession(kbsData.getTokenResponse())
.restorePin(hashedPin);

if (!restoredData.getMasterKey().equals(masterKey)) {
throw new AssertionError("Failed to set the pin correctly");
} else {
Log.i(TAG, "Set and retrieved pin on KBS successfully");
}

kbsValues.setRegistrationLockMasterKey(restoredData, PinHashing.localPinHash(pinValue));
kbsValues.setRegistrationLockMasterKey(kbsData, PinHashing.localPinHash(pinValue));
TextSecurePreferences.clearOldRegistrationLockPin(context);
TextSecurePreferences.setRegistrationLockLastReminderTime(context, System.currentTimeMillis());
TextSecurePreferences.setRegistrationLockNextReminderInterval(context, RegistrationLockReminders.INITIAL_INTERVAL);

Log.i(TAG, "Pin set on KBS");
return true;
} catch (IOException | UnauthenticatedResponseException | KeyBackupServicePinException | KeyBackupSystemNoDataException e) {
} catch (IOException | UnauthenticatedResponseException e) {
Log.w(TAG, e);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,17 @@ void setPin(@NonNull KbsPin kbsPin, @NonNull PinKeyboardType keyboard, @NonNull
KeyBackupService.PinChangeSession pinChangeSession = keyBackupService.newPinChangeSession();
HashedPin hashedPin = PinHashing.hashPin(pinValue, pinChangeSession);
RegistrationLockData kbsData = pinChangeSession.setPin(hashedPin, masterKey);
RegistrationLockData restoredData = keyBackupService.newRestoreSession(kbsData.getTokenResponse())
.restorePin(hashedPin);

if (!restoredData.getMasterKey().equals(masterKey)) {
throw new AssertionError("Failed to set the pin correctly");
} else {
Log.i(TAG, "Set and retrieved pin on KBS successfully");
}

kbsValues.setRegistrationLockMasterKey(restoredData, PinHashing.localPinHash(pinValue));
kbsValues.setRegistrationLockMasterKey(kbsData, PinHashing.localPinHash(pinValue));
TextSecurePreferences.clearOldRegistrationLockPin(context);
TextSecurePreferences.setRegistrationLockLastReminderTime(context, System.currentTimeMillis());
TextSecurePreferences.setRegistrationLockNextReminderInterval(context, RegistrationLockReminders.INITIAL_INTERVAL);
SignalStore.kbsValues().setKeyboardType(keyboard);
ApplicationDependencies.getMegaphoneRepository().markFinished(Megaphones.Event.PINS_FOR_ALL);

Log.i(TAG, "Pin set on KBS");
return PinSetResult.SUCCESS;
} catch (IOException | UnauthenticatedResponseException | KeyBackupServicePinException | KeyBackupSystemNoDataException e) {
} catch (IOException | UnauthenticatedResponseException e) {
Log.w(TAG, e);
return PinSetResult.FAILURE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,8 @@ protected void onRun() throws IOException, UnauthenticatedResponseException, Key
KeyBackupService.PinChangeSession pinChangeSession = keyBackupService.newPinChangeSession();
HashedPin hashedPin = PinHashing.hashPin(pinValue, pinChangeSession);
RegistrationLockData kbsData = pinChangeSession.setPin(hashedPin, masterKey);
RegistrationLockData restoredData = keyBackupService.newRestoreSession(kbsData.getTokenResponse())
.restorePin(hashedPin);

if (!restoredData.getMasterKey().equals(masterKey)) {
throw new RuntimeException("Failed to migrate the pin correctly");
} else {
Log.i(TAG, "Set and retrieved pin on KBS successfully");
}

kbsValues.setRegistrationLockMasterKey(restoredData, PinHashing.localPinHash(pinValue));
kbsValues.setRegistrationLockMasterKey(kbsData, PinHashing.localPinHash(pinValue));
TextSecurePreferences.clearOldRegistrationLockPin(context);

Log.i(TAG, "Pin migrated to Key Backup Service");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.whispersystems.signalservice.internal.keybackup.protos.RestoreResponse;
import org.whispersystems.signalservice.internal.push.PushServiceSocket;
import org.whispersystems.signalservice.internal.push.RemoteAttestationUtil;
import org.whispersystems.signalservice.internal.storage.protos.SignalStorage;
import org.whispersystems.signalservice.internal.util.Hex;
import org.whispersystems.signalservice.internal.util.Util;

Expand Down Expand Up @@ -69,16 +68,6 @@ public PinChangeSession newPinChangeSession(TokenResponse currentToken)
return newSession(pushServiceSocket.getKeyBackupServiceAuthorization(), currentToken);
}

/**
* Use this to validate that the pin is still set on the server with the current token.
* Additionally this validates that no one has used any tries.
*/
public RestoreSession newRestoreSession(TokenResponse currentToken)
throws IOException
{
return newSession(pushServiceSocket.getKeyBackupServiceAuthorization(), currentToken);
}

/**
* Only call before registration, to see how many tries are left.
* <p>
Expand Down

0 comments on commit 7f867a6

Please sign in to comment.