1 /***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ***************************************************************************/
22 #include "curlcheck.h"
23
unit_setup(void)24 static CURLcode unit_setup(void)
25 {
26 return CURLE_OK;
27 }
28
unit_stop(void)29 static void unit_stop(void)
30 {
31 }
32
33 /* only these backends define the tested functions */
34 #if defined(USE_OPENSSL) || defined(USE_GSKIT) || defined(USE_SCHANNEL)
35 #include "vtls/hostcheck.h"
36 struct testcase {
37 const char *host;
38 const char *pattern;
39 bool match;
40 };
41
42 static struct testcase tests[] = {
43 {"", "", FALSE},
44 {"a", "", FALSE},
45 {"", "b", FALSE},
46 {"a", "b", FALSE},
47 {"aa", "bb", FALSE},
48 {"\xff", "\xff", TRUE},
49 {"aa.aa.aa", "aa.aa.bb", FALSE},
50 {"aa.aa.aa", "aa.aa.aa", TRUE},
51 {"aa.aa.aa", "*.aa.bb", FALSE},
52 {"aa.aa.aa", "*.aa.aa", TRUE},
53 {"192.168.0.1", "192.168.0.1", TRUE},
54 {"192.168.0.1", "*.168.0.1", FALSE},
55 {"192.168.0.1", "*.0.1", FALSE},
56 {"h.ello", "*.ello", FALSE},
57 {"h.ello.", "*.ello", FALSE},
58 {"h.ello", "*.ello.", FALSE},
59 {"h.e.llo", "*.e.llo", TRUE},
60 {"h.e.llo", " *.e.llo", FALSE},
61 {" h.e.llo", "*.e.llo", TRUE},
62 {"h.e.llo.", "*.e.llo", TRUE},
63 {"*.e.llo.", "*.e.llo", TRUE},
64 {"************.e.llo.", "*.e.llo", TRUE},
65 {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
66 "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
67 "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
68 "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
69 "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
70 ".e.llo.", "*.e.llo", TRUE},
71 {"\xfe\xfe.e.llo.", "*.e.llo", TRUE},
72 {"h.e.llo.", "*.e.llo.", TRUE},
73 {"h.e.llo", "*.e.llo.", TRUE},
74 {".h.e.llo", "*.e.llo.", FALSE},
75 {"h.e.llo", "*.*.llo.", FALSE},
76 {"h.e.llo", "h.*.llo", FALSE},
77 {"h.e.llo", "h.e.*", FALSE},
78 {"hello", "*.ello", FALSE},
79 {"hello", "**llo", FALSE},
80 {"bar.foo.example.com", "*.example.com", FALSE},
81 {"foo.example.com", "*.example.com", TRUE},
82 {"baz.example.net", "b*z.example.net", FALSE},
83 {"foobaz.example.net", "*baz.example.net", FALSE},
84 {"xn--l8j.example.local", "x*.example.local", FALSE},
85 {"xn--l8j.example.net", "*.example.net", TRUE},
86 {"xn--l8j.example.net", "*j.example.net", FALSE},
87 {"xn--l8j.example.net", "xn--l8j.example.net", TRUE},
88 {"xn--l8j.example.net", "xn--l8j.*.net", FALSE},
89 {"xl8j.example.net", "*.example.net", TRUE},
90 {"fe80::3285:a9ff:fe46:b619", "*::3285:a9ff:fe46:b619", FALSE},
91 {"fe80::3285:a9ff:fe46:b619", "fe80::3285:a9ff:fe46:b619", TRUE},
92 {NULL, NULL, FALSE}
93 };
94
95 UNITTEST_START
96 {
97 int i;
98 for(i = 0; tests[i].host; i++) {
99 if(tests[i].match != Curl_cert_hostcheck(tests[i].pattern,
100 strlen(tests[i].pattern),
101 tests[i].host,
102 strlen(tests[i].host))) {
103 fprintf(stderr,
104 "HOST: %s\n"
105 "PTRN: %s\n"
106 "did %sMATCH\n",
107 tests[i].host,
108 tests[i].pattern,
109 tests[i].match ? "NOT ": "");
110 unitfail++;
111 }
112 }
113 }
114
115 UNITTEST_STOP
116 #else
117
118 UNITTEST_START
119
120 UNITTEST_STOP
121 #endif
122