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 726596 - tlscertificate: support Subject Alternate Name IP address
tlscertificate: support Subject Alternate Name IP address
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: network
2.39.x
Other Linux
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2014-03-18 01:50 UTC by Aleix Conchillo Flaqué
Modified: 2014-07-21 16:29 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
add suport for SAN IP addresses (3.64 KB, patch)
2014-03-18 01:55 UTC, Aleix Conchillo Flaqué
needs-work Details | Review
add suport for SAN IP addresses fixup (2.50 KB, patch)
2014-03-28 20:44 UTC, Aleix Conchillo Flaqué
needs-work Details | Review
add suport for SAN IP addresses 2nd fixup (2.61 KB, patch)
2014-05-05 18:06 UTC, Aleix Conchillo Flaqué
committed Details | Review
update server certificate with SAN IP and add UT (10.97 KB, patch)
2014-07-18 15:58 UTC, Aleix Conchillo Flaqué
committed Details | Review

Description Aleix Conchillo Flaqué 2014-03-18 01:50:36 UTC
g_tls_certificate_verify currently only checks for hostname when verifying the identity.

You can connect to a server using the IP address. This IP address can be set as an IP address in the X509v3 Subject Altername Name.

If getting the hostname for that IP fails, g_tls_certificate_verify will fail without checking the X509v3 SAN.
Comment 1 Aleix Conchillo Flaqué 2014-03-18 01:55:19 UTC
Created attachment 272224 [details] [review]
add suport for SAN IP addresses
Comment 2 Aleix Conchillo Flaqué 2014-03-26 14:46:04 UTC
Ping.
Comment 3 Dan Winship 2014-03-27 19:43:15 UTC
Comment on attachment 272224 [details] [review]
add suport for SAN IP addresses

>+/* Copied from gnutls/lib/x509/output.c */
>+static char *ip_to_string(void *_ip,

You don't want this. GLib has its own routines for IP to string, but you actually want the other direction anyway; there are multiple ways of writing a given IPv6 address, so you need to compare the binary forms, not the textual forms. (Use g_inet_address_new_from_string() and then g_inet_address_get_bytes()/g_inet_address_get_native_size().)

>+      /* Here we only support an additional check to support IP addresses. */

would be good to check g_hostname_is_ip_address(hostname) first

>+          enum { MAX_SAN = 256 };
>+          char san[MAX_SAN];

No real need for a named constant here, and if you were going to use one, it should be a #define anyway.
Comment 4 Aleix Conchillo Flaqué 2014-03-28 20:44:15 UTC
Created attachment 273197 [details] [review]
add suport for SAN IP addresses fixup

New patch with fixes from review. Let's see how it looks now.

Thanks!
Comment 5 Aleix Conchillo Flaqué 2014-05-01 14:09:56 UTC
Already have a GNOME git account. Thanks! Should I go ahead and commit my last
patch? (comment 4).
Comment 6 Dan Winship 2014-05-01 15:32:45 UTC
Comment on attachment 273197 [details] [review]
add suport for SAN IP addresses fixup

This makes it so that gnutls_x509_crt_check_hostname() only gets called if g_hostname_is_ip_address() returns TRUE.

You should probably do

  if (!hostname)
    return G_TLS_CERTIFICATE_BAD_IDENTITY;

  if (gnutls_x509_crt_check_hostname (gnutls->priv->cert, hostname))
    return 0;

  addr = g_inet_address_new_from_string (hostname);
  if (addr)
    ...

>+              if (memcmp (addr_bytes, san, addr_size) == 0)
>+                return 0;

leaks addr
Comment 7 Aleix Conchillo Flaqué 2014-05-05 18:06:40 UTC
Created attachment 275906 [details] [review]
add suport for SAN IP addresses 2nd fixup

Thanks for the review! Let's see how it looks now. I have kept. g_hostname_is_ip_address before g_inet_address_new_from_string.
Comment 8 Aleix Conchillo Flaqué 2014-05-14 14:33:06 UTC
Ping.
Comment 9 Aleix Conchillo Flaqué 2014-06-05 01:58:49 UTC
Any reason I shouldn't apply latest patch?
Comment 10 Dan Winship 2014-06-07 15:52:54 UTC
Can you add a test case? Add a certificate to tls/tests/files/, and add a test to tls/tests/certificate.c to read it in and then verify that it verifies as expected?
Comment 11 Aleix Conchillo Flaqué 2014-06-09 18:04:21 UTC
(In reply to comment #10)
> Can you add a test case? Add a certificate to tls/tests/files/, and add a test
> to tls/tests/certificate.c to read it in and then verify that it verifies as
> expected?

That's a good reason, indeed. :-)

Can you send me or add the CA key so I can create new client certificates with the same issuer as the others?

May be it's already there, but can't find it.
Comment 12 Dan Winship 2014-06-10 13:23:19 UTC
(In reply to comment #11)
> Can you send me or add the CA key so I can create new client certificates with
> the same issuer as the others?
> 
> May be it's already there, but can't find it.

If it's not one of the keys that's already there, then I don't have it.
Comment 13 Aleix Conchillo Flaqué 2014-06-11 22:01:17 UTC
(In reply to comment #12)
> (In reply to comment #11)
> > Can you send me or add the CA key so I can create new client certificates with
> > the same issuer as the others?
> > 
> > May be it's already there, but can't find it.
> 
> If it's not one of the keys that's already there, then I don't have it.

I'm afraid it's not. I'll create a script to generate ca, server and client certificates so we can generate everything easily.
Comment 14 Aleix Conchillo Flaqué 2014-07-18 15:58:31 UTC
Created attachment 281115 [details] [review]
update server certificate with SAN IP and add UT

I have filed bug 733365 and a patch to re-generate UT certificates.

This patch needs the new certificates to exist before being applied. But the new Subject Alternative Name using IP address test cases is added and working.

Let me know if this looks fine and I will also commit these two patches (code + UT). But first, bug 733365.
Comment 15 Dan Winship 2014-07-21 16:29:43 UTC
committed and pushed. thanks