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