X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FRemoteLibraryServer.java;h=72f4e83bcc19a8563102a2adccf3e2762ebce3e8;hb=f83510cf13d55c8700de01ee06ae752da1d102b4;hp=f0d5f7aea0722e68c39d0835e36f85c41b0e65e3;hpb=49f3dec53ec85b1720dbbfb62a2d495011b66622;p=fanfix.git
diff --git a/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java b/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java
index f0d5f7a..72f4e83 100644
--- a/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java
+++ b/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java
@@ -6,6 +6,8 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
+import javax.net.ssl.SSLException;
+
import be.nikiroo.fanfix.Instance;
import be.nikiroo.fanfix.data.Chapter;
import be.nikiroo.fanfix.data.MetaData;
@@ -14,7 +16,6 @@ import be.nikiroo.fanfix.data.Story;
import be.nikiroo.utils.Progress;
import be.nikiroo.utils.Progress.ProgressListener;
import be.nikiroo.utils.StringUtils;
-import be.nikiroo.utils.Version;
import be.nikiroo.utils.serial.server.ConnectActionServerObject;
import be.nikiroo.utils.serial.server.ServerObject;
@@ -24,14 +25,6 @@ import be.nikiroo.utils.serial.server.ServerObject;
* The available commands are given as arrays of objects (first item is the
* command, the rest are the arguments).
*
- * All commands, including PING, will first return a random value to you that
- * you must hash with your key and return before processing the rest; if the
- * value not correct, the connection will be closed.
- *
- * BTW: this system is by no means secure. It is just slightly
- * obfuscated, and operate on clear text (because Google decided not to support
- * anonymous SSL exchanges on Android, and the main use case for this server is
- * Android).
*
* - PING: will return PONG if the key is accepted
* - GET_METADATA *: will return the metadata of all the stories in the
@@ -57,8 +50,6 @@ import be.nikiroo.utils.serial.server.ServerObject;
* @author niki
*/
public class RemoteLibraryServer extends ServerObject {
- private final String key;
-
/**
* Create a new remote server (will not be active until
* {@link RemoteLibraryServer#start()} is called).
@@ -72,22 +63,21 @@ public class RemoteLibraryServer extends ServerObject {
* in case of I/O error
*/
public RemoteLibraryServer(String key, int port) throws IOException {
- super("Fanfix remote library", port, false);
- this.key = key;
+ super("Fanfix remote library", port, key);
setTraceHandler(Instance.getTraceHandler());
}
@Override
- protected Object onRequest(ConnectActionServerObject action,
- Version clientVersion, Object data) throws Exception {
+ protected Object onRequest(ConnectActionServerObject action, Object data)
+ throws Exception {
long start = new Date().getTime();
String command = "";
Object[] args = new Object[0];
if (data instanceof Object[]) {
Object[] dataArray = (Object[]) data;
- if (dataArray.length >= 2) {
+ if (dataArray.length > 0) {
command = "" + dataArray[0];
args = new Object[dataArray.length - 1];
@@ -103,18 +93,6 @@ public class RemoteLibraryServer extends ServerObject {
}
System.out.println(trace);
- // Authentication:
- String random = StringUtils.getMd5Hash(Double.toString(Math.random()));
- action.send(random);
- String answer = "" + action.rec();
-
- if (!answer.equals(RemoteLibrary.hashKey(key, random))) {
- System.out.println("Key rejected.");
- action.close();
- return null;
- }
- //
-
Object rep = doRequest(action, command, args);
String rec = StringUtils.formatNumber(action.getBytesReceived()) + "b";
@@ -224,7 +202,11 @@ public class RemoteLibraryServer extends ServerObject {
@Override
protected void onError(Exception e) {
- getTraceHandler().error(e);
+ if (e instanceof SSLException) {
+ System.out.println("[Client connection refused (bad key)]");
+ } else {
+ getTraceHandler().error(e);
+ }
}
/**