Skip to contentSkip to conversation

vnc: added initial websockets support

PATCH In review Tim Hardeck 3 participants 8 messages Nov 16, 2012 – Nov 19, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vnc: added initial websockets support

This patch adds basic Websockets support to the QEMU VNC component. Websockets allow every modern web browser to connect to QEMU VNC without any additional plugins.

Because of the GnuTLS requirement the Websockets implementation is optional (--enable-vnc-ws).

Websockets connections are recognized by waiting 500ms for a Websocket handshake. If no data is received a regular vnc connection is assumed. If this is not acceptable please suggest if Websockets should be activated by a new VNC option or by an additional console parameter on a different port.

SHA1 is required for the handshake which is generated with GnuTLS. Since using GnuTLS does automatically activate VNC-TLS, which has warnings about deprecated parts, I have changed the configure script to disable VNC-TLS if not explicitly enabled.

The Websockets support was tested with noVNC http://kanaka.github.com/noVNC/ .

I have used parts of the LibVNC websockets implementation that's why I have added the GPL header to the new files. I hope that it is fine that way.

Tim Hardeck (1):
vnc: added initial websockets support

 configure        |   34 +++++++-
 ui/Makefile.objs |    1 +
 ui/vnc-ws.c      |  236 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ui/vnc-ws.h      |  104 ++++++++++++++++++++++++
 ui/vnc.c         |   93 ++++++++++++++++++---
 ui/vnc.h         |   15 ++++
 6 files changed, 471 insertions(+), 12 deletions(-)
 create mode 100644 ui/vnc-ws.c
 create mode 100644 ui/vnc-ws.h

--
1.7.10.4

#1 lore raw

PATCH 1/1 vnc: added initial websockets support

This patch adds basic Websockets version 13 - RFC 6455 - support to QEMU VNC. Binary encoding support on the client side is required.

Websockets support in QEMU is enabled by the configure option --enable-vnc-ws.

Websockets connections are recognized by waiting 500ms for a Websocket handshake. If no data is received a regular vnc connection is assumed.

SHA1 is required for the handshake which is generated by GnuTLS. Since using GnuTLS does automatically activate VNC-TLS, which has warnings about deprecated parts, I have changed the configure script to disable VNC-TLS if not explicitly enabled.

Parts of the implementation base on Anthony Liguori's QEMU Websockets patch from 2010 and on Joel Martin's LibVNC Websockets implementation.

---
 configure        |   34 +++++++-
 ui/Makefile.objs |    1 +
 ui/vnc-ws.c      |  236 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ui/vnc-ws.h      |  104 ++++++++++++++++++++++++
 ui/vnc.c         |   93 ++++++++++++++++++---
 ui/vnc.h         |   15 ++++
 6 files changed, 471 insertions(+), 12 deletions(-)
 create mode 100644 ui/vnc-ws.c
 create mode 100644 ui/vnc-ws.h
configure +33 -1
index 7290f50..d252da5 100755
@@ -154,10 +154,11 @@ vnc="yes"
 sparse="no"
 uuid=""
 vde=""
-vnc_tls=""
+vnc_tls="no"
 vnc_sasl=""
 vnc_jpeg=""
 vnc_png=""
+vnc_ws=""
 xen=""
 xen_ctrl_version=""
 xen_pci_passthrough=""
@@ -703,6 +704,10 @@ for opt do
   ;;
   --enable-vnc-png) vnc_png="yes"
   ;;
+  --disable-vnc-ws) vnc_ws="no"
+  ;;
+  --enable-vnc-ws) vnc_ws="yes"
+  ;;
   --disable-slirp) slirp="no"
   ;;
   --disable-uuid) uuid="no"
@@ -1048,6 +1053,8 @@ echo "  --disable-vnc-jpeg       disable JPEG lossy compression for VNC server"
 echo "  --enable-vnc-jpeg        enable JPEG lossy compression for VNC server"
 echo "  --disable-vnc-png        disable PNG compression for VNC server (default)"
 echo "  --enable-vnc-png         enable PNG compression for VNC server"
+echo "  --disable-vnc-ws         disable Websockets support for VNC server"
+echo "  --enable-vnc-ws          enable Websockets support for VNC server"
 echo "  --disable-curses         disable curses output"
 echo "  --enable-curses          enable curses output"
 echo "  --disable-curl           disable curl connectivity"
@@ -1772,6 +1779,26 @@ EOF
 fi
 
 ##########################################
