Skip to content

Commit

Permalink
Merge branch 'release/0.5.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoduncan committed Dec 9, 2013
2 parents d2b9605 + 2a58cf9 commit 529a177
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 57 deletions.
17 changes: 17 additions & 0 deletions .travis.yml
@@ -0,0 +1,17 @@
language: clojure
lein: lein2
before_script:
- ssh-keygen -N "" -f ~/.ssh/id_rsa
- cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
- ssh-keygen -f ~/.ssh/clj_ssh -t rsa -C "key for test clj-ssh" -N ""
- ssh-keygen -f ~/.ssh/clj_ssh_pp -t rsa -C "key for test clj-ssh" -N "clj-ssh"
- echo "from=\"127.0.0.1,localhost,0.0.0.0\" $(cat ~/.ssh/clj_ssh.pub)" >> ~/.ssh/authorized_keys
- echo "from=\"127.0.0.1,localhost,0.0.0.0\" $(cat ~/.ssh/clj_ssh_pp.pub)" >> ~/.ssh/authorized_keys
- eval $(ssh-agent)
- echo "clj-ssh" > pp
- chmod +x pp
- setsid ssh-add ~/.ssh/clj_ssh_pp < pp # add the key to the keychain

script: lein2 test
# notifications:
# irc: "irc.freenode.org#pallet"
36 changes: 30 additions & 6 deletions README.md
Expand Up @@ -54,7 +54,7 @@ The `clj-ssh.ssh` namespace should be used for SSH from functional code.

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

```clj
(let [agent (ssh-agent {})]
(let [session (session agent "localhost" {:strict-host-key-checking :no})]
(let [session (session agent "host-ip" {:strict-host-key-checking :no})]
(with-connection session
(let [result (ssh session {:in "ssh somehost ls" :agent-forwarding true})]
(println (result :out))))))
Expand All @@ -87,7 +87,7 @@ system, then a local, isolated ssh-agent can be used.
```clj
(let [agent (ssh-agent {:use-system-ssh-agent false})]
(add-identity agent {:private-key-path "/user/name/.ssh/id_rsa"})
(let [session (session agent "localhost" {:strict-host-key-checking :no})]
(let [session (session agent "host-ip" {:strict-host-key-checking :no})]
(with-connection session
(let [result (ssh session {:in "echo hello"})]
(println (result :out)))))
Expand All @@ -97,7 +97,7 @@ SFTP is supported:

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

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

:dependencies [clj-ssh "0.5.6"]
:dependencies [clj-ssh "0.5.7"]

or your favourite maven repository aware tool.

## Tests

The test rely on several keys being authorized on localhost:

```shell
ssh-keygen -f ~/.ssh/clj_ssh -t rsa -C "key for test clj-ssh" -N ""
ssh-keygen -f ~/.ssh/clj_ssh_pp -t rsa -C "key for test clj-ssh" -N "clj-ssh"
cp ~/.ssh/authorized_keys ~/.ssh/authorized_keys.bak
echo "from=\"localhost\" $(cat ~/.ssh/clj_ssh.pub)" >> ~/.ssh/authorized_keys
echo "from=\"localhost\" $(cat ~/.ssh/clj_ssh_pp.pub)" >> ~/.ssh/authorized_keys
```

The `clj_ssh_pp` key should have a passphrase, and should be registered with your `ssh-agent`.

```shell
ssh-add ~/.ssh/clj_ssh_pp
```

On OS X, use:

```shell
ssh-add -K ~/.ssh/clj_ssh_pp
```

## License

Copyright © 2012 Hugo Duncan
Expand Down
10 changes: 7 additions & 3 deletions ReleaseNotes.md
@@ -1,5 +1,9 @@
# Release Notes

## 0.5.7

- Update to jsch.agentproxy 0.0.6

## 0.5.6

- Allow generate-keypair to write key files
Expand All @@ -12,7 +16,7 @@
## 0.5.5

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

## 0.5.4
Expand Down Expand Up @@ -69,7 +73,7 @@

- Split out clj-ssh.cli

clj-ssh.ssh is designed for composability and programmatic use. It takes
clj-ssh.ssh is designed for composability and programmatic use. It takes
map arguments for options and is fully functional.

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

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

## 0.3.2
Expand Down
14 changes: 7 additions & 7 deletions project.clj
@@ -1,15 +1,15 @@
(defproject clj-ssh "0.5.6"
(defproject clj-ssh "0.5.7"
:description "Library for using SSH from clojure."
:url "https://github.com/hugoduncan/clj-ssh"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.4.0"]
[org.clojure/tools.logging "0.1.2"
:exclusions [org.clojure/clojure]]
[com.jcraft/jsch.agentproxy.usocket-jna "0.0.5"]
[com.jcraft/jsch.agentproxy.usocket-nc "0.0.5"]
[com.jcraft/jsch.agentproxy.sshagent "0.0.5"]
[com.jcraft/jsch.agentproxy.pageant "0.0.5"]
[com.jcraft/jsch.agentproxy.core "0.0.5"]
[com.jcraft/jsch.agentproxy.jsch "0.0.5"]
[com.jcraft/jsch.agentproxy.usocket-jna "0.0.6"]
[com.jcraft/jsch.agentproxy.usocket-nc "0.0.6"]
[com.jcraft/jsch.agentproxy.sshagent "0.0.6"]
[com.jcraft/jsch.agentproxy.pageant "0.0.6"]
[com.jcraft/jsch.agentproxy.core "0.0.6"]
[com.jcraft/jsch.agentproxy.jsch "0.0.6"]
[com.jcraft/jsch "0.1.50"]])
8 changes: 5 additions & 3 deletions src/clj_ssh/keychain.clj
Expand Up @@ -6,9 +6,11 @@
[clojure.java.shell :as shell]))

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

