-
Notifications
You must be signed in to change notification settings - Fork 9.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTPS proxy is not supported #3787
Comments
HTTPS proxies are not supported. I don't think this is a thing. Got a spec for this? |
Yes, there are companies using HTTPS proxies. In these environments, this is quite a vital requirement. |
Wow, I've never heard of that. Got a spec? Typically we just follow RFC 2817. |
Honestly I don't know if there is a spec and I am not sure where to find it. Here you can find how to set up squid for doing this: http://www.squid-cache.org/Doc/config/https_port/ (of course there are many other proxies supporting this, it is just an example). |
@mgaido91 in that example Squid is not acting as a proxy from the client’s perspective. Try doing the same thing but without a proxy configured. |
Here what's happening:
OKHttp3.9.1,I watch the source code and debug it,I found the
it's worked |
@swankjesse what do you mean that it is not acting like a proxy? It is and this is confirmed by the curl command working fine. |
Can you find the spec that curl is following? I don't doubt that curl can do something here but we don't use curl as a spec and this behavior is new to me. What do Chrome and Firefox do? |
@swankjesse both Chrome and Firefox support it. Here I found an article about Chromium support (https://www.chromium.org/developers/design-documents/secure-web-proxy). Actually it is often referred as SSL proxy (Firefox terminology) or Secure Web Proxy (OSX terminology). I have not been able to find any specification and I don't think that there can be, since there is nothing to specify: it is simply an implementation of a HTTP proxy using SSL. You already found the curl PR for it, so I am not sending you the commit which implements it in curl. As you can see with a quick search with the keywords "SSL Proxy" the support is widely spread. |
@swankjesse anyway here there is a description of a proxy authentication using a SSL proxy: https://tools.ietf.org/html/draft-loreto-httpbis-trusted-proxy20-01#section-3. This shows that IETF considers this use case as valid. |
Got it. Seems like a thing we can do. How do we know whether the caller wants TLS with their proxy connection? At least for now the easiest way to get this working for yourself is to provide your own socket factory. That will have to do the TLS handshake when connecting the proxy. |
I think that the easiest way is to slightly change the .proxy method accepting an enum telling the kind of proxy (HTTP, HTTPS, SOCKS or NONE) and the InetSocketAddress of the proxy. In this way when you create the socket you know how to create it. What do you think? |
We’ve got something similar from Java but it also doesn't know about TLS to the proxy. In the interim I recommend doing it yourself with a socket factory. |
Thanks for the suggestion. Do you mean passing a socket factory to the OkHttpClient.Builder? May I kindly ask you to show me a fast example? Thank you very much for your answers and your time. |
This might lead you in the right direction:
In practice there’s a bunch more work due to features like ALPN and SNI, and having to verify that the proxy server you connect to is the one who’s certificate chain is trusted. |
I find the same problem now ,okhttp Proxy.Type.HTTP don't support https request ,http request is fine. is any solution for this problem? |
anybody can help me ?okhttp https httpProxy |
@yeyb you can follow @swankjesse 's suggestion. You can find my implementation of his suggestion in nifi here: apache/nifi@37271e8 |
okhttp Proxy.Type.HTTP don't support https request ? follow is my code,https request don't work sslSocketFactory = HttpsUtils.setCertificates(new Buffer().writeUtf8(HttpsCert.NEW_CER_IBU).inputStream()); |
@mgaido91 how to call the method in your sample? |
which method? |
when I set cer ,call which method? |
@yeyb I don't understand your question anyway the answer to your problem is: if you want to support HTTPS proxy, use ProxyType.HTTP and set the |
@mgaido91 yes this is my problem |
I am android develper,and I don't konw how to set socketFactory to a SSLSocketFactory in your suggestion |
@mgaido91 I am a chinese ,thank you for your help!!! |
@yeyb I am not sure which is the problem you are having, but the example by @swankjesse seems very clear to me, I don't know what else to say... |
@mgaido91 ,my problem is what you say.but as you say,if I want to support HTTPS proxy, use ProxyType.HTTP and set the socketFactory to a SSLSocketFactory , how I make a socketFactory ? my code is set the SSLSocketFactoryto a SSLSocketFactory |
@mgaido91 do I need to call okhttpClient.builder..proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("host", port)))? |
@mgaido91 follow code find a problem: sslSocketFactory = HttpsUtils.setCertificates(new Buffer().writeUtf8(HttpsCert.NEW_CER_IBU).inputStream()); |
public static SSLSocketFactory setCertificates(InputStream... certificates) {
|
@swankjesse @mgaido91 see #3782 |
Is this issue still valid? With version 4.9 I could connect to a HTTPS resource via proxy. |
@lordyavin you can connect to an HTTPS origin resource via an HTTP proxy - which is the normal way to do it, the HTTP proxy becomes a dumb TCP/IP tunnel and the TLS handshake happens between the client and the origin server. This issue is about connecting to both the origin server and the proxy server over HTTPS. So the data stream ends up double encrypted - you have an encrypted stream between the client and the proxy server, and that is tunnelling an encrypted stream between the client and the origin server. It's a pretty unusual thing to want to do - all it really additionally protects is the |
@Mahoney thanks for the clarification |
Examples like #7748 show this is possible, but leaving open in case we add support cleanly. |
Is it valid to consider the spec Secure Web Proxy? If so, does anyone have a known working test server? I'm happy to add custom certificates, but want a known working base. It looks like Google cloud can enable this, but I'd like to know we agree what this means. |
What kind of issue is this?
Question. This issue tracker is not the place for questions. If you want to ask how to do
something, or to understand why something isn't working the way you expect it to, use Stack
Overflow. https://stackoverflow.com/questions/tagged/okhttp
Bug report. If you’ve found a bug, spend the time to write a failing test. Bugs with tests
get fixed. Here’s an example: https://gist.github.com/swankjesse/981fcae102f513eb13ed
Feature Request. Start by telling us what problem you’re trying to solve. Often a solution
already exists! Don’t send pull requests to implement new features without first getting our
support. Sometimes we leave features out on purpose to keep the project small.
Hello, I tried to use okhttp to connect through an https proxy, but I wasn't able to. Here is a reproduction:
works like a charm, instead:
fails with the following stacktrace:
I digged a bit into the code and I think that the issue is that here, if the proxy is HTTP, it is used
socketFactory
, while there should be an additional check whether the proxy is running HTTPS or not (and if so,sslSocketFactory
should be used instead).The text was updated successfully, but these errors were encountered: