1/* BEGIN_HEADER */ 2#include "mbedtls/x509.h" 3#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" 9 10const 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 23int verify_none( void *data, mbedtls_x509_crt *crt, int certificate_depth, uint32_t *flags ) 24{ 25 ((void) data); 26 ((void) crt); 27 ((void) certificate_depth); 28 *flags |= MBEDTLS_X509_BADCERT_OTHER; 29 30 return 0; 31} 32 33int verify_all( void *data, mbedtls_x509_crt *crt, int certificate_depth, uint32_t *flags ) 34{ 35 ((void) data); 36 ((void) crt); 37 ((void) certificate_depth); 38 *flags = 0; 39 40 return 0; 41} 42 43/* 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 73#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 */ 113/* END_HEADER */ 114 115/* BEGIN_DEPENDENCIES 116 * depends_on:MBEDTLS_BIGNUM_C 117 * END_DEPENDENCIES 118 */ 119 120/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */ 121void x509_cert_info( char *crt_file, char *result_str ) 122{ 123 mbedtls_x509_crt crt; 124 char buf[2000]; 125 int res; 126 127 mbedtls_x509_crt_init( &crt ); 128 memset( buf, 0, 2000 ); 129 130 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 ); 131 res = mbedtls_x509_crt_info( buf, 2000, "", &crt ); 132 133 TEST_ASSERT( res != -1 ); 134 TEST_ASSERT( res != -2 ); 135 136 TEST_ASSERT( strcmp( buf, result_str ) == 0 ); 137 138exit: 139 mbedtls_x509_crt_free( &crt ); 140} 141/* END_CASE */ 142 143/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRL_PARSE_C */ 144void mbedtls_x509_crl_info( char *crl_file, char *result_str ) 145{ 146 mbedtls_x509_crl crl; 147 char buf[2000]; 148 int res; 149 150 mbedtls_x509_crl_init( &crl ); 151 memset( buf, 0, 2000 ); 152 153 TEST_ASSERT( mbedtls_x509_crl_parse_file( &crl, crl_file ) == 0 ); 154 res = mbedtls_x509_crl_info( buf, 2000, "", &crl ); 155 156 TEST_ASSERT( res != -1 ); 157 TEST_ASSERT( res != -2 ); 158 159 TEST_ASSERT( strcmp( buf, result_str ) == 0 ); 160 161exit: 162 mbedtls_x509_crl_free( &crl ); 163} 164/* END_CASE */ 165 166/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CSR_PARSE_C */ 167void mbedtls_x509_csr_info( char *csr_file, char *result_str ) 168{ 169 mbedtls_x509_csr csr; 170 char buf[2000]; 171 int res; 172 173 mbedtls_x509_csr_init( &csr ); 174 memset( buf, 0, 2000 ); 175 176 TEST_ASSERT( mbedtls_x509_csr_parse_file( &csr, csr_file ) == 0 ); 177 res = mbedtls_x509_csr_info( buf, 2000, "", &csr ); 178 179 TEST_ASSERT( res != -1 ); 180 TEST_ASSERT( res != -2 ); 181 182 TEST_ASSERT( strcmp( buf, result_str ) == 0 ); 183 184exit: 185 mbedtls_x509_csr_free( &csr ); 186} 187/* END_CASE */ 188 189/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */ 190void x509_verify_info( int flags, char *prefix, char *result_str ) 191{ 192 char buf[2000]; 193 int res; 194 195 memset( buf, 0, sizeof( buf ) ); 196 197 res = mbedtls_x509_crt_verify_info( buf, sizeof( buf ), prefix, flags ); 198 199 TEST_ASSERT( res >= 0 ); 200 201 TEST_ASSERT( strcmp( buf, result_str ) == 0 ); 202} 203/* END_CASE */ 204 205/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_CRL_PARSE_C */ 206void x509_verify( char *crt_file, char *ca_file, char *crl_file, 207 char *cn_name_str, int result, int flags_result, 208 char *verify_callback ) 209{ 210 mbedtls_x509_crt crt; 211 mbedtls_x509_crt ca; 212 mbedtls_x509_crl crl; 213 uint32_t flags = 0; 214 int res; 215 int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *) = NULL; 216 char * cn_name = NULL; 217 218 mbedtls_x509_crt_init( &crt ); 219 mbedtls_x509_crt_init( &ca ); 220 mbedtls_x509_crl_init( &crl ); 221 222 if( strcmp( cn_name_str, "NULL" ) != 0 ) 223 cn_name = cn_name_str; 224 225 if( strcmp( verify_callback, "NULL" ) == 0 ) 226 f_vrfy = NULL; 227 else if( strcmp( verify_callback, "verify_none" ) == 0 ) 228 f_vrfy = verify_none; 229 else if( strcmp( verify_callback, "verify_all" ) == 0 ) 230 f_vrfy = verify_all; 231 else 232 TEST_ASSERT( "No known verify callback selected" == 0 ); 233 234 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 ); 235 TEST_ASSERT( mbedtls_x509_crt_parse_file( &ca, ca_file ) == 0 ); 236 TEST_ASSERT( mbedtls_x509_crl_parse_file( &crl, crl_file ) == 0 ); 237 238 res = mbedtls_x509_crt_verify_with_profile( &crt, &ca, &crl, &compat_profile, cn_name, &flags, f_vrfy, NULL ); 239 240 TEST_ASSERT( res == ( result ) ); 241 TEST_ASSERT( flags == (uint32_t)( flags_result ) ); 242 243exit: 244 mbedtls_x509_crt_free( &crt ); 245 mbedtls_x509_crt_free( &ca ); 246 mbedtls_x509_crl_free( &crl ); 247} 248/* END_CASE */ 249 250/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */ 251void x509_verify_callback( char *crt_file, char *ca_file, 252 int exp_ret, char *exp_vrfy_out ) 253{ 254 int ret; 255 mbedtls_x509_crt crt; 256 mbedtls_x509_crt ca; 257 uint32_t flags = 0; 258 verify_print_context vrfy_ctx; 259 260 mbedtls_x509_crt_init( &crt ); 261 mbedtls_x509_crt_init( &ca ); 262 verify_print_init( &vrfy_ctx ); 263 264 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 ); 265 TEST_ASSERT( mbedtls_x509_crt_parse_file( &ca, ca_file ) == 0 ); 266 267 ret = mbedtls_x509_crt_verify( &crt, &ca, NULL, NULL, &flags, 268 verify_print, &vrfy_ctx ); 269 270 TEST_ASSERT( ret == exp_ret ); 271 TEST_ASSERT( strcmp( vrfy_ctx.buf, exp_vrfy_out ) == 0 ); 272 273exit: 274 mbedtls_x509_crt_free( &crt ); 275 mbedtls_x509_crt_free( &ca ); 276} 277/* END_CASE */ 278 279/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */ 280void mbedtls_x509_dn_gets( char *crt_file, char *entity, char *result_str ) 281{ 282 mbedtls_x509_crt crt; 283 char buf[2000]; 284 int res = 0; 285 286 mbedtls_x509_crt_init( &crt ); 287 memset( buf, 0, 2000 ); 288 289 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 ); 290 if( strcmp( entity, "subject" ) == 0 ) 291 res = mbedtls_x509_dn_gets( buf, 2000, &crt.subject ); 292 else if( strcmp( entity, "issuer" ) == 0 ) 293 res = mbedtls_x509_dn_gets( buf, 2000, &crt.issuer ); 294 else 295 TEST_ASSERT( "Unknown entity" == 0 ); 296 297 TEST_ASSERT( res != -1 ); 298 TEST_ASSERT( res != -2 ); 299 300 TEST_ASSERT( strcmp( buf, result_str ) == 0 ); 301 302exit: 303 mbedtls_x509_crt_free( &crt ); 304} 305/* END_CASE */ 306 307/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */ 308void mbedtls_x509_time_is_past( char *crt_file, char *entity, int result ) 309{ 310 mbedtls_x509_crt crt; 311 312 mbedtls_x509_crt_init( &crt ); 313 314 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 ); 315 316 if( strcmp( entity, "valid_from" ) == 0 ) 317 TEST_ASSERT( mbedtls_x509_time_is_past( &crt.valid_from ) == result ); 318 else if( strcmp( entity, "valid_to" ) == 0 ) 319 TEST_ASSERT( mbedtls_x509_time_is_past( &crt.valid_to ) == result ); 320 else 321 TEST_ASSERT( "Unknown entity" == 0 ); 322 323exit: 324 mbedtls_x509_crt_free( &crt ); 325} 326/* END_CASE */ 327 328/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */ 329void mbedtls_x509_time_is_future( char *crt_file, char *entity, int result ) 330{ 331 mbedtls_x509_crt crt; 332 333 mbedtls_x509_crt_init( &crt ); 334 335 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 ); 336 337 if( strcmp( entity, "valid_from" ) == 0 ) 338 TEST_ASSERT( mbedtls_x509_time_is_future( &crt.valid_from ) == result ); 339 else if( strcmp( entity, "valid_to" ) == 0 ) 340 TEST_ASSERT( mbedtls_x509_time_is_future( &crt.valid_to ) == result ); 341 else 342 TEST_ASSERT( "Unknown entity" == 0 ); 343 344exit: 345 mbedtls_x509_crt_free( &crt ); 346} 347/* END_CASE */ 348 349/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_FS_IO */ 350void x509parse_crt_file( char *crt_file, int result ) 351{ 352 mbedtls_x509_crt crt; 353 354 mbedtls_x509_crt_init( &crt ); 355 356 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == result ); 357 358exit: 359 mbedtls_x509_crt_free( &crt ); 360} 361/* END_CASE */ 362 363/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */ 364void x509parse_crt( char *crt_data, char *result_str, int result ) 365{ 366 mbedtls_x509_crt crt; 367 unsigned char buf[2000]; 368 unsigned char output[2000]; 369 int data_len, res; 370 371 mbedtls_x509_crt_init( &crt ); 372 memset( buf, 0, 2000 ); 373 memset( output, 0, 2000 ); 374 375 data_len = unhexify( buf, crt_data ); 376 377 TEST_ASSERT( mbedtls_x509_crt_parse( &crt, buf, data_len ) == ( result ) ); 378 if( ( result ) == 0 ) 379 { 380 res = mbedtls_x509_crt_info( (char *) output, 2000, "", &crt ); 381 382 TEST_ASSERT( res != -1 ); 383 TEST_ASSERT( res != -2 ); 384 385 TEST_ASSERT( strcmp( (char *) output, result_str ) == 0 ); 386 } 387 388exit: 389 mbedtls_x509_crt_free( &crt ); 390} 391/* END_CASE */ 392 393/* BEGIN_CASE depends_on:MBEDTLS_X509_CRL_PARSE_C */ 394void x509parse_crl( char *crl_data, char *result_str, int result ) 395{ 396 mbedtls_x509_crl crl; 397 unsigned char buf[2000]; 398 unsigned char output[2000]; 399 int data_len, res; 400 401 mbedtls_x509_crl_init( &crl ); 402 memset( buf, 0, 2000 ); 403 memset( output, 0, 2000 ); 404 405 data_len = unhexify( buf, crl_data ); 406 407 TEST_ASSERT( mbedtls_x509_crl_parse( &crl, buf, data_len ) == ( result ) ); 408 if( ( result ) == 0 ) 409 { 410 res = mbedtls_x509_crl_info( (char *) output, 2000, "", &crl ); 411 412 TEST_ASSERT( res != -1 ); 413 TEST_ASSERT( res != -2 ); 414 415 TEST_ASSERT( strcmp( (char *) output, result_str ) == 0 ); 416 } 417 418exit: 419 mbedtls_x509_crl_free( &crl ); 420} 421/* END_CASE */ 422 423/* BEGIN_CASE depends_on:MBEDTLS_X509_CSR_PARSE_C */ 424void mbedtls_x509_csr_parse( char *csr_der_hex, char *ref_out, int ref_ret ) 425{ 426 mbedtls_x509_csr csr; 427 unsigned char *csr_der = NULL; 428 char my_out[1000]; 429 size_t csr_der_len; 430 int my_ret; 431 432 mbedtls_x509_csr_init( &csr ); 433 memset( my_out, 0, sizeof( my_out ) ); 434 csr_der = unhexify_alloc( csr_der_hex, &csr_der_len ); 435 436 my_ret = mbedtls_x509_csr_parse_der( &csr, csr_der, csr_der_len ); 437 TEST_ASSERT( my_ret == ref_ret ); 438 439 if( ref_ret == 0 ) 440 { 441 size_t my_out_len = mbedtls_x509_csr_info( my_out, sizeof( my_out ), "", &csr ); 442 TEST_ASSERT( my_out_len == strlen( ref_out ) ); 443 TEST_ASSERT( strcmp( my_out, ref_out ) == 0 ); 444 } 445 446exit: 447 mbedtls_x509_csr_free( &csr ); 448 mbedtls_free( csr_der ); 449} 450/* END_CASE */ 451 452/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */ 453void mbedtls_x509_crt_parse_path( char *crt_path, int ret, int nb_crt ) 454{ 455 mbedtls_x509_crt chain, *cur; 456 int i; 457 458 mbedtls_x509_crt_init( &chain ); 459 460 TEST_ASSERT( mbedtls_x509_crt_parse_path( &chain, crt_path ) == ret ); 461 462 /* Check how many certs we got */ 463 for( i = 0, cur = &chain; cur != NULL; cur = cur->next ) 464 if( cur->raw.p != NULL ) 465 i++; 466 467 TEST_ASSERT( i == nb_crt ); 468 469exit: 470 mbedtls_x509_crt_free( &chain ); 471} 472/* END_CASE */ 473 474/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */ 475void mbedtls_x509_crt_verify_chain( char *chain_paths, char *trusted_ca, int flags_result ) 476{ 477 char* act; 478 uint32_t flags; 479 int result, res; 480 mbedtls_x509_crt trusted, chain; 481 482 result= flags_result?MBEDTLS_ERR_X509_CERT_VERIFY_FAILED:0; 483 484 mbedtls_x509_crt_init( &chain ); 485 mbedtls_x509_crt_init( &trusted ); 486 487 while( ( act = mystrsep( &chain_paths, " " ) ) != NULL ) 488 TEST_ASSERT( mbedtls_x509_crt_parse_file( &chain, act ) == 0 ); 489 TEST_ASSERT( mbedtls_x509_crt_parse_file( &trusted, trusted_ca ) == 0 ); 490 491 res = mbedtls_x509_crt_verify( &chain, &trusted, NULL, NULL, &flags, NULL, NULL ); 492 493 TEST_ASSERT( res == ( result ) ); 494 TEST_ASSERT( flags == (uint32_t)( flags_result ) ); 495 496exit: 497 mbedtls_x509_crt_free( &trusted ); 498 mbedtls_x509_crt_free( &chain ); 499} 500/* END_CASE */ 501 502/* BEGIN_CASE depends_on:MBEDTLS_X509_USE_C */ 503void x509_oid_desc( char *oid_str, char *ref_desc ) 504{ 505 mbedtls_x509_buf oid; 506 const char *desc = NULL; 507 unsigned char buf[20]; 508 int ret; 509 510 memset( buf, 0, sizeof buf ); 511 512 oid.tag = MBEDTLS_ASN1_OID; 513 oid.len = unhexify( buf, oid_str ); 514 oid.p = buf; 515 516 ret = mbedtls_oid_get_extended_key_usage( &oid, &desc ); 517 518 if( strcmp( ref_desc, "notfound" ) == 0 ) 519 { 520 TEST_ASSERT( ret != 0 ); 521 TEST_ASSERT( desc == NULL ); 522 } 523 else 524 { 525 TEST_ASSERT( ret == 0 ); 526 TEST_ASSERT( desc != NULL ); 527 TEST_ASSERT( strcmp( desc, ref_desc ) == 0 ); 528 } 529} 530/* END_CASE */ 531 532/* BEGIN_CASE depends_on:MBEDTLS_X509_USE_C */ 533void x509_oid_numstr( char *oid_str, char *numstr, int blen, int ret ) 534{ 535 mbedtls_x509_buf oid; 536 unsigned char oid_buf[20]; 537 char num_buf[100]; 538 539 memset( oid_buf, 0x00, sizeof oid_buf ); 540 memset( num_buf, 0x2a, sizeof num_buf ); 541 542 oid.tag = MBEDTLS_ASN1_OID; 543 oid.len = unhexify( oid_buf, oid_str ); 544 oid.p = oid_buf; 545 546 TEST_ASSERT( (size_t) blen <= sizeof num_buf ); 547 548 TEST_ASSERT( mbedtls_oid_get_numeric_string( num_buf, blen, &oid ) == ret ); 549 550 if( ret >= 0 ) 551 { 552 TEST_ASSERT( num_buf[ret] == 0 ); 553 TEST_ASSERT( strcmp( num_buf, numstr ) == 0 ); 554 } 555} 556/* END_CASE */ 557 558/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_CHECK_KEY_USAGE */ 559void x509_check_key_usage( char *crt_file, int usage, int ret ) 560{ 561 mbedtls_x509_crt crt; 562 563 mbedtls_x509_crt_init( &crt ); 564 565 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 ); 566 567 TEST_ASSERT( mbedtls_x509_crt_check_key_usage( &crt, usage ) == ret ); 568 569exit: 570 mbedtls_x509_crt_free( &crt ); 571} 572/* END_CASE */ 573 574/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE */ 575void x509_check_extended_key_usage( char *crt_file, char *usage_hex, int ret ) 576{ 577 mbedtls_x509_crt crt; 578 char oid[50]; 579 size_t len; 580 581 mbedtls_x509_crt_init( &crt ); 582 583 len = unhexify( (unsigned char *) oid, usage_hex ); 584 585 TEST_ASSERT( mbedtls_x509_crt_parse_file( &crt, crt_file ) == 0 ); 586 587 TEST_ASSERT( mbedtls_x509_crt_check_extended_key_usage( &crt, oid, len ) == ret ); 588 589exit: 590 mbedtls_x509_crt_free( &crt ); 591} 592/* END_CASE */ 593 594/* BEGIN_CASE depends_on:MBEDTLS_X509_USE_C */ 595void x509_get_time( int tag, char *time_str, int ret, 596 int year, int mon, int day, 597 int hour, int min, int sec ) 598{ 599 mbedtls_x509_time time; 600 unsigned char buf[17]; 601 unsigned char* start = buf; 602 unsigned char* end = buf; 603 604 memset( &time, 0x00, sizeof( time ) ); 605 *end = (unsigned char)tag; end++; 606 if( tag == MBEDTLS_ASN1_UTC_TIME ) 607 *end = 13; 608 else 609 *end = 15; 610 end++; 611 memcpy( end, time_str, (size_t)*(end - 1) ); 612 end += *(end - 1); 613 614 TEST_ASSERT( mbedtls_x509_get_time( &start, end, &time ) == ret ); 615 if( ret == 0 ) 616 { 617 TEST_ASSERT( year == time.year ); 618 TEST_ASSERT( mon == time.mon ); 619 TEST_ASSERT( day == time.day ); 620 TEST_ASSERT( hour == time.hour ); 621 TEST_ASSERT( min == time.min ); 622 TEST_ASSERT( sec == time.sec ); 623 } 624} 625/* END_CASE */ 626 627/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_RSASSA_PSS_SUPPORT */ 628void x509_parse_rsassa_pss_params( char *hex_params, int params_tag, 629 int ref_msg_md, int ref_mgf_md, 630 int ref_salt_len, int ref_ret ) 631{ 632 int my_ret; 633 mbedtls_x509_buf params; 634 mbedtls_md_type_t my_msg_md, my_mgf_md; 635 int my_salt_len; 636 637 params.p = unhexify_alloc( hex_params, ¶ms.len ); 638 params.tag = params_tag; 639 640 my_ret = mbedtls_x509_get_rsassa_pss_params( ¶ms, &my_msg_md, &my_mgf_md, 641 &my_salt_len ); 642 643 TEST_ASSERT( my_ret == ref_ret ); 644 645 if( ref_ret == 0 ) 646 { 647 TEST_ASSERT( my_msg_md == (mbedtls_md_type_t) ref_msg_md ); 648 TEST_ASSERT( my_mgf_md == (mbedtls_md_type_t) ref_mgf_md ); 649 TEST_ASSERT( my_salt_len == ref_salt_len ); 650 } 651 652exit: 653 mbedtls_free( params.p ); 654} 655/* END_CASE */ 656 657/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_SELF_TEST */ 658void x509_selftest() 659{ 660 TEST_ASSERT( mbedtls_x509_self_test( 1 ) == 0 ); 661} 662/* END_CASE */ 663