From 49e64398f77f1a297b02c624421a626dd4e043a0 Mon Sep 17 00:00:00 2001 From: starlet-dx <15929766099@163.com> Date: Sat, 26 Nov 2022 10:01:47 +0800 Subject: [PATCH] Fix build error (cherry picked from commit a3f5fda396b285a939b89e3c8202f9ae39eccfcf) --- Fix-build-error.patch | 457 ++++++++++++++++++++++++++++++++++++++++++ sshj.spec | 8 +- 2 files changed, 463 insertions(+), 2 deletions(-) create mode 100644 Fix-build-error.patch diff --git a/Fix-build-error.patch b/Fix-build-error.patch new file mode 100644 index 0000000..21530ce --- /dev/null +++ b/Fix-build-error.patch @@ -0,0 +1,457 @@ +From 8e1d0ce4f6a11a0d32d49616fdd73a18795fa1db Mon Sep 17 00:00:00 2001 +From: starlet-dx <15929766099@163.com> +Date: Sat, 26 Nov 2022 09:58:19 +0800 +Subject: [PATCH 1/1] Fix build error + +--- + build.gradle | 2 +- + .../java/net/schmizz/sshj/common/KeyType.java | 2 +- + .../hierynomus/sshj/sftp/SFTPClientTest.java | 2 + + .../com/hierynomus/sshj/test/SshFixture.java | 46 +++--- + .../net/schmizz/sshj/LoadsOfConnects.java | 10 +- + src/test/java/net/schmizz/sshj/SmokeTest.java | 12 +- + .../net/schmizz/sshj/util/BasicFixture.java | 155 ------------------ + .../sshj/util/BogusPasswordAuthenticator.java | 45 ----- + 8 files changed, 39 insertions(+), 235 deletions(-) + delete mode 100644 src/test/java/net/schmizz/sshj/util/BasicFixture.java + delete mode 100644 src/test/java/net/schmizz/sshj/util/BogusPasswordAuthenticator.java + +diff --git a/build.gradle b/build.gradle +index 4b0727d..09ededd 100644 +--- a/build.gradle ++++ b/build.gradle +@@ -50,7 +50,7 @@ dependencies { + + testCompile "junit:junit:4.11" + testCompile "org.mockito:mockito-core:1.9.5" +- testCompile "org.apache.sshd:sshd-core:0.11.0" ++ testCompile "org.apache.sshd:sshd-core:1.0.0" + testRuntime "ch.qos.logback:logback-classic:1.1.2" + } + +diff --git a/src/main/java/net/schmizz/sshj/common/KeyType.java b/src/main/java/net/schmizz/sshj/common/KeyType.java +index 099480e..a5ace6b 100644 +--- a/src/main/java/net/schmizz/sshj/common/KeyType.java ++++ b/src/main/java/net/schmizz/sshj/common/KeyType.java +@@ -135,7 +135,7 @@ public enum KeyType { + BigInteger bigY = new BigInteger(1, y); + + X9ECParameters ecParams = NISTNamedCurves.getByName("p-256"); +- ECPoint pPublicPoint = ecParams.getCurve().createPoint(bigX, bigY, false); ++ ECPoint pPublicPoint = ecParams.getCurve().createPoint(bigX, bigY); + ECParameterSpec spec = new ECParameterSpec(ecParams.getCurve(), + ecParams.getG(), ecParams.getN()); + ECPublicKeySpec publicSpec = new ECPublicKeySpec(pPublicPoint, spec); +diff --git a/src/test/java/com/hierynomus/sshj/sftp/SFTPClientTest.java b/src/test/java/com/hierynomus/sshj/sftp/SFTPClientTest.java +index 99abeff..3759136 100644 +--- a/src/test/java/com/hierynomus/sshj/sftp/SFTPClientTest.java ++++ b/src/test/java/com/hierynomus/sshj/sftp/SFTPClientTest.java +@@ -24,6 +24,8 @@ public class SFTPClientTest { + SSHClient sshClient = fixture.setupConnectedDefaultClient(); + sshClient.authPassword("test", "test"); + SFTPClient sftpClient = sshClient.newSFTPClient(); ++ // TODO workaround for bug in Mina 1.0.0 --> Should be fixed in 1.1.0 ++ sftpClient.getFileTransfer().setPreserveAttributes(false); + File file = temp.newFile("source.txt"); + FileUtil.writeToFile(file, "This is the source"); + try { +diff --git a/src/test/java/com/hierynomus/sshj/test/SshFixture.java b/src/test/java/com/hierynomus/sshj/test/SshFixture.java +index 4f18b97..b443783 100644 +--- a/src/test/java/com/hierynomus/sshj/test/SshFixture.java ++++ b/src/test/java/com/hierynomus/sshj/test/SshFixture.java +@@ -3,21 +3,19 @@ package com.hierynomus.sshj.test; + import net.schmizz.sshj.Config; + import net.schmizz.sshj.DefaultConfig; + import net.schmizz.sshj.SSHClient; +-import net.schmizz.sshj.transport.TransportException; +-import net.schmizz.sshj.userauth.UserAuthException; + import net.schmizz.sshj.util.gss.BogusGSSAuthenticator; +-import org.apache.sshd.SshServer; + import org.apache.sshd.common.NamedFactory; +-import org.apache.sshd.common.keyprovider.FileKeyPairProvider; ++import org.apache.sshd.common.keyprovider.AbstractClassLoadableResourceKeyPairProvider; + import org.apache.sshd.common.util.OsUtils; ++import org.apache.sshd.common.util.SecurityUtils; + import org.apache.sshd.server.Command; + import org.apache.sshd.server.CommandFactory; +-import org.apache.sshd.server.PasswordAuthenticator; +-import org.apache.sshd.server.channel.ChannelSession; ++import org.apache.sshd.server.SshServer; ++import org.apache.sshd.server.auth.password.PasswordAuthenticator; + import org.apache.sshd.server.command.ScpCommandFactory; + import org.apache.sshd.server.session.ServerSession; +-import org.apache.sshd.server.sftp.SftpSubsystem; + import org.apache.sshd.server.shell.ProcessShellFactory; ++import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory; + import org.junit.rules.ExternalResource; + + import java.io.IOException; +@@ -31,7 +29,7 @@ import java.util.concurrent.atomic.AtomicBoolean; + * Can be used as a rule to ensure the server is teared down after each test. + */ + public class SshFixture extends ExternalResource { +- public static final String hostkey = "src/test/resources/hostkey.pem"; ++ public static final String hostkey = "hostkey.pem"; + public static final String fingerprint = "ce:a7:c1:cf:17:3f:96:49:6a:53:1a:05:0b:ba:90:db"; + + private SshServer server = defaultSshServer(); +@@ -60,8 +58,9 @@ public class SshFixture extends ExternalResource { + } + + public void start() throws IOException { +- server.start(); +- started.set(true); ++ if (!started.getAndSet(true)) { ++ server.start(); ++ } + } + + public SSHClient setupConnectedDefaultClient() throws IOException { +@@ -96,7 +95,9 @@ public class SshFixture extends ExternalResource { + private SshServer defaultSshServer() { + SshServer sshServer = SshServer.setUpDefaultServer(); + sshServer.setPort(randomPort()); +- sshServer.setKeyPairProvider(new FileKeyPairProvider(new String[]{hostkey})); ++ AbstractClassLoadableResourceKeyPairProvider fileKeyPairProvider = SecurityUtils.createClassLoadableResourceKeyPairProvider(); ++ fileKeyPairProvider.setResources(Collections.singletonList(hostkey)); ++ sshServer.setKeyPairProvider(fileKeyPairProvider); + sshServer.setPasswordAuthenticator(new PasswordAuthenticator() { + @Override + public boolean authenticate(String username, String password, ServerSession session) { +@@ -104,18 +105,15 @@ public class SshFixture extends ExternalResource { + } + }); + sshServer.setGSSAuthenticator(new BogusGSSAuthenticator()); +- sshServer.setSubsystemFactories(Arrays.>asList(new SftpSubsystem.Factory())); +- sshServer.setCommandFactory(new ScpCommandFactory(new CommandFactory() { ++ sshServer.setSubsystemFactories(Arrays.>asList(new SftpSubsystemFactory())); ++ ScpCommandFactory commandFactory = new ScpCommandFactory(); ++ commandFactory.setDelegateCommandFactory(new CommandFactory() { ++ @Override + public Command createCommand(String command) { +- EnumSet ttyOptions; +- if (OsUtils.isUNIX()) { +- ttyOptions = EnumSet.of(ProcessShellFactory.TtyOptions.ONlCr); +- } else { +- ttyOptions = EnumSet.of(ProcessShellFactory.TtyOptions.Echo, ProcessShellFactory.TtyOptions.ICrNl, ProcessShellFactory.TtyOptions.ONlCr); +- } +- return new ProcessShellFactory(command.split(" "), ttyOptions).create(); ++ return new ProcessShellFactory(command.split(" ")).create(); + } +- })); ++ }); ++ sshServer.setCommandFactory(commandFactory); + + return sshServer; + } +@@ -150,10 +148,10 @@ public class SshFixture extends ExternalResource { + } + + public void stopServer() { +- if (started.get()) { ++ if (started.getAndSet(false)) { + try { +- server.stop(); +- } catch (InterruptedException e) { ++ server.stop(true); ++ } catch (IOException e) { + throw new RuntimeException(e); + } + } +diff --git a/src/test/java/net/schmizz/sshj/LoadsOfConnects.java b/src/test/java/net/schmizz/sshj/LoadsOfConnects.java +index 8fb7891..e450aad 100644 +--- a/src/test/java/net/schmizz/sshj/LoadsOfConnects.java ++++ b/src/test/java/net/schmizz/sshj/LoadsOfConnects.java +@@ -15,7 +15,7 @@ + */ + package net.schmizz.sshj; + +-import net.schmizz.sshj.util.BasicFixture; ++import com.hierynomus.sshj.test.SshFixture; + import org.junit.Test; + import org.slf4j.Logger; + import org.slf4j.LoggerFactory; +@@ -26,15 +26,17 @@ public class LoadsOfConnects { + + protected final Logger log = LoggerFactory.getLogger(getClass()); + +- private final BasicFixture fixture = new BasicFixture(); ++ private final SshFixture fixture = new SshFixture(); + + @Test + public void loadsOfConnects() + throws IOException, InterruptedException { + for (int i = 0; i < 1000; i++) { + System.out.println("Try " + i); +- fixture.init(false); +- fixture.done(); ++ fixture.start(); ++ fixture.setupConnectedDefaultClient(); ++ fixture.stopClient(); ++ fixture.stopServer(); + } + } + +diff --git a/src/test/java/net/schmizz/sshj/SmokeTest.java b/src/test/java/net/schmizz/sshj/SmokeTest.java +index bf4186b..de9322a 100644 +--- a/src/test/java/net/schmizz/sshj/SmokeTest.java ++++ b/src/test/java/net/schmizz/sshj/SmokeTest.java +@@ -15,9 +15,9 @@ + */ + package net.schmizz.sshj; + ++import com.hierynomus.sshj.test.SshFixture; + import net.schmizz.sshj.transport.TransportException; + import net.schmizz.sshj.userauth.UserAuthException; +-import net.schmizz.sshj.util.BasicFixture; + import org.junit.After; + import org.junit.Before; + import org.junit.Test; +@@ -29,18 +29,20 @@ import static org.junit.Assert.assertTrue; + /* Kinda basic right now */ + public class SmokeTest { + +- private final BasicFixture fixture = new BasicFixture(); ++ private final SshFixture fixture = new SshFixture(); + + @Before + public void setUp() + throws IOException { +- fixture.init(false); ++ fixture.start(); ++ fixture.setupConnectedDefaultClient(); + } + + @After + public void tearDown() + throws IOException, InterruptedException { +- fixture.done(); ++ fixture.stopClient(); ++ fixture.stopServer(); + } + + @Test +@@ -52,7 +54,7 @@ public class SmokeTest { + @Test + public void authenticated() + throws UserAuthException, TransportException { +- fixture.dummyAuth(); ++ fixture.getClient().authPassword("dummy", "dummy"); + assertTrue(fixture.getClient().isAuthenticated()); + } + +diff --git a/src/test/java/net/schmizz/sshj/util/BasicFixture.java b/src/test/java/net/schmizz/sshj/util/BasicFixture.java +deleted file mode 100644 +index 910697d..0000000 +--- a/src/test/java/net/schmizz/sshj/util/BasicFixture.java ++++ /dev/null +@@ -1,155 +0,0 @@ +-/** +- * Copyright 2009 sshj contributors +- * +- * Licensed under the Apache License, Version 2.0 (the "License"); +- * you may not use this file except in compliance with the License. +- * You may obtain a copy of the License at +- * +- * http://www.apache.org/licenses/LICENSE-2.0 +- * +- * Unless required by applicable law or agreed to in writing, software +- * distributed under the License is distributed on an "AS IS" BASIS, +- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +- * See the License for the specific language governing permissions and +- * limitations under the License. +- */ +-/* +-* Copyright 2010, 2011 sshj contributors +-* +-* Licensed under the Apache License, Version 2.0 (the "License"); +-* you may not use this file except in compliance with the License. +-* You may obtain a copy of the License at +-* +-* http://www.apache.org/licenses/LICENSE-2.0 +-* +-* Unless required by applicable law or agreed to in writing, software +-* distributed under the License is distributed on an "AS IS" BASIS, +-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-* See the License for the specific language governing permissions and +-* limitations under the License. +-*/ +-package net.schmizz.sshj.util; +- +-import net.schmizz.sshj.SSHClient; +-import net.schmizz.sshj.transport.TransportException; +-import net.schmizz.sshj.userauth.UserAuthException; +- +-import org.apache.sshd.SshServer; +-import org.apache.sshd.common.keyprovider.FileKeyPairProvider; +-import org.apache.sshd.server.PasswordAuthenticator; +-import org.apache.sshd.server.auth.gss.GSSAuthenticator; +-import org.apache.sshd.server.session.ServerSession; +- +-import java.io.IOException; +-import java.net.ServerSocket; +- +- +-public class BasicFixture { +- +- public static final String hostkey = "src/test/resources/hostkey.pem"; +- public static final String fingerprint = "ce:a7:c1:cf:17:3f:96:49:6a:53:1a:05:0b:ba:90:db"; +- +- public static final String hostname = "localhost"; +- public final int port = gimmeAPort(); +- +- private GSSAuthenticator gssAuthenticator; +- +- private SSHClient client; +- private SshServer server; +- +- private boolean clientRunning = false; +- private boolean serverRunning = false; +- +- private static int gimmeAPort() { +- try { +- ServerSocket s = null; +- try { +- s = new ServerSocket(0); +- return s.getLocalPort(); +- } finally { +- if (s != null) +- s.close(); +- } +- } catch (IOException e) { +- throw new RuntimeException(e); +- } +- } +- +- public void init() +- throws IOException { +- init(false); +- } +- +- public void init(boolean authenticate) +- throws IOException { +- startServer(); +- startClient(authenticate); +- } +- +- public void done() +- throws InterruptedException, IOException { +- stopClient(); +- stopServer(); +- } +- +- public void startServer() +- throws IOException { +- server = SshServer.setUpDefaultServer(); +- server.setPort(port); +- server.setKeyPairProvider(new FileKeyPairProvider(new String[]{hostkey})); +- server.setPasswordAuthenticator(new PasswordAuthenticator() { +- @Override +- public boolean authenticate(String u, String p, ServerSession s) { +- return false; +- } +- }); +- server.setGSSAuthenticator(gssAuthenticator); +- server.start(); +- serverRunning = true; +- } +- +- public void stopServer() +- throws InterruptedException { +- if (serverRunning) { +- server.stop(); +- serverRunning = false; +- } +- } +- +- public SshServer getServer() { +- return server; +- } +- +- public void startClient(boolean authenticate) +- throws IOException { +- client = new SSHClient(); +- client.addHostKeyVerifier(fingerprint); +- client.connect(hostname, port); +- if (authenticate) +- dummyAuth(); +- clientRunning = true; +- } +- +- public void stopClient() +- throws IOException { +- if (clientRunning) { +- client.disconnect(); +- clientRunning = false; +- } +- } +- +- public SSHClient getClient() { +- return client; +- } +- +- public void setGssAuthenticator(GSSAuthenticator gssAuthenticator) { +- this.gssAuthenticator = gssAuthenticator; +- } +- +- public void dummyAuth() +- throws UserAuthException, TransportException { +- server.setPasswordAuthenticator(new BogusPasswordAuthenticator()); +- client.authPassword("same", "same"); +- } +- +-} +diff --git a/src/test/java/net/schmizz/sshj/util/BogusPasswordAuthenticator.java b/src/test/java/net/schmizz/sshj/util/BogusPasswordAuthenticator.java +deleted file mode 100644 +index 3e88439..0000000 +--- a/src/test/java/net/schmizz/sshj/util/BogusPasswordAuthenticator.java ++++ /dev/null +@@ -1,45 +0,0 @@ +-/** +- * Copyright 2009 sshj contributors +- * +- * Licensed under the Apache License, Version 2.0 (the "License"); +- * you may not use this file except in compliance with the License. +- * You may obtain a copy of the License at +- * +- * http://www.apache.org/licenses/LICENSE-2.0 +- * +- * Unless required by applicable law or agreed to in writing, software +- * distributed under the License is distributed on an "AS IS" BASIS, +- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +- * See the License for the specific language governing permissions and +- * limitations under the License. +- */ +-/* +-* Copyright 2010, 2011 sshj contributors +-* +-* Licensed under the Apache License, Version 2.0 (the "License"); +-* you may not use this file except in compliance with the License. +-* You may obtain a copy of the License at +-* +-* http://www.apache.org/licenses/LICENSE-2.0 +-* +-* Unless required by applicable law or agreed to in writing, software +-* distributed under the License is distributed on an "AS IS" BASIS, +-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-* See the License for the specific language governing permissions and +-* limitations under the License. +-*/ +-package net.schmizz.sshj.util; +- +-import org.apache.sshd.server.PasswordAuthenticator; +-import org.apache.sshd.server.session.ServerSession; +- +-/** Successfully authenticates when username == password. */ +-public class BogusPasswordAuthenticator +- implements PasswordAuthenticator { +- +- @Override +- public boolean authenticate(String username, String password, ServerSession s) { +- return username.equals(password); +- } +- +-} +-- +2.30.0 + diff --git a/sshj.spec b/sshj.spec index a54893f..d237ae1 100644 --- a/sshj.spec +++ b/sshj.spec @@ -1,10 +1,11 @@ Name: sshj Version: 0.13.0 -Release: 10 +Release: 11 Summary: SSH, scp and sftp library for Java License: ASL 2.0 URL: https://github.com/hierynomus/sshj Source0: https://github.com/hierynomus/sshj/archive/v%{version}.tar.gz +Patch0: Fix-build-error.patch BuildRequires: gradle-local mvn(ch.qos.logback:logback-classic) mvn(com.jcraft:jzlib) >= 1.1.0-2 mvn(junit:junit) BuildRequires: mvn(net.iharder:base64) mvn(org.apache.sshd:sshd-core) mvn(org.bouncycastle:bcprov-jdk15on) BuildRequires: mvn(org.bouncycastle:bcpkix-jdk15on) mvn(org.mockito:mockito-core) mvn(org.slf4j:slf4j-api) perl @@ -22,7 +23,7 @@ Summary: Documentation for sshj Documentation for sshj. %prep -%autosetup +%autosetup -p1 find . -name "*.jar" -print -delete perl -p -e "s/mavenCentral/xmvn()\n mavenCentral/" build.gradle > build.gradle.temp && mv build.gradle.temp build.gradle native2ascii -encoding UTF8 src/main/java/net/schmizz/sshj/SSHClient.java src/main/java/net/schmizz/sshj/SSHClient.java @@ -49,5 +50,8 @@ gradle -s --offline -x javadocs install %files help -f .mfiles-javadoc %changelog +* Sat Nov 26 2022 yaoxin - 0.13.0-11 +- Fix build error + * Sat Dec 14 2019 Ling Yang - 0.13.0-10 - Package init