mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-02-02 21:11:07 +00:00
Make use of cb to build linked list presentation of SubjectAltName
This commit is contained in:
parent
ad46219a88
commit
5984d30f4b
|
@ -599,80 +599,13 @@ static int x509_subject_alt_name_traverse( unsigned char *p,
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
static int x509_get_subject_alt_name( unsigned char **p,
|
||||
static int x509_get_subject_alt_name( unsigned char *p,
|
||||
const unsigned char *end,
|
||||
mbedtls_x509_sequence *subject_alt_name )
|
||||
{
|
||||
int ret;
|
||||
size_t len, tag_len;
|
||||
mbedtls_asn1_buf *buf;
|
||||
unsigned char tag;
|
||||
mbedtls_asn1_sequence *cur = subject_alt_name;
|
||||
|
||||
/* Get main sequence tag */
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
|
||||
if( *p + len != end )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
|
||||
while( *p < end )
|
||||
{
|
||||
if( ( end - *p ) < 1 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_OUT_OF_DATA );
|
||||
|
||||
tag = **p;
|
||||
(*p)++;
|
||||
if( ( ret = mbedtls_asn1_get_len( p, end, &tag_len ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
|
||||
if( ( tag & MBEDTLS_ASN1_TAG_CLASS_MASK ) !=
|
||||
MBEDTLS_ASN1_CONTEXT_SPECIFIC )
|
||||
{
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG );
|
||||
}
|
||||
|
||||
/* Skip everything but DNS name */
|
||||
if( tag != ( MBEDTLS_ASN1_CONTEXT_SPECIFIC | 2 ) )
|
||||
{
|
||||
*p += tag_len;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Allocate and assign next pointer */
|
||||
if( cur->buf.p != NULL )
|
||||
{
|
||||
if( cur->next != NULL )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS );
|
||||
|
||||
cur->next = mbedtls_calloc( 1, sizeof( mbedtls_asn1_sequence ) );
|
||||
|
||||
if( cur->next == NULL )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_ALLOC_FAILED );
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
buf = &(cur->buf);
|
||||
buf->tag = tag;
|
||||
buf->p = *p;
|
||||
buf->len = tag_len;
|
||||
*p += buf->len;
|
||||
}
|
||||
|
||||
/* Set final sequence entry's next pointer to NULL */
|
||||
cur->next = NULL;
|
||||
|
||||
if( *p != end )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
|
||||
return( 0 );
|
||||
return( x509_subject_alt_name_traverse( p, end,
|
||||
x509_get_subject_alt_name_cb,
|
||||
(void*) &subject_alt_name ) );
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -793,9 +726,12 @@ static int x509_get_crt_ext( unsigned char **p,
|
|||
/* Parse subject alt name */
|
||||
crt->subject_alt_raw.p = *p;
|
||||
crt->subject_alt_raw.len = end_ext_octet - *p;
|
||||
if( ( ret = x509_get_subject_alt_name( p, end_ext_octet,
|
||||
if( ( ret = x509_get_subject_alt_name( *p, end_ext_octet,
|
||||
&crt->subject_alt_names ) ) != 0 )
|
||||
{
|
||||
return( ret );
|
||||
}
|
||||
*p = end_ext_octet;
|
||||
break;
|
||||
|
||||
case MBEDTLS_X509_EXT_NS_CERT_TYPE:
|
||||
|
|
Loading…
Reference in a new issue