]>
nmode's Git Repositories - signal-cli/blob - src/main/java/org/asamk/signal/commands/TrustCommand.java
d6debf86d4feb22522c5a5c85df9c3cfb82624b6
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
.addArgument("number").help("Specify the phone number, for which to set the trust.").required(true);
20 var mutTrust
= subparser
.addMutuallyExclusiveGroup();
21 mutTrust
.addArgument("-a", "--trust-all-known-keys")
22 .help("Trust all known keys of this user, only use this for testing.")
23 .action(Arguments
.storeTrue());
24 mutTrust
.addArgument("-v", "--verified-safety-number", "--verified-fingerprint")
25 .help("Specify the safety number of the key, only use this option if you have verified the safety number.");
29 public void handleCommand(final Namespace ns
, final Manager m
) throws CommandException
{
30 var number
= ns
.getString("number");
31 if (ns
.getBoolean("trust-all-known-keys")) {
34 res
= m
.trustIdentityAllKeys(number
);
35 } catch (InvalidNumberException e
) {
36 throw new UserErrorException("Failed to parse recipient: " + e
.getMessage());
39 throw new UserErrorException("Failed to set the trust for this number, make sure the number is correct.");
42 var safetyNumber
= ns
.getString("verified-safety-number");
43 if (safetyNumber
!= null) {
44 safetyNumber
= safetyNumber
.replaceAll(" ", "");
45 if (safetyNumber
.length() == 66) {
46 byte[] fingerprintBytes
;
48 fingerprintBytes
= Hex
.toByteArray(safetyNumber
.toLowerCase(Locale
.ROOT
));
49 } catch (Exception e
) {
50 throw new UserErrorException(
51 "Failed to parse the fingerprint, make sure the fingerprint is a correctly encoded hex string without additional characters.");
55 res
= m
.trustIdentityVerified(number
, fingerprintBytes
);
56 } catch (InvalidNumberException e
) {
57 throw new UserErrorException("Failed to parse recipient: " + e
.getMessage());
60 throw new UserErrorException(
61 "Failed to set the trust for the fingerprint of this number, make sure the number and the fingerprint are correct.");
63 } else if (safetyNumber
.length() == 60) {
66 res
= m
.trustIdentityVerifiedSafetyNumber(number
, safetyNumber
);
67 } catch (InvalidNumberException e
) {
68 throw new UserErrorException("Failed to parse recipient: " + e
.getMessage());
71 throw new UserErrorException(
72 "Failed to set the trust for the safety number of this phone number, make sure the phone number and the safety number are correct.");
75 throw new UserErrorException(
76 "Safety number has invalid format, either specify the old hex fingerprint or the new safety number");
79 throw new UserErrorException(
80 "You need to specify the fingerprint/safety number you have verified with -v SAFETY_NUMBER");