@@ -1951,15 +1951,15 @@ bool libspdm_gen_x509_csr(size_t hash_nid, size_t asym_nid,
1951
1951
mbedtls_x509write_csr req ;
1952
1952
mbedtls_md_type_t md_alg ;
1953
1953
mbedtls_asn1_sequence extns ;
1954
- mbedtls_asn1_sequence * next ;
1954
+ mbedtls_asn1_sequence * next_oid ;
1955
1955
mbedtls_x509_buf buf ;
1956
1956
mbedtls_x509_crt * cert ;
1957
1957
mbedtls_pk_context key ;
1958
1958
1959
1959
uint8_t pubkey_buffer [LIBSPDM_MAX_PUBKEY_DER_BUFFER_SIZE ];
1960
1960
uint8_t * pubkey_der_data ;
1961
1961
size_t pubkey_der_len ;
1962
- size_t tag_len ;
1962
+ size_t oid_tag_len ;
1963
1963
1964
1964
/*basic_constraints: CA: false */
1965
1965
#define BASIC_CONSTRAINTS_STRING_FALSE {0x30, 0x00}
@@ -1973,7 +1973,7 @@ bool libspdm_gen_x509_csr(size_t hash_nid, size_t asym_nid,
1973
1973
mbedtls_x509write_csr_init (& req );
1974
1974
mbedtls_pk_init (& key );
1975
1975
csr_buffer_size = * csr_len ;
1976
- next = NULL ;
1976
+ next_oid = NULL ;
1977
1977
1978
1978
ret = 1 ;
1979
1979
switch (asym_nid )
@@ -2073,55 +2073,55 @@ bool libspdm_gen_x509_csr(size_t hash_nid, size_t asym_nid,
2073
2073
/* Set key */
2074
2074
mbedtls_x509write_csr_set_key (& req , & key );
2075
2075
2076
+ /*set basicConstraints*/
2077
+ if (mbedtls_x509write_csr_set_extension (& req , MBEDTLS_OID_BASIC_CONSTRAINTS ,
2078
+ MBEDTLS_OID_SIZE (MBEDTLS_OID_BASIC_CONSTRAINTS ),
2079
+ is_ca ? basic_constraints_true : basic_constraints_false ,
2080
+ is_ca ?
2081
+ sizeof (basic_constraints_true ) :
2082
+ sizeof (basic_constraints_false )
2083
+ ) != 0 ) {
2084
+ ret = 1 ;
2085
+ LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO ,
2086
+ "mbedtls_x509write_csr_set_extension set basicConstraints failed \n" ));
2087
+ goto free_all ;
2088
+ }
2089
+
2076
2090
if (base_cert != NULL ) {
2077
2091
cert = base_cert ;
2078
2092
buf = cert -> v3_ext ;
2079
2093
if (mbedtls_asn1_get_sequence_of (& buf .p , buf .p + buf .len , & extns ,
2080
2094
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE )) {
2081
2095
ret = 1 ;
2082
2096
LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO ,
2083
- "mbedtls_x509write_csr_set_extension unable to get tag \n" ));
2097
+ "mbedtls_x509write_csr_set_extension unable to get sequence \n" ));
2084
2098
goto free_all ;
2085
2099
}
2086
2100
2087
- next = & extns ;
2101
+ next_oid = & extns ;
2088
2102
}
2089
2103
2090
- while (next ) {
2091
- if (mbedtls_asn1_get_tag (& (next -> buf .p ), next -> buf .p + next -> buf .len , & tag_len ,
2092
- MBEDTLS_ASN1_OID )) {
2104
+ while (next_oid ) {
2105
+ if (mbedtls_asn1_get_tag (& (next_oid -> buf .p ), next_oid -> buf .p + next_oid -> buf .len ,
2106
+ & oid_tag_len , MBEDTLS_ASN1_OID )) {
2093
2107
ret = 1 ;
2094
2108
LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO ,
2095
- "mbedtls_x509write_csr_set_extension unable to get tag\n" ));
2109
+ "mbedtls_x509write_csr_set_extension unable to get OID tag\n" ));
2096
2110
goto free_all ;
2097
2111
}
2098
2112
2099
- if (mbedtls_x509write_csr_set_extension (& req , MBEDTLS_OID_BASIC_CONSTRAINTS ,
2100
- MBEDTLS_OID_SIZE ( MBEDTLS_OID_BASIC_CONSTRAINTS ) ,
2101
- next -> buf .p ,
2102
- tag_len
2113
+ if (mbedtls_x509write_csr_set_extension (& req , next_oid -> buf . p ,
2114
+ oid_tag_len ,
2115
+ next_oid -> buf .p + oid_tag_len ,
2116
+ next_oid -> buf . len - oid_tag_len
2103
2117
) != 0 ) {
2104
2118
ret = 1 ;
2105
2119
LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO ,
2106
2120
"mbedtls_x509write_csr_set_extension set custom OID failed \n" ));
2107
2121
goto free_all ;
2108
2122
}
2109
2123
2110
- next = next -> next ;
2111
- }
2112
-
2113
- /*set basicConstraints*/
2114
- if (mbedtls_x509write_csr_set_extension (& req , MBEDTLS_OID_BASIC_CONSTRAINTS ,
2115
- MBEDTLS_OID_SIZE (MBEDTLS_OID_BASIC_CONSTRAINTS ),
2116
- is_ca ? basic_constraints_true : basic_constraints_false ,
2117
- is_ca ?
2118
- sizeof (basic_constraints_true ) :
2119
- sizeof (basic_constraints_false )
2120
- ) != 0 ) {
2121
- ret = 1 ;
2122
- LIBSPDM_DEBUG ((LIBSPDM_DEBUG_INFO ,
2123
- "mbedtls_x509write_csr_set_extension set basicConstraints failed \n" ));
2124
- goto free_all ;
2124
+ next_oid = next_oid -> next ;
2125
2125
}
2126
2126
2127
2127
/*csr data is written at the end of the buffer*/
0 commit comments