diff options
-rw-r--r-- | block/nbd.c | 6 | ||||
-rw-r--r-- | blockdev-nbd.c | 6 | ||||
-rw-r--r-- | chardev/char-socket.c | 18 | ||||
-rw-r--r-- | crypto/tls-cipher-suites.c | 7 | ||||
-rw-r--r-- | crypto/tlscreds.c | 12 | ||||
-rw-r--r-- | crypto/tlscredsanon.c | 2 | ||||
-rw-r--r-- | crypto/tlscredspriv.h | 45 | ||||
-rw-r--r-- | crypto/tlscredspsk.c | 2 | ||||
-rw-r--r-- | crypto/tlscredsx509.c | 1 | ||||
-rw-r--r-- | crypto/tlssession.c | 1 | ||||
-rw-r--r-- | include/crypto/tls-cipher-suites.h | 6 | ||||
-rw-r--r-- | include/crypto/tlscreds.h | 30 | ||||
-rw-r--r-- | include/crypto/tlscredsanon.h | 12 | ||||
-rw-r--r-- | include/crypto/tlscredspsk.h | 12 | ||||
-rw-r--r-- | include/crypto/tlscredsx509.h | 10 | ||||
-rw-r--r-- | migration/tls.c | 6 | ||||
-rw-r--r-- | qemu-nbd.c | 19 | ||||
-rw-r--r-- | ui/vnc.c | 7 |
18 files changed, 108 insertions, 94 deletions
diff --git a/block/nbd.c b/block/nbd.c index 3cbee76..601fccc 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -1839,9 +1839,9 @@ static QCryptoTLSCreds *nbd_get_tls_creds(const char *id, Error **errp) return NULL; } - if (creds->endpoint != QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT) { - error_setg(errp, - "Expecting TLS credentials with a client endpoint"); + if (!qcrypto_tls_creds_check_endpoint(creds, + QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT, + errp)) { return NULL; } object_ref(obj); diff --git a/blockdev-nbd.c b/blockdev-nbd.c index b264620..bdfa7ed 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -108,9 +108,9 @@ static QCryptoTLSCreds *nbd_get_tls_creds(const char *id, Error **errp) return NULL; } - if (creds->endpoint != QCRYPTO_TLS_CREDS_ENDPOINT_SERVER) { - error_setg(errp, - "Expecting TLS credentials with a server endpoint"); + if (!qcrypto_tls_creds_check_endpoint(creds, + QCRYPTO_TLS_CREDS_ENDPOINT_SERVER, + errp)) { return NULL; } object_ref(obj); diff --git a/chardev/char-socket.c b/chardev/char-socket.c index daa89fe..d0fb545 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -1402,18 +1402,12 @@ static void qmp_chardev_open_socket(Chardev *chr, return; } object_ref(OBJECT(s->tls_creds)); - if (is_listen) { - if (s->tls_creds->endpoint != QCRYPTO_TLS_CREDS_ENDPOINT_SERVER) { - error_setg(errp, "%s", - "Expected TLS credentials for server endpoint"); - return; - } - } else { - if (s->tls_creds->endpoint != QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT) { - error_setg(errp, "%s", - "Expected TLS credentials for client endpoint"); - return; - } + if (!qcrypto_tls_creds_check_endpoint(s->tls_creds, + is_listen + ? QCRYPTO_TLS_CREDS_ENDPOINT_SERVER + : QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT, + errp)) { + return; } } s->tls_authz = g_strdup(sock->tls_authz); diff --git a/crypto/tls-cipher-suites.c b/crypto/tls-cipher-suites.c index 55fb5f7..5e4f597 100644 --- a/crypto/tls-cipher-suites.c +++ b/crypto/tls-cipher-suites.c @@ -14,8 +14,15 @@ #include "crypto/tlscreds.h" #include "crypto/tls-cipher-suites.h" #include "hw/nvram/fw_cfg.h" +#include "tlscredspriv.h" #include "trace.h" +struct QCryptoTLSCipherSuites { + /* <private> */ + QCryptoTLSCreds parent_obj; + /* <public> */ +}; + /* * IANA registered TLS ciphers: * https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-4 diff --git a/crypto/tlscreds.c b/crypto/tlscreds.c index b68735f..084ce0d 100644 --- a/crypto/tlscreds.c +++ b/crypto/tlscreds.c @@ -20,6 +20,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" +#include "qapi-types-crypto.h" #include "qemu/module.h" #include "tlscredspriv.h" #include "trace.h" @@ -259,6 +260,17 @@ qcrypto_tls_creds_finalize(Object *obj) g_free(creds->priority); } +bool qcrypto_tls_creds_check_endpoint(QCryptoTLSCreds *creds, + QCryptoTLSCredsEndpoint endpoint, + Error **errp) +{ + if (creds->endpoint != endpoint) { + error_setg(errp, "Expected TLS credentials for a %s endpoint", + QCryptoTLSCredsEndpoint_str(endpoint)); + return false; + } + return true; +} static const TypeInfo qcrypto_tls_creds_info = { .parent = TYPE_OBJECT, diff --git a/crypto/tlscredsanon.c b/crypto/tlscredsanon.c index bea5f76..6fb8363 100644 --- a/crypto/tlscredsanon.c +++ b/crypto/tlscredsanon.c @@ -29,6 +29,8 @@ #ifdef CONFIG_GNUTLS +#include <gnutls/gnutls.h> + static int qcrypto_tls_creds_anon_load(QCryptoTLSCredsAnon *creds, diff --git a/crypto/tlscredspriv.h b/crypto/tlscredspriv.h index 39f1a91..df9815a 100644 --- a/crypto/tlscredspriv.h +++ b/crypto/tlscredspriv.h @@ -24,6 +24,51 @@ #include "crypto/tlscreds.h" #ifdef CONFIG_GNUTLS +#include <gnutls/gnutls.h> +#endif + +struct QCryptoTLSCreds { + Object parent_obj; + char *dir; + QCryptoTLSCredsEndpoint endpoint; +#ifdef CONFIG_GNUTLS + gnutls_dh_params_t dh_params; +#endif + bool verifyPeer; + char *priority; +}; + +struct QCryptoTLSCredsAnon { + QCryptoTLSCreds parent_obj; +#ifdef CONFIG_GNUTLS + union { + gnutls_anon_server_credentials_t server; + gnutls_anon_client_credentials_t client; + } data; +#endif +}; + +struct QCryptoTLSCredsPSK { + QCryptoTLSCreds parent_obj; + char *username; +#ifdef CONFIG_GNUTLS + union { + gnutls_psk_server_credentials_t server; + gnutls_psk_client_credentials_t client; + } data; +#endif +}; + +struct QCryptoTLSCredsX509 { + QCryptoTLSCreds parent_obj; +#ifdef CONFIG_GNUTLS + gnutls_certificate_credentials_t data; +#endif + bool sanityCheck; + char *passwordid; +}; + +#ifdef CONFIG_GNUTLS int qcrypto_tls_creds_get_path(QCryptoTLSCreds *creds, const char *filename, diff --git a/crypto/tlscredspsk.c b/crypto/tlscredspsk.c index f5a3110..752f2d9 100644 --- a/crypto/tlscredspsk.c +++ b/crypto/tlscredspsk.c @@ -29,6 +29,8 @@ #ifdef CONFIG_GNUTLS +#include <gnutls/gnutls.h> + static int lookup_key(const char *pskfile, const char *username, gnutls_datum_t *key, Error **errp) diff --git a/crypto/tlscredsx509.c b/crypto/tlscredsx509.c index d9d6f44..32948a6 100644 --- a/crypto/tlscredsx509.c +++ b/crypto/tlscredsx509.c @@ -30,6 +30,7 @@ #ifdef CONFIG_GNUTLS +#include <gnutls/gnutls.h> #include <gnutls/x509.h> diff --git a/crypto/tlssession.c b/crypto/tlssession.c index 33203e8..a8db8c7 100644 --- a/crypto/tlssession.c +++ b/crypto/tlssession.c @@ -25,6 +25,7 @@ #include "crypto/tlscredsx509.h" #include "qapi/error.h" #include "authz/base.h" +#include "tlscredspriv.h" #include "trace.h" #ifdef CONFIG_GNUTLS diff --git a/include/crypto/tls-cipher-suites.h b/include/crypto/tls-cipher-suites.h index bb9ee53..7eb1b76 100644 --- a/include/crypto/tls-cipher-suites.h +++ b/include/crypto/tls-cipher-suites.h @@ -19,12 +19,6 @@ typedef struct QCryptoTLSCipherSuites QCryptoTLSCipherSuites; DECLARE_INSTANCE_CHECKER(QCryptoTLSCipherSuites, QCRYPTO_TLS_CIPHER_SUITES, TYPE_QCRYPTO_TLS_CIPHER_SUITES) -struct QCryptoTLSCipherSuites { - /* <private> */ - QCryptoTLSCreds parent_obj; - /* <public> */ -}; - /** * qcrypto_tls_cipher_suites_get_data: * @obj: pointer to a TLS cipher suites object diff --git a/include/crypto/tlscreds.h b/include/crypto/tlscreds.h index d0808e3..2a8a857 100644 --- a/include/crypto/tlscreds.h +++ b/include/crypto/tlscreds.h @@ -24,10 +24,6 @@ #include "qapi/qapi-types-crypto.h" #include "qom/object.h" -#ifdef CONFIG_GNUTLS -#include <gnutls/gnutls.h> -#endif - #define TYPE_QCRYPTO_TLS_CREDS "tls-creds" typedef struct QCryptoTLSCreds QCryptoTLSCreds; typedef struct QCryptoTLSCredsClass QCryptoTLSCredsClass; @@ -48,22 +44,24 @@ typedef bool (*CryptoTLSCredsReload)(QCryptoTLSCreds *, Error **); * certificate credentials. */ -struct QCryptoTLSCreds { - Object parent_obj; - char *dir; - QCryptoTLSCredsEndpoint endpoint; -#ifdef CONFIG_GNUTLS - gnutls_dh_params_t dh_params; -#endif - bool verifyPeer; - char *priority; -}; - - struct QCryptoTLSCredsClass { ObjectClass parent_class; CryptoTLSCredsReload reload; }; +/** + * qcrypto_tls_creds_check_endpoint: + * @creds: pointer to a TLS credentials object + * @endpoint: type of network endpoint that will be using the credentials + * @errp: pointer to a NULL-initialized error object + * + * Check whether the credentials is setup according to + * the type of @endpoint argument. + * + * Returns true if the credentials is setup for the endpoint, false otherwise + */ +bool qcrypto_tls_creds_check_endpoint(QCryptoTLSCreds *creds, + QCryptoTLSCredsEndpoint endpoint, + Error **errp); #endif /* QCRYPTO_TLSCREDS_H */ diff --git a/include/crypto/tlscredsanon.h b/include/crypto/tlscredsanon.h index 3f464a3..bd3023f 100644 --- a/include/crypto/tlscredsanon.h +++ b/include/crypto/tlscredsanon.h @@ -92,18 +92,6 @@ typedef struct QCryptoTLSCredsAnonClass QCryptoTLSCredsAnonClass; * */ - -struct QCryptoTLSCredsAnon { - QCryptoTLSCreds parent_obj; -#ifdef CONFIG_GNUTLS - union { - gnutls_anon_server_credentials_t server; - gnutls_anon_client_credentials_t client; - } data; -#endif -}; - - struct QCryptoTLSCredsAnonClass { QCryptoTLSCredsClass parent_class; }; diff --git a/include/crypto/tlscredspsk.h b/include/crypto/tlscredspsk.h index d7e6bdb..bcd07dc 100644 --- a/include/crypto/tlscredspsk.h +++ b/include/crypto/tlscredspsk.h @@ -87,18 +87,6 @@ typedef struct QCryptoTLSCredsPSKClass QCryptoTLSCredsPSKClass; * The PSK file can be created and managed using psktool. */ -struct QCryptoTLSCredsPSK { - QCryptoTLSCreds parent_obj; - char *username; -#ifdef CONFIG_GNUTLS - union { - gnutls_psk_server_credentials_t server; - gnutls_psk_client_credentials_t client; - } data; -#endif -}; - - struct QCryptoTLSCredsPSKClass { QCryptoTLSCredsClass parent_class; }; diff --git a/include/crypto/tlscredsx509.h b/include/crypto/tlscredsx509.h index c6d89b7..c4daba2 100644 --- a/include/crypto/tlscredsx509.h +++ b/include/crypto/tlscredsx509.h @@ -96,16 +96,6 @@ typedef struct QCryptoTLSCredsX509Class QCryptoTLSCredsX509Class; * */ -struct QCryptoTLSCredsX509 { - QCryptoTLSCreds parent_obj; -#ifdef CONFIG_GNUTLS - gnutls_certificate_credentials_t data; -#endif - bool sanityCheck; - char *passwordid; -}; - - struct QCryptoTLSCredsX509Class { QCryptoTLSCredsClass parent_class; }; diff --git a/migration/tls.c b/migration/tls.c index abb149d..ca1ea3b 100644 --- a/migration/tls.c +++ b/migration/tls.c @@ -49,11 +49,7 @@ migration_tls_get_creds(MigrationState *s, s->parameters.tls_creds); return NULL; } - if (ret->endpoint != endpoint) { - error_setg(errp, - "Expected TLS credentials for a %s endpoint", - endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT ? - "client" : "server"); + if (!qcrypto_tls_creds_check_endpoint(ret, endpoint, errp)) { return NULL; } @@ -43,6 +43,7 @@ #include "io/channel-socket.h" #include "io/net-listener.h" #include "crypto/init.h" +#include "crypto/tlscreds.h" #include "trace/control.h" #include "qemu-version.h" @@ -422,18 +423,12 @@ static QCryptoTLSCreds *nbd_get_tls_creds(const char *id, bool list, return NULL; } - if (list) { - if (creds->endpoint != QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT) { - error_setg(errp, - "Expecting TLS credentials with a client endpoint"); - return NULL; - } - } else { - if (creds->endpoint != QCRYPTO_TLS_CREDS_ENDPOINT_SERVER) { - error_setg(errp, - "Expecting TLS credentials with a server endpoint"); - return NULL; - } + if (!qcrypto_tls_creds_check_endpoint(creds, + list + ? QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT + : QCRYPTO_TLS_CREDS_ENDPOINT_SERVER, + errp)) { + return NULL; } object_ref(obj); return creds; @@ -46,6 +46,7 @@ #include "qapi/qapi-commands-ui.h" #include "ui/input.h" #include "crypto/hash.h" +#include "crypto/tlscreds.h" #include "crypto/tlscredsanon.h" #include "crypto/tlscredsx509.h" #include "crypto/random.h" @@ -4080,9 +4081,9 @@ void vnc_display_open(const char *id, Error **errp) } object_ref(OBJECT(vd->tlscreds)); - if (vd->tlscreds->endpoint != QCRYPTO_TLS_CREDS_ENDPOINT_SERVER) { - error_setg(errp, - "Expecting TLS credentials with a server endpoint"); + if (!qcrypto_tls_creds_check_endpoint(vd->tlscreds, + QCRYPTO_TLS_CREDS_ENDPOINT_SERVER, + errp)) { goto fail; } } |