1 package org
.asamk
.signal
.commands
;
3 import com
.fasterxml
.jackson
.core
.type
.TypeReference
;
5 import net
.sourceforge
.argparse4j
.inf
.Namespace
;
6 import net
.sourceforge
.argparse4j
.inf
.Subparser
;
8 import org
.asamk
.signal
.OutputType
;
9 import org
.asamk
.signal
.commands
.exceptions
.CommandException
;
10 import org
.asamk
.signal
.commands
.exceptions
.IOErrorException
;
11 import org
.asamk
.signal
.commands
.exceptions
.UserErrorException
;
12 import org
.asamk
.signal
.manager
.RegistrationManager
;
13 import org
.asamk
.signal
.manager
.api
.IncorrectPinException
;
14 import org
.asamk
.signal
.manager
.api
.PinLockMissingException
;
15 import org
.asamk
.signal
.manager
.api
.PinLockedException
;
16 import org
.asamk
.signal
.output
.JsonWriter
;
17 import org
.slf4j
.Logger
;
18 import org
.slf4j
.LoggerFactory
;
20 import java
.io
.IOException
;
21 import java
.util
.List
;
23 public class VerifyCommand
implements RegistrationCommand
, JsonRpcRegistrationCommand
<VerifyCommand
.VerifyParams
> {
25 private static final Logger logger
= LoggerFactory
.getLogger(VerifyCommand
.class);
28 public String
getName() {
33 public void attachToSubparser(final Subparser subparser
) {
34 subparser
.help("Verify the number using the code received via SMS or voice.");
35 subparser
.addArgument("verification-code").help("The verification code you received via sms or voice call.");
36 subparser
.addArgument("-p", "--pin").help("The registration lock PIN, that was set by the user (Optional)");
40 public void handleCommand(final Namespace ns
, final RegistrationManager m
) throws CommandException
{
41 var verificationCode
= ns
.getString("verification-code");
42 var pin
= ns
.getString("pin");
44 verify(m
, verificationCode
, pin
);
48 public TypeReference
<VerifyParams
> getRequestType() {
49 return new TypeReference
<>() {};
53 public List
<OutputType
> getSupportedOutputTypes() {
54 return List
.of(OutputType
.PLAIN_TEXT
, OutputType
.JSON
);
58 public void handleCommand(
59 final VerifyParams request
,
60 final RegistrationManager m
,
61 final JsonWriter jsonWriter
62 ) throws CommandException
{
63 verify(m
, request
.verificationCode(), request
.pin());
67 final RegistrationManager m
,
68 final String verificationCode
,
70 ) throws UserErrorException
, IOErrorException
{
72 m
.verifyAccount(verificationCode
, pin
);
73 } catch (PinLockedException e
) {
74 throw new UserErrorException(
75 "Verification failed! This number is locked with a pin. Hours remaining until reset: "
76 + (e
.getTimeRemaining() / 1000 / 60 / 60)
77 + "\nUse '--pin PIN_CODE' to specify the registration lock PIN");
78 } catch (IncorrectPinException e
) {
79 throw new UserErrorException("Verification failed! Invalid pin, tries remaining: " + e
.getTriesRemaining());
80 } catch (PinLockMissingException e
) {
81 throw new UserErrorException("Account is pin locked, but pin data has been deleted on the server.");
82 } catch (IOException e
) {
83 throw new IOErrorException("Verify error: " + e
.getMessage(), e
);
87 public record VerifyParams(String verificationCode
, String pin
) {}