From d05ed0a56c60e4c49d4160b15a30ab713653b55a Mon Sep 17 00:00:00 2001 From: AeonLucid Date: Sun, 28 Jul 2024 21:57:17 +0200 Subject: [PATCH] Fix SOCKS5 authentication by setting a default Authenticator (#988) * Fix SOCKS5 authentication by setting a default Authenticator * Fix lint --- .../suwayomi/tachidesk/server/ServerSetup.kt | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt index c3eada5b..5874083d 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt @@ -46,6 +46,8 @@ import xyz.nulldev.ts.config.GlobalConfigManager import xyz.nulldev.ts.config.initLoggerConfig import xyz.nulldev.ts.config.setLogLevelFor import java.io.File +import java.net.Authenticator +import java.net.PasswordAuthentication import java.security.Security import java.util.Locale @@ -265,20 +267,23 @@ fun applicationSetup() { System.setProperty("socksProxyPort", proxyPort) System.setProperty("socksProxyVersion", proxyVersion.toString()) - if (proxyUsername.isNotBlank()) { - System.setProperty("java.net.socks.username", proxyUsername) - } else { - System.clearProperty("java.net.socks.username") - } - if (proxyPassword.isNotBlank()) { - System.setProperty("java.net.socks.password", proxyPassword) - } else { - System.clearProperty("java.net.socks.password") - } + Authenticator.setDefault( + object : Authenticator() { + override fun getPasswordAuthentication(): PasswordAuthentication? { + if (requestingProtocol.startsWith("SOCKS", ignoreCase = true)) { + return PasswordAuthentication(proxyUsername, proxyPassword.toCharArray()) + } + + return null + } + }, + ) } else { System.clearProperty("socksProxyHost") System.clearProperty("socksProxyPort") System.clearProperty("socksProxyVersion") + + Authenticator.setDefault(null) } }, ignoreInitialValue = false,