Minor refactor in Call-Home 37/90537/6
authorOleksii Mozghovyi <oleksii.mozghovyi@pantheon.tech>
Sun, 21 Jun 2020 01:27:10 +0000 (04:27 +0300)
committerTomas Cere <tomas.cere@pantheon.tech>
Fri, 26 Jun 2020 09:07:40 +0000 (09:07 +0000)
JIRA: NETCONF-5
Signed-off-by: Oleksii Mozghovyi <oleksii.mozghovyi@pantheon.tech>
Change-Id: I6d79e7cdfe864f416aeb3466047e7d0f6be23f7e

netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeProtocolSessionContext.java
netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeSessionContext.java
netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/TransportType.java [new file with mode: 0644]
netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeMountSessionManager.java

index 4aff6d3c7940f9d4dfa495c9dc87cfb31a4e08ce..adc0810cc70269f1962a3d3a48cdd0fd5f2dec0e 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.netconf.callhome.protocol;
 
-import java.net.InetSocketAddress;
+import java.net.SocketAddress;
 import java.security.PublicKey;
 
 /**
@@ -20,7 +20,7 @@ public interface CallHomeProtocolSessionContext {
      *
      * @return Returns application-provided session identifier
      */
-    String getSessionName();
+    String getSessionId();
 
     /**
      * Returns public key provided by remote SSH Server for this session.
@@ -34,17 +34,17 @@ public interface CallHomeProtocolSessionContext {
      *
      * @return remote socket address associated with this session.
      */
-    InetSocketAddress getRemoteAddress();
+    SocketAddress getRemoteAddress();
 
     /**
-     * Returns version string provided by remote server.
-     *
-     * @return Version string provided by remote server.
+     * Terminate this session.
      */
-    String getRemoteServerVersion();
+    void terminate();
 
     /**
-     * Terminate this session.
+     * Returns transport type for this session.
+     *
+     * @return {@link TransportType} for this session.
      */
-    void terminate();
+    TransportType getTransportType();
 }
index 429386a15ecc2dc798c037398a05b10ce6bd3958..68902d8da73f2af1684a7e6034ec5fb77bd8b687 100644 (file)
@@ -96,6 +96,11 @@ class CallHomeSessionContext implements CallHomeProtocolSessionContext {
         removeSelf();
     }
 
+    @Override
+    public TransportType getTransportType() {
+        return TransportType.SSH;
+    }
+
     private void channelOpenFailed(final Throwable throwable) {
         LOG.error("Unable to open netconf subsystem, disconnecting.", throwable);
         sshSession.close(false);
@@ -129,18 +134,13 @@ class CallHomeSessionContext implements CallHomeProtocolSessionContext {
         return serverKey;
     }
 
-    @Override
-    public String getRemoteServerVersion() {
-        return sshSession.getServerVersion();
-    }
-
     @Override
     public InetSocketAddress getRemoteAddress() {
         return remoteAddress;
     }
 
     @Override
-    public String getSessionName() {
+    public String getSessionId() {
         return authorization.getSessionName();
     }
 
@@ -163,7 +163,7 @@ class CallHomeSessionContext implements CallHomeProtocolSessionContext {
         }
 
         void remove(final CallHomeSessionContext session) {
-            sessions.remove(session.getSessionName(), session);
+            sessions.remove(session.getSessionId(), session);
         }
 
         ReverseSshChannelInitializer getChannelInitializer(final NetconfClientSessionListener listener) {
@@ -178,7 +178,7 @@ class CallHomeSessionContext implements CallHomeProtocolSessionContext {
                 final CallHomeAuthorization authorization, final SocketAddress remoteAddress) {
             CallHomeSessionContext session = new CallHomeSessionContext(sshSession, authorization,
                     remoteAddress, this);
-            CallHomeSessionContext preexisting = sessions.putIfAbsent(session.getSessionName(), session);
+            CallHomeSessionContext preexisting = sessions.putIfAbsent(session.getSessionId(), session);
             // If preexisting is null - session does not exist, so we can safely create new one, otherwise we return
             // null and incoming connection will be rejected.
             return preexisting == null ? session : null;
diff --git a/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/TransportType.java b/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/TransportType.java
new file mode 100644 (file)
index 0000000..5b59750
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2020 Pantheon Technologies, s.r.o. 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.netconf.callhome.protocol;
+
+/**
+ * Secure transports used by the NETCONF Call-Home.
+ */
+public enum TransportType {
+    SSH,
+    TLS
+}
index ae34495bbaf768a60339e3a9b0fe6a1d0dd18a4b..76007ed6c7f9fc8efdebbe7a2394532545da4547 100644 (file)
@@ -33,21 +33,22 @@ public class CallHomeMountSessionManager implements CallHomeMountSessionContext.
 
     CallHomeMountSessionContext createSession(final CallHomeProtocolSessionContext session,
             final CallHomeChannelActivator activator, final CloseCallback onCloseHandler) {
-        final CallHomeMountSessionContext deviceContext = new CallHomeMountSessionContext(session.getSessionName(),
+        final CallHomeMountSessionContext deviceContext = new CallHomeMountSessionContext(session.getSessionId(),
             session, activator, devCtxt -> onClosed(devCtxt, onCloseHandler));
 
         final PublicKey remoteKey = session.getRemoteServerKey();
         final CallHomeMountSessionContext existing = contextByPublicKey.putIfAbsent(remoteKey, deviceContext);
         if (existing != null) {
-            // Check if the sshkey of the incoming netconf server is present. If present return null, else store the
-            // session. The sshkey is the uniqueness of the callhome sessions not the uniqueid/devicename.
-            LOG.error("SSH Host Key {} is associated with existing session {}, closing session {}", remoteKey, existing,
-                session);
+            // Check if the sshkey or certificate of the incoming netconf server is present. If present return null,
+            // else store the session. The sshkey/certificate is the uniqueness of the callhome sessions not the
+            // uniqueid/devicename
+            LOG.error("Server Host Key/Certificate {} is associated with existing session {}, closing session {}",
+                remoteKey, existing, session);
             session.terminate();
             return null;
         }
 
-        final InetSocketAddress remoteAddress = session.getRemoteAddress();
+        final SocketAddress remoteAddress = session.getRemoteAddress();
         final CallHomeMountSessionContext prev = contextByAddress.put(remoteAddress, deviceContext);
         if (prev != null) {
             LOG.warn("Remote {} replaced context {} with {}", remoteAddress, prev, deviceContext);