|
|
|
@ -346,13 +346,10 @@ static tsi_result add_pem_certificate(X509* cert, tsi_peer_property* property) { |
|
|
|
|
/* Gets the subject SANs from an X509 cert as a tsi_peer_property. */ |
|
|
|
|
static tsi_result add_subject_alt_names_properties_to_peer( |
|
|
|
|
tsi_peer* peer, GENERAL_NAMES* subject_alt_names, |
|
|
|
|
size_t subject_alt_name_count) { |
|
|
|
|
size_t subject_alt_name_count, int* current_insert_index) { |
|
|
|
|
size_t i; |
|
|
|
|
tsi_result result = TSI_OK; |
|
|
|
|
|
|
|
|
|
/* Reset for DNS entries filtering. */ |
|
|
|
|
peer->property_count -= subject_alt_name_count; |
|
|
|
|
|
|
|
|
|
for (i = 0; i < subject_alt_name_count; i++) { |
|
|
|
|
GENERAL_NAME* subject_alt_name = |
|
|
|
|
sk_GENERAL_NAME_value(subject_alt_names, TSI_SIZE_AS_SIZE(i)); |
|
|
|
@ -377,13 +374,7 @@ static tsi_result add_subject_alt_names_properties_to_peer( |
|
|
|
|
result = tsi_construct_string_peer_property( |
|
|
|
|
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, |
|
|
|
|
reinterpret_cast<const char*>(name), static_cast<size_t>(name_size), |
|
|
|
|
&peer->properties[peer->property_count++]); |
|
|
|
|
if (subject_alt_name->type == GEN_URI) { |
|
|
|
|
result = tsi_construct_string_peer_property( |
|
|
|
|
TSI_X509_URI_PEER_PROPERTY, reinterpret_cast<const char*>(name), |
|
|
|
|
static_cast<size_t>(name_size), |
|
|
|
|
&peer->properties[peer->property_count++]); |
|
|
|
|
} |
|
|
|
|
&peer->properties[(*current_insert_index)++]); |
|
|
|
|
OPENSSL_free(name); |
|
|
|
|
} else if (subject_alt_name->type == GEN_IPADD) { |
|
|
|
|
char ntop_buf[INET6_ADDRSTRLEN]; |
|
|
|
@ -408,7 +399,24 @@ static tsi_result add_subject_alt_names_properties_to_peer( |
|
|
|
|
|
|
|
|
|
result = tsi_construct_string_peer_property_from_cstring( |
|
|
|
|
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, name, |
|
|
|
|
&peer->properties[peer->property_count++]); |
|
|
|
|
&peer->properties[(*current_insert_index)++]); |
|
|
|
|
} |
|
|
|
|
if (result != TSI_OK) break; |
|
|
|
|
if (subject_alt_name->type == GEN_URI) { |
|
|
|
|
unsigned char* name = nullptr; |
|
|
|
|
int name_size; |
|
|
|
|
name_size = ASN1_STRING_to_UTF8( |
|
|
|
|
&name, subject_alt_name->d.uniformResourceIdentifier); |
|
|
|
|
if (name_size < 0) { |
|
|
|
|
gpr_log(GPR_ERROR, "Could not get utf8 from asn1 string."); |
|
|
|
|
result = TSI_INTERNAL_ERROR; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
result = tsi_construct_string_peer_property( |
|
|
|
|
TSI_X509_URI_PEER_PROPERTY, reinterpret_cast<const char*>(name), |
|
|
|
|
static_cast<size_t>(name_size), |
|
|
|
|
&peer->properties[(*current_insert_index)++]); |
|
|
|
|
OPENSSL_free(name); |
|
|
|
|
} |
|
|
|
|
if (result != TSI_OK) break; |
|
|
|
|
} |
|
|
|
@ -431,26 +439,35 @@ static tsi_result peer_from_x509(X509* cert, int include_certificate_type, |
|
|
|
|
property_count = (include_certificate_type ? static_cast<size_t>(1) : 0) + |
|
|
|
|
2 /* common name, certificate */ + |
|
|
|
|
static_cast<size_t>(subject_alt_name_count); |
|
|
|
|
for (int i = 0; i < subject_alt_name_count; i++) { |
|
|
|
|
GENERAL_NAME* subject_alt_name = |
|
|
|
|
sk_GENERAL_NAME_value(subject_alt_names, TSI_SIZE_AS_SIZE(i)); |
|
|
|
|
if (subject_alt_name->type == GEN_URI) { |
|
|
|
|
property_count += 1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
result = tsi_construct_peer(property_count, peer); |
|
|
|
|
if (result != TSI_OK) return result; |
|
|
|
|
int current_insert_index = 0; |
|
|
|
|
do { |
|
|
|
|
if (include_certificate_type) { |
|
|
|
|
result = tsi_construct_string_peer_property_from_cstring( |
|
|
|
|
TSI_CERTIFICATE_TYPE_PEER_PROPERTY, TSI_X509_CERTIFICATE_TYPE, |
|
|
|
|
&peer->properties[0]); |
|
|
|
|
&peer->properties[current_insert_index++]); |
|
|
|
|
if (result != TSI_OK) break; |
|
|
|
|
} |
|
|
|
|
result = peer_property_from_x509_common_name( |
|
|
|
|
cert, &peer->properties[include_certificate_type ? 1 : 0]); |
|
|
|
|
cert, &peer->properties[current_insert_index++]); |
|
|
|
|
if (result != TSI_OK) break; |
|
|
|
|
|
|
|
|
|
result = add_pem_certificate( |
|
|
|
|
cert, &peer->properties[include_certificate_type ? 2 : 1]); |
|
|
|
|
result = |
|
|
|
|
add_pem_certificate(cert, &peer->properties[current_insert_index++]); |
|
|
|
|
if (result != TSI_OK) break; |
|
|
|
|
|
|
|
|
|
if (subject_alt_name_count != 0) { |
|
|
|
|
result = add_subject_alt_names_properties_to_peer( |
|
|
|
|
peer, subject_alt_names, static_cast<size_t>(subject_alt_name_count)); |
|
|
|
|
peer, subject_alt_names, static_cast<size_t>(subject_alt_name_count), |
|
|
|
|
¤t_insert_index); |
|
|
|
|
if (result != TSI_OK) break; |
|
|
|
|
} |
|
|
|
|
} while (0); |
|
|
|
@ -459,6 +476,8 @@ static tsi_result peer_from_x509(X509* cert, int include_certificate_type, |
|
|
|
|
sk_GENERAL_NAME_pop_free(subject_alt_names, GENERAL_NAME_free); |
|
|
|
|
} |
|
|
|
|
if (result != TSI_OK) tsi_peer_destruct(peer); |
|
|
|
|
|
|
|
|
|
GPR_ASSERT((int)peer->property_count == current_insert_index); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|