*/
package org.opendaylight.netconf.callhome.protocol;
-import java.net.InetSocketAddress;
+import java.net.SocketAddress;
import java.security.PublicKey;
/**
*
* @return Returns application-provided session identifier
*/
- String getSessionName();
+ String getSessionId();
/**
* Returns public key provided by remote SSH Server for this session.
*
* @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();
}
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);
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();
}
}
void remove(final CallHomeSessionContext session) {
- sessions.remove(session.getSessionName(), session);
+ sessions.remove(session.getSessionId(), session);
}
ReverseSshChannelInitializer getChannelInitializer(final NetconfClientSessionListener listener) {
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;
--- /dev/null
+/*
+ * 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
+}
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);