- remove TLS/SSL support from netconf server and client 19/3319/7
authorMartin Bobak <mbobak@cisco.com>
Mon, 2 Dec 2013 09:30:56 +0000 (10:30 +0100)
committerMartin Bobak <mbobak@cisco.com>
Tue, 3 Dec 2013 12:32:39 +0000 (13:32 +0100)
- refactoring related to AbstractSslChannelInitializer deletion
- common code of initialize method moved to AbstractChannelInitializer
- refactoring sal-netconf-connector's NetconfConnectorModule
- integration tests reflects current changes
- netconf server activator throws InvalidStateException if
  initial tcp configuration is not found

Change-Id: I4fe793866cf9c1927f707943d922b36dae3c6665
Signed-off-by: Martin Bobak <mbobak@cisco.com>
15 files changed:
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModule.java
opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPersisterNotificationHandler.java
opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientDispatcher.java
opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfSshClientDispatcher.java
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerDispatcher.java
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfImplActivator.java
opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java
opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/NetconfDispatcherImplTest.java
opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTest.java
opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITTest.java
opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/osgi/NetconfSSHActivator.java
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/AbstractChannelInitializer.java
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/AbstractSslChannelInitializer.java [deleted file]
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/handler/NetconfHandlerFactory.java [new file with mode: 0644]
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/osgi/NetconfConfigUtil.java

index 12759246140a9d7da0947ff8f73e8d461e6614d6..4d0a1ac6b663e3ecf7aee035ab5b47157de1aed8 100644 (file)
@@ -77,10 +77,9 @@ public final class NetconfConnectorModule extends org.opendaylight.controller.co
         
         EventLoopGroup bossGroup = getBossThreadGroupDependency();
         EventLoopGroup workerGroup = getWorkerThreadGroupDependency();
