~ubuntu-branches/ubuntu/utopic/curl/utopic

« back to all changes in this revision

Viewing changes to lib/hostcheck.c

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2014-04-01 09:25:23 UTC
  • Revision ID: package-import@ubuntu.com-20140401092523-y4maf7lz4aufo1l5
Tags: 7.35.0-1ubuntu2
* SECURITY UPDATE: wrong re-use of connections
  - debian/patches/CVE-2014-0138.patch: fix possible issues with NTLM
    HTTP logic, and extend new connection logic to other protocols in
    lib/http.c, lib/url.c, lib/urldata.h, add new tests to
    tests/data/Makefile.am, tests/data/test1418, tests/data/test1419.
  - CVE-2014-0138
* SECURITY UPDATE: incorrect wildcard SSL certificate validation with
  literal IP addresses
  - debian/patches/CVE-2014-0139.patch: fix wildcard logic in
    lib/hostcheck.c, added tests to tests/data/Makefile.am,
    tests/data/test1397, tests/unit/Makefile.inc, tests/unit/unit1397.c.
  - CVE-2014-0139
* debian/patches/fix_test172.path: fix expired cookie causing test to
  fail.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
#include "hostcheck.h"
30
30
#include "rawstr.h"
 
31
#include "inet_pton.h"
 
32
 
 
33
#include "curl_memory.h"
 
34
/* The last #include file should be: */
 
35
#include "memdebug.h"
31
36
 
32
37
/*
33
38
 * Match a hostname against a wildcard pattern.
36
41
 *
37
42
 * We use the matching rule described in RFC6125, section 6.4.3.
38
43
 * http://tools.ietf.org/html/rfc6125#section-6.4.3
 
44
 *
 
45
 * In addition: ignore trailing dots in the host names and wildcards, so that
 
46
 * the names are used normalized. This is what the browsers do.
 
47
 *
 
48
 * Do not allow wildcard matching on IP numbers. There are apparently
 
49
 * certificates being used with an IP address in the CN field, thus making no
 
50
 * apparent distinction between a name and an IP. We need to detect the use of
 
51
 * an IP address and not wildcard match on such names.
 
52
 *
 
53
 * NOTE: hostmatch() gets called with copied buffers so that it can modify the
 
54
 * contents at will.
39
55
 */
40
56
 
41
 
static int hostmatch(const char *hostname, const char *pattern)
 
57
static int hostmatch(char *hostname, char *pattern)
42
58
{
43
59
  const char *pattern_label_end, *pattern_wildcard, *hostname_label_end;
44
60
  int wildcard_enabled;
45
61
  size_t prefixlen, suffixlen;
 
62
  struct in_addr ignored;
 
63
#ifdef ENABLE_IPV6
 
64
  struct sockaddr_in6 si6;
 
65
#endif
 
66
 
 
67
  /* normalize pattern and hostname by stripping off trailing dots */
 
68
  size_t len = strlen(hostname);
 
69
  if(hostname[len-1]=='.')
 
70
    hostname[len-1]=0;
 
71
  len = strlen(pattern);
 
72
  if(pattern[len-1]=='.')
 
73
    pattern[len-1]=0;
 
74
 
46
75
  pattern_wildcard = strchr(pattern, '*');
47
76
  if(pattern_wildcard == NULL)
48
77
    return Curl_raw_equal(pattern, hostname) ?
49
78
      CURL_HOST_MATCH : CURL_HOST_NOMATCH;
50
79
 
 
80
  /* detect IP address as hostname and fail the match if so */
 
81
  if(Curl_inet_pton(AF_INET, hostname, &ignored) > 0)
 
82
    return CURL_HOST_NOMATCH;
 
83
#ifdef ENABLE_IPV6
 
84
  else if(Curl_inet_pton(AF_INET6, hostname, &si6.sin6_addr) > 0)
 
85
    return CURL_HOST_NOMATCH;
 
86
#endif
 
87
 
51
88
  /* We require at least 2 dots in pattern to avoid too wide wildcard
52
89
     match. */
53
90
  wildcard_enabled = 1;
82
119
 
83
120
int Curl_cert_hostcheck(const char *match_pattern, const char *hostname)
84
121
{
 
122
  char *matchp;
 
123
  char *hostp;
 
124
  int res = 0;
85
125
  if(!match_pattern || !*match_pattern ||
86
126
      !hostname || !*hostname) /* sanity check */
87
 
    return 0;
88
 
 
89
 
  if(Curl_raw_equal(hostname, match_pattern)) /* trivial case */
90
 
    return 1;
91
 
 
92
 
  if(hostmatch(hostname,match_pattern) == CURL_HOST_MATCH)
93
 
    return 1;
94
 
  return 0;
 
127
    ;
 
128
  else {
 
129
    matchp = strdup(match_pattern);
 
130
    if(matchp) {
 
131
      hostp = strdup(hostname);
 
132
      if(hostp) {
 
133
        if(hostmatch(hostp, matchp) == CURL_HOST_MATCH)
 
134
          res= 1;
 
135
        free(hostp);
 
136
      }
 
137
      free(matchp);
 
138
    }
 
139
  }
 
140
 
 
141
  return res;
95
142
}
96
143
 
97
144
#endif /* SSLEAY or AXTLS or QSOSSL or GSKIT or NSS */