mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-12-02 02:34:23 +01:00
Add next_merged
field to X.509 name comparison abort callback
This commit is contained in:
parent
10e6b9b2b5
commit
6b37812a45
@ -320,7 +320,8 @@ int mbedtls_x509_name_cmp_raw( mbedtls_x509_buf_raw const *a,
|
|||||||
mbedtls_x509_buf_raw const *b,
|
mbedtls_x509_buf_raw const *b,
|
||||||
int (*check)( void *ctx,
|
int (*check)( void *ctx,
|
||||||
mbedtls_x509_buf *oid,
|
mbedtls_x509_buf *oid,
|
||||||
mbedtls_x509_buf *val ),
|
mbedtls_x509_buf *val,
|
||||||
|
int next_merged ),
|
||||||
void *check_ctx );
|
void *check_ctx );
|
||||||
int mbedtls_x509_memcasecmp( const void *s1, const void *s2,
|
int mbedtls_x509_memcasecmp( const void *s1, const void *s2,
|
||||||
size_t len1, size_t lend2 );
|
size_t len1, size_t lend2 );
|
||||||
|
@ -451,39 +451,6 @@ exit:
|
|||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
int mbedtls_x509_get_name( unsigned char **p, const unsigned char *end,
|
|
||||||
mbedtls_x509_name *cur )
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
const unsigned char *end_set;
|
|
||||||
|
|
||||||
end_set = *p;
|
|
||||||
while( 1 )
|
|
||||||
{
|
|
||||||
ret = x509_set_sequence_iterate( p, &end_set, end,
|
|
||||||
&cur->oid, &cur->val );
|
|
||||||
if( ret != 0 )
|
|
||||||
return( ret + MBEDTLS_ERR_X509_INVALID_NAME );
|
|
||||||
|
|
||||||
if( *p != end_set )
|
|
||||||
cur->next_merged = 1;
|
|
||||||
|
|
||||||
if( *p == end )
|
|
||||||
{
|
|
||||||
cur->next = NULL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
cur->next = mbedtls_calloc( 1, sizeof( mbedtls_x509_name ) );
|
|
||||||
if( cur->next == NULL )
|
|
||||||
return( MBEDTLS_ERR_X509_ALLOC_FAILED );
|
|
||||||
|
|
||||||
cur = cur->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
return( 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Like memcmp, but case-insensitive and always returns -1 if different
|
* Like memcmp, but case-insensitive and always returns -1 if different
|
||||||
*/
|
*/
|
||||||
@ -572,7 +539,8 @@ int mbedtls_x509_name_cmp_raw( mbedtls_x509_buf_raw const *a,
|
|||||||
mbedtls_x509_buf_raw const *b,
|
mbedtls_x509_buf_raw const *b,
|
||||||
int (*abort_check)( void *ctx,
|
int (*abort_check)( void *ctx,
|
||||||
mbedtls_x509_buf *oid,
|
mbedtls_x509_buf *oid,
|
||||||
mbedtls_x509_buf *val ),
|
mbedtls_x509_buf *val,
|
||||||
|
int next_merged ),
|
||||||
void *abort_check_ctx )
|
void *abort_check_ctx )
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
@ -588,6 +556,7 @@ int mbedtls_x509_name_cmp_raw( mbedtls_x509_buf_raw const *a,
|
|||||||
|
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
|
int next_merged;
|
||||||
mbedtls_x509_buf oid_a, val_a, oid_b, val_b;
|
mbedtls_x509_buf oid_a, val_a, oid_b, val_b;
|
||||||
|
|
||||||
ret = x509_set_sequence_iterate( &p_a, (const unsigned char **) &set_a,
|
ret = x509_set_sequence_iterate( &p_a, (const unsigned char **) &set_a,
|
||||||
@ -609,12 +578,14 @@ int mbedtls_x509_name_cmp_raw( mbedtls_x509_buf_raw const *a,
|
|||||||
if( x509_string_cmp( &val_a, &val_b ) != 0 )
|
if( x509_string_cmp( &val_a, &val_b ) != 0 )
|
||||||
return( 1 );
|
return( 1 );
|
||||||
|
|
||||||
if( ( set_a == p_a ) != ( set_b == p_b ) )
|
next_merged = ( set_a != p_a );
|
||||||
|
if( next_merged != ( set_b != p_b ) )
|
||||||
return( 1 );
|
return( 1 );
|
||||||
|
|
||||||
if( abort_check != NULL )
|
if( abort_check != NULL )
|
||||||
{
|
{
|
||||||
ret = abort_check( abort_check_ctx, &oid_a, &val_a );
|
ret = abort_check( abort_check_ctx, &oid_a, &val_a,
|
||||||
|
next_merged );
|
||||||
if( ret != 0 )
|
if( ret != 0 )
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
@ -630,6 +601,41 @@ exit:
|
|||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int mbedtls_x509_get_name( unsigned char **p, const unsigned char *end,
|
||||||
|
mbedtls_x509_name *cur )
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
const unsigned char *end_set;
|
||||||
|
|
||||||
|
end_set = *p;
|
||||||
|
while( 1 )
|
||||||
|
{
|
||||||
|
ret = x509_set_sequence_iterate( p, &end_set, end,
|
||||||
|
&cur->oid, &cur->val );
|
||||||
|
if( ret != 0 )
|
||||||
|
return( ret + MBEDTLS_ERR_X509_INVALID_NAME );
|
||||||
|
|
||||||
|
if( *p != end_set )
|
||||||
|
cur->next_merged = 1;
|
||||||
|
|
||||||
|
if( *p == end )
|
||||||
|
{
|
||||||
|
cur->next = NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
cur->next = mbedtls_calloc( 1, sizeof( mbedtls_x509_name ) );
|
||||||
|
if( cur->next == NULL )
|
||||||
|
return( MBEDTLS_ERR_X509_ALLOC_FAILED );
|
||||||
|
|
||||||
|
cur = cur->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int x509_parse_int( unsigned char **p, size_t n, int *res )
|
static int x509_parse_int( unsigned char **p, size_t n, int *res )
|
||||||
{
|
{
|
||||||
*res = 0;
|
*res = 0;
|
||||||
|
@ -2420,10 +2420,12 @@ static int x509_crt_check_cn( unsigned char const *buf,
|
|||||||
* traversal as long as the callback returns 0. */
|
* traversal as long as the callback returns 0. */
|
||||||
static int x509_crt_check_name( void *ctx,
|
static int x509_crt_check_name( void *ctx,
|
||||||
mbedtls_x509_buf *oid,
|
mbedtls_x509_buf *oid,
|
||||||
mbedtls_x509_buf *val )
|
mbedtls_x509_buf *val,
|
||||||
|
int next_merged )
|
||||||
{
|
{
|
||||||
char const *cn = (char const*) ctx;
|
char const *cn = (char const*) ctx;
|
||||||
size_t cn_len = strlen( cn );
|
size_t cn_len = strlen( cn );
|
||||||
|
((void) next_merged);
|
||||||
|
|
||||||
if( MBEDTLS_OID_CMP( MBEDTLS_OID_AT_CN, oid ) == 0 &&
|
if( MBEDTLS_OID_CMP( MBEDTLS_OID_AT_CN, oid ) == 0 &&
|
||||||
x509_crt_check_cn( val->p, val->len, cn, cn_len ) == 0 )
|
x509_crt_check_cn( val->p, val->len, cn, cn_len ) == 0 )
|
||||||
|
Loading…
Reference in New Issue
Block a user