Skip to content

Commit 7ccb0c0

Browse files
committed
Fix adding key string identities for ssh-agent
Adding string based ssh keys to an ssh-agent was broken.
1 parent f2935a5 commit 7ccb0c0

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/clj_ssh/ssh.clj

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@
8484
(keyword? arg) (name arg)
8585
:else (str arg)))
8686

87+
(def ^java.nio.charset.Charset ascii
88+
(java.nio.charset.Charset/forName "US-ASCII"))
89+
90+
(defn- ^{:tag (Class/forName "[B")} as-bytes
91+
"Return arg as a byte array. arg must be a string or a byte array."
92+
[arg]
93+
(if (string? arg)
94+
(.getBytes ^String arg ascii)
95+
arg))
96+
8797
(defn ssh-agent?
8898
"Predicate to test for an ssh-agent."
8999
[object] (instance? JSch object))
@@ -149,11 +159,13 @@
149159
identity
150160
(.addIdentity agent identity passphrase)
151161

152-
(and public-key private-key)
162+
private-key
153163
(let [^com.jcraft.jsch.IdentityRepository id-repo (id-repository)]
154164
(if (local-repo? id-repo)
155165
(.addIdentity agent name private-key public-key passphrase)
156-
(let [keypair (KeyPair/load agent private-key-path public-key-path)]
166+
(let [^KeyPair keypair
167+
(KeyPair/load
168+
agent (as-bytes private-key) (as-bytes public-key))]
157169
(when passphrase
158170
(.decrypt keypair passphrase))
159171
(.add id-repo (.forSSHAgent keypair)))))

0 commit comments

Comments
 (0)