server: add trace to display SSL ciphers
authorNiki <david.roulet@uclouvain.be>
Wed, 17 Apr 2019 12:26:51 +0000 (14:26 +0200)
committerNiki <david.roulet@uclouvain.be>
Wed, 17 Apr 2019 12:26:51 +0000 (14:26 +0200)
src/be/nikiroo/utils/serial/server/ConnectAction.java
src/be/nikiroo/utils/serial/server/Server.java

index 10435e299d70febcdeb83f2f10086c41d85339c3..39417a77fca5c7671afd7d932d12cc22d4115397 100644 (file)
@@ -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");
index afceaf95323ec349825372c858b65fc95f185761..f6dd7d86a13cbf94c4c08279458ae3724b8b2f5b 100644 (file)
@@ -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<String> anonCiphers = new ArrayList<String>();
                for (String cipher : ((SSLSocketFactory) SSLSocketFactory.getDefault())
                                .getSupportedCipherSuites()) {