Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 1 | /* BEGIN_HEADER */ |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 2 | #include "mbedtls/bignum.h" |
Andres AG | 4b76aec | 2016-09-23 13:16:02 +0100 | [diff] [blame] | 3 | #include "mbedtls/x509.h" |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 4 | #include "mbedtls/x509_crt.h" |
| 5 | #include "mbedtls/x509_crl.h" |
| 6 | #include "mbedtls/x509_csr.h" |
Valerio Setti | 25b282e | 2024-01-17 10:55:32 +0100 | [diff] [blame] | 7 | #include "x509_internal.h" |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 8 | #include "mbedtls/pem.h" |
| 9 | #include "mbedtls/oid.h" |
| 10 | #include "mbedtls/base64.h" |
Chris Jones | 9f7a693 | 2021-04-14 12:12:09 +0100 | [diff] [blame] | 11 | #include "mbedtls/error.h" |
Valerio Setti | 178b5bd | 2023-02-13 10:04:28 +0100 | [diff] [blame] | 12 | #include "mbedtls/pk.h" |
Mohammad Azim Khan | 67735d5 | 2017-04-06 11:55:43 +0100 | [diff] [blame] | 13 | #include "string.h" |
Paul Bakker | b63b0af | 2011-01-13 17:54:59 +0000 | [diff] [blame] | 14 | |
Simon Butcher | 9e24b51 | 2017-07-28 12:15:13 +0100 | [diff] [blame] | 15 | #if MBEDTLS_X509_MAX_INTERMEDIATE_CA > 19 |
Hanno Becker | 3b1422e | 2017-07-26 13:38:02 +0100 | [diff] [blame] | 16 | #error "The value of MBEDTLS_X509_MAX_INTERMEDIATE_C is larger \ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 17 | than the current threshold 19. To test larger values, please \ |
David Horstmann | 7d0e5d2 | 2024-07-01 16:39:39 +0100 | [diff] [blame] | 18 | adapt the script framework/data_files/dir-max/long.sh." |
Hanno Becker | 3b1422e | 2017-07-26 13:38:02 +0100 | [diff] [blame] | 19 | #endif |
| 20 | |
Hanno Becker | 20a4ade | 2019-06-03 14:27:03 +0100 | [diff] [blame] | 21 | /* Test-only profile allowing all digests, PK algorithms, and curves. */ |
| 22 | const mbedtls_x509_crt_profile profile_all = |
| 23 | { |
| 24 | 0xFFFFFFFF, /* Any MD */ |
| 25 | 0xFFFFFFFF, /* Any PK alg */ |
| 26 | 0xFFFFFFFF, /* Any curve */ |
| 27 | 1024, |
| 28 | }; |
| 29 | |
Gilles Peskine | ef86ab2 | 2017-05-05 18:59:02 +0200 | [diff] [blame] | 30 | /* Profile for backward compatibility. Allows SHA-1, unlike the default |
| 31 | profile. */ |
Manuel Pégourié-Gonnard | 65eefc8 | 2015-10-23 14:08:48 +0200 | [diff] [blame] | 32 | const mbedtls_x509_crt_profile compat_profile = |
| 33 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 34 | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA1) | |
| 35 | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_RIPEMD160) | |
| 36 | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA224) | |
| 37 | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA256) | |
| 38 | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA384) | |
| 39 | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA512), |
Thomas Daubney | 28015e1 | 2022-04-21 08:12:59 +0100 | [diff] [blame] | 40 | 0xFFFFFFFF, /* Any PK alg */ |
| 41 | 0xFFFFFFFF, /* Any curve */ |
Manuel Pégourié-Gonnard | 65eefc8 | 2015-10-23 14:08:48 +0200 | [diff] [blame] | 42 | 1024, |
| 43 | }; |
| 44 | |
Manuel Pégourié-Gonnard | 6622fed | 2017-05-23 11:29:29 +0200 | [diff] [blame] | 45 | const mbedtls_x509_crt_profile profile_rsa3072 = |
| 46 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 47 | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA256) | |
| 48 | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA384) | |
| 49 | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA512), |
| 50 | MBEDTLS_X509_ID_FLAG(MBEDTLS_PK_RSA), |
Manuel Pégourié-Gonnard | 6622fed | 2017-05-23 11:29:29 +0200 | [diff] [blame] | 51 | 0, |
| 52 | 3072, |
| 53 | }; |
| 54 | |
| 55 | const mbedtls_x509_crt_profile profile_sha512 = |
| 56 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 57 | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA512), |
Thomas Daubney | 28015e1 | 2022-04-21 08:12:59 +0100 | [diff] [blame] | 58 | 0xFFFFFFFF, /* Any PK alg */ |
| 59 | 0xFFFFFFFF, /* Any curve */ |
Manuel Pégourié-Gonnard | 6622fed | 2017-05-23 11:29:29 +0200 | [diff] [blame] | 60 | 1024, |
| 61 | }; |
| 62 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 63 | int verify_none(void *data, mbedtls_x509_crt *crt, int certificate_depth, uint32_t *flags) |
Paul Bakker | b63b0af | 2011-01-13 17:54:59 +0000 | [diff] [blame] | 64 | { |
Paul Bakker | 5a62408 | 2011-01-18 16:31:52 +0000 | [diff] [blame] | 65 | ((void) data); |
| 66 | ((void) crt); |
| 67 | ((void) certificate_depth); |
Manuel Pégourié-Gonnard | e6028c9 | 2015-04-20 12:19:02 +0100 | [diff] [blame] | 68 | *flags |= MBEDTLS_X509_BADCERT_OTHER; |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 69 | |
Paul Bakker | 915275b | 2012-09-28 07:10:55 +0000 | [diff] [blame] | 70 | return 0; |
Paul Bakker | b63b0af | 2011-01-13 17:54:59 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 73 | int verify_all(void *data, mbedtls_x509_crt *crt, int certificate_depth, uint32_t *flags) |
Paul Bakker | b63b0af | 2011-01-13 17:54:59 +0000 | [diff] [blame] | 74 | { |
Paul Bakker | 5a62408 | 2011-01-18 16:31:52 +0000 | [diff] [blame] | 75 | ((void) data); |
| 76 | ((void) crt); |
| 77 | ((void) certificate_depth); |
Paul Bakker | 915275b | 2012-09-28 07:10:55 +0000 | [diff] [blame] | 78 | *flags = 0; |
Paul Bakker | 5a62408 | 2011-01-18 16:31:52 +0000 | [diff] [blame] | 79 | |
Paul Bakker | b63b0af | 2011-01-13 17:54:59 +0000 | [diff] [blame] | 80 | return 0; |
| 81 | } |
| 82 | |
Jarno Lamsa | 03cd120 | 2019-03-27 15:45:04 +0200 | [diff] [blame] | 83 | #if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 84 | int ca_callback_fail(void *data, mbedtls_x509_crt const *child, mbedtls_x509_crt **candidates) |
Jarno Lamsa | 557426a | 2019-03-27 17:08:29 +0200 | [diff] [blame] | 85 | { |
| 86 | ((void) data); |
| 87 | ((void) child); |
| 88 | ((void) candidates); |
| 89 | |
| 90 | return -1; |
| 91 | } |
Przemek Stekiel | cd20499 | 2022-04-27 15:33:43 +0200 | [diff] [blame] | 92 | #if defined(MBEDTLS_X509_CRT_PARSE_C) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 93 | int ca_callback(void *data, mbedtls_x509_crt const *child, |
| 94 | mbedtls_x509_crt **candidates) |
Jarno Lamsa | 03cd120 | 2019-03-27 15:45:04 +0200 | [diff] [blame] | 95 | { |
Hanno Becker | cbb5903 | 2019-03-28 14:14:22 +0000 | [diff] [blame] | 96 | int ret = 0; |
Jarno Lamsa | 03cd120 | 2019-03-27 15:45:04 +0200 | [diff] [blame] | 97 | mbedtls_x509_crt *ca = (mbedtls_x509_crt *) data; |
Hanno Becker | cbb5903 | 2019-03-28 14:14:22 +0000 | [diff] [blame] | 98 | mbedtls_x509_crt *first; |
| 99 | |
| 100 | /* This is a test-only implementation of the CA callback |
| 101 | * which always returns the entire list of trusted certificates. |
| 102 | * Production implementations managing a large number of CAs |
| 103 | * should use an efficient presentation and lookup for the |
| 104 | * set of trusted certificates (such as a hashtable) and only |
| 105 | * return those trusted certificates which satisfy basic |
| 106 | * parental checks, such as the matching of child `Issuer` |
| 107 | * and parent `Subject` field. */ |
| 108 | ((void) child); |
| 109 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 110 | first = mbedtls_calloc(1, sizeof(mbedtls_x509_crt)); |
| 111 | if (first == NULL) { |
Hanno Becker | cbb5903 | 2019-03-28 14:14:22 +0000 | [diff] [blame] | 112 | ret = -1; |
| 113 | goto exit; |
| 114 | } |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 115 | mbedtls_x509_crt_init(first); |
Hanno Becker | cbb5903 | 2019-03-28 14:14:22 +0000 | [diff] [blame] | 116 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 117 | if (mbedtls_x509_crt_parse_der(first, ca->raw.p, ca->raw.len) != 0) { |
Hanno Becker | cbb5903 | 2019-03-28 14:14:22 +0000 | [diff] [blame] | 118 | ret = -1; |
| 119 | goto exit; |
| 120 | } |
| 121 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 122 | while (ca->next != NULL) { |
Jarno Lamsa | 03cd120 | 2019-03-27 15:45:04 +0200 | [diff] [blame] | 123 | ca = ca->next; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 124 | if (mbedtls_x509_crt_parse_der(first, ca->raw.p, ca->raw.len) != 0) { |
Hanno Becker | cbb5903 | 2019-03-28 14:14:22 +0000 | [diff] [blame] | 125 | ret = -1; |
| 126 | goto exit; |
| 127 | } |
Jarno Lamsa | 03cd120 | 2019-03-27 15:45:04 +0200 | [diff] [blame] | 128 | } |
Hanno Becker | cbb5903 | 2019-03-28 14:14:22 +0000 | [diff] [blame] | 129 | |
| 130 | exit: |
| 131 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 132 | if (ret != 0) { |
| 133 | mbedtls_x509_crt_free(first); |
| 134 | mbedtls_free(first); |
Hanno Becker | cbb5903 | 2019-03-28 14:14:22 +0000 | [diff] [blame] | 135 | first = NULL; |
| 136 | } |
| 137 | |
Jarno Lamsa | 03cd120 | 2019-03-27 15:45:04 +0200 | [diff] [blame] | 138 | *candidates = first; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 139 | return ret; |
Jarno Lamsa | 03cd120 | 2019-03-27 15:45:04 +0200 | [diff] [blame] | 140 | } |
Przemek Stekiel | cd20499 | 2022-04-27 15:33:43 +0200 | [diff] [blame] | 141 | #endif /* MBEDTLS_X509_CRT_PARSE_C */ |
Jarno Lamsa | 03cd120 | 2019-03-27 15:45:04 +0200 | [diff] [blame] | 142 | #endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */ |
| 143 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 144 | int verify_fatal(void *data, mbedtls_x509_crt *crt, int certificate_depth, uint32_t *flags) |
Manuel Pégourié-Gonnard | 6b9d53f | 2017-05-23 12:26:58 +0200 | [diff] [blame] | 145 | { |
| 146 | int *levels = (int *) data; |
| 147 | |
| 148 | ((void) crt); |
| 149 | ((void) certificate_depth); |
| 150 | |
| 151 | /* Simulate a fatal error in the callback */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 152 | if (*levels & (1 << certificate_depth)) { |
| 153 | *flags |= (1 << certificate_depth); |
| 154 | return -1 - certificate_depth; |
Manuel Pégourié-Gonnard | 6b9d53f | 2017-05-23 12:26:58 +0200 | [diff] [blame] | 155 | } |
| 156 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 157 | return 0; |
Manuel Pégourié-Gonnard | 6b9d53f | 2017-05-23 12:26:58 +0200 | [diff] [blame] | 158 | } |
| 159 | |
Manuel Pégourié-Gonnard | a8838af | 2015-11-02 06:34:46 +0900 | [diff] [blame] | 160 | /* strsep() not available on Windows */ |
| 161 | char *mystrsep(char **stringp, const char *delim) |
| 162 | { |
| 163 | const char *p; |
| 164 | char *ret = *stringp; |
| 165 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 166 | if (*stringp == NULL) { |
| 167 | return NULL; |
| 168 | } |
Manuel Pégourié-Gonnard | a8838af | 2015-11-02 06:34:46 +0900 | [diff] [blame] | 169 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 170 | for (;; (*stringp)++) { |
| 171 | if (**stringp == '\0') { |
Manuel Pégourié-Gonnard | a8838af | 2015-11-02 06:34:46 +0900 | [diff] [blame] | 172 | *stringp = NULL; |
| 173 | goto done; |
| 174 | } |
| 175 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 176 | for (p = delim; *p != '\0'; p++) { |
| 177 | if (**stringp == *p) { |
Manuel Pégourié-Gonnard | a8838af | 2015-11-02 06:34:46 +0900 | [diff] [blame] | 178 | **stringp = '\0'; |
| 179 | (*stringp)++; |
| 180 | goto done; |
| 181 | } |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 182 | } |
Manuel Pégourié-Gonnard | a8838af | 2015-11-02 06:34:46 +0900 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | done: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 186 | return ret; |
Manuel Pégourié-Gonnard | a8838af | 2015-11-02 06:34:46 +0900 | [diff] [blame] | 187 | } |
| 188 | |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 189 | #if defined(MBEDTLS_X509_CRT_PARSE_C) |
| 190 | typedef struct { |
| 191 | char buf[512]; |
| 192 | char *p; |
| 193 | } verify_print_context; |
| 194 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 195 | void verify_print_init(verify_print_context *ctx) |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 196 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 197 | memset(ctx, 0, sizeof(verify_print_context)); |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 198 | ctx->p = ctx->buf; |
| 199 | } |
| 200 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 201 | int verify_print(void *data, mbedtls_x509_crt *crt, int certificate_depth, uint32_t *flags) |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 202 | { |
| 203 | int ret; |
| 204 | verify_print_context *ctx = (verify_print_context *) data; |
| 205 | char *p = ctx->p; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 206 | size_t n = ctx->buf + sizeof(ctx->buf) - ctx->p; |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 207 | ((void) flags); |
| 208 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 209 | ret = mbedtls_snprintf(p, n, "depth %d - serial ", certificate_depth); |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 210 | MBEDTLS_X509_SAFE_SNPRINTF; |
| 211 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 212 | ret = mbedtls_x509_serial_gets(p, n, &crt->serial); |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 213 | MBEDTLS_X509_SAFE_SNPRINTF; |
| 214 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 215 | ret = mbedtls_snprintf(p, n, " - subject "); |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 216 | MBEDTLS_X509_SAFE_SNPRINTF; |
| 217 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 218 | ret = mbedtls_x509_dn_gets(p, n, &crt->subject); |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 219 | MBEDTLS_X509_SAFE_SNPRINTF; |
| 220 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 221 | ret = mbedtls_snprintf(p, n, " - flags 0x%08x\n", *flags); |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 222 | MBEDTLS_X509_SAFE_SNPRINTF; |
| 223 | |
| 224 | ctx->p = p; |
| 225 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 226 | return 0; |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 227 | } |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 228 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 229 | int verify_parse_san(mbedtls_x509_subject_alternative_name *san, |
| 230 | char **buf, size_t *size) |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 231 | { |
| 232 | int ret; |
| 233 | size_t i; |
| 234 | char *p = *buf; |
| 235 | size_t n = *size; |
| 236 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 237 | ret = mbedtls_snprintf(p, n, "type : %d", san->type); |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 238 | MBEDTLS_X509_SAFE_SNPRINTF; |
| 239 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 240 | switch (san->type) { |
| 241 | case (MBEDTLS_X509_SAN_OTHER_NAME): |
| 242 | ret = mbedtls_snprintf(p, n, "\notherName :"); |
Victor Barpp Gomes | 47c7a73 | 2022-09-29 11:34:23 -0300 | [diff] [blame] | 243 | MBEDTLS_X509_SAFE_SNPRINTF; |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 244 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 245 | if (MBEDTLS_OID_CMP(MBEDTLS_OID_ON_HW_MODULE_NAME, |
David Horstmann | cfae6a1 | 2023-08-18 19:12:59 +0100 | [diff] [blame] | 246 | &san->san.other_name.type_id) == 0) { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 247 | ret = mbedtls_snprintf(p, n, " hardware module name :"); |
Victor Barpp Gomes | 47c7a73 | 2022-09-29 11:34:23 -0300 | [diff] [blame] | 248 | MBEDTLS_X509_SAFE_SNPRINTF; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 249 | ret = mbedtls_snprintf(p, n, " hardware type : "); |
Victor Barpp Gomes | 47c7a73 | 2022-09-29 11:34:23 -0300 | [diff] [blame] | 250 | MBEDTLS_X509_SAFE_SNPRINTF; |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 251 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 252 | ret = mbedtls_oid_get_numeric_string(p, |
| 253 | n, |
Matthias Schulz | edc32ea | 2023-10-19 16:09:08 +0200 | [diff] [blame] | 254 | &san->san.other_name.value.hardware_module_name |
| 255 | .oid); |
Victor Barpp Gomes | 47c7a73 | 2022-09-29 11:34:23 -0300 | [diff] [blame] | 256 | MBEDTLS_X509_SAFE_SNPRINTF; |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 257 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 258 | ret = mbedtls_snprintf(p, n, ", hardware serial number : "); |
Victor Barpp Gomes | 47c7a73 | 2022-09-29 11:34:23 -0300 | [diff] [blame] | 259 | MBEDTLS_X509_SAFE_SNPRINTF; |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 260 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 261 | for (i = 0; i < san->san.other_name.value.hardware_module_name.val.len; i++) { |
| 262 | ret = mbedtls_snprintf(p, |
| 263 | n, |
| 264 | "%02X", |
| 265 | san->san.other_name.value.hardware_module_name.val.p[i]); |
Victor Barpp Gomes | 47c7a73 | 2022-09-29 11:34:23 -0300 | [diff] [blame] | 266 | MBEDTLS_X509_SAFE_SNPRINTF; |
| 267 | } |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 268 | } |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 269 | break;/* MBEDTLS_OID_ON_HW_MODULE_NAME */ |
| 270 | case (MBEDTLS_X509_SAN_DNS_NAME): |
| 271 | ret = mbedtls_snprintf(p, n, "\ndNSName : "); |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 272 | MBEDTLS_X509_SAFE_SNPRINTF; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 273 | if (san->san.unstructured_name.len >= n) { |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 274 | *p = '\0'; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 275 | return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL; |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 276 | } |
| 277 | n -= san->san.unstructured_name.len; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 278 | for (i = 0; i < san->san.unstructured_name.len; i++) { |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 279 | *p++ = san->san.unstructured_name.p[i]; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 280 | } |
| 281 | break;/* MBEDTLS_X509_SAN_DNS_NAME */ |
Przemek Stekiel | 608e3ef | 2023-02-09 14:47:50 +0100 | [diff] [blame] | 282 | case (MBEDTLS_X509_SAN_RFC822_NAME): |
| 283 | ret = mbedtls_snprintf(p, n, "\nrfc822Name : "); |
| 284 | MBEDTLS_X509_SAFE_SNPRINTF; |
| 285 | if (san->san.unstructured_name.len >= n) { |
| 286 | *p = '\0'; |
| 287 | return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL; |
| 288 | } |
| 289 | n -= san->san.unstructured_name.len; |
| 290 | for (i = 0; i < san->san.unstructured_name.len; i++) { |
| 291 | *p++ = san->san.unstructured_name.p[i]; |
| 292 | } |
| 293 | break;/* MBEDTLS_X509_SAN_RFC822_NAME */ |
Andrzej Kurek | e12b01d | 2023-01-10 06:47:38 -0500 | [diff] [blame] | 294 | case (MBEDTLS_X509_SAN_DIRECTORY_NAME): |
| 295 | ret = mbedtls_snprintf(p, n, "\ndirectoryName : "); |
| 296 | MBEDTLS_X509_SAFE_SNPRINTF; |
| 297 | ret = mbedtls_x509_dn_gets(p, n, &san->san.directory_name); |
| 298 | if (ret < 0) { |
| 299 | return ret; |
| 300 | } |
| 301 | |
| 302 | p += ret; |
| 303 | n -= ret; |
| 304 | break;/* MBEDTLS_X509_SAN_DIRECTORY_NAME */ |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 305 | default: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 306 | /* |
| 307 | * Should not happen. |
| 308 | */ |
| 309 | return -1; |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 310 | } |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 311 | ret = mbedtls_snprintf(p, n, "\n"); |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 312 | MBEDTLS_X509_SAFE_SNPRINTF; |
| 313 | |
| 314 | *size = n; |
| 315 | *buf = p; |
| 316 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 317 | return 0; |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 318 | } |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 319 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 320 | int parse_crt_ext_cb(void *p_ctx, mbedtls_x509_crt const *crt, mbedtls_x509_buf const *oid, |
| 321 | int critical, const unsigned char *cp, const unsigned char *end) |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 322 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 323 | (void) crt; |
| 324 | (void) critical; |
| 325 | mbedtls_x509_buf *new_oid = (mbedtls_x509_buf *) p_ctx; |
| 326 | if (oid->tag == MBEDTLS_ASN1_OID && |
| 327 | MBEDTLS_OID_CMP(MBEDTLS_OID_CERTIFICATE_POLICIES, oid) == 0) { |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 328 | /* Handle unknown certificate policy */ |
| 329 | int ret, parse_ret = 0; |
| 330 | size_t len; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 331 | unsigned char **p = (unsigned char **) &cp; |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 332 | |
| 333 | /* Get main sequence tag */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 334 | ret = mbedtls_asn1_get_tag(p, end, &len, |
| 335 | MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE); |
| 336 | if (ret != 0) { |
| 337 | return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret); |
| 338 | } |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 339 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 340 | if (*p + len != end) { |
| 341 | return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, |
| 342 | MBEDTLS_ERR_ASN1_LENGTH_MISMATCH); |
| 343 | } |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 344 | |
| 345 | /* |
| 346 | * Cannot be an empty sequence. |
| 347 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 348 | if (len == 0) { |
| 349 | return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, |
| 350 | MBEDTLS_ERR_ASN1_LENGTH_MISMATCH); |
| 351 | } |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 352 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 353 | while (*p < end) { |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 354 | const unsigned char *policy_end; |
| 355 | |
| 356 | /* |
| 357 | * Get the policy sequence |
| 358 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 359 | if ((ret = mbedtls_asn1_get_tag(p, end, &len, |
| 360 | MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != |
| 361 | 0) { |
| 362 | return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret); |
| 363 | } |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 364 | |
| 365 | policy_end = *p + len; |
| 366 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 367 | if ((ret = mbedtls_asn1_get_tag(p, policy_end, &len, |
| 368 | MBEDTLS_ASN1_OID)) != 0) { |
| 369 | return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret); |
| 370 | } |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 371 | |
Nicola Di Lieto | b77fad8 | 2020-06-17 17:57:36 +0200 | [diff] [blame] | 372 | /* |
| 373 | * Recognize exclusively the policy with OID 1 |
| 374 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 375 | if (len != 1 || *p[0] != 1) { |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 376 | parse_ret = MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 377 | } |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 378 | |
| 379 | *p += len; |
| 380 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 381 | /* |
| 382 | * If there is an optional qualifier, then *p < policy_end |
| 383 | * Check the Qualifier len to verify it doesn't exceed policy_end. |
| 384 | */ |
| 385 | if (*p < policy_end) { |
| 386 | if ((ret = mbedtls_asn1_get_tag(p, policy_end, &len, |
| 387 | MBEDTLS_ASN1_CONSTRUCTED | |
| 388 | MBEDTLS_ASN1_SEQUENCE)) != 0) { |
| 389 | return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret); |
| 390 | } |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 391 | /* |
| 392 | * Skip the optional policy qualifiers. |
| 393 | */ |
| 394 | *p += len; |
| 395 | } |
| 396 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 397 | if (*p != policy_end) { |
| 398 | return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, |
| 399 | MBEDTLS_ERR_ASN1_LENGTH_MISMATCH); |
| 400 | } |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 401 | } |
| 402 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 403 | if (*p != end) { |
| 404 | return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, |
| 405 | MBEDTLS_ERR_ASN1_LENGTH_MISMATCH); |
| 406 | } |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 407 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 408 | return parse_ret; |
| 409 | } else if (new_oid != NULL && new_oid->tag == oid->tag && new_oid->len == oid->len && |
| 410 | memcmp(new_oid->p, oid->p, oid->len) == 0) { |
| 411 | return 0; |
| 412 | } else { |
| 413 | return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, |
| 414 | MBEDTLS_ERR_ASN1_UNEXPECTED_TAG); |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 415 | } |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 416 | } |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 417 | #endif /* MBEDTLS_X509_CRT_PARSE_C */ |
Matthias Schulz | ab40822 | 2023-10-18 13:20:59 +0200 | [diff] [blame] | 418 | |
Matthias Schulz | 03bd095 | 2023-10-19 09:52:59 +0200 | [diff] [blame] | 419 | #if defined(MBEDTLS_X509_CSR_PARSE_C) |
Matthias Schulz | ab40822 | 2023-10-18 13:20:59 +0200 | [diff] [blame] | 420 | int parse_csr_ext_accept_cb(void *p_ctx, mbedtls_x509_csr const *csr, mbedtls_x509_buf const *oid, |
Matthias Schulz | edc32ea | 2023-10-19 16:09:08 +0200 | [diff] [blame] | 421 | int critical, const unsigned char *cp, const unsigned char *end) |
Matthias Schulz | ab40822 | 2023-10-18 13:20:59 +0200 | [diff] [blame] | 422 | { |
| 423 | (void) p_ctx; |
| 424 | (void) csr; |
| 425 | (void) oid; |
| 426 | (void) critical; |
| 427 | (void) cp; |
| 428 | (void) end; |
| 429 | |
| 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | int parse_csr_ext_reject_cb(void *p_ctx, mbedtls_x509_csr const *csr, mbedtls_x509_buf const *oid, |
Matthias Schulz | edc32ea | 2023-10-19 16:09:08 +0200 | [diff] [blame] | 434 | int critical, const unsigned char *cp, const unsigned char *end) |
Matthias Schulz | ab40822 | 2023-10-18 13:20:59 +0200 | [diff] [blame] | 435 | { |
| 436 | (void) p_ctx; |
| 437 | (void) csr; |
| 438 | (void) oid; |
| 439 | (void) critical; |
| 440 | (void) cp; |
| 441 | (void) end; |
| 442 | |
| 443 | return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, |
| 444 | MBEDTLS_ERR_ASN1_UNEXPECTED_TAG); |
| 445 | } |
Matthias Schulz | 03bd095 | 2023-10-19 09:52:59 +0200 | [diff] [blame] | 446 | #endif /* MBEDTLS_X509_CSR_PARSE_C */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 447 | /* END_HEADER */ |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 448 | |
Thomas Daubney | 5c9c2ce | 2022-06-06 16:36:43 +0100 | [diff] [blame] | 449 | /* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 450 | void x509_accessor_ext_types(int ext_type, int has_ext_type) |
Thomas Daubney | bd5466a | 2022-05-31 14:16:42 +0100 | [diff] [blame] | 451 | { |
| 452 | mbedtls_x509_crt crt; |
| 453 | int expected_result = ext_type & has_ext_type; |
| 454 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 455 | mbedtls_x509_crt_init(&crt); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 456 | USE_PSA_INIT(); |
Thomas Daubney | bd5466a | 2022-05-31 14:16:42 +0100 | [diff] [blame] | 457 | |
| 458 | crt.ext_types = ext_type; |
| 459 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 460 | TEST_EQUAL(mbedtls_x509_crt_has_ext_type(&crt, has_ext_type), expected_result); |
Thomas Daubney | bd5466a | 2022-05-31 14:16:42 +0100 | [diff] [blame] | 461 | |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 462 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 463 | mbedtls_x509_crt_free(&crt); |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 464 | USE_PSA_DONE(); |
Thomas Daubney | bd5466a | 2022-05-31 14:16:42 +0100 | [diff] [blame] | 465 | } |
| 466 | /* END_CASE */ |
| 467 | |
Glenn Strauss | 6f545ac | 2022-10-25 15:02:14 -0400 | [diff] [blame] | 468 | /* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_TEST_HOOKS */ |
| 469 | void x509_crt_parse_cn_inet_pton(const char *cn, data_t *exp, int ref_ret) |
| 470 | { |
| 471 | uint32_t addr[4]; |
| 472 | size_t addrlen = mbedtls_x509_crt_parse_cn_inet_pton(cn, addr); |
| 473 | TEST_EQUAL(addrlen, (size_t) ref_ret); |
| 474 | |
| 475 | if (addrlen) { |
Tom Cosgrove | e4e9e7d | 2023-07-21 11:40:20 +0100 | [diff] [blame] | 476 | TEST_MEMORY_COMPARE(exp->x, exp->len, addr, addrlen); |
Glenn Strauss | 6f545ac | 2022-10-25 15:02:14 -0400 | [diff] [blame] | 477 | } |
| 478 | } |
| 479 | /* END_CASE */ |
| 480 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 481 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */ |
Andrzej Kurek | d90376e | 2023-01-20 07:08:57 -0500 | [diff] [blame] | 482 | void x509_parse_san(char *crt_file, char *result_str, int parse_result) |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 483 | { |
Ron Eldor | 890819a | 2019-05-13 19:03:04 +0300 | [diff] [blame] | 484 | int ret; |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 485 | mbedtls_x509_crt crt; |
Ron Eldor | 890819a | 2019-05-13 19:03:04 +0300 | [diff] [blame] | 486 | mbedtls_x509_subject_alternative_name san; |
| 487 | mbedtls_x509_sequence *cur = NULL; |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 488 | char buf[2000]; |
| 489 | char *p = buf; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 490 | size_t n = sizeof(buf); |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 491 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 492 | mbedtls_x509_crt_init(&crt); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 493 | USE_PSA_INIT(); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 494 | memset(buf, 0, 2000); |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 495 | |
Andrzej Kurek | d90376e | 2023-01-20 07:08:57 -0500 | [diff] [blame] | 496 | TEST_EQUAL(mbedtls_x509_crt_parse_file(&crt, crt_file), parse_result); |
Ron Eldor | 890819a | 2019-05-13 19:03:04 +0300 | [diff] [blame] | 497 | |
Andrzej Kurek | d90376e | 2023-01-20 07:08:57 -0500 | [diff] [blame] | 498 | if (parse_result != 0) { |
| 499 | goto exit; |
| 500 | } |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 501 | if (crt.ext_types & MBEDTLS_X509_EXT_SUBJECT_ALT_NAME) { |
Ron Eldor | 890819a | 2019-05-13 19:03:04 +0300 | [diff] [blame] | 502 | cur = &crt.subject_alt_names; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 503 | while (cur != NULL) { |
| 504 | ret = mbedtls_x509_parse_subject_alt_name(&cur->buf, &san); |
| 505 | TEST_ASSERT(ret == 0 || ret == MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE); |
Ron Eldor | 890819a | 2019-05-13 19:03:04 +0300 | [diff] [blame] | 506 | /* |
| 507 | * If san type not supported, ignore. |
| 508 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 509 | if (ret == 0) { |
Andrzej Kurek | d40c2b6 | 2023-02-13 07:01:59 -0500 | [diff] [blame] | 510 | ret = verify_parse_san(&san, &p, &n); |
| 511 | mbedtls_x509_free_subject_alt_name(&san); |
| 512 | TEST_EQUAL(ret, 0); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 513 | } |
Ron Eldor | 890819a | 2019-05-13 19:03:04 +0300 | [diff] [blame] | 514 | cur = cur->next; |
| 515 | } |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 516 | } |
| 517 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 518 | TEST_EQUAL(strcmp(buf, result_str), 0); |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 519 | |
| 520 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 521 | mbedtls_x509_crt_free(&crt); |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 522 | USE_PSA_DONE(); |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 523 | } |
| 524 | /* END_CASE */ |
| 525 | |
Hanno Becker | 612a2f1 | 2020-10-09 09:19:39 +0100 | [diff] [blame] | 526 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:!MBEDTLS_X509_REMOVE_INFO:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 527 | void x509_cert_info(char *crt_file, char *result_str) |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 528 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 529 | mbedtls_x509_crt crt; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 530 | char buf[2000]; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 531 | int res; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 532 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 533 | mbedtls_x509_crt_init(&crt); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 534 | USE_PSA_INIT(); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 535 | memset(buf, 0, 2000); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 536 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 537 | TEST_EQUAL(mbedtls_x509_crt_parse_file(&crt, crt_file), 0); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 538 | res = mbedtls_x509_crt_info(buf, 2000, "", &crt); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 539 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 540 | TEST_ASSERT(res != -1); |
| 541 | TEST_ASSERT(res != -2); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 542 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 543 | TEST_EQUAL(strcmp(buf, result_str), 0); |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 544 | |
| 545 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 546 | mbedtls_x509_crt_free(&crt); |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 547 | USE_PSA_DONE(); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 548 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 549 | /* END_CASE */ |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 550 | |
Hanno Becker | 612a2f1 | 2020-10-09 09:19:39 +0100 | [diff] [blame] | 551 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRL_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 552 | void mbedtls_x509_crl_info(char *crl_file, char *result_str) |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 553 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 554 | mbedtls_x509_crl crl; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 555 | char buf[2000]; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 556 | int res; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 557 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 558 | mbedtls_x509_crl_init(&crl); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 559 | USE_PSA_INIT(); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 560 | memset(buf, 0, 2000); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 561 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 562 | TEST_EQUAL(mbedtls_x509_crl_parse_file(&crl, crl_file), 0); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 563 | res = mbedtls_x509_crl_info(buf, 2000, "", &crl); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 564 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 565 | TEST_ASSERT(res != -1); |
| 566 | TEST_ASSERT(res != -2); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 567 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 568 | TEST_EQUAL(strcmp(buf, result_str), 0); |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 569 | |
| 570 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 571 | mbedtls_x509_crl_free(&crl); |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 572 | USE_PSA_DONE(); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 573 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 574 | /* END_CASE */ |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 575 | |
Andres AG | a39db39 | 2016-12-08 17:10:38 +0000 | [diff] [blame] | 576 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRL_PARSE_C */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 577 | void mbedtls_x509_crl_parse(char *crl_file, int result) |
Andres AG | a39db39 | 2016-12-08 17:10:38 +0000 | [diff] [blame] | 578 | { |
| 579 | mbedtls_x509_crl crl; |
| 580 | char buf[2000]; |
| 581 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 582 | mbedtls_x509_crl_init(&crl); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 583 | USE_PSA_INIT(); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 584 | memset(buf, 0, 2000); |
Andres AG | a39db39 | 2016-12-08 17:10:38 +0000 | [diff] [blame] | 585 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 586 | TEST_EQUAL(mbedtls_x509_crl_parse_file(&crl, crl_file), result); |
Andres AG | a39db39 | 2016-12-08 17:10:38 +0000 | [diff] [blame] | 587 | |
| 588 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 589 | mbedtls_x509_crl_free(&crl); |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 590 | USE_PSA_DONE(); |
Andres AG | a39db39 | 2016-12-08 17:10:38 +0000 | [diff] [blame] | 591 | } |
| 592 | /* END_CASE */ |
| 593 | |
Hanno Becker | 612a2f1 | 2020-10-09 09:19:39 +0100 | [diff] [blame] | 594 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CSR_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 595 | void mbedtls_x509_csr_info(char *csr_file, char *result_str) |
Manuel Pégourié-Gonnard | 2a8d7fd | 2014-01-24 17:34:26 +0100 | [diff] [blame] | 596 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 597 | mbedtls_x509_csr csr; |
Manuel Pégourié-Gonnard | 2a8d7fd | 2014-01-24 17:34:26 +0100 | [diff] [blame] | 598 | char buf[2000]; |
| 599 | int res; |
| 600 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 601 | mbedtls_x509_csr_init(&csr); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 602 | USE_PSA_INIT(); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 603 | memset(buf, 0, 2000); |
Manuel Pégourié-Gonnard | 2a8d7fd | 2014-01-24 17:34:26 +0100 | [diff] [blame] | 604 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 605 | TEST_EQUAL(mbedtls_x509_csr_parse_file(&csr, csr_file), 0); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 606 | res = mbedtls_x509_csr_info(buf, 2000, "", &csr); |
Manuel Pégourié-Gonnard | 2a8d7fd | 2014-01-24 17:34:26 +0100 | [diff] [blame] | 607 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 608 | TEST_ASSERT(res != -1); |
| 609 | TEST_ASSERT(res != -2); |
Manuel Pégourié-Gonnard | 2a8d7fd | 2014-01-24 17:34:26 +0100 | [diff] [blame] | 610 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 611 | TEST_EQUAL(strcmp(buf, result_str), 0); |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 612 | |
| 613 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 614 | mbedtls_x509_csr_free(&csr); |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 615 | USE_PSA_DONE(); |
Manuel Pégourié-Gonnard | 2a8d7fd | 2014-01-24 17:34:26 +0100 | [diff] [blame] | 616 | } |
| 617 | /* END_CASE */ |
| 618 | |
Hanno Becker | 612a2f1 | 2020-10-09 09:19:39 +0100 | [diff] [blame] | 619 | /* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 620 | void x509_verify_info(int flags, char *prefix, char *result_str) |
Manuel Pégourié-Gonnard | b5f48ad | 2015-04-20 10:38:13 +0100 | [diff] [blame] | 621 | { |
| 622 | char buf[2000]; |
| 623 | int res; |
| 624 | |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 625 | USE_PSA_INIT(); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 626 | memset(buf, 0, sizeof(buf)); |
Manuel Pégourié-Gonnard | b5f48ad | 2015-04-20 10:38:13 +0100 | [diff] [blame] | 627 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 628 | res = mbedtls_x509_crt_verify_info(buf, sizeof(buf), prefix, flags); |
Manuel Pégourié-Gonnard | b5f48ad | 2015-04-20 10:38:13 +0100 | [diff] [blame] | 629 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 630 | TEST_ASSERT(res >= 0); |
Manuel Pégourié-Gonnard | b5f48ad | 2015-04-20 10:38:13 +0100 | [diff] [blame] | 631 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 632 | TEST_EQUAL(strcmp(buf, result_str), 0); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 633 | |
| 634 | exit: |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 635 | USE_PSA_DONE(); |
Manuel Pégourié-Gonnard | b5f48ad | 2015-04-20 10:38:13 +0100 | [diff] [blame] | 636 | } |
| 637 | /* END_CASE */ |
| 638 | |
Manuel Pégourié-Gonnard | d19a41d | 2017-07-14 11:05:59 +0200 | [diff] [blame] | 639 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_CRL_PARSE_C:MBEDTLS_ECP_RESTARTABLE:MBEDTLS_ECDSA_C */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 640 | void x509_verify_restart(char *crt_file, char *ca_file, |
| 641 | int result, int flags_result, |
| 642 | int max_ops, int min_restart, int max_restart) |
Manuel Pégourié-Gonnard | d19a41d | 2017-07-14 11:05:59 +0200 | [diff] [blame] | 643 | { |
| 644 | int ret, cnt_restart; |
| 645 | mbedtls_x509_crt_restart_ctx rs_ctx; |
| 646 | mbedtls_x509_crt crt; |
| 647 | mbedtls_x509_crt ca; |
| 648 | uint32_t flags = 0; |
| 649 | |
Manuel Pégourié-Gonnard | 8b59049 | 2017-08-14 18:04:19 +0200 | [diff] [blame] | 650 | /* |
| 651 | * See comments on ecp_test_vect_restart() for op count precision. |
| 652 | * |
Gilles Peskine | e820c0a | 2023-08-03 17:45:20 +0200 | [diff] [blame] | 653 | * For reference, with Mbed TLS 2.6 and default settings: |
Manuel Pégourié-Gonnard | 8b59049 | 2017-08-14 18:04:19 +0200 | [diff] [blame] | 654 | * - ecdsa_verify() for P-256: ~ 6700 |
| 655 | * - ecdsa_verify() for P-384: ~ 18800 |
| 656 | * - x509_verify() for server5 -> test-ca2: ~ 18800 |
| 657 | * - x509_verify() for server10 -> int-ca3 -> int-ca2: ~ 25500 |
| 658 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 659 | mbedtls_x509_crt_restart_init(&rs_ctx); |
| 660 | mbedtls_x509_crt_init(&crt); |
| 661 | mbedtls_x509_crt_init(&ca); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 662 | MD_OR_USE_PSA_INIT(); |
Manuel Pégourié-Gonnard | d19a41d | 2017-07-14 11:05:59 +0200 | [diff] [blame] | 663 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 664 | TEST_EQUAL(mbedtls_x509_crt_parse_file(&crt, crt_file), 0); |
| 665 | TEST_EQUAL(mbedtls_x509_crt_parse_file(&ca, ca_file), 0); |
Manuel Pégourié-Gonnard | d19a41d | 2017-07-14 11:05:59 +0200 | [diff] [blame] | 666 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 667 | mbedtls_ecp_set_max_ops(max_ops); |
Manuel Pégourié-Gonnard | d19a41d | 2017-07-14 11:05:59 +0200 | [diff] [blame] | 668 | |
| 669 | cnt_restart = 0; |
| 670 | do { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 671 | ret = mbedtls_x509_crt_verify_restartable(&crt, &ca, NULL, |
| 672 | &mbedtls_x509_crt_profile_default, NULL, &flags, |
| 673 | NULL, NULL, &rs_ctx); |
| 674 | } while (ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart); |
Manuel Pégourié-Gonnard | d19a41d | 2017-07-14 11:05:59 +0200 | [diff] [blame] | 675 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 676 | TEST_EQUAL(ret, result); |
| 677 | TEST_EQUAL(flags, (uint32_t) flags_result); |
Manuel Pégourié-Gonnard | d19a41d | 2017-07-14 11:05:59 +0200 | [diff] [blame] | 678 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 679 | TEST_ASSERT(cnt_restart >= min_restart); |
| 680 | TEST_ASSERT(cnt_restart <= max_restart); |
Manuel Pégourié-Gonnard | d19a41d | 2017-07-14 11:05:59 +0200 | [diff] [blame] | 681 | |
| 682 | /* Do we leak memory when aborting? */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 683 | ret = mbedtls_x509_crt_verify_restartable(&crt, &ca, NULL, |
| 684 | &mbedtls_x509_crt_profile_default, NULL, &flags, |
| 685 | NULL, NULL, &rs_ctx); |
| 686 | TEST_ASSERT(ret == result || ret == MBEDTLS_ERR_ECP_IN_PROGRESS); |
Manuel Pégourié-Gonnard | d19a41d | 2017-07-14 11:05:59 +0200 | [diff] [blame] | 687 | |
| 688 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 689 | mbedtls_x509_crt_restart_free(&rs_ctx); |
| 690 | mbedtls_x509_crt_free(&crt); |
| 691 | mbedtls_x509_crt_free(&ca); |
Manuel Pégourié-Gonnard | 33a1302 | 2023-03-17 14:02:49 +0100 | [diff] [blame] | 692 | MD_OR_USE_PSA_DONE(); |
Manuel Pégourié-Gonnard | d19a41d | 2017-07-14 11:05:59 +0200 | [diff] [blame] | 693 | } |
| 694 | /* END_CASE */ |
| 695 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 696 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_CRL_PARSE_C */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 697 | void x509_verify(char *crt_file, char *ca_file, char *crl_file, |
| 698 | char *cn_name_str, int result, int flags_result, |
| 699 | char *profile_str, |
| 700 | char *verify_callback) |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 701 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 702 | mbedtls_x509_crt crt; |
| 703 | mbedtls_x509_crt ca; |
| 704 | mbedtls_x509_crl crl; |
Manuel Pégourié-Gonnard | e6ef16f | 2015-05-11 19:54:43 +0200 | [diff] [blame] | 705 | uint32_t flags = 0; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 706 | int res; |
Manuel Pégourié-Gonnard | e6ef16f | 2015-05-11 19:54:43 +0200 | [diff] [blame] | 707 | int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *) = NULL; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 708 | char *cn_name = NULL; |
Gilles Peskine | ef86ab2 | 2017-05-05 18:59:02 +0200 | [diff] [blame] | 709 | const mbedtls_x509_crt_profile *profile; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 710 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 711 | mbedtls_x509_crt_init(&crt); |
| 712 | mbedtls_x509_crt_init(&ca); |
| 713 | mbedtls_x509_crl_init(&crl); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 714 | MD_OR_USE_PSA_INIT(); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 715 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 716 | if (strcmp(cn_name_str, "NULL") != 0) { |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 717 | cn_name = cn_name_str; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 718 | } |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 719 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 720 | if (strcmp(profile_str, "") == 0) { |
Gilles Peskine | ef86ab2 | 2017-05-05 18:59:02 +0200 | [diff] [blame] | 721 | profile = &mbedtls_x509_crt_profile_default; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 722 | } else if (strcmp(profile_str, "next") == 0) { |
Ron Eldor | c153998 | 2018-02-06 18:47:17 +0200 | [diff] [blame] | 723 | profile = &mbedtls_x509_crt_profile_next; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 724 | } else if (strcmp(profile_str, "suite_b") == 0) { |
Ron Eldor | c153998 | 2018-02-06 18:47:17 +0200 | [diff] [blame] | 725 | profile = &mbedtls_x509_crt_profile_suiteb; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 726 | } else if (strcmp(profile_str, "compat") == 0) { |
Gilles Peskine | ef86ab2 | 2017-05-05 18:59:02 +0200 | [diff] [blame] | 727 | profile = &compat_profile; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 728 | } else if (strcmp(profile_str, "all") == 0) { |
Hanno Becker | 20a4ade | 2019-06-03 14:27:03 +0100 | [diff] [blame] | 729 | profile = &profile_all; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 730 | } else { |
Agathiyan Bragadeesh | 763b353 | 2023-07-27 13:52:31 +0100 | [diff] [blame] | 731 | TEST_FAIL("Unknown algorithm profile"); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 732 | } |
Gilles Peskine | ef86ab2 | 2017-05-05 18:59:02 +0200 | [diff] [blame] | 733 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 734 | if (strcmp(verify_callback, "NULL") == 0) { |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 735 | f_vrfy = NULL; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 736 | } else if (strcmp(verify_callback, "verify_none") == 0) { |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 737 | f_vrfy = verify_none; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 738 | } else if (strcmp(verify_callback, "verify_all") == 0) { |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 739 | f_vrfy = verify_all; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 740 | } else { |
Agathiyan Bragadeesh | 763b353 | 2023-07-27 13:52:31 +0100 | [diff] [blame] | 741 | TEST_FAIL("No known verify callback selected"); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 742 | } |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 743 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 744 | TEST_EQUAL(mbedtls_x509_crt_parse_file(&crt, crt_file), 0); |
| 745 | TEST_EQUAL(mbedtls_x509_crt_parse_file(&ca, ca_file), 0); |
| 746 | TEST_EQUAL(mbedtls_x509_crl_parse_file(&crl, crl_file), 0); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 747 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 748 | res = mbedtls_x509_crt_verify_with_profile(&crt, |
| 749 | &ca, |
| 750 | &crl, |
| 751 | profile, |
| 752 | cn_name, |
| 753 | &flags, |
| 754 | f_vrfy, |
| 755 | NULL); |
Manuel Pégourié-Gonnard | 65eefc8 | 2015-10-23 14:08:48 +0200 | [diff] [blame] | 756 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 757 | TEST_EQUAL(res, result); |
| 758 | TEST_EQUAL(flags, (uint32_t) flags_result); |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 759 | |
Jarno Lamsa | 03cd120 | 2019-03-27 15:45:04 +0200 | [diff] [blame] | 760 | #if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK) |
Hanno Becker | 0350d56 | 2019-03-28 14:23:36 +0000 | [diff] [blame] | 761 | /* CRLs aren't supported with CA callbacks, so skip the CA callback |
Jarno Lamsa | dfd22c4 | 2019-04-01 15:18:53 +0300 | [diff] [blame] | 762 | * version of the test if CRLs are in use. */ |
Gilles Peskine | bb7d92c | 2023-10-17 17:26:44 +0200 | [diff] [blame] | 763 | if (strcmp(crl_file, "") == 0) { |
Hanno Becker | 0350d56 | 2019-03-28 14:23:36 +0000 | [diff] [blame] | 764 | flags = 0; |
Jarno Lamsa | 03cd120 | 2019-03-27 15:45:04 +0200 | [diff] [blame] | 765 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 766 | res = mbedtls_x509_crt_verify_with_ca_cb(&crt, |
| 767 | ca_callback, |
| 768 | &ca, |
| 769 | profile, |
| 770 | cn_name, |
| 771 | &flags, |
| 772 | f_vrfy, |
| 773 | NULL); |
Jarno Lamsa | 03cd120 | 2019-03-27 15:45:04 +0200 | [diff] [blame] | 774 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 775 | TEST_EQUAL(res, result); |
| 776 | TEST_EQUAL(flags, (uint32_t) (flags_result)); |
Hanno Becker | 0350d56 | 2019-03-28 14:23:36 +0000 | [diff] [blame] | 777 | } |
Jarno Lamsa | 03cd120 | 2019-03-27 15:45:04 +0200 | [diff] [blame] | 778 | #endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */ |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 779 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 780 | mbedtls_x509_crt_free(&crt); |
| 781 | mbedtls_x509_crt_free(&ca); |
| 782 | mbedtls_x509_crl_free(&crl); |
Manuel Pégourié-Gonnard | 33a1302 | 2023-03-17 14:02:49 +0100 | [diff] [blame] | 783 | MD_OR_USE_PSA_DONE(); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 784 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 785 | /* END_CASE */ |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 786 | |
Jarno Lamsa | 557426a | 2019-03-27 17:08:29 +0200 | [diff] [blame] | 787 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_CRL_PARSE_C:MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 788 | void x509_verify_ca_cb_failure(char *crt_file, char *ca_file, char *name, |
| 789 | int exp_ret) |
Jarno Lamsa | 557426a | 2019-03-27 17:08:29 +0200 | [diff] [blame] | 790 | { |
| 791 | int ret; |
| 792 | mbedtls_x509_crt crt; |
| 793 | mbedtls_x509_crt ca; |
| 794 | uint32_t flags = 0; |
Hanno Becker | 3f932bb | 2019-03-28 17:06:47 +0000 | [diff] [blame] | 795 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 796 | mbedtls_x509_crt_init(&crt); |
| 797 | mbedtls_x509_crt_init(&ca); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 798 | USE_PSA_INIT(); |
Jarno Lamsa | 557426a | 2019-03-27 17:08:29 +0200 | [diff] [blame] | 799 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 800 | TEST_EQUAL(mbedtls_x509_crt_parse_file(&crt, crt_file), 0); |
| 801 | TEST_EQUAL(mbedtls_x509_crt_parse_file(&ca, ca_file), 0); |
Jarno Lamsa | 557426a | 2019-03-27 17:08:29 +0200 | [diff] [blame] | 802 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 803 | if (strcmp(name, "NULL") == 0) { |
Jarno Lamsa | 557426a | 2019-03-27 17:08:29 +0200 | [diff] [blame] | 804 | name = NULL; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 805 | } |
Hanno Becker | cbb5903 | 2019-03-28 14:14:22 +0000 | [diff] [blame] | 806 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 807 | ret = mbedtls_x509_crt_verify_with_ca_cb(&crt, ca_callback_fail, &ca, |
| 808 | &compat_profile, name, &flags, |
| 809 | NULL, NULL); |
Jarno Lamsa | 557426a | 2019-03-27 17:08:29 +0200 | [diff] [blame] | 810 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 811 | TEST_EQUAL(ret, exp_ret); |
| 812 | TEST_EQUAL(flags, (uint32_t) (-1)); |
Jarno Lamsa | 557426a | 2019-03-27 17:08:29 +0200 | [diff] [blame] | 813 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 814 | mbedtls_x509_crt_free(&crt); |
| 815 | mbedtls_x509_crt_free(&ca); |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 816 | USE_PSA_DONE(); |
Jarno Lamsa | 557426a | 2019-03-27 17:08:29 +0200 | [diff] [blame] | 817 | } |
| 818 | /* END_CASE */ |
| 819 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 820 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 821 | void x509_verify_callback(char *crt_file, char *ca_file, char *name, |
| 822 | int exp_ret, char *exp_vrfy_out) |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 823 | { |
| 824 | int ret; |
| 825 | mbedtls_x509_crt crt; |
| 826 | mbedtls_x509_crt ca; |
| 827 | uint32_t flags = 0; |
| 828 | verify_print_context vrfy_ctx; |
| 829 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 830 | mbedtls_x509_crt_init(&crt); |
| 831 | mbedtls_x509_crt_init(&ca); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 832 | MD_OR_USE_PSA_INIT(); |
| 833 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 834 | verify_print_init(&vrfy_ctx); |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 835 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 836 | TEST_EQUAL(mbedtls_x509_crt_parse_file(&crt, crt_file), 0); |
| 837 | TEST_EQUAL(mbedtls_x509_crt_parse_file(&ca, ca_file), 0); |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 838 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 839 | if (strcmp(name, "NULL") == 0) { |
Manuel Pégourié-Gonnard | a656825 | 2017-07-05 18:14:38 +0200 | [diff] [blame] | 840 | name = NULL; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 841 | } |
Manuel Pégourié-Gonnard | a656825 | 2017-07-05 18:14:38 +0200 | [diff] [blame] | 842 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 843 | ret = mbedtls_x509_crt_verify_with_profile(&crt, &ca, NULL, |
| 844 | &compat_profile, |
| 845 | name, &flags, |
| 846 | verify_print, &vrfy_ctx); |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 847 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 848 | TEST_EQUAL(ret, exp_ret); |
| 849 | TEST_EQUAL(strcmp(vrfy_ctx.buf, exp_vrfy_out), 0); |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 850 | |
| 851 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 852 | mbedtls_x509_crt_free(&crt); |
| 853 | mbedtls_x509_crt_free(&ca); |
Manuel Pégourié-Gonnard | 33a1302 | 2023-03-17 14:02:49 +0100 | [diff] [blame] | 854 | MD_OR_USE_PSA_DONE(); |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 855 | } |
| 856 | /* END_CASE */ |
| 857 | |
Hanno Becker | 612a2f1 | 2020-10-09 09:19:39 +0100 | [diff] [blame] | 858 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 859 | void mbedtls_x509_dn_gets_subject_replace(char *crt_file, |
| 860 | char *new_subject_ou, |
| 861 | char *result_str, |
| 862 | int ret) |
Werner Lewis | 31ecb96 | 2022-06-17 15:51:55 +0100 | [diff] [blame] | 863 | { |
| 864 | mbedtls_x509_crt crt; |
| 865 | char buf[2000]; |
| 866 | int res = 0; |
| 867 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 868 | mbedtls_x509_crt_init(&crt); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 869 | USE_PSA_INIT(); |
| 870 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 871 | memset(buf, 0, 2000); |
Werner Lewis | 31ecb96 | 2022-06-17 15:51:55 +0100 | [diff] [blame] | 872 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 873 | TEST_EQUAL(mbedtls_x509_crt_parse_file(&crt, crt_file), 0); |
Werner Lewis | 31ecb96 | 2022-06-17 15:51:55 +0100 | [diff] [blame] | 874 | crt.subject.next->val.p = (unsigned char *) new_subject_ou; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 875 | crt.subject.next->val.len = strlen(new_subject_ou); |
Werner Lewis | 31ecb96 | 2022-06-17 15:51:55 +0100 | [diff] [blame] | 876 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 877 | res = mbedtls_x509_dn_gets(buf, 2000, &crt.subject); |
Werner Lewis | 31ecb96 | 2022-06-17 15:51:55 +0100 | [diff] [blame] | 878 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 879 | if (ret != 0) { |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 880 | TEST_EQUAL(res, ret); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 881 | } else { |
| 882 | TEST_ASSERT(res != -1); |
| 883 | TEST_ASSERT(res != -2); |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 884 | TEST_EQUAL(strcmp(buf, result_str), 0); |
Werner Lewis | 31ecb96 | 2022-06-17 15:51:55 +0100 | [diff] [blame] | 885 | } |
| 886 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 887 | mbedtls_x509_crt_free(&crt); |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 888 | USE_PSA_DONE(); |
Werner Lewis | 31ecb96 | 2022-06-17 15:51:55 +0100 | [diff] [blame] | 889 | } |
| 890 | /* END_CASE */ |
| 891 | |
| 892 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 893 | void mbedtls_x509_dn_gets(char *crt_file, char *entity, char *result_str) |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 894 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 895 | mbedtls_x509_crt crt; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 896 | char buf[2000]; |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 897 | int res = 0; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 898 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 899 | mbedtls_x509_crt_init(&crt); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 900 | USE_PSA_INIT(); |
| 901 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 902 | memset(buf, 0, 2000); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 903 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 904 | TEST_EQUAL(mbedtls_x509_crt_parse_file(&crt, crt_file), 0); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 905 | if (strcmp(entity, "subject") == 0) { |
| 906 | res = mbedtls_x509_dn_gets(buf, 2000, &crt.subject); |
| 907 | } else if (strcmp(entity, "issuer") == 0) { |
| 908 | res = mbedtls_x509_dn_gets(buf, 2000, &crt.issuer); |
| 909 | } else { |
Agathiyan Bragadeesh | 763b353 | 2023-07-27 13:52:31 +0100 | [diff] [blame] | 910 | TEST_FAIL("Unknown entity"); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 911 | } |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 912 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 913 | TEST_ASSERT(res != -1); |
| 914 | TEST_ASSERT(res != -2); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 915 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 916 | TEST_EQUAL(strcmp(buf, result_str), 0); |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 917 | |
| 918 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 919 | mbedtls_x509_crt_free(&crt); |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 920 | USE_PSA_DONE(); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 921 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 922 | /* END_CASE */ |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 923 | |
David Horstmann | db73d3b | 2022-10-04 16:49:16 +0100 | [diff] [blame] | 924 | /* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 925 | void mbedtls_x509_get_name(char *rdn_sequence, int exp_ret) |
David Horstmann | db73d3b | 2022-10-04 16:49:16 +0100 | [diff] [blame] | 926 | { |
valerio | e50831c | 2023-04-20 14:48:19 +0200 | [diff] [blame] | 927 | unsigned char *name = NULL; |
David Horstmann | db73d3b | 2022-10-04 16:49:16 +0100 | [diff] [blame] | 928 | unsigned char *p; |
| 929 | size_t name_len; |
David Horstmann | 2bb9c8a | 2022-10-20 10:18:37 +0100 | [diff] [blame] | 930 | mbedtls_x509_name head; |
David Horstmann | 3cd6758 | 2022-10-17 17:59:10 +0100 | [diff] [blame] | 931 | int ret; |
David Horstmann | db73d3b | 2022-10-04 16:49:16 +0100 | [diff] [blame] | 932 | |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 933 | USE_PSA_INIT(); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 934 | memset(&head, 0, sizeof(head)); |
David Horstmann | 2bb9c8a | 2022-10-20 10:18:37 +0100 | [diff] [blame] | 935 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 936 | name = mbedtls_test_unhexify_alloc(rdn_sequence, &name_len); |
David Horstmann | db73d3b | 2022-10-04 16:49:16 +0100 | [diff] [blame] | 937 | p = name; |
| 938 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 939 | ret = mbedtls_x509_get_name(&p, (name + name_len), &head); |
| 940 | if (ret == 0) { |
| 941 | mbedtls_asn1_free_named_data_list_shallow(head.next); |
| 942 | } |
David Horstmann | db73d3b | 2022-10-04 16:49:16 +0100 | [diff] [blame] | 943 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 944 | TEST_EQUAL(ret, exp_ret); |
David Horstmann | db73d3b | 2022-10-04 16:49:16 +0100 | [diff] [blame] | 945 | |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 946 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 947 | mbedtls_free(name); |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 948 | USE_PSA_DONE(); |
David Horstmann | db73d3b | 2022-10-04 16:49:16 +0100 | [diff] [blame] | 949 | } |
| 950 | /* END_CASE */ |
| 951 | |
Werner Lewis | b3acb05 | 2022-06-17 15:59:58 +0100 | [diff] [blame] | 952 | /* BEGIN_CASE depends_on:MBEDTLS_X509_CREATE_C:MBEDTLS_X509_USE_C:MBEDTLS_X509_CRT_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 953 | void mbedtls_x509_dn_get_next(char *name_str, |
| 954 | int next_merged, |
| 955 | char *expected_oids, |
| 956 | int exp_count, |
| 957 | char *exp_dn_gets) |
Werner Lewis | b3acb05 | 2022-06-17 15:59:58 +0100 | [diff] [blame] | 958 | { |
| 959 | int ret = 0, i; |
Werner Lewis | ac80a66 | 2022-06-23 11:58:02 +0100 | [diff] [blame] | 960 | size_t len = 0, out_size; |
Werner Lewis | b3acb05 | 2022-06-17 15:59:58 +0100 | [diff] [blame] | 961 | mbedtls_asn1_named_data *names = NULL; |
Gilles Peskine | 21e46b3 | 2023-10-17 16:35:20 +0200 | [diff] [blame] | 962 | mbedtls_x509_name parsed; |
| 963 | memset(&parsed, 0, sizeof(parsed)); |
| 964 | mbedtls_x509_name *parsed_cur; |
Werner Lewis | ac80a66 | 2022-06-23 11:58:02 +0100 | [diff] [blame] | 965 | // Size of buf is maximum required for test cases |
Gilles Peskine | f257420 | 2023-10-18 17:39:48 +0200 | [diff] [blame] | 966 | unsigned char buf[80] = { 0 }; |
Gilles Peskine | 21e46b3 | 2023-10-17 16:35:20 +0200 | [diff] [blame] | 967 | unsigned char *out = NULL; |
| 968 | unsigned char *c = buf + sizeof(buf); |
Werner Lewis | b3acb05 | 2022-06-17 15:59:58 +0100 | [diff] [blame] | 969 | const char *short_name; |
| 970 | |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 971 | USE_PSA_INIT(); |
Gilles Peskine | 21e46b3 | 2023-10-17 16:35:20 +0200 | [diff] [blame] | 972 | |
Werner Lewis | ac80a66 | 2022-06-23 11:58:02 +0100 | [diff] [blame] | 973 | // Additional size required for trailing space |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 974 | out_size = strlen(expected_oids) + 2; |
Tom Cosgrove | 05b2a87 | 2023-07-21 11:31:13 +0100 | [diff] [blame] | 975 | TEST_CALLOC(out, out_size); |
Werner Lewis | b3acb05 | 2022-06-17 15:59:58 +0100 | [diff] [blame] | 976 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 977 | TEST_EQUAL(mbedtls_x509_string_to_names(&names, name_str), 0); |
Werner Lewis | b3acb05 | 2022-06-17 15:59:58 +0100 | [diff] [blame] | 978 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 979 | ret = mbedtls_x509_write_names(&c, buf, names); |
| 980 | TEST_LE_S(0, ret); |
Werner Lewis | b3acb05 | 2022-06-17 15:59:58 +0100 | [diff] [blame] | 981 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 982 | TEST_EQUAL(mbedtls_asn1_get_tag(&c, buf + sizeof(buf), &len, |
| 983 | MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE), 0); |
| 984 | TEST_EQUAL(mbedtls_x509_get_name(&c, buf + sizeof(buf), &parsed), 0); |
Werner Lewis | b3acb05 | 2022-06-17 15:59:58 +0100 | [diff] [blame] | 985 | |
| 986 | // Iterate over names and set next_merged nodes |
| 987 | parsed_cur = &parsed; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 988 | for (; next_merged != 0 && parsed_cur != NULL; next_merged = next_merged >> 1) { |
Werner Lewis | 12657cd | 2022-06-20 11:47:57 +0100 | [diff] [blame] | 989 | parsed_cur->next_merged = next_merged & 0x01; |
Werner Lewis | b3acb05 | 2022-06-17 15:59:58 +0100 | [diff] [blame] | 990 | parsed_cur = parsed_cur->next; |
| 991 | } |
| 992 | |
| 993 | // Iterate over RDN nodes and print OID of first element to buffer |
| 994 | parsed_cur = &parsed; |
| 995 | len = 0; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 996 | for (i = 0; parsed_cur != NULL; i++) { |
| 997 | TEST_EQUAL(mbedtls_oid_get_attr_short_name(&parsed_cur->oid, |
| 998 | &short_name), 0); |
| 999 | len += mbedtls_snprintf((char *) out + len, out_size - len, "%s ", short_name); |
| 1000 | parsed_cur = mbedtls_x509_dn_get_next(parsed_cur); |
Werner Lewis | b3acb05 | 2022-06-17 15:59:58 +0100 | [diff] [blame] | 1001 | } |
| 1002 | out[len-1] = 0; |
| 1003 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1004 | TEST_EQUAL(exp_count, i); |
| 1005 | TEST_EQUAL(strcmp((char *) out, expected_oids), 0); |
| 1006 | mbedtls_free(out); |
Werner Lewis | ac80a66 | 2022-06-23 11:58:02 +0100 | [diff] [blame] | 1007 | out = NULL; |
Werner Lewis | b3acb05 | 2022-06-17 15:59:58 +0100 | [diff] [blame] | 1008 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1009 | out_size = strlen(exp_dn_gets) + 1; |
Tom Cosgrove | 05b2a87 | 2023-07-21 11:31:13 +0100 | [diff] [blame] | 1010 | TEST_CALLOC(out, out_size); |
Werner Lewis | ac80a66 | 2022-06-23 11:58:02 +0100 | [diff] [blame] | 1011 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1012 | TEST_LE_S(0, mbedtls_x509_dn_gets((char *) out, out_size, &parsed)); |
| 1013 | TEST_EQUAL(strcmp((char *) out, exp_dn_gets), 0); |
Werner Lewis | b3acb05 | 2022-06-17 15:59:58 +0100 | [diff] [blame] | 1014 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1015 | mbedtls_free(out); |
| 1016 | mbedtls_asn1_free_named_data_list(&names); |
| 1017 | mbedtls_asn1_free_named_data_list_shallow(parsed.next); |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 1018 | USE_PSA_DONE(); |
Werner Lewis | b3acb05 | 2022-06-17 15:59:58 +0100 | [diff] [blame] | 1019 | } |
Werner Lewis | b3acb05 | 2022-06-17 15:59:58 +0100 | [diff] [blame] | 1020 | /* END_CASE */ |
| 1021 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1022 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1023 | void mbedtls_x509_time_is_past(char *crt_file, char *entity, int result) |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 1024 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1025 | mbedtls_x509_crt crt; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 1026 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1027 | mbedtls_x509_crt_init(&crt); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 1028 | USE_PSA_INIT(); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 1029 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1030 | TEST_EQUAL(mbedtls_x509_crt_parse_file(&crt, crt_file), 0); |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 1031 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1032 | if (strcmp(entity, "valid_from") == 0) { |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1033 | TEST_EQUAL(mbedtls_x509_time_is_past(&crt.valid_from), result); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1034 | } else if (strcmp(entity, "valid_to") == 0) { |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1035 | TEST_EQUAL(mbedtls_x509_time_is_past(&crt.valid_to), result); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1036 | } else { |
Agathiyan Bragadeesh | 763b353 | 2023-07-27 13:52:31 +0100 | [diff] [blame] | 1037 | TEST_FAIL("Unknown entity"); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1038 | } |
Paul Bakker | b08e684 | 2012-02-11 18:43:20 +0000 | [diff] [blame] | 1039 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 1040 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1041 | mbedtls_x509_crt_free(&crt); |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 1042 | USE_PSA_DONE(); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 1043 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 1044 | /* END_CASE */ |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 1045 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1046 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1047 | void mbedtls_x509_time_is_future(char *crt_file, char *entity, int result) |
Manuel Pégourié-Gonnard | 6304f78 | 2014-03-10 12:26:11 +0100 | [diff] [blame] | 1048 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1049 | mbedtls_x509_crt crt; |
Manuel Pégourié-Gonnard | 6304f78 | 2014-03-10 12:26:11 +0100 | [diff] [blame] | 1050 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1051 | mbedtls_x509_crt_init(&crt); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 1052 | USE_PSA_INIT(); |
Manuel Pégourié-Gonnard | 6304f78 | 2014-03-10 12:26:11 +0100 | [diff] [blame] | 1053 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1054 | TEST_EQUAL(mbedtls_x509_crt_parse_file(&crt, crt_file), 0); |
Manuel Pégourié-Gonnard | 6304f78 | 2014-03-10 12:26:11 +0100 | [diff] [blame] | 1055 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1056 | if (strcmp(entity, "valid_from") == 0) { |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1057 | TEST_EQUAL(mbedtls_x509_time_is_future(&crt.valid_from), result); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1058 | } else if (strcmp(entity, "valid_to") == 0) { |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1059 | TEST_EQUAL(mbedtls_x509_time_is_future(&crt.valid_to), result); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1060 | } else { |
Agathiyan Bragadeesh | 763b353 | 2023-07-27 13:52:31 +0100 | [diff] [blame] | 1061 | TEST_FAIL("Unknown entity"); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1062 | } |
Manuel Pégourié-Gonnard | 6304f78 | 2014-03-10 12:26:11 +0100 | [diff] [blame] | 1063 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 1064 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1065 | mbedtls_x509_crt_free(&crt); |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 1066 | USE_PSA_DONE(); |
Manuel Pégourié-Gonnard | 6304f78 | 2014-03-10 12:26:11 +0100 | [diff] [blame] | 1067 | } |
| 1068 | /* END_CASE */ |
| 1069 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1070 | /* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_FS_IO */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1071 | void x509parse_crt_file(char *crt_file, int result) |
Paul Bakker | 5a5fa92 | 2014-09-26 14:53:04 +0200 | [diff] [blame] | 1072 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1073 | mbedtls_x509_crt crt; |
Paul Bakker | 5a5fa92 | 2014-09-26 14:53:04 +0200 | [diff] [blame] | 1074 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1075 | mbedtls_x509_crt_init(&crt); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 1076 | USE_PSA_INIT(); |
Paul Bakker | 5a5fa92 | 2014-09-26 14:53:04 +0200 | [diff] [blame] | 1077 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1078 | TEST_EQUAL(mbedtls_x509_crt_parse_file(&crt, crt_file), result); |
Paul Bakker | 5a5fa92 | 2014-09-26 14:53:04 +0200 | [diff] [blame] | 1079 | |
| 1080 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1081 | mbedtls_x509_crt_free(&crt); |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 1082 | USE_PSA_DONE(); |
Paul Bakker | 5a5fa92 | 2014-09-26 14:53:04 +0200 | [diff] [blame] | 1083 | } |
| 1084 | /* END_CASE */ |
| 1085 | |
Minos Galanakis | a83ada4 | 2024-01-19 10:59:07 +0000 | [diff] [blame] | 1086 | /* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_FS_IO */ |
| 1087 | void mbedtls_x509_get_ca_istrue(char *crt_file, int result) |
| 1088 | { |
| 1089 | mbedtls_x509_crt crt; |
| 1090 | mbedtls_x509_crt_init(&crt); |
| 1091 | USE_PSA_INIT(); |
| 1092 | |
| 1093 | TEST_EQUAL(mbedtls_x509_crt_parse_file(&crt, crt_file), 0); |
| 1094 | TEST_EQUAL(mbedtls_x509_crt_get_ca_istrue(&crt), result); |
| 1095 | exit: |
| 1096 | mbedtls_x509_crt_free(&crt); |
| 1097 | USE_PSA_DONE(); |
| 1098 | } |
| 1099 | /* END_CASE */ |
| 1100 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1101 | /* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1102 | void x509parse_crt(data_t *buf, char *result_str, int result) |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 1103 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1104 | mbedtls_x509_crt crt; |
Hanno Becker | 612a2f1 | 2020-10-09 09:19:39 +0100 | [diff] [blame] | 1105 | #if !defined(MBEDTLS_X509_REMOVE_INFO) |
Hanno Becker | fff2d57 | 2020-10-09 09:45:19 +0100 | [diff] [blame] | 1106 | unsigned char output[2000] = { 0 }; |
Azim Khan | f1aaec9 | 2017-05-30 14:23:15 +0100 | [diff] [blame] | 1107 | int res; |
Hanno Becker | b4e5ddc | 2020-10-09 09:36:01 +0100 | [diff] [blame] | 1108 | #else |
| 1109 | ((void) result_str); |
Peter Kolbus | 9a969b6 | 2018-12-11 13:55:56 -0600 | [diff] [blame] | 1110 | #endif |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 1111 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1112 | mbedtls_x509_crt_init(&crt); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 1113 | USE_PSA_INIT(); |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 1114 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1115 | TEST_EQUAL(mbedtls_x509_crt_parse_der(&crt, buf->x, buf->len), result); |
Hanno Becker | 612a2f1 | 2020-10-09 09:19:39 +0100 | [diff] [blame] | 1116 | #if !defined(MBEDTLS_X509_REMOVE_INFO) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1117 | if ((result) == 0) { |
| 1118 | res = mbedtls_x509_crt_info((char *) output, 2000, "", &crt); |
| 1119 | TEST_ASSERT(res != -1); |
| 1120 | TEST_ASSERT(res != -2); |
Hanno Becker | 2d8a2c0 | 2019-01-31 09:15:53 +0000 | [diff] [blame] | 1121 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1122 | TEST_EQUAL(strcmp((char *) output, result_str), 0); |
Hanno Becker | 2d8a2c0 | 2019-01-31 09:15:53 +0000 | [diff] [blame] | 1123 | } |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1124 | memset(output, 0, 2000); |
Peter Kolbus | 9a969b6 | 2018-12-11 13:55:56 -0600 | [diff] [blame] | 1125 | #endif |
Hanno Becker | 2d8a2c0 | 2019-01-31 09:15:53 +0000 | [diff] [blame] | 1126 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1127 | mbedtls_x509_crt_free(&crt); |
| 1128 | mbedtls_x509_crt_init(&crt); |
Hanno Becker | 2d8a2c0 | 2019-01-31 09:15:53 +0000 | [diff] [blame] | 1129 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1130 | TEST_EQUAL(mbedtls_x509_crt_parse_der_nocopy(&crt, buf->x, buf->len), result); |
Hanno Becker | 612a2f1 | 2020-10-09 09:19:39 +0100 | [diff] [blame] | 1131 | #if !defined(MBEDTLS_X509_REMOVE_INFO) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1132 | if ((result) == 0) { |
| 1133 | memset(output, 0, 2000); |
Peter Kolbus | 9a969b6 | 2018-12-11 13:55:56 -0600 | [diff] [blame] | 1134 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1135 | res = mbedtls_x509_crt_info((char *) output, 2000, "", &crt); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 1136 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1137 | TEST_ASSERT(res != -1); |
| 1138 | TEST_ASSERT(res != -2); |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 1139 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1140 | TEST_EQUAL(strcmp((char *) output, result_str), 0); |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 1141 | } |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1142 | memset(output, 0, 2000); |
Hanno Becker | b4e5ddc | 2020-10-09 09:36:01 +0100 | [diff] [blame] | 1143 | #endif /* !MBEDTLS_X509_REMOVE_INFO */ |
Paul Bakker | b08e684 | 2012-02-11 18:43:20 +0000 | [diff] [blame] | 1144 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1145 | mbedtls_x509_crt_free(&crt); |
| 1146 | mbedtls_x509_crt_init(&crt); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1147 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1148 | TEST_EQUAL(mbedtls_x509_crt_parse_der_with_ext_cb(&crt, buf->x, buf->len, 0, NULL, NULL), |
| 1149 | result); |
Hanno Becker | b4e5ddc | 2020-10-09 09:36:01 +0100 | [diff] [blame] | 1150 | #if !defined(MBEDTLS_X509_REMOVE_INFO) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1151 | if ((result) == 0) { |
| 1152 | res = mbedtls_x509_crt_info((char *) output, 2000, "", &crt); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1153 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1154 | TEST_ASSERT(res != -1); |
| 1155 | TEST_ASSERT(res != -2); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1156 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1157 | TEST_EQUAL(strcmp((char *) output, result_str), 0); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1158 | } |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1159 | memset(output, 0, 2000); |
Hanno Becker | b4e5ddc | 2020-10-09 09:36:01 +0100 | [diff] [blame] | 1160 | #endif /* !MBEDTLS_X509_REMOVE_INFO */ |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1161 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1162 | mbedtls_x509_crt_free(&crt); |
| 1163 | mbedtls_x509_crt_init(&crt); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1164 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1165 | TEST_EQUAL(mbedtls_x509_crt_parse_der_with_ext_cb(&crt, buf->x, buf->len, 1, NULL, NULL), |
| 1166 | result); |
Hanno Becker | b4e5ddc | 2020-10-09 09:36:01 +0100 | [diff] [blame] | 1167 | #if !defined(MBEDTLS_X509_REMOVE_INFO) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1168 | if ((result) == 0) { |
| 1169 | res = mbedtls_x509_crt_info((char *) output, 2000, "", &crt); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1170 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1171 | TEST_ASSERT(res != -1); |
| 1172 | TEST_ASSERT(res != -2); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1173 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1174 | TEST_EQUAL(strcmp((char *) output, result_str), 0); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1175 | } |
Hanno Becker | b4e5ddc | 2020-10-09 09:36:01 +0100 | [diff] [blame] | 1176 | #endif /* !MBEDTLS_X509_REMOVE_INFO */ |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1177 | |
| 1178 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1179 | mbedtls_x509_crt_free(&crt); |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 1180 | USE_PSA_DONE(); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1181 | } |
| 1182 | /* END_CASE */ |
| 1183 | |
| 1184 | /* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1185 | void x509parse_crt_cb(data_t *buf, char *result_str, int result) |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1186 | { |
| 1187 | mbedtls_x509_crt crt; |
Nicola Di Lieto | e58b463 | 2020-05-29 22:58:25 +0200 | [diff] [blame] | 1188 | mbedtls_x509_buf oid; |
Hanno Becker | fff2d57 | 2020-10-09 09:45:19 +0100 | [diff] [blame] | 1189 | |
| 1190 | #if !defined(MBEDTLS_X509_REMOVE_INFO) |
| 1191 | unsigned char output[2000] = { 0 }; |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1192 | int res; |
Hanno Becker | fff2d57 | 2020-10-09 09:45:19 +0100 | [diff] [blame] | 1193 | #else |
| 1194 | ((void) result_str); |
| 1195 | #endif |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1196 | |
Nicola Di Lieto | e58b463 | 2020-05-29 22:58:25 +0200 | [diff] [blame] | 1197 | oid.tag = MBEDTLS_ASN1_OID; |
| 1198 | oid.len = MBEDTLS_OID_SIZE(MBEDTLS_OID_PKIX "\x01\x1F"); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1199 | oid.p = (unsigned char *) MBEDTLS_OID_PKIX "\x01\x1F"; |
Nicola Di Lieto | e58b463 | 2020-05-29 22:58:25 +0200 | [diff] [blame] | 1200 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1201 | mbedtls_x509_crt_init(&crt); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 1202 | USE_PSA_INIT(); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1203 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1204 | TEST_EQUAL(mbedtls_x509_crt_parse_der_with_ext_cb(&crt, buf->x, buf->len, 0, parse_crt_ext_cb, |
| 1205 | &oid), result); |
Hanno Becker | fff2d57 | 2020-10-09 09:45:19 +0100 | [diff] [blame] | 1206 | #if !defined(MBEDTLS_X509_REMOVE_INFO) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1207 | if ((result) == 0) { |
| 1208 | res = mbedtls_x509_crt_info((char *) output, 2000, "", &crt); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1209 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1210 | TEST_ASSERT(res != -1); |
| 1211 | TEST_ASSERT(res != -2); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1212 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1213 | TEST_EQUAL(strcmp((char *) output, result_str), 0); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1214 | } |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1215 | memset(output, 0, 2000); |
Hanno Becker | fff2d57 | 2020-10-09 09:45:19 +0100 | [diff] [blame] | 1216 | #endif /* !MBEDTLS_X509_REMOVE_INFO */ |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1217 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1218 | mbedtls_x509_crt_free(&crt); |
| 1219 | mbedtls_x509_crt_init(&crt); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1220 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1221 | TEST_EQUAL(mbedtls_x509_crt_parse_der_with_ext_cb(&crt, buf->x, buf->len, 1, parse_crt_ext_cb, |
| 1222 | &oid), (result)); |
Hanno Becker | fff2d57 | 2020-10-09 09:45:19 +0100 | [diff] [blame] | 1223 | #if !defined(MBEDTLS_X509_REMOVE_INFO) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1224 | if ((result) == 0) { |
| 1225 | res = mbedtls_x509_crt_info((char *) output, 2000, "", &crt); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1226 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1227 | TEST_ASSERT(res != -1); |
| 1228 | TEST_ASSERT(res != -2); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1229 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1230 | TEST_EQUAL(strcmp((char *) output, result_str), 0); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1231 | } |
Hanno Becker | fff2d57 | 2020-10-09 09:45:19 +0100 | [diff] [blame] | 1232 | #endif /* !MBEDTLS_X509_REMOVE_INFO */ |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1233 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 1234 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1235 | mbedtls_x509_crt_free(&crt); |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 1236 | USE_PSA_DONE(); |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 1237 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 1238 | /* END_CASE */ |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 1239 | |
Hanno Becker | 612a2f1 | 2020-10-09 09:19:39 +0100 | [diff] [blame] | 1240 | /* BEGIN_CASE depends_on:MBEDTLS_X509_CRL_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1241 | void x509parse_crl(data_t *buf, char *result_str, int result) |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame] | 1242 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1243 | mbedtls_x509_crl crl; |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame] | 1244 | unsigned char output[2000]; |
Azim Khan | f1aaec9 | 2017-05-30 14:23:15 +0100 | [diff] [blame] | 1245 | int res; |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame] | 1246 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1247 | mbedtls_x509_crl_init(&crl); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 1248 | USE_PSA_INIT(); |
| 1249 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1250 | memset(output, 0, 2000); |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame] | 1251 | |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame] | 1252 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1253 | TEST_EQUAL(mbedtls_x509_crl_parse(&crl, buf->x, buf->len), (result)); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1254 | if ((result) == 0) { |
| 1255 | res = mbedtls_x509_crl_info((char *) output, 2000, "", &crl); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 1256 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1257 | TEST_ASSERT(res != -1); |
| 1258 | TEST_ASSERT(res != -2); |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame] | 1259 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1260 | TEST_EQUAL(strcmp((char *) output, result_str), 0); |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame] | 1261 | } |
Paul Bakker | b08e684 | 2012-02-11 18:43:20 +0000 | [diff] [blame] | 1262 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 1263 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1264 | mbedtls_x509_crl_free(&crl); |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 1265 | USE_PSA_DONE(); |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame] | 1266 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 1267 | /* END_CASE */ |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame] | 1268 | |
Hanno Becker | 612a2f1 | 2020-10-09 09:19:39 +0100 | [diff] [blame] | 1269 | /* BEGIN_CASE depends_on:MBEDTLS_X509_CSR_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1270 | void mbedtls_x509_csr_parse(data_t *csr_der, char *ref_out, int ref_ret) |
Manuel Pégourié-Gonnard | d77cd5d | 2014-06-13 11:13:15 +0200 | [diff] [blame] | 1271 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1272 | mbedtls_x509_csr csr; |
Manuel Pégourié-Gonnard | d77cd5d | 2014-06-13 11:13:15 +0200 | [diff] [blame] | 1273 | char my_out[1000]; |
Manuel Pégourié-Gonnard | d77cd5d | 2014-06-13 11:13:15 +0200 | [diff] [blame] | 1274 | int my_ret; |
| 1275 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1276 | mbedtls_x509_csr_init(&csr); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 1277 | USE_PSA_INIT(); |
| 1278 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1279 | memset(my_out, 0, sizeof(my_out)); |
Manuel Pégourié-Gonnard | d77cd5d | 2014-06-13 11:13:15 +0200 | [diff] [blame] | 1280 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1281 | my_ret = mbedtls_x509_csr_parse_der(&csr, csr_der->x, csr_der->len); |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1282 | TEST_EQUAL(my_ret, ref_ret); |
Manuel Pégourié-Gonnard | d77cd5d | 2014-06-13 11:13:15 +0200 | [diff] [blame] | 1283 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1284 | if (ref_ret == 0) { |
| 1285 | size_t my_out_len = mbedtls_x509_csr_info(my_out, sizeof(my_out), "", &csr); |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1286 | TEST_EQUAL(my_out_len, strlen(ref_out)); |
| 1287 | TEST_EQUAL(strcmp(my_out, ref_out), 0); |
Manuel Pégourié-Gonnard | d77cd5d | 2014-06-13 11:13:15 +0200 | [diff] [blame] | 1288 | } |
| 1289 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 1290 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1291 | mbedtls_x509_csr_free(&csr); |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 1292 | USE_PSA_DONE(); |
Manuel Pégourié-Gonnard | d77cd5d | 2014-06-13 11:13:15 +0200 | [diff] [blame] | 1293 | } |
| 1294 | /* END_CASE */ |
| 1295 | |
Matthias Schulz | ab40822 | 2023-10-18 13:20:59 +0200 | [diff] [blame] | 1296 | /* BEGIN_CASE depends_on:MBEDTLS_X509_CSR_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */ |
| 1297 | void mbedtls_x509_csr_parse_with_ext_cb(data_t *csr_der, char *ref_out, int ref_ret, int accept) |
| 1298 | { |
| 1299 | mbedtls_x509_csr csr; |
| 1300 | char my_out[1000]; |
| 1301 | int my_ret; |
| 1302 | |
| 1303 | mbedtls_x509_csr_init(&csr); |
| 1304 | USE_PSA_INIT(); |
| 1305 | |
| 1306 | memset(my_out, 0, sizeof(my_out)); |
| 1307 | |
| 1308 | my_ret = mbedtls_x509_csr_parse_der_with_ext_cb(&csr, csr_der->x, csr_der->len, |
| 1309 | accept ? parse_csr_ext_accept_cb : |
Matthias Schulz | edc32ea | 2023-10-19 16:09:08 +0200 | [diff] [blame] | 1310 | parse_csr_ext_reject_cb, |
Matthias Schulz | ab40822 | 2023-10-18 13:20:59 +0200 | [diff] [blame] | 1311 | NULL); |
| 1312 | TEST_EQUAL(my_ret, ref_ret); |
| 1313 | |
| 1314 | if (ref_ret == 0) { |
| 1315 | size_t my_out_len = mbedtls_x509_csr_info(my_out, sizeof(my_out), "", &csr); |
| 1316 | TEST_EQUAL(my_out_len, strlen(ref_out)); |
| 1317 | TEST_EQUAL(strcmp(my_out, ref_out), 0); |
| 1318 | } |
| 1319 | |
| 1320 | exit: |
| 1321 | mbedtls_x509_csr_free(&csr); |
| 1322 | USE_PSA_DONE(); |
| 1323 | } |
| 1324 | /* END_CASE */ |
| 1325 | |
Przemek Stekiel | d7992df | 2023-01-25 16:19:50 +0100 | [diff] [blame] | 1326 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CSR_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */ |
| 1327 | void mbedtls_x509_csr_parse_file(char *csr_file, char *ref_out, int ref_ret) |
| 1328 | { |
| 1329 | mbedtls_x509_csr csr; |
| 1330 | char my_out[1000]; |
| 1331 | int my_ret; |
| 1332 | |
| 1333 | mbedtls_x509_csr_init(&csr); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 1334 | USE_PSA_INIT(); |
| 1335 | |
Przemek Stekiel | d7992df | 2023-01-25 16:19:50 +0100 | [diff] [blame] | 1336 | memset(my_out, 0, sizeof(my_out)); |
| 1337 | |
| 1338 | my_ret = mbedtls_x509_csr_parse_file(&csr, csr_file); |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1339 | TEST_EQUAL(my_ret, ref_ret); |
Przemek Stekiel | d7992df | 2023-01-25 16:19:50 +0100 | [diff] [blame] | 1340 | |
| 1341 | if (ref_ret == 0) { |
| 1342 | size_t my_out_len = mbedtls_x509_csr_info(my_out, sizeof(my_out), "", &csr); |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1343 | TEST_EQUAL(my_out_len, strlen(ref_out)); |
| 1344 | TEST_EQUAL(strcmp(my_out, ref_out), 0); |
Przemek Stekiel | d7992df | 2023-01-25 16:19:50 +0100 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | exit: |
| 1348 | mbedtls_x509_csr_free(&csr); |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 1349 | USE_PSA_DONE(); |
Przemek Stekiel | d7992df | 2023-01-25 16:19:50 +0100 | [diff] [blame] | 1350 | } |
| 1351 | /* END_CASE */ |
| 1352 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1353 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 1e5fec6 | 2023-04-13 18:13:48 +0200 | [diff] [blame] | 1354 | void mbedtls_x509_crt_parse_file(char *crt_path, int ret, int nb_crt) |
| 1355 | { |
| 1356 | mbedtls_x509_crt chain, *cur; |
| 1357 | int i; |
| 1358 | |
| 1359 | mbedtls_x509_crt_init(&chain); |
| 1360 | USE_PSA_INIT(); |
| 1361 | |
| 1362 | TEST_EQUAL(mbedtls_x509_crt_parse_file(&chain, crt_path), ret); |
| 1363 | |
| 1364 | /* Check how many certs we got */ |
| 1365 | for (i = 0, cur = &chain; cur != NULL; cur = cur->next) { |
| 1366 | if (cur->raw.p != NULL) { |
| 1367 | i++; |
| 1368 | } |
| 1369 | } |
| 1370 | |
| 1371 | TEST_EQUAL(i, nb_crt); |
| 1372 | |
| 1373 | exit: |
| 1374 | mbedtls_x509_crt_free(&chain); |
| 1375 | USE_PSA_DONE(); |
| 1376 | } |
| 1377 | /* END_CASE */ |
| 1378 | |
| 1379 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1380 | void mbedtls_x509_crt_parse_path(char *crt_path, int ret, int nb_crt) |
Manuel Pégourié-Gonnard | fbae2a1 | 2013-11-26 16:43:39 +0100 | [diff] [blame] | 1381 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1382 | mbedtls_x509_crt chain, *cur; |
Manuel Pégourié-Gonnard | fbae2a1 | 2013-11-26 16:43:39 +0100 | [diff] [blame] | 1383 | int i; |
| 1384 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1385 | mbedtls_x509_crt_init(&chain); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 1386 | USE_PSA_INIT(); |
Manuel Pégourié-Gonnard | fbae2a1 | 2013-11-26 16:43:39 +0100 | [diff] [blame] | 1387 | |
Gilles Peskine | 55ad28a | 2023-04-13 18:14:45 +0200 | [diff] [blame] | 1388 | TEST_EQUAL(mbedtls_x509_crt_parse_path(&chain, crt_path), ret); |
Manuel Pégourié-Gonnard | fbae2a1 | 2013-11-26 16:43:39 +0100 | [diff] [blame] | 1389 | |
| 1390 | /* Check how many certs we got */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1391 | for (i = 0, cur = &chain; cur != NULL; cur = cur->next) { |
| 1392 | if (cur->raw.p != NULL) { |
Manuel Pégourié-Gonnard | fbae2a1 | 2013-11-26 16:43:39 +0100 | [diff] [blame] | 1393 | i++; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1394 | } |
| 1395 | } |
Manuel Pégourié-Gonnard | fbae2a1 | 2013-11-26 16:43:39 +0100 | [diff] [blame] | 1396 | |
Gilles Peskine | 55ad28a | 2023-04-13 18:14:45 +0200 | [diff] [blame] | 1397 | TEST_EQUAL(i, nb_crt); |
Manuel Pégourié-Gonnard | fbae2a1 | 2013-11-26 16:43:39 +0100 | [diff] [blame] | 1398 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 1399 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1400 | mbedtls_x509_crt_free(&chain); |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 1401 | USE_PSA_DONE(); |
Manuel Pégourié-Gonnard | fbae2a1 | 2013-11-26 16:43:39 +0100 | [diff] [blame] | 1402 | } |
| 1403 | /* END_CASE */ |
| 1404 | |
Janos Follath | 822b2c3 | 2015-10-11 10:25:22 +0200 | [diff] [blame] | 1405 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1406 | void mbedtls_x509_crt_verify_max(char *ca_file, char *chain_dir, int nb_int, |
| 1407 | int ret_chk, int flags_chk) |
Manuel Pégourié-Gonnard | 1beb048 | 2017-06-05 13:49:44 +0200 | [diff] [blame] | 1408 | { |
| 1409 | char file_buf[128]; |
| 1410 | int ret; |
| 1411 | uint32_t flags; |
| 1412 | mbedtls_x509_crt trusted, chain; |
| 1413 | |
| 1414 | /* |
| 1415 | * We expect chain_dir to contain certificates 00.crt, 01.crt, etc. |
| 1416 | * with NN.crt signed by NN-1.crt |
| 1417 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1418 | mbedtls_x509_crt_init(&trusted); |
| 1419 | mbedtls_x509_crt_init(&chain); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 1420 | MD_OR_USE_PSA_INIT(); |
Manuel Pégourié-Gonnard | 1beb048 | 2017-06-05 13:49:44 +0200 | [diff] [blame] | 1421 | |
| 1422 | /* Load trusted root */ |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1423 | TEST_EQUAL(mbedtls_x509_crt_parse_file(&trusted, ca_file), 0); |
Manuel Pégourié-Gonnard | 1beb048 | 2017-06-05 13:49:44 +0200 | [diff] [blame] | 1424 | |
| 1425 | /* Load a chain with nb_int intermediates (from 01 to nb_int), |
| 1426 | * plus one "end-entity" cert (nb_int + 1) */ |
Dave Rodgman | 6dd757a | 2023-02-02 12:40:50 +0000 | [diff] [blame] | 1427 | ret = mbedtls_snprintf(file_buf, sizeof(file_buf), "%s/c%02d.pem", chain_dir, |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1428 | nb_int + 1); |
Dave Rodgman | 6dd757a | 2023-02-02 12:40:50 +0000 | [diff] [blame] | 1429 | TEST_ASSERT(ret > 0 && (size_t) ret < sizeof(file_buf)); |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1430 | TEST_EQUAL(mbedtls_x509_crt_parse_file(&chain, file_buf), 0); |
Manuel Pégourié-Gonnard | 1beb048 | 2017-06-05 13:49:44 +0200 | [diff] [blame] | 1431 | |
| 1432 | /* Try to verify that chain */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1433 | ret = mbedtls_x509_crt_verify(&chain, &trusted, NULL, NULL, &flags, |
| 1434 | NULL, NULL); |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1435 | TEST_EQUAL(ret, ret_chk); |
| 1436 | TEST_EQUAL(flags, (uint32_t) flags_chk); |
Manuel Pégourié-Gonnard | 1beb048 | 2017-06-05 13:49:44 +0200 | [diff] [blame] | 1437 | |
| 1438 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1439 | mbedtls_x509_crt_free(&chain); |
| 1440 | mbedtls_x509_crt_free(&trusted); |
Manuel Pégourié-Gonnard | 33a1302 | 2023-03-17 14:02:49 +0100 | [diff] [blame] | 1441 | MD_OR_USE_PSA_DONE(); |
Manuel Pégourié-Gonnard | 1beb048 | 2017-06-05 13:49:44 +0200 | [diff] [blame] | 1442 | } |
| 1443 | /* END_CASE */ |
| 1444 | |
| 1445 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1446 | void mbedtls_x509_crt_verify_chain(char *chain_paths, char *trusted_ca, |
| 1447 | int flags_result, int result, |
| 1448 | char *profile_name, int vrfy_fatal_lvls) |
Janos Follath | 822b2c3 | 2015-10-11 10:25:22 +0200 | [diff] [blame] | 1449 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1450 | char *act; |
Janos Follath | 822b2c3 | 2015-10-11 10:25:22 +0200 | [diff] [blame] | 1451 | uint32_t flags; |
Manuel Pégourié-Gonnard | e54931f | 2017-05-22 12:04:25 +0200 | [diff] [blame] | 1452 | int res; |
Manuel Pégourié-Gonnard | e670f90 | 2015-10-30 09:23:19 +0100 | [diff] [blame] | 1453 | mbedtls_x509_crt trusted, chain; |
Manuel Pégourié-Gonnard | e54931f | 2017-05-22 12:04:25 +0200 | [diff] [blame] | 1454 | const mbedtls_x509_crt_profile *profile = NULL; |
Janos Follath | ef4f258 | 2015-10-11 16:17:27 +0200 | [diff] [blame] | 1455 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1456 | mbedtls_x509_crt_init(&chain); |
| 1457 | mbedtls_x509_crt_init(&trusted); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 1458 | MD_OR_USE_PSA_INIT(); |
Janos Follath | 822b2c3 | 2015-10-11 10:25:22 +0200 | [diff] [blame] | 1459 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1460 | while ((act = mystrsep(&chain_paths, " ")) != NULL) { |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1461 | TEST_EQUAL(mbedtls_x509_crt_parse_file(&chain, act), 0); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1462 | } |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1463 | TEST_EQUAL(mbedtls_x509_crt_parse_file(&trusted, trusted_ca), 0); |
Janos Follath | 822b2c3 | 2015-10-11 10:25:22 +0200 | [diff] [blame] | 1464 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1465 | if (strcmp(profile_name, "") == 0) { |
Manuel Pégourié-Gonnard | e54931f | 2017-05-22 12:04:25 +0200 | [diff] [blame] | 1466 | profile = &mbedtls_x509_crt_profile_default; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1467 | } else if (strcmp(profile_name, "next") == 0) { |
Manuel Pégourié-Gonnard | e54931f | 2017-05-22 12:04:25 +0200 | [diff] [blame] | 1468 | profile = &mbedtls_x509_crt_profile_next; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1469 | } else if (strcmp(profile_name, "suiteb") == 0) { |
Manuel Pégourié-Gonnard | e54931f | 2017-05-22 12:04:25 +0200 | [diff] [blame] | 1470 | profile = &mbedtls_x509_crt_profile_suiteb; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1471 | } else if (strcmp(profile_name, "rsa3072") == 0) { |
Manuel Pégourié-Gonnard | 6622fed | 2017-05-23 11:29:29 +0200 | [diff] [blame] | 1472 | profile = &profile_rsa3072; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1473 | } else if (strcmp(profile_name, "sha512") == 0) { |
Manuel Pégourié-Gonnard | 6622fed | 2017-05-23 11:29:29 +0200 | [diff] [blame] | 1474 | profile = &profile_sha512; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1475 | } |
Manuel Pégourié-Gonnard | e54931f | 2017-05-22 12:04:25 +0200 | [diff] [blame] | 1476 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1477 | res = mbedtls_x509_crt_verify_with_profile(&chain, &trusted, NULL, profile, |
| 1478 | NULL, &flags, verify_fatal, &vrfy_fatal_lvls); |
Janos Follath | ef4f258 | 2015-10-11 16:17:27 +0200 | [diff] [blame] | 1479 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1480 | TEST_EQUAL(res, (result)); |
| 1481 | TEST_EQUAL(flags, (uint32_t) (flags_result)); |
Janos Follath | 822b2c3 | 2015-10-11 10:25:22 +0200 | [diff] [blame] | 1482 | |
| 1483 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1484 | mbedtls_x509_crt_free(&trusted); |
| 1485 | mbedtls_x509_crt_free(&chain); |
Manuel Pégourié-Gonnard | 33a1302 | 2023-03-17 14:02:49 +0100 | [diff] [blame] | 1486 | MD_OR_USE_PSA_DONE(); |
Janos Follath | 822b2c3 | 2015-10-11 10:25:22 +0200 | [diff] [blame] | 1487 | } |
| 1488 | /* END_CASE */ |
| 1489 | |
Hanno Becker | 612a2f1 | 2020-10-09 09:19:39 +0100 | [diff] [blame] | 1490 | /* BEGIN_CASE depends_on:MBEDTLS_X509_USE_C:!MBEDTLS_X509_REMOVE_INFO */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1491 | void x509_oid_desc(data_t *buf, char *ref_desc) |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 1492 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1493 | mbedtls_x509_buf oid; |
Manuel Pégourié-Gonnard | 48d3cef | 2015-03-20 18:14:26 +0000 | [diff] [blame] | 1494 | const char *desc = NULL; |
Manuel Pégourié-Gonnard | 48d3cef | 2015-03-20 18:14:26 +0000 | [diff] [blame] | 1495 | int ret; |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 1496 | |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 1497 | USE_PSA_INIT(); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 1498 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1499 | oid.tag = MBEDTLS_ASN1_OID; |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 1500 | oid.p = buf->x; |
| 1501 | oid.len = buf->len; |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 1502 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1503 | ret = mbedtls_oid_get_extended_key_usage(&oid, &desc); |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 1504 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1505 | if (strcmp(ref_desc, "notfound") == 0) { |
| 1506 | TEST_ASSERT(ret != 0); |
| 1507 | TEST_ASSERT(desc == NULL); |
| 1508 | } else { |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1509 | TEST_EQUAL(ret, 0); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1510 | TEST_ASSERT(desc != NULL); |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1511 | TEST_EQUAL(strcmp(desc, ref_desc), 0); |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 1512 | } |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 1513 | |
| 1514 | exit: |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 1515 | USE_PSA_DONE(); |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 1516 | } |
| 1517 | /* END_CASE */ |
| 1518 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1519 | /* BEGIN_CASE depends_on:MBEDTLS_X509_USE_C */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1520 | void x509_oid_numstr(data_t *oid_buf, char *numstr, int blen, int ret) |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 1521 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1522 | mbedtls_x509_buf oid; |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 1523 | char num_buf[100]; |
| 1524 | |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 1525 | USE_PSA_INIT(); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 1526 | |
Dave Rodgman | 6dd757a | 2023-02-02 12:40:50 +0000 | [diff] [blame] | 1527 | memset(num_buf, 0x2a, sizeof(num_buf)); |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 1528 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1529 | oid.tag = MBEDTLS_ASN1_OID; |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 1530 | oid.p = oid_buf->x; |
| 1531 | oid.len = oid_buf->len; |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 1532 | |
Dave Rodgman | 6dd757a | 2023-02-02 12:40:50 +0000 | [diff] [blame] | 1533 | TEST_ASSERT((size_t) blen <= sizeof(num_buf)); |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 1534 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1535 | TEST_EQUAL(mbedtls_oid_get_numeric_string(num_buf, blen, &oid), ret); |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 1536 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1537 | if (ret >= 0) { |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1538 | TEST_EQUAL(num_buf[ret], 0); |
| 1539 | TEST_EQUAL(strcmp(num_buf, numstr), 0); |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 1540 | } |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 1541 | |
| 1542 | exit: |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 1543 | USE_PSA_DONE(); |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 1544 | } |
| 1545 | /* END_CASE */ |
| 1546 | |
TRodziewicz | 442fdc2 | 2021-06-07 13:52:23 +0200 | [diff] [blame] | 1547 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1548 | void x509_check_key_usage(char *crt_file, int usage, int ret) |
Manuel Pégourié-Gonnard | 603116c | 2014-04-09 09:50:03 +0200 | [diff] [blame] | 1549 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1550 | mbedtls_x509_crt crt; |
Manuel Pégourié-Gonnard | 603116c | 2014-04-09 09:50:03 +0200 | [diff] [blame] | 1551 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1552 | mbedtls_x509_crt_init(&crt); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 1553 | USE_PSA_INIT(); |
Manuel Pégourié-Gonnard | 603116c | 2014-04-09 09:50:03 +0200 | [diff] [blame] | 1554 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1555 | TEST_EQUAL(mbedtls_x509_crt_parse_file(&crt, crt_file), 0); |
Manuel Pégourié-Gonnard | 603116c | 2014-04-09 09:50:03 +0200 | [diff] [blame] | 1556 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1557 | TEST_EQUAL(mbedtls_x509_crt_check_key_usage(&crt, usage), ret); |
Manuel Pégourié-Gonnard | 603116c | 2014-04-09 09:50:03 +0200 | [diff] [blame] | 1558 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 1559 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1560 | mbedtls_x509_crt_free(&crt); |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 1561 | USE_PSA_DONE(); |
Manuel Pégourié-Gonnard | 603116c | 2014-04-09 09:50:03 +0200 | [diff] [blame] | 1562 | } |
| 1563 | /* END_CASE */ |
| 1564 | |
TRodziewicz | 442fdc2 | 2021-06-07 13:52:23 +0200 | [diff] [blame] | 1565 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1566 | void x509_check_extended_key_usage(char *crt_file, data_t *oid, int ret |
| 1567 | ) |
Manuel Pégourié-Gonnard | 7afb8a0 | 2014-04-10 17:53:56 +0200 | [diff] [blame] | 1568 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1569 | mbedtls_x509_crt crt; |
Manuel Pégourié-Gonnard | 7afb8a0 | 2014-04-10 17:53:56 +0200 | [diff] [blame] | 1570 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1571 | mbedtls_x509_crt_init(&crt); |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 1572 | USE_PSA_INIT(); |
Manuel Pégourié-Gonnard | 7afb8a0 | 2014-04-10 17:53:56 +0200 | [diff] [blame] | 1573 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1574 | TEST_EQUAL(mbedtls_x509_crt_parse_file(&crt, crt_file), 0); |
Manuel Pégourié-Gonnard | 7afb8a0 | 2014-04-10 17:53:56 +0200 | [diff] [blame] | 1575 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1576 | TEST_EQUAL(mbedtls_x509_crt_check_extended_key_usage(&crt, (const char *) oid->x, oid->len), |
| 1577 | ret); |
Manuel Pégourié-Gonnard | 7afb8a0 | 2014-04-10 17:53:56 +0200 | [diff] [blame] | 1578 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 1579 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1580 | mbedtls_x509_crt_free(&crt); |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 1581 | USE_PSA_DONE(); |
Manuel Pégourié-Gonnard | 7afb8a0 | 2014-04-10 17:53:56 +0200 | [diff] [blame] | 1582 | } |
| 1583 | /* END_CASE */ |
| 1584 | |
Andres AG | 4b76aec | 2016-09-23 13:16:02 +0100 | [diff] [blame] | 1585 | /* BEGIN_CASE depends_on:MBEDTLS_X509_USE_C */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1586 | void x509_get_time(int tag, char *time_str, int ret, int year, int mon, |
| 1587 | int day, int hour, int min, int sec) |
Andres AG | 4b76aec | 2016-09-23 13:16:02 +0100 | [diff] [blame] | 1588 | { |
| 1589 | mbedtls_x509_time time; |
Janos Follath | ea7054a | 2017-02-08 14:13:02 +0000 | [diff] [blame] | 1590 | unsigned char buf[21]; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1591 | unsigned char *start = buf; |
| 1592 | unsigned char *end = buf; |
Andres AG | 4b76aec | 2016-09-23 13:16:02 +0100 | [diff] [blame] | 1593 | |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 1594 | USE_PSA_INIT(); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1595 | memset(&time, 0x00, sizeof(time)); |
| 1596 | *end = (unsigned char) tag; end++; |
| 1597 | *end = strlen(time_str); |
| 1598 | TEST_ASSERT(*end < 20); |
Andres AG | 4b76aec | 2016-09-23 13:16:02 +0100 | [diff] [blame] | 1599 | end++; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1600 | memcpy(end, time_str, (size_t) *(end - 1)); |
Andres AG | 4b76aec | 2016-09-23 13:16:02 +0100 | [diff] [blame] | 1601 | end += *(end - 1); |
| 1602 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1603 | TEST_EQUAL(mbedtls_x509_get_time(&start, end, &time), ret); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1604 | if (ret == 0) { |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1605 | TEST_EQUAL(year, time.year); |
| 1606 | TEST_EQUAL(mon, time.mon); |
| 1607 | TEST_EQUAL(day, time.day); |
| 1608 | TEST_EQUAL(hour, time.hour); |
| 1609 | TEST_EQUAL(min, time.min); |
| 1610 | TEST_EQUAL(sec, time.sec); |
Andres AG | 4b76aec | 2016-09-23 13:16:02 +0100 | [diff] [blame] | 1611 | } |
valerio | 32f2ac9 | 2023-04-20 11:59:52 +0200 | [diff] [blame] | 1612 | exit: |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 1613 | USE_PSA_DONE(); |
Andres AG | 4b76aec | 2016-09-23 13:16:02 +0100 | [diff] [blame] | 1614 | } |
| 1615 | /* END_CASE */ |
| 1616 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1617 | /* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_RSASSA_PSS_SUPPORT */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1618 | void x509_parse_rsassa_pss_params(data_t *params, int params_tag, |
| 1619 | int ref_msg_md, int ref_mgf_md, |
| 1620 | int ref_salt_len, int ref_ret) |
Manuel Pégourié-Gonnard | 8540369 | 2014-06-06 14:48:38 +0200 | [diff] [blame] | 1621 | { |
| 1622 | int my_ret; |
Ronald Cron | ac6ae35 | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 1623 | mbedtls_x509_buf buf; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1624 | mbedtls_md_type_t my_msg_md, my_mgf_md; |
Manuel Pégourié-Gonnard | 8540369 | 2014-06-06 14:48:38 +0200 | [diff] [blame] | 1625 | int my_salt_len; |
| 1626 | |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 1627 | USE_PSA_INIT(); |
| 1628 | |
Ronald Cron | ac6ae35 | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 1629 | buf.p = params->x; |
| 1630 | buf.len = params->len; |
| 1631 | buf.tag = params_tag; |
Manuel Pégourié-Gonnard | 8540369 | 2014-06-06 14:48:38 +0200 | [diff] [blame] | 1632 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1633 | my_ret = mbedtls_x509_get_rsassa_pss_params(&buf, &my_msg_md, &my_mgf_md, |
| 1634 | &my_salt_len); |
Manuel Pégourié-Gonnard | 8540369 | 2014-06-06 14:48:38 +0200 | [diff] [blame] | 1635 | |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1636 | TEST_EQUAL(my_ret, ref_ret); |
Manuel Pégourié-Gonnard | 8540369 | 2014-06-06 14:48:38 +0200 | [diff] [blame] | 1637 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1638 | if (ref_ret == 0) { |
Demi Marie Obenour | 16442cc | 2022-11-26 22:19:48 -0500 | [diff] [blame] | 1639 | TEST_EQUAL(my_msg_md, (mbedtls_md_type_t) ref_msg_md); |
| 1640 | TEST_EQUAL(my_mgf_md, (mbedtls_md_type_t) ref_mgf_md); |
| 1641 | TEST_EQUAL(my_salt_len, ref_salt_len); |
Manuel Pégourié-Gonnard | 8540369 | 2014-06-06 14:48:38 +0200 | [diff] [blame] | 1642 | } |
| 1643 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 1644 | exit: |
Valerio Setti | 569c171 | 2023-04-19 14:53:36 +0200 | [diff] [blame] | 1645 | USE_PSA_DONE(); |
Manuel Pégourié-Gonnard | 8540369 | 2014-06-06 14:48:38 +0200 | [diff] [blame] | 1646 | } |
| 1647 | /* END_CASE */ |
toth92g | a41954d | 2021-02-12 16:11:17 +0100 | [diff] [blame] | 1648 | |
Przemek Stekiel | 05d5c3e | 2023-05-16 16:24:44 +0200 | [diff] [blame] | 1649 | /* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_FS_IO */ |
Przemek Stekiel | 0ad1006 | 2023-04-06 11:11:58 +0200 | [diff] [blame] | 1650 | void x509_crt_parse_subjectkeyid(char *file, data_t *subjectKeyId, int ref_ret) |
toth92g | a41954d | 2021-02-12 16:11:17 +0100 | [diff] [blame] | 1651 | { |
| 1652 | mbedtls_x509_crt crt; |
toth92g | a41954d | 2021-02-12 16:11:17 +0100 | [diff] [blame] | 1653 | |
| 1654 | mbedtls_x509_crt_init(&crt); |
| 1655 | |
Przemek Stekiel | a6a0a79 | 2023-04-24 10:18:52 +0200 | [diff] [blame] | 1656 | TEST_EQUAL(mbedtls_x509_crt_parse_file(&crt, file), ref_ret); |
toth92g | a41954d | 2021-02-12 16:11:17 +0100 | [diff] [blame] | 1657 | |
toth92g | 357b297 | 2021-05-04 15:41:35 +0200 | [diff] [blame] | 1658 | if (ref_ret == 0) { |
Przemek Stekiel | a6a0a79 | 2023-04-24 10:18:52 +0200 | [diff] [blame] | 1659 | TEST_EQUAL(crt.subject_key_id.tag, MBEDTLS_ASN1_OCTET_STRING); |
| 1660 | TEST_EQUAL(memcmp(crt.subject_key_id.p, subjectKeyId->x, subjectKeyId->len), 0); |
| 1661 | TEST_EQUAL(crt.subject_key_id.len, subjectKeyId->len); |
toth92g | 357b297 | 2021-05-04 15:41:35 +0200 | [diff] [blame] | 1662 | } else { |
Przemek Stekiel | a6a0a79 | 2023-04-24 10:18:52 +0200 | [diff] [blame] | 1663 | TEST_EQUAL(crt.subject_key_id.tag, 0); |
| 1664 | TEST_EQUAL(crt.subject_key_id.len, 0); |
toth92g | a41954d | 2021-02-12 16:11:17 +0100 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | exit: |
| 1668 | mbedtls_x509_crt_free(&crt); |
| 1669 | } |
| 1670 | /* END_CASE */ |
| 1671 | |
Przemek Stekiel | 05d5c3e | 2023-05-16 16:24:44 +0200 | [diff] [blame] | 1672 | /* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_FS_IO */ |
Przemek Stekiel | 2568d47 | 2023-04-06 09:23:25 +0200 | [diff] [blame] | 1673 | void x509_crt_parse_authoritykeyid(char *file, |
Przemek Stekiel | ff9c299 | 2023-05-16 19:14:19 +0200 | [diff] [blame] | 1674 | data_t *keyId, |
toth92g | 5042b10 | 2021-05-06 08:22:17 +0200 | [diff] [blame] | 1675 | char *authorityKeyId_issuer, |
Przemek Stekiel | ff9c299 | 2023-05-16 19:14:19 +0200 | [diff] [blame] | 1676 | data_t *serial, |
toth92g | 5042b10 | 2021-05-06 08:22:17 +0200 | [diff] [blame] | 1677 | int ref_ret) |
toth92g | a41954d | 2021-02-12 16:11:17 +0100 | [diff] [blame] | 1678 | { |
| 1679 | mbedtls_x509_crt crt; |
Przemek Stekiel | 39dbe23 | 2023-04-03 10:19:22 +0200 | [diff] [blame] | 1680 | mbedtls_x509_subject_alternative_name san; |
David Horstmann | 9a3a1a6 | 2023-06-22 16:59:09 +0100 | [diff] [blame] | 1681 | char name_buf[128]; |
toth92g | a41954d | 2021-02-12 16:11:17 +0100 | [diff] [blame] | 1682 | |
| 1683 | mbedtls_x509_crt_init(&crt); |
| 1684 | |
Przemek Stekiel | a6a0a79 | 2023-04-24 10:18:52 +0200 | [diff] [blame] | 1685 | TEST_EQUAL(mbedtls_x509_crt_parse_file(&crt, file), ref_ret); |
toth92g | a41954d | 2021-02-12 16:11:17 +0100 | [diff] [blame] | 1686 | |
toth92g | 357b297 | 2021-05-04 15:41:35 +0200 | [diff] [blame] | 1687 | if (ref_ret == 0) { |
toth92g | a41954d | 2021-02-12 16:11:17 +0100 | [diff] [blame] | 1688 | /* KeyId test */ |
Przemek Stekiel | ff9c299 | 2023-05-16 19:14:19 +0200 | [diff] [blame] | 1689 | if (keyId->len > 0) { |
Przemek Stekiel | a6a0a79 | 2023-04-24 10:18:52 +0200 | [diff] [blame] | 1690 | TEST_EQUAL(crt.authority_key_id.keyIdentifier.tag, MBEDTLS_ASN1_OCTET_STRING); |
| 1691 | TEST_EQUAL(memcmp(crt.authority_key_id.keyIdentifier.p, keyId->x, keyId->len), 0); |
| 1692 | TEST_EQUAL(crt.authority_key_id.keyIdentifier.len, keyId->len); |
Przemek Stekiel | 05d5c3e | 2023-05-16 16:24:44 +0200 | [diff] [blame] | 1693 | } else { |
| 1694 | TEST_EQUAL(crt.authority_key_id.keyIdentifier.tag, 0); |
| 1695 | TEST_EQUAL(crt.authority_key_id.keyIdentifier.len, 0); |
Przemek Stekiel | 1969f6a | 2023-04-18 08:38:16 +0200 | [diff] [blame] | 1696 | } |
toth92g | a41954d | 2021-02-12 16:11:17 +0100 | [diff] [blame] | 1697 | |
Przemek Stekiel | 05d5c3e | 2023-05-16 16:24:44 +0200 | [diff] [blame] | 1698 | |
toth92g | a41954d | 2021-02-12 16:11:17 +0100 | [diff] [blame] | 1699 | /* Issuer test */ |
Przemek Stekiel | ff9c299 | 2023-05-16 19:14:19 +0200 | [diff] [blame] | 1700 | if (strlen(authorityKeyId_issuer) > 0) { |
Przemek Stekiel | 1969f6a | 2023-04-18 08:38:16 +0200 | [diff] [blame] | 1701 | mbedtls_x509_sequence *issuerPtr = &crt.authority_key_id.authorityCertIssuer; |
Przemek Stekiel | 0198421 | 2023-02-09 09:29:34 +0100 | [diff] [blame] | 1702 | |
Przemek Stekiel | a6a0a79 | 2023-04-24 10:18:52 +0200 | [diff] [blame] | 1703 | TEST_EQUAL(mbedtls_x509_parse_subject_alt_name(&issuerPtr->buf, &san), 0); |
Przemek Stekiel | 0198421 | 2023-02-09 09:29:34 +0100 | [diff] [blame] | 1704 | |
David Horstmann | 9a3a1a6 | 2023-06-22 16:59:09 +0100 | [diff] [blame] | 1705 | TEST_ASSERT(mbedtls_x509_dn_gets(name_buf, sizeof(name_buf), |
| 1706 | &san.san.directory_name) |
| 1707 | > 0); |
| 1708 | TEST_EQUAL(strcmp(name_buf, authorityKeyId_issuer), 0); |
Przemek Stekiel | 0198421 | 2023-02-09 09:29:34 +0100 | [diff] [blame] | 1709 | |
Przemek Stekiel | 1969f6a | 2023-04-18 08:38:16 +0200 | [diff] [blame] | 1710 | mbedtls_x509_free_subject_alt_name(&san); |
toth92g | a41954d | 2021-02-12 16:11:17 +0100 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | /* Serial test */ |
Przemek Stekiel | ff9c299 | 2023-05-16 19:14:19 +0200 | [diff] [blame] | 1714 | if (serial->len > 0) { |
Przemek Stekiel | a6a0a79 | 2023-04-24 10:18:52 +0200 | [diff] [blame] | 1715 | TEST_EQUAL(crt.authority_key_id.authorityCertSerialNumber.tag, |
Przemek Stekiel | ff9c299 | 2023-05-16 19:14:19 +0200 | [diff] [blame] | 1716 | MBEDTLS_ASN1_INTEGER); |
Przemek Stekiel | a6a0a79 | 2023-04-24 10:18:52 +0200 | [diff] [blame] | 1717 | TEST_EQUAL(memcmp(crt.authority_key_id.authorityCertSerialNumber.p, |
Przemek Stekiel | ff9c299 | 2023-05-16 19:14:19 +0200 | [diff] [blame] | 1718 | serial->x, serial->len), 0); |
Przemek Stekiel | a6a0a79 | 2023-04-24 10:18:52 +0200 | [diff] [blame] | 1719 | TEST_EQUAL(crt.authority_key_id.authorityCertSerialNumber.len, serial->len); |
Przemek Stekiel | 05d5c3e | 2023-05-16 16:24:44 +0200 | [diff] [blame] | 1720 | } else { |
| 1721 | TEST_EQUAL(crt.authority_key_id.authorityCertSerialNumber.tag, 0); |
| 1722 | TEST_EQUAL(crt.authority_key_id.authorityCertSerialNumber.len, 0); |
Przemek Stekiel | 1969f6a | 2023-04-18 08:38:16 +0200 | [diff] [blame] | 1723 | } |
Przemek Stekiel | 0ad1006 | 2023-04-06 11:11:58 +0200 | [diff] [blame] | 1724 | |
toth92g | 357b297 | 2021-05-04 15:41:35 +0200 | [diff] [blame] | 1725 | } else { |
Przemek Stekiel | a6a0a79 | 2023-04-24 10:18:52 +0200 | [diff] [blame] | 1726 | TEST_EQUAL(crt.authority_key_id.keyIdentifier.tag, 0); |
| 1727 | TEST_EQUAL(crt.authority_key_id.keyIdentifier.len, 0); |
toth92g | a41954d | 2021-02-12 16:11:17 +0100 | [diff] [blame] | 1728 | |
Przemek Stekiel | a6a0a79 | 2023-04-24 10:18:52 +0200 | [diff] [blame] | 1729 | TEST_EQUAL(crt.authority_key_id.authorityCertSerialNumber.tag, 0); |
| 1730 | TEST_EQUAL(crt.authority_key_id.authorityCertSerialNumber.len, 0); |
toth92g | a41954d | 2021-02-12 16:11:17 +0100 | [diff] [blame] | 1731 | } |
| 1732 | |
| 1733 | exit: |
| 1734 | mbedtls_x509_crt_free(&crt); |
| 1735 | } |
| 1736 | /* END_CASE */ |