You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried to configure okhttp (v 4.10.0) to make a GET request to an url through an https proxy that use a self-signed certificate.
I saw these issues: #6561 and #3787 that are quite similar exept that they do not address the case where you want to disable the certificate verification during the SSL handshake with the https proxy (because in my case, the proxy is using a self-signed certificate, that may change quite frequently. So requiering to have it downloaded in a client keystore is not a practical option).
Here is the code that I currently have (which is basically the same as the one from @lpuglia in #6561 with just a TrustManager that will accept all server's certificates added) :
String desturl = "https://api64.ipify.org/?format=json"; //"https://myip.com" //"http://neverssl.com" //"http://silverfinebeautifulsecret.neverssl.com/online/"
OkHttpClient.Builder clientb = new OkHttpClient.Builder().proxy(new java.net.Proxy(java.net.Proxy.Type.HTTP, new InetSocketAddress("shoutouttomyex.icu", 443))) ;
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException { System.out.println("checkClientTrusted"); return;}
@Override public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException { System.out.println("checkServerTrusted"); return;}
@Override public java.security.cert.X509Certificate[] getAcceptedIssuers() { System.out.println("getAcceptedIssuers"); return new java.security.cert.X509Certificate[]{}; }
} };
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
clientb.socketFactory(new DelegatingSocketFactory(sslSocketFactory));
clientb.hostnameVerifier(new HostnameVerifier() {
@Override public boolean verify(String hostname, SSLSession session) { System.out.println("Verify "+hostname); return true; }
});
okhttp3.Request.Builder rbuilder = new Request.Builder().url(desturl).get();
Response response = clientb.build().newCall(rbuilder.build()).execute();
System.out.println("Answer: "+response.body().string());
(Note: I don't need any Authenticator as my https proxy is an opened proxy to which you can connect without any username and password)
the problem is that when requesting an https url with this code, I systematically get an answer with a 404 error. Here is the output that I have:
checkServerTrusted
getAcceptedIssuers
java.io.IOException: Unexpected response code for CONNECT: 404
at [email protected]/okhttp3.internal.connection.RealConnection.createTunnel(RealConnection.kt:483)
at [email protected]/okhttp3.internal.connection.RealConnection.connectTunnel(RealConnection.kt:262)
at [email protected]/okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:201)
at [email protected]/okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:226)
at [email protected]/okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106)
at [email protected]/okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74)
at [email protected]/okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:255)
at [email protected]/okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
at [email protected]/okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at [email protected]/okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
at [email protected]/okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at [email protected]/okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
at [email protected]/okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at [email protected]/okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
at [email protected]/okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at [email protected]/okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
at [email protected]/okhttp3.internal.connection.RealCall.execute(RealCall.kt:154)
and if I request an http url (like http://silverfinebeautifulsecret.neverssl.com/online/) I don't have any error but I get an empty answer (which is also a bug as I should receive the page body). Here is the output with an http destination url:
checkServerTrusted
getAcceptedIssuers
Answer:
The same chain of request (requesting an url through my https proxy with proxy's certificate verification disabled) is working just fine with curl.
Here is the output that I get with this curl command : curl -x https://shoutouttomyex.icu:443 https://api64.ipify.org/?format=json --proxy-insecure -v :
I tried to configure okhttp (v
4.10.0
) to make a GET request to an url through an https proxy that use a self-signed certificate.I saw these issues: #6561 and #3787 that are quite similar exept that they do not address the case where you want to disable the certificate verification during the SSL handshake with the https proxy (because in my case, the proxy is using a self-signed certificate, that may change quite frequently. So requiering to have it downloaded in a client keystore is not a practical option).
Here is the code that I currently have (which is basically the same as the one from @lpuglia in #6561 with just a TrustManager that will accept all server's certificates added) :
(Note: I don't need any Authenticator as my https proxy is an opened proxy to which you can connect without any username and password)
the problem is that when requesting an https url with this code, I systematically get an answer with a 404 error. Here is the output that I have:
and if I request an http url (like
http://silverfinebeautifulsecret.neverssl.com/online/
) I don't have any error but I get an empty answer (which is also a bug as I should receive the page body). Here is the output with an http destination url:The same chain of request (requesting an url through my https proxy with proxy's certificate verification disabled) is working just fine with curl.
Here is the output that I get with this curl command :
curl -x https://shoutouttomyex.icu:443 https://api64.ipify.org/?format=json --proxy-insecure -v
:The text was updated successfully, but these errors were encountered: