Skip to contentSkip to conversation

crypto: Allow building with GnuTLS but without Libtasn1

PATCH Superseded Philippe Mathieu-Daudé 2 participants 5 messages May 2, 2024 Arm/Amlogic Meson SoC support

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: Allow building with GnuTLS but without Libtasn1

We only use Libtasn1 in unit tests. As noted in commit d47b83b118 ("tests: add migration tests of TLS with x509 credentials"), having GnuTLS without Libtasn1 is a valid configuration, so do not require Libtasn1, to avoid:

Dependency gnutls found: YES 3.7.1 (cached) Run-time dependency libtasn1 found: NO (tried pkgconfig)

../meson.build:1914:10: ERROR: Dependency "libtasn1" not found, tried pkgconfig

Restrict the unit test pkix_asn1_tab[] variable to CONFIG_TASN1.

Fixes ba7ed407e6 ("configure, meson: convert libtasn1 detection to meson")
---
 meson.build                          | 1 +
 tests/unit/crypto-tls-x509-helpers.h | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)
meson.build +1 -0
index 5db2dbc12e..837a2bdb56 100644
@@ -1912,6 +1912,7 @@ endif
 tasn1 = not_found
 if gnutls.found()
   tasn1 = dependency('libtasn1',
+                     required: false,
                      method: 'pkg-config')
 endif
 keyutils = not_found
tests/unit/crypto-tls-x509-helpers.h +3 -1
index 247e7160eb..bddf00d392 100644
@@ -23,7 +23,6 @@
 
 #include <gnutls/gnutls.h>
 #include <gnutls/x509.h>
-#include <libtasn1.h>
 
 
 #define QCRYPTO_TLS_TEST_CLIENT_NAME "ACME QEMU Client"
@@ -171,6 +170,9 @@ void test_tls_cleanup(const char *keyfile);
     };                                                                  \
     test_tls_generate_cert(&varname, cavarname.crt)
 
+#ifdef CONFIG_TASN1
+#include <libtasn1.h>
 extern const asn1_static_node pkix_asn1_tab[];
+#endif
 
 #endif
Signature · 1 line
2.41.0
#1 lore raw
Quoted 11 lines · Philippe Mathieu-Daudé

We only use Libtasn1 in unit tests. As noted in commit d47b83b118 ("tests: add migration tests of TLS with x509 credentials"), having GnuTLS without Libtasn1 is a valid configuration, so do not require Libtasn1, to avoid:

Dependency gnutls found: YES 3.7.1 (cached) Run-time dependency libtasn1 found: NO (tried pkgconfig)

../meson.build:1914:10: ERROR: Dependency "libtasn1" not found, tried pkgconfig

Restrict the unit test pkix_asn1_tab[] variable to CONFIG_TASN1.

Otherwise we get:

In file included from tests/unit/crypto-tls-psk-helpers.c:23:
tests/unit/crypto-tls-x509-helpers.h:26:10: fatal error:
libtasn1.h: No such file or directory

     26 | #include <libtasn1.h>
        |          ^~~~~~~~~~~~

compilation terminated.

Quoted 41 lines
Fixes ba7ed407e6 ("configure, meson: convert libtasn1 detection to meson")
---
  meson.build                          | 1 +
  tests/unit/crypto-tls-x509-helpers.h | 4 +++-
  2 files changed, 4 insertions(+), 1 deletion(-)
meson.build +1 -0
index 5db2dbc12e..837a2bdb56 100644
@@ -1912,6 +1912,7 @@ endif
  tasn1 = not_found
  if gnutls.found()
    tasn1 = dependency('libtasn1',
+                     required: false,
                       method: 'pkg-config')
  endif
  keyutils = not_found
tests/unit/crypto-tls-x509-helpers.h +3 -1
index 247e7160eb..bddf00d392 100644
@@ -23,7 +23,6 @@
 
  #include <gnutls/gnutls.h>
  #include <gnutls/x509.h>
-#include <libtasn1.h>
 
 
  #define QCRYPTO_TLS_TEST_CLIENT_NAME "ACME QEMU Client"
@@ -171,6 +170,9 @@ void test_tls_cleanup(const char *keyfile);
      };                                                                  \
      test_tls_generate_cert(&varname, cavarname.crt)
 
