Skip to content

Commit 529a177

Browse files
committed
Merge branch 'release/0.5.7'
2 parents d2b9605 + 2a58cf9 commit 529a177

File tree

7 files changed

+110
-57
lines changed

7 files changed

+110
-57
lines changed

.travis.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
language: clojure
2+
lein: lein2
3+
before_script:
4+
- ssh-keygen -N "" -f ~/.ssh/id_rsa
5+
- cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
6+
- ssh-keygen -f ~/.ssh/clj_ssh -t rsa -C "key for test clj-ssh" -N ""
7+
- ssh-keygen -f ~/.ssh/clj_ssh_pp -t rsa -C "key for test clj-ssh" -N "clj-ssh"
8+
- echo "from=\"127.0.0.1,localhost,0.0.0.0\" $(cat ~/.ssh/clj_ssh.pub)" >> ~/.ssh/authorized_keys
9+
- echo "from=\"127.0.0.1,localhost,0.0.0.0\" $(cat ~/.ssh/clj_ssh_pp.pub)" >> ~/.ssh/authorized_keys
10+
- eval $(ssh-agent)
11+
- echo "clj-ssh" > pp
12+
- chmod +x pp
13+
- setsid ssh-add ~/.ssh/clj_ssh_pp < pp # add the key to the keychain
14+
15+
script: lein2 test
16+
# notifications:
17+
# irc: "irc.freenode.org#pallet"

README.md

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ The `clj-ssh.ssh` namespace should be used for SSH from functional code.
5454

