serial: switch from SSL to CryptUtils
authorNiki Roo <niki@nikiroo.be>
Mon, 22 Apr 2019 18:38:58 +0000 (20:38 +0200)
committerNiki Roo <niki@nikiroo.be>
Mon, 22 Apr 2019 18:38:58 +0000 (20:38 +0200)
14 files changed:
changelog.md
src/be/nikiroo/utils/main/bridge.java
src/be/nikiroo/utils/serial/server/ConnectAction.java
src/be/nikiroo/utils/serial/server/ConnectActionClient.java
src/be/nikiroo/utils/serial/server/ConnectActionClientObject.java
src/be/nikiroo/utils/serial/server/ConnectActionClientString.java
src/be/nikiroo/utils/serial/server/ConnectActionServer.java
src/be/nikiroo/utils/serial/server/ConnectActionServerObject.java
src/be/nikiroo/utils/serial/server/ConnectActionServerString.java
src/be/nikiroo/utils/serial/server/Server.java
src/be/nikiroo/utils/serial/server/ServerBridge.java
src/be/nikiroo/utils/serial/server/ServerObject.java
src/be/nikiroo/utils/serial/server/ServerString.java
src/be/nikiroo/utils/test/SerialServerTest.java

index 8ae7248593847be1e8e5744a00ed54b8d696f4a5..79e97c2acbcebbb2a74d0f7ffc573cb998298f29 100644 (file)
@@ -4,6 +4,7 @@
 
 - new: server: count the bytes we rec/send
 - new: CryptUtils
+- serial: SSL -> CryptUtils
 
 ## Version 4.7.2
 
