[PATCH] tests: Replace deprecated ASN1 code

Stefan Weil posted 1 patch 3 years, 3 months ago
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20210128171523.45921-1-sw@weilnetz.de
Maintainers: "Daniel P. Berrangé" <berrange@redhat.com>
tests/crypto-tls-x509-helpers.c | 10 +++++-----
tests/crypto-tls-x509-helpers.h |  2 +-
tests/pkix_asn1_tab.c           |  2 +-
3 files changed, 7 insertions(+), 7 deletions(-)
[PATCH] tests: Replace deprecated ASN1 code
Posted by Stefan Weil 3 years, 3 months ago
This fixes several compiler warnings on MacOS with Homebrew.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
 tests/crypto-tls-x509-helpers.c | 10 +++++-----
 tests/crypto-tls-x509-helpers.h |  2 +-
 tests/pkix_asn1_tab.c           |  2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/tests/crypto-tls-x509-helpers.c b/tests/crypto-tls-x509-helpers.c
index 01b3daf358..97658592a2 100644
--- a/tests/crypto-tls-x509-helpers.c
+++ b/tests/crypto-tls-x509-helpers.c
@@ -30,7 +30,7 @@
  * This stores some static data that is needed when
  * encoding extensions in the x509 certs
  */
-ASN1_TYPE pkix_asn1;
+asn1_node pkix_asn1;
 
 /*
  * To avoid consuming random entropy to generate keys,
@@ -139,7 +139,7 @@ void test_tls_cleanup(const char *keyfile)
 /*
  * Turns an ASN1 object into a DER encoded byte array
  */
