v3ext.c revision 1.1 1 1.1 christos /*
2 1.1 christos * Copyright 2016-2025 The OpenSSL Project Authors. All Rights Reserved.
3 1.1 christos *
4 1.1 christos * Licensed under the Apache License 2.0 (the "License"). You may not use
5 1.1 christos * this file except in compliance with the License. You can obtain a copy
6 1.1 christos * in the file LICENSE in the source distribution or at
7 1.1 christos * https://www.openssl.org/source/license.html
8 1.1 christos */
9 1.1 christos
10 1.1 christos #include <stdio.h>
11 1.1 christos #include <string.h>
12 1.1 christos #include <openssl/x509.h>
13 1.1 christos #include <openssl/x509v3.h>
14 1.1 christos #include <openssl/pem.h>
15 1.1 christos #include <openssl/err.h>
16 1.1 christos #include "internal/nelem.h"
17 1.1 christos
18 1.1 christos #include "testutil.h"
19 1.1 christos
20 1.1 christos static const char *infile;
21 1.1 christos
22 1.1 christos static int test_pathlen(void)
23 1.1 christos {
24 1.1 christos X509 *x = NULL;
25 1.1 christos BIO *b = NULL;
26 1.1 christos long pathlen;
27 1.1 christos int ret = 0;
28 1.1 christos
29 1.1 christos if (!TEST_ptr(b = BIO_new_file(infile, "r"))
30 1.1 christos || !TEST_ptr(x = PEM_read_bio_X509(b, NULL, NULL, NULL))
31 1.1 christos || !TEST_int_eq(pathlen = X509_get_pathlen(x), 6))
32 1.1 christos goto end;
33 1.1 christos
34 1.1 christos ret = 1;
35 1.1 christos
36 1.1 christos end:
37 1.1 christos BIO_free(b);
38 1.1 christos X509_free(x);
39 1.1 christos return ret;
40 1.1 christos }
41 1.1 christos
42 1.1 christos #ifndef OPENSSL_NO_RFC3779
43 1.1 christos static int test_asid(void)
44 1.1 christos {
45 1.1 christos ASN1_INTEGER *val1 = NULL, *val2 = NULL;
46 1.1 christos ASIdentifiers *asid1 = ASIdentifiers_new(), *asid2 = ASIdentifiers_new(),
47 1.1 christos *asid3 = ASIdentifiers_new(), *asid4 = ASIdentifiers_new();
48 1.1 christos int testresult = 0;
49 1.1 christos
50 1.1 christos if (!TEST_ptr(asid1)
51 1.1 christos || !TEST_ptr(asid2)
52 1.1 christos || !TEST_ptr(asid3))
53 1.1 christos goto err;
54 1.1 christos
55 1.1 christos if (!TEST_ptr(val1 = ASN1_INTEGER_new())
56 1.1 christos || !TEST_true(ASN1_INTEGER_set_int64(val1, 64496)))
57 1.1 christos goto err;
58 1.1 christos
59 1.1 christos if (!TEST_true(X509v3_asid_add_id_or_range(asid1, V3_ASID_ASNUM, val1, NULL)))
60 1.1 christos goto err;
61 1.1 christos
62 1.1 christos val1 = NULL;
63 1.1 christos if (!TEST_ptr(val2 = ASN1_INTEGER_new())
64 1.1 christos || !TEST_true(ASN1_INTEGER_set_int64(val2, 64497)))
65 1.1 christos goto err;
66 1.1 christos
67 1.1 christos if (!TEST_true(X509v3_asid_add_id_or_range(asid2, V3_ASID_ASNUM, val2, NULL)))
68 1.1 christos goto err;
69 1.1 christos
70 1.1 christos val2 = NULL;
71 1.1 christos if (!TEST_ptr(val1 = ASN1_INTEGER_new())
72 1.1 christos || !TEST_true(ASN1_INTEGER_set_int64(val1, 64496))
73 1.1 christos || !TEST_ptr(val2 = ASN1_INTEGER_new())
74 1.1 christos || !TEST_true(ASN1_INTEGER_set_int64(val2, 64497)))
75 1.1 christos goto err;
76 1.1 christos
77 1.1 christos /*
78 1.1 christos * Just tests V3_ASID_ASNUM for now. Could be extended at some point to also
79 1.1 christos * test V3_ASID_RDI if we think it is worth it.
80 1.1 christos */
81 1.1 christos if (!TEST_true(X509v3_asid_add_id_or_range(asid3, V3_ASID_ASNUM, val1, val2)))
82 1.1 christos goto err;
83 1.1 christos val1 = val2 = NULL;
84 1.1 christos
85 1.1 christos /* Actual subsets */
86 1.1 christos if (!TEST_true(X509v3_asid_subset(NULL, NULL))
87 1.1 christos || !TEST_true(X509v3_asid_subset(NULL, asid1))
88 1.1 christos || !TEST_true(X509v3_asid_subset(asid1, asid1))
89 1.1 christos || !TEST_true(X509v3_asid_subset(asid2, asid2))
90 1.1 christos || !TEST_true(X509v3_asid_subset(asid1, asid3))
91 1.1 christos || !TEST_true(X509v3_asid_subset(asid2, asid3))
92 1.1 christos || !TEST_true(X509v3_asid_subset(asid3, asid3))
93 1.1 christos || !TEST_true(X509v3_asid_subset(asid4, asid1))
94 1.1 christos || !TEST_true(X509v3_asid_subset(asid4, asid2))
95 1.1 christos || !TEST_true(X509v3_asid_subset(asid4, asid3)))
96 1.1 christos goto err;
97 1.1 christos
98 1.1 christos /* Not subsets */
99 1.1 christos if (!TEST_false(X509v3_asid_subset(asid1, NULL))
100 1.1 christos || !TEST_false(X509v3_asid_subset(asid1, asid2))
101 1.1 christos || !TEST_false(X509v3_asid_subset(asid2, asid1))
102 1.1 christos || !TEST_false(X509v3_asid_subset(asid3, asid1))
103 1.1 christos || !TEST_false(X509v3_asid_subset(asid3, asid2))
104 1.1 christos || !TEST_false(X509v3_asid_subset(asid1, asid4))
105 1.1 christos || !TEST_false(X509v3_asid_subset(asid2, asid4))
106 1.1 christos || !TEST_false(X509v3_asid_subset(asid3, asid4)))
107 1.1 christos goto err;
108 1.1 christos
109 1.1 christos testresult = 1;
110 1.1 christos err:
111 1.1 christos ASN1_INTEGER_free(val1);
112 1.1 christos ASN1_INTEGER_free(val2);
113 1.1 christos ASIdentifiers_free(asid1);
114 1.1 christos ASIdentifiers_free(asid2);
115 1.1 christos ASIdentifiers_free(asid3);
116 1.1 christos ASIdentifiers_free(asid4);
117 1.1 christos return testresult;
118 1.1 christos }
119 1.1 christos
120 1.1 christos static struct ip_ranges_st {
121 1.1 christos const unsigned int afi;
122 1.1 christos const char *ip1;
123 1.1 christos const char *ip2;
124 1.1 christos int rorp;
125 1.1 christos } ranges[] = {
126 1.1 christos { IANA_AFI_IPV4, "192.168.0.0", "192.168.0.1", IPAddressOrRange_addressPrefix},
127 1.1 christos { IANA_AFI_IPV4, "192.168.0.0", "192.168.0.2", IPAddressOrRange_addressRange},
128 1.1 christos { IANA_AFI_IPV4, "192.168.0.0", "192.168.0.3", IPAddressOrRange_addressPrefix},
129 1.1 christos { IANA_AFI_IPV4, "192.168.0.0", "192.168.0.254", IPAddressOrRange_addressRange},
130 1.1 christos { IANA_AFI_IPV4, "192.168.0.0", "192.168.0.255", IPAddressOrRange_addressPrefix},
131 1.1 christos { IANA_AFI_IPV4, "192.168.0.1", "192.168.0.255", IPAddressOrRange_addressRange},
132 1.1 christos { IANA_AFI_IPV4, "192.168.0.1", "192.168.0.1", IPAddressOrRange_addressPrefix},
133 1.1 christos { IANA_AFI_IPV4, "192.168.0.0", "192.168.255.255", IPAddressOrRange_addressPrefix},
134 1.1 christos { IANA_AFI_IPV4, "192.168.1.0", "192.168.255.255", IPAddressOrRange_addressRange},
135 1.1 christos { IANA_AFI_IPV6, "2001:0db8::0", "2001:0db8::1", IPAddressOrRange_addressPrefix},
136 1.1 christos { IANA_AFI_IPV6, "2001:0db8::0", "2001:0db8::2", IPAddressOrRange_addressRange},
137 1.1 christos { IANA_AFI_IPV6, "2001:0db8::0", "2001:0db8::3", IPAddressOrRange_addressPrefix},
138 1.1 christos { IANA_AFI_IPV6, "2001:0db8::0", "2001:0db8::fffe", IPAddressOrRange_addressRange},
139 1.1 christos { IANA_AFI_IPV6, "2001:0db8::0", "2001:0db8::ffff", IPAddressOrRange_addressPrefix},
140 1.1 christos { IANA_AFI_IPV6, "2001:0db8::1", "2001:0db8::ffff", IPAddressOrRange_addressRange},
141 1.1 christos { IANA_AFI_IPV6, "2001:0db8::1", "2001:0db8::1", IPAddressOrRange_addressPrefix},
142 1.1 christos { IANA_AFI_IPV6, "2001:0db8::0:0", "2001:0db8::ffff:ffff", IPAddressOrRange_addressPrefix},
143 1.1 christos { IANA_AFI_IPV6, "2001:0db8::1:0", "2001:0db8::ffff:ffff", IPAddressOrRange_addressRange}
144 1.1 christos };
145 1.1 christos
146 1.1 christos static int check_addr(IPAddrBlocks *addr, int type)
147 1.1 christos {
148 1.1 christos IPAddressFamily *fam;
149 1.1 christos IPAddressOrRange *aorr;
150 1.1 christos
151 1.1 christos if (!TEST_int_eq(sk_IPAddressFamily_num(addr), 1))
152 1.1 christos return 0;
153 1.1 christos
154 1.1 christos fam = sk_IPAddressFamily_value(addr, 0);
155 1.1 christos if (!TEST_ptr(fam))
156 1.1 christos return 0;
157 1.1 christos
158 1.1 christos if (!TEST_int_eq(fam->ipAddressChoice->type, IPAddressChoice_addressesOrRanges))
159 1.1 christos return 0;
160 1.1 christos
161 1.1 christos if (!TEST_int_eq(sk_IPAddressOrRange_num(fam->ipAddressChoice->u.addressesOrRanges), 1))
162 1.1 christos return 0;
163 1.1 christos
164 1.1 christos aorr = sk_IPAddressOrRange_value(fam->ipAddressChoice->u.addressesOrRanges, 0);
165 1.1 christos if (!TEST_ptr(aorr))
166 1.1 christos return 0;
167 1.1 christos
168 1.1 christos if (!TEST_int_eq(aorr->type, type))
169 1.1 christos return 0;
170 1.1 christos
171 1.1 christos return 1;
172 1.1 christos }
173 1.1 christos
174 1.1 christos static int test_addr_ranges(void)
175 1.1 christos {
176 1.1 christos IPAddrBlocks *addr = NULL;
177 1.1 christos ASN1_OCTET_STRING *ip1 = NULL, *ip2 = NULL;
178 1.1 christos size_t i;
179 1.1 christos int testresult = 0;
180 1.1 christos
181 1.1 christos for (i = 0; i < OSSL_NELEM(ranges); i++) {
182 1.1 christos addr = sk_IPAddressFamily_new_null();
183 1.1 christos if (!TEST_ptr(addr))
184 1.1 christos goto end;
185 1.1 christos /*
186 1.1 christos * Has the side effect of installing the comparison function onto the
187 1.1 christos * stack.
188 1.1 christos */
189 1.1 christos if (!TEST_true(X509v3_addr_canonize(addr)))
190 1.1 christos goto end;
191 1.1 christos
192 1.1 christos ip1 = a2i_IPADDRESS(ranges[i].ip1);
193 1.1 christos if (!TEST_ptr(ip1))
194 1.1 christos goto end;
195 1.1 christos if (!TEST_true(ip1->length == 4 || ip1->length == 16))
196 1.1 christos goto end;
197 1.1 christos ip2 = a2i_IPADDRESS(ranges[i].ip2);
198 1.1 christos if (!TEST_ptr(ip2))
199 1.1 christos goto end;
200 1.1 christos if (!TEST_int_eq(ip2->length, ip1->length))
201 1.1 christos goto end;
202 1.1 christos if (!TEST_true(memcmp(ip1->data, ip2->data, ip1->length) <= 0))
203 1.1 christos goto end;
204 1.1 christos
205 1.1 christos if (!TEST_true(X509v3_addr_add_range(addr, ranges[i].afi, NULL, ip1->data, ip2->data)))
206 1.1 christos goto end;
207 1.1 christos
208 1.1 christos if (!TEST_true(X509v3_addr_is_canonical(addr)))
209 1.1 christos goto end;
210 1.1 christos
211 1.1 christos if (!check_addr(addr, ranges[i].rorp))
212 1.1 christos goto end;
213 1.1 christos
214 1.1 christos sk_IPAddressFamily_pop_free(addr, IPAddressFamily_free);
215 1.1 christos addr = NULL;
216 1.1 christos ASN1_OCTET_STRING_free(ip1);
217 1.1 christos ASN1_OCTET_STRING_free(ip2);
218 1.1 christos ip1 = ip2 = NULL;
219 1.1 christos }
220 1.1 christos
221 1.1 christos testresult = 1;
222 1.1 christos end:
223 1.1 christos sk_IPAddressFamily_pop_free(addr, IPAddressFamily_free);
224 1.1 christos ASN1_OCTET_STRING_free(ip1);
225 1.1 christos ASN1_OCTET_STRING_free(ip2);
226 1.1 christos return testresult;
227 1.1 christos }
228 1.1 christos
229 1.1 christos static int test_addr_fam_len(void)
230 1.1 christos {
231 1.1 christos int testresult = 0;
232 1.1 christos IPAddrBlocks *addr = NULL;
233 1.1 christos IPAddressFamily *f1 = NULL;
234 1.1 christos ASN1_OCTET_STRING *ip1 = NULL, *ip2 = NULL;
235 1.1 christos unsigned char key[6];
236 1.1 christos unsigned int keylen;
237 1.1 christos unsigned afi = IANA_AFI_IPV4;
238 1.1 christos
239 1.1 christos /* Create the IPAddrBlocks with a good IPAddressFamily */
240 1.1 christos addr = sk_IPAddressFamily_new_null();
241 1.1 christos if (!TEST_ptr(addr))
242 1.1 christos goto end;
243 1.1 christos ip1 = a2i_IPADDRESS(ranges[0].ip1);
244 1.1 christos if (!TEST_ptr(ip1))
245 1.1 christos goto end;
246 1.1 christos ip2 = a2i_IPADDRESS(ranges[0].ip2);
247 1.1 christos if (!TEST_ptr(ip2))
248 1.1 christos goto end;
249 1.1 christos if (!TEST_true(X509v3_addr_add_range(addr, ranges[0].afi, NULL, ip1->data, ip2->data)))
250 1.1 christos goto end;
251 1.1 christos if (!TEST_true(X509v3_addr_is_canonical(addr)))
252 1.1 christos goto end;
253 1.1 christos
254 1.1 christos /* Create our malformed IPAddressFamily */
255 1.1 christos key[0] = (afi >> 8) & 0xFF;
256 1.1 christos key[1] = afi & 0xFF;
257 1.1 christos key[2] = 0xD;
258 1.1 christos key[3] = 0xE;
259 1.1 christos key[4] = 0xA;
260 1.1 christos key[5] = 0xD;
261 1.1 christos keylen = 6;
262 1.1 christos if ((f1 = IPAddressFamily_new()) == NULL)
263 1.1 christos goto end;
264 1.1 christos if (f1->ipAddressChoice == NULL &&
265 1.1 christos (f1->ipAddressChoice = IPAddressChoice_new()) == NULL)
266 1.1 christos goto end;
267 1.1 christos if (f1->addressFamily == NULL &&
268 1.1 christos (f1->addressFamily = ASN1_OCTET_STRING_new()) == NULL)
269 1.1 christos goto end;
270 1.1 christos if (!ASN1_OCTET_STRING_set(f1->addressFamily, key, keylen))
271 1.1 christos goto end;
272 1.1 christos
273 1.1 christos /* Push and transfer memory ownership to stack */
274 1.1 christos if (!sk_IPAddressFamily_push(addr, f1))
275 1.1 christos goto end;
276 1.1 christos f1 = NULL;
277 1.1 christos
278 1.1 christos /* Shouldn't be able to canonize this as the len is > 3*/
279 1.1 christos if (!TEST_false(X509v3_addr_canonize(addr)))
280 1.1 christos goto end;
281 1.1 christos
282 1.1 christos /* Pop and free the new stack element */
283 1.1 christos IPAddressFamily_free(sk_IPAddressFamily_pop(addr));
284 1.1 christos
285 1.1 christos /* Create a well-formed IPAddressFamily */
286 1.1 christos key[0] = (afi >> 8) & 0xFF;
287 1.1 christos key[1] = afi & 0xFF;
288 1.1 christos key[2] = 0x1;
289 1.1 christos keylen = 3;
290 1.1 christos if ((f1 = IPAddressFamily_new()) == NULL)
291 1.1 christos goto end;
292 1.1 christos if (f1->ipAddressChoice == NULL &&
293 1.1 christos (f1->ipAddressChoice = IPAddressChoice_new()) == NULL)
294 1.1 christos goto end;
295 1.1 christos if (f1->addressFamily == NULL &&
296 1.1 christos (f1->addressFamily = ASN1_OCTET_STRING_new()) == NULL)
297 1.1 christos goto end;
298 1.1 christos if (!ASN1_OCTET_STRING_set(f1->addressFamily, key, keylen))
299 1.1 christos goto end;
300 1.1 christos
301 1.1 christos /* Mark this as inheritance so we skip some of the is_canonize checks */
302 1.1 christos f1->ipAddressChoice->type = IPAddressChoice_inherit;
303 1.1 christos
304 1.1 christos /* Push and transfer memory ownership to stack */
305 1.1 christos if (!sk_IPAddressFamily_push(addr, f1))
306 1.1 christos goto end;
307 1.1 christos f1 = NULL;
308 1.1 christos
309 1.1 christos /* Should be able to canonize now */
310 1.1 christos if (!TEST_true(X509v3_addr_canonize(addr)))
311 1.1 christos goto end;
312 1.1 christos
313 1.1 christos testresult = 1;
314 1.1 christos end:
315 1.1 christos /* Free stack and any memory owned by detached element */
316 1.1 christos IPAddressFamily_free(f1);
317 1.1 christos sk_IPAddressFamily_pop_free(addr, IPAddressFamily_free);
318 1.1 christos
319 1.1 christos ASN1_OCTET_STRING_free(ip1);
320 1.1 christos ASN1_OCTET_STRING_free(ip2);
321 1.1 christos return testresult;
322 1.1 christos }
323 1.1 christos
324 1.1 christos static struct extvalues_st {
325 1.1 christos const char *value;
326 1.1 christos int pass;
327 1.1 christos } extvalues[] = {
328 1.1 christos /* No prefix is ok */
329 1.1 christos { "sbgp-ipAddrBlock = IPv4:192.0.0.1\n", 1 },
330 1.1 christos { "sbgp-ipAddrBlock = IPv4:192.0.0.0/0\n", 1 },
331 1.1 christos { "sbgp-ipAddrBlock = IPv4:192.0.0.0/1\n", 1 },
332 1.1 christos { "sbgp-ipAddrBlock = IPv4:192.0.0.0/32\n", 1 },
333 1.1 christos /* Prefix is too long */
334 1.1 christos { "sbgp-ipAddrBlock = IPv4:192.0.0.0/33\n", 0 },
335 1.1 christos /* Unreasonably large prefix */
336 1.1 christos { "sbgp-ipAddrBlock = IPv4:192.0.0.0/12341234\n", 0 },
337 1.1 christos /* Invalid IP addresses */
338 1.1 christos { "sbgp-ipAddrBlock = IPv4:192.0.0\n", 0 },
339 1.1 christos { "sbgp-ipAddrBlock = IPv4:256.0.0.0\n", 0 },
340 1.1 christos { "sbgp-ipAddrBlock = IPv4:-1.0.0.0\n", 0 },
341 1.1 christos { "sbgp-ipAddrBlock = IPv4:192.0.0.0.0\n", 0 },
342 1.1 christos { "sbgp-ipAddrBlock = IPv3:192.0.0.0\n", 0 },
343 1.1 christos
344 1.1 christos /* IPv6 */
345 1.1 christos /* No prefix is ok */
346 1.1 christos { "sbgp-ipAddrBlock = IPv6:2001:db8::\n", 1 },
347 1.1 christos { "sbgp-ipAddrBlock = IPv6:2001::db8\n", 1 },
348 1.1 christos { "sbgp-ipAddrBlock = IPv6:2001:0db8:0000:0000:0000:0000:0000:0000\n", 1 },
349 1.1 christos { "sbgp-ipAddrBlock = IPv6:2001:db8::/0\n", 1 },
350 1.1 christos { "sbgp-ipAddrBlock = IPv6:2001:db8::/1\n", 1 },
351 1.1 christos { "sbgp-ipAddrBlock = IPv6:2001:db8::/32\n", 1 },
352 1.1 christos { "sbgp-ipAddrBlock = IPv6:2001:0db8:0000:0000:0000:0000:0000:0000/32\n", 1 },
353 1.1 christos { "sbgp-ipAddrBlock = IPv6:2001:db8::/128\n", 1 },
354 1.1 christos /* Prefix is too long */
355 1.1 christos { "sbgp-ipAddrBlock = IPv6:2001:db8::/129\n", 0 },
356 1.1 christos /* Unreasonably large prefix */
357 1.1 christos { "sbgp-ipAddrBlock = IPv6:2001:db8::/12341234\n", 0 },
358 1.1 christos /* Invalid IP addresses */
359 1.1 christos /* Not enough blocks of numbers */
360 1.1 christos { "sbgp-ipAddrBlock = IPv6:2001:0db8:0000:0000:0000:0000:0000\n", 0 },
361 1.1 christos /* Too many blocks of numbers */
362 1.1 christos { "sbgp-ipAddrBlock = IPv6:2001:0db8:0000:0000:0000:0000:0000:0000:0000\n", 0 },
363 1.1 christos /* First value too large */
364 1.1 christos { "sbgp-ipAddrBlock = IPv6:1ffff:0db8:0000:0000:0000:0000:0000:0000\n", 0 },
365 1.1 christos /* First value with invalid characters */
366 1.1 christos { "sbgp-ipAddrBlock = IPv6:fffg:0db8:0000:0000:0000:0000:0000:0000\n", 0 },
367 1.1 christos /* First value is negative */
368 1.1 christos { "sbgp-ipAddrBlock = IPv6:-1:0db8:0000:0000:0000:0000:0000:0000\n", 0 }
369 1.1 christos };
370 1.1 christos
371 1.1 christos static int test_ext_syntax(void)
372 1.1 christos {
373 1.1 christos size_t i;
374 1.1 christos int testresult = 1;
375 1.1 christos
376 1.1 christos for (i = 0; i < OSSL_NELEM(extvalues); i++) {
377 1.1 christos X509V3_CTX ctx;
378 1.1 christos BIO *extbio = BIO_new_mem_buf(extvalues[i].value,
379 1.1 christos strlen(extvalues[i].value));
380 1.1 christos CONF *conf;
381 1.1 christos long eline;
382 1.1 christos
383 1.1 christos if (!TEST_ptr(extbio))
384 1.1 christos return 0 ;
385 1.1 christos
386 1.1 christos conf = NCONF_new_ex(NULL, NULL);
387 1.1 christos if (!TEST_ptr(conf)) {
388 1.1 christos BIO_free(extbio);
389 1.1 christos return 0;
390 1.1 christos }
391 1.1 christos if (!TEST_long_gt(NCONF_load_bio(conf, extbio, &eline), 0)) {
392 1.1 christos testresult = 0;
393 1.1 christos } else {
394 1.1 christos X509V3_set_ctx_test(&ctx);
395 1.1 christos X509V3_set_nconf(&ctx, conf);
396 1.1 christos
397 1.1 christos if (extvalues[i].pass) {
398 1.1 christos if (!TEST_true(X509V3_EXT_add_nconf(conf, &ctx, "default",
399 1.1 christos NULL))) {
400 1.1 christos TEST_info("Value: %s", extvalues[i].value);
401 1.1 christos testresult = 0;
402 1.1 christos }
403 1.1 christos } else {
404 1.1 christos ERR_set_mark();
405 1.1 christos if (!TEST_false(X509V3_EXT_add_nconf(conf, &ctx, "default",
406 1.1 christos NULL))) {
407 1.1 christos testresult = 0;
408 1.1 christos TEST_info("Value: %s", extvalues[i].value);
409 1.1 christos ERR_clear_last_mark();
410 1.1 christos } else {
411 1.1 christos ERR_pop_to_mark();
412 1.1 christos }
413 1.1 christos }
414 1.1 christos }
415 1.1 christos BIO_free(extbio);
416 1.1 christos NCONF_free(conf);
417 1.1 christos }
418 1.1 christos
419 1.1 christos return testresult;
420 1.1 christos }
421 1.1 christos
422 1.1 christos static int test_addr_subset(void)
423 1.1 christos {
424 1.1 christos int i;
425 1.1 christos int ret = 0;
426 1.1 christos IPAddrBlocks *addrEmpty = NULL;
427 1.1 christos IPAddrBlocks *addr[3] = { NULL, NULL };
428 1.1 christos ASN1_OCTET_STRING *ip1[3] = { NULL, NULL };
429 1.1 christos ASN1_OCTET_STRING *ip2[3] = { NULL, NULL };
430 1.1 christos int sz = OSSL_NELEM(addr);
431 1.1 christos
432 1.1 christos for (i = 0; i < sz; ++i) {
433 1.1 christos /* Create the IPAddrBlocks with a good IPAddressFamily */
434 1.1 christos if (!TEST_ptr(addr[i] = sk_IPAddressFamily_new_null())
435 1.1 christos || !TEST_ptr(ip1[i] = a2i_IPADDRESS(ranges[i].ip1))
436 1.1 christos || !TEST_ptr(ip2[i] = a2i_IPADDRESS(ranges[i].ip2))
437 1.1 christos || !TEST_true(X509v3_addr_add_range(addr[i], ranges[i].afi, NULL,
438 1.1 christos ip1[i]->data, ip2[i]->data)))
439 1.1 christos goto end;
440 1.1 christos }
441 1.1 christos
442 1.1 christos ret = TEST_ptr(addrEmpty = sk_IPAddressFamily_new_null())
443 1.1 christos && TEST_true(X509v3_addr_subset(NULL, NULL))
444 1.1 christos && TEST_true(X509v3_addr_subset(NULL, addr[0]))
445 1.1 christos && TEST_true(X509v3_addr_subset(addrEmpty, addr[0]))
446 1.1 christos && TEST_true(X509v3_addr_subset(addr[0], addr[0]))
447 1.1 christos && TEST_true(X509v3_addr_subset(addr[0], addr[1]))
448 1.1 christos && TEST_true(X509v3_addr_subset(addr[0], addr[2]))
449 1.1 christos && TEST_true(X509v3_addr_subset(addr[1], addr[2]))
450 1.1 christos && TEST_false(X509v3_addr_subset(addr[0], NULL))
451 1.1 christos && TEST_false(X509v3_addr_subset(addr[1], addr[0]))
452 1.1 christos && TEST_false(X509v3_addr_subset(addr[2], addr[1]))
453 1.1 christos && TEST_false(X509v3_addr_subset(addr[0], addrEmpty));
454 1.1 christos end:
455 1.1 christos sk_IPAddressFamily_pop_free(addrEmpty, IPAddressFamily_free);
456 1.1 christos for (i = 0; i < sz; ++i) {
457 1.1 christos sk_IPAddressFamily_pop_free(addr[i], IPAddressFamily_free);
458 1.1 christos ASN1_OCTET_STRING_free(ip1[i]);
459 1.1 christos ASN1_OCTET_STRING_free(ip2[i]);
460 1.1 christos }
461 1.1 christos return ret;
462 1.1 christos }
463 1.1 christos
464 1.1 christos #endif /* OPENSSL_NO_RFC3779 */
465 1.1 christos
466 1.1 christos OPT_TEST_DECLARE_USAGE("cert.pem\n")
467 1.1 christos
468 1.1 christos int setup_tests(void)
469 1.1 christos {
470 1.1 christos if (!test_skip_common_options()) {
471 1.1 christos TEST_error("Error parsing test options\n");
472 1.1 christos return 0;
473 1.1 christos }
474 1.1 christos
475 1.1 christos if (!TEST_ptr(infile = test_get_argument(0)))
476 1.1 christos return 0;
477 1.1 christos
478 1.1 christos ADD_TEST(test_pathlen);
479 1.1 christos #ifndef OPENSSL_NO_RFC3779
480 1.1 christos ADD_TEST(test_asid);
481 1.1 christos ADD_TEST(test_addr_ranges);
482 1.1 christos ADD_TEST(test_ext_syntax);
483 1.1 christos ADD_TEST(test_addr_fam_len);
484 1.1 christos ADD_TEST(test_addr_subset);
485 1.1 christos #endif /* OPENSSL_NO_RFC3779 */
486 1.1 christos return 1;
487 1.1 christos }
488