Reversed TLS re-connection issue

31 views Asked by At

We manage to initially create a TLS connection from a server to the java client listening for incoming connections. We have created a socket using a serversocket and then wrap it into an SSLsocket. The below code is used:

@Override
boolean openSessionImpl() throws Exception {
    LOGGER.info("Creating a Call Home TLS connection to {}:{}", getProperties().getHost(),
            getProperties().getChTlsPort());
    // create listening socket.
    Socket socket = createSocket(getProperties().getChTlsPort());
    if (socket == null) {
        return false;
    }
    try {
        SSLSocketFactory sslSf = getSSLSocketFactory();
        sslSocket = (SSLSocket) sslSf.createSocket(socket, null, socket.getPort(), false);
        sslSocket.setUseClientMode(true);
        sslSocket.setSoTimeout(1);//same as in remote-cli

    } catch (IOException | GeneralSecurityException e) {
        throw new NetconfException("Could not create a TLS/SSL Socket for Call Home to "
                + socket.getInetAddress().getHostAddress() + ":" + socket.getPort(), e);
    }
    LOGGER.info("Established Call Home TLS connection to {}:{} ", getProperties().getHost(),
            getProperties().getChTlsPort());
    return true;
}

This is how we create the socket:

Socket createSocket(int port) {
    Socket socket = null;
    try (ServerSocket serverSocket = new ServerSocket()) {
        serverSocket.bind(new InetSocketAddress(port));
        serverSocket.setSoTimeout(properties.getCallHomeConnectTimeout());
        LOGGER.info("Call Home  listening on port [{}]", port);
        socket = serverSocket.accept();
    } catch (Exception e) {
        LOGGER.warn("Failed to create a TCP server socket: ", e);
    }
    return socket;
}

We then loose the connection and then we use the same way to setup the connection but then we this error:

2024-03-30 18:12:16,364 (Slf4jLogConsumer.java:73) INFO : STDERR: [INF]: LN: Successfully connected to host.testcontainers.internal:4335 over IPv4.

INFO : STDERR: [ERR]: LN: SSL_accept failed (Success).

Any idea what we are doing wrong or hints how to find out is greatly appreciated.

Also do you think:

-Djavax.net.debug=all

is good to use?

br,

//mike

0

There are 0 answers