mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 02:20:39 +00:00
Improve behavior when pin data doesn't exist on the server
This commit is contained in:
parent
6b60a6d5a5
commit
a0d5744c49
11 changed files with 31 additions and 9 deletions
|
@ -30,6 +30,7 @@ import org.asamk.signal.manager.api.NotAGroupMemberException;
|
||||||
import org.asamk.signal.manager.api.NotPrimaryDeviceException;
|
import org.asamk.signal.manager.api.NotPrimaryDeviceException;
|
||||||
import org.asamk.signal.manager.api.Pair;
|
import org.asamk.signal.manager.api.Pair;
|
||||||
import org.asamk.signal.manager.api.PendingAdminApprovalException;
|
import org.asamk.signal.manager.api.PendingAdminApprovalException;
|
||||||
|
import org.asamk.signal.manager.api.PinLockMissingException;
|
||||||
import org.asamk.signal.manager.api.PinLockedException;
|
import org.asamk.signal.manager.api.PinLockedException;
|
||||||
import org.asamk.signal.manager.api.RateLimitException;
|
import org.asamk.signal.manager.api.RateLimitException;
|
||||||
import org.asamk.signal.manager.api.ReceiveConfig;
|
import org.asamk.signal.manager.api.ReceiveConfig;
|
||||||
|
@ -140,7 +141,7 @@ public interface Manager extends Closeable {
|
||||||
String newNumber,
|
String newNumber,
|
||||||
String verificationCode,
|
String verificationCode,
|
||||||
String pin
|
String pin
|
||||||
) throws IncorrectPinException, PinLockedException, IOException, NotPrimaryDeviceException;
|
) throws IncorrectPinException, PinLockedException, IOException, NotPrimaryDeviceException, PinLockMissingException;
|
||||||
|
|
||||||
void unregister() throws IOException;
|
void unregister() throws IOException;
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.asamk.signal.manager;
|
||||||
import org.asamk.signal.manager.api.CaptchaRequiredException;
|
import org.asamk.signal.manager.api.CaptchaRequiredException;
|
||||||
import org.asamk.signal.manager.api.IncorrectPinException;
|
import org.asamk.signal.manager.api.IncorrectPinException;
|
||||||
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
|
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
|
||||||
|
import org.asamk.signal.manager.api.PinLockMissingException;
|
||||||
import org.asamk.signal.manager.api.PinLockedException;
|
import org.asamk.signal.manager.api.PinLockedException;
|
||||||
import org.asamk.signal.manager.api.RateLimitException;
|
import org.asamk.signal.manager.api.RateLimitException;
|
||||||
import org.asamk.signal.manager.api.VerificationMethodNotAvailableException;
|
import org.asamk.signal.manager.api.VerificationMethodNotAvailableException;
|
||||||
|
@ -21,7 +22,7 @@ public interface RegistrationManager extends Closeable {
|
||||||
void verifyAccount(
|
void verifyAccount(
|
||||||
String verificationCode,
|
String verificationCode,
|
||||||
String pin
|
String pin
|
||||||
) throws IOException, PinLockedException, IncorrectPinException;
|
) throws IOException, PinLockedException, IncorrectPinException, PinLockMissingException;
|
||||||
|
|
||||||
void deleteLocalAccountData() throws IOException;
|
void deleteLocalAccountData() throws IOException;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package org.asamk.signal.manager.api;
|
||||||
|
|
||||||
|
public class PinLockMissingException extends Exception {}
|
|
@ -4,6 +4,7 @@ import org.asamk.signal.manager.api.CaptchaRequiredException;
|
||||||
import org.asamk.signal.manager.api.DeviceLinkUrl;
|
import org.asamk.signal.manager.api.DeviceLinkUrl;
|
||||||
import org.asamk.signal.manager.api.IncorrectPinException;
|
import org.asamk.signal.manager.api.IncorrectPinException;
|
||||||
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
|
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
|
||||||
|
import org.asamk.signal.manager.api.PinLockMissingException;
|
||||||
import org.asamk.signal.manager.api.PinLockedException;
|
import org.asamk.signal.manager.api.PinLockedException;
|
||||||
import org.asamk.signal.manager.api.RateLimitException;
|
import org.asamk.signal.manager.api.RateLimitException;
|
||||||
import org.asamk.signal.manager.api.VerificationMethodNotAvailableException;
|
import org.asamk.signal.manager.api.VerificationMethodNotAvailableException;
|
||||||
|
@ -185,7 +186,7 @@ public class AccountHelper {
|
||||||
String newNumber,
|
String newNumber,
|
||||||
String verificationCode,
|
String verificationCode,
|
||||||
String pin
|
String pin
|
||||||
) throws IncorrectPinException, PinLockedException, IOException {
|
) throws IncorrectPinException, PinLockedException, IOException, PinLockMissingException {
|
||||||
for (var attempts = 0; attempts < 5; attempts++) {
|
for (var attempts = 0; attempts < 5; attempts++) {
|
||||||
try {
|
try {
|
||||||
finishChangeNumberInternal(newNumber, verificationCode, pin);
|
finishChangeNumberInternal(newNumber, verificationCode, pin);
|
||||||
|
@ -205,7 +206,7 @@ public class AccountHelper {
|
||||||
String newNumber,
|
String newNumber,
|
||||||
String verificationCode,
|
String verificationCode,
|
||||||
String pin
|
String pin
|
||||||
) throws IncorrectPinException, PinLockedException, IOException {
|
) throws IncorrectPinException, PinLockedException, IOException, PinLockMissingException {
|
||||||
final var pniIdentity = KeyUtils.generateIdentityKeyPair();
|
final var pniIdentity = KeyUtils.generateIdentityKeyPair();
|
||||||
final var encryptedDeviceMessages = new ArrayList<OutgoingPushMessage>();
|
final var encryptedDeviceMessages = new ArrayList<OutgoingPushMessage>();
|
||||||
final var devicePniSignedPreKeys = new HashMap<Integer, SignedPreKeyEntity>();
|
final var devicePniSignedPreKeys = new HashMap<Integer, SignedPreKeyEntity>();
|
||||||
|
|
|
@ -88,7 +88,11 @@ public class PinHelper {
|
||||||
IOException exception = null;
|
IOException exception = null;
|
||||||
for (final var secureValueRecovery : secureValueRecoveries) {
|
for (final var secureValueRecovery : secureValueRecoveries) {
|
||||||
try {
|
try {
|
||||||
return getRegistrationLockData(secureValueRecovery, svr2Credentials, pin);
|
final var lockData = getRegistrationLockData(secureValueRecovery, svr2Credentials, pin);
|
||||||
|
if (lockData == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return lockData;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
exception = e;
|
exception = e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@ import org.asamk.signal.manager.api.NotPrimaryDeviceException;
|
||||||
import org.asamk.signal.manager.api.Pair;
|
import org.asamk.signal.manager.api.Pair;
|
||||||
import org.asamk.signal.manager.api.PendingAdminApprovalException;
|
import org.asamk.signal.manager.api.PendingAdminApprovalException;
|
||||||
import org.asamk.signal.manager.api.PhoneNumberSharingMode;
|
import org.asamk.signal.manager.api.PhoneNumberSharingMode;
|
||||||
|
import org.asamk.signal.manager.api.PinLockMissingException;
|
||||||
import org.asamk.signal.manager.api.PinLockedException;
|
import org.asamk.signal.manager.api.PinLockedException;
|
||||||
import org.asamk.signal.manager.api.Profile;
|
import org.asamk.signal.manager.api.Profile;
|
||||||
import org.asamk.signal.manager.api.RateLimitException;
|
import org.asamk.signal.manager.api.RateLimitException;
|
||||||
|
@ -428,7 +429,7 @@ public class ManagerImpl implements Manager {
|
||||||
String newNumber,
|
String newNumber,
|
||||||
String verificationCode,
|
String verificationCode,
|
||||||
String pin
|
String pin
|
||||||
) throws IncorrectPinException, PinLockedException, IOException, NotPrimaryDeviceException {
|
) throws IncorrectPinException, PinLockedException, IOException, NotPrimaryDeviceException, PinLockMissingException {
|
||||||
if (!account.isPrimaryDevice()) {
|
if (!account.isPrimaryDevice()) {
|
||||||
throw new NotPrimaryDeviceException();
|
throw new NotPrimaryDeviceException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import org.asamk.signal.manager.RegistrationManager;
|
||||||
import org.asamk.signal.manager.api.CaptchaRequiredException;
|
import org.asamk.signal.manager.api.CaptchaRequiredException;
|
||||||
import org.asamk.signal.manager.api.IncorrectPinException;
|
import org.asamk.signal.manager.api.IncorrectPinException;
|
||||||
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
|
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
|
||||||
|
import org.asamk.signal.manager.api.PinLockMissingException;
|
||||||
import org.asamk.signal.manager.api.PinLockedException;
|
import org.asamk.signal.manager.api.PinLockedException;
|
||||||
import org.asamk.signal.manager.api.RateLimitException;
|
import org.asamk.signal.manager.api.RateLimitException;
|
||||||
import org.asamk.signal.manager.api.UpdateProfile;
|
import org.asamk.signal.manager.api.UpdateProfile;
|
||||||
|
@ -149,7 +150,7 @@ public class RegistrationManagerImpl implements RegistrationManager {
|
||||||
public void verifyAccount(
|
public void verifyAccount(
|
||||||
String verificationCode,
|
String verificationCode,
|
||||||
String pin
|
String pin
|
||||||
) throws IOException, PinLockedException, IncorrectPinException {
|
) throws IOException, PinLockedException, IncorrectPinException, PinLockMissingException {
|
||||||
if (account.isRegistered()) {
|
if (account.isRegistered()) {
|
||||||
throw new IOException("Account is already registered");
|
throw new IOException("Account is already registered");
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import org.asamk.signal.manager.api.CaptchaRequiredException;
|
||||||
import org.asamk.signal.manager.api.IncorrectPinException;
|
import org.asamk.signal.manager.api.IncorrectPinException;
|
||||||
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
|
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
|
||||||
import org.asamk.signal.manager.api.Pair;
|
import org.asamk.signal.manager.api.Pair;
|
||||||
|
import org.asamk.signal.manager.api.PinLockMissingException;
|
||||||
import org.asamk.signal.manager.api.PinLockedException;
|
import org.asamk.signal.manager.api.PinLockedException;
|
||||||
import org.asamk.signal.manager.api.RateLimitException;
|
import org.asamk.signal.manager.api.RateLimitException;
|
||||||
import org.asamk.signal.manager.api.VerificationMethodNotAvailableException;
|
import org.asamk.signal.manager.api.VerificationMethodNotAvailableException;
|
||||||
|
@ -114,7 +115,7 @@ public class NumberVerificationUtils {
|
||||||
String pin,
|
String pin,
|
||||||
PinHelper pinHelper,
|
PinHelper pinHelper,
|
||||||
Verifier verifier
|
Verifier verifier
|
||||||
) throws IOException, PinLockedException, IncorrectPinException {
|
) throws IOException, PinLockedException, IncorrectPinException, PinLockMissingException {
|
||||||
verificationCode = verificationCode.replace("-", "");
|
verificationCode = verificationCode.replace("-", "");
|
||||||
try {
|
try {
|
||||||
final var response = verifier.verify(sessionId, verificationCode, null);
|
final var response = verifier.verify(sessionId, verificationCode, null);
|
||||||
|
@ -127,7 +128,7 @@ public class NumberVerificationUtils {
|
||||||
|
|
||||||
final var registrationLockData = pinHelper.getRegistrationLockData(pin, e);
|
final var registrationLockData = pinHelper.getRegistrationLockData(pin, e);
|
||||||
if (registrationLockData == null) {
|
if (registrationLockData == null) {
|
||||||
throw e;
|
throw new PinLockMissingException();
|
||||||
}
|
}
|
||||||
|
|
||||||
var registrationLock = registrationLockData.getMasterKey().deriveRegistrationLock();
|
var registrationLock = registrationLockData.getMasterKey().deriveRegistrationLock();
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.asamk.signal.commands.exceptions.UserErrorException;
|
||||||
import org.asamk.signal.manager.Manager;
|
import org.asamk.signal.manager.Manager;
|
||||||
import org.asamk.signal.manager.api.IncorrectPinException;
|
import org.asamk.signal.manager.api.IncorrectPinException;
|
||||||
import org.asamk.signal.manager.api.NotPrimaryDeviceException;
|
import org.asamk.signal.manager.api.NotPrimaryDeviceException;
|
||||||
|
import org.asamk.signal.manager.api.PinLockMissingException;
|
||||||
import org.asamk.signal.manager.api.PinLockedException;
|
import org.asamk.signal.manager.api.PinLockedException;
|
||||||
import org.asamk.signal.output.OutputWriter;
|
import org.asamk.signal.output.OutputWriter;
|
||||||
|
|
||||||
|
@ -50,6 +51,8 @@ public class FinishChangeNumberCommand implements JsonRpcLocalCommand {
|
||||||
+ "\nUse '--pin PIN_CODE' to specify the registration lock PIN");
|
+ "\nUse '--pin PIN_CODE' to specify the registration lock PIN");
|
||||||
} catch (IncorrectPinException e) {
|
} catch (IncorrectPinException e) {
|
||||||
throw new UserErrorException("Verification failed! Invalid pin, tries remaining: " + e.getTriesRemaining());
|
throw new UserErrorException("Verification failed! Invalid pin, tries remaining: " + e.getTriesRemaining());
|
||||||
|
} catch (PinLockMissingException e) {
|
||||||
|
throw new UserErrorException("Account is pin locked, but pin data has been deleted on the server.");
|
||||||
} catch (NotPrimaryDeviceException e) {
|
} catch (NotPrimaryDeviceException e) {
|
||||||
throw new UserErrorException("This command doesn't work on linked devices.");
|
throw new UserErrorException("This command doesn't work on linked devices.");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
|
@ -11,6 +11,7 @@ import org.asamk.signal.commands.exceptions.IOErrorException;
|
||||||
import org.asamk.signal.commands.exceptions.UserErrorException;
|
import org.asamk.signal.commands.exceptions.UserErrorException;
|
||||||
import org.asamk.signal.manager.RegistrationManager;
|
import org.asamk.signal.manager.RegistrationManager;
|
||||||
import org.asamk.signal.manager.api.IncorrectPinException;
|
import org.asamk.signal.manager.api.IncorrectPinException;
|
||||||
|
import org.asamk.signal.manager.api.PinLockMissingException;
|
||||||
import org.asamk.signal.manager.api.PinLockedException;
|
import org.asamk.signal.manager.api.PinLockedException;
|
||||||
import org.asamk.signal.output.JsonWriter;
|
import org.asamk.signal.output.JsonWriter;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -76,6 +77,8 @@ public class VerifyCommand implements RegistrationCommand, JsonRpcRegistrationCo
|
||||||
+ "\nUse '--pin PIN_CODE' to specify the registration lock PIN");
|
+ "\nUse '--pin PIN_CODE' to specify the registration lock PIN");
|
||||||
} catch (IncorrectPinException e) {
|
} catch (IncorrectPinException e) {
|
||||||
throw new UserErrorException("Verification failed! Invalid pin, tries remaining: " + e.getTriesRemaining());
|
throw new UserErrorException("Verification failed! Invalid pin, tries remaining: " + e.getTriesRemaining());
|
||||||
|
} catch (PinLockMissingException e) {
|
||||||
|
throw new UserErrorException("Account is pin locked, but pin data has been deleted on the server.");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IOErrorException("Verify error: " + e.getMessage(), e);
|
throw new IOErrorException("Verify error: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.asamk.signal.manager.RegistrationManager;
|
||||||
import org.asamk.signal.manager.api.CaptchaRequiredException;
|
import org.asamk.signal.manager.api.CaptchaRequiredException;
|
||||||
import org.asamk.signal.manager.api.IncorrectPinException;
|
import org.asamk.signal.manager.api.IncorrectPinException;
|
||||||
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
|
import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
|
||||||
|
import org.asamk.signal.manager.api.PinLockMissingException;
|
||||||
import org.asamk.signal.manager.api.PinLockedException;
|
import org.asamk.signal.manager.api.PinLockedException;
|
||||||
import org.asamk.signal.manager.api.RateLimitException;
|
import org.asamk.signal.manager.api.RateLimitException;
|
||||||
import org.asamk.signal.manager.api.UserAlreadyExistsException;
|
import org.asamk.signal.manager.api.UserAlreadyExistsException;
|
||||||
|
@ -105,6 +106,8 @@ public class DbusSignalControlImpl implements org.asamk.SignalControl {
|
||||||
+ (e.getTimeRemaining() / 1000 / 60 / 60));
|
+ (e.getTimeRemaining() / 1000 / 60 / 60));
|
||||||
} catch (IncorrectPinException e) {
|
} catch (IncorrectPinException e) {
|
||||||
throw new Error.Failure("Verification failed! Invalid pin, tries remaining: " + e.getTriesRemaining());
|
throw new Error.Failure("Verification failed! Invalid pin, tries remaining: " + e.getTriesRemaining());
|
||||||
|
} catch (PinLockMissingException e) {
|
||||||
|
throw new Error.Failure("Account is pin locked, but pin data has been deleted on the server.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue