blob: 25b0d7f8fb0d06b2ff39aaeb6e1bba1933b89c76 [file] [log] [blame]
Paul Bakker33b43f12013-08-20 11:48:36 +02001/* BEGIN_HEADER */
Azim Khand30ca132017-06-09 04:32:58 +01002#include "mbedtls/bignum.h"
Andres AG4b76aec2016-09-23 13:16:02 +01003#include "mbedtls/x509.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +00004#include "mbedtls/x509_crt.h"
5#include "mbedtls/x509_crl.h"
6#include "mbedtls/x509_csr.h"
Hanno Beckerf6bc8882019-05-02 13:05:58 +01007#include "mbedtls/x509_internal.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +00008#include "mbedtls/pem.h"
9#include "mbedtls/oid.h"
10#include "mbedtls/base64.h"
Mohammad Azim Khan67735d52017-04-06 11:55:43 +010011#include "string.h"
Paul Bakkerb63b0af2011-01-13 17:54:59 +000012
Simon Butcher9e24b512017-07-28 12:15:13 +010013#if MBEDTLS_X509_MAX_INTERMEDIATE_CA > 19
Hanno Becker3b1422e2017-07-26 13:38:02 +010014#error "The value of MBEDTLS_X509_MAX_INTERMEDIATE_C is larger \
15than the current threshold 19. To test larger values, please \
16adapt the script tests/data_files/dir-max/long.sh."
17#endif
18
Hanno Beckercfa34182019-06-03 14:27:03 +010019/* Test-only profile allowing all digests, PK algorithms, and curves. */
20const 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 Peskineef86ab22017-05-05 18:59:02 +020028/* Profile for backward compatibility. Allows SHA-1, unlike the default
29 profile. */
Manuel Pégourié-Gonnard65eefc82015-10-23 14:08:48 +020030const mbedtls_x509_crt_profile compat_profile =
31{
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 ),
38 0xFFFFFFF, /* Any PK alg */
39 0xFFFFFFF, /* Any curve */
40 1024,
41};
42
Manuel Pégourié-Gonnard6622fed2017-05-23 11:29:29 +020043const mbedtls_x509_crt_profile profile_rsa3072 =
44{
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 ),
49 0,
50 3072,
51};
52
53const mbedtls_x509_crt_profile profile_sha512 =
54{
55 MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA512 ),
56 0xFFFFFFF, /* Any PK alg */
57 0xFFFFFFF, /* Any curve */
58 1024,
59};
60
Manuel Pégourié-Gonnarde6ef16f2015-05-11 19:54:43 +020061int verify_none( void *data, mbedtls_x509_crt *crt, int certificate_depth, uint32_t *flags )
Paul Bakkerb63b0af2011-01-13 17:54:59 +000062{
Paul Bakker5a624082011-01-18 16:31:52 +000063 ((void) data);
64 ((void) crt);
65 ((void) certificate_depth);
Manuel Pégourié-Gonnarde6028c92015-04-20 12:19:02 +010066 *flags |= MBEDTLS_X509_BADCERT_OTHER;
Paul Bakkerddf26b42013-09-18 13:46:23 +020067
Paul Bakker915275b2012-09-28 07:10:55 +000068 return 0;
Paul Bakkerb63b0af2011-01-13 17:54:59 +000069}
70
Manuel Pégourié-Gonnarde6ef16f2015-05-11 19:54:43 +020071int verify_all( void *data, mbedtls_x509_crt *crt, int certificate_depth, uint32_t *flags )
Paul Bakkerb63b0af2011-01-13 17:54:59 +000072{
Paul Bakker5a624082011-01-18 16:31:52 +000073 ((void) data);
74 ((void) crt);
75 ((void) certificate_depth);
Paul Bakker915275b2012-09-28 07:10:55 +000076 *flags = 0;
Paul Bakker5a624082011-01-18 16:31:52 +000077
Paul Bakkerb63b0af2011-01-13 17:54:59 +000078 return 0;
79}
80
Manuel Pégourié-Gonnard6b9d53f2017-05-23 12:26:58 +020081int verify_fatal( void *data, mbedtls_x509_crt *crt, int certificate_depth, uint32_t *flags )
82{
83 int *levels = (int *) data;
84
85 ((void) crt);
86 ((void) certificate_depth);
87
88 /* Simulate a fatal error in the callback */
89 if( *levels & ( 1 << certificate_depth ) )
90 {
91 *flags |= ( 1 << certificate_depth );
Manuel Pégourié-Gonnard41859782017-05-23 12:58:53 +020092 return( -1 - certificate_depth );
Manuel Pégourié-Gonnard6b9d53f2017-05-23 12:26:58 +020093 }
94
95 return( 0 );
96}
97
Manuel Pégourié-Gonnarda8838af2015-11-02 06:34:46 +090098/* strsep() not available on Windows */
99char *mystrsep(char **stringp, const char *delim)
100{
101 const char *p;
102 char *ret = *stringp;
103
104 if( *stringp == NULL )
105 return( NULL );
106
107 for( ; ; (*stringp)++ )
108 {
109 if( **stringp == '\0' )
110 {
111 *stringp = NULL;
112 goto done;
113 }
114
115 for( p = delim; *p != '\0'; p++ )
116 if( **stringp == *p )
117 {
118 **stringp = '\0';
119 (*stringp)++;
120 goto done;
121 }
122 }
123
124done:
125 return( ret );
126}
127
Manuel Pégourié-Gonnard560fea32015-09-01 11:59:24 +0200128#if defined(MBEDTLS_X509_CRT_PARSE_C)
129typedef struct {
130 char buf[512];
131 char *p;
132} verify_print_context;
133
134void verify_print_init( verify_print_context *ctx )
135{
136 memset( ctx, 0, sizeof( verify_print_context ) );
137 ctx->p = ctx->buf;
138}
139
140int verify_print( void *data, mbedtls_x509_crt *crt, int certificate_depth, uint32_t *flags )
141{
142 int ret;
143 verify_print_context *ctx = (verify_print_context *) data;
144 char *p = ctx->p;
145 size_t n = ctx->buf + sizeof( ctx->buf ) - ctx->p;
Hanno Becker5f268b32019-05-20 16:26:34 +0100146 mbedtls_x509_crt_frame const *frame;
Hanno Becker3f8f0dc2019-02-27 18:06:47 +0000147 mbedtls_x509_name *subject;
Manuel Pégourié-Gonnard560fea32015-09-01 11:59:24 +0200148 ((void) flags);
149
Hanno Becker3f8f0dc2019-02-27 18:06:47 +0000150 ret = mbedtls_x509_crt_get_subject( crt, &subject );
151 if( ret != 0 )
152 return( ret );
153
Hanno Becker5c030582019-02-26 16:45:32 +0000154 ret = mbedtls_x509_crt_frame_acquire( crt, &frame );
155 if( ret != 0 )
156 return( ret );
Manuel Pégourié-Gonnard560fea32015-09-01 11:59:24 +0200157
Hanno Becker5c030582019-02-26 16:45:32 +0000158 ret = mbedtls_snprintf( p, n, "depth %d - serial ", certificate_depth );
Hanno Becker54f1c2c2019-05-13 11:58:47 +0100159 MBEDTLS_X509_SAFE_SNPRINTF_WITH_CLEANUP;
Hanno Becker5c030582019-02-26 16:45:32 +0000160
161 {
162 mbedtls_x509_buf serial;
163 serial.p = frame->serial.p;
164 serial.len = frame->serial.len;
165 ret = mbedtls_x509_serial_gets( p, n, &serial );
Hanno Becker54f1c2c2019-05-13 11:58:47 +0100166 MBEDTLS_X509_SAFE_SNPRINTF_WITH_CLEANUP;
Hanno Becker5c030582019-02-26 16:45:32 +0000167 }
Manuel Pégourié-Gonnard560fea32015-09-01 11:59:24 +0200168
169 ret = mbedtls_snprintf( p, n, " - subject " );
Hanno Becker54f1c2c2019-05-13 11:58:47 +0100170 MBEDTLS_X509_SAFE_SNPRINTF_WITH_CLEANUP;
Manuel Pégourié-Gonnard560fea32015-09-01 11:59:24 +0200171
Hanno Becker3f8f0dc2019-02-27 18:06:47 +0000172 ret = mbedtls_x509_dn_gets( p, n, subject );
Hanno Becker54f1c2c2019-05-13 11:58:47 +0100173 MBEDTLS_X509_SAFE_SNPRINTF_WITH_CLEANUP;
Manuel Pégourié-Gonnard560fea32015-09-01 11:59:24 +0200174
Manuel Pégourié-Gonnardbe2f0b52017-08-21 11:00:22 +0200175 ret = mbedtls_snprintf( p, n, " - flags 0x%08x\n", *flags );
Hanno Becker54f1c2c2019-05-13 11:58:47 +0100176 MBEDTLS_X509_SAFE_SNPRINTF_WITH_CLEANUP;
Manuel Pégourié-Gonnard560fea32015-09-01 11:59:24 +0200177
178 ctx->p = p;
179
Hanno Becker5c030582019-02-26 16:45:32 +0000180cleanup:
181
Hanno Becker3f8f0dc2019-02-27 18:06:47 +0000182 mbedtls_x509_name_free( subject );
Hanno Beckerc6d1c3e2019-03-05 13:50:56 +0000183 mbedtls_x509_crt_frame_release( crt );
Hanno Becker5c030582019-02-26 16:45:32 +0000184
185 if( ret < 0 )
186 return( ret );
187
Manuel Pégourié-Gonnard560fea32015-09-01 11:59:24 +0200188 return( 0 );
189}
190#endif /* MBEDTLS_X509_CRT_PARSE_C */
Paul Bakker33b43f12013-08-20 11:48:36 +0200191/* END_HEADER */
Paul Bakker37940d9f2009-07-10 22:38:58 +0000192
Paul Bakker33b43f12013-08-20 11:48:36 +0200193/* BEGIN_DEPENDENCIES
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200194 * depends_on:MBEDTLS_BIGNUM_C
Paul Bakker33b43f12013-08-20 11:48:36 +0200195 * END_DEPENDENCIES
196 */
Paul Bakker5690efc2011-05-26 13:16:06 +0000197
Hanno Becker02a21932019-06-10 15:08:43 +0100198/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:!MBEDTLS_X509_REMOVE_INFO:MBEDTLS_X509_CRT_PARSE_C */
Azim Khanf1aaec92017-05-30 14:23:15 +0100199void x509_cert_info( char * crt_file, char * result_str )
Paul Bakker37940d9f2009-07-10 22:38:58 +0000200{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200201 mbedtls_x509_crt crt;
Paul Bakker37940d9f2009-07-10 22:38:58 +0000202 char buf[2000];
Paul Bakker69998dd2009-07-11 19:15:20 +0000203 int res;
Paul Bakker37940d9f2009-07-10 22:38:58 +0000204
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200205 mbedtls_x509_crt_init( &crt );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000206 memset( buf, 0, 2000 );
207
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200208 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
209 res = mbedtls_x509_crt_info( buf, 2000, "", &crt );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000210
211 TEST_ASSERT( res != -1 );
212 TEST_ASSERT( res != -2 );
213
Paul Bakker33b43f12013-08-20 11:48:36 +0200214 TEST_ASSERT( strcmp( buf, result_str ) == 0 );
Paul Bakkerbd51b262014-07-10 15:26:12 +0200215
216exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200217 mbedtls_x509_crt_free( &crt );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000218}
Paul Bakker33b43f12013-08-20 11:48:36 +0200219/* END_CASE */
Paul Bakker37940d9f2009-07-10 22:38:58 +0000220
Hanno Becker02a21932019-06-10 15:08:43 +0100221/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRL_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */
Azim Khanf1aaec92017-05-30 14:23:15 +0100222void mbedtls_x509_crl_info( char * crl_file, char * result_str )
Paul Bakker37940d9f2009-07-10 22:38:58 +0000223{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200224 mbedtls_x509_crl crl;
Paul Bakker37940d9f2009-07-10 22:38:58 +0000225 char buf[2000];
Paul Bakker69998dd2009-07-11 19:15:20 +0000226 int res;
Paul Bakker37940d9f2009-07-10 22:38:58 +0000227
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200228 mbedtls_x509_crl_init( &crl );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000229 memset( buf, 0, 2000 );
230
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200231 TEST_ASSERT( mbedtls_x509_crl_parse_file( &crl, crl_file ) == 0 );
232 res = mbedtls_x509_crl_info( buf, 2000, "", &crl );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000233
234 TEST_ASSERT( res != -1 );
235 TEST_ASSERT( res != -2 );
236
Paul Bakker33b43f12013-08-20 11:48:36 +0200237 TEST_ASSERT( strcmp( buf, result_str ) == 0 );
Paul Bakkerbd51b262014-07-10 15:26:12 +0200238
239exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200240 mbedtls_x509_crl_free( &crl );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000241}
Paul Bakker33b43f12013-08-20 11:48:36 +0200242/* END_CASE */
Paul Bakker37940d9f2009-07-10 22:38:58 +0000243
Andres AGa39db392016-12-08 17:10:38 +0000244/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRL_PARSE_C */
Azim Khanf1aaec92017-05-30 14:23:15 +0100245void mbedtls_x509_crl_parse( char * crl_file, int result )
Andres AGa39db392016-12-08 17:10:38 +0000246{
247 mbedtls_x509_crl crl;
248 char buf[2000];
249
250 mbedtls_x509_crl_init( &crl );
251 memset( buf, 0, 2000 );
252
253 TEST_ASSERT( mbedtls_x509_crl_parse_file( &crl, crl_file ) == result );
254
255exit:
256 mbedtls_x509_crl_free( &crl );
257}
258/* END_CASE */
259
Hanno Becker02a21932019-06-10 15:08:43 +0100260/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CSR_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */
Azim Khanf1aaec92017-05-30 14:23:15 +0100261void mbedtls_x509_csr_info( char * csr_file, char * result_str )
Manuel Pégourié-Gonnard2a8d7fd2014-01-24 17:34:26 +0100262{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200263 mbedtls_x509_csr csr;
Manuel Pégourié-Gonnard2a8d7fd2014-01-24 17:34:26 +0100264 char buf[2000];
265 int res;
266
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200267 mbedtls_x509_csr_init( &csr );
Manuel Pégourié-Gonnard2a8d7fd2014-01-24 17:34:26 +0100268 memset( buf, 0, 2000 );
269
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200270 TEST_ASSERT( mbedtls_x509_csr_parse_file( &csr, csr_file ) == 0 );
271 res = mbedtls_x509_csr_info( buf, 2000, "", &csr );
Manuel Pégourié-Gonnard2a8d7fd2014-01-24 17:34:26 +0100272
Manuel Pégourié-Gonnard2a8d7fd2014-01-24 17:34:26 +0100273 TEST_ASSERT( res != -1 );
274 TEST_ASSERT( res != -2 );
275
276 TEST_ASSERT( strcmp( buf, result_str ) == 0 );
Paul Bakkerbd51b262014-07-10 15:26:12 +0200277
278exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200279 mbedtls_x509_csr_free( &csr );
Manuel Pégourié-Gonnard2a8d7fd2014-01-24 17:34:26 +0100280}
281/* END_CASE */
282
Hanno Becker02a21932019-06-10 15:08:43 +0100283/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */
Azim Khanf1aaec92017-05-30 14:23:15 +0100284void x509_verify_info( int flags, char * prefix, char * result_str )
Manuel Pégourié-Gonnardb5f48ad2015-04-20 10:38:13 +0100285{
286 char buf[2000];
287 int res;
288
289 memset( buf, 0, sizeof( buf ) );
290
291 res = mbedtls_x509_crt_verify_info( buf, sizeof( buf ), prefix, flags );
292
293 TEST_ASSERT( res >= 0 );
294
295 TEST_ASSERT( strcmp( buf, result_str ) == 0 );
296}
297/* END_CASE */
298
Manuel Pégourié-Gonnardd19a41d2017-07-14 11:05:59 +0200299/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_CRL_PARSE_C:MBEDTLS_ECP_RESTARTABLE:MBEDTLS_ECDSA_C */
300void x509_verify_restart( char *crt_file, char *ca_file,
301 int result, int flags_result,
302 int max_ops, int min_restart, int max_restart )
303{
304 int ret, cnt_restart;
305 mbedtls_x509_crt_restart_ctx rs_ctx;
306 mbedtls_x509_crt crt;
307 mbedtls_x509_crt ca;
308 uint32_t flags = 0;
309
Manuel Pégourié-Gonnard8b590492017-08-14 18:04:19 +0200310 /*
311 * See comments on ecp_test_vect_restart() for op count precision.
312 *
313 * For reference, with mbed TLS 2.6 and default settings:
314 * - ecdsa_verify() for P-256: ~ 6700
315 * - ecdsa_verify() for P-384: ~ 18800
316 * - x509_verify() for server5 -> test-ca2: ~ 18800
317 * - x509_verify() for server10 -> int-ca3 -> int-ca2: ~ 25500
318 */
319
Manuel Pégourié-Gonnardd19a41d2017-07-14 11:05:59 +0200320 mbedtls_x509_crt_restart_init( &rs_ctx );
321 mbedtls_x509_crt_init( &crt );
322 mbedtls_x509_crt_init( &ca );
323
324 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
325 TEST_ASSERT( mbedtls_x509_crt_parse_file( &ca, ca_file ) == 0 );
326
327 mbedtls_ecp_set_max_ops( max_ops );
328
329 cnt_restart = 0;
330 do {
331 ret = mbedtls_x509_crt_verify_restartable( &crt, &ca, NULL,
332 &mbedtls_x509_crt_profile_default, NULL, &flags,
333 NULL, NULL, &rs_ctx );
334 } while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart );
335
336 TEST_ASSERT( ret == result );
337 TEST_ASSERT( flags == (uint32_t) flags_result );
338
339 TEST_ASSERT( cnt_restart >= min_restart );
340 TEST_ASSERT( cnt_restart <= max_restart );
341
342 /* Do we leak memory when aborting? */
343 ret = mbedtls_x509_crt_verify_restartable( &crt, &ca, NULL,
344 &mbedtls_x509_crt_profile_default, NULL, &flags,
345 NULL, NULL, &rs_ctx );
346 TEST_ASSERT( ret == result || ret == MBEDTLS_ERR_ECP_IN_PROGRESS );
347
348exit:
349 mbedtls_x509_crt_restart_free( &rs_ctx );
350 mbedtls_x509_crt_free( &crt );
351 mbedtls_x509_crt_free( &ca );
352}
353/* END_CASE */
354
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200355/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_CRL_PARSE_C */
Paul Bakker33b43f12013-08-20 11:48:36 +0200356void x509_verify( char *crt_file, char *ca_file, char *crl_file,
357 char *cn_name_str, int result, int flags_result,
Gilles Peskineef86ab22017-05-05 18:59:02 +0200358 char *profile_str,
Paul Bakker33b43f12013-08-20 11:48:36 +0200359 char *verify_callback )
Paul Bakker37940d9f2009-07-10 22:38:58 +0000360{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200361 mbedtls_x509_crt crt;
362 mbedtls_x509_crt ca;
363 mbedtls_x509_crl crl;
Manuel Pégourié-Gonnarde6ef16f2015-05-11 19:54:43 +0200364 uint32_t flags = 0;
Paul Bakker69998dd2009-07-11 19:15:20 +0000365 int res;
Manuel Pégourié-Gonnarde6ef16f2015-05-11 19:54:43 +0200366 int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *) = NULL;
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200367 char * cn_name = NULL;
Gilles Peskineef86ab22017-05-05 18:59:02 +0200368 const mbedtls_x509_crt_profile *profile;
Paul Bakker37940d9f2009-07-10 22:38:58 +0000369
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200370 mbedtls_x509_crt_init( &crt );
371 mbedtls_x509_crt_init( &ca );
372 mbedtls_x509_crl_init( &crl );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000373
Paul Bakker33b43f12013-08-20 11:48:36 +0200374 if( strcmp( cn_name_str, "NULL" ) != 0 )
375 cn_name = cn_name_str;
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200376
Manuel Pégourié-Gonnarda54f6cc2017-08-09 10:41:42 +0200377 if( strcmp( profile_str, "" ) == 0 )
Gilles Peskineef86ab22017-05-05 18:59:02 +0200378 profile = &mbedtls_x509_crt_profile_default;
Ron Eldorc1539982018-02-06 18:47:17 +0200379 else if( strcmp( profile_str, "next" ) == 0 )
380 profile = &mbedtls_x509_crt_profile_next;
381 else if( strcmp( profile_str, "suite_b" ) == 0 )
382 profile = &mbedtls_x509_crt_profile_suiteb;
Gilles Peskineef86ab22017-05-05 18:59:02 +0200383 else if( strcmp( profile_str, "compat" ) == 0 )
384 profile = &compat_profile;
Hanno Beckercfa34182019-06-03 14:27:03 +0100385 else if( strcmp( profile_str, "all" ) == 0 )
386 profile = &profile_all;
Gilles Peskineef86ab22017-05-05 18:59:02 +0200387 else
388 TEST_ASSERT( "Unknown algorithm profile" == 0 );
389
Paul Bakker33b43f12013-08-20 11:48:36 +0200390 if( strcmp( verify_callback, "NULL" ) == 0 )
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200391 f_vrfy = NULL;
Paul Bakker33b43f12013-08-20 11:48:36 +0200392 else if( strcmp( verify_callback, "verify_none" ) == 0 )
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200393 f_vrfy = verify_none;
Paul Bakker33b43f12013-08-20 11:48:36 +0200394 else if( strcmp( verify_callback, "verify_all" ) == 0 )
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200395 f_vrfy = verify_all;
396 else
397 TEST_ASSERT( "No known verify callback selected" == 0 );
398
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200399 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
400 TEST_ASSERT( mbedtls_x509_crt_parse_file( &ca, ca_file ) == 0 );
401 TEST_ASSERT( mbedtls_x509_crl_parse_file( &crl, crl_file ) == 0 );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000402
Gilles Peskineef86ab22017-05-05 18:59:02 +0200403 res = mbedtls_x509_crt_verify_with_profile( &crt, &ca, &crl, profile, cn_name, &flags, f_vrfy, NULL );
Manuel Pégourié-Gonnard65eefc82015-10-23 14:08:48 +0200404
Paul Bakkerbd51b262014-07-10 15:26:12 +0200405 TEST_ASSERT( res == ( result ) );
Manuel Pégourié-Gonnarde6ef16f2015-05-11 19:54:43 +0200406 TEST_ASSERT( flags == (uint32_t)( flags_result ) );
Paul Bakkerbd51b262014-07-10 15:26:12 +0200407
408exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200409 mbedtls_x509_crt_free( &crt );
410 mbedtls_x509_crt_free( &ca );
411 mbedtls_x509_crl_free( &crl );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000412}
Paul Bakker33b43f12013-08-20 11:48:36 +0200413/* END_CASE */
Paul Bakker37940d9f2009-07-10 22:38:58 +0000414
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200415/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
Manuel Pégourié-Gonnarda6568252017-07-05 18:14:38 +0200416void x509_verify_callback( char *crt_file, char *ca_file, char *name,
Manuel Pégourié-Gonnard560fea32015-09-01 11:59:24 +0200417 int exp_ret, char *exp_vrfy_out )
418{
419 int ret;
420 mbedtls_x509_crt crt;
421 mbedtls_x509_crt ca;
422 uint32_t flags = 0;
423 verify_print_context vrfy_ctx;
424
425 mbedtls_x509_crt_init( &crt );
426 mbedtls_x509_crt_init( &ca );
427 verify_print_init( &vrfy_ctx );
428
429 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
430 TEST_ASSERT( mbedtls_x509_crt_parse_file( &ca, ca_file ) == 0 );
431
Manuel Pégourié-Gonnarda6568252017-07-05 18:14:38 +0200432 if( strcmp( name, "NULL" ) == 0 )
433 name = NULL;
434
Gilles Peskineef86ab22017-05-05 18:59:02 +0200435 ret = mbedtls_x509_crt_verify_with_profile( &crt, &ca, NULL,
436 &compat_profile,
Manuel Pégourié-Gonnarda6568252017-07-05 18:14:38 +0200437 name, &flags,
Gilles Peskineef86ab22017-05-05 18:59:02 +0200438 verify_print, &vrfy_ctx );
Manuel Pégourié-Gonnard560fea32015-09-01 11:59:24 +0200439
440 TEST_ASSERT( ret == exp_ret );
441 TEST_ASSERT( strcmp( vrfy_ctx.buf, exp_vrfy_out ) == 0 );
442
443exit:
444 mbedtls_x509_crt_free( &crt );
445 mbedtls_x509_crt_free( &ca );
446}
447/* END_CASE */
448
Hanno Becker02a21932019-06-10 15:08:43 +0100449/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */
Azim Khanf1aaec92017-05-30 14:23:15 +0100450void mbedtls_x509_dn_gets( char * crt_file, char * entity, char * result_str )
Paul Bakker37940d9f2009-07-10 22:38:58 +0000451{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200452 mbedtls_x509_crt crt;
Paul Bakker37940d9f2009-07-10 22:38:58 +0000453 char buf[2000];
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200454 int res = 0;
Hanno Beckerc69c4462019-02-27 09:05:41 +0000455 mbedtls_x509_name *subject = NULL, *issuer = NULL;
Paul Bakker37940d9f2009-07-10 22:38:58 +0000456
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200457 mbedtls_x509_crt_init( &crt );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000458 memset( buf, 0, 2000 );
459
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200460 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
Hanno Beckerc69c4462019-02-27 09:05:41 +0000461 TEST_ASSERT( mbedtls_x509_crt_get_subject( &crt, &subject ) == 0 );
462 TEST_ASSERT( mbedtls_x509_crt_get_issuer( &crt, &issuer ) == 0 );
463
Paul Bakker33b43f12013-08-20 11:48:36 +0200464 if( strcmp( entity, "subject" ) == 0 )
Hanno Beckerc69c4462019-02-27 09:05:41 +0000465 res = mbedtls_x509_dn_gets( buf, 2000, subject );
Paul Bakker33b43f12013-08-20 11:48:36 +0200466 else if( strcmp( entity, "issuer" ) == 0 )
Hanno Beckerc69c4462019-02-27 09:05:41 +0000467 res = mbedtls_x509_dn_gets( buf, 2000, issuer );
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200468 else
469 TEST_ASSERT( "Unknown entity" == 0 );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000470
471 TEST_ASSERT( res != -1 );
472 TEST_ASSERT( res != -2 );
473
Paul Bakker33b43f12013-08-20 11:48:36 +0200474 TEST_ASSERT( strcmp( buf, result_str ) == 0 );
Paul Bakkerbd51b262014-07-10 15:26:12 +0200475
476exit:
Hanno Beckerc69c4462019-02-27 09:05:41 +0000477 mbedtls_x509_name_free( issuer );
478 mbedtls_x509_name_free( subject );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200479 mbedtls_x509_crt_free( &crt );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000480}
Paul Bakker33b43f12013-08-20 11:48:36 +0200481/* END_CASE */
Paul Bakker37940d9f2009-07-10 22:38:58 +0000482
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200483/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
Azim Khanf1aaec92017-05-30 14:23:15 +0100484void mbedtls_x509_time_is_past( char * crt_file, char * entity, int result )
Paul Bakker37940d9f2009-07-10 22:38:58 +0000485{
Hanno Beckerc69c4462019-02-27 09:05:41 +0000486 mbedtls_x509_crt crt;
487 mbedtls_x509_crt_frame frame;
Paul Bakker37940d9f2009-07-10 22:38:58 +0000488
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200489 mbedtls_x509_crt_init( &crt );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000490
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200491 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
Hanno Beckerc69c4462019-02-27 09:05:41 +0000492 TEST_ASSERT( mbedtls_x509_crt_get_frame( &crt, &frame ) == 0 );
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200493
Paul Bakker33b43f12013-08-20 11:48:36 +0200494 if( strcmp( entity, "valid_from" ) == 0 )
Hanno Beckerc69c4462019-02-27 09:05:41 +0000495 TEST_ASSERT( mbedtls_x509_time_is_past( &frame.valid_from ) == result );
Paul Bakker33b43f12013-08-20 11:48:36 +0200496 else if( strcmp( entity, "valid_to" ) == 0 )
Hanno Beckerc69c4462019-02-27 09:05:41 +0000497 TEST_ASSERT( mbedtls_x509_time_is_past( &frame.valid_to ) == result );
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200498 else
499 TEST_ASSERT( "Unknown entity" == 0 );
Paul Bakkerb08e6842012-02-11 18:43:20 +0000500
Paul Bakkerbd51b262014-07-10 15:26:12 +0200501exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200502 mbedtls_x509_crt_free( &crt );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000503}
Paul Bakker33b43f12013-08-20 11:48:36 +0200504/* END_CASE */
Paul Bakker37940d9f2009-07-10 22:38:58 +0000505
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200506/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
Azim Khanf1aaec92017-05-30 14:23:15 +0100507void mbedtls_x509_time_is_future( char * crt_file, char * entity, int result )
Manuel Pégourié-Gonnard6304f782014-03-10 12:26:11 +0100508{
Hanno Beckerc69c4462019-02-27 09:05:41 +0000509 mbedtls_x509_crt crt;
510 mbedtls_x509_crt_frame frame;
Manuel Pégourié-Gonnard6304f782014-03-10 12:26:11 +0100511
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200512 mbedtls_x509_crt_init( &crt );
Manuel Pégourié-Gonnard6304f782014-03-10 12:26:11 +0100513
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200514 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
Hanno Beckerc69c4462019-02-27 09:05:41 +0000515 TEST_ASSERT( mbedtls_x509_crt_get_frame( &crt, &frame ) == 0 );
Manuel Pégourié-Gonnard6304f782014-03-10 12:26:11 +0100516
517 if( strcmp( entity, "valid_from" ) == 0 )
Hanno Beckerc69c4462019-02-27 09:05:41 +0000518 TEST_ASSERT( mbedtls_x509_time_is_future( &frame.valid_from ) == result );
Manuel Pégourié-Gonnard6304f782014-03-10 12:26:11 +0100519 else if( strcmp( entity, "valid_to" ) == 0 )
Hanno Beckerc69c4462019-02-27 09:05:41 +0000520 TEST_ASSERT( mbedtls_x509_time_is_future( &frame.valid_to ) == result );
Manuel Pégourié-Gonnard6304f782014-03-10 12:26:11 +0100521 else
522 TEST_ASSERT( "Unknown entity" == 0 );
523
Paul Bakkerbd51b262014-07-10 15:26:12 +0200524exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200525 mbedtls_x509_crt_free( &crt );
Manuel Pégourié-Gonnard6304f782014-03-10 12:26:11 +0100526}
527/* END_CASE */
528
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200529/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_FS_IO */
Azim Khanf1aaec92017-05-30 14:23:15 +0100530void x509parse_crt_file( char * crt_file, int result )
Paul Bakker5a5fa922014-09-26 14:53:04 +0200531{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200532 mbedtls_x509_crt crt;
Paul Bakker5a5fa922014-09-26 14:53:04 +0200533
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200534 mbedtls_x509_crt_init( &crt );
Paul Bakker5a5fa922014-09-26 14:53:04 +0200535
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200536 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == result );
Paul Bakker5a5fa922014-09-26 14:53:04 +0200537
538exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200539 mbedtls_x509_crt_free( &crt );
Paul Bakker5a5fa922014-09-26 14:53:04 +0200540}
541/* END_CASE */
542
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200543/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */
Azim Khan5fcca462018-06-29 11:05:32 +0100544void x509parse_crt( data_t * buf, char * result_str, int result )
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000545{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200546 mbedtls_x509_crt crt;
Hanno Becker02a21932019-06-10 15:08:43 +0100547#if !defined(MBEDTLS_X509_REMOVE_INFO)
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000548 unsigned char output[2000];
Azim Khanf1aaec92017-05-30 14:23:15 +0100549 int res;
Peter Kolbusdc470ae2018-12-11 13:55:56 -0600550#endif
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000551
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200552 mbedtls_x509_crt_init( &crt );
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000553
Hanno Becker2fa5e732019-01-31 09:15:53 +0000554 TEST_ASSERT( mbedtls_x509_crt_parse_der( &crt, buf->x, buf->len ) == ( result ) );
Peter Kolbusdc470ae2018-12-11 13:55:56 -0600555#if defined(MBEDTLS_X509_INFO)
Hanno Becker2fa5e732019-01-31 09:15:53 +0000556 if( ( result ) == 0 )
557 {
Peter Kolbusdc470ae2018-12-11 13:55:56 -0600558 memset( output, 0, 2000 );
Hanno Becker2fa5e732019-01-31 09:15:53 +0000559 res = mbedtls_x509_crt_info( (char *) output, 2000, "", &crt );
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000560
Hanno Becker2fa5e732019-01-31 09:15:53 +0000561 TEST_ASSERT( res != -1 );
562 TEST_ASSERT( res != -2 );
563
564 TEST_ASSERT( strcmp( (char *) output, result_str ) == 0 );
565 }
Hanno Becker98f85c82019-06-11 17:16:13 +0100566#else
567 ((void) result_str);
Peter Kolbusdc470ae2018-12-11 13:55:56 -0600568#endif
Hanno Becker2fa5e732019-01-31 09:15:53 +0000569
570 mbedtls_x509_crt_free( &crt );
571 mbedtls_x509_crt_init( &crt );
Hanno Becker2fa5e732019-01-31 09:15:53 +0000572
573 TEST_ASSERT( mbedtls_x509_crt_parse_der_nocopy( &crt, buf->x, buf->len ) == ( result ) );
Peter Kolbusdc470ae2018-12-11 13:55:56 -0600574
575 TEST_ASSERT( mbedtls_x509_crt_parse( &crt, buf->x, buf->len ) == ( result ) );
Hanno Becker02a21932019-06-10 15:08:43 +0100576#if !defined(MBEDTLS_X509_REMOVE_INFO)
Paul Bakker33b43f12013-08-20 11:48:36 +0200577 if( ( result ) == 0 )
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000578 {
Peter Kolbusdc470ae2018-12-11 13:55:56 -0600579 memset( output, 0, 2000 );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200580 res = mbedtls_x509_crt_info( (char *) output, 2000, "", &crt );
Paul Bakker33b43f12013-08-20 11:48:36 +0200581
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000582 TEST_ASSERT( res != -1 );
583 TEST_ASSERT( res != -2 );
584
Paul Bakker33b43f12013-08-20 11:48:36 +0200585 TEST_ASSERT( strcmp( (char *) output, result_str ) == 0 );
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000586 }
Peter Kolbusdc470ae2018-12-11 13:55:56 -0600587#endif
588
589 mbedtls_x509_crt_free( &crt );
590 mbedtls_x509_crt_init( &crt );
Hanno Becker02a21932019-06-10 15:08:43 +0100591#if !defined(MBEDTLS_X509_REMOVE_INFO)
Peter Kolbusdc470ae2018-12-11 13:55:56 -0600592 memset( output, 0, 2000 );
593#endif
Paul Bakkerb08e6842012-02-11 18:43:20 +0000594
Paul Bakkerbd51b262014-07-10 15:26:12 +0200595exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200596 mbedtls_x509_crt_free( &crt );
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000597}
Paul Bakker33b43f12013-08-20 11:48:36 +0200598/* END_CASE */
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000599
Hanno Becker7ab8a2e2019-06-28 15:52:54 +0100600/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */
601void x509_nested_acquire( data_t * buf )
602{
603 /* This tests exercises the behavior of the library when
604 * facing nested calls to mbedtls_x509_crt_xxx_acquire().
605 * This is allowed if !MBEDTLS_X509_ALWAYS_FLUSH or
606 * MBEDTLS_THREADING_C, but forbidden otherwise. */
607
608 mbedtls_x509_crt crt;
609 mbedtls_x509_crt_init( &crt );
610 TEST_ASSERT( mbedtls_x509_crt_parse_der( &crt, buf->x, buf->len ) == 0 );
611
612 /* Nested aquire for CRT frames */
613 {
614 int ret;
615 mbedtls_x509_crt_frame const *frame1;
616 mbedtls_x509_crt_frame const *frame2;
617
618 /* Perform a (hopefully) innocent acquire-release pair first. */
619
620 TEST_ASSERT( mbedtls_x509_crt_frame_acquire( &crt, &frame1 ) == 0 );
621 TEST_ASSERT( mbedtls_x509_crt_frame_release( &crt ) == 0 );
622
623 /* Perform two nested acquire calls. */
624
625 TEST_ASSERT( mbedtls_x509_crt_frame_acquire( &crt, &frame1 ) == 0 );
626
627 ret = mbedtls_x509_crt_frame_acquire( &crt, &frame2 );
628#if defined(MBEDTLS_X509_ALWAYS_FLUSH) && \
629 !defined(MBEDTLS_THREADING_C)
630 TEST_ASSERT( ret == MBEDTLS_ERR_X509_FATAL_ERROR );
631#else
632 TEST_ASSERT( ret == 0 );
633 TEST_ASSERT( mbedtls_x509_crt_frame_release( &crt ) == 0 );
634#endif
635
636 TEST_ASSERT( mbedtls_x509_crt_frame_release( &crt ) == 0 );
637
638 ret = mbedtls_x509_crt_frame_release( &crt );
639
640 /* In contexts which use resource counting, we expect an
641 * error on an attempted release() without prior acquire(). */
642#if defined(MBEDTLS_X509_ALWAYS_FLUSH) && \
643 !defined(MBEDTLS_THREADING_C)
644 TEST_ASSERT( ret == 0 );
645#else
646 TEST_ASSERT( ret == MBEDTLS_ERR_X509_FATAL_ERROR );
647#endif
648 }
649
650 /* Nested aquire for PK contexts */
651 {
652 int ret;
653 mbedtls_pk_context *pk1;
654 mbedtls_pk_context *pk2;
655
656 /* Perform a (hopefully) innocent acquire-release pair first. */
657
658 TEST_ASSERT( mbedtls_x509_crt_pk_acquire( &crt, &pk1 ) == 0 );
659 TEST_ASSERT( mbedtls_x509_crt_pk_release( &crt ) == 0 );
660
661 /* Perform two nested acquire calls. */
662
663 TEST_ASSERT( mbedtls_x509_crt_pk_acquire( &crt, &pk1 ) == 0 );
664
665 ret = mbedtls_x509_crt_pk_acquire( &crt, &pk2 );
666#if defined(MBEDTLS_X509_ALWAYS_FLUSH) && \
667 !defined(MBEDTLS_THREADING_C)
668 TEST_ASSERT( ret == MBEDTLS_ERR_X509_FATAL_ERROR );
669#else
670 TEST_ASSERT( ret == 0 );
671 TEST_ASSERT( mbedtls_x509_crt_pk_release( &crt ) == 0 );
672#endif
673
674 TEST_ASSERT( mbedtls_x509_crt_pk_release( &crt ) == 0 );
675
676 ret = mbedtls_x509_crt_pk_release( &crt );
677
678 /* In contexts which use resource counting, we expect an
679 * error on an attempted release() without prior acquire(). */
680#if defined(MBEDTLS_X509_ALWAYS_FLUSH) && \
681 !defined(MBEDTLS_THREADING_C)
682 TEST_ASSERT( ret == 0 );
683#else
684 TEST_ASSERT( ret == MBEDTLS_ERR_X509_FATAL_ERROR );
685#endif
686 }
687
688exit:
689 mbedtls_x509_crt_free( &crt );
690}
691/* END_CASE */
692
Hanno Becker02a21932019-06-10 15:08:43 +0100693/* BEGIN_CASE depends_on:MBEDTLS_X509_CRL_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */
Azim Khan5fcca462018-06-29 11:05:32 +0100694void x509parse_crl( data_t * buf, char * result_str, int result )
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000695{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200696 mbedtls_x509_crl crl;
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000697 unsigned char output[2000];
Azim Khanf1aaec92017-05-30 14:23:15 +0100698 int res;
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000699
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200700 mbedtls_x509_crl_init( &crl );
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000701 memset( output, 0, 2000 );
702
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000703
Azim Khand30ca132017-06-09 04:32:58 +0100704 TEST_ASSERT( mbedtls_x509_crl_parse( &crl, buf->x, buf->len ) == ( result ) );
Paul Bakker33b43f12013-08-20 11:48:36 +0200705 if( ( result ) == 0 )
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000706 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200707 res = mbedtls_x509_crl_info( (char *) output, 2000, "", &crl );
Paul Bakker33b43f12013-08-20 11:48:36 +0200708
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000709 TEST_ASSERT( res != -1 );
710 TEST_ASSERT( res != -2 );
711
Paul Bakker33b43f12013-08-20 11:48:36 +0200712 TEST_ASSERT( strcmp( (char *) output, result_str ) == 0 );
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000713 }
Paul Bakkerb08e6842012-02-11 18:43:20 +0000714
Paul Bakkerbd51b262014-07-10 15:26:12 +0200715exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200716 mbedtls_x509_crl_free( &crl );
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000717}
Paul Bakker33b43f12013-08-20 11:48:36 +0200718/* END_CASE */
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000719
Hanno Becker02a21932019-06-10 15:08:43 +0100720/* BEGIN_CASE depends_on:MBEDTLS_X509_CSR_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */
Azim Khan5fcca462018-06-29 11:05:32 +0100721void mbedtls_x509_csr_parse( data_t * csr_der, char * ref_out, int ref_ret )
Manuel Pégourié-Gonnardd77cd5d2014-06-13 11:13:15 +0200722{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200723 mbedtls_x509_csr csr;
Manuel Pégourié-Gonnardd77cd5d2014-06-13 11:13:15 +0200724 char my_out[1000];
Manuel Pégourié-Gonnardd77cd5d2014-06-13 11:13:15 +0200725 int my_ret;
726
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200727 mbedtls_x509_csr_init( &csr );
Manuel Pégourié-Gonnardd77cd5d2014-06-13 11:13:15 +0200728 memset( my_out, 0, sizeof( my_out ) );
Manuel Pégourié-Gonnardd77cd5d2014-06-13 11:13:15 +0200729
Azim Khand30ca132017-06-09 04:32:58 +0100730 my_ret = mbedtls_x509_csr_parse_der( &csr, csr_der->x, csr_der->len );
Manuel Pégourié-Gonnardd77cd5d2014-06-13 11:13:15 +0200731 TEST_ASSERT( my_ret == ref_ret );
732
733 if( ref_ret == 0 )
734 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200735 size_t my_out_len = mbedtls_x509_csr_info( my_out, sizeof( my_out ), "", &csr );
Manuel Pégourié-Gonnardd77cd5d2014-06-13 11:13:15 +0200736 TEST_ASSERT( my_out_len == strlen( ref_out ) );
737 TEST_ASSERT( strcmp( my_out, ref_out ) == 0 );
738 }
739
Paul Bakkerbd51b262014-07-10 15:26:12 +0200740exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200741 mbedtls_x509_csr_free( &csr );
Manuel Pégourié-Gonnardd77cd5d2014-06-13 11:13:15 +0200742}
743/* END_CASE */
744
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200745/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
Azim Khanf1aaec92017-05-30 14:23:15 +0100746void mbedtls_x509_crt_parse_path( char * crt_path, int ret, int nb_crt )
Manuel Pégourié-Gonnardfbae2a12013-11-26 16:43:39 +0100747{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200748 mbedtls_x509_crt chain, *cur;
Manuel Pégourié-Gonnardfbae2a12013-11-26 16:43:39 +0100749 int i;
750
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200751 mbedtls_x509_crt_init( &chain );
Manuel Pégourié-Gonnardfbae2a12013-11-26 16:43:39 +0100752
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200753 TEST_ASSERT( mbedtls_x509_crt_parse_path( &chain, crt_path ) == ret );
Manuel Pégourié-Gonnardfbae2a12013-11-26 16:43:39 +0100754
755 /* Check how many certs we got */
756 for( i = 0, cur = &chain; cur != NULL; cur = cur->next )
757 if( cur->raw.p != NULL )
758 i++;
759
760 TEST_ASSERT( i == nb_crt );
761
Paul Bakkerbd51b262014-07-10 15:26:12 +0200762exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200763 mbedtls_x509_crt_free( &chain );
Manuel Pégourié-Gonnardfbae2a12013-11-26 16:43:39 +0100764}
765/* END_CASE */
766
Janos Follath822b2c32015-10-11 10:25:22 +0200767/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
Manuel Pégourié-Gonnard1beb0482017-06-05 13:49:44 +0200768void mbedtls_x509_crt_verify_max( char *ca_file, char *chain_dir, int nb_int,
769 int ret_chk, int flags_chk )
770{
771 char file_buf[128];
772 int ret;
773 uint32_t flags;
774 mbedtls_x509_crt trusted, chain;
775
776 /*
777 * We expect chain_dir to contain certificates 00.crt, 01.crt, etc.
778 * with NN.crt signed by NN-1.crt
779 */
780
781 mbedtls_x509_crt_init( &trusted );
782 mbedtls_x509_crt_init( &chain );
783
784 /* Load trusted root */
785 TEST_ASSERT( mbedtls_x509_crt_parse_file( &trusted, ca_file ) == 0 );
786
787 /* Load a chain with nb_int intermediates (from 01 to nb_int),
788 * plus one "end-entity" cert (nb_int + 1) */
789 ret = mbedtls_snprintf( file_buf, sizeof file_buf, "%s/c%02d.pem", chain_dir,
790 nb_int + 1 );
791 TEST_ASSERT( ret > 0 && (size_t) ret < sizeof file_buf );
792 TEST_ASSERT( mbedtls_x509_crt_parse_file( &chain, file_buf ) == 0 );
793
794 /* Try to verify that chain */
795 ret = mbedtls_x509_crt_verify( &chain, &trusted, NULL, NULL, &flags,
796 NULL, NULL );
797 TEST_ASSERT( ret == ret_chk );
798 TEST_ASSERT( flags == (uint32_t) flags_chk );
799
800exit:
801 mbedtls_x509_crt_free( &chain );
802 mbedtls_x509_crt_free( &trusted );
803}
804/* END_CASE */
805
806/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
Manuel Pégourié-Gonnarde54931f2017-05-22 12:04:25 +0200807void mbedtls_x509_crt_verify_chain( char *chain_paths, char *trusted_ca,
808 int flags_result, int result,
Manuel Pégourié-Gonnard6b9d53f2017-05-23 12:26:58 +0200809 char *profile_name, int vrfy_fatal_lvls )
Janos Follath822b2c32015-10-11 10:25:22 +0200810{
811 char* act;
812 uint32_t flags;
Manuel Pégourié-Gonnarde54931f2017-05-22 12:04:25 +0200813 int res;
Manuel Pégourié-Gonnarde670f902015-10-30 09:23:19 +0100814 mbedtls_x509_crt trusted, chain;
Manuel Pégourié-Gonnarde54931f2017-05-22 12:04:25 +0200815 const mbedtls_x509_crt_profile *profile = NULL;
Janos Follathef4f2582015-10-11 16:17:27 +0200816
Janos Follath822b2c32015-10-11 10:25:22 +0200817 mbedtls_x509_crt_init( &chain );
818 mbedtls_x509_crt_init( &trusted );
819
Manuel Pégourié-Gonnarda8838af2015-11-02 06:34:46 +0900820 while( ( act = mystrsep( &chain_paths, " " ) ) != NULL )
Manuel Pégourié-Gonnarde670f902015-10-30 09:23:19 +0100821 TEST_ASSERT( mbedtls_x509_crt_parse_file( &chain, act ) == 0 );
822 TEST_ASSERT( mbedtls_x509_crt_parse_file( &trusted, trusted_ca ) == 0 );
Janos Follath822b2c32015-10-11 10:25:22 +0200823
Manuel Pégourié-Gonnardea2dc142017-08-08 11:10:37 +0200824 if( strcmp( profile_name, "" ) == 0 )
Manuel Pégourié-Gonnarde54931f2017-05-22 12:04:25 +0200825 profile = &mbedtls_x509_crt_profile_default;
Manuel Pégourié-Gonnardea2dc142017-08-08 11:10:37 +0200826 else if( strcmp( profile_name, "next" ) == 0 )
Manuel Pégourié-Gonnarde54931f2017-05-22 12:04:25 +0200827 profile = &mbedtls_x509_crt_profile_next;
Manuel Pégourié-Gonnardea2dc142017-08-08 11:10:37 +0200828 else if( strcmp( profile_name, "suiteb" ) == 0 )
Manuel Pégourié-Gonnarde54931f2017-05-22 12:04:25 +0200829 profile = &mbedtls_x509_crt_profile_suiteb;
Manuel Pégourié-Gonnardea2dc142017-08-08 11:10:37 +0200830 else if( strcmp( profile_name, "rsa3072" ) == 0 )
Manuel Pégourié-Gonnard6622fed2017-05-23 11:29:29 +0200831 profile = &profile_rsa3072;
Manuel Pégourié-Gonnardea2dc142017-08-08 11:10:37 +0200832 else if( strcmp( profile_name, "sha512" ) == 0 )
Manuel Pégourié-Gonnard6622fed2017-05-23 11:29:29 +0200833 profile = &profile_sha512;
Manuel Pégourié-Gonnarde54931f2017-05-22 12:04:25 +0200834
835 res = mbedtls_x509_crt_verify_with_profile( &chain, &trusted, NULL, profile,
Manuel Pégourié-Gonnard6b9d53f2017-05-23 12:26:58 +0200836 NULL, &flags, verify_fatal, &vrfy_fatal_lvls );
Janos Follathef4f2582015-10-11 16:17:27 +0200837
838 TEST_ASSERT( res == ( result ) );
839 TEST_ASSERT( flags == (uint32_t)( flags_result ) );
Janos Follath822b2c32015-10-11 10:25:22 +0200840
841exit:
842 mbedtls_x509_crt_free( &trusted );
843 mbedtls_x509_crt_free( &chain );
844}
845/* END_CASE */
846
Hanno Becker02a21932019-06-10 15:08:43 +0100847/* BEGIN_CASE depends_on:MBEDTLS_X509_USE_C:!MBEDTLS_X509_REMOVE_INFO */
Azim Khan5fcca462018-06-29 11:05:32 +0100848void x509_oid_desc( data_t * buf, char * ref_desc )
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100849{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200850 mbedtls_x509_buf oid;
Manuel Pégourié-Gonnard48d3cef2015-03-20 18:14:26 +0000851 const char *desc = NULL;
Manuel Pégourié-Gonnard48d3cef2015-03-20 18:14:26 +0000852 int ret;
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100853
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100854
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200855 oid.tag = MBEDTLS_ASN1_OID;
Azim Khand30ca132017-06-09 04:32:58 +0100856 oid.p = buf->x;
857 oid.len = buf->len;
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100858
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200859 ret = mbedtls_oid_get_extended_key_usage( &oid, &desc );
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100860
861 if( strcmp( ref_desc, "notfound" ) == 0 )
Manuel Pégourié-Gonnard48d3cef2015-03-20 18:14:26 +0000862 {
863 TEST_ASSERT( ret != 0 );
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100864 TEST_ASSERT( desc == NULL );
Manuel Pégourié-Gonnard48d3cef2015-03-20 18:14:26 +0000865 }
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100866 else
867 {
Manuel Pégourié-Gonnard48d3cef2015-03-20 18:14:26 +0000868 TEST_ASSERT( ret == 0 );
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100869 TEST_ASSERT( desc != NULL );
870 TEST_ASSERT( strcmp( desc, ref_desc ) == 0 );
871 }
872}
873/* END_CASE */
874
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200875/* BEGIN_CASE depends_on:MBEDTLS_X509_USE_C */
Azim Khan5fcca462018-06-29 11:05:32 +0100876void x509_oid_numstr( data_t * oid_buf, char * numstr, int blen, int ret )
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100877{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200878 mbedtls_x509_buf oid;
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100879 char num_buf[100];
880
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100881 memset( num_buf, 0x2a, sizeof num_buf );
882
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200883 oid.tag = MBEDTLS_ASN1_OID;
Azim Khand30ca132017-06-09 04:32:58 +0100884 oid.p = oid_buf->x;
885 oid.len = oid_buf->len;
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100886
887 TEST_ASSERT( (size_t) blen <= sizeof num_buf );
888
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200889 TEST_ASSERT( mbedtls_oid_get_numeric_string( num_buf, blen, &oid ) == ret );
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100890
891 if( ret >= 0 )
892 {
893 TEST_ASSERT( num_buf[ret] == 0 );
894 TEST_ASSERT( strcmp( num_buf, numstr ) == 0 );
895 }
896}
897/* END_CASE */
898
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200899/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_CHECK_KEY_USAGE */
Azim Khanf1aaec92017-05-30 14:23:15 +0100900void x509_check_key_usage( char * crt_file, int usage, int ret )
Manuel Pégourié-Gonnard603116c2014-04-09 09:50:03 +0200901{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200902 mbedtls_x509_crt crt;
Manuel Pégourié-Gonnard603116c2014-04-09 09:50:03 +0200903
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200904 mbedtls_x509_crt_init( &crt );
Manuel Pégourié-Gonnard603116c2014-04-09 09:50:03 +0200905
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200906 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
Manuel Pégourié-Gonnard603116c2014-04-09 09:50:03 +0200907
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200908 TEST_ASSERT( mbedtls_x509_crt_check_key_usage( &crt, usage ) == ret );
Manuel Pégourié-Gonnard603116c2014-04-09 09:50:03 +0200909
Paul Bakkerbd51b262014-07-10 15:26:12 +0200910exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200911 mbedtls_x509_crt_free( &crt );
Manuel Pégourié-Gonnard603116c2014-04-09 09:50:03 +0200912}
913/* END_CASE */
914
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200915/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE */
Azim Khan5fcca462018-06-29 11:05:32 +0100916void x509_check_extended_key_usage( char * crt_file, data_t * oid, int ret
Azim Khand30ca132017-06-09 04:32:58 +0100917 )
Manuel Pégourié-Gonnard7afb8a02014-04-10 17:53:56 +0200918{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200919 mbedtls_x509_crt crt;
Manuel Pégourié-Gonnard7afb8a02014-04-10 17:53:56 +0200920
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200921 mbedtls_x509_crt_init( &crt );
Manuel Pégourié-Gonnard7afb8a02014-04-10 17:53:56 +0200922
Manuel Pégourié-Gonnard7afb8a02014-04-10 17:53:56 +0200923
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200924 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
Manuel Pégourié-Gonnard7afb8a02014-04-10 17:53:56 +0200925
Azim Khand30ca132017-06-09 04:32:58 +0100926 TEST_ASSERT( mbedtls_x509_crt_check_extended_key_usage( &crt, (const char *)oid->x, oid->len ) == ret );
Manuel Pégourié-Gonnard7afb8a02014-04-10 17:53:56 +0200927
Paul Bakkerbd51b262014-07-10 15:26:12 +0200928exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200929 mbedtls_x509_crt_free( &crt );
Manuel Pégourié-Gonnard7afb8a02014-04-10 17:53:56 +0200930}
931/* END_CASE */
932
Andres AG4b76aec2016-09-23 13:16:02 +0100933/* BEGIN_CASE depends_on:MBEDTLS_X509_USE_C */
Azim Khanf1aaec92017-05-30 14:23:15 +0100934void x509_get_time( int tag, char * time_str, int ret, int year, int mon,
935 int day, int hour, int min, int sec )
Andres AG4b76aec2016-09-23 13:16:02 +0100936{
937 mbedtls_x509_time time;
Janos Follathea7054a2017-02-08 14:13:02 +0000938 unsigned char buf[21];
Andres AG4b76aec2016-09-23 13:16:02 +0100939 unsigned char* start = buf;
940 unsigned char* end = buf;
941
942 memset( &time, 0x00, sizeof( time ) );
943 *end = (unsigned char)tag; end++;
Janos Follathea7054a2017-02-08 14:13:02 +0000944 *end = strlen( time_str );
945 TEST_ASSERT( *end < 20 );
Andres AG4b76aec2016-09-23 13:16:02 +0100946 end++;
947 memcpy( end, time_str, (size_t)*(end - 1) );
948 end += *(end - 1);
949
950 TEST_ASSERT( mbedtls_x509_get_time( &start, end, &time ) == ret );
951 if( ret == 0 )
952 {
953 TEST_ASSERT( year == time.year );
954 TEST_ASSERT( mon == time.mon );
955 TEST_ASSERT( day == time.day );
956 TEST_ASSERT( hour == time.hour );
957 TEST_ASSERT( min == time.min );
958 TEST_ASSERT( sec == time.sec );
959 }
960}
961/* END_CASE */
962
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200963/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_RSASSA_PSS_SUPPORT */
Azim Khan5fcca462018-06-29 11:05:32 +0100964void x509_parse_rsassa_pss_params( data_t * hex_params, int params_tag,
Manuel Pégourié-Gonnard85403692014-06-06 14:48:38 +0200965 int ref_msg_md, int ref_mgf_md,
966 int ref_salt_len, int ref_ret )
967{
968 int my_ret;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200969 mbedtls_x509_buf params;
970 mbedtls_md_type_t my_msg_md, my_mgf_md;
Manuel Pégourié-Gonnard85403692014-06-06 14:48:38 +0200971 int my_salt_len;
972
Azim Khand30ca132017-06-09 04:32:58 +0100973 params.p = hex_params->x;
974 params.len = hex_params->len;
Manuel Pégourié-Gonnard85403692014-06-06 14:48:38 +0200975 params.tag = params_tag;
976
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200977 my_ret = mbedtls_x509_get_rsassa_pss_params( &params, &my_msg_md, &my_mgf_md,
Manuel Pégourié-Gonnard85403692014-06-06 14:48:38 +0200978 &my_salt_len );
979
Manuel Pégourié-Gonnard85403692014-06-06 14:48:38 +0200980 TEST_ASSERT( my_ret == ref_ret );
981
982 if( ref_ret == 0 )
983 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200984 TEST_ASSERT( my_msg_md == (mbedtls_md_type_t) ref_msg_md );
985 TEST_ASSERT( my_mgf_md == (mbedtls_md_type_t) ref_mgf_md );
Manuel Pégourié-Gonnard85403692014-06-06 14:48:38 +0200986 TEST_ASSERT( my_salt_len == ref_salt_len );
987 }
988
Paul Bakkerbd51b262014-07-10 15:26:12 +0200989exit:
Azim Khand30ca132017-06-09 04:32:58 +0100990 ;;
Manuel Pégourié-Gonnard85403692014-06-06 14:48:38 +0200991}
992/* END_CASE */
993
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200994/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_SELF_TEST */
Azim Khanf1aaec92017-05-30 14:23:15 +0100995void x509_selftest( )
Paul Bakker37940d9f2009-07-10 22:38:58 +0000996{
Andres AG93012e82016-09-09 09:10:28 +0100997 TEST_ASSERT( mbedtls_x509_self_test( 1 ) == 0 );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000998}
Paul Bakker33b43f12013-08-20 11:48:36 +0200999/* END_CASE */