blob: 156a25fcfe392c08a7ed24de2a012baa372bb271 [file] [log] [blame]
Paul Bakker33b43f12013-08-20 11:48:36 +02001/* BEGIN_HEADER */
Andres AG4b76aec2016-09-23 13:16:02 +01002#include "mbedtls/x509.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +00003#include "mbedtls/x509_crt.h"
4#include "mbedtls/x509_crl.h"
5#include "mbedtls/x509_csr.h"
6#include "mbedtls/pem.h"
7#include "mbedtls/oid.h"
8#include "mbedtls/base64.h"
Paul Bakkerb63b0af2011-01-13 17:54:59 +00009
Manuel Pégourié-Gonnard65eefc82015-10-23 14:08:48 +020010const mbedtls_x509_crt_profile compat_profile =
11{
12 MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA1 ) |
13 MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_RIPEMD160 ) |
14 MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA224 ) |
15 MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA256 ) |
16 MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA384 ) |
17 MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA512 ),
18 0xFFFFFFF, /* Any PK alg */
19 0xFFFFFFF, /* Any curve */
20 1024,
21};
22
Manuel Pégourié-Gonnarde6ef16f2015-05-11 19:54:43 +020023int verify_none( void *data, mbedtls_x509_crt *crt, int certificate_depth, uint32_t *flags )
Paul Bakkerb63b0af2011-01-13 17:54:59 +000024{
Paul Bakker5a624082011-01-18 16:31:52 +000025 ((void) data);
26 ((void) crt);
27 ((void) certificate_depth);
Manuel Pégourié-Gonnarde6028c92015-04-20 12:19:02 +010028 *flags |= MBEDTLS_X509_BADCERT_OTHER;
Paul Bakkerddf26b42013-09-18 13:46:23 +020029
Paul Bakker915275b2012-09-28 07:10:55 +000030 return 0;
Paul Bakkerb63b0af2011-01-13 17:54:59 +000031}
32
Manuel Pégourié-Gonnarde6ef16f2015-05-11 19:54:43 +020033int verify_all( void *data, mbedtls_x509_crt *crt, int certificate_depth, uint32_t *flags )
Paul Bakkerb63b0af2011-01-13 17:54:59 +000034{
Paul Bakker5a624082011-01-18 16:31:52 +000035 ((void) data);
36 ((void) crt);
37 ((void) certificate_depth);
Paul Bakker915275b2012-09-28 07:10:55 +000038 *flags = 0;
Paul Bakker5a624082011-01-18 16:31:52 +000039
Paul Bakkerb63b0af2011-01-13 17:54:59 +000040 return 0;
41}
42
Manuel Pégourié-Gonnarda8838af2015-11-02 06:34:46 +090043/* strsep() not available on Windows */
44char *mystrsep(char **stringp, const char *delim)
45{
46 const char *p;
47 char *ret = *stringp;
48
49 if( *stringp == NULL )
50 return( NULL );
51
52 for( ; ; (*stringp)++ )
53 {
54 if( **stringp == '\0' )
55 {
56 *stringp = NULL;
57 goto done;
58 }
59
60 for( p = delim; *p != '\0'; p++ )
61 if( **stringp == *p )
62 {
63 **stringp = '\0';
64 (*stringp)++;
65 goto done;
66 }
67 }
68
69done:
70 return( ret );
71}
72
Manuel Pégourié-Gonnard560fea32015-09-01 11:59:24 +020073#if defined(MBEDTLS_X509_CRT_PARSE_C)
74typedef struct {
75 char buf[512];
76 char *p;
77} verify_print_context;
78
79void verify_print_init( verify_print_context *ctx )
80{
81 memset( ctx, 0, sizeof( verify_print_context ) );
82 ctx->p = ctx->buf;
83}
84
85int verify_print( void *data, mbedtls_x509_crt *crt, int certificate_depth, uint32_t *flags )
86{
87 int ret;
88 verify_print_context *ctx = (verify_print_context *) data;
89 char *p = ctx->p;
90 size_t n = ctx->buf + sizeof( ctx->buf ) - ctx->p;
91 ((void) flags);
92
93 ret = mbedtls_snprintf( p, n, "depth %d - serial ", certificate_depth );
94 MBEDTLS_X509_SAFE_SNPRINTF;
95
96 ret = mbedtls_x509_serial_gets( p, n, &crt->serial );
97 MBEDTLS_X509_SAFE_SNPRINTF;
98
99 ret = mbedtls_snprintf( p, n, " - subject " );
100 MBEDTLS_X509_SAFE_SNPRINTF;
101
102 ret = mbedtls_x509_dn_gets( p, n, &crt->subject );
103 MBEDTLS_X509_SAFE_SNPRINTF;
104
105 ret = mbedtls_snprintf( p, n, "\n" );
106 MBEDTLS_X509_SAFE_SNPRINTF;
107
108 ctx->p = p;
109
110 return( 0 );
111}
112#endif /* MBEDTLS_X509_CRT_PARSE_C */
Paul Bakker33b43f12013-08-20 11:48:36 +0200113/* END_HEADER */
Paul Bakker37940d9f2009-07-10 22:38:58 +0000114
Paul Bakker33b43f12013-08-20 11:48:36 +0200115/* BEGIN_DEPENDENCIES
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200116 * depends_on:MBEDTLS_BIGNUM_C
Paul Bakker33b43f12013-08-20 11:48:36 +0200117 * END_DEPENDENCIES
118 */
Paul Bakker5690efc2011-05-26 13:16:06 +0000119
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200120/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
Paul Bakker33b43f12013-08-20 11:48:36 +0200121void x509_cert_info( char *crt_file, char *result_str )
Paul Bakker37940d9f2009-07-10 22:38:58 +0000122{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200123 mbedtls_x509_crt crt;
Paul Bakker37940d9f2009-07-10 22:38:58 +0000124 char buf[2000];
Paul Bakker69998dd2009-07-11 19:15:20 +0000125 int res;
Paul Bakker37940d9f2009-07-10 22:38:58 +0000126
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200127 mbedtls_x509_crt_init( &crt );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000128 memset( buf, 0, 2000 );
129
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200130 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
131 res = mbedtls_x509_crt_info( buf, 2000, "", &crt );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000132
133 TEST_ASSERT( res != -1 );
134 TEST_ASSERT( res != -2 );
135
Paul Bakker33b43f12013-08-20 11:48:36 +0200136 TEST_ASSERT( strcmp( buf, result_str ) == 0 );
Paul Bakkerbd51b262014-07-10 15:26:12 +0200137
138exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200139 mbedtls_x509_crt_free( &crt );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000140}
Paul Bakker33b43f12013-08-20 11:48:36 +0200141/* END_CASE */
Paul Bakker37940d9f2009-07-10 22:38:58 +0000142
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200143/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRL_PARSE_C */
144void mbedtls_x509_crl_info( char *crl_file, char *result_str )
Paul Bakker37940d9f2009-07-10 22:38:58 +0000145{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200146 mbedtls_x509_crl crl;
Paul Bakker37940d9f2009-07-10 22:38:58 +0000147 char buf[2000];
Paul Bakker69998dd2009-07-11 19:15:20 +0000148 int res;
Paul Bakker37940d9f2009-07-10 22:38:58 +0000149
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200150 mbedtls_x509_crl_init( &crl );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000151 memset( buf, 0, 2000 );
152
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200153 TEST_ASSERT( mbedtls_x509_crl_parse_file( &crl, crl_file ) == 0 );
154 res = mbedtls_x509_crl_info( buf, 2000, "", &crl );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000155
156 TEST_ASSERT( res != -1 );
157 TEST_ASSERT( res != -2 );
158
Paul Bakker33b43f12013-08-20 11:48:36 +0200159 TEST_ASSERT( strcmp( buf, result_str ) == 0 );
Paul Bakkerbd51b262014-07-10 15:26:12 +0200160
161exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200162 mbedtls_x509_crl_free( &crl );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000163}
Paul Bakker33b43f12013-08-20 11:48:36 +0200164/* END_CASE */
Paul Bakker37940d9f2009-07-10 22:38:58 +0000165
Andres AGa39db392016-12-08 17:10:38 +0000166/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRL_PARSE_C */
167void mbedtls_x509_crl_parse( char *crl_file, int result )
168{
169 mbedtls_x509_crl crl;
170 char buf[2000];
171
172 mbedtls_x509_crl_init( &crl );
173 memset( buf, 0, 2000 );
174
175 TEST_ASSERT( mbedtls_x509_crl_parse_file( &crl, crl_file ) == result );
176
177exit:
178 mbedtls_x509_crl_free( &crl );
179}
180/* END_CASE */
181
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200182/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CSR_PARSE_C */
183void mbedtls_x509_csr_info( char *csr_file, char *result_str )
Manuel Pégourié-Gonnard2a8d7fd2014-01-24 17:34:26 +0100184{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200185 mbedtls_x509_csr csr;
Manuel Pégourié-Gonnard2a8d7fd2014-01-24 17:34:26 +0100186 char buf[2000];
187 int res;
188
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200189 mbedtls_x509_csr_init( &csr );
Manuel Pégourié-Gonnard2a8d7fd2014-01-24 17:34:26 +0100190 memset( buf, 0, 2000 );
191
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200192 TEST_ASSERT( mbedtls_x509_csr_parse_file( &csr, csr_file ) == 0 );
193 res = mbedtls_x509_csr_info( buf, 2000, "", &csr );
Manuel Pégourié-Gonnard2a8d7fd2014-01-24 17:34:26 +0100194
Manuel Pégourié-Gonnard2a8d7fd2014-01-24 17:34:26 +0100195 TEST_ASSERT( res != -1 );
196 TEST_ASSERT( res != -2 );
197
198 TEST_ASSERT( strcmp( buf, result_str ) == 0 );
Paul Bakkerbd51b262014-07-10 15:26:12 +0200199
200exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200201 mbedtls_x509_csr_free( &csr );
Manuel Pégourié-Gonnard2a8d7fd2014-01-24 17:34:26 +0100202}
203/* END_CASE */
204
Manuel Pégourié-Gonnardb5f48ad2015-04-20 10:38:13 +0100205/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */
206void x509_verify_info( int flags, char *prefix, char *result_str )
207{
208 char buf[2000];
209 int res;
210
211 memset( buf, 0, sizeof( buf ) );
212
213 res = mbedtls_x509_crt_verify_info( buf, sizeof( buf ), prefix, flags );
214
215 TEST_ASSERT( res >= 0 );
216
217 TEST_ASSERT( strcmp( buf, result_str ) == 0 );
218}
219/* END_CASE */
220
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200221/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_CRL_PARSE_C */
Paul Bakker33b43f12013-08-20 11:48:36 +0200222void x509_verify( char *crt_file, char *ca_file, char *crl_file,
223 char *cn_name_str, int result, int flags_result,
224 char *verify_callback )
Paul Bakker37940d9f2009-07-10 22:38:58 +0000225{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200226 mbedtls_x509_crt crt;
227 mbedtls_x509_crt ca;
228 mbedtls_x509_crl crl;
Manuel Pégourié-Gonnarde6ef16f2015-05-11 19:54:43 +0200229 uint32_t flags = 0;
Paul Bakker69998dd2009-07-11 19:15:20 +0000230 int res;
Manuel Pégourié-Gonnarde6ef16f2015-05-11 19:54:43 +0200231 int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *) = NULL;
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200232 char * cn_name = NULL;
Paul Bakker37940d9f2009-07-10 22:38:58 +0000233
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200234 mbedtls_x509_crt_init( &crt );
235 mbedtls_x509_crt_init( &ca );
236 mbedtls_x509_crl_init( &crl );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000237
Paul Bakker33b43f12013-08-20 11:48:36 +0200238 if( strcmp( cn_name_str, "NULL" ) != 0 )
239 cn_name = cn_name_str;
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200240
Paul Bakker33b43f12013-08-20 11:48:36 +0200241 if( strcmp( verify_callback, "NULL" ) == 0 )
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200242 f_vrfy = NULL;
Paul Bakker33b43f12013-08-20 11:48:36 +0200243 else if( strcmp( verify_callback, "verify_none" ) == 0 )
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200244 f_vrfy = verify_none;
Paul Bakker33b43f12013-08-20 11:48:36 +0200245 else if( strcmp( verify_callback, "verify_all" ) == 0 )
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200246 f_vrfy = verify_all;
247 else
248 TEST_ASSERT( "No known verify callback selected" == 0 );
249
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200250 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
251 TEST_ASSERT( mbedtls_x509_crt_parse_file( &ca, ca_file ) == 0 );
252 TEST_ASSERT( mbedtls_x509_crl_parse_file( &crl, crl_file ) == 0 );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000253
Manuel Pégourié-Gonnard65eefc82015-10-23 14:08:48 +0200254 res = mbedtls_x509_crt_verify_with_profile( &crt, &ca, &crl, &compat_profile, cn_name, &flags, f_vrfy, NULL );
255
Paul Bakkerbd51b262014-07-10 15:26:12 +0200256 TEST_ASSERT( res == ( result ) );
Manuel Pégourié-Gonnarde6ef16f2015-05-11 19:54:43 +0200257 TEST_ASSERT( flags == (uint32_t)( flags_result ) );
Paul Bakkerbd51b262014-07-10 15:26:12 +0200258
259exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200260 mbedtls_x509_crt_free( &crt );
261 mbedtls_x509_crt_free( &ca );
262 mbedtls_x509_crl_free( &crl );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000263}
Paul Bakker33b43f12013-08-20 11:48:36 +0200264/* END_CASE */
Paul Bakker37940d9f2009-07-10 22:38:58 +0000265
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200266/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
Manuel Pégourié-Gonnard560fea32015-09-01 11:59:24 +0200267void x509_verify_callback( char *crt_file, char *ca_file,
268 int exp_ret, char *exp_vrfy_out )
269{
270 int ret;
271 mbedtls_x509_crt crt;
272 mbedtls_x509_crt ca;
273 uint32_t flags = 0;
274 verify_print_context vrfy_ctx;
275
276 mbedtls_x509_crt_init( &crt );
277 mbedtls_x509_crt_init( &ca );
278 verify_print_init( &vrfy_ctx );
279
280 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
281 TEST_ASSERT( mbedtls_x509_crt_parse_file( &ca, ca_file ) == 0 );
282
283 ret = mbedtls_x509_crt_verify( &crt, &ca, NULL, NULL, &flags,
284 verify_print, &vrfy_ctx );
285
286 TEST_ASSERT( ret == exp_ret );
287 TEST_ASSERT( strcmp( vrfy_ctx.buf, exp_vrfy_out ) == 0 );
288
289exit:
290 mbedtls_x509_crt_free( &crt );
291 mbedtls_x509_crt_free( &ca );
292}
293/* END_CASE */
294
295/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200296void mbedtls_x509_dn_gets( char *crt_file, char *entity, char *result_str )
Paul Bakker37940d9f2009-07-10 22:38:58 +0000297{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200298 mbedtls_x509_crt crt;
Paul Bakker37940d9f2009-07-10 22:38:58 +0000299 char buf[2000];
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200300 int res = 0;
Paul Bakker37940d9f2009-07-10 22:38:58 +0000301
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200302 mbedtls_x509_crt_init( &crt );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000303 memset( buf, 0, 2000 );
304
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200305 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
Paul Bakker33b43f12013-08-20 11:48:36 +0200306 if( strcmp( entity, "subject" ) == 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200307 res = mbedtls_x509_dn_gets( buf, 2000, &crt.subject );
Paul Bakker33b43f12013-08-20 11:48:36 +0200308 else if( strcmp( entity, "issuer" ) == 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200309 res = mbedtls_x509_dn_gets( buf, 2000, &crt.issuer );
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200310 else
311 TEST_ASSERT( "Unknown entity" == 0 );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000312
313 TEST_ASSERT( res != -1 );
314 TEST_ASSERT( res != -2 );
315
Paul Bakker33b43f12013-08-20 11:48:36 +0200316 TEST_ASSERT( strcmp( buf, result_str ) == 0 );
Paul Bakkerbd51b262014-07-10 15:26:12 +0200317
318exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200319 mbedtls_x509_crt_free( &crt );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000320}
Paul Bakker33b43f12013-08-20 11:48:36 +0200321/* END_CASE */
Paul Bakker37940d9f2009-07-10 22:38:58 +0000322
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200323/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
Manuel Pégourié-Gonnardc730ed32015-06-02 10:38:50 +0100324void mbedtls_x509_time_is_past( char *crt_file, char *entity, int result )
Paul Bakker37940d9f2009-07-10 22:38:58 +0000325{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200326 mbedtls_x509_crt crt;
Paul Bakker37940d9f2009-07-10 22:38:58 +0000327
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200328 mbedtls_x509_crt_init( &crt );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000329
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200330 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200331
Paul Bakker33b43f12013-08-20 11:48:36 +0200332 if( strcmp( entity, "valid_from" ) == 0 )
Manuel Pégourié-Gonnardc730ed32015-06-02 10:38:50 +0100333 TEST_ASSERT( mbedtls_x509_time_is_past( &crt.valid_from ) == result );
Paul Bakker33b43f12013-08-20 11:48:36 +0200334 else if( strcmp( entity, "valid_to" ) == 0 )
Manuel Pégourié-Gonnardc730ed32015-06-02 10:38:50 +0100335 TEST_ASSERT( mbedtls_x509_time_is_past( &crt.valid_to ) == result );
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200336 else
337 TEST_ASSERT( "Unknown entity" == 0 );
Paul Bakkerb08e6842012-02-11 18:43:20 +0000338
Paul Bakkerbd51b262014-07-10 15:26:12 +0200339exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200340 mbedtls_x509_crt_free( &crt );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000341}
Paul Bakker33b43f12013-08-20 11:48:36 +0200342/* END_CASE */
Paul Bakker37940d9f2009-07-10 22:38:58 +0000343
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200344/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
Manuel Pégourié-Gonnardc730ed32015-06-02 10:38:50 +0100345void mbedtls_x509_time_is_future( char *crt_file, char *entity, int result )
Manuel Pégourié-Gonnard6304f782014-03-10 12:26:11 +0100346{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200347 mbedtls_x509_crt crt;
Manuel Pégourié-Gonnard6304f782014-03-10 12:26:11 +0100348
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200349 mbedtls_x509_crt_init( &crt );
Manuel Pégourié-Gonnard6304f782014-03-10 12:26:11 +0100350
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200351 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
Manuel Pégourié-Gonnard6304f782014-03-10 12:26:11 +0100352
353 if( strcmp( entity, "valid_from" ) == 0 )
Manuel Pégourié-Gonnardc730ed32015-06-02 10:38:50 +0100354 TEST_ASSERT( mbedtls_x509_time_is_future( &crt.valid_from ) == result );
Manuel Pégourié-Gonnard6304f782014-03-10 12:26:11 +0100355 else if( strcmp( entity, "valid_to" ) == 0 )
Manuel Pégourié-Gonnardc730ed32015-06-02 10:38:50 +0100356 TEST_ASSERT( mbedtls_x509_time_is_future( &crt.valid_to ) == result );
Manuel Pégourié-Gonnard6304f782014-03-10 12:26:11 +0100357 else
358 TEST_ASSERT( "Unknown entity" == 0 );
359
Paul Bakkerbd51b262014-07-10 15:26:12 +0200360exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200361 mbedtls_x509_crt_free( &crt );
Manuel Pégourié-Gonnard6304f782014-03-10 12:26:11 +0100362}
363/* END_CASE */
364
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200365/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_FS_IO */
Paul Bakker5a5fa922014-09-26 14:53:04 +0200366void x509parse_crt_file( char *crt_file, int result )
367{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200368 mbedtls_x509_crt crt;
Paul Bakker5a5fa922014-09-26 14:53:04 +0200369
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200370 mbedtls_x509_crt_init( &crt );
Paul Bakker5a5fa922014-09-26 14:53:04 +0200371
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200372 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == result );
Paul Bakker5a5fa922014-09-26 14:53:04 +0200373
374exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200375 mbedtls_x509_crt_free( &crt );
Paul Bakker5a5fa922014-09-26 14:53:04 +0200376}
377/* END_CASE */
378
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200379/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */
Paul Bakker33b43f12013-08-20 11:48:36 +0200380void x509parse_crt( char *crt_data, char *result_str, int result )
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000381{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200382 mbedtls_x509_crt crt;
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000383 unsigned char buf[2000];
384 unsigned char output[2000];
385 int data_len, res;
386
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200387 mbedtls_x509_crt_init( &crt );
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000388 memset( buf, 0, 2000 );
389 memset( output, 0, 2000 );
390
Paul Bakker33b43f12013-08-20 11:48:36 +0200391 data_len = unhexify( buf, crt_data );
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000392
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200393 TEST_ASSERT( mbedtls_x509_crt_parse( &crt, buf, data_len ) == ( result ) );
Paul Bakker33b43f12013-08-20 11:48:36 +0200394 if( ( result ) == 0 )
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000395 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200396 res = mbedtls_x509_crt_info( (char *) output, 2000, "", &crt );
Paul Bakker33b43f12013-08-20 11:48:36 +0200397
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000398 TEST_ASSERT( res != -1 );
399 TEST_ASSERT( res != -2 );
400
Paul Bakker33b43f12013-08-20 11:48:36 +0200401 TEST_ASSERT( strcmp( (char *) output, result_str ) == 0 );
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000402 }
Paul Bakkerb08e6842012-02-11 18:43:20 +0000403
Paul Bakkerbd51b262014-07-10 15:26:12 +0200404exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200405 mbedtls_x509_crt_free( &crt );
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000406}
Paul Bakker33b43f12013-08-20 11:48:36 +0200407/* END_CASE */
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000408
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200409/* BEGIN_CASE depends_on:MBEDTLS_X509_CRL_PARSE_C */
Paul Bakker33b43f12013-08-20 11:48:36 +0200410void x509parse_crl( char *crl_data, char *result_str, int result )
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000411{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200412 mbedtls_x509_crl crl;
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000413 unsigned char buf[2000];
414 unsigned char output[2000];
415 int data_len, res;
416
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200417 mbedtls_x509_crl_init( &crl );
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000418 memset( buf, 0, 2000 );
419 memset( output, 0, 2000 );
420
Paul Bakker33b43f12013-08-20 11:48:36 +0200421 data_len = unhexify( buf, crl_data );
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000422
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200423 TEST_ASSERT( mbedtls_x509_crl_parse( &crl, buf, data_len ) == ( result ) );
Paul Bakker33b43f12013-08-20 11:48:36 +0200424 if( ( result ) == 0 )
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000425 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200426 res = mbedtls_x509_crl_info( (char *) output, 2000, "", &crl );
Paul Bakker33b43f12013-08-20 11:48:36 +0200427
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000428 TEST_ASSERT( res != -1 );
429 TEST_ASSERT( res != -2 );
430
Paul Bakker33b43f12013-08-20 11:48:36 +0200431 TEST_ASSERT( strcmp( (char *) output, result_str ) == 0 );
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000432 }
Paul Bakkerb08e6842012-02-11 18:43:20 +0000433
Paul Bakkerbd51b262014-07-10 15:26:12 +0200434exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200435 mbedtls_x509_crl_free( &crl );
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000436}
Paul Bakker33b43f12013-08-20 11:48:36 +0200437/* END_CASE */
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000438
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200439/* BEGIN_CASE depends_on:MBEDTLS_X509_CSR_PARSE_C */
440void mbedtls_x509_csr_parse( char *csr_der_hex, char *ref_out, int ref_ret )
Manuel Pégourié-Gonnardd77cd5d2014-06-13 11:13:15 +0200441{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200442 mbedtls_x509_csr csr;
Paul Bakkerbd51b262014-07-10 15:26:12 +0200443 unsigned char *csr_der = NULL;
Manuel Pégourié-Gonnardd77cd5d2014-06-13 11:13:15 +0200444 char my_out[1000];
445 size_t csr_der_len;
446 int my_ret;
447
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200448 mbedtls_x509_csr_init( &csr );
Manuel Pégourié-Gonnardd77cd5d2014-06-13 11:13:15 +0200449 memset( my_out, 0, sizeof( my_out ) );
450 csr_der = unhexify_alloc( csr_der_hex, &csr_der_len );
451
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200452 my_ret = mbedtls_x509_csr_parse_der( &csr, csr_der, csr_der_len );
Manuel Pégourié-Gonnardd77cd5d2014-06-13 11:13:15 +0200453 TEST_ASSERT( my_ret == ref_ret );
454
455 if( ref_ret == 0 )
456 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200457 size_t my_out_len = mbedtls_x509_csr_info( my_out, sizeof( my_out ), "", &csr );
Manuel Pégourié-Gonnardd77cd5d2014-06-13 11:13:15 +0200458 TEST_ASSERT( my_out_len == strlen( ref_out ) );
459 TEST_ASSERT( strcmp( my_out, ref_out ) == 0 );
460 }
461
Paul Bakkerbd51b262014-07-10 15:26:12 +0200462exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200463 mbedtls_x509_csr_free( &csr );
464 mbedtls_free( csr_der );
Manuel Pégourié-Gonnardd77cd5d2014-06-13 11:13:15 +0200465}
466/* END_CASE */
467
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200468/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
469void mbedtls_x509_crt_parse_path( char *crt_path, int ret, int nb_crt )
Manuel Pégourié-Gonnardfbae2a12013-11-26 16:43:39 +0100470{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200471 mbedtls_x509_crt chain, *cur;
Manuel Pégourié-Gonnardfbae2a12013-11-26 16:43:39 +0100472 int i;
473
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200474 mbedtls_x509_crt_init( &chain );
Manuel Pégourié-Gonnardfbae2a12013-11-26 16:43:39 +0100475
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200476 TEST_ASSERT( mbedtls_x509_crt_parse_path( &chain, crt_path ) == ret );
Manuel Pégourié-Gonnardfbae2a12013-11-26 16:43:39 +0100477
478 /* Check how many certs we got */
479 for( i = 0, cur = &chain; cur != NULL; cur = cur->next )
480 if( cur->raw.p != NULL )
481 i++;
482
483 TEST_ASSERT( i == nb_crt );
484
Paul Bakkerbd51b262014-07-10 15:26:12 +0200485exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200486 mbedtls_x509_crt_free( &chain );
Manuel Pégourié-Gonnardfbae2a12013-11-26 16:43:39 +0100487}
488/* END_CASE */
489
Janos Follath822b2c32015-10-11 10:25:22 +0200490/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
Janos Follathef4f2582015-10-11 16:17:27 +0200491void mbedtls_x509_crt_verify_chain( char *chain_paths, char *trusted_ca, int flags_result )
Janos Follath822b2c32015-10-11 10:25:22 +0200492{
493 char* act;
494 uint32_t flags;
Janos Follathef4f2582015-10-11 16:17:27 +0200495 int result, res;
Manuel Pégourié-Gonnarde670f902015-10-30 09:23:19 +0100496 mbedtls_x509_crt trusted, chain;
Janos Follath822b2c32015-10-11 10:25:22 +0200497
Janos Follathef4f2582015-10-11 16:17:27 +0200498 result= flags_result?MBEDTLS_ERR_X509_CERT_VERIFY_FAILED:0;
499
Janos Follath822b2c32015-10-11 10:25:22 +0200500 mbedtls_x509_crt_init( &chain );
501 mbedtls_x509_crt_init( &trusted );
502
Manuel Pégourié-Gonnarda8838af2015-11-02 06:34:46 +0900503 while( ( act = mystrsep( &chain_paths, " " ) ) != NULL )
Manuel Pégourié-Gonnarde670f902015-10-30 09:23:19 +0100504 TEST_ASSERT( mbedtls_x509_crt_parse_file( &chain, act ) == 0 );
505 TEST_ASSERT( mbedtls_x509_crt_parse_file( &trusted, trusted_ca ) == 0 );
Janos Follath822b2c32015-10-11 10:25:22 +0200506
507 res = mbedtls_x509_crt_verify( &chain, &trusted, NULL, NULL, &flags, NULL, NULL );
Janos Follathef4f2582015-10-11 16:17:27 +0200508
509 TEST_ASSERT( res == ( result ) );
510 TEST_ASSERT( flags == (uint32_t)( flags_result ) );
Janos Follath822b2c32015-10-11 10:25:22 +0200511
512exit:
513 mbedtls_x509_crt_free( &trusted );
514 mbedtls_x509_crt_free( &chain );
515}
516/* END_CASE */
517
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200518/* BEGIN_CASE depends_on:MBEDTLS_X509_USE_C */
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100519void x509_oid_desc( char *oid_str, char *ref_desc )
520{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200521 mbedtls_x509_buf oid;
Manuel Pégourié-Gonnard48d3cef2015-03-20 18:14:26 +0000522 const char *desc = NULL;
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100523 unsigned char buf[20];
Manuel Pégourié-Gonnard48d3cef2015-03-20 18:14:26 +0000524 int ret;
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100525
526 memset( buf, 0, sizeof buf );
527
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200528 oid.tag = MBEDTLS_ASN1_OID;
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100529 oid.len = unhexify( buf, oid_str );
530 oid.p = buf;
531
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200532 ret = mbedtls_oid_get_extended_key_usage( &oid, &desc );
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100533
534 if( strcmp( ref_desc, "notfound" ) == 0 )
Manuel Pégourié-Gonnard48d3cef2015-03-20 18:14:26 +0000535 {
536 TEST_ASSERT( ret != 0 );
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100537 TEST_ASSERT( desc == NULL );
Manuel Pégourié-Gonnard48d3cef2015-03-20 18:14:26 +0000538 }
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100539 else
540 {
Manuel Pégourié-Gonnard48d3cef2015-03-20 18:14:26 +0000541 TEST_ASSERT( ret == 0 );
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100542 TEST_ASSERT( desc != NULL );
543 TEST_ASSERT( strcmp( desc, ref_desc ) == 0 );
544 }
545}
546/* END_CASE */
547
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200548/* BEGIN_CASE depends_on:MBEDTLS_X509_USE_C */
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100549void x509_oid_numstr( char *oid_str, char *numstr, int blen, int ret )
550{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200551 mbedtls_x509_buf oid;
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100552 unsigned char oid_buf[20];
553 char num_buf[100];
554
555 memset( oid_buf, 0x00, sizeof oid_buf );
556 memset( num_buf, 0x2a, sizeof num_buf );
557
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200558 oid.tag = MBEDTLS_ASN1_OID;
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100559 oid.len = unhexify( oid_buf, oid_str );
560 oid.p = oid_buf;
561
562 TEST_ASSERT( (size_t) blen <= sizeof num_buf );
563
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200564 TEST_ASSERT( mbedtls_oid_get_numeric_string( num_buf, blen, &oid ) == ret );
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100565
566 if( ret >= 0 )
567 {
568 TEST_ASSERT( num_buf[ret] == 0 );
569 TEST_ASSERT( strcmp( num_buf, numstr ) == 0 );
570 }
571}
572/* END_CASE */
573
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200574/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_CHECK_KEY_USAGE */
Manuel Pégourié-Gonnard603116c2014-04-09 09:50:03 +0200575void x509_check_key_usage( char *crt_file, int usage, int ret )
576{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200577 mbedtls_x509_crt crt;
Manuel Pégourié-Gonnard603116c2014-04-09 09:50:03 +0200578
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200579 mbedtls_x509_crt_init( &crt );
Manuel Pégourié-Gonnard603116c2014-04-09 09:50:03 +0200580
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200581 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
Manuel Pégourié-Gonnard603116c2014-04-09 09:50:03 +0200582
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200583 TEST_ASSERT( mbedtls_x509_crt_check_key_usage( &crt, usage ) == ret );
Manuel Pégourié-Gonnard603116c2014-04-09 09:50:03 +0200584
Paul Bakkerbd51b262014-07-10 15:26:12 +0200585exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200586 mbedtls_x509_crt_free( &crt );
Manuel Pégourié-Gonnard603116c2014-04-09 09:50:03 +0200587}
588/* END_CASE */
589
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200590/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE */
Manuel Pégourié-Gonnard7afb8a02014-04-10 17:53:56 +0200591void x509_check_extended_key_usage( char *crt_file, char *usage_hex, int ret )
592{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200593 mbedtls_x509_crt crt;
Manuel Pégourié-Gonnard7afb8a02014-04-10 17:53:56 +0200594 char oid[50];
595 size_t len;
596
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200597 mbedtls_x509_crt_init( &crt );
Manuel Pégourié-Gonnard7afb8a02014-04-10 17:53:56 +0200598
599 len = unhexify( (unsigned char *) oid, usage_hex );
600
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200601 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 );
Manuel Pégourié-Gonnard7afb8a02014-04-10 17:53:56 +0200602
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200603 TEST_ASSERT( mbedtls_x509_crt_check_extended_key_usage( &crt, oid, len ) == ret );
Manuel Pégourié-Gonnard7afb8a02014-04-10 17:53:56 +0200604
Paul Bakkerbd51b262014-07-10 15:26:12 +0200605exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200606 mbedtls_x509_crt_free( &crt );
Manuel Pégourié-Gonnard7afb8a02014-04-10 17:53:56 +0200607}
608/* END_CASE */
609
Andres AG4b76aec2016-09-23 13:16:02 +0100610/* BEGIN_CASE depends_on:MBEDTLS_X509_USE_C */
611void x509_get_time( int tag, char *time_str, int ret,
612 int year, int mon, int day,
613 int hour, int min, int sec )
614{
615 mbedtls_x509_time time;
616 unsigned char buf[17];
617 unsigned char* start = buf;
618 unsigned char* end = buf;
619
620 memset( &time, 0x00, sizeof( time ) );
621 *end = (unsigned char)tag; end++;
622 if( tag == MBEDTLS_ASN1_UTC_TIME )
623 *end = 13;
624 else
625 *end = 15;
626 end++;
627 memcpy( end, time_str, (size_t)*(end - 1) );
628 end += *(end - 1);
629
630 TEST_ASSERT( mbedtls_x509_get_time( &start, end, &time ) == ret );
631 if( ret == 0 )
632 {
633 TEST_ASSERT( year == time.year );
634 TEST_ASSERT( mon == time.mon );
635 TEST_ASSERT( day == time.day );
636 TEST_ASSERT( hour == time.hour );
637 TEST_ASSERT( min == time.min );
638 TEST_ASSERT( sec == time.sec );
639 }
640}
641/* END_CASE */
642
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200643/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_RSASSA_PSS_SUPPORT */
Manuel Pégourié-Gonnard85403692014-06-06 14:48:38 +0200644void x509_parse_rsassa_pss_params( char *hex_params, int params_tag,
645 int ref_msg_md, int ref_mgf_md,
646 int ref_salt_len, int ref_ret )
647{
648 int my_ret;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200649 mbedtls_x509_buf params;
650 mbedtls_md_type_t my_msg_md, my_mgf_md;
Manuel Pégourié-Gonnard85403692014-06-06 14:48:38 +0200651 int my_salt_len;
652
653 params.p = unhexify_alloc( hex_params, &params.len );
654 params.tag = params_tag;
655
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200656 my_ret = mbedtls_x509_get_rsassa_pss_params( &params, &my_msg_md, &my_mgf_md,
Manuel Pégourié-Gonnard85403692014-06-06 14:48:38 +0200657 &my_salt_len );
658
Manuel Pégourié-Gonnard85403692014-06-06 14:48:38 +0200659 TEST_ASSERT( my_ret == ref_ret );
660
661 if( ref_ret == 0 )
662 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200663 TEST_ASSERT( my_msg_md == (mbedtls_md_type_t) ref_msg_md );
664 TEST_ASSERT( my_mgf_md == (mbedtls_md_type_t) ref_mgf_md );
Manuel Pégourié-Gonnard85403692014-06-06 14:48:38 +0200665 TEST_ASSERT( my_salt_len == ref_salt_len );
666 }
667
Paul Bakkerbd51b262014-07-10 15:26:12 +0200668exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200669 mbedtls_free( params.p );
Manuel Pégourié-Gonnard85403692014-06-06 14:48:38 +0200670}
671/* END_CASE */
672
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200673/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_SELF_TEST */
Paul Bakker33b43f12013-08-20 11:48:36 +0200674void x509_selftest()
Paul Bakker37940d9f2009-07-10 22:38:58 +0000675{
Andres AG93012e82016-09-09 09:10:28 +0100676 TEST_ASSERT( mbedtls_x509_self_test( 1 ) == 0 );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000677}
Paul Bakker33b43f12013-08-20 11:48:36 +0200678/* END_CASE */