Add register parameter to force reregistration

This commit is contained in:
AsamK 2024-02-27 18:12:43 +01:00
parent 2e4cd0eddc
commit 2424fc1f53
6 changed files with 31 additions and 14 deletions

View file

@ -13,7 +13,7 @@ import java.io.IOException;
public interface RegistrationManager extends Closeable { public interface RegistrationManager extends Closeable {
void register( void register(
boolean voiceVerification, String captcha boolean voiceVerification, String captcha, final boolean forceRegister
) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, RateLimitException, VerificationMethoNotAvailableException; ) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, RateLimitException, VerificationMethoNotAvailableException;
void verifyAccount( void verifyAccount(

View file

@ -104,7 +104,7 @@ public class RegistrationManagerImpl implements RegistrationManager {
@Override @Override
public void register( public void register(
boolean voiceVerification, String captcha boolean voiceVerification, String captcha, final boolean forceRegister
) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, RateLimitException, VerificationMethoNotAvailableException { ) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, RateLimitException, VerificationMethoNotAvailableException {
if (account.isRegistered() if (account.isRegistered()
&& account.getServiceEnvironment() != null && account.getServiceEnvironment() != null
@ -113,12 +113,18 @@ public class RegistrationManagerImpl implements RegistrationManager {
} }
try { try {
final var recoveryPassword = account.getRecoveryPassword(); if (!forceRegister) {
if (recoveryPassword != null && account.isPrimaryDevice() && attemptReregisterAccount(recoveryPassword)) { if (account.isRegistered()) {
return; throw new IOException("Account is already registered");
}
if (account.getAci() != null && attemptReactivateAccount()) {
return;
}
} }
if (account.getAci() != null && attemptReactivateAccount()) { final var recoveryPassword = account.getRecoveryPassword();
if (recoveryPassword != null && account.isPrimaryDevice() && attemptReregisterAccount(recoveryPassword)) {
return; return;
} }
@ -128,6 +134,7 @@ public class RegistrationManagerImpl implements RegistrationManager {
voiceVerification, voiceVerification,
captcha); captcha);
NumberVerificationUtils.requestVerificationCode(accountManager, sessionId, voiceVerification); NumberVerificationUtils.requestVerificationCode(accountManager, sessionId, voiceVerification);
account.setRegistered(false);
} catch (DeprecatedVersionException e) { } catch (DeprecatedVersionException e) {
logger.debug("Signal-Server returned deprecated version exception", e); logger.debug("Signal-Server returned deprecated version exception", e);
throw e; throw e;

View file

@ -102,12 +102,15 @@ If the account was deleted (with --delete-account) it cannot be reactivated.
The verification should be done over voice, not SMS. The verification should be done over voice, not SMS.
Voice verification only works if an SMS verification has been attempted before. Voice verification only works if an SMS verification has been attempted before.
*--captcha*:: *--captcha* CAPTCHA::
The captcha token, required if registration failed with a captcha required error. The captcha token, required if registration failed with a captcha required error.
To get the token, go to https://signalcaptchas.org/registration/generate.html To get the token, go to https://signalcaptchas.org/registration/generate.html
For the staging environment, use: https://signalcaptchas.org/staging/registration/generate.html For the staging environment, use: https://signalcaptchas.org/staging/registration/generate.html
After solving the captcha, right-click on the "Open Signal" link and copy the link. After solving the captcha, right-click on the "Open Signal" link and copy the link.
*--reregister*::
Register even if account is already registered.
=== verify === verify
Verify the number using the code received via SMS or voice. Verify the number using the code received via SMS or voice.

View file

@ -37,14 +37,18 @@ public class RegisterCommand implements RegistrationCommand, JsonRpcRegistration
.action(Arguments.storeTrue()); .action(Arguments.storeTrue());
subparser.addArgument("--captcha") subparser.addArgument("--captcha")
.help("The captcha token, required if registration failed with a captcha required error."); .help("The captcha token, required if registration failed with a captcha required error.");
subparser.addArgument("--reregister")
.action(Arguments.storeTrue())
.help("Register even if account is already registered");
} }
@Override @Override
public void handleCommand(final Namespace ns, final RegistrationManager m) throws CommandException { public void handleCommand(final Namespace ns, final RegistrationManager m) throws CommandException {
final boolean voiceVerification = Boolean.TRUE.equals(ns.getBoolean("voice")); final boolean voiceVerification = Boolean.TRUE.equals(ns.getBoolean("voice"));
final var captcha = ns.getString("captcha"); final var captcha = ns.getString("captcha");
final var reregister = Boolean.TRUE.equals(ns.getBoolean("reregister"));
register(m, voiceVerification, captcha); register(m, voiceVerification, captcha, reregister);
} }
@Override @Override
@ -61,14 +65,14 @@ public class RegisterCommand implements RegistrationCommand, JsonRpcRegistration
public void handleCommand( public void handleCommand(
final RegistrationParams request, final RegistrationManager m, final JsonWriter jsonWriter final RegistrationParams request, final RegistrationManager m, final JsonWriter jsonWriter
) throws CommandException { ) throws CommandException {
register(m, Boolean.TRUE.equals(request.voice()), request.captcha()); register(m, Boolean.TRUE.equals(request.voice()), request.captcha(), Boolean.TRUE.equals(request.reregister()));
} }
private void register( private void register(
final RegistrationManager m, final boolean voiceVerification, final String captcha final RegistrationManager m, final boolean voiceVerification, final String captcha, final boolean reregister
) throws CommandException { ) throws CommandException {
try { try {
m.register(voiceVerification, captcha); m.register(voiceVerification, captcha, reregister);
} catch (RateLimitException e) { } catch (RateLimitException e) {
final var message = CommandUtil.getRateLimitMessage(e); final var message = CommandUtil.getRateLimitMessage(e);
throw new RateLimitErrorException(message, e); throw new RateLimitErrorException(message, e);
@ -89,5 +93,5 @@ public class RegisterCommand implements RegistrationCommand, JsonRpcRegistration
} }
} }
public record RegistrationParams(Boolean voice, String captcha) {} public record RegistrationParams(Boolean voice, String captcha, Boolean reregister) {}
} }

View file

@ -27,8 +27,11 @@ public class DbusRegistrationManagerImpl implements RegistrationManager {
@Override @Override
public void register( public void register(
final boolean voiceVerification, final String captcha final boolean voiceVerification, final String captcha, final boolean forceRegister
) throws IOException, CaptchaRequiredException { ) throws IOException, CaptchaRequiredException {
if (forceRegister) {
throw new UnsupportedOperationException();
}
if (captcha == null) { if (captcha == null) {
signalControl.register(number, voiceVerification); signalControl.register(number, voiceVerification);
} else { } else {

View file

@ -63,7 +63,7 @@ public class DbusSignalControlImpl implements org.asamk.SignalControl {
"Invalid account (phone number), make sure you include the country code."); "Invalid account (phone number), make sure you include the country code.");
} }
try (final RegistrationManager registrationManager = c.getNewRegistrationManager(number)) { try (final RegistrationManager registrationManager = c.getNewRegistrationManager(number)) {
registrationManager.register(voiceVerification, captcha); registrationManager.register(voiceVerification, captcha, false);
} catch (RateLimitException e) { } catch (RateLimitException e) {
String message = "Rate limit reached"; String message = "Rate limit reached";
throw new SignalControl.Error.Failure(message); throw new SignalControl.Error.Failure(message);