Skip to content

Commit 39a7be9

Browse files
Set Java 8 as minimum required version (#874)
- Upgraded Bouncy Castle from 1.70 to 1.75 - Upgraded SLF4J from 1.7.36 to 2.0.7 - Upgraded Logback from 1.2.11 to 1.3.8 - Upgraded Apache MINA SSHD from 2.8.0 to 2.10.0 - Upgraded Grizzly HTTP Server from 2.4.4 to 3.0.1 - Upgraded Testcontainers from 1.16.2 to 1.18.3 - Refactored references and removed HttpClient dependency - Upgraded GitHub Actions setup-java from 1 to 3 - Updated GitHub Actions to use Temurin JDK 11 - Added OpenSSL upgrade to RSA Key Tests Co-authored-by: Jeroen van Erp <jeroen@hierynomus.com>
1 parent e7614db commit 39a7be9

File tree

6 files changed

+61
-76
lines changed

6 files changed

+61
-76
lines changed

.github/workflows/gradle.yml

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ name: Build SSHJ
66

77
on:
88
push:
9-
branches: [ master ]
109
pull_request:
1110
branches: [ master ]
1211

1312
jobs:
1413
java12:
15-
name: Build with Java 12
14+
name: Build with Java 11
1615
runs-on: ubuntu-latest
1716
steps:
1817
- uses: actions/checkout@v2
19-
- name: Set up JDK 12
20-
uses: actions/setup-java@v1
18+
- name: Set up Java 11
19+
uses: actions/setup-java@v3
2120
with:
22-
java-version: 12
21+
distribution: 'temurin'
22+
java-version: 11
2323
- name: Grant execute permission for gradlew
2424
run: chmod +x gradlew
2525
- name: Build with Gradle
@@ -29,14 +29,14 @@ jobs:
2929

3030
integration:
3131
name: Integration test
32-
needs: [java12]
33-
runs-on: [ubuntu-latest]
32+
runs-on: ubuntu-latest
3433
steps:
3534
- uses: actions/checkout@v2
3635
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
37-
- uses: actions/setup-java@v1
36+
- uses: actions/setup-java@v3
3837
with:
39-
java-version: 12
38+
distribution: 'temurin'
39+
java-version: 11
4040
- name: Grant execute permission for gradlew
4141
run: chmod +x gradlew
4242
- name: Build with Gradle

README.adoc

+5-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ If you need something that is not included, it shouldn't be too hard to add (do
9595
http://ssh-comparison.quendi.de/comparison.html[SSH Implementation Comparison]
9696

9797
== Dependencies
98-
Java 7+. http://www.slf4j.org/download.html[slf4j] is required. http://www.bouncycastle.org/java.html[bouncycastle] is highly recommended and required for using some of the crypto algorithms.
98+
99+
- Java 8 or higher
100+
- https://www.slf4j.org/[SLF4J 2.0.0]
101+
- https://www.bouncycastle.org[Bouncy Castle]
102+
99103

100104
== Reporting bugs
101105
Issue tracker: https://github.com/hierynomus/sshj/issues

build.gradle

+17-23
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,29 @@ project.version = scmVersion.version
3535

3636
configurations.implementation.transitive = false
3737

38-
def bouncycastleVersion = "1.70"
39-
def sshdVersion = "2.8.0"
38+
def bouncycastleVersion = "1.75"
39+
def sshdVersion = "2.10.0"
4040

4141
dependencies {
42-
implementation "org.slf4j:slf4j-api:1.7.36"
43-
implementation "org.bouncycastle:bcprov-jdk15on:$bouncycastleVersion"
44-
implementation "org.bouncycastle:bcpkix-jdk15on:$bouncycastleVersion"
42+
implementation "org.slf4j:slf4j-api:2.0.7"
43+
implementation "org.bouncycastle:bcprov-jdk18on:$bouncycastleVersion"
44+
implementation "org.bouncycastle:bcpkix-jdk18on:$bouncycastleVersion"
4545
implementation "com.hierynomus:asn-one:0.6.0"
46-
4746
implementation "net.i2p.crypto:eddsa:0.3.0"
4847

49-
testImplementation "junit:junit:4.13.2"
50-
testImplementation 'org.spockframework:spock-core:1.3-groovy-2.4'
51-
testImplementation "org.mockito:mockito-core:4.2.0"
48+
testImplementation(platform("org.junit:junit-bom:5.9.3"))
49+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
50+
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
51+
testImplementation 'junit:junit:4.13.2'
52+
testImplementation 'org.spockframework:spock-core:2.3-groovy-3.0'
53+
testImplementation 'org.spockframework:spock-junit4:2.3-groovy-3.0'
54+
testImplementation "org.mockito:mockito-core:4.11.0"
5255
testImplementation "org.apache.sshd:sshd-core:$sshdVersion"
5356
testImplementation "org.apache.sshd:sshd-sftp:$sshdVersion"
5457
testImplementation "org.apache.sshd:sshd-scp:$sshdVersion"
55-
testImplementation "ch.qos.logback:logback-classic:1.2.11"
56-
testImplementation 'org.glassfish.grizzly:grizzly-http-server:2.4.4'
57-
testImplementation 'org.apache.httpcomponents:httpclient:4.5.13'
58-
testImplementation 'org.testcontainers:testcontainers:1.16.2'
58+
testImplementation "ch.qos.logback:logback-classic:1.3.8"
59+
testImplementation 'org.glassfish.grizzly:grizzly-http-server:3.0.1'
60+
testImplementation 'org.testcontainers:testcontainers:1.18.3'
5961
}
6062

6163
license {
@@ -83,7 +85,7 @@ if (JavaVersion.current().isJava8Compatible()) {
8385
}
8486

8587
compileJava {
86-
options.compilerArgs.addAll(['--release', '7'])
88+
options.compilerArgs.addAll(['--release', '8'])
8789
}
8890

8991
task writeSshjVersionProperties {
@@ -119,7 +121,6 @@ jar {
119121
}
120122
}
121123

122-
123124
java {
124125
withJavadocJar()
125126
withSourcesJar()
@@ -163,14 +164,7 @@ tasks.withType(Test) {
163164
testLogging {
164165
exceptionFormat = 'full'
165166
}
166-
include "**/*Test.*"
167-
include "**/*Spec.*"
168-
if (!project.hasProperty("allTests")) {
169-
useJUnit {
170-
excludeCategories 'com.hierynomus.sshj.test.SlowTests'
171-
excludeCategories 'com.hierynomus.sshj.test.KnownFailingTests'
172-
}
173-
}
167+
useJUnitPlatform()
174168

175169
afterSuite { descriptor, result ->
176170
if (descriptor.className != null) {

src/itest/groovy/com/hierynomus/sshj/RsaShaKeySignatureTest.groovy

+2-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class RsaShaKeySignatureTest extends Specification {
3838

3939
private static void dockerfileBuilder(DockerfileBuilder it, String hostKey, String pubkeyAcceptedAlgorithms) {
4040
it.from("archlinux:base")
41-
it.run('yes | pacman -Sy core/openssh' +
41+
it.run('pacman -Sy --noconfirm core/openssh core/openssl' +
4242
' && (' +
4343
' V=$(echo $(/usr/sbin/sshd -h 2>&1) | grep -o \'OpenSSH_[0-9][0-9]*[.][0-9][0-9]*p[0-9]\');' +
4444
' if [[ "$V" < OpenSSH_8.8p1 ]]; then' +
@@ -61,7 +61,6 @@ class RsaShaKeySignatureTest extends Specification {
6161
'-D',
6262
'-e',
6363
'-f', '/dev/null',
64-
'-o', 'LogLevel=DEBUG2',
6564
'-o', "HostKey=/etc/ssh/$hostKey",
6665
]
6766
if (pubkeyAcceptedAlgorithms != null) {
@@ -130,7 +129,7 @@ class RsaShaKeySignatureTest extends Specification {
130129
}
131130

132131
@Unroll
133-
def "connect to a server with host key #hostkey that supports only ssh-rsa"() {
132+
def "connect to a server with host key #hostKey that supports only ssh-rsa"() {
134133
given:
135134
SshdContainer sshd = makeSshdContainer(hostKey, "ssh-rsa,ssh-ed25519")
136135
sshd.start()

src/test/java/com/hierynomus/sshj/connection/channel/forwarded/LocalPortForwarderTest.java

+18-24
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,28 @@
2121
import net.schmizz.sshj.SSHClient;
2222
import net.schmizz.sshj.connection.channel.direct.LocalPortForwarder;
2323
import net.schmizz.sshj.connection.channel.direct.Parameters;
24-
import org.apache.http.HttpResponse;
25-
import org.apache.http.client.HttpClient;
26-
import org.apache.http.client.methods.HttpGet;
27-
import org.apache.http.impl.client.HttpClientBuilder;
2824
import org.apache.sshd.server.forward.AcceptAllForwardingFilter;
2925
import org.junit.Assert;
3026
import org.junit.Before;
3127
import org.junit.Rule;
3228
import org.junit.Test;
33-
import org.slf4j.Logger;
34-
import org.slf4j.LoggerFactory;
3529

36-
import java.io.*;
30+
import java.io.File;
31+
import java.io.IOException;
32+
import java.io.InputStream;
33+
import java.io.InputStreamReader;
34+
import java.io.OutputStream;
35+
import java.io.PrintWriter;
36+
import java.net.HttpURLConnection;
3737
import java.net.InetSocketAddress;
3838
import java.net.ServerSocket;
3939
import java.net.Socket;
40+
import java.net.URL;
4041

41-
import static org.hamcrest.CoreMatchers.equalTo;
42-
import static org.junit.Assert.assertThat;
42+
import static org.junit.Assert.assertEquals;
4343

4444
public class LocalPortForwarderTest {
45-
private static final Logger log = LoggerFactory.getLogger(LocalPortForwarderTest.class);
45+
private static final String LOCALHOST_URL = "http://127.0.0.1:8080";
4646

4747
@Rule
4848
public SshFixture fixture = new SshFixture();
@@ -59,8 +59,7 @@ public void setUp() throws IOException {
5959

6060
@Test
6161
public void shouldHaveWorkingHttpServer() throws IOException {
62-
// Just to check that we have a working http server...
63-
assertThat(httpGet("127.0.0.1", 8080), equalTo(200));
62+
assertEquals(200, httpGet());
6463
}
6564

6665
@Test
@@ -93,7 +92,6 @@ public void shouldCloseConnectionWhenRemoteServerClosesConnection() throws IOExc
9392
}
9493

9594
public static void httpGetAndAssertConnectionClosedByServer(int port) throws IOException {
96-
System.out.println("HTTP GET to port: " + port);
9795
try (Socket socket = new Socket("localhost", port)) {
9896
// Send a basic HTTP GET
9997
// It returns 400 Bad Request because it's missing a bunch of info, but the HTTP response doesn't matter, we just want to test the connection closing.
@@ -107,12 +105,8 @@ public static void httpGetAndAssertConnectionClosedByServer(int port) throws IOE
107105
InputStream inputStream = socket.getInputStream();
108106
InputStreamReader reader = new InputStreamReader(inputStream);
109107
int buf = -2;
110-
while (true) {
108+
while (buf != -1) {
111109
buf = reader.read();
112-
System.out.print((char)buf);
113-
if (buf == -1) {
114-
break;
115-
}
116110
}
117111

118112
// Attempt to read more. If the server has closed the connection this will return -1
@@ -123,12 +117,12 @@ public static void httpGetAndAssertConnectionClosedByServer(int port) throws IOE
123117
}
124118
}
125119

126-
private int httpGet(String server, int port) throws IOException {
127-
HttpClient client = HttpClientBuilder.create().build();
128-
String urlString = "http://" + server + ":" + port;
129-
log.info("Trying: GET " + urlString);
130-
HttpResponse execute = client.execute(new HttpGet(urlString));
131-
return execute.getStatusLine().getStatusCode();
120+
private int httpGet() throws IOException {
121+
final URL url = new URL(LOCALHOST_URL);
122+
final HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
123+
urlConnection.setConnectTimeout(3000);
124+
urlConnection.setRequestMethod("GET");
125+
return urlConnection.getResponseCode();
132126
}
133127

134128
private SSHClient getFixtureClient() throws IOException {

src/test/java/com/hierynomus/sshj/connection/channel/forwarded/RemotePortForwarderTest.java

+10-16
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,23 @@
2222
import net.schmizz.sshj.connection.ConnectionException;
2323
import net.schmizz.sshj.connection.channel.forwarded.RemotePortForwarder;
2424
import net.schmizz.sshj.connection.channel.forwarded.SocketForwardingConnectListener;
25-
import org.apache.http.HttpResponse;
26-
import org.apache.http.client.HttpClient;
27-
import org.apache.http.client.methods.HttpGet;
28-
import org.apache.http.impl.client.HttpClientBuilder;
2925
import org.apache.sshd.server.forward.AcceptAllForwardingFilter;
3026
import org.junit.Before;
3127
import org.junit.Rule;
3228
import org.junit.Test;
33-
import org.slf4j.Logger;
34-
import org.slf4j.LoggerFactory;
3529

3630
import java.io.File;
3731
import java.io.IOException;
32+
import java.net.HttpURLConnection;
3833
import java.net.InetSocketAddress;
34+
import java.net.URL;
3935

4036
import static org.junit.Assert.assertEquals;
4137

4238
public class RemotePortForwarderTest {
43-
private static final Logger log = LoggerFactory.getLogger(RemotePortForwarderTest.class);
44-
4539
private static final PortRange RANGE = new PortRange(9000, 9999);
4640
private static final String LOCALHOST = "127.0.0.1";
41+
private static final String LOCALHOST_URL_FORMAT = "http://127.0.0.1:%d";
4742
private static final InetSocketAddress HTTP_SERVER_SOCKET_ADDR = new InetSocketAddress(LOCALHOST, 8080);
4843

4944
@Rule
@@ -61,8 +56,7 @@ public void setUp() throws IOException {
6156

6257
@Test
6358
public void shouldHaveWorkingHttpServer() throws IOException {
64-
// Just to check that we have a working http server...
65-
assertEquals(200, httpGet( 8080));
59+
assertEquals(200, httpGet(8080));
6660
}
6761

6862
@Test
@@ -127,12 +121,12 @@ private RemotePortForwarder.Forward forwardPort(SSHClient sshClient, String addr
127121
}
128122
}
129123

130-
private int httpGet(int port) throws IOException {
131-
HttpClient client = HttpClientBuilder.create().build();
132-
String urlString = "http://" + LOCALHOST + ":" + port;
133-
log.info("Trying: GET " + urlString);
134-
HttpResponse execute = client.execute(new HttpGet(urlString));
135-
return execute.getStatusLine().getStatusCode();
124+
private int httpGet(final int port) throws IOException {
125+
final URL url = new URL(String.format(LOCALHOST_URL_FORMAT, port));
126+
final HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
127+
urlConnection.setConnectTimeout(3000);
128+
urlConnection.setRequestMethod("GET");
129+
return urlConnection.getResponseCode();
136130
}
137131

138132
private SSHClient getFixtureClient() throws IOException {

0 commit comments

Comments
 (0)