@@ -1190,6 +1190,7 @@ int mbedtls_x509_time_is_future(const mbedtls_x509_time *from)
11901190 *
11911191 * NOTE: we currently only parse and use otherName of type HwModuleName,
11921192 * as defined in RFC 4108.
1193+ * Other type-ids are kept as raw, undecoded ASN.1 bytes.
11931194 */
11941195static int x509_get_other_name (const mbedtls_x509_buf * subject_alt_name ,
11951196 mbedtls_x509_san_other_name * other_name )
@@ -1218,12 +1219,7 @@ static int x509_get_other_name(const mbedtls_x509_buf *subject_alt_name,
12181219 cur_oid .p = p ;
12191220 cur_oid .len = len ;
12201221
1221- /*
1222- * Only HwModuleName is currently supported.
1223- */
1224- if (MBEDTLS_OID_CMP (MBEDTLS_OID_ON_HW_MODULE_NAME , & cur_oid ) != 0 ) {
1225- return MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE ;
1226- }
1222+ /* Value context-specific tag */
12271223 other_name -> type_id = cur_oid ;
12281224
12291225 p += len ;
@@ -1238,38 +1234,64 @@ static int x509_get_other_name(const mbedtls_x509_buf *subject_alt_name,
12381234 MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
12391235 }
12401236
1241- if ((ret = mbedtls_asn1_get_tag (& p , end , & len ,
1242- MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE )) != 0 ) {
1243- return MBEDTLS_ERROR_ADD (MBEDTLS_ERR_X509_INVALID_EXTENSIONS , ret );
1244- }
1237+ /*
1238+ * HwModuleName
1239+ */
1240+ if (MBEDTLS_OID_CMP (MBEDTLS_OID_ON_HW_MODULE_NAME , & cur_oid ) == 0 ) {
1241+ if ((ret = mbedtls_asn1_get_tag (& p , end , & len ,
1242+ MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE )) != 0 ) {
1243+ return MBEDTLS_ERROR_ADD (MBEDTLS_ERR_X509_INVALID_EXTENSIONS , ret );
1244+ }
12451245
1246- if (end != p + len ) {
1247- return MBEDTLS_ERROR_ADD (MBEDTLS_ERR_X509_INVALID_EXTENSIONS ,
1248- MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
1249- }
1246+ if (end != p + len ) {
1247+ return MBEDTLS_ERROR_ADD (MBEDTLS_ERR_X509_INVALID_EXTENSIONS ,
1248+ MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
1249+ }
12501250
1251- if ((ret = mbedtls_asn1_get_tag (& p , end , & len , MBEDTLS_ASN1_OID )) != 0 ) {
1252- return MBEDTLS_ERROR_ADD (MBEDTLS_ERR_X509_INVALID_EXTENSIONS , ret );
1253- }
1251+ if ((ret = mbedtls_asn1_get_tag (& p , end , & len , MBEDTLS_ASN1_OID )) != 0 ) {
1252+ return MBEDTLS_ERROR_ADD (MBEDTLS_ERR_X509_INVALID_EXTENSIONS , ret );
1253+ }
12541254
1255- other_name -> value .hardware_module_name .oid .tag = MBEDTLS_ASN1_OID ;
1256- other_name -> value .hardware_module_name .oid .p = p ;
1257- other_name -> value .hardware_module_name .oid .len = len ;
1255+ other_name -> value .hardware_module_name .oid .tag = MBEDTLS_ASN1_OID ;
1256+ other_name -> value .hardware_module_name .oid .p = p ;
1257+ other_name -> value .hardware_module_name .oid .len = len ;
12581258
1259- p += len ;
1260- if ((ret = mbedtls_asn1_get_tag (& p , end , & len ,
1261- MBEDTLS_ASN1_OCTET_STRING )) != 0 ) {
1262- return MBEDTLS_ERROR_ADD (MBEDTLS_ERR_X509_INVALID_EXTENSIONS , ret );
1259+ p += len ;
1260+ if ((ret = mbedtls_asn1_get_tag (& p , end , & len ,
1261+ MBEDTLS_ASN1_OCTET_STRING )) != 0 ) {
1262+ return MBEDTLS_ERROR_ADD (MBEDTLS_ERR_X509_INVALID_EXTENSIONS , ret );
1263+ }
1264+
1265+ other_name -> value .hardware_module_name .val .tag = MBEDTLS_ASN1_OCTET_STRING ;
1266+ other_name -> value .hardware_module_name .val .p = p ;
1267+ other_name -> value .hardware_module_name .val .len = len ;
1268+ p += len ;
1269+ if (p != end ) {
1270+ return MBEDTLS_ERROR_ADD (MBEDTLS_ERR_X509_INVALID_EXTENSIONS ,
1271+ MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
1272+ }
12631273 }
1274+ /* Arbitrary raw value */
1275+ else {
1276+ if (p >= end ) {
1277+ return MBEDTLS_ERROR_ADD (MBEDTLS_ERR_X509_INVALID_EXTENSIONS ,
1278+ MBEDTLS_ERR_ASN1_OUT_OF_DATA );
1279+ }
1280+ other_name -> value .raw .tag = * p ;
1281+ p ++ ;
12641282
1265- other_name -> value .hardware_module_name .val .tag = MBEDTLS_ASN1_OCTET_STRING ;
1266- other_name -> value .hardware_module_name .val .p = p ;
1267- other_name -> value .hardware_module_name .val .len = len ;
1268- p += len ;
1269- if (p != end ) {
1270- return MBEDTLS_ERROR_ADD (MBEDTLS_ERR_X509_INVALID_EXTENSIONS ,
1271- MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
1283+ if ((ret = mbedtls_asn1_get_len (& p , end , & len )) != 0 ) {
1284+ return MBEDTLS_ERROR_ADD (MBEDTLS_ERR_X509_INVALID_EXTENSIONS , ret );
1285+ }
1286+ other_name -> value .raw .p = p ;
1287+ other_name -> value .raw .len = len ;
1288+ p += len ;
1289+ if (p != end ) {
1290+ return MBEDTLS_ERROR_ADD (MBEDTLS_ERR_X509_INVALID_EXTENSIONS ,
1291+ MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
1292+ }
12721293 }
1294+
12731295 return 0 ;
12741296}
12751297
@@ -1640,6 +1662,40 @@ int mbedtls_x509_info_subject_alt_name(char **buf, size_t *size,
16401662 MBEDTLS_X509_SAFE_SNPRINTF ;
16411663 }
16421664 }/* MBEDTLS_OID_ON_HW_MODULE_NAME */
1665+ else if (MBEDTLS_OID_CMP (MBEDTLS_OID_ON_BUNDLE_EID ,
1666+ & other_name -> type_id ) == 0 ) {
1667+ int len = 0 ;
1668+ const char * str = NULL ;
1669+ if (other_name -> value .raw .tag == MBEDTLS_ASN1_IA5_STRING ) {
1670+ len = other_name -> value .raw .len ;
1671+ str = (char * )other_name -> value .raw .p ;
1672+ }
1673+
1674+ ret = mbedtls_snprintf (p , n , "\n%s BundleEID : %.*s" , prefix ,
1675+ len , str );
1676+ MBEDTLS_X509_SAFE_SNPRINTF ;
1677+ }/* MBEDTLS_OID_ON_BUNDLE_EID */
1678+ else {
1679+ /* Show type OID */
1680+ ret = mbedtls_snprintf (p , n , "\n%s type-id : " , prefix );
1681+ MBEDTLS_X509_SAFE_SNPRINTF ;
1682+
1683+ ret = mbedtls_oid_get_numeric_string (p ,
1684+ n ,
1685+ & other_name -> type_id );
1686+ MBEDTLS_X509_SAFE_SNPRINTF ;
1687+
1688+ ret = mbedtls_snprintf (p , n , "\n%s value : " , prefix );
1689+ MBEDTLS_X509_SAFE_SNPRINTF ;
1690+
1691+ for (i = 0 ; i < other_name -> value .raw .len ; i ++ ) {
1692+ ret = mbedtls_snprintf (p ,
1693+ n ,
1694+ "%02X" ,
1695+ other_name -> value .raw .p [i ]);
1696+ MBEDTLS_X509_SAFE_SNPRINTF ;
1697+ }
1698+ }
16431699 }
16441700 break ;
16451701 /*
0 commit comments