mirror of
https://git.suyu.dev/suyu/mbedtls.git
synced 2026-01-04 05:35:33 +01:00
Rewrote x509 certificate request writing to use structure for storing
This commit is contained in:
parent
43fdd617e1
commit
8eabfc1461
4 changed files with 215 additions and 119 deletions
|
|
@ -16,31 +16,14 @@ void x509_cert_req_check( char *key_file, int md_type,
|
|||
{
|
||||
rsa_context rsa;
|
||||
pem_context pem;
|
||||
x509_req_name req_name, *cur;
|
||||
x509_cert_req req;
|
||||
unsigned char *c;
|
||||
unsigned char buf[4000];
|
||||
unsigned char check_buf[4000];
|
||||
int ret;
|
||||
size_t olen = 2000;
|
||||
FILE *f;
|
||||
|
||||
cur = &req_name;
|
||||
|
||||
memset( cur, 0, sizeof(x509_req_name) );
|
||||
strcpy( cur->oid, OID_AT_CN );
|
||||
strcpy( cur->name, "PolarSSL Server 1" );
|
||||
cur->next = malloc( sizeof(x509_req_name) );
|
||||
cur = cur->next;
|
||||
|
||||
memset( cur, 0, sizeof(x509_req_name) );
|
||||
strcpy( cur->oid, OID_AT_ORGANIZATION );
|
||||
strcpy( cur->name, "PolarSSL" );
|
||||
cur->next = malloc( sizeof(x509_req_name) );
|
||||
cur = cur->next;
|
||||
|
||||
memset( cur, 0, sizeof(x509_req_name) );
|
||||
strcpy( cur->oid, OID_AT_COUNTRY );
|
||||
strcpy( cur->name, "NL" );
|
||||
char *subject_name = "CN=PolarSSL Server 1,O=PolarSSL,C=NL";
|
||||
|
||||
memset( &rsa, 0, sizeof(rsa_context) );
|
||||
ret = x509parse_keyfile_rsa( &rsa, key_file, NULL );
|
||||
|
|
@ -48,7 +31,12 @@ void x509_cert_req_check( char *key_file, int md_type,
|
|||
if( ret != 0 )
|
||||
return;
|
||||
|
||||
ret = x509_write_cert_req( buf, 4000, &rsa, &req_name, md_type );
|
||||
x509cert_req_init( &req );
|
||||
x509cert_req_set_md_alg( &req, md_type );
|
||||
x509cert_req_set_rsa_key( &req, &rsa );
|
||||
TEST_ASSERT( x509cert_req_set_subject_name( &req, subject_name ) == 0 );
|
||||
|
||||
ret = x509_write_cert_req( &req, buf, 4000 );
|
||||
TEST_ASSERT( ret >= 0 );
|
||||
|
||||
c = buf + 3999 - ret;
|
||||
|
|
@ -64,12 +52,7 @@ void x509_cert_req_check( char *key_file, int md_type,
|
|||
TEST_ASSERT( memcmp( c, pem.buf, pem.buflen ) == 0 );
|
||||
TEST_ASSERT( pem.buflen == (size_t) ret );
|
||||
|
||||
while( ( cur = req_name.next ) != NULL )
|
||||
{
|
||||
req_name.next = cur->next;
|
||||
free( cur );
|
||||
}
|
||||
|
||||
x509cert_req_free( &req );
|
||||
rsa_free( &rsa );
|
||||
pem_free( &pem );
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue