server: add trace to display SSL ciphers
[nikiroo-utils.git] / src / be / nikiroo / utils / serial / server / Server.java
index 2022469a0296387f90bc5aca40005d4b2981849c..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();
@@ -293,13 +302,13 @@ abstract class Server implements Runnable {
                                        }
                                }
                        }
+               }
 
-                       // only return when stopped
-                       while (started || exiting) {
-                               try {
-                                       Thread.sleep(10);
-                               } catch (InterruptedException e) {
-                               }
+               // return only when stopped
+               while (started || exiting) {
+                       try {
+                               Thread.sleep(10);
+                       } catch (InterruptedException e) {
                        }
                }
        }
@@ -357,7 +366,10 @@ abstract class Server implements Runnable {
                Socket s;
                if (ssl) {
                        s = SSLSocketFactory.getDefault().createSocket(host, port);
-                       ((SSLSocket) s).setEnabledCipherSuites(ANON_CIPHERS);
+                       if (s instanceof SSLSocket) {
+                               // Should always be the case
+                               ((SSLSocket) s).setEnabledCipherSuites(ANON_CIPHERS);
+                       }
                } else {
                        s = new Socket(host, port);
                }
@@ -388,7 +400,10 @@ abstract class Server implements Runnable {
                ServerSocket ss;
                if (ssl) {
                        ss = SSLServerSocketFactory.getDefault().createServerSocket(port);
-                       ((SSLServerSocket) ss).setEnabledCipherSuites(ANON_CIPHERS);
+                       if (ss instanceof SSLServerSocket) {
+                               // Should always be the case
+                               ((SSLServerSocket) ss).setEnabledCipherSuites(ANON_CIPHERS);
+                       }
                } else {
                        ss = new ServerSocket(port);
                }
@@ -401,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()) {