+# VNC WS detection
+if test "$vnc" = "yes" -a "$vnc_ws" != "no" ; then
+  cat > $TMPC <<EOF
+#include <gnutls/gnutls.h>
+int main(void) { gnutls_session_t s; gnutls_init(&s, GNUTLS_SERVER); return 0; }
+EOF
+  vnc_ws_cflags=`$pkg_config --cflags gnutls 2> /dev/null`
+  vnc_ws_libs=`$pkg_config --libs gnutls 2> /dev/null`
+  if compile_prog "$vnc_ws_cflags" "$vnc_ws_libs" ; then
+    vnc_ws=yes
+    libs_softmmu="$vnc_ws_libs $libs_softmmu"
+  else
+    if test "$vnc_ws" = "yes" ; then
+      feature_not_found "vnc-ws"
+    fi
+    vnc_ws=no
+  fi
+fi
+
+##########################################
 # fnmatch() probe, used for ACL routines
 fnmatch="no"
 cat > $TMPC << EOF
@@ -3191,6 +3218,7 @@ if test "$vnc" = "yes" ; then
     echo "VNC SASL support  $vnc_sasl"
     echo "VNC JPEG support  $vnc_jpeg"
     echo "VNC PNG support   $vnc_png"
+    echo "VNC WS support    $vnc_ws"
 fi
 if test -n "$sparc_cpu"; then
     echo "Target Sparc Arch $sparc_cpu"
@@ -3367,6 +3395,10 @@ if test "$vnc_png" = "yes" ; then
   echo "CONFIG_VNC_PNG=y" >> $config_host_mak
   echo "VNC_PNG_CFLAGS=$vnc_png_cflags" >> $config_host_mak
 fi
+if test "$vnc_ws" = "yes" ; then
+  echo "CONFIG_VNC_WS=y" >> $config_host_mak
+  echo "VNC_WS_CFLAGS=$vnc_ws_cflags" >> $config_host_mak
+fi
 if test "$fnmatch" = "yes" ; then
   echo "CONFIG_FNMATCH=y" >> $config_host_mak
 fi
ui/Makefile.objs +1 -0
index adc07be..58e191b 100644
@@ -4,6 +4,7 @@ vnc-obj-y += vnc-enc-tight.o vnc-palette.o
 vnc-obj-y += vnc-enc-zrle.o
 vnc-obj-$(CONFIG_VNC_TLS) += vnc-tls.o vnc-auth-vencrypt.o
 vnc-obj-$(CONFIG_VNC_SASL) += vnc-auth-sasl.o
+vnc-obj-$(CONFIG_VNC_WS) += vnc-ws.o
 vnc-obj-y += vnc-jobs.o
 
 common-obj-y += keymaps.o
ui/vnc-ws.c new file +236 -0

236 lines not on this page · raw message

ui/vnc-ws.h new file +104 -0

104 lines not on this page · raw message

ui/vnc.c +82 -11

146 lines not on this page · raw message

ui/vnc.h +15 -0
index 6141e88..86acb6b 100644
@@ -99,6 +99,9 @@ typedef struct VncDisplay VncDisplay;
 #ifdef CONFIG_VNC_SASL
 #include "vnc-auth-sasl.h"
 #endif
