From f8a42862b72206be38b425f1c45a2232184d2def Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Wed, 20 Feb 2019 13:45:16 +0000 Subject: [PATCH] Add buffers with raw issuer/subject data to CRT structure --- include/mbedtls/x509_crt.h | 3 +++ library/x509_crt.c | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/include/mbedtls/x509_crt.h b/include/mbedtls/x509_crt.h index 09ba69f39..6e07ac6f2 100644 --- a/include/mbedtls/x509_crt.h +++ b/include/mbedtls/x509_crt.h @@ -64,6 +64,9 @@ typedef struct mbedtls_x509_crt mbedtls_x509_buf issuer_raw; /**< The raw issuer data (DER). Used for quick comparison. */ mbedtls_x509_buf subject_raw; /**< The raw subject data (DER). Used for quick comparison. */ + mbedtls_x509_buf_raw subject_raw_no_hdr; + mbedtls_x509_buf_raw issuer_raw_no_hdr; + mbedtls_x509_name issuer; /**< The parsed issuer data (named information object). */ mbedtls_x509_name subject; /**< The parsed subject data (named information object). */ diff --git a/library/x509_crt.c b/library/x509_crt.c index 6bec4d024..a05ea9ff4 100644 --- a/library/x509_crt.c +++ b/library/x509_crt.c @@ -848,6 +848,7 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt, mbedtls_x509_crt_free( crt ); return( MBEDTLS_ERR_X509_INVALID_FORMAT + ret ); } + crt->issuer_raw_no_hdr.p = p; if( ( ret = mbedtls_x509_get_name( &p, p + len, &crt->issuer ) ) != 0 ) { @@ -855,6 +856,7 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt, return( ret ); } + crt->issuer_raw_no_hdr.len = p - crt->issuer_raw_no_hdr.p; crt->issuer_raw.len = p - crt->issuer_raw.p; /* @@ -882,12 +884,15 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt, return( MBEDTLS_ERR_X509_INVALID_FORMAT + ret ); } + crt->subject_raw_no_hdr.p = p; + if( len && ( ret = mbedtls_x509_get_name( &p, p + len, &crt->subject ) ) != 0 ) { mbedtls_x509_crt_free( crt ); return( ret ); } + crt->subject_raw_no_hdr.len = p - crt->subject_raw_no_hdr.p; crt->subject_raw.len = p - crt->subject_raw.p; /*