<netconf.version>1.1.0-SNAPSHOT</netconf.version>
<protocol-framework.version>0.8.0-SNAPSHOT</protocol-framework.version>
<yangtools.version>1.0.0-SNAPSHOT</yangtools.version>
- <sshd-core.version>1.2.0</sshd-core.version>
+ <sshd-core.version>0.14.0</sshd-core.version>
<config.configfile.directory>etc/opendaylight/karaf</config.configfile.directory>
<config.netconf.client.configfile>01-netconf.xml</config.netconf.client.configfile>
import io.netty.channel.Channel;
import io.netty.util.concurrent.Promise;
+import java.io.IOException;
import org.opendaylight.netconf.nettyutil.AbstractChannelInitializer;
import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
import org.opendaylight.netconf.nettyutil.handler.ssh.client.AsyncSshHandler;
private final NetconfClientSessionNegotiatorFactory negotiatorFactory;
private final NetconfClientSessionListener sessionListener;
- SshClientChannelInitializer(final AuthenticationHandler authHandler,
- final NetconfClientSessionNegotiatorFactory negotiatorFactory,
- final NetconfClientSessionListener sessionListener) {
+ public SshClientChannelInitializer(final AuthenticationHandler authHandler,
+ final NetconfClientSessionNegotiatorFactory negotiatorFactory,
+ final NetconfClientSessionListener sessionListener) {
this.authenticationHandler = authHandler;
this.negotiatorFactory = negotiatorFactory;
this.sessionListener = sessionListener;
@Override
public void initialize(final Channel ch, final Promise<NetconfClientSession> promise) {
- // ssh handler has to be the first handler in pipeline
- ch.pipeline().addFirst(AsyncSshHandler.createForNetconfSubsystem(authenticationHandler, promise));
- super.initialize(ch,promise);
+ try {
+ // ssh handler has to be the first handler in pipeline
+ ch.pipeline().addFirst(AsyncSshHandler.createForNetconfSubsystem(authenticationHandler, promise));
+ super.initialize(ch,promise);
+ } catch (final IOException e) {
+ throw new RuntimeException(e);
+ }
}
@Override
import io.netty.channel.local.LocalAddress;
import java.net.InetSocketAddress;
-import org.apache.sshd.common.util.net.SshdSocketAddress;
+import org.apache.sshd.common.SshdSocketAddress;
import org.junit.Test;
public class NetconfServerSessionNegotiatorTest {
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-core</artifactId>
- <version>1.2.0</version>
+ <version>0.14.0</version>
</dependency>
<dependency>
<groupId>openexi</groupId>
package org.opendaylight.netconf.nettyutil.handler.ssh.authentication;
import java.io.IOException;
-import org.apache.sshd.client.session.ClientSession;
+import org.apache.sshd.ClientSession;
/**
* Class providing authentication facility to SSH handler.
package org.opendaylight.netconf.nettyutil.handler.ssh.authentication;
import java.io.IOException;
+import org.apache.sshd.ClientSession;
import org.apache.sshd.client.future.AuthFuture;
-import org.apache.sshd.client.session.ClientSession;
/**
* Class Providing username/password authentication option to
import io.netty.util.concurrent.GenericFutureListener;
import java.io.IOException;
import java.net.SocketAddress;
-import org.apache.sshd.client.SshClient;
-import org.apache.sshd.client.channel.ClientChannel;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.sshd.ClientChannel;
+import org.apache.sshd.ClientSession;
+import org.apache.sshd.SshClient;
import org.apache.sshd.client.future.AuthFuture;
import org.apache.sshd.client.future.ConnectFuture;
import org.apache.sshd.client.future.OpenFuture;
-import org.apache.sshd.client.session.ClientSession;
-import org.apache.sshd.client.session.ClientSessionCreator;
import org.apache.sshd.common.future.CloseFuture;
import org.apache.sshd.common.future.SshFutureListener;
import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
public static final SshClient DEFAULT_CLIENT;
static {
+ final Map<String, String> props = new HashMap<>();
+ props.put(SshClient.AUTH_TIMEOUT, Long.toString(DEFAULT_TIMEOUT));
+ props.put(SshClient.IDLE_TIMEOUT, Long.toString(DEFAULT_TIMEOUT));
+
final SshClient c = SshClient.setUpDefaultClient();
- c.getProperties().put(SshClient.AUTH_TIMEOUT, Long.toString(DEFAULT_TIMEOUT));
- c.getProperties().put(SshClient.IDLE_TIMEOUT, Long.toString(DEFAULT_TIMEOUT));
+
+ c.setProperties(props);
// TODO make configurable, or somehow reuse netty threadpool
c.setNioWorkers(SSH_DEFAULT_NIO_WORKERS);
c.start();
}
private final AuthenticationHandler authenticationHandler;
- private final ClientSessionCreator sshClient;
+ private final SshClient sshClient;
private Future<?> negotiationFuture;
private AsyncSshHandlerReader sshReadAsyncListener;
private ChannelPromise connectPromise;
private GenericFutureListener negotiationFutureListener;
- public AsyncSshHandler(final AuthenticationHandler authenticationHandler, final ClientSessionCreator sshClient,
- final Future<?> negotiationFuture) {
+ public AsyncSshHandler(final AuthenticationHandler authenticationHandler, final SshClient sshClient,
+ final Future<?> negotiationFuture) throws IOException {
this(authenticationHandler, sshClient);
this.negotiationFuture = negotiationFuture;
}
*
* @param authenticationHandler
* @param sshClient started SshClient
+ * @throws IOException
*/
- public AsyncSshHandler(final AuthenticationHandler authenticationHandler, final ClientSessionCreator sshClient) {
+ public AsyncSshHandler(final AuthenticationHandler authenticationHandler, final SshClient sshClient) throws IOException {
this.authenticationHandler = Preconditions.checkNotNull(authenticationHandler);
this.sshClient = Preconditions.checkNotNull(sshClient);
}
- public static AsyncSshHandler createForNetconfSubsystem(final AuthenticationHandler authenticationHandler) {
+ public static AsyncSshHandler createForNetconfSubsystem(final AuthenticationHandler authenticationHandler) throws IOException {
return new AsyncSshHandler(authenticationHandler, DEFAULT_CLIENT);
}
/**
*
- * Create AsyncSshHandler for netconf subsystem. Negotiation future has to be set to success after successful
- * NETCONF negotiation.
+ * Create AsyncSshHandler for netconf subsystem. Negotiation future has to be set to success after successful netconf
+ * negotiation.
*
* @param authenticationHandler
* @param negotiationFuture
* @return
+ * @throws IOException
*/
public static AsyncSshHandler createForNetconfSubsystem(final AuthenticationHandler authenticationHandler,
- final Future<?> negotiationFuture) {
+ final Future<?> negotiationFuture) throws IOException {
return new AsyncSshHandler(authenticationHandler, DEFAULT_CLIENT, negotiationFuture);
}
- private void startSsh(final ChannelHandlerContext ctx, final SocketAddress address) throws IOException {
+ private void startSsh(final ChannelHandlerContext ctx, final SocketAddress address) {
LOG.debug("Starting SSH to {} on channel: {}", address, ctx.channel());
final ConnectFuture sshConnectionFuture = sshClient.connect(authenticationHandler.getUsername(), address);
import org.apache.sshd.common.future.SshFutureListener;
import org.apache.sshd.common.io.IoInputStream;
import org.apache.sshd.common.io.IoReadFuture;
-import org.apache.sshd.common.util.buffer.Buffer;
-import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
+import org.apache.sshd.common.util.Buffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
this.readHandler = readHandler;
this.channelId = channelId;
this.asyncOut = asyncOut;
- buf = new ByteArrayBuffer(BUFFER_SIZE);
+ buf = new Buffer(BUFFER_SIZE);
asyncOut.read(buf).addListener(this);
}
readHandler.onMessageRead(msg);
// Schedule next read
- buf = new ByteArrayBuffer(BUFFER_SIZE);
+ buf = new Buffer(BUFFER_SIZE);
currentReadFuture = asyncOut.read(buf);
currentReadFuture.addListener(this);
}
import org.apache.sshd.common.io.IoOutputStream;
import org.apache.sshd.common.io.IoWriteFuture;
import org.apache.sshd.common.io.WritePendingException;
-import org.apache.sshd.common.util.buffer.Buffer;
-import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
+import org.apache.sshd.common.util.Buffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
private static Buffer toBuffer(final ByteBuf msg) {
- // FIXME: Translation from ByteBuf to Buffer. Buffer is an abstract class, so based on the assumptions
- // we can make about the contents of ByteBuf, we should be able to skip copying byte arrays around
- // by creating an appropriate subclass.
-
+ // TODO Buffer vs ByteBuf translate, Can we handle that better ?
msg.resetReaderIndex();
final byte[] temp = new byte[msg.readableBytes()];
msg.readBytes(temp, 0, msg.readableBytes());
- return new ByteArrayBuffer(temp);
+ return new Buffer(temp);
}
private static final class PendingWriteRequest {
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+
+import org.apache.sshd.ClientSession;
import org.apache.sshd.client.future.AuthFuture;
-import org.apache.sshd.client.session.ClientSession;
import org.junit.Test;
public class LoginPasswordTest {
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
+
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import io.netty.channel.DefaultChannelPromise;
import java.io.IOException;
import java.net.SocketAddress;
-import org.apache.sshd.client.SshClient;
+import org.apache.sshd.ClientChannel;
+import org.apache.sshd.ClientSession;
+import org.apache.sshd.SshClient;
import org.apache.sshd.client.channel.ChannelSubsystem;
-import org.apache.sshd.client.channel.ClientChannel;
import org.apache.sshd.client.future.AuthFuture;
import org.apache.sshd.client.future.ConnectFuture;
import org.apache.sshd.client.future.OpenFuture;
-import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.common.future.CloseFuture;
import org.apache.sshd.common.future.SshFuture;
import org.apache.sshd.common.future.SshFutureListener;
import org.apache.sshd.common.io.IoOutputStream;
import org.apache.sshd.common.io.IoReadFuture;
import org.apache.sshd.common.io.IoWriteFuture;
-import org.apache.sshd.common.util.buffer.Buffer;
-import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
+import org.apache.sshd.common.util.Buffer;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
doReturn("channel").when(channel).toString();
}
- private void stubSshClient() throws IOException {
+ private void stubSshClient() {
doNothing().when(sshClient).start();
final ConnectFuture connectFuture = mock(ConnectFuture.class);
Futures.addCallback(stubAddListener(connectFuture), new SuccessFutureListener<ConnectFuture>() {
doReturn(null).when(ioReadFuture).getException();
doReturn(ioReadFuture).when(ioReadFuture).removeListener(Matchers.<SshFutureListener<IoReadFuture>>any());
doReturn(5).when(ioReadFuture).getRead();
- doReturn(new ByteArrayBuffer(new byte[]{0, 1, 2, 3, 4})).when(ioReadFuture).getBuffer();
+ doReturn(new Buffer(new byte[]{0, 1, 2, 3, 4})).when(ioReadFuture).getBuffer();
doReturn(ioReadFuture).when(ioReadFuture).addListener(Matchers.<SshFutureListener<IoReadFuture>>any());
// Always success for read
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.concurrent.Executors;
-import org.apache.sshd.common.util.SecurityUtils;
-import org.opendaylight.controller.config.api.DependencyResolver;
-import org.opendaylight.controller.config.api.ModuleIdentifier;
+import org.apache.sshd.server.keyprovider.PEMGeneratorHostKeyProvider;
import org.opendaylight.netconf.api.NetconfServerDispatcher;
import org.opendaylight.netconf.ssh.SshProxyServer;
import org.opendaylight.netconf.ssh.SshProxyServerConfigurationBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class NetconfNorthboundSshModule extends AbstractNetconfNorthboundSshModule {
+public class NetconfNorthboundSshModule extends org.opendaylight.controller.config.yang.netconf.northbound.ssh.AbstractNetconfNorthboundSshModule {
private static final Logger LOG = LoggerFactory.getLogger(NetconfNorthboundSshModule.class);
- public NetconfNorthboundSshModule(final ModuleIdentifier identifier, final DependencyResolver dependencyResolver) {
+ public NetconfNorthboundSshModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
super(identifier, dependencyResolver);
}
- public NetconfNorthboundSshModule(final ModuleIdentifier identifier, final DependencyResolver dependencyResolver,
- final NetconfNorthboundSshModule oldModule, final java.lang.AutoCloseable oldInstance) {
+ public NetconfNorthboundSshModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, final org.opendaylight.controller.config.yang.netconf.northbound.ssh.NetconfNorthboundSshModule oldModule, final java.lang.AutoCloseable oldInstance) {
super(identifier, dependencyResolver, oldModule, oldInstance);
}
final LocalAddress localAddress = new LocalAddress(getPort().toString());
final ChannelFuture localServer = dispatch.createLocalServer(localAddress);
- final SshProxyServer sshProxyServer = new SshProxyServer(Executors.newScheduledThreadPool(1),
- getWorkerThreadGroupDependency(), getEventExecutorDependency());
+ final SshProxyServer sshProxyServer = new SshProxyServer(Executors.newScheduledThreadPool(1), getWorkerThreadGroupDependency(), getEventExecutorDependency());
final InetSocketAddress bindingAddress = getInetAddress();
final SshProxyServerConfigurationBuilder sshProxyServerConfigurationBuilder = new SshProxyServerConfigurationBuilder();
sshProxyServerConfigurationBuilder.setLocalAddress(localAddress);
sshProxyServerConfigurationBuilder.setAuthenticator(getAuthProviderDependency());
sshProxyServerConfigurationBuilder.setIdleTimeout(Integer.MAX_VALUE);
- sshProxyServerConfigurationBuilder.setKeyPairProvider(SecurityUtils.createGeneratorHostKeyProvider(null));
+ sshProxyServerConfigurationBuilder.setKeyPairProvider(new PEMGeneratorHostKeyProvider());
localServer.addListener(new GenericFutureListener<ChannelFuture>() {
private InetSocketAddress getInetAddress() {
try {
- final InetAddress inetAd = InetAddress.getByName(getBindingAddress().getIpv4Address() == null ?
- getBindingAddress().getIpv6Address().getValue() : getBindingAddress().getIpv4Address().getValue());
+ final InetAddress inetAd = InetAddress.getByName(getBindingAddress().getIpv4Address() == null ? getBindingAddress().getIpv6Address().getValue() : getBindingAddress().getIpv4Address().getValue());
return new InetSocketAddress(inetAd, getPort().getValue());
} catch (final UnknownHostException e) {
throw new IllegalArgumentException("Unable to bind netconf endpoint to address " + getBindingAddress(), e);
import io.netty.channel.EventLoopGroup;
import java.io.IOException;
import java.nio.channels.AsynchronousChannelGroup;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
+import org.apache.sshd.SshServer;
+import org.apache.sshd.common.Cipher;
import org.apache.sshd.common.FactoryManager;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.RuntimeSshException;
-import org.apache.sshd.common.cipher.BuiltinCiphers;
-import org.apache.sshd.common.cipher.Cipher;
+import org.apache.sshd.common.cipher.ARCFOUR128;
+import org.apache.sshd.common.cipher.ARCFOUR256;
import org.apache.sshd.common.io.IoAcceptor;
import org.apache.sshd.common.io.IoConnector;
import org.apache.sshd.common.io.IoHandler;
import org.apache.sshd.common.io.nio2.Nio2Acceptor;
import org.apache.sshd.common.io.nio2.Nio2Connector;
import org.apache.sshd.common.io.nio2.Nio2ServiceFactoryFactory;
-import org.apache.sshd.common.util.closeable.AbstractCloseable;
+import org.apache.sshd.common.util.CloseableUtils;
+import org.apache.sshd.server.PasswordAuthenticator;
import org.apache.sshd.server.ServerFactoryManager;
-import org.apache.sshd.server.SshServer;
-import org.apache.sshd.server.auth.password.PasswordAuthenticator;
import org.apache.sshd.server.session.ServerSession;
/**
*/
public class SshProxyServer implements AutoCloseable {
+ private static final ARCFOUR128.Factory DEFAULT_ARCFOUR128_FACTORY = new ARCFOUR128.Factory();
+ private static final ARCFOUR256.Factory DEFAULT_ARCFOUR256_FACTORY = new ARCFOUR256.Factory();
private final SshServer sshServer;
private final ScheduledExecutorService minaTimerExecutor;
private final EventLoopGroup clientGroup;
final List<NamedFactory<Cipher>> cipherFactories = sshServer.getCipherFactories();
for (Iterator<NamedFactory<Cipher>> i = cipherFactories.iterator(); i.hasNext(); ) {
final NamedFactory<Cipher> factory = i.next();
- if (factory.getName().contains(BuiltinCiphers.arcfour128.getName())
- || factory.getName().contains(BuiltinCiphers.arcfour256.getName())) {
+ if (factory.getName().contains(DEFAULT_ARCFOUR128_FACTORY.getName())
+ || factory.getName().contains(DEFAULT_ARCFOUR256_FACTORY.getName())) {
i.remove();
}
}
sshServer.setIoServiceFactoryFactory(nioServiceWithPoolFactoryFactory);
sshServer.setScheduledExecutorService(minaTimerExecutor);
- sshServer.getProperties().put(ServerFactoryManager.IDLE_TIMEOUT,
- String.valueOf(sshProxyServerConfiguration.getIdleTimeout()));
- sshServer.getProperties().put(ServerFactoryManager.AUTH_TIMEOUT,
- String.valueOf(sshProxyServerConfiguration.getIdleTimeout()));
+ sshServer.setProperties(getProperties(sshProxyServerConfiguration));
final RemoteNetconfCommand.NetconfCommandFactory netconfCommandFactory =
new RemoteNetconfCommand.NetconfCommandFactory(clientGroup, sshProxyServerConfiguration.getLocalAddress());
sshServer.start();
}
+ private static Map<String, String> getProperties(final SshProxyServerConfiguration sshProxyServerConfiguration) {
+ final Map<String, String> ret = new HashMap<>();
+ ret.put(ServerFactoryManager.IDLE_TIMEOUT, String.valueOf(sshProxyServerConfiguration.getIdleTimeout()));
+ // TODO make auth timeout configurable on its own
+ ret.put(ServerFactoryManager.AUTH_TIMEOUT, String.valueOf(sshProxyServerConfiguration.getIdleTimeout()));
+
+ return ret;
+ }
+
@Override
- public void close() throws IOException {
+ public void close() {
try {
sshServer.stop(true);
+ } catch (final InterruptedException e) {
+ throw new RuntimeException("Interrupted while stopping sshServer", e);
} finally {
sshServer.close(true);
}
/**
* Based on Nio2ServiceFactory with one addition: injectable executor
*/
- private static final class NioServiceWithPoolFactory extends AbstractCloseable implements IoServiceFactory {
+ private static final class NioServiceWithPoolFactory extends CloseableUtils.AbstractCloseable implements IoServiceFactory {
private final FactoryManager manager;
private final AsynchronousChannelGroup group;
import com.google.common.base.Preconditions;
import io.netty.channel.local.LocalAddress;
import java.net.InetSocketAddress;
-import org.apache.sshd.common.keyprovider.KeyPairProvider;
+import org.apache.sshd.common.KeyPairProvider;
import org.opendaylight.netconf.auth.AuthProvider;
public final class SshProxyServerConfiguration {
import io.netty.channel.local.LocalAddress;
import java.net.InetSocketAddress;
-import org.apache.sshd.common.keyprovider.KeyPairProvider;
+import org.apache.sshd.common.KeyPairProvider;
import org.opendaylight.netconf.auth.AuthProvider;
public final class SshProxyServerConfigurationBuilder {
import com.google.common.base.Optional;
import io.netty.channel.local.LocalAddress;
import io.netty.channel.nio.NioEventLoopGroup;
-import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
-import org.apache.sshd.common.util.SecurityUtils;
-import org.apache.sshd.common.util.threads.ThreadUtils;
-import org.apache.sshd.server.keyprovider.AbstractGeneratorHostKeyProvider;
+import org.apache.sshd.common.util.ThreadUtils;
+import org.apache.sshd.server.keyprovider.PEMGeneratorHostKeyProvider;
import org.opendaylight.netconf.ssh.SshProxyServer;
import org.opendaylight.netconf.ssh.SshProxyServerConfigurationBuilder;
import org.opendaylight.netconf.util.osgi.NetconfConfigUtil;
server.close();
}
- if (authProviderTracker != null) {
+ if(authProviderTracker != null) {
authProviderTracker.stop();
}
- if (nioExecutor!=null) {
+ if(nioExecutor!=null) {
nioExecutor.shutdownNow();
}
- if (clientGroup != null) {
+ if(clientGroup != null) {
clientGroup.shutdownGracefully();
}
- if (minaTimerExecutor != null) {
+ if(minaTimerExecutor != null) {
minaTimerExecutor.shutdownNow();
}
}
authProviderTracker = new AuthProviderTracker(bundleContext);
final Optional<String> maybePath = NetconfConfigUtil.getPrivateKeyPath(bundleContext);
- if (!maybePath.isPresent()) {
+ if(!maybePath.isPresent()) {
LOG.warn("Private key path not configured. Using default value {}",
NetconfConfigUtil.DEFAULT_PRIVATE_KEY_PATH);
}
LOG.trace("Starting netconf SSH bridge with path to ssh private key {}", path);
final SshProxyServer sshProxyServer = new SshProxyServer(minaTimerExecutor, clientGroup, nioExecutor);
- final AbstractGeneratorHostKeyProvider keyPairProvider = SecurityUtils.createGeneratorHostKeyProvider(null);
- keyPairProvider.setAlgorithm(ALGORITHM);
- keyPairProvider.setKeySize(KEY_SIZE);
- keyPairProvider.setFile(new File(path));
-
sshProxyServer.bind(
new SshProxyServerConfigurationBuilder()
.setBindingAddress(sshSocketAddress)
.setLocalAddress(localAddress)
.setAuthenticator(authProviderTracker)
- .setKeyPairProvider(keyPairProvider)
+ .setKeyPairProvider(new PEMGeneratorHostKeyProvider(path, ALGORITHM, KEY_SIZE))
.setIdleTimeout(DEFAULT_IDLE_TIMEOUT)
.createSshProxyServerConfiguration());
return sshProxyServer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+
import com.google.common.base.Stopwatch;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelInitializer;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
-import org.apache.sshd.common.util.SecurityUtils;
+import org.apache.sshd.server.keyprovider.PEMGeneratorHostKeyProvider;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
final InetSocketAddress addr = new InetSocketAddress("127.0.0.1", 10831);
final SshProxyServer sshProxyServer = new SshProxyServer(minaTimerEx, nettyGroup, nioExec);
- sshProxyServer.bind(new SshProxyServerConfigurationBuilder()
- .setBindingAddress(addr)
- .setLocalAddress(NetconfConfigUtil.getNetconfLocalAddress())
- .setAuthenticator(new AuthProvider() {
+ sshProxyServer.bind(
+ new SshProxyServerConfigurationBuilder().setBindingAddress(addr).setLocalAddress(NetconfConfigUtil.getNetconfLocalAddress()).setAuthenticator(new AuthProvider() {
@Override
public boolean authenticated(final String username, final String password) {
return true;
}
- })
- .setKeyPairProvider(SecurityUtils.createGeneratorHostKeyProvider(sshKeyPair.toPath()))
- .setIdleTimeout(Integer.MAX_VALUE)
- .createSshProxyServerConfiguration());
+ }).setKeyPairProvider(new PEMGeneratorHostKeyProvider(sshKeyPair.toPath().toAbsolutePath().toString())).setIdleTimeout(Integer.MAX_VALUE).createSshProxyServerConfiguration());
final EchoClientHandler echoClientHandler = connectClient(addr);
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
+
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import java.io.File;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
-import org.apache.sshd.client.SshClient;
+import org.apache.sshd.ClientSession;
+import org.apache.sshd.SshClient;
import org.apache.sshd.client.future.AuthFuture;
import org.apache.sshd.client.future.ConnectFuture;
-import org.apache.sshd.client.session.ClientSession;
-import org.apache.sshd.common.util.SecurityUtils;
+import org.apache.sshd.server.keyprovider.PEMGeneratorHostKeyProvider;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
final InetSocketAddress addr = InetSocketAddress.createUnresolved(HOST, PORT);
server = new SshProxyServer(minaTimerEx, clientGroup, nioExec);
- server.bind( new SshProxyServerConfigurationBuilder().setBindingAddress(addr)
- .setLocalAddress(NetconfConfigUtil.getNetconfLocalAddress()).setAuthenticator(new AuthProvider() {
- @Override
- public boolean authenticated(final String username, final String password) {
- return true;
- }
- }).setKeyPairProvider(SecurityUtils.createGeneratorHostKeyProvider(sshKeyPair.toPath()))
- .setIdleTimeout(Integer.MAX_VALUE).createSshProxyServerConfiguration());
+ server.bind(
+ new SshProxyServerConfigurationBuilder().setBindingAddress(addr).setLocalAddress(NetconfConfigUtil.getNetconfLocalAddress()).setAuthenticator(new AuthProvider() {
+ @Override
+ public boolean authenticated(final String username, final String password) {
+ return true;
+ }
+ }).setKeyPairProvider(new PEMGeneratorHostKeyProvider(sshKeyPair.toPath().toAbsolutePath().toString())).setIdleTimeout(Integer.MAX_VALUE).createSshProxyServerConfiguration());
LOG.info("SSH server started on {}", PORT);
}
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
-import org.apache.sshd.common.keyprovider.KeyPairProvider;
-import org.apache.sshd.common.util.SecurityUtils;
-import org.apache.sshd.common.util.threads.ThreadUtils;
+import org.apache.sshd.common.util.ThreadUtils;
+import org.apache.sshd.server.keyprovider.PEMGeneratorHostKeyProvider;
import org.opendaylight.controller.config.util.capability.BasicCapability;
import org.opendaylight.controller.config.util.capability.Capability;
import org.opendaylight.controller.config.util.capability.YangModuleCapability;
final List<Integer> openDevices = Lists.newArrayList();
// Generate key to temp folder
- final KeyPairProvider keyPairProvider = getPemGeneratorHostKeyProvider();
+ final PEMGeneratorHostKeyProvider keyPairProvider = getPemGeneratorHostKeyProvider();
for (int i = 0; i < params.deviceCount; i++) {
if (currentPort > 65535) {
return openDevices;
}
- private static SshProxyServerConfiguration getSshConfiguration(final InetSocketAddress bindingAddress,
- final LocalAddress tcpLocalAddress, final KeyPairProvider keyPairProvider) {
+ private SshProxyServerConfiguration getSshConfiguration(final InetSocketAddress bindingAddress, final LocalAddress tcpLocalAddress, final PEMGeneratorHostKeyProvider keyPairProvider) throws IOException {
return new SshProxyServerConfigurationBuilder()
.setBindingAddress(bindingAddress)
.setLocalAddress(tcpLocalAddress)
.createSshProxyServerConfiguration();
}
- private static KeyPairProvider getPemGeneratorHostKeyProvider() {
+ private PEMGeneratorHostKeyProvider getPemGeneratorHostKeyProvider() {
try {
final Path tempFile = Files.createTempFile("tempKeyNetconfTest", "suffix");
- return SecurityUtils.createGeneratorHostKeyProvider(tempFile.toAbsolutePath());
+ return new PEMGeneratorHostKeyProvider(tempFile.toAbsolutePath().toString());
} catch (final IOException e) {
LOG.error("Unable to generate PEM key", e);
- throw new RuntimeException("Unable to generate PEM key", e);
+ throw new RuntimeException(e);
}
}
return capabilities;
}
- private static void addModuleCapability(final SharedSchemaRepository consumer, final Set<Capability> capabilities,
- final Module module) {
+ private void addModuleCapability(final SharedSchemaRepository consumer, final Set<Capability> capabilities, final Module module) {
final SourceIdentifier moduleSourceIdentifier = SourceIdentifier.create(module.getName(),
(SimpleDateFormatUtil.DEFAULT_DATE_REV == module.getRevision() ? Optional.<String>absent() :
Optional.of(SimpleDateFormatUtil.getRevisionFormat().format(module.getRevision()))));
}
}
- private static void addDefaultSchemas(final SharedSchemaRepository consumer) {
+ private void addDefaultSchemas(final SharedSchemaRepository consumer) {
SourceIdentifier sId = RevisionSourceIdentifier.create("ietf-netconf-monitoring", "2010-10-04");
registerSource(consumer, "/META-INF/yang/ietf-netconf-monitoring.yang", sId);
registerSource(consumer, "/META-INF/yang/ietf-inet-types@2013-07-15.yang", sId);
}
- private static void registerSource(final SharedSchemaRepository consumer, final String resource,
- final SourceIdentifier sourceId) {
+ private void registerSource(final SharedSchemaRepository consumer, final String resource, final SourceIdentifier sourceId) {
consumer.registerSchemaSource(new SchemaSourceProvider<SchemaSourceRepresentation>() {
@Override
public CheckedFuture<? extends SchemaSourceRepresentation, SchemaSourceException> getSource(final SourceIdentifier sourceIdentifier) {
@Override
public void close() {
for (final SshProxyServer sshWrapper : sshWrappers) {
- try {
- sshWrapper.close();
- } catch (IOException e) {
- LOG.error("Failed to close wrapper {}", sshWrapper, e);
- }
+ sshWrapper.close();
}
for (final Channel deviceCh : devicesChannels) {
deviceCh.close();