Handle UnauthenticatedResponseException internally

This commit is contained in:
AsamK 2021-10-31 20:53:03 +01:00
parent 782f96b580
commit 31dec5a666
7 changed files with 16 additions and 24 deletions

View file

@ -30,7 +30,6 @@ import org.whispersystems.signalservice.api.messages.SignalServiceContent;
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.util.PhoneNumberFormatter;
import org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException;
import java.io.Closeable;
import java.io.File;
@ -118,7 +117,7 @@ public interface Manager extends Closeable {
void addDeviceLink(URI linkUri) throws IOException, InvalidDeviceLinkException;
void setRegistrationLockPin(Optional<String> pin) throws IOException, UnauthenticatedResponseException;
void setRegistrationLockPin(Optional<String> pin) throws IOException;
Profile getRecipientProfile(RecipientIdentifier.Single recipient) throws IOException;

View file

@ -382,7 +382,7 @@ public class ManagerImpl implements Manager {
public void deleteAccount() throws IOException {
try {
pinHelper.removeRegistrationLockPin();
} catch (UnauthenticatedResponseException e) {
} catch (IOException e) {
logger.warn("Failed to remove registration lock pin");
}
account.setRegistrationLockPin(null, null);
@ -453,7 +453,7 @@ public class ManagerImpl implements Manager {
}
@Override
public void setRegistrationLockPin(java.util.Optional<String> pin) throws IOException, UnauthenticatedResponseException {
public void setRegistrationLockPin(java.util.Optional<String> pin) throws IOException {
if (!account.isMasterDevice()) {
throw new RuntimeException("Only master device can set a PIN");
}

View file

@ -23,18 +23,26 @@ public class PinHelper {
public void setRegistrationLockPin(
String pin, MasterKey masterKey
) throws IOException, UnauthenticatedResponseException {
) throws IOException {
final var pinChangeSession = keyBackupService.newPinChangeSession();
final var hashedPin = PinHashing.hashPin(pin, pinChangeSession);
pinChangeSession.setPin(hashedPin, masterKey);
try {
pinChangeSession.setPin(hashedPin, masterKey);
} catch (UnauthenticatedResponseException e) {
throw new IOException(e);
}
pinChangeSession.enableRegistrationLock(masterKey);
}
public void removeRegistrationLockPin() throws IOException, UnauthenticatedResponseException {
public void removeRegistrationLockPin() throws IOException {
final var pinChangeSession = keyBackupService.newPinChangeSession();
pinChangeSession.disableRegistrationLock();
pinChangeSession.removePin();
try {
pinChangeSession.removePin();
} catch (UnauthenticatedResponseException e) {
throw new IOException(e);
}
}
public KbsPinData getRegistrationLockData(