Skip to content
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

Allow NoopHostNameVerifier to be set for SOCKS Proxy #647

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/clj_http/conn_mgr.clj
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@
"Given a function that returns a new socket, create an
SSLConnectionSocketFactory that will use that socket."
([socket-factory]
(SSLGenericSocketFactory socket-factory nil))
([socket-factory ^SSLContext ssl-context]
(let [^SSLContext ssl-context' (or ssl-context (SSLContexts/createDefault))]
(proxy [SSLConnectionSocketFactory] [ssl-context']
(SSLGenericSocketFactory socket-factory nil nil))
([socket-factory ^SSLContext ssl-context ^HostnameVerifier hostname-verifier]
(let [^SSLContext ssl-context' (or ssl-context (SSLContexts/createDefault))
^HostnameVerifier hostname-verifier' (or hostname-verifier (DefaultHostnameVerifier.))]
(proxy [SSLConnectionSocketFactory] [ssl-context' hostname-verifier']
(connectSocket [timeout socket host remoteAddress localAddress context]
(let [^SSLConnectionSocketFactory this this] ;; avoid reflection
(proxy-super connectSocket timeout (socket-factory) host remoteAddress
Expand Down Expand Up @@ -114,7 +115,7 @@
[]
(-> (SSLContexts/custom)
(.loadTrustMaterial nil (reify TrustStrategy
(isTrusted [_ chain auth-type] true)))
(isTrusted [_ chain auth-type] true)))
(.build)))

(defn ^SSLContext get-ssl-context
Expand Down Expand Up @@ -150,7 +151,7 @@
(let [socket-factory #(socks-proxied-socket hostname port)
registry (into-registry
{"http" (PlainGenericSocketFactory socket-factory)
"https" (SSLGenericSocketFactory socket-factory (get-ssl-context config))})]
"https" (SSLGenericSocketFactory socket-factory (get-ssl-context config) (get-hostname-verifier config))})]
(PoolingHttpClientConnectionManager. registry))))

(defn ^BasicHttpClientConnectionManager make-regular-conn-manager
Expand Down
Loading