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  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_SERIAL + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
422  {
424  return( 0 );
425  }
426 #endif // POLARSSL_X509_CRT_PARSE_C
427 #ifdef POLARSSL_X509_CRT_PARSE_C
428  if( strcmp( str, "POLARSSL_ERR_PK_INVALID_PUBKEY + POLARSSL_ERR_ASN1_INVALID_DATA" ) == 0 )
429  {
431  return( 0 );
432  }
433 #endif // POLARSSL_X509_CRT_PARSE_C
434 #ifdef POLARSSL_X509_CSR_PARSE_C
435  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
436  {
438  return( 0 );
439  }
440 #endif // POLARSSL_X509_CSR_PARSE_C
441 #ifdef POLARSSL_X509_CRL_PARSE_C
442  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
443  {
445  return( 0 );
446  }
447 #endif // POLARSSL_X509_CRL_PARSE_C
448 #ifdef POLARSSL_X509_CRT_PARSE_C
449  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
450  {
452  return( 0 );
453  }
454 #endif // POLARSSL_X509_CRT_PARSE_C
455 #ifdef POLARSSL_X509_CRT_PARSE_C
456 #ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
457  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
458  {
460  return( 0 );
461  }
462 #endif // POLARSSL_X509_CRT_PARSE_C
463 #endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
464 #ifdef POLARSSL_X509_CRT_PARSE_C
465  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_NAME + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
466  {
468  return( 0 );
469  }
470 #endif // POLARSSL_X509_CRT_PARSE_C
471 #ifdef POLARSSL_X509_CSR_PARSE_C
472  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_NAME + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
473  {
475  return( 0 );
476  }
477 #endif // POLARSSL_X509_CSR_PARSE_C
478 #ifdef POLARSSL_X509_CRL_PARSE_C
479  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_NAME + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
480  {
482  return( 0 );
483  }
484 #endif // POLARSSL_X509_CRL_PARSE_C
485 #ifdef POLARSSL_FS_IO
486 #ifdef POLARSSL_X509_CRT_PARSE_C
487 #ifdef POLARSSL_X509_CRL_PARSE_C
488  if( strcmp( str, "BADCERT_NOT_TRUSTED" ) == 0 )
489  {
490  *value = ( BADCERT_NOT_TRUSTED );
491  return( 0 );
492  }
493 #endif // POLARSSL_FS_IO
494 #endif // POLARSSL_X509_CRT_PARSE_C
495 #endif // POLARSSL_X509_CRL_PARSE_C
496 #ifdef POLARSSL_X509_CSR_PARSE_C
497  if( strcmp( str, "POLARSSL_ERR_PK_KEY_INVALID_FORMAT + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
498  {
500  return( 0 );
501  }
502 #endif // POLARSSL_X509_CSR_PARSE_C
503 #ifdef POLARSSL_X509_CRT_PARSE_C
504  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_VERSION + POLARSSL_ERR_ASN1_INVALID_LENGTH" ) == 0 )
505  {
507  return( 0 );
508  }
509 #endif // POLARSSL_X509_CRT_PARSE_C
510 #ifdef POLARSSL_FS_IO
511 #ifdef POLARSSL_X509_CRT_PARSE_C
512 #ifdef POLARSSL_X509_CRL_PARSE_C
513  if( strcmp( str, "BADCRL_NOT_TRUSTED" ) == 0 )
514  {
515  *value = ( BADCRL_NOT_TRUSTED );
516  return( 0 );
517  }
518 #endif // POLARSSL_FS_IO
519 #endif // POLARSSL_X509_CRT_PARSE_C
520 #endif // POLARSSL_X509_CRL_PARSE_C
521 #ifdef POLARSSL_X509_CSR_PARSE_C
522  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
523  {
525  return( 0 );
526  }
527 #endif // POLARSSL_X509_CSR_PARSE_C
528 #ifdef POLARSSL_X509_CRL_PARSE_C
529  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
530  {
532  return( 0 );
533  }
534 #endif // POLARSSL_X509_CRL_PARSE_C
535 #ifdef POLARSSL_X509_CRT_PARSE_C
536  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
537  {
539  return( 0 );
540  }
541 #endif // POLARSSL_X509_CRT_PARSE_C
542 #ifdef POLARSSL_X509_CRT_PARSE_C
543  if( strcmp( str, "POLARSSL_ERR_PK_KEY_INVALID_FORMAT + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
544  {
546  return( 0 );
547  }
548 #endif // POLARSSL_X509_CRT_PARSE_C
549 #ifdef POLARSSL_X509_CSR_PARSE_C
550  if( strcmp( str, "POLARSSL_ERR_PK_KEY_INVALID_FORMAT + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
551  {
553  return( 0 );
554  }
555 #endif // POLARSSL_X509_CSR_PARSE_C
556 #ifdef POLARSSL_FS_IO
557 #ifdef POLARSSL_X509_CRT_PARSE_C
558 #ifdef POLARSSL_X509_CHECK_KEY_USAGE
559  if( strcmp( str, "KU_KEY_CERT_SIGN" ) == 0 )
560  {
561  *value = ( KU_KEY_CERT_SIGN );
562  return( 0 );
563  }
564 #endif // POLARSSL_FS_IO
565 #endif // POLARSSL_X509_CRT_PARSE_C
566 #endif // POLARSSL_X509_CHECK_KEY_USAGE
567 #ifdef POLARSSL_X509_CRL_PARSE_C
568  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_DATE + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
569  {
571  return( 0 );
572  }
573 #endif // POLARSSL_X509_CRL_PARSE_C
574 #ifdef POLARSSL_X509_CRT_PARSE_C
575  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_DATE + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
576  {
578  return( 0 );
579  }
580 #endif // POLARSSL_X509_CRT_PARSE_C
581 #ifdef POLARSSL_X509_CRT_PARSE_C
582 #ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
583  if( strcmp( str, "POLARSSL_MD_SHA256" ) == 0 )
584  {
585  *value = ( POLARSSL_MD_SHA256 );
586  return( 0 );
587  }
588 #endif // POLARSSL_X509_CRT_PARSE_C
589 #endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
590 #ifdef POLARSSL_X509_CRT_PARSE_C
591  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_VERSION + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
592  {
594  return( 0 );
595  }
596 #endif // POLARSSL_X509_CRT_PARSE_C
597 #ifdef POLARSSL_X509_CRT_PARSE_C
598  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_DATE + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
599  {
601  return( 0 );
602  }
603 #endif // POLARSSL_X509_CRT_PARSE_C
604 #ifdef POLARSSL_FS_IO
605 #ifdef POLARSSL_X509_CRT_PARSE_C
606 #ifdef POLARSSL_X509_CRL_PARSE_C
607  if( strcmp( str, "BADCERT_REVOKED | BADCRL_EXPIRED | BADCERT_CN_MISMATCH" ) == 0 )
608  {
610  return( 0 );
611  }
612 #endif // POLARSSL_FS_IO
613 #endif // POLARSSL_X509_CRT_PARSE_C
614 #endif // POLARSSL_X509_CRL_PARSE_C
615 #ifdef POLARSSL_FS_IO
616 #ifdef POLARSSL_X509_CRT_PARSE_C
617 #ifdef POLARSSL_X509_CRL_PARSE_C
618  if( strcmp( str, "BADCRL_EXPIRED" ) == 0 )
619  {
620  *value = ( BADCRL_EXPIRED );
621  return( 0 );
622  }
623 #endif // POLARSSL_FS_IO
624 #endif // POLARSSL_X509_CRT_PARSE_C
625 #endif // POLARSSL_X509_CRL_PARSE_C
626 #ifdef POLARSSL_X509_CRT_PARSE_C
627  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_DATE" ) == 0 )
628  {
629  *value = ( POLARSSL_ERR_X509_INVALID_DATE );
630  return( 0 );
631  }
632 #endif // POLARSSL_X509_CRT_PARSE_C
633 #ifdef POLARSSL_X509_CRT_PARSE_C
634  if( strcmp( str, "POLARSSL_ERR_X509_UNKNOWN_SIG_ALG + POLARSSL_ERR_OID_NOT_FOUND" ) == 0 )
635  {
637  return( 0 );
638  }
639 #endif // POLARSSL_X509_CRT_PARSE_C
640 #ifdef POLARSSL_X509_CRT_PARSE_C
641 #ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
642  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG" ) == 0 )
643  {
644  *value = ( POLARSSL_ERR_X509_INVALID_ALG );
645  return( 0 );
646  }
647 #endif // POLARSSL_X509_CRT_PARSE_C
648 #endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
649 #ifdef POLARSSL_X509_CRT_PARSE_C
650  if( strcmp( str, "POLARSSL_ERR_X509_SIG_MISMATCH" ) == 0 )
651  {
652  *value = ( POLARSSL_ERR_X509_SIG_MISMATCH );
653  return( 0 );
654  }
655 #endif // POLARSSL_X509_CRT_PARSE_C
656 #ifdef POLARSSL_X509_CRL_PARSE_C
657  if( strcmp( str, "POLARSSL_ERR_X509_SIG_MISMATCH" ) == 0 )
658  {
659  *value = ( POLARSSL_ERR_X509_SIG_MISMATCH );
660  return( 0 );
661  }
662 #endif // POLARSSL_X509_CRL_PARSE_C
663 #ifdef POLARSSL_X509_CRT_PARSE_C
664  if( strcmp( str, "POLARSSL_ERR_PK_INVALID_PUBKEY + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
665  {
667  return( 0 );
668  }
669 #endif // POLARSSL_X509_CRT_PARSE_C
670 #ifdef POLARSSL_FS_IO
671 #ifdef POLARSSL_X509_CRT_PARSE_C
672 #ifdef POLARSSL_X509_CRL_PARSE_C
673  if( strcmp( str, "BADCRL_FUTURE" ) == 0 )
674  {
675  *value = ( BADCRL_FUTURE );
676  return( 0 );
677  }
678 #endif // POLARSSL_FS_IO
679 #endif // POLARSSL_X509_CRT_PARSE_C
680 #endif // POLARSSL_X509_CRL_PARSE_C
681 #ifdef POLARSSL_FS_IO
682 #ifdef POLARSSL_X509_CRT_PARSE_C
683 #ifdef POLARSSL_X509_CRL_PARSE_C
684  if( strcmp( str, "BADCERT_REVOKED | BADCRL_FUTURE" ) == 0 )
685  {
686  *value = ( BADCERT_REVOKED | BADCRL_FUTURE );
687  return( 0 );
688  }
689 #endif // POLARSSL_FS_IO
690 #endif // POLARSSL_X509_CRT_PARSE_C
691 #endif // POLARSSL_X509_CRL_PARSE_C
692 #ifdef POLARSSL_X509_CRT_PARSE_C
693 #ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
694  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_OID_NOT_FOUND" ) == 0 )
695  {
697  return( 0 );
698  }
699 #endif // POLARSSL_X509_CRT_PARSE_C
700 #endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
701 #ifdef POLARSSL_FS_IO
702 #ifdef POLARSSL_X509_CRT_PARSE_C
703 #ifdef POLARSSL_X509_CRL_PARSE_C
704  if( strcmp( str, "BADCERT_REVOKED | BADCERT_CN_MISMATCH" ) == 0 )
705  {
706  *value = ( BADCERT_REVOKED | BADCERT_CN_MISMATCH );
707  return( 0 );
708  }
709 #endif // POLARSSL_FS_IO
710 #endif // POLARSSL_X509_CRT_PARSE_C
711 #endif // POLARSSL_X509_CRL_PARSE_C
712 #ifdef POLARSSL_X509_CRT_PARSE_C
713  if( strcmp( str, "POLARSSL_ERR_PK_INVALID_ALG + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
714  {
716  return( 0 );
717  }
718 #endif // POLARSSL_X509_CRT_PARSE_C
719 #ifdef POLARSSL_FS_IO
720 #ifdef POLARSSL_X509_CRT_PARSE_C
721 #ifdef POLARSSL_X509_CRL_PARSE_C
722  if( strcmp( str, "BADCERT_OTHER" ) == 0 )
723  {
724  *value = ( BADCERT_OTHER );
725  return( 0 );
726  }
727 #endif // POLARSSL_FS_IO
728 #endif // POLARSSL_X509_CRT_PARSE_C
729 #endif // POLARSSL_X509_CRL_PARSE_C
730 #ifdef POLARSSL_FS_IO
731 #ifdef POLARSSL_X509_CRT_PARSE_C
732 #ifdef POLARSSL_X509_CHECK_KEY_USAGE
733  if( strcmp( str, "KU_KEY_CERT_SIGN|KU_CRL_SIGN" ) == 0 )
734  {
735  *value = ( KU_KEY_CERT_SIGN|KU_CRL_SIGN );
736  return( 0 );
737  }
738 #endif // POLARSSL_FS_IO
739 #endif // POLARSSL_X509_CRT_PARSE_C
740 #endif // POLARSSL_X509_CHECK_KEY_USAGE
741 #ifdef POLARSSL_X509_CRT_PARSE_C
742  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_EXTENSIONS + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
743  {
745  return( 0 );
746  }
747 #endif // POLARSSL_X509_CRT_PARSE_C
748 #ifdef POLARSSL_FS_IO
749 #ifdef POLARSSL_X509_CRT_PARSE_C
750 #ifdef POLARSSL_X509_CRL_PARSE_C
751  if( strcmp( str, "BADCERT_FUTURE" ) == 0 )
752  {
753  *value = ( BADCERT_FUTURE );
754  return( 0 );
755  }
756 #endif // POLARSSL_FS_IO
757 #endif // POLARSSL_X509_CRT_PARSE_C
758 #endif // POLARSSL_X509_CRL_PARSE_C
759 #ifdef POLARSSL_X509_CRT_PARSE_C
760 #ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
761  if( strcmp( str, "ASN1_SEQUENCE" ) == 0 )
762  {
763  *value = ( ASN1_SEQUENCE );
764  return( 0 );
765  }
766 #endif // POLARSSL_X509_CRT_PARSE_C
767 #endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
768 #ifdef POLARSSL_FS_IO
769 #ifdef POLARSSL_X509_CRT_PARSE_C
770 #ifdef POLARSSL_X509_CRL_PARSE_C
771  if( strcmp( str, "BADCERT_REVOKED" ) == 0 )
772  {
773  *value = ( BADCERT_REVOKED );
774  return( 0 );
775  }
776 #endif // POLARSSL_FS_IO
777 #endif // POLARSSL_X509_CRT_PARSE_C
778 #endif // POLARSSL_X509_CRL_PARSE_C
779 #ifdef POLARSSL_FS_IO
780 #ifdef POLARSSL_X509_CRT_PARSE_C
781 #ifdef POLARSSL_X509_CHECK_KEY_USAGE
782  if( strcmp( str, "KU_DIGITAL_SIGNATURE|KU_KEY_ENCIPHERMENT" ) == 0 )
783  {
785  return( 0 );
786  }
787 #endif // POLARSSL_FS_IO
788 #endif // POLARSSL_X509_CRT_PARSE_C
789 #endif // POLARSSL_X509_CHECK_KEY_USAGE
790 #ifdef POLARSSL_X509_CRT_PARSE_C
791  if( strcmp( str, "POLARSSL_ERR_PK_INVALID_PUBKEY" ) == 0 )
792  {
793  *value = ( POLARSSL_ERR_PK_INVALID_PUBKEY );
794  return( 0 );
795  }
796 #endif // POLARSSL_X509_CRT_PARSE_C
797 #ifdef POLARSSL_X509_CRT_PARSE_C
798  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_EXTENSIONS + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
799  {
801  return( 0 );
802  }
803 #endif // POLARSSL_X509_CRT_PARSE_C
804 #ifdef POLARSSL_X509_CRT_PARSE_C
805  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_EXTENSIONS + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
806  {
808  return( 0 );
809  }
810 #endif // POLARSSL_X509_CRT_PARSE_C
811 #ifdef POLARSSL_X509_CRT_PARSE_C
812  if( strcmp( str, "POLARSSL_ERR_ASN1_INVALID_LENGTH" ) == 0 )
813  {
815  return( 0 );
816  }
817 #endif // POLARSSL_X509_CRT_PARSE_C
818 #ifdef POLARSSL_X509_CRT_PARSE_C
819  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_SERIAL + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
820  {
822  return( 0 );
823  }
824 #endif // POLARSSL_X509_CRT_PARSE_C
825 #ifdef POLARSSL_X509_CRT_PARSE_C
826  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_NAME + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
827  {
829  return( 0 );
830  }
831 #endif // POLARSSL_X509_CRT_PARSE_C
832 #ifdef POLARSSL_X509_CSR_PARSE_C
833  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_NAME + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
834  {
836  return( 0 );
837  }
838 #endif // POLARSSL_X509_CSR_PARSE_C
839 #ifdef POLARSSL_X509_CRT_PARSE_C
840  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_SIGNATURE + POLARSSL_ERR_ASN1_INVALID_DATA" ) == 0 )
841  {
843  return( 0 );
844  }
845 #endif // POLARSSL_X509_CRT_PARSE_C
846 #ifdef POLARSSL_FS_IO
847 #ifdef POLARSSL_X509_CRT_PARSE_C
848 #ifdef POLARSSL_X509_CRL_PARSE_C
849  if( strcmp( str, "BADCERT_CN_MISMATCH" ) == 0 )
850  {
851  *value = ( BADCERT_CN_MISMATCH );
852  return( 0 );
853  }
854 #endif // POLARSSL_FS_IO
855 #endif // POLARSSL_X509_CRT_PARSE_C
856 #endif // POLARSSL_X509_CRL_PARSE_C
857 #ifdef POLARSSL_FS_IO
858 #ifdef POLARSSL_X509_CRT_PARSE_C
859 #ifdef POLARSSL_X509_CHECK_KEY_USAGE
860  if( strcmp( str, "KU_DIGITAL_SIGNATURE" ) == 0 )
861  {
862  *value = ( KU_DIGITAL_SIGNATURE );
863  return( 0 );
864  }
865 #endif // POLARSSL_FS_IO
866 #endif // POLARSSL_X509_CRT_PARSE_C
867 #endif // POLARSSL_X509_CHECK_KEY_USAGE
868 #ifdef POLARSSL_X509_CRT_PARSE_C
869 #ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
870  if( strcmp( str, "POLARSSL_MD_SHA1" ) == 0 )
871  {
872  *value = ( POLARSSL_MD_SHA1 );
873  return( 0 );
874  }
875 #endif // POLARSSL_X509_CRT_PARSE_C
876 #endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
877 #ifdef POLARSSL_X509_CRT_PARSE_C
878 #ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
879  if( strcmp( str, "ASN1_CONSTRUCTED | ASN1_SEQUENCE" ) == 0 )
880  {
881  *value = ( ASN1_CONSTRUCTED | ASN1_SEQUENCE );
882  return( 0 );
883  }
884 #endif // POLARSSL_X509_CRT_PARSE_C
885 #endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
886 #ifdef POLARSSL_FS_IO
887 #ifdef POLARSSL_X509_CRT_PARSE_C
888 #ifdef POLARSSL_X509_CRL_PARSE_C
889  if( strcmp( str, "BADCERT_CN_MISMATCH + BADCERT_NOT_TRUSTED" ) == 0 )
890  {
892  return( 0 );
893  }
894 #endif // POLARSSL_FS_IO
895 #endif // POLARSSL_X509_CRT_PARSE_C
896 #endif // POLARSSL_X509_CRL_PARSE_C
897 #ifdef POLARSSL_FS_IO
898 #ifdef POLARSSL_X509_CRT_PARSE_C
899 #ifdef POLARSSL_X509_CHECK_KEY_USAGE
900  if( strcmp( str, "POLARSSL_ERR_X509_BAD_INPUT_DATA" ) == 0 )
901  {
903  return( 0 );
904  }
905 #endif // POLARSSL_FS_IO
906 #endif // POLARSSL_X509_CRT_PARSE_C
907 #endif // POLARSSL_X509_CHECK_KEY_USAGE
908 #ifdef POLARSSL_FS_IO
909 #ifdef POLARSSL_X509_CRT_PARSE_C
910 #ifdef POLARSSL_X509_CHECK_EXTENDED_KEY_USAGE
911  if( strcmp( str, "POLARSSL_ERR_X509_BAD_INPUT_DATA" ) == 0 )
912  {
914  return( 0 );
915  }
916 #endif // POLARSSL_FS_IO
917 #endif // POLARSSL_X509_CRT_PARSE_C
918 #endif // POLARSSL_X509_CHECK_EXTENDED_KEY_USAGE
919 #ifdef POLARSSL_X509_CRT_PARSE_C
920  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
921  {
923  return( 0 );
924  }
925 #endif // POLARSSL_X509_CRT_PARSE_C
926 #ifdef POLARSSL_X509_CRT_PARSE_C
927 #ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
928  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
929  {
931  return( 0 );
932  }
933 #endif // POLARSSL_X509_CRT_PARSE_C
934 #endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
935 #ifdef POLARSSL_X509_CRL_PARSE_C
936  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
937  {
939  return( 0 );
940  }
941 #endif // POLARSSL_X509_CRL_PARSE_C
942 #ifdef POLARSSL_X509_CSR_PARSE_C
943  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
944  {
946  return( 0 );
947  }
948 #endif // POLARSSL_X509_CSR_PARSE_C
949 #ifdef POLARSSL_X509_CRT_PARSE_C
950  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_SERIAL + POLARSSL_ERR_ASN1_OUT_OF_DATA " ) == 0 )
951  {
953  return( 0 );
954  }
955 #endif // POLARSSL_X509_CRT_PARSE_C
956 #ifdef POLARSSL_X509_CRL_PARSE_C
957  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_DATE + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
958  {
960  return( 0 );
961  }
962 #endif // POLARSSL_X509_CRL_PARSE_C
963 #ifdef POLARSSL_X509_CSR_PARSE_C
964  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_VERSION + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
965  {
967  return( 0 );
968  }
969 #endif // POLARSSL_X509_CSR_PARSE_C
970 #ifdef POLARSSL_X509_CRL_PARSE_C
971  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_VERSION + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
972  {
974  return( 0 );
975  }
976 #endif // POLARSSL_X509_CRL_PARSE_C
977 #ifdef POLARSSL_X509_CRT_PARSE_C
978  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_VERSION + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
979  {
981  return( 0 );
982  }
983 #endif // POLARSSL_X509_CRT_PARSE_C
984 #ifdef POLARSSL_X509_CRT_PARSE_C
985  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_INVALID_LENGTH" ) == 0 )
986  {
988  return( 0 );
989  }
990 #endif // POLARSSL_X509_CRT_PARSE_C
991 #ifdef POLARSSL_FS_IO
992 #ifdef POLARSSL_X509_CRT_PARSE_C
993 #ifdef POLARSSL_X509_CRL_PARSE_C
994  if( strcmp( str, "BADCERT_EXPIRED" ) == 0 )
995  {
996  *value = ( BADCERT_EXPIRED );
997  return( 0 );
998  }
999 #endif // POLARSSL_FS_IO
1000 #endif // POLARSSL_X509_CRT_PARSE_C
1001 #endif // POLARSSL_X509_CRL_PARSE_C
1002 #ifdef POLARSSL_X509_CRT_PARSE_C
1003 #ifdef POLARSSL_FS_IO
1004  if( strcmp( str, "POLARSSL_ERR_PEM_INVALID_DATA + POLARSSL_ERR_BASE64_INVALID_CHARACTER" ) == 0 )
1005  {
1007  return( 0 );
1008  }
1009 #endif // POLARSSL_X509_CRT_PARSE_C
1010 #endif // POLARSSL_FS_IO
1011 #ifdef POLARSSL_X509_CRT_PARSE_C
1012  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
1013  {
1015  return( 0 );
1016  }
1017 #endif // POLARSSL_X509_CRT_PARSE_C
1018 #ifdef POLARSSL_X509_CRT_PARSE_C
1019 #ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
1020  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
1021  {
1023  return( 0 );
1024  }
1025 #endif // POLARSSL_X509_CRT_PARSE_C
1026 #endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
1027 #ifdef POLARSSL_X509_CSR_PARSE_C
1028  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
1029  {
1031  return( 0 );
1032  }
1033 #endif // POLARSSL_X509_CSR_PARSE_C
1034 #ifdef POLARSSL_X509_CRT_PARSE_C
1035  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
1036  {
1038  return( 0 );
1039  }
1040 #endif // POLARSSL_X509_CRT_PARSE_C
1041 #ifdef POLARSSL_X509_CRL_PARSE_C
1042  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
1043  {
1045  return( 0 );
1046  }
1047 #endif // POLARSSL_X509_CRL_PARSE_C
1048 #ifdef POLARSSL_X509_CSR_PARSE_C
1049  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
1050  {
1052  return( 0 );
1053  }
1054 #endif // POLARSSL_X509_CSR_PARSE_C
1055 #ifdef POLARSSL_X509_CRT_PARSE_C
1056  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
1057  {
1059  return( 0 );
1060  }
1061 #endif // POLARSSL_X509_CRT_PARSE_C
1062 #ifdef POLARSSL_X509_USE_C
1063  if( strcmp( str, "POLARSSL_ERR_OID_BUF_TOO_SMALL" ) == 0 )
1064  {
1065  *value = ( POLARSSL_ERR_OID_BUF_TOO_SMALL );
1066  return( 0 );
1067  }
1068 #endif // POLARSSL_X509_USE_C
1069 #ifdef POLARSSL_X509_CRT_PARSE_C
1070  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT" ) == 0 )
1071  {
1072  *value = ( POLARSSL_ERR_X509_INVALID_FORMAT );
1073  return( 0 );
1074  }
1075 #endif // POLARSSL_X509_CRT_PARSE_C
1076 #ifdef POLARSSL_X509_CRL_PARSE_C
1077  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT" ) == 0 )
1078  {
1079  *value = ( POLARSSL_ERR_X509_INVALID_FORMAT );
1080  return( 0 );
1081  }
1082 #endif // POLARSSL_X509_CRL_PARSE_C
1083 #ifdef POLARSSL_X509_CSR_PARSE_C
1084  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT" ) == 0 )
1085  {
1086  *value = ( POLARSSL_ERR_X509_INVALID_FORMAT );
1087  return( 0 );
1088  }
1089 #endif // POLARSSL_X509_CSR_PARSE_C
1090 #ifdef POLARSSL_FS_IO
1091 #ifdef POLARSSL_X509_CRT_PARSE_C
1092 #ifdef POLARSSL_X509_CHECK_KEY_USAGE
1093  if( strcmp( str, "KU_KEY_ENCIPHERMENT|KU_KEY_AGREEMENT" ) == 0 )
1094  {
1096  return( 0 );
1097  }
1098 #endif // POLARSSL_FS_IO
1099 #endif // POLARSSL_X509_CRT_PARSE_C
1100 #endif // POLARSSL_X509_CHECK_KEY_USAGE
1101 #ifdef POLARSSL_X509_CSR_PARSE_C
1102  if( strcmp( str, "POLARSSL_ERR_X509_UNKNOWN_SIG_ALG" ) == 0 )
1103  {
1104  *value = ( POLARSSL_ERR_X509_UNKNOWN_SIG_ALG );
1105  return( 0 );
1106  }
1107 #endif // POLARSSL_X509_CSR_PARSE_C
1108 #ifdef POLARSSL_X509_CRL_PARSE_C
1109  if( strcmp( str, "POLARSSL_ERR_X509_UNKNOWN_SIG_ALG" ) == 0 )
1110  {
1111  *value = ( POLARSSL_ERR_X509_UNKNOWN_SIG_ALG );
1112  return( 0 );
1113  }
1114 #endif // POLARSSL_X509_CRL_PARSE_C
1115 #ifdef POLARSSL_X509_CRT_PARSE_C
1116  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_SIGNATURE + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
1117  {
1119  return( 0 );
1120  }
1121 #endif // POLARSSL_X509_CRT_PARSE_C
1122 #ifdef POLARSSL_X509_CSR_PARSE_C
1123  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_SIGNATURE + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
1124  {
1126  return( 0 );
1127  }
1128 #endif // POLARSSL_X509_CSR_PARSE_C
1129 #ifdef POLARSSL_FS_IO
1130 #ifdef POLARSSL_X509_CRT_PARSE_C
1131 #ifdef POLARSSL_X509_CRL_PARSE_C
1132  if( strcmp( str, "POLARSSL_ERR_X509_CERT_VERIFY_FAILED" ) == 0 )
1133  {
1135  return( 0 );
1136  }
1137 #endif // POLARSSL_FS_IO
1138 #endif // POLARSSL_X509_CRT_PARSE_C
1139 #endif // POLARSSL_X509_CRL_PARSE_C
1140 #ifdef POLARSSL_X509_CRT_PARSE_C
1141  if( strcmp( str, "POLARSSL_ERR_PK_INVALID_PUBKEY + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
1142  {
1144  return( 0 );
1145  }
1146 #endif // POLARSSL_X509_CRT_PARSE_C
1147 #ifdef POLARSSL_FS_IO
1148 #ifdef POLARSSL_X509_CRT_PARSE_C
1149 #ifdef POLARSSL_X509_CRL_PARSE_C
1150  if( strcmp( str, "BADCERT_REVOKED | BADCRL_FUTURE | BADCERT_CN_MISMATCH" ) == 0 )
1151  {
1153  return( 0 );
1154  }
1155 #endif // POLARSSL_FS_IO
1156 #endif // POLARSSL_X509_CRT_PARSE_C
1157 #endif // POLARSSL_X509_CRL_PARSE_C
1158 #ifdef POLARSSL_X509_CRL_PARSE_C
1159  if( strcmp( str, "POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
1160  {
1161  *value = ( POLARSSL_ERR_ASN1_OUT_OF_DATA );
1162  return( 0 );
1163  }
1164 #endif // POLARSSL_X509_CRL_PARSE_C
1165 #ifdef POLARSSL_X509_CRT_PARSE_C
1166 #ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
1167  if( strcmp( str, "POLARSSL_ERR_X509_FEATURE_UNAVAILABLE + POLARSSL_ERR_OID_NOT_FOUND" ) == 0 )
1168  {
1170  return( 0 );
1171  }
1172 #endif // POLARSSL_X509_CRT_PARSE_C
1173 #endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
1174 #ifdef POLARSSL_X509_CRT_PARSE_C
1175  if( strcmp( str, "POLARSSL_ERR_PK_INVALID_PUBKEY + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
1176  {
1178  return( 0 );
1179  }
1180 #endif // POLARSSL_X509_CRT_PARSE_C
1181 #ifdef POLARSSL_X509_CSR_PARSE_C
1182  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_SIGNATURE + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
1183  {
1185  return( 0 );
1186  }
1187 #endif // POLARSSL_X509_CSR_PARSE_C
1188 #ifdef POLARSSL_X509_CRT_PARSE_C
1189  if( strcmp( str, "POLARSSL_ERR_X509_FEATURE_UNAVAILABLE" ) == 0 )
1190  {
1192  return( 0 );
1193  }
1194 #endif // POLARSSL_X509_CRT_PARSE_C
1195 #ifdef POLARSSL_X509_CRT_PARSE_C
1196  if( strcmp( str, "POLARSSL_ERR_PK_UNKNOWN_PK_ALG" ) == 0 )
1197  {
1198  *value = ( POLARSSL_ERR_PK_UNKNOWN_PK_ALG );
1199  return( 0 );
1200  }
1201 #endif // POLARSSL_X509_CRT_PARSE_C
1202 #ifdef POLARSSL_FS_IO
1203 #ifdef POLARSSL_X509_CRT_PARSE_C
1204 #ifdef POLARSSL_X509_CRL_PARSE_C
1205  if( strcmp( str, "BADCERT_REVOKED | BADCRL_EXPIRED" ) == 0 )
1206  {
1207  *value = ( BADCERT_REVOKED | BADCRL_EXPIRED );
1208  return( 0 );
1209  }
1210 #endif // POLARSSL_FS_IO
1211 #endif // POLARSSL_X509_CRT_PARSE_C
1212 #endif // POLARSSL_X509_CRL_PARSE_C
1213 #ifdef POLARSSL_X509_CRT_PARSE_C
1214  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_VERSION + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
1215  {
1217  return( 0 );
1218  }
1219 #endif // POLARSSL_X509_CRT_PARSE_C
1220 #ifdef POLARSSL_X509_CSR_PARSE_C
1221  if( strcmp( str, " 1" ) == 0 )
1222  {
1223  *value = ( 1 );
1224  return( 0 );
1225  }
1226 #endif // POLARSSL_X509_CSR_PARSE_C
1227 #ifdef POLARSSL_X509_CRL_PARSE_C
1228  if( strcmp( str, " 1" ) == 0 )
1229  {
1230  *value = ( 1 );
1231  return( 0 );
1232  }
1233 #endif // POLARSSL_X509_CRL_PARSE_C
1234 #ifdef POLARSSL_X509_CRT_PARSE_C
1235  if( strcmp( str, " 1" ) == 0 )
1236  {
1237  *value = ( 1 );
1238  return( 0 );
1239  }
1240 #endif // POLARSSL_X509_CRT_PARSE_C
1241 #ifdef POLARSSL_X509_CSR_PARSE_C
1242  if( strcmp( str, "POLARSSL_ERR_X509_UNKNOWN_VERSION" ) == 0 )
1243  {
1244  *value = ( POLARSSL_ERR_X509_UNKNOWN_VERSION );
1245  return( 0 );
1246  }
1247 #endif // POLARSSL_X509_CSR_PARSE_C
1248 #ifdef POLARSSL_X509_CRL_PARSE_C
1249  if( strcmp( str, "POLARSSL_ERR_X509_UNKNOWN_VERSION" ) == 0 )
1250  {
1251  *value = ( POLARSSL_ERR_X509_UNKNOWN_VERSION );
1252  return( 0 );
1253  }
1254 #endif // POLARSSL_X509_CRL_PARSE_C
1255 #ifdef POLARSSL_X509_CRT_PARSE_C
1256  if( strcmp( str, "POLARSSL_ERR_X509_UNKNOWN_VERSION" ) == 0 )
1257  {
1258  *value = ( POLARSSL_ERR_X509_UNKNOWN_VERSION );
1259  return( 0 );
1260  }
1261 #endif // POLARSSL_X509_CRT_PARSE_C
1262 #ifdef POLARSSL_X509_CRT_PARSE_C
1263 #ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
1264  if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_INVALID_DATA" ) == 0 )
1265  {
1267  return( 0 );
1268  }
1269 #endif // POLARSSL_X509_CRT_PARSE_C
1270 #endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
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_SHA512_C" ) == 0 )
1763  {
1764 #if defined(POLARSSL_SHA512_C)
1765  return( 0 );
1766 #else
1767  return( 1 );
1768 #endif
1769  }
1770  if( strcmp( str, "POLARSSL_ECDSA_C" ) == 0 )
1771  {
1772 #if defined(POLARSSL_ECDSA_C)
1773  return( 0 );
1774 #else
1775  return( 1 );
1776 #endif
1777  }
1778  if( strcmp( str, "POLARSSL_MD4_C" ) == 0 )
1779  {
1780 #if defined(POLARSSL_MD4_C)
1781  return( 0 );
1782 #else
1783  return( 1 );
1784 #endif
1785  }
1786  if( strcmp( str, "POLARSSL_PEM_PARSE_C" ) == 0 )
1787  {
1788 #if defined(POLARSSL_PEM_PARSE_C)
1789  return( 0 );
1790 #else
1791  return( 1 );
1792 #endif
1793  }
1794  if( strcmp( str, "POLARSSL_X509_RSASSA_PSS_SUPPORT" ) == 0 )
1795  {
1796 #if defined(POLARSSL_X509_RSASSA_PSS_SUPPORT)
1797  return( 0 );
1798 #else
1799  return( 1 );
1800 #endif
1801  }
1802  if( strcmp( str, "POLARSSL_SHA1_C" ) == 0 )
1803  {
1804 #if defined(POLARSSL_SHA1_C)
1805  return( 0 );
1806 #else
1807  return( 1 );
1808 #endif
1809  }
1810  if( strcmp( str, "POLARSSL_ECP_DP_SECP384R1_ENABLED" ) == 0 )
1811  {
1812 #if defined(POLARSSL_ECP_DP_SECP384R1_ENABLED)
1813  return( 0 );
1814 #else
1815  return( 1 );
1816 #endif
1817  }
1818  if( strcmp( str, "POLARSSL_PKCS1_V15" ) == 0 )
1819  {
1820 #if defined(POLARSSL_PKCS1_V15)
1821  return( 0 );
1822 #else
1823  return( 1 );
1824 #endif
1825  }
1826  if( strcmp( str, "POLARSSL_CERTS_C" ) == 0 )
1827  {
1828 #if defined(POLARSSL_CERTS_C)
1829  return( 0 );
1830 #else
1831  return( 1 );
1832 #endif
1833  }
1834  if( strcmp( str, "POLARSSL_ECP_DP_SECP192R1_ENABLED" ) == 0 )
1835  {
1836 #if defined(POLARSSL_ECP_DP_SECP192R1_ENABLED)
1837  return( 0 );
1838 #else
1839  return( 1 );
1840 #endif
1841  }
1842  if( strcmp( str, "POLARSSL_MD5_C" ) == 0 )
1843  {
1844 #if defined(POLARSSL_MD5_C)
1845  return( 0 );
1846 #else
1847  return( 1 );
1848 #endif
1849  }
1850  if( strcmp( str, "POLARSSL_HAVE_TIME" ) == 0 )
1851  {
1852 #if defined(POLARSSL_HAVE_TIME)
1853  return( 0 );
1854 #else
1855  return( 1 );
1856 #endif
1857  }
1858  if( strcmp( str, "POLARSSL_ECP_DP_SECP383R1_ENABLED" ) == 0 )
1859  {
1860 #if defined(POLARSSL_ECP_DP_SECP383R1_ENABLED)
1861  return( 0 );
1862 #else
1863  return( 1 );
1864 #endif
1865  }
1866  if( strcmp( str, "POLARSSL_ECP_C" ) == 0 )
1867  {
1868 #if defined(POLARSSL_ECP_C)
1869  return( 0 );
1870 #else
1871  return( 1 );
1872 #endif
1873  }
1874  if( strcmp( str, "POLARSSL_ECP_DP_SECP256R1_ENABLED" ) == 0 )
1875  {
1876 #if defined(POLARSSL_ECP_DP_SECP256R1_ENABLED)
1877  return( 0 );
1878 #else
1879  return( 1 );
1880 #endif
1881  }
1882  if( strcmp( str, "POLARSSL_X509_ALLOW_EXTENSIONS_NON_V3" ) == 0 )
1883  {
1884 #if defined(POLARSSL_X509_ALLOW_EXTENSIONS_NON_V3)
1885  return( 0 );
1886 #else
1887  return( 1 );
1888 #endif
1889  }
1890  if( strcmp( str, "POLARSSL_X509_CHECK_KEY_USAGE" ) == 0 )
1891  {
1892 #if defined(POLARSSL_X509_CHECK_KEY_USAGE)
1893  return( 0 );
1894 #else
1895  return( 1 );
1896 #endif
1897  }
1898  if( strcmp( str, "POLARSSL_SHA256_C" ) == 0 )
1899  {
1900 #if defined(POLARSSL_SHA256_C)
1901  return( 0 );
1902 #else
1903  return( 1 );
1904 #endif
1905  }
1906  if( strcmp( str, "POLARSSL_RSA_C" ) == 0 )
1907  {
1908 #if defined(POLARSSL_RSA_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 = "/builddir/build/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 
#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_ERR_PEM_INVALID_DATA
PEM string is not as expected.
Definition: pem.h:39
#define polarssl_free
static int unhexify(unsigned char *obuf, const char *ibuf)
RFC 1521 base64 encoding/decoding.
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 POLARSSL_ERR_BASE64_INVALID_CHARACTER
Invalid character in input.
Definition: base64.h:33
#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