Skip to content
This repository was archived by the owner on Jul 24, 2018. It is now read-only.

No dh keypair #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
:integration :integration
:all (constantly true)}
:aliases {"all" ["with-profile" "dev,1.2:dev,1.3:dev:1.5,dev"]}
:checksum-deps true)
:checksum-deps true
)
32 changes: 32 additions & 0 deletions src/clj_http/lite/NoDHSocketFactory.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
(ns clj-http.lite.NoDHSocketFactory
(:import (javax.net.ssl SSLSocket SSLSocketFactory)
(java.net Socket)))

(defn strip-dh-suites
"Remove cipher suites containing 'DH'"
[suites]
(into-array String (filter #(not (or (re-find #"_DHE_" %)
(re-find #"_DH_" %)
(re-find #"_ECDH_" %)
(re-find #"_ECDHE_" %))) suites)))

(defn set-cipher-suites [s sf]
(.setEnabledCipherSuites s (strip-dh-suites (.getSupportedCipherSuites sf)))
s)

(defn no-dhs-socket-factory [sf]
(proxy [SSLSocketFactory] []
(createSocket
([]
(doto (.createSocket sf)
(set-cipher-suites sf)))
([host port]
(doto (.createSocket sf host port)
(set-cipher-suites sf)))
([host port local-host local-port]
(doto (.createSocket sf host port local-host local-port)
(set-cipher-suites sf))))
(getDefaultCipherSuites []
(.getDefaultCipherSuites sf))
(getSupportedCipherSuites []
(.getSupportedCipherSuites sf))))
19 changes: 16 additions & 3 deletions src/clj_http/lite/core.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
(ns clj-http.lite.core
"Core HTTP request/response implementation."
(:require [clojure.java.io :as io])
(:require [clojure.java.io :as io]
[clj-http.lite.NoDHSocketFactory])
(:import (java.io ByteArrayOutputStream InputStream IOException)
(java.net URI URL HttpURLConnection)))
(java.net URI URL HttpURLConnection)
(javax.net.ssl HttpsURLConnection)))

(defn parse-headers
"Takes a URLConnection and returns a map of names to values.
Expand Down Expand Up @@ -39,6 +41,17 @@
(.flush baos)
(.toByteArray baos)))))

(defn- get-connection [^URL url]
"Wrap .openConnection to "
(let [conn (.openConnection url)]
(if (instance? HttpsURLConnection conn)
(doto conn
(.setSSLSocketFactory
(clj-http.lite.NoDHSocketFactory/no-dhs-socket-factory
(.getSSLSocketFactory conn))))
conn)))


(defn request
"Executes the HTTP request corresponding to the given Ring request map and
returns the Ring response map corresponding to the resulting HTTP response.
Expand All @@ -52,7 +65,7 @@
(when server-port (str ":" server-port))
uri
(when query-string (str "?" query-string)))
conn (.openConnection ^URL (URL. http-url))]
conn (get-connection ^URL (URL. http-url))]
(when (and content-type character-encoding)
(.setRequestProperty conn "Content-Type" (str content-type
"; charset="
Expand Down