Conditionally disable strict-host-key-checking

This commit is contained in:
Antonio Andelic 2022-09-28 11:22:41 +00:00
parent c68ef2ff7f
commit 7265b47932

View File

@ -15,10 +15,14 @@
(connect [this conn-spec]
(if (:dummy conn-spec)
(assoc this :conn-spec conn-spec)
(try+ (let [c (doto (SSHClient. (doto (DefaultConfig.) (.setVerifyHostKeyCertificates false)))
(.addHostKeyVerifier (PromiscuousVerifier.))
(.connect (:host conn-spec) (:port conn-spec))
(auth! conn-spec))]
(try+ (let [c (as-> (SSHClient.) client
(do
(if (:strict-host-key-checking conn-spec)
(.loadKnownHosts client)
(.addHostKeyVerifier client (PromiscuousVerifier.)))
(.connect client (:host conn-spec) (:port conn-spec))
(auth! client conn-spec)
client))]
(assoc this
:conn-spec conn-spec
:client c