1 #if !defined(POLARSSL_CONFIG_FILE)
4 #include POLARSSL_CONFIG_FILE
7 #ifdef POLARSSL_BIGNUM_C
9 #ifdef POLARSSL_PK_PARSE_C
20 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
24 #if defined(POLARSSL_PLATFORM_C)
27 #define polarssl_malloc malloc
28 #define polarssl_free free
33 typedef UINT32 uint32_t;
46 #define GET_UINT32_BE(n,b,i) \
48 (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
49 | ( (uint32_t) (b)[(i) + 1] << 16 ) \
50 | ( (uint32_t) (b)[(i) + 2] << 8 ) \
51 | ( (uint32_t) (b)[(i) + 3] ); \
56 #define PUT_UINT32_BE(n,b,i) \
58 (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
59 (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
60 (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
61 (b)[(i) + 3] = (unsigned char) ( (n) ); \
65 static int unhexify(
unsigned char *obuf,
const char *ibuf)
68 int len = strlen(ibuf) / 2;
69 assert(!(strlen(ibuf) %1));
74 if( c >=
'0' && c <=
'9' )
76 else if( c >=
'a' && c <=
'f' )
78 else if( c >=
'A' && c <=
'F' )
84 if( c2 >=
'0' && c2 <=
'9' )
86 else if( c2 >=
'a' && c2 <=
'f' )
88 else if( c2 >=
'A' && c2 <=
'F' )
93 *obuf++ = ( c << 4 ) | c2;
99 static void hexify(
unsigned char *obuf,
const unsigned char *ibuf,
int len)
111 *obuf++ =
'a' + h - 10;
116 *obuf++ =
'a' + l - 10;
133 size_t actual_len = len != 0 ? len : 1;
138 memset( p, 0x00, actual_len );
157 *olen = strlen(ibuf) / 2;
163 assert( obuf != NULL );
179 static int rnd_std_rand(
void *rng_state,
unsigned char *output,
size_t len )
181 #if !defined(__OpenBSD__)
184 if( rng_state != NULL )
187 for( i = 0; i < len; ++i )
190 if( rng_state != NULL )
193 arc4random_buf( output, len );
204 static int rnd_zero_rand(
void *rng_state,
unsigned char *output,
size_t len )
206 if( rng_state != NULL )
209 memset( output, 0, len );
236 if( rng_state == NULL )
245 memcpy( output, info->
buf, use_len );
246 info->
buf += use_len;
250 if( len - use_len > 0 )
251 return(
rnd_std_rand( NULL, output + use_len, len - use_len ) );
280 uint32_t i, *k, sum, delta=0x9E3779B9;
281 unsigned char result[4], *out = output;
283 if( rng_state == NULL )
290 size_t use_len = ( len > 4 ) ? 4 : len;
293 for( i = 0; i < 32; i++ )
295 info->
v0 += (((info->
v1 << 4) ^ (info->
v1 >> 5)) + info->
v1) ^ (sum + k[sum & 3]);
297 info->
v1 += (((info->
v0 << 4) ^ (info->
v0 >> 5)) + info->
v0) ^ (sum + k[(sum>>11) & 3]);
301 memcpy( out, result, use_len );
313 #if defined(POLARSSL_PLATFORM_C)
316 #define polarssl_printf printf
317 #define polarssl_malloc malloc
318 #define polarssl_free free
323 #ifdef POLARSSL_BIGNUM_C
324 #ifdef POLARSSL_FS_IO
325 #ifdef POLARSSL_PK_PARSE_C
327 #define TEST_SUITE_ACTIVE
329 static int test_assert(
int correct,
const char *test )
336 printf(
"FAILED\n" );
337 printf(
" %s\n", test );
342 #define TEST_ASSERT( TEST ) \
343 do { test_assert( (TEST) ? 1 : 0, #TEST ); \
344 if( test_errors) goto exit; \
349 if( (*str)[0] !=
'"' ||
350 (*str)[strlen( *str ) - 1] !=
'"' )
352 printf(
"Expected string (with \"\") for parameter and got: %s\n", *str );
357 (*str)[strlen( *str ) - 1] =
'\0';
369 for( i = 0; i < strlen( str ); i++ )
371 if( i == 0 && str[i] ==
'-' )
377 if( ( ( minus && i == 2 ) || ( !minus && i == 1 ) ) &&
378 str[i - 1] ==
'0' && str[i] ==
'x' )
384 if( ! ( ( str[i] >=
'0' && str[i] <=
'9' ) ||
385 ( hex && ( ( str[i] >=
'a' && str[i] <=
'f' ) ||
386 ( str[i] >=
'A' && str[i] <=
'F' ) ) ) ) )
396 *value = strtol( str, NULL, 16 );
398 *value = strtol( str, NULL, 10 );
403 #ifdef POLARSSL_X509_CREATE_C
404 #ifdef POLARSSL_X509_USE_C
405 if( strcmp( str,
"POLARSSL_ERR_X509_INVALID_NAME" ) == 0 )
410 #endif // POLARSSL_X509_CREATE_C
411 #endif // POLARSSL_X509_USE_C
412 #ifdef POLARSSL_PEM_WRITE_C
413 #ifdef POLARSSL_X509_CRT_WRITE_C
414 #ifdef POLARSSL_SHA1_C
415 if( strcmp( str,
"KU_DIGITAL_SIGNATURE | KU_NON_REPUDIATION | KU_KEY_ENCIPHERMENT" ) == 0 )
420 #endif // POLARSSL_PEM_WRITE_C
421 #endif // POLARSSL_X509_CRT_WRITE_C
422 #endif // POLARSSL_SHA1_C
423 #ifdef POLARSSL_PEM_WRITE_C
424 #ifdef POLARSSL_X509_CSR_WRITE_C
425 if( strcmp( str,
"KU_DIGITAL_SIGNATURE | KU_NON_REPUDIATION | KU_KEY_ENCIPHERMENT" ) == 0 )
430 #endif // POLARSSL_PEM_WRITE_C
431 #endif // POLARSSL_X509_CSR_WRITE_C
432 #ifdef POLARSSL_X509_CREATE_C
433 #ifdef POLARSSL_X509_USE_C
434 if( strcmp( str,
"POLARSSL_ERR_X509_UNKNOWN_OID" ) == 0 )
439 #endif // POLARSSL_X509_CREATE_C
440 #endif // POLARSSL_X509_USE_C
441 #ifdef POLARSSL_PEM_WRITE_C
442 #ifdef POLARSSL_X509_CSR_WRITE_C
443 if( strcmp( str,
"POLARSSL_MD_SHA384" ) == 0 )
448 #endif // POLARSSL_PEM_WRITE_C
449 #endif // POLARSSL_X509_CSR_WRITE_C
450 #ifdef POLARSSL_PEM_WRITE_C
451 #ifdef POLARSSL_X509_CSR_WRITE_C
452 if( strcmp( str,
"POLARSSL_MD_SHA224" ) == 0 )
457 #endif // POLARSSL_PEM_WRITE_C
458 #endif // POLARSSL_X509_CSR_WRITE_C
459 #ifdef POLARSSL_PEM_WRITE_C
460 #ifdef POLARSSL_X509_CRT_WRITE_C
461 #ifdef POLARSSL_SHA1_C
462 if( strcmp( str,
"X509_CRT_VERSION_1" ) == 0 )
467 #endif // POLARSSL_PEM_WRITE_C
468 #endif // POLARSSL_X509_CRT_WRITE_C
469 #endif // POLARSSL_SHA1_C
470 #ifdef POLARSSL_PEM_WRITE_C
471 #ifdef POLARSSL_X509_CRT_WRITE_C
472 #ifdef POLARSSL_SHA1_C
473 if( strcmp( str,
"-1" ) == 0 )
478 #endif // POLARSSL_PEM_WRITE_C
479 #endif // POLARSSL_X509_CRT_WRITE_C
480 #endif // POLARSSL_SHA1_C
481 #ifdef POLARSSL_PEM_WRITE_C
482 #ifdef POLARSSL_X509_CSR_WRITE_C
483 if( strcmp( str,
"KU_DIGITAL_SIGNATURE | KU_NON_REPUDIATION" ) == 0 )
488 #endif // POLARSSL_PEM_WRITE_C
489 #endif // POLARSSL_X509_CSR_WRITE_C
490 #ifdef POLARSSL_PEM_WRITE_C
491 #ifdef POLARSSL_X509_CSR_WRITE_C
492 if( strcmp( str,
"POLARSSL_MD_SHA256" ) == 0 )
497 #endif // POLARSSL_PEM_WRITE_C
498 #endif // POLARSSL_X509_CSR_WRITE_C
499 #ifdef POLARSSL_PEM_WRITE_C
500 #ifdef POLARSSL_X509_CRT_WRITE_C
501 #ifdef POLARSSL_SHA1_C
502 if( strcmp( str,
"NS_CERT_TYPE_SSL_SERVER" ) == 0 )
507 #endif // POLARSSL_PEM_WRITE_C
508 #endif // POLARSSL_X509_CRT_WRITE_C
509 #endif // POLARSSL_SHA1_C
510 #ifdef POLARSSL_PEM_WRITE_C
511 #ifdef POLARSSL_X509_CSR_WRITE_C
512 if( strcmp( str,
"NS_CERT_TYPE_SSL_SERVER" ) == 0 )
517 #endif // POLARSSL_PEM_WRITE_C
518 #endif // POLARSSL_X509_CSR_WRITE_C
519 #ifdef POLARSSL_PEM_WRITE_C
520 #ifdef POLARSSL_X509_CSR_WRITE_C
521 if( strcmp( str,
"POLARSSL_MD_MD4" ) == 0 )
526 #endif // POLARSSL_PEM_WRITE_C
527 #endif // POLARSSL_X509_CSR_WRITE_C
528 #ifdef POLARSSL_PEM_WRITE_C
529 #ifdef POLARSSL_X509_CSR_WRITE_C
530 if( strcmp( str,
"POLARSSL_MD_SHA1" ) == 0 )
535 #endif // POLARSSL_PEM_WRITE_C
536 #endif // POLARSSL_X509_CSR_WRITE_C
537 #ifdef POLARSSL_PEM_WRITE_C
538 #ifdef POLARSSL_X509_CRT_WRITE_C
539 #ifdef POLARSSL_SHA1_C
540 if( strcmp( str,
"POLARSSL_MD_SHA1" ) == 0 )
545 #endif // POLARSSL_PEM_WRITE_C
546 #endif // POLARSSL_X509_CRT_WRITE_C
547 #endif // POLARSSL_SHA1_C
548 #ifdef POLARSSL_PEM_WRITE_C
549 #ifdef POLARSSL_X509_CSR_WRITE_C
550 if( strcmp( str,
"POLARSSL_MD_SHA512" ) == 0 )
555 #endif // POLARSSL_PEM_WRITE_C
556 #endif // POLARSSL_X509_CSR_WRITE_C
557 #ifdef POLARSSL_PEM_WRITE_C
558 #ifdef POLARSSL_X509_CSR_WRITE_C
559 if( strcmp( str,
"POLARSSL_MD_MD5" ) == 0 )
564 #endif // POLARSSL_PEM_WRITE_C
565 #endif // POLARSSL_X509_CSR_WRITE_C
568 printf(
"Expected integer for parameter and got: %s\n", str );
572 #ifdef POLARSSL_PEM_WRITE_C
573 #ifdef POLARSSL_X509_CSR_WRITE_C
574 void test_suite_x509_csr_check(
char *key_file,
char *cert_req_check_file,
575 int md_type,
int key_usage,
int cert_type )
579 unsigned char buf[4000];
580 unsigned char check_buf[4000];
582 size_t olen = 0, pem_len = 0;
584 const char *subject_name =
"C=NL,O=PolarSSL,CN=PolarSSL Server 1";
605 pem_len = strlen( (
char *) buf );
607 f = fopen( cert_req_check_file,
"r" );
609 olen = fread( check_buf, 1,
sizeof( check_buf ), f );
613 TEST_ASSERT( memcmp( buf, check_buf, pem_len - 1 ) == 0 );
622 #ifdef POLARSSL_PEM_WRITE_C
623 #ifdef POLARSSL_X509_CRT_WRITE_C
624 #ifdef POLARSSL_SHA1_C
625 void test_suite_x509_crt_check(
char *subject_key_file,
char *subject_pwd,
626 char *subject_name,
char *issuer_key_file,
627 char *issuer_pwd,
char *issuer_name,
628 char *serial_str,
char *not_before,
char *not_after,
629 int md_type,
int key_usage,
int cert_type,
int ver,
630 char *cert_check_file )
634 unsigned char buf[4000];
635 unsigned char check_buf[5000];
638 size_t olen = 0, pem_len = 0;
648 subject_pwd ) == 0 );
680 pem_len = strlen( (
char *) buf );
682 f = fopen( cert_check_file,
"r" );
684 olen = fread( check_buf, 1,
sizeof(check_buf), f );
689 TEST_ASSERT( memcmp( buf, check_buf, pem_len - 1 ) == 0 );
701 #ifdef POLARSSL_X509_CREATE_C
702 #ifdef POLARSSL_X509_USE_C
703 void test_suite_x509_string_to_names(
char *name,
char *parsed_name,
int result )
708 x509_name parsed, *parsed_cur, *parsed_prv;
709 unsigned char buf[2048], *c;
711 memset( &parsed, 0,
sizeof( parsed ) );
712 memset( buf, 0,
sizeof( buf ) );
713 c = buf +
sizeof( buf );
728 ret =
x509_dn_gets( (
char *) buf,
sizeof( buf ), &parsed );
731 TEST_ASSERT( strcmp( (
char *) buf, parsed_name ) == 0 );
736 parsed_cur = parsed.
next;
737 while( parsed_cur != 0 )
739 parsed_prv = parsed_cur;
740 parsed_cur = parsed_cur->
next;
758 if( strcmp( str,
"POLARSSL_MD4_C" ) == 0 )
760 #if defined(POLARSSL_MD4_C)
766 if( strcmp( str,
"POLARSSL_PKCS1_V15" ) == 0 )
768 #if defined(POLARSSL_PKCS1_V15)
774 if( strcmp( str,
"POLARSSL_ECDSA_C" ) == 0 )
776 #if defined(POLARSSL_ECDSA_C)
782 if( strcmp( str,
"POLARSSL_SHA1_C" ) == 0 )
784 #if defined(POLARSSL_SHA1_C)
790 if( strcmp( str,
"POLARSSL_SHA256_C" ) == 0 )
792 #if defined(POLARSSL_SHA256_C)
798 if( strcmp( str,
"POLARSSL_ECDSA_DETERMINISTIC" ) == 0 )
800 #if defined(POLARSSL_ECDSA_DETERMINISTIC)
806 if( strcmp( str,
"POLARSSL_RSA_C" ) == 0 )
808 #if defined(POLARSSL_RSA_C)
814 if( strcmp( str,
"POLARSSL_DES_C" ) == 0 )
816 #if defined(POLARSSL_DES_C)
822 if( strcmp( str,
"POLARSSL_SHA512_C" ) == 0 )
824 #if defined(POLARSSL_SHA512_C)
830 if( strcmp( str,
"POLARSSL_ECP_DP_SECP256R1_ENABLED" ) == 0 )
832 #if defined(POLARSSL_ECP_DP_SECP256R1_ENABLED)
838 if( strcmp( str,
"POLARSSL_CIPHER_MODE_CBC" ) == 0 )
840 #if defined(POLARSSL_CIPHER_MODE_CBC)
846 if( strcmp( str,
"POLARSSL_MD5_C" ) == 0 )
848 #if defined(POLARSSL_MD5_C)
865 #if defined(TEST_SUITE_ACTIVE)
866 if( strcmp( params[0],
"x509_csr_check" ) == 0 )
868 #ifdef POLARSSL_PEM_WRITE_C
869 #ifdef POLARSSL_X509_CSR_WRITE_C
871 char *param1 = params[1];
872 char *param2 = params[2];
879 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 6 );
885 if(
verify_int( params[3], ¶m3 ) != 0 )
return( 2 );
886 if(
verify_int( params[4], ¶m4 ) != 0 )
return( 2 );
887 if(
verify_int( params[5], ¶m5 ) != 0 )
return( 2 );
889 test_suite_x509_csr_check( param1, param2, param3, param4, param5 );
897 if( strcmp( params[0],
"x509_crt_check" ) == 0 )
899 #ifdef POLARSSL_PEM_WRITE_C
900 #ifdef POLARSSL_X509_CRT_WRITE_C
901 #ifdef POLARSSL_SHA1_C
903 char *param1 = params[1];
904 char *param2 = params[2];
905 char *param3 = params[3];
906 char *param4 = params[4];
907 char *param5 = params[5];
908 char *param6 = params[6];
909 char *param7 = params[7];
910 char *param8 = params[8];
911 char *param9 = params[9];
916 char *param14 = params[14];
920 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 15 );
933 if(
verify_int( params[10], ¶m10 ) != 0 )
return( 2 );
934 if(
verify_int( params[11], ¶m11 ) != 0 )
return( 2 );
935 if(
verify_int( params[12], ¶m12 ) != 0 )
return( 2 );
936 if(
verify_int( params[13], ¶m13 ) != 0 )
return( 2 );
939 test_suite_x509_crt_check( param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14 );
948 if( strcmp( params[0],
"x509_string_to_names" ) == 0 )
950 #ifdef POLARSSL_X509_CREATE_C
951 #ifdef POLARSSL_X509_USE_C
953 char *param1 = params[1];
954 char *param2 = params[2];
959 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 4 );
965 if(
verify_int( params[3], ¶m3 ) != 0 )
return( 2 );
967 test_suite_x509_string_to_names( param1, param2, param3 );
977 fprintf( stdout,
"FAILED\nSkipping unknown test function '%s'\n", params[0] );
991 ret = fgets( buf, len, f );
995 if( strlen( buf ) && buf[strlen(buf) - 1] ==
'\n' )
996 buf[strlen(buf) - 1] =
'\0';
997 if( strlen( buf ) && buf[strlen(buf) - 1] ==
'\r' )
998 buf[strlen(buf) - 1] =
'\0';
1009 params[cnt++] = cur;
1011 while( *p !=
'\0' && p < buf + len )
1021 if( p + 1 < buf + len )
1024 params[cnt++] = cur;
1033 for( i = 0; i < cnt; i++ )
1040 if( *p ==
'\\' && *(p + 1) ==
'n' )
1045 else if( *p ==
'\\' && *(p + 1) ==
':' )
1050 else if( *p ==
'\\' && *(p + 1) ==
'?' )
1066 int ret, i, cnt, total_errors = 0, total_tests = 0, total_skipped = 0;
1067 const char *filename =
"/tmp/B.1c06a028-9709-4951-a65b-b24142b09746/BUILD/polarssl-1.3.9/tests/suites/test_suite_x509write.data";
1072 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
1073 unsigned char alloc_buf[1000000];
1077 file = fopen( filename,
"r" );
1080 fprintf( stderr,
"Failed to open\n" );
1084 while( !feof( file ) )
1088 if( ( ret =
get_line( file, buf,
sizeof(buf) ) ) != 0 )
1090 fprintf( stdout,
"%s%.66s",
test_errors ?
"\n" :
"", buf );
1091 fprintf( stdout,
" " );
1092 for( i = strlen( buf ) + 1; i < 67; i++ )
1093 fprintf( stdout,
"." );
1094 fprintf( stdout,
" " );
1099 if( ( ret =
get_line( file, buf,
sizeof(buf) ) ) != 0 )
1103 if( strcmp( params[0],
"depends_on" ) == 0 )
1105 for( i = 1; i < cnt; i++ )
1109 if( ( ret =
get_line( file, buf,
sizeof(buf) ) ) != 0 )
1120 if( skip == 1 || ret == 3 )
1123 fprintf( stdout,
"----\n" );
1128 fprintf( stdout,
"PASS\n" );
1133 fprintf( stderr,
"FAILED: FATAL PARSE ERROR\n" );
1140 if( ( ret =
get_line( file, buf,
sizeof(buf) ) ) != 0 )
1142 if( strlen(buf) != 0 )
1144 fprintf( stderr,
"Should be empty %d\n", (
int) strlen(buf) );
1150 fprintf( stdout,
"\n----------------------------------------------------------------------------\n\n");
1151 if( total_errors == 0 )
1152 fprintf( stdout,
"PASSED" );
1154 fprintf( stdout,
"FAILED" );
1156 fprintf( stdout,
" (%d / %d tests (%d skipped))\n",
1157 total_tests - total_errors, total_tests, total_skipped );
1159 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
1160 #if defined(POLARSSL_MEMORY_DEBUG)
1161 memory_buffer_alloc_status();
1166 return( total_errors != 0 );
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 x509write_csr_free(x509write_csr *ctx)
Free the contents of a CSR context.
void x509write_crt_set_version(x509write_cert *ctx, int version)
Set the verion for a Certificate Default: X509_CRT_VERSION_3.
static int rnd_zero_rand(void *rng_state, unsigned char *output, size_t len)
This function only returns zeros.
int x509_string_to_names(asn1_named_data **head, const char *name)
int x509write_crt_set_validity(x509write_cert *ctx, const char *not_before, const char *not_after)
Set the validity period for a Certificate Timestamps should be in string format for UTC timezone i...
#define KU_NON_REPUDIATION
Memory allocation layer (Deprecated to platform layer)
int x509_get_name(unsigned char **p, const unsigned char *end, x509_name *cur)
Info structure for the pseudo random function.
void memory_buffer_alloc_free(void)
Free the mutex for thread-safety and clear remaining memory.
void x509write_csr_set_md_alg(x509write_csr *ctx, md_type_t md_alg)
Set the MD algorithm to use for the signature (e.g.
int x509write_csr_set_ns_cert_type(x509write_csr *ctx, unsigned char ns_cert_type)
Set the Netscape Cert Type flags (e.g.
Configuration options (set of defines)
int x509write_csr_pem(x509write_csr *ctx, unsigned char *buf, size_t size, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Write a CSR (Certificate Signing Request) to a PEM string.
void x509write_crt_set_md_alg(x509write_cert *ctx, md_type_t md_alg)
Set the MD algorithm to use for the signature (e.g.
#define PUT_UINT32_BE(n, b, i)
static int test_assert(int correct, const char *test)
int x509write_csr_set_key_usage(x509write_csr *ctx, unsigned char key_usage)
Set the Key Usage Extension flags (e.g.
void mpi_init(mpi *X)
Initialize one MPI.
Object Identifier (OID) database.
int memory_buffer_alloc_init(unsigned char *buf, size_t len)
Initialize use of stack-based memory allocator.
#define TEST_ASSERT(TEST)
int x509_write_names(unsigned char **p, unsigned char *start, asn1_named_data *first)
int x509write_crt_set_key_usage(x509write_cert *ctx, unsigned char key_usage)
Set the Key Usage Extension flags (e.g.
static void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
void x509write_crt_free(x509write_cert *ctx)
Free the contents of a CRT write context.
Privacy Enhanced Mail (PEM) decoding.
#define X509_CRT_VERSION_3
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...
int x509write_crt_set_subject_key_identifier(x509write_cert *ctx)
Set the subjectKeyIdentifier extension for a CRT Requires that x509write_crt_set_subject_key() has be...
static unsigned char * zero_alloc(size_t len)
Allocate and zeroize a buffer.
#define POLARSSL_ERR_X509_UNKNOWN_OID
Requested OID is unknown.
int x509write_crt_set_issuer_name(x509write_cert *ctx, const char *issuer_name)
Set the issuer name for a Certificate Issuer names should contain a comma-separated list of OID types...
X.509 certificate signing request parsing and writing.
void mpi_free(mpi *X)
Unallocate one MPI.
void x509write_csr_init(x509write_csr *ctx)
Initialize a CSR context.
X.509 certificate parsing and writing.
void x509write_crt_set_issuer_key(x509write_cert *ctx, pk_context *key)
Set the issuer key used for signing the certificate.
int x509write_crt_set_serial(x509write_cert *ctx, const mpi *serial)
Set the serial number for a Certificate.
int get_line(FILE *f, char *buf, size_t len)
void x509write_csr_set_key(x509write_csr *ctx, pk_context *key)
Set the key for a CSR (public key will be included, private key used to sign the CSR when writing it)...
int x509write_crt_set_authority_key_identifier(x509write_cert *ctx)
Set the authorityKeyIdentifier extension for a CRT Requires that x509write_crt_set_issuer_key() has b...
int x509write_crt_set_ns_cert_type(x509write_cert *ctx, unsigned char ns_cert_type)
Set the Netscape Cert Type flags (e.g.
Container for writing a certificate (CRT)
int mpi_read_string(mpi *X, int radix, const char *s)
Import from an ASCII string.
Container for a sequence or list of 'named' ASN.1 data items.
#define X509_CRT_VERSION_1
int x509write_crt_set_subject_name(x509write_cert *ctx, const char *subject_name)
Set the subject name for a Certificate Subject names should contain a comma-separated list of OID typ...
int verify_string(char **str)
void asn1_free_named_data_list(asn1_named_data **head)
Free all entries in a asn1_named_data list Head will be set to NULL.
#define POLARSSL_ERR_X509_INVALID_NAME
The name tag or value is invalid.
void pk_free(pk_context *ctx)
Free a pk_context.
static int rnd_std_rand(void *rng_state, unsigned char *output, size_t len)
This function just returns data from rand().
int parse_arguments(char *buf, size_t len, char *params[50])
int x509write_crt_set_basic_constraints(x509write_cert *ctx, int is_ca, int max_pathlen)
Set the basicConstraints extension for a CRT.
void pk_init(pk_context *ctx)
Initialize a pk_context (as NONE)
int asn1_get_tag(unsigned char **p, const unsigned char *end, size_t *len, int tag)
Get the tag and length of the tag.
#define KU_DIGITAL_SIGNATURE
#define NS_CERT_TYPE_SSL_SERVER
struct _asn1_named_data * next
The next entry in the sequence.
int x509write_csr_set_subject_name(x509write_csr *ctx, const char *subject_name)
Set the subject name for a CSR Subject names should contain a comma-separated list of OID types and v...
int dispatch_test(int cnt, char *params[50])
void x509write_crt_init(x509write_cert *ctx)
Initialize a CRT writing context.
static int rnd_buffer_rand(void *rng_state, unsigned char *output, size_t len)
This function returns random based on a buffer it receives.
int verify_int(char *str, int *value)
static int unhexify(unsigned char *obuf, const char *ibuf)
void x509write_crt_set_subject_key(x509write_cert *ctx, pk_context *key)
Set the subject public key for the certificate.
int pk_parse_keyfile(pk_context *ctx, const char *path, const char *password)
Load and parse a private key.
int x509write_crt_pem(x509write_cert *ctx, unsigned char *buf, size_t size, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Write a built up certificate to a X509 PEM string.
#define KU_KEY_ENCIPHERMENT
Container for writing a CSR.
static unsigned char * unhexify_alloc(const char *ibuf, size_t *olen)
Allocate and fill a buffer from hex data.