-        Optional<SSLContext> maybeContext = Optional.absent();
         NetconfClientDispatcher dispatcher = null;
         if(getTcpOnly()) {
-            dispatcher = new NetconfClientDispatcher(maybeContext , bossGroup, workerGroup);
+            dispatcher = new NetconfClientDispatcher( bossGroup, workerGroup);
         } else {
             AuthenticationHandler authHandler = new LoginPassword(getUsername(),getPassword());
             dispatcher = new NetconfSshClientDispatcher(authHandler , bossGroup, workerGroup);
index b20577afd23fcdde6bb8f3ab50b3f7f73c0c0a6f..99b7ee60a2c51c8033c44e1195f78a93328b63c9 100644 (file)
@@ -13,6 +13,22 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.Sets;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetSocketAddress;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Pattern;
+import javax.annotation.concurrent.ThreadSafe;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanServerConnection;
+import javax.management.Notification;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
 import org.opendaylight.controller.config.api.ConflictingVersionException;
 import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
 import org.opendaylight.controller.config.persist.api.Persister;
@@ -32,24 +48,6 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.xml.sax.SAXException;
 
-import javax.annotation.concurrent.ThreadSafe;
-import javax.management.InstanceNotFoundException;
-import javax.management.MBeanServerConnection;
-import javax.management.Notification;
-import javax.management.NotificationListener;
-import javax.management.ObjectName;
-import javax.net.ssl.SSLContext;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpression;
-import java.io.Closeable;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.InetSocketAddress;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.regex.Pattern;
-
 /**
  * Responsible for listening for notifications from netconf containing latest
  * committed configuration that should be persisted, and also for loading last
@@ -151,7 +149,7 @@ public class ConfigPersisterNotificationHandler implements NotificationListener,
         long deadline = pollingStart + timeout;
         while (System.currentTimeMillis() < deadline) {
             attempt++;
-            netconfClientDispatcher = new NetconfClientDispatcher(Optional.<SSLContext>absent(), nettyThreadgroup, nettyThreadgroup);
+            netconfClientDispatcher = new NetconfClientDispatcher(nettyThreadgroup, nettyThreadgroup);
             try {
                 netconfClient = new NetconfClient(this.toString(), address, delay, netconfClientDispatcher);
             } catch (IllegalStateException e) {
index 62c2113056afa1611300fce0c363ce293314fb49..6ac57a88c9f4750513d8be139354f78abd5575a6 100644 (file)
@@ -8,17 +8,17 @@
 
 package org.opendaylight.controller.netconf.client;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.util.HashedWheelTimer;
 import io.netty.util.concurrent.Future;
 import io.netty.util.concurrent.Promise;
+import java.io.Closeable;
+import java.net.InetSocketAddress;
 import org.opendaylight.controller.netconf.api.NetconfMessage;
 import org.opendaylight.controller.netconf.api.NetconfSession;
 import org.opendaylight.controller.netconf.api.NetconfTerminationReason;
-import org.opendaylight.controller.netconf.util.AbstractSslChannelInitializer;
+import org.opendaylight.controller.netconf.util.AbstractChannelInitializer;
 import org.opendaylight.protocol.framework.AbstractDispatcher;
 import org.opendaylight.protocol.framework.ReconnectStrategy;
 import org.opendaylight.protocol.framework.SessionListener;
@@ -26,22 +26,15 @@ import org.opendaylight.protocol.framework.SessionListenerFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLEngine;
-import java.io.Closeable;
-import java.net.InetSocketAddress;
-
 public class NetconfClientDispatcher extends AbstractDispatcher<NetconfClientSession, NetconfClientSessionListener> implements Closeable {
 
     private static final Logger logger = LoggerFactory.getLogger(NetconfClient.class);
 
-    private final Optional<SSLContext> maybeContext;
     private final NetconfClientSessionNegotiatorFactory negotatorFactory;
     private final HashedWheelTimer timer;
 
-    public NetconfClientDispatcher(final Optional<SSLContext> maybeContext, EventLoopGroup bossGroup, EventLoopGroup workerGroup) {
+    public NetconfClientDispatcher(EventLoopGroup bossGroup, EventLoopGroup workerGroup) {
         super(bossGroup, workerGroup);
-        this.maybeContext = Preconditions.checkNotNull(maybeContext);
         timer = new HashedWheelTimer();
         this.negotatorFactory = new NetconfClientSessionNegotiatorFactory(timer);
     }
@@ -57,23 +50,27 @@ public class NetconfClientDispatcher extends AbstractDispatcher<NetconfClientSes
             }
 
             private void initialize(SocketChannel ch, Promise<NetconfClientSession> promise) {
-                new ClientSslChannelInitializer(maybeContext, negotatorFactory, sessionListener).initialize(ch, promise);
+                new ClientChannelInitializer( negotatorFactory, sessionListener).initialize(ch, promise);
             }
         });
     }
 
-    private static class ClientSslChannelInitializer extends AbstractSslChannelInitializer {
+    private static class ClientChannelInitializer extends AbstractChannelInitializer {
 
         private final NetconfClientSessionNegotiatorFactory negotiatorFactory;
         private final NetconfClientSessionListener sessionListener;
 
-        private ClientSslChannelInitializer(Optional<SSLContext> maybeContext,
-                                            NetconfClientSessionNegotiatorFactory negotiatorFactory, NetconfClientSessionListener sessionListener) {
-            super(maybeContext);
+        private ClientChannelInitializer(NetconfClientSessionNegotiatorFactory negotiatorFactory,
+                                            NetconfClientSessionListener sessionListener) {
             this.negotiatorFactory = negotiatorFactory;
             this.sessionListener = sessionListener;
         }
 
+        @Override
+        public void initialize(SocketChannel ch, Promise<? extends NetconfSession> promise) {
+                super.initialize(ch,promise);
+        }
+
         @Override
         protected void initializeAfterDecoder(SocketChannel ch, Promise<? extends NetconfSession> promise) {
             ch.pipeline().addLast("negotiator", negotiatorFactory.getSessionNegotiator(new SessionListenerFactory() {
@@ -84,12 +81,7 @@ public class NetconfClientDispatcher extends AbstractDispatcher<NetconfClientSes
             }, ch, promise));
         }
 
-        @Override
-        protected void initSslEngine(SSLEngine sslEngine) {
-            sslEngine.setUseClientMode(true);
-        }
     }
-
     @Override
     public void close() {
         try {
index b19c09263b9fa481c76307da0bb2dbebc310bb85..4de6cc35c0dad3f00afe949821a1dab59f4bc3da 100644 (file)
@@ -8,21 +8,21 @@
 
 package org.opendaylight.controller.netconf.client;
 
+import io.netty.channel.ChannelHandler;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.util.HashedWheelTimer;
+import io.netty.util.concurrent.Future;
+import io.netty.util.concurrent.Promise;
 import java.io.IOException;
 import java.net.InetSocketAddress;
-
-import javax.net.ssl.SSLContext;
-
 import org.opendaylight.controller.netconf.api.NetconfMessage;
 import org.opendaylight.controller.netconf.api.NetconfSession;
 import org.opendaylight.controller.netconf.api.NetconfTerminationReason;
 import org.opendaylight.controller.netconf.util.AbstractChannelInitializer;
-import org.opendaylight.controller.netconf.util.handler.FramingMechanismHandlerFactory;
-import org.opendaylight.controller.netconf.util.handler.NetconfMessageAggregator;
 import org.opendaylight.controller.netconf.util.handler.ssh.SshHandler;
 import org.opendaylight.controller.netconf.util.handler.ssh.authentication.AuthenticationHandler;
 import org.opendaylight.controller.netconf.util.handler.ssh.client.Invoker;
-import org.opendaylight.controller.netconf.util.messages.FramingMechanism;
 import org.opendaylight.controller.netconf.util.messages.NetconfMessageFactory;
 import org.opendaylight.protocol.framework.ProtocolHandlerFactory;
 import org.opendaylight.protocol.framework.ProtocolMessageDecoder;
@@ -31,15 +31,6 @@ import org.opendaylight.protocol.framework.ReconnectStrategy;
 import org.opendaylight.protocol.framework.SessionListener;
 import org.opendaylight.protocol.framework.SessionListenerFactory;
 
-import com.google.common.base.Optional;
-
-import io.netty.channel.ChannelHandler;
-import io.netty.channel.EventLoopGroup;
-import io.netty.channel.socket.SocketChannel;
-import io.netty.util.HashedWheelTimer;
-import io.netty.util.concurrent.Future;
-import io.netty.util.concurrent.Promise;
-
 public class NetconfSshClientDispatcher extends NetconfClientDispatcher {
 
     private AuthenticationHandler authHandler;
@@ -48,13 +39,12 @@ public class NetconfSshClientDispatcher extends NetconfClientDispatcher {
 
     public NetconfSshClientDispatcher(AuthenticationHandler authHandler, EventLoopGroup bossGroup,
             EventLoopGroup workerGroup) {
-        super(Optional.<SSLContext> absent(), bossGroup, workerGroup);
+        super(bossGroup, workerGroup);
         this.authHandler = authHandler;
         this.timer = new HashedWheelTimer();
         this.negotatorFactory = new NetconfClientSessionNegotiatorFactory(timer);
     }
 
-    @Override
     public Future<NetconfClientSession> createClient(InetSocketAddress address,
             final NetconfClientSessionListener sessionListener, ReconnectStrategy strat) {
         return super.createClient(address, strat, new PipelineInitializer<NetconfClientSession>() {
@@ -88,12 +78,7 @@ public class NetconfSshClientDispatcher extends NetconfClientDispatcher {
             try {
                 Invoker invoker = Invoker.subsystem("netconf");
                 ch.pipeline().addFirst(new SshHandler(authenticationHandler, invoker));
-                ch.pipeline().addLast("aggregator", new NetconfMessageAggregator(FramingMechanism.EOM));
-                ch.pipeline().addLast(handlerFactory.getDecoders());
-                initializeAfterDecoder(ch, promise);
-                ch.pipeline().addLast("frameEncoder",
-                        FramingMechanismHandlerFactory.createHandler(FramingMechanism.EOM));
-                ch.pipeline().addLast(handlerFactory.getEncoders());
+                super.initialize(ch,promise);
             } catch (IOException e) {
                 throw new RuntimeException(e);
             }
index 882d368a1af3648b06579903769d48026ecdf38c..4f60788975fb910f5ae29a4fbac35b8f28d4fe08 100644 (file)
@@ -8,25 +8,21 @@
 
 package org.opendaylight.controller.netconf.impl;
 
-import com.google.common.base.Optional;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.util.concurrent.Promise;
+import java.net.InetSocketAddress;
 import org.opendaylight.controller.netconf.api.NetconfSession;
 import org.opendaylight.controller.netconf.impl.util.DeserializerExceptionHandler;
-import org.opendaylight.controller.netconf.util.AbstractSslChannelInitializer;
+import org.opendaylight.controller.netconf.util.AbstractChannelInitializer;
 import org.opendaylight.protocol.framework.AbstractDispatcher;
 
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLEngine;
-import java.net.InetSocketAddress;
-
 public class NetconfServerDispatcher extends AbstractDispatcher<NetconfSession, NetconfServerSessionListener> {
 
-    private final ServerSslChannelInitializer initializer;
+    private final ServerChannelInitializer initializer;
 
-    public NetconfServerDispatcher(ServerSslChannelInitializer serverChannelInitializer, EventLoopGroup bossGroup,
+    public NetconfServerDispatcher(ServerChannelInitializer serverChannelInitializer, EventLoopGroup bossGroup,
             EventLoopGroup workerGroup) {
         super(bossGroup, workerGroup);
         this.initializer = serverChannelInitializer;
@@ -43,15 +39,13 @@ public class NetconfServerDispatcher extends AbstractDispatcher<NetconfSession,
         });
     }
 
-    public static class ServerSslChannelInitializer extends AbstractSslChannelInitializer {
+    public static class ServerChannelInitializer extends AbstractChannelInitializer {
 
         private final NetconfServerSessionNegotiatorFactory negotiatorFactory;
         private final NetconfServerSessionListenerFactory listenerFactory;
 
-        public ServerSslChannelInitializer(Optional<SSLContext> maybeContext,
-                                            NetconfServerSessionNegotiatorFactory negotiatorFactory,
+        public ServerChannelInitializer(NetconfServerSessionNegotiatorFactory negotiatorFactory,
                                             NetconfServerSessionListenerFactory listenerFactory) {
-            super(maybeContext);
             this.negotiatorFactory = negotiatorFactory;
             this.listenerFactory = listenerFactory;
         }
@@ -62,10 +56,6 @@ public class NetconfServerDispatcher extends AbstractDispatcher<NetconfSession,
             ch.pipeline().addLast("negotiator", negotiatorFactory.getSessionNegotiator(listenerFactory, ch, promise));
         }
 
-        @Override
-        protected void initSslEngine(SSLEngine sslEngine) {
-            sslEngine.setUseClientMode(false);
-        }
     }
 
 }
index b334c354fbd8749026e7a01447a775aee2d74c05..1d18f063bcc062ed64fb077d7cc34d07369a8d2e 100644 (file)
@@ -7,9 +7,10 @@
  */
 package org.opendaylight.controller.netconf.impl.osgi;
 
-import com.google.common.base.Optional;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.util.HashedWheelTimer;
+import java.lang.management.ManagementFactory;
+import java.net.InetSocketAddress;
 import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer;
 import org.opendaylight.controller.netconf.impl.NetconfServerDispatcher;
 import org.opendaylight.controller.netconf.impl.NetconfServerSessionListenerFactory;
@@ -21,10 +22,6 @@ import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.net.ssl.SSLContext;
-import java.lang.management.ManagementFactory;
-import java.net.InetSocketAddress;
-
 public class NetconfImplActivator implements BundleActivator {
 
     private static final Logger logger = LoggerFactory.getLogger(NetconfImplActivator.class);
@@ -55,8 +52,8 @@ public class NetconfImplActivator implements BundleActivator {
 
         eventLoopGroup = new NioEventLoopGroup();
 
-        NetconfServerDispatcher.ServerSslChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerSslChannelInitializer(
-                Optional.<SSLContext>absent(), serverNegotiatorFactory, listenerFactory);
+        NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(
+                serverNegotiatorFactory, listenerFactory);
         dispatch = new NetconfServerDispatcher(serverChannelInitializer, eventLoopGroup, eventLoopGroup);
 
         logger.info("Starting TCP netconf server at {}", address);
index b363976aaed6b6afd8f3aa4c9844ffb5357a661c..c0d2687a8a092b376f498e5cccadcaadfb816ab4 100644 (file)
@@ -14,6 +14,18 @@ import io.netty.channel.ChannelFuture;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.util.HashedWheelTimer;
+import java.io.DataOutputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.lang.management.ManagementFactory;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import javax.management.ObjectName;
 import org.apache.commons.io.IOUtils;
 import org.junit.After;
 import org.junit.AfterClass;
@@ -42,21 +54,6 @@ import org.opendaylight.controller.netconf.util.xml.XmlUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
-
-import javax.management.ObjectName;
-import javax.net.ssl.SSLContext;
-import java.io.DataOutputStream;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.lang.management.ManagementFactory;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
 import static com.google.common.base.Preconditions.checkNotNull;
 import static org.junit.Assert.fail;
 import static org.mockito.Matchers.any;
@@ -67,8 +64,7 @@ public class ConcurrentClientsTest {
 
     private static final int CONCURRENCY = 16;
     private static EventLoopGroup nettyGroup = new NioEventLoopGroup();
-    public static final NetconfClientDispatcher NETCONF_CLIENT_DISPATCHER = new NetconfClientDispatcher(
-            Optional.<SSLContext> absent(), nettyGroup, nettyGroup);
+    public static final NetconfClientDispatcher NETCONF_CLIENT_DISPATCHER = new NetconfClientDispatcher( nettyGroup, nettyGroup);
 
     @Mock
     private YangStoreService yangStoreService;
@@ -109,8 +105,7 @@ public class ConcurrentClientsTest {
 
         NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
                 factoriesListener, commitNot, idProvider);
-        NetconfServerDispatcher.ServerSslChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerSslChannelInitializer(
-                Optional.<SSLContext> absent(), serverNegotiatorFactory, listenerFactory);
+        NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(serverNegotiatorFactory, listenerFactory);
         dispatch = new NetconfServerDispatcher(serverChannelInitializer, nettyGroup, nettyGroup);
 
         ChannelFuture s = dispatch.createServer(netconfAddress);
index e43febec793f6ad43029169ed083c7ede7f22a4d..eec96592d8e4e6e72e701a5596de52e17a1d7738 100644 (file)
@@ -8,21 +8,18 @@
 
 package org.opendaylight.controller.netconf.impl;
 
-import com.google.common.base.Optional;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.util.HashedWheelTimer;
+import java.lang.management.ManagementFactory;
+import java.net.InetSocketAddress;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListener;
 import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl;
 
-import javax.net.ssl.SSLContext;
-import java.lang.management.ManagementFactory;
-import java.net.InetSocketAddress;
-
 public class NetconfDispatcherImplTest {
 
     private EventLoopGroup nettyGroup;
@@ -50,7 +47,7 @@ public class NetconfDispatcherImplTest {
 
         NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
                 factoriesListener, commitNot, idProvider);
-        NetconfServerDispatcher.ServerSslChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerSslChannelInitializer(Optional.<SSLContext>absent(), serverNegotiatorFactory, listenerFactory);
+        NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(serverNegotiatorFactory, listenerFactory);
 
 
         NetconfServerDispatcher dispatch = new NetconfServerDispatcher(
index 0c22a71c6b38e20b96da5163a26bed1a1b94e30b..a2b87c113c2a2f9e3b5028edefadafb69863e880 100644 (file)
@@ -8,11 +8,24 @@
 
 package org.opendaylight.controller.netconf.it;
 
-import com.google.common.base.Optional;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.util.HashedWheelTimer;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.management.ManagementFactory;
+import java.net.InetSocketAddress;
+import java.security.KeyManagementException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -32,21 +45,6 @@ import org.opendaylight.controller.netconf.impl.SessionIdProvider;
 import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl;
 import org.opendaylight.protocol.util.SSLUtil;
 
-import javax.net.ssl.KeyManagerFactory;
-import javax.net.ssl.SSLContext;
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.management.ManagementFactory;
-import java.net.InetSocketAddress;
-import java.security.KeyManagementException;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.UnrecoverableKeyException;
-import java.security.cert.CertificateException;
-import java.util.Collection;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-
 public class NetconfITSecureTest extends AbstractConfigTest {
 
     private static final InetSocketAddress tlsAddress = new InetSocketAddress("127.0.0.1", 12024);
@@ -68,13 +66,12 @@ public class NetconfITSecureTest extends AbstractConfigTest {
 
         nettyThreadgroup = new NioEventLoopGroup();
 
-        dispatchS = createDispatcher(Optional.of(getSslContext()), factoriesListener);
+        dispatchS = createDispatcher(factoriesListener);
         ChannelFuture s = dispatchS.createServer(tlsAddress);
         s.await();
     }
 
-    private NetconfServerDispatcher createDispatcher(Optional<SSLContext> sslC,
-            NetconfOperationServiceFactoryListenerImpl factoriesListener) {
+    private NetconfServerDispatcher createDispatcher(NetconfOperationServiceFactoryListenerImpl factoriesListener) {
         SessionIdProvider idProvider = new SessionIdProvider();
         NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory(
                 new HashedWheelTimer(5000, TimeUnit.MILLISECONDS), factoriesListener, idProvider);
@@ -82,8 +79,8 @@ public class NetconfITSecureTest extends AbstractConfigTest {
         NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
                 factoriesListener, commitNot, idProvider);
 
-        NetconfServerDispatcher.ServerSslChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerSslChannelInitializer(
-                sslC, serverNegotiatorFactory, listenerFactory);
+        NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(
+                serverNegotiatorFactory, listenerFactory);
         return new NetconfServerDispatcher(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup);
     }
 
@@ -114,7 +111,7 @@ public class NetconfITSecureTest extends AbstractConfigTest {
 
     @Test
     public void testSecure() throws Exception {
-        NetconfClientDispatcher dispatch = new NetconfClientDispatcher(Optional.of(getSslContext()), nettyThreadgroup, nettyThreadgroup);
+        NetconfClientDispatcher dispatch = new NetconfClientDispatcher(nettyThreadgroup, nettyThreadgroup);
         try (NetconfClient netconfClient = new NetconfClient("tls-client", tlsAddress, 4000, dispatch))  {
 
         }
index 65cc2b4e373a3f551633d1cb564461ab39e0b174..9483785031b9c6fee67dbb8f5d4904767b5cd49a 100644 (file)
@@ -29,7 +29,6 @@ import java.util.Set;
 import java.util.concurrent.TimeUnit;
 import java.util.regex.Pattern;
 import javax.management.ObjectName;
-import javax.net.ssl.SSLContext;
 import javax.xml.parsers.ParserConfigurationException;
 import junit.framework.Assert;
 import org.junit.After;
@@ -113,15 +112,14 @@ public class NetconfITTest extends AbstractConfigTest {
 
         commitNot = new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer());
 
-        dispatch = createDispatcher(Optional.<SSLContext> absent(), factoriesListener);
+        dispatch = createDispatcher(factoriesListener);
         ChannelFuture s = dispatch.createServer(tcpAddress);
         s.await();
 
-        clientDispatcher = new NetconfClientDispatcher(Optional.<SSLContext>absent(), nettyThreadgroup, nettyThreadgroup);
+        clientDispatcher = new NetconfClientDispatcher( nettyThreadgroup, nettyThreadgroup);
     }
 
-    private NetconfServerDispatcher createDispatcher(Optional<SSLContext> sslC,
-            NetconfOperationServiceFactoryListenerImpl factoriesListener) {
+    private NetconfServerDispatcher createDispatcher(NetconfOperationServiceFactoryListenerImpl factoriesListener) {
         SessionIdProvider idProvider = new SessionIdProvider();
         NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory(
                 new HashedWheelTimer(5000, TimeUnit.MILLISECONDS), factoriesListener, idProvider);
@@ -129,8 +127,8 @@ public class NetconfITTest extends AbstractConfigTest {
         NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
                 factoriesListener, commitNot, idProvider);
 
-        NetconfServerDispatcher.ServerSslChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerSslChannelInitializer(
-                sslC, serverNegotiatorFactory, listenerFactory);
+        NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(
+                serverNegotiatorFactory, listenerFactory);
         return new NetconfServerDispatcher(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup);
     }
 
index d2f6c8c81ce749a234d7ae2d433dad953e2e20c6..6f164f93d9c9482613a286352a6868e41cf649c3 100644 (file)
@@ -30,15 +30,15 @@ public class NetconfSSHActivator implements BundleActivator{
 
     private NetconfSSHServer server;
     private static final Logger logger =  LoggerFactory.getLogger(NetconfSSHActivator.class);
+    private static final String EXCEPTION_MESSAGE = "Netconf ssh bridge is not available.";
 
     @Override
     public void start(BundleContext context) throws Exception {
 
         logger.trace("Starting netconf SSH  bridge.");
 
-        Optional<InetSocketAddress> sshSocketAddressOptional = NetconfConfigUtil.extractSSHNetconfAddress(context);
-        InetSocketAddress tcpSocketAddress = NetconfConfigUtil.extractTCPNetconfAddress(context,
-                "TCP is not configured, netconf ssh bridge is not available.");
+        Optional<InetSocketAddress> sshSocketAddressOptional = NetconfConfigUtil.extractSSHNetconfAddress(context,EXCEPTION_MESSAGE);
+        InetSocketAddress tcpSocketAddress = NetconfConfigUtil.extractTCPNetconfAddress(context,EXCEPTION_MESSAGE);
 
         if (sshSocketAddressOptional.isPresent()){
             server = NetconfSSHServer.start(sshSocketAddressOptional.get().getPort(),tcpSocketAddress);
index caee5421525515a2b9cef2b136cf00d2f5944fd5..aeee2fb04baea1c4bd1535d7b677fb1f50957d8e 100644 (file)
@@ -11,10 +11,22 @@ package org.opendaylight.controller.netconf.util;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.util.concurrent.Promise;
 import org.opendaylight.controller.netconf.api.NetconfSession;
+import org.opendaylight.controller.netconf.util.handler.FramingMechanismHandlerFactory;
+import org.opendaylight.controller.netconf.util.handler.NetconfHandlerFactory;
+import org.opendaylight.controller.netconf.util.handler.NetconfMessageAggregator;
+import org.opendaylight.controller.netconf.util.messages.FramingMechanism;
+import org.opendaylight.controller.netconf.util.messages.NetconfMessageFactory;
 
 public abstract class AbstractChannelInitializer {
 
-    public abstract void initialize(SocketChannel ch, Promise<? extends NetconfSession> promise);
+    public void initialize(SocketChannel ch, Promise<? extends NetconfSession> promise){
+        NetconfHandlerFactory handlerFactory = new NetconfHandlerFactory(new NetconfMessageFactory());
+        ch.pipeline().addLast("aggregator", new NetconfMessageAggregator(FramingMechanism.EOM));
+        ch.pipeline().addLast(handlerFactory.getDecoders());
+        initializeAfterDecoder(ch, promise);
+        ch.pipeline().addLast("frameEncoder", FramingMechanismHandlerFactory.createHandler(FramingMechanism.EOM));
+        ch.pipeline().addLast(handlerFactory.getEncoders());
+    }
 
     protected abstract void initializeAfterDecoder(SocketChannel ch, Promise<? extends NetconfSession> promise);
 
diff --git a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/AbstractSslChannelInitializer.java b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/AbstractSslChannelInitializer.java
deleted file mode 100644 (file)
index d490eb2..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.controller.netconf.util;
-
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLEngine;
-
-import org.opendaylight.controller.netconf.api.NetconfMessage;
-import org.opendaylight.controller.netconf.api.NetconfSession;
-import org.opendaylight.controller.netconf.util.handler.FramingMechanismHandlerFactory;
-import org.opendaylight.controller.netconf.util.handler.NetconfMessageAggregator;
-import org.opendaylight.controller.netconf.util.messages.FramingMechanism;
-import org.opendaylight.controller.netconf.util.messages.NetconfMessageFactory;
-import org.opendaylight.protocol.framework.ProtocolHandlerFactory;
-import org.opendaylight.protocol.framework.ProtocolMessageDecoder;
-import org.opendaylight.protocol.framework.ProtocolMessageEncoder;
-
-import com.google.common.base.Optional;
-
-import io.netty.channel.ChannelHandler;
-import io.netty.channel.socket.SocketChannel;
-import io.netty.handler.ssl.SslHandler;
-import io.netty.util.concurrent.Promise;
-
-public abstract class AbstractSslChannelInitializer extends AbstractChannelInitializer {
-
-    private final Optional<SSLContext> maybeContext;
-    private final NetconfHandlerFactory handlerFactory;
-
-    public AbstractSslChannelInitializer(Optional<SSLContext> maybeContext) {
-        this.maybeContext = maybeContext;
-        this.handlerFactory = new NetconfHandlerFactory(new NetconfMessageFactory());
-    }
-
-    @Override
-    public void initialize(SocketChannel ch, Promise<? extends NetconfSession> promise) {
-        if (maybeContext.isPresent()) {
-            initSsl(ch);
-        }
-
-        ch.pipeline().addLast("aggregator", new NetconfMessageAggregator(FramingMechanism.EOM));
-        ch.pipeline().addLast(handlerFactory.getDecoders());
-        initializeAfterDecoder(ch, promise);
-        ch.pipeline().addLast("frameEncoder", FramingMechanismHandlerFactory.createHandler(FramingMechanism.EOM));
-        ch.pipeline().addLast(handlerFactory.getEncoders());
-    }
-
-    private void initSsl(SocketChannel ch) {
-        SSLEngine sslEngine = maybeContext.get().createSSLEngine();
-        initSslEngine(sslEngine);
-        final SslHandler handler = new SslHandler(sslEngine);
-        ch.pipeline().addLast("ssl", handler);
-    }
-
-    protected abstract void initSslEngine(SSLEngine sslEngine);
-
-    private static final class NetconfHandlerFactory extends ProtocolHandlerFactory<NetconfMessage> {
-
-        public NetconfHandlerFactory(final NetconfMessageFactory msgFactory) {
-            super(msgFactory);
-        }
-
-        @Override
-        public ChannelHandler[] getEncoders() {
-            return new ChannelHandler[] { new ProtocolMessageEncoder(this.msgFactory) };
-        }
-
-        @Override
-        public ChannelHandler[] getDecoders() {
-            return new ChannelHandler[] { new ProtocolMessageDecoder(this.msgFactory) };
-        }
-    }
-}
diff --git a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/handler/NetconfHandlerFactory.java b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/handler/NetconfHandlerFactory.java
new file mode 100644 (file)
index 0000000..d878c5e
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.netconf.util.handler;
+
+import io.netty.channel.ChannelHandler;
+import org.opendaylight.controller.netconf.api.NetconfMessage;
+import org.opendaylight.controller.netconf.util.messages.NetconfMessageFactory;
+import org.opendaylight.protocol.framework.ProtocolHandlerFactory;
+import org.opendaylight.protocol.framework.ProtocolMessageDecoder;
+import org.opendaylight.protocol.framework.ProtocolMessageEncoder;
+
+public class NetconfHandlerFactory extends ProtocolHandlerFactory<NetconfMessage> {
+
+    public NetconfHandlerFactory(final NetconfMessageFactory msgFactory) {
+        super(msgFactory);
+    }
+
+    @Override
+    public ChannelHandler[] getEncoders() {
+        return new ChannelHandler[] { new ProtocolMessageEncoder(this.msgFactory) };
+    }
+
+    @Override
+    public ChannelHandler[] getDecoders() {
+        return new ChannelHandler[] { new ProtocolMessageDecoder(this.msgFactory) };
+    }
+
+}
index 35e17a2a3e4564ffceac32158d00e5f7e6faba39..b1d902d6341f83415b8be25509bc6e1dc27000c2 100644 (file)
 package org.opendaylight.controller.netconf.util.osgi;
 
 import com.google.common.base.Optional;
-import org.opendaylight.protocol.util.SSLUtil;
-import org.osgi.framework.BundleContext;
-
-import javax.net.ssl.KeyManagerFactory;
-import javax.net.ssl.SSLContext;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
 import java.net.InetSocketAddress;
-
+import org.osgi.framework.BundleContext;
 import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
 
-public class NetconfConfigUtil {
+    public class NetconfConfigUtil {
     private static final String PREFIX_PROP = "netconf.";
 
     private enum InfixProp {
-        tcp, tls, ssh
+        tcp, ssh
     }
 
     private static final String PORT_SUFFIX_PROP = ".port";
     private static final String ADDRESS_SUFFIX_PROP = ".address";
 
-    private static final String NETCONF_TLS_KEYSTORE_PROP = PREFIX_PROP + InfixProp.tls + ".keystore";
-    private static final String NETCONF_TLS_KEYSTORE_PASSWORD_PROP = NETCONF_TLS_KEYSTORE_PROP + ".password";
-
     public static InetSocketAddress extractTCPNetconfAddress(BundleContext context, String exceptionMessageIfNotFound) {
 
-        Optional<InetSocketAddress> inetSocketAddressOptional = extractSomeNetconfAddress(context, InfixProp.tcp);
+        Optional<InetSocketAddress> inetSocketAddressOptional = extractSomeNetconfAddress(context, InfixProp.tcp, exceptionMessageIfNotFound);
+
         if (inetSocketAddressOptional.isPresent() == false) {
             throw new IllegalStateException("Netconf tcp address not found." + exceptionMessageIfNotFound);
         }
         return inetSocketAddressOptional.get();
     }
 
-    public static Optional<InetSocketAddress> extractSSHNetconfAddress(BundleContext context) {
-        return extractSomeNetconfAddress(context, InfixProp.ssh);
-    }
-
-
-    public static Optional<TLSConfiguration> extractTLSConfiguration(BundleContext context) {
-        Optional<InetSocketAddress> address = extractSomeNetconfAddress(context, InfixProp.tls);
-        if (address.isPresent()) {
-            String keystoreFileName = context.getProperty(NETCONF_TLS_KEYSTORE_PROP);
-            File keystoreFile = new File(keystoreFileName);
-            checkState(keystoreFile.exists() && keystoreFile.isFile() && keystoreFile.canRead(),
-                    "Keystore file %s does not exist or is not readable file", keystoreFileName);
-            keystoreFile = keystoreFile.getAbsoluteFile();
-            String keystorePassword = context.getProperty(NETCONF_TLS_KEYSTORE_PASSWORD_PROP);
-            checkNotNull(keystoreFileName, "Property %s must be defined for tls netconf server",
-                    NETCONF_TLS_KEYSTORE_PROP);
-            keystorePassword = keystorePassword != null ? keystorePassword : "";
-            return Optional.of(new TLSConfiguration(address.get(), keystoreFile, keystorePassword));
-        } else {
-            return Optional.absent();
-        }
-    }
-
-    public static class TLSConfiguration {
-        private final InetSocketAddress address;
-        private final File keystoreFile;
-        private final String keystorePassword;
-        private final SSLContext sslContext;
-
-        TLSConfiguration(InetSocketAddress address, File keystoreFile, String keystorePassword) {
-            this.address = address;
-            this.keystoreFile = keystoreFile;
-            this.keystorePassword = keystorePassword;
-            try {
-                try (InputStream keyStoreIS = new FileInputStream(keystoreFile)) {
-                    try (InputStream trustStoreIS = new FileInputStream(keystoreFile)) {
-                        sslContext = SSLUtil.initializeSecureContext("password", keyStoreIS, trustStoreIS, KeyManagerFactory.getDefaultAlgorithm());
-                    }
-                }
-            } catch (Exception e) {
-                throw new RuntimeException("Cannot initialize ssl context for netconf file " + keystoreFile, e);
-            }
-        }
-
-        public SSLContext getSslContext() {
-            return sslContext;
-        }
-
-        public InetSocketAddress getAddress() {
-            return address;
-        }
-
-        public File getKeystoreFile() {
-            return keystoreFile;
-        }
-
-        public String getKeystorePassword() {
-            return keystorePassword;
-        }
+    public static Optional<InetSocketAddress> extractSSHNetconfAddress(BundleContext context, String exceptionMessage) {
+        return extractSomeNetconfAddress(context, InfixProp.ssh, exceptionMessage);
     }
 
     /**
      * @param context
      *            from which properties are being read.
      * @param infixProp
-     *            either tcp or tls
-     * @return absent if address is missing, value if address and port are
-     *         valid.
+     *            either tcp or ssh
+     * @return value if address and port are valid.
      * @throws IllegalStateException
-     *             if address or port are invalid
+     *             if address or port are invalid, or configuration is missing
      */
     private static Optional<InetSocketAddress> extractSomeNetconfAddress(BundleContext context,
-            InfixProp infixProp) {
+            InfixProp infixProp, String exceptionMessage) {
         String address = context.getProperty(PREFIX_PROP + infixProp + ADDRESS_SUFFIX_PROP);
         if (address == null) {
-            return Optional.absent();
+            throw new IllegalStateException("Cannot find initial netconf configuration for parameter    "
+                    +PREFIX_PROP + infixProp + ADDRESS_SUFFIX_PROP
+                    +" in config.ini. "+exceptionMessage);
         }
         String portKey = PREFIX_PROP + infixProp + PORT_SUFFIX_PROP;
         String portString = context.getProperty(portKey);