Skip to content

Commit

Permalink
fix #6: support non standard dh key size by using bouncy castle provider
Browse files Browse the repository at this point in the history
  • Loading branch information
edward.gao committed Jul 26, 2019
1 parent dcbc38b commit 31a45fe
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ sshd server and use port forwarding, X11 forwarding, file transfer, etc., and
you can integrate its functionality into your own Java programs
</description>
<!-- set global properties for this build -->
<property name="version" value="0.1.53"/>
<property name="version" value="0.1.53.2"/>
<property name="src" location="src/main/java/"/>
<property name="exasrc" location="examples"/>
<property name="build" location="build"/>
Expand Down
9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<packaging>jar</packaging>
<version>0.1.53</version>
<version>0.1.53.2</version>
<name>JSch</name>
<url>http://www.jcraft.com/jsch/</url>
<description>JSch is a pure Java implementation of SSH2</description>
Expand Down Expand Up @@ -45,6 +45,13 @@
<version>1.0.7</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk16</artifactId>
<version>1.46</version>
</dependency>

</dependencies>

<build>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/jcraft/jsch/JSch.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class JSch {

config.put("ecdh-sha2-nistp", "com.jcraft.jsch.jce.ECDHN");

config.put(com.jcraft.jsch.jce.DH.KEY_BOUNCY_CASTLE_ENABLE, "true");
config.put("dh", "com.jcraft.jsch.jce.DH");
config.put("3des-cbc", "com.jcraft.jsch.jce.TripleDESCBC");
config.put("blowfish-cbc", "com.jcraft.jsch.jce.BlowfishCBC");
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/com/jcraft/jsch/jce/DH.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING

package com.jcraft.jsch.jce;

import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;

import javax.crypto.KeyAgreement;
Expand All @@ -41,6 +42,9 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
import java.security.PublicKey;

public class DH implements com.jcraft.jsch.DH {

public static final String KEY_BOUNCY_CASTLE_ENABLE = "dh.bouncycastle.enable";

BigInteger p;
BigInteger g;
BigInteger e; // my public key
Expand All @@ -53,7 +57,12 @@ public class DH implements com.jcraft.jsch.DH {
private KeyAgreement myKeyAgree;

public void init() throws Exception {
myKpairGen = KeyPairGenerator.getInstance("DH");
if ("TRUE".equalsIgnoreCase(JSch.getConfig(KEY_BOUNCY_CASTLE_ENABLE))) {
myKpairGen = new org.bouncycastle.jce.provider.JDKKeyPairGenerator.DH();
}
else {
myKpairGen = KeyPairGenerator.getInstance("DH");
}
myKeyAgree = KeyAgreement.getInstance("DH");
}

Expand Down

0 comments on commit 31a45fe

Please sign in to comment.