Move proxy parsing to lib

This commit is contained in:
AsamK committed 2026-11-07 12:33:44 +01:00
1 parent 9d081e5080
commit 7442d8af4f
3 files changed
+15 -30

No files matched your search

@@ -2,7 +2,7 @@ package org.asamk.signal.manager;
import org.asamk.signal.manager.api.TrustNewIdentity;
public record Settings(TrustNewIdentity trustNewIdentity, boolean disableMessageSendLog) {
public record Settings(TrustNewIdentity trustNewIdentity, boolean disableMessageSendLog, String tlsProxy) {
public static final Settings DEFAULT = new Settings(TrustNewIdentity.ON_FIRST_USE, false);
public static final Settings DEFAULT = new Settings(TrustNewIdentity.ON_FIRST_USE, false, null);
}
@@ -46,26 +46,19 @@ public class SignalAccountFiles {
final ServiceEnvironment serviceEnvironment,
final String userAgent,
final Settings settings
) throws IOException {
this(settingsPath, serviceEnvironment, userAgent, settings, Optional.empty());
}
/**
* @param tlsProxy a Signal TLS proxy, as used by the official Signal apps, through which all connections to
* the Signal servers are made.
*/
public SignalAccountFiles(
final File settingsPath,
final ServiceEnvironment serviceEnvironment,
final String userAgent,
final Settings settings,
final Optional<TlsProxy> tlsProxy
) throws IOException {
) throws IOException, TlsProxy.InvalidTlsProxyException {
this.pathConfig = PathConfig.createDefault(settingsPath);
this.serviceEnvironment = serviceEnvironment;
final Optional<SignalProxy> signalProxy;
if (settings.tlsProxy() == null) {
signalProxy = Optional.empty();
} else {
final var proxy = TlsProxy.parse(settings.tlsProxy());
signalProxy = Optional.of(new SignalProxy(proxy.host(), proxy.port()));
}
this.serviceEnvironmentConfig = ServiceConfig.getServiceEnvironmentConfig(this.serviceEnvironment,
userAgent,
tlsProxy.map(proxy -> new SignalProxy(proxy.host(), proxy.port())));
signalProxy);
this.userAgent = userAgent;
this.settings = settings;
this.accountsStore = new AccountsStore(pathConfig.dataPath(), serviceEnvironment, accountPath -> {
+4 -12
View File
@@ -36,7 +36,6 @@ import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Optional;
import java.util.Set;
import static net.sourceforge.argparse4j.DefaultSettings.VERSION_0_9_0_DEFAULT_SETTINGS;
@@ -265,22 +264,15 @@ public class App {
final var disableSendLog = Boolean.TRUE.equals(ns.getBoolean("disable-send-log"));
final var tlsProxyArgument = ns.getString("tls-proxy");
TlsProxy tlsProxy = null;
if (tlsProxyArgument != null) {
try {
tlsProxy = TlsProxy.parse(tlsProxyArgument);
} catch (TlsProxy.InvalidTlsProxyException e) {
throw new UserErrorException(e.getMessage(), e);
}
}
final var tlsProxy = ns.getString("tls-proxy");
try {
return new SignalAccountFiles(dataPath,
serviceEnvironment,
BaseConfig.USER_AGENT,
new Settings(trustNewIdentity, disableSendLog),
Optional.ofNullable(tlsProxy));
new Settings(trustNewIdentity, disableSendLog, tlsProxy));
} catch (TlsProxy.InvalidTlsProxyException e) {
throw new UserErrorException(e.getMessage(), e);
} catch (IOException e) {
throw new IOErrorException("Failed to read local accounts list", e);
}