PATCH: RFC: Support SASL authentication in VNC
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 patch provides an initial implementation of this extension for the QEMU VNC server. I am not requesting it is merged just yet, but I'd like get it all finished in time of the suggested QEMU release at the end of the month, so I'm sending the patch out now for early comments
In most circumstances, it is neccessary to combine use of SASL, with the TLS + x509 support, since most SASL mechanisms only provide for authentication. In this case you would launch QEMU with
qemu ... -vnc localhost:1,tls,x509,sasl
The Kerberos GSSAPI mechanism for SASL is unusual in that it can also provide encryption of the data session (so called SSF layer in SASL terminology). If using this, QEMU can be launched with just
qemu ... -vnc localhost:1,sasl
The actual choice of SASL mechanism is controlled by the SASL service configuration file. THis patch integrates with Cyrus-SASL library and thus the config is in /etc/sasl2/qemu.conf. This patch does not yet support it, but I intend too add support for overriding this config with $HOME/.sasl2/qemu.conf, since most people use QEMU in their regular user accounts and may not have access to the system SASL configs. The updates to qemu-doc.texi show how to config SASL, or the Cyrus-SASL docs can be referred to.
As I mentioned, this uses Cyrus-SASL libraries. The configure script probes for this, and disables SASL support if not found, so it should not cause problems for places without Cyrus-SASL like Windows.
The main missing points in this patch
- Authorization. Once we've authenticated the user, how do we decide whether they're allow to use VNC. eg, just because a user has a valid Kerberos principle, does not imply we should allow access.
We really need an access control list, listing the allowed SASL usernames and/or x509 client certificate CNAMEs which are authorized. This should probably live in an external file, perhaps allowing for ACLs against multiple different QEMU network based devices. eg I could just add a arg
-acl /path/to/aclfile
And invent a format like
eg 1
vnc.allow: [email protected]
vnc.allow: [email protected]
vnc.deny: *
eg 2
vnc.deny: [email protected]
vnc.deny: [email protected]
vnc.allow: *@EXAMPLE.COM
vnc.deny: *- Possible monitor commands to adding/removing ACL entires at runtime
acl add vnc.allow [email protected]
acl remove vnc.allow [email protected]
- Per-user SASL config files, eg $HOME/.sasl2/qemu.conf to allow override of SASL mechanims choice by unprivileged users running QEMU
- Extend 'info vnc' command to report the authenticated username and x509 client certificate CNAME
Finally, I have equivalent patches available for GTK-VNC supporting this SASL authentication protocol on the client end. I would also like to add it to something like TightVNC and/or VINO server to make it a broadly acceptable auth extension for VNC, since VNC is sorely lacking in a good auth standard like SASL.
Makefile.target | 5 configure | 34 ++ qemu-doc.texi | 94 ++++++ qemu.sasl | 34 ++ vnc.c | 800 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- vnc.h | 16 - 6 files changed, 964 insertions(+), 19 deletions(-)
Regards,
Daniel
Makefile.target +5 -0
@@ -554,6 +554,11 @@ 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
vnc.c +783 -17
912 lines not on this page · raw message
qemu.sasl +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.h +14 -2
@@ -15,8 +15,9 @@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, /* Also implemented by GTK-VNC & VINO */ };#ifdef CONFIG_VNC_TLS
@@ -33,6 +34,8 @@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, };#define X509_CA_CERT_FILE "ca-cert.pem"
@@ -42,6 +45,15 @@#endif /* CONFIG_VNC_TLS */ + +#ifdef CONFIG_VNC_SASL +enum qemu_sasl_ssf { +QEMU_SASL_SSF_NONE =0 , +QEMU_SASL_SSF_READ =1 , +QEMU_SASL_SSF_WRITE =2 , +}; +#endif /* CONFIG_VNC_SASL */ +/***************************************************************************** * * Encoding types
qemu-doc.texi +94 -0
119 lines not on this page · raw message
configure +34 -0
@@ -164,6 +164,7 @@ fmod_inc="" oss_lib="" vnc_tls="yes" +vnc_sasl="yes" bsd="no" linux="no" solaris="no"
@@ -387,6 +388,8 @@ ;; --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 " --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 @@ 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 @@ 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 @@ 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
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 :|
Hi Dan,
Quoted 56 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 patch provides an initial implementation of this extension for the QEMU VNC server. I am not requesting it is merged just yet, but I'd like get it all finished in time of the suggested QEMU release at the end of the month, so I'm sending the patch out now for early comments
In most circumstances, it is neccessary to combine use of SASL, with the TLS + x509 support, since most SASL mechanisms only provide for authentication. In this case you would launch QEMU with
qemu ... -vnc localhost:1,tls,x509,saslThe Kerberos GSSAPI mechanism for SASL is unusual in that it can also provide encryption of the data session (so called SSF layer in SASL terminology). If using this, QEMU can be launched with just
qemu ... -vnc localhost:1,sasl
The actual choice of SASL mechanism is controlled by the SASL service
configuration file. THis patch integrates with Cyrus-SASL library and
thus the config is in/etc/sasl2/qemu.conf. This patch does not yet support it, but I intend too add support for overriding this config with$HOME/.sasl2/qemu.conf, since most people use QEMU in their regular
user accounts and may not have access to the system SASL configs. The
updates to qemu-doc.texi show how to config SASL, or the Cyrus-SASL docs
can be referred to.As I mentioned, this uses Cyrus-SASL libraries. The configure script probes for this, and disables SASL support if not found, so it should not cause problems for places without Cyrus-SASL like Windows.
The main missing points in this patch
- Authorization. Once we've authenticated the user, how do we decide whether they're allow to use VNC. eg, just because a user has a valid Kerberos principle, does not imply we should allow access.
Quoted 8 lines
We really need an access control list, listing the allowed SASL usernames and/or x509 client certificate CNAMEs which are authorized. This should probably live in an external file, perhaps allowing for ACLs against multiple different QEMU network based devices. eg I could just add a arg
-acl /path/to/aclfile
Not a huge fan of using an acl file but I'm not terribly opposed to it either. I like the monitor commands but obviously, we'll need a mechanism to list existing acls too.
Quoted 66 lines
Makefile.target | 5 configure | 34 ++ qemu-doc.texi | 94 ++++++ qemu.sasl | 34 ++ vnc.c | 800 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- vnc.h | 16 - 6 files changed, 964 insertions(+), 19 deletions(-)Regards,
DanielIndex: Makefile.target
===================================================================Makefile.target +5
-0@@ -554,6 +554,11 @@ 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) endifIndex:
vnc.c
===================================================================vnc.c +21
-1@@ -43,8 +43,12 @@#include <gnutls/x509.h> #endif /* CONFIG_VNC_TLS */ -// #define _VNC_DEBUG 1 +#ifdef CONFIG_VNC_SASL +#include <sasl/sasl.h> +#endif +#define _VNC_DEBUG 1 +#ifdef _VNC_DEBUG#define VNC_DEBUG (fmt, ...) do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)@@ -123,6 +127,32 @@char *x509cert;char *x509key;#endif + +#ifdef CONFIG_VNC_SASL +sasl_conn_t *saslconn; +/* If we want to negotiate an SSF layer with client */ + int saslWantSSF :1; +/* If we are now running the SSF layer */ + int saslRunSSF :1; +/* +* If this is non-zero, then wait for that many bytes +* to be written plain, before switching to SSF encoding +* This allows the VNC auth result to finish being +* written in plain. +*/ +unsigned int saslWaitWriteSSF; + +/*
vnc.c line 155
Quoted 10 lines
vnc.c +9
-0+* Buffering encoded data to allow more clear data +* to be stuffed onto the output buffer +*/ +const uint8_t *saslEncoded; +unsigned int saslEncodedLength; +unsigned int saslEncodedOffset; +char *saslUsername; +char *saslMechlist; +#endif
I think we could use a little more love here that moved the sasl bits to a vnc-sasl.c provide that it's a sane thing to do.
Quoted 41 lines
vnc.c +1
-0+char challenge[VNC_AUTH_CHALLENGE_SIZE ];#ifdef
CONFIG_VNC_TLSvnc.c +14
-4@@ -829,6 +859,18 @@ } vs->wiremode =VNC_WIREMODE_CLEAR ;#endif /* CONFIG_VNC_TLS */ +#ifdef CONFIG_VNC_SASL +if (vs->saslconn) { + vs->saslRunSSF = vs->saslWaitWriteSSF = vs->saslWantSSF =0 ; + vs->saslEncodedLength = vs->saslEncodedOffset =0 ; + vs->saslEncoded =NULL ; +free (vs->saslUsername); +free (vs->saslMechlist); + vs->saslUsername = vs->saslMechlist =NULL ; +sasl_dispose (&vs->saslconn); + vs->saslconn =NULL ; + } +#endif /* CONFIG_VNC_SASL */ audio_del (vs);return 0 ; }@@ -840,14 +882,12 @@vnc_client_io_error (vs,-1 ,EINVAL ); } -static void vnc_client_write (void *opaque) +static long vnc_client_write_wire (VncState *vs,const uint8_t *data,size_t datalen) {long ret; -VncState *vs = opaque; -#ifdef CONFIG_VNC_TLS if (vs->tls_session) { - ret =gnutls_write (vs->tls_session, vs->output.buffer, vs->output.offset); + ret =gnutls_write (vs->tls_session, data, datalen);if (ret <0 ) {if (ret ==GNUTLS_E_AGAIN ) errno =EAGAIN ;
vnc.c line 904
Quoted 10 lines
vnc.c +4
-2@@ -857,35 +897,117 @@ } } else#endif /* CONFIG_VNC_TLS */ - ret =send (vs->csock, vs->output.buffer, vs->output.offset,0 ); - ret =vnc_client_io_error (vs, ret,socket_error ()); + ret =send (vs->csock, data, datalen,0 ); +VNC_DEBUG ("Wrote wire %p %d -> %ld\n" , data, datalen, ret); +return vnc_client_io_error (vs, ret,socket_error ()); +}
These changes seem extraneous. I'll just assume the patch needs cleanup for such things.
Quoted 70 lines
vnc.c +67
-1+#ifdef CONFIG_VNC_SASL +static long vnc_client_write_sasl (VncState *vs) +{ +long ret; + +VNC_DEBUG ("Write SASL: Pending output %p size %d offset %d Encoded: %p size %d offset %d\n" , + vs->output.buffer, vs->output.capacity, vs->output.offset, + vs->saslEncoded, vs->saslEncodedLength, vs->saslEncodedOffset); + +if (!vs->saslEncoded) { +int err; + err =sasl_encode (vs->saslconn, + (char *)vs->output.buffer, + vs->output.offset, + (const char **)&vs->saslEncoded, + &vs->saslEncodedLength); +if (err !=SASL_OK ) +return vnc_client_io_error (vs,-1 ,EIO ); + + vs->output.offset =0 ; + vs->saslEncodedOffset =0 ; + } + + ret =vnc_client_write_wire (vs, + vs->saslEncoded + vs->saslEncodedOffset, + vs->saslEncodedLength - vs->saslEncodedOffset);if (!ret) -return ; +return 0 ; + vs->saslEncodedOffset += ret; +if (vs->saslEncodedOffset == vs->saslEncodedLength) { + vs->saslEncoded =NULL ; + vs->saslEncodedOffset = vs->saslEncodedLength =0 ; + } + +/* Can't merge this block with one above, because +* someone might have written more unencrypted +* data in vs->output while we were processing +* SASL encoded output +*/ +if (vs->output.offset ==0 ) { +qemu_set_fd_handler2 (vs->csock,NULL , vnc_client_read,NULL , vs); + } + +return ret; +} +#endif /* CONFIG_VNC_SASL */ + +static long vnc_client_write_plain (VncState *vs) +{ +long ret; + +#ifdef CONFIG_VNC_SASL +VNC_DEBUG ("Write Plain: Pending output %p size %d offset %d. Wait SSF %d\n" , + vs->output.buffer, vs->output.capacity, vs->output.offset, + vs->saslWaitWriteSSF); + +if (vs->saslconn && + vs->saslRunSSF && + vs->saslWaitWriteSSF) { + ret =vnc_client_write_wire (vs, vs->output.buffer, vs->saslWaitWriteSSF); +if (ret) + vs->saslWaitWriteSSF -= ret; + } else +#endif /* CONFIG_VNC_SASL */ + ret =vnc_client_write_wire (vs, vs->output.buffer, vs->output.offset); +if (!ret) +return 0 ; +
vnc.c line 983
Quoted 10 lines
vnc.c +2
-0memmove (vs->output.buffer, vs->output.buffer + ret, (vs->output.offset - ret)); vs->output.offset -= ret;if (vs->output.offset ==0 ) {qemu_set_fd_handler2 (vs->csock,NULL , vnc_client_read,NULL , vs); } + +return ret; }
So there are three possible layers of write interaction. SASL -> TLS -> Socket. I think adding a mechanism to register write hooks to implement SASL and TLS would be good. If you can, moving the TLS support into a separate file would be helpful too.
vnc.c line 1860
Quoted 4 lines
vnc.c +3
-0+#ifdef CONFIG_VNC_SASL +/* Max amount of data we send/recv for SASL steps to prevent DOS */ +#define SASL_DATA_MAX_LEN (1024 * 1024)
Be careful with this. Kerberos tickets can contain arbitrary data (for instance, the MS PAC). This can make the data transfer size be much larger than you'd expect.
I like the general idea here. SASL is a nice mechanism and the implementation is pretty straight forward. I'll do a more thorough review when you get something closer to ready for inclusion.
Regards,
Anthony Liguori
Quoted 24 lines · Anthony Liguori
Quoted 23 lines · Daniel P. Berrange
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.
The main missing points in this patch
- Authorization. Once we've authenticated the user, how do we decide whether they're allow to use VNC. eg, just because a user has a valid Kerberos principle, does not imply we should allow access.
We really need an access control list, listing the allowed SASL usernames and/or x509 client certificate CNAMEs which are authorized. This should probably live in an external file, perhaps allowing for ACLs against multiple different QEMU network based devices. eg I could just add a arg
Quoted 6 lines
Quoted 2 lines
-acl /path/to/aclfile
Not a huge fan of using an acl file but I'm not terribly opposed to it either. I like the monitor commands but obviously, we'll need a mechanism to list existing acls too.
I don't particularly like it either, but need some kind of external persistent config for the authorization data - and it needs to be independant of any QEMU machine config file we create, because one authorization list could be shared across many VMs.
The only other option I consider was to punt the problem on to the caller, and require them to issue a series of monitor commands to setup the ACL at startup. I don't particularly like that though since it'd just be pushing the problem elsewhere.
Suggestions welcome from the audience...
Quoted 74 lines
Quoted 74 lines
Makefile.target | 5 configure | 34 ++ qemu-doc.texi | 94 ++++++ qemu.sasl | 34 ++ vnc.c | 800 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- vnc.h | 16 - 6 files changed, 964 insertions(+), 19 deletions(-)Regards,
DanielIndex: Makefile.target
===================================================================Makefile.target +0
-0@@ -554,6 +554,11 @@ LIBS += $(CONFIG_VNC_TLS_LIBS)endif
Makefile.target +5
-0+ifdef CONFIG_VNC_SASL +CPPFLAGS += $(CONFIG_VNC_SASL_CFLAGS) +LIBS += $(CONFIG_VNC_SASL_LIBS) +endif +ifdef
CONFIG_BLUEZ
LIBS += $(CONFIG_BLUEZ_LIBS)
endif
Index:vnc.c
===================================================================vnc.c +26
-1@@ -43,8 +43,12 @@#include <gnutls/x509.h> #endif /* CONFIG_VNC_TLS */ -// #define _VNC_DEBUG 1 +#ifdef CONFIG_VNC_SASL +#include <sasl/sasl.h> +#endif +#define _VNC_DEBUG 1 +#ifdef _VNC_DEBUG#define VNC_DEBUG (fmt, ...) do { fprintf(stderr, fmt, ## __VA_ARGS__); }while (0 )@@ -123,6 +127,32 @@char *x509cert;char *x509key;#endif + +#ifdef CONFIG_VNC_SASL +sasl_conn_t *saslconn; +/* If we want to negotiate an SSF layer with client */ + int saslWantSSF :1; +/* If we are now running the SSF layer */ + int saslRunSSF :1; +/* +* If this is non-zero, then wait for that many bytes +* to be written plain, before switching to SSF encoding +* This allows the VNC auth result to finish being +* written in plain. +*/ +unsigned int saslWaitWriteSSF; + +/* +* Buffering encoded data to allow more clear data +* to be stuffed onto the output buffer +*/ +const uint8_t *saslEncoded; +unsigned int saslEncodedLength;
Quoted 8 lines
vnc.c line 157
Quoted 5 lines
vnc.c +4
-0+unsigned int saslEncodedOffset; +char *saslUsername; +char *saslMechlist; +#endif I think we could use a little more love here that moved the sasl bits to a
vnc-sasl.cprovide that it's a sane thing to do.
I don't think it is desirable to move all the SASL code to an external file - in particular the interaction at the I/O layer I think is important to have in one place to make it clear to read & see the whole picture.
I wouldn't mind moving all this metadata into a separate struct though, and just include an instance of that in the main QEMU client struct.
Likewise I think its reasonable to move the auth handshake impl methods into a separate file, since they're nicely self-contained and quite large pieces of code.
Quoted 21 lines
Quoted 21 lines
vnc.c +1
-1-static void vnc_client_write(void *opaque) +static long vnc_client_write_wire (VncState *vs,const uint8_t *data,size_t datalen){ long ret;vnc.c +0
-2-VncState *vs = opaque; -#ifdef CONFIG_VNC_TLS if (vs->tls_session) {vnc.c +0
-1- ret = gnutls_write(vs->tls_session, vs->output.buffer,
vs->output.offset);vnc.c +1
-0+ ret =gnutls_write (vs->tls_session, data, datalen);if (ret < 0) { if (ret == GNUTLS_E_AGAIN) errno = EAGAIN;vnc.c +0
-2@@ -857,35 +897,117 @@ } } else#endif /* CONFIG_VNC_TLS */ - ret =send (vs->csock, vs->output.buffer, vs->output.offset,0 ); - ret =vnc_client_io_error (vs, ret,socket_error ());
Quoted 8 lines
vnc.c line 933
Quoted 5 lines
vnc.c +4
-0+ ret =send (vs->csock, data, datalen,0 ); +VNC_DEBUG ("Wrote wire %p %d -> %ld\n" , data, datalen, ret); +return vnc_client_io_error (vs, ret,socket_error ()); +}These changes seem extraneous. I'll just assume the patch needs cleanup for such things.
It is required actually - you have two layers of buffering here.
The vnc_write() methods, still put stuff into vs->output.buffer as now. This buffer cannot expect to go straight onto the wire though. It may need to be passed through the SASL SSF layer, by calling sasl_encode() (or sasl_decode() for recv'd data).
For clarity the psuedo-code logical algorithm, is now
vnc_client_write()
if using SASL
call vnc_client_write_sasl
else
call vnc_client_write_plain
vnc_write_plain()
call vnc_client_write_wire(vs->output.bufffer)
vnc_write_sasl()
data = sasl_encode(vs->output.buffer)
call vnc_client_write_wire(data) vnc_write_wire()
if using SSL
call gnutls_write
else
call send()
There are a few complications in the SASL path relating to fact that we have to deal with an intermediate buffer and cannot guarentee that we will be able to write all of this intermediate buffer in one go (if the socket gives EAGAIN). There's also a scenario where we have decided to run SASL, but still have some clear text data to send before actually switching in the encoding routines.
The read path basically follows exactly same model / structure.
Quoted 4 lines
So there are three possible layers of write interaction. SASL -> TLS -> Socket. I think adding a mechanism to register write hooks to implement SASL and TLS would be good. If you can, moving the TLS support into a separate file would be helpful too.
Well, 4 scenarios, and upto 3 layers
- Direct to socket
- TLS -> socket
- SASL -> socket
- SASL -> TLS -> socket
NB, the last case of SASL -> TLS -> socket, is ordinarily identical to the TLS -> socket case, because we inform SASL that TLS is providing a encryption layer, and thus sasl_encode/decode will (likely) become a plain pass-through. This is all decided based on the min_ssf/max_ssf stuff we setup during the SASL auth process. We still do the sasl_decode step though, because you never know when someone will invent a new SASL plugin that will want to actually do something here, despite TLS already providing encryption.
I don't think a write hooks would be particularly helpful at making this clearer, because SASL vs TLS use quite different approachs to how/where the encryption is done. In SASL case you just have encode and decode methods, and you have to take care of all buffering of data yourself. In TLS case, you have replacement read/write methods and TLS hides all the encoding & decoding from you. I think trying to hide these approaches in a generic wrappers will make it harder to understand exactly what is going on & who's doing it.
For TLS, it'd certainly be viable to move the auth handshake methods to separate files since again that stuff is nicely self-contained.
I'd just rather have all the I/O code in one place, since that's got subtle interactions between the layers.
Quoted 8 lines
vnc.c line 1860
Quoted 4 lines
vnc.c +3
-0+#ifdef CONFIG_VNC_SASL +/* Max amount of data we send/recv for SASL steps to prevent DOS */ +#define SASL_DATA_MAX_LEN (1024 * 1024)Be careful with this. Kerberos tickets can contain arbitrary data (for instance, the MS PAC). This can make the data transfer size be much larger than you'd expect.
That is a place where I'm not hugely clear on where to draw the line. I definitely need some kind of limit to avoid DOS attack from the client, but how big is big enough ? I figured 1 MB would be sufficient for a Kerberos ticket, unless someone has counter examples from the real world ?
Quoted 3 lines
I like the general idea here. SASL is a nice mechanism and the implementation is pretty straight forward. I'll do a more thorough review when you get something closer to ready for inclusion.
FYI, the way I have structured the SASL / TLS / plain layering of I/O is basically following the exact same model / structure I used in libvirt daemon for doing the same, so I'm fairly confident in the way fits together.
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 :|