@ -24,6 +24,8 @@
# include <gmock/gmock.h>
# include <gtest/gtest.h>
# include "absl/log/check.h"
# include <grpc/credentials.h>
# include <grpc/support/alloc.h>
# include <grpc/support/log.h>
@ -82,7 +84,7 @@ class TlsSecurityConnectorTest : public ::testing::Test {
static std : : string GetErrorMsg ( grpc_error_handle error ) {
std : : string error_str ;
GPR_ASSERT (
CHECK (
grpc_error_get_str ( error , StatusStrProperty : : kDescription , & error_str ) ) ;
return error_str ;
}
@ -368,13 +370,13 @@ TEST_F(TlsSecurityConnectorTest,
EXPECT_NE ( tls_connector - > ClientHandshakerFactoryForTesting ( ) , nullptr ) ;
// Construct a basic TSI Peer.
tsi_peer peer ;
GPR_ASSERT ( tsi_construct_peer ( 2 , & peer ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property ( TSI_SSL_ALPN_SELECTED_PROTOCOL ,
" h2 " , strlen ( " h2 " ) ,
& peer . properties [ 0 ] ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY , " foo.bar.com " ,
& peer . properties [ 1 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_peer ( 2 , & peer ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property ( TSI_SSL_ALPN_SELECTED_PROTOCOL , " h2 " ,
strlen ( " h2 " ) ,
& peer . properties [ 0 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY , " foo.bar.com " ,
& peer . properties [ 1 ] ) = = TSI_OK ) ;
RefCountedPtr < grpc_auth_context > auth_context ;
ExecCtx exec_ctx ;
grpc_closure * on_peer_checked = GRPC_CLOSURE_CREATE (
@ -404,13 +406,13 @@ TEST_F(TlsSecurityConnectorTest,
EXPECT_NE ( tls_connector - > ClientHandshakerFactoryForTesting ( ) , nullptr ) ;
// Construct a basic TSI Peer.
tsi_peer peer ;
GPR_ASSERT ( tsi_construct_peer ( 2 , & peer ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property ( TSI_SSL_ALPN_SELECTED_PROTOCOL ,
" h2 " , strlen ( " h2 " ) ,
& peer . properties [ 0 ] ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY , " foo.bar.com " ,
& peer . properties [ 1 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_peer ( 2 , & peer ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property ( TSI_SSL_ALPN_SELECTED_PROTOCOL , " h2 " ,
strlen ( " h2 " ) ,
& peer . properties [ 0 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY , " foo.bar.com " ,
& peer . properties [ 1 ] ) = = TSI_OK ) ;
RefCountedPtr < grpc_auth_context > auth_context ;
const char * expected_error_msg =
" Custom verification check failed with error: UNAUTHENTICATED: "
@ -557,13 +559,13 @@ TEST_F(TlsSecurityConnectorTest,
EXPECT_NE ( tls_connector - > ClientHandshakerFactoryForTesting ( ) , nullptr ) ;
// Construct a basic TSI Peer.
tsi_peer peer ;
GPR_ASSERT ( tsi_construct_peer ( 2 , & peer ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property ( TSI_SSL_ALPN_SELECTED_PROTOCOL ,
" h2 " , strlen ( " h2 " ) ,
& peer . properties [ 0 ] ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY , " foo.bar.com " ,
& peer . properties [ 1 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_peer ( 2 , & peer ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property ( TSI_SSL_ALPN_SELECTED_PROTOCOL , " h2 " ,
strlen ( " h2 " ) ,
& peer . properties [ 0 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY , " foo.bar.com " ,
& peer . properties [ 1 ] ) = = TSI_OK ) ;
RefCountedPtr < grpc_auth_context > auth_context ;
ExecCtx exec_ctx ;
grpc_closure * on_peer_checked = GRPC_CLOSURE_CREATE (
@ -593,13 +595,13 @@ TEST_F(TlsSecurityConnectorTest,
EXPECT_NE ( tls_connector - > ClientHandshakerFactoryForTesting ( ) , nullptr ) ;
// Construct a basic TSI Peer.
tsi_peer peer ;
GPR_ASSERT ( tsi_construct_peer ( 2 , & peer ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property ( TSI_SSL_ALPN_SELECTED_PROTOCOL ,
" h2 " , strlen ( " h2 " ) ,
& peer . properties [ 0 ] ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY , " foo.bar.com " ,
& peer . properties [ 1 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_peer ( 2 , & peer ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property ( TSI_SSL_ALPN_SELECTED_PROTOCOL , " h2 " ,
strlen ( " h2 " ) ,
& peer . properties [ 0 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY , " foo.bar.com " ,
& peer . properties [ 1 ] ) = = TSI_OK ) ;
RefCountedPtr < grpc_auth_context > auth_context ;
const char * expected_error_msg =
" Custom verification check failed with error: UNAUTHENTICATED: "
@ -631,29 +633,29 @@ TEST_F(TlsSecurityConnectorTest,
EXPECT_NE ( tls_connector - > ClientHandshakerFactoryForTesting ( ) , nullptr ) ;
// Construct a full TSI Peer.
tsi_peer peer ;
GPR_ASSERT ( tsi_construct_peer ( 7 , & peer ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property ( TSI_SSL_ALPN_SELECTED_PROTOCOL ,
" h2 " , strlen ( " h2 " ) ,
& peer . properties [ 0 ] ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY , " foo.bar.com " ,
& peer . properties [ 1 ] ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_PEM_CERT_PROPERTY , " pem_cert " , & 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 [ 3 ] ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_PEM_CERT_CHAIN_PROPERTY , " pem_cert_chain " ,
& peer . properties [ 4 ] ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY , " foo.bar.com " ,
& peer . properties [ 5 ] ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY , " foo.baz.com " ,
& peer . properties [ 6 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_peer ( 7 , & peer ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property ( TSI_SSL_ALPN_SELECTED_PROTOCOL , " h2 " ,
strlen ( " h2 " ) ,
& peer . properties [ 0 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY , " foo.bar.com " ,
& peer . properties [ 1 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_PEM_CERT_PROPERTY , " pem_cert " , & peer . properties [ 2 ] ) = =
TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property_from_cstring (
TSI_SECURITY_LEVEL_PEER_PROPERTY ,
tsi_security_level_to_string ( TSI_PRIVACY_AND_INTEGRITY ) ,
& peer . properties [ 3 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_PEM_CERT_CHAIN_PROPERTY , " pem_cert_chain " ,
& peer . properties [ 4 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY , " foo.bar.com " ,
& peer . properties [ 5 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY , " foo.baz.com " ,
& peer . properties [ 6 ] ) = = TSI_OK ) ;
RefCountedPtr < grpc_auth_context > auth_context ;
ExecCtx exec_ctx ;
grpc_closure * on_peer_checked = GRPC_CLOSURE_CREATE (
@ -679,29 +681,29 @@ TEST_F(TlsSecurityConnectorTest,
EXPECT_NE ( tls_connector - > ClientHandshakerFactoryForTesting ( ) , nullptr ) ;
// Construct a full TSI Peer.
tsi_peer peer ;
GPR_ASSERT ( tsi_construct_peer ( 7 , & peer ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property ( TSI_SSL_ALPN_SELECTED_PROTOCOL ,
" h2 " , strlen ( " h2 " ) ,
& peer . properties [ 0 ] ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY , " foo.com " ,
& peer . properties [ 1 ] ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_PEM_CERT_PROPERTY , " pem_cert " , & 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 [ 3 ] ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_PEM_CERT_CHAIN_PROPERTY , " pem_cert_chain " ,
& peer . properties [ 4 ] ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY , " *.com " ,
& peer . properties [ 5 ] ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY , " foo.baz.com " ,
& peer . properties [ 6 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_peer ( 7 , & peer ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property ( TSI_SSL_ALPN_SELECTED_PROTOCOL , " h2 " ,
strlen ( " h2 " ) ,
& peer . properties [ 0 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY , " foo.com " ,
& peer . properties [ 1 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_PEM_CERT_PROPERTY , " pem_cert " , & peer . properties [ 2 ] ) = =
TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property_from_cstring (
TSI_SECURITY_LEVEL_PEER_PROPERTY ,
tsi_security_level_to_string ( TSI_PRIVACY_AND_INTEGRITY ) ,
& peer . properties [ 3 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_PEM_CERT_CHAIN_PROPERTY , " pem_cert_chain " ,
& peer . properties [ 4 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY , " *.com " ,
& peer . properties [ 5 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY , " foo.baz.com " ,
& peer . properties [ 6 ] ) = = TSI_OK ) ;
RefCountedPtr < grpc_auth_context > auth_context ;
const char * expected_error_msg =
" Custom verification check failed with error: UNAUTHENTICATED: Hostname "
@ -988,13 +990,13 @@ TEST_F(TlsSecurityConnectorTest,
auto connector = credentials - > create_security_connector ( ChannelArgs ( ) ) ;
// Construct a basic TSI Peer.
tsi_peer peer ;
GPR_ASSERT ( tsi_construct_peer ( 2 , & peer ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property ( TSI_SSL_ALPN_SELECTED_PROTOCOL ,
" h2 " , strlen ( " h2 " ) ,
& peer . properties [ 0 ] ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY , " foo.bar.com " ,
& peer . properties [ 1 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_peer ( 2 , & peer ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property ( TSI_SSL_ALPN_SELECTED_PROTOCOL , " h2 " ,
strlen ( " h2 " ) ,
& peer . properties [ 0 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY , " foo.bar.com " ,
& peer . properties [ 1 ] ) = = TSI_OK ) ;
RefCountedPtr < grpc_auth_context > auth_context ;
ExecCtx exec_ctx ;
grpc_closure * on_peer_checked = GRPC_CLOSURE_CREATE (
@ -1019,13 +1021,13 @@ TEST_F(TlsSecurityConnectorTest,
auto connector = credentials - > create_security_connector ( ChannelArgs ( ) ) ;
// Construct a basic TSI Peer.
tsi_peer peer ;
GPR_ASSERT ( tsi_construct_peer ( 2 , & peer ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property ( TSI_SSL_ALPN_SELECTED_PROTOCOL ,
" h2 " , strlen ( " h2 " ) ,
& peer . properties [ 0 ] ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY , " foo.bar.com " ,
& peer . properties [ 1 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_peer ( 2 , & peer ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property ( TSI_SSL_ALPN_SELECTED_PROTOCOL , " h2 " ,
strlen ( " h2 " ) ,
& peer . properties [ 0 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY , " foo.bar.com " ,
& peer . properties [ 1 ] ) = = TSI_OK ) ;
RefCountedPtr < grpc_auth_context > auth_context ;
const char * expected_error_msg =
" Custom verification check failed with error: UNAUTHENTICATED: "
@ -1054,13 +1056,13 @@ TEST_F(TlsSecurityConnectorTest,
auto connector = credentials - > create_security_connector ( ChannelArgs ( ) ) ;
// Construct a basic TSI Peer.
tsi_peer peer ;
GPR_ASSERT ( tsi_construct_peer ( 2 , & peer ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property ( TSI_SSL_ALPN_SELECTED_PROTOCOL ,
" h2 " , strlen ( " h2 " ) ,
& peer . properties [ 0 ] ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY , " foo.bar.com " ,
& peer . properties [ 1 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_peer ( 2 , & peer ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property ( TSI_SSL_ALPN_SELECTED_PROTOCOL , " h2 " ,
strlen ( " h2 " ) ,
& peer . properties [ 0 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY , " foo.bar.com " ,
& peer . properties [ 1 ] ) = = TSI_OK ) ;
RefCountedPtr < grpc_auth_context > auth_context ;
ExecCtx exec_ctx ;
grpc_closure * on_peer_checked = GRPC_CLOSURE_CREATE (
@ -1087,13 +1089,13 @@ TEST_F(TlsSecurityConnectorTest,
auto connector = credentials - > create_security_connector ( ChannelArgs ( ) ) ;
// Construct a basic TSI Peer.
tsi_peer peer ;
GPR_ASSERT ( tsi_construct_peer ( 2 , & peer ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property ( TSI_SSL_ALPN_SELECTED_PROTOCOL ,
" h2 " , strlen ( " h2 " ) ,
& peer . properties [ 0 ] ) = = TSI_OK ) ;
GPR_ASSERT ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY , " foo.bar.com " ,
& peer . properties [ 1 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_peer ( 2 , & peer ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property ( TSI_SSL_ALPN_SELECTED_PROTOCOL , " h2 " ,
strlen ( " h2 " ) ,
& peer . properties [ 0 ] ) = = TSI_OK ) ;
CHECK ( tsi_construct_string_peer_property_from_cstring (
TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY , " foo.bar.com " ,
& peer . properties [ 1 ] ) = = TSI_OK ) ;
RefCountedPtr < grpc_auth_context > auth_context ;
const char * expected_error_msg =
" Custom verification check failed with error: UNAUTHENTICATED: "