2 Copyright (C) 2015-2021 AsamK and contributors
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org
.asamk
.signal
;
19 import net
.sourceforge
.argparse4j
.ArgumentParsers
;
20 import net
.sourceforge
.argparse4j
.impl
.Arguments
;
21 import net
.sourceforge
.argparse4j
.inf
.ArgumentParserException
;
22 import net
.sourceforge
.argparse4j
.inf
.Namespace
;
24 import org
.asamk
.signal
.commands
.exceptions
.CommandException
;
25 import org
.asamk
.signal
.commands
.exceptions
.IOErrorException
;
26 import org
.asamk
.signal
.commands
.exceptions
.UnexpectedErrorException
;
27 import org
.asamk
.signal
.commands
.exceptions
.UntrustedKeyErrorException
;
28 import org
.asamk
.signal
.commands
.exceptions
.UserErrorException
;
29 import org
.asamk
.signal
.manager
.LibSignalLogger
;
30 import org
.asamk
.signal
.util
.SecurityProvider
;
31 import org
.bouncycastle
.jce
.provider
.BouncyCastleProvider
;
33 import java
.security
.Security
;
37 public static void main(String
[] args
) {
38 // enable unlimited strength crypto via Policy, supported on relevant JREs
39 Security
.setProperty("crypto.policy", "unlimited");
40 installSecurityProviderWorkaround();
42 // Configuring the logger needs to happen before any logger is initialized
43 configureLogging(isVerbose(args
));
45 var parser
= App
.buildArgumentParser();
47 var ns
= parser
.parseArgsOrFail(args
);
52 } catch (CommandException e
) {
53 System
.err
.println(e
.getMessage());
54 status
= getStatusForError(e
);
59 private static void installSecurityProviderWorkaround() {
60 // Register our own security provider
61 Security
.insertProviderAt(new SecurityProvider(), 1);
62 Security
.addProvider(new BouncyCastleProvider());
65 private static boolean isVerbose(String
[] args
) {
66 var parser
= ArgumentParsers
.newFor("signal-cli").build().defaultHelp(false);
67 parser
.addArgument("--verbose").action(Arguments
.storeTrue());
71 ns
= parser
.parseKnownArgs(args
, null);
72 } catch (ArgumentParserException e
) {
76 return ns
.getBoolean("verbose");
79 private static void configureLogging(final boolean verbose
) {
81 System
.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "debug");
82 System
.setProperty("org.slf4j.simpleLogger.showThreadName", "true");
83 System
.setProperty("org.slf4j.simpleLogger.showShortLogName", "false");
84 System
.setProperty("org.slf4j.simpleLogger.showDateTime", "true");
85 System
.setProperty("org.slf4j.simpleLogger.dateTimeFormat", "yyyy-MM-dd'T'HH:mm:ss.SSSXX");
86 LibSignalLogger
.initLogger();
88 System
.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info");
89 System
.setProperty("org.slf4j.simpleLogger.showThreadName", "false");
90 System
.setProperty("org.slf4j.simpleLogger.showShortLogName", "true");
91 System
.setProperty("org.slf4j.simpleLogger.showDateTime", "false");
95 private static int getStatusForError(final CommandException e
) {
96 if (e
instanceof UserErrorException
) {
98 } else if (e
instanceof UnexpectedErrorException
) {
100 } else if (e
instanceof IOErrorException
) {
102 } else if (e
instanceof UntrustedKeyErrorException
) {