Separate registrationLock attribute from master key

This commit is contained in:
AsamK 2022-06-21 16:58:15 +02:00
parent 6bbbccb9ac
commit c1dc44d4fd
3 changed files with 27 additions and 12 deletions

View file

@ -182,7 +182,7 @@ class RegistrationManagerImpl implements RegistrationManager {
account.getLocalRegistrationId(), account.getLocalRegistrationId(),
true, true,
null, null,
account.getPinMasterKey() == null ? null : account.getPinMasterKey().deriveRegistrationLock(), account.getRegistrationLock(),
account.getSelfUnidentifiedAccessKey(), account.getSelfUnidentifiedAccessKey(),
account.isUnrestrictedUnidentifiedAccess(), account.isUnrestrictedUnidentifiedAccess(),
capabilities, capabilities,

View file

@ -9,7 +9,6 @@ import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
import org.asamk.signal.manager.api.PinLockedException; import org.asamk.signal.manager.api.PinLockedException;
import org.asamk.signal.manager.config.ServiceConfig; import org.asamk.signal.manager.config.ServiceConfig;
import org.asamk.signal.manager.storage.SignalAccount; import org.asamk.signal.manager.storage.SignalAccount;
import org.asamk.signal.manager.util.KeyUtils;
import org.asamk.signal.manager.util.NumberVerificationUtils; import org.asamk.signal.manager.util.NumberVerificationUtils;
import org.signal.libsignal.protocol.InvalidKeyException; import org.signal.libsignal.protocol.InvalidKeyException;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -125,7 +124,7 @@ public class AccountHelper {
account.getLocalRegistrationId(), account.getLocalRegistrationId(),
true, true,
null, null,
account.getPinMasterKey() == null ? null : account.getPinMasterKey().deriveRegistrationLock(), account.getRegistrationLock(),
account.getSelfUnidentifiedAccessKey(), account.getSelfUnidentifiedAccessKey(),
account.isUnrestrictedUnidentifiedAccess(), account.isUnrestrictedUnidentifiedAccess(),
ServiceConfig.capabilities, ServiceConfig.capabilities,
@ -157,20 +156,18 @@ public class AccountHelper {
} }
public void setRegistrationPin(String pin) throws IOException { public void setRegistrationPin(String pin) throws IOException {
final var masterKey = account.getPinMasterKey() != null var masterKey = account.getOrCreatePinMasterKey();
? account.getPinMasterKey()
: KeyUtils.createMasterKey();
context.getPinHelper().setRegistrationLockPin(pin, masterKey); context.getPinHelper().setRegistrationLockPin(pin, masterKey);
account.setRegistrationLockPin(pin, masterKey); account.setRegistrationLockPin(pin);
} }
public void removeRegistrationPin() throws IOException { public void removeRegistrationPin() throws IOException {
// Remove KBS Pin // Remove KBS Pin
context.getPinHelper().removeRegistrationLockPin(); context.getPinHelper().removeRegistrationLockPin();
account.setRegistrationLockPin(null, null); account.setRegistrationLockPin(null);
} }
public void unregister() throws IOException { public void unregister() throws IOException {
@ -189,7 +186,7 @@ public class AccountHelper {
} catch (IOException e) { } catch (IOException e) {
logger.warn("Failed to remove registration lock pin"); logger.warn("Failed to remove registration lock pin");
} }
account.setRegistrationLockPin(null, null); account.setRegistrationLockPin(null);
dependencies.getAccountManager().deleteAccount(); dependencies.getAccountManager().deleteAccount();

View file

@ -1253,13 +1253,31 @@ public class SignalAccount implements Closeable {
save(); save();
} }
public void setRegistrationLockPin(final String registrationLockPin, final MasterKey pinMasterKey) { public void setRegistrationLockPin(final String registrationLockPin) {
this.registrationLockPin = registrationLockPin; this.registrationLockPin = registrationLockPin;
this.pinMasterKey = pinMasterKey;
save(); save();
} }
public MasterKey getPinMasterKey() { public String getRegistrationLock() {
final var masterKey = getPinBackedMasterKey();
if (masterKey == null) {
return null;
}
return masterKey.deriveRegistrationLock();
}
public MasterKey getPinBackedMasterKey() {
if (registrationLockPin == null) {
return null;
}
return pinMasterKey;
}
public MasterKey getOrCreatePinMasterKey() {
if (pinMasterKey == null) {
pinMasterKey = KeyUtils.createMasterKey();
save();
}
return pinMasterKey; return pinMasterKey;
} }