Skip to content
Snippets Groups Projects
  1. Jun 29, 2021
    • Philippe Mathieu-Daudé's avatar
      crypto: Make QCryptoTLSCreds* structures private · 678bcc3c
      Philippe Mathieu-Daudé authored
      
      Code consuming the "crypto/tlscreds*.h" APIs doesn't need
      to access its internals. Move the structure definitions to
      the "tlscredspriv.h" private header (only accessible by
      implementations). The public headers (in include/) still
      forward-declare the structures typedef.
      
      Note, tlscreds.c and 3 of the 5 modified source files already
      include "tlscredspriv.h", so only add it to tls-cipher-suites.c
      and tlssession.c.
      
      Removing the internals from the public header solves a bug
      introduced by commit 7de2e856 ("yank: Unregister function
      when using TLS migration") which made migration/qemu-file-channel.c
      include "io/channel-tls.h", itself sometime depends on GNUTLS,
      leading to a build failure on OSX:
      
        [2/35] Compiling C object libmigration.fa.p/migration_qemu-file-channel.c.o
        FAILED: libmigration.fa.p/migration_qemu-file-channel.c.o
        cc -Ilibmigration.fa.p -I. -I.. -Iqapi [ ... ] -o libmigration.fa.p/migration_qemu-file-channel.c.o -c ../migration/qemu-file-channel.c
        In file included from ../migration/qemu-file-channel.c:29:
        In file included from include/io/channel-tls.h:26:
        In file included from include/crypto/tlssession.h:24:
        include/crypto/tlscreds.h:28:10: fatal error: 'gnutls/gnutls.h' file not found
        #include <gnutls/gnutls.h>
                 ^~~~~~~~~~~~~~~~~
        1 error generated.
      
      Reported-by: default avatarStefan Weil <sw@weilnetz.de>
      Suggested-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
      Resolves: https://gitlab.com/qemu-project/qemu/-/issues/407
      
      
      Fixes: 7de2e856 ("yank: Unregister function when using TLS migration")
      Signed-off-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Signed-off-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
      678bcc3c
  2. Jul 19, 2019
  3. Feb 26, 2019
  4. Nov 19, 2018
    • Daniel P. Berrangé's avatar
      io: return 0 for EOF in TLS session read after shutdown · a2458b6f
      Daniel P. Berrangé authored
      
      GNUTLS takes a paranoid approach when seeing 0 bytes returned by the
      underlying OS read() function. It will consider this an error and
      return GNUTLS_E_PREMATURE_TERMINATION instead of propagating the 0
      return value. It expects apps to arrange for clean termination at
      the protocol level and not rely on seeing EOF from a read call to
      detect shutdown. This is to harden apps against a malicious 3rd party
      causing termination of the sockets layer.
      
      This is unhelpful for the QEMU NBD code which does have a clean
      protocol level shutdown, but still relies on seeing 0 from the I/O
      channel read in the coroutine handling incoming replies.
      
      The upshot is that when using a plain NBD connection shutdown is
      silent, but when using TLS, the client spams the console with
      
        Cannot read from TLS channel: Broken pipe
      
      The NBD connection has, however, called qio_channel_shutdown()
      at this point to indicate that it is done with I/O. This gives
      the opportunity to optimize the code such that when the channel
      has been shutdown in the read direction, the error code
      GNUTLS_E_PREMATURE_TERMINATION gets turned into a '0' return
      instead of an error.
      
      Signed-off-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
      Message-Id: <20181119134228.11031-1-berrange@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      a2458b6f
  5. Oct 19, 2018
  6. Jul 03, 2018
    • Richard W.M. Jones's avatar
      crypto: Implement TLS Pre-Shared Keys (PSK). · e1a6dc91
      Richard W.M. Jones authored
      
      Pre-Shared Keys (PSK) is a simpler mechanism for enabling TLS
      connections than using certificates.  It requires only a simple secret
      key:
      
        $ mkdir -m 0700 /tmp/keys
        $ psktool -u rjones -p /tmp/keys/keys.psk
        $ cat /tmp/keys/keys.psk
        rjones:d543770c15ad93d76443fb56f501a31969235f47e999720ae8d2336f6a13fcbc
      
      The key can be secretly shared between clients and servers.  Clients
      must specify the directory containing the "keys.psk" file and a
      username (defaults to "qemu").  Servers must specify only the
      directory.
      
      Example NBD client:
      
        $ qemu-img info \
          --object tls-creds-psk,id=tls0,dir=/tmp/keys,username=rjones,endpoint=client \
          --image-opts \
          file.driver=nbd,file.host=localhost,file.port=10809,file.tls-creds=tls0,file.export=/
      
      Example NBD server using qemu-nbd:
      
        $ qemu-nbd -t -x / \
          --object tls-creds-psk,id=tls0,endpoint=server,dir=/tmp/keys \
          --tls-creds tls0 \
          image.qcow2
      
      Example NBD server using nbdkit:
      
        $ nbdkit -n -e / -fv \
          --tls=on --tls-psk=/tmp/keys/keys.psk \
          file file=disk.img
      
      Signed-off-by: default avatarRichard W.M. Jones <rjones@redhat.com>
      Signed-off-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
      e1a6dc91
  7. Sep 19, 2016
  8. Jul 04, 2016
    • Daniel P. Berrangé's avatar
      crypto: allow default TLS priority to be chosen at build time · a1c5e949
      Daniel P. Berrangé authored
      
      Modern gnutls can use a global config file to control the
      crypto priority settings for TLS connections. For example
      the priority string "@SYSTEM" instructs gnutls to find the
      priority setting named "SYSTEM" in the global config file.
      
      Latest gnutls GIT codebase gained the ability to reference
      multiple priority strings in the config file, with the first
      one that is found to existing winning. This means it is now
      possible to configure QEMU out of the box with a default
      priority of "@QEMU,SYSTEM", which says to look for the
      settings "QEMU" first, and if not found, use the "SYSTEM"
      settings.
      
      To make use of this facility, we introduce the ability to
      set the QEMU default priority at build time via a new
      configure argument.  It is anticipated that distro vendors
      will set this when building QEMU to a suitable value for
      use with distro crypto policy setup. eg current Fedora
      would run
      
       ./configure --tls-priority=@SYSTEM
      
      while future Fedora would run
      
       ./configure --tls-priority=@QEMU,SYSTEM
      
      Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
      a1c5e949
    • Daniel P. Berrangé's avatar
      crypto: add support for TLS priority string override · 13f12430
      Daniel P. Berrangé authored
      
      The gnutls default priority is either "NORMAL" (most historical
      versions of gnutls) which is a built-in label in gnutls code,
      or "@SYSTEM" (latest gnutls on Fedora at least) which refers
      to an admin customizable entry in a gnutls config file.
      
      Regardless of which default is used by a distro, they are both
      global defaults applying to all applications using gnutls. If
      a single application on the system needs to use a weaker set
      of crypto priorities, this potentially forces the weakness onto
      all applications. Or conversely if a single application wants a
      strong default than all others, it can't do this via the global
      config file.
      
      This adds an extra parameter to the tls credential object which
      allows the mgmt app / user to explicitly provide a priority
      string to QEMU when configuring TLS.
      
      For example, to use the "NORMAL" priority, but disable SSL 3.0
      one can now configure QEMU thus:
      
        $QEMU -object tls-creds-x509,id=tls0,dir=/home/berrange/qemutls,\
                      priority="NORMAL:-VERS-SSL3.0" \
              ..other args...
      
      If creating tls-creds-anon, whatever priority the user specifies
      will always have "+ANON-DH" appended to it, since that's mandatory
      to make the anonymous credentials work.
      
      Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
      13f12430
  9. Mar 22, 2016
    • Markus Armbruster's avatar
      include/qemu/osdep.h: Don't include qapi/error.h · da34e65c
      Markus Armbruster authored
      
      Commit 57cb38b3 included qapi/error.h into qemu/osdep.h to get the
      Error typedef.  Since then, we've moved to include qemu/osdep.h
      everywhere.  Its file comment explains: "To avoid getting into
      possible circular include dependencies, this file should not include
      any other QEMU headers, with the exceptions of config-host.h,
      compiler.h, os-posix.h and os-win32.h, all of which are doing a
      similar job to this file and are under similar constraints."
      qapi/error.h doesn't do a similar job, and it doesn't adhere to
      similar constraints: it includes qapi-types.h.  That's in excess of
      100KiB of crap most .c files don't actually need.
      
      Add the typedef to qemu/typedefs.h, and include that instead of
      qapi/error.h.  Include qapi/error.h in .c files that need it and don't
      get it now.  Include qapi-types.h in qom/object.h for uint16List.
      
      Update scripts/clean-includes accordingly.  Update it further to match
      reality: replace config.h by config-target.h, add sysemu/os-posix.h,
      sysemu/os-win32.h.  Update the list of includes in the qemu/osdep.h
      comment quoted above similarly.
      
      This reduces the number of objects depending on qapi/error.h from "all
      of them" to less than a third.  Unfortunately, the number depending on
      qapi-types.h shrinks only a little.  More work is needed for that one.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      [Fix compilation without the spice devel packages. - Paolo]
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      da34e65c
  10. Jan 29, 2016
  11. Nov 18, 2015
  12. Sep 15, 2015
    • Daniel P. Berrangé's avatar
      crypto: introduce new module for handling TLS sessions · d321e1e5
      Daniel P. Berrangé authored
      
      Introduce a QCryptoTLSSession object that will encapsulate
      all the code for setting up and using a client/sever TLS
      session. This isolates the code which depends on the gnutls
      library, avoiding #ifdefs in the rest of the codebase, as
      well as facilitating any possible future port to other TLS
      libraries, if desired. It makes use of the previously
      defined QCryptoTLSCreds object to access credentials to
      use with the session. It also includes further unit tests
      to validate the correctness of the TLS session handshake
      and certificate validation. This is functionally equivalent
      to the current TLS session handling code embedded in the
      VNC server, and will obsolete it.
      
      Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
      d321e1e5
Loading