Improve looks_like_ip_address for IPv6 addresses, and add tests

pull/5666/head
Paul Querna 9 years ago
parent 27df689405
commit 4a9e7c4cb1
  1. 7
      src/core/tsi/ssl_transport_security.c
  2. 2
      src/core/tsi/ssl_transport_security.h
  3. 9
      test/core/tsi/transport_security_test.c

@ -206,13 +206,16 @@ static void ssl_info_callback(const SSL *ssl, int where, int ret) {
}
/* Returns 1 if name looks like an IP address, 0 otherwise.
This is a very rough heuristic as it does not handle IPV6 or things like:
0300.0250.00.01, 0xC0.0Xa8.0x0.0x1, 000030052000001, 0xc0.052000001 */
This is a very rough heuristic, and only handles IPv6 in hexadecimal form. */
static int looks_like_ip_address(const char *name) {
size_t i;
size_t dot_count = 0;
size_t num_size = 0;
for (i = 0; i < strlen(name); i++) {
if (name[i] == ':') {
/* IPv6 Address in hexadecimal form, : is not allowed in DNS names. */
return 1;
}
if (name[i] >= '0' && name[i] <= '9') {
if (num_size > 3) return 0;
num_size++;

@ -1,6 +1,6 @@
/*
*
* Copyright 2015, Google Inc.
* Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

@ -1,6 +1,6 @@
/*
*
* Copyright 2015, Google Inc.
* Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -194,6 +194,13 @@ const cert_name_test_entry cert_name_test_entries[] = {
{0, "173.194.195.139", "foo.example.com", NULL, "8.8.8.8,8.8.4.4"},
{1, "173.194.195.139", "foo.example.com", NULL, "8.8.8.8,173.194.195.139"},
{0, "173.194.195.139", "foo.example.com", NULL, "173.194.195.13"},
{0, "2001:db8:a0b:12f0::1", "foo.example.com", NULL, "173.194.195.13"},
{1, "2001:db8:a0b:12f0::1", "foo.example.com", NULL,
"2001:db8:a0b:12f0::1"},
{0, "2001:db8:a0b:12f0::1", "foo.example.com", NULL,
"2001:db8:a0b:12f0::2"},
{1, "2001:db8:a0b:12f0::1", "foo.example.com", NULL,
"2001:db8:a0b:12f0::2,2001:db8:a0b:12f0::1,8.8.8.8"},
};
typedef struct name_list {

Loading…
Cancel
Save