@ -16,22 +16,31 @@
//
//
# include <stdint.h>
# include <stdio.h>
# include <string.h>
# include <gtest/gtest.h>
# include <string>
# include <openssl/crypto.h>
# include "gtest/gtest.h"
# include <grpc/grpc.h>
# include <grpc/grpc_security.h>
# include <grpc/grpc_security_constants.h>
# include <grpc/impl/propagation_bits.h>
# include <grpc/slice.h>
# include <grpc/status.h>
# include <grpc/support/alloc.h>
# include <grpc/support/log.h>
# include <grpcpp/support/string_ref.h>
# include <grpc/support/time .h>
# include "src/core/lib/channel/channel_args.h"
# include "src/core/lib/gpr/string.h"
# include "src/core/lib/gpr/tmpfile.h"
# include "src/core/lib/gprpp/crash.h"
# include "src/core/lib/gprpp/global_config_generic .h"
# include "src/core/lib/gprpp/host_port.h"
# include "src/core/lib/security/credentials/credentials .h"
# include "src/core/lib/iomgr/exec_ctx .h"
# include "src/core/lib/security/security_connector/ssl_utils_config.h"
# include "test/core/end2end/cq_verifier.h"
# include "test/core/end2end/data/ssl_test_data.h"
@ -49,7 +58,8 @@ struct fullstack_secure_fixture_data {
} ;
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack (
grpc_channel_args * /*client_args*/ , grpc_channel_args * /*server_args*/ ) {
const grpc_channel_args * /*client_args*/ ,
const grpc_channel_args * /*server_args*/ ) {
grpc_end2end_test_fixture f ;
int port = grpc_pick_unused_port_or_die ( ) ;
fullstack_secure_fixture_data * ffd = new fullstack_secure_fixture_data ( ) ;
@ -72,7 +82,7 @@ static void process_auth_failure(void* state, grpc_auth_context* /*ctx*/,
}
static void chttp2_init_client_secure_fullstack (
grpc_end2end_test_fixture * f , grpc_channel_args * client_args ,
grpc_end2end_test_fixture * f , const grpc_channel_args * client_args ,
grpc_channel_credentials * creds ) {
fullstack_secure_fixture_data * ffd =
static_cast < fullstack_secure_fixture_data * > ( f - > fixture_data ) ;
@ -82,7 +92,7 @@ static void chttp2_init_client_secure_fullstack(
}
static void chttp2_init_server_secure_fullstack (
grpc_end2end_test_fixture * f , grpc_channel_args * server_args ,
grpc_end2end_test_fixture * f , const grpc_channel_args * server_args ,
grpc_server_credentials * server_creds ) {
fullstack_secure_fixture_data * ffd =
static_cast < fullstack_secure_fixture_data * > ( f - > fixture_data ) ;
@ -103,7 +113,7 @@ void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) {
delete ffd ;
}
static int fail_server_auth_check ( grpc_channel_args * server_args ) {
static int fail_server_auth_check ( const grpc_channel_args * server_args ) {
size_t i ;
if ( server_args = = nullptr ) return 0 ;
for ( i = 0 ; i < server_args - > num_args ; i + + ) {
@ -118,27 +128,27 @@ static int fail_server_auth_check(grpc_channel_args* server_args) {
# define SERVER_INIT_NAME(REQUEST_TYPE) \
chttp2_init_server_simple_ssl_secure_fullstack_ # # REQUEST_TYPE
# define SERVER_INIT(REQUEST_TYPE) \
static void SERVER_INIT_NAME ( REQUEST_TYPE ) ( \
grpc_end2end_test_fixture * f , grpc_channel_args * server_args ) { \
grpc_ssl_pem_key_cert_pair pem_cert_key_pair ; \
if ( ! test_server1_key_id . empty ( ) ) { \
pem_cert_key_pair . private_key = test_server1_key_id . c_str ( ) ; \
pem_cert_key_pair . cert_chain = test_server1_cert ; \
} else { \
pem_cert_key_pair . private_key = test_server1_key ; \
pem_cert_key_pair . cert_chain = test_server1_cert ; \
} \
grpc_server_credentials * ssl_creds = \
grpc_ssl_server_credentials_create_ex ( \
test_root_cert , & pem_cert_key_pair , 1 , REQUEST_TYPE , NULL ) ; \
if ( fail_server_auth_check ( server_args ) ) { \
grpc_auth_metadata_processor processor = { process_auth_failure , NULL , \
NULL } ; \
grpc_server_credentials_set_auth_metadata_processor ( ssl_creds , \
processor ) ; \
} \
chttp2_init_server_secure_fullstack ( f , server_args , ssl_creds ) ; \
# define SERVER_INIT(REQUEST_TYPE) \
static void SERVER_INIT_NAME ( REQUEST_TYPE ) ( \
grpc_end2end_test_fixture * f , const grpc_channel_args * server_args ) { \
grpc_ssl_pem_key_cert_pair pem_cert_key_pair ; \
if ( ! test_server1_key_id . empty ( ) ) { \
pem_cert_key_pair . private_key = test_server1_key_id . c_str ( ) ; \
pem_cert_key_pair . cert_chain = test_server1_cert ; \
} else { \
pem_cert_key_pair . private_key = test_server1_key ; \
pem_cert_key_pair . cert_chain = test_server1_cert ; \
} \
grpc_server_credentials * ssl_creds = \
grpc_ssl_server_credentials_create_ex ( \
test_root_cert , & pem_cert_key_pair , 1 , REQUEST_TYPE , NULL ) ; \
if ( fail_server_auth_check ( server_args ) ) { \
grpc_auth_metadata_processor processor = { process_auth_failure , NULL , \
NULL } ; \
grpc_server_credentials_set_auth_metadata_processor ( ssl_creds , \
processor ) ; \
} \
chttp2_init_server_secure_fullstack ( f , server_args , ssl_creds ) ; \
}
SERVER_INIT ( GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE )
@ -153,8 +163,8 @@ SERVER_INIT(GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY)
typedef enum { NONE , SELF_SIGNED , SIGNED , BAD_CERT_PAIR } certtype ;
# define CLIENT_INIT(cert_type) \
static void CLIENT_INIT_NAME ( cert_type ) ( grpc_end2end_test_fixture * f , \
grpc_channel_args * client_args ) { \
static void CLIENT_INIT_NAME ( cert_type ) ( \
grpc_end2end_test_fixture * f , const grpc_channel_args * client_args ) { \
grpc_channel_credentials * ssl_creds = NULL ; \
grpc_ssl_pem_key_cert_pair self_signed_client_key_cert_pair = { \
test_self_signed_client_key , test_self_signed_client_cert } ; \
@ -261,7 +271,7 @@ static grpc_end2end_test_config_wrapper configs[] = {
BAD_CERT_PAIR , FAIL ) ,
} ;
static void * tag ( intptr_t t ) { return ( void * ) t ; }
static void * tag ( intptr_t t ) { return reinterpret_cast < void * > ( t ) ; }
static gpr_timespec n_seconds_time ( int n ) {
return grpc_timeout_seconds_to_deadline ( n ) ;
@ -325,7 +335,7 @@ static void simple_request_body(grpc_end2end_test_fixture f,
nullptr ) ;
GPR_ASSERT ( GRPC_CALL_OK = = error ) ;
CQ_EXPECT_COMPLETION ( cqv , tag ( 1 ) , expected_result = = SUCCESS ) ;
cqv . Expect ( tag ( 1 ) , expected_result = = SUCCESS ) ;
cqv . Verify ( ) ;
grpc_call_unref ( c ) ;