diff options
| author | tb <> | 2026-05-22 05:02:46 +0000 |
|---|---|---|
| committer | tb <> | 2026-05-22 05:02:46 +0000 |
| commit | cb7546f1b31d2a3db3ce712955fa1e10a9112665 (patch) | |
| tree | a7559eadb22d78445cf9f51b6d22c2715b5cee80 /src | |
| parent | 824692d17bab6253d4686f666ec6d77a1bf474b5 (diff) | |
| download | openbsd-cb7546f1b31d2a3db3ce712955fa1e10a9112665.tar.gz openbsd-cb7546f1b31d2a3db3ce712955fa1e10a9112665.tar.bz2 openbsd-cb7546f1b31d2a3db3ce712955fa1e10a9112665.zip | |
rfc3779 test: various minor tweaks
- include length in hexdump output
- show hexdumps also if lengths don't match
- more comments and consistency
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libcrypto/x509/rfc3779/rfc3779.c | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/src/regress/lib/libcrypto/x509/rfc3779/rfc3779.c b/src/regress/lib/libcrypto/x509/rfc3779/rfc3779.c index b02c60e8c2..9c3c013fba 100644 --- a/src/regress/lib/libcrypto/x509/rfc3779/rfc3779.c +++ b/src/regress/lib/libcrypto/x509/rfc3779/rfc3779.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: rfc3779.c,v 1.14 2026/05/22 04:41:35 tb Exp $ */ | 1 | /* $OpenBSD: rfc3779.c,v 1.15 2026/05/22 05:02:46 tb Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2021 Theo Buehler <tb@openbsd.org> | 3 | * Copyright (c) 2021 Theo Buehler <tb@openbsd.org> |
| 4 | * | 4 | * |
| @@ -41,9 +41,10 @@ report_hexdump(const char *func, const char *description, const char *msg, | |||
| 41 | const unsigned char *want, size_t want_len, | 41 | const unsigned char *want, size_t want_len, |
| 42 | const unsigned char *got, size_t got_len) | 42 | const unsigned char *got, size_t got_len) |
| 43 | { | 43 | { |
| 44 | fprintf(stderr, "%s: \"%s\" %s\nwant:\n", func, description, msg); | 44 | fprintf(stderr, "%s: \"%s\" %s\nwant %zu bytes:\n", |
| 45 | func, description, msg, want_len); | ||
| 45 | hexdump(want, want_len); | 46 | hexdump(want, want_len); |
| 46 | fprintf(stderr, "got:\n"); | 47 | fprintf(stderr, "got %zu bytes:\n", got_len); |
| 47 | hexdump(got, got_len); | 48 | hexdump(got, got_len); |
| 48 | } | 49 | } |
| 49 | 50 | ||
| @@ -2031,6 +2032,7 @@ run_IPAddressFamily_cmp_ub_test(void) | |||
| 2031 | unsigned char *out = NULL; | 2032 | unsigned char *out = NULL; |
| 2032 | int out_len = 0; | 2033 | int out_len = 0; |
| 2033 | unsigned int nlri_safi = 4; | 2034 | unsigned int nlri_safi = 4; |
| 2035 | int memcmp_failed; | ||
| 2034 | int failed = 1; | 2036 | int failed = 1; |
| 2035 | 2037 | ||
| 2036 | if ((addrs = IPAddrBlocks_new()) == NULL) { | 2038 | if ((addrs = IPAddrBlocks_new()) == NULL) { |
| @@ -2041,6 +2043,7 @@ run_IPAddressFamily_cmp_ub_test(void) | |||
| 2041 | /* | 2043 | /* |
| 2042 | * Add IPv6 NLRI, inheriting | 2044 | * Add IPv6 NLRI, inheriting |
| 2043 | */ | 2045 | */ |
| 2046 | |||
| 2044 | if (!X509v3_addr_add_inherit(addrs, IANA_AFI_IPV6, &nlri_safi)) { | 2047 | if (!X509v3_addr_add_inherit(addrs, IANA_AFI_IPV6, &nlri_safi)) { |
| 2045 | fprintf(stderr, "%s: X509v3_addr_add_inherit IPv6\n", __func__); | 2048 | fprintf(stderr, "%s: X509v3_addr_add_inherit IPv6\n", __func__); |
| 2046 | goto err; | 2049 | goto err; |
| @@ -2049,6 +2052,7 @@ run_IPAddressFamily_cmp_ub_test(void) | |||
| 2049 | /* | 2052 | /* |
| 2050 | * Add IPv6, inheriting | 2053 | * Add IPv6, inheriting |
| 2051 | */ | 2054 | */ |
| 2055 | |||
| 2052 | if (!X509v3_addr_add_inherit(addrs, IANA_AFI_IPV6, NULL)) { | 2056 | if (!X509v3_addr_add_inherit(addrs, IANA_AFI_IPV6, NULL)) { |
| 2053 | fprintf(stderr, "%s: X509v3_addr_add_inherit IPv6\n", __func__); | 2057 | fprintf(stderr, "%s: X509v3_addr_add_inherit IPv6\n", __func__); |
| 2054 | goto err; | 2058 | goto err; |
| @@ -2101,13 +2105,23 @@ run_IPAddressFamily_cmp_ub_test(void) | |||
| 2101 | /* | 2105 | /* |
| 2102 | * Add IPv4, inheriting | 2106 | * Add IPv4, inheriting |
| 2103 | */ | 2107 | */ |
| 2108 | |||
| 2104 | if (!X509v3_addr_add_inherit(addrs, IANA_AFI_IPV4, NULL)) { | 2109 | if (!X509v3_addr_add_inherit(addrs, IANA_AFI_IPV4, NULL)) { |
| 2105 | fprintf(stderr, "%s: X509v3_addr_add_inherit IPv4\n", __func__); | 2110 | fprintf(stderr, "%s: X509v3_addr_add_inherit IPv4\n", __func__); |
| 2106 | goto err; | 2111 | goto err; |
| 2107 | } | 2112 | } |
| 2108 | 2113 | ||
| 2114 | /* | ||
| 2115 | * Sort the thing. | ||
| 2116 | */ | ||
| 2117 | |||
| 2109 | sk_IPAddressFamily_sort(addrs); | 2118 | sk_IPAddressFamily_sort(addrs); |
| 2110 | 2119 | ||
| 2120 | /* | ||
| 2121 | * Since addrs contains two invalid AFIs, X509v3_addr_is_canonical() | ||
| 2122 | * should reject it. Serializing works nevertheless. | ||
| 2123 | */ | ||
| 2124 | |||
| 2111 | if (X509v3_addr_is_canonical(addrs)) { | 2125 | if (X509v3_addr_is_canonical(addrs)) { |
| 2112 | fprintf(stderr, "%s: X509v3_addr_is_canonical\n", __func__); | 2126 | fprintf(stderr, "%s: X509v3_addr_is_canonical\n", __func__); |
| 2113 | goto err; | 2127 | goto err; |
| @@ -2115,16 +2129,17 @@ run_IPAddressFamily_cmp_ub_test(void) | |||
| 2115 | 2129 | ||
| 2116 | if ((out_len = i2d_IPAddrBlocks(addrs, &out)) <= 0) { | 2130 | if ((out_len = i2d_IPAddrBlocks(addrs, &out)) <= 0) { |
| 2117 | fprintf(stderr, "%s: i2d_IPAddrBlocks failed\n", __func__); | 2131 | fprintf(stderr, "%s: i2d_IPAddrBlocks failed\n", __func__); |
| 2132 | out_len = 0; | ||
| 2118 | goto err; | 2133 | goto err; |
| 2119 | } | 2134 | } |
| 2120 | 2135 | ||
| 2121 | if (invalid_block_len != (size_t)out_len) { | 2136 | memcmp_failed = 0; |
| 2122 | fprintf(stderr, "%s: length: want %zu, got %d\n", | 2137 | if (invalid_block_len != (size_t)out_len) |
| 2123 | __func__, invalid_block_len, out_len); | 2138 | memcmp_failed = 1; |
| 2124 | goto err; | 2139 | if (!memcmp_failed) |
| 2125 | } | 2140 | memcmp_failed = memcmp(invalid_block, out, out_len) != 0; |
| 2126 | 2141 | ||
| 2127 | if (memcmp(invalid_block, out, out_len) != 0) { | 2142 | if (memcmp_failed) { |
| 2128 | report_hexdump(__func__, "invalid IPAddrBlock", "memcmp DER failed", | 2143 | report_hexdump(__func__, "invalid IPAddrBlock", "memcmp DER failed", |
| 2129 | invalid_block, invalid_block_len, out, out_len); | 2144 | invalid_block, invalid_block_len, out, out_len); |
| 2130 | goto err; | 2145 | goto err; |
| @@ -2148,20 +2163,22 @@ run_IPAddressFamily_cmp_ub_test(void) | |||
| 2148 | 2163 | ||
| 2149 | if ((out_len = i2d_IPAddrBlocks(addrs, &out)) <= 0) { | 2164 | if ((out_len = i2d_IPAddrBlocks(addrs, &out)) <= 0) { |
| 2150 | fprintf(stderr, "%s: i2d_IPAddrBlocks (2) failed\n", __func__); | 2165 | fprintf(stderr, "%s: i2d_IPAddrBlocks (2) failed\n", __func__); |
| 2166 | out_len = 0; | ||
| 2151 | goto err; | 2167 | goto err; |
| 2152 | } | 2168 | } |
| 2153 | 2169 | ||
| 2154 | if (invalid_block_len != (size_t)out_len) { | 2170 | memcmp_failed = 0; |
| 2155 | fprintf(stderr, "%s: length (2): want %zu, got %d\n", | 2171 | if (invalid_block_len != (size_t)out_len) |
| 2156 | __func__, invalid_block_len, out_len); | 2172 | memcmp_failed = 1; |
| 2157 | goto err; | 2173 | if (!memcmp_failed) |
| 2158 | } | 2174 | memcmp_failed = memcmp(invalid_block, out, out_len) != 0; |
| 2159 | 2175 | ||
| 2160 | if (memcmp(invalid_block, out, out_len) != 0) { | 2176 | if (memcmp_failed) { |
| 2161 | report_hexdump(__func__, "invalid IPAddrBlock (2)", "memcmp DER failed", | 2177 | report_hexdump(__func__, "invalid IPAddrBlock (2)", "memcmp DER failed", |
| 2162 | invalid_block, invalid_block_len, out, out_len); | 2178 | invalid_block, invalid_block_len, out, out_len); |
| 2163 | goto err; | 2179 | goto err; |
| 2164 | } | 2180 | } |
| 2181 | |||
| 2165 | failed = 0; | 2182 | failed = 0; |
| 2166 | 2183 | ||
| 2167 | err: | 2184 | err: |
