Skip to content

Commit e5cfba6

Browse files
committed
Merge branch 'pr/213'
2 parents 0b98a87 + 0db041e commit e5cfba6

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

README.org

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,9 @@ used:
462462
:trust-store-pass "trustpass"})
463463
#+END_SRC
464464

465+
The =:keystore/:trust-store= values may be either paths to keystore
466+
files or =KeyStore= instances.
467+
465468
** Cookie stores
466469

467470
clj-http can simplify the maintenance of cookies across requests if it is

src/clj_http/client.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,9 +833,9 @@
833833
:insecure? - Boolean flag to specify allowing insecure HTTPS connections
834834
default: false
835835
836-
:keystore - keystore file to be used for connection manager
836+
:keystore - keystore file path or KeyStore instance to be used for connection manager
837837
:keystore-pass - keystore password
838-
:trust-store - trust store file to be used for connection manager
838+
:trust-store - trust store file path or KeyStore instance to be used for connection manager
839839
:trust-store-pass - trust store password
840840
841841
Note that :insecure? and :keystore/:trust-store options are mutually exclusive

src/clj_http/conn_mgr.clj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,21 @@
9191
(.register (Scheme. "http" 80 (PlainSocketFactory/getSocketFactory)))
9292
(.register (Scheme. "https" 443 (SSLSocketFactory/getSocketFactory)))))
9393

94-
(defn ^KeyStore get-keystore [keystore-file keystore-type ^String keystore-pass]
94+
(defn ^KeyStore get-keystore* [keystore-file keystore-type ^String keystore-pass]
9595
(when keystore-file
9696
(let [keystore (KeyStore/getInstance (or keystore-type
9797
(KeyStore/getDefaultType)))]
9898
(with-open [is (io/input-stream keystore-file)]
9999
(.load keystore is (when keystore-pass (.toCharArray keystore-pass)))
100100
keystore))))
101101

102+
(defn ^KeyStore get-keystore [keystore & args]
103+
(if (instance? KeyStore keystore)
104+
keystore
105+
(apply get-keystore* keystore args)))
106+
102107
(defn ^SchemeRegistry get-keystore-scheme-registry
103-
[{:keys [keystore keystore-type keystore-pass
108+
[{:keys [keystore keystore-type keystore-pass keystore-instance
104109
trust-store trust-store-type trust-store-pass]
105110
:as req}]
106111
(let [ks (get-keystore keystore keystore-type keystore-pass)

test/clj_http/test/conn_mgr.clj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
(is (instance? KeyStore ks))
2727
(is (> (.size ks) 0))))
2828

29+
(deftest use-existing-keystore
30+
(let [ks (conn-mgr/get-keystore "test-resources/keystore" nil "keykey")
31+
ks (conn-mgr/get-keystore ks nil nil)]
32+
(is (instance? KeyStore ks))
33+
(is (> (.size ks) 0))))
34+
2935
(deftest load-keystore-with-nil-pass
3036
(let [ks (conn-mgr/get-keystore "test-resources/keystore" nil nil)]
3137
(is (instance? KeyStore ks))))

0 commit comments

Comments
 (0)