git://git.nikiroo.be
/
nikiroo-utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
serial: switch from SSL to CryptUtils
[nikiroo-utils.git]
/
src
/
be
/
nikiroo
/
utils
/
serial
/
server
/
ServerBridge.java
diff --git
a/src/be/nikiroo/utils/serial/server/ServerBridge.java
b/src/be/nikiroo/utils/serial/server/ServerBridge.java
index db50876b32aafb144bc89047e73073c391c569f8..6c2ed019e830226ce93ed95a95c316d4b6f220eb 100644
(file)
--- a/
src/be/nikiroo/utils/serial/server/ServerBridge.java
+++ b/
src/be/nikiroo/utils/serial/server/ServerBridge.java
@@
-25,7
+25,7
@@
import be.nikiroo.utils.serial.Importer;
public class ServerBridge extends Server {
private final String forwardToHost;
private final int forwardToPort;
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
/**
* 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()}
* 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 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
*
* @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
*/
* 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.forwardToHost = forwardToHost;
this.forwardToPort = forwardToPort;
- this.forwardTo
Ssl = forwardToSsl
;
+ this.forwardTo
Key = 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
* 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 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
*
* @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
*/
* 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 {
throws IOException {
- super(name, port,
ssl
);
+ super(name, port,
key
);
this.forwardToHost = forwardToHost;
this.forwardToPort = forwardToPort;
this.forwardToHost = forwardToHost;
this.forwardToPort = forwardToPort;
- this.forwardTo
Ssl = forwardToSsl
;
+ this.forwardTo
Key = forwardToKey
;
}
/**
}
/**
@@
-118,7
+123,7
@@
public class ServerBridge extends Server {
@Override
protected ConnectActionServer createConnectActionServer(Socket s) {
@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);
@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,
try {
new ConnectActionClientString(forwardToHost, forwardToPort,
- forwardTo
Ssl
, clientVersion) {
+ forwardTo
Key
, clientVersion) {
@Override
public void action(final Version serverVersion)
throws Exception {
@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 + " ("
getTraceHandler().trace(
getName() + ": will forward to " + forwardToHost + ":"
+ forwardToPort + " ("
- + (forwardToSsl ? "SSL" : "plain text") + ")");
+ + (forwardToKey != null ? "encrypted" : "plain text")
+ + ")");
super.run();
}
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();
*/
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);
getTraceHandler().trace(prefix + ": " + ssize, 1);