blob: b7a10951239fc54b45500f780558450c067f3d88 [file] [log] [blame]
Paul Bakker33b43f12013-08-20 11:48:36 +02001/* BEGIN_HEADER */
Paul Bakker7c6b2c32013-09-16 13:49:26 +02002#include <polarssl/x509_crt.h>
3#include <polarssl/x509_crl.h>
Manuel Pégourié-Gonnard2a8d7fd2014-01-24 17:34:26 +01004#include <polarssl/x509_csr.h>
Paul Bakker96743fc2011-02-12 14:30:57 +00005#include <polarssl/pem.h>
Paul Bakkerc70b9822013-04-07 22:00:46 +02006#include <polarssl/oid.h>
Paul Bakkerb63b0af2011-01-13 17:54:59 +00007
Paul Bakkerc559c7a2013-09-18 14:13:26 +02008int verify_none( void *data, x509_crt *crt, int certificate_depth, int *flags )
Paul Bakkerb63b0af2011-01-13 17:54:59 +00009{
Paul Bakker5a624082011-01-18 16:31:52 +000010 ((void) data);
11 ((void) crt);
12 ((void) certificate_depth);
Paul Bakker915275b2012-09-28 07:10:55 +000013 *flags |= BADCERT_OTHER;
Paul Bakkerddf26b42013-09-18 13:46:23 +020014
Paul Bakker915275b2012-09-28 07:10:55 +000015 return 0;
Paul Bakkerb63b0af2011-01-13 17:54:59 +000016}
17
Paul Bakkerc559c7a2013-09-18 14:13:26 +020018int verify_all( void *data, x509_crt *crt, int certificate_depth, int *flags )
Paul Bakkerb63b0af2011-01-13 17:54:59 +000019{
Paul Bakker5a624082011-01-18 16:31:52 +000020 ((void) data);
21 ((void) crt);
22 ((void) certificate_depth);
Paul Bakker915275b2012-09-28 07:10:55 +000023 *flags = 0;
Paul Bakker5a624082011-01-18 16:31:52 +000024
Paul Bakkerb63b0af2011-01-13 17:54:59 +000025 return 0;
26}
27
Paul Bakker33b43f12013-08-20 11:48:36 +020028/* END_HEADER */
Paul Bakker37940d9f2009-07-10 22:38:58 +000029
Paul Bakker33b43f12013-08-20 11:48:36 +020030/* BEGIN_DEPENDENCIES
Paul Bakker7c6b2c32013-09-16 13:49:26 +020031 * depends_on:POLARSSL_BIGNUM_C
Paul Bakker33b43f12013-08-20 11:48:36 +020032 * END_DEPENDENCIES
33 */
Paul Bakker5690efc2011-05-26 13:16:06 +000034
Paul Bakker7c6b2c32013-09-16 13:49:26 +020035/* BEGIN_CASE depends_on:POLARSSL_FS_IO:POLARSSL_X509_CRT_PARSE_C */
Paul Bakker33b43f12013-08-20 11:48:36 +020036void x509_cert_info( char *crt_file, char *result_str )
Paul Bakker37940d9f2009-07-10 22:38:58 +000037{
Paul Bakkerc559c7a2013-09-18 14:13:26 +020038 x509_crt crt;
Paul Bakker37940d9f2009-07-10 22:38:58 +000039 char buf[2000];
Paul Bakker69998dd2009-07-11 19:15:20 +000040 int res;
Paul Bakker37940d9f2009-07-10 22:38:58 +000041
Paul Bakker369d2eb2013-09-18 11:58:25 +020042 x509_crt_init( &crt );
Paul Bakker37940d9f2009-07-10 22:38:58 +000043 memset( buf, 0, 2000 );
44
Paul Bakkerddf26b42013-09-18 13:46:23 +020045 TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == 0 );
46 res = x509_crt_info( buf, 2000, "", &crt );
Paul Bakker37940d9f2009-07-10 22:38:58 +000047
Paul Bakker7c6b2c32013-09-16 13:49:26 +020048 x509_crt_free( &crt );
Paul Bakkerb08e6842012-02-11 18:43:20 +000049
Paul Bakker37940d9f2009-07-10 22:38:58 +000050 TEST_ASSERT( res != -1 );
51 TEST_ASSERT( res != -2 );
52
Paul Bakker33b43f12013-08-20 11:48:36 +020053 TEST_ASSERT( strcmp( buf, result_str ) == 0 );
Paul Bakker37940d9f2009-07-10 22:38:58 +000054}
Paul Bakker33b43f12013-08-20 11:48:36 +020055/* END_CASE */
Paul Bakker37940d9f2009-07-10 22:38:58 +000056
Paul Bakker7c6b2c32013-09-16 13:49:26 +020057/* BEGIN_CASE depends_on:POLARSSL_FS_IO:POLARSSL_X509_CRL_PARSE_C */
Paul Bakker33b43f12013-08-20 11:48:36 +020058void x509_crl_info( char *crl_file, char *result_str )
Paul Bakker37940d9f2009-07-10 22:38:58 +000059{
60 x509_crl crl;
61 char buf[2000];
Paul Bakker69998dd2009-07-11 19:15:20 +000062 int res;
Paul Bakker37940d9f2009-07-10 22:38:58 +000063
Paul Bakker369d2eb2013-09-18 11:58:25 +020064 x509_crl_init( &crl );
Paul Bakker37940d9f2009-07-10 22:38:58 +000065 memset( buf, 0, 2000 );
66
Paul Bakkerddf26b42013-09-18 13:46:23 +020067 TEST_ASSERT( x509_crl_parse_file( &crl, crl_file ) == 0 );
68 res = x509_crl_info( buf, 2000, "", &crl );
Paul Bakker37940d9f2009-07-10 22:38:58 +000069
Paul Bakkerb08e6842012-02-11 18:43:20 +000070 x509_crl_free( &crl );
71
Paul Bakker37940d9f2009-07-10 22:38:58 +000072 TEST_ASSERT( res != -1 );
73 TEST_ASSERT( res != -2 );
74
Paul Bakker33b43f12013-08-20 11:48:36 +020075 TEST_ASSERT( strcmp( buf, result_str ) == 0 );
Paul Bakker37940d9f2009-07-10 22:38:58 +000076}
Paul Bakker33b43f12013-08-20 11:48:36 +020077/* END_CASE */
Paul Bakker37940d9f2009-07-10 22:38:58 +000078
Manuel Pégourié-Gonnard2a8d7fd2014-01-24 17:34:26 +010079/* BEGIN_CASE depends_on:POLARSSL_FS_IO:POLARSSL_X509_CSR_PARSE_C */
80void x509_csr_info( char *csr_file, char *result_str )
81{
82 x509_csr csr;
83 char buf[2000];
84 int res;
85
86 x509_csr_init( &csr );
87 memset( buf, 0, 2000 );
88
89 TEST_ASSERT( x509_csr_parse_file( &csr, csr_file ) == 0 );
90 res = x509_csr_info( buf, 2000, "", &csr );
91
92 x509_csr_free( &csr );
93
94 TEST_ASSERT( res != -1 );
95 TEST_ASSERT( res != -2 );
96
97 TEST_ASSERT( strcmp( buf, result_str ) == 0 );
98}
99/* END_CASE */
100
Manuel Pégourié-Gonnardcbf3ef32013-09-23 12:20:02 +0200101/* BEGIN_CASE depends_on:POLARSSL_FS_IO:POLARSSL_X509_CRT_PARSE_C:POLARSSL_X509_CRL_PARSE_C */
Paul Bakker33b43f12013-08-20 11:48:36 +0200102void x509_verify( char *crt_file, char *ca_file, char *crl_file,
103 char *cn_name_str, int result, int flags_result,
104 char *verify_callback )
Paul Bakker37940d9f2009-07-10 22:38:58 +0000105{
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200106 x509_crt crt;
107 x509_crt ca;
Paul Bakker37940d9f2009-07-10 22:38:58 +0000108 x509_crl crl;
109 int flags = 0;
Paul Bakker69998dd2009-07-11 19:15:20 +0000110 int res;
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200111 int (*f_vrfy)(void *, x509_crt *, int, int *) = NULL;
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200112 char * cn_name = NULL;
Paul Bakker37940d9f2009-07-10 22:38:58 +0000113
Paul Bakker369d2eb2013-09-18 11:58:25 +0200114 x509_crt_init( &crt );
115 x509_crt_init( &ca );
116 x509_crl_init( &crl );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000117
Paul Bakker33b43f12013-08-20 11:48:36 +0200118 if( strcmp( cn_name_str, "NULL" ) != 0 )
119 cn_name = cn_name_str;
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200120
Paul Bakker33b43f12013-08-20 11:48:36 +0200121 if( strcmp( verify_callback, "NULL" ) == 0 )
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200122 f_vrfy = NULL;
Paul Bakker33b43f12013-08-20 11:48:36 +0200123 else if( strcmp( verify_callback, "verify_none" ) == 0 )
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200124 f_vrfy = verify_none;
Paul Bakker33b43f12013-08-20 11:48:36 +0200125 else if( strcmp( verify_callback, "verify_all" ) == 0 )
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200126 f_vrfy = verify_all;
127 else
128 TEST_ASSERT( "No known verify callback selected" == 0 );
129
Paul Bakkerddf26b42013-09-18 13:46:23 +0200130 TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == 0 );
131 TEST_ASSERT( x509_crt_parse_file( &ca, ca_file ) == 0 );
132 TEST_ASSERT( x509_crl_parse_file( &crl, crl_file ) == 0 );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000133
Paul Bakkerddf26b42013-09-18 13:46:23 +0200134 res = x509_crt_verify( &crt, &ca, &crl, cn_name, &flags, f_vrfy, NULL );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000135
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200136 x509_crt_free( &crt );
137 x509_crt_free( &ca );
Paul Bakkerb08e6842012-02-11 18:43:20 +0000138 x509_crl_free( &crl );
139
Paul Bakker33b43f12013-08-20 11:48:36 +0200140 TEST_ASSERT( res == ( result ) );
141 TEST_ASSERT( flags == ( flags_result ) );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000142}
Paul Bakker33b43f12013-08-20 11:48:36 +0200143/* END_CASE */
Paul Bakker37940d9f2009-07-10 22:38:58 +0000144
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200145/* BEGIN_CASE depends_on:POLARSSL_FS_IO:POLARSSL_X509_USE_C */
Paul Bakker33b43f12013-08-20 11:48:36 +0200146void x509_dn_gets( char *crt_file, char *entity, char *result_str )
Paul Bakker37940d9f2009-07-10 22:38:58 +0000147{
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200148 x509_crt crt;
Paul Bakker37940d9f2009-07-10 22:38:58 +0000149 char buf[2000];
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200150 int res = 0;
Paul Bakker37940d9f2009-07-10 22:38:58 +0000151
Paul Bakker369d2eb2013-09-18 11:58:25 +0200152 x509_crt_init( &crt );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000153 memset( buf, 0, 2000 );
154
Paul Bakkerddf26b42013-09-18 13:46:23 +0200155 TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == 0 );
Paul Bakker33b43f12013-08-20 11:48:36 +0200156 if( strcmp( entity, "subject" ) == 0 )
Paul Bakker86d0c192013-09-18 11:11:02 +0200157 res = x509_dn_gets( buf, 2000, &crt.subject );
Paul Bakker33b43f12013-08-20 11:48:36 +0200158 else if( strcmp( entity, "issuer" ) == 0 )
Paul Bakker86d0c192013-09-18 11:11:02 +0200159 res = x509_dn_gets( buf, 2000, &crt.issuer );
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200160 else
161 TEST_ASSERT( "Unknown entity" == 0 );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000162
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200163 x509_crt_free( &crt );
Paul Bakkerb08e6842012-02-11 18:43:20 +0000164
Paul Bakker37940d9f2009-07-10 22:38:58 +0000165 TEST_ASSERT( res != -1 );
166 TEST_ASSERT( res != -2 );
167
Paul Bakker33b43f12013-08-20 11:48:36 +0200168 TEST_ASSERT( strcmp( buf, result_str ) == 0 );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000169}
Paul Bakker33b43f12013-08-20 11:48:36 +0200170/* END_CASE */
Paul Bakker37940d9f2009-07-10 22:38:58 +0000171
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200172/* BEGIN_CASE depends_on:POLARSSL_FS_IO:POLARSSL_X509_USE_C */
Paul Bakker33b43f12013-08-20 11:48:36 +0200173void x509_time_expired( char *crt_file, char *entity, int result )
Paul Bakker37940d9f2009-07-10 22:38:58 +0000174{
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200175 x509_crt crt;
Paul Bakker37940d9f2009-07-10 22:38:58 +0000176
Paul Bakker369d2eb2013-09-18 11:58:25 +0200177 x509_crt_init( &crt );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000178
Paul Bakkerddf26b42013-09-18 13:46:23 +0200179 TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == 0 );
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200180
Paul Bakker33b43f12013-08-20 11:48:36 +0200181 if( strcmp( entity, "valid_from" ) == 0 )
Paul Bakker86d0c192013-09-18 11:11:02 +0200182 TEST_ASSERT( x509_time_expired( &crt.valid_from ) == result );
Paul Bakker33b43f12013-08-20 11:48:36 +0200183 else if( strcmp( entity, "valid_to" ) == 0 )
Paul Bakker86d0c192013-09-18 11:11:02 +0200184 TEST_ASSERT( x509_time_expired( &crt.valid_to ) == result );
Paul Bakkerdbd443d2013-08-16 13:38:47 +0200185 else
186 TEST_ASSERT( "Unknown entity" == 0 );
Paul Bakkerb08e6842012-02-11 18:43:20 +0000187
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200188 x509_crt_free( &crt );
Paul Bakker37940d9f2009-07-10 22:38:58 +0000189}
Paul Bakker33b43f12013-08-20 11:48:36 +0200190/* END_CASE */
Paul Bakker37940d9f2009-07-10 22:38:58 +0000191
Manuel Pégourié-Gonnard6304f782014-03-10 12:26:11 +0100192/* BEGIN_CASE depends_on:POLARSSL_FS_IO:POLARSSL_X509_USE_C */
193void x509_time_future( char *crt_file, char *entity, int result )
194{
195 x509_crt crt;
196
197 x509_crt_init( &crt );
198
199 TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == 0 );
200
201 if( strcmp( entity, "valid_from" ) == 0 )
202 TEST_ASSERT( x509_time_future( &crt.valid_from ) == result );
203 else if( strcmp( entity, "valid_to" ) == 0 )
204 TEST_ASSERT( x509_time_future( &crt.valid_to ) == result );
205 else
206 TEST_ASSERT( "Unknown entity" == 0 );
207
208 x509_crt_free( &crt );
209}
210/* END_CASE */
211
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200212/* BEGIN_CASE depends_on:POLARSSL_X509_CRT_PARSE_C */
Paul Bakker33b43f12013-08-20 11:48:36 +0200213void x509parse_crt( char *crt_data, char *result_str, int result )
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000214{
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200215 x509_crt crt;
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000216 unsigned char buf[2000];
217 unsigned char output[2000];
218 int data_len, res;
219
Paul Bakker369d2eb2013-09-18 11:58:25 +0200220 x509_crt_init( &crt );
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000221 memset( buf, 0, 2000 );
222 memset( output, 0, 2000 );
223
Paul Bakker33b43f12013-08-20 11:48:36 +0200224 data_len = unhexify( buf, crt_data );
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000225
Paul Bakkerddf26b42013-09-18 13:46:23 +0200226 TEST_ASSERT( x509_crt_parse( &crt, buf, data_len ) == ( result ) );
Paul Bakker33b43f12013-08-20 11:48:36 +0200227 if( ( result ) == 0 )
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000228 {
Paul Bakkerddf26b42013-09-18 13:46:23 +0200229 res = x509_crt_info( (char *) output, 2000, "", &crt );
Paul Bakker33b43f12013-08-20 11:48:36 +0200230
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000231 TEST_ASSERT( res != -1 );
232 TEST_ASSERT( res != -2 );
233
Paul Bakker33b43f12013-08-20 11:48:36 +0200234 TEST_ASSERT( strcmp( (char *) output, result_str ) == 0 );
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000235 }
Paul Bakkerb08e6842012-02-11 18:43:20 +0000236
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200237 x509_crt_free( &crt );
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000238}
Paul Bakker33b43f12013-08-20 11:48:36 +0200239/* END_CASE */
Paul Bakkerb2c38f52009-07-19 19:36:15 +0000240
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200241/* BEGIN_CASE depends_on:POLARSSL_X509_CRL_PARSE_C */
Paul Bakker33b43f12013-08-20 11:48:36 +0200242void x509parse_crl( char *crl_data, char *result_str, int result )
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000243{
244 x509_crl crl;
245 unsigned char buf[2000];
246 unsigned char output[2000];
247 int data_len, res;
248
Paul Bakker369d2eb2013-09-18 11:58:25 +0200249 x509_crl_init( &crl );
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000250 memset( buf, 0, 2000 );
251 memset( output, 0, 2000 );
252
Paul Bakker33b43f12013-08-20 11:48:36 +0200253 data_len = unhexify( buf, crl_data );
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000254
Paul Bakkerddf26b42013-09-18 13:46:23 +0200255 TEST_ASSERT( x509_crl_parse( &crl, buf, data_len ) == ( result ) );
Paul Bakker33b43f12013-08-20 11:48:36 +0200256 if( ( result ) == 0 )
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000257 {
Paul Bakkerddf26b42013-09-18 13:46:23 +0200258 res = x509_crl_info( (char *) output, 2000, "", &crl );
Paul Bakker33b43f12013-08-20 11:48:36 +0200259
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000260 TEST_ASSERT( res != -1 );
261 TEST_ASSERT( res != -2 );
262
Paul Bakker33b43f12013-08-20 11:48:36 +0200263 TEST_ASSERT( strcmp( (char *) output, result_str ) == 0 );
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000264 }
Paul Bakkerb08e6842012-02-11 18:43:20 +0000265
266 x509_crl_free( &crl );
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000267}
Paul Bakker33b43f12013-08-20 11:48:36 +0200268/* END_CASE */
Paul Bakker6b0fa4f2009-07-20 20:35:41 +0000269
Manuel Pégourié-Gonnardfbae2a12013-11-26 16:43:39 +0100270/* BEGIN_CASE depends_on:POLARSSL_FS_IO:POLARSSL_X509_CRT_PARSE_C */
271void x509_crt_parse_path( char *crt_path, int ret, int nb_crt )
272{
273 x509_crt chain, *cur;
274 int i;
275
276 x509_crt_init( &chain );
277
278 TEST_ASSERT( x509_crt_parse_path( &chain, crt_path ) == ret );
279
280 /* Check how many certs we got */
281 for( i = 0, cur = &chain; cur != NULL; cur = cur->next )
282 if( cur->raw.p != NULL )
283 i++;
284
285 TEST_ASSERT( i == nb_crt );
286
Paul Bakkera2ffccd2013-12-02 21:56:37 +0100287 x509_crt_free( &chain );
Manuel Pégourié-Gonnardfbae2a12013-11-26 16:43:39 +0100288}
289/* END_CASE */
290
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100291/* BEGIN_CASE */
292void x509_oid_desc( char *oid_str, char *ref_desc )
293{
294 x509_buf oid;
295 const char *desc;
296 unsigned char buf[20];
297
298 memset( buf, 0, sizeof buf );
299
300 oid.tag = ASN1_OID;
301 oid.len = unhexify( buf, oid_str );
302 oid.p = buf;
303
304 desc = x509_oid_get_description( &oid );
305
306 if( strcmp( ref_desc, "notfound" ) == 0 )
307 TEST_ASSERT( desc == NULL );
308 else
309 {
310 TEST_ASSERT( desc != NULL );
311 TEST_ASSERT( strcmp( desc, ref_desc ) == 0 );
312 }
313}
314/* END_CASE */
315
316/* BEGIN_CASE */
317void x509_oid_numstr( char *oid_str, char *numstr, int blen, int ret )
318{
319 x509_buf oid;
320 unsigned char oid_buf[20];
321 char num_buf[100];
322
323 memset( oid_buf, 0x00, sizeof oid_buf );
324 memset( num_buf, 0x2a, sizeof num_buf );
325
326 oid.tag = ASN1_OID;
327 oid.len = unhexify( oid_buf, oid_str );
328 oid.p = oid_buf;
329
330 TEST_ASSERT( (size_t) blen <= sizeof num_buf );
331
332 TEST_ASSERT( x509_oid_get_numeric_string( num_buf, blen, &oid ) == ret );
333
334 if( ret >= 0 )
335 {
336 TEST_ASSERT( num_buf[ret] == 0 );
337 TEST_ASSERT( strcmp( num_buf, numstr ) == 0 );
338 }
339}
340/* END_CASE */
341
Paul Bakker5c986f52014-04-09 16:58:51 +0200342/* BEGIN_CASE depends_on:POLARSSL_X509_CRT_PARSE_C:POLARSSL_X509_CHECK_KEY_USAGE */
Manuel Pégourié-Gonnard603116c2014-04-09 09:50:03 +0200343void x509_check_key_usage( char *crt_file, int usage, int ret )
344{
345 x509_crt crt;
346
347 x509_crt_init( &crt );
348
349 TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == 0 );
350
351 TEST_ASSERT( x509_crt_check_key_usage( &crt, usage ) == ret );
352
353 x509_crt_free( &crt );
354}
355/* END_CASE */
356
Manuel Pégourié-Gonnard7afb8a02014-04-10 17:53:56 +0200357/* BEGIN_CASE depends_on:POLARSSL_X509_CRT_PARSE_C:POLARSSL_X509_CHECK_EXTENDED_KEY_USAGE */
358void x509_check_extended_key_usage( char *crt_file, char *usage_hex, int ret )
359{
360 x509_crt crt;
361 char oid[50];
362 size_t len;
363
364 x509_crt_init( &crt );
365
366 len = unhexify( (unsigned char *) oid, usage_hex );
367
368 TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == 0 );
369
370 TEST_ASSERT( x509_crt_check_extended_key_usage( &crt, oid, len ) == ret );
371
372 x509_crt_free( &crt );
373}
374/* END_CASE */
375
Manuel Pégourié-Gonnard85403692014-06-06 14:48:38 +0200376/* BEGIN_CASE depends_on:POLARSSL_X509_CRT_PARSE_C:POLARSSL_RSASSA_PSS_CERTIFICATES */
377void x509_parse_rsassa_pss_params( char *hex_params, int params_tag,
378 int ref_msg_md, int ref_mgf_md,
379 int ref_salt_len, int ref_ret )
380{
381 int my_ret;
382 x509_buf params;
383 md_type_t my_msg_md, my_mgf_md;
384 int my_salt_len;
385
386 params.p = unhexify_alloc( hex_params, &params.len );
387 params.tag = params_tag;
388
389 my_ret = x509_get_rsassa_pss_params( &params, &my_msg_md, &my_mgf_md,
390 &my_salt_len );
391
392 if( my_ret != ref_ret ) printf( "\n%04X\n", - my_ret );
393
394 TEST_ASSERT( my_ret == ref_ret );
395
396 if( ref_ret == 0 )
397 {
398 TEST_ASSERT( my_msg_md == (md_type_t) ref_msg_md );
399 TEST_ASSERT( my_mgf_md == (md_type_t) ref_mgf_md );
400 TEST_ASSERT( my_salt_len == ref_salt_len );
401 }
402
403 polarssl_free( params.p );
404}
405/* END_CASE */
406
Manuel Pégourié-Gonnard20140162013-10-10 12:48:03 +0200407/* BEGIN_CASE depends_on:POLARSSL_X509_CRT_PARSE_C:POLARSSL_SELF_TEST */
Paul Bakker33b43f12013-08-20 11:48:36 +0200408void x509_selftest()
Paul Bakker37940d9f2009-07-10 22:38:58 +0000409{
410 TEST_ASSERT( x509_self_test( 0 ) == 0 );
411}
Paul Bakker33b43f12013-08-20 11:48:36 +0200412/* END_CASE */