ssl-verify: Changed IPv4 hostname to IPv6

Change inet_aton function to glib functions.

inet_aton only supported IPv4 addresses, and wasn't available on windows
machines. GInetAddress functions support IPv6 natively, and requires less
boilerplate code then IPv6 gettaddrinfo().
This commit is contained in:
Lukas Venhoda 2015-10-22 14:22:21 +02:00 committed by Fabiano Fidêncio
parent 9b74e47ed3
commit 9749e7ed14

View File

@ -31,19 +31,7 @@
#endif
#include <ctype.h>
#include <string.h>
#ifdef WIN32
static int inet_aton(const char* ip, struct in_addr* in_addr)
{
unsigned long addr = inet_addr(ip);
if (addr == INADDR_NONE) {
return 0;
}
in_addr->S_un.S_addr = addr;
return 1;
}
#endif
#include <gio/gio.h>
static int verify_pubkey(X509* cert, const char *key, size_t key_size)
{
@ -202,20 +190,29 @@ static int verify_hostname(X509* cert, const char *hostname)
return 1;
}
} else if (name->type == GEN_IPADD) {
struct in_addr addr;
int addr_len = 0;
int alt_ip_len = ASN1_STRING_length(name->d.iPAddress);
GInetAddress * alt_ip = NULL;
GInetAddress * ip = NULL;
gchar * alt_ip_string = NULL;
const guint8 * ip_binary = NULL;
int alt_ip_len = 0;
int ip_len = 0;
found_dns_name = 1;
// only IpV4 supported
if (inet_aton(hostname, &addr)) {
addr_len = sizeof(struct in_addr);
}
ip = g_inet_address_new_from_string(hostname);
ip_len = g_inet_address_get_native_size(ip);
ip_binary = g_inet_address_to_bytes(ip);
if ((addr_len == alt_ip_len)&&
!memcmp(ASN1_STRING_data(name->d.iPAddress), &addr, addr_len)) {
spice_debug("alt name IP match=%s",
inet_ntoa(*((struct in_addr*)ASN1_STRING_data(name->d.dNSName))));
alt_ip_len = ASN1_STRING_length(name->d.iPAddress);
if ((ip_len == alt_ip_len) &&
(memcmp(ASN1_STRING_data(name->d.iPAddress), ip_binary, ip_len)) == 0) {
alt_ip = g_inet_address_new_from_bytes(ASN1_STRING_data(name->d.iPAddress),
g_inet_address_get_family(ip));
alt_ip_string = g_inet_address_to_string(alt_ip);
spice_debug("alt name IP match=%s", alt_ip_string);
g_free(alt_ip_string);
GENERAL_NAMES_free(subject_alt_names);
return 1;
}