|
4 | 4 | import com.spotify.Authentication; |
5 | 5 | import com.spotify.Keyexchange; |
6 | 6 | import com.spotify.connectstate.Connect; |
| 7 | +import okhttp3.Authenticator; |
7 | 8 | import okhttp3.*; |
8 | 9 | import org.apache.log4j.Logger; |
9 | 10 | import org.jetbrains.annotations.NotNull; |
|
31 | 32 | import javax.crypto.spec.SecretKeySpec; |
32 | 33 | import java.io.*; |
33 | 34 | import java.math.BigInteger; |
34 | | -import java.net.InetSocketAddress; |
35 | | -import java.net.Proxy; |
36 | | -import java.net.Socket; |
37 | | -import java.net.SocketTimeoutException; |
| 35 | +import java.net.*; |
38 | 36 | import java.nio.ByteBuffer; |
39 | 37 | import java.security.*; |
40 | 38 | import java.security.spec.RSAPublicKeySpec; |
@@ -865,6 +863,21 @@ static ConnectionHolder create(@NotNull String addr, @NotNull ProxyConfiguration |
865 | 863 | LOGGER.info("Successfully connected to the HTTP proxy."); |
866 | 864 | return new ConnectionHolder(sock); |
867 | 865 | case SOCKS: |
| 866 | + if (conf.proxyAuth()) { |
| 867 | + java.net.Authenticator.setDefault(new java.net.Authenticator() { |
| 868 | + final String username = conf.proxyUsername(); |
| 869 | + final String password = conf.proxyPassword(); |
| 870 | + |
| 871 | + @Override |
| 872 | + protected PasswordAuthentication getPasswordAuthentication() { |
| 873 | + if (Objects.equals(getRequestingProtocol(), "SOCKS5") && Objects.equals(getRequestingPrompt(), "SOCKS authentication")) |
| 874 | + return new PasswordAuthentication(username, password.toCharArray()); |
| 875 | + |
| 876 | + return super.getPasswordAuthentication(); |
| 877 | + } |
| 878 | + }); |
| 879 | + } |
| 880 | + |
868 | 881 | Proxy proxy = new Proxy(conf.proxyType(), new InetSocketAddress(conf.proxyAddress(), conf.proxyPort())); |
869 | 882 | Socket proxySocket = new Socket(proxy); |
870 | 883 | proxySocket.connect(new InetSocketAddress(apAddr, apPort)); |
|
0 commit comments