File tree Expand file tree Collapse file tree 4 files changed +63
-2
lines changed Expand file tree Collapse file tree 4 files changed +63
-2
lines changed Original file line number Diff line number Diff line change 97
97
<dependency >
98
98
<groupId >com.jcraft</groupId >
99
99
<artifactId >jsch</artifactId >
100
- <version >0.1.44-1</version >
100
+ <version >${jsch.version} </version >
101
+ </dependency >
102
+ <dependency >
103
+ <groupId >jsch-agent-proxy</groupId >
104
+ <artifactId >jsch-agent-proxy</artifactId >
105
+ <version >0.0.4-SNAPSHOT</version >
101
106
</dependency >
102
107
<dependency >
103
108
<groupId >log4j</groupId >
149
154
<project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
150
155
<clojure .version>1.2.0</clojure .version>
151
156
<slingshot .version>0.2.0</slingshot .version>
157
+ <jsch .version>0.1.48</jsch .version>
152
158
</properties >
153
159
</project >
Original file line number Diff line number Diff line change
1
+ (ns clj-ssh.agent
2
+ " Agent integration (using jsch-agent-proxy)"
3
+ (:require
4
+ [clojure.tools.logging :as logging])
5
+ (:import
6
+ com.jcraft.jsch.JSch
7
+ [com.jcraft.jsch.agentproxy
8
+ AgentProxyException Connector RemoteIdentityRepository]
9
+ [com.jcraft.jsch.agentproxy.connector
10
+ PageantConnector SSHAgentConnector]
11
+ com.jcraft.jsch.agentproxy.usocket.JNAUSocketFactory))
12
+
13
+ (defn sock-agent-connector
14
+ []
15
+ (when (SSHAgentConnector/isConnectorAvailable )
16
+ (try
17
+ (let [usf (JNAUSocketFactory. )]
18
+ (SSHAgentConnector. usf))
19
+ (catch AgentProxyException e
20
+ (logging/warnf
21
+ e " Failed to load JNA connector, although SSH_AUTH_SOCK is set" )))))
22
+
23
+ (defn pageant-connector
24
+ []
25
+ (when (PageantConnector/isConnectorAvailable )
26
+ (try
27
+ (PageantConnector. )
28
+ (catch AgentProxyException e
29
+ (logging/warn
30
+ e " Failed to load Pageant connector, although running on windows" )))))
31
+
32
+ (defn connect
33
+ " Connect the specified jsch object to the system ssh-agent."
34
+ [^JSch jsch]
35
+ (when-let [connector (or (sock-agent-connector ) (pageant-connector ))]
36
+ (doto jsch
37
+ ; (.setConfig "PreferredAuthentications" "publickey")
38
+ (.setIdentityRepository (RemoteIdentityRepository. connector)))))
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ Leiningen (http://github.com/technomancy/leiningen).
38
38
39
39
Licensed under EPL (http://www.eclipse.org/legal/epl-v10.html)"
40
40
(:require
41
+ [clj-ssh.agent :as agent]
41
42
[clj-ssh.keychain :as keychain]
42
43
[clj-ssh.reflect :as reflect]
43
44
[clojure.java.io :as io]
@@ -177,6 +178,11 @@ Licensed under EPL (http://www.eclipse.org/legal/epl-v10.html)"
177
178
(logging/error " Passphrase required, but none findable." ))
178
179
(add-identity agent identity))))))
179
180
181
+ (defn ssh-agent
182
+ " Create an agent that uses the system ssh-agent (or paegant on windows)."
183
+ []
184
+ (doto (JSch. ) (agent/connect )))
185
+
180
186
(defn create-ssh-agent
181
187
" Create an ssh-agent. By default try and add the current user's id_rsa key."
182
188
([] (create-ssh-agent true ))
Original file line number Diff line number Diff line change @@ -137,7 +137,18 @@ list, Alan Dipert and MeikelBrandmeyer."
137
137
(.getBytes (slurp (public-key-path )))
138
138
nil )
139
139
(is (= 1 (count (.getIdentityNames *ssh-agent*))))
140
- (is (= " name" (first (.getIdentityNames *ssh-agent*)))))))
140
+ (is (= " name" (first (.getIdentityNames *ssh-agent*))))))
141
+ (testing " ssh-agent"
142
+ (with-ssh-agent (ssh-agent )
143
+ (let [n (count (.getIdentityNames *ssh-agent*))]
144
+ (add-identity
145
+ *ssh-agent*
146
+ " name"
147
+ (.getBytes (slurp (private-key-path )))
148
+ (.getBytes (slurp (public-key-path )))
149
+ nil )
150
+ (is (= (inc n) (count (.getIdentityNames *ssh-agent*)))))
151
+ (is (some #(= " name" %) (.getIdentityNames *ssh-agent*))))))
141
152
142
153
(deftest has-identity?-test
143
154
(let [key (private-key-path )]
You can’t perform that action at this time.
0 commit comments