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
.commands
.exceptions
.CommandException
;
7 import org
.asamk
.signal
.commands
.exceptions
.IOErrorException
;
8 import org
.asamk
.signal
.commands
.exceptions
.UnexpectedErrorException
;
9 import org
.asamk
.signal
.commands
.exceptions
.UserErrorException
;
10 import org
.asamk
.signal
.manager
.RegistrationManager
;
11 import org
.whispersystems
.signalservice
.api
.KeyBackupServicePinException
;
12 import org
.whispersystems
.signalservice
.api
.KeyBackupSystemNoDataException
;
13 import org
.whispersystems
.signalservice
.internal
.push
.LockedException
;
15 import java
.io
.IOException
;
17 public class VerifyCommand
implements RegistrationCommand
{
20 public void attachToSubparser(final Subparser subparser
) {
21 subparser
.help("Verify the number using the code received via SMS or voice.");
22 subparser
.addArgument("verificationCode").help("The verification code you received via sms or voice call.");
23 subparser
.addArgument("-p", "--pin").help("The registration lock PIN, that was set by the user (Optional)");
27 public void handleCommand(final Namespace ns
, final RegistrationManager m
) throws CommandException
{
28 var verificationCode
= ns
.getString("verificationCode");
29 var pin
= ns
.getString("pin");
32 final var manager
= m
.verifyAccount(verificationCode
, pin
);
34 } catch (LockedException e
) {
35 throw new UserErrorException(
36 "Verification failed! This number is locked with a pin. Hours remaining until reset: "
37 + (e
.getTimeRemaining() / 1000 / 60 / 60)
38 + "\nUse '--pin PIN_CODE' to specify the registration lock PIN");
39 } catch (KeyBackupServicePinException e
) {
40 throw new UserErrorException("Verification failed! Invalid pin, tries remaining: " + e
.getTriesRemaining());
41 } catch (KeyBackupSystemNoDataException e
) {
42 throw new UnexpectedErrorException("Verification failed! No KBS data.");
43 } catch (IOException e
) {
44 throw new IOErrorException("Verify error: " + e
.getMessage());