Skip to contentSkip to conversation

crypto: Make QCryptoTLSCreds* structures private

PATCH Superseded Philippe Mathieu-Daudé 2 participants 12 messages Jun 15, 2021

Subsystems (2)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 cover crypto: Make QCryptoTLSCreds* structures private

Follow Daniel suggestion to simplify qcrypto TLS implementations, aiming to solve the OSX build failure.

Supersedes: <[email protected]>

Philippe Mathieu-Daudé (7):
crypto/tlscreds: Introduce qcrypto_tls_creds_check_endpoint() helper block/nbd: Use qcrypto_tls_creds_check_endpoint() chardev/socket: Use qcrypto_tls_creds_check_endpoint() migration/tls: Use qcrypto_tls_creds_check_endpoint() crypto/tlssession: Introduce qcrypto_tls_creds_check_endpoint() helper ui/vnc: Use qcrypto_tls_session_check_role()
crypto: Make QCryptoTLSCreds* structures private

 crypto/tlscredspriv.h         | 15 +++++++++++++++
 include/crypto/tlscreds.h     | 28 ++++++++++++----------------
 include/crypto/tlscredsanon.h | 12 ------------
 include/crypto/tlscredspsk.h  | 12 ------------
 include/crypto/tlscredsx509.h | 10 ----------
 include/crypto/tlssession.h   | 13 +++++++++++++
 block/nbd.c                   |  3 ++-
 blockdev-nbd.c                |  3 ++-
 chardev/char-socket.c         |  6 ++++--
 crypto/tlscreds.c             |  5 +++++
 crypto/tlscredsanon.c         | 13 +++++++++++++
 crypto/tlscredspsk.c          | 14 ++++++++++++++
 crypto/tlscredsx509.c         | 16 +++++++++++++---
 crypto/tlssession.c           |  6 ++++++
 migration/tls.c               |  2 +-
 ui/vnc.c                      |  3 ++-
 16 files changed, 102 insertions(+), 59 deletions(-)
Signature · 1 line
2.31.1
#2 lore raw

PATCH v2 2/7 block/nbd: Use qcrypto_tls_creds_check_endpoint()

Avoid accessing QCryptoTLSCreds internals by using the qcrypto_tls_creds_check_endpoint() helper.

---
 block/nbd.c    | 3 ++-
 blockdev-nbd.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
block/nbd.c +2 -1
index 616f9ae6c4d..c3523ebf785 100644
@@ -2159,7 +2159,8 @@ static QCryptoTLSCreds *nbd_get_tls_creds(const char *id, Error **errp)
         return NULL;
     }
 
