Skip to content

Commit f3b6c5c

Browse files
authored
Merge pull request #79 from norrisjeremy/20210913
More legacy algorithm support and bugfixes
2 parents 085934b + 161a035 commit f3b6c5c

23 files changed

Lines changed: 939 additions & 9 deletions

ChangeLog.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1+
* [0.1.68](https://github.com/mwiede/jsch/releases/tag/jsch-0.1.68)
2+
* Added support for the rijndael-cbc@<!-- -->lysator.liu.se algorithm
3+
* Added support for the hmac-ripemd160, hmac-ripemd160@<!-- -->openssh.com and hmac-ripemd160-etm@<!-- -->openssh.com algorithms using [Bouncy Castle](https://www.bouncycastle.org/java.html)
4+
* Added support for various algorithms from [RFC 4253](https://datatracker.ietf.org/doc/html/rfc4253) and [RFC 4344](https://datatracker.ietf.org/doc/html/rfc4344) using [Bouncy Castle](https://www.bouncycastle.org/java.html)
5+
* cast128-cbc
6+
* cast128-ctr
7+
* twofish-cbc
8+
* twofish128-cbc
9+
* twofish128-ctr
10+
* twofish192-cbc
11+
* twofish192-ctr
12+
* twofish256-cbc
13+
* twofish256-ctr
14+
* Added support for the seed-cbc@<!-- -->ssh.com algorithm using [Bouncy Castle](https://www.bouncycastle.org/java.html)
15+
* Address [#76](https://github.com/mwiede/jsch/issues/76) by making the "Host" keyword case-insensitive
116
* [0.1.67](https://github.com/mwiede/jsch/releases/tag/jsch-0.1.67)
217
* Added support for the blowfish-ctr algorithm from [RFC 4344](https://datatracker.ietf.org/doc/html/rfc4344)
318
* Fix bug where ext-info-c was incorrectly advertised during rekeying
419
* According to [RFC 8308 section 2.1](https://datatracker.ietf.org/doc/html/rfc8308#section-2.1), ext-info-c should only advertised during the first key exchange
5-
* Address [#77](https://github.com/mwiede/jsch/issues/77) by attempting to add compatibility with older [Bouncy Castle](https://www.bouncycastle.org/) releases
20+
* Address [#77](https://github.com/mwiede/jsch/issues/77) by attempting to add compatibility with older [Bouncy Castle](https://www.bouncycastle.org/java.html) releases
621
* [0.1.66](https://github.com/mwiede/jsch/releases/tag/jsch-0.1.66)
722
* Added support for [RFC 8308](https://datatracker.ietf.org/doc/html/rfc8308) extension negotiation and server-sig-algs extension
823
* This support is enabled by default, but can be controlled via the enable_server_sig_algs config option (or `jsch.enable_server_sig_algs` system property)
@@ -36,7 +51,7 @@
3651
* See `examples/JSchWithAgentProxy.java` for simple example
3752
* ssh-agent support requires either [Java 16's JEP 380](https://openjdk.java.net/jeps/380) or the addition of [junixsocket](https://github.com/kohlschutter/junixsocket) to classpath
3853
* Pageant support is untested & requires the addition of [JNA](https://github.com/java-native-access/jna) to classpath
39-
* Added support for the following algorithms with older Java releases by using [Bouncy Castle](https://www.bouncycastle.org/):
54+
* Added support for the following algorithms with older Java releases by using [Bouncy Castle](https://www.bouncycastle.org/java.html):
4055
* ssh-ed25519
4156
* ssh-ed448
4257
* curve25519-sha256

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ As I explained in a [blog post](http://www.matez.de/index.php/2020/06/22/the-fut
6464
* This library is a Multi-Release-jar, which means that you can only use certain features when a more recent Java version is used.
6565
* In order to use ssh-ed25519 & ssh-ed448, you must use at least Java 15.
6666
* In order to use curve25519-sha256, curve448-sha512 & chacha20-poly1305@<!-- -->openssh.com, you must use at least Java 11.
67-
* As of the [0.1.66](https://github.com/mwiede/jsch/releases/tag/jsch-0.1.66) release, these algorithms can now be used with older Java releases if [Bouncy Castle](https://www.bouncycastle.org/) (bcprov-jdk15on) is added to the classpath.
67+
* As of the [0.1.66](https://github.com/mwiede/jsch/releases/tag/jsch-0.1.66) release, these algorithms can now be used with older Java releases if [Bouncy Castle](https://www.bouncycastle.org/java.html) (bcprov-jdk15on) is added to the classpath.
6868

6969
## Changes since fork:
7070
See [ChangeLog.md](ChangeLog.md)

src/main/java/com/jcraft/jsch/JSch.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ public class JSch{
154154
config.put("keypairgen.ecdsa", "com.jcraft.jsch.jce.KeyPairGenECDSA");
155155
config.put("random", "com.jcraft.jsch.jce.Random");
156156

157+
config.put("hmac-ripemd160", "com.jcraft.jsch.bc.HMACRIPEMD160");
158+
config.put("hmac-ripemd160@openssh.com", "com.jcraft.jsch.bc.HMACRIPEMD160OpenSSH");
159+
config.put("hmac-ripemd160-etm@openssh.com", "com.jcraft.jsch.bc.HMACRIPEMD160ETM");
160+
157161
config.put("none", "com.jcraft.jsch.CipherNone");
158162

159163
config.put("aes128-gcm@openssh.com", "com.jcraft.jsch.jce.AES128GCM");
@@ -162,6 +166,18 @@ public class JSch{
162166
config.put("aes128-cbc", "com.jcraft.jsch.jce.AES128CBC");
163167
config.put("aes192-cbc", "com.jcraft.jsch.jce.AES192CBC");
164168
config.put("aes256-cbc", "com.jcraft.jsch.jce.AES256CBC");
169+
config.put("rijndael-cbc@lysator.liu.se", "com.jcraft.jsch.jce.AES256CBC");
170+
171+
config.put("cast128-cbc", "com.jcraft.jsch.bc.CAST128CBC");
172+
config.put("cast128-ctr", "com.jcraft.jsch.bc.CAST128CTR");
173+
config.put("twofish128-cbc", "com.jcraft.jsch.bc.Twofish128CBC");
174+
config.put("twofish192-cbc", "com.jcraft.jsch.bc.Twofish192CBC");
175+
config.put("twofish256-cbc", "com.jcraft.jsch.bc.Twofish256CBC");
176+
config.put("twofish-cbc", "com.jcraft.jsch.bc.Twofish256CBC");
177+
config.put("twofish128-ctr", "com.jcraft.jsch.bc.Twofish128CTR");
178+
config.put("twofish192-ctr", "com.jcraft.jsch.bc.Twofish192CTR");
179+
config.put("twofish256-ctr", "com.jcraft.jsch.bc.Twofish256CTR");
180+
config.put("seed-cbc@ssh.com", "com.jcraft.jsch.bc.SEEDCBC");
165181

166182
config.put("aes128-ctr", "com.jcraft.jsch.jce.AES128CTR");
167183
config.put("aes192-ctr", "com.jcraft.jsch.jce.AES192CTR");

src/main/java/com/jcraft/jsch/OpenSSHConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private void _parse(BufferedReader br) throws IOException {
124124
if(key_value.length <= 1)
125125
continue;
126126

127-
if(key_value[0].equals("Host")){
127+
if(key_value[0].toUpperCase().equals("Host")){
128128
config.put(host, kv);
129129
hosts.addElement(host);
130130
host = key_value[1];
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2+
/*
3+
Copyright (c) 2005-2018 ymnk, JCraft,Inc. All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
1. Redistributions of source code must retain the above copyright notice,
9+
this list of conditions and the following disclaimer.
10+
11+
2. Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in
13+
the documentation and/or other materials provided with the distribution.
14+
15+
3. The names of the authors may not be used to endorse or promote products
16+
derived from this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
19+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
21+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
22+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
30+
package com.jcraft.jsch.bc;
31+
32+
import com.jcraft.jsch.Cipher;
33+
import org.bouncycastle.crypto.BufferedBlockCipher;
34+
import org.bouncycastle.crypto.engines.CAST5Engine;
35+
import org.bouncycastle.crypto.modes.CBCBlockCipher;
36+
import org.bouncycastle.crypto.params.*;
37+
38+
public class CAST128CBC implements Cipher{
39+
private static final int ivsize=8;
40+
private static final int bsize=16;
41+
private BufferedBlockCipher cipher;
42+
@Override
43+
public int getIVSize(){return ivsize;}
44+
@Override
45+
public int getBlockSize(){return bsize;}
46+
@Override
47+
public int getTagSize(){return 0;}
48+
@Override
49+
public void init(int mode, byte[] key, byte[] iv) throws Exception{
50+
byte[] tmp;
51+
if(iv.length>ivsize){
52+
tmp=new byte[ivsize];
53+
System.arraycopy(iv, 0, tmp, 0, tmp.length);
54+
iv=tmp;
55+
}
56+
if(key.length>bsize){
57+
tmp=new byte[bsize];
58+
System.arraycopy(key, 0, tmp, 0, tmp.length);
59+
key=tmp;
60+
}
61+
62+
try{
63+
ParametersWithIV keyspec=new ParametersWithIV(new KeyParameter(key, 0, key.length), iv, 0, iv.length);
64+
cipher=new BufferedBlockCipher(new CBCBlockCipher(new CAST5Engine()));
65+
cipher.init(mode==ENCRYPT_MODE, keyspec);
66+
}
67+
catch(Exception e){
68+
cipher=null;
69+
throw e;
70+
}
71+
}
72+
@Override
73+
public void update(int foo) throws Exception{
74+
}
75+
@Override
76+
public void update(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception{
77+
cipher.processBytes(foo, s1, len, bar, s2);
78+
}
79+
@Override
80+
public void updateAAD(byte[] foo, int s1, int len) throws Exception{
81+
}
82+
@Override
83+
public void doFinal(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception{
84+
}
85+
@Override
86+
public boolean isCBC(){return true; }
87+
@Override
88+
public boolean isAEAD(){return false; }
89+
@Override
90+
public boolean isChaCha20(){return false; }
91+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2+
/*
3+
Copyright (c) 2005-2018 ymnk, JCraft,Inc. All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
1. Redistributions of source code must retain the above copyright notice,
9+
this list of conditions and the following disclaimer.
10+
11+
2. Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in
13+
the documentation and/or other materials provided with the distribution.
14+
15+
3. The names of the authors may not be used to endorse or promote products
16+
derived from this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
19+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
21+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
22+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
30+
package com.jcraft.jsch.bc;
31+
32+
import com.jcraft.jsch.Cipher;
33+
import org.bouncycastle.crypto.engines.CAST5Engine;
34+
import org.bouncycastle.crypto.modes.SICBlockCipher;
35+
import org.bouncycastle.crypto.params.*;
36+
37+
public class CAST128CTR implements Cipher{
38+
private static final int ivsize=8;
39+
private static final int bsize=16;
40+
private SICBlockCipher cipher;
41+
@Override
42+
public int getIVSize(){return ivsize;}
43+
@Override
44+
public int getBlockSize(){return bsize;}
45+
@Override
46+
public int getTagSize(){return 0;}
47+
@Override
48+
public void init(int mode, byte[] key, byte[] iv) throws Exception{
49+
byte[] tmp;
50+
if(iv.length>ivsize){
51+
tmp=new byte[ivsize];
52+
System.arraycopy(iv, 0, tmp, 0, tmp.length);
53+
iv=tmp;
54+
}
55+
if(key.length>bsize){
56+
tmp=new byte[bsize];
57+
System.arraycopy(key, 0, tmp, 0, tmp.length);
58+
key=tmp;
59+
}
60+
61+
try{
62+
ParametersWithIV keyspec=new ParametersWithIV(new KeyParameter(key, 0, key.length), iv, 0, iv.length);
63+
cipher=new SICBlockCipher(new CAST5Engine());
64+
cipher.init(mode==ENCRYPT_MODE, keyspec);
65+
}
66+
catch(Exception e){
67+
cipher=null;
68+
throw e;
69+
}
70+
}
71+
@Override
72+
public void update(int foo) throws Exception{
73+
}
74+
@Override
75+
public void update(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception{
76+
cipher.processBytes(foo, s1, len, bar, s2);
77+
}
78+
@Override
79+
public void updateAAD(byte[] foo, int s1, int len) throws Exception{
80+
}
81+
@Override
82+
public void doFinal(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception{
83+
}
84+
@Override
85+
public boolean isCBC(){return false; }
86+
@Override
87+
public boolean isAEAD(){return false; }
88+
@Override
89+
public boolean isChaCha20(){return false; }
90+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2+
/*
3+
Copyright (c) 2012-2018 ymnk, JCraft,Inc. All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
1. Redistributions of source code must retain the above copyright notice,
9+
this list of conditions and the following disclaimer.
10+
11+
2. Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in
13+
the documentation and/or other materials provided with the distribution.
14+
15+
3. The names of the authors may not be used to endorse or promote products
16+
derived from this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
19+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
21+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
22+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
30+
package com.jcraft.jsch.bc;
31+
32+
import com.jcraft.jsch.MAC;
33+
import org.bouncycastle.crypto.Digest;
34+
import org.bouncycastle.crypto.macs.HMac;
35+
import org.bouncycastle.crypto.params.KeyParameter;
36+
37+
abstract class HMAC implements MAC {
38+
protected String name;
39+
protected int bsize;
40+
protected Digest digest;
41+
protected boolean etm;
42+
private HMac mac;
43+
44+
@Override
45+
public int getBlockSize() {
46+
return bsize;
47+
};
48+
49+
@Override
50+
public void init(byte[] key) throws Exception {
51+
if(key.length>bsize){
52+
byte[] tmp = new byte[bsize];
53+
System.arraycopy(key, 0, tmp, 0, bsize);
54+
key = tmp;
55+
}
56+
KeyParameter skey = new KeyParameter(key, 0, key.length);
57+
mac = new HMac(digest);
58+
mac.init(skey);
59+
}
60+
61+
private final byte[] tmp = new byte[4];
62+
@Override
63+
public void update(int i){
64+
tmp[0] = (byte)(i>>>24);
65+
tmp[1] = (byte)(i>>>16);
66+
tmp[2] = (byte)(i>>>8);
67+
tmp[3] = (byte)i;
68+
update(tmp, 0, 4);
69+
}
70+
71+
@Override
72+
public void update(byte foo[], int s, int l){
73+
mac.update(foo, s, l);
74+
}
75+
76+
@Override
77+
public void doFinal(byte[] buf, int offset){
78+
mac.doFinal(buf, offset);
79+
}
80+
81+
@Override
82+
public String getName(){
83+
return name;
84+
}
85+
86+
@Override
87+
public boolean isEtM(){
88+
return etm;
89+
}
90+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2+
/*
3+
Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
1. Redistributions of source code must retain the above copyright notice,
9+
this list of conditions and the following disclaimer.
10+
11+
2. Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in
13+
the documentation and/or other materials provided with the distribution.
14+
15+
3. The names of the authors may not be used to endorse or promote products
16+
derived from this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
19+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
21+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
22+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
30+
package com.jcraft.jsch.bc;
31+
32+
import org.bouncycastle.crypto.digests.RIPEMD160Digest;
33+
34+
public class HMACRIPEMD160 extends HMAC {
35+
public HMACRIPEMD160(){
36+
name = "hmac-ripemd160";
37+
bsize = 20;
38+
digest = new RIPEMD160Digest();
39+
}
40+
}

0 commit comments

Comments
 (0)