early-access version 1503
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
/* BEGIN_HEADER */
|
||||
#include "mbedtls/bignum.h"
|
||||
#include "mbedtls/x509_crt.h"
|
||||
#include "mbedtls/x509_csr.h"
|
||||
#include "mbedtls/pem.h"
|
||||
@@ -35,15 +36,16 @@ size_t mbedtls_rsa_key_len_func( void *ctx )
|
||||
*/
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_PEM_WRITE_C:MBEDTLS_X509_CSR_WRITE_C */
|
||||
void x509_csr_check( char *key_file, char *cert_req_check_file,
|
||||
int md_type, int key_usage, int cert_type )
|
||||
void x509_csr_check( char * key_file, char * cert_req_check_file, int md_type,
|
||||
int key_usage, int set_key_usage, int cert_type,
|
||||
int set_cert_type )
|
||||
{
|
||||
mbedtls_pk_context key;
|
||||
mbedtls_x509write_csr req;
|
||||
unsigned char buf[4096];
|
||||
unsigned char check_buf[4000];
|
||||
int ret;
|
||||
size_t olen = 0, pem_len = 0;
|
||||
size_t olen = 0, pem_len = 0, buf_index;
|
||||
int der_len = -1;
|
||||
FILE *f;
|
||||
const char *subject_name = "C=NL,O=PolarSSL,CN=PolarSSL Server 1";
|
||||
@@ -58,9 +60,9 @@ void x509_csr_check( char *key_file, char *cert_req_check_file,
|
||||
mbedtls_x509write_csr_set_md_alg( &req, md_type );
|
||||
mbedtls_x509write_csr_set_key( &req, &key );
|
||||
TEST_ASSERT( mbedtls_x509write_csr_set_subject_name( &req, subject_name ) == 0 );
|
||||
if( key_usage != 0 )
|
||||
if( set_key_usage != 0 )
|
||||
TEST_ASSERT( mbedtls_x509write_csr_set_key_usage( &req, key_usage ) == 0 );
|
||||
if( cert_type != 0 )
|
||||
if( set_cert_type != 0 )
|
||||
TEST_ASSERT( mbedtls_x509write_csr_set_ns_cert_type( &req, cert_type ) == 0 );
|
||||
|
||||
ret = mbedtls_x509write_csr_pem( &req, buf, sizeof( buf ),
|
||||
@@ -69,6 +71,11 @@ void x509_csr_check( char *key_file, char *cert_req_check_file,
|
||||
|
||||
pem_len = strlen( (char *) buf );
|
||||
|
||||
for( buf_index = pem_len; buf_index < sizeof( buf ); ++buf_index )
|
||||
{
|
||||
TEST_ASSERT( buf[buf_index] == 0 );
|
||||
}
|
||||
|
||||
f = fopen( cert_req_check_file, "r" );
|
||||
TEST_ASSERT( f != NULL );
|
||||
olen = fread( check_buf, 1, sizeof( check_buf ), f );
|
||||
@@ -99,7 +106,8 @@ void x509_crt_check( char *subject_key_file, char *subject_pwd,
|
||||
char *subject_name, char *issuer_key_file,
|
||||
char *issuer_pwd, char *issuer_name,
|
||||
char *serial_str, char *not_before, char *not_after,
|
||||
int md_type, int key_usage, int cert_type, int auth_ident,
|
||||
int md_type, int key_usage, int set_key_usage,
|
||||
int cert_type, int set_cert_type, int auth_ident,
|
||||
int ver, char *cert_check_file, int rsa_alt )
|
||||
{
|
||||
mbedtls_pk_context subject_key, issuer_key, issuer_key_alt;
|
||||
@@ -110,7 +118,7 @@ void x509_crt_check( char *subject_key_file, char *subject_pwd,
|
||||
unsigned char check_buf[5000];
|
||||
mbedtls_mpi serial;
|
||||
int ret;
|
||||
size_t olen = 0, pem_len = 0;
|
||||
size_t olen = 0, pem_len = 0, buf_index = 0;
|
||||
int der_len = -1;
|
||||
FILE *f;
|
||||
rnd_pseudo_info rnd_info;
|
||||
@@ -167,9 +175,9 @@ void x509_crt_check( char *subject_key_file, char *subject_pwd,
|
||||
TEST_ASSERT( mbedtls_x509write_crt_set_subject_key_identifier( &crt ) == 0 );
|
||||
if( auth_ident )
|
||||
TEST_ASSERT( mbedtls_x509write_crt_set_authority_key_identifier( &crt ) == 0 );
|
||||
if( key_usage != 0 )
|
||||
if( set_key_usage != 0 )
|
||||
TEST_ASSERT( mbedtls_x509write_crt_set_key_usage( &crt, key_usage ) == 0 );
|
||||
if( cert_type != 0 )
|
||||
if( set_cert_type != 0 )
|
||||
TEST_ASSERT( mbedtls_x509write_crt_set_ns_cert_type( &crt, cert_type ) == 0 );
|
||||
}
|
||||
|
||||
@@ -179,6 +187,12 @@ void x509_crt_check( char *subject_key_file, char *subject_pwd,
|
||||
|
||||
pem_len = strlen( (char *) buf );
|
||||
|
||||
// check that the rest of the buffer remains clear
|
||||
for( buf_index = pem_len; buf_index < sizeof( buf ); ++buf_index )
|
||||
{
|
||||
TEST_ASSERT( buf[buf_index] == 0 );
|
||||
}
|
||||
|
||||
f = fopen( cert_check_file, "r" );
|
||||
TEST_ASSERT( f != NULL );
|
||||
olen = fread( check_buf, 1, sizeof( check_buf ), f );
|
||||
@@ -209,7 +223,8 @@ exit:
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_X509_CREATE_C:MBEDTLS_X509_USE_C */
|
||||
void mbedtls_x509_string_to_names( char *name, char *parsed_name, int result )
|
||||
void mbedtls_x509_string_to_names( char * name, char * parsed_name, int result
|
||||
)
|
||||
{
|
||||
int ret;
|
||||
size_t len = 0;
|
||||
|
Reference in New Issue
Block a user