2 * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 /* Internal tests for the x509 and x509v3 modules */
15 #include <openssl/x509.h>
16 #include <openssl/x509v3.h>
18 #include "internal/nelem.h"
20 /**********************************************************************
26 #include "../crypto/x509/ext_dat.h"
27 #include "../crypto/x509/standard_exts.h"
29 static int test_standard_exts(void)
32 int prev = -1, good = 1;
33 const X509V3_EXT_METHOD **tmp;
36 for (i = 0; i < OSSL_NELEM(standard_exts); i++, tmp++) {
37 if ((*tmp)->ext_nid < prev)
39 prev = (*tmp)->ext_nid;
44 TEST_error("Extensions out of order!");
45 for (i = 0; i < STANDARD_EXTENSION_COUNT; i++, tmp++)
46 TEST_note("%d : %s", (*tmp)->ext_nid, OBJ_nid2sn((*tmp)->ext_nid));
57 static IP_TESTDATA a2i_ipaddress_tests[] = {
58 {"127.0.0.1", "\x7f\x00\x00\x01", 4},
59 {"1.2.3.4", "\x01\x02\x03\x04", 4},
60 {"1.2.3.255", "\x01\x02\x03\xff", 4},
62 {"1.2.3 .4", NULL, 0},
64 {"::1", "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", 16},
65 {"1:1:1:1:1:1:1:1", "\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01", 16},
66 {"2001:db8::ff00:42:8329", "\x20\x01\x0d\xb8\x00\x00\x00\x00\x00\x00\xff\x00\x00\x42\x83\x29", 16},
67 {"1:1:1:1:1:1:1:1.test", NULL, 0},
69 {"2001::123g", NULL, 0},
71 {"example.test", NULL, 0},
74 {"1.2.3.4 ", "\x01\x02\x03\x04", 4},
75 {" 1.2.3.4", "\x01\x02\x03\x04", 4},
76 {" 1.2.3.4 ", "\x01\x02\x03\x04", 4},
77 {"1.2.3.4.example.test", NULL, 0},
81 static int test_a2i_ipaddress(int idx)
84 ASN1_OCTET_STRING *ip;
85 int len = a2i_ipaddress_tests[idx].length;
87 ip = a2i_IPADDRESS(a2i_ipaddress_tests[idx].ipasc);
89 if (!TEST_ptr_null(ip)) {
91 TEST_note("'%s' should not be parsed as IP address", a2i_ipaddress_tests[idx].ipasc);
95 || !TEST_int_eq(ASN1_STRING_length(ip), len)
96 || !TEST_mem_eq(ASN1_STRING_get0_data(ip), len,
97 a2i_ipaddress_tests[idx].data, len)) {
101 ASN1_OCTET_STRING_free(ip);
105 int setup_tests(void)
107 ADD_TEST(test_standard_exts);
108 ADD_ALL_TESTS(test_a2i_ipaddress, OSSL_NELEM(a2i_ipaddress_tests));