summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2020-05-15 15:28:04 +0200
committerSimon Rettberg2020-05-15 15:28:04 +0200
commit71dc6a3e9053d22ab6b0fe7a6e6960653813fcd0 (patch)
tree3a68f5d75e7972600da660c334952b6d3c75052b
parentKeep track of the number of tunnels per user. (diff)
downloadbwlp-guacamole-ext-71dc6a3e9053d22ab6b0fe7a6e6960653813fcd0.tar.gz
bwlp-guacamole-ext-71dc6a3e9053d22ab6b0fe7a6e6960653813fcd0.tar.xz
bwlp-guacamole-ext-71dc6a3e9053d22ab6b0fe7a6e6960653813fcd0.zip
Check if remote host actually repies with RFB handshake
-rw-r--r--src/main/java/de/bwlehrpool/bwlp_guac/AvailableClient.java11
-rw-r--r--src/main/java/de/bwlehrpool/bwlp_guac/VncConnection.java6
2 files changed, 14 insertions, 3 deletions
diff --git a/src/main/java/de/bwlehrpool/bwlp_guac/AvailableClient.java b/src/main/java/de/bwlehrpool/bwlp_guac/AvailableClient.java
index 8798813..c60db10 100644
--- a/src/main/java/de/bwlehrpool/bwlp_guac/AvailableClient.java
+++ b/src/main/java/de/bwlehrpool/bwlp_guac/AvailableClient.java
@@ -161,18 +161,23 @@ public class AvailableClient implements Cloneable {
if (now < this.lastConnectionCheck) {
this.lastConnectionCheck = 0;
}
- if (now - this.lastConnectionCheck < 1000)
+ if (now - this.lastConnectionCheck < 2000)
return this.connectionOk;
for (;;) {
try (VncConnection vnc = new VncConnection(this.clientip, 5900)) {
- LOGGER.debug("VNC Version for " + this.clientip + " is " + vnc.handshake());
+ String version = vnc.handshake();
+ if (version == null) {
+ LOGGER.info("Host " + this.clientip + " doesn't speak RFB protocol");
+ break;
+ }
+ LOGGER.debug("VNC Version for " + this.clientip + " is " + version);
if (vnc.tryLogin(this.password)) {
LOGGER.info("Connection to " + this + " is OK");
this.lastConnectionCheck = now;
return this.connectionOk = true;
}
} catch (IOException e) {
- LOGGER.info("Connection error VNC @ " + this, e);
+ LOGGER.info("Connection error VNC @ " + this);
if (retries-- > 0) {
try {
Thread.sleep(1000);
diff --git a/src/main/java/de/bwlehrpool/bwlp_guac/VncConnection.java b/src/main/java/de/bwlehrpool/bwlp_guac/VncConnection.java
index 8bd4bd0..06a7013 100644
--- a/src/main/java/de/bwlehrpool/bwlp_guac/VncConnection.java
+++ b/src/main/java/de/bwlehrpool/bwlp_guac/VncConnection.java
@@ -36,9 +36,15 @@ public class VncConnection implements Closeable {
in = new DataInputStream(sock.getInputStream());
}
+ /**
+ * @return Version string on success, null if not RFB
+ * @throws IOException
+ */
public String handshake() throws IOException {
byte[] buffer = new byte[12];
in.readFully(buffer);
+ if (buffer[0] != 'R' || buffer[1] != 'F' || buffer[2] != 'B')
+ return null;
out.write("RFB 003.008\n".getBytes());
out.flush();
return new String(buffer).substring(4, 11);