diff options
author | David Crosson <david.crosson@orange.com> | 2018-07-16 17:52:06 +0200 |
---|---|---|
committer | Takamune Cho <tc012c@att.com> | 2018-07-23 21:04:52 +0000 |
commit | 9fa2ece15b6389389782a56061a919d2a239540d (patch) | |
tree | d2dd38702286c56e993577de5c75df0f567cdecb | |
parent | a2f2cddc19030e31bcf7315d2db227a4d6351d76 (diff) |
Fix ssh adapter compilation issues.
Apache sshd library updated to 2.0.0
Issue-ID: APPC-835
Change-Id: Idfbc396291c3d05a47e4dceb45d06bc8084c054d
Signed-off-by: David Crosson <david.crosson@orange.com>
4 files changed, 63 insertions, 39 deletions
diff --git a/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/pom.xml b/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/pom.xml index 2c3f10e05..854e2d4ef 100644 --- a/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/pom.xml +++ b/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/pom.xml @@ -44,6 +44,16 @@ <scope>provided</scope> </dependency> <dependency> + <groupId>org.apache.sshd</groupId> + <artifactId>sshd-sftp</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.sshd</groupId> + <artifactId>sshd-scp</artifactId> + <scope>provided</scope> + </dependency> + <dependency> <groupId>com.att.eelf</groupId> <artifactId>eelf-core</artifactId> </dependency> diff --git a/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/src/main/java/org/onap/appc/adapter/ssh/sshd/SshConnectionSshd.java b/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/src/main/java/org/onap/appc/adapter/ssh/sshd/SshConnectionSshd.java index 10d30191c..d54fe4355 100644 --- a/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/src/main/java/org/onap/appc/adapter/ssh/sshd/SshConnectionSshd.java +++ b/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/src/main/java/org/onap/appc/adapter/ssh/sshd/SshConnectionSshd.java @@ -23,26 +23,28 @@ package org.onap.appc.adapter.ssh.sshd; +import org.apache.sshd.client.channel.ClientChannelEvent; import org.onap.appc.adapter.ssh.Constants; import org.onap.appc.adapter.ssh.SshConnection; import org.onap.appc.adapter.ssh.SshException; import org.onap.appc.encryption.EncryptionTool; import org.onap.appc.configuration.Configuration; import org.onap.appc.configuration.ConfigurationFactory; -import org.apache.sshd.ClientChannel; -import org.apache.sshd.ClientSession; -import org.apache.sshd.SshClient; +import org.apache.sshd.client.session.ClientSession; +import org.apache.sshd.client.SshClient; import org.apache.sshd.client.channel.ChannelExec; import org.apache.sshd.client.future.AuthFuture; import org.apache.sshd.client.future.OpenFuture; -import org.apache.sshd.common.KeyPairProvider; +import org.apache.sshd.common.keyprovider.KeyPairProvider; import org.apache.sshd.common.keyprovider.FileKeyPairProvider; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; +import java.io.File; import java.io.OutputStream; import java.security.KeyPair; +import java.util.Arrays; /** * Implementation of SshConnection interface based on Apache MINA SSHD library. @@ -86,14 +88,14 @@ class SshConnectionSshd implements SshConnection { sshClient.start(); try { clientSession = - sshClient.connect(EncryptionTool.getInstance().decrypt(username), host, port).await().getSession(); + sshClient.connect(EncryptionTool.getInstance().decrypt(username), host, port).verify().getSession(); if (password != null) { clientSession.addPasswordIdentity(EncryptionTool.getInstance().decrypt(password)); } if (keyFile != null) { - KeyPairProvider keyPairProvider = new FileKeyPairProvider(new String[] { - keyFile - }); + KeyPairProvider keyPairProvider = new FileKeyPairProvider( + new File(keyFile).toPath() + ); KeyPair keyPair = keyPairProvider.loadKeys().iterator().next(); clientSession.addPublicKeyIdentity(keyPair); } @@ -183,7 +185,7 @@ class SshConnectionSshd implements SshConnection { OpenFuture openFuture = client.open(); int exitStatus; try { - client.waitFor(ClientChannel.CLOSED, timeout); + client.waitFor(Arrays.asList(ClientChannelEvent.CLOSED), timeout); openFuture.verify(); Integer exitStatusI = client.getExitStatus(); if (exitStatusI == null) { diff --git a/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/src/test/java/org/onap/appc/adapter/ssh/sshd/SshAdapterTest.java b/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/src/test/java/org/onap/appc/adapter/ssh/sshd/SshAdapterTest.java index 5fdbf5431..accc6c1a9 100644 --- a/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/src/test/java/org/onap/appc/adapter/ssh/sshd/SshAdapterTest.java +++ b/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/src/test/java/org/onap/appc/adapter/ssh/sshd/SshAdapterTest.java @@ -23,27 +23,27 @@ package org.onap.appc.adapter.ssh.sshd; -import org.apache.sshd.SshServer; +import org.apache.sshd.server.SshServer; +import org.apache.sshd.common.keyprovider.KeyPairProvider; import org.apache.sshd.common.NamedFactory; import org.apache.sshd.common.util.OsUtils; -import org.apache.sshd.server.Command; -import org.apache.sshd.server.CommandFactory; -import org.apache.sshd.server.PasswordAuthenticator; -import org.apache.sshd.server.PublickeyAuthenticator; -import org.apache.sshd.server.command.ScpCommandFactory; +import org.apache.sshd.server.command.Command; +import org.apache.sshd.server.auth.password.PasswordAuthenticator; +import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator; import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; +import org.apache.sshd.server.scp.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.hamcrest.CoreMatchers; import org.junit.*; import org.junit.rules.ExpectedException; import org.onap.appc.adapter.ssh.SshAdapter; import org.onap.appc.adapter.ssh.SshConnection; import org.onap.appc.adapter.ssh.SshException; -import org.onap.appc.adapter.ssh.sshd.SshAdapterSshd; import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.IOException; import java.io.OutputStream; import java.net.BindException; @@ -51,6 +51,7 @@ import java.security.PublicKey; import java.util.Collections; import java.util.EnumSet; +//@Ignore public class SshAdapterTest { private static final boolean START_SERVER = true; @@ -162,42 +163,43 @@ public class SshAdapterTest { private void startServer() throws IOException { sshd = SshServer.setUpDefaultServer(); - sshd.setSubsystemFactories(Collections.<NamedFactory<Command>>singletonList(new SftpSubsystem.Factory())); - sshd.setCommandFactory(new ScpCommandFactory(new CommandFactory() { + sshd.setSubsystemFactories(Collections.<NamedFactory<Command>>singletonList(new SftpSubsystemFactory())); + sshd.setCommandFactory(new ScpCommandFactory() { public Command createCommand(String command) { - EnumSet<ProcessShellFactory.TtyOptions> 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(); + //EnumSet<ProcessShellFactory.TtyOptions> 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(); } - })); + }); if (OsUtils.isUNIX()) { - sshd.setShellFactory(new ProcessShellFactory(new String[]{"/bin/sh", "-i", "-l"}, - EnumSet.of(ProcessShellFactory.TtyOptions.ONlCr))); + sshd.setShellFactory(new ProcessShellFactory(new String[]{"/bin/sh", "-i", "-l"}/*, + EnumSet.of(ProcessShellFactory.TtyOptions.ONlCr)*/)); } else { - sshd.setShellFactory(new ProcessShellFactory(new String[]{"cmd.exe "}, - EnumSet.of(ProcessShellFactory.TtyOptions.Echo, ProcessShellFactory.TtyOptions.ICrNl, ProcessShellFactory.TtyOptions.ONlCr))); + sshd.setShellFactory(new ProcessShellFactory(new String[]{"cmd.exe "}/*, + EnumSet.of(ProcessShellFactory.TtyOptions.Echo, ProcessShellFactory.TtyOptions.ICrNl, ProcessShellFactory.TtyOptions.ONlCr)*/)); } // if(SecurityUtils.isBouncyCastleRegistered()) { // sshd.setKeyPairProvider(new PEMGeneratorHostKeyProvider(System.getProperty("java.io.tmpdir") + "/key.pem")); // } else { - sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(System.getProperty("java.io.tmpdir") + "/key.ser")); + sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File(System.getProperty("java.io.tmpdir") + "/key.ser"))); // } sshd.setPasswordAuthenticator(new PasswordAuthenticator() { - @Override public boolean authenticate(String username, String password, ServerSession session) { return (SSH_USERNAME.equals(username) && SSH_PASSWORD.equals(password)); } }); sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() { - + // We're testing access using passwords, so do not authorize authentitication using public keys public boolean authenticate(String username, PublicKey key, ServerSession session) { - return true; + return false; } }); sshd.getProperties().put(SshServer.WELCOME_BANNER, "Welcome to SSHD\n"); @@ -236,11 +238,11 @@ public class SshAdapterTest { private void stopServer() { try { if (sshd != null) { - sshd.stop(true); + sshd.stop(); System.out.println("SSH server stopped on port [" + sshPort + "]. [" + getClass().getName() + "#" + System.identityHashCode(this) + "]"); } - } catch (InterruptedException e) { - System.err.println("=> Error stopping SSH server."); + } catch (IOException e) { + System.err.println("=> IO Error stopping SSH server."); e.printStackTrace(); } finally { sshd = null; @@ -404,7 +404,17 @@ limitations under the License. <dependency> <groupId>org.apache.sshd</groupId> <artifactId>sshd-core</artifactId> - <version>0.12.0</version> + <version>2.0.0</version> + </dependency> + <dependency> + <groupId>org.apache.sshd</groupId> + <artifactId>sshd-sftp</artifactId> + <version>2.0.0</version> + </dependency> + <dependency> + <groupId>org.apache.sshd</groupId> + <artifactId>sshd-scp</artifactId> + <version>2.0.0</version> </dependency> <dependency> <groupId>org.mockito</groupId> |