After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 794286 - Certificate tests fail with GnuTLS 3.6
Certificate tests fail with GnuTLS 3.6
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: network
2.56.x
Other Linux
: Normal minor
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2018-03-13 12:11 UTC by Adam Sampson
Modified: 2018-04-17 16:33 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
tests: Bring back check for old GnuTLS rehandshaking bug (1.97 KB, patch)
2018-04-16 01:46 UTC, Michael Catanzaro
committed Details | Review

Description Adam Sampson 2018-03-13 12:11:03 UTC
When building glib-networking 2.56.0 against GnuTLS 3.6.2, the "certificate", "file-database" and "connection" tests fail with this kind of error:

/tls/certificate/verify-good:                                                   
--- stderr ---                                                                  
**                                                                              
GLib-Net:ERROR:../glib-networking-2.56.0/tls/tests/certificate.c:381:           test_verify_certificate_good: assertion failed (errors == 0): (34 == 0)

Error code 34 is G_TLS_CERTIFICATE_INSECURE | G_TLS_CERTIFICATE_BAD_IDENTITY. This is because GnuTLS is correctly reporting GNUTLS_CERT_INSECURE_ALGORITHM on the test certificates; tls/tests/files/server.pem has "Signature Algorithm: sha1WithRSAEncryption" according to "openssl x509", and GnuTLS since 3.6.0 considers SHA1 to be insecure for signing certificates.

Regenerating the test certificates following current best practice would presumably fix this.

I note there's also a report of this bug in Red Hat's tracker:
https://bugzilla.redhat.com/show_bug.cgi?id=1540078
Comment 1 Dan Winship 2018-03-13 13:48:57 UTC
I forget if there are any existing tests of G_TLS_CERTIFICATE_INSECURE, but if not then you could also keep the old certificate around to test that against (when the gnutls version is new enough).
Comment 2 Michael Catanzaro 2018-03-13 18:10:31 UTC
Thanks for reporting this. I'll look into this soon.

(Note: Gnutls 3.6.2 is a development release, not a stable release. The version numbers are confusing. Just making sure you know.)
Comment 3 Michael Catanzaro 2018-04-11 02:18:22 UTC
I can fix the G_TLS_CERTIFICATE_INSECURE errors easily enough, with this change:

diff --git a/tls/tests/files/ssl/client.conf b/tls/tests/files/ssl/client.conf
index be59460..2ba2c77 100644
--- a/tls/tests/files/ssl/client.conf
+++ b/tls/tests/files/ssl/client.conf
@@ -1,7 +1,7 @@
 # Client
 
 [ req ]
-default_md              = sha1
+default_md              = sha256
 utf8                    = yes
 string_mask             = utf8only
 prompt                  = no
diff --git a/tls/tests/files/ssl/server-intermediate.conf b/tls/tests/files/ssl/server-intermediate.conf
index d899a0f..103f50d 100644
--- a/tls/tests/files/ssl/server-intermediate.conf
+++ b/tls/tests/files/ssl/server-intermediate.conf
@@ -1,7 +1,7 @@
 # Server
 
 [ req ]
-default_md              = sha1
+default_md              = sha256
 utf8                    = yes
 string_mask             = utf8only
 prompt                  = no
diff --git a/tls/tests/files/ssl/server.conf b/tls/tests/files/ssl/server.conf
index 6a98029..76b62f1 100644
--- a/tls/tests/files/ssl/server.conf
+++ b/tls/tests/files/ssl/server.conf
@@ -1,7 +1,7 @@
 # Server
 
 [ req ]
-default_md              = sha1
+default_md              = sha256
 utf8                    = yes
 string_mask             = utf8only
 prompt                  = no

and then regenerating the certificates.

