X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fserial%2Fserver%2FConnectAction.java;h=39417a77fca5c7671afd7d932d12cc22d4115397;hb=d9e2136bc52c2b7661698614016d864cfa8b350b;hp=8f57c628fb18e861c9805174468f5ccb0ce0fba1;hpb=79ce1a4973eba079ba819ba841d906de42f38e40;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/serial/server/ConnectAction.java b/src/be/nikiroo/utils/serial/server/ConnectAction.java index 8f57c62..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,12 +104,26 @@ 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 { if (server) { + String line = in.readLine(); + if (line != null && line.startsWith("VERSION ")) { + // "VERSION client-version" (VERSION 1.0.0) + Version clientVersion = new Version( + line.substring("VERSION ".length())); + this.clientVersion = clientVersion; + Version v = negotiateVersion(clientVersion); + if (v == null) { + v = new Version(); + } + + sendString("VERSION " + v.toString()); + } + action(clientVersion); } else { String v = sendString("VERSION " + version.toString()); @@ -119,11 +135,27 @@ abstract class ConnectAction { } } finally { out.close(); + out = null; } } finally { in.close(); + 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 { @@ -156,10 +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)); + String rep = sendString( + new Exporter().append(data).toString(true, true)); if (rep != null) { return new Importer().read(rep).getValue(); } @@ -192,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"); @@ -253,22 +287,7 @@ abstract class ConnectAction { contentToSend = false; } - String line = in.readLine(); - if (server && line != null && line.startsWith("VERSION ")) { - // "VERSION client-version" (VERSION 1.0.0) - Version clientVersion = new Version( - line.substring("VERSION ".length())); - this.clientVersion = clientVersion; - Version v = negotiateVersion(clientVersion); - if (v == null) { - v = new Version(); - } - sendString("VERSION " + v.toString()); - - line = in.readLine(); - } - - return line; + return in.readLine(); } return null;