Skip to content

Commit

Permalink
Merge pull request #79 from norrisjeremy/20210913
Browse files Browse the repository at this point in the history
More legacy algorithm support and bugfixes
  • Loading branch information
mwiede authored Oct 4, 2021
2 parents 085934b + 161a035 commit f3b6c5c
Show file tree
Hide file tree
Showing 23 changed files with 939 additions and 9 deletions.
19 changes: 17 additions & 2 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
* [0.1.68](https://github.com/mwiede/jsch/releases/tag/jsch-0.1.68)
* Added support for the rijndael-cbc@<!-- -->lysator.liu.se algorithm
* 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)
* 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)
* cast128-cbc
* cast128-ctr
* twofish-cbc
* twofish128-cbc
* twofish128-ctr
* twofish192-cbc
* twofish192-ctr
* twofish256-cbc
* twofish256-ctr
* Added support for the seed-cbc@<!-- -->ssh.com algorithm using [Bouncy Castle](https://www.bouncycastle.org/java.html)
* Address [#76](https://github.com/mwiede/jsch/issues/76) by making the "Host" keyword case-insensitive
* [0.1.67](https://github.com/mwiede/jsch/releases/tag/jsch-0.1.67)
* Added support for the blowfish-ctr algorithm from [RFC 4344](https://datatracker.ietf.org/doc/html/rfc4344)
* Fix bug where ext-info-c was incorrectly advertised during rekeying
* 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
* Address [#77](https://github.com/mwiede/jsch/issues/77) by attempting to add compatibility with older [Bouncy Castle](https://www.bouncycastle.org/) releases
* 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
* [0.1.66](https://github.com/mwiede/jsch/releases/tag/jsch-0.1.66)
* Added support for [RFC 8308](https://datatracker.ietf.org/doc/html/rfc8308) extension negotiation and server-sig-algs extension
* 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)
Expand Down Expand Up @@ -36,7 +51,7 @@
* See `examples/JSchWithAgentProxy.java` for simple example
* 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
* Pageant support is untested & requires the addition of [JNA](https://github.com/java-native-access/jna) to classpath
* Added support for the following algorithms with older Java releases by using [Bouncy Castle](https://www.bouncycastle.org/):
* Added support for the following algorithms with older Java releases by using [Bouncy Castle](https://www.bouncycastle.org/java.html):
* ssh-ed25519
* ssh-ed448
* curve25519-sha256
Expand Down
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ As I explained in a [blog post](http://www.matez.de/index.php/2020/06/22/the-fut
* This library is a Multi-Release-jar, which means that you can only use certain features when a more recent Java version is used.
* In order to use ssh-ed25519 & ssh-ed448, you must use at least Java 15.
* In order to use curve25519-sha256, curve448-sha512 & chacha20-poly1305@<!-- -->openssh.com, you must use at least Java 11.
* 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.
* 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.

## Changes since fork:
See [ChangeLog.md](ChangeLog.md)
16 changes: 16 additions & 0 deletions src/main/java/com/jcraft/jsch/JSch.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ public class JSch{
config.put("keypairgen.ecdsa", "com.jcraft.jsch.jce.KeyPairGenECDSA");
config.put("random", "com.jcraft.jsch.jce.Random");

config.put("hmac-ripemd160", "com.jcraft.jsch.bc.HMACRIPEMD160");
config.put("[email protected]", "com.jcraft.jsch.bc.HMACRIPEMD160OpenSSH");
config.put("[email protected]", "com.jcraft.jsch.bc.HMACRIPEMD160ETM");

config.put("none", "com.jcraft.jsch.CipherNone");

config.put("[email protected]", "com.jcraft.jsch.jce.AES128GCM");
Expand All @@ -162,6 +166,18 @@ public class JSch{
config.put("aes128-cbc", "com.jcraft.jsch.jce.AES128CBC");
config.put("aes192-cbc", "com.jcraft.jsch.jce.AES192CBC");
config.put("aes256-cbc", "com.jcraft.jsch.jce.AES256CBC");
config.put("[email protected]", "com.jcraft.jsch.jce.AES256CBC");

config.put("cast128-cbc", "com.jcraft.jsch.bc.CAST128CBC");
config.put("cast128-ctr", "com.jcraft.jsch.bc.CAST128CTR");
config.put("twofish128-cbc", "com.jcraft.jsch.bc.Twofish128CBC");
config.put("twofish192-cbc", "com.jcraft.jsch.bc.Twofish192CBC");
config.put("twofish256-cbc", "com.jcraft.jsch.bc.Twofish256CBC");
config.put("twofish-cbc", "com.jcraft.jsch.bc.Twofish256CBC");
config.put("twofish128-ctr", "com.jcraft.jsch.bc.Twofish128CTR");
config.put("twofish192-ctr", "com.jcraft.jsch.bc.Twofish192CTR");
config.put("twofish256-ctr", "com.jcraft.jsch.bc.Twofish256CTR");
config.put("[email protected]", "com.jcraft.jsch.bc.SEEDCBC");

config.put("aes128-ctr", "com.jcraft.jsch.jce.AES128CTR");
config.put("aes192-ctr", "com.jcraft.jsch.jce.AES192CTR");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jcraft/jsch/OpenSSHConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private void _parse(BufferedReader br) throws IOException {
if(key_value.length <= 1)
continue;

if(key_value[0].equals("Host")){
if(key_value[0].toUpperCase().equals("Host")){
config.put(host, kv);
hosts.addElement(host);
host = key_value[1];
Expand Down
91 changes: 91 additions & 0 deletions src/main/java/com/jcraft/jsch/bc/CAST128CBC.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
Copyright (c) 2005-2018 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.jcraft.jsch.bc;

import com.jcraft.jsch.Cipher;
import org.bouncycastle.crypto.BufferedBlockCipher;
import org.bouncycastle.crypto.engines.CAST5Engine;
import org.bouncycastle.crypto.modes.CBCBlockCipher;
import org.bouncycastle.crypto.params.*;

public class CAST128CBC implements Cipher{
private static final int ivsize=8;
private static final int bsize=16;
private BufferedBlockCipher cipher;
@Override
public int getIVSize(){return ivsize;}
@Override
public int getBlockSize(){return bsize;}
@Override
public int getTagSize(){return 0;}
@Override
public void init(int mode, byte[] key, byte[] iv) throws Exception{
byte[] tmp;
if(iv.length>ivsize){
tmp=new byte[ivsize];
System.arraycopy(iv, 0, tmp, 0, tmp.length);
iv=tmp;
}
if(key.length>bsize){
tmp=new byte[bsize];
System.arraycopy(key, 0, tmp, 0, tmp.length);
key=tmp;
}

try{
ParametersWithIV keyspec=new ParametersWithIV(new KeyParameter(key, 0, key.length), iv, 0, iv.length);
cipher=new BufferedBlockCipher(new CBCBlockCipher(new CAST5Engine()));
cipher.init(mode==ENCRYPT_MODE, keyspec);
}
catch(Exception e){
cipher=null;
throw e;
}
}
@Override
public void update(int foo) throws Exception{
}
@Override
public void update(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception{
cipher.processBytes(foo, s1, len, bar, s2);
}
@Override
public void updateAAD(byte[] foo, int s1, int len) throws Exception{
}
@Override
public void doFinal(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception{
}
@Override
public boolean isCBC(){return true; }
@Override
public boolean isAEAD(){return false; }
@Override
public boolean isChaCha20(){return false; }
}
90 changes: 90 additions & 0 deletions src/main/java/com/jcraft/jsch/bc/CAST128CTR.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
Copyright (c) 2005-2018 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.jcraft.jsch.bc;

import com.jcraft.jsch.Cipher;
import org.bouncycastle.crypto.engines.CAST5Engine;
import org.bouncycastle.crypto.modes.SICBlockCipher;
import org.bouncycastle.crypto.params.*;

public class CAST128CTR implements Cipher{
private static final int ivsize=8;
private static final int bsize=16;
private SICBlockCipher cipher;
@Override
public int getIVSize(){return ivsize;}
@Override
public int getBlockSize(){return bsize;}
@Override
public int getTagSize(){return 0;}
@Override
public void init(int mode, byte[] key, byte[] iv) throws Exception{
byte[] tmp;
if(iv.length>ivsize){
tmp=new byte[ivsize];
System.arraycopy(iv, 0, tmp, 0, tmp.length);
iv=tmp;
}
if(key.length>bsize){
tmp=new byte[bsize];
System.arraycopy(key, 0, tmp, 0, tmp.length);
key=tmp;
}

try{
ParametersWithIV keyspec=new ParametersWithIV(new KeyParameter(key, 0, key.length), iv, 0, iv.length);
cipher=new SICBlockCipher(new CAST5Engine());
cipher.init(mode==ENCRYPT_MODE, keyspec);
}
catch(Exception e){
cipher=null;
throw e;
}
}
@Override
public void update(int foo) throws Exception{
}
@Override
public void update(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception{
cipher.processBytes(foo, s1, len, bar, s2);
}
@Override
public void updateAAD(byte[] foo, int s1, int len) throws Exception{
}
@Override
public void doFinal(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception{
}
@Override
public boolean isCBC(){return false; }
@Override
public boolean isAEAD(){return false; }
@Override
public boolean isChaCha20(){return false; }
}
90 changes: 90 additions & 0 deletions src/main/java/com/jcraft/jsch/bc/HMAC.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
Copyright (c) 2012-2018 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.jcraft.jsch.bc;

import com.jcraft.jsch.MAC;
import org.bouncycastle.crypto.Digest;
import org.bouncycastle.crypto.macs.HMac;
import org.bouncycastle.crypto.params.KeyParameter;

abstract class HMAC implements MAC {
protected String name;
protected int bsize;
protected Digest digest;
protected boolean etm;
private HMac mac;

@Override
public int getBlockSize() {
return bsize;
};

@Override
public void init(byte[] key) throws Exception {
if(key.length>bsize){
byte[] tmp = new byte[bsize];
System.arraycopy(key, 0, tmp, 0, bsize);
key = tmp;
}
KeyParameter skey = new KeyParameter(key, 0, key.length);
mac = new HMac(digest);
mac.init(skey);
}

private final byte[] tmp = new byte[4];
@Override
public void update(int i){
tmp[0] = (byte)(i>>>24);
tmp[1] = (byte)(i>>>16);
tmp[2] = (byte)(i>>>8);
tmp[3] = (byte)i;
update(tmp, 0, 4);
}

@Override
public void update(byte foo[], int s, int l){
mac.update(foo, s, l);
}

@Override
public void doFinal(byte[] buf, int offset){
mac.doFinal(buf, offset);
}

@Override
public String getName(){
return name;
}

@Override
public boolean isEtM(){
return etm;
}
}
40 changes: 40 additions & 0 deletions src/main/java/com/jcraft/jsch/bc/HMACRIPEMD160.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.jcraft.jsch.bc;

import org.bouncycastle.crypto.digests.RIPEMD160Digest;

public class HMACRIPEMD160 extends HMAC {
public HMACRIPEMD160(){
name = "hmac-ripemd160";
bsize = 20;
digest = new RIPEMD160Digest();
}
}
Loading

0 comments on commit f3b6c5c

Please sign in to comment.