Commit 369d2eb2 authored by Paul Bakker's avatar Paul Bakker
Browse files

Introduced x509_crt_init(), x509_crl_init() and x509_csr_init()

parent 86d0c194
......@@ -134,6 +134,13 @@ int x509parse_crlfile( x509_crl *chain, const char *path );
int x509parse_crl_info( char *buf, size_t size, const char *prefix,
const x509_crl *crl );
/**
* \brief Initialize a CRL (chain)
*
* \param crl CRL chain to initialize
*/
void x509_crl_init( x509_crl *crl );
/**
* \brief Unallocate all CRL data
*
......
......@@ -254,6 +254,13 @@ int x509parse_verify( x509_cert *crt,
int x509parse_revoked( const x509_cert *crt, const x509_crl *crl );
#endif /* POLARSSL_X509_CRL_PARSE_C */
/**
* \brief Initialize a certificate (chain)
*
* \param crt Certificate chain to initialize
*/
void x509_crt_init( x509_cert *crt );
/**
* \brief Unallocate all certificate data
*
......
......@@ -117,6 +117,13 @@ int x509parse_csrfile( x509_csr *csr, const char *path );
int x509parse_csr_info( char *buf, size_t size, const char *prefix,
const x509_csr *csr );
/**
* \brief Initialize a CSR
*
* \param csr CSR to initialize
*/
void x509_csr_init( x509_csr *csr );
/**
* \brief Unallocate all CSR data
*
......
......@@ -279,7 +279,7 @@ int x509parse_crl( x509_crl *chain, const unsigned char *buf, size_t buflen )
}
crl = crl->next;
memset( crl, 0, sizeof( x509_crl ) );
x509_crl_init( crl );
}
#if defined(POLARSSL_PEM_PARSE_C)
......@@ -514,7 +514,7 @@ int x509parse_crl( x509_crl *chain, const unsigned char *buf, size_t buflen )
}
crl = crl->next;
memset( crl, 0, sizeof( x509_crl ) );
x509_crl_init( crl );
return( x509parse_crl( crl, buf, buflen ) );
}
......@@ -679,6 +679,14 @@ int x509parse_crl_info( char *buf, size_t size, const char *prefix,
return( (int) ( size - n ) );
}
/*
* Initialize a CRL chain
*/
void x509_crl_init( x509_crl *crl )
{
memset( crl, 0, sizeof(x509_crl) );
}
/*
* Unallocate all CRL data
*/
......
......@@ -785,7 +785,7 @@ int x509parse_crt_der( x509_cert *chain, const unsigned char *buf, size_t buflen
prev = crt;
crt = crt->next;
memset( crt, 0, sizeof( x509_cert ) );
x509_crt_init( crt );
}
if( ( ret = x509parse_crt_der_core( crt, buf, buflen ) ) != 0 )
......@@ -1602,6 +1602,14 @@ int x509parse_verify( x509_cert *crt,
return( 0 );
}
/*
* Initialize a certificate chain
*/
void x509_crt_init( x509_cert *crt )
{
memset( crt, 0, sizeof(x509_cert) );
}
/*
* Unallocate all certificate data
*/
......
......@@ -103,7 +103,7 @@ int x509parse_csr( x509_csr *csr, const unsigned char *buf, size_t buflen )
if( csr == NULL || buf == NULL )
return( POLARSSL_ERR_X509_BAD_INPUT_DATA );
memset( csr, 0, sizeof( x509_csr ) );
x509_csr_init( csr );
#if defined(POLARSSL_PEM_PARSE_C)
pem_init( &pem );
......@@ -405,6 +405,14 @@ int x509parse_csr_info( char *buf, size_t size, const char *prefix,
return( (int) ( size - n ) );
}
/*
* Initialize a CSR
*/
void x509_csr_init( x509_csr *csr )
{
memset( csr, 0, sizeof(x509_csr) );
}
/*
* Unallocate all CSR data
*/
......
......@@ -90,7 +90,7 @@ int main( int argc, char *argv[] )
* 0. Initialize the RNG and the session data
*/
memset( &ssl, 0, sizeof( ssl_context ) );
memset( &cacert, 0, sizeof( x509_cert ) );
x509_crt_init( &cacert );
printf( "\n . Seeding the random number generator..." );
fflush( stdout );
......
......@@ -269,8 +269,8 @@ int main( int argc, char *argv[] )
memset( &ssl, 0, sizeof( ssl_context ) );
memset( &saved_session, 0, sizeof( ssl_session ) );
#if defined(POLARSSL_X509_CRT_PARSE_C)
memset( &cacert, 0, sizeof( x509_cert ) );
memset( &clicert, 0, sizeof( x509_cert ) );
x509_crt_init( &cacert );
x509_crt_init( &clicert );
pk_init( &pkey );
#endif
......
......@@ -134,7 +134,7 @@ int main( int argc, char *argv[] )
printf( " . Loading the server cert. and key..." );
fflush( stdout );
memset( &srvcert, 0, sizeof( x509_cert ) );
x509_crt_init( &srvcert );
/*
* This demonstration program uses embedded test certificates.
......
......@@ -363,8 +363,8 @@ int main( int argc, char *argv[] )
* Make sure memory references are valid.
*/
server_fd = 0;
memset( &cacert, 0, sizeof( x509_cert ) );
memset( &clicert, 0, sizeof( x509_cert ) );
x509_crt_init( &cacert );
x509_crt_init( &clicert );
pk_init( &pkey );
if( argc == 0 )
......
......@@ -114,7 +114,7 @@ int main( int argc, char *argv[] )
printf( "\n . Loading the server cert. and key..." );
fflush( stdout );
memset( &srvcert, 0, sizeof( x509_cert ) );
x509_crt_init( &srvcert );
/*
* This demonstration program uses embedded test certificates.
......
......@@ -237,8 +237,8 @@ int main( int argc, char *argv[] )
*/
listen_fd = 0;
#if defined(POLARSSL_X509_CRT_PARSE_C)
memset( &cacert, 0, sizeof( x509_cert ) );
memset( &srvcert, 0, sizeof( x509_cert ) );
x509_crt_init( &cacert );
x509_crt_init( &srvcert );
pk_init( &pkey );
#endif
#if defined(POLARSSL_SSL_CACHE_C)
......
......@@ -89,8 +89,8 @@ int main( int argc, char *argv[] )
((void) argc);
((void) argv);
memset( &cacert, 0, sizeof( x509_cert ) );
memset( &crl, 0, sizeof( x509_crl ) );
x509_crt_init( &cacert );
x509_crl_init( &crl );
/*
* 1.1. Load the trusted CA
......@@ -142,7 +142,7 @@ int main( int argc, char *argv[] )
x509_cert clicert;
pk_context pk;
memset( &clicert, 0, sizeof( x509_cert ) );
x509_crt_init( &clicert );
pk_init( &pk );
snprintf(name, 512, "ssl/test-ca/%s", client_certificates[i]);
......
......@@ -187,7 +187,7 @@ static int ssl_test( struct options *opt )
memset( read_state, 0, sizeof( read_state ) );
memset( write_state, 0, sizeof( write_state ) );
memset( &srvcert, 0, sizeof( x509_cert ) );
x509_crt_init( &srvcert );
pk_init( &pkey );
if( opt->opmode == OPMODE_CLIENT )
......
......@@ -168,8 +168,8 @@ int main( int argc, char *argv[] )
* Set to sane values
*/
server_fd = 0;
memset( &cacert, 0, sizeof( x509_cert ) );
memset( &clicert, 0, sizeof( x509_cert ) );
x509_crt_init( &cacert );
x509_crt_init( &clicert );
pk_init( &pkey );
if( argc == 0 )
......@@ -269,7 +269,7 @@ int main( int argc, char *argv[] )
{
x509_cert crt;
x509_cert *cur = &crt;
memset( &crt, 0, sizeof( x509_cert ) );
x509_crt_init( &crt );
/*
* 1.1. Load the certificate(s)
......
......@@ -208,9 +208,9 @@ int main( int argc, char *argv[] )
pk_init( &loaded_subject_key );
mpi_init( &serial );
#if defined(POLARSSL_X509_CSR_PARSE_C)
memset( &csr, 0, sizeof(x509_csr) );
x509_csr_init( &csr );
#endif
memset( &issuer_crt, 0, sizeof(x509_cert) );
x509_crt_init( &issuer_crt );
memset( buf, 0, 1024 );
if( argc == 0 )
......
......@@ -76,7 +76,7 @@ int main( int argc, char *argv[] )
/*
* Set to sane values
*/
memset( &crl, 0, sizeof( x509_crl ) );
x509_crl_init( &crl );
if( argc == 0 )
{
......
......@@ -76,7 +76,7 @@ int main( int argc, char *argv[] )
/*
* Set to sane values
*/
memset( &csr, 0, sizeof( x509_csr ) );
x509_csr_init( &csr );
if( argc == 0 )
{
......
......@@ -30,7 +30,7 @@ void debug_print_crt( char *crt_file, char *file, int line, char *prefix,
ssl_context ssl;
struct buffer_data buffer;
memset( &crt, 0, sizeof( x509_cert ) );
x509_crt_init( &crt );
memset( &ssl, 0, sizeof( ssl_context ) );
memset( buffer.buf, 0, 2000 );
buffer.ptr = buffer.buf;
......
......@@ -38,7 +38,7 @@ void x509_cert_info( char *crt_file, char *result_str )
char buf[2000];
int res;
memset( &crt, 0, sizeof( x509_cert ) );
x509_crt_init( &crt );
memset( buf, 0, 2000 );
TEST_ASSERT( x509parse_crtfile( &crt, crt_file ) == 0 );
......@@ -60,7 +60,7 @@ void x509_crl_info( char *crl_file, char *result_str )
char buf[2000];
int res;
memset( &crl, 0, sizeof( x509_crl ) );
x509_crl_init( &crl );
memset( buf, 0, 2000 );
TEST_ASSERT( x509parse_crlfile( &crl, crl_file ) == 0 );
......@@ -88,9 +88,9 @@ void x509_verify( char *crt_file, char *ca_file, char *crl_file,
int (*f_vrfy)(void *, x509_cert *, int, int *) = NULL;
char * cn_name = NULL;
memset( &crt, 0, sizeof( x509_cert ) );
memset( &ca, 0, sizeof( x509_cert ) );
memset( &crl, 0, sizeof( x509_crl ) );
x509_crt_init( &crt );
x509_crt_init( &ca );
x509_crl_init( &crl );
if( strcmp( cn_name_str, "NULL" ) != 0 )
cn_name = cn_name_str;
......@@ -126,7 +126,7 @@ void x509_dn_gets( char *crt_file, char *entity, char *result_str )
char buf[2000];
int res = 0;
memset( &crt, 0, sizeof( x509_cert ) );
x509_crt_init( &crt );
memset( buf, 0, 2000 );
TEST_ASSERT( x509parse_crtfile( &crt, crt_file ) == 0 );
......@@ -151,7 +151,7 @@ void x509_time_expired( char *crt_file, char *entity, int result )
{
x509_cert crt;
memset( &crt, 0, sizeof( x509_cert ) );
x509_crt_init( &crt );
TEST_ASSERT( x509parse_crtfile( &crt, crt_file ) == 0 );
......@@ -174,7 +174,7 @@ void x509parse_crt( char *crt_data, char *result_str, int result )
unsigned char output[2000];
int data_len, res;
memset( &crt, 0, sizeof( x509_cert ) );
x509_crt_init( &crt );
memset( buf, 0, 2000 );
memset( output, 0, 2000 );
......@@ -203,7 +203,7 @@ void x509parse_crl( char *crl_data, char *result_str, int result )
unsigned char output[2000];
int data_len, res;
memset( &crl, 0, sizeof( x509_crl ) );
x509_crl_init( &crl );
memset( buf, 0, 2000 );
memset( output, 0, 2000 );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment