Merge qcrypto 2017/05/07
Subsystems (2)
The following changes since commit dd1559bb267becbb838de41132ef60771d183e5d:
Merge remote-tracking branch 'elmarco/tags/chr-tests-pull-request' into staging (2017-05-05 17:07:55 +0100)
are available in the git repository at:
git://github.com/berrange/qemu tags/pull-qcrypto-2017-05-09-1
for you to fetch changes up to a37278169d0d7d33270c6817f4a2e4f7345e1098:
crypto: qcrypto_random_bytes() now works on windows w/o any other crypto libs (2017-05-09 14:41:47 +0100)
----------------------------------------------------------------
Merge qcrypto 2017/05/09 v1
----------------------------------------------------------------
Daniel P. Berrange (3):
Default to GSSAPI (Kerberos) instead of DIGEST-MD5 for SASL List SASL config file under the cryptography maintainer's realm
crypto: move 'opaque' parameter to (nearly) the end of parameter list
Geert Martin Ijewski (1):
crypto: qcrypto_random_bytes() now works on windows w/o any other
crypto libs
MAINTAINERS | 1 + block/crypto.c | 6 +++--- crypto/block-luks.c | 13 +++++++----- crypto/init.c | 6 ++++++ crypto/random-gcrypt.c | 2 ++ crypto/random-gnutls.c | 3 +++ crypto/random-platform.c | 45 ++++++++++++++++++++++++++++++++------- include/crypto/block.h | 6 +++--- include/crypto/random.h | 9 ++++++++ qemu-doc.texi | 50 +++++++++++++++++++++++++------------------ qemu.sasl | 54 +++++++++++++++++++++++++++-------------------- tests/test-crypto-block.c | 6 +++--- 12 files changed, 135 insertions(+), 66 deletions(-)
Signature · 1 line
2.9.3
[Qemu-devel] [PULL v1 1/4] Default to GSSAPI (Kerberos) instead of DIGEST-MD5 for SASL
RFC 6331 documents a number of serious security weaknesses in the SASL DIGEST-MD5 mechanism. As such, QEMU should not be using or recommending it as a default mechanism for VNC auth with SASL.
GSSAPI (Kerberos) is the only other viable SASL mechanism that can provide secure session encryption so enable that by defalt as the replacement. If users have TLS enabled for VNC, they can optionally decide to use SCRAM-SHA-1 instead of GSSAPI, allowing plain username and password auth.
--- qemu-doc.texi | 50 +++++++++++++++++++++++++++++--------------------- qemu.sasl | 54 +++++++++++++++++++++++++++++++----------------------- 2 files changed, 60 insertions(+), 44 deletions(-)
qemu-doc.texi +29 -21
@@ -1732,37 +1732,45 @@ SASL service config /etc/sasl2/qemu.conf. If running QEMU as an unprivileged user, an environment variable SASL_CONF_PATH can be used to make it search alternate locations for the service config. -The default configuration might contain +If the TLS option is enabled for VNC, then it will provide session encryption, +otherwise the SASL mechanism will have to provide encryption. In the latter +case the list of possible plugins that can be used is drastically reduced. In +fact only the GSSAPI SASL mechanism provides an acceptable level of security +by modern standards. Previous versions of QEMU referred to the DIGEST-MD5 +mechanism, however, it has multiple serious flaws described in detail in +RFC 6331 and thus should never be used any more. The SCRAM-SHA-1 mechanism +provides a simple username/password auth facility similar to DIGEST-MD5, but +does not support session encryption, so can only be used in combination with +TLS. + +When not using TLS the recommended configuration is @example -mech_list: digest-md5 -sasldb_path: /etc/qemu/passwd.db +mech_list: gssapi +keytab: /etc/qemu/krb5.tab @end example -This says to use the 'Digest MD5' mechanism, which is similar to the HTTP -Digest-MD5 mechanism. The list of valid usernames & passwords is maintained -in the /etc/qemu/passwd.db file, and can be updated using the saslpasswd2 -command. While this mechanism is easy to configure and use, it is not -considered secure by modern standards, so only suitable for developers / -ad-hoc testing. +This says to use the 'GSSAPI' mechanism with the Kerberos v5 protocol, with +the server principal stored in /etc/qemu/krb5.tab. For this to work the +administrator of your KDC must generate a Kerberos principal for the server, +with a name of 'qemu/somehost.example.com@@EXAMPLE.COM' replacing +'somehost.example.com' with the fully qualified host name of the machine +running QEMU, and 'EXAMPLE.COM' with the Kerberos Realm. -A more serious deployment might use Kerberos, which is done with the 'gssapi' -mechanism +When using TLS, if username+password authentication is desired, then a +reasonable configuration is @example -mech_list: gssapi -keytab: /etc/qemu/krb5.tab +mech_list: scram-sha-1 +sasldb_path: /etc/qemu/passwd.db @end example -For this to work the administrator of your KDC must generate a Kerberos -principal for the server, with a name of 'qemu/somehost.example.com@@EXAMPLE.COM' -replacing 'somehost.example.com' with the fully qualified host name of the -machine running QEMU, and 'EXAMPLE.COM' with the Kerberos Realm. +The saslpasswd2 program can be used to populate the passwd.db file with +accounts. -Other configurations will be left as an exercise for the reader. It should -be noted that only Digest-MD5 and GSSAPI provides a SSF layer for data -encryption. For all other mechanisms, VNC should always be configured to -use TLS and x509 certificates to protect security credentials from snooping. +Other SASL configurations will be left as an exercise for the reader. Note that +all mechanisms except GSSAPI, should be combined with use of TLS to ensure a +secure data channel. @node gdb_usage @section GDB usage
qemu.sasl +31 -23
67 lines not on this page · raw message
Signature · 1 line
2.9.3
[Qemu-devel] [PULL v1 2/4] List SASL config file under the cryptography maintainer's realm
In reply to Daniel P. BerrangeNo one is listed as maintainer for qemu.sasl. It is used by the VNC server for SASL auth, but since it is cryptography related, list it under the crytography maintainer's realm, rather than under the UI maintainer.
--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
@@ -1484,6 +1484,7 @@ S: Maintained F: crypto/ F: include/crypto/ F: tests/test-crypto-* +F: qemu.sasl Coroutines M: Stefan Hajnoczi <[email protected]>
Signature · 1 line
2.9.3
[Qemu-devel] [PULL v1 3/4] crypto: move 'opaque' parameter to (nearly) the end of parameter list
In reply to Daniel P. BerrangePrevious commit moved 'opaque' to be the 2nd parameter in the list:
commit 375092332eeaa6e47561ce47fd36144cdaf964d0
Author: Fam Zheng <[email protected]>
Date: Fri Apr 21 20:27:02 2017 +0800
crypto: Make errp the last parameter of functions
Move opaque to 2nd instead of the 2nd to last, so that compilers help check with the conversion.
this puts it back to the 2nd to last position.
--- block/crypto.c | 6 +++--- crypto/block-luks.c | 13 ++++++++----- include/crypto/block.h | 6 +++--- tests/test-crypto-block.c | 6 +++--- 4 files changed, 17 insertions(+), 14 deletions(-)
block/crypto.c +3 -3
@@ -56,10 +56,10 @@ static int block_crypto_probe_generic(QCryptoBlockFormat format,static ssize_t block_crypto_read_func (QCryptoBlock *block, -void *opaque,size_t offset,uint8_t *buf,size_t buflen, +void *opaque,Error **errp) {BlockDriverState *bs = opaque;
@@ -83,10 +83,10 @@ struct BlockCryptoCreateData {static ssize_t block_crypto_write_func (QCryptoBlock *block, -void *opaque,size_t offset,const uint8_t *buf,size_t buflen, +void *opaque,Error **errp) {struct BlockCryptoCreateData *data = opaque;
@@ -102,8 +102,8 @@ static ssize_t block_crypto_write_func(QCryptoBlock *block,static ssize_t block_crypto_init_func (QCryptoBlock *block, -void *opaque,size_t headerlen, +void *opaque,Error **errp) {struct BlockCryptoCreateData *data = opaque;
crypto/block-luks.c +8 -5
@@ -473,9 +473,9 @@ qcrypto_block_luks_load_key(QCryptoBlock *block,* then encrypted. */ rv =readfunc (block, - opaque, slot->key_offset *QCRYPTO_BLOCK_LUKS_SECTOR_SIZE , splitkey, splitkeylen, + opaque, errp);if (rv <0 ) { goto cleanup;
@@ -676,9 +676,10 @@ qcrypto_block_luks_open(QCryptoBlock *block,/* Read the entire LUKS header, minus the key material from * the underlying device */ - rv =readfunc (block, opaque,0 , + rv =readfunc (block,0 , (uint8_t *)&luks->header,sizeof (luks->header), + opaque, errp);if (rv <0 ) { ret = rv;
@@ -1245,7 +1246,7 @@ qcrypto_block_luks_create(QCryptoBlock *block,QCRYPTO_BLOCK_LUKS_SECTOR_SIZE ;/* Reserve header space to match payload offset */ -initfunc (block, opaque, block->payload_offset, &local_err); +initfunc (block, block->payload_offset, opaque, &local_err);if (local_err) {error_propagate (errp, local_err); goto error;
@@ -1267,9 +1268,10 @@ qcrypto_block_luks_create(QCryptoBlock *block,/* Write out the partition header and key slot headers */ -writefunc (block, opaque,0 , +writefunc (block,0 , (const uint8_t *)&luks->header,sizeof (luks->header), + opaque, &local_err);/* Delay checking local_err until we've byte-swapped */
@@ -1295,10 +1297,11 @@ qcrypto_block_luks_create(QCryptoBlock *block,/* Write out the master key material, starting at the * sector immediately following the partition header. */ -if (writefunc (block, opaque, +if (writefunc (block, luks->header.key_slots[0 ].key_offset *QCRYPTO_BLOCK_LUKS_SECTOR_SIZE , splitkey, splitkeylen, + opaque, errp) != splitkeylen) { goto error; }
include/crypto/block.h +3 -3
@@ -30,22 +30,22 @@ typedef struct QCryptoBlock QCryptoBlock;* and QCryptoBlockOpenOptions in qapi/crypto.json */ typedef ssize_t (*QCryptoBlockReadFunc )(QCryptoBlock *block, -void *opaque,size_t offset,uint8_t *buf,size_t buflen, +void *opaque,Error **errp);typedef ssize_t (*QCryptoBlockInitFunc )(QCryptoBlock *block, -void *opaque,size_t headerlen, +void *opaque,Error **errp);typedef ssize_t (*QCryptoBlockWriteFunc )(QCryptoBlock *block, -void *opaque,size_t offset,const uint8_t *buf,size_t buflen, +void *opaque,Error **errp);/**
tests/test-crypto-block.c +3 -3
@@ -187,10 +187,10 @@ static struct QCryptoBlockTestData {static ssize_t test_block_read_func (QCryptoBlock *block, -void *opaque,size_t offset,uint8_t *buf,size_t buflen, +void *opaque,Error **errp) {Buffer *header = opaque;
@@ -204,8 +204,8 @@ static ssize_t test_block_read_func(QCryptoBlock *block,static ssize_t test_block_init_func (QCryptoBlock *block, -void *opaque,size_t headerlen, +void *opaque,Error **errp) {Buffer *header = opaque;
@@ -219,10 +219,10 @@ static ssize_t test_block_init_func(QCryptoBlock *block,static ssize_t test_block_write_func (QCryptoBlock *block, -void *opaque,size_t offset,const uint8_t *buf,size_t buflen, +void *opaque,Error **errp) {Buffer *header = opaque;
Signature · 1 line
2.9.3
[Qemu-devel] [PULL v1 4/4] crypto: qcrypto_random_bytes() now works on windows w/o any other crypto libs
In reply to Daniel P. BerrangeFrom: Geert Martin Ijewski <[email protected]>
If no crypto library is included in the build, QEMU uses qcrypto_random_bytes() to generate random data. That function tried to open /dev/urandom or /dev/random and if opening both files failed it errored out.
Those files obviously do not exist on windows, so there the code uses CryptGenRandom().
Furthermore there was some refactoring and a new function qcrypto_random_init() was introduced. If a proper crypto library (gnutls or libgcrypt) is included in the build, this function does nothing. If neither is included it initializes the (platform specific) handles that are used by qcrypto_random_bytes().
Either:
* a handle to /dev/urandom | /dev/random on unix like systems
* a handle to a cryptographic service provider on windows
--- crypto/init.c | 6 ++++++ crypto/random-gcrypt.c | 2 ++ crypto/random-gnutls.c | 3 +++ crypto/random-platform.c | 45 +++++++++++++++++++++++++++++++++++++-------- include/crypto/random.h | 9 +++++++++ 5 files changed, 57 insertions(+), 8 deletions(-)
crypto/init.c +6 -0
@@ -32,6 +32,8 @@#include <gcrypt.h> #endif +#include "crypto/random.h" +/* #define DEBUG_GNUTLS */ /*
@@ -146,5 +148,9 @@ int qcrypto_init(Error **errp)gcry_control (GCRYCTL_INITIALIZATION_FINISHED ,0 );#endif +if (qcrypto_random_init (errp) <0 ) { +return -1 ; + } +return 0 ; }
crypto/random-gcrypt.c +2 -0
@@ -31,3 +31,5 @@ int qcrypto_random_bytes(uint8_t *buf,gcry_randomize (buf, buflen,GCRY_STRONG_RANDOM );return 0 ; } + +int qcrypto_random_init(Error **errp G_GNUC_UNUSED) { return 0; }
crypto/random-gnutls.c +3 -0
@@ -41,3 +41,6 @@ int qcrypto_random_bytes(uint8_t *buf,return 0 ; } + + +int qcrypto_random_init(Error **errp G_GNUC_UNUSED) { return 0; }
crypto/random-platform.c +37 -8
63 lines not on this page · raw message
include/crypto/random.h +9 -0
@@ -40,5 +40,14 @@ int qcrypto_random_bytes(uint8_t *buf,size_t buflen, Error **errp); +/** +* qcrypto_random_init: +* @errp: pointer to a NULL-initialized error object +* +* Initializes the handles used by qcrypto_random_bytes +* +* Returns 0 on success, -1 on error +*/ +int qcrypto_random_init (Error **errp);#endif /* QCRYPTO_RANDOM_H */
Signature · 1 line
2.9.3
Stefan Hajnoczi
AppliedQuoted 26 lines · Daniel P. Berrange
The following changes since commit
dd1559bb267becbb838de41132ef60771d183e5d:Merge remote-tracking branch 'elmarco/tags/chr-tests-pull-request' into staging (2017-05-05 17:07:55 +0100)
are available in the git repository at:
git://github.com/berrange/qemutags/pull-qcrypto-2017-05-09-1for you to fetch changes up to
a37278169d0d7d33270c6817f4a2e4f7345e1098:crypto:
qcrypto_random_bytes()now works on windows w/o any other crypto libs (2017-05-09 14:41:47 +0100)----------------------------------------------------------------
Merge qcrypto 2017/05/09 v1----------------------------------------------------------------
Daniel P. Berrange (3):
Default to GSSAPI (Kerberos) instead of DIGEST-MD5 for SASL List SASL config file under the cryptography maintainer's realm
crypto: move 'opaque' parameter to (nearly) the end of parameter listGeert Martin Ijewski (1):
crypto:qcrypto_random_bytes()now works on windows w/o any other
crypto libs
Quoted 18 lines
MAINTAINERS | 1 + block/crypto.c | 6 +++--- crypto/block-luks.c | 13 +++++++----- crypto/init.c | 6 ++++++ crypto/random-gcrypt.c | 2 ++ crypto/random-gnutls.c | 3 +++ crypto/random-platform.c | 45 ++++++++++++++++++++++++++++++++------- include/crypto/block.h | 6 +++--- include/crypto/random.h | 9 ++++++++ qemu-doc.texi | 50 +++++++++++++++++++++++++------------------ qemu.sasl | 54 +++++++++++++++++++++++++++-------------------- tests/test-crypto-block.c | 6 +++--- 12 files changed, 135 insertions(+), 66 deletions(-)Signature · 1 line
2.9.3
Thanks, applied to my staging tree:
https://github.com/stefanha/qemu/commits/staging
Stefan