-static void test_tls_der_encode(ASN1_TYPE src,
+static void test_tls_der_encode(asn1_node src,
                                 const char *src_name,
                                 gnutls_datum_t *res)
 {
@@ -317,7 +317,7 @@ test_tls_generate_cert(QCryptoTLSTestCertReq *req,
      * the 'critical' field which we want control over
      */
     if (req->basicConstraintsEnable) {
-        ASN1_TYPE ext = ASN1_TYPE_EMPTY;
+        asn1_node ext = NULL;
 
         asn1_create_element(pkix_asn1, "PKIX1.BasicConstraints", &ext);
         asn1_write_value(ext, "cA",
@@ -344,7 +344,7 @@ test_tls_generate_cert(QCryptoTLSTestCertReq *req,
      * to be 'critical'
      */
     if (req->keyUsageEnable) {
-        ASN1_TYPE ext = ASN1_TYPE_EMPTY;
+        asn1_node ext = NULL;
         char str[2];
 
         str[0] = req->keyUsageValue & 0xff;
@@ -374,7 +374,7 @@ test_tls_generate_cert(QCryptoTLSTestCertReq *req,
      * set this the hard way building up ASN1 data ourselves
      */
     if (req->keyPurposeEnable) {
-        ASN1_TYPE ext = ASN1_TYPE_EMPTY;
+        asn1_node ext = NULL;
 
         asn1_create_element(pkix_asn1, "PKIX1.ExtKeyUsageSyntax", &ext);
         if (req->keyPurposeOID1) {
diff --git a/tests/crypto-tls-x509-helpers.h b/tests/crypto-tls-x509-helpers.h
index 08efba4e19..8fcd7785ab 100644
--- a/tests/crypto-tls-x509-helpers.h
+++ b/tests/crypto-tls-x509-helpers.h
@@ -125,7 +125,7 @@ void test_tls_cleanup(const char *keyfile);
     };                                                                  \
     test_tls_generate_cert(&varname, NULL)
 
-extern const ASN1_ARRAY_TYPE pkix_asn1_tab[];
+extern const asn1_static_node pkix_asn1_tab[];
 
 #endif /* QCRYPTO_HAVE_TLS_TEST_SUPPORT */
 
diff --git a/tests/pkix_asn1_tab.c b/tests/pkix_asn1_tab.c
index f15fc515cb..4aaf736d3f 100644
--- a/tests/pkix_asn1_tab.c
+++ b/tests/pkix_asn1_tab.c
@@ -8,7 +8,7 @@
 
 #ifdef QCRYPTO_HAVE_TLS_TEST_SUPPORT
 
-const ASN1_ARRAY_TYPE pkix_asn1_tab[] = {
+const asn1_static_node pkix_asn1_tab[] = {
   {"PKIX1", 536875024, 0},
   {0, 1073741836, 0},
   {"id-ce", 1879048204, 0},
-- 
2.24.3 (Apple Git-128)


Re: [PATCH] tests: Replace deprecated ASN1 code
Posted by Daniel P. Berrangé 3 years, 3 months ago
On Thu, Jan 28, 2021 at 06:15:23PM +0100, Stefan Weil wrote:
> This fixes several compiler warnings on MacOS with Homebrew.

Could you give an example of the warnings seen as I'm wondering
why we won't have seen them already on other platforms ? 

> 
> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> ---
>  tests/crypto-tls-x509-helpers.c | 10 +++++-----
>  tests/crypto-tls-x509-helpers.h |  2 +-
>  tests/pkix_asn1_tab.c           |  2 +-
>  3 files changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/tests/crypto-tls-x509-helpers.c b/tests/crypto-tls-x509-helpers.c
> index 01b3daf358..97658592a2 100644
> --- a/tests/crypto-tls-x509-helpers.c
> +++ b/tests/crypto-tls-x509-helpers.c
> @@ -30,7 +30,7 @@
>   * This stores some static data that is needed when
>   * encoding extensions in the x509 certs
>   */
> -ASN1_TYPE pkix_asn1;
> +asn1_node pkix_asn1;
>  
>  /*
>   * To avoid consuming random entropy to generate keys,
> @@ -139,7 +139,7 @@ void test_tls_cleanup(const char *keyfile)
>  /*
>   * Turns an ASN1 object into a DER encoded byte array
>   */
> -static void test_tls_der_encode(ASN1_TYPE src,
> +static void test_tls_der_encode(asn1_node src,
>                                  const char *src_name,
>                                  gnutls_datum_t *res)
>  {
> @@ -317,7 +317,7 @@ test_tls_generate_cert(QCryptoTLSTestCertReq *req,
>       * the 'critical' field which we want control over
>       */
>      if (req->basicConstraintsEnable) {
> -        ASN1_TYPE ext = ASN1_TYPE_EMPTY;
> +        asn1_node ext = NULL;
>  
>          asn1_create_element(pkix_asn1, "PKIX1.BasicConstraints", &ext);
>          asn1_write_value(ext, "cA",
> @@ -344,7 +344,7 @@ test_tls_generate_cert(QCryptoTLSTestCertReq *req,
>       * to be 'critical'
>       */
>      if (req->keyUsageEnable) {
> -        ASN1_TYPE ext = ASN1_TYPE_EMPTY;
> +        asn1_node ext = NULL;
>          char str[2];
>  
>          str[0] = req->keyUsageValue & 0xff;
> @@ -374,7 +374,7 @@ test_tls_generate_cert(QCryptoTLSTestCertReq *req,
>       * set this the hard way building up ASN1 data ourselves
>       */
>      if (req->keyPurposeEnable) {
> -        ASN1_TYPE ext = ASN1_TYPE_EMPTY;
> +        asn1_node ext = NULL;
>  
>          asn1_create_element(pkix_asn1, "PKIX1.ExtKeyUsageSyntax", &ext);
>          if (req->keyPurposeOID1) {
> diff --git a/tests/crypto-tls-x509-helpers.h b/tests/crypto-tls-x509-helpers.h
> index 08efba4e19..8fcd7785ab 100644
> --- a/tests/crypto-tls-x509-helpers.h
> +++ b/tests/crypto-tls-x509-helpers.h
> @@ -125,7 +125,7 @@ void test_tls_cleanup(const char *keyfile);
>      };                                                                  \
>      test_tls_generate_cert(&varname, NULL)
>  
> -extern const ASN1_ARRAY_TYPE pkix_asn1_tab[];
> +extern const asn1_static_node pkix_asn1_tab[];
>  
>  #endif /* QCRYPTO_HAVE_TLS_TEST_SUPPORT */
>  
> diff --git a/tests/pkix_asn1_tab.c b/tests/pkix_asn1_tab.c
> index f15fc515cb..4aaf736d3f 100644
> --- a/tests/pkix_asn1_tab.c
> +++ b/tests/pkix_asn1_tab.c
> @@ -8,7 +8,7 @@
>  
>  #ifdef QCRYPTO_HAVE_TLS_TEST_SUPPORT
>  
> -const ASN1_ARRAY_TYPE pkix_asn1_tab[] = {
> +const asn1_static_node pkix_asn1_tab[] = {
>    {"PKIX1", 536875024, 0},
>    {0, 1073741836, 0},
>    {"id-ce", 1879048204, 0},
> -- 
> 2.24.3 (Apple Git-128)
> 
> 

Regards,
Daniel
-- 
|: 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 :|


Re: [PATCH] tests: Replace deprecated ASN1 code
Posted by Stefan Weil 3 years, 3 months ago
Am 29.01.21 um 11:06 schrieb Daniel P. Berrangé:

> On Thu, Jan 28, 2021 at 06:15:23PM +0100, Stefan Weil wrote:
>> This fixes several compiler warnings on MacOS with Homebrew.
> Could you give an example of the warnings seen as I'm wondering
> why we won't have seen them already on other platforms ?


Here they are (at least the first few, as the list is lengthy). I used

../configure --enable-sanitizers --enable-debug 
--extra-cflags=-I/opt/homebrew/include --enable-cocoa

Maybe the warnings were enabled by --enable-debug.

Regards, Stefan


% ninja
[4696/4942] Compiling C object 
tests/test-crypto-tlscredsx509.p/test-crypto-tlscredsx509.c.o
In file included from ../../../tests/test-crypto-tlscredsx509.c:23:
../../../tests/crypto-tls-x509-helpers.h:128:14: warning: 
'ASN1_ARRAY_TYPE' macro is deprecated, use 'asn1_static_node' instead. 
[-W#pragma-messages]
extern const ASN1_ARRAY_TYPE pkix_asn1_tab[];
              ^
/opt/homebrew/Cellar/libtasn1/4.16.0/include/libtasn1.h:582:25: note: 
expanded from macro 'ASN1_ARRAY_TYPE'
#define ASN1_ARRAY_TYPE _Pragma ("GCC warning \"'ASN1_ARRAY_TYPE' macro 
is deprecated, use 'asn1_static_node' instead.\"") asn1_static_node
                         ^
<scratch space>:18:6: note: expanded from here
  GCC warning "'ASN1_ARRAY_TYPE' macro is deprecated, use 
'asn1_static_node' instead."
      ^
1 warning generated.
[4700/4942] Compiling C object 
tests/test-crypto-tlscredsx509.p/pkix_asn1_tab.c.o
In file included from ../../../tests/pkix_asn1_tab.c:7:
/Users/stefan/src/github/qemu/qemu/tests/crypto-tls-x509-helpers.h:128:14: 
warning: 'ASN1_ARRAY_TYPE' macro is deprecated, use 'asn1_static_node' 
instead. [-W#pragma-messages]
extern const ASN1_ARRAY_TYPE pkix_asn1_tab[];
              ^
/opt/homebrew/Cellar/libtasn1/4.16.0/include/libtasn1.h:582:25: note: 
expanded from macro 'ASN1_ARRAY_TYPE'
#define ASN1_ARRAY_TYPE _Pragma ("GCC warning \"'ASN1_ARRAY_TYPE' macro 
is deprecated, use 'asn1_static_node' instead.\"") asn1_static_node
                         ^
<scratch space>:18:6: note: expanded from here
  GCC warning "'ASN1_ARRAY_TYPE' macro is deprecated, use 
'asn1_static_node' instead."
      ^
../../../tests/pkix_asn1_tab.c:11:7: warning: 'ASN1_ARRAY_TYPE' macro is 
deprecated, use 'asn1_static_node' instead. [-W#pragma-messages]
const ASN1_ARRAY_TYPE pkix_asn1_tab[] = {
       ^
/opt/homebrew/Cellar/libtasn1/4.16.0/include/libtasn1.h:582:25: note: 
expanded from macro 'ASN1_ARRAY_TYPE'
#define ASN1_ARRAY_TYPE _Pragma ("GCC warning \"'ASN1_ARRAY_TYPE' macro 
is deprecated, use 'asn1_static_node' instead.\"") asn1_static_node
                         ^
<scratch space>:20:6: note: expanded from here
  GCC warning "'ASN1_ARRAY_TYPE' macro is deprecated, use 
'asn1_static_node' instead."
      ^
2 warnings generated.
[4701/4942] Compiling C object 
tests/test-crypto-tlscredsx509.p/crypto-tls-x509-helpers.c.o
In file included from ../../../tests/crypto-tls-x509-helpers.c:23:
../../../tests/crypto-tls-x509-helpers.h:128:14: warning: 
'ASN1_ARRAY_TYPE' macro is deprecated, use 'asn1_static_node' instead. 
[-W#pragma-messages]
extern const ASN1_ARRAY_TYPE pkix_asn1_tab[];
              ^
/opt/homebrew/Cellar/libtasn1/4.16.0/include/libtasn1.h:582:25: note: 
expanded from macro 'ASN1_ARRAY_TYPE'
#define ASN1_ARRAY_TYPE _Pragma ("GCC warning \"'ASN1_ARRAY_TYPE' macro 
is deprecated, use 'asn1_static_node' instead.\"") asn1_static_node
                         ^
<scratch space>:18:6: note: expanded from here
  GCC warning "'ASN1_ARRAY_TYPE' macro is deprecated, use 
'asn1_static_node' instead."
      ^
../../../tests/crypto-tls-x509-helpers.c:33:1: warning: 'ASN1_TYPE' 
macro is deprecated, use 'asn1_node' instead. [-W#pragma-messages]
ASN1_TYPE pkix_asn1;
^
/opt/homebrew/Cellar/libtasn1/4.16.0/include/libtasn1.h:537:19: note: 
expanded from macro 'ASN1_TYPE'
#define ASN1_TYPE _Pragma ("GCC warning \"'ASN1_TYPE' macro is 
deprecated, use 'asn1_node' instead.\"") asn1_node
                   ^
<scratch space>:117:6: note: expanded from here
  GCC warning "'ASN1_TYPE' macro is deprecated, use 'asn1_node' instead."
      ^
../../../tests/crypto-tls-x509-helpers.c:142:33: warning: 'ASN1_TYPE' 
macro is deprecated, use 'asn1_node' instead. [-W#pragma-messages]
static void test_tls_der_encode(ASN1_TYPE src,
                                 ^
/opt/homebrew/Cellar/libtasn1/4.16.0/include/libtasn1.h:537:19: note: 
expanded from macro 'ASN1_TYPE'
#define ASN1_TYPE _Pragma ("GCC warning \"'ASN1_TYPE' macro is 
deprecated, use 'asn1_node' instead.\"") asn1_node
                   ^
<scratch space>:119:6: note: expanded from here
  GCC warning "'ASN1_TYPE' macro is deprecated, use 'asn1_node' instead."
      ^
../../../tests/crypto-tls-x509-helpers.c:320:9: warning: 'ASN1_TYPE' 
macro is deprecated, use 'asn1_node' instead. [-W#pragma-messages]
         ASN1_TYPE ext = ASN1_TYPE_EMPTY;
         ^
/opt/homebrew/Cellar/libtasn1/4.16.0/include/libtasn1.h:537:19: note: 
expanded from macro 'ASN1_TYPE'
#define ASN1_TYPE _Pragma ("GCC warning \"'ASN1_TYPE' macro is 
deprecated, use 'asn1_node' instead.\"") asn1_node
                   ^
<scratch space>:128:6: note: expanded from here
  GCC warning "'ASN1_TYPE' macro is deprecated, use 'asn1_node' instead."
      ^
../../../tests/crypto-tls-x509-helpers.c:320:25: warning: 
'ASN1_TYPE_EMPTY' macro is deprecated, use 'NULL' instead. 
[-W#pragma-messages]
         ASN1_TYPE ext = ASN1_TYPE_EMPTY;
                         ^
/opt/homebrew/Cellar/libtasn1/4.16.0/include/libtasn1.h:552:25: note: 
expanded from macro 'ASN1_TYPE_EMPTY'
#define ASN1_TYPE_EMPTY _Pragma ("GCC warning \"'ASN1_TYPE_EMPTY' macro 
is deprecated, use 'NULL' instead.\"") NULL
                         ^
<scratch space>:130:6: note: expanded from here
  GCC warning "'ASN1_TYPE_EMPTY' macro is deprecated, use 'NULL' instead."
      ^
../../../tests/crypto-tls-x509-helpers.c:347:9: warning: 'ASN1_TYPE' 
macro is deprecated, use 'asn1_node' instead. [-W#pragma-messages]
         ASN1_TYPE ext = ASN1_TYPE_EMPTY;
         ^

Re: [PATCH] tests: Replace deprecated ASN1 code
Posted by Daniel P. Berrangé 3 years, 3 months ago
On Fri, Jan 29, 2021 at 12:35:59PM +0100, Stefan Weil wrote:
> Am 29.01.21 um 11:06 schrieb Daniel P. Berrangé:
> 
> > On Thu, Jan 28, 2021 at 06:15:23PM +0100, Stefan Weil wrote:
> > > This fixes several compiler warnings on MacOS with Homebrew.
> > Could you give an example of the warnings seen as I'm wondering
> > why we won't have seen them already on other platforms ?
> 
> 
> Here they are (at least the first few, as the list is lengthy). I used
> 
> ../configure --enable-sanitizers --enable-debug
> --extra-cflags=-I/opt/homebrew/include --enable-cocoa
> 
> Maybe the warnings were enabled by --enable-debug.
> 
> Regards, Stefan
> 
> 
> % ninja
> [4696/4942] Compiling C object
> tests/test-crypto-tlscredsx509.p/test-crypto-tlscredsx509.c.o
> In file included from ../../../tests/test-crypto-tlscredsx509.c:23:
> ../../../tests/crypto-tls-x509-helpers.h:128:14: warning: 'ASN1_ARRAY_TYPE'
> macro is deprecated, use 'asn1_static_node' instead. [-W#pragma-messages]
> extern const ASN1_ARRAY_TYPE pkix_asn1_tab[];
>              ^
> /opt/homebrew/Cellar/libtasn1/4.16.0/include/libtasn1.h:582:25: note:
> expanded from macro 'ASN1_ARRAY_TYPE'
> #define ASN1_ARRAY_TYPE _Pragma ("GCC warning \"'ASN1_ARRAY_TYPE' macro is
> deprecated, use 'asn1_static_node' instead.\"") asn1_static_node
>                         ^
> <scratch space>:18:6: note: expanded from here

This is really odd.

I've got the 4.16.0 tar.gz for libtasn1 and it does not contain any
such _Pragma / deprecation warnings.

The libtasn1  git repo *does* contain these pragmas, but only in the
dev tree for the unreleased 4.17.0 version.

The homebrew-core.git repo recipe for libtasn1 claims to be using
4.16.0 release

  https://github.com/Homebrew/homebrew-core/blob/master/Formula/libtasn1.rb

and those tarballs match what i have.

None the less it looks like your 4.16.0 installed version is in fact
a  git snapshot. Damned if I understand what homebrew is doing.

None the less, given that these deprecations are in libtasn1 git upstream,
we're going to have to deal with them.


Regards,
Daniel
-- 
|: 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 :|


Re: [PATCH] tests: Replace deprecated ASN1 code
Posted by Stefan Weil 3 years, 3 months ago
Am 29.01.21 um 12:47 schrieb Daniel P. Berrangé:

> This is really odd.
> I've got the 4.16.0 tar.gz for libtasn1 and it does not contain any
> such _Pragma / deprecation warnings.
>
> The libtasn1  git repo *does* contain these pragmas, but only in the
> dev tree for the unreleased 4.17.0 version.
>
> The homebrew-core.git repo recipe for libtasn1 claims to be using
> 4.16.0 release
>
>    https://github.com/Homebrew/homebrew-core/blob/master/Formula/libtasn1.rb
>
> and those tarballs match what i have.
>
> None the less it looks like your 4.16.0 installed version is in fact
> a  git snapshot. Damned if I understand what homebrew is doing.
>
> None the less, given that these deprecations are in libtasn1 git upstream,
> we're going to have to deal with them.
>
>
> Regards,
> Daniel


Mea culpa.

While examining the problem with some tests on new Macs which were 
reported by Peter, I used a local build of libtasn1 with debug 
information. I also tried git master to see whether the problem was 
fixed there, so my current header files were indeed newer than the 
official 4.16.0 ones. That explains why I was the first one to see those 
error messages.

Stefan




Re: [PATCH] tests: Replace deprecated ASN1 code
Posted by Daniel P. Berrangé 3 years, 3 months ago
On Fri, Jan 29, 2021 at 01:18:43PM +0100, Stefan Weil wrote:
> Am 29.01.21 um 12:47 schrieb Daniel P. Berrangé:
> 
> > This is really odd.
> > I've got the 4.16.0 tar.gz for libtasn1 and it does not contain any
> > such _Pragma / deprecation warnings.
> > 
> > The libtasn1  git repo *does* contain these pragmas, but only in the
> > dev tree for the unreleased 4.17.0 version.
> > 
> > The homebrew-core.git repo recipe for libtasn1 claims to be using
> > 4.16.0 release
> > 
> >    https://github.com/Homebrew/homebrew-core/blob/master/Formula/libtasn1.rb
> > 
> > and those tarballs match what i have.
> > 
> > None the less it looks like your 4.16.0 installed version is in fact
> > a  git snapshot. Damned if I understand what homebrew is doing.
> > 
> > None the less, given that these deprecations are in libtasn1 git upstream,
> > we're going to have to deal with them.
> > 
> > 
> > Regards,
> > Daniel
> 
> 
> Mea culpa.
> 
> While examining the problem with some tests on new Macs which were reported
> by Peter, I used a local build of libtasn1 with debug information. I also
> tried git master to see whether the problem was fixed there, so my current
> header files were indeed newer than the official 4.16.0 ones. That explains
> why I was the first one to see those error messages.

No problem, I'm queuing your patch anyway, with an expanded commit
msg to say that these deprecations will be in the forthcoming 4.17.0
release.

Regards,
Daniel
-- 
|: 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 :|