From d9e2136bc52c2b7661698614016d864cfa8b350b Mon Sep 17 00:00:00 2001 From: Niki Date: Wed, 17 Apr 2019 14:26:51 +0200 Subject: [PATCH] server: add trace to display SSL ciphers --- .../utils/serial/server/ConnectAction.java | 35 ++++++++++++++----- .../nikiroo/utils/serial/server/Server.java | 11 +++++- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/be/nikiroo/utils/serial/server/ConnectAction.java b/src/be/nikiroo/utils/serial/server/ConnectAction.java index 10435e2..39417a7 100644 --- a/src/be/nikiroo/utils/serial/server/ConnectAction.java +++ b/src/be/nikiroo/utils/serial/server/ConnectAction.java @@ -6,6 +6,8 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.Socket; +import javax.net.ssl.SSLException; + import be.nikiroo.utils.Version; import be.nikiroo.utils.serial.Exporter; import be.nikiroo.utils.serial.Importer; @@ -102,8 +104,8 @@ abstract class ConnectAction { */ public void connect() { try { - in = new BufferedReader(new InputStreamReader(s.getInputStream(), - "UTF-8")); + in = new BufferedReader( + new InputStreamReader(s.getInputStream(), "UTF-8")); try { out = new OutputStreamWriter(s.getOutputStream(), "UTF-8"); try { @@ -140,6 +142,20 @@ abstract class ConnectAction { in = null; } } catch (Exception e) { + if (e instanceof SSLException) { + String ciphers = ""; + for (String cipher : Server.getAnonCiphers()) { + if (!ciphers.isEmpty()) { + ciphers += ", "; + } + ciphers += cipher; + } + + e = new SSLException( + "SSL error (available SSL ciphers: " + ciphers + ")", + e); + } + onError(e); } finally { try { @@ -172,11 +188,12 @@ abstract class ConnectAction { * @throws ClassNotFoundException * if a class described in the serialised data cannot be found */ - protected Object sendObject(Object data) throws IOException, - NoSuchFieldException, NoSuchMethodException, ClassNotFoundException { + protected Object sendObject(Object data) + throws IOException, NoSuchFieldException, NoSuchMethodException, + ClassNotFoundException { synchronized (lock) { - String rep = sendString(new Exporter().append(data).toString(true, - true)); + String rep = sendString( + new Exporter().append(data).toString(true, true)); if (rep != null) { return new Importer().read(rep).getValue(); } @@ -209,9 +226,9 @@ abstract class ConnectAction { * @throws java.lang.NullPointerException * if the counter part has no data to send */ - protected Object recObject() throws IOException, NoSuchFieldException, - NoSuchMethodException, ClassNotFoundException, - java.lang.NullPointerException { + protected Object recObject() + throws IOException, NoSuchFieldException, NoSuchMethodException, + ClassNotFoundException, java.lang.NullPointerException { String str = recString(); if (str == null) { throw new NullPointerException("No more data available"); diff --git a/src/be/nikiroo/utils/serial/server/Server.java b/src/be/nikiroo/utils/serial/server/Server.java index afceaf9..f6dd7d8 100644 --- a/src/be/nikiroo/utils/serial/server/Server.java +++ b/src/be/nikiroo/utils/serial/server/Server.java @@ -194,6 +194,15 @@ abstract class Server implements Runnable { tracer.trace(name + ": server starting on port " + port + " (" + (ssl ? "SSL" : "plain text") + ")"); + String ciphers = ""; + for (String cipher : getAnonCiphers()) { + if (!ciphers.isEmpty()) { + ciphers += ", "; + } + ciphers += cipher; + } + tracer.trace("Available SSL ciphers: " + ciphers); + while (started && !exiting) { count(1); final Socket s = ss.accept(); @@ -407,7 +416,7 @@ abstract class Server implements Runnable { * * @return the list of such supported ciphers */ - private static String[] getAnonCiphers() { + public static String[] getAnonCiphers() { List anonCiphers = new ArrayList(); for (String cipher : ((SSLSocketFactory) SSLSocketFactory.getDefault()) .getSupportedCipherSuites()) { -- 2.27.0