mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-06 23:30:55 +03:00
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>
This commit is contained in:
18
.github/workflows/gradle.yml
vendored
18
.github/workflows/gradle.yml
vendored
@@ -6,20 +6,20 @@ name: Build SSHJ
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ master ]
|
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ master ]
|
branches: [ master ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
java12:
|
java12:
|
||||||
name: Build with Java 12
|
name: Build with Java 11
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Set up JDK 12
|
- name: Set up Java 11
|
||||||
uses: actions/setup-java@v1
|
uses: actions/setup-java@v3
|
||||||
with:
|
with:
|
||||||
java-version: 12
|
distribution: 'temurin'
|
||||||
|
java-version: 11
|
||||||
- name: Grant execute permission for gradlew
|
- name: Grant execute permission for gradlew
|
||||||
run: chmod +x gradlew
|
run: chmod +x gradlew
|
||||||
- name: Build with Gradle
|
- name: Build with Gradle
|
||||||
@@ -29,14 +29,14 @@ jobs:
|
|||||||
|
|
||||||
integration:
|
integration:
|
||||||
name: Integration test
|
name: Integration test
|
||||||
needs: [java12]
|
runs-on: ubuntu-latest
|
||||||
runs-on: [ubuntu-latest]
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
|
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
|
||||||
- uses: actions/setup-java@v1
|
- uses: actions/setup-java@v3
|
||||||
with:
|
with:
|
||||||
java-version: 12
|
distribution: 'temurin'
|
||||||
|
java-version: 11
|
||||||
- name: Grant execute permission for gradlew
|
- name: Grant execute permission for gradlew
|
||||||
run: chmod +x gradlew
|
run: chmod +x gradlew
|
||||||
- name: Build with Gradle
|
- name: Build with Gradle
|
||||||
|
|||||||
@@ -95,7 +95,11 @@ If you need something that is not included, it shouldn't be too hard to add (do
|
|||||||
http://ssh-comparison.quendi.de/comparison.html[SSH Implementation Comparison]
|
http://ssh-comparison.quendi.de/comparison.html[SSH Implementation Comparison]
|
||||||
|
|
||||||
== Dependencies
|
== Dependencies
|
||||||
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.
|
|
||||||
|
- Java 8 or higher
|
||||||
|
- https://www.slf4j.org/[SLF4J 2.0.0]
|
||||||
|
- https://www.bouncycastle.org[Bouncy Castle]
|
||||||
|
|
||||||
|
|
||||||
== Reporting bugs
|
== Reporting bugs
|
||||||
Issue tracker: https://github.com/hierynomus/sshj/issues
|
Issue tracker: https://github.com/hierynomus/sshj/issues
|
||||||
|
|||||||
40
build.gradle
40
build.gradle
@@ -35,27 +35,29 @@ project.version = scmVersion.version
|
|||||||
|
|
||||||
configurations.implementation.transitive = false
|
configurations.implementation.transitive = false
|
||||||
|
|
||||||
def bouncycastleVersion = "1.70"
|
def bouncycastleVersion = "1.75"
|
||||||
def sshdVersion = "2.8.0"
|
def sshdVersion = "2.10.0"
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "org.slf4j:slf4j-api:1.7.36"
|
implementation "org.slf4j:slf4j-api:2.0.7"
|
||||||
implementation "org.bouncycastle:bcprov-jdk15on:$bouncycastleVersion"
|
implementation "org.bouncycastle:bcprov-jdk18on:$bouncycastleVersion"
|
||||||
implementation "org.bouncycastle:bcpkix-jdk15on:$bouncycastleVersion"
|
implementation "org.bouncycastle:bcpkix-jdk18on:$bouncycastleVersion"
|
||||||
implementation "com.hierynomus:asn-one:0.6.0"
|
implementation "com.hierynomus:asn-one:0.6.0"
|
||||||
|
|
||||||
implementation "net.i2p.crypto:eddsa:0.3.0"
|
implementation "net.i2p.crypto:eddsa:0.3.0"
|
||||||
|
|
||||||
testImplementation "junit:junit:4.13.2"
|
testImplementation(platform("org.junit:junit-bom:5.9.3"))
|
||||||
testImplementation 'org.spockframework:spock-core:1.3-groovy-2.4'
|
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
|
||||||
testImplementation "org.mockito:mockito-core:4.2.0"
|
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
|
||||||
|
testImplementation 'junit:junit:4.13.2'
|
||||||
|
testImplementation 'org.spockframework:spock-core:2.3-groovy-3.0'
|
||||||
|
testImplementation 'org.spockframework:spock-junit4:2.3-groovy-3.0'
|
||||||
|
testImplementation "org.mockito:mockito-core:4.11.0"
|
||||||
testImplementation "org.apache.sshd:sshd-core:$sshdVersion"
|
testImplementation "org.apache.sshd:sshd-core:$sshdVersion"
|
||||||
testImplementation "org.apache.sshd:sshd-sftp:$sshdVersion"
|
testImplementation "org.apache.sshd:sshd-sftp:$sshdVersion"
|
||||||
testImplementation "org.apache.sshd:sshd-scp:$sshdVersion"
|
testImplementation "org.apache.sshd:sshd-scp:$sshdVersion"
|
||||||
testImplementation "ch.qos.logback:logback-classic:1.2.11"
|
testImplementation "ch.qos.logback:logback-classic:1.3.8"
|
||||||
testImplementation 'org.glassfish.grizzly:grizzly-http-server:2.4.4'
|
testImplementation 'org.glassfish.grizzly:grizzly-http-server:3.0.1'
|
||||||
testImplementation 'org.apache.httpcomponents:httpclient:4.5.13'
|
testImplementation 'org.testcontainers:testcontainers:1.18.3'
|
||||||
testImplementation 'org.testcontainers:testcontainers:1.16.2'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
license {
|
license {
|
||||||
@@ -83,7 +85,7 @@ if (JavaVersion.current().isJava8Compatible()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
compileJava {
|
compileJava {
|
||||||
options.compilerArgs.addAll(['--release', '7'])
|
options.compilerArgs.addAll(['--release', '8'])
|
||||||
}
|
}
|
||||||
|
|
||||||
task writeSshjVersionProperties {
|
task writeSshjVersionProperties {
|
||||||
@@ -119,7 +121,6 @@ jar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
java {
|
java {
|
||||||
withJavadocJar()
|
withJavadocJar()
|
||||||
withSourcesJar()
|
withSourcesJar()
|
||||||
@@ -163,14 +164,7 @@ tasks.withType(Test) {
|
|||||||
testLogging {
|
testLogging {
|
||||||
exceptionFormat = 'full'
|
exceptionFormat = 'full'
|
||||||
}
|
}
|
||||||
include "**/*Test.*"
|
useJUnitPlatform()
|
||||||
include "**/*Spec.*"
|
|
||||||
if (!project.hasProperty("allTests")) {
|
|
||||||
useJUnit {
|
|
||||||
excludeCategories 'com.hierynomus.sshj.test.SlowTests'
|
|
||||||
excludeCategories 'com.hierynomus.sshj.test.KnownFailingTests'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
afterSuite { descriptor, result ->
|
afterSuite { descriptor, result ->
|
||||||
if (descriptor.className != null) {
|
if (descriptor.className != null) {
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ class RsaShaKeySignatureTest extends Specification {
|
|||||||
|
|
||||||
private static void dockerfileBuilder(DockerfileBuilder it, String hostKey, String pubkeyAcceptedAlgorithms) {
|
private static void dockerfileBuilder(DockerfileBuilder it, String hostKey, String pubkeyAcceptedAlgorithms) {
|
||||||
it.from("archlinux:base")
|
it.from("archlinux:base")
|
||||||
it.run('yes | pacman -Sy core/openssh' +
|
it.run('pacman -Sy --noconfirm core/openssh core/openssl' +
|
||||||
' && (' +
|
' && (' +
|
||||||
' V=$(echo $(/usr/sbin/sshd -h 2>&1) | grep -o \'OpenSSH_[0-9][0-9]*[.][0-9][0-9]*p[0-9]\');' +
|
' V=$(echo $(/usr/sbin/sshd -h 2>&1) | grep -o \'OpenSSH_[0-9][0-9]*[.][0-9][0-9]*p[0-9]\');' +
|
||||||
' if [[ "$V" < OpenSSH_8.8p1 ]]; then' +
|
' if [[ "$V" < OpenSSH_8.8p1 ]]; then' +
|
||||||
@@ -61,7 +61,6 @@ class RsaShaKeySignatureTest extends Specification {
|
|||||||
'-D',
|
'-D',
|
||||||
'-e',
|
'-e',
|
||||||
'-f', '/dev/null',
|
'-f', '/dev/null',
|
||||||
'-o', 'LogLevel=DEBUG2',
|
|
||||||
'-o', "HostKey=/etc/ssh/$hostKey",
|
'-o', "HostKey=/etc/ssh/$hostKey",
|
||||||
]
|
]
|
||||||
if (pubkeyAcceptedAlgorithms != null) {
|
if (pubkeyAcceptedAlgorithms != null) {
|
||||||
@@ -130,7 +129,7 @@ class RsaShaKeySignatureTest extends Specification {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Unroll
|
@Unroll
|
||||||
def "connect to a server with host key #hostkey that supports only ssh-rsa"() {
|
def "connect to a server with host key #hostKey that supports only ssh-rsa"() {
|
||||||
given:
|
given:
|
||||||
SshdContainer sshd = makeSshdContainer(hostKey, "ssh-rsa,ssh-ed25519")
|
SshdContainer sshd = makeSshdContainer(hostKey, "ssh-rsa,ssh-ed25519")
|
||||||
sshd.start()
|
sshd.start()
|
||||||
|
|||||||
@@ -21,28 +21,28 @@ import com.hierynomus.sshj.test.util.FileUtil;
|
|||||||
import net.schmizz.sshj.SSHClient;
|
import net.schmizz.sshj.SSHClient;
|
||||||
import net.schmizz.sshj.connection.channel.direct.LocalPortForwarder;
|
import net.schmizz.sshj.connection.channel.direct.LocalPortForwarder;
|
||||||
import net.schmizz.sshj.connection.channel.direct.Parameters;
|
import net.schmizz.sshj.connection.channel.direct.Parameters;
|
||||||
import org.apache.http.HttpResponse;
|
|
||||||
import org.apache.http.client.HttpClient;
|
|
||||||
import org.apache.http.client.methods.HttpGet;
|
|
||||||
import org.apache.http.impl.client.HttpClientBuilder;
|
|
||||||
import org.apache.sshd.server.forward.AcceptAllForwardingFilter;
|
import org.apache.sshd.server.forward.AcceptAllForwardingFilter;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.equalTo;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
public class LocalPortForwarderTest {
|
public class LocalPortForwarderTest {
|
||||||
private static final Logger log = LoggerFactory.getLogger(LocalPortForwarderTest.class);
|
private static final String LOCALHOST_URL = "http://127.0.0.1:8080";
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public SshFixture fixture = new SshFixture();
|
public SshFixture fixture = new SshFixture();
|
||||||
@@ -59,8 +59,7 @@ public class LocalPortForwarderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldHaveWorkingHttpServer() throws IOException {
|
public void shouldHaveWorkingHttpServer() throws IOException {
|
||||||
// Just to check that we have a working http server...
|
assertEquals(200, httpGet());
|
||||||
assertThat(httpGet("127.0.0.1", 8080), equalTo(200));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -93,7 +92,6 @@ public class LocalPortForwarderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void httpGetAndAssertConnectionClosedByServer(int port) throws IOException {
|
public static void httpGetAndAssertConnectionClosedByServer(int port) throws IOException {
|
||||||
System.out.println("HTTP GET to port: " + port);
|
|
||||||
try (Socket socket = new Socket("localhost", port)) {
|
try (Socket socket = new Socket("localhost", port)) {
|
||||||
// Send a basic HTTP GET
|
// Send a basic HTTP GET
|
||||||
// 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.
|
// 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 class LocalPortForwarderTest {
|
|||||||
InputStream inputStream = socket.getInputStream();
|
InputStream inputStream = socket.getInputStream();
|
||||||
InputStreamReader reader = new InputStreamReader(inputStream);
|
InputStreamReader reader = new InputStreamReader(inputStream);
|
||||||
int buf = -2;
|
int buf = -2;
|
||||||
while (true) {
|
while (buf != -1) {
|
||||||
buf = reader.read();
|
buf = reader.read();
|
||||||
System.out.print((char)buf);
|
|
||||||
if (buf == -1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to read more. If the server has closed the connection this will return -1
|
// Attempt to read more. If the server has closed the connection this will return -1
|
||||||
@@ -123,12 +117,12 @@ public class LocalPortForwarderTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int httpGet(String server, int port) throws IOException {
|
private int httpGet() throws IOException {
|
||||||
HttpClient client = HttpClientBuilder.create().build();
|
final URL url = new URL(LOCALHOST_URL);
|
||||||
String urlString = "http://" + server + ":" + port;
|
final HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
|
||||||
log.info("Trying: GET " + urlString);
|
urlConnection.setConnectTimeout(3000);
|
||||||
HttpResponse execute = client.execute(new HttpGet(urlString));
|
urlConnection.setRequestMethod("GET");
|
||||||
return execute.getStatusLine().getStatusCode();
|
return urlConnection.getResponseCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
private SSHClient getFixtureClient() throws IOException {
|
private SSHClient getFixtureClient() throws IOException {
|
||||||
|
|||||||
@@ -22,28 +22,23 @@ import net.schmizz.sshj.SSHClient;
|
|||||||
import net.schmizz.sshj.connection.ConnectionException;
|
import net.schmizz.sshj.connection.ConnectionException;
|
||||||
import net.schmizz.sshj.connection.channel.forwarded.RemotePortForwarder;
|
import net.schmizz.sshj.connection.channel.forwarded.RemotePortForwarder;
|
||||||
import net.schmizz.sshj.connection.channel.forwarded.SocketForwardingConnectListener;
|
import net.schmizz.sshj.connection.channel.forwarded.SocketForwardingConnectListener;
|
||||||
import org.apache.http.HttpResponse;
|
|
||||||
import org.apache.http.client.HttpClient;
|
|
||||||
import org.apache.http.client.methods.HttpGet;
|
|
||||||
import org.apache.http.impl.client.HttpClientBuilder;
|
|
||||||
import org.apache.sshd.server.forward.AcceptAllForwardingFilter;
|
import org.apache.sshd.server.forward.AcceptAllForwardingFilter;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class RemotePortForwarderTest {
|
public class RemotePortForwarderTest {
|
||||||
private static final Logger log = LoggerFactory.getLogger(RemotePortForwarderTest.class);
|
|
||||||
|
|
||||||
private static final PortRange RANGE = new PortRange(9000, 9999);
|
private static final PortRange RANGE = new PortRange(9000, 9999);
|
||||||
private static final String LOCALHOST = "127.0.0.1";
|
private static final String LOCALHOST = "127.0.0.1";
|
||||||
|
private static final String LOCALHOST_URL_FORMAT = "http://127.0.0.1:%d";
|
||||||
private static final InetSocketAddress HTTP_SERVER_SOCKET_ADDR = new InetSocketAddress(LOCALHOST, 8080);
|
private static final InetSocketAddress HTTP_SERVER_SOCKET_ADDR = new InetSocketAddress(LOCALHOST, 8080);
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
@@ -61,8 +56,7 @@ public class RemotePortForwarderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldHaveWorkingHttpServer() throws IOException {
|
public void shouldHaveWorkingHttpServer() throws IOException {
|
||||||
// Just to check that we have a working http server...
|
assertEquals(200, httpGet(8080));
|
||||||
assertEquals(200, httpGet( 8080));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -127,12 +121,12 @@ public class RemotePortForwarderTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int httpGet(int port) throws IOException {
|
private int httpGet(final int port) throws IOException {
|
||||||
HttpClient client = HttpClientBuilder.create().build();
|
final URL url = new URL(String.format(LOCALHOST_URL_FORMAT, port));
|
||||||
String urlString = "http://" + LOCALHOST + ":" + port;
|
final HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
|
||||||
log.info("Trying: GET " + urlString);
|
urlConnection.setConnectTimeout(3000);
|
||||||
HttpResponse execute = client.execute(new HttpGet(urlString));
|
urlConnection.setRequestMethod("GET");
|
||||||
return execute.getStatusLine().getStatusCode();
|
return urlConnection.getResponseCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
private SSHClient getFixtureClient() throws IOException {
|
private SSHClient getFixtureClient() throws IOException {
|
||||||
|
|||||||
Reference in New Issue
Block a user