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