Add gnutls patches for new CVE's
authorAndre Heinecke <aheinecke@intevation.de>
Fri, 5 Jun 2015 08:03:13 +0000 (10:03 +0200)
committerAndre Heinecke <aheinecke@intevation.de>
Fri, 5 Jun 2015 09:32:07 +0000 (11:32 +0200)
* src/Makefile.am (EXTRA_DIST): Include patches.
* patches/gnutls-2.12.23/06-cve-2015-0282.patch,
patches/gnutls-2.12.23/07-cve-2015-0294.patch: New.

Makefile.am
patches/gnutls-2.12.23/06-cve-2015-0282.patch [new file with mode: 0755]
patches/gnutls-2.12.23/07-cve-2015-0294.patch [new file with mode: 0755]

index 8a4026b..e3c1e8a 100644 (file)
@@ -49,6 +49,8 @@ EXTRA_DIST = autogen.sh README.GIT ONEWS \
         patches/gnutls-2.12.23/03-cve-2014-1959.patch \
         patches/gnutls-2.12.23/04-cve-2014-0092.patch \
         patches/gnutls-2.12.23/05-cve-2014-3466.patch \
+        patches/gnutls-2.12.23/06-cve-2015-0282.patch \
+        patches/gnutls-2.12.23/07-cve-2015-0294.patch \
         patches/gnutls-2.12.23/fix-gcrypt-private-api-usage.patch \
         patches/gnutls-2.12.23/gnulib-mingw-w64-fix.patch \
         patches/gtkhtml2_viewer-0.34/80-src-makefile.postcfg-build \
