Add system HTTP proxy support to libsignal-net.

Co-authored-by: Cody Henthorne <cody@signal.org>
This commit is contained in:
andrew-signal
2025-04-11 18:58:07 -05:00
committed by Cody Henthorne
parent 8e880fe117
commit 74c6e76808
8 changed files with 101 additions and 18 deletions

View File

@@ -0,0 +1,6 @@
package org.whispersystems.signalservice.internal.configuration
/**
* HTTP Proxy configuration from Android OS configuration.
*/
class HttpProxy(val host: String, val port: Int)

View File

@@ -17,6 +17,7 @@ data class SignalServiceConfiguration(
val networkInterceptors: List<Interceptor>,
val dns: Optional<Dns>,
val signalProxy: Optional<SignalProxy>,
val systemHttpProxy: Optional<HttpProxy>,
val zkGroupServerPublicParams: ByteArray,
val genericServerPublicParams: ByteArray,
val backupServerPublicParams: ByteArray,

View File

@@ -30,16 +30,27 @@ fun Network.transformAndSetRemoteConfig(remoteConfig: Map<String, Any>) {
* Helper method to apply settings from the SignalServiceConfiguration.
*/
fun Network.applyConfiguration(config: SignalServiceConfiguration) {
val proxy = config.signalProxy.orNull()
val signalProxy = config.signalProxy.orNull()
val systemHttpProxy = config.systemHttpProxy.orNull()
if (proxy == null) {
this.clearProxy()
} else {
try {
this.setProxy(proxy.host, proxy.port)
} catch (e: IOException) {
Log.e(TAG, "Invalid proxy configuration set! Failing connections until changed.")
this.setInvalidProxy()
when {
(signalProxy != null) -> {
try {
this.setProxy(signalProxy.host, signalProxy.port)
} catch (e: IOException) {
Log.e(TAG, "Invalid proxy configuration set! Failing connections until changed.")
this.setInvalidProxy()
}
}
(systemHttpProxy != null) -> {
try {
this.setProxy("http", systemHttpProxy.host, systemHttpProxy.port, "", "")
} catch (e: IOException) {
// The Android settings screen where this is set explicitly calls out that apps are allowed to
// ignore the HTTP Proxy setting, so if using the specified proxy would cause us to break, let's
// try just ignoring it and seeing if that still lets us connect.
Log.w(TAG, "Failed to set system HTTP proxy, ignoring and continuing...")
}
}
}