]> nmode's Git Repositories - signal-cli/commitdiff
Add register parameter to force reregistration
authorAsamK <asamk@gmx.de>
Tue, 27 Feb 2024 17:12:43 +0000 (18:12 +0100)
committerAsamK <asamk@gmx.de>
Tue, 27 Feb 2024 17:12:43 +0000 (18:12 +0100)
lib/src/main/java/org/asamk/signal/manager/RegistrationManager.java
lib/src/main/java/org/asamk/signal/manager/internal/RegistrationManagerImpl.java
man/signal-cli.1.adoc
src/main/java/org/asamk/signal/commands/RegisterCommand.java
src/main/java/org/asamk/signal/dbus/DbusRegistrationManagerImpl.java
src/main/java/org/asamk/signal/dbus/DbusSignalControlImpl.java

index 365dd3996133fe346d64695f2a1526df70adf52f..75a91dc972fa19bf88014169f2dd28e592984ed2 100644 (file)
@@ -13,7 +13,7 @@ import java.io.IOException;
 public interface RegistrationManager extends Closeable {
 
     void register(
-            boolean voiceVerification, String captcha
+            boolean voiceVerification, String captcha, final boolean forceRegister
     ) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, RateLimitException, VerificationMethoNotAvailableException;
 
     void verifyAccount(
index 2df7ff4bad669b0421dc13d2ea491e380699ea91..b0725cbd23ce9fe25d3d66600f5ad86ef03ffbc4 100644 (file)
@@ -104,7 +104,7 @@ public class RegistrationManagerImpl implements RegistrationManager {
 
     @Override
     public void register(
-            boolean voiceVerification, String captcha
+            boolean voiceVerification, String captcha, final boolean forceRegister
     ) throws IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, RateLimitException, VerificationMethoNotAvailableException {
         if (account.isRegistered()
                 && account.getServiceEnvironment() != null
@@ -113,12 +113,18 @@ public class RegistrationManagerImpl implements RegistrationManager {
         }
 
         try {
-            final var recoveryPassword = account.getRecoveryPassword();
-            if (recoveryPassword != null && account.isPrimaryDevice() && attemptReregisterAccount(recoveryPassword)) {
-                return;
+            if (!forceRegister) {
+                if (account.isRegistered()) {
+                    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;
             }
 
@@ -128,6 +134,7 @@ public class RegistrationManagerImpl implements RegistrationManager {
                     voiceVerification,
                     captcha);
             NumberVerificationUtils.requestVerificationCode(accountManager, sessionId, voiceVerification);
+            account.setRegistered(false);
         } catch (DeprecatedVersionException e) {
             logger.debug("Signal-Server returned deprecated version exception", e);
             throw e;
index 4b59c75422372faa18533d71b003ba728bc40bd4..80d4c37ef07d34efc49376c44ef28ada4d42d276 100644 (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.
 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.
 To get the token, go to https://signalcaptchas.org/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.
 
+*--reregister*::
+Register even if account is already registered.
+
 === verify
 
 Verify the number using the code received via SMS or voice.
index 4776ac6e2e0359de197a45b7935ea1ca6f654207..2f03cbb3b42e9503eaf3e4eb9340f5728e208387 100644 (file)
@@ -37,14 +37,18 @@ public class RegisterCommand implements RegistrationCommand, JsonRpcRegistration
                 .action(Arguments.storeTrue());
         subparser.addArgument("--captcha")
                 .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
     public void handleCommand(final Namespace ns, final RegistrationManager m) throws CommandException {
         final boolean voiceVerification = Boolean.TRUE.equals(ns.getBoolean("voice"));
         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
@@ -61,14 +65,14 @@ public class RegisterCommand implements RegistrationCommand, JsonRpcRegistration
     public void handleCommand(
             final RegistrationParams request, final RegistrationManager m, final JsonWriter jsonWriter
     ) 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(
-            final RegistrationManager m, final boolean voiceVerification, final String captcha
+            final RegistrationManager m, final boolean voiceVerification, final String captcha, final boolean reregister
     ) throws CommandException {
         try {
-            m.register(voiceVerification, captcha);
+            m.register(voiceVerification, captcha, reregister);
         } catch (RateLimitException e) {
             final var message = CommandUtil.getRateLimitMessage(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) {}
 }
index 4d43b98c28d867b0e0afeb11a9ddc87930071434..788e0c913d20a72e89ccdedf196074f60d8df55a 100644 (file)
@@ -27,8 +27,11 @@ public class DbusRegistrationManagerImpl implements RegistrationManager {
 
     @Override
     public void register(
-            final boolean voiceVerification, final String captcha
+            final boolean voiceVerification, final String captcha, final boolean forceRegister
     ) throws IOException, CaptchaRequiredException {
+        if (forceRegister) {
+            throw new UnsupportedOperationException();
+        }
         if (captcha == null) {
             signalControl.register(number, voiceVerification);
         } else {
index d8465d2678acb227493e1054b5f8af8b146c8380..ddf25cd18f7a5d71c327f3635fd57ffce674bd47 100644 (file)
@@ -63,7 +63,7 @@ public class DbusSignalControlImpl implements org.asamk.SignalControl {
                     "Invalid account (phone number), make sure you include the country code.");
         }
         try (final RegistrationManager registrationManager = c.getNewRegistrationManager(number)) {
-            registrationManager.register(voiceVerification, captcha);
+            registrationManager.register(voiceVerification, captcha, false);
         } catch (RateLimitException e) {
             String message = "Rate limit reached";
             throw new SignalControl.Error.Failure(message);