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
16int 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
26int 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>
52typedef 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
84static 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
118static 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
149static 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
172static 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
198static 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
223static 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
233typedef struct
234{
235 unsigned char *buf;
236 size_t length;
238
250static 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
282typedef struct
283{
284 uint32_t key[16];
285 uint32_t v0, v1;
287
296static 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
340static int test_errors = 0;
341
342#ifdef POLARSSL_BIGNUM_C
343
344#define TEST_SUITE_ACTIVE
345
346static 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
364int 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
379int 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_FS_IO
421#ifdef POLARSSL_X509_CRT_PARSE_C
422#ifdef POLARSSL_X509_CRL_PARSE_C
423 if( strcmp( str, "BADCERT_OTHER" ) == 0 )
424 {
425 *value = ( BADCERT_OTHER );
426 return( 0 );
427 }
428#endif // POLARSSL_FS_IO
429#endif // POLARSSL_X509_CRT_PARSE_C
430#endif // POLARSSL_X509_CRL_PARSE_C
431#ifdef POLARSSL_X509_CRT_PARSE_C
432 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_VERSION + POLARSSL_ERR_ASN1_INVALID_LENGTH" ) == 0 )
433 {
435 return( 0 );
436 }
437#endif // POLARSSL_X509_CRT_PARSE_C
438#ifdef POLARSSL_X509_CRT_PARSE_C
439 if( strcmp( str, "POLARSSL_ERR_PK_KEY_INVALID_FORMAT + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
440 {
442 return( 0 );
443 }
444#endif // POLARSSL_X509_CRT_PARSE_C
445#ifdef POLARSSL_X509_CSR_PARSE_C
446 if( strcmp( str, "POLARSSL_ERR_PK_KEY_INVALID_FORMAT + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
447 {
449 return( 0 );
450 }
451#endif // POLARSSL_X509_CSR_PARSE_C
452#ifdef POLARSSL_X509_CRT_PARSE_C
453 if( strcmp( str, "POLARSSL_ERR_PK_INVALID_PUBKEY" ) == 0 )
454 {
456 return( 0 );
457 }
458#endif // POLARSSL_X509_CRT_PARSE_C
459#ifdef POLARSSL_X509_CRT_PARSE_C
460 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_SIGNATURE + POLARSSL_ERR_ASN1_INVALID_DATA" ) == 0 )
461 {
463 return( 0 );
464 }
465#endif // POLARSSL_X509_CRT_PARSE_C
466#ifdef POLARSSL_X509_CRT_PARSE_C
467 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_EXTENSIONS + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
468 {
470 return( 0 );
471 }
472#endif // POLARSSL_X509_CRT_PARSE_C
473#ifdef POLARSSL_X509_CRT_PARSE_C
474 if( strcmp( str, "POLARSSL_ERR_ASN1_INVALID_LENGTH" ) == 0 )
475 {
477 return( 0 );
478 }
479#endif // POLARSSL_X509_CRT_PARSE_C
480#ifdef POLARSSL_X509_CSR_PARSE_C
481 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
482 {
484 return( 0 );
485 }
486#endif // POLARSSL_X509_CSR_PARSE_C
487#ifdef POLARSSL_X509_CRL_PARSE_C
488 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
489 {
491 return( 0 );
492 }
493#endif // POLARSSL_X509_CRL_PARSE_C
494#ifdef POLARSSL_X509_CRT_PARSE_C
495 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
496 {
498 return( 0 );
499 }
500#endif // POLARSSL_X509_CRT_PARSE_C
501#ifdef POLARSSL_X509_CRT_PARSE_C
502 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_SERIAL + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
503 {
505 return( 0 );
506 }
507#endif // POLARSSL_X509_CRT_PARSE_C
508#ifdef POLARSSL_FS_IO
509#ifdef POLARSSL_X509_CRT_PARSE_C
510#ifdef POLARSSL_X509_CRL_PARSE_C
511 if( strcmp( str, "BADCERT_EXPIRED" ) == 0 )
512 {
513 *value = ( BADCERT_EXPIRED );
514 return( 0 );
515 }
516#endif // POLARSSL_FS_IO
517#endif // POLARSSL_X509_CRT_PARSE_C
518#endif // POLARSSL_X509_CRL_PARSE_C
519#ifdef POLARSSL_X509_CRT_PARSE_C
520 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_EXTENSIONS + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
521 {
523 return( 0 );
524 }
525#endif // POLARSSL_X509_CRT_PARSE_C
526#ifdef POLARSSL_FS_IO
527#ifdef POLARSSL_X509_CRT_PARSE_C
528#ifdef POLARSSL_X509_CHECK_KEY_USAGE
529 if( strcmp( str, "KU_DIGITAL_SIGNATURE" ) == 0 )
530 {
531 *value = ( KU_DIGITAL_SIGNATURE );
532 return( 0 );
533 }
534#endif // POLARSSL_FS_IO
535#endif // POLARSSL_X509_CRT_PARSE_C
536#endif // POLARSSL_X509_CHECK_KEY_USAGE
537#ifdef POLARSSL_X509_CRT_PARSE_C
538 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_VERSION + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
539 {
541 return( 0 );
542 }
543#endif // POLARSSL_X509_CRT_PARSE_C
544#ifdef POLARSSL_X509_CRL_PARSE_C
545 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_DATE + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
546 {
548 return( 0 );
549 }
550#endif // POLARSSL_X509_CRL_PARSE_C
551#ifdef POLARSSL_X509_CSR_PARSE_C
552 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT" ) == 0 )
553 {
555 return( 0 );
556 }
557#endif // POLARSSL_X509_CSR_PARSE_C
558#ifdef POLARSSL_X509_CRL_PARSE_C
559 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT" ) == 0 )
560 {
562 return( 0 );
563 }
564#endif // POLARSSL_X509_CRL_PARSE_C
565#ifdef POLARSSL_X509_CRT_PARSE_C
566 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT" ) == 0 )
567 {
569 return( 0 );
570 }
571#endif // POLARSSL_X509_CRT_PARSE_C
572#ifdef POLARSSL_X509_CRT_PARSE_C
573#ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
574 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
575 {
577 return( 0 );
578 }
579#endif // POLARSSL_X509_CRT_PARSE_C
580#endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
581#ifdef POLARSSL_X509_CRT_PARSE_C
582 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
583 {
585 return( 0 );
586 }
587#endif // POLARSSL_X509_CRT_PARSE_C
588#ifdef POLARSSL_X509_CRL_PARSE_C
589 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
590 {
592 return( 0 );
593 }
594#endif // POLARSSL_X509_CRL_PARSE_C
595#ifdef POLARSSL_X509_CSR_PARSE_C
596 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
597 {
599 return( 0 );
600 }
601#endif // POLARSSL_X509_CSR_PARSE_C
602#ifdef POLARSSL_X509_CRT_PARSE_C
603 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_INVALID_LENGTH" ) == 0 )
604 {
606 return( 0 );
607 }
608#endif // POLARSSL_X509_CRT_PARSE_C
609#ifdef POLARSSL_X509_CRT_PARSE_C
610 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_EXTENSIONS + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
611 {
613 return( 0 );
614 }
615#endif // POLARSSL_X509_CRT_PARSE_C
616#ifdef POLARSSL_FS_IO
617#ifdef POLARSSL_X509_CRT_PARSE_C
618#ifdef POLARSSL_X509_CRL_PARSE_C
619 if( strcmp( str, "BADCERT_REVOKED | BADCRL_FUTURE" ) == 0 )
620 {
621 *value = ( BADCERT_REVOKED | BADCRL_FUTURE );
622 return( 0 );
623 }
624#endif // POLARSSL_FS_IO
625#endif // POLARSSL_X509_CRT_PARSE_C
626#endif // POLARSSL_X509_CRL_PARSE_C
627#ifdef POLARSSL_X509_CRT_PARSE_C
628 if( strcmp( str, "POLARSSL_ERR_PK_UNKNOWN_PK_ALG" ) == 0 )
629 {
631 return( 0 );
632 }
633#endif // POLARSSL_X509_CRT_PARSE_C
634#ifdef POLARSSL_X509_CRT_PARSE_C
635#ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
636 if( strcmp( str, "POLARSSL_MD_SHA256" ) == 0 )
637 {
638 *value = ( POLARSSL_MD_SHA256 );
639 return( 0 );
640 }
641#endif // POLARSSL_X509_CRT_PARSE_C
642#endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
643#ifdef POLARSSL_X509_CRT_PARSE_C
644 if( strcmp( str, "POLARSSL_ERR_X509_FEATURE_UNAVAILABLE" ) == 0 )
645 {
647 return( 0 );
648 }
649#endif // POLARSSL_X509_CRT_PARSE_C
650#ifdef POLARSSL_FS_IO
651#ifdef POLARSSL_X509_CRT_PARSE_C
652#ifdef POLARSSL_X509_CRL_PARSE_C
653 if( strcmp( str, "BADCRL_NOT_TRUSTED" ) == 0 )
654 {
655 *value = ( BADCRL_NOT_TRUSTED );
656 return( 0 );
657 }
658#endif // POLARSSL_FS_IO
659#endif // POLARSSL_X509_CRT_PARSE_C
660#endif // POLARSSL_X509_CRL_PARSE_C
661#ifdef POLARSSL_X509_CRL_PARSE_C
662 if( strcmp( str, "POLARSSL_ERR_X509_UNKNOWN_VERSION" ) == 0 )
663 {
665 return( 0 );
666 }
667#endif // POLARSSL_X509_CRL_PARSE_C
668#ifdef POLARSSL_X509_CSR_PARSE_C
669 if( strcmp( str, "POLARSSL_ERR_X509_UNKNOWN_VERSION" ) == 0 )
670 {
672 return( 0 );
673 }
674#endif // POLARSSL_X509_CSR_PARSE_C
675#ifdef POLARSSL_X509_CRT_PARSE_C
676 if( strcmp( str, "POLARSSL_ERR_X509_UNKNOWN_VERSION" ) == 0 )
677 {
679 return( 0 );
680 }
681#endif // POLARSSL_X509_CRT_PARSE_C
682#ifdef POLARSSL_X509_CRT_PARSE_C
683#ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
684 if( strcmp( str, "ASN1_CONSTRUCTED | ASN1_SEQUENCE" ) == 0 )
685 {
686 *value = ( ASN1_CONSTRUCTED | ASN1_SEQUENCE );
687 return( 0 );
688 }
689#endif // POLARSSL_X509_CRT_PARSE_C
690#endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
691#ifdef POLARSSL_FS_IO
692#ifdef POLARSSL_X509_CRT_PARSE_C
693#ifdef POLARSSL_X509_CHECK_KEY_USAGE
694 if( strcmp( str, "KU_DIGITAL_SIGNATURE|KU_KEY_ENCIPHERMENT" ) == 0 )
695 {
697 return( 0 );
698 }
699#endif // POLARSSL_FS_IO
700#endif // POLARSSL_X509_CRT_PARSE_C
701#endif // POLARSSL_X509_CHECK_KEY_USAGE
702#ifdef POLARSSL_X509_CRT_PARSE_C
703#ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
704 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
705 {
707 return( 0 );
708 }
709#endif // POLARSSL_X509_CRT_PARSE_C
710#endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
711#ifdef POLARSSL_X509_CRT_PARSE_C
712 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
713 {
715 return( 0 );
716 }
717#endif // POLARSSL_X509_CRT_PARSE_C
718#ifdef POLARSSL_X509_CSR_PARSE_C
719 if( strcmp( str, " 1" ) == 0 )
720 {
721 *value = ( 1 );
722 return( 0 );
723 }
724#endif // POLARSSL_X509_CSR_PARSE_C
725#ifdef POLARSSL_X509_CRL_PARSE_C
726 if( strcmp( str, " 1" ) == 0 )
727 {
728 *value = ( 1 );
729 return( 0 );
730 }
731#endif // POLARSSL_X509_CRL_PARSE_C
732#ifdef POLARSSL_X509_CRT_PARSE_C
733 if( strcmp( str, " 1" ) == 0 )
734 {
735 *value = ( 1 );
736 return( 0 );
737 }
738#endif // POLARSSL_X509_CRT_PARSE_C
739#ifdef POLARSSL_X509_CRT_PARSE_C
740#ifdef POLARSSL_FS_IO
741 if( strcmp( str, "POLARSSL_ERR_PEM_INVALID_DATA + POLARSSL_ERR_BASE64_INVALID_CHARACTER" ) == 0 )
742 {
744 return( 0 );
745 }
746#endif // POLARSSL_X509_CRT_PARSE_C
747#endif // POLARSSL_FS_IO
748#ifdef POLARSSL_X509_CRT_PARSE_C
749#ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
750 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG" ) == 0 )
751 {
753 return( 0 );
754 }
755#endif // POLARSSL_X509_CRT_PARSE_C
756#endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
757#ifdef POLARSSL_FS_IO
758#ifdef POLARSSL_X509_CRT_PARSE_C
759#ifdef POLARSSL_X509_CRL_PARSE_C
760 if( strcmp( str, "BADCRL_FUTURE" ) == 0 )
761 {
762 *value = ( BADCRL_FUTURE );
763 return( 0 );
764 }
765#endif // POLARSSL_FS_IO
766#endif // POLARSSL_X509_CRT_PARSE_C
767#endif // POLARSSL_X509_CRL_PARSE_C
768#ifdef POLARSSL_X509_CRL_PARSE_C
769 if( strcmp( str, "POLARSSL_ERR_X509_SIG_MISMATCH" ) == 0 )
770 {
772 return( 0 );
773 }
774#endif // POLARSSL_X509_CRL_PARSE_C
775#ifdef POLARSSL_X509_CRT_PARSE_C
776 if( strcmp( str, "POLARSSL_ERR_X509_SIG_MISMATCH" ) == 0 )
777 {
779 return( 0 );
780 }
781#endif // POLARSSL_X509_CRT_PARSE_C
782#ifdef POLARSSL_X509_CSR_PARSE_C
783 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
784 {
786 return( 0 );
787 }
788#endif // POLARSSL_X509_CSR_PARSE_C
789#ifdef POLARSSL_X509_CRT_PARSE_C
790 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
791 {
793 return( 0 );
794 }
795#endif // POLARSSL_X509_CRT_PARSE_C
796#ifdef POLARSSL_FS_IO
797#ifdef POLARSSL_X509_CRT_PARSE_C
798#ifdef POLARSSL_X509_CRL_PARSE_C
799 if( strcmp( str, "BADCERT_REVOKED" ) == 0 )
800 {
801 *value = ( BADCERT_REVOKED );
802 return( 0 );
803 }
804#endif // POLARSSL_FS_IO
805#endif // POLARSSL_X509_CRT_PARSE_C
806#endif // POLARSSL_X509_CRL_PARSE_C
807#ifdef POLARSSL_X509_CRT_PARSE_C
808 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_VERSION + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
809 {
811 return( 0 );
812 }
813#endif // POLARSSL_X509_CRT_PARSE_C
814#ifdef POLARSSL_X509_CSR_PARSE_C
815 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_NAME + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
816 {
818 return( 0 );
819 }
820#endif // POLARSSL_X509_CSR_PARSE_C
821#ifdef POLARSSL_X509_CRT_PARSE_C
822 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_NAME + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
823 {
825 return( 0 );
826 }
827#endif // POLARSSL_X509_CRT_PARSE_C
828#ifdef POLARSSL_X509_CRT_PARSE_C
829 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_DATE + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
830 {
832 return( 0 );
833 }
834#endif // POLARSSL_X509_CRT_PARSE_C
835#ifdef POLARSSL_X509_CRL_PARSE_C
836 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
837 {
839 return( 0 );
840 }
841#endif // POLARSSL_X509_CRL_PARSE_C
842#ifdef POLARSSL_X509_CSR_PARSE_C
843 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
844 {
846 return( 0 );
847 }
848#endif // POLARSSL_X509_CSR_PARSE_C
849#ifdef POLARSSL_X509_CRT_PARSE_C
850 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
851 {
853 return( 0 );
854 }
855#endif // POLARSSL_X509_CRT_PARSE_C
856#ifdef POLARSSL_X509_CRT_PARSE_C
857#ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
858 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
859 {
861 return( 0 );
862 }
863#endif // POLARSSL_X509_CRT_PARSE_C
864#endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
865#ifdef POLARSSL_X509_CRT_PARSE_C
866#ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
867 if( strcmp( str, "ASN1_SEQUENCE" ) == 0 )
868 {
869 *value = ( ASN1_SEQUENCE );
870 return( 0 );
871 }
872#endif // POLARSSL_X509_CRT_PARSE_C
873#endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
874#ifdef POLARSSL_FS_IO
875#ifdef POLARSSL_X509_CRT_PARSE_C
876#ifdef POLARSSL_X509_CHECK_KEY_USAGE
877 if( strcmp( str, "POLARSSL_ERR_X509_BAD_INPUT_DATA" ) == 0 )
878 {
880 return( 0 );
881 }
882#endif // POLARSSL_FS_IO
883#endif // POLARSSL_X509_CRT_PARSE_C
884#endif // POLARSSL_X509_CHECK_KEY_USAGE
885#ifdef POLARSSL_FS_IO
886#ifdef POLARSSL_X509_CRT_PARSE_C
887#ifdef POLARSSL_X509_CHECK_EXTENDED_KEY_USAGE
888 if( strcmp( str, "POLARSSL_ERR_X509_BAD_INPUT_DATA" ) == 0 )
889 {
891 return( 0 );
892 }
893#endif // POLARSSL_FS_IO
894#endif // POLARSSL_X509_CRT_PARSE_C
895#endif // POLARSSL_X509_CHECK_EXTENDED_KEY_USAGE
896#ifdef POLARSSL_X509_CSR_PARSE_C
897 if( strcmp( str, "POLARSSL_ERR_X509_UNKNOWN_SIG_ALG" ) == 0 )
898 {
900 return( 0 );
901 }
902#endif // POLARSSL_X509_CSR_PARSE_C
903#ifdef POLARSSL_X509_CRL_PARSE_C
904 if( strcmp( str, "POLARSSL_ERR_X509_UNKNOWN_SIG_ALG" ) == 0 )
905 {
907 return( 0 );
908 }
909#endif // POLARSSL_X509_CRL_PARSE_C
910#ifdef POLARSSL_FS_IO
911#ifdef POLARSSL_X509_CRT_PARSE_C
912#ifdef POLARSSL_X509_CRL_PARSE_C
913 if( strcmp( str, "BADCERT_REVOKED | BADCRL_FUTURE | BADCERT_CN_MISMATCH" ) == 0 )
914 {
916 return( 0 );
917 }
918#endif // POLARSSL_FS_IO
919#endif // POLARSSL_X509_CRT_PARSE_C
920#endif // POLARSSL_X509_CRL_PARSE_C
921#ifdef POLARSSL_FS_IO
922#ifdef POLARSSL_X509_CRT_PARSE_C
923#ifdef POLARSSL_X509_CRL_PARSE_C
924 if( strcmp( str, "BADCERT_NOT_TRUSTED" ) == 0 )
925 {
926 *value = ( BADCERT_NOT_TRUSTED );
927 return( 0 );
928 }
929#endif // POLARSSL_FS_IO
930#endif // POLARSSL_X509_CRT_PARSE_C
931#endif // POLARSSL_X509_CRL_PARSE_C
932#ifdef POLARSSL_FS_IO
933#ifdef POLARSSL_X509_CRT_PARSE_C
934#ifdef POLARSSL_X509_CHECK_KEY_USAGE
935 if( strcmp( str, "KU_KEY_CERT_SIGN|KU_CRL_SIGN" ) == 0 )
936 {
937 *value = ( KU_KEY_CERT_SIGN|KU_CRL_SIGN );
938 return( 0 );
939 }
940#endif // POLARSSL_FS_IO
941#endif // POLARSSL_X509_CRT_PARSE_C
942#endif // POLARSSL_X509_CHECK_KEY_USAGE
943#ifdef POLARSSL_X509_CRT_PARSE_C
944 if( strcmp( str, "POLARSSL_ERR_PK_INVALID_PUBKEY + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
945 {
947 return( 0 );
948 }
949#endif // POLARSSL_X509_CRT_PARSE_C
950#ifdef POLARSSL_FS_IO
951#ifdef POLARSSL_X509_CRT_PARSE_C
952#ifdef POLARSSL_X509_CRL_PARSE_C
953 if( strcmp( str, "BADCRL_EXPIRED" ) == 0 )
954 {
955 *value = ( BADCRL_EXPIRED );
956 return( 0 );
957 }
958#endif // POLARSSL_FS_IO
959#endif // POLARSSL_X509_CRT_PARSE_C
960#endif // POLARSSL_X509_CRL_PARSE_C
961#ifdef POLARSSL_X509_CSR_PARSE_C
962 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
963 {
965 return( 0 );
966 }
967#endif // POLARSSL_X509_CSR_PARSE_C
968#ifdef POLARSSL_X509_CRL_PARSE_C
969 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
970 {
972 return( 0 );
973 }
974#endif // POLARSSL_X509_CRL_PARSE_C
975#ifdef POLARSSL_X509_CRT_PARSE_C
976 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_FORMAT + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
977 {
979 return( 0 );
980 }
981#endif // POLARSSL_X509_CRT_PARSE_C
982#ifdef POLARSSL_X509_CRL_PARSE_C
983 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_DATE + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
984 {
986 return( 0 );
987 }
988#endif // POLARSSL_X509_CRL_PARSE_C
989#ifdef POLARSSL_X509_CRT_PARSE_C
990 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_DATE + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
991 {
993 return( 0 );
994 }
995#endif // POLARSSL_X509_CRT_PARSE_C
996#ifdef POLARSSL_X509_CSR_PARSE_C
997 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_NAME + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
998 {
1000 return( 0 );
1001 }
1002#endif // POLARSSL_X509_CSR_PARSE_C
1003#ifdef POLARSSL_X509_CRL_PARSE_C
1004 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_NAME + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
1005 {
1007 return( 0 );
1008 }
1009#endif // POLARSSL_X509_CRL_PARSE_C
1010#ifdef POLARSSL_X509_CRT_PARSE_C
1011 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_NAME + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
1012 {
1014 return( 0 );
1015 }
1016#endif // POLARSSL_X509_CRT_PARSE_C
1017#ifdef POLARSSL_FS_IO
1018#ifdef POLARSSL_X509_CRT_PARSE_C
1019#ifdef POLARSSL_X509_CHECK_KEY_USAGE
1020 if( strcmp( str, "KU_KEY_CERT_SIGN" ) == 0 )
1021 {
1022 *value = ( KU_KEY_CERT_SIGN );
1023 return( 0 );
1024 }
1025#endif // POLARSSL_FS_IO
1026#endif // POLARSSL_X509_CRT_PARSE_C
1027#endif // POLARSSL_X509_CHECK_KEY_USAGE
1028#ifdef POLARSSL_X509_CRT_PARSE_C
1029#ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
1030 if( strcmp( str, "POLARSSL_MD_SHA1" ) == 0 )
1031 {
1032 *value = ( POLARSSL_MD_SHA1 );
1033 return( 0 );
1034 }
1035#endif // POLARSSL_X509_CRT_PARSE_C
1036#endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
1037#ifdef POLARSSL_FS_IO
1038#ifdef POLARSSL_X509_CRT_PARSE_C
1039#ifdef POLARSSL_X509_CRL_PARSE_C
1040 if( strcmp( str, "BADCERT_REVOKED | BADCRL_EXPIRED" ) == 0 )
1041 {
1042 *value = ( BADCERT_REVOKED | BADCRL_EXPIRED );
1043 return( 0 );
1044 }
1045#endif // POLARSSL_FS_IO
1046#endif // POLARSSL_X509_CRT_PARSE_C
1047#endif // POLARSSL_X509_CRL_PARSE_C
1048#ifdef POLARSSL_X509_CRT_PARSE_C
1049 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_VERSION + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
1050 {
1052 return( 0 );
1053 }
1054#endif // POLARSSL_X509_CRT_PARSE_C
1055#ifdef POLARSSL_X509_CSR_PARSE_C
1056 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_VERSION + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
1057 {
1059 return( 0 );
1060 }
1061#endif // POLARSSL_X509_CSR_PARSE_C
1062#ifdef POLARSSL_X509_CRL_PARSE_C
1063 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_VERSION + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
1064 {
1066 return( 0 );
1067 }
1068#endif // POLARSSL_X509_CRL_PARSE_C
1069#ifdef POLARSSL_FS_IO
1070#ifdef POLARSSL_X509_CRT_PARSE_C
1071#ifdef POLARSSL_X509_CRL_PARSE_C
1072 if( strcmp( str, "BADCERT_FUTURE" ) == 0 )
1073 {
1074 *value = ( BADCERT_FUTURE );
1075 return( 0 );
1076 }
1077#endif // POLARSSL_FS_IO
1078#endif // POLARSSL_X509_CRT_PARSE_C
1079#endif // POLARSSL_X509_CRL_PARSE_C
1080#ifdef POLARSSL_FS_IO
1081#ifdef POLARSSL_X509_CRT_PARSE_C
1082#ifdef POLARSSL_X509_CRL_PARSE_C
1083 if( strcmp( str, "BADCERT_REVOKED | BADCERT_CN_MISMATCH" ) == 0 )
1084 {
1085 *value = ( BADCERT_REVOKED | BADCERT_CN_MISMATCH );
1086 return( 0 );
1087 }
1088#endif // POLARSSL_FS_IO
1089#endif // POLARSSL_X509_CRT_PARSE_C
1090#endif // POLARSSL_X509_CRL_PARSE_C
1091#ifdef POLARSSL_X509_CRT_PARSE_C
1092 if( strcmp( str, "POLARSSL_ERR_PK_INVALID_PUBKEY + POLARSSL_ERR_ASN1_LENGTH_MISMATCH" ) == 0 )
1093 {
1095 return( 0 );
1096 }
1097#endif // POLARSSL_X509_CRT_PARSE_C
1098#ifdef POLARSSL_X509_CRT_PARSE_C
1099#ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
1100 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_INVALID_DATA" ) == 0 )
1101 {
1103 return( 0 );
1104 }
1105#endif // POLARSSL_X509_CRT_PARSE_C
1106#endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
1107#ifdef POLARSSL_FS_IO
1108#ifdef POLARSSL_X509_CRT_PARSE_C
1109#ifdef POLARSSL_X509_CRL_PARSE_C
1110 if( strcmp( str, "POLARSSL_ERR_X509_CERT_VERIFY_FAILED" ) == 0 )
1111 {
1113 return( 0 );
1114 }
1115#endif // POLARSSL_FS_IO
1116#endif // POLARSSL_X509_CRT_PARSE_C
1117#endif // POLARSSL_X509_CRL_PARSE_C
1118#ifdef POLARSSL_X509_CRT_PARSE_C
1119 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_SERIAL + POLARSSL_ERR_ASN1_OUT_OF_DATA " ) == 0 )
1120 {
1122 return( 0 );
1123 }
1124#endif // POLARSSL_X509_CRT_PARSE_C
1125#ifdef POLARSSL_X509_CRT_PARSE_C
1126#ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
1127 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_OID_NOT_FOUND" ) == 0 )
1128 {
1130 return( 0 );
1131 }
1132#endif // POLARSSL_X509_CRT_PARSE_C
1133#endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
1134#ifdef POLARSSL_X509_CRL_PARSE_C
1135 if( strcmp( str, "POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
1136 {
1137 *value = ( POLARSSL_ERR_ASN1_OUT_OF_DATA );
1138 return( 0 );
1139 }
1140#endif // POLARSSL_X509_CRL_PARSE_C
1141#ifdef POLARSSL_X509_USE_C
1142 if( strcmp( str, "POLARSSL_ERR_OID_BUF_TOO_SMALL" ) == 0 )
1143 {
1144 *value = ( POLARSSL_ERR_OID_BUF_TOO_SMALL );
1145 return( 0 );
1146 }
1147#endif // POLARSSL_X509_USE_C
1148#ifdef POLARSSL_X509_CRT_PARSE_C
1149 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_DATE" ) == 0 )
1150 {
1151 *value = ( POLARSSL_ERR_X509_INVALID_DATE );
1152 return( 0 );
1153 }
1154#endif // POLARSSL_X509_CRT_PARSE_C
1155#ifdef POLARSSL_FS_IO
1156#ifdef POLARSSL_X509_CRT_PARSE_C
1157#ifdef POLARSSL_X509_CHECK_KEY_USAGE
1158 if( strcmp( str, "KU_KEY_ENCIPHERMENT|KU_KEY_AGREEMENT" ) == 0 )
1159 {
1161 return( 0 );
1162 }
1163#endif // POLARSSL_FS_IO
1164#endif // POLARSSL_X509_CRT_PARSE_C
1165#endif // POLARSSL_X509_CHECK_KEY_USAGE
1166#ifdef POLARSSL_X509_CRT_PARSE_C
1167 if( strcmp( str, "POLARSSL_ERR_X509_UNKNOWN_SIG_ALG + POLARSSL_ERR_OID_NOT_FOUND" ) == 0 )
1168 {
1170 return( 0 );
1171 }
1172#endif // POLARSSL_X509_CRT_PARSE_C
1173#ifdef POLARSSL_X509_CRT_PARSE_C
1174 if( strcmp( str, "POLARSSL_ERR_PK_INVALID_PUBKEY + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
1175 {
1177 return( 0 );
1178 }
1179#endif // POLARSSL_X509_CRT_PARSE_C
1180#ifdef POLARSSL_X509_CRT_PARSE_C
1181 if( strcmp( str, "POLARSSL_ERR_PK_INVALID_PUBKEY + POLARSSL_ERR_ASN1_INVALID_DATA" ) == 0 )
1182 {
1184 return( 0 );
1185 }
1186#endif // POLARSSL_X509_CRT_PARSE_C
1187#ifdef POLARSSL_X509_CRT_PARSE_C
1188#ifdef POLARSSL_X509_RSASSA_PSS_SUPPORT
1189 if( strcmp( str, "POLARSSL_ERR_X509_FEATURE_UNAVAILABLE + POLARSSL_ERR_OID_NOT_FOUND" ) == 0 )
1190 {
1192 return( 0 );
1193 }
1194#endif // POLARSSL_X509_CRT_PARSE_C
1195#endif // POLARSSL_X509_RSASSA_PSS_SUPPORT
1196#ifdef POLARSSL_FS_IO
1197#ifdef POLARSSL_X509_CRT_PARSE_C
1198#ifdef POLARSSL_X509_CRL_PARSE_C
1199 if( strcmp( str, "BADCERT_CN_MISMATCH + BADCERT_NOT_TRUSTED" ) == 0 )
1200 {
1202 return( 0 );
1203 }
1204#endif // POLARSSL_FS_IO
1205#endif // POLARSSL_X509_CRT_PARSE_C
1206#endif // POLARSSL_X509_CRL_PARSE_C
1207#ifdef POLARSSL_X509_CSR_PARSE_C
1208 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_SIGNATURE + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
1209 {
1211 return( 0 );
1212 }
1213#endif // POLARSSL_X509_CSR_PARSE_C
1214#ifdef POLARSSL_X509_CRT_PARSE_C
1215 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_SIGNATURE + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
1216 {
1218 return( 0 );
1219 }
1220#endif // POLARSSL_X509_CRT_PARSE_C
1221#ifdef POLARSSL_X509_CRT_PARSE_C
1222 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_SERIAL + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
1223 {
1225 return( 0 );
1226 }
1227#endif // POLARSSL_X509_CRT_PARSE_C
1228#ifdef POLARSSL_FS_IO
1229#ifdef POLARSSL_X509_CRT_PARSE_C
1230#ifdef POLARSSL_X509_CRL_PARSE_C
1231 if( strcmp( str, "BADCERT_CN_MISMATCH" ) == 0 )
1232 {
1233 *value = ( BADCERT_CN_MISMATCH );
1234 return( 0 );
1235 }
1236#endif // POLARSSL_FS_IO
1237#endif // POLARSSL_X509_CRT_PARSE_C
1238#endif // POLARSSL_X509_CRL_PARSE_C
1239#ifdef POLARSSL_X509_CSR_PARSE_C
1240 if( strcmp( str, "POLARSSL_ERR_PK_KEY_INVALID_FORMAT + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
1241 {
1243 return( 0 );
1244 }
1245#endif // POLARSSL_X509_CSR_PARSE_C
1246#ifdef POLARSSL_X509_CRT_PARSE_C
1247 if( strcmp( str, "POLARSSL_ERR_PK_INVALID_ALG + POLARSSL_ERR_ASN1_OUT_OF_DATA" ) == 0 )
1248 {
1250 return( 0 );
1251 }
1252#endif // POLARSSL_X509_CRT_PARSE_C
1253#ifdef POLARSSL_FS_IO
1254#ifdef POLARSSL_X509_CRT_PARSE_C
1255#ifdef POLARSSL_X509_CRL_PARSE_C
1256 if( strcmp( str, "BADCERT_REVOKED | BADCRL_EXPIRED | BADCERT_CN_MISMATCH" ) == 0 )
1257 {
1259 return( 0 );
1260 }
1261#endif // POLARSSL_FS_IO
1262#endif // POLARSSL_X509_CRT_PARSE_C
1263#endif // POLARSSL_X509_CRL_PARSE_C
1264#ifdef POLARSSL_X509_CSR_PARSE_C
1265 if( strcmp( str, "POLARSSL_ERR_X509_INVALID_SIGNATURE + POLARSSL_ERR_ASN1_UNEXPECTED_TAG" ) == 0 )
1266 {
1268 return( 0 );
1269 }
1270#endif // POLARSSL_X509_CSR_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
1279void 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
1296exit:
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
1304void 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
1321exit:
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
1329void 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
1346exit:
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
1355void 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
1392exit:
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
1403void 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
1425exit:
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
1433void 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
1448exit:
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
1456void 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
1471exit:
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
1479void 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
1487exit:
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
1494void 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
1518exit:
1519 x509_crt_free( &crt );
1520}
1521#endif /* POLARSSL_X509_CRT_PARSE_C */
1522
1523#ifdef POLARSSL_X509_CRL_PARSE_C
1524void 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
1548exit:
1549 x509_crl_free( &crl );
1550}
1551#endif /* POLARSSL_X509_CRL_PARSE_C */
1552
1553#ifdef POLARSSL_X509_CSR_PARSE_C
1554void 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
1576exit:
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
1584void 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
1600exit:
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
1607void 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
1629exit:
1630 return;
1631}
1632#endif /* POLARSSL_X509_USE_C */
1633
1634#ifdef POLARSSL_X509_USE_C
1635void 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
1658exit:
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
1666void 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
1676exit:
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
1686void 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
1700exit:
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
1709void 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
1735exit:
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
1743void test_suite_x509_selftest()
1744{
1745 TEST_ASSERT( x509_self_test( 0 ) == 0 );
1746
1747exit:
1748 return;
1749}
1750#endif /* POLARSSL_X509_CRT_PARSE_C */
1751#endif /* POLARSSL_SELF_TEST */
1752
1753
1754#endif /* POLARSSL_BIGNUM_C */
1755
1756
1757int dep_check( char *str )
1758{
1759 if( str == NULL )
1760 return( 1 );
1761
1762 if( strcmp( str, "POLARSSL_PEM_PARSE_C" ) == 0 )
1763 {
1764#if defined(POLARSSL_PEM_PARSE_C)
1765 return( 0 );
1766#else
1767 return( 1 );
1768#endif
1769 }
1770 if( strcmp( str, "POLARSSL_ECP_C" ) == 0 )
1771 {
1772#if defined(POLARSSL_ECP_C)
1773 return( 0 );
1774#else
1775 return( 1 );
1776#endif
1777 }
1778 if( strcmp( str, "POLARSSL_X509_CHECK_KEY_USAGE" ) == 0 )
1779 {
1780#if defined(POLARSSL_X509_CHECK_KEY_USAGE)
1781 return( 0 );
1782#else
1783 return( 1 );
1784#endif
1785 }
1786 if( strcmp( str, "POLARSSL_MD5_C" ) == 0 )
1787 {
1788#if defined(POLARSSL_MD5_C)
1789 return( 0 );
1790#else
1791 return( 1 );
1792#endif
1793 }
1794 if( strcmp( str, "POLARSSL_X509_ALLOW_EXTENSIONS_NON_V3" ) == 0 )
1795 {
1796#if defined(POLARSSL_X509_ALLOW_EXTENSIONS_NON_V3)
1797 return( 0 );
1798#else
1799 return( 1 );
1800#endif
1801 }
1802 if( strcmp( str, "POLARSSL_ECP_DP_SECP383R1_ENABLED" ) == 0 )
1803 {
1804#if defined(POLARSSL_ECP_DP_SECP383R1_ENABLED)
1805 return( 0 );
1806#else
1807 return( 1 );
1808#endif
1809 }
1810 if( strcmp( str, "POLARSSL_RSA_C" ) == 0 )
1811 {
1812#if defined(POLARSSL_RSA_C)
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_SHA512_C" ) == 0 )
1827 {
1828#if defined(POLARSSL_SHA512_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_MD4_C" ) == 0 )
1843 {
1844#if defined(POLARSSL_MD4_C)
1845 return( 0 );
1846#else
1847 return( 1 );
1848#endif
1849 }
1850 if( strcmp( str, "POLARSSL_ECP_DP_SECP256R1_ENABLED" ) == 0 )
1851 {
1852#if defined(POLARSSL_ECP_DP_SECP256R1_ENABLED)
1853 return( 0 );
1854#else
1855 return( 1 );
1856#endif
1857 }
1858 if( strcmp( str, "POLARSSL_HAVE_TIME" ) == 0 )
1859 {
1860#if defined(POLARSSL_HAVE_TIME)
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_SHA256_C" ) == 0 )
1875 {
1876#if defined(POLARSSL_SHA256_C)
1877 return( 0 );
1878#else
1879 return( 1 );
1880#endif
1881 }
1882 if( strcmp( str, "POLARSSL_PKCS1_V15" ) == 0 )
1883 {
1884#if defined(POLARSSL_PKCS1_V15)
1885 return( 0 );
1886#else
1887 return( 1 );
1888#endif
1889 }
1890 if( strcmp( str, "POLARSSL_X509_RSASSA_PSS_SUPPORT" ) == 0 )
1891 {
1892#if defined(POLARSSL_X509_RSASSA_PSS_SUPPORT)
1893 return( 0 );
1894#else
1895 return( 1 );
1896#endif
1897 }
1898 if( strcmp( str, "POLARSSL_ECDSA_C" ) == 0 )
1899 {
1900#if defined(POLARSSL_ECDSA_C)
1901 return( 0 );
1902#else
1903 return( 1 );
1904#endif
1905 }
1906 if( strcmp( str, "POLARSSL_CERTS_C" ) == 0 )
1907 {
1908#if defined(POLARSSL_CERTS_C)
1909 return( 0 );
1910#else
1911 return( 1 );
1912#endif
1913 }
1914
1915
1916 return( 1 );
1917}
1918
1919int 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
2420int 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
2436int 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
2497int 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
RFC 1521 base64 encoding/decoding.
#define POLARSSL_ERR_BASE64_INVALID_CHARACTER
Invalid character in input.
Definition base64.h:33
Configuration options (set of defines)
#define POLARSSL_ERR_ASN1_OUT_OF_DATA
Out of data when parsing an ASN1 data structure.
Definition asn1.h:54
#define POLARSSL_ERR_ASN1_INVALID_LENGTH
Error when trying to determine the length or invalid length.
Definition asn1.h:56
int tag
ASN1 type, e.g.
Definition asn1.h:126
#define POLARSSL_ERR_ASN1_UNEXPECTED_TAG
ASN1 tag was of an unexpected value.
Definition asn1.h:55
#define ASN1_OID
Definition asn1.h:80
size_t len
ASN1 length, e.g.
Definition asn1.h:127
unsigned char * p
ASN1 data, e.g.
Definition asn1.h:128
#define POLARSSL_ERR_ASN1_INVALID_DATA
Data is invalid.
Definition asn1.h:58
#define ASN1_CONSTRUCTED
Definition asn1.h:92
#define ASN1_SEQUENCE
Definition asn1.h:82
#define POLARSSL_ERR_ASN1_LENGTH_MISMATCH
Actual length differs from expected length.
Definition asn1.h:57
x509_time valid_to
End time of certificate validity.
Definition x509_crt.h:73
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_X509_UNKNOWN_VERSION
CRT/CRL/CSR has an unsupported version number.
Definition x509.h:62
x509_name issuer
The parsed issuer data (named information object).
Definition x509_crt.h:69
#define KU_CRL_SIGN
Definition x509.h:99
int x509_crt_check_key_usage(const x509_crt *crt, int usage)
Check usage of certificate against keyUsage extension.
int x509_crl_info(char *buf, size_t size, const char *prefix, const x509_crl *crl)
Returns an informational string about the CRL.
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_CERT_VERIFY_FAILED
Certificate verification failed, e.g.
Definition x509.h:65
#define BADCERT_FUTURE
The certificate validity starts in the future.
Definition x509.h:85
void x509_crt_init(x509_crt *crt)
Initialize a certificate (chain)
int x509_crt_parse_file(x509_crt *chain, const char *path)
Load one or more certificates and add them to the chained list.
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.
#define KU_KEY_AGREEMENT
Definition x509.h:97
#define KU_DIGITAL_SIGNATURE
Definition x509.h:93
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.
#define POLARSSL_ERR_X509_INVALID_NAME
The name tag or value is invalid.
Definition x509.h:58
int x509_self_test(int verbose)
Checkup routine.
#define POLARSSL_ERR_X509_INVALID_DATE
The date tag or value is invalid.
Definition x509.h:59
#define BADCERT_REVOKED
The certificate has been revoked (is on a CRL).
Definition x509.h:77
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.
#define POLARSSL_ERR_X509_INVALID_SIGNATURE
The signature tag or value invalid.
Definition x509.h:60
#define POLARSSL_ERR_X509_BAD_INPUT_DATA
Input invalid.
Definition x509.h:67
void x509_csr_free(x509_csr *csr)
Unallocate all CSR data.
#define KU_KEY_CERT_SIGN
Definition x509.h:98
#define POLARSSL_ERR_X509_INVALID_SERIAL
The serial tag or value is invalid.
Definition x509.h:56
x509_time valid_from
Start time of certificate validity.
Definition x509_crt.h:72
void x509_crt_free(x509_crt *crt)
Unallocate all certificate data.
#define BADCERT_EXPIRED
The certificate validity has expired.
Definition x509.h:76
#define KU_KEY_ENCIPHERMENT
Definition x509.h:95
x509_buf raw
The raw certificate data (DER).
Definition x509_crt.h:59
#define BADCERT_NOT_TRUSTED
The certificate is not correctly signed by the trusted CA.
Definition x509.h:79
const char * x509_oid_get_description(x509_buf *oid)
Give an known OID, return its descriptive string.
#define POLARSSL_ERR_X509_INVALID_VERSION
The CRT/CRL/CSR version element is invalid.
Definition x509.h:55
int x509_crt_info(char *buf, size_t size, const char *prefix, const x509_crt *crt)
Returns an informational string about the certificate.
#define POLARSSL_ERR_X509_UNKNOWN_SIG_ALG
Signature algorithm (oid) is unsupported.
Definition x509.h:63
#define BADCRL_FUTURE
The CRL is from the future.
Definition x509.h:86
int x509_csr_parse_file(x509_csr *csr, const char *path)
Load a Certificate Signing Request (CSR)
void x509_crl_free(x509_crl *crl)
Unallocate all CRL data.
#define POLARSSL_ERR_X509_FEATURE_UNAVAILABLE
Unavailable feature, e.g.
Definition x509.h:52
x509_name subject
The parsed subject data (named information object).
Definition x509_crt.h:70
#define POLARSSL_ERR_X509_INVALID_FORMAT
The CRT/CRL/CSR format is invalid, e.g.
Definition x509.h:54
#define BADCERT_OTHER
Other reason (can be used by verify callback)
Definition x509.h:84
int x509_crl_parse_file(x509_crl *chain, const char *path)
Load one or more CRLs and add them to the chained list.
#define POLARSSL_ERR_X509_SIG_MISMATCH
Signature algorithms do not match.
Definition x509.h:64
int x509_csr_parse_der(x509_csr *csr, const unsigned char *buf, size_t buflen)
Load a Certificate Signing Request (CSR) in DER format.
#define POLARSSL_ERR_X509_INVALID_ALG
The algorithm tag or value is invalid.
Definition x509.h:57
void x509_csr_init(x509_csr *csr)
Initialize a CSR.
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.
#define BADCERT_CN_MISMATCH
The certificate Common Name (CN) does not match with the expected CN.
Definition x509.h:78
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 BADCRL_NOT_TRUSTED
CRL is not correctly signed by the trusted CA.
Definition x509.h:80
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.
#define BADCRL_EXPIRED
CRL is expired.
Definition x509.h:81
void x509_crl_init(x509_crl *crl)
Initialize a CRL (chain)
int x509_get_rsassa_pss_params(const x509_buf *params, md_type_t *md_alg, md_type_t *mgf_md, int *salt_len)
#define POLARSSL_ERR_X509_INVALID_EXTENSIONS
The extension tag or value is invalid.
Definition x509.h:61
struct _x509_crt * next
Next certificate in the CA-chain.
Definition x509_crt.h:98
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.
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.
md_type_t
Definition md.h:51
@ POLARSSL_MD_SHA1
Definition md.h:56
@ POLARSSL_MD_SHA256
Definition md.h:58
Memory allocation layer (Deprecated to platform layer)
void memory_buffer_alloc_free(void)
Free the mutex for thread-safety and clear remaining memory.
int memory_buffer_alloc_init(unsigned char *buf, size_t len)
Initialize use of stack-based memory allocator.
Object Identifier (OID) database.
#define POLARSSL_ERR_OID_NOT_FOUND
OID is not found.
Definition oid.h:50
#define POLARSSL_ERR_OID_BUF_TOO_SMALL
output buffer is too small
Definition oid.h:51
Privacy Enhanced Mail (PEM) decoding.
#define POLARSSL_ERR_PEM_INVALID_DATA
PEM string is not as expected.
Definition pem.h:39
#define POLARSSL_ERR_PK_KEY_INVALID_FORMAT
Invalid key tag or value.
Definition pk.h:56
#define POLARSSL_ERR_PK_INVALID_ALG
The algorithm tag or value is invalid.
Definition pk.h:61
#define POLARSSL_ERR_PK_UNKNOWN_PK_ALG
Key algorithm is unsupported (only RSA and EC are supported).
Definition pk.h:57
#define POLARSSL_ERR_PK_INVALID_PUBKEY
The pubkey tag or value is invalid (only RSA and EC are supported).
Definition pk.h:60
PolarSSL Platform abstraction layer.
Type-length-value structure that allows for ASN1 using DER.
Definition asn1.h:125
Certificate revocation list structure.
Definition x509_crl.h:74
Container for an X.509 certificate.
Definition x509_crt.h:58
Certificate Signing Request (CSR) structure.
Definition x509_csr.h:55
unsigned char * buf
Info structure for the pseudo random function.
int verify_int(char *str, int *value)
static int test_assert(int correct, const char *test)
int verify_string(char **str)
#define TEST_ASSERT(TEST)
static unsigned char * unhexify_alloc(const char *ibuf, size_t *olen)
Allocate and fill a buffer from hex data.
int dep_check(char *str)
int dispatch_test(int cnt, char *params[50])
#define polarssl_malloc
static void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
int parse_arguments(char *buf, size_t len, char *params[50])
#define polarssl_free
#define PUT_UINT32_BE(n, b, i)
static int rnd_pseudo_rand(void *rng_state, unsigned char *output, size_t len)
This function returns random based on a pseudo random function.
int get_line(FILE *f, char *buf, size_t len)
static int test_errors
static int rnd_buffer_rand(void *rng_state, unsigned char *output, size_t len)
This function returns random based on a buffer it receives.
static int unhexify(unsigned char *obuf, const char *ibuf)
static unsigned char * zero_alloc(size_t len)
Allocate and zeroize a buffer.
static int rnd_std_rand(void *rng_state, unsigned char *output, size_t len)
This function just returns data from rand().
int main()
static int rnd_zero_rand(void *rng_state, unsigned char *output, size_t len)
This function only returns zeros.
X.509 certificate revocation list parsing.
X.509 certificate parsing and writing.
X.509 certificate signing request parsing and writing.