@ -40,20 +40,6 @@
# define TSI_OPENSSL_ALPN_SUPPORT 1
# endif
static int check_transport_security_type ( const grpc_auth_context * ctx ) {
grpc_auth_property_iterator it = grpc_auth_context_find_properties_by_name (
ctx , GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME ) ;
const grpc_auth_property * prop = grpc_auth_property_iterator_next ( & it ) ;
if ( prop = = nullptr ) return 0 ;
if ( strncmp ( prop - > value , GRPC_SSL_TRANSPORT_SECURITY_TYPE ,
prop - > value_length ) ! = 0 ) {
return 0 ;
}
/* Check that we have only one property with this name. */
if ( grpc_auth_property_iterator_next ( & it ) ! = nullptr ) return 0 ;
return 1 ;
}
static int check_peer_property ( const tsi_peer * peer ,
const tsi_peer_property * expected ) {
size_t i ;
@ -106,124 +92,30 @@ static void test_check_security_level() {
GRPC_SECURITY_NONE ) = = true ) ;
}
static void test_unauthenticated_ssl_peer ( void ) {
tsi_peer peer ;
tsi_peer rpeer ;
GPR_ASSERT ( tsi_construct_peer ( 2 , & peer ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_CERTIFICATE_TYPE_PEER_PROPERTY , TSI_X509_CERTIFICATE_TYPE ,
& peer . properties [ 0 ] ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_SECURITY_LEVEL_PEER_PROPERTY ,
tsi_security_level_to_string ( TSI_PRIVACY_AND_INTEGRITY ) ,
& peer . properties [ 1 ] ) = = TSI_OK ) ;
grpc_core : : RefCountedPtr < grpc_auth_context > ctx =
grpc_ssl_peer_to_auth_context ( & peer , GRPC_SSL_TRANSPORT_SECURITY_TYPE ) ;
GPR_ASSERT ( ctx ! = nullptr ) ;
GPR_ASSERT ( ! grpc_auth_context_peer_is_authenticated ( ctx . get ( ) ) ) ;
GPR_ASSERT ( check_transport_security_type ( ctx . get ( ) ) ) ;
rpeer = grpc_shallow_peer_from_ssl_auth_context ( ctx . get ( ) ) ;
GPR_ASSERT ( check_ssl_peer_equivalence ( & peer , & rpeer ) ) ;
grpc_shallow_peer_destruct ( & rpeer ) ;
tsi_peer_destruct ( & peer ) ;
ctx . reset ( DEBUG_LOCATION , " test " ) ;
}
static int check_identity ( const grpc_auth_context * ctx ,
static int check_property ( const grpc_auth_context * ctx ,
const char * expected_property_name ,
const char * * expected_identities ,
size_t num_identities ) {
grpc_auth_property_iterator it ;
const grpc_auth_property * prop ;
size_t i ;
GPR_ASSERT ( grpc_auth_context_peer_is_authenticated ( ctx ) ) ;
it = grpc_auth_context_peer_identity ( ctx ) ;
for ( i = 0 ; i < num_identities ; i + + ) {
prop = grpc_auth_property_iterator_next ( & it ) ;
if ( prop = = nullptr ) {
gpr_log ( GPR_ERROR , " Expected identity value %s not found. " ,
expected_identities [ i ] ) ;
return 0 ;
}
if ( strcmp ( prop - > name , expected_property_name ) ! = 0 ) {
gpr_log ( GPR_ERROR , " Expected peer identity property name %s and got %s. " ,
expected_property_name , prop - > name ) ;
return 0 ;
}
if ( strncmp ( prop - > value , expected_identities [ i ] , prop - > value_length ) ! = 0 ) {
gpr_log ( GPR_ERROR , " Expected peer identity %s and got %s. " ,
expected_identities [ i ] , prop - > value ) ;
return 0 ;
}
}
return 1 ;
}
static int check_x509_cn ( const grpc_auth_context * ctx ,
const char * expected_cn ) {
grpc_auth_property_iterator it = grpc_auth_context_find_properties_by_name (
ctx , GRPC_X509_CN_PROPERTY_NAME ) ;
const grpc_auth_property * prop = grpc_auth_property_iterator_next ( & it ) ;
if ( prop = = nullptr ) {
gpr_log ( GPR_ERROR , " CN property not found. " ) ;
return 0 ;
}
if ( strncmp ( prop - > value , expected_cn , prop - > value_length ) ! = 0 ) {
gpr_log ( GPR_ERROR , " Expected CN %s and got %s " , expected_cn , prop - > value ) ;
return 0 ;
}
if ( grpc_auth_property_iterator_next ( & it ) ! = nullptr ) {
gpr_log ( GPR_ERROR , " Expected only one property for CN. " ) ;
return 0 ;
}
return 1 ;
}
static int check_x509_pem_cert ( const grpc_auth_context * ctx ,
const char * expected_pem_cert ) {
grpc_auth_property_iterator it = grpc_auth_context_find_properties_by_name (
ctx , GRPC_X509_PEM_CERT_PROPERTY_NAME ) ;
const grpc_auth_property * prop = grpc_auth_property_iterator_next ( & it ) ;
if ( prop = = nullptr ) {
gpr_log ( GPR_ERROR , " Pem certificate property not found. " ) ;
return 0 ;
}
if ( strncmp ( prop - > value , expected_pem_cert , prop - > value_length ) ! = 0 ) {
gpr_log ( GPR_ERROR , " Expected pem cert %s and got %s " , expected_pem_cert ,
prop - > value ) ;
return 0 ;
}
if ( grpc_auth_property_iterator_next ( & it ) ! = nullptr ) {
gpr_log ( GPR_ERROR , " Expected only one property for pem cert. " ) ;
return 0 ;
}
return 1 ;
}
static int check_x509_pem_cert_chain ( const grpc_auth_context * ctx ,
const char * expected_pem_cert_chain ) {
grpc_auth_property_iterator it = grpc_auth_context_find_properties_by_name (
ctx , GRPC_X509_PEM_CERT_CHAIN_PROPERTY_NAME ) ;
const char * expected_property_value ) {
grpc_auth_property_iterator it =
grpc_auth_context_find_properties_by_name ( ctx , expected_property_name ) ;
const grpc_auth_property * prop = grpc_auth_property_iterator_next ( & it ) ;
if ( prop = = nullptr ) {
gpr_log ( GPR_ERROR , " Pem certificate chain property not found. " ) ;
gpr_log ( GPR_ERROR , " Expected value %s not found. " , expected_property_value ) ;
return 0 ;
}
if ( strncmp ( prop - > value , expected_pem_cert_chain , prop - > value_length ) ! = 0 ) {
gpr_log ( GPR_ERROR , " Expected pem cert chain %s and got %s " ,
expected_pem_cert_chain , prop - > value ) ;
if ( strncmp ( prop - > value , expected_property_value , prop - > value_length ) ! = 0 ) {
gpr_log ( GPR_ERROR , " Expected value %s and got %s for property %s. " ,
expected_property_value , prop - > value , expected_property_name ) ;
return 0 ;
}
if ( grpc_auth_property_iterator_next ( & it ) ! = nullptr ) {
gpr_log ( GPR_ERROR , " Expected only one property for pem cert chain. " ) ;
gpr_log ( GPR_ERROR , " Expected only one property for %s. " ,
expected_property_name ) ;
return 0 ;
}
return 1 ;
}
static int check_san s (
static int check_properties (
const grpc_auth_context * ctx , const char * expected_property_name ,
const std : : vector < std : : string > & expected_property_values ) {
grpc_auth_property_iterator it =
@ -235,9 +127,14 @@ static int check_sans(
property_value . c_str ( ) ) ;
return 0 ;
}
if ( strcmp ( prop - > name , expected_property_name ) ! = 0 ) {
gpr_log ( GPR_ERROR , " Expected peer property name %s and got %s. " ,
expected_property_name , prop - > name ) ;
return 0 ;
}
if ( strncmp ( prop - > value , property_value . c_str ( ) , prop - > value_length ) ! = 0 ) {
gpr_log ( GPR_ERROR , " Expected peer %s and got %s. " , property_value . c_str ( ) ,
prop - > value ) ;
gpr_log ( GPR_ERROR , " Expected peer property value %s and got %s. " ,
property_value . c_str ( ) , prop - > value ) ;
return 0 ;
}
}
@ -278,6 +175,33 @@ static int check_spiffe_id(const grpc_auth_context* ctx,
return 1 ;
}
static void test_unauthenticated_ssl_peer ( void ) {
tsi_peer peer ;
tsi_peer rpeer ;
GPR_ASSERT ( tsi_construct_peer ( 2 , & peer ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_CERTIFICATE_TYPE_PEER_PROPERTY , TSI_X509_CERTIFICATE_TYPE ,
& peer . properties [ 0 ] ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_SECURITY_LEVEL_PEER_PROPERTY ,
tsi_security_level_to_string ( TSI_PRIVACY_AND_INTEGRITY ) ,
& peer . properties [ 1 ] ) = = TSI_OK ) ;
grpc_core : : RefCountedPtr < grpc_auth_context > ctx =
grpc_ssl_peer_to_auth_context ( & peer , GRPC_SSL_TRANSPORT_SECURITY_TYPE ) ;
GPR_ASSERT ( ctx ! = nullptr ) ;
GPR_ASSERT ( ! grpc_auth_context_peer_is_authenticated ( ctx . get ( ) ) ) ;
GPR_ASSERT ( check_property ( ctx . get ( ) ,
GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME ,
GRPC_SSL_TRANSPORT_SECURITY_TYPE ) ) ;
rpeer = grpc_shallow_peer_from_ssl_auth_context ( ctx . get ( ) ) ;
GPR_ASSERT ( check_ssl_peer_equivalence ( & peer , & rpeer ) ) ;
grpc_shallow_peer_destruct ( & rpeer ) ;
tsi_peer_destruct ( & peer ) ;
ctx . reset ( DEBUG_LOCATION , " test " ) ;
}
static void test_cn_only_ssl_peer_to_auth_context ( void ) {
tsi_peer peer ;
tsi_peer rpeer ;
@ -306,11 +230,16 @@ static void test_cn_only_ssl_peer_to_auth_context(void) {
GPR_ASSERT ( ctx ! = nullptr ) ;
GPR_ASSERT ( grpc_auth_context_peer_is_authenticated ( ctx . get ( ) ) ) ;
GPR_ASSERT (
check_identity ( ctx . get ( ) , GRPC_X509_CN_PROPERTY_NAME , & expected_cn , 1 ) ) ;
GPR_ASSERT ( check_transport_security_type ( ctx . get ( ) ) ) ;
GPR_ASSERT ( check_x509_cn ( ctx . get ( ) , expected_cn ) ) ;
GPR_ASSERT ( check_x509_pem_cert ( ctx . get ( ) , expected_pem_cert ) ) ;
GPR_ASSERT ( check_x509_pem_cert_chain ( ctx . get ( ) , expected_pem_cert_chain ) ) ;
check_property ( ctx . get ( ) , GRPC_X509_CN_PROPERTY_NAME , expected_cn ) ) ;
GPR_ASSERT ( check_property ( ctx . get ( ) ,
GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME ,
GRPC_SSL_TRANSPORT_SECURITY_TYPE ) ) ;
GPR_ASSERT (
check_property ( ctx . get ( ) , GRPC_X509_CN_PROPERTY_NAME , expected_cn ) ) ;
GPR_ASSERT ( check_property ( ctx . get ( ) , GRPC_X509_PEM_CERT_PROPERTY_NAME ,
expected_pem_cert ) ) ;
GPR_ASSERT ( check_property ( ctx . get ( ) , GRPC_X509_PEM_CERT_CHAIN_PROPERTY_NAME ,
expected_pem_cert_chain ) ) ;
rpeer = grpc_shallow_peer_from_ssl_auth_context ( ctx . get ( ) ) ;
GPR_ASSERT ( check_ssl_peer_equivalence ( & peer , & rpeer ) ) ;
@ -324,7 +253,7 @@ static void test_cn_and_one_san_ssl_peer_to_auth_context(void) {
tsi_peer peer ;
tsi_peer rpeer ;
const char * expected_cn = " cn1 " ;
const char * expected_san = " san1 " ;
const std : : vector < std : : string > expected_sans = { " san1 " } ;
const char * expected_pem_cert = " pem_cert1 " ;
const char * expected_pem_cert_chain = " pem_cert1_chain " ;
GPR_ASSERT ( tsi_construct_peer ( 6 , & peer ) = = TSI_OK ) ;
@ -334,29 +263,37 @@ static void test_cn_and_one_san_ssl_peer_to_auth_context(void) {
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY , expected_cn ,
& peer . properties [ 1 ] ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY , expected_san ,
& peer . properties [ 2 ] ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_PEM_CERT_PROPERTY , expected_pem_cert ,
& peer . properties [ 3 ] ) = = TSI_OK ) ;
& peer . properties [ 2 ] ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_SECURITY_LEVEL_PEER_PROPERTY ,
tsi_security_level_to_string ( TSI_PRIVACY_AND_INTEGRITY ) ,
& peer . properties [ 4 ] ) = = TSI_OK ) ;
& peer . properties [ 3 ] ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_PEM_CERT_CHAIN_PROPERTY , expected_pem_cert_chain ,
& peer . properties [ 5 ] ) = = TSI_OK ) ;
& peer . properties [ 4 ] ) = = TSI_OK ) ;
for ( size_t i = 0 ; i < expected_sans . size ( ) ; i + + ) {
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY ,
expected_sans [ i ] . c_str ( ) ,
& peer . properties [ 5 + i ] ) = = TSI_OK ) ;
}
grpc_core : : RefCountedPtr < grpc_auth_context > ctx =
grpc_ssl_peer_to_auth_context ( & peer , GRPC_SSL_TRANSPORT_SECURITY_TYPE ) ;
GPR_ASSERT ( ctx ! = nullptr ) ;
GPR_ASSERT ( grpc_auth_context_peer_is_authenticated ( ctx . get ( ) ) ) ;
GPR_ASSERT (
check_identity ( ctx . get ( ) , GRPC_X509_SAN_PROPERTY_NAME , & expected_san , 1 ) ) ;
GPR_ASSERT ( check_transport_security_type ( ctx . get ( ) ) ) ;
GPR_ASSERT ( check_x509_cn ( ctx . get ( ) , expected_cn ) ) ;
GPR_ASSERT ( check_x509_pem_cert ( ctx . get ( ) , expected_pem_cert ) ) ;
GPR_ASSERT ( check_x509_pem_cert_chain ( ctx . get ( ) , expected_pem_cert_chain ) ) ;
check_properties ( ctx . get ( ) , GRPC_X509_SAN_PROPERTY_NAME , expected_sans ) ) ;
GPR_ASSERT ( check_property ( ctx . get ( ) ,
GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME ,
GRPC_SSL_TRANSPORT_SECURITY_TYPE ) ) ;
GPR_ASSERT (
check_property ( ctx . get ( ) , GRPC_X509_CN_PROPERTY_NAME , expected_cn ) ) ;
GPR_ASSERT ( check_property ( ctx . get ( ) , GRPC_X509_PEM_CERT_PROPERTY_NAME ,
expected_pem_cert ) ) ;
GPR_ASSERT ( check_property ( ctx . get ( ) , GRPC_X509_PEM_CERT_CHAIN_PROPERTY_NAME ,
expected_pem_cert_chain ) ) ;
rpeer = grpc_shallow_peer_from_ssl_auth_context ( ctx . get ( ) ) ;
GPR_ASSERT ( check_ssl_peer_equivalence ( & peer , & rpeer ) ) ;
@ -370,12 +307,11 @@ static void test_cn_and_multiple_sans_ssl_peer_to_auth_context(void) {
tsi_peer peer ;
tsi_peer rpeer ;
const char * expected_cn = " cn1 " ;
const char * expected_sans [ ] = { " san1 " , " san2 " , " san3 " } ;
const std : : vector < std : : string > expected_sans = { " san1 " , " san2 " , " san3 " } ;
const char * expected_pem_cert = " pem_cert1 " ;
const char * expected_pem_cert_chain = " pem_cert1_chain " ;
size_t i ;
GPR_ASSERT ( tsi_construct_peer ( 5 + GPR_ARRAY_SIZE ( expected_sans ) , & peer ) = =
TSI_OK ) ;
GPR_ASSERT ( tsi_construct_peer ( 5 + expected_sans . size ( ) , & peer ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_CERTIFICATE_TYPE_PEER_PROPERTY , TSI_X509_CERTIFICATE_TYPE ,
& peer . properties [ 0 ] ) = = TSI_OK ) ;
@ -392,21 +328,27 @@ static void test_cn_and_multiple_sans_ssl_peer_to_auth_context(void) {
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_PEM_CERT_CHAIN_PROPERTY , expected_pem_cert_chain ,
& peer . properties [ 4 ] ) = = TSI_OK ) ;
for ( i = 0 ; i < GPR_ARRAY_SIZE ( expected_sans ) ; i + + ) {
for ( i = 0 ; i < expected_sans . size ( ) ; i + + ) {
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY ,
expected_sans [ i ] , & peer . properties [ 5 + i ] ) = = TSI_OK ) ;
expected_sans [ i ] . c_str ( ) ,
& peer . properties [ 5 + i ] ) = = TSI_OK ) ;
}
grpc_core : : RefCountedPtr < grpc_auth_context > ctx =
grpc_ssl_peer_to_auth_context ( & peer , GRPC_SSL_TRANSPORT_SECURITY_TYPE ) ;
GPR_ASSERT ( ctx ! = nullptr ) ;
GPR_ASSERT ( grpc_auth_context_peer_is_authenticated ( ctx . get ( ) ) ) ;
GPR_ASSERT ( check_identity ( ctx . get ( ) , GRPC_X509_SAN_PROPERTY_NAME ,
expected_sans , GPR_ARRAY_SIZE ( expected_sans ) ) ) ;
GPR_ASSERT ( check_transport_security_type ( ctx . get ( ) ) ) ;
GPR_ASSERT ( check_x509_cn ( ctx . get ( ) , expected_cn ) ) ;
GPR_ASSERT ( check_x509_pem_cert ( ctx . get ( ) , expected_pem_cert ) ) ;
GPR_ASSERT ( check_x509_pem_cert_chain ( ctx . get ( ) , expected_pem_cert_chain ) ) ;
GPR_ASSERT (
check_properties ( ctx . get ( ) , GRPC_X509_SAN_PROPERTY_NAME , expected_sans ) ) ;
GPR_ASSERT ( check_property ( ctx . get ( ) ,
GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME ,
GRPC_SSL_TRANSPORT_SECURITY_TYPE ) ) ;
GPR_ASSERT (
check_property ( ctx . get ( ) , GRPC_X509_CN_PROPERTY_NAME , expected_cn ) ) ;
GPR_ASSERT ( check_property ( ctx . get ( ) , GRPC_X509_PEM_CERT_PROPERTY_NAME ,
expected_pem_cert ) ) ;
GPR_ASSERT ( check_property ( ctx . get ( ) , GRPC_X509_PEM_CERT_CHAIN_PROPERTY_NAME ,
expected_pem_cert_chain ) ) ;
rpeer = grpc_shallow_peer_from_ssl_auth_context ( ctx . get ( ) ) ;
GPR_ASSERT ( check_ssl_peer_equivalence ( & peer , & rpeer ) ) ;
@ -423,10 +365,9 @@ static void test_cn_and_multiple_sans_and_others_ssl_peer_to_auth_context(
const char * expected_cn = " cn1 " ;
const char * expected_pem_cert = " pem_cert1 " ;
const char * expected_pem_cert_chain = " pem_cert1_chain " ;
const char * expected_sans [ ] = { " san1 " , " san2 " , " san3 " } ;
const std : : vector < std : : string > expected_sans = { " san1 " , " san2 " , " san3 " } ;
size_t i ;
GPR_ASSERT ( tsi_construct_peer ( 7 + GPR_ARRAY_SIZE ( expected_sans ) , & peer ) = =
TSI_OK ) ;
GPR_ASSERT ( tsi_construct_peer ( 7 + expected_sans . size ( ) , & peer ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_CERTIFICATE_TYPE_PEER_PROPERTY , TSI_X509_CERTIFICATE_TYPE ,
& peer . properties [ 0 ] ) = = TSI_OK ) ;
@ -447,21 +388,27 @@ static void test_cn_and_multiple_sans_and_others_ssl_peer_to_auth_context(
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_PEM_CERT_CHAIN_PROPERTY , expected_pem_cert_chain ,
& peer . properties [ 6 ] ) = = TSI_OK ) ;
for ( i = 0 ; i < GPR_ARRAY_SIZE ( expected_sans ) ; i + + ) {
for ( i = 0 ; i < expected_sans . size ( ) ; i + + ) {
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY ,
expected_sans [ i ] , & peer . properties [ 7 + i ] ) = = TSI_OK ) ;
expected_sans [ i ] . c_str ( ) ,
& peer . properties [ 7 + i ] ) = = TSI_OK ) ;
}
grpc_core : : RefCountedPtr < grpc_auth_context > ctx =
grpc_ssl_peer_to_auth_context ( & peer , GRPC_SSL_TRANSPORT_SECURITY_TYPE ) ;
GPR_ASSERT ( ctx ! = nullptr ) ;
GPR_ASSERT ( grpc_auth_context_peer_is_authenticated ( ctx . get ( ) ) ) ;
GPR_ASSERT ( check_identity ( ctx . get ( ) , GRPC_X509_SAN_PROPERTY_NAME ,
expected_sans , GPR_ARRAY_SIZE ( expected_sans ) ) ) ;
GPR_ASSERT ( check_transport_security_type ( ctx . get ( ) ) ) ;
GPR_ASSERT ( check_x509_cn ( ctx . get ( ) , expected_cn ) ) ;
GPR_ASSERT ( check_x509_pem_cert ( ctx . get ( ) , expected_pem_cert ) ) ;
GPR_ASSERT ( check_x509_pem_cert_chain ( ctx . get ( ) , expected_pem_cert_chain ) ) ;
GPR_ASSERT (
check_properties ( ctx . get ( ) , GRPC_X509_SAN_PROPERTY_NAME , expected_sans ) ) ;
GPR_ASSERT ( check_property ( ctx . get ( ) ,
GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME ,
GRPC_SSL_TRANSPORT_SECURITY_TYPE ) ) ;
GPR_ASSERT (
check_property ( ctx . get ( ) , GRPC_X509_CN_PROPERTY_NAME , expected_cn ) ) ;
GPR_ASSERT ( check_property ( ctx . get ( ) , GRPC_X509_PEM_CERT_PROPERTY_NAME ,
expected_pem_cert ) ) ;
GPR_ASSERT ( check_property ( ctx . get ( ) , GRPC_X509_PEM_CERT_CHAIN_PROPERTY_NAME ,
expected_pem_cert_chain ) ) ;
rpeer = grpc_shallow_peer_from_ssl_auth_context ( ctx . get ( ) ) ;
GPR_ASSERT ( check_ssl_peer_equivalence ( & peer , & rpeer ) ) ;
@ -483,7 +430,8 @@ static void test_dns_peer_to_auth_context(void) {
grpc_core : : RefCountedPtr < grpc_auth_context > ctx =
grpc_ssl_peer_to_auth_context ( & peer , GRPC_SSL_TRANSPORT_SECURITY_TYPE ) ;
GPR_ASSERT ( ctx ! = nullptr ) ;
GPR_ASSERT ( check_sans ( ctx . get ( ) , GRPC_PEER_DNS_PROPERTY_NAME , expected_dns ) ) ;
GPR_ASSERT (
check_properties ( ctx . get ( ) , GRPC_PEER_DNS_PROPERTY_NAME , expected_dns ) ) ;
tsi_peer_destruct ( & peer ) ;
ctx . reset ( DEBUG_LOCATION , " test " ) ;
}
@ -500,7 +448,8 @@ static void test_uri_peer_to_auth_context(void) {
grpc_core : : RefCountedPtr < grpc_auth_context > ctx =
grpc_ssl_peer_to_auth_context ( & peer , GRPC_SSL_TRANSPORT_SECURITY_TYPE ) ;
GPR_ASSERT ( ctx ! = nullptr ) ;
GPR_ASSERT ( check_sans ( ctx . get ( ) , GRPC_PEER_URI_PROPERTY_NAME , expected_uri ) ) ;
GPR_ASSERT (
check_properties ( ctx . get ( ) , GRPC_PEER_URI_PROPERTY_NAME , expected_uri ) ) ;
tsi_peer_destruct ( & peer ) ;
ctx . reset ( DEBUG_LOCATION , " test " ) ;
}
@ -517,8 +466,8 @@ static void test_email_peer_to_auth_context(void) {
grpc_core : : RefCountedPtr < grpc_auth_context > ctx =
grpc_ssl_peer_to_auth_context ( & peer , GRPC_SSL_TRANSPORT_SECURITY_TYPE ) ;
GPR_ASSERT ( ctx ! = nullptr ) ;
GPR_ASSERT (
check_sans ( ctx . get ( ) , GRPC_PEER_EMAIL_PROPERTY_NAME , expected_emails ) ) ;
GPR_ASSERT ( check_properties ( ctx . get ( ) , GRPC_PEER_EMAIL_PROPERTY_NAME ,
expected_emails ) ) ;
tsi_peer_destruct ( & peer ) ;
ctx . reset ( DEBUG_LOCATION , " test " ) ;
}
@ -536,7 +485,8 @@ static void test_ip_peer_to_auth_context(void) {
grpc_core : : RefCountedPtr < grpc_auth_context > ctx =
grpc_ssl_peer_to_auth_context ( & peer , GRPC_SSL_TRANSPORT_SECURITY_TYPE ) ;
GPR_ASSERT ( ctx ! = nullptr ) ;
GPR_ASSERT ( check_sans ( ctx . get ( ) , GRPC_PEER_IP_PROPERTY_NAME , expected_ips ) ) ;
GPR_ASSERT (
check_properties ( ctx . get ( ) , GRPC_PEER_IP_PROPERTY_NAME , expected_ips ) ) ;
tsi_peer_destruct ( & peer ) ;
ctx . reset ( DEBUG_LOCATION , " test " ) ;
}
@ -622,6 +572,22 @@ static void test_spiffe_id_peer_to_auth_context(void) {
multiple_uri_ctx . reset ( DEBUG_LOCATION , " test " ) ;
}
static void test_subject_to_auth_context ( void ) {
tsi_peer peer ;
const char * expected_subject = " subject1 " ;
GPR_ASSERT ( tsi_construct_peer ( 1 , & peer ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_PEER_PROPERTY , expected_subject ,
& peer . properties [ 0 ] ) = = TSI_OK ) ;
grpc_core : : RefCountedPtr < grpc_auth_context > ctx =
grpc_ssl_peer_to_auth_context ( & peer , GRPC_SSL_TRANSPORT_SECURITY_TYPE ) ;
GPR_ASSERT ( ctx ! = nullptr ) ;
GPR_ASSERT ( check_property ( ctx . get ( ) , GRPC_X509_SUBJECT_PROPERTY_NAME ,
expected_subject ) ) ;
tsi_peer_destruct ( & peer ) ;
ctx . reset ( DEBUG_LOCATION , " test " ) ;
}
static const char * roots_for_override_api = " roots for override api " ;
static grpc_ssl_roots_override_result override_roots_success (
@ -775,6 +741,7 @@ int main(int argc, char** argv) {
test_email_peer_to_auth_context ( ) ;
test_ip_peer_to_auth_context ( ) ;
test_spiffe_id_peer_to_auth_context ( ) ;
test_subject_to_auth_context ( ) ;
test_ipv6_address_san ( ) ;
test_default_ssl_roots ( ) ;
test_peer_alpn_check ( ) ;