1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-29 11:41:15 +03:00

Merge pull request #5861 from wernerlewis/csr_subject_comma

Fix output of commas and other special characters in X509 DN values
This commit is contained in:
Gilles Peskine
2022-06-28 21:00:49 +02:00
committed by GitHub
8 changed files with 120 additions and 10 deletions

View File

@ -741,7 +741,7 @@ int mbedtls_x509_get_ext( unsigned char **p, const unsigned char *end,
int mbedtls_x509_dn_gets( char *buf, size_t size, const mbedtls_x509_name *dn )
{
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
size_t i, n;
size_t i, j, n;
unsigned char c, merge = 0;
const mbedtls_x509_name *name;
const char *short_name = NULL;
@ -775,17 +775,24 @@ int mbedtls_x509_dn_gets( char *buf, size_t size, const mbedtls_x509_name *dn )
ret = mbedtls_snprintf( p, n, "\?\?=" );
MBEDTLS_X509_SAFE_SNPRINTF;
for( i = 0; i < name->val.len; i++ )
for( i = 0, j = 0; i < name->val.len; i++, j++ )
{
if( i >= sizeof( s ) - 1 )
break;
if( j >= sizeof( s ) - 1 )
return( MBEDTLS_ERR_X509_BUFFER_TOO_SMALL );
c = name->val.p[i];
// Special characters requiring escaping, RFC 1779
if( c && strchr( ",=+<>#;\"\\", c ) )
{
if( j + 1 >= sizeof( s ) - 1 )
return( MBEDTLS_ERR_X509_BUFFER_TOO_SMALL );
s[j++] = '\\';
}
if( c < 32 || c >= 127 )
s[i] = '?';
else s[i] = c;
s[j] = '?';
else s[j] = c;
}
s[i] = '\0';
s[j] = '\0';
ret = mbedtls_snprintf( p, n, "%s", s );
MBEDTLS_X509_SAFE_SNPRINTF;