mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Separate registrationLock attribute from master key
This commit is contained in:
parent
6bbbccb9ac
commit
c1dc44d4fd
3 changed files with 27 additions and 12 deletions
|
@ -182,7 +182,7 @@ class RegistrationManagerImpl implements RegistrationManager {
|
|||
account.getLocalRegistrationId(),
|
||||
true,
|
||||
null,
|
||||
account.getPinMasterKey() == null ? null : account.getPinMasterKey().deriveRegistrationLock(),
|
||||
account.getRegistrationLock(),
|
||||
account.getSelfUnidentifiedAccessKey(),
|
||||
account.isUnrestrictedUnidentifiedAccess(),
|
||||
capabilities,
|
||||
|
|
|
@ -9,7 +9,6 @@ import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
|
|||
import org.asamk.signal.manager.api.PinLockedException;
|
||||
import org.asamk.signal.manager.config.ServiceConfig;
|
||||
import org.asamk.signal.manager.storage.SignalAccount;
|
||||
import org.asamk.signal.manager.util.KeyUtils;
|
||||
import org.asamk.signal.manager.util.NumberVerificationUtils;
|
||||
import org.signal.libsignal.protocol.InvalidKeyException;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -125,7 +124,7 @@ public class AccountHelper {
|
|||
account.getLocalRegistrationId(),
|
||||
true,
|
||||
null,
|
||||
account.getPinMasterKey() == null ? null : account.getPinMasterKey().deriveRegistrationLock(),
|
||||
account.getRegistrationLock(),
|
||||
account.getSelfUnidentifiedAccessKey(),
|
||||
account.isUnrestrictedUnidentifiedAccess(),
|
||||
ServiceConfig.capabilities,
|
||||
|
@ -157,20 +156,18 @@ public class AccountHelper {
|
|||
}
|
||||
|
||||
public void setRegistrationPin(String pin) throws IOException {
|
||||
final var masterKey = account.getPinMasterKey() != null
|
||||
? account.getPinMasterKey()
|
||||
: KeyUtils.createMasterKey();
|
||||
var masterKey = account.getOrCreatePinMasterKey();
|
||||
|
||||
context.getPinHelper().setRegistrationLockPin(pin, masterKey);
|
||||
|
||||
account.setRegistrationLockPin(pin, masterKey);
|
||||
account.setRegistrationLockPin(pin);
|
||||
}
|
||||
|
||||
public void removeRegistrationPin() throws IOException {
|
||||
// Remove KBS Pin
|
||||
context.getPinHelper().removeRegistrationLockPin();
|
||||
|
||||
account.setRegistrationLockPin(null, null);
|
||||
account.setRegistrationLockPin(null);
|
||||
}
|
||||
|
||||
public void unregister() throws IOException {
|
||||
|
@ -189,7 +186,7 @@ public class AccountHelper {
|
|||
} catch (IOException e) {
|
||||
logger.warn("Failed to remove registration lock pin");
|
||||
}
|
||||
account.setRegistrationLockPin(null, null);
|
||||
account.setRegistrationLockPin(null);
|
||||
|
||||
dependencies.getAccountManager().deleteAccount();
|
||||
|
||||
|
|
|
@ -1253,13 +1253,31 @@ public class SignalAccount implements Closeable {
|
|||
save();
|
||||
}
|
||||
|
||||
public void setRegistrationLockPin(final String registrationLockPin, final MasterKey pinMasterKey) {
|
||||
public void setRegistrationLockPin(final String registrationLockPin) {
|
||||
this.registrationLockPin = registrationLockPin;
|
||||
this.pinMasterKey = pinMasterKey;
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue