Skip to content

Commit

Permalink
GnuTLS 3.3.6 (partly) fixed the certificate check against IP literals
Browse files Browse the repository at this point in the history
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Jul 4, 2014
1 parent 5786d86 commit dcbe8c6
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions gnutls.c
Expand Up @@ -1793,25 +1793,29 @@ static int verify_peer(gnutls_session_t session)
goto done;

if (!gnutls_x509_crt_check_hostname(cert, vpninfo->hostname)) {
#if GNUTLS_VERSION_NUMBER <= 0x999999 /* FIXME when GnuTLS is fixed. */
/* GnuTLS as of 3.2.x doesn't bother to check the IP address */
int i, ret;
unsigned char addrbuf[sizeof(struct in6_addr)];
unsigned char certaddr[sizeof(struct in6_addr)];
size_t addrlen, certaddrlen;
size_t addrlen = 0, certaddrlen;

if (inet_pton(AF_INET, vpninfo->hostname, addrbuf) > 0)
addrlen = 4;
else if (inet_pton(AF_INET6, vpninfo->hostname, addrbuf) > 0)
addrlen = 16;
else if (vpninfo->hostname[0] == '[' &&
vpninfo->hostname[strlen(vpninfo->hostname)-1] == ']') {
/* gnutls_x509_crt_check_hostname() doesn't cope with IPv6 literals
in URI form with surrounding [] so we must check for ourselves. */
if (vpninfo->hostname[0] == '[' &&
vpninfo->hostname[strlen(vpninfo->hostname)-1] == ']') {
char *p = &vpninfo->hostname[strlen(vpninfo->hostname)-1];
*p = 0;
if (inet_pton(AF_INET6, vpninfo->hostname + 1, addrbuf) > 0)
addrlen = 16;
*p = ']';
} else {
}
#if GNUTLS_VERSION_NUMBER < 0x030306
/* And before 3.3.6 it didn't check IP addresses at all. */
else if (inet_pton(AF_INET, vpninfo->hostname, addrbuf) > 0)
addrlen = 4;
else if (inet_pton(AF_INET6, vpninfo->hostname, addrbuf) > 0)
addrlen = 16;
#endif
if (!addrlen) {
/* vpninfo->hostname was not a bare IP address. Nothing to do */
goto badhost;
}
Expand All @@ -1831,7 +1835,6 @@ static int verify_peer(gnutls_session_t session)
goto done;
}
badhost:
#endif
reason = _("certificate does not match hostname");
}
done:
Expand Down

0 comments on commit dcbe8c6

Please sign in to comment.