Introduced x509_crt_init(), x509_crl_init() and x509_csr_init()
This commit is contained in:
parent
86d0c1949e
commit
369d2eb2a2
20 changed files with 79 additions and 34 deletions
|
@ -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,
|
int x509parse_crl_info( char *buf, size_t size, const char *prefix,
|
||||||
const x509_crl *crl );
|
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
|
* \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 );
|
int x509parse_revoked( const x509_cert *crt, const x509_crl *crl );
|
||||||
#endif /* POLARSSL_X509_CRL_PARSE_C */
|
#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
|
* \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,
|
int x509parse_csr_info( char *buf, size_t size, const char *prefix,
|
||||||
const x509_csr *csr );
|
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
|
* \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;
|
crl = crl->next;
|
||||||
memset( crl, 0, sizeof( x509_crl ) );
|
x509_crl_init( crl );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(POLARSSL_PEM_PARSE_C)
|
#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;
|
crl = crl->next;
|
||||||
memset( crl, 0, sizeof( x509_crl ) );
|
x509_crl_init( crl );
|
||||||
|
|
||||||
return( x509parse_crl( crl, buf, buflen ) );
|
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 ) );
|
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
|
* Unallocate all CRL data
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -785,7 +785,7 @@ int x509parse_crt_der( x509_cert *chain, const unsigned char *buf, size_t buflen
|
||||||
|
|
||||||
prev = crt;
|
prev = crt;
|
||||||
crt = crt->next;
|
crt = crt->next;
|
||||||
memset( crt, 0, sizeof( x509_cert ) );
|
x509_crt_init( crt );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ( ret = x509parse_crt_der_core( crt, buf, buflen ) ) != 0 )
|
if( ( ret = x509parse_crt_der_core( crt, buf, buflen ) ) != 0 )
|
||||||
|
@ -1602,6 +1602,14 @@ int x509parse_verify( x509_cert *crt,
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initialize a certificate chain
|
||||||
|
*/
|
||||||
|
void x509_crt_init( x509_cert *crt )
|
||||||
|
{
|
||||||
|
memset( crt, 0, sizeof(x509_cert) );
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unallocate all certificate data
|
* 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 )
|
if( csr == NULL || buf == NULL )
|
||||||
return( POLARSSL_ERR_X509_BAD_INPUT_DATA );
|
return( POLARSSL_ERR_X509_BAD_INPUT_DATA );
|
||||||
|
|
||||||
memset( csr, 0, sizeof( x509_csr ) );
|
x509_csr_init( csr );
|
||||||
|
|
||||||
#if defined(POLARSSL_PEM_PARSE_C)
|
#if defined(POLARSSL_PEM_PARSE_C)
|
||||||
pem_init( &pem );
|
pem_init( &pem );
|
||||||
|
@ -405,6 +405,14 @@ int x509parse_csr_info( char *buf, size_t size, const char *prefix,
|
||||||
return( (int) ( size - n ) );
|
return( (int) ( size - n ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initialize a CSR
|
||||||
|
*/
|
||||||
|
void x509_csr_init( x509_csr *csr )
|
||||||
|
{
|
||||||
|
memset( csr, 0, sizeof(x509_csr) );
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unallocate all CSR data
|
* Unallocate all CSR data
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -90,7 +90,7 @@ int main( int argc, char *argv[] )
|
||||||
* 0. Initialize the RNG and the session data
|
* 0. Initialize the RNG and the session data
|
||||||
*/
|
*/
|
||||||
memset( &ssl, 0, sizeof( ssl_context ) );
|
memset( &ssl, 0, sizeof( ssl_context ) );
|
||||||
memset( &cacert, 0, sizeof( x509_cert ) );
|
x509_crt_init( &cacert );
|
||||||
|
|
||||||
printf( "\n . Seeding the random number generator..." );
|
printf( "\n . Seeding the random number generator..." );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
|
|
|
@ -269,8 +269,8 @@ int main( int argc, char *argv[] )
|
||||||
memset( &ssl, 0, sizeof( ssl_context ) );
|
memset( &ssl, 0, sizeof( ssl_context ) );
|
||||||
memset( &saved_session, 0, sizeof( ssl_session ) );
|
memset( &saved_session, 0, sizeof( ssl_session ) );
|
||||||
#if defined(POLARSSL_X509_CRT_PARSE_C)
|
#if defined(POLARSSL_X509_CRT_PARSE_C)
|
||||||
memset( &cacert, 0, sizeof( x509_cert ) );
|
x509_crt_init( &cacert );
|
||||||
memset( &clicert, 0, sizeof( x509_cert ) );
|
x509_crt_init( &clicert );
|
||||||
pk_init( &pkey );
|
pk_init( &pkey );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,7 @@ int main( int argc, char *argv[] )
|
||||||
printf( " . Loading the server cert. and key..." );
|
printf( " . Loading the server cert. and key..." );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
|
|
||||||
memset( &srvcert, 0, sizeof( x509_cert ) );
|
x509_crt_init( &srvcert );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This demonstration program uses embedded test certificates.
|
* This demonstration program uses embedded test certificates.
|
||||||
|
|
|
@ -363,8 +363,8 @@ int main( int argc, char *argv[] )
|
||||||
* Make sure memory references are valid.
|
* Make sure memory references are valid.
|
||||||
*/
|
*/
|
||||||
server_fd = 0;
|
server_fd = 0;
|
||||||
memset( &cacert, 0, sizeof( x509_cert ) );
|
x509_crt_init( &cacert );
|
||||||
memset( &clicert, 0, sizeof( x509_cert ) );
|
x509_crt_init( &clicert );
|
||||||
pk_init( &pkey );
|
pk_init( &pkey );
|
||||||
|
|
||||||
if( argc == 0 )
|
if( argc == 0 )
|
||||||
|
|
|
@ -114,7 +114,7 @@ int main( int argc, char *argv[] )
|
||||||
printf( "\n . Loading the server cert. and key..." );
|
printf( "\n . Loading the server cert. and key..." );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
|
|
||||||
memset( &srvcert, 0, sizeof( x509_cert ) );
|
x509_crt_init( &srvcert );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This demonstration program uses embedded test certificates.
|
* This demonstration program uses embedded test certificates.
|
||||||
|
|
|
@ -237,8 +237,8 @@ int main( int argc, char *argv[] )
|
||||||
*/
|
*/
|
||||||
listen_fd = 0;
|
listen_fd = 0;
|
||||||
#if defined(POLARSSL_X509_CRT_PARSE_C)
|
#if defined(POLARSSL_X509_CRT_PARSE_C)
|
||||||
memset( &cacert, 0, sizeof( x509_cert ) );
|
x509_crt_init( &cacert );
|
||||||
memset( &srvcert, 0, sizeof( x509_cert ) );
|
x509_crt_init( &srvcert );
|
||||||
pk_init( &pkey );
|
pk_init( &pkey );
|
||||||
#endif
|
#endif
|
||||||
#if defined(POLARSSL_SSL_CACHE_C)
|
#if defined(POLARSSL_SSL_CACHE_C)
|
||||||
|
|
|
@ -89,8 +89,8 @@ int main( int argc, char *argv[] )
|
||||||
((void) argc);
|
((void) argc);
|
||||||
((void) argv);
|
((void) argv);
|
||||||
|
|
||||||
memset( &cacert, 0, sizeof( x509_cert ) );
|
x509_crt_init( &cacert );
|
||||||
memset( &crl, 0, sizeof( x509_crl ) );
|
x509_crl_init( &crl );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 1.1. Load the trusted CA
|
* 1.1. Load the trusted CA
|
||||||
|
@ -142,7 +142,7 @@ int main( int argc, char *argv[] )
|
||||||
x509_cert clicert;
|
x509_cert clicert;
|
||||||
pk_context pk;
|
pk_context pk;
|
||||||
|
|
||||||
memset( &clicert, 0, sizeof( x509_cert ) );
|
x509_crt_init( &clicert );
|
||||||
pk_init( &pk );
|
pk_init( &pk );
|
||||||
|
|
||||||
snprintf(name, 512, "ssl/test-ca/%s", client_certificates[i]);
|
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( read_state, 0, sizeof( read_state ) );
|
||||||
memset( write_state, 0, sizeof( write_state ) );
|
memset( write_state, 0, sizeof( write_state ) );
|
||||||
|
|
||||||
memset( &srvcert, 0, sizeof( x509_cert ) );
|
x509_crt_init( &srvcert );
|
||||||
pk_init( &pkey );
|
pk_init( &pkey );
|
||||||
|
|
||||||
if( opt->opmode == OPMODE_CLIENT )
|
if( opt->opmode == OPMODE_CLIENT )
|
||||||
|
|
|
@ -168,8 +168,8 @@ int main( int argc, char *argv[] )
|
||||||
* Set to sane values
|
* Set to sane values
|
||||||
*/
|
*/
|
||||||
server_fd = 0;
|
server_fd = 0;
|
||||||
memset( &cacert, 0, sizeof( x509_cert ) );
|
x509_crt_init( &cacert );
|
||||||
memset( &clicert, 0, sizeof( x509_cert ) );
|
x509_crt_init( &clicert );
|
||||||
pk_init( &pkey );
|
pk_init( &pkey );
|
||||||
|
|
||||||
if( argc == 0 )
|
if( argc == 0 )
|
||||||
|
@ -269,7 +269,7 @@ int main( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
x509_cert crt;
|
x509_cert crt;
|
||||||
x509_cert *cur = &crt;
|
x509_cert *cur = &crt;
|
||||||
memset( &crt, 0, sizeof( x509_cert ) );
|
x509_crt_init( &crt );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 1.1. Load the certificate(s)
|
* 1.1. Load the certificate(s)
|
||||||
|
|
|
@ -208,9 +208,9 @@ int main( int argc, char *argv[] )
|
||||||
pk_init( &loaded_subject_key );
|
pk_init( &loaded_subject_key );
|
||||||
mpi_init( &serial );
|
mpi_init( &serial );
|
||||||
#if defined(POLARSSL_X509_CSR_PARSE_C)
|
#if defined(POLARSSL_X509_CSR_PARSE_C)
|
||||||
memset( &csr, 0, sizeof(x509_csr) );
|
x509_csr_init( &csr );
|
||||||
#endif
|
#endif
|
||||||
memset( &issuer_crt, 0, sizeof(x509_cert) );
|
x509_crt_init( &issuer_crt );
|
||||||
memset( buf, 0, 1024 );
|
memset( buf, 0, 1024 );
|
||||||
|
|
||||||
if( argc == 0 )
|
if( argc == 0 )
|
||||||
|
|
|
@ -76,7 +76,7 @@ int main( int argc, char *argv[] )
|
||||||
/*
|
/*
|
||||||
* Set to sane values
|
* Set to sane values
|
||||||
*/
|
*/
|
||||||
memset( &crl, 0, sizeof( x509_crl ) );
|
x509_crl_init( &crl );
|
||||||
|
|
||||||
if( argc == 0 )
|
if( argc == 0 )
|
||||||
{
|
{
|
||||||
|
|
|
@ -76,7 +76,7 @@ int main( int argc, char *argv[] )
|
||||||
/*
|
/*
|
||||||
* Set to sane values
|
* Set to sane values
|
||||||
*/
|
*/
|
||||||
memset( &csr, 0, sizeof( x509_csr ) );
|
x509_csr_init( &csr );
|
||||||
|
|
||||||
if( argc == 0 )
|
if( argc == 0 )
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,7 +30,7 @@ void debug_print_crt( char *crt_file, char *file, int line, char *prefix,
|
||||||
ssl_context ssl;
|
ssl_context ssl;
|
||||||
struct buffer_data buffer;
|
struct buffer_data buffer;
|
||||||
|
|
||||||
memset( &crt, 0, sizeof( x509_cert ) );
|
x509_crt_init( &crt );
|
||||||
memset( &ssl, 0, sizeof( ssl_context ) );
|
memset( &ssl, 0, sizeof( ssl_context ) );
|
||||||
memset( buffer.buf, 0, 2000 );
|
memset( buffer.buf, 0, 2000 );
|
||||||
buffer.ptr = buffer.buf;
|
buffer.ptr = buffer.buf;
|
||||||
|
|
|
@ -38,7 +38,7 @@ void x509_cert_info( char *crt_file, char *result_str )
|
||||||
char buf[2000];
|
char buf[2000];
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
memset( &crt, 0, sizeof( x509_cert ) );
|
x509_crt_init( &crt );
|
||||||
memset( buf, 0, 2000 );
|
memset( buf, 0, 2000 );
|
||||||
|
|
||||||
TEST_ASSERT( x509parse_crtfile( &crt, crt_file ) == 0 );
|
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];
|
char buf[2000];
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
memset( &crl, 0, sizeof( x509_crl ) );
|
x509_crl_init( &crl );
|
||||||
memset( buf, 0, 2000 );
|
memset( buf, 0, 2000 );
|
||||||
|
|
||||||
TEST_ASSERT( x509parse_crlfile( &crl, crl_file ) == 0 );
|
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;
|
int (*f_vrfy)(void *, x509_cert *, int, int *) = NULL;
|
||||||
char * cn_name = NULL;
|
char * cn_name = NULL;
|
||||||
|
|
||||||
memset( &crt, 0, sizeof( x509_cert ) );
|
x509_crt_init( &crt );
|
||||||
memset( &ca, 0, sizeof( x509_cert ) );
|
x509_crt_init( &ca );
|
||||||
memset( &crl, 0, sizeof( x509_crl ) );
|
x509_crl_init( &crl );
|
||||||
|
|
||||||
if( strcmp( cn_name_str, "NULL" ) != 0 )
|
if( strcmp( cn_name_str, "NULL" ) != 0 )
|
||||||
cn_name = cn_name_str;
|
cn_name = cn_name_str;
|
||||||
|
@ -126,7 +126,7 @@ void x509_dn_gets( char *crt_file, char *entity, char *result_str )
|
||||||
char buf[2000];
|
char buf[2000];
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
memset( &crt, 0, sizeof( x509_cert ) );
|
x509_crt_init( &crt );
|
||||||
memset( buf, 0, 2000 );
|
memset( buf, 0, 2000 );
|
||||||
|
|
||||||
TEST_ASSERT( x509parse_crtfile( &crt, crt_file ) == 0 );
|
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;
|
x509_cert crt;
|
||||||
|
|
||||||
memset( &crt, 0, sizeof( x509_cert ) );
|
x509_crt_init( &crt );
|
||||||
|
|
||||||
TEST_ASSERT( x509parse_crtfile( &crt, crt_file ) == 0 );
|
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];
|
unsigned char output[2000];
|
||||||
int data_len, res;
|
int data_len, res;
|
||||||
|
|
||||||
memset( &crt, 0, sizeof( x509_cert ) );
|
x509_crt_init( &crt );
|
||||||
memset( buf, 0, 2000 );
|
memset( buf, 0, 2000 );
|
||||||
memset( output, 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];
|
unsigned char output[2000];
|
||||||
int data_len, res;
|
int data_len, res;
|
||||||
|
|
||||||
memset( &crl, 0, sizeof( x509_crl ) );
|
x509_crl_init( &crl );
|
||||||
memset( buf, 0, 2000 );
|
memset( buf, 0, 2000 );
|
||||||
memset( output, 0, 2000 );
|
memset( output, 0, 2000 );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue