PATCH: 0/7: Support SASL authentication in VNC server
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 2nd version of the patches I initially posted here
http://lists.gnu.org/archive/html/qemu-devel/2009-02/msg00255.html
Changes since last time
- Re-factor the code to move TLS and SASL methods into separate files, vnc-tls.c, vnc-auth-vencrypt.c and vnc-auth-vencrypt.h
- Added simple access control lists for authorization of client users on either SASL username, or x509 distinguished name
- Added proof of concept external file format for persisting ACLs
- Extend 'info vnc' to show much more information about clients and auth
- Tested with SASL + Digest-MD5, SASL + GSSAPI. TLS + SASL + Digest-MD5 and TLS + SASL + GSSAPI. This gives coverage off all interesting code paths and/or I/O encryption combinations.
The combined diffstat for all 7 patches about to follow, is
.hgignore | 16 Makefile | 27 + Makefile.target | 5 b/acl.c | 264 ++++++++++++ b/acl.h | 71 +++ b/keymaps.h | 60 ++ b/qemu.sasl | 34 + b/vnc-auth-sasl.c | 640 +++++++++++++++++++++++++++++ b/vnc-auth-sasl.h | 76 +++ b/vnc-auth-vencrypt.c | 175 +++++++ b/vnc-auth-vencrypt.h | 33 + b/vnc-tls.c | 456 ++++++++++++++++++++ b/vnc-tls.h | 76 +++ configure | 34 + curses.c | 3 curses_keys.h | 9 keymaps.c | 45 -- monitor.c | 80 +++ qemu-doc.texi | 109 ++++ sdl.c | 3 sdl_keysym.h | 7 vl.c | 12 vnc.c | 1100 ++++++++++++++++++-------------------------------- vnc.h | 215 +++++++++ vnc_keysym.h | 5 25 files changed, 2795 insertions(+), 760 deletions(-)
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 :|
Re: [Qemu-devel] PATCH: 1/7: Extend 'info vnc' output to show client
The 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: active
address: 0.0.0.0:5901
auth: vencrypt+x509+saslClient: none
And when a client is connected
(qemu) info vnc
Server: active
address: 0.0.0.0:5901
auth: vencrypt+x509+sasl
Client: active
address: 127.0.0.1:42956More 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 | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 124 insertions(+), 8 deletions(-)
Daniel
vnc.c +124 -8
@@ -154,19 +154,127 @@ struct VncStatestatic VncState *vnc_state;/* 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 (VncState *vs) { +switch (vs->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 (vs->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" +void do_info_vnc (void ) {if (vnc_state ==NULL || vnc_state->display ==NULL ) -term_printf ("VNC server disabled\n" ); +term_printf ("Server: disabled\n" );else { -term_printf ("VNC server active on: " ); -term_print_filename (vnc_state->display); -term_printf ("\n" ); +char *serverAddr =vnc_socket_local_addr (" address: %s:%s\n" , + vnc_state->lsock); -if (vnc_state->csock ==-1 ) -term_printf ("No client connected\n" ); -else -term_printf ("Client connected\n" ); +if (!serverAddr) +return ; + +term_puts ("Server: active\n" ); +term_puts (serverAddr); +free (serverAddr); +term_printf (" auth: %s\n" ,vnc_auth_name (vnc_state)); + +if (vnc_state->csock ==-1 ) { +term_puts ("Client: none\n" ); + }else { +char *clientAddr = +vnc_socket_remote_addr (" address: %s:%s\n" , + vnc_state->csock); +if (!clientAddr) +return ; + +term_puts ("Client: active\n" ); +term_puts (clientAddr); +free (clientAddr); + } } }
@@ -2518,3 +2626,11 @@ int vnc_display_open(DisplayState *ds, creturn qemu_set_fd_handler2 (vs->lsock, vnc_listen_poll, vnc_listen_read,NULL , vs); } + +/* +* Local variables: +* c-indent-level: 4 +* c-basic-offset: 4 +* tab-width: 8 +* End: +*/
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/7: Extend 'info vnc' output to show client
Quoted 11 lines · Daniel P. Berrange
The 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).
vnc.c +0
-0@@ -2518,3 +2626,11 @@ int vnc_display_open(DisplayState *ds, c
vnc.c int vnc_display_open(DisplayState *ds, c · line 2636
Quoted 10 lines
vnc.c +8
-0return qemu_set_fd_handler2 (vs->lsock, vnc_listen_poll, vnc_listen_read,NULL , vs); } + +/* +* Local variables: +* c-indent-level: 4 +* c-basic-offset: 4 +* tab-width: 8 +* End: +*/
I'd prefer you not add this randomly in a patch.
Regards,
Anthony Liguori
Re: [Qemu-devel] PATCH: 1/7: Extend 'info vnc' output to show client
Quoted 12 lines · Anthony Liguori
Quoted 11 lines · Daniel P. Berrange
The 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).(quoted diff) +0
-0@@ -2518,3 +2626,11 @@ int vnc_display_open(DisplayState *ds, c
Quoted 14 lines
vnc.c int vnc_display_open(DisplayState *ds, c · line 2636
Quoted 12 lines
(quoted diff) +0
-0return qemu_set_fd_handler2(vs->lsock, vnc_listen_poll, vnc_listen_read, NULL, vs);}
vnc.c +8
-0+ +/* +* Local variables: +* c-indent-level: 4 +* c-basic-offset: 4 +* tab-width: 8 +* End: +*/ I'd prefer you not add this randomly in a patch.
Sorry, I added this to all the files I touched as QEMU's indentation rules don't match the default emacs & emacs will thus mess up all the whitespace. That said vnc.c already has alot of inconsistent whitespace :-( I'll strip this chunk out of future patches before submission.
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 :|
Re: [Qemu-devel] PATCH: 1/7: Extend 'info vnc' output to show client
Quoted 3 lines · Daniel P. Berrange
Sorry, I added this to all the files I touched as QEMU's indentation rules don't match the default emacs & emacs will thus mess up all the whitespace.
(c-add-style "qemu"
'("stroustrup"
(indent-tabs-mode . nil)
(c-basic-offset . 4)
(tab-width . 8)
)
nil) ; t = set this style, nil = don'tIs what I'm using FWIW.
Regards,
Anthony Liguori
[Qemu-devel] Re: PATCH: 1/7: Extend 'info vnc' output to show client
In reply to Daniel P. BerrangeQuoted 14 lines · Daniel P. Berrange
Quoted 12 lines · Anthony Liguori
vnc.c int vnc_display_open(DisplayState *ds, c · line 2636
Quoted 9 lines · Daniel P. Berrange
vnc.c +8
-0+ +/* +* Local variables: +* c-indent-level: 4 +* c-basic-offset: 4 +* tab-width: 8 +* End: +*/ I'd prefer you not add this randomly in a patch.
Quoted 4 lines
Sorry, I added this to all the files I touched as QEMU's indentation rules don't match the default emacs & emacs will thus mess up all the whitespace. That said
vnc.calready has alot of inconsistent whitespace :-( I'll strip this chunk out of future patches before submission.
Jimmy Xenidis helped me solve this problem automatically using the following e-lisp. Put it in your custom.el or a file sourced by it. It will automatically set the indent, offset, and tab width for you based on the path of the file you are editing. The example below has styles for Linux and Xen. You simply need to extrapolate and add another style for Qemu.
;; xen c-style
;; Jimmy Xenidis <[email protected]>
(defconst xen-style
'( "bsd"
(c-basic-offset . 4)
(indent-tabs-mode . nil)
(tab-width . 4)
(label . 1)
) "Xen C Programming Style")
(c-add-style "xen" xen-style t)
(defconst linux-c-style
'( "K&R" (c-basic-offset . 8) (indent-tabs-mode . t) (tab-width . 8) )
"Linux CodingStyle")
(c-add-style "linux" linux-c-style t)
(defun my-c-mode-hooks ()
"Look at auto-c-mode-alist to decide on the c style mode" (save-excursion
(let ((name (file-name-sans-versions buffer-file-name))
(alist auto-c-mode-alist)
(mode nil))
(while (and (not mode) alist)
(if (string-match (car (car alist)) name)
(if (and (consp (cdr (car alist)))
(nth 2 (car alist)))
(progn
(setq mode (car (cdr (car alist)))
name (substring name 0 (match-beginning 0)) keep-going t))
(setq mode (cdr (car alist))
keep-going nil)))
(setq alist (cdr alist)))
(c-set-style mode))))
(setq c-style-variables-are-local-p t)
(setq auto-c-mode-alist
'(
("/linux" . "linux")
("/xen" . "xen")
("" . "bsd")))
(add-hook 'c-mode-hook 'my-c-mode-hooks)
Signature · 4 lines
Mike Day http://www.ncultra.org AIM: ncmikeday | Yahoo IM: ultra.runner PGP key: http://www.ncultra.org/ncmike/pubkey.asc
Re: [Qemu-devel] PATCH: 2/7: Push VncState struct into vnc.h
In reply to Daniel P. BerrangeThis patch moves the declaration for the VncState struct out of the vnc.c file and into vnc.h. This is to prepare for next patches which have the auth mechanisms implementated in separate vnc-auth-vencrypt.c and vnc-auth-sasl.c files
In doing this, I discovered that there is a pile of duplicated keymap code statically compiled into all the console frontends. A couple of trivial 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.
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 | 101 ++--------------------------------------- vnc.h | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- vnc_keysym.h | 5 -- 10 files changed, 235 insertions(+), 147 deletions(-)
Daniel
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 +5 -96
137 lines not on this page · raw message
vnc.h +137 -3
146 lines not on this page · raw message
vnc_keysym.h +1 -4
@@ -1,7 +1,4 @@ -typedef struct { -const char * name; -int keysym; -}name2keysym_t ; +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: 2/7: Push VncState struct into vnc.h
Quoted 11 lines · Daniel P. Berrange
This patch moves the declaration for the VncState struct out of the
vnc.cfile and intovnc.h. This is to prepare for next patches which have the auth mechanisms implementated in separatevnc-auth-vencrypt.candvnc-auth-sasl.cfilesIn doing this, I discovered that there is a pile of duplicated keymap code statically compiled into all the console frontends. A couple of trivial changes allowed this to be sanitized, so instead of doing a #include "
keymaps.c", duplicating all code, we can have a sharedkeymaps.hfile, and only compile code once.
It would be better if you split the keymap cleanup into a different patch.
Regards,
Anthony Liguori
Quoted 612 lines
Signed-off-by Daniel P. Berrange <[email protected]>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 | 101 ++--------------------------------------- vnc.h | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- vnc_keysym.h | 5 -- 10 files changed, 235 insertions(+), 147 deletions(-)Daniel
diff -r
1e8d80609fe1MakefileMakefile +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)diff -r
1e8d80609fe1curses.ccurses.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 ); }diff -r
1e8d80609fe1curses_keys.hcurses_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 },diff -r
1e8d80609fe1keymaps.ckeymaps.c +17
-28@@ -22,34 +22,20 @@* THE SOFTWARE. */ -static int get_keysym (const char *name) +#include "keymaps.h" +#include "sysemu.h" + +static int get_keysym (const name2keysym_t *table, +const char *name) {const name2keysym_t *p; -for (p = name2keysym; p->name !=NULL ; p++) { +for (p = table; p->name !=NULL ; p++) {if (!strcmp (p->name, name))return p->keysym; }return 0 ; } -struct key_range { -int start; -int end; -struct key_range *next; -}; - -#define MAX_NORMAL_KEYCODE 512 -#define MAX_EXTRA_COUNT 256 -typedef struct { -uint16_t keysym2keycode[MAX_NORMAL_KEYCODE ]; -struct { -int keysym; -uint16_t keycode; - } keysym2keycode_extra[MAX_EXTRA_COUNT ]; -int extra_count; -struct key_range *keypad_range; -struct key_range *numlock_range; -}kbd_layout_t ;static void add_to_key_range (struct key_range **krp,int code) {struct key_range *kr;@@ -73,7 +59,8 @@ static void add_to_key_range(struct key_ } } -static kbd_layout_t *parse_keyboard_layout (const char *language, +static kbd_layout_t *parse_keyboard_layout (const name2keysym_t *table, +const char *language,kbd_layout_t * k) {FILE *f;@@ -102,7 +89,7 @@ static kbd_layout_t *parse_keyboard_layoif (!strncmp (line,"map " ,4 ))continue ;if (!strncmp (line,"include " ,8 )) { -parse_keyboard_layout (line +8 , k); +parse_keyboard_layout (table, line +8 , k); }else {char *end_of_keysym = line;while (*end_of_keysym !=0 && *end_of_keysym !=' ' )@@ -110,7 +97,7 @@ static kbd_layout_t *parse_keyboard_layoif (*end_of_keysym) {int keysym; *end_of_keysym =0 ; - keysym =get_keysym (line); + keysym =get_keysym (table, line);if (keysym ==0 ) {// fprintf(stderr, "Warning: unknown keysym %s\n", line); }else {@@ -154,12 +141,14 @@ static kbd_layout_t *parse_keyboard_layoreturn k; } -static void *init_keyboard_layout (const char *language) + +void *init_keyboard_layout (const name2keysym_t *table,const char *language) { -return parse_keyboard_layout (language,0 ); +return parse_keyboard_layout (table, language,0 ); } -static int keysym2scancode (void *kbd_layout,int keysym) + +int keysym2scancode (void *kbd_layout,int keysym) {kbd_layout_t *k = kbd_layout;if (keysym <MAX_NORMAL_KEYCODE ) {@@ -180,7 +169,7 @@ static int keysym2scancode(void *kbd_layreturn 0 ; } -static inline int keycode_is_keypad (void *kbd_layout,int keycode) +int keycode_is_keypad (void *kbd_layout,int keycode) {kbd_layout_t *k = kbd_layout;struct key_range *kr;@@ -191,7 +180,7 @@ static inline int keycode_is_keypad(voidreturn 0 ; } -static inline int keysym_is_numlock (void *kbd_layout,int keysym) +int keysym_is_numlock (void *kbd_layout,int keysym) {kbd_layout_t *k = kbd_layout;struct key_range *kr;diff -r
1e8d80609fe1keymaps.hkeymaps.h new file +60
-0@@ -0,0 +1,60 @@ +/* +* QEMU keysym to keycode conversion using rdesktop keymaps +* +* Copyright (c) 2004 Johannes Schindelin +* +* 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_KEYMAPS_H__ +#define __QEMU_KEYMAPS_H__ + +#include "qemu-common.h" + +typedef struct { +const char * name; +int keysym; +}name2keysym_t ; + +struct key_range { +int start; +int end; +struct key_range *next; +}; + +#define MAX_NORMAL_KEYCODE 512 +#define MAX_EXTRA_COUNT 256 +typedef struct { +uint16_t keysym2keycode[MAX_NORMAL_KEYCODE ]; +struct { +int keysym; +uint16_t keycode; + } keysym2keycode_extra[MAX_EXTRA_COUNT ]; +int extra_count; +struct key_range *keypad_range; +struct key_range *numlock_range; +}kbd_layout_t ; + + +void *init_keyboard_layout (const name2keysym_t *table,const char *language); +int keysym2scancode (void *kbd_layout,int keysym); +int keycode_is_keypad (void *kbd_layout,int keycode); +int keysym_is_numlock (void *kbd_layout,int keysym); + +#endif /* __QEMU_KEYMAPS_H__ */ diff -r
1e8d80609fe1sdl.csdl.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 ); }diff -r
1e8d80609fe1sdl_keysym.hsdl_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 },diff -r
1e8d80609fe1vnc.cvnc.c +5
-96@@ -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,26 +24,17 @@* 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 "keymaps.c" #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@@ -65,91 +57,8 @@ 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 - -struct VncState -{ -QEMUTimer *timer; -int lsock; -int csock; -DisplayState *ds; -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 *display; -char *password; -int auth; -#ifdef CONFIG_VNC_TLS -int subauth; -int x509verify; - -char *x509cacert; -char *x509cacrl; -char *x509cert; -char *x509key; -#endif -char challenge[VNC_AUTH_CHALLENGE_SIZE ]; - -#ifdef CONFIG_VNC_TLS -int wiremode; -gnutls_session_t tls_session; -#endif - -Buffer output; -Buffer input; -kbd_layout_t *kbd_layout; -/* 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 ]; -};static VncState *vnc_state;/* needed for info vnc */ static DisplayChangeListener *dcl;@@ -2352,9 +2261,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 );diff -r
1e8d80609fe1vnc.hvnc.h +137
-3@@ -1,5 +1,139 @@ -#ifndef __VNCTIGHT_H -#define __VNCTIGHT_H +/* +* 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 __VNC_H +#define __VNC_H + + +#include "qemu-common.h" +#include "console.h" +#include "audio/audio.h" +#include <zlib.h> + +#ifdef CONFIG_VNC_TLS +#include <gnutls/gnutls.h> +#include <gnutls/x509.h> +#endif /* CONFIG_VNC_TLS */ + +#include "keymaps.h" + + +/***************************************************************************** +* +* Core data structures +* +*****************************************************************************/ + + +#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 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); + + +typedef struct Buffer +{ +size_t capacity; +size_t offset; +uint8_t *buffer; +}Buffer ; + +struct VncState +{ +QEMUTimer *timer; +int lsock; +int csock; +DisplayState *ds; +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 *display; +char *password; +int auth; +#ifdef CONFIG_VNC_TLS +int subauth; +int x509verify; + +char *x509cacert; +char *x509cacrl; +char *x509cert; +char *x509key; +#endif +char challenge[VNC_AUTH_CHALLENGE_SIZE ]; + +#ifdef CONFIG_VNC_TLS +int wiremode; +gnutls_session_t tls_session; +#endif + +Buffer output; +Buffer input; +kbd_layout_t *kbd_layout; +/* 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 ]; +};/***************************************************************************** * @@ -109,4 +243,4 @@ enum {#define VNC_FEATURE_TIGHT_MASK (1 << VNC_FEATURE_TIGHT)#define VNC_FEATURE_ZLIB_MASK (1 << VNC_FEATURE_ZLIB) -#endif /* __VNCTIGHT_H */ +#endif /* __VNC_H */ diff -r
1e8d80609fe1vnc_keysym.hvnc_keysym.h +1
-4@@ -1,7 +1,4 @@ -typedef struct { -const char * name; -int keysym; -}name2keysym_t ; +static const name2keysym_t name2keysym[]={/* ascii */ {"space" ,0x020 },
Re: [Qemu-devel] PATCH: 2/7: Push VncState struct into vnc.h
Quoted 6 lines · Anthony Liguori
Quoted 5 lines · Daniel P. Berrange
This patch moves the declaration for the VncState struct out of the
vnc.cfile and intovnc.h. This is to prepare for next patches which have the auth mechanisms implementated in separatevnc-auth-vencrypt.candvnc-auth-sasl.cfiles
Quoted 8 lines
Quoted 6 lines
In doing this, I discovered that there is a pile of duplicated keymap code statically compiled into all the console frontends. A couple of trivial changes allowed this to be sanitized, so instead of doing a #include "
keymaps.c", duplicating all code, we can have a sharedkeymaps.hfile, and only compile code once.It would be better if you split the keymap cleanup into a different patch.
Ok, easy enough todo. I'll post new patch to deal with this keymap change first.
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 :|
Re: [Qemu-devel] PATCH: 3/7: Split out VNC TLS auth code to 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.
Makefile | 11 b/vnc-auth-vencrypt.c | 167 ++++++++++++++ b/vnc-auth-vencrypt.h | 33 ++ b/vnc-tls.c | 420 +++++++++++++++++++++++++++++++++++ b/vnc-tls.h | 70 +++++ vnc.c | 588 +++----------------------------------------------- vnc.h | 78 ++++-- 7 files changed, 786 insertions(+), 581 deletions(-)
Daniel
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 +420 -0
420 lines not on this page · raw message
vnc-tls.h new file +70 -0
70 lines not on this page · raw message
vnc.c +37 -551
768 lines not on this page · raw message
vnc.h +49 -29
123 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: 4/7: Add SASL authentication extension to VNC
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 | 629 ++++++++++++++++++++++++++++++++++++++++++++++++++++ b/vnc-auth-sasl.h | 72 +++++ configure | 34 ++ qemu-doc.texi | 109 ++++++++- vnc-auth-vencrypt.c | 12 vnc.c | 252 ++++++++++++++++++-- vnc.h | 31 ++ 10 files changed, 1146 insertions(+), 39 deletions(-)
Daniel
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 +102 -7
158 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 +629 -0
629 lines not on this page · raw message
vnc-auth-sasl.h new file +72 -0
72 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->auth); +VNC_DEBUG ("Reject subauth %d server bug\n" , vs->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)->subauth == VNC_AUTH_VENCRYPT_X509NONE || \ (vs)->subauth == VNC_AUTH_VENCRYPT_X509VNC || \ - (vs)->subauth == VNC_AUTH_VENCRYPT_X509PLAIN) + (vs)->subauth == VNC_AUTH_VENCRYPT_X509PLAIN || \ + (vs)->subauth == VNC_AUTH_VENCRYPT_X509SASL)static int protocol_client_vencrypt_auth (VncState *vs,uint8_t *data,size_t len)
vnc.c +225 -27
401 lines not on this page · raw message
vnc.h +29 -2
@@ -82,6 +82,10 @@ typedef struct Buffer#include "vnc-auth-vencrypt.h" #endif +#ifdef CONFIG_VNC_SASL +#include "vnc-auth-sasl.h" +#endif +struct VncState {QEMUTimer *timer;
@@ -111,6 +115,9 @@ struct VncStatestruct VncStateTLS tls;#endif char challenge[VNC_AUTH_CHALLENGE_SIZE ]; +#ifdef CONFIG_VNC_SASL +struct VncStateSASL sasl; +#endif Buffer output;Buffer input;
@@ -147,8 +154,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 {
@@ -159,6 +167,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, };
@@ -240,6 +250,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);
@@ -259,8 +271,23 @@ 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 /* __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: 5/7: 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.
(qemu) info vnc
Server: active
address: 0.0.0.0:5901
auth: vencrypt+x509+sasl Client: active
address: 127.0.0.1:42956
x509 dname: C=GB,O=Red Hat,L=London,ST=London,CN=localhost
username: test
vnc-tls.c | 17 +++++++++++++++++ vnc-tls.h | 3 +++ vnc.c | 19 +++++++++++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-)
Daniel
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); }
@@ -346,6 +362,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
@@ -48,6 +48,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
@@ -176,6 +176,21 @@ void do_info_vnc(void)term_puts ("Client: active\n" );term_puts (clientAddr);free (clientAddr); + +#ifdef CONFIG_VNC_TLS +if (vnc_state->tls.session && + vnc_state->tls.dname) +term_printf (" x509 dname: %s\n" , vnc_state->tls.dname); +else +term_puts (" x509 dname: none\n" ); +#endif +#ifdef CONFIG_VNC_SASL +if (vnc_state->sasl.conn && + vnc_state->sasl.username) +term_printf (" username: %s\n" , vnc_state->sasl.username); +else +term_puts (" username: none\n" ); +#endif } } }
@@ -1781,7 +1796,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->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" ;
@@ -1821,7 +1836,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->auth); +VNC_DEBUG ("Reject auth %d server code bug\n" , vs->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: 6/7: Support simple ACL for client authorization
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
At startup the ACLs currently default to an allow policy. The next patch will provide a way to load a pre-defined ACL when starting up
Makefile | 6 +- b/acl.c | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ b/acl.h | 68 ++++++++++++++++++++++++ monitor.c | 80 ++++++++++++++++++++++++++++ vnc-auth-sasl.c | 19 +++++- vnc-auth-sasl.h | 4 + vnc-tls.c | 19 ++++++ vnc-tls.h | 3 + vnc.c | 14 ++++ 9 files changed, 363 insertions(+), 8 deletions(-)
Daniel
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 +158 -0
158 lines not on this page · raw message
acl.h new file +68 -0
68 lines not on this page · raw message
monitor.c +80 -0
101 lines not on this page · raw message
vnc-auth-sasl.c +15 -4
@@ -120,26 +120,37 @@ 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 =strdup ((const char *)val);if (vs->sasl.username ==NULL ) { -VNC_DEBUG ("out of memory copying username\n" ); +VNC_DEBUG ("out of memory copying username, denying access\n" );return -1 ; } -return 0 ; +if (vs->sasl.acl ==NULL ) { +VNC_DEBUG ("unexpectedly missing ACL, denying access\n" ); +return -1 ; + } + + allow =qemu_acl_party_is_allowed (vs->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 +4 -0
@@ -29,6 +29,8 @@#include <sasl/sasl.h> +#include "acl.h" +struct VncStateSASL {sasl_conn_t *conn;/* If we want to negotiate an SSF layer with client */
@@ -52,6 +54,8 @@ struct VncStateSASL {unsigned int encodedOffset;char *username;char *mechlist; + +ACL *acl; };void vnc_sasl_client_cleanup (VncState *vs);
vnc-tls.c +19 -0
@@ -255,6 +255,25 @@ int vnc_tls_validate_certificate(struct gnutls_strerror (ret));return -1 ; } + +if (vs->tls.x509verify) { +int allow; +if (!vs->tls.acl) { +VNC_DEBUG ("unexpected missing acl, denying client\n" ); +gnutls_x509_crt_deinit (cert); +return -1 ; + } + + allow =qemu_acl_party_is_allowed (vs->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 ,
@@ -38,6 +40,7 @@ enum {struct VncStateTLS {int x509verify;/* Non-zero if server requests & validates client cert */ +ACL *acl;/* Paths to x509 certs/keys */ char *x509cacert;
vnc.c +12 -2
@@ -29,6 +29,7 @@#include "sysemu.h" #include "qemu_socket.h" #include "qemu-timer.h" +#include "acl.h" #define VNC_REFRESH_INTERVAL (1000 / 30)
@@ -2072,6 +2073,10 @@ int vnc_display_open(DisplayState *ds, c #ifdef CONFIG_VNC_SASL }else if (strncmp (options,"sasl" ,4 ) ==0 ) { sasl =1 ;/* Require SASL auth */ +if (!(vs->sasl.acl =qemu_acl_init ("vnc.username" ))) { +fprintf (stderr,"Failed to create username ACL\n" ); +exit (1 ); + }#endif #ifdef CONFIG_VNC_TLS }else if (strncmp (options,"tls" ,3 ) ==0 ) {
@@ -2079,8 +2084,13 @@ int vnc_display_open(DisplayState *ds, c }else if (strncmp (options,"x509" ,4 ) ==0 ) {char *start, *end; x509 =1 ;/* Require x509 certificates */ -if (strncmp (options,"x509verify" ,10 ) ==0 ) - vs->tls.x509verify =1 ;/* ...and verify client certs */ +if (strncmp (options,"x509verify" ,10 ) ==0 ) { + vs->tls.x509verify =1 ;/* ...and verify client certs */ +if (!(vs->tls.acl =qemu_acl_init ("vnc.x509dname" ))) { +fprintf (stderr,"Failed to create x509 dname ACL\n" ); +exit (1 ); + } + }/* Now check for 'x509=/some/path' postfix * and use that to setup x509 certificate/key paths */
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/7: Support simple ACL for client authorization
Quoted 126 lines · Daniel P. Berrange
This 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 policyIf 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=bobAt startup the ACLs currently default to an allow policy. The next patch will provide a way to load a pre-defined ACL when starting up
Signed-off-by Daniel P. Berrange <[email protected]>Makefile | 6 +- b/acl.c | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ b/acl.h | 68 ++++++++++++++++++++++++ monitor.c | 80 ++++++++++++++++++++++++++++ vnc-auth-sasl.c | 19 +++++- vnc-auth-sasl.h | 4 + vnc-tls.c | 19 ++++++ vnc-tls.h | 3 + vnc.c | 14 ++++ 9 files changed, 363 insertions(+), 8 deletions(-)Daniel
diff -r
efb50f6c8c69MakefileMakefile +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)diff -r
efb50f6c8c69acl.cacl.c new file +23
-0@@ -0,0 +1,158 @@ +/* +* QEMU access control list management +* +* 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. +*/
acl.c line 33
Quoted 10 lines
acl.c new file +10
-0+ + +#include "qemu-common.h" +#include "sysemu.h" +#include "acl.h" +#include <fnmatch.h> + + +static unsigned int nacls =0 ; +static ACL **acls =NULL ;
I'd prefer you make this a list (using sys-queue.h). An advantage would be that you could support removing rules in the monitor as that seems like an obvious feature.
BTW, there is a qemu_strdup and you don't have to check it's results.
Regards,
Anthony Liguori
Re: [Qemu-devel] PATCH: 7/7: Add external persistent ACL file
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 | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ acl.h | 3 + vl.c | 12 +++++++ 3 files changed, 121 insertions(+)
Daniel
acl.c +106 -0
@@ -71,6 +71,112 @@ ACL *qemu_acl_init(const char *aclname)return 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; +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' ; + +if (fnmatch (scope, name ? name :"" ,0 ) !=0 ) { +continue ; + } + + 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 (ACL *acl,const char *party) {
acl.h +3 -0
@@ -44,6 +44,9 @@ ACL *qemu_acl_init(const char *aclname);ACL *qemu_acl_find (const char *aclname); +int qemu_acl_load_file (const char *path, +const char *name); +int qemu_acl_party_is_allowed (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>
@@ -3948,6 +3949,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"
@@ -4129,6 +4131,7 @@ enum { QEMU_OPTION_full_screen, QEMU_OPTION_g, QEMU_OPTION_vnc, + QEMU_OPTION_acl,/* Network options: */ QEMU_OPTION_net,
@@ -4243,6 +4246,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},
@@ -4621,6 +4625,7 @@ int main(int argc, char **argv, char **econst char *pid_file =NULL ;int autostart;const char *incoming =NULL ; +const char *acl_file =NULL ;qemu_cache_utils_init (envp);
@@ -5160,6 +5165,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 ;
@@ -5611,6 +5619,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 :|
Re: [Qemu-devel] PATCH: 7/7: Add external persistent ACL file
Quoted 35 lines · Daniel P. Berrange
This 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
Quoted 9 lines
# 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"
I feel really uncomfortable with this especially since Markus is now working on configuration file support. It seems to me that we'll want to store any ACL information in the host configuration file.
Unless there's a really strong case that you always want ACLs to be stored in a separate file, I'd rather wait to see how the host configuration file stuff turns out before applying this.
I assume that libvirt will use the monitor interface anyway so presumably, it's not a huge problem to wait on this?
Regards,
Anthony Liguori
Re: [Qemu-devel] PATCH: 7/7: Add external persistent ACL file
Quoted 8 lines · Anthony Liguori
I feel really uncomfortable with this especially since Markus is now working on configuration file support. It seems to me that we'll want to store any ACL information in the host configuration file.
Unless there's a really strong case that you always want ACLs to be stored in a separate file, I'd rather wait to see how the host configuration file stuff turns out before applying this.
I rather wanted the ACL configuration to be separate from the general emulator configuration. This file format was intended to allow you to have one ACL file that is used across all your QEMU instances, regardless of what emulator configuration file they might be using.
Though, perhaps if the general config file allowed '#include acl.cfg' that would be sufficient flexibilty, allowing a shared ACL for all configs.
Quoted 2 lines
I assume that libvirt will use the monitor interface anyway so presumably, it's not a huge problem to wait on this?
I'm not really decided on what the best way to approach things is from the libvirt POV. We could certainly use the monitor interface to set it up - just have to decide how/where to persist it.
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 20 lines · Daniel P. Berrange
The combined diffstat for all 7 patches about to follow, is
.hgignore | 16 Makefile | 27 + Makefile.target | 5 b/acl.c | 264 ++++++++++++ b/acl.h | 71 +++ b/keymaps.h | 60 ++ b/qemu.sasl | 34 + b/vnc-auth-sasl.c | 640 +++++++++++++++++++++++++++++ b/vnc-auth-sasl.h | 76 +++ b/vnc-auth-vencrypt.c | 175 +++++++ b/vnc-auth-vencrypt.h | 33 + b/vnc-tls.c | 456 ++++++++++++++++++++ b/vnc-tls.h | 76 +++ configure | 34 + curses.c | 3 curses_keys.h | 9 keymaps.c | 45 -- monitor.c | 80 +++
Quoted 8 lines
qemu-doc.texi | 109 ++++ sdl.c | 3 sdl_keysym.h | 7 vl.c | 12 vnc.c | 1100 ++++++++++++++++++-------------------------------- vnc.h | 215 +++++++++ vnc_keysym.h | 5 25 files changed, 2795 insertions(+), 760 deletions(-)
FYI, the patches in this series are all diffed against the following SVN changeset:
r6617 | aliguori | 2009-02-11 21:00:43 +0000 (Wed, 11 Feb 2009) | 8 lines
KVM: cpuid function 2: store all values (Amit Shah)
And also assume my TLS bugfix from earlier today is applied
http://lists.gnu.org/archive/html/qemu-devel/2009-02/msg00820.html
Regards,
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 15 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
Quoted 9 lines
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 2nd version of the patches I initially posted here
http://lists.gnu.org/archive/html/qemu-devel/2009-02/msg00255.html
Modulo the comments I made, this series look really nice. I'm going to apply Brian Kress' multiple clients patch once he adds a SoB so you'll want to make sure to rebase against that for the next series.
Regards,
Anthony Liguori
Quoted 51 lines
Changes since last time
- Re-factor the code to move TLS and SASL methods into separate files,
vnc-tls.c,vnc-auth-vencrypt.candvnc-auth-vencrypt.h- Added simple access control lists for authorization of client users on either SASL username, or x509 distinguished name
- Added proof of concept external file format for persisting ACLs
- Extend 'info vnc' to show much more information about clients and auth
- Tested with SASL + Digest-MD5, SASL + GSSAPI. TLS + SASL + Digest-MD5 and TLS + SASL + GSSAPI. This gives coverage off all interesting code paths and/or I/O encryption combinations.
The combined diffstat for all 7 patches about to follow, is
.hgignore | 16 Makefile | 27 + Makefile.target | 5 b/acl.c | 264 ++++++++++++ b/acl.h | 71 +++ b/keymaps.h | 60 ++ b/qemu.sasl | 34 + b/vnc-auth-sasl.c | 640 +++++++++++++++++++++++++++++ b/vnc-auth-sasl.h | 76 +++ b/vnc-auth-vencrypt.c | 175 +++++++ b/vnc-auth-vencrypt.h | 33 + b/vnc-tls.c | 456 ++++++++++++++++++++ b/vnc-tls.h | 76 +++ configure | 34 + curses.c | 3 curses_keys.h | 9 keymaps.c | 45 -- monitor.c | 80 +++ qemu-doc.texi | 109 ++++ sdl.c | 3 sdl_keysym.h | 7 vl.c | 12 vnc.c | 1100 ++++++++++++++++++-------------------------------- vnc.h | 215 +++++++++ vnc_keysym.h | 5 25 files changed, 2795 insertions(+), 760 deletions(-)Daniel