]>
nmode's Git Repositories - signal-cli/blob - src/main/java/org/asamk/signal/commands/TrustCommand.java
7f303dbb3034a6df73ed9581b731a9c1126d79b1
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
.util
.Hex
;
11 import org
.whispersystems
.signalservice
.api
.util
.InvalidNumberException
;
13 import java
.util
.Locale
;
15 public class TrustCommand
implements LocalCommand
{
18 public void attachToSubparser(final Subparser subparser
) {
19 subparser
.help("Set the trust level of a given number.");
20 subparser
.addArgument("number").help("Specify the phone number, for which to set the trust.").required(true);
21 var mutTrust
= subparser
.addMutuallyExclusiveGroup();
22 mutTrust
.addArgument("-a", "--trust-all-known-keys")
23 .help("Trust all known keys of this user, only use this for testing.")
24 .action(Arguments
.storeTrue());
25 mutTrust
.addArgument("-v", "--verified-safety-number", "--verified-fingerprint")
26 .help("Specify the safety number of the key, only use this option if you have verified the safety number.");
30 public void handleCommand(final Namespace ns
, final Manager m
) throws CommandException
{
31 var number
= ns
.getString("number");
32 if (ns
.getBoolean("trust-all-known-keys")) {
35 res
= m
.trustIdentityAllKeys(number
);
36 } catch (InvalidNumberException e
) {
37 throw new UserErrorException("Failed to parse recipient: " + e
.getMessage());
40 throw new UserErrorException("Failed to set the trust for this number, make sure the number is correct.");
43 var safetyNumber
= ns
.getString("verified-safety-number");
44 if (safetyNumber
!= null) {
45 safetyNumber
= safetyNumber
.replaceAll(" ", "");
46 if (safetyNumber
.length() == 66) {
47 byte[] fingerprintBytes
;
49 fingerprintBytes
= Hex
.toByteArray(safetyNumber
.toLowerCase(Locale
.ROOT
));
50 } catch (Exception e
) {
51 throw new UserErrorException(
52 "Failed to parse the fingerprint, make sure the fingerprint is a correctly encoded hex string without additional characters.");
56 res
= m
.trustIdentityVerified(number
, fingerprintBytes
);
57 } catch (InvalidNumberException e
) {
58 throw new UserErrorException("Failed to parse recipient: " + e
.getMessage());
61 throw new UserErrorException(
62 "Failed to set the trust for the fingerprint of this number, make sure the number and the fingerprint are correct.");
64 } else if (safetyNumber
.length() == 60) {
67 res
= m
.trustIdentityVerifiedSafetyNumber(number
, safetyNumber
);
68 } catch (InvalidNumberException e
) {
69 throw new UserErrorException("Failed to parse recipient: " + e
.getMessage());
72 throw new UserErrorException(
73 "Failed to set the trust for the safety number of this phone number, make sure the phone number and the safety number are correct.");
76 throw new UserErrorException(
77 "Safety number has invalid format, either specify the old hex fingerprint or the new safety number");
80 throw new UserErrorException(
81 "You need to specify the fingerprint/safety number you have verified with -v SAFETY_NUMBER");