]> nmode's Git Repositories - signal-cli/commitdiff
Add possibility to pass a captcha token to register command
authorAsamK <asamk@gmx.de>
Sun, 22 Nov 2020 10:03:14 +0000 (11:03 +0100)
committerAsamK <asamk@gmx.de>
Sun, 22 Nov 2020 10:03:14 +0000 (11:03 +0100)
Fixes #251

man/signal-cli.1.adoc
src/main/java/org/asamk/signal/commands/RegisterCommand.java
src/main/java/org/asamk/signal/manager/Manager.java

index 98a5da2aa5ab8c2dfeec547b6ec20d968aee2d2e..0bef0afcf0fc07c84629d0f7e68a0bc90b3d39a3 100644 (file)
@@ -54,6 +54,12 @@ Use the verify command to complete the verification.
 *-v*, *--voice*::
 The verification should be done over voice, not SMS.
 
+*--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
+Check the developer tools for a redirect starting with signalcaptcha://
+Everything after signalcaptcha:// is the captcha token.
+
 === verify
 
 Verify the number using the code received via SMS or voice.
index e95487bfe0eaee33667d447f469e8aea5b2f8328..f69e0844b8673650c91dd2398414c8731b49c022 100644 (file)
@@ -16,15 +16,19 @@ public class RegisterCommand implements LocalCommand {
         subparser.addArgument("-v", "--voice")
                 .help("The verification should be done over voice, not sms.")
                 .action(Arguments.storeTrue());
+        subparser.addArgument("--captcha")
+                .help("The captcha token, required if registration failed with a captcha required error.");
     }
 
     @Override
     public int handleCommand(final Namespace ns, final Manager m) {
         try {
-            m.register(ns.getBoolean("voice"));
+            final boolean voiceVerification = ns.getBoolean("voice");
+            final String captcha = ns.getString("captcha");
+            m.register(voiceVerification, captcha);
             return 0;
         } catch (CaptchaRequiredException e) {
-            System.err.println("Captcha required for verification (" + e.getMessage() + ")");
+            System.err.println("Captcha invalid or required for verification (" + e.getMessage() + ")");
             return 1;
         } catch (IOException e) {
             System.err.println("Request verify error: " + e.getMessage());
index 63c6ee7de53359ee248c4c8b3ddb96729c7db6a9..83a3926a6f7dc55032857b9e32ce8590491b4948 100644 (file)
@@ -298,7 +298,7 @@ public class Manager implements Closeable {
         return account.isRegistered();
     }
 
-    public void register(boolean voiceVerification) throws IOException {
+    public void register(boolean voiceVerification, String captcha) throws IOException {
         account.setPassword(KeyUtils.createPassword());
 
         // Resetting UUID, because registering doesn't work otherwise
@@ -306,9 +306,9 @@ public class Manager implements Closeable {
         accountManager = createSignalServiceAccountManager();
 
         if (voiceVerification) {
-            accountManager.requestVoiceVerificationCode(Locale.getDefault(), Optional.absent(), Optional.absent());
+            accountManager.requestVoiceVerificationCode(Locale.getDefault(), Optional.fromNullable(captcha), Optional.absent());
         } else {
-            accountManager.requestSmsVerificationCode(false, Optional.absent(), Optional.absent());
+            accountManager.requestSmsVerificationCode(false, Optional.fromNullable(captcha), Optional.absent());
         }
 
         account.setRegistered(false);