index 8aaa93f71de9286b6342e7bbb70854d3b9411cd6..f2f3df2c6fad170190309e2f2df074be3f10189c 100644 (file)
@@ -18,10 +18,11 @@ public class bridge {
         *            <ul>
         *            <li>The bridge name</li>
         *            <li>The bridge port</li>
-        *            <li>TRUE for an SSL bridge, FALSE for plain text</li>
+        *            <li>a key for an encrypted bridge, PLAIN_TEXT for plain text</li>
         *            <li>The forward server host</li>
         *            <li>The forward server port</li>
-        *            <li>TRUE for an SSL forward server, FALSE for plain text</li>
+        *            <li>a key for an encrypted forward server, PLAIN_TEXT for
+        *            plain text</li>
         *            <li>(optional) a trace level</li>
         *            <li>(optional) a truncate size for data</li>
         *            </ul>
@@ -34,10 +35,10 @@ public class bridge {
                                                + "Syntax: [name] [port] [ssl] [fhost] [fport] [fssl] ([trace level]) ([max])\n"
                                                + "\tname: the bridge name\n"
                                                + "\tport: the bridge port\n"
-                                               + "\tssl: TRUE for an SSL bridge, FALSE for plain text\n"
+                                               + "\tkey: a key for an encrypted bridge, PLAIN_TEXT for plain text\n"
                                                + "\tfhost: the forward server host\n"
                                                + "\tfport: the forward server port\n"
-                                               + "\tfssl: TRUE for an SSL forward server, FALSE for plain text\n"
+                                               + "\tfkey: a key for an encrypted forward server, PLAIN_TEXT for plain text\n"
                                                + "\ttrace level: the optional trace level (default is 1)\n"
                                                + "\tmax: the maximum size after which to truncate data\n");
                                return;
@@ -46,10 +47,18 @@ public class bridge {
                        int i = 0;
                        String name = args[i++];
                        int port = Integer.parseInt(args[i++]);
-                       boolean ssl = Boolean.parseBoolean(args[i++]);
+                       String key = args[i++];
+                       // TODO: bad
+                       if ("PLAIN_TEXT".equals(key)) {
+                               key = null;
+                       }
                        String fhost = args[i++];
                        int fport = Integer.parseInt(args[i++]);
-                       boolean fssl = Boolean.parseBoolean(args[i++]);
+                       String fkey = args[i++];
+                       // TODO: bad
+                       if ("PLAIN_TEXT".equals(fkey)) {
+                               fkey = null;
+                       }
 
                        int traceLevel = 1;
                        if (args.length > 6) {
@@ -60,8 +69,8 @@ public class bridge {
                                maxPrintSize = Integer.parseInt(args[i++]);
                        }
 
-                       ServerBridge bridge = new ServerBridge(name, port, ssl, fhost,
-                                       fport, fssl);
+                       ServerBridge bridge = new ServerBridge(name, port, key, fhost,
+                                       fport, fkey);
                        bridge.setTraceHandler(new TraceHandler(true, true, traceLevel,
                                        maxPrintSize));
                        bridge.run();
index cef10adf1c80736a4603c8d99c1fe4c82710d480..7d724248384d77a5ba459f4215a1aeebf80e7a13 100644 (file)
@@ -6,8 +6,7 @@ import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
 import java.net.Socket;
 
-import javax.net.ssl.SSLException;
-
+import be.nikiroo.utils.CryptUtils;
 import be.nikiroo.utils.Version;
 import be.nikiroo.utils.serial.Exporter;
 import be.nikiroo.utils.serial.Importer;
@@ -27,6 +26,8 @@ abstract class ConnectAction {
        private Version version;
        private Version clientVersion;
 
+       private CryptUtils crypt;
+
        private Object lock = new Object();
        private BufferedReader in;
        private OutputStreamWriter out;
@@ -77,12 +78,19 @@ abstract class ConnectAction {
         * @param server
         *            TRUE for a server action, FALSE for a client action (will
         *            impact the process)
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         * @param version
         *            the version of this client-or-server
         */
-       protected ConnectAction(Socket s, boolean server, Version version) {
+       protected ConnectAction(Socket s, boolean server, String key,
+                       Version version) {
                this.s = s;
                this.server = server;
+               if (key != null) {
+                       crypt = new CryptUtils(key);
+               }
 
                if (version == null) {
                        this.version = new Version();
@@ -131,7 +139,7 @@ abstract class ConnectAction {
                                out = new OutputStreamWriter(s.getOutputStream(), "UTF-8");
                                try {
                                        if (server) {
-                                               String line = in.readLine();
+                                               String line = readLine(in);
                                                if (line != null && line.startsWith("VERSION ")) {
                                                        // "VERSION client-version" (VERSION 1.0.0)
                                                        Version clientVersion = new Version(
@@ -163,19 +171,6 @@ 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 {
@@ -271,9 +266,7 @@ abstract class ConnectAction {
         */
        protected String sendString(String line) throws IOException {
                synchronized (lock) {
-                       out.write(line);
-                       out.write("\n");
-                       bytesSent += line.length() + 1;
+                       writeLine(out, line);
 
                        if (server) {
                                out.flush();
@@ -307,15 +300,37 @@ abstract class ConnectAction {
                                        contentToSend = false;
                                }
 
-                               String line = in.readLine();
-                               if (line != null) {
-                                       bytesReceived += line.length();
-                               }
-
-                               return line;
+                               return readLine(in);
                        }
 
                        return null;
                }
        }
+
+       private String readLine(BufferedReader in) throws IOException {
+               String line = in.readLine();
+               if (line != null) {
+                       bytesReceived += line.length();
+                       if (crypt != null) {
+                               line = crypt.decrypt64s(line, false);
+                       }
+               }
+
+               return line;
+       }
+
+       private void writeLine(OutputStreamWriter out, String line)
+                       throws IOException {
+               if (crypt == null) {
+                       out.write(line);
+                       bytesSent += line.length();
+               } else {
+                       // TODO: how NOT to create so many big Strings?
+                       String b64 = crypt.encrypt64(line, false);
+                       out.write(b64);
+                       bytesSent += b64.length();
+               }
+               out.write("\n");
+               bytesSent++;
+       }
 }
\ No newline at end of file
index db06a9f247544cef1d210531d7db45429af1a78b..c56dddd0a727b869f58cec1ce37f6a23c2d2be0f 100644 (file)
@@ -28,9 +28,12 @@ abstract class ConnectActionClient {
         * 
         * @param s
         *            the socket to bind to
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         */
-       public ConnectActionClient(Socket s) {
-               this(s, Version.getCurrentVersion());
+       public ConnectActionClient(Socket s, String key) {
+               this(s, key, Version.getCurrentVersion());
        }
 
        /**
@@ -41,8 +44,9 @@ abstract class ConnectActionClient {
         *            the host to bind to
         * @param port
         *            the port to bind to
-        * @param ssl
-        *            TRUE for an SSL connection, FALSE for plain text
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         * 
         * @throws IOException
         *             in case of I/O error
@@ -52,9 +56,9 @@ abstract class ConnectActionClient {
         *             if the port parameter is outside the specified range of valid
         *             port values, which is between 0 and 65535, inclusive
         */
-       public ConnectActionClient(String host, int port, boolean ssl)
+       public ConnectActionClient(String host, int port, String key)
                        throws IOException {
-               this(Server.createSocket(host, port, ssl), Version.getCurrentVersion());
+               this(new Socket(host, port), key, Version.getCurrentVersion());
        }
 
        /**
@@ -64,8 +68,9 @@ abstract class ConnectActionClient {
         *            the host to bind to
         * @param port
         *            the port to bind to
-        * @param ssl
-        *            TRUE for an SSL connection, FALSE for plain text
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         * @param version
         *            the client version
         * 
@@ -77,9 +82,9 @@ abstract class ConnectActionClient {
         *             if the port parameter is outside the specified range of valid
         *             port values, which is between 0 and 65535, inclusive
         */
-       public ConnectActionClient(String host, int port, boolean ssl,
+       public ConnectActionClient(String host, int port, String key,
                        Version version) throws IOException {
-               this(Server.createSocket(host, port, ssl), version);
+               this(new Socket(host, port), key, version);
        }
 
        /**
@@ -87,11 +92,14 @@ abstract class ConnectActionClient {
         * 
         * @param s
         *            the socket to bind to
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         * @param version
         *            the client version
         */
-       public ConnectActionClient(Socket s, Version version) {
-               action = new ConnectAction(s, false, version) {
+       public ConnectActionClient(Socket s, String key, Version version) {
+               action = new ConnectAction(s, false, key, version) {
                        @Override
                        protected void action(Version serverVersion) throws Exception {
                                ConnectActionClient.this.action(serverVersion);
index dd6f917ee03cf373ffe025a26fe83518e364f457..f8eaae176561ce32bbaeac73371e22dbb52e649d 100644 (file)
@@ -22,9 +22,12 @@ public class ConnectActionClientObject extends ConnectActionClient {
         * 
         * @param s
         *            the socket to bind to
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         */
-       public ConnectActionClientObject(Socket s) {
-               super(s);
+       public ConnectActionClientObject(Socket s, String key) {
+               super(s, key);
        }
 
        /**
@@ -36,8 +39,9 @@ public class ConnectActionClientObject extends ConnectActionClient {
         *            the host to bind to
         * @param port
         *            the port to bind to
-        * @param ssl
-        *            TRUE for an SSL connection, FALSE for plain text
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         * 
         * @throws IOException
         *             in case of I/O error
@@ -47,9 +51,9 @@ public class ConnectActionClientObject extends ConnectActionClient {
         *             if the port parameter is outside the specified range of valid
         *             port values, which is between 0 and 65535, inclusive
         */
-       public ConnectActionClientObject(String host, int port, boolean ssl)
+       public ConnectActionClientObject(String host, int port, String key)
                        throws IOException {
-               super(host, port, ssl);
+               super(host, port, key);
        }
 
        /**
@@ -59,8 +63,9 @@ public class ConnectActionClientObject extends ConnectActionClient {
         *            the host to bind to
         * @param port
         *            the port to bind to
-        * @param ssl
-        *            TRUE for an SSL connection, FALSE for plain text
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         * @param version
         *            the client version
         * 
@@ -72,9 +77,9 @@ public class ConnectActionClientObject extends ConnectActionClient {
         *             if the port parameter is outside the specified range of valid
         *             port values, which is between 0 and 65535, inclusive
         */
-       public ConnectActionClientObject(String host, int port, boolean ssl,
+       public ConnectActionClientObject(String host, int port, String key,
                        Version version) throws IOException {
-               super(host, port, ssl, version);
+               super(host, port, key, version);
        }
 
        /**
@@ -84,9 +89,12 @@ public class ConnectActionClientObject extends ConnectActionClient {
         *            the socket to bind to
         * @param version
         *            the client version
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         */
-       public ConnectActionClientObject(Socket s, Version version) {
-               super(s, version);
+       public ConnectActionClientObject(Socket s, String key, Version version) {
+               super(s, key, version);
        }
 
        /**
index 8b5ec2af1bb56da102c9c80c5d431bef558f1049..35a01d8233bfa0e189f094514298134a73e0d604 100644 (file)
@@ -22,9 +22,12 @@ public class ConnectActionClientString extends ConnectActionClient {
         * 
         * @param s
         *            the socket to bind to
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         */
-       public ConnectActionClientString(Socket s) {
-               super(s);
+       public ConnectActionClientString(Socket s, String key) {
+               super(s, key);
        }
 
        /**
@@ -36,8 +39,9 @@ public class ConnectActionClientString extends ConnectActionClient {
         *            the host to bind to
         * @param port
         *            the port to bind to
-        * @param ssl
-        *            TRUE for an SSL connection, FALSE for plain text
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         * 
         * @throws IOException
         *             in case of I/O error
@@ -47,9 +51,9 @@ public class ConnectActionClientString extends ConnectActionClient {
         *             if the port parameter is outside the specified range of valid
         *             port values, which is between 0 and 65535, inclusive
         */
-       public ConnectActionClientString(String host, int port, boolean ssl)
+       public ConnectActionClientString(String host, int port, String key)
                        throws IOException {
-               super(host, port, ssl);
+               super(host, port, key);
        }
 
        /**
@@ -59,8 +63,9 @@ public class ConnectActionClientString extends ConnectActionClient {
         *            the host to bind to
         * @param port
         *            the port to bind to
-        * @param ssl
-        *            TRUE for an SSL connection, FALSE for plain text
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         * @param version
         *            the client version
         * 
@@ -72,9 +77,9 @@ public class ConnectActionClientString extends ConnectActionClient {
         *             if the port parameter is outside the specified range of valid
         *             port values, which is between 0 and 65535, inclusive
         */
-       public ConnectActionClientString(String host, int port, boolean ssl,
+       public ConnectActionClientString(String host, int port, String key,
                        Version version) throws IOException {
-               super(host, port, ssl, version);
+               super(host, port, key, version);
        }
 
        /**
@@ -82,11 +87,14 @@ public class ConnectActionClientString extends ConnectActionClient {
         * 
         * @param s
         *            the socket to bind to
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         * @param version
         *            the client version
         */
-       public ConnectActionClientString(Socket s, Version version) {
-               super(s, version);
+       public ConnectActionClientString(Socket s, String key, Version version) {
+               super(s, key, version);
        }
 
        /**
index 10d3440e7af4a4a09e5b7cdf06151ab15ac98f66..699f3074b44b228ac797e186c0f18da58208d08c 100644 (file)
@@ -28,9 +28,12 @@ abstract class ConnectActionServer {
         * 
         * @param s
         *            the socket to bind to
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         */
-       public ConnectActionServer(Socket s) {
-               this(s, Version.getCurrentVersion());
+       public ConnectActionServer(Socket s, String key) {
+               this(s, key, Version.getCurrentVersion());
        }
 
        /**
@@ -38,11 +41,14 @@ abstract class ConnectActionServer {
         * 
         * @param s
         *            the socket to bind to
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         * @param version
         *            the server version
         */
-       public ConnectActionServer(Socket s, Version version) {
-               action = new ConnectAction(s, true, version) {
+       public ConnectActionServer(Socket s, String key, Version version) {
+               action = new ConnectAction(s, true, key, version) {
                        @Override
                        protected void action(Version clientVersion) throws Exception {
                                ConnectActionServer.this.action(clientVersion);
@@ -87,6 +93,8 @@ abstract class ConnectActionServer {
         * <p>
         * Example of usage: the client failed an authentication check, cut the
         * connection here and now.
+        * 
+        * @return TRUE when it is
         */
        public boolean isClosing() {
                return closing;
index e0e4276059d7044e9c01d0e3b6b127d3e575ca95..79fa38ce616ec4535067dcc9830b4f4ea2ea01ca 100644 (file)
@@ -21,9 +21,12 @@ public class ConnectActionServerObject extends ConnectActionServer {
         * 
         * @param s
         *            the socket to bind to
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         */
-       public ConnectActionServerObject(Socket s) {
-               super(s);
+       public ConnectActionServerObject(Socket s, String key) {
+               super(s, key);
        }
 
        /**
@@ -31,11 +34,14 @@ public class ConnectActionServerObject extends ConnectActionServer {
         * 
         * @param s
         *            the socket to bind to
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         * @param version
         *            the server version
         */
-       public ConnectActionServerObject(Socket s, Version version) {
-               super(s, version);
+       public ConnectActionServerObject(Socket s, String key, Version version) {
+               super(s, key, version);
        }
 
        /**
index 35dd4dd1985fb810c8300d4a810f16f227efd5a8..545e4b79fdae73c494333240443bc2c47db57d29 100644 (file)
@@ -21,9 +21,12 @@ public class ConnectActionServerString extends ConnectActionServer {
         * 
         * @param s
         *            the socket to bind to
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         */
-       public ConnectActionServerString(Socket s) {
-               super(s);
+       public ConnectActionServerString(Socket s, String key) {
+               super(s, key);
        }
 
        /**
@@ -31,11 +34,14 @@ public class ConnectActionServerString extends ConnectActionServer {
         * 
         * @param s
         *            the socket to bind to
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         * @param version
         *            the server version
         */
-       public ConnectActionServerString(Socket s, Version version) {
-               super(s, version);
+       public ConnectActionServerString(Socket s, String key, Version version) {
+               super(s, key, version);
        }
 
        /**
index 2f23c288388bbc82315672dc3e375c39ec3622cc..ed27557e4cd56e0c8335c1d0ef05cc5ca84b68f4 100644 (file)
@@ -4,13 +4,6 @@ import java.io.IOException;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.net.ssl.SSLServerSocket;
-import javax.net.ssl.SSLServerSocketFactory;
-import javax.net.ssl.SSLSocket;
-import javax.net.ssl.SSLSocketFactory;
 
 import be.nikiroo.utils.TraceHandler;
 
@@ -24,10 +17,9 @@ import be.nikiroo.utils.TraceHandler;
  * @author niki
  */
 abstract class Server implements Runnable {
-       static private final String[] ANON_CIPHERS = getAnonCiphers();
+       protected final String key;
 
        private final String name;
-       private final boolean ssl;
        private final Object lock = new Object();
        private final Object counterLock = new Object();
 
@@ -61,8 +53,9 @@ abstract class Server implements Runnable {
         *            the port to listen on, or 0 to assign any unallocated port
         *            found (which can later on be queried via
         *            {@link Server#getPort()}
-        * @param ssl
-        *            use a SSL connection (or not)
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         * 
         * @throws IOException
         *             in case of I/O error
@@ -72,20 +65,20 @@ abstract class Server implements Runnable {
         *             if the port parameter is outside the specified range of valid
         *             port values, which is between 0 and 65535, inclusive
         */
-       public Server(int port, boolean ssl) throws IOException {
-               this((String) null, port, ssl);
+       public Server(int port, String key) throws IOException {
+               this((String) null, port, key);
        }
 
        /**
         * Create a new server that will start listening on the network when
         * {@link Server#start()} is called.
+        * <p>
+        * All the communications will happen in plain text.
         * 
         * @param name
         *            the server name (only used for debug info and traces)
         * @param port
         *            the port to listen on
-        * @param ssl
-        *            use a SSL connection (or not)
         * 
         * @throws IOException
         *             in case of I/O error
@@ -95,11 +88,35 @@ abstract class Server implements Runnable {
         *             if the port parameter is outside the specified range of valid
         *             port values, which is between 0 and 65535, inclusive
         */
-       public Server(String name, int port, boolean ssl) throws IOException {
+       public Server(String name, int port) throws IOException {
+               this(name, port, null);
+       }
+
+       /**
+        * Create a new server that will start listening on the network when
+        * {@link Server#start()} is called.
+        * 
+        * @param name
+        *            the server name (only used for debug info and traces)
+        * @param port
+        *            the port to listen on
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
+        * 
+        * @throws IOException
+        *             in case of I/O error
+        * @throws UnknownHostException
+        *             if the IP address of the host could not be determined
+        * @throws IllegalArgumentException
+        *             if the port parameter is outside the specified range of valid
+        *             port values, which is between 0 and 65535, inclusive
+        */
+       public Server(String name, int port, String key) throws IOException {
                this.name = name;
                this.port = port;
-               this.ssl = ssl;
-               this.ss = createSocketServer(port, ssl);
+               this.key = key;
+               this.ss = new ServerSocket(port);
 
                if (this.port == 0) {
                        this.port = this.ss.getLocalPort();
@@ -213,7 +230,7 @@ abstract class Server implements Runnable {
 
                try {
                        tracer.trace(name + ": server starting on port " + port + " ("
-                                       + (ssl ? "SSL" : "plain text") + ")");
+                                       + (key != null ? "encrypted" : "plain text") + ")");
 
                        while (started && !exiting) {
                                count(1);
@@ -306,8 +323,8 @@ abstract class Server implements Runnable {
                                exiting = true;
 
                                try {
-                                       new ConnectActionClientObject(createSocket(null, port, ssl))
-                                                       .connect();
+                                       new ConnectActionClientObject(new Socket((String) null,
+                                                       port), key).connect();
                                        long time = 0;
                                        while (ss != null && timeout > 0 && timeout > time) {
                                                Thread.sleep(10);
@@ -366,8 +383,6 @@ abstract class Server implements Runnable {
         *            the host to connect to
         * @param port
         *            the port to connect to
-        * @param ssl
-        *            TRUE for SSL mode (or FALSE for plain text mode)
         * 
         * @return the {@link Socket}
         * 
@@ -379,20 +394,9 @@ abstract class Server implements Runnable {
         *             if the port parameter is outside the specified range of valid
         *             port values, which is between 0 and 65535, inclusive
         */
-       static Socket createSocket(String host, int port, boolean ssl)
-                       throws IOException {
-               Socket s;
-               if (ssl) {
-                       s = SSLSocketFactory.getDefault().createSocket(host, port);
-                       if (s instanceof SSLSocket) {
-                               // Should always be the case
-                               ((SSLSocket) s).setEnabledCipherSuites(ANON_CIPHERS);
-                       }
-               } else {
-                       s = new Socket(host, port);
-               }
-
-               return s;
+       @Deprecated
+       static Socket createSocket(String host, int port) throws IOException {
+               return new Socket(host, port);
        }
 
        /**
@@ -400,8 +404,6 @@ abstract class Server implements Runnable {
         * 
         * @param port
         *            the port to accept connections on
-        * @param ssl
-        *            TRUE for SSL mode (or FALSE for plain text mode)
         * 
         * @return the {@link ServerSocket}
         * 
@@ -413,36 +415,8 @@ abstract class Server implements Runnable {
         *             if the port parameter is outside the specified range of valid
         *             port values, which is between 0 and 65535, inclusive
         */
-       static ServerSocket createSocketServer(int port, boolean ssl)
-                       throws IOException {
-               ServerSocket ss;
-               if (ssl) {
-                       ss = SSLServerSocketFactory.getDefault().createServerSocket(port);
-                       if (ss instanceof SSLServerSocket) {
-                               // Should always be the case
-                               ((SSLServerSocket) ss).setEnabledCipherSuites(ANON_CIPHERS);
-                       }
-               } else {
-                       ss = new ServerSocket(port);
-               }
-
-               return ss;
-       }
-
-       /**
-        * Return all the supported ciphers that do not use authentication.
-        * 
-        * @return the list of such supported ciphers
-        */
-       public static String[] getAnonCiphers() {
-               List<String> anonCiphers = new ArrayList<String>();
-               for (String cipher : ((SSLSocketFactory) SSLSocketFactory.getDefault())
-                               .getSupportedCipherSuites()) {
-                       if (cipher.contains("_anon_")) {
-                               anonCiphers.add(cipher);
-                       }
-               }
-
-               return anonCiphers.toArray(new String[] {});
+       @Deprecated
+       static ServerSocket createSocketServer(int port) throws IOException {
+               return new ServerSocket(port);
        }
 }
index db50876b32aafb144bc89047e73073c391c569f8..6c2ed019e830226ce93ed95a95c316d4b6f220eb 100644 (file)
@@ -25,7 +25,7 @@ import be.nikiroo.utils.serial.Importer;
 public class ServerBridge extends Server {
        private final String forwardToHost;
        private final int forwardToPort;
-       private final boolean forwardToSsl;
+       private final String forwardToKey;
 
        /**
         * Create a new server that will start listening on the network when
@@ -35,14 +35,16 @@ public class ServerBridge extends Server {
         *            the port to listen on, or 0 to assign any unallocated port
         *            found (which can later on be queried via
         *            {@link ServerBridge#getPort()}
-        * @param ssl
-        *            use an SSL connection (or not)
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         * @param forwardToHost
         *            the host server to forward the calls to
         * @param forwardToPort
         *            the host port to forward the calls to
-        * @param forwardToSsl
-        *            use an SSL connection for the forward server or not
+        * @param forwardToKey
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         * 
         * @throws IOException
         *             in case of I/O error
@@ -52,12 +54,12 @@ public class ServerBridge extends Server {
         *             if the port parameter is outside the specified range of valid
         *             port values, which is between 0 and 65535, inclusive
         */
-       public ServerBridge(int port, boolean ssl, String forwardToHost,
-                       int forwardToPort, boolean forwardToSsl) throws IOException {
-               super(port, ssl);
+       public ServerBridge(int port, String key, String forwardToHost,
+                       int forwardToPort, String forwardToKey) throws IOException {
+               super(port, key);
                this.forwardToHost = forwardToHost;
                this.forwardToPort = forwardToPort;
-               this.forwardToSsl = forwardToSsl;
+               this.forwardToKey = forwardToKey;
        }
 
        /**
@@ -68,14 +70,17 @@ public class ServerBridge extends Server {
         *            the server name (only used for debug info and traces)
         * @param port
         *            the port to listen on
-        * @param ssl
-        *            use an SSL connection (or not)
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         * @param forwardToHost
         *            the host server to forward the calls to
         * @param forwardToPort
         *            the host port to forward the calls to
-        * @param forwardToSsl
-        *            use an SSL connection for the forward server or not
+        * @param forwardToKey
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text) use an SSL connection
+        *            for the forward server or not
         * 
         * @throws IOException
         *             in case of I/O error
@@ -85,13 +90,13 @@ public class ServerBridge extends Server {
         *             if the port parameter is outside the specified range of valid
         *             port values, which is between 0 and 65535, inclusive
         */
-       public ServerBridge(String name, int port, boolean ssl,
-                       String forwardToHost, int forwardToPort, boolean forwardToSsl)
+       public ServerBridge(String name, int port, String key,
+                       String forwardToHost, int forwardToPort, String forwardToKey)
                        throws IOException {
-               super(name, port, ssl);
+               super(name, port, key);
                this.forwardToHost = forwardToHost;
                this.forwardToPort = forwardToPort;
-               this.forwardToSsl = forwardToSsl;
+               this.forwardToKey = forwardToKey;
        }
 
        /**
@@ -118,7 +123,7 @@ public class ServerBridge extends Server {
 
        @Override
        protected ConnectActionServer createConnectActionServer(Socket s) {
-               return new ConnectActionServerString(s) {
+               return new ConnectActionServerString(s, key) {
                        @Override
                        public void action(final Version clientVersion) throws Exception {
                                onClientContact(clientVersion);
@@ -126,7 +131,7 @@ public class ServerBridge extends Server {
 
                                try {
                                        new ConnectActionClientString(forwardToHost, forwardToPort,
-                                                       forwardToSsl, clientVersion) {
+                                                       forwardToKey, clientVersion) {
                                                @Override
                                                public void action(final Version serverVersion)
                                                                throws Exception {
@@ -207,7 +212,8 @@ public class ServerBridge extends Server {
                getTraceHandler().trace(
                                getName() + ": will forward to " + forwardToHost + ":"
                                                + forwardToPort + " ("
-                                               + (forwardToSsl ? "SSL" : "plain text") + ")");
+                                               + (forwardToKey != null ? "encrypted" : "plain text")
+                                               + ")");
                super.run();
        }
 
@@ -221,18 +227,7 @@ public class ServerBridge extends Server {
         */
        private void trace(String prefix, String data) {
                int size = data == null ? 0 : data.length();
-               String ssize = size + " byte";
-               if (size > 1) {
-                       ssize = size + " bytes";
-                       if (size >= 1000) {
-                               size = size / 1000;
-                               ssize = size + " kb";
-                               if (size > 1000) {
-                                       size = size / 1000;
-                                       ssize = size + " MB";
-                               }
-                       }
-               }
+               String ssize = StringUtils.formatNumber(size) + "bytes";
 
                getTraceHandler().trace(prefix + ": " + ssize, 1);
 
index 6d3d53935208d713ef251d3ec8bf7b5ce54c85bf..4f72013a3e7008896a65107d6e8737f87a640c0e 100644 (file)
@@ -24,8 +24,9 @@ abstract public class ServerObject extends Server {
         *            the port to listen on, or 0 to assign any unallocated port
         *            found (which can later on be queried via
         *            {@link ServerObject#getPort()}
-        * @param ssl
-        *            use a SSL connection (or not)
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         * 
         * @throws IOException
         *             in case of I/O error
@@ -35,8 +36,8 @@ abstract public class ServerObject extends Server {
         *             if the port parameter is outside the specified range of valid
         *             port values, which is between 0 and 65535, inclusive
         */
-       public ServerObject(int port, boolean ssl) throws IOException {
-               super(port, ssl);
+       public ServerObject(int port, String key) throws IOException {
+               super(port, key);
        }
 
        /**
@@ -47,8 +48,9 @@ abstract public class ServerObject extends Server {
         *            the server name (only used for debug info and traces)
         * @param port
         *            the port to listen on
-        * @param ssl
-        *            use a SSL connection (or not)
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         * 
         * @throws IOException
         *             in case of I/O error
@@ -58,13 +60,13 @@ abstract public class ServerObject extends Server {
         *             if the port parameter is outside the specified range of valid
         *             port values, which is between 0 and 65535, inclusive
         */
-       public ServerObject(String name, int port, boolean ssl) throws IOException {
-               super(name, port, ssl);
+       public ServerObject(String name, int port, String key) throws IOException {
+               super(name, port, key);
        }
 
        @Override
        protected ConnectActionServer createConnectActionServer(Socket s) {
-               return new ConnectActionServerObject(s) {
+               return new ConnectActionServerObject(s, key) {
                        @Override
                        public void action(Version clientVersion) throws Exception {
                                try {
index 89a7b28c6042418be95348191ad79794adb826fe..9d8d008e02a3907f3c0a386ca165c1c8e4b12352 100644 (file)
@@ -24,8 +24,9 @@ abstract public class ServerString extends Server {
         *            the port to listen on, or 0 to assign any unallocated port
         *            found (which can later on be queried via
         *            {@link ServerString#getPort()}
-        * @param ssl
-        *            use a SSL connection (or not)
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         * 
         * @throws IOException
         *             in case of I/O error
@@ -35,8 +36,8 @@ abstract public class ServerString extends Server {
         *             if the port parameter is outside the specified range of valid
         *             port values, which is between 0 and 65535, inclusive
         */
-       public ServerString(int port, boolean ssl) throws IOException {
-               super(port, ssl);
+       public ServerString(int port, String key) throws IOException {
+               super(port, key);
        }
 
        /**
@@ -47,8 +48,9 @@ abstract public class ServerString extends Server {
         *            the server name (only used for debug info and traces)
         * @param port
         *            the port to listen on
-        * @param ssl
-        *            use a SSL connection (or not)
+        * @param key
+        *            an optional key to encrypt all the communications (if NULL,
+        *            everything will be sent in clear text)
         * 
         * @throws IOException
         *             in case of I/O error
@@ -58,13 +60,13 @@ abstract public class ServerString extends Server {
         *             if the port parameter is outside the specified range of valid
         *             port values, which is between 0 and 65535, inclusive
         */
-       public ServerString(String name, int port, boolean ssl) throws IOException {
-               super(name, port, ssl);
+       public ServerString(String name, int port, String key) throws IOException {
+               super(name, port, key);
        }
 
        @Override
        protected ConnectActionServer createConnectActionServer(Socket s) {
-               return new ConnectActionServerString(s) {
+               return new ConnectActionServerString(s, key) {
                        @Override
                        public void action(Version clientVersion) throws Exception {
                                for (String data = rec(); data != null; data = rec()) {
index a34d30e4fa7a83dfca08ba1cad6a9edac522c26c..a3f4f9ef4794455eac3862765fbbc8f3a684b33d 100644 (file)
@@ -13,18 +13,18 @@ import be.nikiroo.utils.serial.server.ServerString;
 
 class SerialServerTest extends TestLauncher {
        private TestLauncher createServerStringTestCases(final String[] args,
-                       final boolean ssl, final boolean bridge) {
-               final String ssls = (ssl ? "(ssl)" : "(plain text)");
+                       final String key, final boolean bridge) {
+               final String skey = (key != null ? "(encrypted)" : "(plain text)");
                final String bridges = (bridge ? " with bridge" : "");
                TestLauncher series = new TestLauncher(
-                               "ServerString " + ssls + bridges, args);
+                               "ServerString " + skey + bridges, args);
 
-               series.addTest(new TestCase("Simple connection " + ssls) {
+               series.addTest(new TestCase("Simple connection " + skey) {
                        @Override
                        public void test() throws Exception {
                                final String[] rec = new String[1];
 
-                               ServerString server = new ServerString(this.getName(), 0, ssl) {
+                               ServerString server = new ServerString(this.getName(), 0, key) {
                                        @Override
                                        protected String onRequest(
                                                        ConnectActionServerString action,
@@ -45,7 +45,7 @@ class SerialServerTest extends TestLauncher {
 
                                ServerBridge br = null;
                                if (bridge) {
-                                       br = new ServerBridge(0, ssl, "", port, ssl);
+                                       br = new ServerBridge(0, key, "", port, key);
                                        br.setTraceHandler(null);
 
                                        port = br.getPort();
@@ -58,7 +58,7 @@ class SerialServerTest extends TestLauncher {
 
                                try {
                                        try {
-                                               new ConnectActionClientObject(null, port, ssl) {
+                                               new ConnectActionClientObject(null, port, key) {
                                                        @Override
                                                        public void action(Version serverVersion)
                                                                        throws Exception {
@@ -79,14 +79,14 @@ class SerialServerTest extends TestLauncher {
                        }
                });
 
-               series.addTest(new TestCase("Simple exchange " + ssls) {
+               series.addTest(new TestCase("Simple exchange " + skey) {
                        final String[] sent = new String[1];
                        final String[] recd = new String[1];
                        final Exception[] err = new Exception[1];
 
                        @Override
                        public void test() throws Exception {
-                               ServerString server = new ServerString(this.getName(), 0, ssl) {
+                               ServerString server = new ServerString(this.getName(), 0, key) {
                                        @Override
                                        protected String onRequest(
                                                        ConnectActionServerString action,
@@ -108,7 +108,7 @@ class SerialServerTest extends TestLauncher {
 
                                ServerBridge br = null;
                                if (bridge) {
-                                       br = new ServerBridge(0, ssl, "", port, ssl);
+                                       br = new ServerBridge(0, key, "", port, key);
                                        br.setTraceHandler(null);
                                        port = br.getPort();
                                        br.start();
@@ -116,7 +116,7 @@ class SerialServerTest extends TestLauncher {
 
                                try {
                                        try {
-                                               new ConnectActionClientString(null, port, ssl) {
+                                               new ConnectActionClientString(null, port, key) {
                                                        @Override
                                                        public void action(Version serverVersion)
                                                                        throws Exception {
@@ -141,14 +141,14 @@ class SerialServerTest extends TestLauncher {
                        }
                });
 
-               series.addTest(new TestCase("Multiple exchanges " + ssls) {
+               series.addTest(new TestCase("Multiple exchanges " + skey) {
                        final String[] sent = new String[3];
                        final String[] recd = new String[3];
                        final Exception[] err = new Exception[1];
 
                        @Override
                        public void test() throws Exception {
-                               ServerString server = new ServerString(this.getName(), 0, ssl) {
+                               ServerString server = new ServerString(this.getName(), 0, key) {
                                        @Override
                                        protected String onRequest(
                                                        ConnectActionServerString action,
@@ -172,7 +172,7 @@ class SerialServerTest extends TestLauncher {
 
                                ServerBridge br = null;
                                if (bridge) {
-                                       br = new ServerBridge(0, ssl, "", port, ssl);
+                                       br = new ServerBridge(0, key, "", port, key);
                                        br.setTraceHandler(null);
                                        port = br.getPort();
                                        br.start();
@@ -180,7 +180,7 @@ class SerialServerTest extends TestLauncher {
 
                                try {
                                        try {
-                                               new ConnectActionClientString(null, port, ssl) {
+                                               new ConnectActionClientString(null, port, key) {
                                                        @Override
                                                        public void action(Version serverVersion)
                                                                        throws Exception {
@@ -208,14 +208,14 @@ class SerialServerTest extends TestLauncher {
                        }
                });
 
-               series.addTest(new TestCase("Multiple call from client " + ssls) {
+               series.addTest(new TestCase("Multiple call from client " + skey) {
                        final String[] sent = new String[3];
                        final String[] recd = new String[3];
                        final Exception[] err = new Exception[1];
 
                        @Override
                        public void test() throws Exception {
-                               ServerString server = new ServerString(this.getName(), 0, ssl) {
+                               ServerString server = new ServerString(this.getName(), 0, key) {
                                        @Override
                                        protected String onRequest(
                                                        ConnectActionServerString action,
@@ -237,7 +237,7 @@ class SerialServerTest extends TestLauncher {
 
                                ServerBridge br = null;
                                if (bridge) {
-                                       br = new ServerBridge(0, ssl, "", port, ssl);
+                                       br = new ServerBridge(0, key, "", port, key);
                                        br.setTraceHandler(null);
                                        port = br.getPort();
                                        br.start();
@@ -245,7 +245,7 @@ class SerialServerTest extends TestLauncher {
 
                                try {
                                        try {
-                                               new ConnectActionClientString(null, port, ssl) {
+                                               new ConnectActionClientString(null, port, key) {
                                                        @Override
                                                        public void action(Version serverVersion)
                                                                        throws Exception {
@@ -280,18 +280,18 @@ class SerialServerTest extends TestLauncher {
        }
 
        private TestLauncher createServerObjectTestCases(final String[] args,
-                       final boolean ssl, final boolean bridge) {
-               final String ssls = (ssl ? "(ssl)" : "(plain text)");
+                       final String key, final boolean bridge) {
+               final String skey = (key != null ? "(encrypted)" : "(plain text)");
                final String bridges = (bridge ? " with bridge" : "");
                TestLauncher series = new TestLauncher(
-                               "ServerObject " + ssls + bridges, args);
+                               "ServerObject " + skey + bridges, args);
 
-               series.addTest(new TestCase("Simple connection " + ssls) {
+               series.addTest(new TestCase("Simple connection " + skey) {
                        @Override
                        public void test() throws Exception {
                                final Object[] rec = new Object[1];
 
-                               ServerObject server = new ServerObject(this.getName(), 0, ssl) {
+                               ServerObject server = new ServerObject(this.getName(), 0, key) {
                                        @Override
                                        protected Object onRequest(
                                                        ConnectActionServerObject action,
@@ -312,7 +312,7 @@ class SerialServerTest extends TestLauncher {
 
                                ServerBridge br = null;
                                if (bridge) {
-                                       br = new ServerBridge(0, ssl, "", port, ssl);
+                                       br = new ServerBridge(0, key, "", port, key);
                                        br.setTraceHandler(null);
                                        port = br.getPort();
                                        br.start();
@@ -320,7 +320,7 @@ class SerialServerTest extends TestLauncher {
 
                                try {
                                        try {
-                                               new ConnectActionClientObject(null, port, ssl) {
+                                               new ConnectActionClientObject(null, port, key) {
                                                        @Override
                                                        public void action(Version serverVersion)
                                                                        throws Exception {
@@ -345,14 +345,14 @@ class SerialServerTest extends TestLauncher {
                        }
                });
 
-               series.addTest(new TestCase("Simple exchange " + ssls) {
+               series.addTest(new TestCase("Simple exchange " + skey) {
                        final Object[] sent = new Object[1];
                        final Object[] recd = new Object[1];
                        final Exception[] err = new Exception[1];
 
                        @Override
                        public void test() throws Exception {
-                               ServerObject server = new ServerObject(this.getName(), 0, ssl) {
+                               ServerObject server = new ServerObject(this.getName(), 0, key) {
                                        @Override
                                        protected Object onRequest(
                                                        ConnectActionServerObject action,
@@ -374,7 +374,7 @@ class SerialServerTest extends TestLauncher {
 
                                ServerBridge br = null;
                                if (bridge) {
-                                       br = new ServerBridge(0, ssl, "", port, ssl);
+                                       br = new ServerBridge(0, key, "", port, key);
                                        br.setTraceHandler(null);
                                        port = br.getPort();
                                        br.start();
@@ -382,7 +382,7 @@ class SerialServerTest extends TestLauncher {
 
                                try {
                                        try {
-                                               new ConnectActionClientObject(null, port, ssl) {
+                                               new ConnectActionClientObject(null, port, key) {
                                                        @Override
                                                        public void action(Version serverVersion)
                                                                        throws Exception {
@@ -407,14 +407,14 @@ class SerialServerTest extends TestLauncher {
                        }
                });
 
-               series.addTest(new TestCase("Multiple exchanges " + ssls) {
+               series.addTest(new TestCase("Multiple exchanges " + skey) {
                        final Object[] sent = new Object[3];
                        final Object[] recd = new Object[3];
                        final Exception[] err = new Exception[1];
 
                        @Override
                        public void test() throws Exception {
-                               ServerObject server = new ServerObject(this.getName(), 0, ssl) {
+                               ServerObject server = new ServerObject(this.getName(), 0, key) {
                                        @Override
                                        protected Object onRequest(
                                                        ConnectActionServerObject action,
@@ -438,7 +438,7 @@ class SerialServerTest extends TestLauncher {
 
                                ServerBridge br = null;
                                if (bridge) {
-                                       br = new ServerBridge(0, ssl, "", port, ssl);
+                                       br = new ServerBridge(0, key, "", port, key);
                                        br.setTraceHandler(null);
                                        port = br.getPort();
                                        br.start();
@@ -446,7 +446,7 @@ class SerialServerTest extends TestLauncher {
 
                                try {
                                        try {
-                                               new ConnectActionClientObject(null, port, ssl) {
+                                               new ConnectActionClientObject(null, port, key) {
                                                        @Override
                                                        public void action(Version serverVersion)
                                                                        throws Exception {
@@ -474,14 +474,14 @@ class SerialServerTest extends TestLauncher {
                        }
                });
 
-               series.addTest(new TestCase("Object array of URLs " + ssls) {
+               series.addTest(new TestCase("Object array of URLs " + skey) {
                        final Object[] sent = new Object[1];
                        final Object[] recd = new Object[1];
                        final Exception[] err = new Exception[1];
 
                        @Override
                        public void test() throws Exception {
-                               ServerObject server = new ServerObject(this.getName(), 0, ssl) {
+                               ServerObject server = new ServerObject(this.getName(), 0, key) {
                                        @Override
                                        protected Object onRequest(
                                                        ConnectActionServerObject action,
@@ -503,7 +503,7 @@ class SerialServerTest extends TestLauncher {
 
                                ServerBridge br = null;
                                if (bridge) {
-                                       br = new ServerBridge(0, ssl, "", port, ssl);
+                                       br = new ServerBridge(0, key, "", port, key);
                                        br.setTraceHandler(null);
                                        port = br.getPort();
                                        br.start();
@@ -511,7 +511,7 @@ class SerialServerTest extends TestLauncher {
 
                                try {
                                        try {
-                                               new ConnectActionClientObject(null, port, ssl) {
+                                               new ConnectActionClientObject(null, port, key) {
                                                        @Override
                                                        public void action(Version serverVersion)
                                                                        throws Exception {
@@ -546,14 +546,14 @@ class SerialServerTest extends TestLauncher {
                        }
                });
 
-               series.addTest(new TestCase("Multiple call from client " + ssls) {
+               series.addTest(new TestCase("Multiple call from client " + skey) {
                        final Object[] sent = new Object[3];
                        final Object[] recd = new Object[3];
                        final Exception[] err = new Exception[1];
 
                        @Override
                        public void test() throws Exception {
-                               ServerObject server = new ServerObject(this.getName(), 0, ssl) {
+                               ServerObject server = new ServerObject(this.getName(), 0, key) {
                                        @Override
                                        protected Object onRequest(
                                                        ConnectActionServerObject action,
@@ -575,7 +575,7 @@ class SerialServerTest extends TestLauncher {
 
                                ServerBridge br = null;
                                if (bridge) {
-                                       br = new ServerBridge(0, ssl, "", port, ssl);
+                                       br = new ServerBridge(0, key, "", port, key);
                                        br.setTraceHandler(null);
                                        port = br.getPort();
                                        br.start();
@@ -583,7 +583,7 @@ class SerialServerTest extends TestLauncher {
 
                                try {
                                        try {
-                                               new ConnectActionClientObject(null, port, ssl) {
+                                               new ConnectActionClientObject(null, port, key) {
                                                        @Override
                                                        public void action(Version serverVersion)
                                                                        throws Exception {
@@ -620,10 +620,10 @@ class SerialServerTest extends TestLauncher {
        public SerialServerTest(String[] args) {
                super("SerialServer test", args);
 
-               for (boolean ssl : new Boolean[] { false, true }) {
+               for (String key : new String[] { null, "" }) {
                        for (boolean bridge : new Boolean[] { false, true }) {
-                               addSeries(createServerObjectTestCases(args, ssl, bridge));
-                               addSeries(createServerStringTestCases(args, ssl, bridge));
+                               addSeries(createServerObjectTestCases(args, key, bridge));
+                               addSeries(createServerStringTestCases(args, key, bridge));
                        }
                }
        }