mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-08-08 17:42:09 +03:00
Test and fix x509_oid functions
This commit is contained in:
@@ -802,3 +802,27 @@ x509_crt_parse_path:"data_files/dir2":0:2
|
||||
X509 CRT parse path #4 (two certs, one non-cert)
|
||||
depends_on:POLARSSL_SHA1_C:POLARSSL_RSA_C:POLARSSL_SHA256_C:POLARSSL_ECDSA_C:POLARSSL_ECP_DP_SECP384R1_ENABLED
|
||||
x509_crt_parse_path:"data_files/dir3":1:2
|
||||
|
||||
X509 OID description #1
|
||||
x509_oid_desc:"2B06010505070301":"TLS Web Server Authentication"
|
||||
|
||||
X509 OID description #2
|
||||
x509_oid_desc:"2B0601050507030f":"notfound"
|
||||
|
||||
X509 OID description #3
|
||||
x509_oid_desc:"2B0601050507030100":"notfound"
|
||||
|
||||
X509 OID numstring #1 (wide buffer)
|
||||
x509_oid_numstr:"2B06010505070301":"1.3.6.1.5.5.7.3.1":20:17
|
||||
|
||||
X509 OID numstring #2 (buffer just fits)
|
||||
x509_oid_numstr:"2B06010505070301":"1.3.6.1.5.5.7.3.1":18:17
|
||||
|
||||
X509 OID numstring #3 (buffer too small)
|
||||
x509_oid_numstr:"2B06010505070301":"1.3.6.1.5.5.7.3.1":17:POLARSSL_ERR_OID_BUF_TOO_SMALL
|
||||
|
||||
X509 OID numstring #4 (larger number)
|
||||
x509_oid_numstr:"2A864886F70D":"1.2.840.113549":15:14
|
||||
|
||||
X509 OID numstring #5 (arithmetic overflow)
|
||||
x509_oid_numstr:"2A8648F9F8F7F6F5F4F3F2F1F001":"":100:POLARSSL_ERR_OID_BUF_TOO_SMALL
|
||||
|
@@ -265,6 +265,57 @@ void x509_crt_parse_path( char *crt_path, int ret, int nb_crt )
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void x509_oid_desc( char *oid_str, char *ref_desc )
|
||||
{
|
||||
x509_buf oid;
|
||||
const char *desc;
|
||||
unsigned char buf[20];
|
||||
|
||||
memset( buf, 0, sizeof buf );
|
||||
|
||||
oid.tag = ASN1_OID;
|
||||
oid.len = unhexify( buf, oid_str );
|
||||
oid.p = buf;
|
||||
|
||||
desc = x509_oid_get_description( &oid );
|
||||
|
||||
if( strcmp( ref_desc, "notfound" ) == 0 )
|
||||
TEST_ASSERT( desc == NULL );
|
||||
else
|
||||
{
|
||||
TEST_ASSERT( desc != NULL );
|
||||
TEST_ASSERT( strcmp( desc, ref_desc ) == 0 );
|
||||
}
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void x509_oid_numstr( char *oid_str, char *numstr, int blen, int ret )
|
||||
{
|
||||
x509_buf oid;
|
||||
unsigned char oid_buf[20];
|
||||
char num_buf[100];
|
||||
|
||||
memset( oid_buf, 0x00, sizeof oid_buf );
|
||||
memset( num_buf, 0x2a, sizeof num_buf );
|
||||
|
||||
oid.tag = ASN1_OID;
|
||||
oid.len = unhexify( oid_buf, oid_str );
|
||||
oid.p = oid_buf;
|
||||
|
||||
TEST_ASSERT( (size_t) blen <= sizeof num_buf );
|
||||
|
||||
TEST_ASSERT( x509_oid_get_numeric_string( num_buf, blen, &oid ) == ret );
|
||||
|
||||
if( ret >= 0 )
|
||||
{
|
||||
TEST_ASSERT( num_buf[ret] == 0 );
|
||||
TEST_ASSERT( strcmp( num_buf, numstr ) == 0 );
|
||||
}
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:POLARSSL_X509_CRT_PARSE_C:POLARSSL_SELF_TEST */
|
||||
void x509_selftest()
|
||||
{
|
||||
|
Reference in New Issue
Block a user