1 package org
.asamk
.signal
.commands
;
3 import net
.sourceforge
.argparse4j
.impl
.Arguments
;
4 import net
.sourceforge
.argparse4j
.inf
.Namespace
;
5 import net
.sourceforge
.argparse4j
.inf
.Subparser
;
7 import org
.asamk
.signal
.commands
.exceptions
.CommandException
;
8 import org
.asamk
.signal
.commands
.exceptions
.UserErrorException
;
9 import org
.asamk
.signal
.manager
.Manager
;
10 import org
.asamk
.signal
.manager
.api
.IdentityVerificationCode
;
11 import org
.asamk
.signal
.manager
.api
.UnregisteredRecipientException
;
12 import org
.asamk
.signal
.output
.OutputWriter
;
13 import org
.asamk
.signal
.util
.CommandUtil
;
15 public class TrustCommand
implements JsonRpcLocalCommand
{
18 public String
getName() {
23 public void attachToSubparser(final Subparser subparser
) {
24 subparser
.help("Set the trust level of a given number.");
25 subparser
.addArgument("recipient").help("Specify the phone number, for which to set the trust.").required(true);
26 var mutTrust
= subparser
.addMutuallyExclusiveGroup();
27 mutTrust
.addArgument("-a", "--trust-all-known-keys")
28 .help("Trust all known keys of this user, only use this for testing.")
29 .action(Arguments
.storeTrue());
30 mutTrust
.addArgument("-v", "--verified-safety-number", "--verified-fingerprint")
31 .help("Specify the safety number of the key, only use this option if you have verified the safety number.");
35 public void handleCommand(
36 final Namespace ns
, final Manager m
, final OutputWriter outputWriter
37 ) throws CommandException
{
38 var recipientString
= ns
.getString("recipient");
39 var recipient
= CommandUtil
.getSingleRecipientIdentifier(recipientString
, m
.getSelfNumber());
40 if (Boolean
.TRUE
.equals(ns
.getBoolean("trust-all-known-keys"))) {
42 final var res
= m
.trustIdentityAllKeys(recipient
);
44 throw new UserErrorException(
45 "Failed to set the trust for this number, make sure the number is correct.");
47 } catch (UnregisteredRecipientException e
) {
48 throw new UserErrorException("The user " + e
.getSender().getIdentifier() + " is not registered.");
51 var safetyNumber
= ns
.getString("verified-safety-number");
52 if (safetyNumber
== null) {
53 throw new UserErrorException(
54 "You need to specify the fingerprint/safety number you have verified with -v SAFETY_NUMBER");
57 final IdentityVerificationCode verificationCode
;
59 verificationCode
= IdentityVerificationCode
.parse(safetyNumber
);
60 } catch (Exception e
) {
61 throw new UserErrorException(
62 "Safety number has invalid format, either specify the old hex fingerprint or the new safety number");
66 final var res
= m
.trustIdentityVerified(recipient
, verificationCode
);
68 throw new UserErrorException(
69 "Failed to set the trust for this number, make sure the number and the fingerprint/safety number are correct.");
71 } catch (UnregisteredRecipientException e
) {
72 throw new UserErrorException("The user " + e
.getSender().getIdentifier() + " is not registered.");