Skip to content
Snippets Groups Projects
  1. Dec 04, 2015
    • Daniel P. Berrangé's avatar
      crypto: avoid two coverity false positive error reports · 0e1d0245
      Daniel P. Berrangé authored
      
      In qcrypto_tls_creds_get_path() coverity complains that
      we are checking '*creds' for NULL, despite having
      dereferenced it previously. This is harmless bug due
      to fact that the trace call was too early. Moving it
      after the cleanup gets the desired semantics.
      
      In qcrypto_tls_creds_check_cert_key_purpose() coverity
      complains that we're passing a pointer to a previously
      free'd buffer into gnutls_x509_crt_get_key_purpose_oid()
      This is harmless because we're passing a size == 0, so
      gnutls won't access the buffer, but rather just report
      what size it needs to be. We can avoid it though by
      explicitly setting the buffer to NULL after free'ing
      it.
      
      Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Signed-off-by: default avatarMichael Tokarev <mjt@tls.msk.ru>
      0e1d0245
  2. Nov 18, 2015
  3. Oct 22, 2015
    • Daniel P. Berrangé's avatar
      crypto: add sanity checking of plaintext/ciphertext length · 3a661f1e
      Daniel P. Berrangé authored
      
      When encrypting/decrypting data, the plaintext/ciphertext
      buffers are required to be a multiple of the cipher block
      size. If this is not done, nettle will abort and gcrypt
      will report an error. To get consistent behaviour add
      explicit checks upfront for the buffer sizes.
      
      Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
      3a661f1e
    • Daniel P. Berrangé's avatar
      crypto: don't let builtin aes crash if no IV is provided · eb2a770b
      Daniel P. Berrangé authored
      
      If no IV is provided, then use a default IV of all-zeros
      instead of crashing. This gives parity with gcrypt and
      nettle backends.
      
      Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
      eb2a770b
    • Daniel P. Berrangé's avatar
      crypto: allow use of nettle/gcrypt to be selected explicitly · 91bfcdb0
      Daniel P. Berrangé authored
      
      Currently the choice of whether to use nettle or gcrypt is
      made based on what gnutls is linked to. There are times
      when it is desirable to be able to force build against a
      specific library. For example, if testing changes to QEMU's
      crypto code all 3 possible backends need to be checked
      regardless of what the local gnutls uses.
      
      It is also desirable to be able to enable nettle/gcrypt
      for cipher/hash algorithms, without enabling gnutls
      for TLS support.
      
      This gives two new configure flags, which allow the
      following possibilities
      
      Automatically determine nettle vs gcrypt from what
      gnutls links to (recommended to minimize number of
      crypto libraries linked to)
      
       ./configure
      
      Automatically determine nettle vs gcrypt based on
      which is installed
      
       ./configure --disable-gnutls
      
      Force use of nettle
      
       ./configure --enable-nettle
      
      Force use of gcrypt
      
       ./configure --enable-gcrypt
      
      Force use of built-in AES & crippled-DES
      
       ./configure --disable-nettle --disable-gcrypt
      
      Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
      91bfcdb0
  4. 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
    • Daniel P. Berrangé's avatar
      crypto: add sanity checking of TLS x509 credentials · 9a2fd434
      Daniel P. Berrangé authored
      
      If the administrator incorrectly sets up their x509 certificates,
      the errors seen at runtime during connection attempts are very
      obscure and difficult to diagnose. This has been a particular
      problem for people using openssl to generate their certificates
      instead of the gnutls certtool, because the openssl tools don't
      turn on the various x509 extensions that gnutls expects to be
      present by default.
      
      This change thus adds support in the TLS credentials object to
      sanity check the certificates when QEMU first loads them. This
      gives the administrator immediate feedback for the majority of
      common configuration mistakes, reducing the pain involved in
      setting up TLS. The code is derived from equivalent code that
      has been part of libvirt's TLS support and has been seen to be
      valuable in assisting admins.
      
      It is possible to disable the sanity checking, however, via
      the new 'sanity-check' property on the tls-creds object type,
      with a value of 'no'.
      
      Unit tests are included in this change to verify the correctness
      of the sanity checking code in all the key scenarios it is
      intended to cope with. As part of the test suite, the pkix_asn1_tab.c
      from gnutls is imported. This file is intentionally copied from the
      (long since obsolete) gnutls 1.6.3 source tree, since that version
      was still under GPLv2+, rather than the GPLv3+ of gnutls >= 2.0.
      
      Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
      9a2fd434
    • Daniel P. Berrangé's avatar
      crypto: introduce new module for TLS x509 credentials · 85bcbc78
      Daniel P. Berrangé authored
      
      Introduce a QCryptoTLSCredsX509 class which is used to
      manage x509 certificate TLS credentials. This will be
      the preferred credential type offering strong security
      characteristics
      
      Example CLI configuration:
      
       $QEMU -object tls-creds-x509,id=tls0,endpoint=server,\
                     dir=/path/to/creds/dir,verify-peer=yes
      
      The 'id' value in the -object args will be used to associate the
      credentials with the network services. For example, when the VNC
      server is later converted it would use
      
       $QEMU -object tls-creds-x509,id=tls0,.... \
             -vnc 127.0.0.1:1,tls-creds=tls0
      
      Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      85bcbc78
    • Daniel P. Berrangé's avatar
      crypto: introduce new module for TLS anonymous credentials · e00adf6c
      Daniel P. Berrangé authored
      
      Introduce a QCryptoTLSCredsAnon class which is used to
      manage anonymous TLS credentials. Use of this class is
      generally discouraged since it does not offer strong
      security, but it is required for backwards compatibility
      with the current VNC server implementation.
      
      Simple example CLI configuration:
      
       $QEMU -object tls-creds-anon,id=tls0,endpoint=server
      
      Example using pre-created diffie-hellman parameters
      
       $QEMU -object tls-creds-anon,id=tls0,endpoint=server,\
                     dir=/path/to/creds/dir
      
      The 'id' value in the -object args will be used to associate the
      credentials with the network services. For example, when the VNC
      server is later converted it would use
      
       $QEMU -object tls-creds-anon,id=tls0,.... \
             -vnc 127.0.0.1:1,tls-creds=tls0
      
      Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      e00adf6c
    • Daniel P. Berrangé's avatar
      crypto: introduce new base module for TLS credentials · a090187d
      Daniel P. Berrangé authored
      
      Introduce a QCryptoTLSCreds class to act as the base class for
      storing TLS credentials. This will be later subclassed to provide
      handling of anonymous and x509 credential types. The subclasses
      will be user creatable objects, so instances can be created &
      deleted via 'object-add' and 'object-del' QMP commands respectively,
      or via the -object command line arg.
      
      If the credentials cannot be initialized an error will be reported
      as a QMP reply, or on stderr respectively.
      
      The idea is to make it possible to represent and manage TLS
      credentials independently of the network service that is using
      them. This will enable multiple services to use the same set of
      credentials and minimize code duplication. A later patch will
      convert the current VNC server TLS code over to use this object.
      
      The representation of credentials will be functionally equivalent
      to that currently implemented in the VNC server with one exception.
      The new code has the ability to (optionally) load a pre-generated
      set of diffie-hellman parameters, if the file dh-params.pem exists,
      whereas the current VNC server will always generate them on startup.
      This is beneficial for admins who wish to avoid the (small) time
      sink of generating DH parameters at startup and/or avoid depleting
      entropy.
      
      Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
      a090187d
    • Daniel P. Berrangé's avatar
      crypto: move crypto objects out of libqemuutil.la · fb37726d
      Daniel P. Berrangé authored
      
      Future patches will be adding more crypto related APIs which
      rely on QOM infrastructure. This creates a problem, because
      QOM relies on library constructors to register objects. When
      you have a file in a static .a library though which is only
      referenced by a constructor the linker is dumb and will drop
      that file when linking to the final executable :-( The only
      workaround for this is to link the .a library to the executable
      using the -Wl,--whole-archive flag, but this creates its own
      set of problems because QEMU is relying on lazy linking for
      libqemuutil.a. Using --whole-archive majorly increases the
      size of final executables as they now contain a bunch of
      object code they don't actually use.
      
      The least bad option is to thus not include the crypto objects
      in libqemuutil.la, and instead define a crypto-obj-y variable
      that is referenced directly by all the executables that need
      this code (tools + softmmu, but not qemu-ga). We avoid pulling
      entire of crypto-obj-y into the userspace emulators as that
      would force them to link to gnutls too, which is not required.
      
      Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
      fb37726d
  5. Jul 27, 2015
  6. Jul 20, 2015
  7. Jul 16, 2015
    • Radim Krčmář's avatar
      crypto: avoid undefined behavior in nettle calls · d3462e37
      Radim Krčmář authored
      
      Calling a function pointer that was cast from an incompatible function
      results in undefined behavior.  'void *' isn't compatible with 'struct
      XXX *', so we can't cast to nettle_cipher_func, but have to provide a
      wrapper.  (Conversion from 'void *' to 'struct XXX *' might require
      computation, which won't be done if we drop argument's true type, and
      pointers can have different sizes so passing arguments on stack would
      bug.)
      
      Having two different prototypes based on nettle version doesn't make
      this solution any nicer.
      
      Reported-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Signed-off-by: default avatarRadim Krčmář <rkrcmar@redhat.com>
      Message-Id: <1437062641-12684-3-git-send-email-rkrcmar@redhat.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      d3462e37
    • Radim Krčmář's avatar
      crypto: fix build with nettle >= 3.0.0 · becaeb72
      Radim Krčmář authored
      
      In nettle 3, cbc_encrypt() accepts 'nettle_cipher_func' instead of
      'nettle_crypt_func' and these two differ in 'const' qualifier of the
      first argument.  The build fails with:
      
        In file included from crypto/cipher.c:71:0:
        ./crypto/cipher-nettle.c: In function ‘qcrypto_cipher_encrypt’:
        ./crypto/cipher-nettle.c:154:38: error: passing argument 2 of
        ‘nettle_cbc_encrypt’ from incompatible pointer type
                 cbc_encrypt(ctx->ctx_encrypt, ctx->alg_encrypt,
                                                     ^
        In file included from ./crypto/cipher-nettle.c:24:0,
                         from crypto/cipher.c:71:
        /usr/include/nettle/cbc.h:48:1: note: expected
        ‘void (*)(const void *, size_t, uint8_t *, const uint8_t *)
        but argument is of type
        ‘void (*)(      void *, size_t, uint8_t *, const uint8_t *)
      
      To allow both versions, we switch to the new definition and #if typedef
      it for old versions.
      
      Signed-off-by: default avatarRadim Krčmář <rkrcmar@redhat.com>
      Message-Id: <1436548682-9315-2-git-send-email-rkrcmar@redhat.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      becaeb72
  8. Jul 09, 2015
  9. Jul 08, 2015
  10. Jul 07, 2015
Loading