Skip to content

Commit

Permalink
#77 attempt to add compatibility with older Bouncy Castle releases.
Browse files Browse the repository at this point in the history
  • Loading branch information
norrisjeremy committed Sep 13, 2021
1 parent 9456e8a commit f5f41bd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* 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
* [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
8 changes: 4 additions & 4 deletions src/main/java/com/jcraft/jsch/bc/ChaCha20Poly1305.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public void init(int mode, byte[] key, byte[] iv) throws Exception{
System.arraycopy(key, 0, K_2, 0, bsize/2);
this.mode=mode;
try{
K_1_spec=new KeyParameter(K_1);
K_2_spec=new KeyParameter(K_2);
K_1_spec=new KeyParameter(K_1, 0, K_1.length);
K_2_spec=new KeyParameter(K_2, 0, K_2.length);
header_cipher=new ChaChaEngine();
main_cipher=new ChaChaEngine();
}
Expand All @@ -85,8 +85,8 @@ public void init(int mode, byte[] key, byte[] iv) throws Exception{
public void update(int foo) throws Exception{
ByteBuffer nonce=ByteBuffer.allocate(8);
nonce.putLong(0, foo);
header_cipher.init(this.mode==ENCRYPT_MODE, new ParametersWithIV(K_1_spec, nonce.array()));
main_cipher.init(this.mode==ENCRYPT_MODE, new ParametersWithIV(K_2_spec, nonce.array()));
header_cipher.init(this.mode==ENCRYPT_MODE, new ParametersWithIV(K_1_spec, nonce.array(), 0, nonce.array().length));
main_cipher.init(this.mode==ENCRYPT_MODE, new ParametersWithIV(K_2_spec, nonce.array(), 0, nonce.array().length));
// Trying to reinit the cipher again with same nonce results in InvalidKeyException
// So just read entire first 64-byte block, which should increment global counter from 0->1
byte[] poly_key = new byte[32];
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/jcraft/jsch/bc/SignatureEdDSA.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ public void init() throws Exception{
public void setPubKey(byte[] y_arr) throws Exception{
try {
if(getAlgo().equals("Ed25519")){
Ed25519PublicKeyParameters pubKey = new Ed25519PublicKeyParameters(y_arr);
Ed25519PublicKeyParameters pubKey = new Ed25519PublicKeyParameters(y_arr, 0);
signature.init(false, pubKey);
}
else{
Ed448PublicKeyParameters pubKey = new Ed448PublicKeyParameters(y_arr);
Ed448PublicKeyParameters pubKey = new Ed448PublicKeyParameters(y_arr, 0);
signature.init(false, pubKey);
}
}
Expand All @@ -80,11 +80,11 @@ public void setPubKey(byte[] y_arr) throws Exception{
public void setPrvKey(byte[] bytes) throws Exception{
try {
if(getAlgo().equals("Ed25519")){
Ed25519PrivateKeyParameters prvKey = new Ed25519PrivateKeyParameters(bytes);
Ed25519PrivateKeyParameters prvKey = new Ed25519PrivateKeyParameters(bytes, 0);
signature.init(true, prvKey);
}
else{
Ed448PrivateKeyParameters prvKey = new Ed448PrivateKeyParameters(bytes);
Ed448PrivateKeyParameters prvKey = new Ed448PrivateKeyParameters(bytes, 0);
signature.init(true, prvKey);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/jcraft/jsch/bc/XDH.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public byte[] getSecret(byte[] Q) throws Exception{
if(name.equals("X25519")){
X25519PublicKeyParameters publicKey = null;
try{
publicKey = new X25519PublicKeyParameters(Q);
publicKey = new X25519PublicKeyParameters(Q, 0);
}
catch(Exception e){
throw new InvalidKeyException(e);
Expand All @@ -86,7 +86,7 @@ public byte[] getSecret(byte[] Q) throws Exception{
else{
X448PublicKeyParameters publicKey = null;
try{
publicKey = new X448PublicKeyParameters(Q);
publicKey = new X448PublicKeyParameters(Q, 0);
}
catch(Exception e){
throw new InvalidKeyException(e);
Expand Down

0 comments on commit f5f41bd

Please sign in to comment.