PolarSSL v1.3.8
test_suite_x509parse.c
Go to the documentation of this file.
1 #if !defined(POLARSSL_CONFIG_FILE)
2 #include <polarssl/config.h>
3 #else
4 #include POLARSSL_CONFIG_FILE
5 #endif
6 
7 #ifdef POLARSSL_BIGNUM_C
8 
9 #include <polarssl/x509_crt.h>
10 #include <polarssl/x509_crl.h>
11 #include <polarssl/x509_csr.h>
12 #include <polarssl/pem.h>
13 #include <polarssl/oid.h>
14 
15 int verify_none( void *data, x509_crt *crt, int certificate_depth, int *flags )
16 {
17  ((void) data);
18  ((void) crt);
19  ((void) certificate_depth);
20  *flags |= BADCERT_OTHER;
21 
22  return 0;
23 }
24 
25 int verify_all( void *data, x509_crt *crt, int certificate_depth, int *flags )
26 {
27  ((void) data);
28  ((void) crt);
29  ((void) certificate_depth);
30  *flags = 0;
31 
32  return 0;
33 }
34 
35 #endif /* POLARSSL_BIGNUM_C */
36 
37 
38 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
39 #include "polarssl/memory.h"
40 #endif
41 
42 #if defined(POLARSSL_PLATFORM_C)
43 #include "polarssl/platform.h"
44 #else
45 #define polarssl_malloc malloc
46 #define polarssl_free free
47 #endif
48 
49 #ifdef _MSC_VER
50 #include <basetsd.h>
51 typedef UINT32 uint32_t;
52 #else
53 #include <inttypes.h>
54 #endif
55 
56 #include <assert.h>
57 #include <stdlib.h>
58 #include <string.h>
59 
60 /*
61  * 32-bit integer manipulation macros (big endian)
62  */
63 #ifndef GET_UINT32_BE
64 #define GET_UINT32_BE(n,b,i) \
65 { \
66  (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
67  | ( (uint32_t) (b)[(i) + 1] << 16 ) \
68  | ( (uint32_t) (b)[(i) + 2] << 8 ) \
69  | ( (uint32_t) (b)[(i) + 3] ); \
70 }
71 #endif
72 
73 #ifndef PUT_UINT32_BE
74 #define PUT_UINT32_BE(n,b,i) \
75 { \
76  (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
77  (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
78  (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
79  (b)[(i) + 3] = (unsigned char) ( (n) ); \
80 }
81 #endif
82 
83 static int unhexify(unsigned char *obuf, const char *ibuf)
84 {
85  unsigned char c, c2;
86  int len = strlen(ibuf) / 2;
87  assert(!(strlen(ibuf) %1)); // must be even number of bytes
88 
89  while (*ibuf != 0)
90  {
91  c = *ibuf++;
92  if( c >= '0' && c <= '9' )
93  c -= '0';
94  else if( c >= 'a' && c <= 'f' )
95  c -= 'a' - 10;
96  else if( c >= 'A' && c <= 'F' )
97  c -= 'A' - 10;
98  else
99  assert( 0 );
100 
101  c2 = *ibuf++;
102  if( c2 >= '0' && c2 <= '9' )
103  c2 -= '0';
104  else if( c2 >= 'a' && c2 <= 'f' )
105  c2 -= 'a' - 10;
106  else if( c2 >= 'A' && c2 <= 'F' )
107  c2 -= 'A' - 10;
108  else
109  assert( 0 );
110 
111  *obuf++ = ( c << 4 ) | c2;
112  }
113 
114  return len;
115 }
116 
117 static void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
118 {
119  unsigned char l, h;
120 
121  while (len != 0)
122  {
123  h = (*ibuf) / 16;
124  l = (*ibuf) % 16;
125 
126  if( h < 10 )
127  *obuf++ = '0' + h;
128  else
129  *obuf++ = 'a' + h - 10;
130 
131  if( l < 10 )
132  *obuf++ = '0' + l;
133  else
134  *obuf++ = 'a' + l - 10;
135 
136  ++ibuf;
137  len--;
138  }
139 }
140 
148 static unsigned char *zero_alloc( size_t len )
149 {
150  void *p;
151  size_t actual_len = len != 0 ? len : 1;
152 
153  p = polarssl_malloc( actual_len );
154  assert( p != NULL );
155 
156  memset( p, 0x00, actual_len );
157 
158  return( p );
159 }
160 
171 static unsigned char *unhexify_alloc( const char *ibuf, size_t *olen )
172 {
173  unsigned char *obuf;
174 
175  *olen = strlen(ibuf) / 2;
176 
177  if( *olen == 0 )
178  return( zero_alloc( *olen ) );
179 
180  obuf = polarssl_malloc( *olen );
181  assert( obuf != NULL );
182 
183  (void) unhexify( obuf, ibuf );
184 
185  return( obuf );
186 }
187 
197 static int rnd_std_rand( void *rng_state, unsigned char *output, size_t len )
198 {
199 #if !defined(__OpenBSD__)
200  size_t i;
201 
202  if( rng_state != NULL )
203  rng_state = NULL;
204 
205  for( i = 0; i < len; ++i )
206  output[i] = rand();
207 #else
208  if( rng_state != NULL )
209  rng_state = NULL;
210 
211  arc4random_buf( output, len );
212 #endif /* !OpenBSD */
213 
214  return( 0 );
215 }
216 
222 static int rnd_zero_rand( void *rng_state, unsigned char *output, size_t len )
223 {
224  if( rng_state != NULL )
225  rng_state = NULL;
226 
227  memset( output, 0, len );
228 
229  return( 0 );
230 }
231 
232 typedef struct
233 {
234  unsigned char *buf;
235  size_t length;
236 } rnd_buf_info;
237 
249 static int rnd_buffer_rand( void *rng_state, unsigned char *output, size_t len )
250 {
251  rnd_buf_info *info = (rnd_buf_info *) rng_state;
252  size_t use_len;
253 
254  if( rng_state == NULL )
255  return( rnd_std_rand( NULL, output, len ) );
256 
257  use_len = len;
258  if( len > info->length )
259  use_len = info->length;
260 
261  if( use_len )
262  {
263  memcpy( output, info->buf, use_len );
264  info->buf += use_len;
265  info->length -= use_len;
266  }
267 
268  if( len - use_len > 0 )
269  return( rnd_std_rand( NULL, output + use_len, len - use_len ) );
270 
271  return( 0 );
272 }
273 
281 typedef struct
282 {
283  uint32_t key[16];
284  uint32_t v0, v1;
286 
295 static int rnd_pseudo_rand( void *rng_state, unsigned char *output, size_t len )
296 {
297  rnd_pseudo_info *info = (rnd_pseudo_info *) rng_state;
298  uint32_t i, *k, sum, delta=0x9E3779B9;
299  unsigned char result[4], *out = output;
300 
301  if( rng_state == NULL )
302  return( rnd_std_rand( NULL, output, len ) );
303 
304  k = info->key;
305 
306  while( len > 0 )
307  {
308  size_t use_len = ( len > 4 ) ? 4 : len;
309  sum = 0;
310 
311  for( i = 0; i < 32; i++ )
312  {
313  info->v0 += (((info->v1 << 4) ^ (info->v1 >> 5)) + info->v1) ^ (sum + k[sum & 3]);
314  sum += delta;
315  info->v1 += (((info->v0 << 4) ^ (info->v0 >> 5)) + info->v0) ^ (sum + k[(sum>>11) & 3]);
316  }
317 
318  PUT_UINT32_BE( info->v0, result, 0 );
319  memcpy( out, result, use_len );
320  len -= use_len;
321  out += 4;
322  }
323 
324  return( 0 );
325 }
326 
327 
328 #include <stdio.h>
329 #include <string.h>
330 
331 #if defined(POLARSSL_PLATFORM_C)
332 #include "polarssl/platform.h"
333 #else
334 #define polarssl_printf printf
335 #define polarssl_malloc malloc
336 #define polarssl_free free
337 #endif
338 
339 static int test_errors = 0;
340 
341 #ifdef POLARSSL_BIGNUM_C
342 
343 #define TEST_SUITE_ACTIVE
344 
345 static int test_assert( int correct, const char *test )
346 {
347  if( correct )
348  return( 0 );
349 
350  test_errors++;
351  if( test_errors == 1 )
352  printf( "FAILED\n" );
353  printf( " %s\n", test );
354 
355  return( 1 );
356 }
357 
358 #define TEST_ASSERT( TEST ) \
359  do { test_assert( (TEST) ? 1 : 0, #TEST ); \
360  if( test_errors) goto exit; \
361  } while (0)
362 
363 int verify_string( char **str )
364 {
365  if( (*str)[0] != '"' ||
366  (*str)[strlen( *str ) - 1] != '"' )
367  {
368  printf( "Expected string (with \"\") for parameter and got: %s\n", *str );
369  return( -1 );
370  }
371 
372  (*str)++;
373  (*str)[strlen( *str ) - 1] = '\0';
374 
375  return( 0 );
376 }
377 
378 int verify_int( char *str, int *value )
379 {
380  size_t i;
381  int minus = 0;
382  int digits = 1;
383  int hex = 0;
384 
385  for( i = 0; i < strlen( str ); i++ )
386  {
387  if( i == 0 && str[i] == '-' )
388  {
389  minus = 1;
390  continue;
391  }
392 
393  if( ( ( minus && i == 2 ) || ( !minus && i == 1 ) ) &&
394  str[i - 1] == '0' && str[i] == 'x' )
395  {
396  hex = 1;
397  continue;
398  }
399 
400  if( ! ( ( str[i] >= '0' && str[i] <= '9' ) ||
401  ( hex && ( ( str[i] >= 'a' && str[i] <= 'f' ) ||
402  ( str[i] >= 'A' && str[i] <= 'F' ) ) ) ) )
403  {
404  digits = 0;
405  break;
406  }
407  }
408 
409  if( digits )
410  {
411  if( hex )
412  *value = strtol( str, NULL, 16 );
413  else
414  *value = strtol( str, NULL, 10 );
415 
416  return( 0 );
417  }
418 
419 #ifdef POLARSSL_X509_CRT_PARSE_C
420  if( strcmp( str, "POLARSSL_ERR_X509_SIG_MISMATCH" ) == 0 )
421  {
422  *value = ( POLARSSL_ERR_X509_SIG_MISMATCH );
423  return( 0 );
424  }
425 #endif // POLARSSL_X509_CRT_PARSE_C
426 #ifdef POLARSSL_X509_CRL_PARSE_C
427  if( strcmp( str, "POLARSSL_ERR_X509_SIG_MISMATCH" ) == 0 )
428  {
429  *value = ( POLARSSL_ERR_X509_SIG_MISMATCH );
430  return( 0 );
431  }
432 #endif // POLARSSL_X509_CRL_PARSE_C
433 #ifdef POLARSSL_X509_CRT_PARSE_C
434  if( strcmp( str, "POLARSSL_ERR_X509_UNKNOWN_SIG_ALG + POLARSSL_ERR_OID_NOT_FOUND" ) == 0 )
435  {
437  return( 0 );
438  }
439 #endif // POLARSSL_X509_CRT_PARSE_C
440 #ifdef POLARSSL_FS_IO
441 #ifdef POLARSSL_X509_CRT_PARSE_C
442 #ifdef POLARSSL_X509_CRL_PARSE_C
443  if( strcmp( str, "BADCERT_EXPIRED" ) == 0 )
444  {
445  *value = ( BADCERT_EXPIRED );
446  return( 0 );
447  }
448 #endif // POLARSSL_FS_IO
449 #endif // POLARSSL_X509_CRT_PARSE_C
450 #endif // POLARSSL_X509_CRL_PARSE_C
451 #ifdef POLARSSL_X509_CRT_PARSE_C
452  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_EXTENSIONS + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
453  {
455  return( 0 );
456  }
457 #endif // POLARSSL_X509_CRT_PARSE_C
458 #ifdef POLARSSL_FS_IO
459 #ifdef POLARSSL_X509_CRT_PARSE_C
460 #ifdef POLARSSL_X509_CRL_PARSE_C
461  if( strcmp( str, "BADCERT_NOT_TRUSTED" ) == 0 )
462  {
463  *value = ( BADCERT_NOT_TRUSTED );
464  return( 0 );
465  }
466 #endif // POLARSSL_FS_IO
467 #endif // POLARSSL_X509_CRT_PARSE_C
468 #endif // POLARSSL_X509_CRL_PARSE_C
469 #ifdef POLARSSL_X509_CRT_PARSE_C
470  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_SERIAL + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
471  {
473  return( 0 );
474  }
475 #endif // POLARSSL_X509_CRT_PARSE_C
476 #ifdef POLARSSL_FS_IO
477 #ifdef POLARSSL_X509_CRT_PARSE_C
478 #ifdef POLARSSL_X509_CRL_PARSE_C
479  if( strcmp( str, "BADCERT_REVOKED | BADCRL_FUTURE" ) == 0 )
480  {
481  *value = ( BADCERT_REVOKED | BADCRL_FUTURE );
482  return( 0 );
483  }
484 #endif // POLARSSL_FS_IO
485 #endif // POLARSSL_X509_CRT_PARSE_C
486 #endif // POLARSSL_X509_CRL_PARSE_C
487 #ifdef POLARSSL_FS_IO
488 #ifdef POLARSSL_X509_CRT_PARSE_C
489 #ifdef POLARSSL_X509_CRL_PARSE_C
490  if( strcmp( str, "POLARSSL_ERR_X509_CERT_VERIFY_FAILED" ) == 0 )
491  {
493  return( 0 );
494  }
495 #endif // POLARSSL_FS_IO
496 #endif // POLARSSL_X509_CRT_PARSE_C
497 #endif // POLARSSL_X509_CRL_PARSE_C
498 #ifdef POLARSSL_X509_CRT_PARSE_C
499  if( strcmp( str, "POLARSSL_ERR_PK_UNKNOWN_PK_ALG" ) == 0 )
500  {
501  *value = ( POLARSSL_ERR_PK_UNKNOWN_PK_ALG );
502  return( 0 );
503  }
504 #endif // POLARSSL_X509_CRT_PARSE_C
505 #ifdef POLARSSL_X509_CRT_PARSE_C
506  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_INVALID_LENGTH" ) == 0 )
507  {
509  return( 0 );
510  }
511 #endif // POLARSSL_X509_CRT_PARSE_C
512 #ifdef POLARSSL_X509_CSR_PARSE_C
513  if( strcmp( str, " 1" ) == 0 )
514  {
515  *value = ( 1 );
516  return( 0 );
517  }
518 #endif // POLARSSL_X509_CSR_PARSE_C
519 #ifdef POLARSSL_X509_CRT_PARSE_C
520  if( strcmp( str, " 1" ) == 0 )
521  {
522  *value = ( 1 );
523  return( 0 );
524  }
525 #endif // POLARSSL_X509_CRT_PARSE_C
526 #ifdef POLARSSL_X509_CRL_PARSE_C
527  if( strcmp( str, " 1" ) == 0 )
528  {
529  *value = ( 1 );
530  return( 0 );
531  }
532 #endif // POLARSSL_X509_CRL_PARSE_C
533 #ifdef POLARSSL_FS_IO
534 #ifdef POLARSSL_X509_CRT_PARSE_C
535 #ifdef POLARSSL_X509_CRL_PARSE_C
536  if( strcmp( str, "BADCERT_FUTURE" ) == 0 )
537  {
538  *value = ( BADCERT_FUTURE );
539  return( 0 );
540  }
541 #endif // POLARSSL_FS_IO
542 #endif // POLARSSL_X509_CRT_PARSE_C
543 #endif // POLARSSL_X509_CRL_PARSE_C
544 #ifdef POLARSSL_X509_CRL_PARSE_C
545  if( strcmp( str, "POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
546  {
547  *value = ( POLARSSL_ERR_ASN1_OUT_OF_DATA );
548  return( 0 );
549  }
550 #endif // POLARSSL_X509_CRL_PARSE_C
551 #ifdef POLARSSL_X509_CRT_PARSE_C
552 #ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
553  if( strcmp( str, "POLARSSL_ERR_X509_FEATURE_UNAVAILABLE + POLARSSL_ERR_OID_NOT_FOUND" ) == 0 )
554  {
556  return( 0 );
557  }
558 #endif // POLARSSL_X509_CRT_PARSE_C
559 #endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
560 #ifdef POLARSSL_FS_IO
561 #ifdef POLARSSL_X509_CRT_PARSE_C
562 #ifdef POLARSSL_X509_CHECK_KEY_USAGE
563  if( strcmp( str, "KU_KEY_CERT_SIGN|KU_CRL_SIGN" ) == 0 )
564  {
565  *value = ( KU_KEY_CERT_SIGN|KU_CRL_SIGN );
566  return( 0 );
567  }
568 #endif // POLARSSL_FS_IO
569 #endif // POLARSSL_X509_CRT_PARSE_C
570 #endif // POLARSSL_X509_CHECK_KEY_USAGE
571 #ifdef POLARSSL_X509_CRT_PARSE_C
572  if( strcmp( str, "POLARSSL_ERR_ASN1_INVALID_LENGTH" ) == 0 )
573  {
575  return( 0 );
576  }
577 #endif // POLARSSL_X509_CRT_PARSE_C
578 #ifdef POLARSSL_X509_CSR_PARSE_C
579  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
580  {
582  return( 0 );
583  }
584 #endif // POLARSSL_X509_CSR_PARSE_C
585 #ifdef POLARSSL_X509_CRT_PARSE_C
586  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
587  {
589  return( 0 );
590  }
591 #endif // POLARSSL_X509_CRT_PARSE_C
592 #ifdef POLARSSL_X509_CRL_PARSE_C
593  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
594  {
596  return( 0 );
597  }
598 #endif // POLARSSL_X509_CRL_PARSE_C
599 #ifdef POLARSSL_X509_CSR_PARSE_C
600  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_SIGNATURE + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
601  {
603  return( 0 );
604  }
605 #endif // POLARSSL_X509_CSR_PARSE_C
606 #ifdef POLARSSL_X509_CRT_PARSE_C
607  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_SIGNATURE + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
608  {
610  return( 0 );
611  }
612 #endif // POLARSSL_X509_CRT_PARSE_C
613 #ifdef POLARSSL_X509_CRT_PARSE_C
614  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_EXTENSIONS + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
615  {
617  return( 0 );
618  }
619 #endif // POLARSSL_X509_CRT_PARSE_C
620 #ifdef POLARSSL_FS_IO
621 #ifdef POLARSSL_X509_CRT_PARSE_C
622 #ifdef POLARSSL_X509_CRL_PARSE_C
623  if( strcmp( str, "BADCERT_REVOKED | BADCERT_CN_MISMATCH" ) == 0 )
624  {
625  *value = ( BADCERT_REVOKED | BADCERT_CN_MISMATCH );
626  return( 0 );
627  }
628 #endif // POLARSSL_FS_IO
629 #endif // POLARSSL_X509_CRT_PARSE_C
630 #endif // POLARSSL_X509_CRL_PARSE_C
631 #ifdef POLARSSL_FS_IO
632 #ifdef POLARSSL_X509_CRT_PARSE_C
633 #ifdef POLARSSL_X509_CRL_PARSE_C
634  if( strcmp( str, "BADCERT_OTHER" ) == 0 )
635  {
636  *value = ( BADCERT_OTHER );
637  return( 0 );
638  }
639 #endif // POLARSSL_FS_IO
640 #endif // POLARSSL_X509_CRT_PARSE_C
641 #endif // POLARSSL_X509_CRL_PARSE_C
642 #ifdef POLARSSL_FS_IO
643 #ifdef POLARSSL_X509_CRT_PARSE_C
644 #ifdef POLARSSL_X509_CRL_PARSE_C
645  if( strcmp( str, "BADCRL_EXPIRED" ) == 0 )
646  {
647  *value = ( BADCRL_EXPIRED );
648  return( 0 );
649  }
650 #endif // POLARSSL_FS_IO
651 #endif // POLARSSL_X509_CRT_PARSE_C
652 #endif // POLARSSL_X509_CRL_PARSE_C
653 #ifdef POLARSSL_X509_CRT_PARSE_C
654  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_VERSION + POLARSSL_ERR_ASN1_INVALID_LENGTH" ) == 0 )
655  {
657  return( 0 );
658  }
659 #endif // POLARSSL_X509_CRT_PARSE_C
660 #ifdef POLARSSL_X509_USE_C
661  if( strcmp( str, "POLARSSL_ERR_OID_BUF_TOO_SMALL" ) == 0 )
662  {
663  *value = ( POLARSSL_ERR_OID_BUF_TOO_SMALL );
664  return( 0 );
665  }
666 #endif // POLARSSL_X509_USE_C
667 #ifdef POLARSSL_X509_CRT_PARSE_C
668  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_DATE + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
669  {
671  return( 0 );
672  }
673 #endif // POLARSSL_X509_CRT_PARSE_C
674 #ifdef POLARSSL_X509_CRT_PARSE_C
675 #ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
676  if( strcmp( str, "POLARSSL_MD_SHA256" ) == 0 )
677  {
678  *value = ( POLARSSL_MD_SHA256 );
679  return( 0 );
680  }
681 #endif // POLARSSL_X509_CRT_PARSE_C
682 #endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
683 #ifdef POLARSSL_X509_CRT_PARSE_C
684  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_VERSION + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
685  {
687  return( 0 );
688  }
689 #endif // POLARSSL_X509_CRT_PARSE_C
690 #ifdef POLARSSL_FS_IO
691 #ifdef POLARSSL_X509_CRT_PARSE_C
692 #ifdef POLARSSL_X509_CRL_PARSE_C
693  if( strcmp( str, "BADCERT_REVOKED | BADCRL_FUTURE | BADCERT_CN_MISMATCH" ) == 0 )
694  {
696  return( 0 );
697  }
698 #endif // POLARSSL_FS_IO
699 #endif // POLARSSL_X509_CRT_PARSE_C
700 #endif // POLARSSL_X509_CRL_PARSE_C
701 #ifdef POLARSSL_X509_CRT_PARSE_C
702  if( strcmp( str, "POLARSSL_ERR_PK_INVALID_PUBKEY + POLARSSL_ERR_ASN1_INVALID_DATA" ) == 0 )
703  {
705  return( 0 );
706  }
707 #endif // POLARSSL_X509_CRT_PARSE_C
708 #ifdef POLARSSL_X509_CSR_PARSE_C
709  if( strcmp( str, "POLARSSL_ERR_X509_UNKNOWN_SIG_ALG" ) == 0 )
710  {
712  return( 0 );
713  }
714 #endif // POLARSSL_X509_CSR_PARSE_C
715 #ifdef POLARSSL_X509_CRL_PARSE_C
716  if( strcmp( str, "POLARSSL_ERR_X509_UNKNOWN_SIG_ALG" ) == 0 )
717  {
719  return( 0 );
720  }
721 #endif // POLARSSL_X509_CRL_PARSE_C
722 #ifdef POLARSSL_X509_CRL_PARSE_C
723  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_DATE + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
724  {
726  return( 0 );
727  }
728 #endif // POLARSSL_X509_CRL_PARSE_C
729 #ifdef POLARSSL_X509_CRL_PARSE_C
730  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_VERSION + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
731  {
733  return( 0 );
734  }
735 #endif // POLARSSL_X509_CRL_PARSE_C
736 #ifdef POLARSSL_X509_CRT_PARSE_C
737  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_VERSION + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
738  {
740  return( 0 );
741  }
742 #endif // POLARSSL_X509_CRT_PARSE_C
743 #ifdef POLARSSL_X509_CSR_PARSE_C
744  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_VERSION + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
745  {
747  return( 0 );
748  }
749 #endif // POLARSSL_X509_CSR_PARSE_C
750 #ifdef POLARSSL_X509_CRT_PARSE_C
751  if( strcmp( str, "POLARSSL_ERR_PK_INVALID_ALG + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
752  {
754  return( 0 );
755  }
756 #endif // POLARSSL_X509_CRT_PARSE_C
757 #ifdef POLARSSL_FS_IO
758 #ifdef POLARSSL_X509_CRT_PARSE_C
759 #ifdef POLARSSL_X509_CHECK_KEY_USAGE
760  if( strcmp( str, "KU_KEY_ENCIPHERMENT|KU_KEY_AGREEMENT" ) == 0 )
761  {
763  return( 0 );
764  }
765 #endif // POLARSSL_FS_IO
766 #endif // POLARSSL_X509_CRT_PARSE_C
767 #endif // POLARSSL_X509_CHECK_KEY_USAGE
768 #ifdef POLARSSL_X509_CRT_PARSE_C
769  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_DATE" ) == 0 )
770  {
771  *value = ( POLARSSL_ERR_X509_INVALID_DATE );
772  return( 0 );
773  }
774 #endif // POLARSSL_X509_CRT_PARSE_C
775 #ifdef POLARSSL_FS_IO
776 #ifdef POLARSSL_X509_CRT_PARSE_C
777 #ifdef POLARSSL_X509_CRL_PARSE_C
778  if( strcmp( str, "BADCRL_FUTURE" ) == 0 )
779  {
780  *value = ( BADCRL_FUTURE );
781  return( 0 );
782  }
783 #endif // POLARSSL_FS_IO
784 #endif // POLARSSL_X509_CRT_PARSE_C
785 #endif // POLARSSL_X509_CRL_PARSE_C
786 #ifdef POLARSSL_FS_IO
787 #ifdef POLARSSL_X509_CRT_PARSE_C
788 #ifdef POLARSSL_X509_CRL_PARSE_C
789  if( strcmp( str, "BADCERT_CN_MISMATCH + BADCERT_NOT_TRUSTED" ) == 0 )
790  {
792  return( 0 );
793  }
794 #endif // POLARSSL_FS_IO
795 #endif // POLARSSL_X509_CRT_PARSE_C
796 #endif // POLARSSL_X509_CRL_PARSE_C
797 #ifdef POLARSSL_X509_CSR_PARSE_C
798  if( strcmp( str, "POLARSSL_ERR_PK_KEY_INVALID_FORMAT + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
799  {
801  return( 0 );
802  }
803 #endif // POLARSSL_X509_CSR_PARSE_C
804 #ifdef POLARSSL_X509_CRT_PARSE_C
805  if( strcmp( str, "POLARSSL_ERR_PK_KEY_INVALID_FORMAT + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
806  {
808  return( 0 );
809  }
810 #endif // POLARSSL_X509_CRT_PARSE_C
811 #ifdef POLARSSL_FS_IO
812 #ifdef POLARSSL_X509_CRT_PARSE_C
813 #ifdef POLARSSL_X509_CHECK_KEY_USAGE
814  if( strcmp( str, "KU_DIGITAL_SIGNATURE|KU_KEY_ENCIPHERMENT" ) == 0 )
815  {
817  return( 0 );
818  }
819 #endif // POLARSSL_FS_IO
820 #endif // POLARSSL_X509_CRT_PARSE_C
821 #endif // POLARSSL_X509_CHECK_KEY_USAGE
822 #ifdef POLARSSL_X509_CSR_PARSE_C
823  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_NAME + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
824  {
826  return( 0 );
827  }
828 #endif // POLARSSL_X509_CSR_PARSE_C
829 #ifdef POLARSSL_X509_CRL_PARSE_C
830  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_NAME + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
831  {
833  return( 0 );
834  }
835 #endif // POLARSSL_X509_CRL_PARSE_C
836 #ifdef POLARSSL_X509_CRT_PARSE_C
837  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_NAME + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
838  {
840  return( 0 );
841  }
842 #endif // POLARSSL_X509_CRT_PARSE_C
843 #ifdef POLARSSL_X509_CRT_PARSE_C
844  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_DATE + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
845  {
847  return( 0 );
848  }
849 #endif // POLARSSL_X509_CRT_PARSE_C
850 #ifdef POLARSSL_X509_CRL_PARSE_C
851  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_DATE + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
852  {
854  return( 0 );
855  }
856 #endif // POLARSSL_X509_CRL_PARSE_C
857 #ifdef POLARSSL_X509_CRT_PARSE_C
858  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
859  {
861  return( 0 );
862  }
863 #endif // POLARSSL_X509_CRT_PARSE_C
864 #ifdef POLARSSL_X509_CRT_PARSE_C
865 #ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
866  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
867  {
869  return( 0 );
870  }
871 #endif // POLARSSL_X509_CRT_PARSE_C
872 #endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
873 #ifdef POLARSSL_FS_IO
874 #ifdef POLARSSL_X509_CRT_PARSE_C
875 #ifdef POLARSSL_X509_CHECK_KEY_USAGE
876  if( strcmp( str, "KU_DIGITAL_SIGNATURE" ) == 0 )
877  {
878  *value = ( KU_DIGITAL_SIGNATURE );
879  return( 0 );
880  }
881 #endif // POLARSSL_FS_IO
882 #endif // POLARSSL_X509_CRT_PARSE_C
883 #endif // POLARSSL_X509_CHECK_KEY_USAGE
884 #ifdef POLARSSL_FS_IO
885 #ifdef POLARSSL_X509_CRT_PARSE_C
886 #ifdef POLARSSL_X509_CHECK_KEY_USAGE
887  if( strcmp( str, "KU_KEY_CERT_SIGN" ) == 0 )
888  {
889  *value = ( KU_KEY_CERT_SIGN );
890  return( 0 );
891  }
892 #endif // POLARSSL_FS_IO
893 #endif // POLARSSL_X509_CRT_PARSE_C
894 #endif // POLARSSL_X509_CHECK_KEY_USAGE
895 #ifdef POLARSSL_X509_CRT_PARSE_C
896  if( strcmp( str, "POLARSSL_ERR_PK_INVALID_PUBKEY + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
897  {
899  return( 0 );
900  }
901 #endif // POLARSSL_X509_CRT_PARSE_C
902 #ifdef POLARSSL_X509_CRT_PARSE_C
903  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_SERIAL + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
904  {
906  return( 0 );
907  }
908 #endif // POLARSSL_X509_CRT_PARSE_C
909 #ifdef POLARSSL_X509_CRT_PARSE_C
910 #ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
911  if( strcmp( str, "ASN1_CONSTRUCTED | ASN1_SEQUENCE" ) == 0 )
912  {
913  *value = ( ASN1_CONSTRUCTED | ASN1_SEQUENCE );
914  return( 0 );
915  }
916 #endif // POLARSSL_X509_CRT_PARSE_C
917 #endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
918 #ifdef POLARSSL_FS_IO
919 #ifdef POLARSSL_X509_CRT_PARSE_C
920 #ifdef POLARSSL_X509_CRL_PARSE_C
921  if( strcmp( str, "BADCERT_REVOKED | BADCRL_EXPIRED | BADCERT_CN_MISMATCH" ) == 0 )
922  {
924  return( 0 );
925  }
926 #endif // POLARSSL_FS_IO
927 #endif // POLARSSL_X509_CRT_PARSE_C
928 #endif // POLARSSL_X509_CRL_PARSE_C
929 #ifdef POLARSSL_X509_CRT_PARSE_C
930  if( strcmp( str, "POLARSSL_ERR_PK_INVALID_PUBKEY + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
931  {
933  return( 0 );
934  }
935 #endif // POLARSSL_X509_CRT_PARSE_C
936 #ifdef POLARSSL_FS_IO
937 #ifdef POLARSSL_X509_CRT_PARSE_C
938 #ifdef POLARSSL_X509_CRL_PARSE_C
939  if( strcmp( str, "BADCERT_REVOKED" ) == 0 )
940  {
941  *value = ( BADCERT_REVOKED );
942  return( 0 );
943  }
944 #endif // POLARSSL_FS_IO
945 #endif // POLARSSL_X509_CRT_PARSE_C
946 #endif // POLARSSL_X509_CRL_PARSE_C
947 #ifdef POLARSSL_X509_CRT_PARSE_C
948 #ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
949  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_INVALID_DATA" ) == 0 )
950  {
952  return( 0 );
953  }
954 #endif // POLARSSL_X509_CRT_PARSE_C
955 #endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
956 #ifdef POLARSSL_X509_CRT_PARSE_C
957  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_EXTENSIONS + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
958  {
960  return( 0 );
961  }
962 #endif // POLARSSL_X509_CRT_PARSE_C
963 #ifdef POLARSSL_X509_CRT_PARSE_C
964 #ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
965  if( strcmp( str, "ASN1_SEQUENCE" ) == 0 )
966  {
967  *value = ( ASN1_SEQUENCE );
968  return( 0 );
969  }
970 #endif // POLARSSL_X509_CRT_PARSE_C
971 #endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
972 #ifdef POLARSSL_X509_CRT_PARSE_C
973 #ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
974  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG" ) == 0 )
975  {
976  *value = ( POLARSSL_ERR_X509_INVALID_ALG );
977  return( 0 );
978  }
979 #endif // POLARSSL_X509_CRT_PARSE_C
980 #endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
981 #ifdef POLARSSL_X509_CSR_PARSE_C
982  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
983  {
985  return( 0 );
986  }
987 #endif // POLARSSL_X509_CSR_PARSE_C
988 #ifdef POLARSSL_X509_CRT_PARSE_C
989 #ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
990  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
991  {
993  return( 0 );
994  }
995 #endif // POLARSSL_X509_CRT_PARSE_C
996 #endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
997 #ifdef POLARSSL_X509_CRL_PARSE_C
998  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
999  {
1001  return( 0 );
1002  }
1003 #endif // POLARSSL_X509_CRL_PARSE_C
1004 #ifdef POLARSSL_X509_CRT_PARSE_C
1005  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
1006  {
1008  return( 0 );
1009  }
1010 #endif // POLARSSL_X509_CRT_PARSE_C
1011 #ifdef POLARSSL_FS_IO
1012 #ifdef POLARSSL_X509_CRT_PARSE_C
1013 #ifdef POLARSSL_X509_CRL_PARSE_C
1014  if( strcmp( str, "BADCERT_CN_MISMATCH" ) == 0 )
1015  {
1016  *value = ( BADCERT_CN_MISMATCH );
1017  return( 0 );
1018  }
1019 #endif // POLARSSL_FS_IO
1020 #endif // POLARSSL_X509_CRT_PARSE_C
1021 #endif // POLARSSL_X509_CRL_PARSE_C
1022 #ifdef POLARSSL_X509_CRL_PARSE_C
1023  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
1024  {
1026  return( 0 );
1027  }
1028 #endif // POLARSSL_X509_CRL_PARSE_C
1029 #ifdef POLARSSL_X509_CRT_PARSE_C
1030  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
1031  {
1033  return( 0 );
1034  }
1035 #endif // POLARSSL_X509_CRT_PARSE_C
1036 #ifdef POLARSSL_X509_CSR_PARSE_C
1037  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
1038  {
1040  return( 0 );
1041  }
1042 #endif // POLARSSL_X509_CSR_PARSE_C
1043 #ifdef POLARSSL_X509_CRT_PARSE_C
1044 #ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
1045  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
1046  {
1048  return( 0 );
1049  }
1050 #endif // POLARSSL_X509_CRT_PARSE_C
1051 #endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
1052 #ifdef POLARSSL_FS_IO
1053 #ifdef POLARSSL_X509_CRT_PARSE_C
1054 #ifdef POLARSSL_X509_CHECK_KEY_USAGE
1055  if( strcmp( str, "POLARSSL_ERR_X509_BAD_INPUT_DATA" ) == 0 )
1056  {
1057  *value = ( POLARSSL_ERR_X509_BAD_INPUT_DATA );
1058  return( 0 );
1059  }
1060 #endif // POLARSSL_FS_IO
1061 #endif // POLARSSL_X509_CRT_PARSE_C
1062 #endif // POLARSSL_X509_CHECK_KEY_USAGE
1063 #ifdef POLARSSL_FS_IO
1064 #ifdef POLARSSL_X509_CRT_PARSE_C
1065 #ifdef POLARSSL_X509_CHECK_EXTENDED_KEY_USAGE
1066  if( strcmp( str, "POLARSSL_ERR_X509_BAD_INPUT_DATA" ) == 0 )
1067  {
1068  *value = ( POLARSSL_ERR_X509_BAD_INPUT_DATA );
1069  return( 0 );
1070  }
1071 #endif // POLARSSL_FS_IO
1072 #endif // POLARSSL_X509_CRT_PARSE_C
1073 #endif // POLARSSL_X509_CHECK_EXTENDED_KEY_USAGE
1074 #ifdef POLARSSL_X509_CRT_PARSE_C
1075  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_SIGNATURE + POLARSSL_ERR_ASN1_INVALID_DATA" ) == 0 )
1076  {
1078  return( 0 );
1079  }
1080 #endif // POLARSSL_X509_CRT_PARSE_C
1081 #ifdef POLARSSL_X509_CRT_PARSE_C
1082 #ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
1083  if( strcmp( str, "POLARSSL_MD_SHA1" ) == 0 )
1084  {
1085  *value = ( POLARSSL_MD_SHA1 );
1086  return( 0 );
1087  }
1088 #endif // POLARSSL_X509_CRT_PARSE_C
1089 #endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
1090 #ifdef POLARSSL_X509_CSR_PARSE_C
1091  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
1092  {
1094  return( 0 );
1095  }
1096 #endif // POLARSSL_X509_CSR_PARSE_C
1097 #ifdef POLARSSL_X509_CRT_PARSE_C
1098  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
1099  {
1101  return( 0 );
1102  }
1103 #endif // POLARSSL_X509_CRT_PARSE_C
1104 #ifdef POLARSSL_X509_CSR_PARSE_C
1105  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT" ) == 0 )
1106  {
1107  *value = ( POLARSSL_ERR_X509_INVALID_FORMAT );
1108  return( 0 );
1109  }
1110 #endif // POLARSSL_X509_CSR_PARSE_C
1111 #ifdef POLARSSL_X509_CRL_PARSE_C
1112  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT" ) == 0 )
1113  {
1114  *value = ( POLARSSL_ERR_X509_INVALID_FORMAT );
1115  return( 0 );
1116  }
1117 #endif // POLARSSL_X509_CRL_PARSE_C
1118 #ifdef POLARSSL_X509_CRT_PARSE_C
1119  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT" ) == 0 )
1120  {
1121  *value = ( POLARSSL_ERR_X509_INVALID_FORMAT );
1122  return( 0 );
1123  }
1124 #endif // POLARSSL_X509_CRT_PARSE_C
1125 #ifdef POLARSSL_X509_CSR_PARSE_C
1126  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_SIGNATURE + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
1127  {
1129  return( 0 );
1130  }
1131 #endif // POLARSSL_X509_CSR_PARSE_C
1132 #ifdef POLARSSL_X509_CRT_PARSE_C
1133 #ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
1134  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_OID_NOT_FOUND" ) == 0 )
1135  {
1137  return( 0 );
1138  }
1139 #endif // POLARSSL_X509_CRT_PARSE_C
1140 #endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
1141 #ifdef POLARSSL_X509_CRT_PARSE_C
1142  if( strcmp( str, "POLARSSL_ERR_PK_INVALID_PUBKEY + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
1143  {
1145  return( 0 );
1146  }
1147 #endif // POLARSSL_X509_CRT_PARSE_C
1148 #ifdef POLARSSL_X509_CSR_PARSE_C
1149  if( strcmp( str, "POLARSSL_ERR_X509_UNKNOWN_VERSION" ) == 0 )
1150  {
1151  *value = ( POLARSSL_ERR_X509_UNKNOWN_VERSION );
1152  return( 0 );
1153  }
1154 #endif // POLARSSL_X509_CSR_PARSE_C
1155 #ifdef POLARSSL_X509_CRT_PARSE_C
1156  if( strcmp( str, "POLARSSL_ERR_X509_UNKNOWN_VERSION" ) == 0 )
1157  {
1158  *value = ( POLARSSL_ERR_X509_UNKNOWN_VERSION );
1159  return( 0 );
1160  }
1161 #endif // POLARSSL_X509_CRT_PARSE_C
1162 #ifdef POLARSSL_X509_CRL_PARSE_C
1163  if( strcmp( str, "POLARSSL_ERR_X509_UNKNOWN_VERSION" ) == 0 )
1164  {
1165  *value = ( POLARSSL_ERR_X509_UNKNOWN_VERSION );
1166  return( 0 );
1167  }
1168 #endif // POLARSSL_X509_CRL_PARSE_C
1169 #ifdef POLARSSL_X509_CRT_PARSE_C
1170  if( strcmp( str, "POLARSSL_ERR_PK_INVALID_PUBKEY" ) == 0 )
1171  {
1172  *value = ( POLARSSL_ERR_PK_INVALID_PUBKEY );
1173  return( 0 );
1174  }
1175 #endif // POLARSSL_X509_CRT_PARSE_C
1176 #ifdef POLARSSL_X509_CRT_PARSE_C
1177  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_VERSION + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
1178  {
1180  return( 0 );
1181  }
1182 #endif // POLARSSL_X509_CRT_PARSE_C
1183 #ifdef POLARSSL_X509_CSR_PARSE_C
1184  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
1185  {
1187  return( 0 );
1188  }
1189 #endif // POLARSSL_X509_CSR_PARSE_C
1190 #ifdef POLARSSL_X509_CRL_PARSE_C
1191  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
1192  {
1194  return( 0 );
1195  }
1196 #endif // POLARSSL_X509_CRL_PARSE_C
1197 #ifdef POLARSSL_X509_CRT_PARSE_C
1198  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
1199  {
1201  return( 0 );
1202  }
1203 #endif // POLARSSL_X509_CRT_PARSE_C
1204 #ifdef POLARSSL_X509_CRT_PARSE_C
1205  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_SERIAL + POLARSSL_ERR_ASN1_OUT_OF_DATA " ) == 0 )
1206  {
1208  return( 0 );
1209  }
1210 #endif // POLARSSL_X509_CRT_PARSE_C
1211 #ifdef POLARSSL_X509_CSR_PARSE_C
1212  if( strcmp( str, "POLARSSL_ERR_PK_KEY_INVALID_FORMAT + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
1213  {
1215  return( 0 );
1216  }
1217 #endif // POLARSSL_X509_CSR_PARSE_C
1218 #ifdef POLARSSL_FS_IO
1219 #ifdef POLARSSL_X509_CRT_PARSE_C
1220 #ifdef POLARSSL_X509_CRL_PARSE_C
1221  if( strcmp( str, "BADCRL_NOT_TRUSTED" ) == 0 )
1222  {
1223  *value = ( BADCRL_NOT_TRUSTED );
1224  return( 0 );
1225  }
1226 #endif // POLARSSL_FS_IO
1227 #endif // POLARSSL_X509_CRT_PARSE_C
1228 #endif // POLARSSL_X509_CRL_PARSE_C
1229 #ifdef POLARSSL_X509_CSR_PARSE_C
1230  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_NAME + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
1231  {
1233  return( 0 );
1234  }
1235 #endif // POLARSSL_X509_CSR_PARSE_C
1236 #ifdef POLARSSL_X509_CRT_PARSE_C
1237  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_NAME + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
1238  {
1240  return( 0 );
1241  }
1242 #endif // POLARSSL_X509_CRT_PARSE_C
1243 #ifdef POLARSSL_FS_IO
1244 #ifdef POLARSSL_X509_CRT_PARSE_C
1245 #ifdef POLARSSL_X509_CRL_PARSE_C
1246  if( strcmp( str, "BADCERT_REVOKED | BADCRL_EXPIRED" ) == 0 )
1247  {
1248  *value = ( BADCERT_REVOKED | BADCRL_EXPIRED );
1249  return( 0 );
1250  }
1251 #endif // POLARSSL_FS_IO
1252 #endif // POLARSSL_X509_CRT_PARSE_C
1253 #endif // POLARSSL_X509_CRL_PARSE_C
1254 
1255 
1256  printf( "Expected integer for parameter and got: %s\n", str );
1257  return( -1 );
1258 }
1259 
1260 #ifdef POLARSSL_FS_IO
1261 #ifdef POLARSSL_X509_CRT_PARSE_C
1262 void test_suite_x509_cert_info( char *crt_file, char *result_str )
1263 {
1264  x509_crt crt;
1265  char buf[2000];
1266  int res;
1267 
1268  x509_crt_init( &crt );
1269  memset( buf, 0, 2000 );
1270 
1271  TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == 0 );
1272  res = x509_crt_info( buf, 2000, "", &crt );
1273 
1274  TEST_ASSERT( res != -1 );
1275  TEST_ASSERT( res != -2 );
1276 
1277  TEST_ASSERT( strcmp( buf, result_str ) == 0 );
1278 
1279 exit:
1280  x509_crt_free( &crt );
1281 }
1282 #endif /* POLARSSL_FS_IO */
1283 #endif /* POLARSSL_X509_CRT_PARSE_C */
1284 
1285 #ifdef POLARSSL_FS_IO
1286 #ifdef POLARSSL_X509_CRL_PARSE_C
1287 void test_suite_x509_crl_info( char *crl_file, char *result_str )
1288 {
1289  x509_crl crl;
1290  char buf[2000];
1291  int res;
1292 
1293  x509_crl_init( &crl );
1294  memset( buf, 0, 2000 );
1295 
1296  TEST_ASSERT( x509_crl_parse_file( &crl, crl_file ) == 0 );
1297  res = x509_crl_info( buf, 2000, "", &crl );
1298 
1299  TEST_ASSERT( res != -1 );
1300  TEST_ASSERT( res != -2 );
1301 
1302  TEST_ASSERT( strcmp( buf, result_str ) == 0 );
1303 
1304 exit:
1305  x509_crl_free( &crl );
1306 }
1307 #endif /* POLARSSL_FS_IO */
1308 #endif /* POLARSSL_X509_CRL_PARSE_C */
1309 
1310 #ifdef POLARSSL_FS_IO
1311 #ifdef POLARSSL_X509_CSR_PARSE_C
1312 void test_suite_x509_csr_info( char *csr_file, char *result_str )
1313 {
1314  x509_csr csr;
1315  char buf[2000];
1316  int res;
1317 
1318  x509_csr_init( &csr );
1319  memset( buf, 0, 2000 );
1320 
1321  TEST_ASSERT( x509_csr_parse_file( &csr, csr_file ) == 0 );
1322  res = x509_csr_info( buf, 2000, "", &csr );
1323 
1324  TEST_ASSERT( res != -1 );
1325  TEST_ASSERT( res != -2 );
1326 
1327  TEST_ASSERT( strcmp( buf, result_str ) == 0 );
1328 
1329 exit:
1330  x509_csr_free( &csr );
1331 }
1332 #endif /* POLARSSL_FS_IO */
1333 #endif /* POLARSSL_X509_CSR_PARSE_C */
1334 
1335 #ifdef POLARSSL_FS_IO
1336 #ifdef POLARSSL_X509_CRT_PARSE_C
1337 #ifdef POLARSSL_X509_CRL_PARSE_C
1338 void test_suite_x509_verify( char *crt_file, char *ca_file, char *crl_file,
1339  char *cn_name_str, int result, int flags_result,
1340  char *verify_callback )
1341 {
1342  x509_crt crt;
1343  x509_crt ca;
1344  x509_crl crl;
1345  int flags = 0;
1346  int res;
1347  int (*f_vrfy)(void *, x509_crt *, int, int *) = NULL;
1348  char * cn_name = NULL;
1349 
1350  x509_crt_init( &crt );
1351  x509_crt_init( &ca );
1352  x509_crl_init( &crl );
1353 
1354  if( strcmp( cn_name_str, "NULL" ) != 0 )
1355  cn_name = cn_name_str;
1356 
1357  if( strcmp( verify_callback, "NULL" ) == 0 )
1358  f_vrfy = NULL;
1359  else if( strcmp( verify_callback, "verify_none" ) == 0 )
1360  f_vrfy = verify_none;
1361  else if( strcmp( verify_callback, "verify_all" ) == 0 )
1362  f_vrfy = verify_all;
1363  else
1364  TEST_ASSERT( "No known verify callback selected" == 0 );
1365 
1366  TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == 0 );
1367  TEST_ASSERT( x509_crt_parse_file( &ca, ca_file ) == 0 );
1368  TEST_ASSERT( x509_crl_parse_file( &crl, crl_file ) == 0 );
1369 
1370  res = x509_crt_verify( &crt, &ca, &crl, cn_name, &flags, f_vrfy, NULL );
1371 
1372  TEST_ASSERT( res == ( result ) );
1373  TEST_ASSERT( flags == ( flags_result ) );
1374 
1375 exit:
1376  x509_crt_free( &crt );
1377  x509_crt_free( &ca );
1378  x509_crl_free( &crl );
1379 }
1380 #endif /* POLARSSL_FS_IO */
1381 #endif /* POLARSSL_X509_CRT_PARSE_C */
1382 #endif /* POLARSSL_X509_CRL_PARSE_C */
1383 
1384 #ifdef POLARSSL_FS_IO
1385 #ifdef POLARSSL_X509_CRT_C
1386 void test_suite_x509_dn_gets( char *crt_file, char *entity, char *result_str )
1387 {
1388  x509_crt crt;
1389  char buf[2000];
1390  int res = 0;
1391 
1392  x509_crt_init( &crt );
1393  memset( buf, 0, 2000 );
1394 
1395  TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == 0 );
1396  if( strcmp( entity, "subject" ) == 0 )
1397  res = x509_dn_gets( buf, 2000, &crt.subject );
1398  else if( strcmp( entity, "issuer" ) == 0 )
1399  res = x509_dn_gets( buf, 2000, &crt.issuer );
1400  else
1401  TEST_ASSERT( "Unknown entity" == 0 );
1402 
1403  TEST_ASSERT( res != -1 );
1404  TEST_ASSERT( res != -2 );
1405 
1406  TEST_ASSERT( strcmp( buf, result_str ) == 0 );
1407 
1408 exit:
1409  x509_crt_free( &crt );
1410 }
1411 #endif /* POLARSSL_FS_IO */
1412 #endif /* POLARSSL_X509_CRT_C */
1413 
1414 #ifdef POLARSSL_FS_IO
1415 #ifdef POLARSSL_X509_CRT_C
1416 void test_suite_x509_time_expired( char *crt_file, char *entity, int result )
1417 {
1418  x509_crt crt;
1419 
1420  x509_crt_init( &crt );
1421 
1422  TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == 0 );
1423 
1424  if( strcmp( entity, "valid_from" ) == 0 )
1425  TEST_ASSERT( x509_time_expired( &crt.valid_from ) == result );
1426  else if( strcmp( entity, "valid_to" ) == 0 )
1427  TEST_ASSERT( x509_time_expired( &crt.valid_to ) == result );
1428  else
1429  TEST_ASSERT( "Unknown entity" == 0 );
1430 
1431 exit:
1432  x509_crt_free( &crt );
1433 }
1434 #endif /* POLARSSL_FS_IO */
1435 #endif /* POLARSSL_X509_CRT_C */
1436 
1437 #ifdef POLARSSL_FS_IO
1438 #ifdef POLARSSL_X509_CRT_C
1439 void test_suite_x509_time_future( char *crt_file, char *entity, int result )
1440 {
1441  x509_crt crt;
1442 
1443  x509_crt_init( &crt );
1444 
1445  TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == 0 );
1446 
1447  if( strcmp( entity, "valid_from" ) == 0 )
1448  TEST_ASSERT( x509_time_future( &crt.valid_from ) == result );
1449  else if( strcmp( entity, "valid_to" ) == 0 )
1450  TEST_ASSERT( x509_time_future( &crt.valid_to ) == result );
1451  else
1452  TEST_ASSERT( "Unknown entity" == 0 );
1453 
1454 exit:
1455  x509_crt_free( &crt );
1456 }
1457 #endif /* POLARSSL_FS_IO */
1458 #endif /* POLARSSL_X509_CRT_C */
1459 
1460 #ifdef POLARSSL_X509_CRT_PARSE_C
1461 void test_suite_x509parse_crt( char *crt_data, char *result_str, int result )
1462 {
1463  x509_crt crt;
1464  unsigned char buf[2000];
1465  unsigned char output[2000];
1466  int data_len, res;
1467 
1468  x509_crt_init( &crt );
1469  memset( buf, 0, 2000 );
1470  memset( output, 0, 2000 );
1471 
1472  data_len = unhexify( buf, crt_data );
1473 
1474  TEST_ASSERT( x509_crt_parse( &crt, buf, data_len ) == ( result ) );
1475  if( ( result ) == 0 )
1476  {
1477  res = x509_crt_info( (char *) output, 2000, "", &crt );
1478 
1479  TEST_ASSERT( res != -1 );
1480  TEST_ASSERT( res != -2 );
1481 
1482  TEST_ASSERT( strcmp( (char *) output, result_str ) == 0 );
1483  }
1484 
1485 exit:
1486  x509_crt_free( &crt );
1487 }
1488 #endif /* POLARSSL_X509_CRT_PARSE_C */
1489 
1490 #ifdef POLARSSL_X509_CRL_PARSE_C
1491 void test_suite_x509parse_crl( char *crl_data, char *result_str, int result )
1492 {
1493  x509_crl crl;
1494  unsigned char buf[2000];
1495  unsigned char output[2000];
1496  int data_len, res;
1497 
1498  x509_crl_init( &crl );
1499  memset( buf, 0, 2000 );
1500  memset( output, 0, 2000 );
1501 
1502  data_len = unhexify( buf, crl_data );
1503 
1504  TEST_ASSERT( x509_crl_parse( &crl, buf, data_len ) == ( result ) );
1505  if( ( result ) == 0 )
1506  {
1507  res = x509_crl_info( (char *) output, 2000, "", &crl );
1508 
1509  TEST_ASSERT( res != -1 );
1510  TEST_ASSERT( res != -2 );
1511 
1512  TEST_ASSERT( strcmp( (char *) output, result_str ) == 0 );
1513  }
1514 
1515 exit:
1516  x509_crl_free( &crl );
1517 }
1518 #endif /* POLARSSL_X509_CRL_PARSE_C */
1519 
1520 #ifdef POLARSSL_X509_CSR_PARSE_C
1521 void test_suite_x509_csr_parse( char *csr_der_hex, char *ref_out, int ref_ret )
1522 {
1523  x509_csr csr;
1524  unsigned char *csr_der = NULL;
1525  char my_out[1000];
1526  size_t csr_der_len;
1527  int my_ret;
1528 
1529  x509_csr_init( &csr );
1530  memset( my_out, 0, sizeof( my_out ) );
1531  csr_der = unhexify_alloc( csr_der_hex, &csr_der_len );
1532 
1533  my_ret = x509_csr_parse_der( &csr, csr_der, csr_der_len );
1534  TEST_ASSERT( my_ret == ref_ret );
1535 
1536  if( ref_ret == 0 )
1537  {
1538  size_t my_out_len = x509_csr_info( my_out, sizeof( my_out ), "", &csr );
1539  TEST_ASSERT( my_out_len == strlen( ref_out ) );
1540  TEST_ASSERT( strcmp( my_out, ref_out ) == 0 );
1541  }
1542 
1543 exit:
1544  x509_csr_free( &csr );
1545  polarssl_free( csr_der );
1546 }
1547 #endif /* POLARSSL_X509_CSR_PARSE_C */
1548 
1549 #ifdef POLARSSL_FS_IO
1550 #ifdef POLARSSL_X509_CRT_PARSE_C
1551 void test_suite_x509_crt_parse_path( char *crt_path, int ret, int nb_crt )
1552 {
1553  x509_crt chain, *cur;
1554  int i;
1555 
1556  x509_crt_init( &chain );
1557 
1558  TEST_ASSERT( x509_crt_parse_path( &chain, crt_path ) == ret );
1559 
1560  /* Check how many certs we got */
1561  for( i = 0, cur = &chain; cur != NULL; cur = cur->next )
1562  if( cur->raw.p != NULL )
1563  i++;
1564 
1565  TEST_ASSERT( i == nb_crt );
1566 
1567 exit:
1568  x509_crt_free( &chain );
1569 }
1570 #endif /* POLARSSL_FS_IO */
1571 #endif /* POLARSSL_X509_CRT_PARSE_C */
1572 
1573 #ifdef POLARSSL_X509_USE_C
1574 void test_suite_x509_oid_desc( char *oid_str, char *ref_desc )
1575 {
1576  x509_buf oid;
1577  const char *desc;
1578  unsigned char buf[20];
1579 
1580  memset( buf, 0, sizeof buf );
1581 
1582  oid.tag = ASN1_OID;
1583  oid.len = unhexify( buf, oid_str );
1584  oid.p = buf;
1585 
1586  desc = x509_oid_get_description( &oid );
1587 
1588  if( strcmp( ref_desc, "notfound" ) == 0 )
1589  TEST_ASSERT( desc == NULL );
1590  else
1591  {
1592  TEST_ASSERT( desc != NULL );
1593  TEST_ASSERT( strcmp( desc, ref_desc ) == 0 );
1594  }
1595 
1596 exit:
1597  return;
1598 }
1599 #endif /* POLARSSL_X509_USE_C */
1600 
1601 #ifdef POLARSSL_X509_USE_C
1602 void test_suite_x509_oid_numstr( char *oid_str, char *numstr, int blen, int ret )
1603 {
1604  x509_buf oid;
1605  unsigned char oid_buf[20];
1606  char num_buf[100];
1607 
1608  memset( oid_buf, 0x00, sizeof oid_buf );
1609  memset( num_buf, 0x2a, sizeof num_buf );
1610 
1611  oid.tag = ASN1_OID;
1612  oid.len = unhexify( oid_buf, oid_str );
1613  oid.p = oid_buf;
1614 
1615  TEST_ASSERT( (size_t) blen <= sizeof num_buf );
1616 
1617  TEST_ASSERT( x509_oid_get_numeric_string( num_buf, blen, &oid ) == ret );
1618 
1619  if( ret >= 0 )
1620  {
1621  TEST_ASSERT( num_buf[ret] == 0 );
1622  TEST_ASSERT( strcmp( num_buf, numstr ) == 0 );
1623  }
1624 
1625 exit:
1626  return;
1627 }
1628 #endif /* POLARSSL_X509_USE_C */
1629 
1630 #ifdef POLARSSL_FS_IO
1631 #ifdef POLARSSL_X509_CRT_PARSE_C
1632 #ifdef POLARSSL_X509_CHECK_KEY_USAGE
1633 void test_suite_x509_check_key_usage( char *crt_file, int usage, int ret )
1634 {
1635  x509_crt crt;
1636 
1637  x509_crt_init( &crt );
1638 
1639  TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == 0 );
1640 
1641  TEST_ASSERT( x509_crt_check_key_usage( &crt, usage ) == ret );
1642 
1643 exit:
1644  x509_crt_free( &crt );
1645 }
1646 #endif /* POLARSSL_FS_IO */
1647 #endif /* POLARSSL_X509_CRT_PARSE_C */
1648 #endif /* POLARSSL_X509_CHECK_KEY_USAGE */
1649 
1650 #ifdef POLARSSL_FS_IO
1651 #ifdef POLARSSL_X509_CRT_PARSE_C
1652 #ifdef POLARSSL_X509_CHECK_EXTENDED_KEY_USAGE
1653 void test_suite_x509_check_extended_key_usage( char *crt_file, char *usage_hex, int ret )
1654 {
1655  x509_crt crt;
1656  char oid[50];
1657  size_t len;
1658 
1659  x509_crt_init( &crt );
1660 
1661  len = unhexify( (unsigned char *) oid, usage_hex );
1662 
1663  TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == 0 );
1664 
1665  TEST_ASSERT( x509_crt_check_extended_key_usage( &crt, oid, len ) == ret );
1666 
1667 exit:
1668  x509_crt_free( &crt );
1669 }
1670 #endif /* POLARSSL_FS_IO */
1671 #endif /* POLARSSL_X509_CRT_PARSE_C */
1672 #endif /* POLARSSL_X509_CHECK_EXTENDED_KEY_USAGE */
1673 
1674 #ifdef POLARSSL_X509_CRT_PARSE_C
1675 #ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
1676 void test_suite_x509_parse_rsassa_pss_params( char *hex_params, int params_tag,
1677  int ref_msg_md, int ref_mgf_md,
1678  int ref_salt_len, int ref_ret )
1679 {
1680  int my_ret;
1681  x509_buf params;
1682  md_type_t my_msg_md, my_mgf_md;
1683  int my_salt_len;
1684 
1685  params.p = unhexify_alloc( hex_params, &params.len );
1686  params.tag = params_tag;
1687 
1688  my_ret = x509_get_rsassa_pss_params( &params, &my_msg_md, &my_mgf_md,
1689  &my_salt_len );
1690 
1691  if( my_ret != ref_ret ) printf( "\n%04X\n", - my_ret );
1692 
1693  TEST_ASSERT( my_ret == ref_ret );
1694 
1695  if( ref_ret == 0 )
1696  {
1697  TEST_ASSERT( my_msg_md == (md_type_t) ref_msg_md );
1698  TEST_ASSERT( my_mgf_md == (md_type_t) ref_mgf_md );
1699  TEST_ASSERT( my_salt_len == ref_salt_len );
1700  }
1701 
1702 exit:
1703  polarssl_free( params.p );
1704 }
1705 #endif /* POLARSSL_X509_CRT_PARSE_C */
1706 #endif /* POLARSSL_X509_RSASSA_PSS_SUPPORT */
1707 
1708 #ifdef POLARSSL_X509_CRT_PARSE_C
1709 #ifdef POLARSSL_SELF_TEST
1710 void test_suite_x509_selftest()
1711 {
1712  TEST_ASSERT( x509_self_test( 0 ) == 0 );
1713 
1714 exit:
1715  return;
1716 }
1717 #endif /* POLARSSL_X509_CRT_PARSE_C */
1718 #endif /* POLARSSL_SELF_TEST */
1719 
1720 
1721 #endif /* POLARSSL_BIGNUM_C */
1722 
1723 
1724 int dep_check( char *str )
1725 {
1726  if( str == NULL )
1727  return( 1 );
1728 
1729  if( strcmp( str, "POLARSSL_X509_CHECK_KEY_USAGE" ) == 0 )
1730  {
1731 #if defined(POLARSSL_X509_CHECK_KEY_USAGE)
1732  return( 0 );
1733 #else
1734  return( 1 );
1735 #endif
1736  }
1737  if( strcmp( str, "POLARSSL_SHA256_C" ) == 0 )
1738  {
1739 #if defined(POLARSSL_SHA256_C)
1740  return( 0 );
1741 #else
1742  return( 1 );
1743 #endif
1744  }
1745  if( strcmp( str, "POLARSSL_ECP_C" ) == 0 )
1746  {
1747 #if defined(POLARSSL_ECP_C)
1748  return( 0 );
1749 #else
1750  return( 1 );
1751 #endif
1752  }
1753  if( strcmp( str, "POLARSSL_CERTS_C" ) == 0 )
1754  {
1755 #if defined(POLARSSL_CERTS_C)
1756  return( 0 );
1757 #else
1758  return( 1 );
1759 #endif
1760  }
1761  if( strcmp( str, "POLARSSL_ECP_DP_SECP383R1_ENABLED" ) == 0 )
1762  {
1763 #if defined(POLARSSL_ECP_DP_SECP383R1_ENABLED)
1764  return( 0 );
1765 #else
1766  return( 1 );
1767 #endif
1768  }
1769  if( strcmp( str, "POLARSSL_ECP_DP_SECP256R1_ENABLED" ) == 0 )
1770  {
1771 #if defined(POLARSSL_ECP_DP_SECP256R1_ENABLED)
1772  return( 0 );
1773 #else
1774  return( 1 );
1775 #endif
1776  }
1777  if( strcmp( str, "POLARSSL_SHA1_C" ) == 0 )
1778  {
1779 #if defined(POLARSSL_SHA1_C)
1780  return( 0 );
1781 #else
1782  return( 1 );
1783 #endif
1784  }
1785  if( strcmp( str, "POLARSSL_RSA_C" ) == 0 )
1786  {
1787 #if defined(POLARSSL_RSA_C)
1788  return( 0 );
1789 #else
1790  return( 1 );
1791 #endif
1792  }
1793  if( strcmp( str, "POLARSSL_X509_RSASSA_PSS_SUPPORT" ) == 0 )
1794  {
1795 #if defined(POLARSSL_X509_RSASSA_PSS_SUPPORT)
1796  return( 0 );
1797 #else
1798  return( 1 );
1799 #endif
1800  }
1801  if( strcmp( str, "POLARSSL_ECP_DP_SECP192R1_ENABLED" ) == 0 )
1802  {
1803 #if defined(POLARSSL_ECP_DP_SECP192R1_ENABLED)
1804  return( 0 );
1805 #else
1806  return( 1 );
1807 #endif
1808  }
1809  if( strcmp( str, "POLARSSL_MD5_C" ) == 0 )
1810  {
1811 #if defined(POLARSSL_MD5_C)
1812  return( 0 );
1813 #else
1814  return( 1 );
1815 #endif
1816  }
1817  if( strcmp( str, "POLARSSL_PEM_PARSE_C" ) == 0 )
1818  {
1819 #if defined(POLARSSL_PEM_PARSE_C)
1820  return( 0 );
1821 #else
1822  return( 1 );
1823 #endif
1824  }
1825  if( strcmp( str, "POLARSSL_MD4_C" ) == 0 )
1826  {
1827 #if defined(POLARSSL_MD4_C)
1828  return( 0 );
1829 #else
1830  return( 1 );
1831 #endif
1832  }
1833  if( strcmp( str, "POLARSSL_ECDSA_C" ) == 0 )
1834  {
1835 #if defined(POLARSSL_ECDSA_C)
1836  return( 0 );
1837 #else
1838  return( 1 );
1839 #endif
1840  }
1841  if( strcmp( str, "POLARSSL_PKCS1_V15" ) == 0 )
1842  {
1843 #if defined(POLARSSL_PKCS1_V15)
1844  return( 0 );
1845 #else
1846  return( 1 );
1847 #endif
1848  }
1849  if( strcmp( str, "POLARSSL_ECP_DP_SECP384R1_ENABLED" ) == 0 )
1850  {
1851 #if defined(POLARSSL_ECP_DP_SECP384R1_ENABLED)
1852  return( 0 );
1853 #else
1854  return( 1 );
1855 #endif
1856  }
1857  if( strcmp( str, "POLARSSL_X509_ALLOW_EXTENSIONS_NON_V3" ) == 0 )
1858  {
1859 #if defined(POLARSSL_X509_ALLOW_EXTENSIONS_NON_V3)
1860  return( 0 );
1861 #else
1862  return( 1 );
1863 #endif
1864  }
1865  if( strcmp( str, "POLARSSL_HAVE_TIME" ) == 0 )
1866  {
1867 #if defined(POLARSSL_HAVE_TIME)
1868  return( 0 );
1869 #else
1870  return( 1 );
1871 #endif
1872  }
1873  if( strcmp( str, "POLARSSL_SHA512_C" ) == 0 )
1874  {
1875 #if defined(POLARSSL_SHA512_C)
1876  return( 0 );
1877 #else
1878  return( 1 );
1879 #endif
1880  }
1881 
1882 
1883  return( 1 );
1884 }
1885 
1886 int dispatch_test(int cnt, char *params[50])
1887 {
1888  int ret;
1889  ((void) cnt);
1890  ((void) params);
1891 
1892 #if defined(TEST_SUITE_ACTIVE)
1893  if( strcmp( params[0], "x509_cert_info" ) == 0 )
1894  {
1895  #ifdef POLARSSL_FS_IO
1896  #ifdef POLARSSL_X509_CRT_PARSE_C
1897 
1898  char *param1 = params[1];
1899  char *param2 = params[2];
1900 
1901  if( cnt != 3 )
1902  {
1903  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 3 );
1904  return( 2 );
1905  }
1906 
1907  if( verify_string( &param1 ) != 0 ) return( 2 );
1908  if( verify_string( &param2 ) != 0 ) return( 2 );
1909 
1910  test_suite_x509_cert_info( param1, param2 );
1911  return ( 0 );
1912  #endif /* POLARSSL_FS_IO */
1913  #endif /* POLARSSL_X509_CRT_PARSE_C */
1914 
1915  return ( 3 );
1916  }
1917  else
1918  if( strcmp( params[0], "x509_crl_info" ) == 0 )
1919  {
1920  #ifdef POLARSSL_FS_IO
1921  #ifdef POLARSSL_X509_CRL_PARSE_C
1922 
1923  char *param1 = params[1];
1924  char *param2 = params[2];
1925 
1926  if( cnt != 3 )
1927  {
1928  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 3 );
1929  return( 2 );
1930  }
1931 
1932  if( verify_string( &param1 ) != 0 ) return( 2 );
1933  if( verify_string( &param2 ) != 0 ) return( 2 );
1934 
1935  test_suite_x509_crl_info( param1, param2 );
1936  return ( 0 );
1937  #endif /* POLARSSL_FS_IO */
1938  #endif /* POLARSSL_X509_CRL_PARSE_C */
1939 
1940  return ( 3 );
1941  }
1942  else
1943  if( strcmp( params[0], "x509_csr_info" ) == 0 )
1944  {
1945  #ifdef POLARSSL_FS_IO
1946  #ifdef POLARSSL_X509_CSR_PARSE_C
1947 
1948  char *param1 = params[1];
1949  char *param2 = params[2];
1950 
1951  if( cnt != 3 )
1952  {
1953  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 3 );
1954  return( 2 );
1955  }
1956 
1957  if( verify_string( &param1 ) != 0 ) return( 2 );
1958  if( verify_string( &param2 ) != 0 ) return( 2 );
1959 
1960  test_suite_x509_csr_info( param1, param2 );
1961  return ( 0 );
1962  #endif /* POLARSSL_FS_IO */
1963  #endif /* POLARSSL_X509_CSR_PARSE_C */
1964 
1965  return ( 3 );
1966  }
1967  else
1968  if( strcmp( params[0], "x509_verify" ) == 0 )
1969  {
1970  #ifdef POLARSSL_FS_IO
1971  #ifdef POLARSSL_X509_CRT_PARSE_C
1972  #ifdef POLARSSL_X509_CRL_PARSE_C
1973 
1974  char *param1 = params[1];
1975  char *param2 = params[2];
1976  char *param3 = params[3];
1977  char *param4 = params[4];
1978  int param5;
1979  int param6;
1980  char *param7 = params[7];
1981 
1982  if( cnt != 8 )
1983  {
1984  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 8 );
1985  return( 2 );
1986  }
1987 
1988  if( verify_string( &param1 ) != 0 ) return( 2 );
1989  if( verify_string( &param2 ) != 0 ) return( 2 );
1990  if( verify_string( &param3 ) != 0 ) return( 2 );
1991  if( verify_string( &param4 ) != 0 ) return( 2 );
1992  if( verify_int( params[5], &param5 ) != 0 ) return( 2 );
1993  if( verify_int( params[6], &param6 ) != 0 ) return( 2 );
1994  if( verify_string( &param7 ) != 0 ) return( 2 );
1995 
1996  test_suite_x509_verify( param1, param2, param3, param4, param5, param6, param7 );
1997  return ( 0 );
1998  #endif /* POLARSSL_FS_IO */
1999  #endif /* POLARSSL_X509_CRT_PARSE_C */
2000  #endif /* POLARSSL_X509_CRL_PARSE_C */
2001 
2002  return ( 3 );
2003  }
2004  else
2005  if( strcmp( params[0], "x509_dn_gets" ) == 0 )
2006  {
2007  #ifdef POLARSSL_FS_IO
2008  #ifdef POLARSSL_X509_CRT_C
2009 
2010  char *param1 = params[1];
2011  char *param2 = params[2];
2012  char *param3 = params[3];
2013 
2014  if( cnt != 4 )
2015  {
2016  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 4 );
2017  return( 2 );
2018  }
2019 
2020  if( verify_string( &param1 ) != 0 ) return( 2 );
2021  if( verify_string( &param2 ) != 0 ) return( 2 );
2022  if( verify_string( &param3 ) != 0 ) return( 2 );
2023 
2024  test_suite_x509_dn_gets( param1, param2, param3 );
2025  return ( 0 );
2026  #endif /* POLARSSL_FS_IO */
2027  #endif /* POLARSSL_X509_CRT_C */
2028 
2029  return ( 3 );
2030  }
2031  else
2032  if( strcmp( params[0], "x509_time_expired" ) == 0 )
2033  {
2034  #ifdef POLARSSL_FS_IO
2035  #ifdef POLARSSL_X509_CRT_C
2036 
2037  char *param1 = params[1];
2038  char *param2 = params[2];
2039  int param3;
2040 
2041  if( cnt != 4 )
2042  {
2043  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 4 );
2044  return( 2 );
2045  }
2046 
2047  if( verify_string( &param1 ) != 0 ) return( 2 );
2048  if( verify_string( &param2 ) != 0 ) return( 2 );
2049  if( verify_int( params[3], &param3 ) != 0 ) return( 2 );
2050 
2051  test_suite_x509_time_expired( param1, param2, param3 );
2052  return ( 0 );
2053  #endif /* POLARSSL_FS_IO */
2054  #endif /* POLARSSL_X509_CRT_C */
2055 
2056  return ( 3 );
2057  }
2058  else
2059  if( strcmp( params[0], "x509_time_future" ) == 0 )
2060  {
2061  #ifdef POLARSSL_FS_IO
2062  #ifdef POLARSSL_X509_CRT_C
2063 
2064  char *param1 = params[1];
2065  char *param2 = params[2];
2066  int param3;
2067 
2068  if( cnt != 4 )
2069  {
2070  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 4 );
2071  return( 2 );
2072  }
2073 
2074  if( verify_string( &param1 ) != 0 ) return( 2 );
2075  if( verify_string( &param2 ) != 0 ) return( 2 );
2076  if( verify_int( params[3], &param3 ) != 0 ) return( 2 );
2077 
2078  test_suite_x509_time_future( param1, param2, param3 );
2079  return ( 0 );
2080  #endif /* POLARSSL_FS_IO */
2081  #endif /* POLARSSL_X509_CRT_C */
2082 
2083  return ( 3 );
2084  }
2085  else
2086  if( strcmp( params[0], "x509parse_crt" ) == 0 )
2087  {
2088  #ifdef POLARSSL_X509_CRT_PARSE_C
2089 
2090  char *param1 = params[1];
2091  char *param2 = params[2];
2092  int param3;
2093 
2094  if( cnt != 4 )
2095  {
2096  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 4 );
2097  return( 2 );
2098  }
2099 
2100  if( verify_string( &param1 ) != 0 ) return( 2 );
2101  if( verify_string( &param2 ) != 0 ) return( 2 );
2102  if( verify_int( params[3], &param3 ) != 0 ) return( 2 );
2103 
2104  test_suite_x509parse_crt( param1, param2, param3 );
2105  return ( 0 );
2106  #endif /* POLARSSL_X509_CRT_PARSE_C */
2107 
2108  return ( 3 );
2109  }
2110  else
2111  if( strcmp( params[0], "x509parse_crl" ) == 0 )
2112  {
2113  #ifdef POLARSSL_X509_CRL_PARSE_C
2114 
2115  char *param1 = params[1];
2116  char *param2 = params[2];
2117  int param3;
2118 
2119  if( cnt != 4 )
2120  {
2121  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 4 );
2122  return( 2 );
2123  }
2124 
2125  if( verify_string( &param1 ) != 0 ) return( 2 );
2126  if( verify_string( &param2 ) != 0 ) return( 2 );
2127  if( verify_int( params[3], &param3 ) != 0 ) return( 2 );
2128 
2129  test_suite_x509parse_crl( param1, param2, param3 );
2130  return ( 0 );
2131  #endif /* POLARSSL_X509_CRL_PARSE_C */
2132 
2133  return ( 3 );
2134  }
2135  else
2136  if( strcmp( params[0], "x509_csr_parse" ) == 0 )
2137  {
2138  #ifdef POLARSSL_X509_CSR_PARSE_C
2139 
2140  char *param1 = params[1];
2141  char *param2 = params[2];
2142  int param3;
2143 
2144  if( cnt != 4 )
2145  {
2146  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 4 );
2147  return( 2 );
2148  }
2149 
2150  if( verify_string( &param1 ) != 0 ) return( 2 );
2151  if( verify_string( &param2 ) != 0 ) return( 2 );
2152  if( verify_int( params[3], &param3 ) != 0 ) return( 2 );
2153 
2154  test_suite_x509_csr_parse( param1, param2, param3 );
2155  return ( 0 );
2156  #endif /* POLARSSL_X509_CSR_PARSE_C */
2157 
2158  return ( 3 );
2159  }
2160  else
2161  if( strcmp( params[0], "x509_crt_parse_path" ) == 0 )
2162  {
2163  #ifdef POLARSSL_FS_IO
2164  #ifdef POLARSSL_X509_CRT_PARSE_C
2165 
2166  char *param1 = params[1];
2167  int param2;
2168  int param3;
2169 
2170  if( cnt != 4 )
2171  {
2172  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 4 );
2173  return( 2 );
2174  }
2175 
2176  if( verify_string( &param1 ) != 0 ) return( 2 );
2177  if( verify_int( params[2], &param2 ) != 0 ) return( 2 );
2178  if( verify_int( params[3], &param3 ) != 0 ) return( 2 );
2179 
2180  test_suite_x509_crt_parse_path( param1, param2, param3 );
2181  return ( 0 );
2182  #endif /* POLARSSL_FS_IO */
2183  #endif /* POLARSSL_X509_CRT_PARSE_C */
2184 
2185  return ( 3 );
2186  }
2187  else
2188  if( strcmp( params[0], "x509_oid_desc" ) == 0 )
2189  {
2190  #ifdef POLARSSL_X509_USE_C
2191 
2192  char *param1 = params[1];
2193  char *param2 = params[2];
2194 
2195  if( cnt != 3 )
2196  {
2197  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 3 );
2198  return( 2 );
2199  }
2200 
2201  if( verify_string( &param1 ) != 0 ) return( 2 );
2202  if( verify_string( &param2 ) != 0 ) return( 2 );
2203 
2204  test_suite_x509_oid_desc( param1, param2 );
2205  return ( 0 );
2206  #endif /* POLARSSL_X509_USE_C */
2207 
2208  return ( 3 );
2209  }
2210  else
2211  if( strcmp( params[0], "x509_oid_numstr" ) == 0 )
2212  {
2213  #ifdef POLARSSL_X509_USE_C
2214 
2215  char *param1 = params[1];
2216  char *param2 = params[2];
2217  int param3;
2218  int param4;
2219 
2220  if( cnt != 5 )
2221  {
2222  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 5 );
2223  return( 2 );
2224  }
2225 
2226  if( verify_string( &param1 ) != 0 ) return( 2 );
2227  if( verify_string( &param2 ) != 0 ) return( 2 );
2228  if( verify_int( params[3], &param3 ) != 0 ) return( 2 );
2229  if( verify_int( params[4], &param4 ) != 0 ) return( 2 );
2230 
2231  test_suite_x509_oid_numstr( param1, param2, param3, param4 );
2232  return ( 0 );
2233  #endif /* POLARSSL_X509_USE_C */
2234 
2235  return ( 3 );
2236  }
2237  else
2238  if( strcmp( params[0], "x509_check_key_usage" ) == 0 )
2239  {
2240  #ifdef POLARSSL_FS_IO
2241  #ifdef POLARSSL_X509_CRT_PARSE_C
2242  #ifdef POLARSSL_X509_CHECK_KEY_USAGE
2243 
2244  char *param1 = params[1];
2245  int param2;
2246  int param3;
2247 
2248  if( cnt != 4 )
2249  {
2250  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 4 );
2251  return( 2 );
2252  }
2253 
2254  if( verify_string( &param1 ) != 0 ) return( 2 );
2255  if( verify_int( params[2], &param2 ) != 0 ) return( 2 );
2256  if( verify_int( params[3], &param3 ) != 0 ) return( 2 );
2257 
2258  test_suite_x509_check_key_usage( param1, param2, param3 );
2259  return ( 0 );
2260  #endif /* POLARSSL_FS_IO */
2261  #endif /* POLARSSL_X509_CRT_PARSE_C */
2262  #endif /* POLARSSL_X509_CHECK_KEY_USAGE */
2263 
2264  return ( 3 );
2265  }
2266  else
2267  if( strcmp( params[0], "x509_check_extended_key_usage" ) == 0 )
2268  {
2269  #ifdef POLARSSL_FS_IO
2270  #ifdef POLARSSL_X509_CRT_PARSE_C
2271  #ifdef POLARSSL_X509_CHECK_EXTENDED_KEY_USAGE
2272 
2273  char *param1 = params[1];
2274  char *param2 = params[2];
2275  int param3;
2276 
2277  if( cnt != 4 )
2278  {
2279  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 4 );
2280  return( 2 );
2281  }
2282 
2283  if( verify_string( &param1 ) != 0 ) return( 2 );
2284  if( verify_string( &param2 ) != 0 ) return( 2 );
2285  if( verify_int( params[3], &param3 ) != 0 ) return( 2 );
2286 
2287  test_suite_x509_check_extended_key_usage( param1, param2, param3 );
2288  return ( 0 );
2289  #endif /* POLARSSL_FS_IO */
2290  #endif /* POLARSSL_X509_CRT_PARSE_C */
2291  #endif /* POLARSSL_X509_CHECK_EXTENDED_KEY_USAGE */
2292 
2293  return ( 3 );
2294  }
2295  else
2296  if( strcmp( params[0], "x509_parse_rsassa_pss_params" ) == 0 )
2297  {
2298  #ifdef POLARSSL_X509_CRT_PARSE_C
2299  #ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
2300 
2301  char *param1 = params[1];
2302  int param2;
2303  int param3;
2304  int param4;
2305  int param5;
2306  int param6;
2307 
2308  if( cnt != 7 )
2309  {
2310  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 7 );
2311  return( 2 );
2312  }
2313 
2314  if( verify_string( &param1 ) != 0 ) return( 2 );
2315  if( verify_int( params[2], &param2 ) != 0 ) return( 2 );
2316  if( verify_int( params[3], &param3 ) != 0 ) return( 2 );
2317  if( verify_int( params[4], &param4 ) != 0 ) return( 2 );
2318  if( verify_int( params[5], &param5 ) != 0 ) return( 2 );
2319  if( verify_int( params[6], &param6 ) != 0 ) return( 2 );
2320 
2321  test_suite_x509_parse_rsassa_pss_params( param1, param2, param3, param4, param5, param6 );
2322  return ( 0 );
2323  #endif /* POLARSSL_X509_CRT_PARSE_C */
2324  #endif /* POLARSSL_X509_RSASSA_PSS_SUPPORT */
2325 
2326  return ( 3 );
2327  }
2328  else
2329  if( strcmp( params[0], "x509_selftest" ) == 0 )
2330  {
2331  #ifdef POLARSSL_X509_CRT_PARSE_C
2332  #ifdef POLARSSL_SELF_TEST
2333 
2334 
2335  if( cnt != 1 )
2336  {
2337  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 1 );
2338  return( 2 );
2339  }
2340 
2341 
2342  test_suite_x509_selftest( );
2343  return ( 0 );
2344  #endif /* POLARSSL_X509_CRT_PARSE_C */
2345  #endif /* POLARSSL_SELF_TEST */
2346 
2347  return ( 3 );
2348  }
2349  else
2350 
2351  {
2352  fprintf( stdout, "FAILED\nSkipping unknown test function '%s'\n", params[0] );
2353  fflush( stdout );
2354  return( 1 );
2355  }
2356 #else
2357  return( 3 );
2358 #endif
2359  return( ret );
2360 }
2361 
2362 int get_line( FILE *f, char *buf, size_t len )
2363 {
2364  char *ret;
2365 
2366  ret = fgets( buf, len, f );
2367  if( ret == NULL )
2368  return( -1 );
2369 
2370  if( strlen( buf ) && buf[strlen(buf) - 1] == '\n' )
2371  buf[strlen(buf) - 1] = '\0';
2372  if( strlen( buf ) && buf[strlen(buf) - 1] == '\r' )
2373  buf[strlen(buf) - 1] = '\0';
2374 
2375  return( 0 );
2376 }
2377 
2378 int parse_arguments( char *buf, size_t len, char *params[50] )
2379 {
2380  int cnt = 0, i;
2381  char *cur = buf;
2382  char *p = buf, *q;
2383 
2384  params[cnt++] = cur;
2385 
2386  while( *p != '\0' && p < buf + len )
2387  {
2388  if( *p == '\\' )
2389  {
2390  p++;
2391  p++;
2392  continue;
2393  }
2394  if( *p == ':' )
2395  {
2396  if( p + 1 < buf + len )
2397  {
2398  cur = p + 1;
2399  params[cnt++] = cur;
2400  }
2401  *p = '\0';
2402  }
2403 
2404  p++;
2405  }
2406 
2407  // Replace newlines, question marks and colons in strings
2408  for( i = 0; i < cnt; i++ )
2409  {
2410  p = params[i];
2411  q = params[i];
2412 
2413  while( *p != '\0' )
2414  {
2415  if( *p == '\\' && *(p + 1) == 'n' )
2416  {
2417  p += 2;
2418  *(q++) = '\n';
2419  }
2420  else if( *p == '\\' && *(p + 1) == ':' )
2421  {
2422  p += 2;
2423  *(q++) = ':';
2424  }
2425  else if( *p == '\\' && *(p + 1) == '?' )
2426  {
2427  p += 2;
2428  *(q++) = '?';
2429  }
2430  else
2431  *(q++) = *(p++);
2432  }
2433  *q = '\0';
2434  }
2435 
2436  return( cnt );
2437 }
2438 
2439 int main()
2440 {
2441  int ret, i, cnt, total_errors = 0, total_tests = 0, total_skipped = 0;
2442  const char *filename = "/tmp/B.43ee1cd1-d3e3-4a1b-8449-a820e9bbf54f/BUILD/polarssl-1.3.8/tests/suites/test_suite_x509parse.data";
2443  FILE *file;
2444  char buf[5000];
2445  char *params[50];
2446 
2447 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
2448  unsigned char alloc_buf[1000000];
2449  memory_buffer_alloc_init( alloc_buf, sizeof(alloc_buf) );
2450 #endif
2451 
2452  file = fopen( filename, "r" );
2453  if( file == NULL )
2454  {
2455  fprintf( stderr, "Failed to open\n" );
2456  return( 1 );
2457  }
2458 
2459  while( !feof( file ) )
2460  {
2461  int skip = 0;
2462 
2463  if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
2464  break;
2465  fprintf( stdout, "%s%.66s", test_errors ? "\n" : "", buf );
2466  fprintf( stdout, " " );
2467  for( i = strlen( buf ) + 1; i < 67; i++ )
2468  fprintf( stdout, "." );
2469  fprintf( stdout, " " );
2470  fflush( stdout );
2471 
2472  total_tests++;
2473 
2474  if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
2475  break;
2476  cnt = parse_arguments( buf, strlen(buf), params );
2477 
2478  if( strcmp( params[0], "depends_on" ) == 0 )
2479  {
2480  for( i = 1; i < cnt; i++ )
2481  if( dep_check( params[i] ) != 0 )
2482  skip = 1;
2483 
2484  if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
2485  break;
2486  cnt = parse_arguments( buf, strlen(buf), params );
2487  }
2488 
2489  if( skip == 0 )
2490  {
2491  test_errors = 0;
2492  ret = dispatch_test( cnt, params );
2493  }
2494 
2495  if( skip == 1 || ret == 3 )
2496  {
2497  total_skipped++;
2498  fprintf( stdout, "----\n" );
2499  fflush( stdout );
2500  }
2501  else if( ret == 0 && test_errors == 0 )
2502  {
2503  fprintf( stdout, "PASS\n" );
2504  fflush( stdout );
2505  }
2506  else if( ret == 2 )
2507  {
2508  fprintf( stderr, "FAILED: FATAL PARSE ERROR\n" );
2509  fclose(file);
2510  exit( 2 );
2511  }
2512  else
2513  total_errors++;
2514 
2515  if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
2516  break;
2517  if( strlen(buf) != 0 )
2518  {
2519  fprintf( stderr, "Should be empty %d\n", (int) strlen(buf) );
2520  return( 1 );
2521  }
2522  }
2523  fclose(file);
2524 
2525  fprintf( stdout, "\n----------------------------------------------------------------------------\n\n");
2526  if( total_errors == 0 )
2527  fprintf( stdout, "PASSED" );
2528  else
2529  fprintf( stdout, "FAILED" );
2530 
2531  fprintf( stdout, " (%d / %d tests (%d skipped))\n",
2532  total_tests - total_errors, total_tests, total_skipped );
2533 
2534 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
2535 #if defined(POLARSSL_MEMORY_DEBUG)
2536  memory_buffer_alloc_status();
2537 #endif
2539 #endif
2540 
2541  return( total_errors != 0 );
2542 }
2543 
2544 
#define POLARSSL_ERR_PK_INVALID_ALG
The algorithm tag or value is invalid.
Definition: pk.h:61
int x509_time_expired(const x509_time *time)
Check a given x509_time against the system time and check if it is not expired.
#define POLARSSL_ERR_PK_KEY_INVALID_FORMAT
Invalid key tag or value.
Definition: pk.h:56
int x509_csr_parse_der(x509_csr *csr, const unsigned char *buf, size_t buflen)
Load a Certificate Signing Request (CSR) in DER format.
void x509_crl_init(x509_crl *crl)
Initialize a CRL (chain)
int main()
Memory allocation layer (Deprecated to platform layer)
#define ASN1_OID
Definition: asn1.h:80
#define POLARSSL_ERR_X509_INVALID_DATE
The date tag or value is invalid.
Definition: x509.h:59
#define BADCERT_OTHER
Other reason (can be used by verify callback)
Definition: x509.h:84
Info structure for the pseudo random function.
x509_buf raw
The raw certificate data (DER).
Definition: x509_crt.h:59
#define POLARSSL_ERR_ASN1_LENGTH_MISMATCH
Actual length differs from expected length.
Definition: asn1.h:57
void memory_buffer_alloc_free(void)
Free the mutex for thread-safety and clear remaining memory.
static void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
int get_line(FILE *f, char *buf, size_t len)
#define POLARSSL_ERR_X509_INVALID_FORMAT
The CRT/CRL/CSR format is invalid, e.g.
Definition: x509.h:54
const char * x509_oid_get_description(x509_buf *oid)
Give an known OID, return its descriptive string.
int x509_crt_parse(x509_crt *chain, const unsigned char *buf, size_t buflen)
Parse one or more certificates and add them to the chained list.
#define ASN1_SEQUENCE
Definition: asn1.h:82
static int rnd_pseudo_rand(void *rng_state, unsigned char *output, size_t len)
This function returns random based on a pseudo random function.
void x509_crt_free(x509_crt *crt)
Unallocate all certificate data.
Configuration options (set of defines)
#define POLARSSL_ERR_X509_UNKNOWN_SIG_ALG
Signature algorithm (oid) is unsupported.
Definition: x509.h:63
#define POLARSSL_ERR_ASN1_INVALID_DATA
Data is invalid.
Definition: asn1.h:58
#define ASN1_CONSTRUCTED
Definition: asn1.h:92
PolarSSL Platform abstraction layer.
#define POLARSSL_ERR_X509_INVALID_SIGNATURE
The signature tag or value invalid.
Definition: x509.h:60
#define polarssl_malloc
static int test_assert(int correct, const char *test)
#define BADCRL_NOT_TRUSTED
CRL is not correctly signed by the trusted CA.
Definition: x509.h:80
#define POLARSSL_ERR_ASN1_INVALID_LENGTH
Error when trying to determine the length or invalid length.
Definition: asn1.h:56
#define POLARSSL_ERR_X509_UNKNOWN_VERSION
CRT/CRL/CSR has an unsupported version number.
Definition: x509.h:62
static unsigned char * zero_alloc(size_t len)
Allocate and zeroize a buffer.
int x509_crl_parse_file(x509_crl *chain, const char *path)
Load one or more CRLs and add them to the chained list.
Object Identifier (OID) database.
int x509_crl_parse(x509_crl *chain, const unsigned char *buf, size_t buflen)
Parse one or more CRLs and add them to the chained list.
int x509_crl_info(char *buf, size_t size, const char *prefix, const x509_crl *crl)
Returns an informational string about the CRL.
struct _x509_crt * next
Next certificate in the CA-chain.
Definition: x509_crt.h:98
int x509_crt_check_key_usage(const x509_crt *crt, int usage)
Check usage of certificate against keyUsage extension.
md_type_t
Definition: md.h:51
int memory_buffer_alloc_init(unsigned char *buf, size_t len)
Initialize use of stack-based memory allocator.
#define TEST_ASSERT(TEST)
#define BADCERT_EXPIRED
The certificate validity has expired.
Definition: x509.h:76
#define BADCERT_FUTURE
The certificate validity starts in the future.
Definition: x509.h:85
static int test_errors
#define POLARSSL_ERR_X509_CERT_VERIFY_FAILED
Certificate verification failed, e.g.
Definition: x509.h:65
Container for an X.509 certificate.
Definition: x509_crt.h:57
#define POLARSSL_ERR_OID_NOT_FOUND
OID is not found.
Definition: oid.h:50
Privacy Enhanced Mail (PEM) decoding.
x509_time valid_from
Start time of certificate validity.
Definition: x509_crt.h:72
int x509_dn_gets(char *buf, size_t size, const x509_name *dn)
Store the certificate DN in printable form into buf; no more than size characters will be written...
void x509_crl_free(x509_crl *crl)
Unallocate all CRL data.
static int rnd_zero_rand(void *rng_state, unsigned char *output, size_t len)
This function only returns zeros.
void x509_crt_init(x509_crt *crt)
Initialize a certificate (chain)
unsigned char * p
ASN1 data, e.g.
Definition: asn1.h:128
x509_name subject
The parsed subject data (named information object).
Definition: x509_crt.h:70
X.509 certificate signing request parsing and writing.
int x509_crt_verify(x509_crt *crt, x509_crt *trust_ca, x509_crl *ca_crl, const char *cn, int *flags, int(*f_vrfy)(void *, x509_crt *, int, int *), void *p_vrfy)
Verify the certificate signature.
int x509_oid_get_numeric_string(char *buf, size_t size, x509_buf *oid)
Give an OID, return a string version of its OID number.
void x509_csr_free(x509_csr *csr)
Unallocate all CSR data.
static unsigned char * unhexify_alloc(const char *ibuf, size_t *olen)
Allocate and fill a buffer from hex data.
x509_time valid_to
End time of certificate validity.
Definition: x509_crt.h:73
int dispatch_test(int cnt, char *params[50])
X.509 certificate parsing and writing.
#define POLARSSL_ERR_X509_INVALID_ALG
The algorithm tag or value is invalid.
Definition: x509.h:57
int tag
ASN1 type, e.g.
Definition: asn1.h:126
#define KU_KEY_AGREEMENT
Definition: x509.h:97
#define POLARSSL_ERR_ASN1_OUT_OF_DATA
Out of data when parsing an ASN1 data structure.
Definition: asn1.h:54
int x509_get_rsassa_pss_params(const x509_buf *params, md_type_t *md_alg, md_type_t *mgf_md, int *salt_len)
int parse_arguments(char *buf, size_t len, char *params[50])
#define BADCERT_NOT_TRUSTED
The certificate is not correctly signed by the trusted CA.
Definition: x509.h:79
#define polarssl_free
static int unhexify(unsigned char *obuf, const char *ibuf)
Type-length-value structure that allows for ASN1 using DER.
Definition: asn1.h:124
size_t len
ASN1 length, e.g.
Definition: asn1.h:127
#define BADCRL_FUTURE
The CRL is from the future.
Definition: x509.h:86
int verify_string(char **str)
x509_name issuer
The parsed issuer data (named information object).
Definition: x509_crt.h:69
#define POLARSSL_ERR_X509_INVALID_NAME
The name tag or value is invalid.
Definition: x509.h:58
static int rnd_buffer_rand(void *rng_state, unsigned char *output, size_t len)
This function returns random based on a buffer it receives.
#define BADCERT_REVOKED
The certificate has been revoked (is on a CRL).
Definition: x509.h:77
#define BADCRL_EXPIRED
CRL is expired.
Definition: x509.h:81
#define POLARSSL_ERR_X509_FEATURE_UNAVAILABLE
Unavailable feature, e.g.
Definition: x509.h:52
X.509 certificate revocation list parsing.
#define KU_DIGITAL_SIGNATURE
Definition: x509.h:93
#define POLARSSL_ERR_X509_INVALID_VERSION
The CRT/CRL/CSR version element is invalid.
Definition: x509.h:55
unsigned char * buf
Certificate revocation list structure.
Definition: x509_crl.h:73
int x509_csr_info(char *buf, size_t size, const char *prefix, const x509_csr *csr)
Returns an informational string about the CSR.
#define POLARSSL_ERR_X509_INVALID_EXTENSIONS
The extension tag or value is invalid.
Definition: x509.h:61
#define POLARSSL_ERR_OID_BUF_TOO_SMALL
output buffer is too small
Definition: oid.h:51
int dep_check(char *str)
int x509_time_future(const x509_time *time)
Check a given x509_time against the system time and check if it is not from the future.
int x509_crt_parse_path(x509_crt *chain, const char *path)
Load one or more certificate files from a path and add them to the chained list.
Certificate Signing Request (CSR) structure.
Definition: x509_csr.h:54
#define POLARSSL_ERR_X509_BAD_INPUT_DATA
Input invalid.
Definition: x509.h:67
#define KU_KEY_CERT_SIGN
Definition: x509.h:98
#define PUT_UINT32_BE(n, b, i)
#define BADCERT_CN_MISMATCH
The certificate Common Name (CN) does not match with the expected CN.
Definition: x509.h:78
int x509_csr_parse_file(x509_csr *csr, const char *path)
Load a Certificate Signing Request (CSR)
int x509_self_test(int verbose)
Checkup routine.
int verify_int(char *str, int *value)
int x509_crt_info(char *buf, size_t size, const char *prefix, const x509_crt *crt)
Returns an informational string about the certificate.
void x509_csr_init(x509_csr *csr)
Initialize a CSR.
#define POLARSSL_ERR_X509_INVALID_SERIAL
The serial tag or value is invalid.
Definition: x509.h:56
int x509_crt_check_extended_key_usage(const x509_crt *crt, const char *usage_oid, size_t usage_len)
Check usage of certificate against extentedJeyUsage.
#define POLARSSL_ERR_PK_INVALID_PUBKEY
The pubkey tag or value is invalid (only RSA and EC are supported).
Definition: pk.h:60
#define POLARSSL_ERR_ASN1_UNEXPECTED_TAG
ASN1 tag was of an unexpected value.
Definition: asn1.h:55
#define KU_KEY_ENCIPHERMENT
Definition: x509.h:95
#define POLARSSL_ERR_PK_UNKNOWN_PK_ALG
Key algorithm is unsupported (only RSA and EC are supported).
Definition: pk.h:57
static int rnd_std_rand(void *rng_state, unsigned char *output, size_t len)
This function just returns data from rand().
#define POLARSSL_ERR_X509_SIG_MISMATCH
Signature algorithms do not match.
Definition: x509.h:64
int x509_crt_parse_file(x509_crt *chain, const char *path)
Load one or more certificates and add them to the chained list.
#define KU_CRL_SIGN
Definition: x509.h:99