summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/regress/lib/libcrypto/x509/constraints.c69
1 files changed, 57 insertions, 12 deletions
diff --git a/src/regress/lib/libcrypto/x509/constraints.c b/src/regress/lib/libcrypto/x509/constraints.c
index b6c4e79c16..136dd07f6e 100644
--- a/src/regress/lib/libcrypto/x509/constraints.c
+++ b/src/regress/lib/libcrypto/x509/constraints.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: constraints.c,v 1.20 2026/05/26 09:35:53 jsing Exp $ */ 1/* $OpenBSD: constraints.c,v 1.21 2026/07/14 15:54:14 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2020 Bob Beck <beck@openbsd.org> 3 * Copyright (c) 2020 Bob Beck <beck@openbsd.org>
4 * 4 *
@@ -160,6 +160,10 @@ unsigned char *invaliduri[] = {
160 "https://192.168..1.1/", 160 "https://192.168..1.1/",
161 "https://.2001:0DB8:AC10:FE01::/", 161 "https://.2001:0DB8:AC10:FE01::/",
162 "https://.2001:0DB8:AC10:FE01::|/", 162 "https://.2001:0DB8:AC10:FE01::|/",
163 "https://2001:0DB8:AC10:FE01::1/",
164 "https://beck@openbsd.org@example.com",
165 "https://beck:password@openbsd.org:4433:example.com/",
166 "//:/",
163 "///", 167 "///",
164 "//", 168 "//",
165 "/", 169 "/",
@@ -167,13 +171,47 @@ unsigned char *invaliduri[] = {
167 NULL, 171 NULL,
168}; 172};
169 173
170unsigned char *validuri[] = { 174struct uri_test {
171 "https://www.openbsd.org/meep/meep/meep/", 175 unsigned char *uri;
172 "https://192.168.1.1/", 176 unsigned char *hostpart;
173 "https://2001:0DB8:AC10:FE01::/", 177};
174 "https://192.168.1/", /* Not an IP, but valid component */ 178
175 "https://999.999.999.999/", /* Not an IP, but valid component */ 179static const struct uri_test validuri[] = {
176 NULL, 180 {
181 .uri = "https://www.openbsd.org/meep/meep/meep/",
182 .hostpart = "www.openbsd.org",
183 },
184 {
185 .uri = "https://beck:password@openbsd.org:4433/",
186 .hostpart = "openbsd.org",
187 },
188 {
189 .uri = "https://192.168.1.1/",
190 .hostpart = "192.168.1.1",
191 },
192 {
193 .uri = "https://[2001:0DB8:AC10:FE01::1]/",
194 .hostpart = "[2001:0DB8:AC10:FE01::1]",
195 },
196 {
197 .uri = "https://[2001:0DB8:AC10:FE01::1]:443/",
198 .hostpart = "[2001:0DB8:AC10:FE01::1]",
199 },
200 {
201 .uri = "https://beck:password@[2001:0DB8:AC10:FE01::1]:443/",
202 .hostpart = "[2001:0DB8:AC10:FE01::1]",
203 },
204 {
205 .uri = "https://192.168.1/", /* Not an IP, but valid component */
206 .hostpart = "192.168.1",
207 },
208 {
209 .uri = "https://999.999.999.999/", /* Not an IP, but valid component */
210 .hostpart = "999.999.999.999",
211 },
212 {
213 .uri = NULL,
214 },
177}; 215};
178 216
179static int 217static int
@@ -395,11 +433,17 @@ test_valid_uri(void)
395 int j, failure = 0; 433 int j, failure = 0;
396 char *hostpart = NULL; 434 char *hostpart = NULL;
397 435
398 for (j = 0; validuri[j] != NULL; j++) { 436 for (j = 0; validuri[j].uri != NULL; j++) {
399 if (x509_constraints_uri_host(validuri[j], 437 if (x509_constraints_uri_host(validuri[j].uri,
400 strlen(validuri[j]), &hostpart) == 0) { 438 strlen(validuri[j].uri), &hostpart) == 0) {
401 FAIL("Valid URI '%s' NOT accepted\n", 439 FAIL("Valid URI '%s' NOT accepted\n",
402 validuri[j]); 440 validuri[j].uri);
441 failure = 1;
442 goto done;
443 }
444 if (strcmp(hostpart, validuri[j].hostpart) != 0) {
445 FAIL("Valid URI hostpart '%s' != '%s'\n",
446 hostpart, validuri[j].hostpart);
403 failure = 1; 447 failure = 1;
404 goto done; 448 goto done;
405 } 449 }
@@ -452,6 +496,7 @@ test_constraints1(void)
452 "https://www.openbsd.net?", 496 "https://www.openbsd.net?",
453 "https://org#", 497 "https://org#",
454 "herp://beck@org:", 498 "herp://beck@org:",
499 "https://openbsd.org:password@example.com/path",
455 "///", 500 "///",
456 "//", 501 "//",
457 "/", 502 "/",