diff --git a/patches/gnutls-2.12.23/06-cve-2015-0282.patch b/patches/gnutls-2.12.23/06-cve-2015-0282.patch
new file mode 100755 (executable)
index 0000000..a12dd6a
--- /dev/null
@@ -0,0 +1,484 @@
+#! /bin/sh
+patch -p1 -l -f $* < $0
+exit $?
+
+From d326f81daed5a1a06476d66a81584f8c7b71141d Mon Sep 17 00:00:00 2001
+From: Nikos Mavrogiannopoulos <nmav@redhat.com>
+Date: Mon, 23 Feb 2015 10:03:47 +0100
+Subject: [PATCH] Added fix for GNUTLS-SA-2015-1
+
+---
+ lib/gnutls_algorithms.c |  8 ++++++++
+ lib/gnutls_algorithms.h |  1 +
+ lib/gnutls_pubkey.c     |  4 ++--
+ lib/gnutls_sig.c        | 14 ++++++++------
+ lib/x509/common.h       |  2 +-
+ lib/x509/crq.c          | 49 ++++++++++++++++++++++++++++++++++++++++++++++++-
+ lib/x509/privkey.c      |  3 ++-
+ lib/x509/verify.c       | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
+ lib/x509/x509.c         |  4 ++--
+ lib/x509/x509_int.h     |  7 ++++---
+ 10 files changed, 127 insertions(+), 42 deletions(-)
+
+Index: gnutls26-2.12.23/lib/gnutls_algorithms.c
+===================================================================
+--- gnutls26-2.12.23.orig/lib/gnutls_algorithms.c      2015-03-20 09:07:52.587827857 -0400
++++ gnutls26-2.12.23/lib/gnutls_algorithms.c   2015-03-20 09:07:52.579827744 -0400
+@@ -2056,6 +2056,14 @@
+   return ret;
+ }
+
++int
++_gnutls_sign_get_hash (gnutls_sign_algorithm_t algorithm)
++{
++  GNUTLS_SIGN_LOOP (if (p->id == algorithm) return p->mac);
++
++  return GNUTLS_MAC_UNKNOWN;
++}
++
+ gnutls_sign_algorithm_t
+ _gnutls_x509_oid2sign_algorithm (const char *oid)
+ {
+Index: gnutls26-2.12.23/lib/gnutls_algorithms.h
+===================================================================
+--- gnutls26-2.12.23.orig/lib/gnutls_algorithms.h      2015-03-20 09:07:52.587827857 -0400
++++ gnutls26-2.12.23/lib/gnutls_algorithms.h   2015-03-20 09:07:52.583827801 -0400
+@@ -105,6 +105,7 @@
+ enum encipher_type _gnutls_kx_encipher_type (gnutls_kx_algorithm_t algorithm);
+
+ /* Functions for sign algorithms. */
++int _gnutls_sign_get_hash (gnutls_sign_algorithm_t algorithm);
+ gnutls_sign_algorithm_t _gnutls_x509_oid2sign_algorithm (const char *oid);
+ gnutls_sign_algorithm_t _gnutls_x509_pk_to_sign (gnutls_pk_algorithm_t pk,
+                                                  gnutls_mac_algorithm_t mac);
+Index: gnutls26-2.12.23/lib/gnutls_pubkey.c
+===================================================================
+--- gnutls26-2.12.23.orig/lib/gnutls_pubkey.c  2015-03-20 09:07:52.587827857 -0400
++++ gnutls26-2.12.23/lib/gnutls_pubkey.c       2015-03-20 09:07:52.583827801 -0400
+@@ -1048,7 +1048,7 @@
+       return GNUTLS_E_INVALID_REQUEST;
+     }
+
+-  ret = pubkey_verify_sig( data, NULL, signature, pubkey->pk_algorithm,
++  ret = pubkey_verify_sig(GNUTLS_MAC_UNKNOWN, data, NULL, signature, pubkey->pk_algorithm,
+     pubkey->params, pubkey->params_size);
+   if (ret < 0)
+     {
+@@ -1086,7 +1086,7 @@
+     }
+
+   ret =
+-    pubkey_verify_sig (NULL, hash, signature, key->pk_algorithm,
++    pubkey_verify_sig (GNUTLS_MAC_UNKNOWN, NULL, hash, signature, key->pk_algorithm,
+                        key->params, key->params_size);
+
+   return ret;
+Index: gnutls26-2.12.23/lib/gnutls_sig.c
+===================================================================
+--- gnutls26-2.12.23.orig/lib/gnutls_sig.c     2015-03-20 09:07:52.587827857 -0400
++++ gnutls26-2.12.23/lib/gnutls_sig.c  2015-03-20 09:07:52.583827801 -0400
+@@ -273,7 +273,8 @@
+ verify_tls_hash (gnutls_session_t session, gnutls_protocol_t ver, gnutls_cert * cert,
+                     const gnutls_datum_t * hash_concat,
+                     gnutls_datum_t * signature, size_t sha1pos,
+-                    gnutls_pk_algorithm_t pk_algo)
++                    gnutls_pk_algorithm_t pk_algo,
++                    int hashalg)
+ {
+   int ret;
+   gnutls_datum_t vdata;
+@@ -309,7 +310,7 @@
+         ret = _gnutls_rsa_verify (&vdata, signature, cert->params,
+                                      cert->params_size, 1);
+       else
+-        ret = pubkey_verify_sig( NULL, &vdata, signature, pk_algo,
++        ret = pubkey_verify_sig(hashalg, NULL, &vdata, signature, pk_algo,
+           cert->params, cert->params_size);
+
+       if (ret < 0)
+@@ -324,7 +325,7 @@
+       vdata.data = &hash_concat->data[sha1pos];
+       vdata.size = hash_concat->size - sha1pos;
+
+-      ret = pubkey_verify_sig( NULL, &vdata, signature, pk_algo,
++      ret = pubkey_verify_sig(hashalg, NULL, &vdata, signature, pk_algo,
+         cert->params, cert->params_size);
+       /* verify signature */
+       if (ret < 0)
+@@ -428,7 +429,8 @@
+   ret = verify_tls_hash (session, ver, cert, &dconcat, signature,
+                             dconcat.size -
+                             _gnutls_hash_get_algo_len (hash_algo),
+-                            _gnutls_sign_get_pk_algorithm (algo));
++                            _gnutls_sign_get_pk_algorithm (algo),
++                            hash_algo);
+   if (ret < 0)
+     {
+       gnutls_assert ();
+@@ -491,7 +493,7 @@
+
+   ret =
+     verify_tls_hash (session, ver, cert, &dconcat, signature, 0,
+-                        cert->subject_pk_algorithm);
++                        cert->subject_pk_algorithm, hash_algo);
+   if (ret < 0)
+     {
+       gnutls_assert ();
+@@ -582,7 +584,7 @@
+
+   ret =
+     verify_tls_hash (session, ver, cert, &dconcat, signature, 16,
+-                        cert->subject_pk_algorithm);
++                        cert->subject_pk_algorithm, GNUTLS_MAC_UNKNOWN);
+   if (ret < 0)
+     {
+       gnutls_assert ();
+Index: gnutls26-2.12.23/lib/x509/common.h
+===================================================================
+--- gnutls26-2.12.23.orig/lib/x509/common.h    2015-03-20 09:07:52.587827857 -0400
++++ gnutls26-2.12.23/lib/x509/common.h 2015-03-20 09:07:52.583827801 -0400
+@@ -151,7 +151,7 @@
+ void _asnstr_append_name (char *name, size_t name_size, const char *part1,
+                           const char *part2);
+
+-int pubkey_verify_sig (const gnutls_datum_t * tbs,
++int pubkey_verify_sig (int hashalg, const gnutls_datum_t * tbs,
+                        const gnutls_datum_t * hash,
+                        const gnutls_datum_t * signature,
+                        gnutls_pk_algorithm_t pk, bigint_t * issuer_params,
+Index: gnutls26-2.12.23/lib/x509/crq.c
+===================================================================
+--- gnutls26-2.12.23.orig/lib/x509/crq.c       2015-03-20 09:07:52.587827857 -0400
++++ gnutls26-2.12.23/lib/x509/crq.c    2015-03-20 09:07:52.583827801 -0400
+@@ -2540,6 +2540,7 @@
+ gnutls_datum signature = { NULL, 0 };
+ bigint_t params[MAX_PUBLIC_PARAMS_SIZE];
+ int ret, params_size = 0, i;
++int hashalg, sigalg;
+
+   ret =
+     _gnutls_x509_get_signed_data (crq->crq, "certificationRequestInfo", &data);
+@@ -2565,7 +2566,10 @@
+       goto cleanup;
+     }
+
+-  ret = pubkey_verify_sig(&data, NULL, &signature,
++  sigalg = gnutls_x509_crq_get_signature_algorithm (crq);
++  hashalg = _gnutls_sign_get_hash(sigalg);
++
++  ret = pubkey_verify_sig(hashalg, &data, NULL, &signature,
+                           gnutls_x509_crq_get_pk_algorithm (crq, NULL),
+     params, params_size);
+   if (ret < 0)
+@@ -2588,5 +2592,48 @@
+   return ret;
+ }
+
++/**
++ * gnutls_x509_crq_get_signature_algorithm:
++ * @crl: should contain a #gnutls_x509_crl_t structure
++ *
++ * This function will return a value of the #gnutls_sign_algorithm_t
++ * enumeration that is the signature algorithm.
++ *
++ * Returns: On success, %GNUTLS_E_SUCCESS is returned, otherwise a
++ *   negative error value.
++ **/
++int
++gnutls_x509_crq_get_signature_algorithm (gnutls_x509_crq_t crq)
++{
++  int result;
++  gnutls_datum_t sa;
++
++  if (crq == NULL)
++    {
++      gnutls_assert ();
++      return GNUTLS_E_INVALID_REQUEST;
++    }
++
++  /* Read the signature algorithm. Note that parameters are not
++   * read. They will be read from the issuer's certificate if needed.
++   */
++
++  result =
++    _gnutls_x509_read_value (crq->crq, "signatureAlgorithm.algorithm",
++                             &sa, 0);
++
++  if (result < 0)
++    {
++      gnutls_assert ();
++      return result;
++    }
++
++  result = _gnutls_x509_oid2sign_algorithm ((const char *) sa.data);
++
++  _gnutls_free_datum (&sa);
++
++  return result;
++}
++
+ #endif /* ENABLE_PKI */
+
+Index: gnutls26-2.12.23/lib/x509/privkey.c
+===================================================================
+--- gnutls26-2.12.23.orig/lib/x509/privkey.c   2015-03-20 09:07:52.587827857 -0400
++++ gnutls26-2.12.23/lib/x509/privkey.c        2015-03-20 09:07:52.583827801 -0400
+@@ -1828,7 +1828,8 @@
+       return GNUTLS_E_INVALID_REQUEST;
+     }
+
+-  result = _gnutls_x509_privkey_verify_signature (data, signature, key);
++  result = _gnutls_x509_privkey_verify_signature (GNUTLS_MAC_UNKNOWN, data, signature, key);
++
+   if (result < 0)
+     {
+       gnutls_assert ();
+Index: gnutls26-2.12.23/lib/x509/verify.c
+===================================================================
+--- gnutls26-2.12.23.orig/lib/x509/verify.c    2015-03-20 09:07:52.587827857 -0400
++++ gnutls26-2.12.23/lib/x509/verify.c 2015-03-20 09:07:52.587827857 -0400
+@@ -332,6 +332,7 @@
+   gnutls_datum_t cert_signature = { NULL, 0 };
+   gnutls_x509_crt_t issuer = NULL;
+   int issuer_version, result = 0;
++  int sigalg, hashalg;
+
+   if (output)
+     *output = 0;
+@@ -399,8 +400,18 @@
+       goto cleanup;
+     }
+
++  sigalg = gnutls_x509_crt_get_signature_algorithm (cert);
++  hashalg = _gnutls_sign_get_hash(sigalg);
++
++  if (hashalg == GNUTLS_MAC_UNKNOWN)
++    {
++      gnutls_assert();
++      result = 0;
++      goto cleanup;
++    }
++
+   result =
+-    _gnutls_x509_verify_signature (&cert_signed_data, NULL, &cert_signature,
++    _gnutls_x509_verify_signature (hashalg, &cert_signed_data, NULL, &cert_signature,
+                                    issuer);
+   if (result == GNUTLS_E_PK_SIG_VERIFY_FAILED)
+     {
+@@ -423,10 +434,6 @@
+    */
+   if (is_issuer (cert, cert) == 0)
+     {
+-      int sigalg;
+-
+-      sigalg = gnutls_x509_crt_get_signature_algorithm (cert);
+-
+       if (((sigalg == GNUTLS_SIGN_RSA_MD2) &&
+            !(flags & GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD2)) ||
+           ((sigalg == GNUTLS_SIGN_RSA_MD5) &&
+@@ -749,12 +756,12 @@
+  * params[1] is public key
+  */
+ static int
+-_pkcs1_rsa_verify_sig (const gnutls_datum_t * text,
+-                       const gnutls_datum_t * prehash,
+-                       const gnutls_datum_t * signature, bigint_t * params,
+-                       int params_len)
++_pkcs1_rsa_verify_sig (gnutls_mac_algorithm_t hash, const gnutls_datum_t * text,
++                     const gnutls_datum_t * prehash,
++                     const gnutls_datum_t * signature, bigint_t * params,
++                     int params_len)
+ {
+-  gnutls_mac_algorithm_t hash = GNUTLS_MAC_UNKNOWN;
++  gnutls_mac_algorithm_t phash = GNUTLS_MAC_UNKNOWN;
+   int ret;
+   opaque digest[MAX_HASH_SIZE], md[MAX_HASH_SIZE], *cmp;
+   int digest_size;
+@@ -774,7 +781,7 @@
+
+   digest_size = sizeof (digest);
+   if ((ret =
+-       decode_ber_digest_info (&decrypted, &hash, digest, &digest_size)) != 0)
++       decode_ber_digest_info (&decrypted, &phash, digest, &digest_size)) != 0)
+     {
+       gnutls_assert ();
+       _gnutls_free_datum (&decrypted);
+@@ -783,6 +790,15 @@
+
+   _gnutls_free_datum (&decrypted);
+
++  if (hash != GNUTLS_MAC_UNKNOWN && hash != phash)
++    {
++      gnutls_assert();
++      return GNUTLS_E_PK_SIG_VERIFY_FAILED;
++    }
++  else
++    hash = phash;
++
++
+   if (digest_size != _gnutls_hash_get_algo_len (hash))
+     {
+       gnutls_assert ();
+@@ -878,11 +894,11 @@
+  * not verified, or 1 otherwise.
+  */
+ int
+-pubkey_verify_sig (const gnutls_datum_t * tbs,
+-                   const gnutls_datum_t * hash,
+-                   const gnutls_datum_t * signature,
+-                   gnutls_pk_algorithm_t pk, bigint_t * issuer_params,
+-                   int issuer_params_size)
++pubkey_verify_sig (int hashalg, const gnutls_datum_t * tbs,
++          const gnutls_datum_t * hash,
++          const gnutls_datum_t * signature,
++          gnutls_pk_algorithm_t pk, bigint_t * issuer_params,
++          int issuer_params_size)
+ {
+
+   switch (pk)
+@@ -890,7 +906,7 @@
+     case GNUTLS_PK_RSA:
+
+       if (_pkcs1_rsa_verify_sig
+-          (tbs, hash, signature, issuer_params, issuer_params_size) != 0)
++          (hashalg, tbs, hash, signature, issuer_params, issuer_params_size) != 0)
+         {
+           gnutls_assert ();
+           return GNUTLS_E_PK_SIG_VERIFY_FAILED;
+@@ -1021,7 +1037,7 @@
+  * 'signature' is the signature!
+  */
+ int
+-_gnutls_x509_verify_signature (const gnutls_datum_t * tbs,
++_gnutls_x509_verify_signature (int hashalg, const gnutls_datum_t * tbs,
+                                const gnutls_datum_t * hash,
+                                const gnutls_datum_t * signature,
+                                gnutls_x509_crt_t issuer)
+@@ -1041,7 +1057,7 @@
+     }
+
+   ret =
+-    pubkey_verify_sig (tbs, hash, signature,
++    pubkey_verify_sig (hashalg, tbs, hash, signature,
+                        gnutls_x509_crt_get_pk_algorithm (issuer, NULL),
+                        issuer_params, issuer_params_size);
+   if (ret < 0)
+@@ -1066,13 +1082,13 @@
+  * 'signature' is the signature!
+  */
+ int
+-_gnutls_x509_privkey_verify_signature (const gnutls_datum_t * tbs,
++_gnutls_x509_privkey_verify_signature (int hashalg, const gnutls_datum_t * tbs,
+                                        const gnutls_datum_t * signature,
+                                        gnutls_x509_privkey_t issuer)
+ {
+   int ret;
+
+-  ret = pubkey_verify_sig (tbs, NULL, signature, issuer->pk_algorithm,
++  ret = pubkey_verify_sig (hashalg, tbs, NULL, signature, issuer->pk_algorithm,
+                            issuer->params, issuer->params_size);
+   if (ret < 0)
+     {
+@@ -1293,6 +1309,7 @@
+   gnutls_datum_t crl_signature = { NULL, 0 };
+   gnutls_x509_crt_t issuer;
+   int result;
++  int sigalg, hashalg;
+
+   if (output)
+     *output = 0;
+@@ -1334,6 +1351,7 @@
+   if (result < 0)
+     {
+       gnutls_assert ();
++      result = 0;
+       goto cleanup;
+     }
+
+@@ -1341,11 +1359,21 @@
+   if (result < 0)
+     {
+       gnutls_assert ();
++      result = 0;
++      goto cleanup;
++    }
++
++  sigalg = gnutls_x509_crl_get_signature_algorithm (crl);
++  hashalg = _gnutls_sign_get_hash(sigalg);
++  if (hashalg == GNUTLS_MAC_UNKNOWN)
++    {
++      gnutls_assert();
++      result = 0;
+       goto cleanup;
+     }
+
+   result =
+-    _gnutls_x509_verify_signature (&crl_signed_data, NULL, &crl_signature,
++    _gnutls_x509_verify_signature (hashalg, &crl_signed_data, NULL, &crl_signature,
+                                    issuer);
+   if (result == GNUTLS_E_PK_SIG_VERIFY_FAILED)
+     {
+@@ -1358,14 +1386,11 @@
+   else if (result < 0)
+     {
+       gnutls_assert ();
++      result = 0;
+       goto cleanup;
+     }
+
+   {
+-    int sigalg;
+-
+-    sigalg = gnutls_x509_crl_get_signature_algorithm (crl);
+-
+     if (((sigalg == GNUTLS_SIGN_RSA_MD2) &&
+          !(flags & GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD2)) ||
+         ((sigalg == GNUTLS_SIGN_RSA_MD5) &&
+Index: gnutls26-2.12.23/lib/x509/x509.c
+===================================================================
+--- gnutls26-2.12.23.orig/lib/x509/x509.c      2015-03-20 09:07:52.587827857 -0400
++++ gnutls26-2.12.23/lib/x509/x509.c   2015-03-20 09:07:52.587827857 -0400
+@@ -2714,7 +2714,7 @@
+       return GNUTLS_E_INVALID_REQUEST;
+     }
+
+-  result = _gnutls_x509_verify_signature (data, NULL, signature, crt);
++  result = _gnutls_x509_verify_signature (GNUTLS_MAC_UNKNOWN, data, NULL, signature, crt);
+   if (result < 0)
+     {
+       gnutls_assert ();
+@@ -2752,7 +2752,7 @@
+       return GNUTLS_E_INVALID_REQUEST;
+     }
+
+-  result = _gnutls_x509_verify_signature (NULL, hash, signature, crt);
++  result = _gnutls_x509_verify_signature (GNUTLS_MAC_UNKNOWN, NULL, hash, signature, crt);
+   if (result < 0)
+     {
+       gnutls_assert ();
+Index: gnutls26-2.12.23/lib/x509/x509_int.h
+===================================================================
+--- gnutls26-2.12.23.orig/lib/x509/x509_int.h  2015-03-20 09:07:52.587827857 -0400
++++ gnutls26-2.12.23/lib/x509/x509_int.h       2015-03-20 09:07:52.587827857 -0400
+@@ -187,11 +187,11 @@
+                                bigint_t * issuer_params,
+                                unsigned int issuer_params_size);
+
+-int _gnutls_x509_verify_signature (const gnutls_datum_t * tbs,
++int _gnutls_x509_verify_signature (int sigalg, const gnutls_datum_t * tbs,
+                                    const gnutls_datum_t * hash,
+                                    const gnutls_datum_t * signature,
+                                    gnutls_x509_crt_t issuer);
+-int _gnutls_x509_privkey_verify_signature (const gnutls_datum_t * tbs,
++int _gnutls_x509_privkey_verify_signature (int sigalg, const gnutls_datum_t * tbs,
+                                            const gnutls_datum_t * signature,
+                                            gnutls_x509_privkey_t issuer);
+
+@@ -390,5 +390,6 @@
+                                     const char *ext_id,
+                                     const gnutls_datum_t * ext_data,
+                                     unsigned int critical);
+-
++int
++gnutls_x509_crq_get_signature_algorithm (gnutls_x509_crq_t crq);
+ #endif
diff --git a/patches/gnutls-2.12.23/07-cve-2015-0294.patch b/patches/gnutls-2.12.23/07-cve-2015-0294.patch
new file mode 100755 (executable)
index 0000000..2983fec
--- /dev/null
@@ -0,0 +1,74 @@
+#! /bin/sh
+patch -p1 -l -f $* < $0
+exit $?
+
+From 2458d6d158fd523418e331e50abb35cd334bb795 Mon Sep 17 00:00:00 2001
+From: Nikos Mavrogiannopoulos <nmav@redhat.com>
+Date: Mon, 23 Feb 2015 10:41:56 +0100
+Subject: [PATCH] added fix for certificate algorithm consistency check
+
+---
+ lib/x509/x509.c | 34 +++++++++++++++++++++++++++++++++-
+ 1 file changed, 33 insertions(+), 1 deletion(-)
+
+diff --git a/lib/x509/x509.c b/lib/x509/x509.c
+index 6db574c..f51ba3b 100644
+--- a/lib/x509/x509.c
++++ b/lib/x509/x509.c
+@@ -165,7 +165,7 @@ gnutls_x509_crt_import (gnutls_x509_crt_t cert,
+                         gnutls_x509_crt_fmt_t format)
+ {
+   int result = 0, need_free = 0;
+-  gnutls_datum_t _data;
++  gnutls_datum_t _data, sa1 = {NULL, 0}, sa2 = {NULL, 0};
+
+   if (cert == NULL)
+     {
+@@ -233,6 +233,36 @@ gnutls_x509_crt_import (gnutls_x509_crt_t cert,
+       goto cleanup;
+     }
+
++  result =
++    _gnutls_x509_read_value (cert->cert, "tbsCertificate.signature.algorithm",
++                           &sa1, 0);
++  if (result != ASN1_SUCCESS)
++    {
++      result = _gnutls_asn2err (result);
++      gnutls_assert ();
++      goto cleanup;
++    }
++
++  result =
++    _gnutls_x509_read_value (cert->cert, "signatureAlgorithm.algorithm",
++                           &sa2, 0);
++  if (result != ASN1_SUCCESS)
++    {
++      result = _gnutls_asn2err (result);
++      gnutls_assert ();
++      goto cleanup;
++    }
++
++  if (sa1.size != sa2.size || sa1.size == 0 || strcmp(sa1.data, sa2.data) != 0)
++    {
++      result = GNUTLS_E_CERTIFICATE_ERROR;
++      gnutls_assert ();
++      goto cleanup;
++    }
++
++  _gnutls_free_datum (&sa1);
++  _gnutls_free_datum (&sa2);
++
+   /* Since we do not want to disable any extension
+    */
+   cert->use_extensions = 1;
+@@ -242,6 +272,8 @@ gnutls_x509_crt_import (gnutls_x509_crt_t cert,
+   return 0;
+
+ cleanup:
++  _gnutls_free_datum (&sa1);
++  _gnutls_free_datum (&sa2);
+   if (need_free)
+     _gnutls_free_datum (&_data);
+   return result;
+--
+libgit2 0.21.4