-    if (creds->endpoint != QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT) {
+    if (!qcrypto_tls_creds_check_endpoint(creds,
+                                          QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT)) {
         error_setg(errp,
                    "Expecting TLS credentials with a client endpoint");
         return NULL;
blockdev-nbd.c +2 -1
index b264620b98d..b6023052ac7 100644
@@ -108,7 +108,8 @@ static QCryptoTLSCreds *nbd_get_tls_creds(const char *id, Error **errp)
         return NULL;
     }
 
-    if (creds->endpoint != QCRYPTO_TLS_CREDS_ENDPOINT_SERVER) {
+    if (!qcrypto_tls_creds_check_endpoint(creds,
+                                          QCRYPTO_TLS_CREDS_ENDPOINT_SERVER)) {
         error_setg(errp,
                    "Expecting TLS credentials with a server endpoint");
         return NULL;
Signature · 1 line
2.31.1
#5 lore raw

PATCH v2 4/7 migration/tls: Use qcrypto_tls_creds_check_endpoint()

In reply to Philippe Mathieu-Daudé

Avoid accessing QCryptoTLSCreds internals by using the qcrypto_tls_creds_check_endpoint() helper.

---
 migration/tls.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
migration/tls.c +1 -1
index abb149d8325..ee49ecba484 100644
@@ -49,7 +49,7 @@ migration_tls_get_creds(MigrationState *s,
                    s->parameters.tls_creds);
         return NULL;
     }
-    if (ret->endpoint != endpoint) {
+    if (!qcrypto_tls_creds_check_endpoint(ret, endpoint)) {
         error_setg(errp,
                    "Expected TLS credentials for a %s endpoint",
                    endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT ?
Signature · 1 line
2.31.1
#6 lore raw

PATCH v2 5/7 crypto/tlssession: Introduce qcrypto_tls_creds_check_endpoint() helper

In reply to Philippe Mathieu-Daudé

Introduce the qcrypto_tls_creds_check_endpoint() helper to avoid accessing QCryptoTLSCreds internal 'endpoint' field directly.

---
 include/crypto/tlssession.h | 13 +++++++++++++
 crypto/tlssession.c         |  6 ++++++
 2 files changed, 19 insertions(+)
include/crypto/tlssession.h +13 -0
index 15b9cef086c..fdf7578609c 100644
@@ -162,6 +162,19 @@ void qcrypto_tls_session_free(QCryptoTLSSession *sess);
 
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(QCryptoTLSSession, qcrypto_tls_session_free)
 
+/**
+ * qcrypto_tls_session_check_role:
+ * @creds: pointer to a TLS credentials object
+ * @endpoint: role of the TLS session, client or server
+ *
+ * Check whether the session object operates according to
+ * the role of the @endpoint argument.
+ *
+ * Returns true if the session is setup for the endpoint role, false otherwise
+ */
+bool qcrypto_tls_session_check_role(QCryptoTLSCreds *creds,
+                                    QCryptoTLSCredsEndpoint endpoint);
+
 /**
  * qcrypto_tls_session_check_credentials:
  * @sess: the TLS session object
crypto/tlssession.c +6 -0
index 33203e8ca71..cf2781363fe 100644
@@ -640,3 +640,9 @@ qcrypto_tls_session_get_peer_name(QCryptoTLSSession *sess)
 }
 
 #endif
+
+bool qcrypto_tls_session_check_role(QCryptoTLSCreds *creds,
+                                    QCryptoTLSCredsEndpoint endpoint)
+{
+    return qcrypto_tls_creds_check_endpoint(creds, endpoint);
+}
Signature · 1 line
2.31.1
#1 lore raw

PATCH v2 1/7 crypto/tlscreds: Introduce qcrypto_tls_creds_check_endpoint() helper

In reply to Philippe Mathieu-Daudé

Introduce the qcrypto_tls_creds_check_endpoint() helper to access QCryptoTLSCreds internal 'endpoint' field.

---
 include/crypto/tlscreds.h | 12 ++++++++++++
 crypto/tlscreds.c         |  5 +++++
 2 files changed, 17 insertions(+)
include/crypto/tlscreds.h +12 -0
index d0808e391e9..eb9d5e75a84 100644
@@ -65,5 +65,17 @@ struct QCryptoTLSCredsClass {
     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
+ *
+ * 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);
 
 #endif /* QCRYPTO_TLSCREDS_H */
crypto/tlscreds.c +5 -0
index b68735f06fe..f9f45e12db1 100644
@@ -259,6 +259,11 @@ qcrypto_tls_creds_finalize(Object *obj)
     g_free(creds->priority);
 }
 
+bool qcrypto_tls_creds_check_endpoint(QCryptoTLSCreds *creds,
+                                      QCryptoTLSCredsEndpoint endpoint)
+{
+    return creds->endpoint == endpoint;
+}
 
 static const TypeInfo qcrypto_tls_creds_info = {
     .parent = TYPE_OBJECT,
Signature · 1 line
2.31.1
#7 lore raw

PATCH v2 6/7 ui/vnc: Use qcrypto_tls_session_check_role()

In reply to Philippe Mathieu-Daudé

Avoid accessing QCryptoTLSCreds internals by using the qcrypto_tls_session_check_role() helper.

---
 ui/vnc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
ui/vnc.c +2 -1
index b3d4d7b9a5f..ad68f9b639f 100644
@@ -4080,7 +4080,8 @@ void vnc_display_open(const char *id, Error **errp)
         }
         object_ref(OBJECT(vd->tlscreds));
 
-        if (vd->tlscreds->endpoint != QCRYPTO_TLS_CREDS_ENDPOINT_SERVER) {
+        if (!qcrypto_tls_session_check_role(vd->tlscreds,
+                                            QCRYPTO_TLS_CREDS_ENDPOINT_SERVER)) {
             error_setg(errp,
                        "Expecting TLS credentials with a server endpoint");
             goto fail;
Signature · 1 line
2.31.1
#8 lore raw

PATCH v2 7/7 crypto: Make QCryptoTLSCreds* structures private

In reply to Philippe Mathieu-Daudé

Code consuming the "crypto/tlscreds*.h" APIs doesn't need to access its internals. Move the structure definitions to the implementations in crypto/. The headers still forward declare the structures typedef.

This solves a bug introduced by commit 7de2e856533 which made migration/qemu-file-channel.c include "io/channel-tls.h", itself sometime depends on GNUTLS, leading to 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.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/407

Fixes 7de2e856533 ("yank: Unregister function when using TLS migration")
---
 crypto/tlscredspriv.h         | 15 +++++++++++++++
 include/crypto/tlscreds.h     | 16 ----------------
 include/crypto/tlscredsanon.h | 12 ------------
 include/crypto/tlscredspsk.h  | 12 ------------
 include/crypto/tlscredsx509.h | 10 ----------
 crypto/tlscredsanon.c         | 13 +++++++++++++
 crypto/tlscredspsk.c          | 14 ++++++++++++++
 crypto/tlscredsx509.c         | 16 +++++++++++++---
 8 files changed, 55 insertions(+), 53 deletions(-)
crypto/tlscredspriv.h +15 -0
index 39f1a91c413..67e76c24539 100644
@@ -23,6 +23,21 @@
 
 #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;
+};
+
 #ifdef CONFIG_GNUTLS
 
 int qcrypto_tls_creds_get_path(QCryptoTLSCreds *creds,
include/crypto/tlscreds.h +0 -16
index eb9d5e75a84..bb3f2e4f303 100644
@@ -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,18 +44,6 @@ 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;
include/crypto/tlscredsanon.h +0 -12
index 3f464a38095..bd3023f9ea7 100644
@@ -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;
 };
include/crypto/tlscredspsk.h +0 -12
index d7e6bdb5edf..bcd07dc4f62 100644
@@ -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;
 };
include/crypto/tlscredsx509.h +0 -10
index c6d89b78819..c4daba21a6b 100644
@@ -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;
 };
crypto/tlscredsanon.c +13 -0
index bea5f76c55d..e7f74061ae2 100644
@@ -26,6 +26,19 @@
 #include "qom/object_interfaces.h"
 #include "trace.h"
 
+#ifdef CONFIG_GNUTLS
+#include <gnutls/gnutls.h>
+#endif
+
+struct QCryptoTLSCredsAnon {
+    QCryptoTLSCreds parent_obj;
+#ifdef CONFIG_GNUTLS
+    union {
+        gnutls_anon_server_credentials_t server;
+        gnutls_anon_client_credentials_t client;
+    } data;
+#endif
+};
 
 #ifdef CONFIG_GNUTLS
 
crypto/tlscredspsk.c +14 -0
index f5a31108d15..b4053741b3b 100644
@@ -26,6 +26,20 @@
 #include "qom/object_interfaces.h"
 #include "trace.h"
 
+#ifdef CONFIG_GNUTLS
+#include <gnutls/gnutls.h>
+#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
+};
 
 #ifdef CONFIG_GNUTLS
 
crypto/tlscredsx509.c +13 -3
index d9d6f4421e5..0a8284f930b 100644
@@ -27,12 +27,22 @@
 #include "qom/object_interfaces.h"
 #include "trace.h"
 
+#ifdef CONFIG_GNUTLS
+#include <gnutls/gnutls.h>
+#include <gnutls/x509.h>
+#endif
+
+struct QCryptoTLSCredsX509 {
+    QCryptoTLSCreds parent_obj;
+#ifdef CONFIG_GNUTLS
+    gnutls_certificate_credentials_t data;
+#endif
+    bool sanityCheck;
+    char *passwordid;
+};
 
 #ifdef CONFIG_GNUTLS
 
-#include <gnutls/x509.h>
-
-
 static int
 qcrypto_tls_creds_check_cert_times(gnutls_x509_crt_t cert,
                                    const char *certFile,
Signature · 1 line
2.31.1
#4 lore raw

PATCH v2 3/7 chardev/socket: Use qcrypto_tls_creds_check_endpoint()

In reply to Philippe Mathieu-Daudé

Avoid accessing QCryptoTLSCreds internals by using the qcrypto_tls_creds_check_endpoint() helper.

---
 chardev/char-socket.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
chardev/char-socket.c +4 -2
index daa89fe5d1d..fe6b1fe2110 100644
@@ -1403,13 +1403,15 @@ static void qmp_chardev_open_socket(Chardev *chr,
         }
         object_ref(OBJECT(s->tls_creds));
         if (is_listen) {
-            if (s->tls_creds->endpoint != QCRYPTO_TLS_CREDS_ENDPOINT_SERVER) {
+            if (!qcrypto_tls_creds_check_endpoint(s->tls_creds,
+                                        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) {
+            if (!qcrypto_tls_creds_check_endpoint(s->tls_creds,
+                                        QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT)) {
                 error_setg(errp, "%s",
                            "Expected TLS credentials for client endpoint");
                 return;
Signature · 1 line
2.31.1
Reviewed-by on v2 7/7
#9 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 26 lines · Philippe Mathieu-Daudé

Code consuming the "crypto/tlscreds*.h" APIs doesn't need to access its internals. Move the structure definitions to the implementations in crypto/. The headers still forward declare the structures typedef.

This solves a bug introduced by commit 7de2e856533 which made migration/qemu-file-channel.c include "io/channel-tls.h", itself sometime depends on GNUTLS, leading to 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.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/407

Fixes 7de2e856533 ("yank: Unregister function when using TLS migration")
Quoted 10 lines
---
 crypto/tlscredspriv.h         | 15 +++++++++++++++
 include/crypto/tlscreds.h     | 16 ----------------
 include/crypto/tlscredsanon.h | 12 ------------
 include/crypto/tlscredspsk.h  | 12 ------------
 include/crypto/tlscredsx509.h | 10 ----------
 crypto/tlscredsanon.c         | 13 +++++++++++++
 crypto/tlscredspsk.c          | 14 ++++++++++++++
 crypto/tlscredsx509.c         | 16 +++++++++++++---
 8 files changed, 55 insertions(+), 53 deletions(-)

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#3 lore raw

Re: [PATCH v2 2/7] block/nbd: Use qcrypto_tls_creds_check_endpoint()

In reply to Philippe Mathieu-Daudé
Quoted 14 lines · Philippe Mathieu-Daudé

Avoid accessing QCryptoTLSCreds internals by using the qcrypto_tls_creds_check_endpoint() helper.

---
 block/nbd.c    | 3 ++-
 blockdev-nbd.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
block/nbd.c +0 -0
index 616f9ae6c4d..c3523ebf785 100644

block/nbd.c static QCryptoTLSCreds *nbd_get_tls_creds(const char *id, Error **errp) · line 2165

Quoted 8 lines
block/nbd.c +2 -1
@@ -2159,7 +2159,8 @@ static QCryptoTLSCreds *nbd_get_tls_creds(const char *id, Error **errp)
         return NULL;
     }
 
-    if (creds->endpoint != QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT) {
+    if (!qcrypto_tls_creds_check_endpoint(creds,
+                                          QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT)) {
         error_setg(errp,
                    "Expecting TLS credentials with a client endpoint");

I'd suggest we pass 'errp' into the qcrypto_tls_creds_check_endpoint method, so we don't duplicate the error message in all callers.

Quoted 18 lines
block/nbd.c +0 -0
         return NULL;
blockdev-nbd.c +2 -1
index b264620b98d..b6023052ac7 100644
@@ -108,7 +108,8 @@ static QCryptoTLSCreds *nbd_get_tls_creds(const char *id, Error **errp)
         return NULL;
     }
 
-    if (creds->endpoint != QCRYPTO_TLS_CREDS_ENDPOINT_SERVER) {
+    if (!qcrypto_tls_creds_check_endpoint(creds,
+                                          QCRYPTO_TLS_CREDS_ENDPOINT_SERVER)) {
         error_setg(errp,
                    "Expecting TLS credentials with a server endpoint");
         return NULL;
Signature · 1 line
2.31.1

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#10 lore raw
In reply to Daniel P. Berrangé
Quoted 38 lines · Daniel P. Berrangé
Quoted 26 lines · Philippe Mathieu-Daudé

Code consuming the "crypto/tlscreds*.h" APIs doesn't need to access its internals. Move the structure definitions to the implementations in crypto/. The headers still forward declare the structures typedef.

This solves a bug introduced by commit 7de2e856533 which made migration/qemu-file-channel.c include "io/channel-tls.h", itself sometime depends on GNUTLS, leading to 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.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/407

Fixes 7de2e856533 ("yank: Unregister function when using TLS migration")
Quoted 10 lines
---
 crypto/tlscredspriv.h         | 15 +++++++++++++++
 include/crypto/tlscreds.h     | 16 ----------------
 include/crypto/tlscredsanon.h | 12 ------------
 include/crypto/tlscredspsk.h  | 12 ------------
 include/crypto/tlscredsx509.h | 10 ----------
 crypto/tlscredsanon.c         | 13 +++++++++++++
 crypto/tlscredspsk.c          | 14 ++++++++++++++
 crypto/tlscredsx509.c         | 16 +++++++++++++---
 8 files changed, 55 insertions(+), 53 deletions(-)
Quoted 1 line

Thanks, however I missed something:

crypto/tlssession.c: In function ‘qcrypto_tls_session_new’:
crypto/tlssession.c:163:48: error: invalid use of incomplete typedef ‘QCryptoTLSCredsAnon’
163 | acreds->data.server);
| ^~
crypto/tlssession.c:167:48: error: invalid use of incomplete typedef ‘QCryptoTLSCredsAnon’
167 | acreds->data.client);
| ^~
crypto/tlssession.c:201:48: error: invalid use of incomplete typedef ‘QCryptoTLSCredsPSK’
201 | pcreds->data.server);
| ^~
crypto/tlssession.c:205:48: error: invalid use of incomplete typedef ‘QCryptoTLSCredsPSK’
205 | pcreds->data.client);
| ^~
crypto/tlssession.c:228:44: error: invalid use of incomplete typedef ‘QCryptoTLSCredsX509’
228 | tcreds->data);
| ^~

#11 lore raw
Quoted 56 lines · Philippe Mathieu-Daudé
Quoted 38 lines · Daniel P. Berrangé
Quoted 26 lines · Philippe Mathieu-Daudé

Code consuming the "crypto/tlscreds*.h" APIs doesn't need to access its internals. Move the structure definitions to the implementations in crypto/. The headers still forward declare the structures typedef.

This solves a bug introduced by commit 7de2e856533 which made migration/qemu-file-channel.c include "io/channel-tls.h", itself sometime depends on GNUTLS, leading to 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.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/407

Fixes 7de2e856533 ("yank: Unregister function when using TLS migration")
Quoted 10 lines
---
 crypto/tlscredspriv.h         | 15 +++++++++++++++
 include/crypto/tlscreds.h     | 16 ----------------
 include/crypto/tlscredsanon.h | 12 ------------
 include/crypto/tlscredspsk.h  | 12 ------------
 include/crypto/tlscredsx509.h | 10 ----------
 crypto/tlscredsanon.c         | 13 +++++++++++++
 crypto/tlscredspsk.c          | 14 ++++++++++++++
 crypto/tlscredsx509.c         | 16 +++++++++++++---
 8 files changed, 55 insertions(+), 53 deletions(-)
Quoted 1 line

Thanks, however I missed something:

crypto/tlssession.c: In function ‘qcrypto_tls_session_new’:
crypto/tlssession.c:163:48: error: invalid use of incomplete typedef ‘QCryptoTLSCredsAnon’
163 | acreds->data.server);
| ^~
crypto/tlssession.c:167:48: error: invalid use of incomplete typedef ‘QCryptoTLSCredsAnon’
167 | acreds->data.client);
| ^~
crypto/tlssession.c:201:48: error: invalid use of incomplete typedef ‘QCryptoTLSCredsPSK’
201 | pcreds->data.server);
| ^~

Quoted 8 lines

crypto/tlssession.c:205:48: error: invalid use of incomplete typedef ‘QCryptoTLSCredsPSK’
205 | pcreds->data.client);
| ^~
crypto/tlssession.c:228:44: error: invalid use of incomplete typedef ‘QCryptoTLSCredsX509’
228 | tcreds->data);
| ^~

Ah, yes, the tls session code needs to peer at the tlscred data.

We could have a 'crypto/tlscredspriv.h' header that declares some accessors for getting this data from tls session.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|