5555
```clj
5656
(let [agent (ssh-agent {})]
57-
(let [session (session agent "localhost" {:strict-host-key-checking :no})]
57+
(let [session (session agent "host-ip" {:strict-host-key-checking :no})]
5858
(with-connection session
5959
(let [result (ssh session {:in "echo hello"})]
6060
(println (result :out)))
@@ -75,7 +75,7 @@ remote host using the credentials in your local ssh-agent:
7575

7676
```clj
7777
(let [agent (ssh-agent {})]
78-
(let [session (session agent "localhost" {:strict-host-key-checking :no})]
78+
(let [session (session agent "host-ip" {:strict-host-key-checking :no})]
7979
(with-connection session
8080
(let [result (ssh session {:in "ssh somehost ls" :agent-forwarding true})]
8181
(println (result :out))))))
@@ -87,7 +87,7 @@ system, then a local, isolated ssh-agent can be used.
8787
```clj
8888
(let [agent (ssh-agent {:use-system-ssh-agent false})]
8989
(add-identity agent {:private-key-path "/user/name/.ssh/id_rsa"})
90-
(let [session (session agent "localhost" {:strict-host-key-checking :no})]
90+
(let [session (session agent "host-ip" {:strict-host-key-checking :no})]
9191
(with-connection session
9292
(let [result (ssh session {:in "echo hello"})]
9393
(println (result :out)))))
@@ -97,7 +97,7 @@ SFTP is supported:
9797

9898
```clj
9999
(let [agent (ssh-agent {})]
100-
(let [session (session agent "localhost" {:strict-host-key-checking :no})]
100+
(let [session (session agent "host-ip" {:strict-host-key-checking :no})]
101101
(with-connection session
102102
(let [channel (ssh-sftp session)]
103103
(with-channel-connection channel
@@ -109,7 +109,7 @@ SSH tunneling is also supported:
109109

110110
```clj
111111
(let [agent (ssh-agent {})]
112-
(let [session (session agent "localhost" {:strict-host-key-checking :no})]
112+
(let [session (session agent "host-ip" {:strict-host-key-checking :no})]
113113
(with-connection session
114114
(with-local-port-forward [session 8080 80]
115115
(comment do something with port 8080 here)))))
@@ -143,10 +143,34 @@ Thanks to [Ryan Stradling](http://github.com/rstradling) for these.
143143
Via [clojars](http://clojars.org) and
144144
[Leiningen](http://github.com/technomancy/leiningen).
145145

146-
:dependencies [clj-ssh "0.5.6"]
146+
:dependencies [clj-ssh "0.5.7"]
147147

148148
or your favourite maven repository aware tool.
149149

150+
## Tests
151+
152+
The test rely on several keys being authorized on localhost:
153+
154+
```shell
155+
ssh-keygen -f ~/.ssh/clj_ssh -t rsa -C "key for test clj-ssh" -N ""
156+
ssh-keygen -f ~/.ssh/clj_ssh_pp -t rsa -C "key for test clj-ssh" -N "clj-ssh"
157+
cp ~/.ssh/authorized_keys ~/.ssh/authorized_keys.bak
158+
echo "from=\"localhost\" $(cat ~/.ssh/clj_ssh.pub)" >> ~/.ssh/authorized_keys
159+
echo "from=\"localhost\" $(cat ~/.ssh/clj_ssh_pp.pub)" >> ~/.ssh/authorized_keys
160+
```
161+
162+
The `clj_ssh_pp` key should have a passphrase, and should be registered with your `ssh-agent`.
163+
164+
```shell
165+
ssh-add ~/.ssh/clj_ssh_pp
166+
```
167+
168+
On OS X, use:
169+
170+
```shell
171+
ssh-add -K ~/.ssh/clj_ssh_pp
172+
```
173+
150174
## License
151175

152176
Copyright © 2012 Hugo Duncan

ReleaseNotes.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release Notes
22

3+
## 0.5.7
4+
5+
- Update to jsch.agentproxy 0.0.6
6+
37
## 0.5.6
48

59
- Allow generate-keypair to write key files
@@ -12,7 +16,7 @@
1216
## 0.5.5
1317

1418
- Wrap open-channel exceptions
15-
When .openChannel throws an exception, wrap it in an ex-info exception.
19+
When .openChannel throws an exception, wrap it in an ex-info exception.
1620
This allows easier procession of the exceptions in consuming code.
1721

1822
## 0.5.4
@@ -69,7 +73,7 @@
6973

7074
- Split out clj-ssh.cli
7175

72-
clj-ssh.ssh is designed for composability and programmatic use. It takes
76+
clj-ssh.ssh is designed for composability and programmatic use. It takes
7377
map arguments for options and is fully functional.
7478

7579
clj-ssh.cli is intended to simplify repl usage. It takes variadic
@@ -81,7 +85,7 @@
8185
A boolean value is passed with :agent-forwarding to clj-ssh.ssh/ssh.
8286

8387
- Add support for system ssh-agent
84-
Support the system ssh-agent (or pageant on windows when using putty) via
88+
Support the system ssh-agent (or pageant on windows when using putty) via
8589
jsch-agent-proxy. Introduces a new agent function, clj-ssh.ssh/ssh-agent.
8690

8791
## 0.3.2

project.clj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
(defproject clj-ssh "0.5.6"
1+
(defproject clj-ssh "0.5.7"
22
:description "Library for using SSH from clojure."
33
:url "https://github.com/hugoduncan/clj-ssh"
44
:license {:name "Eclipse Public License"
55
:url "http://www.eclipse.org/legal/epl-v10.html"}
66
:dependencies [[org.clojure/clojure "1.4.0"]
77
[org.clojure/tools.logging "0.1.2"
88
:exclusions [org.clojure/clojure]]
9-
[com.jcraft/jsch.agentproxy.usocket-jna "0.0.5"]
10-
[com.jcraft/jsch.agentproxy.usocket-nc "0.0.5"]
11-
[com.jcraft/jsch.agentproxy.sshagent "0.0.5"]
12-
[com.jcraft/jsch.agentproxy.pageant "0.0.5"]
13-
[com.jcraft/jsch.agentproxy.core "0.0.5"]
14-
[com.jcraft/jsch.agentproxy.jsch "0.0.5"]
9+
[com.jcraft/jsch.agentproxy.usocket-jna "0.0.6"]
10+
[com.jcraft/jsch.agentproxy.usocket-nc "0.0.6"]
11+
[com.jcraft/jsch.agentproxy.sshagent "0.0.6"]
12+
[com.jcraft/jsch.agentproxy.pageant "0.0.6"]
13+
[com.jcraft/jsch.agentproxy.core "0.0.6"]
14+
[com.jcraft/jsch.agentproxy.jsch "0.0.6"]
1515
[com.jcraft/jsch "0.1.50"]])

src/clj_ssh/keychain.clj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
[clojure.java.shell :as shell]))
77

88
(defn ask-passphrase [path]
9-
(when-let [console (. System console)]
10-
(print "Passphrase for" path ": ")
11-
(.readPassword console)))
9+
(if-let [console (. System console)]
10+
(do (print "Passphrase for" path ": ")
11+
(.readPassword console))
12+
(throw (ex-info "No means to ask for passphrase"
13+
{:type :clj-ssh/no-passphrase-available}))))
1214

1315
(defmulti keychain-passphrase "Obtain password for path"
1416
(fn [system path] system))

test/clj_ssh/cli_test.clj

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,23 @@
7474
(is (connected? session)))
7575
(is (not (connected? session)))))
7676
(with-ssh-agent (ssh-agent {:use-system-ssh-agent false})
77-
(add-identity-with-keychain
78-
:private-key-path (encrypted-private-key-path)
79-
:passphrase "clj-ssh")
80-
(let [session (session "localhost")]
81-
(is (instance? com.jcraft.jsch.Session session))
82-
(is (not (connected? session)))
83-
(connect session)
84-
(is (connected? session))
85-
(disconnect session)
86-
(is (not (connected? session))))
87-
(let [session (session "localhost")]
88-
(with-connection session
89-
(is (connected? session)))
90-
(is (not (connected? session)))))
77+
(try (add-identity-with-keychain
78+
:private-key-path (encrypted-private-key-path)
79+
:passphrase "clj-ssh")
80+
(let [session (session "localhost")]
81+
(is (instance? com.jcraft.jsch.Session session))
82+
(is (not (connected? session)))
83+
(connect session)
84+
(is (connected? session))
85+
(disconnect session)
86+
(is (not (connected? session))))
87+
(let [session (session "localhost")]
88+
(with-connection session
89+
(is (connected? session)))
90+
(is (not (connected? session))))
91+
(catch Exception e
92+
(when-not (= :clj-ssh/no-passphrase-available (:type (ex-data e)))
93+
(throw e)))))
9194
(with-ssh-agent (ssh-agent {})
9295
(let [session (session "localhost")]
9396
(is (instance? com.jcraft.jsch.Session session))

test/clj_ssh/ssh_test.clj

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -138,30 +138,33 @@
138138
(is (connected? session)))
139139
(is (not (connected? session)))))
140140
(testing "key with passphrase"
141-
(let [agent (ssh-agent {:use-system-ssh-agent false})]
142-
(add-identity-with-keychain
143-
agent
144-
{:private-key-path (encrypted-private-key-path)
145-
:passphrase "clj-ssh"})
146-
(let [session (session
147-
agent
148-
"localhost"
149-
{:username (username)
150-
:strict-host-key-checking :no})]
151-
(is (instance? com.jcraft.jsch.Session session))
152-
(is (not (connected? session)))
153-
(connect session)
154-
(is (connected? session))
155-
(disconnect session)
156-
(is (not (connected? session))))
157-
(let [session (session
158-
agent
159-
"localhost"
160-
{:username (username)
161-
:strict-host-key-checking :no})]
162-
(with-connection session
163-
(is (connected? session)))
164-
(is (not (connected? session)))))))
141+
(try (let [agent (ssh-agent {:use-system-ssh-agent false})]
142+
(add-identity-with-keychain
143+
agent
144+
{:private-key-path (encrypted-private-key-path)
145+
:passphrase "clj-ssh"})
146+
(let [session (session
147+
agent
148+
"localhost"
149+
{:username (username)
150+
:strict-host-key-checking :no})]
151+
(is (instance? com.jcraft.jsch.Session session))
152+
(is (not (connected? session)))
153+
(connect session)
154+
(is (connected? session))
155+
(disconnect session)
156+
(is (not (connected? session))))
157+
(let [session (session
158+
agent
159+
"localhost"
160+
{:username (username)
161+
:strict-host-key-checking :no})]
162+
(with-connection session
163+
(is (connected? session)))
164+
(is (not (connected? session)))))
165+
(catch Exception e
166+
(when-not (= :clj-ssh/no-passphrase-available (:type (ex-data e)))
167+
(throw e))))))
165168
(testing "system ssh-agent"
166169
(let [agent (ssh-agent {})]
167170
(let [session (session

0 commit comments

Comments
 (0)