1*0a6a1f1dSLionel Sambuc /* $NetBSD: test_name.c,v 1.1.1.2 2014/04/24 12:45:42 pettai Exp $ */
2ebfedea0SLionel Sambuc
3ebfedea0SLionel Sambuc /*
4ebfedea0SLionel Sambuc * Copyright (c) 2006 - 2007 Kungliga Tekniska Högskolan
5ebfedea0SLionel Sambuc * (Royal Institute of Technology, Stockholm, Sweden).
6ebfedea0SLionel Sambuc * All rights reserved.
7ebfedea0SLionel Sambuc *
8ebfedea0SLionel Sambuc * Redistribution and use in source and binary forms, with or without
9ebfedea0SLionel Sambuc * modification, are permitted provided that the following conditions
10ebfedea0SLionel Sambuc * are met:
11ebfedea0SLionel Sambuc *
12ebfedea0SLionel Sambuc * 1. Redistributions of source code must retain the above copyright
13ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer.
14ebfedea0SLionel Sambuc *
15ebfedea0SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright
16ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer in the
17ebfedea0SLionel Sambuc * documentation and/or other materials provided with the distribution.
18ebfedea0SLionel Sambuc *
19ebfedea0SLionel Sambuc * 3. Neither the name of the Institute nor the names of its contributors
20ebfedea0SLionel Sambuc * may be used to endorse or promote products derived from this software
21ebfedea0SLionel Sambuc * without specific prior written permission.
22ebfedea0SLionel Sambuc *
23ebfedea0SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24ebfedea0SLionel Sambuc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25ebfedea0SLionel Sambuc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ebfedea0SLionel Sambuc * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27ebfedea0SLionel Sambuc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28ebfedea0SLionel Sambuc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29ebfedea0SLionel Sambuc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30ebfedea0SLionel Sambuc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31ebfedea0SLionel Sambuc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32ebfedea0SLionel Sambuc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33ebfedea0SLionel Sambuc * SUCH DAMAGE.
34ebfedea0SLionel Sambuc */
35ebfedea0SLionel Sambuc
36ebfedea0SLionel Sambuc #include "hx_locl.h"
37ebfedea0SLionel Sambuc
38ebfedea0SLionel Sambuc static int
test_name(hx509_context context,const char * name)39ebfedea0SLionel Sambuc test_name(hx509_context context, const char *name)
40ebfedea0SLionel Sambuc {
41ebfedea0SLionel Sambuc hx509_name n;
42ebfedea0SLionel Sambuc char *s;
43ebfedea0SLionel Sambuc int ret;
44ebfedea0SLionel Sambuc
45ebfedea0SLionel Sambuc ret = hx509_parse_name(context, name, &n);
46ebfedea0SLionel Sambuc if (ret)
47ebfedea0SLionel Sambuc return 1;
48ebfedea0SLionel Sambuc
49ebfedea0SLionel Sambuc ret = hx509_name_to_string(n, &s);
50ebfedea0SLionel Sambuc if (ret)
51ebfedea0SLionel Sambuc return 1;
52ebfedea0SLionel Sambuc
53ebfedea0SLionel Sambuc if (strcmp(s, name) != 0)
54ebfedea0SLionel Sambuc return 1;
55ebfedea0SLionel Sambuc
56ebfedea0SLionel Sambuc hx509_name_free(&n);
57ebfedea0SLionel Sambuc free(s);
58ebfedea0SLionel Sambuc
59ebfedea0SLionel Sambuc return 0;
60ebfedea0SLionel Sambuc }
61ebfedea0SLionel Sambuc
62ebfedea0SLionel Sambuc static int
test_name_fail(hx509_context context,const char * name)63ebfedea0SLionel Sambuc test_name_fail(hx509_context context, const char *name)
64ebfedea0SLionel Sambuc {
65ebfedea0SLionel Sambuc hx509_name n;
66ebfedea0SLionel Sambuc
67ebfedea0SLionel Sambuc if (hx509_parse_name(context, name, &n) == HX509_NAME_MALFORMED)
68ebfedea0SLionel Sambuc return 0;
69ebfedea0SLionel Sambuc hx509_name_free(&n);
70ebfedea0SLionel Sambuc return 1;
71ebfedea0SLionel Sambuc }
72ebfedea0SLionel Sambuc
73ebfedea0SLionel Sambuc static int
test_expand(hx509_context context,const char * name,const char * expected)74ebfedea0SLionel Sambuc test_expand(hx509_context context, const char *name, const char *expected)
75ebfedea0SLionel Sambuc {
76ebfedea0SLionel Sambuc hx509_env env = NULL;
77ebfedea0SLionel Sambuc hx509_name n;
78ebfedea0SLionel Sambuc char *s;
79ebfedea0SLionel Sambuc int ret;
80ebfedea0SLionel Sambuc
81ebfedea0SLionel Sambuc hx509_env_add(context, &env, "uid", "lha");
82ebfedea0SLionel Sambuc
83ebfedea0SLionel Sambuc ret = hx509_parse_name(context, name, &n);
84ebfedea0SLionel Sambuc if (ret)
85ebfedea0SLionel Sambuc return 1;
86ebfedea0SLionel Sambuc
87ebfedea0SLionel Sambuc ret = hx509_name_expand(context, n, env);
88ebfedea0SLionel Sambuc hx509_env_free(&env);
89ebfedea0SLionel Sambuc if (ret)
90ebfedea0SLionel Sambuc return 1;
91ebfedea0SLionel Sambuc
92ebfedea0SLionel Sambuc ret = hx509_name_to_string(n, &s);
93ebfedea0SLionel Sambuc hx509_name_free(&n);
94ebfedea0SLionel Sambuc if (ret)
95ebfedea0SLionel Sambuc return 1;
96ebfedea0SLionel Sambuc
97ebfedea0SLionel Sambuc ret = strcmp(s, expected) != 0;
98ebfedea0SLionel Sambuc free(s);
99ebfedea0SLionel Sambuc if (ret)
100ebfedea0SLionel Sambuc return 1;
101ebfedea0SLionel Sambuc
102ebfedea0SLionel Sambuc return 0;
103ebfedea0SLionel Sambuc }
104ebfedea0SLionel Sambuc
105ebfedea0SLionel Sambuc char certdata1[] =
106ebfedea0SLionel Sambuc "\x30\x82\x04\x1d\x30\x82\x03\x05\xa0\x03\x02\x01\x02\x02\x10\x4e"
107ebfedea0SLionel Sambuc "\x81\x2d\x8a\x82\x65\xe0\x0b\x02\xee\x3e\x35\x02\x46\xe5\x3d\x30"
108ebfedea0SLionel Sambuc "\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x05\x05\x00\x30\x81"
109ebfedea0SLionel Sambuc "\x81\x31\x0b\x30\x09\x06\x03\x55\x04\x06\x13\x02\x47\x42\x31\x1b"
110ebfedea0SLionel Sambuc "\x30\x19\x06\x03\x55\x04\x08\x13\x12\x47\x72\x65\x61\x74\x65\x72"
111ebfedea0SLionel Sambuc "\x20\x4d\x61\x6e\x63\x68\x65\x73\x74\x65\x72\x31\x10\x30\x0e\x06"
112ebfedea0SLionel Sambuc "\x03\x55\x04\x07\x13\x07\x53\x61\x6c\x66\x6f\x72\x64\x31\x1a\x30"
113ebfedea0SLionel Sambuc "\x18\x06\x03\x55\x04\x0a\x13\x11\x43\x4f\x4d\x4f\x44\x4f\x20\x43"
114ebfedea0SLionel Sambuc "\x41\x20\x4c\x69\x6d\x69\x74\x65\x64\x31\x27\x30\x25\x06\x03\x55"
115ebfedea0SLionel Sambuc "\x04\x03\x13\x1e\x43\x4f\x4d\x4f\x44\x4f\x20\x43\x65\x72\x74\x69"
116ebfedea0SLionel Sambuc "\x66\x69\x63\x61\x74\x69\x6f\x6e\x20\x41\x75\x74\x68\x6f\x72\x69"
117ebfedea0SLionel Sambuc "\x74\x79\x30\x1e\x17\x0d\x30\x36\x31\x32\x30\x31\x30\x30\x30\x30"
118ebfedea0SLionel Sambuc "\x30\x30\x5a\x17\x0d\x32\x39\x31\x32\x33\x31\x32\x33\x35\x39\x35"
119ebfedea0SLionel Sambuc "\x39\x5a\x30\x81\x81\x31\x0b\x30\x09\x06\x03\x55\x04\x06\x13\x02"
120ebfedea0SLionel Sambuc "\x47\x42\x31\x1b\x30\x19\x06\x03\x55\x04\x08\x13\x12\x47\x72\x65"
121ebfedea0SLionel Sambuc "\x61\x74\x65\x72\x20\x4d\x61\x6e\x63\x68\x65\x73\x74\x65\x72\x31"
122ebfedea0SLionel Sambuc "\x10\x30\x0e\x06\x03\x55\x04\x07\x13\x07\x53\x61\x6c\x66\x6f\x72"
123ebfedea0SLionel Sambuc "\x64\x31\x1a\x30\x18\x06\x03\x55\x04\x0a\x13\x11\x43\x4f\x4d\x4f"
124ebfedea0SLionel Sambuc "\x44\x4f\x20\x43\x41\x20\x4c\x69\x6d\x69\x74\x65\x64\x31\x27\x30"
125ebfedea0SLionel Sambuc "\x25\x06\x03\x55\x04\x03\x13\x1e\x43\x4f\x4d\x4f\x44\x4f\x20\x43"
126ebfedea0SLionel Sambuc "\x65\x72\x74\x69\x66\x69\x63\x61\x74\x69\x6f\x6e\x20\x41\x75\x74"
127ebfedea0SLionel Sambuc "\x68\x6f\x72\x69\x74\x79\x30\x82\x01\x22\x30\x0d\x06\x09\x2a\x86"
128ebfedea0SLionel Sambuc "\x48\x86\xf7\x0d\x01\x01\x01\x05\x00\x03\x82\x01\x0f\x00\x30\x82"
129ebfedea0SLionel Sambuc "\x01\x0a\x02\x82\x01\x01\x00\xd0\x40\x8b\x8b\x72\xe3\x91\x1b\xf7"
130ebfedea0SLionel Sambuc "\x51\xc1\x1b\x54\x04\x98\xd3\xa9\xbf\xc1\xe6\x8a\x5d\x3b\x87\xfb"
131ebfedea0SLionel Sambuc "\xbb\x88\xce\x0d\xe3\x2f\x3f\x06\x96\xf0\xa2\x29\x50\x99\xae\xdb"
132ebfedea0SLionel Sambuc "\x3b\xa1\x57\xb0\x74\x51\x71\xcd\xed\x42\x91\x4d\x41\xfe\xa9\xc8"
133ebfedea0SLionel Sambuc "\xd8\x6a\x86\x77\x44\xbb\x59\x66\x97\x50\x5e\xb4\xd4\x2c\x70\x44"
134ebfedea0SLionel Sambuc "\xcf\xda\x37\x95\x42\x69\x3c\x30\xc4\x71\xb3\x52\xf0\x21\x4d\xa1"
135ebfedea0SLionel Sambuc "\xd8\xba\x39\x7c\x1c\x9e\xa3\x24\x9d\xf2\x83\x16\x98\xaa\x16\x7c"
136ebfedea0SLionel Sambuc "\x43\x9b\x15\x5b\xb7\xae\x34\x91\xfe\xd4\x62\x26\x18\x46\x9a\x3f"
137ebfedea0SLionel Sambuc "\xeb\xc1\xf9\xf1\x90\x57\xeb\xac\x7a\x0d\x8b\xdb\x72\x30\x6a\x66"
138ebfedea0SLionel Sambuc "\xd5\xe0\x46\xa3\x70\xdc\x68\xd9\xff\x04\x48\x89\x77\xde\xb5\xe9"
139ebfedea0SLionel Sambuc "\xfb\x67\x6d\x41\xe9\xbc\x39\xbd\x32\xd9\x62\x02\xf1\xb1\xa8\x3d"
140ebfedea0SLionel Sambuc "\x6e\x37\x9c\xe2\x2f\xe2\xd3\xa2\x26\x8b\xc6\xb8\x55\x43\x88\xe1"
141ebfedea0SLionel Sambuc "\x23\x3e\xa5\xd2\x24\x39\x6a\x47\xab\x00\xd4\xa1\xb3\xa9\x25\xfe"
142ebfedea0SLionel Sambuc "\x0d\x3f\xa7\x1d\xba\xd3\x51\xc1\x0b\xa4\xda\xac\x38\xef\x55\x50"
143ebfedea0SLionel Sambuc "\x24\x05\x65\x46\x93\x34\x4f\x2d\x8d\xad\xc6\xd4\x21\x19\xd2\x8e"
144ebfedea0SLionel Sambuc "\xca\x05\x61\x71\x07\x73\x47\xe5\x8a\x19\x12\xbd\x04\x4d\xce\x4e"
145ebfedea0SLionel Sambuc "\x9c\xa5\x48\xac\xbb\x26\xf7\x02\x03\x01\x00\x01\xa3\x81\x8e\x30"
146ebfedea0SLionel Sambuc "\x81\x8b\x30\x1d\x06\x03\x55\x1d\x0e\x04\x16\x04\x14\x0b\x58\xe5"
147ebfedea0SLionel Sambuc "\x8b\xc6\x4c\x15\x37\xa4\x40\xa9\x30\xa9\x21\xbe\x47\x36\x5a\x56"
148ebfedea0SLionel Sambuc "\xff\x30\x0e\x06\x03\x55\x1d\x0f\x01\x01\xff\x04\x04\x03\x02\x01"
149ebfedea0SLionel Sambuc "\x06\x30\x0f\x06\x03\x55\x1d\x13\x01\x01\xff\x04\x05\x30\x03\x01"
150ebfedea0SLionel Sambuc "\x01\xff\x30\x49\x06\x03\x55\x1d\x1f\x04\x42\x30\x40\x30\x3e\xa0"
151ebfedea0SLionel Sambuc "\x3c\xa0\x3a\x86\x38\x68\x74\x74\x70\x3a\x2f\x2f\x63\x72\x6c\x2e"
152ebfedea0SLionel Sambuc "\x63\x6f\x6d\x6f\x64\x6f\x63\x61\x2e\x63\x6f\x6d\x2f\x43\x4f\x4d"
153ebfedea0SLionel Sambuc "\x4f\x44\x4f\x43\x65\x72\x74\x69\x66\x69\x63\x61\x74\x69\x6f\x6e"
154ebfedea0SLionel Sambuc "\x41\x75\x74\x68\x6f\x72\x69\x74\x79\x2e\x63\x72\x6c\x30\x0d\x06"
155ebfedea0SLionel Sambuc "\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x05\x05\x00\x03\x82\x01\x01"
156ebfedea0SLionel Sambuc "\x00\x3e\x98\x9e\x9b\xf6\x1b\xe9\xd7\x39\xb7\x78\xae\x1d\x72\x18"
157ebfedea0SLionel Sambuc "\x49\xd3\x87\xe4\x43\x82\xeb\x3f\xc9\xaa\xf5\xa8\xb5\xef\x55\x7c"
158ebfedea0SLionel Sambuc "\x21\x52\x65\xf9\xd5\x0d\xe1\x6c\xf4\x3e\x8c\x93\x73\x91\x2e\x02"
159ebfedea0SLionel Sambuc "\xc4\x4e\x07\x71\x6f\xc0\x8f\x38\x61\x08\xa8\x1e\x81\x0a\xc0\x2f"
160ebfedea0SLionel Sambuc "\x20\x2f\x41\x8b\x91\xdc\x48\x45\xbc\xf1\xc6\xde\xba\x76\x6b\x33"
161ebfedea0SLionel Sambuc "\xc8\x00\x2d\x31\x46\x4c\xed\xe7\x9d\xcf\x88\x94\xff\x33\xc0\x56"
162ebfedea0SLionel Sambuc "\xe8\x24\x86\x26\xb8\xd8\x38\x38\xdf\x2a\x6b\xdd\x12\xcc\xc7\x3f"
163ebfedea0SLionel Sambuc "\x47\x17\x4c\xa2\xc2\x06\x96\x09\xd6\xdb\xfe\x3f\x3c\x46\x41\xdf"
164ebfedea0SLionel Sambuc "\x58\xe2\x56\x0f\x3c\x3b\xc1\x1c\x93\x35\xd9\x38\x52\xac\xee\xc8"
165ebfedea0SLionel Sambuc "\xec\x2e\x30\x4e\x94\x35\xb4\x24\x1f\x4b\x78\x69\xda\xf2\x02\x38"
166ebfedea0SLionel Sambuc "\xcc\x95\x52\x93\xf0\x70\x25\x59\x9c\x20\x67\xc4\xee\xf9\x8b\x57"
167ebfedea0SLionel Sambuc "\x61\xf4\x92\x76\x7d\x3f\x84\x8d\x55\xb7\xe8\xe5\xac\xd5\xf1\xf5"
168ebfedea0SLionel Sambuc "\x19\x56\xa6\x5a\xfb\x90\x1c\xaf\x93\xeb\xe5\x1c\xd4\x67\x97\x5d"
169ebfedea0SLionel Sambuc "\x04\x0e\xbe\x0b\x83\xa6\x17\x83\xb9\x30\x12\xa0\xc5\x33\x15\x05"
170ebfedea0SLionel Sambuc "\xb9\x0d\xfb\xc7\x05\x76\xe3\xd8\x4a\x8d\xfc\x34\x17\xa3\xc6\x21"
171ebfedea0SLionel Sambuc "\x28\xbe\x30\x45\x31\x1e\xc7\x78\xbe\x58\x61\x38\xac\x3b\xe2\x01"
172ebfedea0SLionel Sambuc "\x65";
173ebfedea0SLionel Sambuc
174ebfedea0SLionel Sambuc char certdata2[] =
175ebfedea0SLionel Sambuc "\x30\x82\x03\x02\x30\x82\x02\x6b\x02\x10\x39\xca\x54\x89\xfe\x50"
176ebfedea0SLionel Sambuc "\x22\x32\xfe\x32\xd9\xdb\xfb\x1b\x84\x19\x30\x0d\x06\x09\x2a\x86"
177ebfedea0SLionel Sambuc "\x48\x86\xf7\x0d\x01\x01\x05\x05\x00\x30\x81\xc1\x31\x0b\x30\x09"
178ebfedea0SLionel Sambuc "\x06\x03\x55\x04\x06\x13\x02\x55\x53\x31\x17\x30\x15\x06\x03\x55"
179ebfedea0SLionel Sambuc "\x04\x0a\x13\x0e\x56\x65\x72\x69\x53\x69\x67\x6e\x2c\x20\x49\x6e"
180ebfedea0SLionel Sambuc "\x63\x2e\x31\x3c\x30\x3a\x06\x03\x55\x04\x0b\x13\x33\x43\x6c\x61"
181ebfedea0SLionel Sambuc "\x73\x73\x20\x31\x20\x50\x75\x62\x6c\x69\x63\x20\x50\x72\x69\x6d"
182ebfedea0SLionel Sambuc "\x61\x72\x79\x20\x43\x65\x72\x74\x69\x66\x69\x63\x61\x74\x69\x6f"
183ebfedea0SLionel Sambuc "\x6e\x20\x41\x75\x74\x68\x6f\x72\x69\x74\x79\x20\x2d\x20\x47\x32"
184ebfedea0SLionel Sambuc "\x31\x3a\x30\x38\x06\x03\x55\x04\x0b\x13\x31\x28\x63\x29\x20\x31"
185ebfedea0SLionel Sambuc "\x39\x39\x38\x20\x56\x65\x72\x69\x53\x69\x67\x6e\x2c\x20\x49\x6e"
186ebfedea0SLionel Sambuc "\x63\x2e\x20\x2d\x20\x46\x6f\x72\x20\x61\x75\x74\x68\x6f\x72\x69"
187ebfedea0SLionel Sambuc "\x7a\x65\x64\x20\x75\x73\x65\x20\x6f\x6e\x6c\x79\x31\x1f\x30\x1d"
188ebfedea0SLionel Sambuc "\x06\x03\x55\x04\x0b\x13\x16\x56\x65\x72\x69\x53\x69\x67\x6e\x20"
189ebfedea0SLionel Sambuc "\x54\x72\x75\x73\x74\x20\x4e\x65\x74\x77\x6f\x72\x6b\x30\x1e\x17"
190ebfedea0SLionel Sambuc "\x0d\x39\x38\x30\x35\x31\x38\x30\x30\x30\x30\x30\x30\x5a\x17\x0d"
191ebfedea0SLionel Sambuc "\x31\x38\x30\x35\x31\x38\x32\x33\x35\x39\x35\x39\x5a\x30\x81\xc1"
192ebfedea0SLionel Sambuc "\x31\x0b\x30\x09\x06\x03\x55\x04\x06\x13\x02\x55\x53\x31\x17\x30"
193ebfedea0SLionel Sambuc "\x15\x06\x03\x55\x04\x0a\x13\x0e\x56\x65\x72\x69\x53\x69\x67\x6e"
194ebfedea0SLionel Sambuc "\x2c\x20\x49\x6e\x63\x2e\x31\x3c\x30\x3a\x06\x03\x55\x04\x0b\x13"
195ebfedea0SLionel Sambuc "\x33\x43\x6c\x61\x73\x73\x20\x31\x20\x50\x75\x62\x6c\x69\x63\x20"
196ebfedea0SLionel Sambuc "\x50\x72\x69\x6d\x61\x72\x79\x20\x43\x65\x72\x74\x69\x66\x69\x63"
197ebfedea0SLionel Sambuc "\x61\x74\x69\x6f\x6e\x20\x41\x75\x74\x68\x6f\x72\x69\x74\x79\x20"
198ebfedea0SLionel Sambuc "\x2d\x20\x47\x32\x31\x3a\x30\x38\x06\x03\x55\x04\x0b\x13\x31\x28"
199ebfedea0SLionel Sambuc "\x63\x29\x20\x31\x39\x39\x38\x20\x56\x65\x72\x69\x53\x69\x67\x6e"
200ebfedea0SLionel Sambuc "\x2c\x20\x49\x6e\x63\x2e\x20\x2d\x20\x46\x6f\x72\x20\x61\x75\x74"
201ebfedea0SLionel Sambuc "\x68\x6f\x72\x69\x7a\x65\x64\x20\x75\x73\x65\x20\x6f\x6e\x6c\x79"
202ebfedea0SLionel Sambuc "\x31\x1f\x30\x1d\x06\x03\x55\x04\x0b\x13\x16\x56\x65\x72\x69\x53"
203ebfedea0SLionel Sambuc "\x69\x67\x6e\x20\x54\x72\x75\x73\x74\x20\x4e\x65\x74\x77\x6f\x72"
204ebfedea0SLionel Sambuc "\x6b\x30\x81\x9f\x30\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01"
205ebfedea0SLionel Sambuc "\x01\x05\x00\x03\x81\x8d\x00\x30\x81\x89\x02\x81\x81\x00\xaa\xd0"
206ebfedea0SLionel Sambuc "\xba\xbe\x16\x2d\xb8\x83\xd4\xca\xd2\x0f\xbc\x76\x31\xca\x94\xd8"
207ebfedea0SLionel Sambuc "\x1d\x93\x8c\x56\x02\xbc\xd9\x6f\x1a\x6f\x52\x36\x6e\x75\x56\x0a"
208ebfedea0SLionel Sambuc "\x55\xd3\xdf\x43\x87\x21\x11\x65\x8a\x7e\x8f\xbd\x21\xde\x6b\x32"
209ebfedea0SLionel Sambuc "\x3f\x1b\x84\x34\x95\x05\x9d\x41\x35\xeb\x92\xeb\x96\xdd\xaa\x59"
210ebfedea0SLionel Sambuc "\x3f\x01\x53\x6d\x99\x4f\xed\xe5\xe2\x2a\x5a\x90\xc1\xb9\xc4\xa6"
211ebfedea0SLionel Sambuc "\x15\xcf\xc8\x45\xeb\xa6\x5d\x8e\x9c\x3e\xf0\x64\x24\x76\xa5\xcd"
212ebfedea0SLionel Sambuc "\xab\x1a\x6f\xb6\xd8\x7b\x51\x61\x6e\xa6\x7f\x87\xc8\xe2\xb7\xe5"
213ebfedea0SLionel Sambuc "\x34\xdc\x41\x88\xea\x09\x40\xbe\x73\x92\x3d\x6b\xe7\x75\x02\x03"
214ebfedea0SLionel Sambuc "\x01\x00\x01\x30\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x05"
215ebfedea0SLionel Sambuc "\x05\x00\x03\x81\x81\x00\x8b\xf7\x1a\x10\xce\x76\x5c\x07\xab\x83"
216ebfedea0SLionel Sambuc "\x99\xdc\x17\x80\x6f\x34\x39\x5d\x98\x3e\x6b\x72\x2c\xe1\xc7\xa2"
217ebfedea0SLionel Sambuc "\x7b\x40\x29\xb9\x78\x88\xba\x4c\xc5\xa3\x6a\x5e\x9e\x6e\x7b\xe3"
218ebfedea0SLionel Sambuc "\xf2\x02\x41\x0c\x66\xbe\xad\xfb\xae\xa2\x14\xce\x92\xf3\xa2\x34"
219ebfedea0SLionel Sambuc "\x8b\xb4\xb2\xb6\x24\xf2\xe5\xd5\xe0\xc8\xe5\x62\x6d\x84\x7b\xcb"
220ebfedea0SLionel Sambuc "\xbe\xbb\x03\x8b\x7c\x57\xca\xf0\x37\xa9\x90\xaf\x8a\xee\x03\xbe"
221ebfedea0SLionel Sambuc "\x1d\x28\x9c\xd9\x26\x76\xa0\xcd\xc4\x9d\x4e\xf0\xae\x07\x16\xd5"
222ebfedea0SLionel Sambuc "\xbe\xaf\x57\x08\x6a\xd0\xa0\x42\x42\x42\x1e\xf4\x20\xcc\xa5\x78"
223ebfedea0SLionel Sambuc "\x82\x95\x26\x38\x8a\x47";
224ebfedea0SLionel Sambuc
225ebfedea0SLionel Sambuc char certdata3[] =
226ebfedea0SLionel Sambuc "\x30\x82\x04\x43\x30\x82\x03\x2b\xa0\x03\x02\x01\x02\x02\x01\x01"
227ebfedea0SLionel Sambuc "\x30\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x05\x05\x00\x30"
228ebfedea0SLionel Sambuc "\x7f\x31\x0b\x30\x09\x06\x03\x55\x04\x06\x13\x02\x47\x42\x31\x1b"
229ebfedea0SLionel Sambuc "\x30\x19\x06\x03\x55\x04\x08\x0c\x12\x47\x72\x65\x61\x74\x65\x72"
230ebfedea0SLionel Sambuc "\x20\x4d\x61\x6e\x63\x68\x65\x73\x74\x65\x72\x31\x10\x30\x0e\x06"
231ebfedea0SLionel Sambuc "\x03\x55\x04\x07\x0c\x07\x53\x61\x6c\x66\x6f\x72\x64\x31\x1a\x30"
232ebfedea0SLionel Sambuc "\x18\x06\x03\x55\x04\x0a\x0c\x11\x43\x6f\x6d\x6f\x64\x6f\x20\x43"
233ebfedea0SLionel Sambuc "\x41\x20\x4c\x69\x6d\x69\x74\x65\x64\x31\x25\x30\x23\x06\x03\x55"
234ebfedea0SLionel Sambuc "\x04\x03\x0c\x1c\x54\x72\x75\x73\x74\x65\x64\x20\x43\x65\x72\x74"
235ebfedea0SLionel Sambuc "\x69\x66\x69\x63\x61\x74\x65\x20\x53\x65\x72\x76\x69\x63\x65\x73"
236ebfedea0SLionel Sambuc "\x30\x1e\x17\x0d\x30\x34\x30\x31\x30\x31\x30\x30\x30\x30\x30\x30"
237ebfedea0SLionel Sambuc "\x5a\x17\x0d\x32\x38\x31\x32\x33\x31\x32\x33\x35\x39\x35\x39\x5a"
238ebfedea0SLionel Sambuc "\x30\x7f\x31\x0b\x30\x09\x06\x03\x55\x04\x06\x13\x02\x47\x42\x31"
239ebfedea0SLionel Sambuc "\x1b\x30\x19\x06\x03\x55\x04\x08\x0c\x12\x47\x72\x65\x61\x74\x65"
240ebfedea0SLionel Sambuc "\x72\x20\x4d\x61\x6e\x63\x68\x65\x73\x74\x65\x72\x31\x10\x30\x0e"
241ebfedea0SLionel Sambuc "\x06\x03\x55\x04\x07\x0c\x07\x53\x61\x6c\x66\x6f\x72\x64\x31\x1a"
242ebfedea0SLionel Sambuc "\x30\x18\x06\x03\x55\x04\x0a\x0c\x11\x43\x6f\x6d\x6f\x64\x6f\x20"
243ebfedea0SLionel Sambuc "\x43\x41\x20\x4c\x69\x6d\x69\x74\x65\x64\x31\x25\x30\x23\x06\x03"
244ebfedea0SLionel Sambuc "\x55\x04\x03\x0c\x1c\x54\x72\x75\x73\x74\x65\x64\x20\x43\x65\x72"
245ebfedea0SLionel Sambuc "\x74\x69\x66\x69\x63\x61\x74\x65\x20\x53\x65\x72\x76\x69\x63\x65"
246ebfedea0SLionel Sambuc "\x73\x30\x82\x01\x22\x30\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01"
247ebfedea0SLionel Sambuc "\x01\x01\x05\x00\x03\x82\x01\x0f\x00\x30\x82\x01\x0a\x02\x82\x01"
248ebfedea0SLionel Sambuc "\x01\x00\xdf\x71\x6f\x36\x58\x53\x5a\xf2\x36\x54\x57\x80\xc4\x74"
249ebfedea0SLionel Sambuc "\x08\x20\xed\x18\x7f\x2a\x1d\xe6\x35\x9a\x1e\x25\xac\x9c\xe5\x96"
250ebfedea0SLionel Sambuc "\x7e\x72\x52\xa0\x15\x42\xdb\x59\xdd\x64\x7a\x1a\xd0\xb8\x7b\xdd"
251ebfedea0SLionel Sambuc "\x39\x15\xbc\x55\x48\xc4\xed\x3a\x00\xea\x31\x11\xba\xf2\x71\x74"
252ebfedea0SLionel Sambuc "\x1a\x67\xb8\xcf\x33\xcc\xa8\x31\xaf\xa3\xe3\xd7\x7f\xbf\x33\x2d"
253ebfedea0SLionel Sambuc "\x4c\x6a\x3c\xec\x8b\xc3\x92\xd2\x53\x77\x24\x74\x9c\x07\x6e\x70"
254ebfedea0SLionel Sambuc "\xfc\xbd\x0b\x5b\x76\xba\x5f\xf2\xff\xd7\x37\x4b\x4a\x60\x78\xf7"
255ebfedea0SLionel Sambuc "\xf0\xfa\xca\x70\xb4\xea\x59\xaa\xa3\xce\x48\x2f\xa9\xc3\xb2\x0b"
256ebfedea0SLionel Sambuc "\x7e\x17\x72\x16\x0c\xa6\x07\x0c\x1b\x38\xcf\xc9\x62\xb7\x3f\xa0"
257ebfedea0SLionel Sambuc "\x93\xa5\x87\x41\xf2\xb7\x70\x40\x77\xd8\xbe\x14\x7c\xe3\xa8\xc0"
258ebfedea0SLionel Sambuc "\x7a\x8e\xe9\x63\x6a\xd1\x0f\x9a\xc6\xd2\xf4\x8b\x3a\x14\x04\x56"
259ebfedea0SLionel Sambuc "\xd4\xed\xb8\xcc\x6e\xf5\xfb\xe2\x2c\x58\xbd\x7f\x4f\x6b\x2b\xf7"
260ebfedea0SLionel Sambuc "\x60\x24\x58\x24\xce\x26\xef\x34\x91\x3a\xd5\xe3\x81\xd0\xb2\xf0"
261ebfedea0SLionel Sambuc "\x04\x02\xd7\x5b\xb7\x3e\x92\xac\x6b\x12\x8a\xf9\xe4\x05\xb0\x3b"
262ebfedea0SLionel Sambuc "\x91\x49\x5c\xb2\xeb\x53\xea\xf8\x9f\x47\x86\xee\xbf\x95\xc0\xc0"
263ebfedea0SLionel Sambuc "\x06\x9f\xd2\x5b\x5e\x11\x1b\xf4\xc7\x04\x35\x29\xd2\x55\x5c\xe4"
264ebfedea0SLionel Sambuc "\xed\xeb\x02\x03\x01\x00\x01\xa3\x81\xc9\x30\x81\xc6\x30\x1d\x06"
265ebfedea0SLionel Sambuc "\x03\x55\x1d\x0e\x04\x16\x04\x14\xc5\x7b\x58\xbd\xed\xda\x25\x69"
266ebfedea0SLionel Sambuc "\xd2\xf7\x59\x16\xa8\xb3\x32\xc0\x7b\x27\x5b\xf4\x30\x0e\x06\x03"
267ebfedea0SLionel Sambuc "\x55\x1d\x0f\x01\x01\xff\x04\x04\x03\x02\x01\x06\x30\x0f\x06\x03"
268ebfedea0SLionel Sambuc "\x55\x1d\x13\x01\x01\xff\x04\x05\x30\x03\x01\x01\xff\x30\x81\x83"
269ebfedea0SLionel Sambuc "\x06\x03\x55\x1d\x1f\x04\x7c\x30\x7a\x30\x3c\xa0\x3a\xa0\x38\x86"
270ebfedea0SLionel Sambuc "\x36\x68\x74\x74\x70\x3a\x2f\x2f\x63\x72\x6c\x2e\x63\x6f\x6d\x6f"
271ebfedea0SLionel Sambuc "\x64\x6f\x63\x61\x2e\x63\x6f\x6d\x2f\x54\x72\x75\x73\x74\x65\x64"
272ebfedea0SLionel Sambuc "\x43\x65\x72\x74\x69\x66\x69\x63\x61\x74\x65\x53\x65\x72\x76\x69"
273ebfedea0SLionel Sambuc "\x63\x65\x73\x2e\x63\x72\x6c\x30\x3a\xa0\x38\xa0\x36\x86\x34\x68"
274ebfedea0SLionel Sambuc "\x74\x74\x70\x3a\x2f\x2f\x63\x72\x6c\x2e\x63\x6f\x6d\x6f\x64\x6f"
275ebfedea0SLionel Sambuc "\x2e\x6e\x65\x74\x2f\x54\x72\x75\x73\x74\x65\x64\x43\x65\x72\x74"
276ebfedea0SLionel Sambuc "\x69\x66\x69\x63\x61\x74\x65\x53\x65\x72\x76\x69\x63\x65\x73\x2e"
277ebfedea0SLionel Sambuc "\x63\x72\x6c\x30\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x05"
278ebfedea0SLionel Sambuc "\x05\x00\x03\x82\x01\x01\x00\xc8\x93\x81\x3b\x89\xb4\xaf\xb8\x84"
279ebfedea0SLionel Sambuc "\x12\x4c\x8d\xd2\xf0\xdb\x70\xba\x57\x86\x15\x34\x10\xb9\x2f\x7f"
280ebfedea0SLionel Sambuc "\x1e\xb0\xa8\x89\x60\xa1\x8a\xc2\x77\x0c\x50\x4a\x9b\x00\x8b\xd8"
281ebfedea0SLionel Sambuc "\x8b\xf4\x41\xe2\xd0\x83\x8a\x4a\x1c\x14\x06\xb0\xa3\x68\x05\x70"
282ebfedea0SLionel Sambuc "\x31\x30\xa7\x53\x9b\x0e\xe9\x4a\xa0\x58\x69\x67\x0e\xae\x9d\xf6"
283ebfedea0SLionel Sambuc "\xa5\x2c\x41\xbf\x3c\x06\x6b\xe4\x59\xcc\x6d\x10\xf1\x96\x6f\x1f"
284ebfedea0SLionel Sambuc "\xdf\xf4\x04\x02\xa4\x9f\x45\x3e\xc8\xd8\xfa\x36\x46\x44\x50\x3f"
285ebfedea0SLionel Sambuc "\x82\x97\x91\x1f\x28\xdb\x18\x11\x8c\x2a\xe4\x65\x83\x57\x12\x12"
286ebfedea0SLionel Sambuc "\x8c\x17\x3f\x94\x36\xfe\x5d\xb0\xc0\x04\x77\x13\xb8\xf4\x15\xd5"
287ebfedea0SLionel Sambuc "\x3f\x38\xcc\x94\x3a\x55\xd0\xac\x98\xf5\xba\x00\x5f\xe0\x86\x19"
288ebfedea0SLionel Sambuc "\x81\x78\x2f\x28\xc0\x7e\xd3\xcc\x42\x0a\xf5\xae\x50\xa0\xd1\x3e"
289ebfedea0SLionel Sambuc "\xc6\xa1\x71\xec\x3f\xa0\x20\x8c\x66\x3a\x89\xb4\x8e\xd4\xd8\xb1"
290ebfedea0SLionel Sambuc "\x4d\x25\x47\xee\x2f\x88\xc8\xb5\xe1\x05\x45\xc0\xbe\x14\x71\xde"
291ebfedea0SLionel Sambuc "\x7a\xfd\x8e\x7b\x7d\x4d\x08\x96\xa5\x12\x73\xf0\x2d\xca\x37\x27"
292ebfedea0SLionel Sambuc "\x74\x12\x27\x4c\xcb\xb6\x97\xe9\xd9\xae\x08\x6d\x5a\x39\x40\xdd"
293ebfedea0SLionel Sambuc "\x05\x47\x75\x6a\x5a\x21\xb3\xa3\x18\xcf\x4e\xf7\x2e\x57\xb7\x98"
294ebfedea0SLionel Sambuc "\x70\x5e\xc8\xc4\x78\xb0\x62";
295ebfedea0SLionel Sambuc
296ebfedea0SLionel Sambuc
297ebfedea0SLionel Sambuc static int
compare_subject(hx509_cert c1,hx509_cert c2,int * l)298ebfedea0SLionel Sambuc compare_subject(hx509_cert c1, hx509_cert c2, int *l)
299ebfedea0SLionel Sambuc {
300ebfedea0SLionel Sambuc hx509_name n1, n2;
301ebfedea0SLionel Sambuc int ret;
302ebfedea0SLionel Sambuc
303ebfedea0SLionel Sambuc ret = hx509_cert_get_subject(c1, &n1);
304ebfedea0SLionel Sambuc if (ret) return 1;
305ebfedea0SLionel Sambuc ret = hx509_cert_get_subject(c2, &n2);
306ebfedea0SLionel Sambuc if (ret) return 1;
307ebfedea0SLionel Sambuc
308ebfedea0SLionel Sambuc *l = hx509_name_cmp(n1, n2);
309ebfedea0SLionel Sambuc hx509_name_free(&n1);
310ebfedea0SLionel Sambuc hx509_name_free(&n2);
311ebfedea0SLionel Sambuc
312ebfedea0SLionel Sambuc return 0;
313ebfedea0SLionel Sambuc }
314ebfedea0SLionel Sambuc
315ebfedea0SLionel Sambuc static int
test_compare(hx509_context context)316ebfedea0SLionel Sambuc test_compare(hx509_context context)
317ebfedea0SLionel Sambuc {
318ebfedea0SLionel Sambuc int ret;
319ebfedea0SLionel Sambuc hx509_cert c1, c2, c3;
320ebfedea0SLionel Sambuc int l0, l1, l2, l3;
321ebfedea0SLionel Sambuc
322ebfedea0SLionel Sambuc /* check transative properties of name compare function */
323ebfedea0SLionel Sambuc
324ebfedea0SLionel Sambuc ret = hx509_cert_init_data(context, certdata1, sizeof(certdata1) - 1, &c1);
325ebfedea0SLionel Sambuc if (ret) return 1;
326ebfedea0SLionel Sambuc
327ebfedea0SLionel Sambuc ret = hx509_cert_init_data(context, certdata2, sizeof(certdata2) - 1, &c2);
328ebfedea0SLionel Sambuc if (ret) return 1;
329ebfedea0SLionel Sambuc
330ebfedea0SLionel Sambuc ret = hx509_cert_init_data(context, certdata3, sizeof(certdata3) - 1, &c3);
331ebfedea0SLionel Sambuc if (ret) return 1;
332ebfedea0SLionel Sambuc
333ebfedea0SLionel Sambuc ret = compare_subject(c1, c1, &l0);
334ebfedea0SLionel Sambuc if (ret) return 1;
335ebfedea0SLionel Sambuc ret = compare_subject(c1, c2, &l1);
336ebfedea0SLionel Sambuc if (ret) return 1;
337ebfedea0SLionel Sambuc ret = compare_subject(c1, c3, &l2);
338ebfedea0SLionel Sambuc if (ret) return 1;
339ebfedea0SLionel Sambuc ret = compare_subject(c2, c3, &l3);
340ebfedea0SLionel Sambuc if (ret) return 1;
341ebfedea0SLionel Sambuc
342ebfedea0SLionel Sambuc if (l0 != 0) return 1;
343ebfedea0SLionel Sambuc if (l2 < l1) return 1;
344ebfedea0SLionel Sambuc if (l3 < l2) return 1;
345ebfedea0SLionel Sambuc if (l3 < l1) return 1;
346ebfedea0SLionel Sambuc
347ebfedea0SLionel Sambuc hx509_cert_free(c1);
348ebfedea0SLionel Sambuc hx509_cert_free(c2);
349ebfedea0SLionel Sambuc hx509_cert_free(c3);
350ebfedea0SLionel Sambuc
351ebfedea0SLionel Sambuc return 0;
352ebfedea0SLionel Sambuc }
353ebfedea0SLionel Sambuc
354ebfedea0SLionel Sambuc
355ebfedea0SLionel Sambuc int
main(int argc,char ** argv)356ebfedea0SLionel Sambuc main(int argc, char **argv)
357ebfedea0SLionel Sambuc {
358ebfedea0SLionel Sambuc hx509_context context;
359ebfedea0SLionel Sambuc int ret = 0;
360ebfedea0SLionel Sambuc
361ebfedea0SLionel Sambuc ret = hx509_context_init(&context);
362ebfedea0SLionel Sambuc if (ret)
363ebfedea0SLionel Sambuc errx(1, "hx509_context_init failed with %d", ret);
364ebfedea0SLionel Sambuc
365ebfedea0SLionel Sambuc ret += test_name(context, "CN=foo,C=SE");
366ebfedea0SLionel Sambuc ret += test_name(context, "CN=foo,CN=kaka,CN=FOO,DC=ad1,C=SE");
367ebfedea0SLionel Sambuc ret += test_name(context, "1.2.3.4=foo,C=SE");
368ebfedea0SLionel Sambuc ret += test_name_fail(context, "=");
369ebfedea0SLionel Sambuc ret += test_name_fail(context, "CN=foo,=foo");
370ebfedea0SLionel Sambuc ret += test_name_fail(context, "CN=foo,really-unknown-type=foo");
371ebfedea0SLionel Sambuc
372ebfedea0SLionel Sambuc ret += test_expand(context, "UID=${uid},C=SE", "UID=lha,C=SE");
373ebfedea0SLionel Sambuc ret += test_expand(context, "UID=foo${uid},C=SE", "UID=foolha,C=SE");
374ebfedea0SLionel Sambuc ret += test_expand(context, "UID=${uid}bar,C=SE", "UID=lhabar,C=SE");
375ebfedea0SLionel Sambuc ret += test_expand(context, "UID=f${uid}b,C=SE", "UID=flhab,C=SE");
376ebfedea0SLionel Sambuc ret += test_expand(context, "UID=${uid}${uid},C=SE", "UID=lhalha,C=SE");
377ebfedea0SLionel Sambuc ret += test_expand(context, "UID=${uid}{uid},C=SE", "UID=lha{uid},C=SE");
378ebfedea0SLionel Sambuc
379ebfedea0SLionel Sambuc ret += test_compare(context);
380ebfedea0SLionel Sambuc
381ebfedea0SLionel Sambuc hx509_context_free(&context);
382ebfedea0SLionel Sambuc
383ebfedea0SLionel Sambuc return ret;
384ebfedea0SLionel Sambuc }
385