1 package org
.asamk
.signal
.commands
;
3 import net
.sourceforge
.argparse4j
.inf
.Namespace
;
4 import net
.sourceforge
.argparse4j
.inf
.Subparser
;
6 import org
.asamk
.signal
.OutputWriter
;
7 import org
.asamk
.signal
.commands
.exceptions
.CommandException
;
8 import org
.asamk
.signal
.commands
.exceptions
.IOErrorException
;
9 import org
.asamk
.signal
.commands
.exceptions
.UnexpectedErrorException
;
10 import org
.asamk
.signal
.commands
.exceptions
.UserErrorException
;
11 import org
.asamk
.signal
.manager
.RegistrationManager
;
12 import org
.whispersystems
.signalservice
.api
.KeyBackupServicePinException
;
13 import org
.whispersystems
.signalservice
.api
.KeyBackupSystemNoDataException
;
14 import org
.whispersystems
.signalservice
.internal
.push
.LockedException
;
16 import java
.io
.IOException
;
18 public class VerifyCommand
implements RegistrationCommand
{
20 public VerifyCommand(final OutputWriter outputWriter
) {
23 public static void attachToSubparser(final Subparser subparser
) {
24 subparser
.help("Verify the number using the code received via SMS or voice.");
25 subparser
.addArgument("verificationCode").help("The verification code you received via sms or voice call.");
26 subparser
.addArgument("-p", "--pin").help("The registration lock PIN, that was set by the user (Optional)");
30 public void handleCommand(final Namespace ns
, final RegistrationManager m
) throws CommandException
{
31 var verificationCode
= ns
.getString("verificationCode");
32 var pin
= ns
.getString("pin");
35 final var manager
= m
.verifyAccount(verificationCode
, pin
);
37 } catch (LockedException e
) {
38 throw new UserErrorException(
39 "Verification failed! This number is locked with a pin. Hours remaining until reset: "
40 + (e
.getTimeRemaining() / 1000 / 60 / 60)
41 + "\nUse '--pin PIN_CODE' to specify the registration lock PIN");
42 } catch (KeyBackupServicePinException e
) {
43 throw new UserErrorException("Verification failed! Invalid pin, tries remaining: " + e
.getTriesRemaining());
44 } catch (KeyBackupSystemNoDataException e
) {
45 throw new UnexpectedErrorException("Verification failed! No KBS data.");
46 } catch (IOException e
) {
47 throw new IOErrorException("Verify error: " + e
.getMessage());