@@ -25,7 +25,24 @@ class SslProxyTunnelEstablisher {
25
25
26
26
private static final String CRLF = "\r \n " ;
27
27
private static final String PROXY_AUTHORIZATION_HEADER = "Proxy-Authorization" ;
28
+
29
+ // Default timeout for regular connections (10 seconds)
30
+ private static final int DEFAULT_SOCKET_TIMEOUT = 10000 ;
28
31
32
+ /**
33
+ * Establishes an SSL tunnel through the proxy using the CONNECT method.
34
+ * After successful tunnel establishment, extracts the underlying socket
35
+ * for use with origin server SSL connections.
36
+ *
37
+ * @param proxyHost The proxy server hostname
38
+ * @param proxyPort The proxy server port
39
+ * @param targetHost The target server hostname
40
+ * @param targetPort The target server port
41
+ * @param sslSocketFactory SSL socket factory for proxy authentication
42
+ * @param proxyCredentialsProvider Credentials provider for proxy authentication
43
+ * @return Raw socket with tunnel established (connection maintained)
44
+ * @throws IOException if tunnel establishment fails
45
+ */
29
46
/**
30
47
* Establishes an SSL tunnel through the proxy using the CONNECT method.
31
48
* After successful tunnel establishment, extracts the underlying socket
@@ -52,14 +69,17 @@ public Socket establishTunnel(@NonNull String proxyHost,
52
69
SSLSocket sslSocket = null ;
53
70
54
71
try {
72
+ // Determine which timeout to use based on connection type
73
+ int timeout = DEFAULT_SOCKET_TIMEOUT ;
74
+
55
75
// Step 1: Create raw TCP connection to proxy
56
76
rawSocket = new Socket (proxyHost , proxyPort );
57
- rawSocket .setSoTimeout (10000 ); // 10 second timeout
77
+ rawSocket .setSoTimeout (timeout );
58
78
59
79
// Create a temporary SSL socket to establish the SSL session with proper trust validation
60
80
sslSocket = (SSLSocket ) sslSocketFactory .createSocket (rawSocket , proxyHost , proxyPort , false );
61
81
sslSocket .setUseClientMode (true );
62
- sslSocket .setSoTimeout (10000 ); // 10 second timeout
82
+ sslSocket .setSoTimeout (timeout );
63
83
64
84
// Perform SSL handshake using the SSL socket with custom CA certificates
65
85
sslSocket .startHandshake ();
@@ -108,7 +128,7 @@ public Socket establishTunnel(@NonNull String proxyHost,
108
128
private void sendConnectRequest (@ NonNull SSLSocket sslSocket ,
109
129
@ NonNull String targetHost ,
110
130
int targetPort ,
111
- @ Nullable ProxyCredentialsProvider proxyCredentialsProvider ) throws IOException {
131
+ @ Nullable BearerCredentialsProvider proxyCredentialsProvider ) throws IOException {
112
132
113
133
Logger .v ("Sending CONNECT request through SSL: CONNECT " + targetHost + ":" + targetPort + " HTTP/1.1" );
114
134
@@ -118,7 +138,7 @@ private void sendConnectRequest(@NonNull SSLSocket sslSocket,
118
138
119
139
if (proxyCredentialsProvider != null ) {
120
140
// Send Proxy-Authorization header if credentials are set
121
- String bearerToken = proxyCredentialsProvider .getBearerToken ();
141
+ String bearerToken = proxyCredentialsProvider .getToken ();
122
142
if (bearerToken != null && !bearerToken .trim ().isEmpty ()) {
123
143
writer .write (PROXY_AUTHORIZATION_HEADER + ": Bearer " + bearerToken + CRLF );
124
144
}
0 commit comments