+#ifdef CONFIG_VNC_WS
+#include "vnc-ws.h"
+#endif
 
 struct VncRectStat
 {
@@ -269,11 +272,18 @@ struct VncState
 #ifdef CONFIG_VNC_SASL
     VncStateSASL sasl;
 #endif
+#ifdef CONFIG_VNC_WS
+    QEMUTimer *ws_recognition_timer;
+    int encode_ws;
+#endif
 
     QObject *info;
 
     Buffer output;
     Buffer input;
+#ifdef CONFIG_VNC_WS
+    Buffer ws_input;
+#endif
     /* current output mode information */
     VncWritePixels *write_pixels;
     PixelFormat client_pf;
@@ -505,11 +515,16 @@ int vnc_client_io_error(VncState *vs, int ret, int last_errno);
 void start_client_init(VncState *vs);
 void start_auth_vnc(VncState *vs);
 
+#ifdef CONFIG_VNC_WS
+void vnc_init_state(VncState *vs);
+#endif
+
 /* Buffer management */
 void buffer_reserve(Buffer *buffer, size_t len);
 void buffer_reset(Buffer *buffer);
 void buffer_free(Buffer *buffer);
 void buffer_append(Buffer *buffer, const void *data, size_t len);
+void buffer_advance(Buffer *buf, size_t len);
 
 
 /* Misc helpers */
Signature · 1 line
1.7.10.4
#2 lore raw
In reply to Tim Hardeck
Quoted 2 lines · Tim Hardeck

Websockets connections are recognized by waiting 500ms for a Websocket handshake. If no data is received a regular vnc connection is assumed. If this is not acceptable please suggest if Websockets should be activated by a new VNC option or by an additional console parameter on a different port.

Perhaps it's better to speak Websockets on a different port. That way no timer is required and we never fail to detect the correct protocol to speak.

Stefan

#3 lore raw

Hi Stefan,

thanks for your input but how should it be implemented?

I personally would like activating Websockets as a VNC option like: " -vnc :0 -vnc :1,websockets"
I have already tested this locally and it does work but only for one protocol since QEMU does only interpret the last vnc option. So is allowing more than one VNC command line entry in combination with having more than one VNC thread for the same display worth working on or do you have something different in mind?

Regards
Tim

Quoted 9 lines · Stefan Hajnoczi
Quoted 2 lines · Tim Hardeck

Websockets connections are recognized by waiting 500ms for a Websocket handshake. If no data is received a regular vnc connection is assumed. If this is not acceptable please suggest if Websockets should be activated by a new VNC option or by an additional console parameter on a different port.

Perhaps it's better to speak Websockets on a different port. That way no timer is required and we never fail to detect the correct protocol to speak.

Stefan

Signature · 5 lines
SUSE LINUX Products GmbH, GF: Jeff Hawn, Jennifer Guild, Felix
Imendörffer, HRB 16746 (AG Nürnberg)
Maxfeldstr. 5, 90409 Nürnberg, Germany
T: +49 (0) 911 74053-0  F: +49 (0) 911 74053-483
http://www.suse.de/
#4 lore raw
Quoted 11 lines · Tim Hardeck

Hi Stefan,

thanks for your input but how should it be implemented?

I personally would like activating Websockets as a VNC option like:
" -vnc :0 -vnc :1,websockets" I have already tested this locally and it does work but only for one protocol since QEMU does only interpret the last vnc option. So is allowing more than one VNC command line entry in combination with having more than one VNC thread for the same display worth working on or do you have something different in mind?

-vnc :0,websock=$portnr ?

cheers,
Gerd

#5 lore raw
Quoted 13 lines · Gerd Hoffmann
Quoted 11 lines · Tim Hardeck

Hi Stefan,

thanks for your input but how should it be implemented?

I personally would like activating Websockets as a VNC option like:
" -vnc :0 -vnc :1,websockets" I have already tested this locally and it does work but only for one protocol since QEMU does only interpret the last vnc option. So is allowing more than one VNC command line entry in combination with having more than one VNC thread for the same display worth working on or do you have something different in mind?

Quoted 1 line

-vnc :0,websock=$portnr ?

This sounds resonable although maybe the websockets port could just always be display + 1 so there is no need to parse a port.

Regards
Tim

Signature · 5 lines
SUSE LINUX Products GmbH, GF: Jeff Hawn, Jennifer Guild, Felix
Imendörffer, HRB 16746 (AG Nürnberg)
Maxfeldstr. 5, 90409 Nürnberg, Germany
T: +49 (0) 911 74053-0  F: +49 (0) 911 74053-483
http://www.suse.de/
#6 lore raw
In reply to Tim Hardeck
Quoted 11 lines · Tim Hardeck

Hi Stefan,

thanks for your input but how should it be implemented?

I personally would like activating Websockets as a VNC option like: " -vnc :0 -vnc :1,websockets"
I have already tested this locally and it does work but only for one protocol since QEMU does only interpret the last vnc option. So is allowing more than one VNC command line entry in combination with having more than one VNC thread for the same display worth working on or do you have something different in mind?

I'm not familiar enough with the VNC code to suggest how to best implement this.

One thing to think about is that Websockets is a transport. Perhaps the VNC code itself shouldn't speak it, instead generic QEMU socket code should implement Websockets so that non-VNC components can also make use of it in the future.

Stefan

#7 lore raw
Quoted 13 lines · Stefan Hajnoczi
Quoted 11 lines · Tim Hardeck

Hi Stefan,

thanks for your input but how should it be implemented?

I personally would like activating Websockets as a VNC option like: " -vnc :0 -vnc :1,websockets"
I have already tested this locally and it does work but only for one protocol since QEMU does only interpret the last vnc option. So is allowing more than one VNC command line entry in combination with having more than one VNC thread for the same display worth working on or do you have something different in mind?

Quoted 7 lines

I'm not familiar enough with the VNC code to suggest how to best implement this.

One thing to think about is that Websockets is a transport. Perhaps the VNC code itself shouldn't speak it, instead generic QEMU socket code should implement Websockets so that non-VNC components can also make use of it in the future.

I have talked about this with a colleague and it seems like quite some effort for no use case besides VNC.
It might be interesting in the long run though.

Is the rest of my implementation OK besides the protocol recognition by timeout - which should only be an issue for high latency websockets connection?

Regards
Tim

Signature · 5 lines
SUSE LINUX Products GmbH, GF: Jeff Hawn, Jennifer Guild, Felix
Imendörffer, HRB 16746 (AG Nürnberg)
Maxfeldstr. 5, 90409 Nürnberg, Germany
T: +49 (0) 911 74053-0  F: +49 (0) 911 74053-483
http://www.suse.de/