Skip to content

Commit 6375dac

Browse files
committed
Allow NoopHostNameVerifier to be set for SOCKS Proxy
It's useful, during testing, when using a SOCKS Proxy, to allow the HostnameVerifier to be set to a NoopHostNameVerifier - similar to how *non SOCKS proxy* connections allow this to be done. This change allows a NoopHostNameVerifier to be used if the key `:insecure` (or `:insecure?`) is set `true` in the config settings during `make-socks-proxied-conn-manager`. -=david=-
1 parent b8e4947 commit 6375dac

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/clj_http/conn_mgr.clj

+7-6
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@
3737
"Given a function that returns a new socket, create an
3838
SSLConnectionSocketFactory that will use that socket."
3939
([socket-factory]
40-
(SSLGenericSocketFactory socket-factory nil))
41-
([socket-factory ^SSLContext ssl-context]
42-
(let [^SSLContext ssl-context' (or ssl-context (SSLContexts/createDefault))]
43-
(proxy [SSLConnectionSocketFactory] [ssl-context']
40+
(SSLGenericSocketFactory socket-factory nil nil))
41+
([socket-factory ^SSLContext ssl-context ^HostnameVerifier hostname-verifier]
42+
(let [^SSLContext ssl-context' (or ssl-context (SSLContexts/createDefault))
43+
^HostnameVerifier hostname-verifier' (or hostname-verifier (DefaultHostnameVerifier.))]
44+
(proxy [SSLConnectionSocketFactory] [ssl-context' hostname-verifier']
4445
(connectSocket [timeout socket host remoteAddress localAddress context]
4546
(let [^SSLConnectionSocketFactory this this] ;; avoid reflection
4647
(proxy-super connectSocket timeout (socket-factory) host remoteAddress
@@ -114,7 +115,7 @@
114115
[]
115116
(-> (SSLContexts/custom)
116117
(.loadTrustMaterial nil (reify TrustStrategy
117-
(isTrusted [_ chain auth-type] true)))
118+
(isTrusted [_ chain auth-type] true)))
118119
(.build)))
119120

120121
(defn ^SSLContext get-ssl-context
@@ -150,7 +151,7 @@
150151
(let [socket-factory #(socks-proxied-socket hostname port)
151152
registry (into-registry
152153
{"http" (PlainGenericSocketFactory socket-factory)
153-
"https" (SSLGenericSocketFactory socket-factory (get-ssl-context config))})]
154+
"https" (SSLGenericSocketFactory socket-factory (get-ssl-context config) (get-hostname-verifier config))})]
154155
(PoolingHttpClientConnectionManager. registry))))
155156

156157
(defn ^BasicHttpClientConnectionManager make-regular-conn-manager

0 commit comments

Comments
 (0)