But I don't understand where the G_TLS_CERTIFICATE_BAD_IDENTITY is coming from.
Comment 4 Michael Catanzaro 2018-04-11 02:26:27 UTC
It corresponds to GNUTLS_CERT_UNEXPECTED_OWNER, which shouldn't be happening.
Comment 5 Michael Catanzaro 2018-04-11 02:32:48 UTC
(In reply to Dan Winship from comment #1)
> I forget if there are any existing tests of G_TLS_CERTIFICATE_INSECURE, but
> if not then you could also keep the old certificate around to test that
> against (when the gnutls version is new enough).

There's currently no tests for this. Should be easy to add one. I'll do that as part of this bug.
Comment 6 Michael Catanzaro 2018-04-11 03:17:04 UTC
(In reply to Michael Catanzaro from comment #4)
> It corresponds to GNUTLS_CERT_UNEXPECTED_OWNER, which shouldn't be happening.

I'm stumped on this one.
Comment 7 Dan Winship 2018-04-11 15:17:02 UTC
G_TLS_CERTIFICATE_BAD_IDENTITY corresponds to GNUTLS_CERT_UNEXPECTED_OWNER *or* to g_tls_certificate_gnutls_verify_identity() failing. In particular, perhaps gnutls_x509_crt_check_hostname() now returns FALSE for insecure certificates even if the hostname matches?
Comment 8 Dan Winship 2018-04-11 15:21:03 UTC
Or did you mean you're still getting it even after regenerating the certificate?

If you add "#define GTLS_GNUTLS_DEBUG" to the top of gtlsbackend-gnutls.c you'll get lots of debug output, including the line number of any non-"success" return statement that gets hit.
Comment 9 Michael Catanzaro 2018-04-11 17:19:07 UTC
(In reply to Dan Winship from comment #8)
> Or did you mean you're still getting it even after regenerating the
> certificate?

Yeah. We switched gnome-build-meta over to the freedesktop SDK, which has GnuTLS 3.6.1. I was able to reproduce the reported bug:

"Error code 34 is G_TLS_CERTIFICATE_INSECURE | G_TLS_CERTIFICATE_BAD_IDENTITY."

After changing the digest algorithm and regenerating the certificates, I'm now getting just 2: G_TLS_CERTIFICATE_BAD_IDENTITY.

> If you add "#define GTLS_GNUTLS_DEBUG" to the top of gtlsbackend-gnutls.c
> you'll get lots of debug output, including the line number of any
> non-"success" return statement that gets hit.

I'll try that, thanks. I'll also try upgrading to GnuTLS 3.6.2 just in case it might be related to https://gitlab.com/gnutls/gnutls/issues/347 (though I don't think it is).
Comment 10 Michael Catanzaro 2018-04-15 03:52:56 UTC
(In reply to Dan Winship from comment #8)
> If you add "#define GTLS_GNUTLS_DEBUG" to the top of gtlsbackend-gnutls.c
> you'll get lots of debug output, including the line number of any
> non-"success" return statement that gets hit.

Didn't help much.

(In reply to Dan Winship from comment #7)
> G_TLS_CERTIFICATE_BAD_IDENTITY corresponds to GNUTLS_CERT_UNEXPECTED_OWNER
> *or* to g_tls_certificate_gnutls_verify_identity() failing. In particular,
> perhaps gnutls_x509_crt_check_hostname() now returns FALSE for insecure
> certificates even if the hostname matches?

Good call: g_tls_certificate_gnutls_verify_identity() is indeed the problem. gnutls_x509_crt_list_verify() works fine after switching from sha1 to sha256 in the config files.

I spent a while looking at https://gitlab.com/gnutls/gnutls/commit/27e61632048c156a578e688a7d3b2cfc277848c2 because our server certificate specifies only an IP address in subjectAltNames, which was valid in GnuTLS 3.5 but not in 3.6. Removing that wasn't enough to fix this, though. Still investigating.
Comment 11 Michael Catanzaro 2018-04-15 04:07:03 UTC
(In reply to Michael Catanzaro from comment #10) 
> Removing that wasn't enough to fix this, though.

Wrong, I failed to notice that the line number on the assertion failure had changed. ^_^  Removing the subject alt name makes the hostname check for "server.example.com" pass. But then of course the next check for the IP address fails. So to make this work, I figure we need to include both in the subject alt name, like this in the server.conf file:

[ alt_names ]
IP.0                    = 192.168.1.10
dirName                 = req_dn

Which gives this result (from 'certtool --certificate-info --infile=server.pem'):

Subject Alternative Name (not critical):
	IPAddress: 192.168.1.10
	directoryName: CN=server.example.com,DC=EXAMPLE,DC=COM

But if I do that, verification for "server.example.com" fails once again.

Irritatingly, 'certtool --verify --infile=server.pem --load-ca-certificate=ca.pem --verify-hostname=server.example.com' accepts this certificate, which is weird since I would expect --verify-hostname to have the same behavior as gnutls_x509_crt_check_hostname().
Comment 12 Michael Catanzaro 2018-04-15 04:39:02 UTC
Found the solution:

[ alt_names ]
IP.0                    = 192.168.1.10
DNS.0                   = "server.example.com"
Comment 13 Michael Catanzaro 2018-04-15 15:28:22 UTC
Final problem is that /tls/connection/simultaneous-async-rehandshake and /tls/connection/simultaneous-sync-rehandshake are both broken. I'm guessing that's caused by https://gitlab.com/gnutls/gnutls/issues/158.
Comment 14 Michael Catanzaro 2018-04-15 16:30:05 UTC
(In reply to Michael Catanzaro from comment #13)
> Final problem is that /tls/connection/simultaneous-async-rehandshake and
> /tls/connection/simultaneous-sync-rehandshake are both broken. I'm guessing
> that's caused by https://gitlab.com/gnutls/gnutls/issues/158.

Maybe not, we're getting GNUTLS_E_INVALID_REQUEST, but the error conditions added there return GNUTLS_E_UNAVAILABLE_DURING_HANDSHAKE.
Comment 15 Michael Catanzaro 2018-04-15 18:25:04 UTC
Failure is here in _gnutls_epoch_new:

	/* If slot out of range or not empty. */
	if (slot == NULL)
		return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);

	if (*slot != NULL)
		return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);

It's the second check that's failing (slot not empty).

Bugzilla is my liveblog.
Comment 16 Michael Catanzaro 2018-04-16 01:07:26 UTC
d161a6323fe83ab4213643bfa838deb46caf3d27 is the first bad commit
commit d161a6323fe83ab4213643bfa838deb46caf3d27
Author: Nikos Mavrogiannopoulos <nmav@redhat.com>
Date:   Fri Sep 15 09:29:30 2017 +0200

    constate: simplified allocation of epochs
    
    Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>

:040000 040000 be4d0bf50e24e986d021ae0b84cbf8ad8871cfa2 6393ae6a3a08931ff28444fb2a0c0fbde16f5a74 M	lib
Comment 17 Michael Catanzaro 2018-04-16 01:46:01 UTC
The following fix has been pushed:
d217a26 tests: Bring back check for old GnuTLS rehandshaking bug
Comment 18 Michael Catanzaro 2018-04-16 01:46:09 UTC
Created attachment 370974 [details] [review]
tests: Bring back check for old GnuTLS rehandshaking bug

This reverts commit 2ef2af4ecd6bf06bc7000d7e13caf72a2eac7448.

Adapted to check for our new rehandshaking bug!
Comment 19 Michael Catanzaro 2018-04-16 01:57:21 UTC
Reported https://gitlab.com/gnutls/gnutls/issues/426, let's see what Nikos thinks about it.
Comment 20 Michael Catanzaro 2018-04-17 16:33:26 UTC
(In reply to Michael Catanzaro from comment #19)
> Reported https://gitlab.com/gnutls/gnutls/issues/426, let's see what Nikos
> thinks about it.

He fixed it in https://gitlab.com/gnutls/gnutls/merge_requests/620, thanks!