(defmulti keychain-passphrase "Obtain password for path"
(fn [system path] system))
Expand Down
31 changes: 17 additions & 14 deletions test/clj_ssh/cli_test.clj
Expand Up @@ -74,20 +74,23 @@
(is (connected? session)))
(is (not (connected? session)))))
(with-ssh-agent (ssh-agent {:use-system-ssh-agent false})
(add-identity-with-keychain
:private-key-path (encrypted-private-key-path)
:passphrase "clj-ssh")
(let [session (session "localhost")]
(is (instance? com.jcraft.jsch.Session session))
(is (not (connected? session)))
(connect session)
(is (connected? session))
(disconnect session)
(is (not (connected? session))))
(let [session (session "localhost")]
(with-connection session
(is (connected? session)))
(is (not (connected? session)))))
(try (add-identity-with-keychain
:private-key-path (encrypted-private-key-path)
:passphrase "clj-ssh")
(let [session (session "localhost")]
(is (instance? com.jcraft.jsch.Session session))
(is (not (connected? session)))
(connect session)
(is (connected? session))
(disconnect session)
(is (not (connected? session))))
(let [session (session "localhost")]
(with-connection session
(is (connected? session)))
(is (not (connected? session))))
(catch Exception e
(when-not (= :clj-ssh/no-passphrase-available (:type (ex-data e)))
(throw e)))))
(with-ssh-agent (ssh-agent {})
(let [session (session "localhost")]
(is (instance? com.jcraft.jsch.Session session))
Expand Down
51 changes: 27 additions & 24 deletions test/clj_ssh/ssh_test.clj
Expand Up @@ -138,30 +138,33 @@
(is (connected? session)))
(is (not (connected? session)))))
(testing "key with passphrase"
(let [agent (ssh-agent {:use-system-ssh-agent false})]
(add-identity-with-keychain
agent
{:private-key-path (encrypted-private-key-path)
:passphrase "clj-ssh"})
(let [session (session
agent
"localhost"
{:username (username)
:strict-host-key-checking :no})]
(is (instance? com.jcraft.jsch.Session session))
(is (not (connected? session)))
(connect session)
(is (connected? session))
(disconnect session)
(is (not (connected? session))))
(let [session (session
agent
"localhost"
{:username (username)
:strict-host-key-checking :no})]
(with-connection session
(is (connected? session)))
(is (not (connected? session)))))))
(try (let [agent (ssh-agent {:use-system-ssh-agent false})]
(add-identity-with-keychain
agent
{:private-key-path (encrypted-private-key-path)
:passphrase "clj-ssh"})
(let [session (session
agent
"localhost"
{:username (username)
:strict-host-key-checking :no})]
(is (instance? com.jcraft.jsch.Session session))
(is (not (connected? session)))
(connect session)
(is (connected? session))
(disconnect session)
(is (not (connected? session))))
(let [session (session
agent
"localhost"
{:username (username)
:strict-host-key-checking :no})]
(with-connection session
(is (connected? session)))
(is (not (connected? session)))))
(catch Exception e
(when-not (= :clj-ssh/no-passphrase-available (:type (ex-data e)))
(throw e))))))
(testing "system ssh-agent"
(let [agent (ssh-agent {})]
(let [session (session
Expand Down

0 comments on commit 529a177

Please sign in to comment.