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" |
| 7 | #include "mbedtls/pem.h" |
| 8 | #include "mbedtls/oid.h" |
| 9 | #include "mbedtls/base64.h" |
Chris Jones | 9f7a693 | 2021-04-14 12:12:09 +0100 | [diff] [blame] | 10 | #include "mbedtls/error.h" |
Mohammad Azim Khan | 67735d5 | 2017-04-06 11:55:43 +0100 | [diff] [blame] | 11 | #include "string.h" |
Paul Bakker | b63b0af | 2011-01-13 17:54:59 +0000 | [diff] [blame] | 12 | |
Simon Butcher | 9e24b51 | 2017-07-28 12:15:13 +0100 | [diff] [blame] | 13 | #if MBEDTLS_X509_MAX_INTERMEDIATE_CA > 19 |
Hanno Becker | 3b1422e | 2017-07-26 13:38:02 +0100 | [diff] [blame] | 14 | #error "The value of MBEDTLS_X509_MAX_INTERMEDIATE_C is larger \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 15 | than the current threshold 19. To test larger values, please \ |
| 16 | adapt the script tests/data_files/dir-max/long.sh." |
Hanno Becker | 3b1422e | 2017-07-26 13:38:02 +0100 | [diff] [blame] | 17 | #endif |
| 18 | |
Hanno Becker | 20a4ade | 2019-06-03 14:27:03 +0100 | [diff] [blame] | 19 | /* Test-only profile allowing all digests, PK algorithms, and curves. */ |
| 20 | const mbedtls_x509_crt_profile profile_all = |
| 21 | { |
| 22 | 0xFFFFFFFF, /* Any MD */ |
| 23 | 0xFFFFFFFF, /* Any PK alg */ |
| 24 | 0xFFFFFFFF, /* Any curve */ |
| 25 | 1024, |
| 26 | }; |
| 27 | |
Gilles Peskine | ef86ab2 | 2017-05-05 18:59:02 +0200 | [diff] [blame] | 28 | /* Profile for backward compatibility. Allows SHA-1, unlike the default |
| 29 | profile. */ |
Manuel Pégourié-Gonnard | 65eefc8 | 2015-10-23 14:08:48 +0200 | [diff] [blame] | 30 | const mbedtls_x509_crt_profile compat_profile = |
| 31 | { |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 32 | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA1) | |
| 33 | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_RIPEMD160) | |
| 34 | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA224) | |
| 35 | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA256) | |
| 36 | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA384) | |
| 37 | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA512), |
Thomas Daubney | b84f8d4 | 2022-04-21 08:35:29 +0100 | [diff] [blame] | 38 | 0xFFFFFFFF, /* Any PK alg */ |
| 39 | 0xFFFFFFFF, /* Any curve */ |
Manuel Pégourié-Gonnard | 65eefc8 | 2015-10-23 14:08:48 +0200 | [diff] [blame] | 40 | 1024, |
| 41 | }; |
| 42 | |
Manuel Pégourié-Gonnard | 6622fed | 2017-05-23 11:29:29 +0200 | [diff] [blame] | 43 | const mbedtls_x509_crt_profile profile_rsa3072 = |
| 44 | { |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 45 | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA256) | |
| 46 | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA384) | |
| 47 | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA512), |
| 48 | MBEDTLS_X509_ID_FLAG(MBEDTLS_PK_RSA), |
Manuel Pégourié-Gonnard | 6622fed | 2017-05-23 11:29:29 +0200 | [diff] [blame] | 49 | 0, |
| 50 | 3072, |
| 51 | }; |
| 52 | |
| 53 | const mbedtls_x509_crt_profile profile_sha512 = |
| 54 | { |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 55 | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA512), |
Thomas Daubney | b84f8d4 | 2022-04-21 08:35:29 +0100 | [diff] [blame] | 56 | 0xFFFFFFFF, /* Any PK alg */ |
| 57 | 0xFFFFFFFF, /* Any curve */ |
Manuel Pégourié-Gonnard | 6622fed | 2017-05-23 11:29:29 +0200 | [diff] [blame] | 58 | 1024, |
| 59 | }; |
| 60 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 61 | 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] | 62 | { |
Paul Bakker | 5a62408 | 2011-01-18 16:31:52 +0000 | [diff] [blame] | 63 | ((void) data); |
| 64 | ((void) crt); |
| 65 | ((void) certificate_depth); |
Manuel Pégourié-Gonnard | e6028c9 | 2015-04-20 12:19:02 +0100 | [diff] [blame] | 66 | *flags |= MBEDTLS_X509_BADCERT_OTHER; |
Paul Bakker | ddf26b4 | 2013-09-18 13:46:23 +0200 | [diff] [blame] | 67 | |
Paul Bakker | 915275b | 2012-09-28 07:10:55 +0000 | [diff] [blame] | 68 | return 0; |
Paul Bakker | b63b0af | 2011-01-13 17:54:59 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 71 | 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] | 72 | { |
Paul Bakker | 5a62408 | 2011-01-18 16:31:52 +0000 | [diff] [blame] | 73 | ((void) data); |
| 74 | ((void) crt); |
| 75 | ((void) certificate_depth); |
Paul Bakker | 915275b | 2012-09-28 07:10:55 +0000 | [diff] [blame] | 76 | *flags = 0; |
Paul Bakker | 5a62408 | 2011-01-18 16:31:52 +0000 | [diff] [blame] | 77 | |
Paul Bakker | b63b0af | 2011-01-13 17:54:59 +0000 | [diff] [blame] | 78 | return 0; |
| 79 | } |
| 80 | |
Jarno Lamsa | 03cd120 | 2019-03-27 15:45:04 +0200 | [diff] [blame] | 81 | #if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK) |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 82 | 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] | 83 | { |
| 84 | ((void) data); |
| 85 | ((void) child); |
| 86 | ((void) candidates); |
| 87 | |
| 88 | return -1; |
| 89 | } |
| 90 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 91 | int ca_callback(void *data, mbedtls_x509_crt const *child, |
| 92 | mbedtls_x509_crt **candidates) |
Jarno Lamsa | 03cd120 | 2019-03-27 15:45:04 +0200 | [diff] [blame] | 93 | { |
Hanno Becker | cbb5903 | 2019-03-28 14:14:22 +0000 | [diff] [blame] | 94 | int ret = 0; |
Jarno Lamsa | 03cd120 | 2019-03-27 15:45:04 +0200 | [diff] [blame] | 95 | mbedtls_x509_crt *ca = (mbedtls_x509_crt *) data; |
Hanno Becker | cbb5903 | 2019-03-28 14:14:22 +0000 | [diff] [blame] | 96 | mbedtls_x509_crt *first; |
| 97 | |
| 98 | /* This is a test-only implementation of the CA callback |
| 99 | * which always returns the entire list of trusted certificates. |
| 100 | * Production implementations managing a large number of CAs |
| 101 | * should use an efficient presentation and lookup for the |
| 102 | * set of trusted certificates (such as a hashtable) and only |
| 103 | * return those trusted certificates which satisfy basic |
| 104 | * parental checks, such as the matching of child `Issuer` |
| 105 | * and parent `Subject` field. */ |
| 106 | ((void) child); |
| 107 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 108 | first = mbedtls_calloc(1, sizeof(mbedtls_x509_crt)); |
| 109 | if (first == NULL) { |
Hanno Becker | cbb5903 | 2019-03-28 14:14:22 +0000 | [diff] [blame] | 110 | ret = -1; |
| 111 | goto exit; |
| 112 | } |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 113 | mbedtls_x509_crt_init(first); |
Hanno Becker | cbb5903 | 2019-03-28 14:14:22 +0000 | [diff] [blame] | 114 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 115 | 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] | 116 | ret = -1; |
| 117 | goto exit; |
| 118 | } |
| 119 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 120 | while (ca->next != NULL) { |
Jarno Lamsa | 03cd120 | 2019-03-27 15:45:04 +0200 | [diff] [blame] | 121 | ca = ca->next; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 122 | 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] | 123 | ret = -1; |
| 124 | goto exit; |
| 125 | } |
Jarno Lamsa | 03cd120 | 2019-03-27 15:45:04 +0200 | [diff] [blame] | 126 | } |
Hanno Becker | cbb5903 | 2019-03-28 14:14:22 +0000 | [diff] [blame] | 127 | |
| 128 | exit: |
| 129 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 130 | if (ret != 0) { |
| 131 | mbedtls_x509_crt_free(first); |
| 132 | mbedtls_free(first); |
Hanno Becker | cbb5903 | 2019-03-28 14:14:22 +0000 | [diff] [blame] | 133 | first = NULL; |
| 134 | } |
| 135 | |
Jarno Lamsa | 03cd120 | 2019-03-27 15:45:04 +0200 | [diff] [blame] | 136 | *candidates = first; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 137 | return ret; |
Jarno Lamsa | 03cd120 | 2019-03-27 15:45:04 +0200 | [diff] [blame] | 138 | } |
| 139 | #endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */ |
| 140 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 141 | 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] | 142 | { |
| 143 | int *levels = (int *) data; |
| 144 | |
| 145 | ((void) crt); |
| 146 | ((void) certificate_depth); |
| 147 | |
| 148 | /* Simulate a fatal error in the callback */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 149 | if (*levels & (1 << certificate_depth)) { |
| 150 | *flags |= (1 << certificate_depth); |
| 151 | return -1 - certificate_depth; |
Manuel Pégourié-Gonnard | 6b9d53f | 2017-05-23 12:26:58 +0200 | [diff] [blame] | 152 | } |
| 153 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 154 | return 0; |
Manuel Pégourié-Gonnard | 6b9d53f | 2017-05-23 12:26:58 +0200 | [diff] [blame] | 155 | } |
| 156 | |
Manuel Pégourié-Gonnard | a8838af | 2015-11-02 06:34:46 +0900 | [diff] [blame] | 157 | /* strsep() not available on Windows */ |
| 158 | char *mystrsep(char **stringp, const char *delim) |
| 159 | { |
| 160 | const char *p; |
| 161 | char *ret = *stringp; |
| 162 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 163 | if (*stringp == NULL) { |
| 164 | return NULL; |
| 165 | } |
Manuel Pégourié-Gonnard | a8838af | 2015-11-02 06:34:46 +0900 | [diff] [blame] | 166 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 167 | for (;; (*stringp)++) { |
| 168 | if (**stringp == '\0') { |
Manuel Pégourié-Gonnard | a8838af | 2015-11-02 06:34:46 +0900 | [diff] [blame] | 169 | *stringp = NULL; |
| 170 | goto done; |
| 171 | } |
| 172 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 173 | for (p = delim; *p != '\0'; p++) { |
| 174 | if (**stringp == *p) { |
Manuel Pégourié-Gonnard | a8838af | 2015-11-02 06:34:46 +0900 | [diff] [blame] | 175 | **stringp = '\0'; |
| 176 | (*stringp)++; |
| 177 | goto done; |
| 178 | } |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 179 | } |
Manuel Pégourié-Gonnard | a8838af | 2015-11-02 06:34:46 +0900 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | done: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 183 | return ret; |
Manuel Pégourié-Gonnard | a8838af | 2015-11-02 06:34:46 +0900 | [diff] [blame] | 184 | } |
| 185 | |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 186 | #if defined(MBEDTLS_X509_CRT_PARSE_C) |
| 187 | typedef struct { |
| 188 | char buf[512]; |
| 189 | char *p; |
| 190 | } verify_print_context; |
| 191 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 192 | void verify_print_init(verify_print_context *ctx) |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 193 | { |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 194 | memset(ctx, 0, sizeof(verify_print_context)); |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 195 | ctx->p = ctx->buf; |
| 196 | } |
| 197 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 198 | 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] | 199 | { |
| 200 | int ret; |
| 201 | verify_print_context *ctx = (verify_print_context *) data; |
| 202 | char *p = ctx->p; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 203 | size_t n = ctx->buf + sizeof(ctx->buf) - ctx->p; |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 204 | ((void) flags); |
| 205 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 206 | ret = mbedtls_snprintf(p, n, "depth %d - serial ", certificate_depth); |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 207 | MBEDTLS_X509_SAFE_SNPRINTF; |
| 208 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 209 | ret = mbedtls_x509_serial_gets(p, n, &crt->serial); |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 210 | MBEDTLS_X509_SAFE_SNPRINTF; |
| 211 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 212 | ret = mbedtls_snprintf(p, n, " - subject "); |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 213 | MBEDTLS_X509_SAFE_SNPRINTF; |
| 214 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 215 | ret = mbedtls_x509_dn_gets(p, n, &crt->subject); |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 216 | MBEDTLS_X509_SAFE_SNPRINTF; |
| 217 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 218 | ret = mbedtls_snprintf(p, n, " - flags 0x%08x\n", *flags); |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 219 | MBEDTLS_X509_SAFE_SNPRINTF; |
| 220 | |
| 221 | ctx->p = p; |
| 222 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 223 | return 0; |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 224 | } |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 225 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 226 | int verify_parse_san(mbedtls_x509_subject_alternative_name *san, |
| 227 | char **buf, size_t *size) |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 228 | { |
| 229 | int ret; |
| 230 | size_t i; |
| 231 | char *p = *buf; |
| 232 | size_t n = *size; |
| 233 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 234 | ret = mbedtls_snprintf(p, n, "type : %d", san->type); |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 235 | MBEDTLS_X509_SAFE_SNPRINTF; |
| 236 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 237 | switch (san->type) { |
| 238 | case (MBEDTLS_X509_SAN_OTHER_NAME): |
| 239 | ret = mbedtls_snprintf(p, n, "\notherName :"); |
Victor Barpp Gomes | fb4723a | 2022-09-29 10:00:32 -0300 | [diff] [blame] | 240 | MBEDTLS_X509_SAFE_SNPRINTF; |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 241 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 242 | if (MBEDTLS_OID_CMP(MBEDTLS_OID_ON_HW_MODULE_NAME, |
| 243 | &san->san.other_name.value.hardware_module_name.oid) != 0) { |
| 244 | ret = mbedtls_snprintf(p, n, " hardware module name :"); |
Victor Barpp Gomes | fb4723a | 2022-09-29 10:00:32 -0300 | [diff] [blame] | 245 | MBEDTLS_X509_SAFE_SNPRINTF; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 246 | ret = mbedtls_snprintf(p, n, " hardware type : "); |
Victor Barpp Gomes | fb4723a | 2022-09-29 10:00:32 -0300 | [diff] [blame] | 247 | MBEDTLS_X509_SAFE_SNPRINTF; |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 248 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 249 | ret = mbedtls_oid_get_numeric_string(p, |
| 250 | n, |
| 251 | &san->san.other_name.value.hardware_module_name.oid); |
Victor Barpp Gomes | fb4723a | 2022-09-29 10:00:32 -0300 | [diff] [blame] | 252 | MBEDTLS_X509_SAFE_SNPRINTF; |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 253 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 254 | ret = mbedtls_snprintf(p, n, ", hardware serial number : "); |
Victor Barpp Gomes | fb4723a | 2022-09-29 10:00:32 -0300 | [diff] [blame] | 255 | MBEDTLS_X509_SAFE_SNPRINTF; |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 256 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 257 | for (i = 0; i < san->san.other_name.value.hardware_module_name.val.len; i++) { |
| 258 | ret = mbedtls_snprintf(p, |
| 259 | n, |
| 260 | "%02X", |
| 261 | san->san.other_name.value.hardware_module_name.val.p[i]); |
Victor Barpp Gomes | fb4723a | 2022-09-29 10:00:32 -0300 | [diff] [blame] | 262 | MBEDTLS_X509_SAFE_SNPRINTF; |
| 263 | } |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 264 | } |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 265 | break;/* MBEDTLS_OID_ON_HW_MODULE_NAME */ |
| 266 | case (MBEDTLS_X509_SAN_DNS_NAME): |
| 267 | ret = mbedtls_snprintf(p, n, "\ndNSName : "); |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 268 | MBEDTLS_X509_SAFE_SNPRINTF; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 269 | if (san->san.unstructured_name.len >= n) { |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 270 | *p = '\0'; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 271 | return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL; |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 272 | } |
| 273 | n -= san->san.unstructured_name.len; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 274 | for (i = 0; i < san->san.unstructured_name.len; i++) { |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 275 | *p++ = san->san.unstructured_name.p[i]; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 276 | } |
| 277 | break;/* MBEDTLS_X509_SAN_DNS_NAME */ |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 278 | |
| 279 | default: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 280 | /* |
| 281 | * Should not happen. |
| 282 | */ |
| 283 | return -1; |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 284 | } |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 285 | ret = mbedtls_snprintf(p, n, "\n"); |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 286 | MBEDTLS_X509_SAFE_SNPRINTF; |
| 287 | |
| 288 | *size = n; |
| 289 | *buf = p; |
| 290 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 291 | return 0; |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 292 | } |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 293 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 294 | int parse_crt_ext_cb(void *p_ctx, mbedtls_x509_crt const *crt, mbedtls_x509_buf const *oid, |
| 295 | int critical, const unsigned char *cp, const unsigned char *end) |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 296 | { |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 297 | (void) crt; |
| 298 | (void) critical; |
| 299 | mbedtls_x509_buf *new_oid = (mbedtls_x509_buf *) p_ctx; |
| 300 | if (oid->tag == MBEDTLS_ASN1_OID && |
| 301 | MBEDTLS_OID_CMP(MBEDTLS_OID_CERTIFICATE_POLICIES, oid) == 0) { |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 302 | /* Handle unknown certificate policy */ |
| 303 | int ret, parse_ret = 0; |
| 304 | size_t len; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 305 | unsigned char **p = (unsigned char **) &cp; |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 306 | |
| 307 | /* Get main sequence tag */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 308 | ret = mbedtls_asn1_get_tag(p, end, &len, |
| 309 | MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE); |
| 310 | if (ret != 0) { |
| 311 | return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret); |
| 312 | } |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 313 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 314 | if (*p + len != end) { |
| 315 | return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, |
| 316 | MBEDTLS_ERR_ASN1_LENGTH_MISMATCH); |
| 317 | } |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 318 | |
| 319 | /* |
| 320 | * Cannot be an empty sequence. |
| 321 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 322 | if (len == 0) { |
| 323 | return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, |
| 324 | MBEDTLS_ERR_ASN1_LENGTH_MISMATCH); |
| 325 | } |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 326 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 327 | while (*p < end) { |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 328 | const unsigned char *policy_end; |
| 329 | |
| 330 | /* |
| 331 | * Get the policy sequence |
| 332 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 333 | if ((ret = mbedtls_asn1_get_tag(p, end, &len, |
| 334 | MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != |
| 335 | 0) { |
| 336 | return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret); |
| 337 | } |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 338 | |
| 339 | policy_end = *p + len; |
| 340 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 341 | if ((ret = mbedtls_asn1_get_tag(p, policy_end, &len, |
| 342 | MBEDTLS_ASN1_OID)) != 0) { |
| 343 | return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret); |
| 344 | } |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 345 | |
Nicola Di Lieto | b77fad8 | 2020-06-17 17:57:36 +0200 | [diff] [blame] | 346 | /* |
| 347 | * Recognize exclusively the policy with OID 1 |
| 348 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 349 | if (len != 1 || *p[0] != 1) { |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 350 | parse_ret = MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 351 | } |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 352 | |
| 353 | *p += len; |
| 354 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 355 | /* |
| 356 | * If there is an optional qualifier, then *p < policy_end |
| 357 | * Check the Qualifier len to verify it doesn't exceed policy_end. |
| 358 | */ |
| 359 | if (*p < policy_end) { |
| 360 | if ((ret = mbedtls_asn1_get_tag(p, policy_end, &len, |
| 361 | MBEDTLS_ASN1_CONSTRUCTED | |
| 362 | MBEDTLS_ASN1_SEQUENCE)) != 0) { |
| 363 | return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret); |
| 364 | } |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 365 | /* |
| 366 | * Skip the optional policy qualifiers. |
| 367 | */ |
| 368 | *p += len; |
| 369 | } |
| 370 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 371 | if (*p != policy_end) { |
| 372 | return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, |
| 373 | MBEDTLS_ERR_ASN1_LENGTH_MISMATCH); |
| 374 | } |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 375 | } |
| 376 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 377 | if (*p != end) { |
| 378 | return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, |
| 379 | MBEDTLS_ERR_ASN1_LENGTH_MISMATCH); |
| 380 | } |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 381 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 382 | return parse_ret; |
| 383 | } else if (new_oid != NULL && new_oid->tag == oid->tag && new_oid->len == oid->len && |
| 384 | memcmp(new_oid->p, oid->p, oid->len) == 0) { |
| 385 | return 0; |
| 386 | } else { |
| 387 | return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_EXTENSIONS, |
| 388 | MBEDTLS_ERR_ASN1_UNEXPECTED_TAG); |
Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 389 | } |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 390 | } |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 391 | #endif /* MBEDTLS_X509_CRT_PARSE_C */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 392 | /* END_HEADER */ |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 393 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 394 | /* BEGIN_DEPENDENCIES |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 395 | * depends_on:MBEDTLS_BIGNUM_C |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 396 | * END_DEPENDENCIES |
| 397 | */ |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 398 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 399 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 400 | void x509_parse_san(char *crt_file, char *result_str) |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 401 | { |
Ron Eldor | 890819a | 2019-05-13 19:03:04 +0300 | [diff] [blame] | 402 | int ret; |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 403 | mbedtls_x509_crt crt; |
Ron Eldor | 890819a | 2019-05-13 19:03:04 +0300 | [diff] [blame] | 404 | mbedtls_x509_subject_alternative_name san; |
| 405 | mbedtls_x509_sequence *cur = NULL; |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 406 | char buf[2000]; |
| 407 | char *p = buf; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 408 | size_t n = sizeof(buf); |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 409 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 410 | mbedtls_x509_crt_init(&crt); |
| 411 | memset(buf, 0, 2000); |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 412 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 413 | TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0); |
Ron Eldor | 890819a | 2019-05-13 19:03:04 +0300 | [diff] [blame] | 414 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 415 | if (crt.ext_types & MBEDTLS_X509_EXT_SUBJECT_ALT_NAME) { |
Ron Eldor | 890819a | 2019-05-13 19:03:04 +0300 | [diff] [blame] | 416 | cur = &crt.subject_alt_names; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 417 | while (cur != NULL) { |
| 418 | ret = mbedtls_x509_parse_subject_alt_name(&cur->buf, &san); |
| 419 | TEST_ASSERT(ret == 0 || ret == MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE); |
Ron Eldor | 890819a | 2019-05-13 19:03:04 +0300 | [diff] [blame] | 420 | /* |
| 421 | * If san type not supported, ignore. |
| 422 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 423 | if (ret == 0) { |
| 424 | TEST_ASSERT(verify_parse_san(&san, &p, &n) == 0); |
| 425 | } |
Ron Eldor | 890819a | 2019-05-13 19:03:04 +0300 | [diff] [blame] | 426 | cur = cur->next; |
| 427 | } |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 428 | } |
| 429 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 430 | TEST_ASSERT(strcmp(buf, result_str) == 0); |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 431 | |
| 432 | exit: |
| 433 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 434 | mbedtls_x509_crt_free(&crt); |
Ron Eldor | b2dc3fa | 2019-03-21 13:40:13 +0200 | [diff] [blame] | 435 | } |
| 436 | /* END_CASE */ |
| 437 | |
| 438 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 439 | void x509_cert_info(char *crt_file, char *result_str) |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 440 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 441 | mbedtls_x509_crt crt; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 442 | char buf[2000]; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 443 | int res; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 444 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 445 | mbedtls_x509_crt_init(&crt); |
| 446 | memset(buf, 0, 2000); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 447 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 448 | TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0); |
| 449 | res = mbedtls_x509_crt_info(buf, 2000, "", &crt); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 450 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 451 | TEST_ASSERT(res != -1); |
| 452 | TEST_ASSERT(res != -2); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 453 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 454 | TEST_ASSERT(strcmp(buf, result_str) == 0); |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 455 | |
| 456 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 457 | mbedtls_x509_crt_free(&crt); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 458 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 459 | /* END_CASE */ |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 460 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 461 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRL_PARSE_C */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 462 | void mbedtls_x509_crl_info(char *crl_file, char *result_str) |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 463 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 464 | mbedtls_x509_crl crl; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 465 | char buf[2000]; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 466 | int res; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 467 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 468 | mbedtls_x509_crl_init(&crl); |
| 469 | memset(buf, 0, 2000); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 470 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 471 | TEST_ASSERT(mbedtls_x509_crl_parse_file(&crl, crl_file) == 0); |
| 472 | res = mbedtls_x509_crl_info(buf, 2000, "", &crl); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 473 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 474 | TEST_ASSERT(res != -1); |
| 475 | TEST_ASSERT(res != -2); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 476 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 477 | TEST_ASSERT(strcmp(buf, result_str) == 0); |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 478 | |
| 479 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 480 | mbedtls_x509_crl_free(&crl); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 481 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 482 | /* END_CASE */ |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 483 | |
Andres AG | a39db39 | 2016-12-08 17:10:38 +0000 | [diff] [blame] | 484 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRL_PARSE_C */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 485 | void mbedtls_x509_crl_parse(char *crl_file, int result) |
Andres AG | a39db39 | 2016-12-08 17:10:38 +0000 | [diff] [blame] | 486 | { |
| 487 | mbedtls_x509_crl crl; |
| 488 | char buf[2000]; |
| 489 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 490 | mbedtls_x509_crl_init(&crl); |
| 491 | memset(buf, 0, 2000); |
Andres AG | a39db39 | 2016-12-08 17:10:38 +0000 | [diff] [blame] | 492 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 493 | TEST_ASSERT(mbedtls_x509_crl_parse_file(&crl, crl_file) == result); |
Andres AG | a39db39 | 2016-12-08 17:10:38 +0000 | [diff] [blame] | 494 | |
| 495 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 496 | mbedtls_x509_crl_free(&crl); |
Andres AG | a39db39 | 2016-12-08 17:10:38 +0000 | [diff] [blame] | 497 | } |
| 498 | /* END_CASE */ |
| 499 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 500 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CSR_PARSE_C */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 501 | 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] | 502 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 503 | mbedtls_x509_csr csr; |
Manuel Pégourié-Gonnard | 2a8d7fd | 2014-01-24 17:34:26 +0100 | [diff] [blame] | 504 | char buf[2000]; |
| 505 | int res; |
| 506 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 507 | mbedtls_x509_csr_init(&csr); |
| 508 | memset(buf, 0, 2000); |
Manuel Pégourié-Gonnard | 2a8d7fd | 2014-01-24 17:34:26 +0100 | [diff] [blame] | 509 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 510 | TEST_ASSERT(mbedtls_x509_csr_parse_file(&csr, csr_file) == 0); |
| 511 | res = mbedtls_x509_csr_info(buf, 2000, "", &csr); |
Manuel Pégourié-Gonnard | 2a8d7fd | 2014-01-24 17:34:26 +0100 | [diff] [blame] | 512 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 513 | TEST_ASSERT(res != -1); |
| 514 | TEST_ASSERT(res != -2); |
Manuel Pégourié-Gonnard | 2a8d7fd | 2014-01-24 17:34:26 +0100 | [diff] [blame] | 515 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 516 | TEST_ASSERT(strcmp(buf, result_str) == 0); |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 517 | |
| 518 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 519 | mbedtls_x509_csr_free(&csr); |
Manuel Pégourié-Gonnard | 2a8d7fd | 2014-01-24 17:34:26 +0100 | [diff] [blame] | 520 | } |
| 521 | /* END_CASE */ |
| 522 | |
Manuel Pégourié-Gonnard | b5f48ad | 2015-04-20 10:38:13 +0100 | [diff] [blame] | 523 | /* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 524 | 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] | 525 | { |
| 526 | char buf[2000]; |
| 527 | int res; |
| 528 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 529 | memset(buf, 0, sizeof(buf)); |
Manuel Pégourié-Gonnard | b5f48ad | 2015-04-20 10:38:13 +0100 | [diff] [blame] | 530 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 531 | 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] | 532 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 533 | TEST_ASSERT(res >= 0); |
Manuel Pégourié-Gonnard | b5f48ad | 2015-04-20 10:38:13 +0100 | [diff] [blame] | 534 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 535 | TEST_ASSERT(strcmp(buf, result_str) == 0); |
Manuel Pégourié-Gonnard | b5f48ad | 2015-04-20 10:38:13 +0100 | [diff] [blame] | 536 | } |
| 537 | /* END_CASE */ |
| 538 | |
Manuel Pégourié-Gonnard | d19a41d | 2017-07-14 11:05:59 +0200 | [diff] [blame] | 539 | /* 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 | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 540 | void x509_verify_restart(char *crt_file, char *ca_file, |
| 541 | int result, int flags_result, |
| 542 | int max_ops, int min_restart, int max_restart) |
Manuel Pégourié-Gonnard | d19a41d | 2017-07-14 11:05:59 +0200 | [diff] [blame] | 543 | { |
| 544 | int ret, cnt_restart; |
| 545 | mbedtls_x509_crt_restart_ctx rs_ctx; |
| 546 | mbedtls_x509_crt crt; |
| 547 | mbedtls_x509_crt ca; |
| 548 | uint32_t flags = 0; |
| 549 | |
Manuel Pégourié-Gonnard | 8b59049 | 2017-08-14 18:04:19 +0200 | [diff] [blame] | 550 | /* |
| 551 | * See comments on ecp_test_vect_restart() for op count precision. |
| 552 | * |
| 553 | * For reference, with mbed TLS 2.6 and default settings: |
| 554 | * - ecdsa_verify() for P-256: ~ 6700 |
| 555 | * - ecdsa_verify() for P-384: ~ 18800 |
| 556 | * - x509_verify() for server5 -> test-ca2: ~ 18800 |
| 557 | * - x509_verify() for server10 -> int-ca3 -> int-ca2: ~ 25500 |
| 558 | */ |
| 559 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 560 | mbedtls_x509_crt_restart_init(&rs_ctx); |
| 561 | mbedtls_x509_crt_init(&crt); |
| 562 | mbedtls_x509_crt_init(&ca); |
Manuel Pégourié-Gonnard | d19a41d | 2017-07-14 11:05:59 +0200 | [diff] [blame] | 563 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 564 | TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0); |
| 565 | TEST_ASSERT(mbedtls_x509_crt_parse_file(&ca, ca_file) == 0); |
Manuel Pégourié-Gonnard | d19a41d | 2017-07-14 11:05:59 +0200 | [diff] [blame] | 566 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 567 | mbedtls_ecp_set_max_ops(max_ops); |
Manuel Pégourié-Gonnard | d19a41d | 2017-07-14 11:05:59 +0200 | [diff] [blame] | 568 | |
| 569 | cnt_restart = 0; |
| 570 | do { |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 571 | ret = mbedtls_x509_crt_verify_restartable(&crt, &ca, NULL, |
| 572 | &mbedtls_x509_crt_profile_default, NULL, &flags, |
| 573 | NULL, NULL, &rs_ctx); |
| 574 | } while (ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart); |
Manuel Pégourié-Gonnard | d19a41d | 2017-07-14 11:05:59 +0200 | [diff] [blame] | 575 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 576 | TEST_ASSERT(ret == result); |
| 577 | TEST_ASSERT(flags == (uint32_t) flags_result); |
Manuel Pégourié-Gonnard | d19a41d | 2017-07-14 11:05:59 +0200 | [diff] [blame] | 578 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 579 | TEST_ASSERT(cnt_restart >= min_restart); |
| 580 | TEST_ASSERT(cnt_restart <= max_restart); |
Manuel Pégourié-Gonnard | d19a41d | 2017-07-14 11:05:59 +0200 | [diff] [blame] | 581 | |
| 582 | /* Do we leak memory when aborting? */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 583 | ret = mbedtls_x509_crt_verify_restartable(&crt, &ca, NULL, |
| 584 | &mbedtls_x509_crt_profile_default, NULL, &flags, |
| 585 | NULL, NULL, &rs_ctx); |
| 586 | TEST_ASSERT(ret == result || ret == MBEDTLS_ERR_ECP_IN_PROGRESS); |
Manuel Pégourié-Gonnard | d19a41d | 2017-07-14 11:05:59 +0200 | [diff] [blame] | 587 | |
| 588 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 589 | mbedtls_x509_crt_restart_free(&rs_ctx); |
| 590 | mbedtls_x509_crt_free(&crt); |
| 591 | mbedtls_x509_crt_free(&ca); |
Manuel Pégourié-Gonnard | d19a41d | 2017-07-14 11:05:59 +0200 | [diff] [blame] | 592 | } |
| 593 | /* END_CASE */ |
| 594 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 595 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_CRL_PARSE_C */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 596 | void x509_verify(char *crt_file, char *ca_file, char *crl_file, |
| 597 | char *cn_name_str, int result, int flags_result, |
| 598 | char *profile_str, |
| 599 | char *verify_callback) |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 600 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 601 | mbedtls_x509_crt crt; |
| 602 | mbedtls_x509_crt ca; |
| 603 | mbedtls_x509_crl crl; |
Manuel Pégourié-Gonnard | e6ef16f | 2015-05-11 19:54:43 +0200 | [diff] [blame] | 604 | uint32_t flags = 0; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 605 | int res; |
Manuel Pégourié-Gonnard | e6ef16f | 2015-05-11 19:54:43 +0200 | [diff] [blame] | 606 | int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *) = NULL; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 607 | char *cn_name = NULL; |
Gilles Peskine | ef86ab2 | 2017-05-05 18:59:02 +0200 | [diff] [blame] | 608 | const mbedtls_x509_crt_profile *profile; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 609 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 610 | mbedtls_x509_crt_init(&crt); |
| 611 | mbedtls_x509_crt_init(&ca); |
| 612 | mbedtls_x509_crl_init(&crl); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 613 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 614 | USE_PSA_INIT(); |
Gilles Peskine | 9de97e2 | 2021-02-02 21:00:11 +0100 | [diff] [blame] | 615 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 616 | if (strcmp(cn_name_str, "NULL") != 0) { |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 617 | cn_name = cn_name_str; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 618 | } |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 619 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 620 | if (strcmp(profile_str, "") == 0) { |
Gilles Peskine | ef86ab2 | 2017-05-05 18:59:02 +0200 | [diff] [blame] | 621 | profile = &mbedtls_x509_crt_profile_default; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 622 | } else if (strcmp(profile_str, "next") == 0) { |
Ron Eldor | c153998 | 2018-02-06 18:47:17 +0200 | [diff] [blame] | 623 | profile = &mbedtls_x509_crt_profile_next; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 624 | } else if (strcmp(profile_str, "suite_b") == 0) { |
Ron Eldor | c153998 | 2018-02-06 18:47:17 +0200 | [diff] [blame] | 625 | profile = &mbedtls_x509_crt_profile_suiteb; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 626 | } else if (strcmp(profile_str, "compat") == 0) { |
Gilles Peskine | ef86ab2 | 2017-05-05 18:59:02 +0200 | [diff] [blame] | 627 | profile = &compat_profile; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 628 | } else if (strcmp(profile_str, "all") == 0) { |
Hanno Becker | 20a4ade | 2019-06-03 14:27:03 +0100 | [diff] [blame] | 629 | profile = &profile_all; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 630 | } else { |
| 631 | TEST_ASSERT("Unknown algorithm profile" == 0); |
| 632 | } |
Gilles Peskine | ef86ab2 | 2017-05-05 18:59:02 +0200 | [diff] [blame] | 633 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 634 | if (strcmp(verify_callback, "NULL") == 0) { |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 635 | f_vrfy = NULL; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 636 | } else if (strcmp(verify_callback, "verify_none") == 0) { |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 637 | f_vrfy = verify_none; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 638 | } else if (strcmp(verify_callback, "verify_all") == 0) { |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 639 | f_vrfy = verify_all; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 640 | } else { |
| 641 | TEST_ASSERT("No known verify callback selected" == 0); |
| 642 | } |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 643 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 644 | TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0); |
| 645 | TEST_ASSERT(mbedtls_x509_crt_parse_file(&ca, ca_file) == 0); |
| 646 | TEST_ASSERT(mbedtls_x509_crl_parse_file(&crl, crl_file) == 0); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 647 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 648 | res = mbedtls_x509_crt_verify_with_profile(&crt, |
| 649 | &ca, |
| 650 | &crl, |
| 651 | profile, |
| 652 | cn_name, |
| 653 | &flags, |
| 654 | f_vrfy, |
| 655 | NULL); |
Manuel Pégourié-Gonnard | 65eefc8 | 2015-10-23 14:08:48 +0200 | [diff] [blame] | 656 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 657 | TEST_ASSERT(res == (result)); |
| 658 | TEST_ASSERT(flags == (uint32_t) (flags_result)); |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 659 | |
Jarno Lamsa | 03cd120 | 2019-03-27 15:45:04 +0200 | [diff] [blame] | 660 | #if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK) |
Hanno Becker | 0350d56 | 2019-03-28 14:23:36 +0000 | [diff] [blame] | 661 | /* CRLs aren't supported with CA callbacks, so skip the CA callback |
Jarno Lamsa | dfd22c4 | 2019-04-01 15:18:53 +0300 | [diff] [blame] | 662 | * version of the test if CRLs are in use. */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 663 | if (crl_file == NULL || strcmp(crl_file, "") == 0) { |
Hanno Becker | 0350d56 | 2019-03-28 14:23:36 +0000 | [diff] [blame] | 664 | flags = 0; |
Jarno Lamsa | 03cd120 | 2019-03-27 15:45:04 +0200 | [diff] [blame] | 665 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 666 | res = mbedtls_x509_crt_verify_with_ca_cb(&crt, |
| 667 | ca_callback, |
| 668 | &ca, |
| 669 | profile, |
| 670 | cn_name, |
| 671 | &flags, |
| 672 | f_vrfy, |
| 673 | NULL); |
Jarno Lamsa | 03cd120 | 2019-03-27 15:45:04 +0200 | [diff] [blame] | 674 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 675 | TEST_ASSERT(res == (result)); |
| 676 | TEST_ASSERT(flags == (uint32_t) (flags_result)); |
Hanno Becker | 0350d56 | 2019-03-28 14:23:36 +0000 | [diff] [blame] | 677 | } |
Jarno Lamsa | 03cd120 | 2019-03-27 15:45:04 +0200 | [diff] [blame] | 678 | #endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */ |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 679 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 680 | mbedtls_x509_crt_free(&crt); |
| 681 | mbedtls_x509_crt_free(&ca); |
| 682 | mbedtls_x509_crl_free(&crl); |
| 683 | USE_PSA_DONE(); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 684 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 685 | /* END_CASE */ |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 686 | |
Jarno Lamsa | 557426a | 2019-03-27 17:08:29 +0200 | [diff] [blame] | 687 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_CRL_PARSE_C:MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 688 | void x509_verify_ca_cb_failure(char *crt_file, char *ca_file, char *name, |
| 689 | int exp_ret) |
Jarno Lamsa | 557426a | 2019-03-27 17:08:29 +0200 | [diff] [blame] | 690 | { |
| 691 | int ret; |
| 692 | mbedtls_x509_crt crt; |
| 693 | mbedtls_x509_crt ca; |
| 694 | uint32_t flags = 0; |
Hanno Becker | 3f932bb | 2019-03-28 17:06:47 +0000 | [diff] [blame] | 695 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 696 | mbedtls_x509_crt_init(&crt); |
| 697 | mbedtls_x509_crt_init(&ca); |
Jarno Lamsa | 557426a | 2019-03-27 17:08:29 +0200 | [diff] [blame] | 698 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 699 | TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0); |
| 700 | TEST_ASSERT(mbedtls_x509_crt_parse_file(&ca, ca_file) == 0); |
Jarno Lamsa | 557426a | 2019-03-27 17:08:29 +0200 | [diff] [blame] | 701 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 702 | if (strcmp(name, "NULL") == 0) { |
Jarno Lamsa | 557426a | 2019-03-27 17:08:29 +0200 | [diff] [blame] | 703 | name = NULL; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 704 | } |
Hanno Becker | cbb5903 | 2019-03-28 14:14:22 +0000 | [diff] [blame] | 705 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 706 | ret = mbedtls_x509_crt_verify_with_ca_cb(&crt, ca_callback_fail, &ca, |
| 707 | &compat_profile, name, &flags, |
| 708 | NULL, NULL); |
Jarno Lamsa | 557426a | 2019-03-27 17:08:29 +0200 | [diff] [blame] | 709 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 710 | TEST_ASSERT(ret == exp_ret); |
| 711 | TEST_ASSERT(flags == (uint32_t) (-1)); |
Jarno Lamsa | 557426a | 2019-03-27 17:08:29 +0200 | [diff] [blame] | 712 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 713 | mbedtls_x509_crt_free(&crt); |
| 714 | mbedtls_x509_crt_free(&ca); |
Jarno Lamsa | 557426a | 2019-03-27 17:08:29 +0200 | [diff] [blame] | 715 | } |
| 716 | /* END_CASE */ |
| 717 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 718 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 719 | void x509_verify_callback(char *crt_file, char *ca_file, char *name, |
| 720 | int exp_ret, char *exp_vrfy_out) |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 721 | { |
| 722 | int ret; |
| 723 | mbedtls_x509_crt crt; |
| 724 | mbedtls_x509_crt ca; |
| 725 | uint32_t flags = 0; |
| 726 | verify_print_context vrfy_ctx; |
| 727 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 728 | mbedtls_x509_crt_init(&crt); |
| 729 | mbedtls_x509_crt_init(&ca); |
| 730 | verify_print_init(&vrfy_ctx); |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 731 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 732 | USE_PSA_INIT(); |
Gilles Peskine | 9de97e2 | 2021-02-02 21:00:11 +0100 | [diff] [blame] | 733 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 734 | TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0); |
| 735 | TEST_ASSERT(mbedtls_x509_crt_parse_file(&ca, ca_file) == 0); |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 736 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 737 | if (strcmp(name, "NULL") == 0) { |
Manuel Pégourié-Gonnard | a656825 | 2017-07-05 18:14:38 +0200 | [diff] [blame] | 738 | name = NULL; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 739 | } |
Manuel Pégourié-Gonnard | a656825 | 2017-07-05 18:14:38 +0200 | [diff] [blame] | 740 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 741 | ret = mbedtls_x509_crt_verify_with_profile(&crt, &ca, NULL, |
| 742 | &compat_profile, |
| 743 | name, &flags, |
| 744 | verify_print, &vrfy_ctx); |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 745 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 746 | TEST_ASSERT(ret == exp_ret); |
| 747 | TEST_ASSERT(strcmp(vrfy_ctx.buf, exp_vrfy_out) == 0); |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 748 | |
| 749 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 750 | mbedtls_x509_crt_free(&crt); |
| 751 | mbedtls_x509_crt_free(&ca); |
| 752 | USE_PSA_DONE(); |
Manuel Pégourié-Gonnard | 560fea3 | 2015-09-01 11:59:24 +0200 | [diff] [blame] | 753 | } |
| 754 | /* END_CASE */ |
| 755 | |
| 756 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 757 | 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] | 758 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 759 | mbedtls_x509_crt crt; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 760 | char buf[2000]; |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 761 | int res = 0; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 762 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 763 | mbedtls_x509_crt_init(&crt); |
| 764 | memset(buf, 0, 2000); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 765 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 766 | TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0); |
| 767 | if (strcmp(entity, "subject") == 0) { |
| 768 | res = mbedtls_x509_dn_gets(buf, 2000, &crt.subject); |
| 769 | } else if (strcmp(entity, "issuer") == 0) { |
| 770 | res = mbedtls_x509_dn_gets(buf, 2000, &crt.issuer); |
| 771 | } else { |
| 772 | TEST_ASSERT("Unknown entity" == 0); |
| 773 | } |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 774 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 775 | TEST_ASSERT(res != -1); |
| 776 | TEST_ASSERT(res != -2); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 777 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 778 | TEST_ASSERT(strcmp(buf, result_str) == 0); |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 779 | |
| 780 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 781 | mbedtls_x509_crt_free(&crt); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 782 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 783 | /* END_CASE */ |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 784 | |
Werner Lewis | 9a2356b | 2022-06-17 15:51:55 +0100 | [diff] [blame] | 785 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 786 | void mbedtls_x509_dn_gets_subject_replace(char *crt_file, |
| 787 | char *new_subject_ou, |
| 788 | char *result_str, |
| 789 | int ret) |
Werner Lewis | 9a2356b | 2022-06-17 15:51:55 +0100 | [diff] [blame] | 790 | { |
| 791 | mbedtls_x509_crt crt; |
| 792 | char buf[2000]; |
| 793 | int res = 0; |
| 794 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 795 | mbedtls_x509_crt_init(&crt); |
| 796 | memset(buf, 0, 2000); |
Werner Lewis | 9a2356b | 2022-06-17 15:51:55 +0100 | [diff] [blame] | 797 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 798 | TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0); |
Werner Lewis | 9a2356b | 2022-06-17 15:51:55 +0100 | [diff] [blame] | 799 | crt.subject.next->val.p = (unsigned char *) new_subject_ou; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 800 | crt.subject.next->val.len = strlen(new_subject_ou); |
Werner Lewis | 9a2356b | 2022-06-17 15:51:55 +0100 | [diff] [blame] | 801 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 802 | res = mbedtls_x509_dn_gets(buf, 2000, &crt.subject); |
Werner Lewis | 9a2356b | 2022-06-17 15:51:55 +0100 | [diff] [blame] | 803 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 804 | if (ret != 0) { |
| 805 | TEST_ASSERT(res == ret); |
| 806 | } else { |
| 807 | TEST_ASSERT(res != -1); |
| 808 | TEST_ASSERT(res != -2); |
| 809 | TEST_ASSERT(strcmp(buf, result_str) == 0); |
Werner Lewis | 9a2356b | 2022-06-17 15:51:55 +0100 | [diff] [blame] | 810 | } |
| 811 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 812 | mbedtls_x509_crt_free(&crt); |
Werner Lewis | 9a2356b | 2022-06-17 15:51:55 +0100 | [diff] [blame] | 813 | } |
| 814 | /* END_CASE */ |
| 815 | |
David Horstmann | 77ecc6e | 2022-10-05 13:08:45 +0100 | [diff] [blame] | 816 | /* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 817 | void mbedtls_x509_get_name(char *rdn_sequence, int exp_ret) |
David Horstmann | 77ecc6e | 2022-10-05 13:08:45 +0100 | [diff] [blame] | 818 | { |
| 819 | unsigned char *name; |
| 820 | unsigned char *p; |
| 821 | size_t name_len; |
David Horstmann | 6c4226c | 2022-10-20 10:18:37 +0100 | [diff] [blame] | 822 | mbedtls_x509_name head; |
David Horstmann | 77ecc6e | 2022-10-05 13:08:45 +0100 | [diff] [blame] | 823 | mbedtls_x509_name *allocated, *prev; |
David Horstmann | 4a67c35 | 2022-10-17 17:59:10 +0100 | [diff] [blame] | 824 | int ret; |
David Horstmann | 77ecc6e | 2022-10-05 13:08:45 +0100 | [diff] [blame] | 825 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 826 | memset(&head, 0, sizeof(head)); |
David Horstmann | 6c4226c | 2022-10-20 10:18:37 +0100 | [diff] [blame] | 827 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 828 | name = mbedtls_test_unhexify_alloc(rdn_sequence, &name_len); |
David Horstmann | 77ecc6e | 2022-10-05 13:08:45 +0100 | [diff] [blame] | 829 | p = name; |
| 830 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 831 | ret = mbedtls_x509_get_name(&p, (name + name_len), &head); |
| 832 | if (ret == 0) { |
David Horstmann | 77ecc6e | 2022-10-05 13:08:45 +0100 | [diff] [blame] | 833 | allocated = head.next; |
David Horstmann | 77ecc6e | 2022-10-05 13:08:45 +0100 | [diff] [blame] | 834 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 835 | while (allocated != NULL) { |
David Horstmann | 77ecc6e | 2022-10-05 13:08:45 +0100 | [diff] [blame] | 836 | prev = allocated; |
| 837 | allocated = allocated->next; |
| 838 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 839 | mbedtls_free(prev); |
David Horstmann | 77ecc6e | 2022-10-05 13:08:45 +0100 | [diff] [blame] | 840 | } |
| 841 | } |
| 842 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 843 | TEST_EQUAL(ret, exp_ret); |
David Horstmann | 77ecc6e | 2022-10-05 13:08:45 +0100 | [diff] [blame] | 844 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 845 | mbedtls_free(name); |
David Horstmann | 77ecc6e | 2022-10-05 13:08:45 +0100 | [diff] [blame] | 846 | } |
| 847 | /* END_CASE */ |
| 848 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 849 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 850 | 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] | 851 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 852 | mbedtls_x509_crt crt; |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 853 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 854 | mbedtls_x509_crt_init(&crt); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 855 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 856 | TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0); |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 857 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 858 | if (strcmp(entity, "valid_from") == 0) { |
| 859 | TEST_ASSERT(mbedtls_x509_time_is_past(&crt.valid_from) == result); |
| 860 | } else if (strcmp(entity, "valid_to") == 0) { |
| 861 | TEST_ASSERT(mbedtls_x509_time_is_past(&crt.valid_to) == result); |
| 862 | } else { |
| 863 | TEST_ASSERT("Unknown entity" == 0); |
| 864 | } |
Paul Bakker | b08e684 | 2012-02-11 18:43:20 +0000 | [diff] [blame] | 865 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 866 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 867 | mbedtls_x509_crt_free(&crt); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 868 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 869 | /* END_CASE */ |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 870 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 871 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 872 | 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] | 873 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 874 | mbedtls_x509_crt crt; |
Manuel Pégourié-Gonnard | 6304f78 | 2014-03-10 12:26:11 +0100 | [diff] [blame] | 875 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 876 | mbedtls_x509_crt_init(&crt); |
Manuel Pégourié-Gonnard | 6304f78 | 2014-03-10 12:26:11 +0100 | [diff] [blame] | 877 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 878 | TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0); |
Manuel Pégourié-Gonnard | 6304f78 | 2014-03-10 12:26:11 +0100 | [diff] [blame] | 879 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 880 | if (strcmp(entity, "valid_from") == 0) { |
| 881 | TEST_ASSERT(mbedtls_x509_time_is_future(&crt.valid_from) == result); |
| 882 | } else if (strcmp(entity, "valid_to") == 0) { |
| 883 | TEST_ASSERT(mbedtls_x509_time_is_future(&crt.valid_to) == result); |
| 884 | } else { |
| 885 | TEST_ASSERT("Unknown entity" == 0); |
| 886 | } |
Manuel Pégourié-Gonnard | 6304f78 | 2014-03-10 12:26:11 +0100 | [diff] [blame] | 887 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 888 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 889 | mbedtls_x509_crt_free(&crt); |
Manuel Pégourié-Gonnard | 6304f78 | 2014-03-10 12:26:11 +0100 | [diff] [blame] | 890 | } |
| 891 | /* END_CASE */ |
| 892 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 893 | /* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_FS_IO */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 894 | void x509parse_crt_file(char *crt_file, int result) |
Paul Bakker | 5a5fa92 | 2014-09-26 14:53:04 +0200 | [diff] [blame] | 895 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 896 | mbedtls_x509_crt crt; |
Paul Bakker | 5a5fa92 | 2014-09-26 14:53:04 +0200 | [diff] [blame] | 897 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 898 | mbedtls_x509_crt_init(&crt); |
Paul Bakker | 5a5fa92 | 2014-09-26 14:53:04 +0200 | [diff] [blame] | 899 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 900 | TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == result); |
Paul Bakker | 5a5fa92 | 2014-09-26 14:53:04 +0200 | [diff] [blame] | 901 | |
| 902 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 903 | mbedtls_x509_crt_free(&crt); |
Paul Bakker | 5a5fa92 | 2014-09-26 14:53:04 +0200 | [diff] [blame] | 904 | } |
| 905 | /* END_CASE */ |
| 906 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 907 | /* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 908 | void x509parse_crt(data_t *buf, char *result_str, int result) |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 909 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 910 | mbedtls_x509_crt crt; |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 911 | unsigned char output[2000]; |
Azim Khan | f1aaec9 | 2017-05-30 14:23:15 +0100 | [diff] [blame] | 912 | int res; |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 913 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 914 | mbedtls_x509_crt_init(&crt); |
| 915 | memset(output, 0, 2000); |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 916 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 917 | TEST_ASSERT(mbedtls_x509_crt_parse_der(&crt, buf->x, buf->len) == (result)); |
| 918 | if ((result) == 0) { |
| 919 | res = mbedtls_x509_crt_info((char *) output, 2000, "", &crt); |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 920 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 921 | TEST_ASSERT(res != -1); |
| 922 | TEST_ASSERT(res != -2); |
Hanno Becker | 2d8a2c0 | 2019-01-31 09:15:53 +0000 | [diff] [blame] | 923 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 924 | TEST_ASSERT(strcmp((char *) output, result_str) == 0); |
Hanno Becker | 2d8a2c0 | 2019-01-31 09:15:53 +0000 | [diff] [blame] | 925 | } |
| 926 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 927 | mbedtls_x509_crt_free(&crt); |
| 928 | mbedtls_x509_crt_init(&crt); |
| 929 | memset(output, 0, 2000); |
Hanno Becker | 2d8a2c0 | 2019-01-31 09:15:53 +0000 | [diff] [blame] | 930 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 931 | TEST_ASSERT(mbedtls_x509_crt_parse_der_nocopy(&crt, buf->x, buf->len) == (result)); |
| 932 | if ((result) == 0) { |
| 933 | res = mbedtls_x509_crt_info((char *) output, 2000, "", &crt); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 934 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 935 | TEST_ASSERT(res != -1); |
| 936 | TEST_ASSERT(res != -2); |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 937 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 938 | TEST_ASSERT(strcmp((char *) output, result_str) == 0); |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 939 | } |
Paul Bakker | b08e684 | 2012-02-11 18:43:20 +0000 | [diff] [blame] | 940 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 941 | mbedtls_x509_crt_free(&crt); |
| 942 | mbedtls_x509_crt_init(&crt); |
| 943 | memset(output, 0, 2000); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 944 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 945 | TEST_ASSERT(mbedtls_x509_crt_parse_der_with_ext_cb(&crt, buf->x, buf->len, 0, NULL, |
| 946 | NULL) == (result)); |
| 947 | if ((result) == 0) { |
| 948 | res = mbedtls_x509_crt_info((char *) output, 2000, "", &crt); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 949 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 950 | TEST_ASSERT(res != -1); |
| 951 | TEST_ASSERT(res != -2); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 952 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 953 | TEST_ASSERT(strcmp((char *) output, result_str) == 0); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 954 | } |
| 955 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 956 | mbedtls_x509_crt_free(&crt); |
| 957 | mbedtls_x509_crt_init(&crt); |
| 958 | memset(output, 0, 2000); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 959 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 960 | TEST_ASSERT(mbedtls_x509_crt_parse_der_with_ext_cb(&crt, buf->x, buf->len, 1, NULL, |
| 961 | NULL) == (result)); |
| 962 | if ((result) == 0) { |
| 963 | res = mbedtls_x509_crt_info((char *) output, 2000, "", &crt); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 964 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 965 | TEST_ASSERT(res != -1); |
| 966 | TEST_ASSERT(res != -2); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 967 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 968 | TEST_ASSERT(strcmp((char *) output, result_str) == 0); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 972 | mbedtls_x509_crt_free(&crt); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 973 | } |
| 974 | /* END_CASE */ |
| 975 | |
| 976 | /* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 977 | 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] | 978 | { |
| 979 | mbedtls_x509_crt crt; |
Nicola Di Lieto | e58b463 | 2020-05-29 22:58:25 +0200 | [diff] [blame] | 980 | mbedtls_x509_buf oid; |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 981 | unsigned char output[2000]; |
| 982 | int res; |
| 983 | |
Nicola Di Lieto | e58b463 | 2020-05-29 22:58:25 +0200 | [diff] [blame] | 984 | oid.tag = MBEDTLS_ASN1_OID; |
| 985 | oid.len = MBEDTLS_OID_SIZE(MBEDTLS_OID_PKIX "\x01\x1F"); |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 986 | oid.p = (unsigned char *) MBEDTLS_OID_PKIX "\x01\x1F"; |
Nicola Di Lieto | e58b463 | 2020-05-29 22:58:25 +0200 | [diff] [blame] | 987 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 988 | mbedtls_x509_crt_init(&crt); |
| 989 | memset(output, 0, 2000); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 990 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 991 | TEST_ASSERT(mbedtls_x509_crt_parse_der_with_ext_cb(&crt, buf->x, buf->len, 0, parse_crt_ext_cb, |
| 992 | &oid) == (result)); |
| 993 | if ((result) == 0) { |
| 994 | res = mbedtls_x509_crt_info((char *) output, 2000, "", &crt); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 995 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 996 | TEST_ASSERT(res != -1); |
| 997 | TEST_ASSERT(res != -2); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 998 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 999 | TEST_ASSERT(strcmp((char *) output, result_str) == 0); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1000 | } |
| 1001 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1002 | mbedtls_x509_crt_free(&crt); |
| 1003 | mbedtls_x509_crt_init(&crt); |
| 1004 | memset(output, 0, 2000); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1005 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1006 | TEST_ASSERT(mbedtls_x509_crt_parse_der_with_ext_cb(&crt, buf->x, buf->len, 1, parse_crt_ext_cb, |
| 1007 | &oid) == (result)); |
| 1008 | if ((result) == 0) { |
| 1009 | res = mbedtls_x509_crt_info((char *) output, 2000, "", &crt); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1010 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1011 | TEST_ASSERT(res != -1); |
| 1012 | TEST_ASSERT(res != -2); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1013 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1014 | TEST_ASSERT(strcmp((char *) output, result_str) == 0); |
Nicola Di Lieto | 17bb60c | 2020-05-28 23:04:15 +0200 | [diff] [blame] | 1015 | } |
| 1016 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 1017 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1018 | mbedtls_x509_crt_free(&crt); |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 1019 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 1020 | /* END_CASE */ |
Paul Bakker | b2c38f5 | 2009-07-19 19:36:15 +0000 | [diff] [blame] | 1021 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1022 | /* BEGIN_CASE depends_on:MBEDTLS_X509_CRL_PARSE_C */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1023 | void x509parse_crl(data_t *buf, char *result_str, int result) |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame] | 1024 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1025 | mbedtls_x509_crl crl; |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame] | 1026 | unsigned char output[2000]; |
Azim Khan | f1aaec9 | 2017-05-30 14:23:15 +0100 | [diff] [blame] | 1027 | int res; |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame] | 1028 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1029 | mbedtls_x509_crl_init(&crl); |
| 1030 | memset(output, 0, 2000); |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame] | 1031 | |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame] | 1032 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1033 | TEST_ASSERT(mbedtls_x509_crl_parse(&crl, buf->x, buf->len) == (result)); |
| 1034 | if ((result) == 0) { |
| 1035 | res = mbedtls_x509_crl_info((char *) output, 2000, "", &crl); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 1036 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1037 | TEST_ASSERT(res != -1); |
| 1038 | TEST_ASSERT(res != -2); |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame] | 1039 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1040 | TEST_ASSERT(strcmp((char *) output, result_str) == 0); |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame] | 1041 | } |
Paul Bakker | b08e684 | 2012-02-11 18:43:20 +0000 | [diff] [blame] | 1042 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 1043 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1044 | mbedtls_x509_crl_free(&crl); |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame] | 1045 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 1046 | /* END_CASE */ |
Paul Bakker | 6b0fa4f | 2009-07-20 20:35:41 +0000 | [diff] [blame] | 1047 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1048 | /* BEGIN_CASE depends_on:MBEDTLS_X509_CSR_PARSE_C */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1049 | 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] | 1050 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1051 | mbedtls_x509_csr csr; |
Manuel Pégourié-Gonnard | d77cd5d | 2014-06-13 11:13:15 +0200 | [diff] [blame] | 1052 | char my_out[1000]; |
Manuel Pégourié-Gonnard | d77cd5d | 2014-06-13 11:13:15 +0200 | [diff] [blame] | 1053 | int my_ret; |
| 1054 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1055 | mbedtls_x509_csr_init(&csr); |
| 1056 | memset(my_out, 0, sizeof(my_out)); |
Manuel Pégourié-Gonnard | d77cd5d | 2014-06-13 11:13:15 +0200 | [diff] [blame] | 1057 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1058 | my_ret = mbedtls_x509_csr_parse_der(&csr, csr_der->x, csr_der->len); |
| 1059 | TEST_ASSERT(my_ret == ref_ret); |
Manuel Pégourié-Gonnard | d77cd5d | 2014-06-13 11:13:15 +0200 | [diff] [blame] | 1060 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1061 | if (ref_ret == 0) { |
| 1062 | size_t my_out_len = mbedtls_x509_csr_info(my_out, sizeof(my_out), "", &csr); |
| 1063 | TEST_ASSERT(my_out_len == strlen(ref_out)); |
| 1064 | TEST_ASSERT(strcmp(my_out, ref_out) == 0); |
Manuel Pégourié-Gonnard | d77cd5d | 2014-06-13 11:13:15 +0200 | [diff] [blame] | 1065 | } |
| 1066 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 1067 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1068 | mbedtls_x509_csr_free(&csr); |
Manuel Pégourié-Gonnard | d77cd5d | 2014-06-13 11:13:15 +0200 | [diff] [blame] | 1069 | } |
| 1070 | /* END_CASE */ |
| 1071 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1072 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1073 | 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] | 1074 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1075 | mbedtls_x509_crt chain, *cur; |
Manuel Pégourié-Gonnard | fbae2a1 | 2013-11-26 16:43:39 +0100 | [diff] [blame] | 1076 | int i; |
| 1077 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1078 | mbedtls_x509_crt_init(&chain); |
Manuel Pégourié-Gonnard | fbae2a1 | 2013-11-26 16:43:39 +0100 | [diff] [blame] | 1079 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1080 | TEST_ASSERT(mbedtls_x509_crt_parse_path(&chain, crt_path) == ret); |
Manuel Pégourié-Gonnard | fbae2a1 | 2013-11-26 16:43:39 +0100 | [diff] [blame] | 1081 | |
| 1082 | /* Check how many certs we got */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1083 | for (i = 0, cur = &chain; cur != NULL; cur = cur->next) { |
| 1084 | if (cur->raw.p != NULL) { |
Manuel Pégourié-Gonnard | fbae2a1 | 2013-11-26 16:43:39 +0100 | [diff] [blame] | 1085 | i++; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1086 | } |
| 1087 | } |
Manuel Pégourié-Gonnard | fbae2a1 | 2013-11-26 16:43:39 +0100 | [diff] [blame] | 1088 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1089 | TEST_ASSERT(i == nb_crt); |
Manuel Pégourié-Gonnard | fbae2a1 | 2013-11-26 16:43:39 +0100 | [diff] [blame] | 1090 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 1091 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1092 | mbedtls_x509_crt_free(&chain); |
Manuel Pégourié-Gonnard | fbae2a1 | 2013-11-26 16:43:39 +0100 | [diff] [blame] | 1093 | } |
| 1094 | /* END_CASE */ |
| 1095 | |
Janos Follath | 822b2c3 | 2015-10-11 10:25:22 +0200 | [diff] [blame] | 1096 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1097 | void mbedtls_x509_crt_verify_max(char *ca_file, char *chain_dir, int nb_int, |
| 1098 | int ret_chk, int flags_chk) |
Manuel Pégourié-Gonnard | 1beb048 | 2017-06-05 13:49:44 +0200 | [diff] [blame] | 1099 | { |
| 1100 | char file_buf[128]; |
| 1101 | int ret; |
| 1102 | uint32_t flags; |
| 1103 | mbedtls_x509_crt trusted, chain; |
| 1104 | |
| 1105 | /* |
| 1106 | * We expect chain_dir to contain certificates 00.crt, 01.crt, etc. |
| 1107 | * with NN.crt signed by NN-1.crt |
| 1108 | */ |
| 1109 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1110 | mbedtls_x509_crt_init(&trusted); |
| 1111 | mbedtls_x509_crt_init(&chain); |
Manuel Pégourié-Gonnard | 1beb048 | 2017-06-05 13:49:44 +0200 | [diff] [blame] | 1112 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1113 | USE_PSA_INIT(); |
Gilles Peskine | 9de97e2 | 2021-02-02 21:00:11 +0100 | [diff] [blame] | 1114 | |
Manuel Pégourié-Gonnard | 1beb048 | 2017-06-05 13:49:44 +0200 | [diff] [blame] | 1115 | /* Load trusted root */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1116 | TEST_ASSERT(mbedtls_x509_crt_parse_file(&trusted, ca_file) == 0); |
Manuel Pégourié-Gonnard | 1beb048 | 2017-06-05 13:49:44 +0200 | [diff] [blame] | 1117 | |
| 1118 | /* Load a chain with nb_int intermediates (from 01 to nb_int), |
| 1119 | * plus one "end-entity" cert (nb_int + 1) */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1120 | ret = mbedtls_snprintf(file_buf, sizeof file_buf, "%s/c%02d.pem", chain_dir, |
| 1121 | nb_int + 1); |
| 1122 | TEST_ASSERT(ret > 0 && (size_t) ret < sizeof file_buf); |
| 1123 | TEST_ASSERT(mbedtls_x509_crt_parse_file(&chain, file_buf) == 0); |
Manuel Pégourié-Gonnard | 1beb048 | 2017-06-05 13:49:44 +0200 | [diff] [blame] | 1124 | |
| 1125 | /* Try to verify that chain */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1126 | ret = mbedtls_x509_crt_verify(&chain, &trusted, NULL, NULL, &flags, |
| 1127 | NULL, NULL); |
| 1128 | TEST_ASSERT(ret == ret_chk); |
| 1129 | TEST_ASSERT(flags == (uint32_t) flags_chk); |
Manuel Pégourié-Gonnard | 1beb048 | 2017-06-05 13:49:44 +0200 | [diff] [blame] | 1130 | |
| 1131 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1132 | mbedtls_x509_crt_free(&chain); |
| 1133 | mbedtls_x509_crt_free(&trusted); |
| 1134 | USE_PSA_DONE(); |
Manuel Pégourié-Gonnard | 1beb048 | 2017-06-05 13:49:44 +0200 | [diff] [blame] | 1135 | } |
| 1136 | /* END_CASE */ |
| 1137 | |
| 1138 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1139 | void mbedtls_x509_crt_verify_chain(char *chain_paths, char *trusted_ca, |
| 1140 | int flags_result, int result, |
| 1141 | char *profile_name, int vrfy_fatal_lvls) |
Janos Follath | 822b2c3 | 2015-10-11 10:25:22 +0200 | [diff] [blame] | 1142 | { |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1143 | char *act; |
Janos Follath | 822b2c3 | 2015-10-11 10:25:22 +0200 | [diff] [blame] | 1144 | uint32_t flags; |
Manuel Pégourié-Gonnard | e54931f | 2017-05-22 12:04:25 +0200 | [diff] [blame] | 1145 | int res; |
Manuel Pégourié-Gonnard | e670f90 | 2015-10-30 09:23:19 +0100 | [diff] [blame] | 1146 | mbedtls_x509_crt trusted, chain; |
Manuel Pégourié-Gonnard | e54931f | 2017-05-22 12:04:25 +0200 | [diff] [blame] | 1147 | const mbedtls_x509_crt_profile *profile = NULL; |
Janos Follath | ef4f258 | 2015-10-11 16:17:27 +0200 | [diff] [blame] | 1148 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1149 | mbedtls_x509_crt_init(&chain); |
| 1150 | mbedtls_x509_crt_init(&trusted); |
Janos Follath | 822b2c3 | 2015-10-11 10:25:22 +0200 | [diff] [blame] | 1151 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1152 | USE_PSA_INIT(); |
Gilles Peskine | 9de97e2 | 2021-02-02 21:00:11 +0100 | [diff] [blame] | 1153 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1154 | while ((act = mystrsep(&chain_paths, " ")) != NULL) { |
| 1155 | TEST_ASSERT(mbedtls_x509_crt_parse_file(&chain, act) == 0); |
| 1156 | } |
| 1157 | TEST_ASSERT(mbedtls_x509_crt_parse_file(&trusted, trusted_ca) == 0); |
Janos Follath | 822b2c3 | 2015-10-11 10:25:22 +0200 | [diff] [blame] | 1158 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1159 | if (strcmp(profile_name, "") == 0) { |
Manuel Pégourié-Gonnard | e54931f | 2017-05-22 12:04:25 +0200 | [diff] [blame] | 1160 | profile = &mbedtls_x509_crt_profile_default; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1161 | } else if (strcmp(profile_name, "next") == 0) { |
Manuel Pégourié-Gonnard | e54931f | 2017-05-22 12:04:25 +0200 | [diff] [blame] | 1162 | profile = &mbedtls_x509_crt_profile_next; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1163 | } else if (strcmp(profile_name, "suiteb") == 0) { |
Manuel Pégourié-Gonnard | e54931f | 2017-05-22 12:04:25 +0200 | [diff] [blame] | 1164 | profile = &mbedtls_x509_crt_profile_suiteb; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1165 | } else if (strcmp(profile_name, "rsa3072") == 0) { |
Manuel Pégourié-Gonnard | 6622fed | 2017-05-23 11:29:29 +0200 | [diff] [blame] | 1166 | profile = &profile_rsa3072; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1167 | } else if (strcmp(profile_name, "sha512") == 0) { |
Manuel Pégourié-Gonnard | 6622fed | 2017-05-23 11:29:29 +0200 | [diff] [blame] | 1168 | profile = &profile_sha512; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1169 | } |
Manuel Pégourié-Gonnard | e54931f | 2017-05-22 12:04:25 +0200 | [diff] [blame] | 1170 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1171 | res = mbedtls_x509_crt_verify_with_profile(&chain, &trusted, NULL, profile, |
| 1172 | NULL, &flags, verify_fatal, &vrfy_fatal_lvls); |
Janos Follath | ef4f258 | 2015-10-11 16:17:27 +0200 | [diff] [blame] | 1173 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1174 | TEST_ASSERT(res == (result)); |
| 1175 | TEST_ASSERT(flags == (uint32_t) (flags_result)); |
Janos Follath | 822b2c3 | 2015-10-11 10:25:22 +0200 | [diff] [blame] | 1176 | |
| 1177 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1178 | mbedtls_x509_crt_free(&trusted); |
| 1179 | mbedtls_x509_crt_free(&chain); |
| 1180 | USE_PSA_DONE(); |
Janos Follath | 822b2c3 | 2015-10-11 10:25:22 +0200 | [diff] [blame] | 1181 | } |
| 1182 | /* END_CASE */ |
| 1183 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1184 | /* BEGIN_CASE depends_on:MBEDTLS_X509_USE_C */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1185 | void x509_oid_desc(data_t *buf, char *ref_desc) |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 1186 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1187 | mbedtls_x509_buf oid; |
Manuel Pégourié-Gonnard | 48d3cef | 2015-03-20 18:14:26 +0000 | [diff] [blame] | 1188 | const char *desc = NULL; |
Manuel Pégourié-Gonnard | 48d3cef | 2015-03-20 18:14:26 +0000 | [diff] [blame] | 1189 | int ret; |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 1190 | |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 1191 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1192 | oid.tag = MBEDTLS_ASN1_OID; |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 1193 | oid.p = buf->x; |
| 1194 | oid.len = buf->len; |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 1195 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1196 | ret = mbedtls_oid_get_extended_key_usage(&oid, &desc); |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 1197 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1198 | if (strcmp(ref_desc, "notfound") == 0) { |
| 1199 | TEST_ASSERT(ret != 0); |
| 1200 | TEST_ASSERT(desc == NULL); |
| 1201 | } else { |
| 1202 | TEST_ASSERT(ret == 0); |
| 1203 | TEST_ASSERT(desc != NULL); |
| 1204 | TEST_ASSERT(strcmp(desc, ref_desc) == 0); |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 1205 | } |
| 1206 | } |
| 1207 | /* END_CASE */ |
| 1208 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1209 | /* BEGIN_CASE depends_on:MBEDTLS_X509_USE_C */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1210 | 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] | 1211 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1212 | mbedtls_x509_buf oid; |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 1213 | char num_buf[100]; |
| 1214 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1215 | memset(num_buf, 0x2a, sizeof num_buf); |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 1216 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1217 | oid.tag = MBEDTLS_ASN1_OID; |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 1218 | oid.p = oid_buf->x; |
| 1219 | oid.len = oid_buf->len; |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 1220 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1221 | TEST_ASSERT((size_t) blen <= sizeof num_buf); |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 1222 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1223 | TEST_ASSERT(mbedtls_oid_get_numeric_string(num_buf, blen, &oid) == ret); |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 1224 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1225 | if (ret >= 0) { |
| 1226 | TEST_ASSERT(num_buf[ret] == 0); |
| 1227 | TEST_ASSERT(strcmp(num_buf, numstr) == 0); |
Manuel Pégourié-Gonnard | 7afdb88 | 2014-03-28 16:06:35 +0100 | [diff] [blame] | 1228 | } |
| 1229 | } |
| 1230 | /* END_CASE */ |
| 1231 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1232 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_CHECK_KEY_USAGE */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1233 | 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] | 1234 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1235 | mbedtls_x509_crt crt; |
Manuel Pégourié-Gonnard | 603116c | 2014-04-09 09:50:03 +0200 | [diff] [blame] | 1236 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1237 | mbedtls_x509_crt_init(&crt); |
Manuel Pégourié-Gonnard | 603116c | 2014-04-09 09:50:03 +0200 | [diff] [blame] | 1238 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1239 | TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0); |
Manuel Pégourié-Gonnard | 603116c | 2014-04-09 09:50:03 +0200 | [diff] [blame] | 1240 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1241 | TEST_ASSERT(mbedtls_x509_crt_check_key_usage(&crt, usage) == ret); |
Manuel Pégourié-Gonnard | 603116c | 2014-04-09 09:50:03 +0200 | [diff] [blame] | 1242 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 1243 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1244 | mbedtls_x509_crt_free(&crt); |
Manuel Pégourié-Gonnard | 603116c | 2014-04-09 09:50:03 +0200 | [diff] [blame] | 1245 | } |
| 1246 | /* END_CASE */ |
| 1247 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1248 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1249 | void x509_check_extended_key_usage(char *crt_file, data_t *oid, int ret |
| 1250 | ) |
Manuel Pégourié-Gonnard | 7afb8a0 | 2014-04-10 17:53:56 +0200 | [diff] [blame] | 1251 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1252 | mbedtls_x509_crt crt; |
Manuel Pégourié-Gonnard | 7afb8a0 | 2014-04-10 17:53:56 +0200 | [diff] [blame] | 1253 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1254 | mbedtls_x509_crt_init(&crt); |
Manuel Pégourié-Gonnard | 7afb8a0 | 2014-04-10 17:53:56 +0200 | [diff] [blame] | 1255 | |
Manuel Pégourié-Gonnard | 7afb8a0 | 2014-04-10 17:53:56 +0200 | [diff] [blame] | 1256 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1257 | TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0); |
Manuel Pégourié-Gonnard | 7afb8a0 | 2014-04-10 17:53:56 +0200 | [diff] [blame] | 1258 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1259 | TEST_ASSERT(mbedtls_x509_crt_check_extended_key_usage(&crt, (const char *) oid->x, |
| 1260 | oid->len) == ret); |
Manuel Pégourié-Gonnard | 7afb8a0 | 2014-04-10 17:53:56 +0200 | [diff] [blame] | 1261 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 1262 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1263 | mbedtls_x509_crt_free(&crt); |
Manuel Pégourié-Gonnard | 7afb8a0 | 2014-04-10 17:53:56 +0200 | [diff] [blame] | 1264 | } |
| 1265 | /* END_CASE */ |
| 1266 | |
Andres AG | 4b76aec | 2016-09-23 13:16:02 +0100 | [diff] [blame] | 1267 | /* BEGIN_CASE depends_on:MBEDTLS_X509_USE_C */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1268 | void x509_get_time(int tag, char *time_str, int ret, int year, int mon, |
| 1269 | int day, int hour, int min, int sec) |
Andres AG | 4b76aec | 2016-09-23 13:16:02 +0100 | [diff] [blame] | 1270 | { |
| 1271 | mbedtls_x509_time time; |
Janos Follath | ea7054a | 2017-02-08 14:13:02 +0000 | [diff] [blame] | 1272 | unsigned char buf[21]; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1273 | unsigned char *start = buf; |
| 1274 | unsigned char *end = buf; |
Andres AG | 4b76aec | 2016-09-23 13:16:02 +0100 | [diff] [blame] | 1275 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1276 | memset(&time, 0x00, sizeof(time)); |
| 1277 | *end = (unsigned char) tag; end++; |
| 1278 | *end = strlen(time_str); |
| 1279 | TEST_ASSERT(*end < 20); |
Andres AG | 4b76aec | 2016-09-23 13:16:02 +0100 | [diff] [blame] | 1280 | end++; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1281 | memcpy(end, time_str, (size_t) *(end - 1)); |
Andres AG | 4b76aec | 2016-09-23 13:16:02 +0100 | [diff] [blame] | 1282 | end += *(end - 1); |
| 1283 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1284 | TEST_ASSERT(mbedtls_x509_get_time(&start, end, &time) == ret); |
| 1285 | if (ret == 0) { |
| 1286 | TEST_ASSERT(year == time.year); |
| 1287 | TEST_ASSERT(mon == time.mon); |
| 1288 | TEST_ASSERT(day == time.day); |
| 1289 | TEST_ASSERT(hour == time.hour); |
| 1290 | TEST_ASSERT(min == time.min); |
| 1291 | TEST_ASSERT(sec == time.sec); |
Andres AG | 4b76aec | 2016-09-23 13:16:02 +0100 | [diff] [blame] | 1292 | } |
| 1293 | } |
| 1294 | /* END_CASE */ |
| 1295 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1296 | /* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_RSASSA_PSS_SUPPORT */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1297 | void x509_parse_rsassa_pss_params(data_t *params, int params_tag, |
| 1298 | int ref_msg_md, int ref_mgf_md, |
| 1299 | int ref_salt_len, int ref_ret) |
Manuel Pégourié-Gonnard | 8540369 | 2014-06-06 14:48:38 +0200 | [diff] [blame] | 1300 | { |
| 1301 | int my_ret; |
Ronald Cron | ac6ae35 | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 1302 | mbedtls_x509_buf buf; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1303 | mbedtls_md_type_t my_msg_md, my_mgf_md; |
Manuel Pégourié-Gonnard | 8540369 | 2014-06-06 14:48:38 +0200 | [diff] [blame] | 1304 | int my_salt_len; |
| 1305 | |
Ronald Cron | ac6ae35 | 2020-06-26 14:33:03 +0200 | [diff] [blame] | 1306 | buf.p = params->x; |
| 1307 | buf.len = params->len; |
| 1308 | buf.tag = params_tag; |
Manuel Pégourié-Gonnard | 8540369 | 2014-06-06 14:48:38 +0200 | [diff] [blame] | 1309 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1310 | my_ret = mbedtls_x509_get_rsassa_pss_params(&buf, &my_msg_md, &my_mgf_md, |
| 1311 | &my_salt_len); |
Manuel Pégourié-Gonnard | 8540369 | 2014-06-06 14:48:38 +0200 | [diff] [blame] | 1312 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1313 | TEST_ASSERT(my_ret == ref_ret); |
Manuel Pégourié-Gonnard | 8540369 | 2014-06-06 14:48:38 +0200 | [diff] [blame] | 1314 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1315 | if (ref_ret == 0) { |
| 1316 | TEST_ASSERT(my_msg_md == (mbedtls_md_type_t) ref_msg_md); |
| 1317 | TEST_ASSERT(my_mgf_md == (mbedtls_md_type_t) ref_mgf_md); |
| 1318 | TEST_ASSERT(my_salt_len == ref_salt_len); |
Manuel Pégourié-Gonnard | 8540369 | 2014-06-06 14:48:38 +0200 | [diff] [blame] | 1319 | } |
| 1320 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 1321 | exit: |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 1322 | ;; |
Manuel Pégourié-Gonnard | 8540369 | 2014-06-06 14:48:38 +0200 | [diff] [blame] | 1323 | } |
| 1324 | /* END_CASE */ |
| 1325 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1326 | /* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_SELF_TEST */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1327 | void x509_selftest() |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 1328 | { |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 1329 | TEST_ASSERT(mbedtls_x509_self_test(1) == 0); |
Paul Bakker | 37940d9f | 2009-07-10 22:38:58 +0000 | [diff] [blame] | 1330 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 1331 | /* END_CASE */ |