Skip to content

Commit bf6c6e6

Browse files
CACD-DevJason Brault
andauthored
Update of jsch version and generate-keypair API (#63)
* Updated jsch version and addressed issues with API change Identified previous version of clj-ssh (0.5.15) had two vulneratbilities listed in maven repository (CVE-2017-5929 and CVE-2016-5726) Vulnerabilities were addressed in newer versions of; com.jcraft/jsch (0.1.55) ch.qos.logback/logback-classic (1.4.7) Newer version of jsch broke authentication with older RSA private key header (fix is listed in readme) Newer version of jsch lists setPassphrase method in com.jcraft.jsch/KeyPair as deprecated. Made changes to ssh/generate-keypair to accomodate (and nil passphrase) *Suggested TO DO, test of generate-keypair only operates in memory and does not test writing out files. Header identification could then be tested to identify possible future jsch changes. Test profile expanded to include newer versions of clojure. All 31 tests pass with no failures / errors * Fixed typo in profiles.clj Minor typo error in clojure version fixed. --------- Co-authored-by: Jason Brault <[email protected]>
1 parent cad8841 commit bf6c6e6

File tree

5 files changed

+83
-16
lines changed

5 files changed

+83
-16
lines changed

README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
# clj-ssh
77

8-
SSH in clojure. Uses jsch.
8+
SSH in clojure. Uses jsch.
9+
(See section RSA Private Key format if using openssl generated keys)
910

1011
## Usage
1112

@@ -145,6 +146,42 @@ works with both a `jump-session` session and a single host session.
145146
[Annotated source](http:/hugoduncan.github.com/clj-ssh/0.5/annotated/uberdoc.html).
146147
[API](http:/hugoduncan.github.com/clj-ssh/0.5/api/index.html).
147148

149+
## RSA Private Key Format and clj-ssh
150+
151+
There have been changes to the header of RSA Private Keys. With the upgrade of
152+
com.jcraft/jsch to "0.1.55", the older openssh headers work with ssh will throw
153+
an authentication failure.
154+
155+
Older format
156+
```
157+
-----BEGIN OPENSSH PRIVATE KEY-----`
158+
```
159+
160+
New RSA format
161+
```
162+
-----BEGIN RSA PRIVATE KEY-----
163+
```
164+
165+
Old private keys can be easily converted to the new format, through the use of
166+
ssh-keygen's passphrase changing command. This will change the file in place.
167+
```
168+
ssh-keygen -p -f privateKeyFile -m pem -P passphrase -N passphrase
169+
```
170+
The -m flag will force the file to pem format, fixing the header.
171+
The -P (for old passphrase) and -N (new passphrase) can be ommitted to generate
172+
an interactive query instead.
173+
(enter "" at either -P or -N to identify no passphrase)
174+
175+
### Note: clj-ssh key generation
176+
clj-ssh does have the ability to generate the public / private key pairs for both
177+
RSA and DSA (found in clj-ssh.ssh/generate-keypair).
178+
179+
Unlike ssh-keygen, the RSA passphrase on the private key will be limited to
180+
DES-EDE3-CBC DEK format to encrypt/decrypt the passphrase if created within clj-ssh.
181+
ssh-keygen will likely use what is standard in your operating system's crypto suite,
182+
(e.g. AES-128-CBC)
183+
184+
148185
## FAQ
149186

150187
Q: What does

ReleaseNotes.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
## 0.5.16
2+
3+
- Moved jsch to version 0.1.55
4+
5+
- Moved clojure tools.logging to 1.2.4
6+
7+
- Moved logback-classic to 1.4.7
8+
9+
- Changed ssh/generate-keypair to now match jsch API
10+
(and remove setPassphrase method which is listed as depricated)
11+
12+
- Included section in readme.md regarding RSA header issues and
13+
compatibilities
14+
115
## 0.5.14
216

317
- Remove println from scp code

profiles.clj

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
{:dev
2-
{:dependencies [[ch.qos.logback/logback-classic "1.0.0"]]
2+
{:dependencies [[ch.qos.logback/logback-classic "1.4.7"]]
33
:aliases {"test" ["with-profile"
4-
"clojure-1.4.0:clojure-1.5.1:clojure-1.6.0:clojure-1.7.0:clojure-1.8.0"
4+
"clojure-1.4.0:clojure-1.5.1:clojure-1.6.0:clojure-1.7.0:clojure-1.8.0:clojure-1.9.0:clojure-1.10.0:clojure-1.10.1:clojure-1.10.2:clojure-1.10.3:clojure-1.11.0:clojure-1.11.1"
55
"test"]}}
6-
:clojure-1.2.1 {:dependencies [[org.clojure/clojure "1.2.1"]]}
7-
:clojure-1.3.0 {:dependencies [[org.clojure/clojure "1.3.0"]]}
86
:clojure-1.4.0 {:dependencies [[org.clojure/clojure "1.4.0"]]}
97
:clojure-1.5.1 {:dependencies [[org.clojure/clojure "1.5.1"]]}
108
:clojure-1.6.0 {:dependencies [[org.clojure/clojure "1.6.0"]]}
119
:clojure-1.7.0 {:dependencies [[org.clojure/clojure "1.7.0"]]}
12-
:clojure-1.8.0 {:dependencies [[org.clojure/clojure "1.8.0"]]}}
10+
:clojure-1.8.0 {:dependencies [[org.clojure/clojure "1.8.0"]]}
11+
:clojure-1.9.0 {:dependencies [[org.clojure/clojure "1.9.0"]]}
12+
:clojure-1.10.0 {:dependencies [[org.clojure/clojure "1.10.0"]]}
13+
:clojure-1.10.1 {:dependencies [[org.clojure/clojure "1.10.1"]]}
14+
:clojure-1.10.2 {:dependencies [[org.clojure/clojure "1.10.2"]]}
15+
:clojure-1.10.3 {:dependencies [[org.clojure/clojure "1.10.3"]]}
16+
:clojure-1.11.0 {:dependencies [[org.clojure/clojure "1.11.0"]]}
17+
:clojure-1.11.1 {:dependencies [[org.clojure/clojure "1.11.1"]]}
18+
19+
20+
}

project.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
(def agentproxy-version "0.0.9")
22

3-
(defproject clj-commons/clj-ssh "0.5.15-SNAPSHOT"
3+
(defproject clj-commons/clj-ssh "0.5.16-SNAPSHOT"
44
:description "Library for using SSH from clojure."
55
:url "https://github.com/clj-commons/clj-ssh"
66
:license {:name "Eclipse Public License"
77
:url "http://www.eclipse.org/legal/epl-v10.html"}
8-
:dependencies [[org.clojure/tools.logging "0.2.6"
8+
:dependencies [[org.clojure/tools.logging "1.2.4"
99
:exclusions [org.clojure/clojure]]
1010
[com.jcraft/jsch.agentproxy.usocket-jna ~agentproxy-version]
1111
[com.jcraft/jsch.agentproxy.usocket-nc ~agentproxy-version]
1212
[com.jcraft/jsch.agentproxy.sshagent ~agentproxy-version]
1313
[com.jcraft/jsch.agentproxy.pageant ~agentproxy-version]
1414
[com.jcraft/jsch.agentproxy.core ~agentproxy-version]
1515
[com.jcraft/jsch.agentproxy.jsch ~agentproxy-version]
16-
[com.jcraft/jsch "0.1.53"]]
16+
[com.jcraft/jsch "0.1.55"]]
1717
:jvm-opts ["-Djava.awt.headless=true"]
1818
:profiles {:provided {:dependencies [[org.clojure/clojure "1.10.1"]]}})

src/clj_ssh/ssh.clj

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,15 +1107,23 @@ cmd specifies a command to exec. Valid commands are:
11071107
using the :private-key-path and :public-key-path keys."
11081108
[agent key-type key-size passphrase
11091109
& {:keys [comment private-key-path public-key-path]}]
1110-
(let [keypair (KeyPair/genKeyPair agent (key-type key-types) key-size)]
1111-
(when passphrase
1112-
(.setPassphrase keypair passphrase))
1110+
(let [keypair (KeyPair/genKeyPair agent (key-type key-types) key-size)
1111+
write-pub (if (nil? comment)
1112+
(fn [x] (.writePublicKey keypair x ""))
1113+
(fn [x] (.writePublicKey keypair x comment)))
1114+
write-pvt (if (nil? passphrase)
1115+
(fn [x] (.writePrivateKey keypair x))
1116+
(fn [x] (.writePrivateKey keypair x
1117+
(if (= (type passphrase) String)
1118+
(.getBytes passphrase)
1119+
passphrase))))
1120+
]
11131121
(when public-key-path
1114-
(.writePublicKey keypair public-key-path comment))
1122+
(write-pub public-key-path))
11151123
(when private-key-path
1116-
(.writePrivateKey keypair private-key-path))
1124+
(write-pvt private-key-path))
11171125
(let [pub-baos (ByteArrayOutputStream.)
11181126
pri-baos (ByteArrayOutputStream.)]
1119-
(.writePublicKey keypair pub-baos "")
1120-
(.writePrivateKey keypair pri-baos)
1127+
(write-pub pub-baos)
1128+
(write-pvt pri-baos)
11211129
[(.toByteArray pri-baos) (.toByteArray pub-baos)])))

0 commit comments

Comments
 (0)