PATCH: 0/9: Support SASL authentication in VNC server (version 4)
Previously I provided patches for QEMU's VNC server to support SSL/TLS and x509 certificates. This provides good encryption capabilities for the VNC session. It doesn't really address the authentication problem though.
I have been working to create a new authentication type in the RFB protocol to address this need in a generic, extendable way, by mapping the SASL API into the RFB protocol. Since SASL is a generic plugin based API, this will allow use of a huge range of auth mechanims over VNC, without us having to add any more auth code. For example, PAM, Digest-MD5, GSSAPI/Kerberos, One-time key/password, LDAP password lookup, SQL db password lookup, and more.
I have got a VNC auth type assigned by the RFB spec maintainers:
http://realvnc.com/pipermail/vnc-list/2008-December/059463.html
With the full current spec for the SASL extension currently documented here:
http://realvnc.com/pipermail/vnc-list/2008-December/059462.html
This is the 4th version of the patches I previously posted:
v1: http://lists.gnu.org/archive/html/qemu-devel/2009-02/msg00255.html
v2: http://lists.gnu.org/archive/html/qemu-devel/2009-02/msg00826.html
v3: http://lists.gnu.org/archive/html/qemu-devel/2009-02/msg01418.html
Changes since last time
- Removed mistaken changes to qemu-doc.texi from bad merge
- Renamed the 'ACL' struct to 'qemu_acl' to avoid clash with a system header typedef in Win32 platforms
- Check for 'fnmatch' function in configure, and if not found then revert to exact strcmp() matching instead of wildcard matching
- Add docs for the 'acl' monitor command
The combined diffstat for all 9 patches is
Makefile | 27 + Makefile.target | 5 b/acl.c | 298 +++++++++++++ b/acl.h | 77 +++ b/keymaps.h | 60 ++ b/qemu.sasl | 34 + b/vnc-auth-sasl.c | 636 ++++++++++++++++++++++++++++ b/vnc-auth-sasl.h | 74 +++ b/vnc-auth-vencrypt.c | 175 +++++++ b/vnc-auth-vencrypt.h | 33 + b/vnc-tls.c | 450 ++++++++++++++++++++ b/vnc-tls.h | 76 +++ configure | 52 ++ curses.c | 3 curses_keys.h | 9 keymaps.c | 45 -- monitor.c | 95 ++++ qemu-doc.texi | 146 ++++++ sdl.c | 3 sdl_keysym.h | 7 vl.c | 12 vnc.c | 1117 ++++++++++++++++++-------------------------------- vnc.h | 229 +++++++++- vnc_keysym.h | 7 24 files changed, 2908 insertions(+), 762 deletions(-)
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Re: [Qemu-devel] PATCH: 1/9: Fix bug in TLS authentication
This patch was previously posted here:
http://lists.gnu.org/archive/html/qemu-devel/2009-02/msg00820.html
In the case where the TLS handshake does *not* block on I/O, QEMU sends the next 'start sub-auth' message twice. This seriously confuses the VNC client :-) Fortunately the chances of the handshake not blocking are close to zero for a TCP socket, which is why it has not been noticed thus far. Even with both client & server on localhost, I can only hit the bug 1 time in 20.
NB, the diff context here is not too informative. If you look at the full code you'll see that a few lines early we called vnc_start_tls() which called vnc_continue_handshake() which called the method start_auth_vencrypt_subauth(). Hence, fixing the bug, just involves removing the 2nd bogus call to start_auth_vencrypt_subauth() as per this patch.
vnc.c | 8 -------- 1 file changed, 8 deletions(-)
vnc.c +0 -8
@@ -2096,14 +2096,6 @@ static int protocol_client_vencrypt_authVNC_DEBUG ("Failed to complete TLS\n" );return 0 ; } - -if (vs->wiremode ==VNC_WIREMODE_TLS ) { -VNC_DEBUG ("Starting VeNCrypt subauth\n" ); -return start_auth_vencrypt_subauth (vs); - }else { -VNC_DEBUG ("TLS handshake blocked\n" ); -return 0 ; - } }return 0 ; }
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Re: [Qemu-devel] PATCH: 2/9: Enhance 'info vnc' monitor output
In reply to Daniel P. BerrangeThe current 'info vnc' monitor output just displays the VNC server address as provided by the -vnc command line flag. This isn't particularly useful since it doesn't tell you what VNC is actually listening on. eg, if you use '-vnc :1' it is useful to know whether this translated to '0.0.0.0:5901' or chose IPv6 ':::5901'. It is also useful to know the address of the client that is currently connected. It is also useful to know the active authentication (if any).
This patch tweaks the monitor output to look like:
(qemu) info vnc
Server:
address: 0.0.0.0:5902
auth: vencrypt+x509
Client: noneAnd when 2 clients are connected
(qemu) info vnc
Server:
address: 0.0.0.0:5902
auth: vencrypt+x509
Client:
address: 10.33.6.67:38621
Client:
address: 10.33.6.63:38620More data will be added to this later in the patch series...
The 'addr_to_string' helper method in this patch is overly generic for the needs of this patch alone. This is because it will be re-used by the later SASL patches in this series, where the flexibility is important.
vnc.c | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 127 insertions(+), 10 deletions(-)
vnc.c +127 -10
@@ -166,19 +166,136 @@ struct VncStatestatic VncDisplay *vnc_display;/* needed for info vnc */ static DisplayChangeListener *dcl; +static char *addr_to_string (const char *format, +struct sockaddr_storage *sa, +socklen_t salen) { +char *addr; +char host[NI_MAXHOST ]; +char serv[NI_MAXSERV ]; +int err; + +if ((err =getnameinfo ((struct sockaddr *)sa, salen, + host,sizeof (host), + serv,sizeof (serv), +NI_NUMERICHOST |NI_NUMERICSERV )) !=0 ) { +VNC_DEBUG ("Cannot resolve address %d: %s\n" , + err,gai_strerror (err)); +return NULL ; + } + +if (asprintf (&addr, format, host, serv) <0 ) +return NULL ; + +return addr; +} + +static char *vnc_socket_local_addr (const char *format,int fd) { +struct sockaddr_storage sa; +socklen_t salen; + + salen =sizeof (sa); +if (getsockname (fd, (struct sockaddr *)&sa, &salen) <0 ) +return NULL ; + +return addr_to_string (format, &sa, salen); +} + +static char *vnc_socket_remote_addr (const char *format,int fd) { +struct sockaddr_storage sa; +socklen_t salen; + + salen =sizeof (sa); +if (getpeername (fd, (struct sockaddr *)&sa, &salen) <0 ) +return NULL ; + +return addr_to_string (format, &sa, salen); +} + +static const char *vnc_auth_name (VncDisplay *vd) { +switch (vd->auth) { +case VNC_AUTH_INVALID : +return "invalid" ; +case VNC_AUTH_NONE : +return "none" ; +case VNC_AUTH_VNC : +return "vnc" ; +case VNC_AUTH_RA2 : +return "ra2" ; +case VNC_AUTH_RA2NE : +return "ra2ne" ; +case VNC_AUTH_TIGHT : +return "tight" ; +case VNC_AUTH_ULTRA : +return "ultra" ; +case VNC_AUTH_TLS : +return "tls" ; +case VNC_AUTH_VENCRYPT : +#ifdef CONFIG_VNC_TLS +switch (vd->subauth) { +case VNC_AUTH_VENCRYPT_PLAIN : +return "vencrypt+plain" ; +case VNC_AUTH_VENCRYPT_TLSNONE : +return "vencrypt+tls+none" ; +case VNC_AUTH_VENCRYPT_TLSVNC : +return "vencrypt+tls+vnc" ; +case VNC_AUTH_VENCRYPT_TLSPLAIN : +return "vencrypt+tls+plain" ; +case VNC_AUTH_VENCRYPT_X509NONE : +return "vencrypt+x509+none" ; +case VNC_AUTH_VENCRYPT_X509VNC : +return "vencrypt+x509+vnc" ; +case VNC_AUTH_VENCRYPT_X509PLAIN : +return "vencrypt+x509+plain" ; +default : +return "vencrypt" ; + } +#else +return "vencrypt" ; +#endif + } +return "unknown" ; +} + +#define VNC_SOCKET_FORMAT_PRETTY "local %s:%s" + +static void do_info_vnc_client (VncState *client) +{ +char *clientAddr = +vnc_socket_remote_addr (" address: %s:%s\n" , + client->csock); +if (!clientAddr) +return ; + +term_puts ("Client:\n" ); +term_puts (clientAddr); +free (clientAddr); +} +void do_info_vnc (void ) { -if (vnc_display ==NULL || vnc_display->display ==NULL ) -term_printf ("VNC server disabled\n" ); -else { -term_printf ("VNC server active on: " ); -term_print_filename (vnc_display->display); -term_printf ("\n" ); +if (vnc_display ==NULL || vnc_display->display ==NULL ) { +term_printf ("Server: disabled\n" ); + }else { +char *serverAddr =vnc_socket_local_addr (" address: %s:%s\n" , + vnc_display->lsock); -if (vnc_display->clients ==NULL ) -term_printf ("No client connected\n" ); -else -term_printf ("Client connected\n" ); +if (!serverAddr) +return ; + +term_puts ("Server:\n" ); +term_puts (serverAddr); +free (serverAddr); +term_printf (" auth: %s\n" ,vnc_auth_name (vnc_display)); + +if (vnc_display->clients) { +VncState *client = vnc_display->clients; +while (client) { +do_info_vnc_client (client); + client = client->next; + } + }else { +term_printf ("Client: none\n" ); + } } }
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Re: [Qemu-devel] PATCH: 3/9: Refactor keymap code to avoid duplication
In reply to Daniel P. BerrangeEach of the graphical frontends #include a .c file, for keymap code resulting in duplicated definitions & duplicated compiled code. A couple of small changes allowed this to be sanitized, so instead of doing a #include "keymaps.c", duplicating all code, we can have a shared keymaps.h file, and only compile code once. This allows the next patch to move the VncState struct out into a header file without causing clashing definitions.
Makefile | 9 +++++--- b/keymaps.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ curses.c | 3 -- curses_keys.h | 9 +++----- keymaps.c | 45 ++++++++++++++++--------------------------- sdl.c | 3 -- sdl_keysym.h | 7 ++---- vnc.c | 5 +--- vnc_keysym.h | 7 ++---- 9 files changed, 97 insertions(+), 51 deletions(-)
Makefile +6 -3
@@ -137,6 +137,7 @@ endif AUDIO_OBJS+= wavcapture.o OBJS+=$(addprefix audio/, $(AUDIO_OBJS)) +OBJS+=keymaps.o ifdef CONFIG_SDL OBJS+=sdl.o x_keymap.o endif
@@ -161,15 +162,17 @@ LIBS+=$(VDE_LIBS) cocoa.o: cocoa.m -sdl.o: sdl.c keymaps.c sdl_keysym.h +keymaps.o: keymaps.c keymaps.h + +sdl.o: sdl.c keymaps.h sdl_keysym.h sdl.o audio/sdlaudio.o: CFLAGS += $(SDL_CFLAGS) -vnc.o: vnc.c keymaps.c sdl_keysym.h vnchextile.h d3des.c d3des.h +vnc.o: vnc.c keymaps.h sdl_keysym.h vnchextile.h d3des.c d3des.h vnc.o: CFLAGS += $(CONFIG_VNC_TLS_CFLAGS) -curses.o: curses.c keymaps.c curses_keys.h +curses.o: curses.c keymaps.h curses_keys.h bt-host.o: CFLAGS += $(CONFIG_BLUEZ_CFLAGS)
curses.c +1 -2
@@ -158,7 +158,6 @@ static void curses_cursor_position(Displ/* generic keyboard conversion */ #include "curses_keys.h" -#include "keymaps.c" static kbd_layout_t *kbd_layout =0 ;static int keycode2keysym[CURSES_KEYS ];
@@ -311,7 +310,7 @@ static void curses_keyboard_setup(void) keyboard_layout ="en-us" ;#endif if (keyboard_layout) { - kbd_layout =init_keyboard_layout (keyboard_layout); + kbd_layout =init_keyboard_layout (name2keysym, keyboard_layout);if (!kbd_layout)exit (1 ); }
curses_keys.h +4 -5
@@ -21,6 +21,10 @@* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + +#include "keymaps.h" + +#define KEY_RELEASE 0x80#define KEY_MASK 0x7f#define SHIFT_CODE 0x2a
@@ -239,11 +243,6 @@ static const int curses2keysym[CURSES_KE }; -typedef struct { -const char * name; -int keysym; -}name2keysym_t ; -static const name2keysym_t name2keysym[] = {/* Plain ASCII */ {"space" ,0x020 },
keymaps.c +17 -28
98 lines not on this page · raw message
keymaps.h new file +60 -0
60 lines not on this page · raw message
sdl.c +1 -2
@@ -107,7 +107,6 @@ static void sdl_resize(DisplayState *ds)/* generic keyboard conversion */ #include "sdl_keysym.h" -#include "keymaps.c" static kbd_layout_t *kbd_layout =NULL ;
@@ -623,7 +622,7 @@ void sdl_display_init(DisplayState *ds, keyboard_layout ="en-us" ;#endif if (keyboard_layout) { - kbd_layout =init_keyboard_layout (keyboard_layout); + kbd_layout =init_keyboard_layout (name2keysym, keyboard_layout);if (!kbd_layout)exit (1 ); }
sdl_keysym.h +3 -4
@@ -1,7 +1,6 @@ -typedef struct { -const char * name; -int keysym; -}name2keysym_t ; + +#include "keymaps.h" +static const name2keysym_t name2keysym[]={/* ascii */ {"space" ,0x020 },
vnc.c +2 -3
@@ -35,7 +35,6 @@#include "vnc.h" #include "vnc_keysym.h" -#include "keymaps.c" #include "d3des.h" #ifdef CONFIG_VNC_TLS
@@ -2420,9 +2419,9 @@ void vnc_display_init(DisplayState *ds) vs->ds = ds;if (keyboard_layout) - vs->kbd_layout =init_keyboard_layout (keyboard_layout); + vs->kbd_layout =init_keyboard_layout (name2keysym, keyboard_layout);else - vs->kbd_layout =init_keyboard_layout ("en-us" ); + vs->kbd_layout =init_keyboard_layout (name2keysym,"en-us" );if (!vs->kbd_layout)exit (1 );
vnc_keysym.h +3 -4
@@ -1,7 +1,6 @@ -typedef struct { -const char * name; -int keysym; -}name2keysym_t ; + +#include "keymaps.h" +static const name2keysym_t name2keysym[]={/* ascii */ {"space" ,0x020 },
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Re: [Qemu-devel] PATCH: 4/9: Move VNC structs into header file
In reply to Daniel P. BerrangeThis patch moves the definitions of VncState and VncDisplay structs out into a vnc.h header file. This is to allow the code for TLS and SASL auth mechanisms to be moved out of the main vnc.c file.
vnc.c | 109 ------------------------------------------------ vnc.h | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 148 insertions(+), 110 deletions(-)
vnc.c +2 -107
@@ -3,6 +3,7 @@* * Copyright (C) 2006 Anthony Liguori <[email protected]> * Copyright (C) 2006 Fabrice Bellard +* Copyright (C) 2009 Red Hat, Inc * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal
@@ -23,25 +24,16 @@* THE SOFTWARE. */ -#include "qemu-common.h" -#include "console.h" +#include "vnc.h" #include "sysemu.h" #include "qemu_socket.h" #include "qemu-timer.h" -#include "audio/audio.h" -#include <zlib.h> #define VNC_REFRESH_INTERVAL (1000 / 30) -#include "vnc.h" #include "vnc_keysym.h" #include "d3des.h" -#ifdef CONFIG_VNC_TLS -#include <gnutls/gnutls.h> -#include <gnutls/x509.h> -#endif /* CONFIG_VNC_TLS */ -// #define _VNC_DEBUG 1 #ifdef _VNC_DEBUG
@@ -64,103 +56,6 @@ static void vnc_debug_gnutls_log(int lev } \ } -typedef struct Buffer -{ -size_t capacity; -size_t offset; -uint8_t *buffer; -}Buffer ; - -typedef struct VncState VncState ; - -typedef int VncReadEvent (VncState *vs,uint8_t *data,size_t len); - -typedef void VncWritePixels (VncState *vs,void *data,int size); - -typedef void VncSendHextileTile (VncState *vs, -int x,int y,int w,int h, -void *last_bg, -void *last_fg, -int *has_bg,int *has_fg); - -#define VNC_MAX_WIDTH 2048 -#define VNC_MAX_HEIGHT 2048 -#define VNC_DIRTY_WORDS (VNC_MAX_WIDTH / (16 * 32)) - -#define VNC_AUTH_CHALLENGE_SIZE 16 - -typedef struct VncDisplay VncDisplay ; - -struct VncDisplay -{ -int lsock; -DisplayState *ds; -VncState *clients; -kbd_layout_t *kbd_layout; - -char *display; -char *password; -int auth; -#ifdef CONFIG_VNC_TLS -int subauth; -int x509verify; - -char *x509cacert; -char *x509cacrl; -char *x509cert; -char *x509key; -#endif -}; - -struct VncState -{ -QEMUTimer *timer; -int csock; -DisplayState *ds; -VncDisplay *vd; -int need_update; -uint32_t dirty_row[VNC_MAX_HEIGHT ][VNC_DIRTY_WORDS ]; -char *old_data; -uint32_t features; -int absolute; -int last_x; -int last_y; - -uint32_t vnc_encoding; -uint8_t tight_quality; -uint8_t tight_compression; - -int major; -int minor; - -char challenge[VNC_AUTH_CHALLENGE_SIZE ]; - -#ifdef CONFIG_VNC_TLS -int wiremode; -gnutls_session_t tls_session; -#endif - -Buffer output; -Buffer input; -/* current output mode information */ -VncWritePixels *write_pixels; -VncSendHextileTile *send_hextile_tile; -DisplaySurface clientds, serverds; - -CaptureVoiceOut *audio_cap; -struct audsettings as; - -VncReadEvent *read_handler; -size_t read_handler_expect; -/* input */ -uint8_t modifiers_state[256 ]; - -Buffer zlib; -Buffer zlib_tmp; -z_stream zlib_stream[4 ]; - -VncState *next; -};static VncDisplay *vnc_display;/* needed for info vnc */ static DisplayChangeListener *dcl;
vnc.h +146 -3
155 lines not on this page · raw message
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Re: [Qemu-devel] PATCH: 5/9: Move TLS auth into separate file
In reply to Daniel P. BerrangeThis patch refactors the existing TLS code to make the main VNC code more managable. The code moves to two new files
- vnc-tls.c: generic helpers for TLS handshake & credential setup
- vnc-auth-vencrypt.c: the actual VNC TLS authentication mechanism.
The reason for this split is that there are other TLS based auth mechanisms which we may like to use in the future. These can all share the same vnc-tls.c routines. In addition this will facilitate anyone who may want to port the vnc-tls.c file to allow for choice of GNUTLS & NSS for impl.
The TLS state is moved out of the VncState struct, and into a separate VncStateTLS struct, defined in vnc-tls.h. This is then referenced from the main VncState. End size of the struct is the same, but it keeps things a little more managable.
The vnc.h file gains a bunch more function prototypes, for functions in vnc.c that were previously static, but now need to be accessed from the separate auth code files.
The only TLS related code still in the main vl.c is the command line argument handling / setup, and the low level I/O routines calling gnutls_send/recv.
Makefile | 11 b/vnc-auth-vencrypt.c | 167 ++++++++++++++ b/vnc-auth-vencrypt.h | 33 ++ b/vnc-tls.c | 414 +++++++++++++++++++++++++++++++++++ b/vnc-tls.h | 70 ++++++ vnc.c | 581 +++----------------------------------------------- vnc.h | 76 ++++-- 7 files changed, 780 insertions(+), 572 deletions(-)
Makefile +10 -1
@@ -145,6 +145,9 @@ ifdef CONFIG_CURSES OBJS+=curses.o endif OBJS+=vnc.o d3des.o +ifdef CONFIG_VNC_TLS +OBJS+=vnc-tls.o vnc-auth-vencrypt.o +endif ifdef CONFIG_COCOA OBJS+=cocoa.o
@@ -168,10 +171,16 @@ sdl.o: sdl.c keymaps.h sdl_keysym.h sdl.o audio/sdlaudio.o: CFLAGS += $(SDL_CFLAGS) -vnc.o: vnc.c keymaps.h sdl_keysym.h vnchextile.h d3des.c d3des.h +vnc.h: vnc-tls.h vnc-auth-vencrypt.h keymaps.h + +vnc.o: vnc.c vnc.h vnc_keysym.h vnchextile.h d3des.c d3des.h vnc.o: CFLAGS += $(CONFIG_VNC_TLS_CFLAGS) +vnc-tls.o: vnc-tls.c vnc.h + +vnc-auth-vencrypt.o: vnc-auth-vencrypt.c vnc.h + curses.o: curses.c keymaps.h curses_keys.h bt-host.o: CFLAGS += $(CONFIG_BLUEZ_CFLAGS)
vnc-auth-vencrypt.c new file +167 -0
167 lines not on this page · raw message
vnc-auth-vencrypt.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* QEMU VNC display driver +* +* Copyright (C) 2006 Anthony Liguori <[email protected]> +* Copyright (C) 2006 Fabrice Bellard +* Copyright (C) 2009 Red Hat, Inc +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + + +#ifndef __QEMU_VNC_AUTH_VENCRYPT_H__ +#define __QEMU_VNC_AUTH_VENCRYPT_H__ + +void start_auth_vencrypt (VncState *vs); + +#endif /* __QEMU_VNC_AUTH_VENCRYPT_H__ */
vnc-tls.c new file +414 -0
414 lines not on this page · raw message
vnc-tls.h new file +70 -0
70 lines not on this page · raw message
vnc.c +36 -545
756 lines not on this page · raw message
vnc.h +50 -26
117 lines not on this page · raw message
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Re: [Qemu-devel] PATCH: 6/9: Add SASL authentication support
In reply to Daniel P. BerrangeThis patch adds the new SASL authentication protocol to the VNC server.
It is enabled by setting the 'sasl' flag when launching VNC. SASL can optionally provide encryption via its SSF layer, if a suitable mechanism is configured (eg, GSSAPI/Kerberos, or Digest-MD5). If an SSF layer is not available, then it should be combined with the x509 VNC authentication protocol which provides encryption.
eg, if using GSSAPI
qemu -vnc localhost:1,sasl
eg if using TLS/x509 for encryption
qemu -vnc localhost:1,sasl,tls,x509
By default the Cyrus SASL library will look for its configuration in the file /etc/sasl2/qemu.conf. For non-root users, this can be overridden by setting the SASL_CONF_PATH environment variable, eg to make it look in $HOME/.sasl2. NB unprivileged users may not have access to the full range of SASL mechanisms, since some of them require some administrative privileges to configure. The patch includes an example SASL configuration file which illustrates config for GSSAPI and Digest-MD5, though it should be noted that the latter is not really considered secure any more.
Most of the SASL authentication code is located in a separate source file, vnc-auth-sasl.c. The main vnc.c file only contains minimal integration glue, specifically parsing of command line flags / setup, and calls to start the SASL auth process, to do encoding/decoding for data.
There are several possible stacks for reading & writing of data, depending on the combo of VNC authentication methods in use
- Clear. read/write straight to socket - TLS. read/write via GNUTLS helpers - SASL. encode/decode via SASL SSF layer, then read/write to socket
- SASL+TLS. encode/decode via SASL SSF layer, then read/write via GNUTLS
Hence, the vnc_client_read & vnc_client_write methods have been refactored a little.
vnc_client_read: main entry point for reading, calls either
- vnc_client_read_plain reading, with no intermediate decoding
- vnc_client_read_sasl reading, with SASL SSF decoding
These two methods, then call vnc_client_read_buf(). This decides whether to write to the socket directly or write via GNUTLS.
The situation is the same for writing data. More extensive comments have been added in the code / patch. The vnc_client_read_sasl and vnc_client_write_sasl method implementations live in the separate vnc-auth-sasl.c file.
The state required for the SASL auth mechanism is kept in a separate VncStateSASL struct, defined in vnc-auth-sasl.h and included in the main VncState.
The configure script probes for SASL and automatically enables it if found, unless --disable-vnc-sasl was given to override it.
Makefile | 7 Makefile.target | 5 b/qemu.sasl | 34 ++ b/vnc-auth-sasl.c | 626 ++++++++++++++++++++++++++++++++++++++++++++++++++++ b/vnc-auth-sasl.h | 67 +++++ configure | 34 ++ qemu-doc.texi | 97 ++++++++ vnc-auth-vencrypt.c | 12 vnc.c | 249 ++++++++++++++++++-- vnc.h | 31 ++ 10 files changed, 1129 insertions(+), 33 deletions(-)
Makefile +6 -1
@@ -148,6 +148,9 @@ OBJS+=vnc.o d3des.o ifdef CONFIG_VNC_TLS OBJS+=vnc-tls.o vnc-auth-vencrypt.o endif +ifdef CONFIG_VNC_SASL +OBJS+=vnc-auth-sasl.o +endif ifdef CONFIG_COCOA OBJS+=cocoa.o
@@ -171,7 +174,7 @@ sdl.o: sdl.c keymaps.h sdl_keysym.h sdl.o audio/sdlaudio.o: CFLAGS += $(SDL_CFLAGS) -vnc.h: vnc-tls.h vnc-auth-vencrypt.h keymaps.h +vnc.h: vnc-tls.h vnc-auth-vencrypt.h vnc-auth-sasl.h keymaps.h vnc.o: vnc.c vnc.h vnc_keysym.h vnchextile.h d3des.c d3des.h
@@ -181,6 +184,8 @@ vnc-tls.o: vnc-tls.c vnc.h vnc-auth-vencrypt.o: vnc-auth-vencrypt.c vnc.h +vnc-auth-sasl.o: vnc-auth-sasl.c vnc.h + curses.o: curses.c keymaps.h curses_keys.h bt-host.o: CFLAGS += $(CONFIG_BLUEZ_CFLAGS)
Makefile.target +5 -0
@@ -554,6 +554,11 @@ CPPFLAGS += $(CONFIG_VNC_TLS_CFLAGS) LIBS += $(CONFIG_VNC_TLS_LIBS) endif +ifdef CONFIG_VNC_SASL +CPPFLAGS += $(CONFIG_VNC_SASL_CFLAGS) +LIBS += $(CONFIG_VNC_SASL_LIBS) +endif + ifdef CONFIG_BLUEZ LIBS += $(CONFIG_BLUEZ_LIBS) endif
configure +34 -0
@@ -164,6 +164,7 @@ fmod_lib="" fmod_inc="" oss_lib="" vnc_tls="yes" +vnc_sasl="yes" bsd="no" linux="no" solaris="no"
@@ -387,6 +388,8 @@ for opt do ;; --disable-vnc-tls) vnc_tls="no" ;; + --disable-vnc-sasl) vnc_sasl="no" + ;; --disable-slirp) slirp="no" ;; --disable-vde) vde="no"
@@ -544,6 +547,7 @@ echo " Availab echo " --enable-mixemu enable mixer emulation" echo " --disable-brlapi disable BrlAPI" echo " --disable-vnc-tls disable TLS encryption for VNC server" +echo " --disable-vnc-sasl disable SASL encryption for VNC server" echo " --disable-curses disable curses output" echo " --disable-bluez disable bluez stack connectivity" echo " --disable-kvm disable KVM acceleration support"
@@ -823,6 +827,25 @@ EOF fi ########################################## +# VNC SASL detection +if test "$vnc_sasl" = "yes" ; then +cat > $TMPC <<EOF +#include <sasl/sasl.h> +#include <stdio.h> +int main(void) { sasl_server_init(NULL, "qemu"); return 0; } +EOF + # Assuming Cyrus-SASL installed in /usr prefix + vnc_sasl_cflags="" + vnc_sasl_libs="-lsasl2" + if $cc $ARCH_CFLAGS -o $TMPE ${OS_CFLAGS} $vnc_sasl_cflags $TMPC \ + $vnc_sasl_libs 2> /dev/null ; then + : + else + vnc_sasl="no" + fi +fi + +########################################## # vde libraries probe if test "$vde" = "yes" ; then cat > $TMPC << EOF
@@ -1130,6 +1153,11 @@ if test "$vnc_tls" = "yes" ; then echo " TLS CFLAGS $vnc_tls_cflags" echo " TLS LIBS $vnc_tls_libs" fi +echo "VNC SASL support $vnc_sasl" +if test "$vnc_sasl" = "yes" ; then + echo " SASL CFLAGS $vnc_sasl_cflags" + echo " SASL LIBS $vnc_sasl_libs" +fi if test -n "$sparc_cpu"; then echo "Target Sparc Arch $sparc_cpu" fi
@@ -1371,6 +1399,12 @@ if test "$vnc_tls" = "yes" ; then echo "CONFIG_VNC_TLS_LIBS=$vnc_tls_libs" >> $config_mak echo "#define CONFIG_VNC_TLS 1" >> $config_h fi +if test "$vnc_sasl" = "yes" ; then + echo "CONFIG_VNC_SASL=yes" >> $config_mak + echo "CONFIG_VNC_SASL_CFLAGS=$vnc_sasl_cflags" >> $config_mak + echo "CONFIG_VNC_SASL_LIBS=$vnc_sasl_libs" >> $config_mak + echo "#define CONFIG_VNC_SASL 1" >> $config_h +fi qemu_version=`head $source_path/VERSION` echo "VERSION=$qemu_version" >>$config_mak echo "#define QEMU_VERSION \"$qemu_version\"" >> $config_h
qemu-doc.texi +97 -0
122 lines not on this page · raw message
qemu.sasl new file +34 -0
@@ -0,0 +1,34 @@ +# If you want to use the non-TLS socket, then you *must* include +# the GSSAPI or DIGEST-MD5 mechanisms, because they are the only +# ones that can offer session encryption as well as authentication. +# +# If you're only using TLS, then you can turn on any mechanisms +# you like for authentication, because TLS provides the encryption +# +# Default to a simple username+password mechanism +# NB digest-md5 is no longer considered secure by current standards +mech_list: digest-md5 + +# Before you can use GSSAPI, you need a service principle on the +# KDC server for libvirt, and that to be exported to the keytab +# file listed below +#mech_list: gssapi +# +# You can also list many mechanisms at once, then the user can choose +# by adding '?auth=sasl.gssapi' to their libvirt URI, eg +# qemu+tcp://hostname/system?auth=sasl.gssapi +#mech_list: digest-md5 gssapi + +# Some older builds of MIT kerberos on Linux ignore this option & +# instead need KRB5_KTNAME env var. +# For modern Linux, and other OS, this should be sufficient +keytab: /etc/qemu/krb5.tab + +# If using digest-md5 for username/passwds, then this is the file +# containing the passwds. Use 'saslpasswd2 -a qemu [username]' +# to add entries, and 'sasldblistusers2 -a qemu' to browse it +sasldb_path: /etc/qemu/passwd.db + + +auxprop_plugin: sasldb +
vnc-auth-sasl.c new file +626 -0
626 lines not on this page · raw message
vnc-auth-sasl.h new file +67 -0
67 lines not on this page · raw message
vnc-auth-vencrypt.c +10 -2
@@ -43,8 +43,15 @@ static void start_auth_vencrypt_subauth(start_auth_vnc (vs);break ; +#ifdef CONFIG_VNC_SASL +case VNC_AUTH_VENCRYPT_TLSSASL : +case VNC_AUTH_VENCRYPT_X509SASL : +VNC_DEBUG ("Start TLS auth SASL\n" ); +return start_auth_sasl (vs); +#endif /* CONFIG_VNC_SASL */ +default :/* Should not be possible, but just in case */ -VNC_DEBUG ("Reject auth %d\n" , vs->vd->auth); +VNC_DEBUG ("Reject subauth %d server bug\n" , vs->vd->auth);vnc_write_u8 (vs,1 );if (vs->minor >=8 ) {static const char err[] ="Unsupported authentication type" ;
@@ -105,7 +112,8 @@ static void vnc_tls_handshake_io(void *o#define NEED_X509_AUTH (vs) \ ((vs)->vd->subauth == VNC_AUTH_VENCRYPT_X509NONE || \ (vs)->vd->subauth == VNC_AUTH_VENCRYPT_X509VNC || \ - (vs)->vd->subauth == VNC_AUTH_VENCRYPT_X509PLAIN) + (vs)->vd->subauth == VNC_AUTH_VENCRYPT_X509PLAIN || \ + (vs)->vd->subauth == VNC_AUTH_VENCRYPT_X509SASL)static int protocol_client_vencrypt_auth (VncState *vs,uint8_t *data,size_t len)
vnc.c +222 -27
392 lines not on this page · raw message
vnc.h +28 -3
@@ -79,6 +79,10 @@ typedef struct VncDisplay VncDisplay;#include "vnc-tls.h" #include "vnc-auth-vencrypt.h" #endif +#ifdef CONFIG_VNC_SASL +#include "vnc-auth-sasl.h" +#endif +struct VncDisplay {
@@ -118,10 +122,12 @@ struct VncStateint minor;char challenge[VNC_AUTH_CHALLENGE_SIZE ]; -#ifdef CONFIG_VNC_TLS VncStateTLS tls;#endif +#ifdef CONFIG_VNC_SASL +VncStateSASL sasl; +#endif Buffer output;Buffer input;
@@ -160,8 +166,9 @@ enum {VNC_AUTH_RA2NE =6 ,VNC_AUTH_TIGHT =16 ,VNC_AUTH_ULTRA =17 , -VNC_AUTH_TLS =18 , -VNC_AUTH_VENCRYPT =19 +VNC_AUTH_TLS =18 ,/* Supported in GTK-VNC & VINO */ +VNC_AUTH_VENCRYPT =19 ,/* Supported in GTK-VNC & VeNCrypt */ + VNC_AUTH_SASL = 20, /* Supported in GTK-VNC & VINO */ }; enum {
@@ -172,6 +179,8 @@ enum {VNC_AUTH_VENCRYPT_X509NONE =260 ,VNC_AUTH_VENCRYPT_X509VNC =261 ,VNC_AUTH_VENCRYPT_X509PLAIN =262 , +VNC_AUTH_VENCRYPT_X509SASL =263 , + VNC_AUTH_VENCRYPT_TLSSASL = 264, };
@@ -255,6 +264,8 @@ enum {void vnc_client_read (void *opaque);void vnc_client_write (void *opaque); +long vnc_client_read_buf (VncState *vs,uint8_t *data,size_t datalen); +long vnc_client_write_buf (VncState *vs,const uint8_t *data,size_t datalen);/* Protocol I/O functions */ void vnc_write (VncState *vs,const void *data,size_t len);
@@ -274,8 +285,22 @@ uint32_t read_u32(uint8_t *data, size_t/* Protocol stage functions */ void vnc_client_error (VncState *vs); +int vnc_client_io_error (VncState *vs,int ret,int last_errno);void start_client_init (VncState *vs);void start_auth_vnc (VncState *vs); +/* Buffer management */ +void buffer_reserve (Buffer *buffer,size_t len); +int buffer_empty (Buffer *buffer); +uint8_t *buffer_end (Buffer *buffer); +void buffer_reset (Buffer *buffer); +void buffer_append (Buffer *buffer,const void *data,size_t len); + + +/* Misc helpers */ + +char *vnc_socket_local_addr (const char *format,int fd); +char *vnc_socket_remote_addr (const char *format,int fd); +#endif /* __QEMU_VNC_H */
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Re: [Qemu-devel] PATCH: 7/9: Include auth credentials in 'info vnc'
In reply to Daniel P. BerrangeThis patch extends the 'info vnc' monitor output to include information about the VNC client authentication credentials.
For clients authenticated using SASL, this will output the username.
For clients authenticated using x509 certificates, this will output the x509 distinguished name.
Auth can be stacked, so both username & x509 dname may be shown.
Server:
address: 0.0.0.0:5902
auth: vencrypt+x509+sasl
Client:
address: 10.33.6.67:38621
x509 dname: C=GB,O=ACME,L=London,ST=London,CN=localhost
username: admin
Client:
address: 10.33.6.63:38620
x509 dname: C=GB,O=ACME,L=London,ST=London,CN=localhost
username: adminvnc-tls.c | 17 +++++++++++++++++ vnc-tls.h | 3 +++ vnc.c | 19 +++++++++++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-)
vnc-tls.c +17 -0
@@ -241,6 +241,22 @@ int vnc_tls_validate_certificate(structreturn -1 ; } +if (i ==0 ) { +size_t dnameSize =1024 ; + vs->tls.dname =qemu_malloc (dnameSize); + requery: +if ((ret =gnutls_x509_crt_get_dn (cert, vs->tls.dname, &dnameSize)) !=0 ) { +if (ret ==GNUTLS_E_SHORT_MEMORY_BUFFER ) { + vs->tls.dname =qemu_realloc (vs->tls.dname, dnameSize); + goto requery; + } +gnutls_x509_crt_deinit (cert); +VNC_DEBUG ("Cannot get client distinguished name: %s" , +gnutls_strerror (ret)); +return -1 ; + } + } +gnutls_x509_crt_deinit (cert); }
@@ -347,6 +363,7 @@ void vnc_tls_client_cleanup(struct VncSt vs->tls.session =NULL ; } vs->tls.wiremode =VNC_WIREMODE_CLEAR ; +free (vs->tls.dname); }
vnc-tls.h +3 -0
@@ -55,6 +55,9 @@ struct VncStateTLS {/* Whether data is being TLS encrypted yet */ int wiremode;gnutls_session_t session; + +/* Client's Distinguished Name from the x509 cert */ +char *dname; };int vnc_tls_client_setup (VncState *vs,int x509Creds);
vnc.c +17 -2
@@ -156,6 +156,21 @@ static void do_info_vnc_client(VncStateterm_puts ("Client:\n" );term_puts (clientAddr);free (clientAddr); + +#ifdef CONFIG_VNC_TLS +if (client->tls.session && + client->tls.dname) +term_printf (" x509 dname: %s\n" , client->tls.dname); +else +term_puts (" x509 dname: none\n" ); +#endif +#ifdef CONFIG_VNC_SASL +if (client->sasl.conn && + client->sasl.username) +term_printf (" username: %s\n" , client->sasl.username); +else +term_puts (" username: none\n" ); +#endif }void do_info_vnc (void )
@@ -1823,7 +1838,7 @@ static int protocol_client_auth(VncState/* We only advertise 1 auth scheme at a time, so client * must pick the one we sent. Verify this */ if (data[0 ] != vs->vd->auth) {/* Reject auth */ -VNC_DEBUG ("Reject auth %d\n" , (int )data[0 ]); +VNC_DEBUG ("Reject auth %d because it didn't match advertized\n" , (int )data[0 ]);vnc_write_u32 (vs,1 );if (vs->minor >=8 ) {static const char err[] ="Authentication failed" ;
@@ -1863,7 +1878,7 @@ static int protocol_client_auth(VncState#endif /* CONFIG_VNC_SASL */ default :/* Should not be possible, but just in case */ -VNC_DEBUG ("Reject auth %d\n" , vs->vd->auth); +VNC_DEBUG ("Reject auth %d server code bug\n" , vs->vd->auth);vnc_write_u8 (vs,1 );if (vs->minor >=8 ) {static const char err[] ="Authentication failed" ;
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Re: [Qemu-devel] PATCH: 8/9: Support ACLs for controlling VNC access
In reply to Daniel P. BerrangeThis patch introduces a generic internal API for access control lists to be used by network servers in QEMU. It adds support for checking these ACL in the VNC server, in two places. The first ACL is for the SASL authentication mechanism, checking the SASL username. This ACL is called 'vnc.username'. The second is for the TLS authentication mechanism, when x509 client certificates are turned on, checking against the Distinguished Name of the client. This ACL is called 'vnc.x509dname'
The internal API provides for an ACL with the following characteristics
- A unique name, eg vnc.username, and vnc.x509dname.
- A default policy, allow or deny
- An ordered series of match rules, with allow or deny policy
If none of the match rules apply, then the default policy is used.
There is a monitor API to manipulate the ACLs, which I'll describe via examples
(qemu) acl show vnc.username
policy: allow
(qemu) acl policy vnc.username denya
acl: policy set to 'deny'
(qemu) acl allow vnc.username fred
acl: added rule at position 1
(qemu) acl allow vnc.username bob
acl: added rule at position 2
(qemu) acl allow vnc.username joe 1
acl: added rule at position 1
(qemu) acl show vnc.username
policy: deny
0: allow fred
1: allow joe
2: allow bob
(qemu) acl show vnc.x509dname
policy: allow
(qemu) acl policy vnc.x509dname deny
acl: policy set to 'deny'
(qemu) acl allow vnc.x509dname C=GB,O=ACME,L=London,CN=*
acl: added rule at position 1
(qemu) acl allow vnc.x509dname C=GB,O=ACME,L=Boston,CN=bob
acl: added rule at position 2
(qemu) acl show vnc.x509dname
policy: deny
0: allow C=GB,O=ACME,L=London,CN=*
1: allow C=GB,O=ACME,L=Boston,CN=bob
By default the VNC server will not use any ACLs, allowing access to the server if the user successfully authenticates. To enable use of ACLs to restrict user access, the ',acl' flag should be given when starting QEMU. The initial ACL activated will be a 'deny all' policy and should be customized using monitor commands.
eg enable SASL auth and ACLs
qemu .... -vnc localhost:1,sasl,acl
The next patch will provide a way to load a pre-defined ACL when starting up
Makefile | 6 + b/acl.c | 185 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ b/acl.h | 74 ++++++++++++++++++++++ configure | 18 +++++ monitor.c | 95 ++++++++++++++++++++++++++++ qemu-doc.texi | 49 ++++++++++++++ vnc-auth-sasl.c | 16 +++- vnc-auth-sasl.h | 7 ++ vnc-tls.c | 19 +++++ vnc-tls.h | 3 vnc.c | 21 ++++++ vnc.h | 3 12 files changed, 491 insertions(+), 5 deletions(-)
Makefile +4 -2
@@ -144,7 +144,7 @@ endif ifdef CONFIG_CURSES OBJS+=curses.o endif -OBJS+=vnc.o d3des.o +OBJS+=vnc.o acl.o d3des.o ifdef CONFIG_VNC_TLS OBJS+=vnc-tls.o vnc-auth-vencrypt.o endif
@@ -174,9 +174,11 @@ sdl.o: sdl.c keymaps.h sdl_keysym.h sdl.o audio/sdlaudio.o: CFLAGS += $(SDL_CFLAGS) +acl.o: acl.h acl.c + vnc.h: vnc-tls.h vnc-auth-vencrypt.h vnc-auth-sasl.h keymaps.h -vnc.o: vnc.c vnc.h vnc_keysym.h vnchextile.h d3des.c d3des.h +vnc.o: vnc.c vnc.h vnc_keysym.h vnchextile.h d3des.c d3des.h acl.h vnc.o: CFLAGS += $(CONFIG_VNC_TLS_CFLAGS)
acl.c new file +185 -0
185 lines not on this page · raw message
acl.h new file +74 -0
74 lines not on this page · raw message
configure +18 -0
@@ -846,6 +846,21 @@ EOF fi ########################################## +# fnmatch() probe, used for ACL routines +fnmatch="no" +cat > $TMPC << EOF +#include <fnmatch.h> +int main(void) +{ + fnmatch("foo", "foo", 0); + return 0; +} +EOF +if $cc $ARCH_CFLAGS -o $TMPE $TMPC > /dev/null 2> /dev/null ; then + fnmatch="yes" +fi + +########################################## # vde libraries probe if test "$vde" = "yes" ; then cat > $TMPC << EOF
@@ -1405,6 +1420,9 @@ if test "$vnc_sasl" = "yes" ; then echo "CONFIG_VNC_SASL_LIBS=$vnc_sasl_libs" >> $config_mak echo "#define CONFIG_VNC_SASL 1" >> $config_h fi +if test "$fnmatch" = "yes" ; then + echo "#define HAVE_FNMATCH_H 1" >> $config_h +fi qemu_version=`head $source_path/VERSION` echo "VERSION=$qemu_version" >>$config_mak echo "#define QEMU_VERSION \"$qemu_version\"" >> $config_h
monitor.c +95 -0
116 lines not on this page · raw message
qemu-doc.texi +49 -0
61 lines not on this page · raw message
vnc-auth-sasl.c +13 -3
@@ -120,22 +120,32 @@ static int vnc_auth_sasl_check_access(Vn {const void *val;int err; +int allow; err =sasl_getprop (vs->sasl.conn,SASL_USERNAME , &val);if (err !=SASL_OK ) { -VNC_DEBUG ("cannot query SASL username on connection %d (%s)\n" , +VNC_DEBUG ("cannot query SASL username on connection %d (%s), denying access\n" , err,sasl_errstring (err,NULL ,NULL ));return -1 ; }if (val ==NULL ) { -VNC_DEBUG ("no client username was found\n" ); +VNC_DEBUG ("no client username was found, denying access\n" );return -1 ; }VNC_DEBUG ("SASL client username %s\n" , (const char *)val); vs->sasl.username =qemu_strdup ((const char *)val); -return 0 ; +if (vs->vd->sasl.acl ==NULL ) { +VNC_DEBUG ("no ACL activated, allowing access\n" ); +return 0 ; + } + + allow =qemu_acl_party_is_allowed (vs->vd->sasl.acl, vs->sasl.username); + +VNC_DEBUG ("SASL client %s %s by ACL\n" , vs->sasl.username, + allow ?"allowed" :"denied" ); +return allow ?0 :-1 ; }static int vnc_auth_sasl_check_ssf (VncState *vs)
vnc-auth-sasl.h +7 -0
@@ -30,6 +30,9 @@#include <sasl/sasl.h> typedef struct VncStateSASL VncStateSASL ; +typedef struct VncDisplaySASL VncDisplaySASL ; + +#include "acl.h" struct VncStateSASL {sasl_conn_t *conn;
@@ -56,6 +59,10 @@ struct VncStateSASL {char *mechlist; }; +struct VncDisplaySASL { +qemu_acl *acl; +}; +void vnc_sasl_client_cleanup (VncState *vs);long vnc_client_read_sasl (VncState *vs);
vnc-tls.c +19 -0
@@ -255,6 +255,25 @@ int vnc_tls_validate_certificate(struct gnutls_strerror (ret));return -1 ; } + +if (vs->vd->tls.x509verify) { +int allow; +if (!vs->vd->tls.acl) { +VNC_DEBUG ("no ACL activated, allowing access" ); +gnutls_x509_crt_deinit (cert); +continue ; + } + + allow =qemu_acl_party_is_allowed (vs->vd->tls.acl, + vs->tls.dname); + +VNC_DEBUG ("TLS x509 ACL check for %s is %s\n" , + vs->tls.dname, allow ?"allowed" :"denied" ); +if (!allow) { +gnutls_x509_crt_deinit (cert); +return -1 ; + } + } }gnutls_x509_crt_deinit (cert);
vnc-tls.h +3 -0
@@ -31,6 +31,8 @@#include <gnutls/gnutls.h> #include <gnutls/x509.h> +#include "acl.h" +enum {VNC_WIREMODE_CLEAR ,VNC_WIREMODE_TLS ,
@@ -42,6 +44,7 @@ typedef struct VncStateTLS VncStateTLS;/* Server state */ struct VncDisplayTLS {int x509verify;/* Non-zero if server requests & validates client cert */ +qemu_acl *acl;/* Paths to x509 certs/keys */ char *x509cacert;
vnc.c +21 -0
@@ -28,6 +28,7 @@#include "sysemu.h" #include "qemu_socket.h" #include "qemu-timer.h" +#include "acl.h" #define VNC_REFRESH_INTERVAL (1000 / 30)
@@ -2082,6 +2083,7 @@ int vnc_display_open(DisplayState *ds, cint sasl =0 ;int saslErr;#endif +int acl =0 ;if (!vnc_display)return -1 ;
@@ -2138,9 +2140,28 @@ int vnc_display_open(DisplayState *ds, c return -1; }#endif + }else if (strncmp (options,"acl" ,3 ) ==0 ) { + acl =1 ; } } +#ifdef CONFIG_VNC_TLS +if (acl && x509 && vs->tls.x509verify) { +if (!(vs->tls.acl =qemu_acl_init ("vnc.x509dname" ))) { +fprintf (stderr,"Failed to create x509 dname ACL\n" ); +exit (1 ); + } + } +#endif +#ifdef CONFIG_VNC_SASL +if (acl && sasl) { +if (!(vs->sasl.acl =qemu_acl_init ("vnc.username" ))) { +fprintf (stderr,"Failed to create username ACL\n" ); +exit (1 ); + } + } +#endif +/* * Combinations we support here: *
vnc.h +3 -0
@@ -98,6 +98,9 @@ struct VncDisplayint subauth;/* Used by VeNCrypt */ VncDisplayTLS tls;#endif +#ifdef CONFIG_VNC_SASL +VncDisplaySASL sasl; +#endif };struct VncState
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Re: [Qemu-devel] PATCH: 9/9: Persist ACLs in external files
In reply to Daniel P. BerrangeThis patch introduces a simple access control file capability for authorizing clients of QEMU's various network services. The file is designed such that it can be shared amongst multiple QEMU instances. The style of commands is similar to that used in the monitor ACL commands. It is a line oriented format, with comments indicated by leading '#'.Each non-comment line consists of 4 fields, 'scope', 'aclname', 'action' and 'value'.
The scope allows control over what VMs the rule applies to. This is a glob, so '*' matches any VM. An explicit value can be match against the VM name, as given by the '-name' argument.
The aclname is one of the ACLs defined by QEMU, either vnc.username or vnc.x509dname for now. More later perhaps.
The action can be one of 'policy' 'allow', or 'deny'. The policy sets the default allow/deny state for the ACL, if no rules match.
Finally the 'value' is another glob matching against the client name being checked.
An example showing use of both SASL username ACLs, and x509 client certificate distinguished name ACLs.
# Default deny all for all SASL authenticated users in all VMs
* vnc.username policy deny
# Allow bob access to all VMs
* vnc.username allow bob
# Allow fred and test access to the VM named 'demo' demo vnc.username allow fred
demo vnc.username allow test
# Deny all x509 client certificates on all VMs
* vnc.x509dname policy deny
# Allow all users from the ACME, London office to all VMs
* vnc.x509dname allow "C=GB,O=ACME,L=London,CN=*"
# Allow Joe from Boston, access to VM 'demo' demo vnc.x509dname allow "C=GB,O=ACME,L=Boston,CN=joe"
Save this to a file, and give it to QEMU at startup with '-acl demo.acl'
The code for parsing the file is a little crude because I didn't want to spend too much time writing this. Its more of a proof of concept of how it might be possible to store ACL rules in a simple way.
acl.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ acl.h | 3 + vl.c | 12 +++++++ 3 files changed, 128 insertions(+)
acl.c +113 -0
@@ -73,6 +73,119 @@ qemu_acl *qemu_acl_init(const char *aclnreturn acl; } +#define SKIP_SPACES (buf) while (*buf == ' ') { buf++; } + +int qemu_acl_load_file (const char *path, +const char *name) +{ +FILE *f =fopen (path,"r" ); +char line[1024 ]; +int ret =-1 ; +int linenum =0 ; + +if (!f) +return -1 ; + +/* * vnc.username policy deny */ +/* * vnc.username allow fred */ +/* somevm vnc.username allow joe */ +/* somevm vnc.username deny bob*/ +while (fgets (line,sizeof (line), f)) { +char *scope, *aclname, *action, *value; +char *tmp = line; +qemu_acl *acl; +int quoted =0 ; + + linenum++; + +SKIP_SPACES (tmp); +if (line[0 ] =='#' || + line[0 ] =='\n' || + line[0 ] =='\0' ) +continue ; + + scope = tmp; + + tmp =strchr (tmp,' ' ); +if (!tmp) { +fprintf (stderr,"missing aclname data at line %d\n" , linenum); +continue ; + } + *tmp++ ='\0' ; +SKIP_SPACES (tmp); + aclname = tmp; + + tmp =strchr (tmp,' ' ); +if (!tmp) { +fprintf (stderr,"missing action data at line %d\n" , linenum); +continue ; + } + *tmp++ ='\0' ; +SKIP_SPACES (tmp); + action = tmp; + + tmp =strchr (tmp,' ' ); +if (!tmp) { +fprintf (stderr,"missing value data at line %d\n" , linenum); +continue ; + } + *tmp++ ='\0' ; +SKIP_SPACES (tmp); + value = tmp; + + +if (*tmp =='"' ) { + quoted =1 ; + value++; + tmp++; + } +while (*tmp !='\0' && *tmp !='\n' ) { +if ((quoted && *tmp =='"' ) || + (!quoted && *tmp ==' ' )) +break ; + tmp++; + } +if (tmp) + *tmp ='\0' ; + +#ifdef HAVE_FNMATCH_H +if (fnmatch (scope, name ? name :"" ,0 ) !=0 ) { +continue ; + } +#else +if (name && +strcmp (scope, name) !=0 ) { +continue ; + } +#endif + + acl =qemu_acl_init (aclname); +if (!acl) + goto cleanup; + +if (strcmp (action,"policy" ) ==0 ) { +if (strcmp (value,"allow" ) ==0 ) + acl->defaultDeny =0 ; +else if (strcmp (value,"deny" ) ==0 ) + acl->defaultDeny =1 ; +else +fprintf (stderr,"unknown ACL policy '%s'\n" , value); + }else if (strcmp (action,"allow" ) ==0 || +strcmp (action,"deny" ) ==0 ) { +int deny =strcmp (action,"deny" ) ==0 ?1 :0 ; +qemu_acl_append (acl, deny, value); + }else { +fprintf (stderr,"unknown ACL action '%s'\n" , action); + } + } + ret =0 ; + + cleanup: +fclose (f); + +return ret; +} +int qemu_acl_party_is_allowed (qemu_acl *acl,const char *party) {
acl.h +3 -0
@@ -48,6 +48,9 @@ qemu_acl *qemu_acl_init(const char *aclnqemu_acl *qemu_acl_find (const char *aclname); +int qemu_acl_load_file (const char *path, +const char *name); +int qemu_acl_party_is_allowed (qemu_acl *acl,const char *party);
vl.c +12 -0
@@ -42,6 +42,7 @@#include "migration.h" #include "kvm.h" #include "balloon.h" +#include "acl.h" #include <unistd.h> #include <fcntl.h>
@@ -3956,6 +3957,7 @@ static void help(int exitcode) "-g WxH[xDEPTH] Set the initial graphical resolution and depth\n"#endif "-vnc display start a VNC server on display\n" +"-acl path path to access control list for network services\n" "\n" "Network options:\n" "-net nic[,vlan=n][,macaddr=addr][,model=type][,name=str]\n"
@@ -4143,6 +4145,7 @@ enum { QEMU_OPTION_full_screen, QEMU_OPTION_g, QEMU_OPTION_vnc, + QEMU_OPTION_acl,/* Network options: */ QEMU_OPTION_net,
@@ -4260,6 +4263,7 @@ static const QEMUOption qemu_options[] = { "g", 1, QEMU_OPTION_g }, #endif { "vnc", HAS_ARG, QEMU_OPTION_vnc }, + { "acl", HAS_ARG, QEMU_OPTION_acl }, /* Network options: */ { "net", HAS_ARG, QEMU_OPTION_net},
@@ -4641,6 +4645,7 @@ int main(int argc, char **argv, char **econst char *pid_file =NULL ;int autostart;const char *incoming =NULL ; +const char *acl_file =NULL ;int fd =0 ;struct passwd *pwd =NULL ;const char *chroot_dir =NULL ;
@@ -5189,6 +5194,9 @@ int main(int argc, char **argv, char **ecase QEMU_OPTION_vnc: vnc_display = optarg;break ; +case QEMU_OPTION_acl: + acl_file = optarg; +break ;case QEMU_OPTION_no_acpi: acpi_enabled =0 ;break ;
@@ -5644,6 +5652,10 @@ int main(int argc, char **argv, char **e } } +/* Load access control data */ +if (acl_file) +qemu_acl_load_file (acl_file, qemu_name); +if (!display_state)dumb_display_init ();/* just use the first displaystate for the moment */
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Quoted 32 lines · Daniel P. Berrange
Previously I provided patches for QEMU's VNC server to support SSL/TLS and x509 certificates. This provides good encryption capabilities for the VNC session. It doesn't really address the authentication problem though.
I have been working to create a new authentication type in the RFB protocol to address this need in a generic, extendable way, by mapping the SASL API into the RFB protocol. Since SASL is a generic plugin based API, this will allow use of a huge range of auth mechanims over VNC, without us having to add any more auth code. For example, PAM, Digest-MD5, GSSAPI/Kerberos, One-time key/password, LDAP password lookup, SQL db password lookup, and more.
I have got a VNC auth type assigned by the RFB spec maintainers:
http://realvnc.com/pipermail/vnc-list/2008-December/059463.html
With the full current spec for the SASL extension currently documented here:
http://realvnc.com/pipermail/vnc-list/2008-December/059462.html
This is the 4th version of the patches I previously posted:
v1: http://lists.gnu.org/archive/html/qemu-devel/2009-02/msg00255.html
v2: http://lists.gnu.org/archive/html/qemu-devel/2009-02/msg00826.html
v3: http://lists.gnu.org/archive/html/qemu-devel/2009-02/msg01418.htmlChanges since last time
- Removed mistaken changes to qemu-doc.texi from bad merge
Quoted 8 lines
- Renamed the 'ACL' struct to '
qemu_acl' to avoid clash with a system header typedef in Win32 platforms- Check for 'fnmatch' function in configure, and if not found then revert to exact
strcmp()matching instead of wildcard matching- Add docs for the 'acl' monitor command
One other change I forgot to mention
- ACLs are not activated unless you explicitly set the ',acl' flag to the -vnc command line option. eg -vnc localhost:1,sasl,acl
- When activated, ACLs now have a default policy of 'deny'.
The combination of those two changes is required to ensure current usage of QEMU / VNC is not subject to breakage, while allowing secure use of ACLs. Previous versions of these patches had ACLs enabled by default, but with 'allow all' policy. This meant there was a window of open access between QEMU starting up, and the user configuring ACLs in the monitor console.
Also, as previously discussed, I'm happy for patch 9 to be left out until the more general QEMU config file plans come to fruition. I just include it for completeness / as a demo.
Daniel
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Quoted 13 lines · Daniel P. Berrange
Previously I provided patches for QEMU's VNC server to support SSL/TLS and x509 certificates. This provides good encryption capabilities for the VNC session. It doesn't really address the authentication problem though.
I have been working to create a new authentication type in the RFB protocol to address this need in a generic, extendable way, by mapping the SASL API into the RFB protocol. Since SASL is a generic plugin based API, this will allow use of a huge range of auth mechanims over VNC, without us having to add any more auth code. For example, PAM, Digest-MD5, GSSAPI/Kerberos, One-time key/password, LDAP password lookup, SQL db password lookup, and more.
Quoted 4 lines
I have got a VNC auth type assigned by the RFB spec maintainers:
http://realvnc.com/pipermail/vnc-list/2008-December/059463.html
Applied 1-8. I'd like to wait on 9.
There was a lot of rejects because of Jan's series. I fixed these up. I also added another patch that fixed the tabs introduced by your series.
You want to add:
(indent-tabs-mode . nil)
To your emacs bits.
Regards,
Anthony Liguori
Quoted 14 lines · Anthony Liguori
Quoted 13 lines · Daniel P. Berrange
Previously I provided patches for QEMU's VNC server to support SSL/TLS and x509 certificates. This provides good encryption capabilities for the VNC session. It doesn't really address the authentication problem though.
I have been working to create a new authentication type in the RFB protocol to address this need in a generic, extendable way, by mapping the SASL API into the RFB protocol. Since SASL is a generic plugin based API, this will allow use of a huge range of auth mechanims over VNC, without us having to add any more auth code. For example, PAM, Digest-MD5, GSSAPI/Kerberos, One-time key/password, LDAP password lookup, SQL db password lookup, and more.
Quoted 6 lines
Quoted 4 lines
I have got a VNC auth type assigned by the RFB spec maintainers:
http://realvnc.com/pipermail/vnc-list/2008-December/059463.html
Applied 1-8. I'd like to wait on 9.
Thanks, I've no problem waiting for a better solution to #9 - it was merely a basic proof of concept which I wasn't all that happy with.
Daniel
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|