+#ifdef CONFIG_TASN1
+#include <libtasn1.h>
  extern const asn1_static_node pkix_asn1_tab[];
+#endif
 
  #endif
#2 lore raw
Quoted 13 lines · Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

We only use Libtasn1 in unit tests. As noted in commit d47b83b118 ("tests: add migration tests of TLS with x509 credentials"), having GnuTLS without Libtasn1 is a valid configuration, so do not require Libtasn1, to avoid:

Dependency gnutls found: YES 3.7.1 (cached) Run-time dependency libtasn1 found: NO (tried pkgconfig)

../meson.build:1914:10: ERROR: Dependency "libtasn1" not found, tried pkgconfig

Restrict the unit test pkix_asn1_tab[] variable to CONFIG_TASN1.

Quoted 8 lines

Otherwise we get:

In file included from tests/unit/crypto-tls-psk-helpers.c:23:
tests/unit/crypto-tls-x509-helpers.h:26:10: fatal error:
libtasn1.h: No such file or directory

     26 | #include <libtasn1.h>
        |          ^~~~~~~~~~~~

compilation terminated.

I'd say that crypto-tls-psk-helpers.c shouldn't be including crypto-tls-x509-helpers.h at all, as PSK auth does not depend on X509 code

With 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
Quoted 23 lines · Daniel P. Berrangé
Quoted 13 lines · Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

We only use Libtasn1 in unit tests. As noted in commit d47b83b118 ("tests: add migration tests of TLS with x509 credentials"), having GnuTLS without Libtasn1 is a valid configuration, so do not require Libtasn1, to avoid:

Dependency gnutls found: YES 3.7.1 (cached) Run-time dependency libtasn1 found: NO (tried pkgconfig)

../meson.build:1914:10: ERROR: Dependency "libtasn1" not found, tried pkgconfig

Restrict the unit test pkix_asn1_tab[] variable to CONFIG_TASN1.

Quoted 8 lines

Otherwise we get:

   In file included from tests/unit/crypto-tls-psk-helpers.c:23:
   tests/unit/crypto-tls-x509-helpers.h:26:10: fatal error:
   libtasn1.h: No such file or directory
      26 | #include <libtasn1.h>
         |          ^~~~~~~~~~~~
   compilation terminated.
Quoted 3 lines

I'd say that crypto-tls-psk-helpers.c shouldn't be including crypto-tls-x509-helpers.h at all, as PSK auth does not depend on X509 code

I agree, I tried the "less code churn" path first :)

#4 lore raw
Quoted 24 lines · Philippe Mathieu-Daudé
Quoted 23 lines · Daniel P. Berrangé
Quoted 21 lines · Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

We only use Libtasn1 in unit tests. As noted in commit d47b83b118 ("tests: add migration tests of TLS with x509 credentials"), having GnuTLS without Libtasn1 is a valid configuration, so do not require Libtasn1, to avoid:

    Dependency gnutls found: YES 3.7.1 (cached) Run-time dependency libtasn1 found: NO (tried pkgconfig)

    ../meson.build:1914:10: ERROR: Dependency "libtasn1" not found, tried pkgconfig

Restrict the unit test pkix_asn1_tab[] variable to CONFIG_TASN1.

Otherwise we get:

   In file included from tests/unit/crypto-tls-psk-helpers.c:23:
   tests/unit/crypto-tls-x509-helpers.h:26:10: fatal error:
   libtasn1.h: No such file or directory
      26 | #include <libtasn1.h>
         |          ^~~~~~~~~~~~
   compilation terminated.

Quoted 5 lines
Quoted 3 lines

I'd say that crypto-tls-psk-helpers.c shouldn't be including crypto-tls-x509-helpers.h at all, as PSK auth does not depend on X509 code

I agree, I tried the "less code churn" path first :)

test_tls_init() calls asn1_array2tree(), test_tls_cleanup() calls asn1_delete_structure() and test_tls_generate_cert() calls:
asn1_create_element(pkix_asn1, "PKIX1.BasicConstraints", ... asn1_write_value(ext, "cA", ... asn1_write_value(ext, "pathLenConstraint", ...