Skip to content

Commit

Permalink
Merge pull request #363 from norrisjeremy/20230721
Browse files Browse the repository at this point in the history
0.2.10 changes
  • Loading branch information
mwiede authored Jul 26, 2023
2 parents 1060a4d + 5746922 commit 7c96ac8
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 35 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
* [0.2.10](https://github.com/mwiede/jsch/releases/tag/jsch-0.2.10)
* Fix new Java 21 compiler warning: `possible 'this' escape before subclass is fully initialized`.
* Tweak OSGi bundle manifest to allow Log4j 3.
* [#362](https://github.com/mwiede/jsch/issues/362) fix PEM key parsing to work with windows line endings.
* [#361](https://github.com/mwiede/jsch/issues/361) guard against `UIKeyboardInteractive` implementations that include NULL elements in the `String[]` returned from `promptKeyboardInteractive()`.
* Add a default implmentation of the deprecated `decrypt()` method to the `Identity` interface that throws an `UnsupportedOperationException`.
* [0.2.9](https://github.com/mwiede/jsch/releases/tag/jsch-0.2.9)
* [#293](https://github.com/mwiede/jsch/issues/293) allow UserAuthNone to be extended.
* Make JGSS module optional.
Expand Down
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.kohlschutter.junixsocket</groupId>
<artifactId>junixsocket-native-common</artifactId>
<version>${junixsocket.version}</version>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.13.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>32.1.1-jre</version>
<groupId>com.kohlschutter.junixsocket</groupId>
<artifactId>junixsocket-native-common</artifactId>
<version>${junixsocket.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/com/jcraft/jsch/AgentIdentity.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ public byte[] getSignature(byte[] data, String alg) {
return agent.sign(blob, data, alg);
}

@Override
@Deprecated
public boolean decrypt() {
throw new RuntimeException("not implemented");
}

@Override
public String getAlgName() {
return algname;
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/com/jcraft/jsch/Identity.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,30 @@ public default byte[] getSignature(byte[] data, String alg) {
}

/**
* This method is deprecated and the default implmentation of this method will throw an
* {@link UnsupportedOperationException}.
*
* @deprecated The decryption should be done automatically in {@link #setPassphrase(byte[])}
* @return <code>true</code> if the decryption is succeeded or this identity is not cyphered.
* @see #setPassphrase(byte[])
*/
@Deprecated
public boolean decrypt();
public default boolean decrypt() {
throw new UnsupportedOperationException("not implemented");
}

/**
* Returns the name of the key algorithm.
*
* @return "ssh-rsa" or "ssh-dss"
* @return the name of the key algorithm
*/
public String getAlgName();

/**
* Returns the name of this identity. It will be useful to identify this object in the
* {@link IdentityRepository}.
*
* @return the name of this identity
*/
public String getName();

Expand Down
19 changes: 5 additions & 14 deletions src/main/java/com/jcraft/jsch/IdentityFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static IdentityFile newInstance(String name, byte[] prvkey, byte[] pubkey,
return new IdentityFile(name, kpair);
}

private IdentityFile(String name, KeyPair kpair) throws JSchException {
private IdentityFile(String name, KeyPair kpair) {
this.identity = name;
this.kpair = kpair;
}
Expand Down Expand Up @@ -94,30 +94,21 @@ public byte[] getSignature(byte[] data, String alg) {
return kpair.getSignature(data, alg);
}

/**
* @deprecated This method should not be invoked.
* @see #setPassphrase(byte[] passphrase)
*/
@Override
@Deprecated
public boolean decrypt() {
throw new RuntimeException("not implemented");
}

/**
* Returns the name of the key algorithm.
*
* @return "ssh-rsa" or "ssh-dss"
* @return the name of the key algorithm
*/
@Override
public String getAlgName() {
byte[] name = kpair.getKeyTypeName();
return Util.byte2str(name);
return kpair.getKeyTypeString();
}

/**
* Returns the name of this identity. It will be useful to identify this object in the
* {@link IdentityRepository}.
*
* @return the name of this identity
*/
@Override
public String getName() {
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/com/jcraft/jsch/KeyPair.java
Original file line number Diff line number Diff line change
Expand Up @@ -891,15 +891,18 @@ static KeyPair load(JSch.InstanceLogger instLogger, byte[] prvkey, byte[] pubkey

start = 0;
i = 0;
int xds = 0;

int _len = _buf.length;
while (i < _len) {
if (_buf[i] == '\n') {
boolean xd = (_buf[i - 1] == '\r');
// ignore \n (or \r\n)
System.arraycopy(_buf, i + 1, _buf, i - (xd ? 1 : 0), _len - (i + 1));
if (xd)
if (xd) {
_len--;
xds++;
}
_len--;
continue;
}
Expand All @@ -909,8 +912,8 @@ static KeyPair load(JSch.InstanceLogger instLogger, byte[] prvkey, byte[] pubkey
i++;
}

if (i - start > 0)
data = Util.fromBase64(_buf, start, i - start);
if (i - xds - start > 0)
data = Util.fromBase64(_buf, start, i - xds - start);

Util.bzero(_buf);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public boolean start(Session session) throws Exception {
if (_response != null) {
response = new byte[_response.length][];
for (int i = 0; i < _response.length; i++) {
response[i] = Util.str2byte(_response[i]);
response[i] = _response[i] != null ? Util.str2byte(_response[i]) : Util.empty;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jcraft/jsch/UserAuthPassword.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public boolean start(Session session) throws Exception {
throw new JSchAuthCancelException("password");
}

byte[] newpassword = Util.str2byte(response[0]);
byte[] newpassword = response[0] != null ? Util.str2byte(response[0]) : Util.empty;

// send
// byte SSH_MSG_USERAUTH_REQUEST(50)
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/jcraft/jsch/AbstractBufferMargin.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.github.valfirst.slf4jtest.LoggingEvent;
import com.github.valfirst.slf4jtest.TestLogger;
import com.github.valfirst.slf4jtest.TestLoggerFactory;
import com.google.common.io.ByteStreams;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand All @@ -17,6 +16,7 @@
import java.util.List;
import java.util.Random;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.input.BoundedInputStream;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -209,7 +209,7 @@ private void doScp(Session session, boolean debugException) throws Exception {
byte[] buf = new byte[17];
is.read(buf, 0, 17);
sendAck(os);
Files.copy(ByteStreams.limit(is, 100L * 1024L), out);
Files.copy(new BoundedInputStream(is, 100L * 1024L), out);
checkAck(is);
sendAck(os);
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/jcraft/jsch/KeyPairTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ static Stream<Arguments> keyArgs() {
Arguments.of("docker/ssh_host_dsa_key", null, "ssh-dss"),
// encrypted dsa
Arguments.of("encrypted_openssh_private_key_dsa", "secret123", "ssh-dss"),
// unencrypted RSA with windows (\r\n) line endings
Arguments.of("issue362_rsa", null, "ssh-rsa"),
// ecdsa EC private key format
Arguments.of("docker/id_ecdsa256", null, "ecdsa-sha2-nistp256"), //
Arguments.of("docker/id_ecdsa384", null, "ecdsa-sha2-nistp384"), //
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/docker/authorized_keys.KeyPairIT
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDNVEfQu64p2GczvWj0AlncuNG+PzPd0jZ1/hfx/JDz
ssh-dss AAAAB3NzaC1kc3MAAACBAKCQzxCEIM7yb5fbSmuJCz/+v40WEbULx4JKCXBb7zmRtDtweBqUJXDM1bMjQ4VwGB1EkfMZJQR7rPrOAxfdMdCpkqgPR0+xlljZLVarSJHwt1KR9EudUjUdD2ZrPlvPlG1sAyvMVTK5KCx2QaS2Bn/gukx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zODQAAAAIbmlzdHAzODQAAABhBPKyvhX/3Q32EEhZKF6s+fEzfQwabsSpXgFJ2LwpGxKFxzE2jw4Nvwe9W3YbPyrZU6K2MMA7p7ZdJwdDP/tQ9dhttOGGSkea9Cq4dcdgC9cdBuQ4aGb8crmY3Z5wc1dPxQ== test
ecdsa-sha2-nistp521 AAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAAAIbmlzdHA1MjEAAACFBAG3XTlAFoQd4iIBt5KoTHJk46v1AdZSd+wfCSpc2/GCzHNGVqidrKCrypszpkQOW6vYG8riilyfF36rJa9ipjR+5gDApLIe/ix1Fknr8MU6nWoYv2+NBTsEcaS/VTeiUuMKftMtlO2wOaWFcbZBQUAlb3LDnpMyYKCqIXhhl4vqCxBukg== test
Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/issue362_rsa
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEA2Pt9umdG1Dp/JGFHN/fT9pq+xIdBOzXPcz67/NAdOcpH5rAjNOd0ohmEIMD+Wgc2ZPNz3VnWCCtdlPXjuVs08E9qaPT62U9AL7ARp1OzJM0kpV1+/XvRC2xmDVleA2n0/1R8VcArqHLRu1ylKKxgN2R8Rm4TVsqP/uizcMgjHMX6Y6QnpSVp+DE8BarNA1ZnuEdksvi2lYNzb+VW24tu3CGwPujq4rdmow1FAhyb3EJaRqzOsfcNM27eKVCOshzwhyCKmRD849dvORghemUM4tEzBH+MB7QPHzdV4J9bwcPiBJKwAJ0FHk1jkdZ3OggxRBk5cmJSLs+t+COAcH4QZQIDAQABAoIBAGcA5AuEEWyYJFkZ0Nwxyq6LgTn8VywLfGJiCo2WIfmYHA/X1666nXSCFmYSF+yW9exwYbVXezI/m9ol7CfGs1fM61/Nw/M7GuZId+jt4+H5fIb/3lPo3jDFEaEOpoGKYCKBcdCnPFJnx0ZhUYoAYmCJVDF++bE+0aKZxu0oJPr35Lda1hBeCfrb8fDReAAU71jIoOGyuSyOXlCVyT+OmBhVme0u2xDpdY8cd5t9YueTK7BFNjNt3sJOI4L+2wRskNwxqHCrECtuOXmzEyza7vqo8cjRGSx1HZfqhoKgiRpRkRmSi8p+X1+DZOVZuCxc3BTZ7WrPgVZhu7u9hsISKyECgYEA+C9ajUNsx7Hx9gOg6Zvr+zV461PjKI/0n9g0DTZ5RHdcAfeNs3ugmsiDK6b9SayUW08EVyveJ1OJjT/NPvdP0/KhCAjUt+kN0j9f9CPdHKEWoboDca8u67dayOAhC10mNhoAp3tFQryfgpb678GIzqnXkVjGgyWC/8Z81AN7uAkCgYEA39CcJAUVMc6FigTwoMOkdOgNK6qCxAxkNBTdfB/cBBtG3h8g49n0u/fAMjkfL6awdl53j3jVCP4pUZgSSqArLb0aGo84G2vP92iN3d3j/kPiox22w8KG2XR7tHLWcc+CFfk8mdiKdPFxaWVQaYJ6htGq9LGqY3sw5lVzmk0wlH0CgYEAuWim/WGhoo4NdPzA+cTCRqlr7GJ/EY558fBS8ov/jGafFdkawztYgEnLtJDMKH4FVzFwzK65CCggWqWPb7rSqERaiOYQBFTXPnqZ9InWZczyW1/bstJs+yu/ZtIJ3bN5GHHUi0pMM882Wxjv3q12xu2bXbo0k0Uy2GIwXzM6+gECgYBDByur0eXeC7aMdhxGWTEoXdKL8D3HTtq3ikQmhzgR9sVLglEMS9rybCkgIWFImQgh+vqdehd64Pso130q4jrsMMTfjWLFO42Fz8ck2e4M2PHH3f89M0XFXBAsI3Q7k2SnBgRzIpmcmi5X3SKu5oehVqt3KroXnu4vHQpI/LL+1QKBgD3zxf795zFXw53iZXtKkzYNQhEMVRzbx6dQE+tguB0YCb2vPvYaxfejg/02hCQ4twIMuMK18v0Y9W7E34C0m++lP8UbnHdR0Dsg9ryH7OlUMp4662060HWDnDy79swB/Nnk9dxf+BoPIXGny84bEpk6cLoiHuL6TRpQhuJ292DW
-----END RSA PRIVATE KEY-----
1 change: 1 addition & 0 deletions src/test/resources/issue362_rsa.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDY+326Z0bUOn8kYUc399P2mr7Eh0E7Nc9zPrv80B05ykfmsCM053SiGYQgwP5aBzZk83PdWdYIK12U9eO5WzTwT2po9PrZT0AvsBGnU7MkzSSlXX79e9ELbGYNWV4DafT/VHxVwCuoctG7XKUorGA3ZHxGbhNWyo/+6LNwyCMcxfpjpCelJWn4MTwFqs0DVme4R2Sy+LaVg3Nv5Vbbi27cIbA+6Orit2ajDUUCHJvcQlpGrM6x9w0zbt4pUI6yHPCHIIqZEPzj1285GCF6ZQzi0TMEf4wHtA8fN1Xgn1vBw+IEkrAAnQUeTWOR1nc6CDFEGTlyYlIuz634I4BwfhBl test

0 comments on commit 7c96ac8

Please sign in to comment.