summary |
shortlog |
log |
commit | commitdiff |
review |
tree
raw |
patch |
inline | side by side (from parent 1:
a2f2cdd)
Apache sshd library updated to 2.0.0
Issue-ID: APPC-835
Change-Id: Idfbc396291c3d05a47e4dceb45d06bc8084c054d
Signed-off-by: David Crosson <david.crosson@orange.com>
<artifactId>sshd-core</artifactId>
<scope>provided</scope>
</dependency>
<artifactId>sshd-core</artifactId>
<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>
<groupId>com.att.eelf</groupId>
<artifactId>eelf-core</artifactId>
package org.onap.appc.adapter.ssh.sshd;
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.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.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 org.apache.sshd.common.keyprovider.FileKeyPairProvider;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import java.io.OutputStream;
import java.security.KeyPair;
import java.io.OutputStream;
import java.security.KeyPair;
+import java.util.Arrays;
/**
* Implementation of SshConnection interface based on Apache MINA SSHD library.
/**
* Implementation of SshConnection interface based on Apache MINA SSHD library.
sshClient.start();
try {
clientSession =
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) {
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);
}
KeyPair keyPair = keyPairProvider.loadKeys().iterator().next();
clientSession.addPublicKeyIdentity(keyPair);
}
OpenFuture openFuture = client.open();
int exitStatus;
try {
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) {
openFuture.verify();
Integer exitStatusI = client.getExitStatus();
if (exitStatusI == null) {
package org.onap.appc.adapter.ssh.sshd;
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.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.keyprovider.SimpleGeneratorHostKeyProvider;
+import org.apache.sshd.server.scp.ScpCommandFactory;
import org.apache.sshd.server.session.ServerSession;
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.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.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.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.BindException;
import java.io.IOException;
import java.io.OutputStream;
import java.net.BindException;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Collections;
import java.util.EnumSet;
public class SshAdapterTest {
private static final boolean START_SERVER = true;
public class SshAdapterTest {
private static final boolean START_SERVER = true;
private void startServer() throws IOException {
sshd = SshServer.setUpDefaultServer();
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) {
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();
- 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)*/));
- 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 {
}
// 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() {
// }
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() {
@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) {
public boolean authenticate(String username, PublicKey key, ServerSession session) {
}
});
sshd.getProperties().put(SshServer.WELCOME_BANNER, "Welcome to SSHD\n");
}
});
sshd.getProperties().put(SshServer.WELCOME_BANNER, "Welcome to SSHD\n");
private void stopServer() {
try {
if (sshd != null) {
private void stopServer() {
try {
if (sshd != null) {
System.out.println("SSH server stopped on port [" + sshPort + "]. [" + getClass().getName() + "#" + System.identityHashCode(this) + "]");
}
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;
e.printStackTrace();
} finally {
sshd = null;
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-core</artifactId>
<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>
</dependency>
<dependency>
<groupId>org.mockito</groupId>