From 0a538e6dcf20fd392fc51a4e187ebf1e44c5a8c8 Mon Sep 17 00:00:00 2001 From: Noah Eisen Date: Wed, 24 Jan 2018 16:24:12 -0800 Subject: regenerate project on linux --- gRPC-C++.podspec | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'gRPC-C++.podspec') diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index abbb69c88f..8f9f6afc55 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -298,11 +298,13 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.h', 'src/core/lib/channel/channel_stack.h', 'src/core/lib/channel/channel_stack_builder.h', + 'src/core/lib/channel/channel_tracer.h', 'src/core/lib/channel/connected_channel.h', 'src/core/lib/channel/context.h', 'src/core/lib/channel/handshaker.h', 'src/core/lib/channel/handshaker_factory.h', 'src/core/lib/channel/handshaker_registry.h', + 'src/core/lib/channel/object_registry.h', 'src/core/lib/compression/algorithm_metadata.h', 'src/core/lib/compression/message_compress.h', 'src/core/lib/compression/stream_compression.h', @@ -469,11 +471,13 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.h', 'src/core/lib/channel/channel_stack.h', 'src/core/lib/channel/channel_stack_builder.h', + 'src/core/lib/channel/channel_tracer.h', 'src/core/lib/channel/connected_channel.h', 'src/core/lib/channel/context.h', 'src/core/lib/channel/handshaker.h', 'src/core/lib/channel/handshaker_factory.h', 'src/core/lib/channel/handshaker_registry.h', + 'src/core/lib/channel/object_registry.h', 'src/core/lib/compression/algorithm_metadata.h', 'src/core/lib/compression/message_compress.h', 'src/core/lib/compression/stream_compression.h', @@ -616,6 +620,7 @@ Pod::Spec.new do |s| 'test/core/end2end/fixtures/http_proxy_fixture.h', 'test/core/end2end/fixtures/proxy.h', 'test/core/iomgr/endpoint_tests.h', + 'test/core/util/channel_tracing_utils.h', 'test/core/util/debugger_macros.h', 'test/core/util/grpc_profiler.h', 'test/core/util/histogram.h', -- cgit v1.2.3 From 31c05ba668ee6ede5326c669277204a7f778a9ab Mon Sep 17 00:00:00 2001 From: ncteisen Date: Mon, 5 Mar 2018 23:06:12 -0800 Subject: reviewer feedback, rename --- CMakeLists.txt | 22 +-- Makefile | 42 ++-- build.yaml | 8 +- config.m4 | 2 +- config.w32 | 2 +- gRPC-C++.podspec | 4 +- gRPC-Core.podspec | 6 +- grpc.gemspec | 4 +- grpc.gyp | 8 +- package.xml | 4 +- src/core/ext/filters/client_channel/subchannel.cc | 2 +- src/core/lib/channel/channel_trace.cc | 216 +++++++++++++++++++++ src/core/lib/channel/channel_trace.h | 115 +++++++++++ src/core/lib/channel/channel_tracer.cc | 215 -------------------- src/core/lib/channel/channel_tracer.h | 115 ----------- src/core/lib/surface/channel.cc | 2 +- src/python/grpcio/grpc_core_dependencies.py | 2 +- test/core/channel/BUILD | 8 +- test/core/channel/channel_trace_test.cc | 209 ++++++++++++++++++++ test/core/channel/channel_tracer_test.cc | 209 -------------------- test/core/util/channel_tracing_utils.cc | 2 +- test/core/util/channel_tracing_utils.h | 2 - tools/doxygen/Doxyfile.c++.internal | 2 +- tools/doxygen/Doxyfile.core.internal | 4 +- tools/run_tests/generated/sources_and_headers.json | 10 +- tools/run_tests/generated/tests.json | 2 +- 26 files changed, 610 insertions(+), 607 deletions(-) create mode 100644 src/core/lib/channel/channel_trace.cc create mode 100644 src/core/lib/channel/channel_trace.h delete mode 100644 src/core/lib/channel/channel_tracer.cc delete mode 100644 src/core/lib/channel/channel_tracer.h create mode 100644 test/core/channel/channel_trace_test.cc delete mode 100644 test/core/channel/channel_tracer_test.cc (limited to 'gRPC-C++.podspec') diff --git a/CMakeLists.txt b/CMakeLists.txt index 93d3b12962..651fb6bde9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -517,7 +517,7 @@ add_dependencies(buildtests_cxx bm_pollset) endif() add_dependencies(buildtests_cxx channel_arguments_test) add_dependencies(buildtests_cxx channel_filter_test) -add_dependencies(buildtests_cxx channel_tracer_test) +add_dependencies(buildtests_cxx channel_trace_test) add_dependencies(buildtests_cxx chttp2_settings_timeout_test) add_dependencies(buildtests_cxx cli_call_test) add_dependencies(buildtests_cxx client_channel_stress_test) @@ -800,7 +800,7 @@ add_library(grpc src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc - src/core/lib/channel/channel_tracer.cc + src/core/lib/channel/channel_trace.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc @@ -1144,7 +1144,7 @@ add_library(grpc_cronet src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc - src/core/lib/channel/channel_tracer.cc + src/core/lib/channel/channel_trace.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc @@ -1475,7 +1475,7 @@ add_library(grpc_test_util src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc - src/core/lib/channel/channel_tracer.cc + src/core/lib/channel/channel_trace.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc @@ -1767,7 +1767,7 @@ add_library(grpc_test_util_unsecure src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc - src/core/lib/channel/channel_tracer.cc + src/core/lib/channel/channel_trace.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc @@ -2038,7 +2038,7 @@ add_library(grpc_unsecure src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc - src/core/lib/channel/channel_tracer.cc + src/core/lib/channel/channel_trace.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc @@ -2843,7 +2843,7 @@ add_library(grpc++_cronet src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc - src/core/lib/channel/channel_tracer.cc + src/core/lib/channel/channel_trace.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc @@ -9485,14 +9485,14 @@ target_link_libraries(channel_filter_test endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -add_executable(channel_tracer_test - test/core/channel/channel_tracer_test.cc +add_executable(channel_trace_test + test/core/channel/channel_trace_test.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(channel_tracer_test +target_include_directories(channel_trace_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -9508,7 +9508,7 @@ target_include_directories(channel_tracer_test PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(channel_tracer_test +target_link_libraries(channel_trace_test ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} grpc_test_util diff --git a/Makefile b/Makefile index d5777d0e10..01bad6692d 100644 --- a/Makefile +++ b/Makefile @@ -1114,7 +1114,7 @@ bm_metadata: $(BINDIR)/$(CONFIG)/bm_metadata bm_pollset: $(BINDIR)/$(CONFIG)/bm_pollset channel_arguments_test: $(BINDIR)/$(CONFIG)/channel_arguments_test channel_filter_test: $(BINDIR)/$(CONFIG)/channel_filter_test -channel_tracer_test: $(BINDIR)/$(CONFIG)/channel_tracer_test +channel_trace_test: $(BINDIR)/$(CONFIG)/channel_trace_test chttp2_settings_timeout_test: $(BINDIR)/$(CONFIG)/chttp2_settings_timeout_test cli_call_test: $(BINDIR)/$(CONFIG)/cli_call_test client_channel_stress_test: $(BINDIR)/$(CONFIG)/client_channel_stress_test @@ -1583,7 +1583,7 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/bm_pollset \ $(BINDIR)/$(CONFIG)/channel_arguments_test \ $(BINDIR)/$(CONFIG)/channel_filter_test \ - $(BINDIR)/$(CONFIG)/channel_tracer_test \ + $(BINDIR)/$(CONFIG)/channel_trace_test \ $(BINDIR)/$(CONFIG)/chttp2_settings_timeout_test \ $(BINDIR)/$(CONFIG)/cli_call_test \ $(BINDIR)/$(CONFIG)/client_channel_stress_test \ @@ -1732,7 +1732,7 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/bm_pollset \ $(BINDIR)/$(CONFIG)/channel_arguments_test \ $(BINDIR)/$(CONFIG)/channel_filter_test \ - $(BINDIR)/$(CONFIG)/channel_tracer_test \ + $(BINDIR)/$(CONFIG)/channel_trace_test \ $(BINDIR)/$(CONFIG)/chttp2_settings_timeout_test \ $(BINDIR)/$(CONFIG)/cli_call_test \ $(BINDIR)/$(CONFIG)/client_channel_stress_test \ @@ -2129,8 +2129,8 @@ test_cxx: buildtests_cxx $(Q) $(BINDIR)/$(CONFIG)/channel_arguments_test || ( echo test channel_arguments_test failed ; exit 1 ) $(E) "[RUN] Testing channel_filter_test" $(Q) $(BINDIR)/$(CONFIG)/channel_filter_test || ( echo test channel_filter_test failed ; exit 1 ) - $(E) "[RUN] Testing channel_tracer_test" - $(Q) $(BINDIR)/$(CONFIG)/channel_tracer_test || ( echo test channel_tracer_test failed ; exit 1 ) + $(E) "[RUN] Testing channel_trace_test" + $(Q) $(BINDIR)/$(CONFIG)/channel_trace_test || ( echo test channel_trace_test failed ; exit 1 ) $(E) "[RUN] Testing chttp2_settings_timeout_test" $(Q) $(BINDIR)/$(CONFIG)/chttp2_settings_timeout_test || ( echo test chttp2_settings_timeout_test failed ; exit 1 ) $(E) "[RUN] Testing cli_call_test" @@ -3040,7 +3040,7 @@ LIBGRPC_SRC = \ src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ - src/core/lib/channel/channel_tracer.cc \ + src/core/lib/channel/channel_trace.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ @@ -3386,7 +3386,7 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ - src/core/lib/channel/channel_tracer.cc \ + src/core/lib/channel/channel_trace.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ @@ -3718,7 +3718,7 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ - src/core/lib/channel/channel_tracer.cc \ + src/core/lib/channel/channel_trace.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ @@ -4003,7 +4003,7 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ - src/core/lib/channel/channel_tracer.cc \ + src/core/lib/channel/channel_trace.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ @@ -4254,7 +4254,7 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ - src/core/lib/channel/channel_tracer.cc \ + src/core/lib/channel/channel_trace.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ @@ -5058,7 +5058,7 @@ LIBGRPC++_CRONET_SRC = \ src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ - src/core/lib/channel/channel_tracer.cc \ + src/core/lib/channel/channel_trace.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ @@ -15134,15 +15134,15 @@ endif endif -CHANNEL_TRACER_TEST_SRC = \ - test/core/channel/channel_tracer_test.cc \ +CHANNEL_TRACE_TEST_SRC = \ + test/core/channel/channel_trace_test.cc \ -CHANNEL_TRACER_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(CHANNEL_TRACER_TEST_SRC)))) +CHANNEL_TRACE_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(CHANNEL_TRACE_TEST_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/channel_tracer_test: openssl_dep_error +$(BINDIR)/$(CONFIG)/channel_trace_test: openssl_dep_error else @@ -15153,26 +15153,26 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/channel_tracer_test: protobuf_dep_error +$(BINDIR)/$(CONFIG)/channel_trace_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/channel_tracer_test: $(PROTOBUF_DEP) $(CHANNEL_TRACER_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/channel_trace_test: $(PROTOBUF_DEP) $(CHANNEL_TRACE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(CHANNEL_TRACER_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/channel_tracer_test + $(Q) $(LDXX) $(LDFLAGS) $(CHANNEL_TRACE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/channel_trace_test endif endif -$(OBJDIR)/$(CONFIG)/test/core/channel/channel_tracer_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/channel/channel_trace_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a -deps_channel_tracer_test: $(CHANNEL_TRACER_TEST_OBJS:.o=.dep) +deps_channel_trace_test: $(CHANNEL_TRACE_TEST_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(CHANNEL_TRACER_TEST_OBJS:.o=.dep) +-include $(CHANNEL_TRACE_TEST_OBJS:.o=.dep) endif endif diff --git a/build.yaml b/build.yaml index bdc6db8d8d..9ef6092e03 100644 --- a/build.yaml +++ b/build.yaml @@ -154,7 +154,7 @@ filegroups: - src/core/lib/channel/channel_args.cc - src/core/lib/channel/channel_stack.cc - src/core/lib/channel/channel_stack_builder.cc - - src/core/lib/channel/channel_tracer.cc + - src/core/lib/channel/channel_trace.cc - src/core/lib/channel/connected_channel.cc - src/core/lib/channel/handshaker.cc - src/core/lib/channel/handshaker_factory.cc @@ -312,7 +312,7 @@ filegroups: - src/core/lib/channel/channel_args.h - src/core/lib/channel/channel_stack.h - src/core/lib/channel/channel_stack_builder.h - - src/core/lib/channel/channel_tracer.h + - src/core/lib/channel/channel_trace.h - src/core/lib/channel/connected_channel.h - src/core/lib/channel/context.h - src/core/lib/channel/handshaker.h @@ -3885,12 +3885,12 @@ targets: - grpc - gpr uses_polling: false -- name: channel_tracer_test +- name: channel_trace_test gtest: true build: test language: c++ src: - - test/core/channel/channel_tracer_test.cc + - test/core/channel/channel_trace_test.cc deps: - grpc_test_util - grpc++ diff --git a/config.m4 b/config.m4 index 5f79cbcb6a..d53c2f4589 100644 --- a/config.m4 +++ b/config.m4 @@ -84,7 +84,7 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ - src/core/lib/channel/channel_tracer.cc \ + src/core/lib/channel/channel_trace.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ diff --git a/config.w32 b/config.w32 index 5471d5cc56..548ae73e31 100644 --- a/config.w32 +++ b/config.w32 @@ -61,7 +61,7 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\channel\\channel_args.cc " + "src\\core\\lib\\channel\\channel_stack.cc " + "src\\core\\lib\\channel\\channel_stack_builder.cc " + - "src\\core\\lib\\channel\\channel_tracer.cc " + + "src\\core\\lib\\channel\\channel_trace.cc " + "src\\core\\lib\\channel\\connected_channel.cc " + "src\\core\\lib\\channel\\handshaker.cc " + "src\\core\\lib\\channel\\handshaker_factory.cc " + diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index d9237752c5..4403af53c5 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -316,7 +316,7 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.h', 'src/core/lib/channel/channel_stack.h', 'src/core/lib/channel/channel_stack_builder.h', - 'src/core/lib/channel/channel_tracer.h', + 'src/core/lib/channel/channel_trace.h', 'src/core/lib/channel/connected_channel.h', 'src/core/lib/channel/context.h', 'src/core/lib/channel/handshaker.h', @@ -497,7 +497,7 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.h', 'src/core/lib/channel/channel_stack.h', 'src/core/lib/channel/channel_stack_builder.h', - 'src/core/lib/channel/channel_tracer.h', + 'src/core/lib/channel/channel_trace.h', 'src/core/lib/channel/connected_channel.h', 'src/core/lib/channel/context.h', 'src/core/lib/channel/handshaker.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 6546fe8af2..852992e606 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -327,7 +327,7 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.h', 'src/core/lib/channel/channel_stack.h', 'src/core/lib/channel/channel_stack_builder.h', - 'src/core/lib/channel/channel_tracer.h', + 'src/core/lib/channel/channel_trace.h', 'src/core/lib/channel/connected_channel.h', 'src/core/lib/channel/context.h', 'src/core/lib/channel/handshaker.h', @@ -473,7 +473,7 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', - 'src/core/lib/channel/channel_tracer.cc', + 'src/core/lib/channel/channel_trace.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', @@ -825,7 +825,7 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.h', 'src/core/lib/channel/channel_stack.h', 'src/core/lib/channel/channel_stack_builder.h', - 'src/core/lib/channel/channel_tracer.h', + 'src/core/lib/channel/channel_trace.h', 'src/core/lib/channel/connected_channel.h', 'src/core/lib/channel/context.h', 'src/core/lib/channel/handshaker.h', diff --git a/grpc.gemspec b/grpc.gemspec index d33333ace9..a53cdfdfe9 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -253,7 +253,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/channel/channel_args.h ) s.files += %w( src/core/lib/channel/channel_stack.h ) s.files += %w( src/core/lib/channel/channel_stack_builder.h ) - s.files += %w( src/core/lib/channel/channel_tracer.h ) + s.files += %w( src/core/lib/channel/channel_trace.h ) s.files += %w( src/core/lib/channel/connected_channel.h ) s.files += %w( src/core/lib/channel/context.h ) s.files += %w( src/core/lib/channel/handshaker.h ) @@ -403,7 +403,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/channel/channel_args.cc ) s.files += %w( src/core/lib/channel/channel_stack.cc ) s.files += %w( src/core/lib/channel/channel_stack_builder.cc ) - s.files += %w( src/core/lib/channel/channel_tracer.cc ) + s.files += %w( src/core/lib/channel/channel_trace.cc ) s.files += %w( src/core/lib/channel/connected_channel.cc ) s.files += %w( src/core/lib/channel/handshaker.cc ) s.files += %w( src/core/lib/channel/handshaker_factory.cc ) diff --git a/grpc.gyp b/grpc.gyp index 9b5ae58ee4..ca76c68077 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -225,7 +225,7 @@ 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', - 'src/core/lib/channel/channel_tracer.cc', + 'src/core/lib/channel/channel_trace.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', @@ -527,7 +527,7 @@ 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', - 'src/core/lib/channel/channel_tracer.cc', + 'src/core/lib/channel/channel_trace.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', @@ -747,7 +747,7 @@ 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', - 'src/core/lib/channel/channel_tracer.cc', + 'src/core/lib/channel/channel_trace.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', @@ -945,7 +945,7 @@ 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', - 'src/core/lib/channel/channel_tracer.cc', + 'src/core/lib/channel/channel_trace.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', diff --git a/package.xml b/package.xml index 1cf10540ee..a0841886a9 100644 --- a/package.xml +++ b/package.xml @@ -260,7 +260,7 @@ - + @@ -410,7 +410,7 @@ - + diff --git a/src/core/ext/filters/client_channel/subchannel.cc b/src/core/ext/filters/client_channel/subchannel.cc index 77c0fe2c43..e8ff352be8 100644 --- a/src/core/ext/filters/client_channel/subchannel.cc +++ b/src/core/ext/filters/client_channel/subchannel.cc @@ -36,7 +36,7 @@ #include "src/core/ext/filters/client_channel/uri_parser.h" #include "src/core/lib/backoff/backoff.h" #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/channel/channel_tracer.h" +#include "src/core/lib/channel/channel_trace.h" #include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/channel/object_registry.h" #include "src/core/lib/debug/stats.h" diff --git a/src/core/lib/channel/channel_trace.cc b/src/core/lib/channel/channel_trace.cc new file mode 100644 index 0000000000..3217a83fba --- /dev/null +++ b/src/core/lib/channel/channel_trace.cc @@ -0,0 +1,216 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/lib/channel/channel_trace.h" + +#include +#include +#include +#include +#include +#include + +#include "src/core/ext/filters/client_channel/status_util.h" +#include "src/core/lib/channel/object_registry.h" +#include "src/core/lib/gpr/string.h" +#include "src/core/lib/gpr/useful.h" +#include "src/core/lib/gprpp/memory.h" +#include "src/core/lib/iomgr/error.h" +#include "src/core/lib/slice/slice_internal.h" +#include "src/core/lib/surface/channel.h" +#include "src/core/lib/transport/connectivity_state.h" +#include "src/core/lib/transport/error_utils.h" + +namespace grpc_core { + +ChannelTrace::TraceEvent::TraceEvent( + grpc_slice data, grpc_error* error, + grpc_connectivity_state connectivity_state, + RefCountedPtr referenced_tracer) + : data_(data), + error_(error), + timestamp_(grpc_millis_to_timespec(grpc_core::ExecCtx::Get()->Now(), + GPR_CLOCK_REALTIME)), + connectivity_state_(connectivity_state), + next_(nullptr), + referenced_tracer_(std::move(referenced_tracer)) {} + +ChannelTrace::TraceEvent::TraceEvent(grpc_slice data, grpc_error* error, + grpc_connectivity_state connectivity_state) + : data_(data), + error_(error), + timestamp_(grpc_millis_to_timespec(grpc_core::ExecCtx::Get()->Now(), + GPR_CLOCK_REALTIME)), + connectivity_state_(connectivity_state), + next_(nullptr) {} + +ChannelTrace::TraceEvent::~TraceEvent() { + GRPC_ERROR_UNREF(error_); + grpc_slice_unref_internal(data_); +} + +ChannelTrace::ChannelTrace(size_t max_events) + : channel_uuid_(-1), + num_events_logged_(0), + num_children_seen_(0), + list_size_(0), + max_list_size_(max_events), + head_trace_(nullptr), + tail_trace_(nullptr) { + if (max_list_size_ == 0) return; // tracing is disabled if max_events == 0 + gpr_mu_init(&tracer_mu_); + channel_uuid_ = grpc_object_registry_register_object( + this, GRPC_OBJECT_REGISTRY_CHANNEL_TRACER); + time_created_ = grpc_millis_to_timespec(grpc_core::ExecCtx::Get()->Now(), + GPR_CLOCK_REALTIME); +} + +ChannelTrace::~ChannelTrace() { + if (max_list_size_ == 0) return; // tracing is disabled if max_events == 0 + TraceEvent* it = head_trace_; + while (it != nullptr) { + TraceEvent* to_free = it; + it = it->next(); + Delete(to_free); + } + gpr_mu_destroy(&tracer_mu_); +} + +intptr_t ChannelTrace::GetUuid() const { return channel_uuid_; } + +void ChannelTrace::AddTraceEventHelper(TraceEvent* new_trace_event) { + ++num_events_logged_; + // first event case + if (head_trace_ == nullptr) { + head_trace_ = tail_trace_ = new_trace_event; + } + // regular event add case + else { + tail_trace_->set_next(new_trace_event); + tail_trace_ = tail_trace_->next(); + } + ++list_size_; + // maybe garbage collect the end + if (list_size_ > max_list_size_) { + TraceEvent* to_free = head_trace_; + head_trace_ = head_trace_->next(); + Delete(to_free); + --list_size_; + } +} + +void ChannelTrace::AddTraceEvent( + grpc_slice data, grpc_error* error, + grpc_connectivity_state connectivity_state, + RefCountedPtr referenced_tracer) { + if (max_list_size_ == 0) return; // tracing is disabled if max_events == 0 + ++num_children_seen_; + // create and fill up the new event + AddTraceEventHelper(New(data, error, connectivity_state, + std::move(referenced_tracer))); +} + +void ChannelTrace::AddTraceEvent(grpc_slice data, grpc_error* error, + grpc_connectivity_state connectivity_state) { + if (max_list_size_ == 0) return; // tracing is disabled if max_events == 0 + AddTraceEventHelper(New(data, error, connectivity_state)); +} + +namespace { + +// returns an allocated string that represents tm according to RFC-3339. +char* fmt_time(gpr_timespec tm) { + char buffer[35]; + struct tm* tm_info = localtime((const time_t*)&tm.tv_sec); + strftime(buffer, sizeof(buffer), "%Y-%m-%dT%H:%M:%S", tm_info); + char* full_time_str; + gpr_asprintf(&full_time_str, "%s.%09dZ", buffer, tm.tv_nsec); + return full_time_str; +} + +} // anonymous namespace + +void ChannelTrace::TraceEvent::RenderTraceEvent(grpc_json* json) const { + grpc_json* json_iterator = nullptr; + json_iterator = grpc_json_create_child(json_iterator, json, "description", + grpc_slice_to_c_string(data_), + GRPC_JSON_STRING, true); + // TODO(ncteisen): Either format this as google.rpc.Status here, or ensure + // it is done in the layers above core. + if (error_ != GRPC_ERROR_NONE) { + grpc_status_code code; + grpc_slice message; + grpc_error_get_status(error_, GRPC_MILLIS_INF_FUTURE, &code, &message, + nullptr, nullptr); + grpc_json* status = grpc_json_create_child( + json_iterator, json, "status", nullptr, GRPC_JSON_OBJECT, false); + json_iterator = grpc_json_create_child(nullptr, status, "code", + grpc_status_code_to_string(code), + GRPC_JSON_STRING, false); + grpc_json_create_child(json_iterator, status, "message", + grpc_slice_to_c_string(message), GRPC_JSON_STRING, + true); + grpc_slice_unref_internal(message); + json_iterator = status; + } + json_iterator = + grpc_json_create_child(json_iterator, json, "timestamp", + fmt_time(timestamp_), GRPC_JSON_STRING, true); + json_iterator = + grpc_json_create_child(json_iterator, json, "state", + grpc_connectivity_state_name(connectivity_state_), + GRPC_JSON_STRING, false); + if (referenced_tracer_ != nullptr) { + char* uuid_str; + gpr_asprintf(&uuid_str, "%" PRIdPTR, referenced_tracer_->channel_uuid_); + json_iterator = grpc_json_create_child(json_iterator, json, "child_ref", + uuid_str, GRPC_JSON_NUMBER, true); + } +} + +char* ChannelTrace::RenderTrace() const { + if (!max_list_size_) + return nullptr; // tracing is disabled if max_events == 0 + grpc_json* json = grpc_json_create(GRPC_JSON_OBJECT); + char* num_events_logged_str; + gpr_asprintf(&num_events_logged_str, "%" PRId64, num_events_logged_); + grpc_json* json_iterator = nullptr; + json_iterator = + grpc_json_create_child(json_iterator, json, "num_events_logged", + num_events_logged_str, GRPC_JSON_NUMBER, true); + json_iterator = + grpc_json_create_child(json_iterator, json, "creation_time", + fmt_time(time_created_), GRPC_JSON_STRING, true); + grpc_json* events = grpc_json_create_child(json_iterator, json, "events", + nullptr, GRPC_JSON_ARRAY, false); + json_iterator = nullptr; + TraceEvent* it = head_trace_; + while (it != nullptr) { + json_iterator = grpc_json_create_child(json_iterator, events, nullptr, + nullptr, GRPC_JSON_OBJECT, false); + it->RenderTraceEvent(json_iterator); + it = it->next(); + } + char* json_str = grpc_json_dump_to_string(json, 0); + grpc_json_destroy(json); + return json_str; +} + +} // namespace grpc_core diff --git a/src/core/lib/channel/channel_trace.h b/src/core/lib/channel/channel_trace.h new file mode 100644 index 0000000000..536f51a1f6 --- /dev/null +++ b/src/core/lib/channel/channel_trace.h @@ -0,0 +1,115 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_LIB_CHANNEL_CHANNEL_TRACE_H +#define GRPC_CORE_LIB_CHANNEL_CHANNEL_TRACE_H + +#include + +#include +#include "src/core/lib/gprpp/ref_counted.h" +#include "src/core/lib/gprpp/ref_counted_ptr.h" +#include "src/core/lib/iomgr/error.h" +#include "src/core/lib/json/json.h" + +namespace grpc_core { + +// Object used to hold live data for a channel. This data is exposed via the +// channelz service: +// https://github.com/grpc/proposal/blob/master/A14-channelz.md +class ChannelTrace : public RefCounted { + public: + ChannelTrace(size_t max_events); + ~ChannelTrace(); + + // returns the tracer's uuid + intptr_t GetUuid() const; + + // Adds a new trace event to the tracing object + void AddTraceEvent(grpc_slice data, grpc_error* error, + grpc_connectivity_state connectivity_state); + + // Adds a new trace event to the tracing object. This trace event refers to a + // an event on a child of the channel. For example, if this channel has + // created a new subchannel, then it would record that with a TraceEvent + // referencing the new subchannel. + + // TODO(ncteisen): Once channelz is implemented, the events should reference + // the overall channelz object, not just the ChannelTrace object. + void AddTraceEvent(grpc_slice data, grpc_error* error, + grpc_connectivity_state connectivity_state, + RefCountedPtr referenced_tracer); + + // Returns the tracing data rendered as a grpc json string. + // The string is owned by the caller and must be freed. + char* RenderTrace() const; + + private: + // Private class to encapsulate all the data and bookkeeping needed for a + // a trace event. + class TraceEvent { + public: + // Constructor for a TraceEvent that references a different channel. + // TODO(ncteisen): once channelz is implemented, this should reference the + // overall channelz object, not just the ChannelTrace object + TraceEvent(grpc_slice data, grpc_error* error, + grpc_connectivity_state connectivity_state, + RefCountedPtr referenced_tracer); + + // Constructor for a TraceEvent that does not reverence a different + // channel. + TraceEvent(grpc_slice data, grpc_error* error, + grpc_connectivity_state connectivity_state); + + ~TraceEvent(); + + // Renders the data inside of this TraceEvent into a json object. This is + // used by the ChannelTrace, when it is rendering itself. + void RenderTraceEvent(grpc_json* json) const; + + // set and get for the next_ pointer. + TraceEvent* next() const { return next_; } + void set_next(TraceEvent* next) { next_ = next; } + + private: + grpc_slice data_; + grpc_error* error_; + gpr_timespec timestamp_; + grpc_connectivity_state connectivity_state_; + TraceEvent* next_; + // the tracer object for the (sub)channel that this trace event refers to. + RefCountedPtr referenced_tracer_; + }; // TraceEvent + + // Internal helper to add and link in a trace event + void AddTraceEventHelper(TraceEvent* new_trace_event); + + gpr_mu tracer_mu_; + intptr_t channel_uuid_; + uint64_t num_events_logged_; + uint64_t num_children_seen_; + size_t list_size_; + size_t max_list_size_; + TraceEvent* head_trace_; + TraceEvent* tail_trace_; + gpr_timespec time_created_; +}; + +} // namespace grpc_core + +#endif /* GRPC_CORE_LIB_CHANNEL_CHANNEL_TRACE_H */ diff --git a/src/core/lib/channel/channel_tracer.cc b/src/core/lib/channel/channel_tracer.cc deleted file mode 100644 index 38a5b1ee20..0000000000 --- a/src/core/lib/channel/channel_tracer.cc +++ /dev/null @@ -1,215 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/lib/channel/channel_tracer.h" - -#include -#include -#include -#include -#include -#include - -#include "src/core/ext/filters/client_channel/status_util.h" -#include "src/core/lib/channel/object_registry.h" -#include "src/core/lib/gpr/string.h" -#include "src/core/lib/gpr/useful.h" -#include "src/core/lib/gprpp/memory.h" -#include "src/core/lib/iomgr/error.h" -#include "src/core/lib/slice/slice_internal.h" -#include "src/core/lib/surface/channel.h" -#include "src/core/lib/transport/connectivity_state.h" -#include "src/core/lib/transport/error_utils.h" - -namespace grpc_core { - -ChannelTrace::TraceEvent::TraceEvent( - grpc_slice data, grpc_error* error, - grpc_connectivity_state connectivity_state, - RefCountedPtr referenced_tracer) - : data_(data), - error_(error), - timestamp_(grpc_millis_to_timespec(grpc_core::ExecCtx::Get()->Now(), - GPR_CLOCK_REALTIME)), - connectivity_state_(connectivity_state), - next_(nullptr), - referenced_tracer_(std::move(referenced_tracer)) {} - -ChannelTrace::TraceEvent::TraceEvent(grpc_slice data, grpc_error* error, - grpc_connectivity_state connectivity_state) - : data_(data), - error_(error), - timestamp_(grpc_millis_to_timespec(grpc_core::ExecCtx::Get()->Now(), - GPR_CLOCK_REALTIME)), - connectivity_state_(connectivity_state), - next_(nullptr) {} - -ChannelTrace::TraceEvent::~TraceEvent() { - GRPC_ERROR_UNREF(error_); - grpc_slice_unref_internal(data_); -} - -ChannelTrace::ChannelTrace(size_t max_events) - : channel_uuid_(-1), - num_events_logged_(0), - num_children_seen_(0), - list_size_(0), - max_list_size_(max_events), - head_trace_(nullptr), - tail_trace_(nullptr) { - if (max_list_size_ == 0) return; // tracing is disabled if max_events == 0 - gpr_mu_init(&tracer_mu_); - channel_uuid_ = grpc_object_registry_register_object( - this, GRPC_OBJECT_REGISTRY_CHANNEL_TRACER); - time_created_ = grpc_millis_to_timespec(grpc_core::ExecCtx::Get()->Now(), - GPR_CLOCK_REALTIME); -} - -ChannelTrace::~ChannelTrace() { - if (max_list_size_ == 0) return; // tracing is disabled if max_events == 0 - TraceEvent* it = head_trace_; - while (it != nullptr) { - TraceEvent* to_free = it; - it = it->next(); - Delete(to_free); - } - gpr_mu_destroy(&tracer_mu_); -} - -intptr_t ChannelTrace::GetUuid() const { return channel_uuid_; } - -void ChannelTrace::AddTraceEventHelper(TraceEvent* new_trace_event) { - ++num_events_logged_; - // first event case - if (head_trace_ == nullptr) { - head_trace_ = tail_trace_ = new_trace_event; - } - // regular event add case - else { - tail_trace_->set_next(new_trace_event); - tail_trace_ = tail_trace_->next(); - } - ++list_size_; - // maybe garbage collect the end - if (list_size_ > max_list_size_) { - TraceEvent* to_free = head_trace_; - head_trace_ = head_trace_->next(); - Delete(to_free); - --list_size_; - } -} - -void ChannelTrace::AddTraceEvent( - grpc_slice data, grpc_error* error, - grpc_connectivity_state connectivity_state, - RefCountedPtr referenced_tracer) { - if (max_list_size_ == 0) return; // tracing is disabled if max_events == 0 - ++num_children_seen_; - // create and fill up the new event - AddTraceEventHelper(New(data, error, connectivity_state, - std::move(referenced_tracer))); -} - -void ChannelTrace::AddTraceEvent(grpc_slice data, grpc_error* error, - grpc_connectivity_state connectivity_state) { - AddTraceEventHelper(New(data, error, connectivity_state)); -} - -namespace { - -// returns an allocated string that represents tm according to RFC-3339. -char* fmt_time(gpr_timespec tm) { - char buffer[35]; - struct tm* tm_info = localtime((const time_t*)&tm.tv_sec); - strftime(buffer, sizeof(buffer), "%Y-%m-%dT%H:%M:%S", tm_info); - char* full_time_str; - gpr_asprintf(&full_time_str, "%s.%09dZ", buffer, tm.tv_nsec); - return full_time_str; -} - -} // anonymous namespace - -void ChannelTrace::TraceEvent::RenderTraceEvent(grpc_json* json) const { - grpc_json* json_iterator = nullptr; - json_iterator = grpc_json_create_child(json_iterator, json, "description", - grpc_slice_to_c_string(data_), - GRPC_JSON_STRING, true); - // TODO(ncteisen): Either format this as google.rpc.Status here, or ensure - // it is done in the layers above core. - if (error_ != GRPC_ERROR_NONE) { - grpc_status_code code; - grpc_slice message; - grpc_error_get_status(error_, GRPC_MILLIS_INF_FUTURE, &code, &message, - nullptr, nullptr); - grpc_json* status = grpc_json_create_child( - json_iterator, json, "status", nullptr, GRPC_JSON_OBJECT, false); - json_iterator = grpc_json_create_child(nullptr, status, "code", - grpc_status_code_to_string(code), - GRPC_JSON_STRING, false); - grpc_json_create_child(json_iterator, status, "message", - grpc_slice_to_c_string(message), GRPC_JSON_STRING, - true); - grpc_slice_unref_internal(message); - json_iterator = status; - } - json_iterator = - grpc_json_create_child(json_iterator, json, "timestamp", - fmt_time(timestamp_), GRPC_JSON_STRING, true); - json_iterator = - grpc_json_create_child(json_iterator, json, "state", - grpc_connectivity_state_name(connectivity_state_), - GRPC_JSON_STRING, false); - if (referenced_tracer_ != nullptr) { - char* uuid_str; - gpr_asprintf(&uuid_str, "%" PRIdPTR, referenced_tracer_->channel_uuid_); - json_iterator = grpc_json_create_child(json_iterator, json, "child_ref", - uuid_str, GRPC_JSON_NUMBER, true); - } -} - -char* ChannelTrace::RenderTrace() const { - if (!max_list_size_) - return nullptr; // tracing is disabled if max_events == 0 - grpc_json* json = grpc_json_create(GRPC_JSON_OBJECT); - char* num_events_logged_str; - gpr_asprintf(&num_events_logged_str, "%" PRId64, num_events_logged_); - grpc_json* json_iterator = nullptr; - json_iterator = - grpc_json_create_child(json_iterator, json, "num_events_logged", - num_events_logged_str, GRPC_JSON_NUMBER, true); - json_iterator = - grpc_json_create_child(json_iterator, json, "creation_time", - fmt_time(time_created_), GRPC_JSON_STRING, true); - grpc_json* events = grpc_json_create_child(json_iterator, json, "events", - nullptr, GRPC_JSON_ARRAY, false); - json_iterator = nullptr; - TraceEvent* it = head_trace_; - while (it != nullptr) { - json_iterator = grpc_json_create_child(json_iterator, events, nullptr, - nullptr, GRPC_JSON_OBJECT, false); - it->RenderTraceEvent(json_iterator); - it = it->next(); - } - char* json_str = grpc_json_dump_to_string(json, 0); - grpc_json_destroy(json); - return json_str; -} - -} // namespace grpc_core diff --git a/src/core/lib/channel/channel_tracer.h b/src/core/lib/channel/channel_tracer.h deleted file mode 100644 index 3339be85e3..0000000000 --- a/src/core/lib/channel/channel_tracer.h +++ /dev/null @@ -1,115 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_LIB_CHANNEL_CHANNEL_TRACER_H -#define GRPC_CORE_LIB_CHANNEL_CHANNEL_TRACER_H - -#include - -#include -#include "src/core/lib/gprpp/ref_counted.h" -#include "src/core/lib/gprpp/ref_counted_ptr.h" -#include "src/core/lib/iomgr/error.h" -#include "src/core/lib/json/json.h" - -namespace grpc_core { - -// Object used to hold live data for a channel. This data is exposed via the -// channelz service: -// https://github.com/grpc/proposal/blob/master/A14-channelz.md -class ChannelTrace : public RefCounted { - public: - ChannelTrace(size_t max_events); - ~ChannelTrace(); - - // returns the tracer's uuid - intptr_t GetUuid() const; - - // Adds a new trace event to the tracing object - void AddTraceEvent(grpc_slice data, grpc_error* error, - grpc_connectivity_state connectivity_state); - - // Adds a new trace event to the tracing object. This trace event refers to a - // an event on a child of the channel. For example, if this channel has - // created a new subchannel, then it would record that with a TraceEvent - // referencing the new subchannel. - - // TODO(ncteisen): Once channelz is implemented, the events should reference - // the overall channelz object, not just the ChannelTrace object. - void AddTraceEvent(grpc_slice data, grpc_error* error, - grpc_connectivity_state connectivity_state, - RefCountedPtr referenced_tracer); - - // Returns the tracing data rendered as a grpc json string. - // The string is owned by the caller and must be freed. - char* RenderTrace() const; - - private: - // Private class to encapsulate all the data and bookkeeping needed for a - // a trace event. - class TraceEvent { - public: - // Constructor for a TraceEvent that references a different channel. - // TODO(ncteisen): once channelz is implemented, this should reference the - // overall channelz object, not just the ChannelTrace object - TraceEvent(grpc_slice data, grpc_error* error, - grpc_connectivity_state connectivity_state, - RefCountedPtr referenced_tracer); - - // Constructor for a TraceEvent that does not reverence a different - // channel. - TraceEvent(grpc_slice data, grpc_error* error, - grpc_connectivity_state connectivity_state); - - ~TraceEvent(); - - // Renders the data inside of this TraceEvent into a json object. This is - // used by the ChannelTrace, when it is rendering itself. - void RenderTraceEvent(grpc_json* json) const; - - // set and get for the next_ pointer. - TraceEvent* next() const { return next_; } - void set_next(TraceEvent* next) { next_ = next; } - - private: - grpc_slice data_; - grpc_error* error_; - gpr_timespec timestamp_; - grpc_connectivity_state connectivity_state_; - TraceEvent* next_; - // the tracer object for the (sub)channel that this trace event refers to. - RefCountedPtr referenced_tracer_; - }; // TraceEvent - - // Internal helper to add and link in a trace event - void AddTraceEventHelper(TraceEvent* new_trace_event); - - gpr_mu tracer_mu_; - intptr_t channel_uuid_; - uint64_t num_events_logged_; - uint64_t num_children_seen_; - size_t list_size_; - size_t max_list_size_; - TraceEvent* head_trace_; - TraceEvent* tail_trace_; - gpr_timespec time_created_; -}; - -} // namespace grpc_core - -#endif /* GRPC_CORE_LIB_CHANNEL_CHANNEL_TRACER_H */ diff --git a/src/core/lib/surface/channel.cc b/src/core/lib/surface/channel.cc index fb435b9881..c470f6d0d8 100644 --- a/src/core/lib/surface/channel.cc +++ b/src/core/lib/surface/channel.cc @@ -31,7 +31,7 @@ #include #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/channel/channel_tracer.h" +#include "src/core/lib/channel/channel_trace.h" #include "src/core/lib/channel/object_registry.h" #include "src/core/lib/debug/stats.h" #include "src/core/lib/gpr/string.h" diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index bf8fb90c5f..3c3c1d6943 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -60,7 +60,7 @@ CORE_SOURCE_FILES = [ 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', - 'src/core/lib/channel/channel_tracer.cc', + 'src/core/lib/channel/channel_trace.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', diff --git a/test/core/channel/BUILD b/test/core/channel/BUILD index b215aa205c..633c424eae 100644 --- a/test/core/channel/BUILD +++ b/test/core/channel/BUILD @@ -67,12 +67,16 @@ grpc_cc_test( ) grpc_cc_test( - name = "channel_tracer_test", - srcs = ["channel_tracer_test.cc"], + name = "channel_trace_test", + srcs = ["channel_trace_test.cc"], + external_deps = [ + "gtest", + ], language = "C++", deps = [ "//:gpr", "//:grpc", + "//:grpc++", "//test/core/util:gpr_test_util", "//test/core/util:grpc_test_util", ], diff --git a/test/core/channel/channel_trace_test.cc b/test/core/channel/channel_trace_test.cc new file mode 100644 index 0000000000..c0cccb77ac --- /dev/null +++ b/test/core/channel/channel_trace_test.cc @@ -0,0 +1,209 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include + +#include +#include + +#include + +#include "src/core/lib/channel/channel_trace.h" +#include "src/core/lib/channel/object_registry.h" +#include "src/core/lib/gpr/useful.h" +#include "src/core/lib/iomgr/exec_ctx.h" + +#include "test/core/util/channel_tracing_utils.h" +#include "test/core/util/test_config.h" + +namespace grpc_core { +namespace testing { + +static void add_simple_trace_event(RefCountedPtr tracer) { + tracer->AddTraceEvent(grpc_slice_from_static_string("simple trace"), + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Error"), + GRPC_CHANNEL_READY); +} + +// checks for the existence of all the required members of the tracer. +static void validate_trace(RefCountedPtr tracer, + size_t expected_num_event_logged, + size_t max_nodes) { + if (!max_nodes) return; + char* json_str = tracer->RenderTrace(); + grpc_json* json = grpc_json_parse_string(json_str); + validate_channel_trace_data(json, expected_num_event_logged, + GPR_MIN(expected_num_event_logged, max_nodes)); + grpc_json_destroy(json); + gpr_free(json_str); +} + +static void validate_trace_data_matches_uuid_lookup( + RefCountedPtr tracer) { + intptr_t uuid = tracer->GetUuid(); + if (uuid == -1) return; // Doesn't make sense to lookup if tracing disabled + char* tracer_json_str = tracer->RenderTrace(); + void* object; + grpc_object_registry_type type = + grpc_object_registry_get_object(uuid, &object); + GPR_ASSERT(type == GRPC_OBJECT_REGISTRY_CHANNEL_TRACER); + char* uuid_lookup_json_str = + static_cast(object)->RenderTrace(); + GPR_ASSERT(strcmp(tracer_json_str, uuid_lookup_json_str) == 0); + gpr_free(tracer_json_str); + gpr_free(uuid_lookup_json_str); +} + +// Tests basic ChannelTrace functionality like construction, adding trace, and +// lookups by uuid. +static void test_basic_channel_trace(size_t max_nodes) { + grpc_core::ExecCtx exec_ctx; + RefCountedPtr tracer = MakeRefCounted(max_nodes); + add_simple_trace_event(tracer); + add_simple_trace_event(tracer); + validate_trace_data_matches_uuid_lookup(tracer); + tracer->AddTraceEvent( + grpc_slice_from_static_string("trace three"), + grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("Error"), + GRPC_ERROR_INT_HTTP2_ERROR, 2), + GRPC_CHANNEL_IDLE); + tracer->AddTraceEvent(grpc_slice_from_static_string("trace four"), + GRPC_ERROR_NONE, GRPC_CHANNEL_SHUTDOWN); + validate_trace(tracer, 4, max_nodes); + add_simple_trace_event(tracer); + add_simple_trace_event(tracer); + validate_trace(tracer, 6, max_nodes); + add_simple_trace_event(tracer); + add_simple_trace_event(tracer); + add_simple_trace_event(tracer); + add_simple_trace_event(tracer); + validate_trace(tracer, 10, max_nodes); + validate_trace_data_matches_uuid_lookup(tracer); + tracer.reset(nullptr); +} + +// Calls basic test with various values for max_nodes (including 0, which turns +// the tracer off). +TEST(ChannelTracerTest, BasicTest) { + test_basic_channel_trace(0); + test_basic_channel_trace(1); + test_basic_channel_trace(2); + test_basic_channel_trace(6); + test_basic_channel_trace(10); + test_basic_channel_trace(15); +} + +// Tests more complex functionality, like a parent channel tracking +// subchannles. This exercises the ref/unref patterns since the parent tracer +// and this function will both hold refs to the subchannel. +static void test_complex_channel_trace(size_t max_nodes) { + grpc_core::ExecCtx exec_ctx; + RefCountedPtr tracer = MakeRefCounted(max_nodes); + add_simple_trace_event(tracer); + add_simple_trace_event(tracer); + RefCountedPtr sc1 = MakeRefCounted(max_nodes); + tracer->AddTraceEvent(grpc_slice_from_static_string("subchannel one created"), + GRPC_ERROR_NONE, GRPC_CHANNEL_IDLE, sc1); + validate_trace(tracer, 3, max_nodes); + add_simple_trace_event(sc1); + add_simple_trace_event(sc1); + add_simple_trace_event(sc1); + validate_trace(sc1, 3, max_nodes); + add_simple_trace_event(sc1); + add_simple_trace_event(sc1); + add_simple_trace_event(sc1); + validate_trace(sc1, 6, max_nodes); + add_simple_trace_event(tracer); + add_simple_trace_event(tracer); + validate_trace(tracer, 5, max_nodes); + validate_trace_data_matches_uuid_lookup(tracer); + RefCountedPtr sc2 = MakeRefCounted(max_nodes); + tracer->AddTraceEvent(grpc_slice_from_static_string("subchannel two created"), + GRPC_ERROR_NONE, GRPC_CHANNEL_IDLE, sc2); + tracer->AddTraceEvent( + grpc_slice_from_static_string("subchannel one inactive"), GRPC_ERROR_NONE, + GRPC_CHANNEL_IDLE, sc1); + validate_trace(tracer, 7, max_nodes); + add_simple_trace_event(tracer); + add_simple_trace_event(tracer); + add_simple_trace_event(tracer); + add_simple_trace_event(tracer); + add_simple_trace_event(tracer); + add_simple_trace_event(tracer); + validate_trace_data_matches_uuid_lookup(tracer); + tracer.reset(nullptr); + sc1.reset(nullptr); + sc2.reset(nullptr); +} + +// Calls the complex test with a sweep of sizes for max_nodes. +TEST(ChannelTracerTest, ComplexTest) { + test_complex_channel_trace(0); + test_complex_channel_trace(1); + test_complex_channel_trace(2); + test_complex_channel_trace(6); + test_complex_channel_trace(10); + test_complex_channel_trace(15); +} + +// Test a case in which the parent channel has subchannels and the subchannels +// have connections. Ensures that everything lives as long as it should then +// gets deleted. +TEST(ChannelTracerTest, TestNesting) { + grpc_core::ExecCtx exec_ctx; + RefCountedPtr tracer = MakeRefCounted(10); + add_simple_trace_event(tracer); + add_simple_trace_event(tracer); + RefCountedPtr sc1 = MakeRefCounted(5); + tracer->AddTraceEvent(grpc_slice_from_static_string("subchannel one created"), + GRPC_ERROR_NONE, GRPC_CHANNEL_IDLE, sc1); + add_simple_trace_event(sc1); + RefCountedPtr conn1 = MakeRefCounted(5); + // nesting one level deeper. + sc1->AddTraceEvent(grpc_slice_from_static_string("connection one created"), + GRPC_ERROR_NONE, GRPC_CHANNEL_IDLE, conn1); + add_simple_trace_event(conn1); + add_simple_trace_event(tracer); + add_simple_trace_event(tracer); + RefCountedPtr sc2 = MakeRefCounted(5); + tracer->AddTraceEvent(grpc_slice_from_static_string("subchannel two created"), + GRPC_ERROR_NONE, GRPC_CHANNEL_IDLE, sc2); + // this trace should not get added to the parents children since it is already + // present in the tracer. + tracer->AddTraceEvent( + grpc_slice_from_static_string("subchannel one inactive"), GRPC_ERROR_NONE, + GRPC_CHANNEL_IDLE, sc1); + add_simple_trace_event(tracer); + tracer.reset(nullptr); + sc1.reset(nullptr); + sc2.reset(nullptr); + conn1.reset(nullptr); +} + +} // namespace testing +} // namespace grpc_core + +int main(int argc, char** argv) { + grpc_test_init(argc, argv); + grpc_init(); + ::testing::InitGoogleTest(&argc, argv); + int ret = RUN_ALL_TESTS(); + grpc_shutdown(); + return ret; +} diff --git a/test/core/channel/channel_tracer_test.cc b/test/core/channel/channel_tracer_test.cc deleted file mode 100644 index d76daccbdb..0000000000 --- a/test/core/channel/channel_tracer_test.cc +++ /dev/null @@ -1,209 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include - -#include -#include - -#include - -#include "src/core/lib/channel/channel_tracer.h" -#include "src/core/lib/channel/object_registry.h" -#include "src/core/lib/gpr/useful.h" -#include "src/core/lib/iomgr/exec_ctx.h" - -#include "test/core/util/channel_tracing_utils.h" -#include "test/core/util/test_config.h" - -namespace grpc_core { -namespace testing { - -static void add_simple_trace_event(RefCountedPtr tracer) { - tracer->AddTraceEvent(grpc_slice_from_static_string("simple trace"), - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Error"), - GRPC_CHANNEL_READY); -} - -// checks for the existence of all the required members of the tracer. -static void validate_tracer(RefCountedPtr tracer, - size_t expected_num_event_logged, - size_t max_nodes) { - if (!max_nodes) return; - char* json_str = tracer->RenderTrace(); - grpc_json* json = grpc_json_parse_string(json_str); - validate_channel_trace_data(json, expected_num_event_logged, - GPR_MIN(expected_num_event_logged, max_nodes)); - grpc_json_destroy(json); - gpr_free(json_str); -} - -static void validate_tracer_data_matches_uuid_lookup( - RefCountedPtr tracer) { - intptr_t uuid = tracer->GetUuid(); - if (uuid == -1) return; // Doesn't make sense to lookup if tracing disabled - char* tracer_json_str = tracer->RenderTrace(); - void* object; - grpc_object_registry_type type = - grpc_object_registry_get_object(uuid, &object); - GPR_ASSERT(type == GRPC_OBJECT_REGISTRY_CHANNEL_TRACER); - char* uuid_lookup_json_str = - static_cast(object)->RenderTrace(); - GPR_ASSERT(strcmp(tracer_json_str, uuid_lookup_json_str) == 0); - gpr_free(tracer_json_str); - gpr_free(uuid_lookup_json_str); -} - -// Tests basic ChannelTrace functionality like construction, adding trace, and -// lookups by uuid. -static void test_basic_channel_tracing(size_t max_nodes) { - grpc_core::ExecCtx exec_ctx; - RefCountedPtr tracer = MakeRefCounted(max_nodes); - add_simple_trace_event(tracer); - add_simple_trace_event(tracer); - validate_tracer_data_matches_uuid_lookup(tracer); - tracer->AddTraceEvent( - grpc_slice_from_static_string("trace three"), - grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("Error"), - GRPC_ERROR_INT_HTTP2_ERROR, 2), - GRPC_CHANNEL_IDLE); - tracer->AddTraceEvent(grpc_slice_from_static_string("trace four"), - GRPC_ERROR_NONE, GRPC_CHANNEL_SHUTDOWN); - validate_tracer(tracer, 4, max_nodes); - add_simple_trace_event(tracer); - add_simple_trace_event(tracer); - validate_tracer(tracer, 6, max_nodes); - add_simple_trace_event(tracer); - add_simple_trace_event(tracer); - add_simple_trace_event(tracer); - add_simple_trace_event(tracer); - validate_tracer(tracer, 10, max_nodes); - validate_tracer_data_matches_uuid_lookup(tracer); - tracer.reset(nullptr); -} - -// Calls basic test with various values for max_nodes (including 0, which turns -// the tracer off). -TEST(ChannelTracerTest, BasicTest) { - test_basic_channel_tracing(0); - test_basic_channel_tracing(1); - test_basic_channel_tracing(2); - test_basic_channel_tracing(6); - test_basic_channel_tracing(10); - test_basic_channel_tracing(15); -} - -// Tests more complex functionality, like a parent channel tracking -// subchannles. This exercises the ref/unref patterns since the parent tracer -// and this function will both hold refs to the subchannel. -static void test_complex_channel_tracing(size_t max_nodes) { - grpc_core::ExecCtx exec_ctx; - RefCountedPtr tracer = MakeRefCounted(max_nodes); - add_simple_trace_event(tracer); - add_simple_trace_event(tracer); - RefCountedPtr sc1 = MakeRefCounted(max_nodes); - tracer->AddTraceEvent(grpc_slice_from_static_string("subchannel one created"), - GRPC_ERROR_NONE, GRPC_CHANNEL_IDLE, sc1); - validate_tracer(tracer, 3, max_nodes); - add_simple_trace_event(sc1); - add_simple_trace_event(sc1); - add_simple_trace_event(sc1); - validate_tracer(sc1, 3, max_nodes); - add_simple_trace_event(sc1); - add_simple_trace_event(sc1); - add_simple_trace_event(sc1); - validate_tracer(sc1, 6, max_nodes); - add_simple_trace_event(tracer); - add_simple_trace_event(tracer); - validate_tracer(tracer, 5, max_nodes); - validate_tracer_data_matches_uuid_lookup(tracer); - RefCountedPtr sc2 = MakeRefCounted(max_nodes); - tracer->AddTraceEvent(grpc_slice_from_static_string("subchannel two created"), - GRPC_ERROR_NONE, GRPC_CHANNEL_IDLE, sc2); - tracer->AddTraceEvent( - grpc_slice_from_static_string("subchannel one inactive"), GRPC_ERROR_NONE, - GRPC_CHANNEL_IDLE, sc1); - validate_tracer(tracer, 7, max_nodes); - add_simple_trace_event(tracer); - add_simple_trace_event(tracer); - add_simple_trace_event(tracer); - add_simple_trace_event(tracer); - add_simple_trace_event(tracer); - add_simple_trace_event(tracer); - validate_tracer_data_matches_uuid_lookup(tracer); - tracer.reset(nullptr); - sc1.reset(nullptr); - sc2.reset(nullptr); -} - -// Calls the complex test with a sweep of sizes for max_nodes. -TEST(ChannelTracerTest, ComplexTest) { - test_complex_channel_tracing(0); - test_complex_channel_tracing(1); - test_complex_channel_tracing(2); - test_complex_channel_tracing(6); - test_complex_channel_tracing(10); - test_complex_channel_tracing(15); -} - -// Test a case in which the parent channel has subchannels and the subchannels -// have connections. Ensures that everything lives as long as it should then -// gets deleted. -TEST(ChannelTracerTest, TestNesting) { - grpc_core::ExecCtx exec_ctx; - RefCountedPtr tracer = MakeRefCounted(10); - add_simple_trace_event(tracer); - add_simple_trace_event(tracer); - RefCountedPtr sc1 = MakeRefCounted(5); - tracer->AddTraceEvent(grpc_slice_from_static_string("subchannel one created"), - GRPC_ERROR_NONE, GRPC_CHANNEL_IDLE, sc1); - add_simple_trace_event(sc1); - RefCountedPtr conn1 = MakeRefCounted(5); - // nesting one level deeper. - sc1->AddTraceEvent(grpc_slice_from_static_string("connection one created"), - GRPC_ERROR_NONE, GRPC_CHANNEL_IDLE, conn1); - add_simple_trace_event(conn1); - add_simple_trace_event(tracer); - add_simple_trace_event(tracer); - RefCountedPtr sc2 = MakeRefCounted(5); - tracer->AddTraceEvent(grpc_slice_from_static_string("subchannel two created"), - GRPC_ERROR_NONE, GRPC_CHANNEL_IDLE, sc2); - // this trace should not get added to the parents children since it is already - // present in the tracer. - tracer->AddTraceEvent( - grpc_slice_from_static_string("subchannel one inactive"), GRPC_ERROR_NONE, - GRPC_CHANNEL_IDLE, sc1); - add_simple_trace_event(tracer); - tracer.reset(nullptr); - sc1.reset(nullptr); - sc2.reset(nullptr); - conn1.reset(nullptr); -} - -} // namespace testing -} // namespace grpc_core - -int main(int argc, char** argv) { - grpc_test_init(argc, argv); - grpc_init(); - ::testing::InitGoogleTest(&argc, argv); - int ret = RUN_ALL_TESTS(); - grpc_shutdown(); - return ret; -} diff --git a/test/core/util/channel_tracing_utils.cc b/test/core/util/channel_tracing_utils.cc index a2449cc4bd..be37703ecc 100644 --- a/test/core/util/channel_tracing_utils.cc +++ b/test/core/util/channel_tracing_utils.cc @@ -20,7 +20,7 @@ #include #include -#include "src/core/lib/channel/channel_tracer.h" +#include "src/core/lib/channel/channel_trace.h" #include "src/core/lib/gpr/useful.h" #include "src/core/lib/json/json.h" diff --git a/test/core/util/channel_tracing_utils.h b/test/core/util/channel_tracing_utils.h index fc04d8bae6..2038cd83aa 100644 --- a/test/core/util/channel_tracing_utils.h +++ b/test/core/util/channel_tracing_utils.h @@ -19,8 +19,6 @@ #ifndef GRPC_TEST_CORE_UTIL_CHANNEL_TRACING_UTILS_H #define GRPC_TEST_CORE_UTIL_CHANNEL_TRACING_UTILS_H -#include "src/core/lib/channel/channel_tracer.h" - void validate_json_array_size(grpc_json* json, const char* key, size_t expected_size); diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index 4a7428e2d8..72fb62d1f2 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -1007,7 +1007,7 @@ src/core/lib/backoff/backoff.h \ src/core/lib/channel/channel_args.h \ src/core/lib/channel/channel_stack.h \ src/core/lib/channel/channel_stack_builder.h \ -src/core/lib/channel/channel_tracer.h \ +src/core/lib/channel/channel_trace.h \ src/core/lib/channel/connected_channel.h \ src/core/lib/channel/context.h \ src/core/lib/channel/handshaker.h \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index e1856bf9aa..a64ff1eaf1 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -1034,8 +1034,8 @@ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack.h \ src/core/lib/channel/channel_stack_builder.cc \ src/core/lib/channel/channel_stack_builder.h \ -src/core/lib/channel/channel_tracer.cc \ -src/core/lib/channel/channel_tracer.h \ +src/core/lib/channel/channel_trace.cc \ +src/core/lib/channel/channel_trace.h \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/connected_channel.h \ src/core/lib/channel/context.h \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index e4741fc0d2..1854b33ce1 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -2837,9 +2837,9 @@ "headers": [], "is_filegroup": false, "language": "c++", - "name": "channel_tracer_test", + "name": "channel_trace_test", "src": [ - "test/core/channel/channel_tracer_test.cc" + "test/core/channel/channel_trace_test.cc" ], "third_party": false, "type": "target" @@ -8575,7 +8575,7 @@ "src/core/lib/channel/channel_args.cc", "src/core/lib/channel/channel_stack.cc", "src/core/lib/channel/channel_stack_builder.cc", - "src/core/lib/channel/channel_tracer.cc", + "src/core/lib/channel/channel_trace.cc", "src/core/lib/channel/connected_channel.cc", "src/core/lib/channel/handshaker.cc", "src/core/lib/channel/handshaker_factory.cc", @@ -8734,7 +8734,7 @@ "src/core/lib/channel/channel_args.h", "src/core/lib/channel/channel_stack.h", "src/core/lib/channel/channel_stack_builder.h", - "src/core/lib/channel/channel_tracer.h", + "src/core/lib/channel/channel_trace.h", "src/core/lib/channel/connected_channel.h", "src/core/lib/channel/context.h", "src/core/lib/channel/handshaker.h", @@ -8880,7 +8880,7 @@ "src/core/lib/channel/channel_args.h", "src/core/lib/channel/channel_stack.h", "src/core/lib/channel/channel_stack_builder.h", - "src/core/lib/channel/channel_tracer.h", + "src/core/lib/channel/channel_trace.h", "src/core/lib/channel/connected_channel.h", "src/core/lib/channel/context.h", "src/core/lib/channel/handshaker.h", diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 4d86843f13..cae60dd29a 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -3352,7 +3352,7 @@ "flaky": false, "gtest": true, "language": "c++", - "name": "channel_tracer_test", + "name": "channel_trace_test", "platforms": [ "linux", "mac", -- cgit v1.2.3 From 1cc064dbfc5fd91a6f705881427b39ca4675abe3 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Tue, 6 Mar 2018 07:53:58 -0800 Subject: Reviewer feedback, s/object_registry/channel_trace_registry --- CMakeLists.txt | 12 +-- Makefile | 12 +-- build.yaml | 4 +- config.m4 | 2 +- config.w32 | 2 +- gRPC-C++.podspec | 4 +- gRPC-Core.podspec | 6 +- grpc.gemspec | 4 +- grpc.gyp | 8 +- package.xml | 4 +- src/core/ext/filters/client_channel/subchannel.cc | 2 +- src/core/lib/channel/channel_trace.cc | 6 +- src/core/lib/channel/channel_trace_registry.cc | 80 ++++++++++++++++ src/core/lib/channel/channel_trace_registry.h | 43 +++++++++ src/core/lib/channel/object_registry.cc | 103 --------------------- src/core/lib/channel/object_registry.h | 52 ----------- src/core/lib/surface/channel.cc | 1 - src/core/lib/surface/init.cc | 6 +- src/python/grpcio/grpc_core_dependencies.py | 2 +- test/core/channel/channel_trace_test.cc | 14 +-- tools/doxygen/Doxyfile.c++.internal | 2 +- tools/doxygen/Doxyfile.core.internal | 4 +- tools/run_tests/generated/sources_and_headers.json | 6 +- 23 files changed, 171 insertions(+), 208 deletions(-) create mode 100644 src/core/lib/channel/channel_trace_registry.cc create mode 100644 src/core/lib/channel/channel_trace_registry.h delete mode 100644 src/core/lib/channel/object_registry.cc delete mode 100644 src/core/lib/channel/object_registry.h (limited to 'gRPC-C++.podspec') diff --git a/CMakeLists.txt b/CMakeLists.txt index 651fb6bde9..9c4d6a3070 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -801,11 +801,11 @@ add_library(grpc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc src/core/lib/channel/channel_trace.cc + src/core/lib/channel/channel_trace_registry.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc src/core/lib/channel/handshaker_registry.cc - src/core/lib/channel/object_registry.cc src/core/lib/compression/compression.cc src/core/lib/compression/compression_internal.cc src/core/lib/compression/message_compress.cc @@ -1145,11 +1145,11 @@ add_library(grpc_cronet src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc src/core/lib/channel/channel_trace.cc + src/core/lib/channel/channel_trace_registry.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc src/core/lib/channel/handshaker_registry.cc - src/core/lib/channel/object_registry.cc src/core/lib/compression/compression.cc src/core/lib/compression/compression_internal.cc src/core/lib/compression/message_compress.cc @@ -1476,11 +1476,11 @@ add_library(grpc_test_util src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc src/core/lib/channel/channel_trace.cc + src/core/lib/channel/channel_trace_registry.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc src/core/lib/channel/handshaker_registry.cc - src/core/lib/channel/object_registry.cc src/core/lib/compression/compression.cc src/core/lib/compression/compression_internal.cc src/core/lib/compression/message_compress.cc @@ -1768,11 +1768,11 @@ add_library(grpc_test_util_unsecure src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc src/core/lib/channel/channel_trace.cc + src/core/lib/channel/channel_trace_registry.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc src/core/lib/channel/handshaker_registry.cc - src/core/lib/channel/object_registry.cc src/core/lib/compression/compression.cc src/core/lib/compression/compression_internal.cc src/core/lib/compression/message_compress.cc @@ -2039,11 +2039,11 @@ add_library(grpc_unsecure src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc src/core/lib/channel/channel_trace.cc + src/core/lib/channel/channel_trace_registry.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc src/core/lib/channel/handshaker_registry.cc - src/core/lib/channel/object_registry.cc src/core/lib/compression/compression.cc src/core/lib/compression/compression_internal.cc src/core/lib/compression/message_compress.cc @@ -2844,11 +2844,11 @@ add_library(grpc++_cronet src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc src/core/lib/channel/channel_trace.cc + src/core/lib/channel/channel_trace_registry.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc src/core/lib/channel/handshaker_registry.cc - src/core/lib/channel/object_registry.cc src/core/lib/compression/compression.cc src/core/lib/compression/compression_internal.cc src/core/lib/compression/message_compress.cc diff --git a/Makefile b/Makefile index 01bad6692d..ed87a6a2c4 100644 --- a/Makefile +++ b/Makefile @@ -3041,11 +3041,11 @@ LIBGRPC_SRC = \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ src/core/lib/channel/channel_trace.cc \ + src/core/lib/channel/channel_trace_registry.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ - src/core/lib/channel/object_registry.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ @@ -3387,11 +3387,11 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ src/core/lib/channel/channel_trace.cc \ + src/core/lib/channel/channel_trace_registry.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ - src/core/lib/channel/object_registry.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ @@ -3719,11 +3719,11 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ src/core/lib/channel/channel_trace.cc \ + src/core/lib/channel/channel_trace_registry.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ - src/core/lib/channel/object_registry.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ @@ -4004,11 +4004,11 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ src/core/lib/channel/channel_trace.cc \ + src/core/lib/channel/channel_trace_registry.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ - src/core/lib/channel/object_registry.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ @@ -4255,11 +4255,11 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ src/core/lib/channel/channel_trace.cc \ + src/core/lib/channel/channel_trace_registry.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ - src/core/lib/channel/object_registry.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ @@ -5059,11 +5059,11 @@ LIBGRPC++_CRONET_SRC = \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ src/core/lib/channel/channel_trace.cc \ + src/core/lib/channel/channel_trace_registry.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ - src/core/lib/channel/object_registry.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ diff --git a/build.yaml b/build.yaml index 9ef6092e03..85ea6e7993 100644 --- a/build.yaml +++ b/build.yaml @@ -155,11 +155,11 @@ filegroups: - src/core/lib/channel/channel_stack.cc - src/core/lib/channel/channel_stack_builder.cc - src/core/lib/channel/channel_trace.cc + - src/core/lib/channel/channel_trace_registry.cc - src/core/lib/channel/connected_channel.cc - src/core/lib/channel/handshaker.cc - src/core/lib/channel/handshaker_factory.cc - src/core/lib/channel/handshaker_registry.cc - - src/core/lib/channel/object_registry.cc - src/core/lib/compression/compression.cc - src/core/lib/compression/compression_internal.cc - src/core/lib/compression/message_compress.cc @@ -313,12 +313,12 @@ filegroups: - src/core/lib/channel/channel_stack.h - src/core/lib/channel/channel_stack_builder.h - src/core/lib/channel/channel_trace.h + - src/core/lib/channel/channel_trace_registry.h - src/core/lib/channel/connected_channel.h - src/core/lib/channel/context.h - src/core/lib/channel/handshaker.h - src/core/lib/channel/handshaker_factory.h - src/core/lib/channel/handshaker_registry.h - - src/core/lib/channel/object_registry.h - src/core/lib/compression/algorithm_metadata.h - src/core/lib/compression/compression_internal.h - src/core/lib/compression/message_compress.h diff --git a/config.m4 b/config.m4 index d53c2f4589..b46eb4078b 100644 --- a/config.m4 +++ b/config.m4 @@ -85,11 +85,11 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ src/core/lib/channel/channel_trace.cc \ + src/core/lib/channel/channel_trace_registry.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ - src/core/lib/channel/object_registry.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ diff --git a/config.w32 b/config.w32 index 548ae73e31..ea90cb5424 100644 --- a/config.w32 +++ b/config.w32 @@ -62,11 +62,11 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\channel\\channel_stack.cc " + "src\\core\\lib\\channel\\channel_stack_builder.cc " + "src\\core\\lib\\channel\\channel_trace.cc " + + "src\\core\\lib\\channel\\channel_trace_registry.cc " + "src\\core\\lib\\channel\\connected_channel.cc " + "src\\core\\lib\\channel\\handshaker.cc " + "src\\core\\lib\\channel\\handshaker_factory.cc " + "src\\core\\lib\\channel\\handshaker_registry.cc " + - "src\\core\\lib\\channel\\object_registry.cc " + "src\\core\\lib\\compression\\compression.cc " + "src\\core\\lib\\compression\\compression_internal.cc " + "src\\core\\lib\\compression\\message_compress.cc " + diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 4403af53c5..ae45fe12f3 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -317,12 +317,12 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_stack.h', 'src/core/lib/channel/channel_stack_builder.h', 'src/core/lib/channel/channel_trace.h', + 'src/core/lib/channel/channel_trace_registry.h', 'src/core/lib/channel/connected_channel.h', 'src/core/lib/channel/context.h', 'src/core/lib/channel/handshaker.h', 'src/core/lib/channel/handshaker_factory.h', 'src/core/lib/channel/handshaker_registry.h', - 'src/core/lib/channel/object_registry.h', 'src/core/lib/compression/algorithm_metadata.h', 'src/core/lib/compression/compression_internal.h', 'src/core/lib/compression/message_compress.h', @@ -498,12 +498,12 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_stack.h', 'src/core/lib/channel/channel_stack_builder.h', 'src/core/lib/channel/channel_trace.h', + 'src/core/lib/channel/channel_trace_registry.h', 'src/core/lib/channel/connected_channel.h', 'src/core/lib/channel/context.h', 'src/core/lib/channel/handshaker.h', 'src/core/lib/channel/handshaker_factory.h', 'src/core/lib/channel/handshaker_registry.h', - 'src/core/lib/channel/object_registry.h', 'src/core/lib/compression/algorithm_metadata.h', 'src/core/lib/compression/compression_internal.h', 'src/core/lib/compression/message_compress.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 852992e606..cf26d7e73d 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -328,12 +328,12 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_stack.h', 'src/core/lib/channel/channel_stack_builder.h', 'src/core/lib/channel/channel_trace.h', + 'src/core/lib/channel/channel_trace_registry.h', 'src/core/lib/channel/connected_channel.h', 'src/core/lib/channel/context.h', 'src/core/lib/channel/handshaker.h', 'src/core/lib/channel/handshaker_factory.h', 'src/core/lib/channel/handshaker_registry.h', - 'src/core/lib/channel/object_registry.h', 'src/core/lib/compression/algorithm_metadata.h', 'src/core/lib/compression/compression_internal.h', 'src/core/lib/compression/message_compress.h', @@ -474,11 +474,11 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', 'src/core/lib/channel/channel_trace.cc', + 'src/core/lib/channel/channel_trace_registry.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', 'src/core/lib/channel/handshaker_registry.cc', - 'src/core/lib/channel/object_registry.cc', 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/compression_internal.cc', 'src/core/lib/compression/message_compress.cc', @@ -826,12 +826,12 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_stack.h', 'src/core/lib/channel/channel_stack_builder.h', 'src/core/lib/channel/channel_trace.h', + 'src/core/lib/channel/channel_trace_registry.h', 'src/core/lib/channel/connected_channel.h', 'src/core/lib/channel/context.h', 'src/core/lib/channel/handshaker.h', 'src/core/lib/channel/handshaker_factory.h', 'src/core/lib/channel/handshaker_registry.h', - 'src/core/lib/channel/object_registry.h', 'src/core/lib/compression/algorithm_metadata.h', 'src/core/lib/compression/compression_internal.h', 'src/core/lib/compression/message_compress.h', diff --git a/grpc.gemspec b/grpc.gemspec index a53cdfdfe9..a20d8efe14 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -254,12 +254,12 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/channel/channel_stack.h ) s.files += %w( src/core/lib/channel/channel_stack_builder.h ) s.files += %w( src/core/lib/channel/channel_trace.h ) + s.files += %w( src/core/lib/channel/channel_trace_registry.h ) s.files += %w( src/core/lib/channel/connected_channel.h ) s.files += %w( src/core/lib/channel/context.h ) s.files += %w( src/core/lib/channel/handshaker.h ) s.files += %w( src/core/lib/channel/handshaker_factory.h ) s.files += %w( src/core/lib/channel/handshaker_registry.h ) - s.files += %w( src/core/lib/channel/object_registry.h ) s.files += %w( src/core/lib/compression/algorithm_metadata.h ) s.files += %w( src/core/lib/compression/compression_internal.h ) s.files += %w( src/core/lib/compression/message_compress.h ) @@ -404,11 +404,11 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/channel/channel_stack.cc ) s.files += %w( src/core/lib/channel/channel_stack_builder.cc ) s.files += %w( src/core/lib/channel/channel_trace.cc ) + s.files += %w( src/core/lib/channel/channel_trace_registry.cc ) s.files += %w( src/core/lib/channel/connected_channel.cc ) s.files += %w( src/core/lib/channel/handshaker.cc ) s.files += %w( src/core/lib/channel/handshaker_factory.cc ) s.files += %w( src/core/lib/channel/handshaker_registry.cc ) - s.files += %w( src/core/lib/channel/object_registry.cc ) s.files += %w( src/core/lib/compression/compression.cc ) s.files += %w( src/core/lib/compression/compression_internal.cc ) s.files += %w( src/core/lib/compression/message_compress.cc ) diff --git a/grpc.gyp b/grpc.gyp index ca76c68077..0b7b3b9daf 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -226,11 +226,11 @@ 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', 'src/core/lib/channel/channel_trace.cc', + 'src/core/lib/channel/channel_trace_registry.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', 'src/core/lib/channel/handshaker_registry.cc', - 'src/core/lib/channel/object_registry.cc', 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/compression_internal.cc', 'src/core/lib/compression/message_compress.cc', @@ -528,11 +528,11 @@ 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', 'src/core/lib/channel/channel_trace.cc', + 'src/core/lib/channel/channel_trace_registry.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', 'src/core/lib/channel/handshaker_registry.cc', - 'src/core/lib/channel/object_registry.cc', 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/compression_internal.cc', 'src/core/lib/compression/message_compress.cc', @@ -748,11 +748,11 @@ 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', 'src/core/lib/channel/channel_trace.cc', + 'src/core/lib/channel/channel_trace_registry.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', 'src/core/lib/channel/handshaker_registry.cc', - 'src/core/lib/channel/object_registry.cc', 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/compression_internal.cc', 'src/core/lib/compression/message_compress.cc', @@ -946,11 +946,11 @@ 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', 'src/core/lib/channel/channel_trace.cc', + 'src/core/lib/channel/channel_trace_registry.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', 'src/core/lib/channel/handshaker_registry.cc', - 'src/core/lib/channel/object_registry.cc', 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/compression_internal.cc', 'src/core/lib/compression/message_compress.cc', diff --git a/package.xml b/package.xml index a0841886a9..a2b59e7339 100644 --- a/package.xml +++ b/package.xml @@ -261,12 +261,12 @@ + - @@ -411,11 +411,11 @@ + - diff --git a/src/core/ext/filters/client_channel/subchannel.cc b/src/core/ext/filters/client_channel/subchannel.cc index e8ff352be8..4802110e5a 100644 --- a/src/core/ext/filters/client_channel/subchannel.cc +++ b/src/core/ext/filters/client_channel/subchannel.cc @@ -37,8 +37,8 @@ #include "src/core/lib/backoff/backoff.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_trace.h" +#include "src/core/lib/channel/channel_trace_registry.h" #include "src/core/lib/channel/connected_channel.h" -#include "src/core/lib/channel/object_registry.h" #include "src/core/lib/debug/stats.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/manual_constructor.h" diff --git a/src/core/lib/channel/channel_trace.cc b/src/core/lib/channel/channel_trace.cc index 3217a83fba..226ab0292d 100644 --- a/src/core/lib/channel/channel_trace.cc +++ b/src/core/lib/channel/channel_trace.cc @@ -28,7 +28,7 @@ #include #include "src/core/ext/filters/client_channel/status_util.h" -#include "src/core/lib/channel/object_registry.h" +#include "src/core/lib/channel/channel_trace_registry.h" #include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/memory.h" @@ -76,8 +76,7 @@ ChannelTrace::ChannelTrace(size_t max_events) tail_trace_(nullptr) { if (max_list_size_ == 0) return; // tracing is disabled if max_events == 0 gpr_mu_init(&tracer_mu_); - channel_uuid_ = grpc_object_registry_register_object( - this, GRPC_OBJECT_REGISTRY_CHANNEL_TRACER); + channel_uuid_ = grpc_channel_trace_registry_register_channel_trace(this); time_created_ = grpc_millis_to_timespec(grpc_core::ExecCtx::Get()->Now(), GPR_CLOCK_REALTIME); } @@ -90,6 +89,7 @@ ChannelTrace::~ChannelTrace() { it = it->next(); Delete(to_free); } + grpc_channel_trace_registry_unregister_channel_trace(channel_uuid_); gpr_mu_destroy(&tracer_mu_); } diff --git a/src/core/lib/channel/channel_trace_registry.cc b/src/core/lib/channel/channel_trace_registry.cc new file mode 100644 index 0000000000..6c82431467 --- /dev/null +++ b/src/core/lib/channel/channel_trace_registry.cc @@ -0,0 +1,80 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/lib/avl/avl.h" +#include "src/core/lib/channel/channel_trace.h" +#include "src/core/lib/channel/channel_trace_registry.h" +#include "src/core/lib/gpr/useful.h" + +#include +#include + +// file global lock and avl. +static gpr_mu g_mu; +static grpc_avl g_avl; +static gpr_atm g_uuid = 0; + +// avl vtable for uuid (intptr_t) -> ChannelTrace +// this table is only looking, it does not own anything. +static void destroy_intptr(void* not_used, void* user_data) {} +static void* copy_intptr(void* key, void* user_data) { return key; } +static long compare_intptr(void* key1, void* key2, void* user_data) { + return GPR_ICMP(key1, key2); +} + +static void destroy_channel_trace(void* trace, void* user_data) {} +static void* copy_channel_trace(void* trace, void* user_data) { return trace; } +static const grpc_avl_vtable avl_vtable = { + destroy_intptr, copy_intptr, compare_intptr, destroy_channel_trace, + copy_channel_trace}; + +void grpc_channel_trace_registry_init() { + gpr_mu_init(&g_mu); + g_avl = grpc_avl_create(&avl_vtable); +} + +void grpc_channel_trace_registry_shutdown() { + grpc_avl_unref(g_avl, nullptr); + gpr_mu_destroy(&g_mu); +} + +intptr_t grpc_channel_trace_registry_register_channel_trace( + grpc_core::ChannelTrace* channel_trace) { + intptr_t prior = gpr_atm_no_barrier_fetch_add(&g_uuid, 1); + gpr_mu_lock(&g_mu); + g_avl = grpc_avl_add(g_avl, (void*)prior, channel_trace, nullptr); + gpr_mu_unlock(&g_mu); + return prior; +} + +void grpc_channel_trace_registry_unregister_channel_trace(intptr_t uuid) { + gpr_mu_lock(&g_mu); + g_avl = grpc_avl_remove(g_avl, (void*)uuid, nullptr); + gpr_mu_unlock(&g_mu); +} + +grpc_core::ChannelTrace* grpc_channel_trace_registry_get_channel_trace( + intptr_t uuid) { + gpr_mu_lock(&g_mu); + grpc_core::ChannelTrace* ret = static_cast( + grpc_avl_get(g_avl, (void*)uuid, nullptr)); + gpr_mu_unlock(&g_mu); + return ret; +} diff --git a/src/core/lib/channel/channel_trace_registry.h b/src/core/lib/channel/channel_trace_registry.h new file mode 100644 index 0000000000..391ecba7de --- /dev/null +++ b/src/core/lib/channel/channel_trace_registry.h @@ -0,0 +1,43 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_LIB_CHANNEL_CHANNEL_TRACE_REGISTRY_H +#define GRPC_CORE_LIB_CHANNEL_CHANNEL_TRACE_REGISTRY_H + +#include + +#include "src/core/lib/channel/channel_trace.h" + +#include + +// TODO(ncteisen): convert this file to C++ + +void grpc_channel_trace_registry_init(); +void grpc_channel_trace_registry_shutdown(); + +// globally registers a ChannelTrace. Returns its unique uuid +intptr_t grpc_channel_trace_registry_register_channel_trace( + grpc_core::ChannelTrace* channel_trace); +// globally unregisters the ChannelTrace that is associated to uuid. +void grpc_channel_trace_registry_unregister_channel_trace(intptr_t uuid); +// if object with uuid has previously been registered, returns the ChannelTrace +// associated with that uuid. Else returns nullptr. +grpc_core::ChannelTrace* grpc_channel_trace_registry_get_channel_trace( + intptr_t uuid); + +#endif /* GRPC_CORE_LIB_CHANNEL_CHANNEL_TRACE_REGISTRY_H */ diff --git a/src/core/lib/channel/object_registry.cc b/src/core/lib/channel/object_registry.cc deleted file mode 100644 index 987c5366ca..0000000000 --- a/src/core/lib/channel/object_registry.cc +++ /dev/null @@ -1,103 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/lib/avl/avl.h" -#include "src/core/lib/channel/object_registry.h" -#include "src/core/lib/gpr/useful.h" - -#include -#include - -// file global lock and avl. -static gpr_mu g_mu; -static grpc_avl g_avl; -static gpr_atm g_uuid = 0; - -typedef struct { - void* object; - grpc_object_registry_type type; -} object_tracker; - -// avl vtable for uuid (intptr_t) -> object_tracker -// this table is only looking, it does not own anything. -static void destroy_intptr(void* not_used, void* user_data) {} -static void* copy_intptr(void* key, void* user_data) { return key; } -static long compare_intptr(void* key1, void* key2, void* user_data) { - return GPR_ICMP(key1, key2); -} - -static void destroy_tracker(void* tracker, void* user_data) { - gpr_free((object_tracker*)tracker); -} - -static void* copy_tracker(void* value, void* user_data) { - object_tracker* old = static_cast(value); - object_tracker* new_obj = - static_cast(gpr_malloc(sizeof(object_tracker))); - new_obj->object = old->object; - new_obj->type = old->type; - return new_obj; -} -static const grpc_avl_vtable avl_vtable = { - destroy_intptr, copy_intptr, compare_intptr, destroy_tracker, copy_tracker}; - -void grpc_object_registry_init() { - gpr_mu_init(&g_mu); - g_avl = grpc_avl_create(&avl_vtable); -} - -void grpc_object_registry_shutdown() { - grpc_avl_unref(g_avl, nullptr); - gpr_mu_destroy(&g_mu); -} - -intptr_t grpc_object_registry_register_object(void* object, - grpc_object_registry_type type) { - object_tracker* tracker = - static_cast(gpr_malloc(sizeof(object_tracker))); - tracker->object = object; - tracker->type = type; - intptr_t prior = gpr_atm_no_barrier_fetch_add(&g_uuid, 1); - gpr_mu_lock(&g_mu); - g_avl = grpc_avl_add(g_avl, (void*)prior, tracker, nullptr); - gpr_mu_unlock(&g_mu); - return prior; -} - -void grpc_object_registry_unregister_object(intptr_t uuid) { - gpr_mu_lock(&g_mu); - g_avl = grpc_avl_remove(g_avl, (void*)uuid, nullptr); - gpr_mu_unlock(&g_mu); -} - -grpc_object_registry_type grpc_object_registry_get_object(intptr_t uuid, - void** object) { - GPR_ASSERT(object); - gpr_mu_lock(&g_mu); - object_tracker* tracker = - static_cast(grpc_avl_get(g_avl, (void*)uuid, nullptr)); - gpr_mu_unlock(&g_mu); - if (tracker == nullptr) { - *object = nullptr; - return GRPC_OBJECT_REGISTRY_UNKNOWN; - } - *object = tracker->object; - return tracker->type; -} diff --git a/src/core/lib/channel/object_registry.h b/src/core/lib/channel/object_registry.h deleted file mode 100644 index 446d0cb41f..0000000000 --- a/src/core/lib/channel/object_registry.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_LIB_CHANNEL_OBJECT_REGISTRY_H -#define GRPC_CORE_LIB_CHANNEL_OBJECT_REGISTRY_H - -#include - -#include - -// TODO(ncteisen): convert this file to C++ - -// Different types that may be stored in the general object registry. For now, -// the only use case is channel tracers, but the design has been left general. -typedef enum { - // Used to hold uuid -> ChannelTracer mappings to allow for the trace data - // to be looked up by uuid, rather then have to walk the entire tree of - // trace. - GRPC_OBJECT_REGISTRY_CHANNEL_TRACER, - // Usually represents an error has occurred in the object lookup. - GRPC_OBJECT_REGISTRY_UNKNOWN, -} grpc_object_registry_type; - -void grpc_object_registry_init(); -void grpc_object_registry_shutdown(); - -// globally registers the object. Returns its unique uuid -intptr_t grpc_object_registry_register_object(void* object, - grpc_object_registry_type type); -// globally unregisters the object that is associated to uuid. -void grpc_object_registry_unregister_object(intptr_t uuid); -// if object with uuid has previously been registered, stores it in *object. -// if not, returns GRPC_OBJECT_REGISTRY_UNKNOWN and sets *object unchanged. -grpc_object_registry_type grpc_object_registry_get_object(intptr_t uuid, - void** object); - -#endif /* GRPC_CORE_LIB_CHANNEL_OBJECT_REGISTRY_H */ diff --git a/src/core/lib/surface/channel.cc b/src/core/lib/surface/channel.cc index c470f6d0d8..dca583abbe 100644 --- a/src/core/lib/surface/channel.cc +++ b/src/core/lib/surface/channel.cc @@ -32,7 +32,6 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_trace.h" -#include "src/core/lib/channel/object_registry.h" #include "src/core/lib/debug/stats.h" #include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/manual_constructor.h" diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc index 2d4b3b55d4..bd436d6857 100644 --- a/src/core/lib/surface/init.cc +++ b/src/core/lib/surface/init.cc @@ -27,9 +27,9 @@ #include #include #include "src/core/lib/channel/channel_stack.h" +#include "src/core/lib/channel/channel_trace_registry.h" #include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/channel/handshaker_registry.h" -#include "src/core/lib/channel/object_registry.h" #include "src/core/lib/debug/stats.h" #include "src/core/lib/debug/trace.h" #include "src/core/lib/gpr/fork.h" @@ -129,7 +129,7 @@ void grpc_init(void) { grpc_slice_intern_init(); grpc_mdctx_global_init(); grpc_channel_init_init(); - grpc_object_registry_init(); + grpc_channel_trace_registry_init(); grpc_security_pre_init(); grpc_core::ExecCtx::GlobalInit(); grpc_iomgr_init(); @@ -178,7 +178,7 @@ void grpc_shutdown(void) { grpc_mdctx_global_shutdown(); grpc_handshaker_factory_registry_shutdown(); grpc_slice_intern_shutdown(); - grpc_object_registry_shutdown(); + grpc_channel_trace_registry_shutdown(); grpc_stats_shutdown(); } grpc_core::ExecCtx::GlobalShutdown(); diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 3c3c1d6943..bc9b5a3c73 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -61,11 +61,11 @@ CORE_SOURCE_FILES = [ 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', 'src/core/lib/channel/channel_trace.cc', + 'src/core/lib/channel/channel_trace_registry.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', 'src/core/lib/channel/handshaker_registry.cc', - 'src/core/lib/channel/object_registry.cc', 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/compression_internal.cc', 'src/core/lib/compression/message_compress.cc', diff --git a/test/core/channel/channel_trace_test.cc b/test/core/channel/channel_trace_test.cc index c0cccb77ac..dcc3a347bf 100644 --- a/test/core/channel/channel_trace_test.cc +++ b/test/core/channel/channel_trace_test.cc @@ -25,7 +25,7 @@ #include #include "src/core/lib/channel/channel_trace.h" -#include "src/core/lib/channel/object_registry.h" +#include "src/core/lib/channel/channel_trace_registry.h" #include "src/core/lib/gpr/useful.h" #include "src/core/lib/iomgr/exec_ctx.h" @@ -43,8 +43,7 @@ static void add_simple_trace_event(RefCountedPtr tracer) { // checks for the existence of all the required members of the tracer. static void validate_trace(RefCountedPtr tracer, - size_t expected_num_event_logged, - size_t max_nodes) { + size_t expected_num_event_logged, size_t max_nodes) { if (!max_nodes) return; char* json_str = tracer->RenderTrace(); grpc_json* json = grpc_json_parse_string(json_str); @@ -59,12 +58,9 @@ static void validate_trace_data_matches_uuid_lookup( intptr_t uuid = tracer->GetUuid(); if (uuid == -1) return; // Doesn't make sense to lookup if tracing disabled char* tracer_json_str = tracer->RenderTrace(); - void* object; - grpc_object_registry_type type = - grpc_object_registry_get_object(uuid, &object); - GPR_ASSERT(type == GRPC_OBJECT_REGISTRY_CHANNEL_TRACER); - char* uuid_lookup_json_str = - static_cast(object)->RenderTrace(); + ChannelTrace* uuid_lookup = + grpc_channel_trace_registry_get_channel_trace(uuid); + char* uuid_lookup_json_str = uuid_lookup->RenderTrace(); GPR_ASSERT(strcmp(tracer_json_str, uuid_lookup_json_str) == 0); gpr_free(tracer_json_str); gpr_free(uuid_lookup_json_str); diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index 72fb62d1f2..cae5cc5fa1 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -1008,12 +1008,12 @@ src/core/lib/channel/channel_args.h \ src/core/lib/channel/channel_stack.h \ src/core/lib/channel/channel_stack_builder.h \ src/core/lib/channel/channel_trace.h \ +src/core/lib/channel/channel_trace_registry.h \ src/core/lib/channel/connected_channel.h \ src/core/lib/channel/context.h \ src/core/lib/channel/handshaker.h \ src/core/lib/channel/handshaker_factory.h \ src/core/lib/channel/handshaker_registry.h \ -src/core/lib/channel/object_registry.h \ src/core/lib/compression/algorithm_metadata.h \ src/core/lib/compression/compression_internal.h \ src/core/lib/compression/message_compress.h \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index a64ff1eaf1..78805a0ad1 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -1036,6 +1036,8 @@ src/core/lib/channel/channel_stack_builder.cc \ src/core/lib/channel/channel_stack_builder.h \ src/core/lib/channel/channel_trace.cc \ src/core/lib/channel/channel_trace.h \ +src/core/lib/channel/channel_trace_registry.cc \ +src/core/lib/channel/channel_trace_registry.h \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/connected_channel.h \ src/core/lib/channel/context.h \ @@ -1045,8 +1047,6 @@ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_factory.h \ src/core/lib/channel/handshaker_registry.cc \ src/core/lib/channel/handshaker_registry.h \ -src/core/lib/channel/object_registry.cc \ -src/core/lib/channel/object_registry.h \ src/core/lib/compression/algorithm_metadata.h \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 1854b33ce1..90ef05546f 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -8576,11 +8576,11 @@ "src/core/lib/channel/channel_stack.cc", "src/core/lib/channel/channel_stack_builder.cc", "src/core/lib/channel/channel_trace.cc", + "src/core/lib/channel/channel_trace_registry.cc", "src/core/lib/channel/connected_channel.cc", "src/core/lib/channel/handshaker.cc", "src/core/lib/channel/handshaker_factory.cc", "src/core/lib/channel/handshaker_registry.cc", - "src/core/lib/channel/object_registry.cc", "src/core/lib/compression/compression.cc", "src/core/lib/compression/compression_internal.cc", "src/core/lib/compression/message_compress.cc", @@ -8735,12 +8735,12 @@ "src/core/lib/channel/channel_stack.h", "src/core/lib/channel/channel_stack_builder.h", "src/core/lib/channel/channel_trace.h", + "src/core/lib/channel/channel_trace_registry.h", "src/core/lib/channel/connected_channel.h", "src/core/lib/channel/context.h", "src/core/lib/channel/handshaker.h", "src/core/lib/channel/handshaker_factory.h", "src/core/lib/channel/handshaker_registry.h", - "src/core/lib/channel/object_registry.h", "src/core/lib/compression/algorithm_metadata.h", "src/core/lib/compression/compression_internal.h", "src/core/lib/compression/message_compress.h", @@ -8881,12 +8881,12 @@ "src/core/lib/channel/channel_stack.h", "src/core/lib/channel/channel_stack_builder.h", "src/core/lib/channel/channel_trace.h", + "src/core/lib/channel/channel_trace_registry.h", "src/core/lib/channel/connected_channel.h", "src/core/lib/channel/context.h", "src/core/lib/channel/handshaker.h", "src/core/lib/channel/handshaker_factory.h", "src/core/lib/channel/handshaker_registry.h", - "src/core/lib/channel/object_registry.h", "src/core/lib/compression/algorithm_metadata.h", "src/core/lib/compression/compression_internal.h", "src/core/lib/compression/message_compress.h", -- cgit v1.2.3 From e9587db8530446d894d5de470591201dabb3ac77 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Tue, 6 Mar 2018 08:16:04 -0800 Subject: Move status util --- BUILD | 4 +- CMakeLists.txt | 14 +-- Makefile | 16 ++-- build.yaml | 6 +- config.m4 | 2 +- config.w32 | 2 +- gRPC-C++.podspec | 3 +- gRPC-Core.podspec | 6 +- grpc.gemspec | 4 +- grpc.gyp | 8 +- package.xml | 4 +- .../ext/filters/client_channel/client_channel.cc | 2 +- .../ext/filters/client_channel/method_params.cc | 2 +- .../ext/filters/client_channel/method_params.h | 2 +- src/core/ext/filters/client_channel/status_util.cc | 100 --------------------- src/core/ext/filters/client_channel/status_util.h | 58 ------------ src/core/lib/channel/channel_trace.cc | 2 +- src/core/lib/channel/status_util.cc | 100 +++++++++++++++++++++ src/core/lib/channel/status_util.h | 58 ++++++++++++ src/python/grpcio/grpc_core_dependencies.py | 2 +- test/core/channel/BUILD | 18 +++- test/core/channel/status_util_test.cc | 49 ++++++++++ test/core/client_channel/BUILD | 12 --- test/core/client_channel/status_util_test.cc | 49 ---------- tools/doxygen/Doxyfile.c++.internal | 1 + tools/doxygen/Doxyfile.core.internal | 4 +- tools/run_tests/generated/sources_and_headers.json | 8 +- 27 files changed, 269 insertions(+), 267 deletions(-) delete mode 100644 src/core/ext/filters/client_channel/status_util.cc delete mode 100644 src/core/ext/filters/client_channel/status_util.h create mode 100644 src/core/lib/channel/status_util.cc create mode 100644 src/core/lib/channel/status_util.h create mode 100644 test/core/channel/status_util_test.cc delete mode 100644 test/core/client_channel/status_util_test.cc (limited to 'gRPC-C++.podspec') diff --git a/BUILD b/BUILD index 0baf89ff57..40ba497a59 100644 --- a/BUILD +++ b/BUILD @@ -677,6 +677,7 @@ grpc_cc_library( "src/core/lib/channel/channel_stack.cc", "src/core/lib/channel/channel_stack_builder.cc", "src/core/lib/channel/channel_tracer.cc", + "src/core/lib/channel/status_util.cc", "src/core/lib/channel/connected_channel.cc", "src/core/lib/channel/object_registry.cc", "src/core/lib/channel/handshaker.cc", @@ -814,6 +815,7 @@ grpc_cc_library( "src/core/lib/channel/channel_stack.h", "src/core/lib/channel/channel_stack_builder.h", "src/core/lib/channel/channel_tracer.h", + "src/core/lib/channel/status_util.h", "src/core/lib/channel/connected_channel.h", "src/core/lib/channel/context.h", "src/core/lib/channel/object_registry.h", @@ -1006,7 +1008,6 @@ grpc_cc_library( "src/core/ext/filters/client_channel/resolver.cc", "src/core/ext/filters/client_channel/resolver_registry.cc", "src/core/ext/filters/client_channel/retry_throttle.cc", - "src/core/ext/filters/client_channel/status_util.cc", "src/core/ext/filters/client_channel/subchannel.cc", "src/core/ext/filters/client_channel/subchannel_index.cc", "src/core/ext/filters/client_channel/uri_parser.cc", @@ -1029,7 +1030,6 @@ grpc_cc_library( "src/core/ext/filters/client_channel/resolver_factory.h", "src/core/ext/filters/client_channel/resolver_registry.h", "src/core/ext/filters/client_channel/retry_throttle.h", - "src/core/ext/filters/client_channel/status_util.h", "src/core/ext/filters/client_channel/subchannel.h", "src/core/ext/filters/client_channel/subchannel_index.h", "src/core/ext/filters/client_channel/uri_parser.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c4d6a3070..088373f470 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -806,6 +806,7 @@ add_library(grpc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc src/core/lib/channel/handshaker_registry.cc + src/core/lib/channel/status_util.cc src/core/lib/compression/compression.cc src/core/lib/compression/compression_internal.cc src/core/lib/compression/message_compress.cc @@ -1010,7 +1011,6 @@ add_library(grpc src/core/ext/filters/client_channel/resolver.cc src/core/ext/filters/client_channel/resolver_registry.cc src/core/ext/filters/client_channel/retry_throttle.cc - src/core/ext/filters/client_channel/status_util.cc src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc @@ -1150,6 +1150,7 @@ add_library(grpc_cronet src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc src/core/lib/channel/handshaker_registry.cc + src/core/lib/channel/status_util.cc src/core/lib/compression/compression.cc src/core/lib/compression/compression_internal.cc src/core/lib/compression/message_compress.cc @@ -1325,7 +1326,6 @@ add_library(grpc_cronet src/core/ext/filters/client_channel/resolver.cc src/core/ext/filters/client_channel/resolver_registry.cc src/core/ext/filters/client_channel/retry_throttle.cc - src/core/ext/filters/client_channel/status_util.cc src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc @@ -1481,6 +1481,7 @@ add_library(grpc_test_util src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc src/core/lib/channel/handshaker_registry.cc + src/core/lib/channel/status_util.cc src/core/lib/compression/compression.cc src/core/lib/compression/compression_internal.cc src/core/lib/compression/message_compress.cc @@ -1625,7 +1626,6 @@ add_library(grpc_test_util src/core/ext/filters/client_channel/resolver.cc src/core/ext/filters/client_channel/resolver_registry.cc src/core/ext/filters/client_channel/retry_throttle.cc - src/core/ext/filters/client_channel/status_util.cc src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc @@ -1773,6 +1773,7 @@ add_library(grpc_test_util_unsecure src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc src/core/lib/channel/handshaker_registry.cc + src/core/lib/channel/status_util.cc src/core/lib/compression/compression.cc src/core/lib/compression/compression_internal.cc src/core/lib/compression/message_compress.cc @@ -1917,7 +1918,6 @@ add_library(grpc_test_util_unsecure src/core/ext/filters/client_channel/resolver.cc src/core/ext/filters/client_channel/resolver_registry.cc src/core/ext/filters/client_channel/retry_throttle.cc - src/core/ext/filters/client_channel/status_util.cc src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc @@ -2044,6 +2044,7 @@ add_library(grpc_unsecure src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc src/core/lib/channel/handshaker_registry.cc + src/core/lib/channel/status_util.cc src/core/lib/compression/compression.cc src/core/lib/compression/compression_internal.cc src/core/lib/compression/message_compress.cc @@ -2221,7 +2222,6 @@ add_library(grpc_unsecure src/core/ext/filters/client_channel/resolver.cc src/core/ext/filters/client_channel/resolver_registry.cc src/core/ext/filters/client_channel/retry_throttle.cc - src/core/ext/filters/client_channel/status_util.cc src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc @@ -2849,6 +2849,7 @@ add_library(grpc++_cronet src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc src/core/lib/channel/handshaker_registry.cc + src/core/lib/channel/status_util.cc src/core/lib/compression/compression.cc src/core/lib/compression/compression_internal.cc src/core/lib/compression/message_compress.cc @@ -2998,7 +2999,6 @@ add_library(grpc++_cronet src/core/ext/filters/client_channel/resolver.cc src/core/ext/filters/client_channel/resolver_registry.cc src/core/ext/filters/client_channel/retry_throttle.cc - src/core/ext/filters/client_channel/status_util.cc src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc @@ -12402,7 +12402,7 @@ endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) add_executable(status_util_test - test/core/client_channel/status_util_test.cc + test/core/channel/status_util_test.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) diff --git a/Makefile b/Makefile index ed87a6a2c4..6487050b63 100644 --- a/Makefile +++ b/Makefile @@ -3046,6 +3046,7 @@ LIBGRPC_SRC = \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ + src/core/lib/channel/status_util.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ @@ -3250,7 +3251,6 @@ LIBGRPC_SRC = \ src/core/ext/filters/client_channel/resolver.cc \ src/core/ext/filters/client_channel/resolver_registry.cc \ src/core/ext/filters/client_channel/retry_throttle.cc \ - src/core/ext/filters/client_channel/status_util.cc \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ @@ -3392,6 +3392,7 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ + src/core/lib/channel/status_util.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ @@ -3567,7 +3568,6 @@ LIBGRPC_CRONET_SRC = \ src/core/ext/filters/client_channel/resolver.cc \ src/core/ext/filters/client_channel/resolver_registry.cc \ src/core/ext/filters/client_channel/retry_throttle.cc \ - src/core/ext/filters/client_channel/status_util.cc \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ @@ -3724,6 +3724,7 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ + src/core/lib/channel/status_util.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ @@ -3868,7 +3869,6 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/ext/filters/client_channel/resolver.cc \ src/core/ext/filters/client_channel/resolver_registry.cc \ src/core/ext/filters/client_channel/retry_throttle.cc \ - src/core/ext/filters/client_channel/status_util.cc \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ @@ -4009,6 +4009,7 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ + src/core/lib/channel/status_util.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ @@ -4153,7 +4154,6 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ src/core/ext/filters/client_channel/resolver.cc \ src/core/ext/filters/client_channel/resolver_registry.cc \ src/core/ext/filters/client_channel/retry_throttle.cc \ - src/core/ext/filters/client_channel/status_util.cc \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ @@ -4260,6 +4260,7 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ + src/core/lib/channel/status_util.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ @@ -4437,7 +4438,6 @@ LIBGRPC_UNSECURE_SRC = \ src/core/ext/filters/client_channel/resolver.cc \ src/core/ext/filters/client_channel/resolver_registry.cc \ src/core/ext/filters/client_channel/retry_throttle.cc \ - src/core/ext/filters/client_channel/status_util.cc \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ @@ -5064,6 +5064,7 @@ LIBGRPC++_CRONET_SRC = \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ + src/core/lib/channel/status_util.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ @@ -5213,7 +5214,6 @@ LIBGRPC++_CRONET_SRC = \ src/core/ext/filters/client_channel/resolver.cc \ src/core/ext/filters/client_channel/resolver_registry.cc \ src/core/ext/filters/client_channel/retry_throttle.cc \ - src/core/ext/filters/client_channel/status_util.cc \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ @@ -18213,7 +18213,7 @@ endif STATUS_UTIL_TEST_SRC = \ - test/core/client_channel/status_util_test.cc \ + test/core/channel/status_util_test.cc \ STATUS_UTIL_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(STATUS_UTIL_TEST_SRC)))) ifeq ($(NO_SECURE),true) @@ -18244,7 +18244,7 @@ endif endif -$(OBJDIR)/$(CONFIG)/test/core/client_channel/status_util_test.o: $(LIBDIR)/$(CONFIG)/libgrpc.a +$(OBJDIR)/$(CONFIG)/test/core/channel/status_util_test.o: $(LIBDIR)/$(CONFIG)/libgrpc.a deps_status_util_test: $(STATUS_UTIL_TEST_OBJS:.o=.dep) diff --git a/build.yaml b/build.yaml index 85ea6e7993..d03aa62c27 100644 --- a/build.yaml +++ b/build.yaml @@ -160,6 +160,7 @@ filegroups: - src/core/lib/channel/handshaker.cc - src/core/lib/channel/handshaker_factory.cc - src/core/lib/channel/handshaker_registry.cc + - src/core/lib/channel/status_util.cc - src/core/lib/compression/compression.cc - src/core/lib/compression/compression_internal.cc - src/core/lib/compression/message_compress.cc @@ -319,6 +320,7 @@ filegroups: - src/core/lib/channel/handshaker.h - src/core/lib/channel/handshaker_factory.h - src/core/lib/channel/handshaker_registry.h + - src/core/lib/channel/status_util.h - src/core/lib/compression/algorithm_metadata.h - src/core/lib/compression/compression_internal.h - src/core/lib/compression/message_compress.h @@ -460,7 +462,6 @@ filegroups: - src/core/ext/filters/client_channel/resolver_factory.h - src/core/ext/filters/client_channel/resolver_registry.h - src/core/ext/filters/client_channel/retry_throttle.h - - src/core/ext/filters/client_channel/status_util.h - src/core/ext/filters/client_channel/subchannel.h - src/core/ext/filters/client_channel/subchannel_index.h - src/core/ext/filters/client_channel/uri_parser.h @@ -483,7 +484,6 @@ filegroups: - src/core/ext/filters/client_channel/resolver.cc - src/core/ext/filters/client_channel/resolver_registry.cc - src/core/ext/filters/client_channel/retry_throttle.cc - - src/core/ext/filters/client_channel/status_util.cc - src/core/ext/filters/client_channel/subchannel.cc - src/core/ext/filters/client_channel/subchannel_index.cc - src/core/ext/filters/client_channel/uri_parser.cc @@ -4909,7 +4909,7 @@ targets: build: test language: c++ src: - - test/core/client_channel/status_util_test.cc + - test/core/channel/status_util_test.cc deps: - grpc uses_polling: false diff --git a/config.m4 b/config.m4 index b46eb4078b..b53f5f7f35 100644 --- a/config.m4 +++ b/config.m4 @@ -90,6 +90,7 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ + src/core/lib/channel/status_util.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ @@ -294,7 +295,6 @@ if test "$PHP_GRPC" != "no"; then src/core/ext/filters/client_channel/resolver.cc \ src/core/ext/filters/client_channel/resolver_registry.cc \ src/core/ext/filters/client_channel/retry_throttle.cc \ - src/core/ext/filters/client_channel/status_util.cc \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ diff --git a/config.w32 b/config.w32 index ea90cb5424..eeb4895181 100644 --- a/config.w32 +++ b/config.w32 @@ -67,6 +67,7 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\channel\\handshaker.cc " + "src\\core\\lib\\channel\\handshaker_factory.cc " + "src\\core\\lib\\channel\\handshaker_registry.cc " + + "src\\core\\lib\\channel\\status_util.cc " + "src\\core\\lib\\compression\\compression.cc " + "src\\core\\lib\\compression\\compression_internal.cc " + "src\\core\\lib\\compression\\message_compress.cc " + @@ -271,7 +272,6 @@ if (PHP_GRPC != "no") { "src\\core\\ext\\filters\\client_channel\\resolver.cc " + "src\\core\\ext\\filters\\client_channel\\resolver_registry.cc " + "src\\core\\ext\\filters\\client_channel\\retry_throttle.cc " + - "src\\core\\ext\\filters\\client_channel\\status_util.cc " + "src\\core\\ext\\filters\\client_channel\\subchannel.cc " + "src\\core\\ext\\filters\\client_channel\\subchannel_index.cc " + "src\\core\\ext\\filters\\client_channel\\uri_parser.cc " + diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index ae45fe12f3..9df76bcd49 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -304,7 +304,6 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/resolver_factory.h', 'src/core/ext/filters/client_channel/resolver_registry.h', 'src/core/ext/filters/client_channel/retry_throttle.h', - 'src/core/ext/filters/client_channel/status_util.h', 'src/core/ext/filters/client_channel/subchannel.h', 'src/core/ext/filters/client_channel/subchannel_index.h', 'src/core/ext/filters/client_channel/uri_parser.h', @@ -323,6 +322,7 @@ Pod::Spec.new do |s| 'src/core/lib/channel/handshaker.h', 'src/core/lib/channel/handshaker_factory.h', 'src/core/lib/channel/handshaker_registry.h', + 'src/core/lib/channel/status_util.h', 'src/core/lib/compression/algorithm_metadata.h', 'src/core/lib/compression/compression_internal.h', 'src/core/lib/compression/message_compress.h', @@ -504,6 +504,7 @@ Pod::Spec.new do |s| 'src/core/lib/channel/handshaker.h', 'src/core/lib/channel/handshaker_factory.h', 'src/core/lib/channel/handshaker_registry.h', + 'src/core/lib/channel/status_util.h', 'src/core/lib/compression/algorithm_metadata.h', 'src/core/lib/compression/compression_internal.h', 'src/core/lib/compression/message_compress.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index cf26d7e73d..a7f27aeb10 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -315,7 +315,6 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/resolver_factory.h', 'src/core/ext/filters/client_channel/resolver_registry.h', 'src/core/ext/filters/client_channel/retry_throttle.h', - 'src/core/ext/filters/client_channel/status_util.h', 'src/core/ext/filters/client_channel/subchannel.h', 'src/core/ext/filters/client_channel/subchannel_index.h', 'src/core/ext/filters/client_channel/uri_parser.h', @@ -334,6 +333,7 @@ Pod::Spec.new do |s| 'src/core/lib/channel/handshaker.h', 'src/core/lib/channel/handshaker_factory.h', 'src/core/lib/channel/handshaker_registry.h', + 'src/core/lib/channel/status_util.h', 'src/core/lib/compression/algorithm_metadata.h', 'src/core/lib/compression/compression_internal.h', 'src/core/lib/compression/message_compress.h', @@ -479,6 +479,7 @@ Pod::Spec.new do |s| 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', 'src/core/lib/channel/handshaker_registry.cc', + 'src/core/lib/channel/status_util.cc', 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/compression_internal.cc', 'src/core/lib/compression/message_compress.cc', @@ -683,7 +684,6 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/resolver.cc', 'src/core/ext/filters/client_channel/resolver_registry.cc', 'src/core/ext/filters/client_channel/retry_throttle.cc', - 'src/core/ext/filters/client_channel/status_util.cc', 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', @@ -813,7 +813,6 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/resolver_factory.h', 'src/core/ext/filters/client_channel/resolver_registry.h', 'src/core/ext/filters/client_channel/retry_throttle.h', - 'src/core/ext/filters/client_channel/status_util.h', 'src/core/ext/filters/client_channel/subchannel.h', 'src/core/ext/filters/client_channel/subchannel_index.h', 'src/core/ext/filters/client_channel/uri_parser.h', @@ -832,6 +831,7 @@ Pod::Spec.new do |s| 'src/core/lib/channel/handshaker.h', 'src/core/lib/channel/handshaker_factory.h', 'src/core/lib/channel/handshaker_registry.h', + 'src/core/lib/channel/status_util.h', 'src/core/lib/compression/algorithm_metadata.h', 'src/core/lib/compression/compression_internal.h', 'src/core/lib/compression/message_compress.h', diff --git a/grpc.gemspec b/grpc.gemspec index a20d8efe14..2f4591a4ae 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -241,7 +241,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/client_channel/resolver_factory.h ) s.files += %w( src/core/ext/filters/client_channel/resolver_registry.h ) s.files += %w( src/core/ext/filters/client_channel/retry_throttle.h ) - s.files += %w( src/core/ext/filters/client_channel/status_util.h ) s.files += %w( src/core/ext/filters/client_channel/subchannel.h ) s.files += %w( src/core/ext/filters/client_channel/subchannel_index.h ) s.files += %w( src/core/ext/filters/client_channel/uri_parser.h ) @@ -260,6 +259,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/channel/handshaker.h ) s.files += %w( src/core/lib/channel/handshaker_factory.h ) s.files += %w( src/core/lib/channel/handshaker_registry.h ) + s.files += %w( src/core/lib/channel/status_util.h ) s.files += %w( src/core/lib/compression/algorithm_metadata.h ) s.files += %w( src/core/lib/compression/compression_internal.h ) s.files += %w( src/core/lib/compression/message_compress.h ) @@ -409,6 +409,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/channel/handshaker.cc ) s.files += %w( src/core/lib/channel/handshaker_factory.cc ) s.files += %w( src/core/lib/channel/handshaker_registry.cc ) + s.files += %w( src/core/lib/channel/status_util.cc ) s.files += %w( src/core/lib/compression/compression.cc ) s.files += %w( src/core/lib/compression/compression_internal.cc ) s.files += %w( src/core/lib/compression/message_compress.cc ) @@ -613,7 +614,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/client_channel/resolver.cc ) s.files += %w( src/core/ext/filters/client_channel/resolver_registry.cc ) s.files += %w( src/core/ext/filters/client_channel/retry_throttle.cc ) - s.files += %w( src/core/ext/filters/client_channel/status_util.cc ) s.files += %w( src/core/ext/filters/client_channel/subchannel.cc ) s.files += %w( src/core/ext/filters/client_channel/subchannel_index.cc ) s.files += %w( src/core/ext/filters/client_channel/uri_parser.cc ) diff --git a/grpc.gyp b/grpc.gyp index 0b7b3b9daf..092487d1a5 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -231,6 +231,7 @@ 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', 'src/core/lib/channel/handshaker_registry.cc', + 'src/core/lib/channel/status_util.cc', 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/compression_internal.cc', 'src/core/lib/compression/message_compress.cc', @@ -435,7 +436,6 @@ 'src/core/ext/filters/client_channel/resolver.cc', 'src/core/ext/filters/client_channel/resolver_registry.cc', 'src/core/ext/filters/client_channel/retry_throttle.cc', - 'src/core/ext/filters/client_channel/status_util.cc', 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', @@ -533,6 +533,7 @@ 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', 'src/core/lib/channel/handshaker_registry.cc', + 'src/core/lib/channel/status_util.cc', 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/compression_internal.cc', 'src/core/lib/compression/message_compress.cc', @@ -677,7 +678,6 @@ 'src/core/ext/filters/client_channel/resolver.cc', 'src/core/ext/filters/client_channel/resolver_registry.cc', 'src/core/ext/filters/client_channel/retry_throttle.cc', - 'src/core/ext/filters/client_channel/status_util.cc', 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', @@ -753,6 +753,7 @@ 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', 'src/core/lib/channel/handshaker_registry.cc', + 'src/core/lib/channel/status_util.cc', 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/compression_internal.cc', 'src/core/lib/compression/message_compress.cc', @@ -897,7 +898,6 @@ 'src/core/ext/filters/client_channel/resolver.cc', 'src/core/ext/filters/client_channel/resolver_registry.cc', 'src/core/ext/filters/client_channel/retry_throttle.cc', - 'src/core/ext/filters/client_channel/status_util.cc', 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', @@ -951,6 +951,7 @@ 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', 'src/core/lib/channel/handshaker_registry.cc', + 'src/core/lib/channel/status_util.cc', 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/compression_internal.cc', 'src/core/lib/compression/message_compress.cc', @@ -1128,7 +1129,6 @@ 'src/core/ext/filters/client_channel/resolver.cc', 'src/core/ext/filters/client_channel/resolver_registry.cc', 'src/core/ext/filters/client_channel/retry_throttle.cc', - 'src/core/ext/filters/client_channel/status_util.cc', 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', diff --git a/package.xml b/package.xml index a2b59e7339..5e8356cb32 100644 --- a/package.xml +++ b/package.xml @@ -248,7 +248,6 @@ - @@ -267,6 +266,7 @@ + @@ -416,6 +416,7 @@ + @@ -620,7 +621,6 @@ - diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index 90b93fbe23..09cc06e169 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -38,12 +38,12 @@ #include "src/core/ext/filters/client_channel/proxy_mapper_registry.h" #include "src/core/ext/filters/client_channel/resolver_registry.h" #include "src/core/ext/filters/client_channel/retry_throttle.h" -#include "src/core/ext/filters/client_channel/status_util.h" #include "src/core/ext/filters/client_channel/subchannel.h" #include "src/core/ext/filters/deadline/deadline_filter.h" #include "src/core/lib/backoff/backoff.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/connected_channel.h" +#include "src/core/lib/channel/status_util.h" #include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/inlined_vector.h" #include "src/core/lib/gprpp/manual_constructor.h" diff --git a/src/core/ext/filters/client_channel/method_params.cc b/src/core/ext/filters/client_channel/method_params.cc index 374b87e170..1f116bb67d 100644 --- a/src/core/ext/filters/client_channel/method_params.cc +++ b/src/core/ext/filters/client_channel/method_params.cc @@ -26,7 +26,7 @@ #include #include "src/core/ext/filters/client_channel/method_params.h" -#include "src/core/ext/filters/client_channel/status_util.h" +#include "src/core/lib/channel/status_util.h" #include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/memory.h" diff --git a/src/core/ext/filters/client_channel/method_params.h b/src/core/ext/filters/client_channel/method_params.h index 48ece29867..099924edf3 100644 --- a/src/core/ext/filters/client_channel/method_params.h +++ b/src/core/ext/filters/client_channel/method_params.h @@ -21,7 +21,7 @@ #include -#include "src/core/ext/filters/client_channel/status_util.h" +#include "src/core/lib/channel/status_util.h" #include "src/core/lib/gprpp/ref_counted.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/iomgr/exec_ctx.h" // for grpc_millis diff --git a/src/core/ext/filters/client_channel/status_util.cc b/src/core/ext/filters/client_channel/status_util.cc deleted file mode 100644 index 11f732ab44..0000000000 --- a/src/core/ext/filters/client_channel/status_util.cc +++ /dev/null @@ -1,100 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/ext/filters/client_channel/status_util.h" - -#include "src/core/lib/gpr/useful.h" - -typedef struct { - const char* str; - grpc_status_code status; -} status_string_entry; - -static const status_string_entry g_status_string_entries[] = { - {"OK", GRPC_STATUS_OK}, - {"CANCELLED", GRPC_STATUS_CANCELLED}, - {"UNKNOWN", GRPC_STATUS_UNKNOWN}, - {"INVALID_ARGUMENT", GRPC_STATUS_INVALID_ARGUMENT}, - {"DEADLINE_EXCEEDED", GRPC_STATUS_DEADLINE_EXCEEDED}, - {"NOT_FOUND", GRPC_STATUS_NOT_FOUND}, - {"ALREADY_EXISTS", GRPC_STATUS_ALREADY_EXISTS}, - {"PERMISSION_DENIED", GRPC_STATUS_PERMISSION_DENIED}, - {"UNAUTHENTICATED", GRPC_STATUS_UNAUTHENTICATED}, - {"RESOURCE_EXHAUSTED", GRPC_STATUS_RESOURCE_EXHAUSTED}, - {"FAILED_PRECONDITION", GRPC_STATUS_FAILED_PRECONDITION}, - {"ABORTED", GRPC_STATUS_ABORTED}, - {"OUT_OF_RANGE", GRPC_STATUS_OUT_OF_RANGE}, - {"UNIMPLEMENTED", GRPC_STATUS_UNIMPLEMENTED}, - {"INTERNAL", GRPC_STATUS_INTERNAL}, - {"UNAVAILABLE", GRPC_STATUS_UNAVAILABLE}, - {"DATA_LOSS", GRPC_STATUS_DATA_LOSS}, -}; - -bool grpc_status_code_from_string(const char* status_str, - grpc_status_code* status) { - for (size_t i = 0; i < GPR_ARRAY_SIZE(g_status_string_entries); ++i) { - if (strcmp(status_str, g_status_string_entries[i].str) == 0) { - *status = g_status_string_entries[i].status; - return true; - } - } - return false; -} - -const char* grpc_status_code_to_string(grpc_status_code status) { - switch (status) { - case GRPC_STATUS_OK: - return "OK"; - case GRPC_STATUS_CANCELLED: - return "CANCELLED"; - case GRPC_STATUS_UNKNOWN: - return "UNKNOWN"; - case GRPC_STATUS_INVALID_ARGUMENT: - return "INVALID_ARGUMENT"; - case GRPC_STATUS_DEADLINE_EXCEEDED: - return "DEADLINE_EXCEEDED"; - case GRPC_STATUS_NOT_FOUND: - return "NOT_FOUND"; - case GRPC_STATUS_ALREADY_EXISTS: - return "ALREADY_EXISTS"; - case GRPC_STATUS_PERMISSION_DENIED: - return "PERMISSION_DENIED"; - case GRPC_STATUS_UNAUTHENTICATED: - return "UNAUTHENTICATED"; - case GRPC_STATUS_RESOURCE_EXHAUSTED: - return "RESOURCE_EXHAUSTED"; - case GRPC_STATUS_FAILED_PRECONDITION: - return "FAILED_PRECONDITION"; - case GRPC_STATUS_ABORTED: - return "ABORTED"; - case GRPC_STATUS_OUT_OF_RANGE: - return "OUT_OF_RANGE"; - case GRPC_STATUS_UNIMPLEMENTED: - return "UNIMPLEMENTED"; - case GRPC_STATUS_INTERNAL: - return "INTERNAL"; - case GRPC_STATUS_UNAVAILABLE: - return "UNAVAILABLE"; - case GRPC_STATUS_DATA_LOSS: - return "DATA_LOSS"; - default: - return "UNKNOWN"; - } -} diff --git a/src/core/ext/filters/client_channel/status_util.h b/src/core/ext/filters/client_channel/status_util.h deleted file mode 100644 index e018709730..0000000000 --- a/src/core/ext/filters/client_channel/status_util.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_STATUS_UTIL_H -#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_STATUS_UTIL_H - -#include - -#include - -#include -#include - -/// If \a status_str is a valid status string, sets \a status to the -/// corresponding status value and returns true. -bool grpc_status_code_from_string(const char* status_str, - grpc_status_code* status); - -/// Returns the string form of \a status, or "UNKNOWN" if invalid. -const char* grpc_status_code_to_string(grpc_status_code status); - -namespace grpc_core { -namespace internal { - -/// A set of grpc_status_code values. -class StatusCodeSet { - public: - bool Empty() const { return status_code_mask_ == 0; } - - void Add(grpc_status_code status) { status_code_mask_ |= (1 << status); } - - bool Contains(grpc_status_code status) const { - return status_code_mask_ & (1 << status); - } - - private: - int status_code_mask_ = 0; // A bitfield of status codes in the set. -}; - -} // namespace internal -} // namespace grpc_core - -#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_STATUS_UTIL_H */ diff --git a/src/core/lib/channel/channel_trace.cc b/src/core/lib/channel/channel_trace.cc index 226ab0292d..07c2c1fd97 100644 --- a/src/core/lib/channel/channel_trace.cc +++ b/src/core/lib/channel/channel_trace.cc @@ -27,8 +27,8 @@ #include #include -#include "src/core/ext/filters/client_channel/status_util.h" #include "src/core/lib/channel/channel_trace_registry.h" +#include "src/core/lib/channel/status_util.h" #include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/memory.h" diff --git a/src/core/lib/channel/status_util.cc b/src/core/lib/channel/status_util.cc new file mode 100644 index 0000000000..563db40846 --- /dev/null +++ b/src/core/lib/channel/status_util.cc @@ -0,0 +1,100 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/lib/channel/status_util.h" + +#include "src/core/lib/gpr/useful.h" + +typedef struct { + const char* str; + grpc_status_code status; +} status_string_entry; + +static const status_string_entry g_status_string_entries[] = { + {"OK", GRPC_STATUS_OK}, + {"CANCELLED", GRPC_STATUS_CANCELLED}, + {"UNKNOWN", GRPC_STATUS_UNKNOWN}, + {"INVALID_ARGUMENT", GRPC_STATUS_INVALID_ARGUMENT}, + {"DEADLINE_EXCEEDED", GRPC_STATUS_DEADLINE_EXCEEDED}, + {"NOT_FOUND", GRPC_STATUS_NOT_FOUND}, + {"ALREADY_EXISTS", GRPC_STATUS_ALREADY_EXISTS}, + {"PERMISSION_DENIED", GRPC_STATUS_PERMISSION_DENIED}, + {"UNAUTHENTICATED", GRPC_STATUS_UNAUTHENTICATED}, + {"RESOURCE_EXHAUSTED", GRPC_STATUS_RESOURCE_EXHAUSTED}, + {"FAILED_PRECONDITION", GRPC_STATUS_FAILED_PRECONDITION}, + {"ABORTED", GRPC_STATUS_ABORTED}, + {"OUT_OF_RANGE", GRPC_STATUS_OUT_OF_RANGE}, + {"UNIMPLEMENTED", GRPC_STATUS_UNIMPLEMENTED}, + {"INTERNAL", GRPC_STATUS_INTERNAL}, + {"UNAVAILABLE", GRPC_STATUS_UNAVAILABLE}, + {"DATA_LOSS", GRPC_STATUS_DATA_LOSS}, +}; + +bool grpc_status_code_from_string(const char* status_str, + grpc_status_code* status) { + for (size_t i = 0; i < GPR_ARRAY_SIZE(g_status_string_entries); ++i) { + if (strcmp(status_str, g_status_string_entries[i].str) == 0) { + *status = g_status_string_entries[i].status; + return true; + } + } + return false; +} + +const char* grpc_status_code_to_string(grpc_status_code status) { + switch (status) { + case GRPC_STATUS_OK: + return "OK"; + case GRPC_STATUS_CANCELLED: + return "CANCELLED"; + case GRPC_STATUS_UNKNOWN: + return "UNKNOWN"; + case GRPC_STATUS_INVALID_ARGUMENT: + return "INVALID_ARGUMENT"; + case GRPC_STATUS_DEADLINE_EXCEEDED: + return "DEADLINE_EXCEEDED"; + case GRPC_STATUS_NOT_FOUND: + return "NOT_FOUND"; + case GRPC_STATUS_ALREADY_EXISTS: + return "ALREADY_EXISTS"; + case GRPC_STATUS_PERMISSION_DENIED: + return "PERMISSION_DENIED"; + case GRPC_STATUS_UNAUTHENTICATED: + return "UNAUTHENTICATED"; + case GRPC_STATUS_RESOURCE_EXHAUSTED: + return "RESOURCE_EXHAUSTED"; + case GRPC_STATUS_FAILED_PRECONDITION: + return "FAILED_PRECONDITION"; + case GRPC_STATUS_ABORTED: + return "ABORTED"; + case GRPC_STATUS_OUT_OF_RANGE: + return "OUT_OF_RANGE"; + case GRPC_STATUS_UNIMPLEMENTED: + return "UNIMPLEMENTED"; + case GRPC_STATUS_INTERNAL: + return "INTERNAL"; + case GRPC_STATUS_UNAVAILABLE: + return "UNAVAILABLE"; + case GRPC_STATUS_DATA_LOSS: + return "DATA_LOSS"; + default: + return "UNKNOWN"; + } +} diff --git a/src/core/lib/channel/status_util.h b/src/core/lib/channel/status_util.h new file mode 100644 index 0000000000..2c552fa20a --- /dev/null +++ b/src/core/lib/channel/status_util.h @@ -0,0 +1,58 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_LIB_CHANNEL_STATUS_UTILS_H +#define GRPC_LIB_CHANNEL_STATUS_UTILS_H + +#include + +#include + +#include +#include + +/// If \a status_str is a valid status string, sets \a status to the +/// corresponding status value and returns true. +bool grpc_status_code_from_string(const char* status_str, + grpc_status_code* status); + +/// Returns the string form of \a status, or "UNKNOWN" if invalid. +const char* grpc_status_code_to_string(grpc_status_code status); + +namespace grpc_core { +namespace internal { + +/// A set of grpc_status_code values. +class StatusCodeSet { + public: + bool Empty() const { return status_code_mask_ == 0; } + + void Add(grpc_status_code status) { status_code_mask_ |= (1 << status); } + + bool Contains(grpc_status_code status) const { + return status_code_mask_ & (1 << status); + } + + private: + int status_code_mask_ = 0; // A bitfield of status codes in the set. +}; + +} // namespace internal +} // namespace grpc_core + +#endif /* GRPC_LIB_CHANNEL_STATUS_UTILS_H */ diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index bc9b5a3c73..49016bad55 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -66,6 +66,7 @@ CORE_SOURCE_FILES = [ 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', 'src/core/lib/channel/handshaker_registry.cc', + 'src/core/lib/channel/status_util.cc', 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/compression_internal.cc', 'src/core/lib/compression/message_compress.cc', @@ -270,7 +271,6 @@ CORE_SOURCE_FILES = [ 'src/core/ext/filters/client_channel/resolver.cc', 'src/core/ext/filters/client_channel/resolver_registry.cc', 'src/core/ext/filters/client_channel/retry_throttle.cc', - 'src/core/ext/filters/client_channel/status_util.cc', 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', diff --git a/test/core/channel/BUILD b/test/core/channel/BUILD index 633c424eae..e1388c6e1a 100644 --- a/test/core/channel/BUILD +++ b/test/core/channel/BUILD @@ -69,9 +69,6 @@ grpc_cc_test( grpc_cc_test( name = "channel_trace_test", srcs = ["channel_trace_test.cc"], - external_deps = [ - "gtest", - ], language = "C++", deps = [ "//:gpr", @@ -80,4 +77,19 @@ grpc_cc_test( "//test/core/util:gpr_test_util", "//test/core/util:grpc_test_util", ], + external_deps = [ + "gtest", + ], +) + +grpc_cc_test( + name = "status_util_test", + srcs = ["status_util_test.cc"], + language = "C++", + deps = [ + "//:grpc", + ], + external_deps = [ + "gtest", + ], ) diff --git a/test/core/channel/status_util_test.cc b/test/core/channel/status_util_test.cc new file mode 100644 index 0000000000..1d64bf1995 --- /dev/null +++ b/test/core/channel/status_util_test.cc @@ -0,0 +1,49 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "src/core/lib/channel/status_util.h" + +#include + +namespace grpc_core { +namespace internal { +namespace { + +TEST(StatusCodeSet, Basic) { + StatusCodeSet set; + EXPECT_TRUE(set.Empty()); + EXPECT_FALSE(set.Contains(GRPC_STATUS_OK)); + EXPECT_FALSE(set.Contains(GRPC_STATUS_UNAVAILABLE)); + set.Add(GRPC_STATUS_OK); + EXPECT_FALSE(set.Empty()); + EXPECT_TRUE(set.Contains(GRPC_STATUS_OK)); + EXPECT_FALSE(set.Contains(GRPC_STATUS_UNAVAILABLE)); + set.Add(GRPC_STATUS_UNAVAILABLE); + EXPECT_FALSE(set.Empty()); + EXPECT_TRUE(set.Contains(GRPC_STATUS_OK)); + EXPECT_TRUE(set.Contains(GRPC_STATUS_UNAVAILABLE)); +} + +} // namespace +} // namespace internal +} // namespace grpc_core + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test/core/client_channel/BUILD b/test/core/client_channel/BUILD index d430b722df..5148dc5f74 100644 --- a/test/core/client_channel/BUILD +++ b/test/core/client_channel/BUILD @@ -53,15 +53,3 @@ grpc_cc_test( "//test/core/util:grpc_test_util", ], ) - -grpc_cc_test( - name = "status_util_test", - srcs = ["status_util_test.cc"], - language = "C++", - deps = [ - "//:grpc", - ], - external_deps = [ - "gtest", - ], -) diff --git a/test/core/client_channel/status_util_test.cc b/test/core/client_channel/status_util_test.cc deleted file mode 100644 index f944990ad2..0000000000 --- a/test/core/client_channel/status_util_test.cc +++ /dev/null @@ -1,49 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "src/core/ext/filters/client_channel/status_util.h" - -#include - -namespace grpc_core { -namespace internal { -namespace { - -TEST(StatusCodeSet, Basic) { - StatusCodeSet set; - EXPECT_TRUE(set.Empty()); - EXPECT_FALSE(set.Contains(GRPC_STATUS_OK)); - EXPECT_FALSE(set.Contains(GRPC_STATUS_UNAVAILABLE)); - set.Add(GRPC_STATUS_OK); - EXPECT_FALSE(set.Empty()); - EXPECT_TRUE(set.Contains(GRPC_STATUS_OK)); - EXPECT_FALSE(set.Contains(GRPC_STATUS_UNAVAILABLE)); - set.Add(GRPC_STATUS_UNAVAILABLE); - EXPECT_FALSE(set.Empty()); - EXPECT_TRUE(set.Contains(GRPC_STATUS_OK)); - EXPECT_TRUE(set.Contains(GRPC_STATUS_UNAVAILABLE)); -} - -} // namespace -} // namespace internal -} // namespace grpc_core - -int main(int argc, char** argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index cae5cc5fa1..30ee95d785 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -1014,6 +1014,7 @@ src/core/lib/channel/context.h \ src/core/lib/channel/handshaker.h \ src/core/lib/channel/handshaker_factory.h \ src/core/lib/channel/handshaker_registry.h \ +src/core/lib/channel/status_util.h \ src/core/lib/compression/algorithm_metadata.h \ src/core/lib/compression/compression_internal.h \ src/core/lib/compression/message_compress.h \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 78805a0ad1..326ced6d70 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -929,8 +929,6 @@ src/core/ext/filters/client_channel/resolver_registry.cc \ src/core/ext/filters/client_channel/resolver_registry.h \ src/core/ext/filters/client_channel/retry_throttle.cc \ src/core/ext/filters/client_channel/retry_throttle.h \ -src/core/ext/filters/client_channel/status_util.cc \ -src/core/ext/filters/client_channel/status_util.h \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel.h \ src/core/ext/filters/client_channel/subchannel_index.cc \ @@ -1047,6 +1045,8 @@ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_factory.h \ src/core/lib/channel/handshaker_registry.cc \ src/core/lib/channel/handshaker_registry.h \ +src/core/lib/channel/status_util.cc \ +src/core/lib/channel/status_util.h \ src/core/lib/compression/algorithm_metadata.h \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 90ef05546f..706ec69845 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -4265,7 +4265,7 @@ "language": "c++", "name": "status_util_test", "src": [ - "test/core/client_channel/status_util_test.cc" + "test/core/channel/status_util_test.cc" ], "third_party": false, "type": "target" @@ -8581,6 +8581,7 @@ "src/core/lib/channel/handshaker.cc", "src/core/lib/channel/handshaker_factory.cc", "src/core/lib/channel/handshaker_registry.cc", + "src/core/lib/channel/status_util.cc", "src/core/lib/compression/compression.cc", "src/core/lib/compression/compression_internal.cc", "src/core/lib/compression/message_compress.cc", @@ -8741,6 +8742,7 @@ "src/core/lib/channel/handshaker.h", "src/core/lib/channel/handshaker_factory.h", "src/core/lib/channel/handshaker_registry.h", + "src/core/lib/channel/status_util.h", "src/core/lib/compression/algorithm_metadata.h", "src/core/lib/compression/compression_internal.h", "src/core/lib/compression/message_compress.h", @@ -8887,6 +8889,7 @@ "src/core/lib/channel/handshaker.h", "src/core/lib/channel/handshaker_factory.h", "src/core/lib/channel/handshaker_registry.h", + "src/core/lib/channel/status_util.h", "src/core/lib/compression/algorithm_metadata.h", "src/core/lib/compression/compression_internal.h", "src/core/lib/compression/message_compress.h", @@ -9032,7 +9035,6 @@ "src/core/ext/filters/client_channel/resolver_factory.h", "src/core/ext/filters/client_channel/resolver_registry.h", "src/core/ext/filters/client_channel/retry_throttle.h", - "src/core/ext/filters/client_channel/status_util.h", "src/core/ext/filters/client_channel/subchannel.h", "src/core/ext/filters/client_channel/subchannel_index.h", "src/core/ext/filters/client_channel/uri_parser.h" @@ -9076,8 +9078,6 @@ "src/core/ext/filters/client_channel/resolver_registry.h", "src/core/ext/filters/client_channel/retry_throttle.cc", "src/core/ext/filters/client_channel/retry_throttle.h", - "src/core/ext/filters/client_channel/status_util.cc", - "src/core/ext/filters/client_channel/status_util.h", "src/core/ext/filters/client_channel/subchannel.cc", "src/core/ext/filters/client_channel/subchannel.h", "src/core/ext/filters/client_channel/subchannel_index.cc", -- cgit v1.2.3 From ae277dd000254c2df9f6cc51dbb70dff1ea55aa2 Mon Sep 17 00:00:00 2001 From: Sree Kuchibhotla Date: Wed, 7 Mar 2018 14:35:36 -0800 Subject: Revert "Add ALTS C stack to gRPC core" --- BUILD | 112 -- CMakeLists.txt | 1081 ++-------- Makefile | 1327 ++---------- bazel/grpc_build_system.bzl | 9 +- build.yaml | 247 --- config.m4 | 62 +- config.w32 | 63 +- gRPC-C++.podspec | 41 +- gRPC-Core.podspec | 144 +- grpc.gemspec | 106 +- grpc.gyp | 74 +- package.xml | 106 +- setup.py | 3 +- .../security/credentials/alts/alts_credentials.cc | 119 -- .../security/credentials/alts/alts_credentials.h | 102 - .../credentials/alts/check_gcp_environment.cc | 72 - .../credentials/alts/check_gcp_environment.h | 57 - .../alts/check_gcp_environment_linux.cc | 67 - .../alts/check_gcp_environment_no_op.cc | 33 - .../alts/check_gcp_environment_windows.cc | 114 -- .../alts/grpc_alts_credentials_client_options.cc | 126 -- .../alts/grpc_alts_credentials_options.cc | 46 - .../alts/grpc_alts_credentials_options.h | 112 -- .../alts/grpc_alts_credentials_server_options.cc | 58 - .../security_connector/alts_security_connector.cc | 287 --- .../security_connector/alts_security_connector.h | 69 - src/core/plugin_registry/grpc_plugin_registry.cc | 8 +- src/core/tsi/alts/crypt/aes_gcm.cc | 687 ------- src/core/tsi/alts/crypt/gsec.cc | 189 -- src/core/tsi/alts/crypt/gsec.h | 454 ----- src/core/tsi/alts/frame_protector/alts_counter.cc | 118 -- src/core/tsi/alts/frame_protector/alts_counter.h | 98 - src/core/tsi/alts/frame_protector/alts_crypter.cc | 66 - src/core/tsi/alts/frame_protector/alts_crypter.h | 255 --- .../alts/frame_protector/alts_frame_protector.cc | 407 ---- .../alts/frame_protector/alts_frame_protector.h | 55 - .../alts_record_protocol_crypter_common.cc | 114 -- .../alts_record_protocol_crypter_common.h | 114 -- .../alts_seal_privacy_integrity_crypter.cc | 105 - .../alts_unseal_privacy_integrity_crypter.cc | 103 - src/core/tsi/alts/frame_protector/frame_handler.cc | 218 -- src/core/tsi/alts/frame_protector/frame_handler.h | 236 --- .../tsi/alts/handshaker/alts_handshaker_client.cc | 316 --- .../tsi/alts/handshaker/alts_handshaker_client.h | 137 -- .../alts/handshaker/alts_handshaker_service_api.cc | 520 ----- .../alts/handshaker/alts_handshaker_service_api.h | 323 --- .../handshaker/alts_handshaker_service_api_util.cc | 143 -- .../handshaker/alts_handshaker_service_api_util.h | 149 -- src/core/tsi/alts/handshaker/alts_tsi_event.cc | 73 - src/core/tsi/alts/handshaker/alts_tsi_event.h | 93 - .../tsi/alts/handshaker/alts_tsi_handshaker.cc | 483 ----- src/core/tsi/alts/handshaker/alts_tsi_handshaker.h | 83 - .../alts/handshaker/alts_tsi_handshaker_private.h | 52 - src/core/tsi/alts/handshaker/alts_tsi_utils.cc | 58 - src/core/tsi/alts/handshaker/alts_tsi_utils.h | 52 - src/core/tsi/alts/handshaker/altscontext.pb.c | 48 - src/core/tsi/alts/handshaker/altscontext.pb.h | 64 - src/core/tsi/alts/handshaker/handshaker.pb.c | 123 -- src/core/tsi/alts/handshaker/handshaker.pb.h | 255 --- .../tsi/alts/handshaker/proto/altscontext.proto | 41 - .../tsi/alts/handshaker/proto/handshaker.options | 2 - .../tsi/alts/handshaker/proto/handshaker.proto | 220 -- .../proto/transport_security_common.proto | 40 - .../alts/handshaker/transport_security_common.pb.c | 50 - .../alts/handshaker/transport_security_common.pb.h | 78 - .../handshaker/transport_security_common_api.cc | 196 -- .../handshaker/transport_security_common_api.h | 163 -- .../alts_grpc_integrity_only_record_protocol.cc | 180 -- .../alts_grpc_integrity_only_record_protocol.h | 52 - .../alts_grpc_privacy_integrity_record_protocol.cc | 144 -- .../alts_grpc_privacy_integrity_record_protocol.h | 49 - .../alts_grpc_record_protocol.h | 91 - .../alts_grpc_record_protocol_common.cc | 173 -- .../alts_grpc_record_protocol_common.h | 100 - .../alts_iovec_record_protocol.cc | 476 ----- .../alts_iovec_record_protocol.h | 199 -- .../alts_zero_copy_grpc_protector.cc | 295 --- .../alts_zero_copy_grpc_protector.h | 52 - src/python/grpcio/grpc_core_dependencies.py | 57 +- templates/CMakeLists.txt.template | 2 - templates/Makefile.template | 2 - templates/gRPC-Core.podspec.template | 2 +- templates/grpc.gyp.template | 6 +- test/core/security/BUILD | 36 - test/core/security/alts_security_connector_test.cc | 166 -- .../security/check_gcp_environment_linux_test.cc | 83 - .../security/check_gcp_environment_windows_test.cc | 71 - .../security/grpc_alts_credentials_options_test.cc | 118 -- test/core/tsi/BUILD | 2 +- test/core/tsi/alts/crypt/BUILD | 38 - test/core/tsi/alts/crypt/aes_gcm_test.cc | 2105 -------------------- test/core/tsi/alts/crypt/gsec_test_util.cc | 87 - test/core/tsi/alts/crypt/gsec_test_util.h | 91 - test/core/tsi/alts/frame_protector/BUILD | 60 - .../tsi/alts/frame_protector/alts_counter_test.cc | 180 -- .../tsi/alts/frame_protector/alts_crypter_test.cc | 493 ----- .../frame_protector/alts_frame_protector_test.cc | 394 ---- .../tsi/alts/frame_protector/frame_handler_test.cc | 244 --- test/core/tsi/alts/handshaker/BUILD | 78 - .../alts/handshaker/alts_handshaker_client_test.cc | 412 ---- .../handshaker/alts_handshaker_service_api_test.cc | 149 -- .../alts_handshaker_service_api_test_lib.cc | 642 ------ .../alts_handshaker_service_api_test_lib.h | 143 -- .../alts/handshaker/alts_tsi_handshaker_test.cc | 682 ------- .../tsi/alts/handshaker/alts_tsi_utils_test.cc | 73 - .../transport_security_common_api_test.cc | 196 -- test/core/tsi/alts/zero_copy_frame_protector/BUILD | 49 - .../alts_grpc_record_protocol_test.cc | 449 ----- .../alts_iovec_record_protocol_test.cc | 928 --------- .../alts_zero_copy_grpc_protector_test.cc | 289 --- test/core/tsi/fake_transport_security_test.cc | 2 +- test/core/tsi/ssl_transport_security_test.cc | 2 +- test/core/tsi/transport_security_test_lib.cc | 224 +-- test/core/tsi/transport_security_test_lib.h | 89 +- third_party/nanopb/pb.h | 2 +- tools/codegen/core/gen_nano_proto.sh | 9 +- tools/distrib/check_copyright.py | 6 - tools/distrib/check_include_guards.py | 3 - tools/distrib/check_nanopb_output.sh | 27 - tools/doxygen/Doxyfile.core.internal | 60 - tools/run_tests/generated/sources_and_headers.json | 429 ---- tools/run_tests/generated/tests.json | 408 ---- 122 files changed, 596 insertions(+), 22429 deletions(-) delete mode 100644 src/core/lib/security/credentials/alts/alts_credentials.cc delete mode 100644 src/core/lib/security/credentials/alts/alts_credentials.h delete mode 100644 src/core/lib/security/credentials/alts/check_gcp_environment.cc delete mode 100644 src/core/lib/security/credentials/alts/check_gcp_environment.h delete mode 100644 src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc delete mode 100644 src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc delete mode 100644 src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc delete mode 100644 src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc delete mode 100644 src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc delete mode 100644 src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h delete mode 100644 src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc delete mode 100644 src/core/lib/security/security_connector/alts_security_connector.cc delete mode 100644 src/core/lib/security/security_connector/alts_security_connector.h delete mode 100644 src/core/tsi/alts/crypt/aes_gcm.cc delete mode 100644 src/core/tsi/alts/crypt/gsec.cc delete mode 100644 src/core/tsi/alts/crypt/gsec.h delete mode 100644 src/core/tsi/alts/frame_protector/alts_counter.cc delete mode 100644 src/core/tsi/alts/frame_protector/alts_counter.h delete mode 100644 src/core/tsi/alts/frame_protector/alts_crypter.cc delete mode 100644 src/core/tsi/alts/frame_protector/alts_crypter.h delete mode 100644 src/core/tsi/alts/frame_protector/alts_frame_protector.cc delete mode 100644 src/core/tsi/alts/frame_protector/alts_frame_protector.h delete mode 100644 src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc delete mode 100644 src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h delete mode 100644 src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc delete mode 100644 src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc delete mode 100644 src/core/tsi/alts/frame_protector/frame_handler.cc delete mode 100644 src/core/tsi/alts/frame_protector/frame_handler.h delete mode 100644 src/core/tsi/alts/handshaker/alts_handshaker_client.cc delete mode 100644 src/core/tsi/alts/handshaker/alts_handshaker_client.h delete mode 100644 src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc delete mode 100644 src/core/tsi/alts/handshaker/alts_handshaker_service_api.h delete mode 100644 src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc delete mode 100644 src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h delete mode 100644 src/core/tsi/alts/handshaker/alts_tsi_event.cc delete mode 100644 src/core/tsi/alts/handshaker/alts_tsi_event.h delete mode 100644 src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc delete mode 100644 src/core/tsi/alts/handshaker/alts_tsi_handshaker.h delete mode 100644 src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h delete mode 100644 src/core/tsi/alts/handshaker/alts_tsi_utils.cc delete mode 100644 src/core/tsi/alts/handshaker/alts_tsi_utils.h delete mode 100644 src/core/tsi/alts/handshaker/altscontext.pb.c delete mode 100644 src/core/tsi/alts/handshaker/altscontext.pb.h delete mode 100644 src/core/tsi/alts/handshaker/handshaker.pb.c delete mode 100644 src/core/tsi/alts/handshaker/handshaker.pb.h delete mode 100644 src/core/tsi/alts/handshaker/proto/altscontext.proto delete mode 100644 src/core/tsi/alts/handshaker/proto/handshaker.options delete mode 100644 src/core/tsi/alts/handshaker/proto/handshaker.proto delete mode 100644 src/core/tsi/alts/handshaker/proto/transport_security_common.proto delete mode 100644 src/core/tsi/alts/handshaker/transport_security_common.pb.c delete mode 100644 src/core/tsi/alts/handshaker/transport_security_common.pb.h delete mode 100644 src/core/tsi/alts/handshaker/transport_security_common_api.cc delete mode 100644 src/core/tsi/alts/handshaker/transport_security_common_api.h delete mode 100644 src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc delete mode 100644 src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h delete mode 100644 src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc delete mode 100644 src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h delete mode 100644 src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h delete mode 100644 src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc delete mode 100644 src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h delete mode 100644 src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc delete mode 100644 src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h delete mode 100644 src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc delete mode 100644 src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h delete mode 100644 test/core/security/alts_security_connector_test.cc delete mode 100644 test/core/security/check_gcp_environment_linux_test.cc delete mode 100644 test/core/security/check_gcp_environment_windows_test.cc delete mode 100644 test/core/security/grpc_alts_credentials_options_test.cc delete mode 100644 test/core/tsi/alts/crypt/BUILD delete mode 100644 test/core/tsi/alts/crypt/aes_gcm_test.cc delete mode 100644 test/core/tsi/alts/crypt/gsec_test_util.cc delete mode 100644 test/core/tsi/alts/crypt/gsec_test_util.h delete mode 100644 test/core/tsi/alts/frame_protector/BUILD delete mode 100644 test/core/tsi/alts/frame_protector/alts_counter_test.cc delete mode 100644 test/core/tsi/alts/frame_protector/alts_crypter_test.cc delete mode 100644 test/core/tsi/alts/frame_protector/alts_frame_protector_test.cc delete mode 100644 test/core/tsi/alts/frame_protector/frame_handler_test.cc delete mode 100644 test/core/tsi/alts/handshaker/BUILD delete mode 100644 test/core/tsi/alts/handshaker/alts_handshaker_client_test.cc delete mode 100644 test/core/tsi/alts/handshaker/alts_handshaker_service_api_test.cc delete mode 100644 test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc delete mode 100644 test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h delete mode 100644 test/core/tsi/alts/handshaker/alts_tsi_handshaker_test.cc delete mode 100644 test/core/tsi/alts/handshaker/alts_tsi_utils_test.cc delete mode 100644 test/core/tsi/alts/handshaker/transport_security_common_api_test.cc delete mode 100644 test/core/tsi/alts/zero_copy_frame_protector/BUILD delete mode 100644 test/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_test.cc delete mode 100644 test/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol_test.cc delete mode 100644 test/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector_test.cc (limited to 'gRPC-C++.podspec') diff --git a/BUILD b/BUILD index 9c99f95fcd..4fe3dc660e 100644 --- a/BUILD +++ b/BUILD @@ -1326,8 +1326,6 @@ grpc_cc_library( "src/core/lib/security/credentials/oauth2/oauth2_credentials.cc", "src/core/lib/security/credentials/plugin/plugin_credentials.cc", "src/core/lib/security/credentials/ssl/ssl_credentials.cc", - "src/core/lib/security/credentials/alts/alts_credentials.cc", - "src/core/lib/security/security_connector/alts_security_connector.cc", "src/core/lib/security/security_connector/security_connector.cc", "src/core/lib/security/transport/client_auth_filter.cc", "src/core/lib/security/transport/secure_endpoint.cc", @@ -1351,8 +1349,6 @@ grpc_cc_library( "src/core/lib/security/credentials/oauth2/oauth2_credentials.h", "src/core/lib/security/credentials/plugin/plugin_credentials.h", "src/core/lib/security/credentials/ssl/ssl_credentials.h", - "src/core/lib/security/credentials/alts/alts_credentials.h", - "src/core/lib/security/security_connector/alts_security_connector.h", "src/core/lib/security/security_connector/security_connector.h", "src/core/lib/security/transport/auth_filters.h", "src/core/lib/security/transport/secure_endpoint.h", @@ -1364,7 +1360,6 @@ grpc_cc_library( language = "c++", public_hdrs = GRPC_SECURE_PUBLIC_HDRS, deps = [ - "alts_util", "grpc_base", "grpc_transport_chttp2_alpn", "tsi", @@ -1587,119 +1582,16 @@ grpc_cc_library( ], ) -grpc_cc_library( - name = "alts_frame_protector", - srcs = [ - "src/core/tsi/alts/crypt/aes_gcm.cc", - "src/core/tsi/alts/crypt/gsec.cc", - "src/core/tsi/alts/frame_protector/alts_counter.cc", - "src/core/tsi/alts/frame_protector/alts_crypter.cc", - "src/core/tsi/alts/frame_protector/alts_frame_protector.cc", - "src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc", - "src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc", - "src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc", - "src/core/tsi/alts/frame_protector/frame_handler.cc", - "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc", - "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc", - "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc", - "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc", - "src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc", - ], - hdrs = [ - "src/core/tsi/alts/crypt/gsec.h", - "src/core/tsi/alts/frame_protector/alts_counter.h", - "src/core/tsi/alts/frame_protector/alts_crypter.h", - "src/core/tsi/alts/frame_protector/alts_frame_protector.h", - "src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h", - "src/core/tsi/alts/frame_protector/frame_handler.h", - "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h", - "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h", - "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h", - "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h", - "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h", - "src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h", - "src/core/tsi/transport_security_grpc.h", - ], - external_deps = [ - "libssl", - ], - language = "c++", - deps = [ - "gpr", - "grpc_base", - "tsi_interface", - ], -) - -grpc_cc_library( - name = "alts_proto", - srcs = [ - "src/core/tsi/alts/handshaker/altscontext.pb.c", - "src/core/tsi/alts/handshaker/handshaker.pb.c", - "src/core/tsi/alts/handshaker/transport_security_common.pb.c", - ], - hdrs = [ - "src/core/tsi/alts/handshaker/altscontext.pb.h", - "src/core/tsi/alts/handshaker/handshaker.pb.h", - "src/core/tsi/alts/handshaker/transport_security_common.pb.h", - ], - external_deps = [ - "nanopb", - ], - language = "c++", -) - -grpc_cc_library( - name = "alts_util", - srcs = [ - "src/core/lib/security/credentials/alts/check_gcp_environment.cc", - "src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc", - "src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc", - "src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc", - "src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc", - "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc", - "src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc", - "src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc", - "src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc", - "src/core/tsi/alts/handshaker/transport_security_common_api.cc", - ], - hdrs = [ - "src/core/lib/security/credentials/alts/check_gcp_environment.h", - "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h", - "src/core/tsi/alts/handshaker/alts_handshaker_service_api.h", - "src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h", - "src/core/tsi/alts/handshaker/transport_security_common_api.h", - ], - external_deps = [ - "nanopb", - ], - language = "c++", - deps = [ - "alts_proto", - "gpr", - "grpc_base", - ], -) - grpc_cc_library( name = "tsi", srcs = [ "src/core/tsi/alts_transport_security.cc", - "src/core/tsi/alts/handshaker/alts_handshaker_client.cc", - "src/core/tsi/alts/handshaker/alts_tsi_event.cc", - "src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc", - "src/core/tsi/alts/handshaker/alts_tsi_utils.cc", "src/core/tsi/fake_transport_security.cc", "src/core/tsi/ssl_transport_security.cc", "src/core/tsi/transport_security_grpc.cc", ], hdrs = [ "src/core/tsi/alts_transport_security.h", - "src/core/tsi/alts/handshaker/alts_handshaker_client.h", - "src/core/tsi/alts/handshaker/alts_tsi_event.h", - "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h", - "src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h", - "src/core/tsi/alts/handshaker/alts_tsi_utils.h", "src/core/tsi/fake_transport_security.h", "src/core/tsi/ssl_transport_security.h", "src/core/tsi/ssl_types.h", @@ -1710,11 +1602,7 @@ grpc_cc_library( ], language = "c++", deps = [ - "alts_frame_protector", - "alts_util", - "gpr", "grpc_base", - "grpc_transport_chttp2_client_insecure", "tsi_interface", ], ) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5dfbdcb85a..ab4fa8a253 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,8 +91,6 @@ endif() set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) -add_definitions(-DPB_FIELD_16BIT) - if (MSVC) include(cmake/msvc_static_runtime.cmake) add_definitions(-D_WIN32_WINNT=0x600 -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS) @@ -471,19 +469,6 @@ add_dependencies(buildtests_c uri_fuzzer_test_one_entry) add_custom_target(buildtests_cxx) add_dependencies(buildtests_cxx alarm_test) -add_dependencies(buildtests_cxx alts_counter_test) -add_dependencies(buildtests_cxx alts_crypt_test) -add_dependencies(buildtests_cxx alts_crypter_test) -add_dependencies(buildtests_cxx alts_frame_handler_test) -add_dependencies(buildtests_cxx alts_frame_protector_test) -add_dependencies(buildtests_cxx alts_grpc_record_protocol_test) -add_dependencies(buildtests_cxx alts_handshaker_client_test) -add_dependencies(buildtests_cxx alts_handshaker_service_api_test) -add_dependencies(buildtests_cxx alts_iovec_record_protocol_test) -add_dependencies(buildtests_cxx alts_security_connector_test) -add_dependencies(buildtests_cxx alts_tsi_handshaker_test) -add_dependencies(buildtests_cxx alts_tsi_utils_test) -add_dependencies(buildtests_cxx alts_zero_copy_grpc_protector_test) add_dependencies(buildtests_cxx async_end2end_test) add_dependencies(buildtests_cxx auth_property_iterator_test) add_dependencies(buildtests_cxx backoff_test) @@ -532,8 +517,6 @@ add_dependencies(buildtests_cxx bm_pollset) endif() add_dependencies(buildtests_cxx channel_arguments_test) add_dependencies(buildtests_cxx channel_filter_test) -add_dependencies(buildtests_cxx check_gcp_environment_linux_test) -add_dependencies(buildtests_cxx check_gcp_environment_windows_test) add_dependencies(buildtests_cxx chttp2_settings_timeout_test) add_dependencies(buildtests_cxx cli_call_test) add_dependencies(buildtests_cxx client_channel_stress_test) @@ -555,7 +538,6 @@ add_dependencies(buildtests_cxx exception_test) add_dependencies(buildtests_cxx filter_end2end_test) add_dependencies(buildtests_cxx generic_end2end_test) add_dependencies(buildtests_cxx golden_file_test) -add_dependencies(buildtests_cxx grpc_alts_credentials_options_test) add_dependencies(buildtests_cxx grpc_cli) add_dependencies(buildtests_cxx grpc_tool_test) add_dependencies(buildtests_cxx grpclb_api_test) @@ -629,7 +611,6 @@ add_dependencies(buildtests_cxx stress_test) add_dependencies(buildtests_cxx thread_manager_test) add_dependencies(buildtests_cxx thread_stress_test) add_dependencies(buildtests_cxx transport_pid_controller_test) -add_dependencies(buildtests_cxx transport_security_common_api_test) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) add_dependencies(buildtests_cxx writes_per_rpc_test) endif() @@ -650,44 +631,6 @@ add_custom_target(buildtests DEPENDS buildtests_c buildtests_cxx) endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) - -add_library(alts_test_util - test/core/tsi/alts/crypt/gsec_test_util.cc - test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc -) - -if(WIN32 AND MSVC) - set_target_properties(alts_test_util PROPERTIES COMPILE_PDB_NAME "alts_test_util" - COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" - ) - if (gRPC_INSTALL) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/alts_test_util.pdb - DESTINATION ${gRPC_INSTALL_LIBDIR} OPTIONAL - ) - endif() -endif() - - -target_include_directories(alts_test_util - PUBLIC $ $ - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${_gRPC_SSL_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} - PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} - PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} - PRIVATE ${_gRPC_CARES_INCLUDE_DIR} - PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} -) - -target_link_libraries(alts_test_util - ${_gRPC_SSL_LIBRARIES} - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc -) - - -endif (gRPC_BUILD_TESTS) add_library(gpr src/core/lib/gpr/alloc.cc @@ -1016,7 +959,6 @@ add_library(grpc src/core/ext/filters/http/server/http_server_filter.cc src/core/lib/http/httpcli_security_connector.cc src/core/lib/security/context/security_context.cc - src/core/lib/security/credentials/alts/alts_credentials.cc src/core/lib/security/credentials/composite/composite_credentials.cc src/core/lib/security/credentials/credentials.cc src/core/lib/security/credentials/credentials_metadata.cc @@ -1030,7 +972,6 @@ add_library(grpc src/core/lib/security/credentials/oauth2/oauth2_credentials.cc src/core/lib/security/credentials/plugin/plugin_credentials.cc src/core/lib/security/credentials/ssl/ssl_credentials.cc - src/core/lib/security/security_connector/alts_security_connector.cc src/core/lib/security/security_connector/security_connector.cc src/core/lib/security/transport/client_auth_filter.cc src/core/lib/security/transport/secure_endpoint.cc @@ -1040,45 +981,14 @@ add_library(grpc src/core/lib/security/transport/tsi_error.cc src/core/lib/security/util/json_util.cc src/core/lib/surface/init_secure.cc - src/core/tsi/alts/crypt/aes_gcm.cc - src/core/tsi/alts/crypt/gsec.cc - src/core/tsi/alts/frame_protector/alts_counter.cc - src/core/tsi/alts/frame_protector/alts_crypter.cc - src/core/tsi/alts/frame_protector/alts_frame_protector.cc - src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc - src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc - src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc - src/core/tsi/alts/frame_protector/frame_handler.cc - src/core/tsi/alts/handshaker/alts_handshaker_client.cc - src/core/tsi/alts/handshaker/alts_tsi_event.cc - src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc - src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc - src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc - src/core/lib/security/credentials/alts/check_gcp_environment.cc - src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc - src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc - src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc - src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc - src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc - src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc - src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc - src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc - src/core/tsi/alts/handshaker/alts_tsi_utils.cc - src/core/tsi/alts/handshaker/transport_security_common_api.cc - src/core/tsi/alts/handshaker/altscontext.pb.c - src/core/tsi/alts/handshaker/handshaker.pb.c - src/core/tsi/alts/handshaker/transport_security_common.pb.c - third_party/nanopb/pb_common.c - third_party/nanopb/pb_decode.c - third_party/nanopb/pb_encode.c + src/core/tsi/alts_transport_security.cc + src/core/tsi/fake_transport_security.cc + src/core/tsi/ssl_transport_security.cc + src/core/tsi/transport_security_grpc.cc src/core/tsi/transport_security.cc src/core/tsi/transport_security_adapter.cc - src/core/ext/transport/chttp2/client/insecure/channel_create.cc - src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc - src/core/ext/transport/chttp2/client/chttp2_connector.cc + src/core/ext/transport/chttp2/server/chttp2_server.cc + src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc src/core/ext/filters/client_channel/client_channel.cc @@ -1102,14 +1012,11 @@ add_library(grpc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc src/core/ext/filters/deadline/deadline_filter.cc - src/core/tsi/alts_transport_security.cc - src/core/tsi/fake_transport_security.cc - src/core/tsi/ssl_transport_security.cc - src/core/tsi/transport_security_grpc.cc - src/core/ext/transport/chttp2/server/chttp2_server.cc - src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc + src/core/ext/transport/chttp2/client/chttp2_connector.cc src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc + src/core/ext/transport/chttp2/client/insecure/channel_create.cc + src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc src/core/ext/transport/inproc/inproc_plugin.cc src/core/ext/transport/inproc/inproc_transport.cc src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc @@ -1118,6 +1025,9 @@ add_library(grpc src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c + third_party/nanopb/pb_common.c + third_party/nanopb/pb_decode.c + third_party/nanopb/pb_encode.c src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc @@ -1417,7 +1327,6 @@ add_library(grpc_cronet src/core/ext/filters/deadline/deadline_filter.cc src/core/lib/http/httpcli_security_connector.cc src/core/lib/security/context/security_context.cc - src/core/lib/security/credentials/alts/alts_credentials.cc src/core/lib/security/credentials/composite/composite_credentials.cc src/core/lib/security/credentials/credentials.cc src/core/lib/security/credentials/credentials_metadata.cc @@ -1431,7 +1340,6 @@ add_library(grpc_cronet src/core/lib/security/credentials/oauth2/oauth2_credentials.cc src/core/lib/security/credentials/plugin/plugin_credentials.cc src/core/lib/security/credentials/ssl/ssl_credentials.cc - src/core/lib/security/security_connector/alts_security_connector.cc src/core/lib/security/security_connector/security_connector.cc src/core/lib/security/transport/client_auth_filter.cc src/core/lib/security/transport/secure_endpoint.cc @@ -1441,49 +1349,13 @@ add_library(grpc_cronet src/core/lib/security/transport/tsi_error.cc src/core/lib/security/util/json_util.cc src/core/lib/surface/init_secure.cc - src/core/tsi/alts/crypt/aes_gcm.cc - src/core/tsi/alts/crypt/gsec.cc - src/core/tsi/alts/frame_protector/alts_counter.cc - src/core/tsi/alts/frame_protector/alts_crypter.cc - src/core/tsi/alts/frame_protector/alts_frame_protector.cc - src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc - src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc - src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc - src/core/tsi/alts/frame_protector/frame_handler.cc - src/core/tsi/alts/handshaker/alts_handshaker_client.cc - src/core/tsi/alts/handshaker/alts_tsi_event.cc - src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc - src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc - src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc - src/core/lib/security/credentials/alts/check_gcp_environment.cc - src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc - src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc - src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc - src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc - src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc - src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc - src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc - src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc - src/core/tsi/alts/handshaker/alts_tsi_utils.cc - src/core/tsi/alts/handshaker/transport_security_common_api.cc - src/core/tsi/alts/handshaker/altscontext.pb.c - src/core/tsi/alts/handshaker/handshaker.pb.c - src/core/tsi/alts/handshaker/transport_security_common.pb.c - third_party/nanopb/pb_common.c - third_party/nanopb/pb_decode.c - third_party/nanopb/pb_encode.c - src/core/tsi/transport_security.cc - src/core/tsi/transport_security_adapter.cc - src/core/ext/transport/chttp2/client/insecure/channel_create.cc - src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc - src/core/ext/transport/chttp2/client/chttp2_connector.cc src/core/tsi/alts_transport_security.cc src/core/tsi/fake_transport_security.cc src/core/tsi/ssl_transport_security.cc src/core/tsi/transport_security_grpc.cc + src/core/tsi/transport_security.cc + src/core/tsi/transport_security_adapter.cc + src/core/ext/transport/chttp2/client/chttp2_connector.cc src/core/ext/filters/load_reporting/server_load_reporting_filter.cc src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc src/core/plugin_registry/grpc_cronet_plugin_registry.cc @@ -8789,14 +8661,14 @@ target_link_libraries(alarm_test endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -add_executable(alts_counter_test - test/core/tsi/alts/frame_protector/alts_counter_test.cc +add_executable(async_end2end_test + test/cpp/end2end/async_end2end_test.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(alts_counter_test +target_include_directories(async_end2end_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -8812,26 +8684,29 @@ target_include_directories(alts_counter_test PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(alts_counter_test +target_link_libraries(async_end2end_test ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - alts_test_util - gpr + grpc++_test_util + grpc_test_util + grpc++ grpc + gpr_test_util + gpr ${_gRPC_GFLAGS_LIBRARIES} ) endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -add_executable(alts_crypt_test - test/core/tsi/alts/crypt/aes_gcm_test.cc +add_executable(auth_property_iterator_test + test/cpp/common/auth_property_iterator_test.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(alts_crypt_test +target_include_directories(auth_property_iterator_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -8847,27 +8722,29 @@ target_include_directories(alts_crypt_test PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(alts_crypt_test +target_link_libraries(auth_property_iterator_test ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - alts_test_util + grpc++_test_util + grpc_test_util + grpc++ + grpc gpr_test_util gpr - grpc ${_gRPC_GFLAGS_LIBRARIES} ) endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -add_executable(alts_crypter_test - test/core/tsi/alts/frame_protector/alts_crypter_test.cc +add_executable(backoff_test + test/core/backoff/backoff_test.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(alts_crypter_test +target_include_directories(backoff_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -8883,26 +8760,27 @@ target_include_directories(alts_crypter_test PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(alts_crypter_test +target_link_libraries(backoff_test ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - alts_test_util - gpr + grpc_test_util grpc + gpr_test_util + gpr ${_gRPC_GFLAGS_LIBRARIES} ) endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -add_executable(alts_frame_handler_test - test/core/tsi/alts/frame_protector/frame_handler_test.cc +add_executable(bdp_estimator_test + test/core/transport/bdp_estimator_test.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(alts_frame_handler_test +target_include_directories(bdp_estimator_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -8918,27 +8796,30 @@ target_include_directories(alts_frame_handler_test PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(alts_frame_handler_test +target_link_libraries(bdp_estimator_test ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - alts_test_util - gpr + grpc++_test_util + grpc++ + grpc_test_util grpc + gpr_test_util + gpr ${_gRPC_GFLAGS_LIBRARIES} ) endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) -add_executable(alts_frame_protector_test - test/core/tsi/alts/frame_protector/alts_frame_protector_test.cc - test/core/tsi/transport_security_test_lib.cc +add_executable(bm_arena + test/cpp/microbenchmarks/bm_arena.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(alts_frame_protector_test +target_include_directories(bm_arena PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -8954,26 +8835,33 @@ target_include_directories(alts_frame_protector_test PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(alts_frame_protector_test +target_link_libraries(bm_arena ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - alts_test_util + grpc_benchmark + ${_gRPC_BENCHMARK_LIBRARIES} + grpc++_test_util_unsecure + grpc_test_util_unsecure + grpc++_unsecure + grpc_unsecure + gpr_test_util gpr - grpc ${_gRPC_GFLAGS_LIBRARIES} ) +endif() endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) -add_executable(alts_grpc_record_protocol_test - test/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_test.cc +add_executable(bm_call_create + test/cpp/microbenchmarks/bm_call_create.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(alts_grpc_record_protocol_test +target_include_directories(bm_call_create PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -8989,26 +8877,33 @@ target_include_directories(alts_grpc_record_protocol_test PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(alts_grpc_record_protocol_test +target_link_libraries(bm_call_create ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - alts_test_util + grpc_benchmark + ${_gRPC_BENCHMARK_LIBRARIES} + grpc++_test_util_unsecure + grpc_test_util_unsecure + grpc++_unsecure + grpc_unsecure + gpr_test_util gpr - grpc ${_gRPC_GFLAGS_LIBRARIES} ) +endif() endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) -add_executable(alts_handshaker_client_test - test/core/tsi/alts/handshaker/alts_handshaker_client_test.cc +add_executable(bm_chttp2_hpack + test/cpp/microbenchmarks/bm_chttp2_hpack.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(alts_handshaker_client_test +target_include_directories(bm_chttp2_hpack PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -9024,26 +8919,33 @@ target_include_directories(alts_handshaker_client_test PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(alts_handshaker_client_test +target_link_libraries(bm_chttp2_hpack ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - alts_test_util + grpc_benchmark + ${_gRPC_BENCHMARK_LIBRARIES} + grpc++_test_util_unsecure + grpc_test_util_unsecure + grpc++_unsecure + grpc_unsecure + gpr_test_util gpr - grpc ${_gRPC_GFLAGS_LIBRARIES} ) +endif() endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) -add_executable(alts_handshaker_service_api_test - test/core/tsi/alts/handshaker/alts_handshaker_service_api_test.cc +add_executable(bm_chttp2_transport + test/cpp/microbenchmarks/bm_chttp2_transport.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(alts_handshaker_service_api_test +target_include_directories(bm_chttp2_transport PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -9059,26 +8961,33 @@ target_include_directories(alts_handshaker_service_api_test PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(alts_handshaker_service_api_test +target_link_libraries(bm_chttp2_transport ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - alts_test_util + grpc_benchmark + ${_gRPC_BENCHMARK_LIBRARIES} + grpc++_test_util_unsecure + grpc_test_util_unsecure + grpc++_unsecure + grpc_unsecure + gpr_test_util gpr - grpc ${_gRPC_GFLAGS_LIBRARIES} ) +endif() endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) -add_executable(alts_iovec_record_protocol_test - test/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol_test.cc +add_executable(bm_closure + test/cpp/microbenchmarks/bm_closure.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(alts_iovec_record_protocol_test +target_include_directories(bm_closure PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -9094,26 +9003,33 @@ target_include_directories(alts_iovec_record_protocol_test PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(alts_iovec_record_protocol_test +target_link_libraries(bm_closure ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - alts_test_util + grpc_benchmark + ${_gRPC_BENCHMARK_LIBRARIES} + grpc++_test_util_unsecure + grpc_test_util_unsecure + grpc++_unsecure + grpc_unsecure + gpr_test_util gpr - grpc ${_gRPC_GFLAGS_LIBRARIES} ) +endif() endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) -add_executable(alts_security_connector_test - test/core/security/alts_security_connector_test.cc +add_executable(bm_cq + test/cpp/microbenchmarks/bm_cq.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(alts_security_connector_test +target_include_directories(bm_cq PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -9129,25 +9045,33 @@ target_include_directories(alts_security_connector_test PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(alts_security_connector_test +target_link_libraries(bm_cq ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} + grpc_benchmark + ${_gRPC_BENCHMARK_LIBRARIES} + grpc++_test_util_unsecure + grpc_test_util_unsecure + grpc++_unsecure + grpc_unsecure + gpr_test_util gpr - grpc ${_gRPC_GFLAGS_LIBRARIES} ) +endif() endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) -add_executable(alts_tsi_handshaker_test - test/core/tsi/alts/handshaker/alts_tsi_handshaker_test.cc +add_executable(bm_cq_multiple_threads + test/cpp/microbenchmarks/bm_cq_multiple_threads.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(alts_tsi_handshaker_test +target_include_directories(bm_cq_multiple_threads PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -9163,26 +9087,33 @@ target_include_directories(alts_tsi_handshaker_test PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(alts_tsi_handshaker_test +target_link_libraries(bm_cq_multiple_threads ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - alts_test_util + grpc_benchmark + ${_gRPC_BENCHMARK_LIBRARIES} + grpc++_test_util_unsecure + grpc_test_util_unsecure + grpc++_unsecure + grpc_unsecure + gpr_test_util gpr - grpc ${_gRPC_GFLAGS_LIBRARIES} ) +endif() endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) -add_executable(alts_tsi_utils_test - test/core/tsi/alts/handshaker/alts_tsi_utils_test.cc +add_executable(bm_error + test/cpp/microbenchmarks/bm_error.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(alts_tsi_utils_test +target_include_directories(bm_error PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -9198,26 +9129,33 @@ target_include_directories(alts_tsi_utils_test PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(alts_tsi_utils_test +target_link_libraries(bm_error ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - alts_test_util + grpc_benchmark + ${_gRPC_BENCHMARK_LIBRARIES} + grpc++_test_util_unsecure + grpc_test_util_unsecure + grpc++_unsecure + grpc_unsecure + gpr_test_util gpr - grpc ${_gRPC_GFLAGS_LIBRARIES} ) +endif() endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) -add_executable(alts_zero_copy_grpc_protector_test - test/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector_test.cc +add_executable(bm_fullstack_streaming_ping_pong + test/cpp/microbenchmarks/bm_fullstack_streaming_ping_pong.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(alts_zero_copy_grpc_protector_test +target_include_directories(bm_fullstack_streaming_ping_pong PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -9233,26 +9171,33 @@ target_include_directories(alts_zero_copy_grpc_protector_test PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(alts_zero_copy_grpc_protector_test +target_link_libraries(bm_fullstack_streaming_ping_pong ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - alts_test_util + grpc_benchmark + ${_gRPC_BENCHMARK_LIBRARIES} + grpc++_test_util_unsecure + grpc_test_util_unsecure + grpc++_unsecure + grpc_unsecure + gpr_test_util gpr - grpc ${_gRPC_GFLAGS_LIBRARIES} ) +endif() endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) -add_executable(async_end2end_test - test/cpp/end2end/async_end2end_test.cc +add_executable(bm_fullstack_streaming_pump + test/cpp/microbenchmarks/bm_fullstack_streaming_pump.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(async_end2end_test +target_include_directories(bm_fullstack_streaming_pump PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -9268,556 +9213,27 @@ target_include_directories(async_end2end_test PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(async_end2end_test +target_link_libraries(bm_fullstack_streaming_pump ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - grpc++_test_util - grpc_test_util - grpc++ - grpc + grpc_benchmark + ${_gRPC_BENCHMARK_LIBRARIES} + grpc++_test_util_unsecure + grpc_test_util_unsecure + grpc++_unsecure + grpc_unsecure gpr_test_util gpr ${_gRPC_GFLAGS_LIBRARIES} ) +endif() endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) -add_executable(auth_property_iterator_test - test/cpp/common/auth_property_iterator_test.cc - third_party/googletest/googletest/src/gtest-all.cc - third_party/googletest/googlemock/src/gmock-all.cc -) - - -target_include_directories(auth_property_iterator_test - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${_gRPC_SSL_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} - PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} - PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} - PRIVATE ${_gRPC_CARES_INCLUDE_DIR} - PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} - PRIVATE third_party/googletest/googletest/include - PRIVATE third_party/googletest/googletest - PRIVATE third_party/googletest/googlemock/include - PRIVATE third_party/googletest/googlemock - PRIVATE ${_gRPC_PROTO_GENS_DIR} -) - -target_link_libraries(auth_property_iterator_test - ${_gRPC_PROTOBUF_LIBRARIES} - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc++_test_util - grpc_test_util - grpc++ - grpc - gpr_test_util - gpr - ${_gRPC_GFLAGS_LIBRARIES} -) - -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) - -add_executable(backoff_test - test/core/backoff/backoff_test.cc - third_party/googletest/googletest/src/gtest-all.cc - third_party/googletest/googlemock/src/gmock-all.cc -) - - -target_include_directories(backoff_test - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${_gRPC_SSL_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} - PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} - PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} - PRIVATE ${_gRPC_CARES_INCLUDE_DIR} - PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} - PRIVATE third_party/googletest/googletest/include - PRIVATE third_party/googletest/googletest - PRIVATE third_party/googletest/googlemock/include - PRIVATE third_party/googletest/googlemock - PRIVATE ${_gRPC_PROTO_GENS_DIR} -) - -target_link_libraries(backoff_test - ${_gRPC_PROTOBUF_LIBRARIES} - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_test_util - grpc - gpr_test_util - gpr - ${_gRPC_GFLAGS_LIBRARIES} -) - -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) - -add_executable(bdp_estimator_test - test/core/transport/bdp_estimator_test.cc - third_party/googletest/googletest/src/gtest-all.cc - third_party/googletest/googlemock/src/gmock-all.cc -) - - -target_include_directories(bdp_estimator_test - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${_gRPC_SSL_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} - PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} - PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} - PRIVATE ${_gRPC_CARES_INCLUDE_DIR} - PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} - PRIVATE third_party/googletest/googletest/include - PRIVATE third_party/googletest/googletest - PRIVATE third_party/googletest/googlemock/include - PRIVATE third_party/googletest/googlemock - PRIVATE ${_gRPC_PROTO_GENS_DIR} -) - -target_link_libraries(bdp_estimator_test - ${_gRPC_PROTOBUF_LIBRARIES} - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc++_test_util - grpc++ - grpc_test_util - grpc - gpr_test_util - gpr - ${_gRPC_GFLAGS_LIBRARIES} -) - -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) -if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) - -add_executable(bm_arena - test/cpp/microbenchmarks/bm_arena.cc - third_party/googletest/googletest/src/gtest-all.cc - third_party/googletest/googlemock/src/gmock-all.cc -) - - -target_include_directories(bm_arena - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${_gRPC_SSL_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} - PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} - PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} - PRIVATE ${_gRPC_CARES_INCLUDE_DIR} - PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} - PRIVATE third_party/googletest/googletest/include - PRIVATE third_party/googletest/googletest - PRIVATE third_party/googletest/googlemock/include - PRIVATE third_party/googletest/googlemock - PRIVATE ${_gRPC_PROTO_GENS_DIR} -) - -target_link_libraries(bm_arena - ${_gRPC_PROTOBUF_LIBRARIES} - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_benchmark - ${_gRPC_BENCHMARK_LIBRARIES} - grpc++_test_util_unsecure - grpc_test_util_unsecure - grpc++_unsecure - grpc_unsecure - gpr_test_util - gpr - ${_gRPC_GFLAGS_LIBRARIES} -) - -endif() -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) -if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) - -add_executable(bm_call_create - test/cpp/microbenchmarks/bm_call_create.cc - third_party/googletest/googletest/src/gtest-all.cc - third_party/googletest/googlemock/src/gmock-all.cc -) - - -target_include_directories(bm_call_create - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${_gRPC_SSL_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} - PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} - PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} - PRIVATE ${_gRPC_CARES_INCLUDE_DIR} - PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} - PRIVATE third_party/googletest/googletest/include - PRIVATE third_party/googletest/googletest - PRIVATE third_party/googletest/googlemock/include - PRIVATE third_party/googletest/googlemock - PRIVATE ${_gRPC_PROTO_GENS_DIR} -) - -target_link_libraries(bm_call_create - ${_gRPC_PROTOBUF_LIBRARIES} - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_benchmark - ${_gRPC_BENCHMARK_LIBRARIES} - grpc++_test_util_unsecure - grpc_test_util_unsecure - grpc++_unsecure - grpc_unsecure - gpr_test_util - gpr - ${_gRPC_GFLAGS_LIBRARIES} -) - -endif() -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) -if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) - -add_executable(bm_chttp2_hpack - test/cpp/microbenchmarks/bm_chttp2_hpack.cc - third_party/googletest/googletest/src/gtest-all.cc - third_party/googletest/googlemock/src/gmock-all.cc -) - - -target_include_directories(bm_chttp2_hpack - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${_gRPC_SSL_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} - PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} - PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} - PRIVATE ${_gRPC_CARES_INCLUDE_DIR} - PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} - PRIVATE third_party/googletest/googletest/include - PRIVATE third_party/googletest/googletest - PRIVATE third_party/googletest/googlemock/include - PRIVATE third_party/googletest/googlemock - PRIVATE ${_gRPC_PROTO_GENS_DIR} -) - -target_link_libraries(bm_chttp2_hpack - ${_gRPC_PROTOBUF_LIBRARIES} - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_benchmark - ${_gRPC_BENCHMARK_LIBRARIES} - grpc++_test_util_unsecure - grpc_test_util_unsecure - grpc++_unsecure - grpc_unsecure - gpr_test_util - gpr - ${_gRPC_GFLAGS_LIBRARIES} -) - -endif() -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) -if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) - -add_executable(bm_chttp2_transport - test/cpp/microbenchmarks/bm_chttp2_transport.cc - third_party/googletest/googletest/src/gtest-all.cc - third_party/googletest/googlemock/src/gmock-all.cc -) - - -target_include_directories(bm_chttp2_transport - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${_gRPC_SSL_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} - PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} - PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} - PRIVATE ${_gRPC_CARES_INCLUDE_DIR} - PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} - PRIVATE third_party/googletest/googletest/include - PRIVATE third_party/googletest/googletest - PRIVATE third_party/googletest/googlemock/include - PRIVATE third_party/googletest/googlemock - PRIVATE ${_gRPC_PROTO_GENS_DIR} -) - -target_link_libraries(bm_chttp2_transport - ${_gRPC_PROTOBUF_LIBRARIES} - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_benchmark - ${_gRPC_BENCHMARK_LIBRARIES} - grpc++_test_util_unsecure - grpc_test_util_unsecure - grpc++_unsecure - grpc_unsecure - gpr_test_util - gpr - ${_gRPC_GFLAGS_LIBRARIES} -) - -endif() -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) -if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) - -add_executable(bm_closure - test/cpp/microbenchmarks/bm_closure.cc - third_party/googletest/googletest/src/gtest-all.cc - third_party/googletest/googlemock/src/gmock-all.cc -) - - -target_include_directories(bm_closure - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${_gRPC_SSL_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} - PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} - PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} - PRIVATE ${_gRPC_CARES_INCLUDE_DIR} - PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} - PRIVATE third_party/googletest/googletest/include - PRIVATE third_party/googletest/googletest - PRIVATE third_party/googletest/googlemock/include - PRIVATE third_party/googletest/googlemock - PRIVATE ${_gRPC_PROTO_GENS_DIR} -) - -target_link_libraries(bm_closure - ${_gRPC_PROTOBUF_LIBRARIES} - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_benchmark - ${_gRPC_BENCHMARK_LIBRARIES} - grpc++_test_util_unsecure - grpc_test_util_unsecure - grpc++_unsecure - grpc_unsecure - gpr_test_util - gpr - ${_gRPC_GFLAGS_LIBRARIES} -) - -endif() -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) -if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) - -add_executable(bm_cq - test/cpp/microbenchmarks/bm_cq.cc - third_party/googletest/googletest/src/gtest-all.cc - third_party/googletest/googlemock/src/gmock-all.cc -) - - -target_include_directories(bm_cq - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${_gRPC_SSL_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} - PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} - PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} - PRIVATE ${_gRPC_CARES_INCLUDE_DIR} - PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} - PRIVATE third_party/googletest/googletest/include - PRIVATE third_party/googletest/googletest - PRIVATE third_party/googletest/googlemock/include - PRIVATE third_party/googletest/googlemock - PRIVATE ${_gRPC_PROTO_GENS_DIR} -) - -target_link_libraries(bm_cq - ${_gRPC_PROTOBUF_LIBRARIES} - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_benchmark - ${_gRPC_BENCHMARK_LIBRARIES} - grpc++_test_util_unsecure - grpc_test_util_unsecure - grpc++_unsecure - grpc_unsecure - gpr_test_util - gpr - ${_gRPC_GFLAGS_LIBRARIES} -) - -endif() -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) -if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) - -add_executable(bm_cq_multiple_threads - test/cpp/microbenchmarks/bm_cq_multiple_threads.cc - third_party/googletest/googletest/src/gtest-all.cc - third_party/googletest/googlemock/src/gmock-all.cc -) - - -target_include_directories(bm_cq_multiple_threads - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${_gRPC_SSL_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} - PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} - PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} - PRIVATE ${_gRPC_CARES_INCLUDE_DIR} - PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} - PRIVATE third_party/googletest/googletest/include - PRIVATE third_party/googletest/googletest - PRIVATE third_party/googletest/googlemock/include - PRIVATE third_party/googletest/googlemock - PRIVATE ${_gRPC_PROTO_GENS_DIR} -) - -target_link_libraries(bm_cq_multiple_threads - ${_gRPC_PROTOBUF_LIBRARIES} - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_benchmark - ${_gRPC_BENCHMARK_LIBRARIES} - grpc++_test_util_unsecure - grpc_test_util_unsecure - grpc++_unsecure - grpc_unsecure - gpr_test_util - gpr - ${_gRPC_GFLAGS_LIBRARIES} -) - -endif() -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) -if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) - -add_executable(bm_error - test/cpp/microbenchmarks/bm_error.cc - third_party/googletest/googletest/src/gtest-all.cc - third_party/googletest/googlemock/src/gmock-all.cc -) - - -target_include_directories(bm_error - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${_gRPC_SSL_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} - PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} - PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} - PRIVATE ${_gRPC_CARES_INCLUDE_DIR} - PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} - PRIVATE third_party/googletest/googletest/include - PRIVATE third_party/googletest/googletest - PRIVATE third_party/googletest/googlemock/include - PRIVATE third_party/googletest/googlemock - PRIVATE ${_gRPC_PROTO_GENS_DIR} -) - -target_link_libraries(bm_error - ${_gRPC_PROTOBUF_LIBRARIES} - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_benchmark - ${_gRPC_BENCHMARK_LIBRARIES} - grpc++_test_util_unsecure - grpc_test_util_unsecure - grpc++_unsecure - grpc_unsecure - gpr_test_util - gpr - ${_gRPC_GFLAGS_LIBRARIES} -) - -endif() -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) -if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) - -add_executable(bm_fullstack_streaming_ping_pong - test/cpp/microbenchmarks/bm_fullstack_streaming_ping_pong.cc - third_party/googletest/googletest/src/gtest-all.cc - third_party/googletest/googlemock/src/gmock-all.cc -) - - -target_include_directories(bm_fullstack_streaming_ping_pong - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${_gRPC_SSL_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} - PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} - PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} - PRIVATE ${_gRPC_CARES_INCLUDE_DIR} - PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} - PRIVATE third_party/googletest/googletest/include - PRIVATE third_party/googletest/googletest - PRIVATE third_party/googletest/googlemock/include - PRIVATE third_party/googletest/googlemock - PRIVATE ${_gRPC_PROTO_GENS_DIR} -) - -target_link_libraries(bm_fullstack_streaming_ping_pong - ${_gRPC_PROTOBUF_LIBRARIES} - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_benchmark - ${_gRPC_BENCHMARK_LIBRARIES} - grpc++_test_util_unsecure - grpc_test_util_unsecure - grpc++_unsecure - grpc_unsecure - gpr_test_util - gpr - ${_gRPC_GFLAGS_LIBRARIES} -) - -endif() -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) -if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) - -add_executable(bm_fullstack_streaming_pump - test/cpp/microbenchmarks/bm_fullstack_streaming_pump.cc - third_party/googletest/googletest/src/gtest-all.cc - third_party/googletest/googlemock/src/gmock-all.cc -) - - -target_include_directories(bm_fullstack_streaming_pump - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${_gRPC_SSL_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} - PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} - PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} - PRIVATE ${_gRPC_CARES_INCLUDE_DIR} - PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} - PRIVATE third_party/googletest/googletest/include - PRIVATE third_party/googletest/googletest - PRIVATE third_party/googletest/googlemock/include - PRIVATE third_party/googletest/googlemock - PRIVATE ${_gRPC_PROTO_GENS_DIR} -) - -target_link_libraries(bm_fullstack_streaming_pump - ${_gRPC_PROTOBUF_LIBRARIES} - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_benchmark - ${_gRPC_BENCHMARK_LIBRARIES} - grpc++_test_util_unsecure - grpc_test_util_unsecure - grpc++_unsecure - grpc_unsecure - gpr_test_util - gpr - ${_gRPC_GFLAGS_LIBRARIES} -) - -endif() -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) -if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) - -add_executable(bm_fullstack_trickle - test/cpp/microbenchmarks/bm_fullstack_trickle.cc +add_executable(bm_fullstack_trickle + test/cpp/microbenchmarks/bm_fullstack_trickle.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) @@ -10054,74 +9470,6 @@ target_link_libraries(channel_filter_test endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -add_executable(check_gcp_environment_linux_test - test/core/security/check_gcp_environment_linux_test.cc - third_party/googletest/googletest/src/gtest-all.cc - third_party/googletest/googlemock/src/gmock-all.cc -) - - -target_include_directories(check_gcp_environment_linux_test - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${_gRPC_SSL_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} - PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} - PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} - PRIVATE ${_gRPC_CARES_INCLUDE_DIR} - PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} - PRIVATE third_party/googletest/googletest/include - PRIVATE third_party/googletest/googletest - PRIVATE third_party/googletest/googlemock/include - PRIVATE third_party/googletest/googlemock - PRIVATE ${_gRPC_PROTO_GENS_DIR} -) - -target_link_libraries(check_gcp_environment_linux_test - ${_gRPC_PROTOBUF_LIBRARIES} - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc - gpr - ${_gRPC_GFLAGS_LIBRARIES} -) - -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) - -add_executable(check_gcp_environment_windows_test - test/core/security/check_gcp_environment_windows_test.cc - third_party/googletest/googletest/src/gtest-all.cc - third_party/googletest/googlemock/src/gmock-all.cc -) - - -target_include_directories(check_gcp_environment_windows_test - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${_gRPC_SSL_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} - PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} - PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} - PRIVATE ${_gRPC_CARES_INCLUDE_DIR} - PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} - PRIVATE third_party/googletest/googletest/include - PRIVATE third_party/googletest/googletest - PRIVATE third_party/googletest/googlemock/include - PRIVATE third_party/googletest/googlemock - PRIVATE ${_gRPC_PROTO_GENS_DIR} -) - -target_link_libraries(check_gcp_environment_windows_test - ${_gRPC_PROTOBUF_LIBRARIES} - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc - gpr - ${_gRPC_GFLAGS_LIBRARIES} -) - -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) - add_executable(chttp2_settings_timeout_test test/core/transport/chttp2/settings_timeout_test.cc third_party/googletest/googletest/src/gtest-all.cc @@ -10915,40 +10263,6 @@ target_link_libraries(golden_file_test endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -add_executable(grpc_alts_credentials_options_test - test/core/security/grpc_alts_credentials_options_test.cc - third_party/googletest/googletest/src/gtest-all.cc - third_party/googletest/googlemock/src/gmock-all.cc -) - - -target_include_directories(grpc_alts_credentials_options_test - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${_gRPC_SSL_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} - PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} - PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} - PRIVATE ${_gRPC_CARES_INCLUDE_DIR} - PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} - PRIVATE third_party/googletest/googletest/include - PRIVATE third_party/googletest/googletest - PRIVATE third_party/googletest/googlemock/include - PRIVATE third_party/googletest/googlemock - PRIVATE ${_gRPC_PROTO_GENS_DIR} -) - -target_link_libraries(grpc_alts_credentials_options_test - ${_gRPC_PROTOBUF_LIBRARIES} - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc - gpr - ${_gRPC_GFLAGS_LIBRARIES} -) - -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) - add_executable(grpc_cli test/cpp/util/grpc_cli.cc third_party/googletest/googletest/src/gtest-all.cc @@ -13287,41 +12601,6 @@ target_link_libraries(transport_pid_controller_test ${_gRPC_GFLAGS_LIBRARIES} ) -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) - -add_executable(transport_security_common_api_test - test/core/tsi/alts/handshaker/transport_security_common_api_test.cc - third_party/googletest/googletest/src/gtest-all.cc - third_party/googletest/googlemock/src/gmock-all.cc -) - - -target_include_directories(transport_security_common_api_test - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${_gRPC_SSL_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} - PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} - PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} - PRIVATE ${_gRPC_CARES_INCLUDE_DIR} - PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} - PRIVATE third_party/googletest/googletest/include - PRIVATE third_party/googletest/googletest - PRIVATE third_party/googletest/googlemock/include - PRIVATE third_party/googletest/googlemock - PRIVATE ${_gRPC_PROTO_GENS_DIR} -) - -target_link_libraries(transport_security_common_api_test - ${_gRPC_PROTOBUF_LIBRARIES} - ${_gRPC_ALLTARGETS_LIBRARIES} - alts_test_util - gpr - grpc - ${_gRPC_GFLAGS_LIBRARIES} -) - endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) diff --git a/Makefile b/Makefile index 7bc2c82938..b090b9fb94 100644 --- a/Makefile +++ b/Makefile @@ -338,8 +338,6 @@ CPPFLAGS += -g -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter -DOSAT COREFLAGS += -fno-rtti -fno-exceptions LDFLAGS += -g -DEFINES += PB_FIELD_16BIT - CPPFLAGS += $(CPPFLAGS_$(CONFIG)) CFLAGS += $(CFLAGS_$(CONFIG)) CXXFLAGS += $(CXXFLAGS_$(CONFIG)) @@ -1096,19 +1094,6 @@ uri_fuzzer_test: $(BINDIR)/$(CONFIG)/uri_fuzzer_test uri_parser_test: $(BINDIR)/$(CONFIG)/uri_parser_test wakeup_fd_cv_test: $(BINDIR)/$(CONFIG)/wakeup_fd_cv_test alarm_test: $(BINDIR)/$(CONFIG)/alarm_test -alts_counter_test: $(BINDIR)/$(CONFIG)/alts_counter_test -alts_crypt_test: $(BINDIR)/$(CONFIG)/alts_crypt_test -alts_crypter_test: $(BINDIR)/$(CONFIG)/alts_crypter_test -alts_frame_handler_test: $(BINDIR)/$(CONFIG)/alts_frame_handler_test -alts_frame_protector_test: $(BINDIR)/$(CONFIG)/alts_frame_protector_test -alts_grpc_record_protocol_test: $(BINDIR)/$(CONFIG)/alts_grpc_record_protocol_test -alts_handshaker_client_test: $(BINDIR)/$(CONFIG)/alts_handshaker_client_test -alts_handshaker_service_api_test: $(BINDIR)/$(CONFIG)/alts_handshaker_service_api_test -alts_iovec_record_protocol_test: $(BINDIR)/$(CONFIG)/alts_iovec_record_protocol_test -alts_security_connector_test: $(BINDIR)/$(CONFIG)/alts_security_connector_test -alts_tsi_handshaker_test: $(BINDIR)/$(CONFIG)/alts_tsi_handshaker_test -alts_tsi_utils_test: $(BINDIR)/$(CONFIG)/alts_tsi_utils_test -alts_zero_copy_grpc_protector_test: $(BINDIR)/$(CONFIG)/alts_zero_copy_grpc_protector_test async_end2end_test: $(BINDIR)/$(CONFIG)/async_end2end_test auth_property_iterator_test: $(BINDIR)/$(CONFIG)/auth_property_iterator_test backoff_test: $(BINDIR)/$(CONFIG)/backoff_test @@ -1129,8 +1114,6 @@ bm_metadata: $(BINDIR)/$(CONFIG)/bm_metadata bm_pollset: $(BINDIR)/$(CONFIG)/bm_pollset channel_arguments_test: $(BINDIR)/$(CONFIG)/channel_arguments_test channel_filter_test: $(BINDIR)/$(CONFIG)/channel_filter_test -check_gcp_environment_linux_test: $(BINDIR)/$(CONFIG)/check_gcp_environment_linux_test -check_gcp_environment_windows_test: $(BINDIR)/$(CONFIG)/check_gcp_environment_windows_test chttp2_settings_timeout_test: $(BINDIR)/$(CONFIG)/chttp2_settings_timeout_test cli_call_test: $(BINDIR)/$(CONFIG)/cli_call_test client_channel_stress_test: $(BINDIR)/$(CONFIG)/client_channel_stress_test @@ -1150,7 +1133,6 @@ exception_test: $(BINDIR)/$(CONFIG)/exception_test filter_end2end_test: $(BINDIR)/$(CONFIG)/filter_end2end_test generic_end2end_test: $(BINDIR)/$(CONFIG)/generic_end2end_test golden_file_test: $(BINDIR)/$(CONFIG)/golden_file_test -grpc_alts_credentials_options_test: $(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test grpc_cli: $(BINDIR)/$(CONFIG)/grpc_cli grpc_cpp_plugin: $(BINDIR)/$(CONFIG)/grpc_cpp_plugin grpc_csharp_plugin: $(BINDIR)/$(CONFIG)/grpc_csharp_plugin @@ -1209,7 +1191,6 @@ stress_test: $(BINDIR)/$(CONFIG)/stress_test thread_manager_test: $(BINDIR)/$(CONFIG)/thread_manager_test thread_stress_test: $(BINDIR)/$(CONFIG)/thread_stress_test transport_pid_controller_test: $(BINDIR)/$(CONFIG)/transport_pid_controller_test -transport_security_common_api_test: $(BINDIR)/$(CONFIG)/transport_security_common_api_test writes_per_rpc_test: $(BINDIR)/$(CONFIG)/writes_per_rpc_test public_headers_must_be_c89: $(BINDIR)/$(CONFIG)/public_headers_must_be_c89 gen_hpack_tables: $(BINDIR)/$(CONFIG)/gen_hpack_tables @@ -1371,7 +1352,7 @@ plugins: $(PROTOC_PLUGINS) privatelibs: privatelibs_c privatelibs_cxx -privatelibs_c: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libreconnect_server.a $(LIBDIR)/$(CONFIG)/libtest_tcp_server.a $(LIBDIR)/$(CONFIG)/libz.a $(LIBDIR)/$(CONFIG)/libares.a $(LIBDIR)/$(CONFIG)/libbad_client_test.a $(LIBDIR)/$(CONFIG)/libbad_ssl_test_server.a $(LIBDIR)/$(CONFIG)/libend2end_tests.a $(LIBDIR)/$(CONFIG)/libend2end_nosec_tests.a +privatelibs_c: $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libreconnect_server.a $(LIBDIR)/$(CONFIG)/libtest_tcp_server.a $(LIBDIR)/$(CONFIG)/libz.a $(LIBDIR)/$(CONFIG)/libares.a $(LIBDIR)/$(CONFIG)/libbad_client_test.a $(LIBDIR)/$(CONFIG)/libbad_ssl_test_server.a $(LIBDIR)/$(CONFIG)/libend2end_tests.a $(LIBDIR)/$(CONFIG)/libend2end_nosec_tests.a pc_c: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc pc_c_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc @@ -1581,19 +1562,6 @@ buildtests_c: privatelibs_c \ ifeq ($(EMBED_OPENSSL),true) buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/alarm_test \ - $(BINDIR)/$(CONFIG)/alts_counter_test \ - $(BINDIR)/$(CONFIG)/alts_crypt_test \ - $(BINDIR)/$(CONFIG)/alts_crypter_test \ - $(BINDIR)/$(CONFIG)/alts_frame_handler_test \ - $(BINDIR)/$(CONFIG)/alts_frame_protector_test \ - $(BINDIR)/$(CONFIG)/alts_grpc_record_protocol_test \ - $(BINDIR)/$(CONFIG)/alts_handshaker_client_test \ - $(BINDIR)/$(CONFIG)/alts_handshaker_service_api_test \ - $(BINDIR)/$(CONFIG)/alts_iovec_record_protocol_test \ - $(BINDIR)/$(CONFIG)/alts_security_connector_test \ - $(BINDIR)/$(CONFIG)/alts_tsi_handshaker_test \ - $(BINDIR)/$(CONFIG)/alts_tsi_utils_test \ - $(BINDIR)/$(CONFIG)/alts_zero_copy_grpc_protector_test \ $(BINDIR)/$(CONFIG)/async_end2end_test \ $(BINDIR)/$(CONFIG)/auth_property_iterator_test \ $(BINDIR)/$(CONFIG)/backoff_test \ @@ -1614,8 +1582,6 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/bm_pollset \ $(BINDIR)/$(CONFIG)/channel_arguments_test \ $(BINDIR)/$(CONFIG)/channel_filter_test \ - $(BINDIR)/$(CONFIG)/check_gcp_environment_linux_test \ - $(BINDIR)/$(CONFIG)/check_gcp_environment_windows_test \ $(BINDIR)/$(CONFIG)/chttp2_settings_timeout_test \ $(BINDIR)/$(CONFIG)/cli_call_test \ $(BINDIR)/$(CONFIG)/client_channel_stress_test \ @@ -1635,7 +1601,6 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/filter_end2end_test \ $(BINDIR)/$(CONFIG)/generic_end2end_test \ $(BINDIR)/$(CONFIG)/golden_file_test \ - $(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test \ $(BINDIR)/$(CONFIG)/grpc_cli \ $(BINDIR)/$(CONFIG)/grpc_tool_test \ $(BINDIR)/$(CONFIG)/grpclb_api_test \ @@ -1687,7 +1652,6 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/thread_manager_test \ $(BINDIR)/$(CONFIG)/thread_stress_test \ $(BINDIR)/$(CONFIG)/transport_pid_controller_test \ - $(BINDIR)/$(CONFIG)/transport_security_common_api_test \ $(BINDIR)/$(CONFIG)/writes_per_rpc_test \ $(BINDIR)/$(CONFIG)/boringssl_crypto_test_data \ $(BINDIR)/$(CONFIG)/boringssl_asn1_test \ @@ -1746,19 +1710,6 @@ buildtests_cxx: privatelibs_cxx \ else buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/alarm_test \ - $(BINDIR)/$(CONFIG)/alts_counter_test \ - $(BINDIR)/$(CONFIG)/alts_crypt_test \ - $(BINDIR)/$(CONFIG)/alts_crypter_test \ - $(BINDIR)/$(CONFIG)/alts_frame_handler_test \ - $(BINDIR)/$(CONFIG)/alts_frame_protector_test \ - $(BINDIR)/$(CONFIG)/alts_grpc_record_protocol_test \ - $(BINDIR)/$(CONFIG)/alts_handshaker_client_test \ - $(BINDIR)/$(CONFIG)/alts_handshaker_service_api_test \ - $(BINDIR)/$(CONFIG)/alts_iovec_record_protocol_test \ - $(BINDIR)/$(CONFIG)/alts_security_connector_test \ - $(BINDIR)/$(CONFIG)/alts_tsi_handshaker_test \ - $(BINDIR)/$(CONFIG)/alts_tsi_utils_test \ - $(BINDIR)/$(CONFIG)/alts_zero_copy_grpc_protector_test \ $(BINDIR)/$(CONFIG)/async_end2end_test \ $(BINDIR)/$(CONFIG)/auth_property_iterator_test \ $(BINDIR)/$(CONFIG)/backoff_test \ @@ -1779,8 +1730,6 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/bm_pollset \ $(BINDIR)/$(CONFIG)/channel_arguments_test \ $(BINDIR)/$(CONFIG)/channel_filter_test \ - $(BINDIR)/$(CONFIG)/check_gcp_environment_linux_test \ - $(BINDIR)/$(CONFIG)/check_gcp_environment_windows_test \ $(BINDIR)/$(CONFIG)/chttp2_settings_timeout_test \ $(BINDIR)/$(CONFIG)/cli_call_test \ $(BINDIR)/$(CONFIG)/client_channel_stress_test \ @@ -1800,7 +1749,6 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/filter_end2end_test \ $(BINDIR)/$(CONFIG)/generic_end2end_test \ $(BINDIR)/$(CONFIG)/golden_file_test \ - $(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test \ $(BINDIR)/$(CONFIG)/grpc_cli \ $(BINDIR)/$(CONFIG)/grpc_tool_test \ $(BINDIR)/$(CONFIG)/grpclb_api_test \ @@ -1852,7 +1800,6 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/thread_manager_test \ $(BINDIR)/$(CONFIG)/thread_stress_test \ $(BINDIR)/$(CONFIG)/transport_pid_controller_test \ - $(BINDIR)/$(CONFIG)/transport_security_common_api_test \ $(BINDIR)/$(CONFIG)/writes_per_rpc_test \ $(BINDIR)/$(CONFIG)/resolver_component_test_unsecure \ $(BINDIR)/$(CONFIG)/resolver_component_test \ @@ -2139,32 +2086,6 @@ flaky_test_c: buildtests_c test_cxx: buildtests_cxx $(E) "[RUN] Testing alarm_test" $(Q) $(BINDIR)/$(CONFIG)/alarm_test || ( echo test alarm_test failed ; exit 1 ) - $(E) "[RUN] Testing alts_counter_test" - $(Q) $(BINDIR)/$(CONFIG)/alts_counter_test || ( echo test alts_counter_test failed ; exit 1 ) - $(E) "[RUN] Testing alts_crypt_test" - $(Q) $(BINDIR)/$(CONFIG)/alts_crypt_test || ( echo test alts_crypt_test failed ; exit 1 ) - $(E) "[RUN] Testing alts_crypter_test" - $(Q) $(BINDIR)/$(CONFIG)/alts_crypter_test || ( echo test alts_crypter_test failed ; exit 1 ) - $(E) "[RUN] Testing alts_frame_handler_test" - $(Q) $(BINDIR)/$(CONFIG)/alts_frame_handler_test || ( echo test alts_frame_handler_test failed ; exit 1 ) - $(E) "[RUN] Testing alts_frame_protector_test" - $(Q) $(BINDIR)/$(CONFIG)/alts_frame_protector_test || ( echo test alts_frame_protector_test failed ; exit 1 ) - $(E) "[RUN] Testing alts_grpc_record_protocol_test" - $(Q) $(BINDIR)/$(CONFIG)/alts_grpc_record_protocol_test || ( echo test alts_grpc_record_protocol_test failed ; exit 1 ) - $(E) "[RUN] Testing alts_handshaker_client_test" - $(Q) $(BINDIR)/$(CONFIG)/alts_handshaker_client_test || ( echo test alts_handshaker_client_test failed ; exit 1 ) - $(E) "[RUN] Testing alts_handshaker_service_api_test" - $(Q) $(BINDIR)/$(CONFIG)/alts_handshaker_service_api_test || ( echo test alts_handshaker_service_api_test failed ; exit 1 ) - $(E) "[RUN] Testing alts_iovec_record_protocol_test" - $(Q) $(BINDIR)/$(CONFIG)/alts_iovec_record_protocol_test || ( echo test alts_iovec_record_protocol_test failed ; exit 1 ) - $(E) "[RUN] Testing alts_security_connector_test" - $(Q) $(BINDIR)/$(CONFIG)/alts_security_connector_test || ( echo test alts_security_connector_test failed ; exit 1 ) - $(E) "[RUN] Testing alts_tsi_handshaker_test" - $(Q) $(BINDIR)/$(CONFIG)/alts_tsi_handshaker_test || ( echo test alts_tsi_handshaker_test failed ; exit 1 ) - $(E) "[RUN] Testing alts_tsi_utils_test" - $(Q) $(BINDIR)/$(CONFIG)/alts_tsi_utils_test || ( echo test alts_tsi_utils_test failed ; exit 1 ) - $(E) "[RUN] Testing alts_zero_copy_grpc_protector_test" - $(Q) $(BINDIR)/$(CONFIG)/alts_zero_copy_grpc_protector_test || ( echo test alts_zero_copy_grpc_protector_test failed ; exit 1 ) $(E) "[RUN] Testing async_end2end_test" $(Q) $(BINDIR)/$(CONFIG)/async_end2end_test || ( echo test async_end2end_test failed ; exit 1 ) $(E) "[RUN] Testing auth_property_iterator_test" @@ -2205,10 +2126,6 @@ test_cxx: buildtests_cxx $(Q) $(BINDIR)/$(CONFIG)/channel_arguments_test || ( echo test channel_arguments_test failed ; exit 1 ) $(E) "[RUN] Testing channel_filter_test" $(Q) $(BINDIR)/$(CONFIG)/channel_filter_test || ( echo test channel_filter_test failed ; exit 1 ) - $(E) "[RUN] Testing check_gcp_environment_linux_test" - $(Q) $(BINDIR)/$(CONFIG)/check_gcp_environment_linux_test || ( echo test check_gcp_environment_linux_test failed ; exit 1 ) - $(E) "[RUN] Testing check_gcp_environment_windows_test" - $(Q) $(BINDIR)/$(CONFIG)/check_gcp_environment_windows_test || ( echo test check_gcp_environment_windows_test failed ; exit 1 ) $(E) "[RUN] Testing chttp2_settings_timeout_test" $(Q) $(BINDIR)/$(CONFIG)/chttp2_settings_timeout_test || ( echo test chttp2_settings_timeout_test failed ; exit 1 ) $(E) "[RUN] Testing cli_call_test" @@ -2245,8 +2162,6 @@ test_cxx: buildtests_cxx $(Q) $(BINDIR)/$(CONFIG)/generic_end2end_test || ( echo test generic_end2end_test failed ; exit 1 ) $(E) "[RUN] Testing golden_file_test" $(Q) $(BINDIR)/$(CONFIG)/golden_file_test || ( echo test golden_file_test failed ; exit 1 ) - $(E) "[RUN] Testing grpc_alts_credentials_options_test" - $(Q) $(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test || ( echo test grpc_alts_credentials_options_test failed ; exit 1 ) $(E) "[RUN] Testing grpc_tool_test" $(Q) $(BINDIR)/$(CONFIG)/grpc_tool_test || ( echo test grpc_tool_test failed ; exit 1 ) $(E) "[RUN] Testing grpclb_api_test" @@ -2321,8 +2236,6 @@ test_cxx: buildtests_cxx $(Q) $(BINDIR)/$(CONFIG)/thread_stress_test || ( echo test thread_stress_test failed ; exit 1 ) $(E) "[RUN] Testing transport_pid_controller_test" $(Q) $(BINDIR)/$(CONFIG)/transport_pid_controller_test || ( echo test transport_pid_controller_test failed ; exit 1 ) - $(E) "[RUN] Testing transport_security_common_api_test" - $(Q) $(BINDIR)/$(CONFIG)/transport_security_common_api_test || ( echo test transport_security_common_api_test failed ; exit 1 ) $(E) "[RUN] Testing writes_per_rpc_test" $(Q) $(BINDIR)/$(CONFIG)/writes_per_rpc_test || ( echo test writes_per_rpc_test failed ; exit 1 ) $(E) "[RUN] Testing resolver_component_tests_runner_invoker_unsecure" @@ -2980,46 +2893,6 @@ clean: # The various libraries -LIBALTS_TEST_UTIL_SRC = \ - test/core/tsi/alts/crypt/gsec_test_util.cc \ - test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc \ - -PUBLIC_HEADERS_C += \ - -LIBALTS_TEST_UTIL_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBALTS_TEST_UTIL_SRC)))) - - -ifeq ($(NO_SECURE),true) - -# You can't build secure libraries if you don't have OpenSSL. - -$(LIBDIR)/$(CONFIG)/libalts_test_util.a: openssl_dep_error - - -else - - -$(LIBDIR)/$(CONFIG)/libalts_test_util.a: $(ZLIB_DEP) $(OPENSSL_DEP) $(CARES_DEP) $(LIBALTS_TEST_UTIL_OBJS) - $(E) "[AR] Creating $@" - $(Q) mkdir -p `dirname $@` - $(Q) rm -f $(LIBDIR)/$(CONFIG)/libalts_test_util.a - $(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBALTS_TEST_UTIL_OBJS) -ifeq ($(SYSTEM),Darwin) - $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/libalts_test_util.a -endif - - - - -endif - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(LIBALTS_TEST_UTIL_OBJS:.o=.dep) -endif -endif - - LIBGPR_SRC = \ src/core/lib/gpr/alloc.cc \ src/core/lib/gpr/arena.cc \ @@ -3322,7 +3195,6 @@ LIBGRPC_SRC = \ src/core/ext/filters/http/server/http_server_filter.cc \ src/core/lib/http/httpcli_security_connector.cc \ src/core/lib/security/context/security_context.cc \ - src/core/lib/security/credentials/alts/alts_credentials.cc \ src/core/lib/security/credentials/composite/composite_credentials.cc \ src/core/lib/security/credentials/credentials.cc \ src/core/lib/security/credentials/credentials_metadata.cc \ @@ -3336,7 +3208,6 @@ LIBGRPC_SRC = \ src/core/lib/security/credentials/oauth2/oauth2_credentials.cc \ src/core/lib/security/credentials/plugin/plugin_credentials.cc \ src/core/lib/security/credentials/ssl/ssl_credentials.cc \ - src/core/lib/security/security_connector/alts_security_connector.cc \ src/core/lib/security/security_connector/security_connector.cc \ src/core/lib/security/transport/client_auth_filter.cc \ src/core/lib/security/transport/secure_endpoint.cc \ @@ -3346,45 +3217,14 @@ LIBGRPC_SRC = \ src/core/lib/security/transport/tsi_error.cc \ src/core/lib/security/util/json_util.cc \ src/core/lib/surface/init_secure.cc \ - src/core/tsi/alts/crypt/aes_gcm.cc \ - src/core/tsi/alts/crypt/gsec.cc \ - src/core/tsi/alts/frame_protector/alts_counter.cc \ - src/core/tsi/alts/frame_protector/alts_crypter.cc \ - src/core/tsi/alts/frame_protector/alts_frame_protector.cc \ - src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc \ - src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc \ - src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc \ - src/core/tsi/alts/frame_protector/frame_handler.cc \ - src/core/tsi/alts/handshaker/alts_handshaker_client.cc \ - src/core/tsi/alts/handshaker/alts_tsi_event.cc \ - src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc \ - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc \ - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc \ - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc \ - src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc \ - src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc \ - src/core/lib/security/credentials/alts/check_gcp_environment.cc \ - src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc \ - src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc \ - src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc \ - src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc \ - src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc \ - src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc \ - src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc \ - src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc \ - src/core/tsi/alts/handshaker/alts_tsi_utils.cc \ - src/core/tsi/alts/handshaker/transport_security_common_api.cc \ - src/core/tsi/alts/handshaker/altscontext.pb.c \ - src/core/tsi/alts/handshaker/handshaker.pb.c \ - src/core/tsi/alts/handshaker/transport_security_common.pb.c \ - third_party/nanopb/pb_common.c \ - third_party/nanopb/pb_decode.c \ - third_party/nanopb/pb_encode.c \ + src/core/tsi/alts_transport_security.cc \ + src/core/tsi/fake_transport_security.cc \ + src/core/tsi/ssl_transport_security.cc \ + src/core/tsi/transport_security_grpc.cc \ src/core/tsi/transport_security.cc \ src/core/tsi/transport_security_adapter.cc \ - src/core/ext/transport/chttp2/client/insecure/channel_create.cc \ - src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \ - src/core/ext/transport/chttp2/client/chttp2_connector.cc \ + src/core/ext/transport/chttp2/server/chttp2_server.cc \ + src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ src/core/ext/filters/client_channel/client_channel.cc \ @@ -3408,14 +3248,11 @@ LIBGRPC_SRC = \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ src/core/ext/filters/deadline/deadline_filter.cc \ - src/core/tsi/alts_transport_security.cc \ - src/core/tsi/fake_transport_security.cc \ - src/core/tsi/ssl_transport_security.cc \ - src/core/tsi/transport_security_grpc.cc \ - src/core/ext/transport/chttp2/server/chttp2_server.cc \ - src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc \ + src/core/ext/transport/chttp2/client/chttp2_connector.cc \ src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc \ src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc \ + src/core/ext/transport/chttp2/client/insecure/channel_create.cc \ + src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \ src/core/ext/transport/inproc/inproc_plugin.cc \ src/core/ext/transport/inproc/inproc_transport.cc \ src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc \ @@ -3424,6 +3261,9 @@ LIBGRPC_SRC = \ src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc \ src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc \ src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c \ + third_party/nanopb/pb_common.c \ + third_party/nanopb/pb_decode.c \ + third_party/nanopb/pb_encode.c \ src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc \ src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc \ src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc \ @@ -3725,7 +3565,6 @@ LIBGRPC_CRONET_SRC = \ src/core/ext/filters/deadline/deadline_filter.cc \ src/core/lib/http/httpcli_security_connector.cc \ src/core/lib/security/context/security_context.cc \ - src/core/lib/security/credentials/alts/alts_credentials.cc \ src/core/lib/security/credentials/composite/composite_credentials.cc \ src/core/lib/security/credentials/credentials.cc \ src/core/lib/security/credentials/credentials_metadata.cc \ @@ -3739,7 +3578,6 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/security/credentials/oauth2/oauth2_credentials.cc \ src/core/lib/security/credentials/plugin/plugin_credentials.cc \ src/core/lib/security/credentials/ssl/ssl_credentials.cc \ - src/core/lib/security/security_connector/alts_security_connector.cc \ src/core/lib/security/security_connector/security_connector.cc \ src/core/lib/security/transport/client_auth_filter.cc \ src/core/lib/security/transport/secure_endpoint.cc \ @@ -3749,49 +3587,13 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/security/transport/tsi_error.cc \ src/core/lib/security/util/json_util.cc \ src/core/lib/surface/init_secure.cc \ - src/core/tsi/alts/crypt/aes_gcm.cc \ - src/core/tsi/alts/crypt/gsec.cc \ - src/core/tsi/alts/frame_protector/alts_counter.cc \ - src/core/tsi/alts/frame_protector/alts_crypter.cc \ - src/core/tsi/alts/frame_protector/alts_frame_protector.cc \ - src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc \ - src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc \ - src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc \ - src/core/tsi/alts/frame_protector/frame_handler.cc \ - src/core/tsi/alts/handshaker/alts_handshaker_client.cc \ - src/core/tsi/alts/handshaker/alts_tsi_event.cc \ - src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc \ - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc \ - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc \ - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc \ - src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc \ - src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc \ - src/core/lib/security/credentials/alts/check_gcp_environment.cc \ - src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc \ - src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc \ - src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc \ - src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc \ - src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc \ - src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc \ - src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc \ - src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc \ - src/core/tsi/alts/handshaker/alts_tsi_utils.cc \ - src/core/tsi/alts/handshaker/transport_security_common_api.cc \ - src/core/tsi/alts/handshaker/altscontext.pb.c \ - src/core/tsi/alts/handshaker/handshaker.pb.c \ - src/core/tsi/alts/handshaker/transport_security_common.pb.c \ - third_party/nanopb/pb_common.c \ - third_party/nanopb/pb_decode.c \ - third_party/nanopb/pb_encode.c \ - src/core/tsi/transport_security.cc \ - src/core/tsi/transport_security_adapter.cc \ - src/core/ext/transport/chttp2/client/insecure/channel_create.cc \ - src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \ - src/core/ext/transport/chttp2/client/chttp2_connector.cc \ src/core/tsi/alts_transport_security.cc \ src/core/tsi/fake_transport_security.cc \ src/core/tsi/ssl_transport_security.cc \ src/core/tsi/transport_security_grpc.cc \ + src/core/tsi/transport_security.cc \ + src/core/tsi/transport_security_adapter.cc \ + src/core/ext/transport/chttp2/client/chttp2_connector.cc \ src/core/ext/filters/load_reporting/server_load_reporting_filter.cc \ src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc \ src/core/plugin_registry/grpc_cronet_plugin_registry.cc \ @@ -14439,15 +14241,15 @@ endif endif -ALTS_COUNTER_TEST_SRC = \ - test/core/tsi/alts/frame_protector/alts_counter_test.cc \ +ASYNC_END2END_TEST_SRC = \ + test/cpp/end2end/async_end2end_test.cc \ -ALTS_COUNTER_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ALTS_COUNTER_TEST_SRC)))) +ASYNC_END2END_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ASYNC_END2END_TEST_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/alts_counter_test: openssl_dep_error +$(BINDIR)/$(CONFIG)/async_end2end_test: openssl_dep_error else @@ -14458,39 +14260,39 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/alts_counter_test: protobuf_dep_error +$(BINDIR)/$(CONFIG)/async_end2end_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/alts_counter_test: $(PROTOBUF_DEP) $(ALTS_COUNTER_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a +$(BINDIR)/$(CONFIG)/async_end2end_test: $(PROTOBUF_DEP) $(ASYNC_END2END_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(ALTS_COUNTER_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/alts_counter_test + $(Q) $(LDXX) $(LDFLAGS) $(ASYNC_END2END_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/async_end2end_test endif endif -$(OBJDIR)/$(CONFIG)/test/core/tsi/alts/frame_protector/alts_counter_test.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a +$(OBJDIR)/$(CONFIG)/test/cpp/end2end/async_end2end_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a -deps_alts_counter_test: $(ALTS_COUNTER_TEST_OBJS:.o=.dep) +deps_async_end2end_test: $(ASYNC_END2END_TEST_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(ALTS_COUNTER_TEST_OBJS:.o=.dep) +-include $(ASYNC_END2END_TEST_OBJS:.o=.dep) endif endif -ALTS_CRYPT_TEST_SRC = \ - test/core/tsi/alts/crypt/aes_gcm_test.cc \ +AUTH_PROPERTY_ITERATOR_TEST_SRC = \ + test/cpp/common/auth_property_iterator_test.cc \ -ALTS_CRYPT_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ALTS_CRYPT_TEST_SRC)))) +AUTH_PROPERTY_ITERATOR_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(AUTH_PROPERTY_ITERATOR_TEST_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/alts_crypt_test: openssl_dep_error +$(BINDIR)/$(CONFIG)/auth_property_iterator_test: openssl_dep_error else @@ -14501,39 +14303,39 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/alts_crypt_test: protobuf_dep_error +$(BINDIR)/$(CONFIG)/auth_property_iterator_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/alts_crypt_test: $(PROTOBUF_DEP) $(ALTS_CRYPT_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a +$(BINDIR)/$(CONFIG)/auth_property_iterator_test: $(PROTOBUF_DEP) $(AUTH_PROPERTY_ITERATOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(ALTS_CRYPT_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/alts_crypt_test + $(Q) $(LDXX) $(LDFLAGS) $(AUTH_PROPERTY_ITERATOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/auth_property_iterator_test endif endif -$(OBJDIR)/$(CONFIG)/test/core/tsi/alts/crypt/aes_gcm_test.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a +$(OBJDIR)/$(CONFIG)/test/cpp/common/auth_property_iterator_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a -deps_alts_crypt_test: $(ALTS_CRYPT_TEST_OBJS:.o=.dep) +deps_auth_property_iterator_test: $(AUTH_PROPERTY_ITERATOR_TEST_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(ALTS_CRYPT_TEST_OBJS:.o=.dep) +-include $(AUTH_PROPERTY_ITERATOR_TEST_OBJS:.o=.dep) endif endif -ALTS_CRYPTER_TEST_SRC = \ - test/core/tsi/alts/frame_protector/alts_crypter_test.cc \ +BACKOFF_TEST_SRC = \ + test/core/backoff/backoff_test.cc \ -ALTS_CRYPTER_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ALTS_CRYPTER_TEST_SRC)))) +BACKOFF_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BACKOFF_TEST_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/alts_crypter_test: openssl_dep_error +$(BINDIR)/$(CONFIG)/backoff_test: openssl_dep_error else @@ -14544,39 +14346,39 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/alts_crypter_test: protobuf_dep_error +$(BINDIR)/$(CONFIG)/backoff_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/alts_crypter_test: $(PROTOBUF_DEP) $(ALTS_CRYPTER_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a +$(BINDIR)/$(CONFIG)/backoff_test: $(PROTOBUF_DEP) $(BACKOFF_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(ALTS_CRYPTER_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/alts_crypter_test + $(Q) $(LDXX) $(LDFLAGS) $(BACKOFF_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/backoff_test endif endif -$(OBJDIR)/$(CONFIG)/test/core/tsi/alts/frame_protector/alts_crypter_test.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a +$(OBJDIR)/$(CONFIG)/test/core/backoff/backoff_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a -deps_alts_crypter_test: $(ALTS_CRYPTER_TEST_OBJS:.o=.dep) +deps_backoff_test: $(BACKOFF_TEST_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(ALTS_CRYPTER_TEST_OBJS:.o=.dep) +-include $(BACKOFF_TEST_OBJS:.o=.dep) endif endif -ALTS_FRAME_HANDLER_TEST_SRC = \ - test/core/tsi/alts/frame_protector/frame_handler_test.cc \ +BDP_ESTIMATOR_TEST_SRC = \ + test/core/transport/bdp_estimator_test.cc \ -ALTS_FRAME_HANDLER_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ALTS_FRAME_HANDLER_TEST_SRC)))) +BDP_ESTIMATOR_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BDP_ESTIMATOR_TEST_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/alts_frame_handler_test: openssl_dep_error +$(BINDIR)/$(CONFIG)/bdp_estimator_test: openssl_dep_error else @@ -14587,40 +14389,39 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/alts_frame_handler_test: protobuf_dep_error +$(BINDIR)/$(CONFIG)/bdp_estimator_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/alts_frame_handler_test: $(PROTOBUF_DEP) $(ALTS_FRAME_HANDLER_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a +$(BINDIR)/$(CONFIG)/bdp_estimator_test: $(PROTOBUF_DEP) $(BDP_ESTIMATOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(ALTS_FRAME_HANDLER_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/alts_frame_handler_test + $(Q) $(LDXX) $(LDFLAGS) $(BDP_ESTIMATOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bdp_estimator_test endif endif -$(OBJDIR)/$(CONFIG)/test/core/tsi/alts/frame_protector/frame_handler_test.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a +$(OBJDIR)/$(CONFIG)/test/core/transport/bdp_estimator_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a -deps_alts_frame_handler_test: $(ALTS_FRAME_HANDLER_TEST_OBJS:.o=.dep) +deps_bdp_estimator_test: $(BDP_ESTIMATOR_TEST_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(ALTS_FRAME_HANDLER_TEST_OBJS:.o=.dep) +-include $(BDP_ESTIMATOR_TEST_OBJS:.o=.dep) endif endif -ALTS_FRAME_PROTECTOR_TEST_SRC = \ - test/core/tsi/alts/frame_protector/alts_frame_protector_test.cc \ - test/core/tsi/transport_security_test_lib.cc \ +BM_ARENA_SRC = \ + test/cpp/microbenchmarks/bm_arena.cc \ -ALTS_FRAME_PROTECTOR_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ALTS_FRAME_PROTECTOR_TEST_SRC)))) +BM_ARENA_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_ARENA_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/alts_frame_protector_test: openssl_dep_error +$(BINDIR)/$(CONFIG)/bm_arena: openssl_dep_error else @@ -14631,41 +14432,40 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/alts_frame_protector_test: protobuf_dep_error +$(BINDIR)/$(CONFIG)/bm_arena: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/alts_frame_protector_test: $(PROTOBUF_DEP) $(ALTS_FRAME_PROTECTOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a +$(BINDIR)/$(CONFIG)/bm_arena: $(PROTOBUF_DEP) $(BM_ARENA_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(ALTS_FRAME_PROTECTOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/alts_frame_protector_test + $(Q) $(LDXX) $(LDFLAGS) $(BM_ARENA_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_arena endif endif -$(OBJDIR)/$(CONFIG)/test/core/tsi/alts/frame_protector/alts_frame_protector_test.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a - -$(OBJDIR)/$(CONFIG)/test/core/tsi/transport_security_test_lib.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a +$(BM_ARENA_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX +$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_arena.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a -deps_alts_frame_protector_test: $(ALTS_FRAME_PROTECTOR_TEST_OBJS:.o=.dep) +deps_bm_arena: $(BM_ARENA_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(ALTS_FRAME_PROTECTOR_TEST_OBJS:.o=.dep) +-include $(BM_ARENA_OBJS:.o=.dep) endif endif -ALTS_GRPC_RECORD_PROTOCOL_TEST_SRC = \ - test/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_test.cc \ +BM_CALL_CREATE_SRC = \ + test/cpp/microbenchmarks/bm_call_create.cc \ -ALTS_GRPC_RECORD_PROTOCOL_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ALTS_GRPC_RECORD_PROTOCOL_TEST_SRC)))) +BM_CALL_CREATE_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_CALL_CREATE_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/alts_grpc_record_protocol_test: openssl_dep_error +$(BINDIR)/$(CONFIG)/bm_call_create: openssl_dep_error else @@ -14676,39 +14476,40 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/alts_grpc_record_protocol_test: protobuf_dep_error +$(BINDIR)/$(CONFIG)/bm_call_create: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/alts_grpc_record_protocol_test: $(PROTOBUF_DEP) $(ALTS_GRPC_RECORD_PROTOCOL_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a +$(BINDIR)/$(CONFIG)/bm_call_create: $(PROTOBUF_DEP) $(BM_CALL_CREATE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(ALTS_GRPC_RECORD_PROTOCOL_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/alts_grpc_record_protocol_test + $(Q) $(LDXX) $(LDFLAGS) $(BM_CALL_CREATE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_call_create endif endif -$(OBJDIR)/$(CONFIG)/test/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_test.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a +$(BM_CALL_CREATE_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX +$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_call_create.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a -deps_alts_grpc_record_protocol_test: $(ALTS_GRPC_RECORD_PROTOCOL_TEST_OBJS:.o=.dep) +deps_bm_call_create: $(BM_CALL_CREATE_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(ALTS_GRPC_RECORD_PROTOCOL_TEST_OBJS:.o=.dep) +-include $(BM_CALL_CREATE_OBJS:.o=.dep) endif endif -ALTS_HANDSHAKER_CLIENT_TEST_SRC = \ - test/core/tsi/alts/handshaker/alts_handshaker_client_test.cc \ +BM_CHTTP2_HPACK_SRC = \ + test/cpp/microbenchmarks/bm_chttp2_hpack.cc \ -ALTS_HANDSHAKER_CLIENT_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ALTS_HANDSHAKER_CLIENT_TEST_SRC)))) +BM_CHTTP2_HPACK_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_CHTTP2_HPACK_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/alts_handshaker_client_test: openssl_dep_error +$(BINDIR)/$(CONFIG)/bm_chttp2_hpack: openssl_dep_error else @@ -14719,39 +14520,40 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/alts_handshaker_client_test: protobuf_dep_error +$(BINDIR)/$(CONFIG)/bm_chttp2_hpack: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/alts_handshaker_client_test: $(PROTOBUF_DEP) $(ALTS_HANDSHAKER_CLIENT_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a +$(BINDIR)/$(CONFIG)/bm_chttp2_hpack: $(PROTOBUF_DEP) $(BM_CHTTP2_HPACK_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(ALTS_HANDSHAKER_CLIENT_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/alts_handshaker_client_test + $(Q) $(LDXX) $(LDFLAGS) $(BM_CHTTP2_HPACK_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_chttp2_hpack endif endif -$(OBJDIR)/$(CONFIG)/test/core/tsi/alts/handshaker/alts_handshaker_client_test.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a +$(BM_CHTTP2_HPACK_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX +$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_chttp2_hpack.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a -deps_alts_handshaker_client_test: $(ALTS_HANDSHAKER_CLIENT_TEST_OBJS:.o=.dep) +deps_bm_chttp2_hpack: $(BM_CHTTP2_HPACK_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(ALTS_HANDSHAKER_CLIENT_TEST_OBJS:.o=.dep) +-include $(BM_CHTTP2_HPACK_OBJS:.o=.dep) endif endif -ALTS_HANDSHAKER_SERVICE_API_TEST_SRC = \ - test/core/tsi/alts/handshaker/alts_handshaker_service_api_test.cc \ +BM_CHTTP2_TRANSPORT_SRC = \ + test/cpp/microbenchmarks/bm_chttp2_transport.cc \ -ALTS_HANDSHAKER_SERVICE_API_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ALTS_HANDSHAKER_SERVICE_API_TEST_SRC)))) +BM_CHTTP2_TRANSPORT_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_CHTTP2_TRANSPORT_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/alts_handshaker_service_api_test: openssl_dep_error +$(BINDIR)/$(CONFIG)/bm_chttp2_transport: openssl_dep_error else @@ -14762,39 +14564,40 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/alts_handshaker_service_api_test: protobuf_dep_error +$(BINDIR)/$(CONFIG)/bm_chttp2_transport: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/alts_handshaker_service_api_test: $(PROTOBUF_DEP) $(ALTS_HANDSHAKER_SERVICE_API_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a +$(BINDIR)/$(CONFIG)/bm_chttp2_transport: $(PROTOBUF_DEP) $(BM_CHTTP2_TRANSPORT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(ALTS_HANDSHAKER_SERVICE_API_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/alts_handshaker_service_api_test + $(Q) $(LDXX) $(LDFLAGS) $(BM_CHTTP2_TRANSPORT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_chttp2_transport endif endif -$(OBJDIR)/$(CONFIG)/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a +$(BM_CHTTP2_TRANSPORT_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX +$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_chttp2_transport.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a -deps_alts_handshaker_service_api_test: $(ALTS_HANDSHAKER_SERVICE_API_TEST_OBJS:.o=.dep) +deps_bm_chttp2_transport: $(BM_CHTTP2_TRANSPORT_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(ALTS_HANDSHAKER_SERVICE_API_TEST_OBJS:.o=.dep) +-include $(BM_CHTTP2_TRANSPORT_OBJS:.o=.dep) endif endif -ALTS_IOVEC_RECORD_PROTOCOL_TEST_SRC = \ - test/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol_test.cc \ +BM_CLOSURE_SRC = \ + test/cpp/microbenchmarks/bm_closure.cc \ -ALTS_IOVEC_RECORD_PROTOCOL_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ALTS_IOVEC_RECORD_PROTOCOL_TEST_SRC)))) +BM_CLOSURE_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_CLOSURE_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/alts_iovec_record_protocol_test: openssl_dep_error +$(BINDIR)/$(CONFIG)/bm_closure: openssl_dep_error else @@ -14805,39 +14608,40 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/alts_iovec_record_protocol_test: protobuf_dep_error +$(BINDIR)/$(CONFIG)/bm_closure: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/alts_iovec_record_protocol_test: $(PROTOBUF_DEP) $(ALTS_IOVEC_RECORD_PROTOCOL_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a +$(BINDIR)/$(CONFIG)/bm_closure: $(PROTOBUF_DEP) $(BM_CLOSURE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(ALTS_IOVEC_RECORD_PROTOCOL_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/alts_iovec_record_protocol_test + $(Q) $(LDXX) $(LDFLAGS) $(BM_CLOSURE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_closure endif endif -$(OBJDIR)/$(CONFIG)/test/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol_test.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a +$(BM_CLOSURE_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX +$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_closure.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a -deps_alts_iovec_record_protocol_test: $(ALTS_IOVEC_RECORD_PROTOCOL_TEST_OBJS:.o=.dep) +deps_bm_closure: $(BM_CLOSURE_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(ALTS_IOVEC_RECORD_PROTOCOL_TEST_OBJS:.o=.dep) +-include $(BM_CLOSURE_OBJS:.o=.dep) endif endif -ALTS_SECURITY_CONNECTOR_TEST_SRC = \ - test/core/security/alts_security_connector_test.cc \ +BM_CQ_SRC = \ + test/cpp/microbenchmarks/bm_cq.cc \ -ALTS_SECURITY_CONNECTOR_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ALTS_SECURITY_CONNECTOR_TEST_SRC)))) +BM_CQ_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_CQ_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/alts_security_connector_test: openssl_dep_error +$(BINDIR)/$(CONFIG)/bm_cq: openssl_dep_error else @@ -14848,39 +14652,40 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/alts_security_connector_test: protobuf_dep_error +$(BINDIR)/$(CONFIG)/bm_cq: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/alts_security_connector_test: $(PROTOBUF_DEP) $(ALTS_SECURITY_CONNECTOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a +$(BINDIR)/$(CONFIG)/bm_cq: $(PROTOBUF_DEP) $(BM_CQ_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(ALTS_SECURITY_CONNECTOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/alts_security_connector_test + $(Q) $(LDXX) $(LDFLAGS) $(BM_CQ_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_cq endif endif -$(OBJDIR)/$(CONFIG)/test/core/security/alts_security_connector_test.o: $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a +$(BM_CQ_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX +$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_cq.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a -deps_alts_security_connector_test: $(ALTS_SECURITY_CONNECTOR_TEST_OBJS:.o=.dep) +deps_bm_cq: $(BM_CQ_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(ALTS_SECURITY_CONNECTOR_TEST_OBJS:.o=.dep) +-include $(BM_CQ_OBJS:.o=.dep) endif endif -ALTS_TSI_HANDSHAKER_TEST_SRC = \ - test/core/tsi/alts/handshaker/alts_tsi_handshaker_test.cc \ +BM_CQ_MULTIPLE_THREADS_SRC = \ + test/cpp/microbenchmarks/bm_cq_multiple_threads.cc \ -ALTS_TSI_HANDSHAKER_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ALTS_TSI_HANDSHAKER_TEST_SRC)))) +BM_CQ_MULTIPLE_THREADS_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_CQ_MULTIPLE_THREADS_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/alts_tsi_handshaker_test: openssl_dep_error +$(BINDIR)/$(CONFIG)/bm_cq_multiple_threads: openssl_dep_error else @@ -14891,39 +14696,40 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/alts_tsi_handshaker_test: protobuf_dep_error +$(BINDIR)/$(CONFIG)/bm_cq_multiple_threads: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/alts_tsi_handshaker_test: $(PROTOBUF_DEP) $(ALTS_TSI_HANDSHAKER_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a +$(BINDIR)/$(CONFIG)/bm_cq_multiple_threads: $(PROTOBUF_DEP) $(BM_CQ_MULTIPLE_THREADS_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(ALTS_TSI_HANDSHAKER_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/alts_tsi_handshaker_test + $(Q) $(LDXX) $(LDFLAGS) $(BM_CQ_MULTIPLE_THREADS_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_cq_multiple_threads endif endif -$(OBJDIR)/$(CONFIG)/test/core/tsi/alts/handshaker/alts_tsi_handshaker_test.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a +$(BM_CQ_MULTIPLE_THREADS_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX +$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_cq_multiple_threads.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a -deps_alts_tsi_handshaker_test: $(ALTS_TSI_HANDSHAKER_TEST_OBJS:.o=.dep) +deps_bm_cq_multiple_threads: $(BM_CQ_MULTIPLE_THREADS_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(ALTS_TSI_HANDSHAKER_TEST_OBJS:.o=.dep) +-include $(BM_CQ_MULTIPLE_THREADS_OBJS:.o=.dep) endif endif -ALTS_TSI_UTILS_TEST_SRC = \ - test/core/tsi/alts/handshaker/alts_tsi_utils_test.cc \ +BM_ERROR_SRC = \ + test/cpp/microbenchmarks/bm_error.cc \ -ALTS_TSI_UTILS_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ALTS_TSI_UTILS_TEST_SRC)))) +BM_ERROR_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_ERROR_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/alts_tsi_utils_test: openssl_dep_error +$(BINDIR)/$(CONFIG)/bm_error: openssl_dep_error else @@ -14934,39 +14740,40 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/alts_tsi_utils_test: protobuf_dep_error +$(BINDIR)/$(CONFIG)/bm_error: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/alts_tsi_utils_test: $(PROTOBUF_DEP) $(ALTS_TSI_UTILS_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a +$(BINDIR)/$(CONFIG)/bm_error: $(PROTOBUF_DEP) $(BM_ERROR_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(ALTS_TSI_UTILS_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/alts_tsi_utils_test + $(Q) $(LDXX) $(LDFLAGS) $(BM_ERROR_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_error endif endif -$(OBJDIR)/$(CONFIG)/test/core/tsi/alts/handshaker/alts_tsi_utils_test.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a +$(BM_ERROR_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX +$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_error.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a -deps_alts_tsi_utils_test: $(ALTS_TSI_UTILS_TEST_OBJS:.o=.dep) +deps_bm_error: $(BM_ERROR_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(ALTS_TSI_UTILS_TEST_OBJS:.o=.dep) +-include $(BM_ERROR_OBJS:.o=.dep) endif endif -ALTS_ZERO_COPY_GRPC_PROTECTOR_TEST_SRC = \ - test/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector_test.cc \ +BM_FULLSTACK_STREAMING_PING_PONG_SRC = \ + test/cpp/microbenchmarks/bm_fullstack_streaming_ping_pong.cc \ -ALTS_ZERO_COPY_GRPC_PROTECTOR_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ALTS_ZERO_COPY_GRPC_PROTECTOR_TEST_SRC)))) +BM_FULLSTACK_STREAMING_PING_PONG_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_FULLSTACK_STREAMING_PING_PONG_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/alts_zero_copy_grpc_protector_test: openssl_dep_error +$(BINDIR)/$(CONFIG)/bm_fullstack_streaming_ping_pong: openssl_dep_error else @@ -14977,39 +14784,40 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/alts_zero_copy_grpc_protector_test: protobuf_dep_error +$(BINDIR)/$(CONFIG)/bm_fullstack_streaming_ping_pong: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/alts_zero_copy_grpc_protector_test: $(PROTOBUF_DEP) $(ALTS_ZERO_COPY_GRPC_PROTECTOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a +$(BINDIR)/$(CONFIG)/bm_fullstack_streaming_ping_pong: $(PROTOBUF_DEP) $(BM_FULLSTACK_STREAMING_PING_PONG_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(ALTS_ZERO_COPY_GRPC_PROTECTOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/alts_zero_copy_grpc_protector_test + $(Q) $(LDXX) $(LDFLAGS) $(BM_FULLSTACK_STREAMING_PING_PONG_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_fullstack_streaming_ping_pong endif endif -$(OBJDIR)/$(CONFIG)/test/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector_test.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a +$(BM_FULLSTACK_STREAMING_PING_PONG_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX +$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_fullstack_streaming_ping_pong.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a -deps_alts_zero_copy_grpc_protector_test: $(ALTS_ZERO_COPY_GRPC_PROTECTOR_TEST_OBJS:.o=.dep) +deps_bm_fullstack_streaming_ping_pong: $(BM_FULLSTACK_STREAMING_PING_PONG_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(ALTS_ZERO_COPY_GRPC_PROTECTOR_TEST_OBJS:.o=.dep) +-include $(BM_FULLSTACK_STREAMING_PING_PONG_OBJS:.o=.dep) endif endif -ASYNC_END2END_TEST_SRC = \ - test/cpp/end2end/async_end2end_test.cc \ +BM_FULLSTACK_STREAMING_PUMP_SRC = \ + test/cpp/microbenchmarks/bm_fullstack_streaming_pump.cc \ -ASYNC_END2END_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ASYNC_END2END_TEST_SRC)))) +BM_FULLSTACK_STREAMING_PUMP_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_FULLSTACK_STREAMING_PUMP_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/async_end2end_test: openssl_dep_error +$(BINDIR)/$(CONFIG)/bm_fullstack_streaming_pump: openssl_dep_error else @@ -15020,39 +14828,40 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/async_end2end_test: protobuf_dep_error +$(BINDIR)/$(CONFIG)/bm_fullstack_streaming_pump: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/async_end2end_test: $(PROTOBUF_DEP) $(ASYNC_END2END_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/bm_fullstack_streaming_pump: $(PROTOBUF_DEP) $(BM_FULLSTACK_STREAMING_PUMP_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(ASYNC_END2END_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/async_end2end_test + $(Q) $(LDXX) $(LDFLAGS) $(BM_FULLSTACK_STREAMING_PUMP_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_fullstack_streaming_pump endif endif -$(OBJDIR)/$(CONFIG)/test/cpp/end2end/async_end2end_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BM_FULLSTACK_STREAMING_PUMP_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX +$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_fullstack_streaming_pump.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a -deps_async_end2end_test: $(ASYNC_END2END_TEST_OBJS:.o=.dep) +deps_bm_fullstack_streaming_pump: $(BM_FULLSTACK_STREAMING_PUMP_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(ASYNC_END2END_TEST_OBJS:.o=.dep) +-include $(BM_FULLSTACK_STREAMING_PUMP_OBJS:.o=.dep) endif endif -AUTH_PROPERTY_ITERATOR_TEST_SRC = \ - test/cpp/common/auth_property_iterator_test.cc \ +BM_FULLSTACK_TRICKLE_SRC = \ + test/cpp/microbenchmarks/bm_fullstack_trickle.cc \ -AUTH_PROPERTY_ITERATOR_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(AUTH_PROPERTY_ITERATOR_TEST_SRC)))) +BM_FULLSTACK_TRICKLE_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_FULLSTACK_TRICKLE_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/auth_property_iterator_test: openssl_dep_error +$(BINDIR)/$(CONFIG)/bm_fullstack_trickle: openssl_dep_error else @@ -15063,604 +14872,35 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/auth_property_iterator_test: protobuf_dep_error +$(BINDIR)/$(CONFIG)/bm_fullstack_trickle: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/auth_property_iterator_test: $(PROTOBUF_DEP) $(AUTH_PROPERTY_ITERATOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/bm_fullstack_trickle: $(PROTOBUF_DEP) $(BM_FULLSTACK_TRICKLE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(AUTH_PROPERTY_ITERATOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/auth_property_iterator_test + $(Q) $(LDXX) $(LDFLAGS) $(BM_FULLSTACK_TRICKLE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_fullstack_trickle endif endif -$(OBJDIR)/$(CONFIG)/test/cpp/common/auth_property_iterator_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BM_FULLSTACK_TRICKLE_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX +$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_fullstack_trickle.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a -deps_auth_property_iterator_test: $(AUTH_PROPERTY_ITERATOR_TEST_OBJS:.o=.dep) +deps_bm_fullstack_trickle: $(BM_FULLSTACK_TRICKLE_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(AUTH_PROPERTY_ITERATOR_TEST_OBJS:.o=.dep) +-include $(BM_FULLSTACK_TRICKLE_OBJS:.o=.dep) endif endif -BACKOFF_TEST_SRC = \ - test/core/backoff/backoff_test.cc \ +BM_FULLSTACK_UNARY_PING_PONG_SRC = \ + test/cpp/microbenchmarks/bm_fullstack_unary_ping_pong.cc \ -BACKOFF_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BACKOFF_TEST_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/backoff_test: openssl_dep_error - -else - - - - -ifeq ($(NO_PROTOBUF),true) - -# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. - -$(BINDIR)/$(CONFIG)/backoff_test: protobuf_dep_error - -else - -$(BINDIR)/$(CONFIG)/backoff_test: $(PROTOBUF_DEP) $(BACKOFF_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(BACKOFF_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/backoff_test - -endif - -endif - -$(OBJDIR)/$(CONFIG)/test/core/backoff/backoff_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_backoff_test: $(BACKOFF_TEST_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(BACKOFF_TEST_OBJS:.o=.dep) -endif -endif - - -BDP_ESTIMATOR_TEST_SRC = \ - test/core/transport/bdp_estimator_test.cc \ - -BDP_ESTIMATOR_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BDP_ESTIMATOR_TEST_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/bdp_estimator_test: openssl_dep_error - -else - - - - -ifeq ($(NO_PROTOBUF),true) - -# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. - -$(BINDIR)/$(CONFIG)/bdp_estimator_test: protobuf_dep_error - -else - -$(BINDIR)/$(CONFIG)/bdp_estimator_test: $(PROTOBUF_DEP) $(BDP_ESTIMATOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(BDP_ESTIMATOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bdp_estimator_test - -endif - -endif - -$(OBJDIR)/$(CONFIG)/test/core/transport/bdp_estimator_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_bdp_estimator_test: $(BDP_ESTIMATOR_TEST_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(BDP_ESTIMATOR_TEST_OBJS:.o=.dep) -endif -endif - - -BM_ARENA_SRC = \ - test/cpp/microbenchmarks/bm_arena.cc \ - -BM_ARENA_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_ARENA_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/bm_arena: openssl_dep_error - -else - - - - -ifeq ($(NO_PROTOBUF),true) - -# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. - -$(BINDIR)/$(CONFIG)/bm_arena: protobuf_dep_error - -else - -$(BINDIR)/$(CONFIG)/bm_arena: $(PROTOBUF_DEP) $(BM_ARENA_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(BM_ARENA_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_arena - -endif - -endif - -$(BM_ARENA_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX -$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_arena.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_bm_arena: $(BM_ARENA_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(BM_ARENA_OBJS:.o=.dep) -endif -endif - - -BM_CALL_CREATE_SRC = \ - test/cpp/microbenchmarks/bm_call_create.cc \ - -BM_CALL_CREATE_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_CALL_CREATE_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/bm_call_create: openssl_dep_error - -else - - - - -ifeq ($(NO_PROTOBUF),true) - -# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. - -$(BINDIR)/$(CONFIG)/bm_call_create: protobuf_dep_error - -else - -$(BINDIR)/$(CONFIG)/bm_call_create: $(PROTOBUF_DEP) $(BM_CALL_CREATE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(BM_CALL_CREATE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_call_create - -endif - -endif - -$(BM_CALL_CREATE_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX -$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_call_create.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_bm_call_create: $(BM_CALL_CREATE_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(BM_CALL_CREATE_OBJS:.o=.dep) -endif -endif - - -BM_CHTTP2_HPACK_SRC = \ - test/cpp/microbenchmarks/bm_chttp2_hpack.cc \ - -BM_CHTTP2_HPACK_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_CHTTP2_HPACK_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/bm_chttp2_hpack: openssl_dep_error - -else - - - - -ifeq ($(NO_PROTOBUF),true) - -# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. - -$(BINDIR)/$(CONFIG)/bm_chttp2_hpack: protobuf_dep_error - -else - -$(BINDIR)/$(CONFIG)/bm_chttp2_hpack: $(PROTOBUF_DEP) $(BM_CHTTP2_HPACK_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(BM_CHTTP2_HPACK_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_chttp2_hpack - -endif - -endif - -$(BM_CHTTP2_HPACK_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX -$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_chttp2_hpack.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_bm_chttp2_hpack: $(BM_CHTTP2_HPACK_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(BM_CHTTP2_HPACK_OBJS:.o=.dep) -endif -endif - - -BM_CHTTP2_TRANSPORT_SRC = \ - test/cpp/microbenchmarks/bm_chttp2_transport.cc \ - -BM_CHTTP2_TRANSPORT_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_CHTTP2_TRANSPORT_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/bm_chttp2_transport: openssl_dep_error - -else - - - - -ifeq ($(NO_PROTOBUF),true) - -# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. - -$(BINDIR)/$(CONFIG)/bm_chttp2_transport: protobuf_dep_error - -else - -$(BINDIR)/$(CONFIG)/bm_chttp2_transport: $(PROTOBUF_DEP) $(BM_CHTTP2_TRANSPORT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(BM_CHTTP2_TRANSPORT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_chttp2_transport - -endif - -endif - -$(BM_CHTTP2_TRANSPORT_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX -$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_chttp2_transport.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_bm_chttp2_transport: $(BM_CHTTP2_TRANSPORT_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(BM_CHTTP2_TRANSPORT_OBJS:.o=.dep) -endif -endif - - -BM_CLOSURE_SRC = \ - test/cpp/microbenchmarks/bm_closure.cc \ - -BM_CLOSURE_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_CLOSURE_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/bm_closure: openssl_dep_error - -else - - - - -ifeq ($(NO_PROTOBUF),true) - -# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. - -$(BINDIR)/$(CONFIG)/bm_closure: protobuf_dep_error - -else - -$(BINDIR)/$(CONFIG)/bm_closure: $(PROTOBUF_DEP) $(BM_CLOSURE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(BM_CLOSURE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_closure - -endif - -endif - -$(BM_CLOSURE_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX -$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_closure.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_bm_closure: $(BM_CLOSURE_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(BM_CLOSURE_OBJS:.o=.dep) -endif -endif - - -BM_CQ_SRC = \ - test/cpp/microbenchmarks/bm_cq.cc \ - -BM_CQ_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_CQ_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/bm_cq: openssl_dep_error - -else - - - - -ifeq ($(NO_PROTOBUF),true) - -# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. - -$(BINDIR)/$(CONFIG)/bm_cq: protobuf_dep_error - -else - -$(BINDIR)/$(CONFIG)/bm_cq: $(PROTOBUF_DEP) $(BM_CQ_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(BM_CQ_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_cq - -endif - -endif - -$(BM_CQ_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX -$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_cq.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_bm_cq: $(BM_CQ_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(BM_CQ_OBJS:.o=.dep) -endif -endif - - -BM_CQ_MULTIPLE_THREADS_SRC = \ - test/cpp/microbenchmarks/bm_cq_multiple_threads.cc \ - -BM_CQ_MULTIPLE_THREADS_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_CQ_MULTIPLE_THREADS_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/bm_cq_multiple_threads: openssl_dep_error - -else - - - - -ifeq ($(NO_PROTOBUF),true) - -# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. - -$(BINDIR)/$(CONFIG)/bm_cq_multiple_threads: protobuf_dep_error - -else - -$(BINDIR)/$(CONFIG)/bm_cq_multiple_threads: $(PROTOBUF_DEP) $(BM_CQ_MULTIPLE_THREADS_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(BM_CQ_MULTIPLE_THREADS_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_cq_multiple_threads - -endif - -endif - -$(BM_CQ_MULTIPLE_THREADS_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX -$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_cq_multiple_threads.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_bm_cq_multiple_threads: $(BM_CQ_MULTIPLE_THREADS_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(BM_CQ_MULTIPLE_THREADS_OBJS:.o=.dep) -endif -endif - - -BM_ERROR_SRC = \ - test/cpp/microbenchmarks/bm_error.cc \ - -BM_ERROR_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_ERROR_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/bm_error: openssl_dep_error - -else - - - - -ifeq ($(NO_PROTOBUF),true) - -# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. - -$(BINDIR)/$(CONFIG)/bm_error: protobuf_dep_error - -else - -$(BINDIR)/$(CONFIG)/bm_error: $(PROTOBUF_DEP) $(BM_ERROR_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(BM_ERROR_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_error - -endif - -endif - -$(BM_ERROR_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX -$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_error.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_bm_error: $(BM_ERROR_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(BM_ERROR_OBJS:.o=.dep) -endif -endif - - -BM_FULLSTACK_STREAMING_PING_PONG_SRC = \ - test/cpp/microbenchmarks/bm_fullstack_streaming_ping_pong.cc \ - -BM_FULLSTACK_STREAMING_PING_PONG_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_FULLSTACK_STREAMING_PING_PONG_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/bm_fullstack_streaming_ping_pong: openssl_dep_error - -else - - - - -ifeq ($(NO_PROTOBUF),true) - -# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. - -$(BINDIR)/$(CONFIG)/bm_fullstack_streaming_ping_pong: protobuf_dep_error - -else - -$(BINDIR)/$(CONFIG)/bm_fullstack_streaming_ping_pong: $(PROTOBUF_DEP) $(BM_FULLSTACK_STREAMING_PING_PONG_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(BM_FULLSTACK_STREAMING_PING_PONG_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_fullstack_streaming_ping_pong - -endif - -endif - -$(BM_FULLSTACK_STREAMING_PING_PONG_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX -$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_fullstack_streaming_ping_pong.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_bm_fullstack_streaming_ping_pong: $(BM_FULLSTACK_STREAMING_PING_PONG_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(BM_FULLSTACK_STREAMING_PING_PONG_OBJS:.o=.dep) -endif -endif - - -BM_FULLSTACK_STREAMING_PUMP_SRC = \ - test/cpp/microbenchmarks/bm_fullstack_streaming_pump.cc \ - -BM_FULLSTACK_STREAMING_PUMP_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_FULLSTACK_STREAMING_PUMP_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/bm_fullstack_streaming_pump: openssl_dep_error - -else - - - - -ifeq ($(NO_PROTOBUF),true) - -# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. - -$(BINDIR)/$(CONFIG)/bm_fullstack_streaming_pump: protobuf_dep_error - -else - -$(BINDIR)/$(CONFIG)/bm_fullstack_streaming_pump: $(PROTOBUF_DEP) $(BM_FULLSTACK_STREAMING_PUMP_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(BM_FULLSTACK_STREAMING_PUMP_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_fullstack_streaming_pump - -endif - -endif - -$(BM_FULLSTACK_STREAMING_PUMP_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX -$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_fullstack_streaming_pump.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_bm_fullstack_streaming_pump: $(BM_FULLSTACK_STREAMING_PUMP_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(BM_FULLSTACK_STREAMING_PUMP_OBJS:.o=.dep) -endif -endif - - -BM_FULLSTACK_TRICKLE_SRC = \ - test/cpp/microbenchmarks/bm_fullstack_trickle.cc \ - -BM_FULLSTACK_TRICKLE_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_FULLSTACK_TRICKLE_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/bm_fullstack_trickle: openssl_dep_error - -else - - - - -ifeq ($(NO_PROTOBUF),true) - -# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. - -$(BINDIR)/$(CONFIG)/bm_fullstack_trickle: protobuf_dep_error - -else - -$(BINDIR)/$(CONFIG)/bm_fullstack_trickle: $(PROTOBUF_DEP) $(BM_FULLSTACK_TRICKLE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(BM_FULLSTACK_TRICKLE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_fullstack_trickle - -endif - -endif - -$(BM_FULLSTACK_TRICKLE_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX -$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_fullstack_trickle.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a - -deps_bm_fullstack_trickle: $(BM_FULLSTACK_TRICKLE_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(BM_FULLSTACK_TRICKLE_OBJS:.o=.dep) -endif -endif - - -BM_FULLSTACK_UNARY_PING_PONG_SRC = \ - test/cpp/microbenchmarks/bm_fullstack_unary_ping_pong.cc \ - -BM_FULLSTACK_UNARY_PING_PONG_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_FULLSTACK_UNARY_PING_PONG_SRC)))) +BM_FULLSTACK_UNARY_PING_PONG_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_FULLSTACK_UNARY_PING_PONG_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. @@ -15875,92 +15115,6 @@ endif endif -CHECK_GCP_ENVIRONMENT_LINUX_TEST_SRC = \ - test/core/security/check_gcp_environment_linux_test.cc \ - -CHECK_GCP_ENVIRONMENT_LINUX_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(CHECK_GCP_ENVIRONMENT_LINUX_TEST_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/check_gcp_environment_linux_test: openssl_dep_error - -else - - - - -ifeq ($(NO_PROTOBUF),true) - -# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. - -$(BINDIR)/$(CONFIG)/check_gcp_environment_linux_test: protobuf_dep_error - -else - -$(BINDIR)/$(CONFIG)/check_gcp_environment_linux_test: $(PROTOBUF_DEP) $(CHECK_GCP_ENVIRONMENT_LINUX_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(CHECK_GCP_ENVIRONMENT_LINUX_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/check_gcp_environment_linux_test - -endif - -endif - -$(OBJDIR)/$(CONFIG)/test/core/security/check_gcp_environment_linux_test.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_check_gcp_environment_linux_test: $(CHECK_GCP_ENVIRONMENT_LINUX_TEST_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(CHECK_GCP_ENVIRONMENT_LINUX_TEST_OBJS:.o=.dep) -endif -endif - - -CHECK_GCP_ENVIRONMENT_WINDOWS_TEST_SRC = \ - test/core/security/check_gcp_environment_windows_test.cc \ - -CHECK_GCP_ENVIRONMENT_WINDOWS_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(CHECK_GCP_ENVIRONMENT_WINDOWS_TEST_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/check_gcp_environment_windows_test: openssl_dep_error - -else - - - - -ifeq ($(NO_PROTOBUF),true) - -# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. - -$(BINDIR)/$(CONFIG)/check_gcp_environment_windows_test: protobuf_dep_error - -else - -$(BINDIR)/$(CONFIG)/check_gcp_environment_windows_test: $(PROTOBUF_DEP) $(CHECK_GCP_ENVIRONMENT_WINDOWS_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(CHECK_GCP_ENVIRONMENT_WINDOWS_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/check_gcp_environment_windows_test - -endif - -endif - -$(OBJDIR)/$(CONFIG)/test/core/security/check_gcp_environment_windows_test.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_check_gcp_environment_windows_test: $(CHECK_GCP_ENVIRONMENT_WINDOWS_TEST_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(CHECK_GCP_ENVIRONMENT_WINDOWS_TEST_OBJS:.o=.dep) -endif -endif - - CHTTP2_SETTINGS_TIMEOUT_TEST_SRC = \ test/core/transport/chttp2/settings_timeout_test.cc \ @@ -16826,49 +15980,6 @@ endif $(OBJDIR)/$(CONFIG)/test/cpp/codegen/golden_file_test.o: $(GENDIR)/src/proto/grpc/testing/compiler_test.pb.cc $(GENDIR)/src/proto/grpc/testing/compiler_test.grpc.pb.cc -GRPC_ALTS_CREDENTIALS_OPTIONS_TEST_SRC = \ - test/core/security/grpc_alts_credentials_options_test.cc \ - -GRPC_ALTS_CREDENTIALS_OPTIONS_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(GRPC_ALTS_CREDENTIALS_OPTIONS_TEST_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test: openssl_dep_error - -else - - - - -ifeq ($(NO_PROTOBUF),true) - -# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. - -$(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test: protobuf_dep_error - -else - -$(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test: $(PROTOBUF_DEP) $(GRPC_ALTS_CREDENTIALS_OPTIONS_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(GRPC_ALTS_CREDENTIALS_OPTIONS_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test - -endif - -endif - -$(OBJDIR)/$(CONFIG)/test/core/security/grpc_alts_credentials_options_test.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_grpc_alts_credentials_options_test: $(GRPC_ALTS_CREDENTIALS_OPTIONS_TEST_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(GRPC_ALTS_CREDENTIALS_OPTIONS_TEST_OBJS:.o=.dep) -endif -endif - - GRPC_CLI_SRC = \ test/cpp/util/grpc_cli.cc \ @@ -19322,49 +18433,6 @@ endif endif -TRANSPORT_SECURITY_COMMON_API_TEST_SRC = \ - test/core/tsi/alts/handshaker/transport_security_common_api_test.cc \ - -TRANSPORT_SECURITY_COMMON_API_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(TRANSPORT_SECURITY_COMMON_API_TEST_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/transport_security_common_api_test: openssl_dep_error - -else - - - - -ifeq ($(NO_PROTOBUF),true) - -# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. - -$(BINDIR)/$(CONFIG)/transport_security_common_api_test: protobuf_dep_error - -else - -$(BINDIR)/$(CONFIG)/transport_security_common_api_test: $(PROTOBUF_DEP) $(TRANSPORT_SECURITY_COMMON_API_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(TRANSPORT_SECURITY_COMMON_API_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/transport_security_common_api_test - -endif - -endif - -$(OBJDIR)/$(CONFIG)/test/core/tsi/alts/handshaker/transport_security_common_api_test.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a - -deps_transport_security_common_api_test: $(TRANSPORT_SECURITY_COMMON_API_TEST_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(TRANSPORT_SECURITY_COMMON_API_TEST_OBJS:.o=.dep) -endif -endif - - WRITES_PER_RPC_TEST_SRC = \ test/cpp/performance/writes_per_rpc_test.cc \ @@ -23335,14 +22403,6 @@ src/core/ext/transport/cronet/transport/cronet_api_dummy.cc: $(OPENSSL_DEP) src/core/ext/transport/cronet/transport/cronet_transport.cc: $(OPENSSL_DEP) src/core/lib/http/httpcli_security_connector.cc: $(OPENSSL_DEP) src/core/lib/security/context/security_context.cc: $(OPENSSL_DEP) -src/core/lib/security/credentials/alts/alts_credentials.cc: $(OPENSSL_DEP) -src/core/lib/security/credentials/alts/check_gcp_environment.cc: $(OPENSSL_DEP) -src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc: $(OPENSSL_DEP) -src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc: $(OPENSSL_DEP) -src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc: $(OPENSSL_DEP) -src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc: $(OPENSSL_DEP) -src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc: $(OPENSSL_DEP) -src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc: $(OPENSSL_DEP) src/core/lib/security/credentials/composite/composite_credentials.cc: $(OPENSSL_DEP) src/core/lib/security/credentials/credentials.cc: $(OPENSSL_DEP) src/core/lib/security/credentials/credentials_metadata.cc: $(OPENSSL_DEP) @@ -23356,7 +22416,6 @@ src/core/lib/security/credentials/jwt/jwt_verifier.cc: $(OPENSSL_DEP) src/core/lib/security/credentials/oauth2/oauth2_credentials.cc: $(OPENSSL_DEP) src/core/lib/security/credentials/plugin/plugin_credentials.cc: $(OPENSSL_DEP) src/core/lib/security/credentials/ssl/ssl_credentials.cc: $(OPENSSL_DEP) -src/core/lib/security/security_connector/alts_security_connector.cc: $(OPENSSL_DEP) src/core/lib/security/security_connector/security_connector.cc: $(OPENSSL_DEP) src/core/lib/security/transport/client_auth_filter.cc: $(OPENSSL_DEP) src/core/lib/security/transport/secure_endpoint.cc: $(OPENSSL_DEP) @@ -23368,30 +22427,6 @@ src/core/lib/security/util/json_util.cc: $(OPENSSL_DEP) src/core/lib/surface/init_secure.cc: $(OPENSSL_DEP) src/core/plugin_registry/grpc_cronet_plugin_registry.cc: $(OPENSSL_DEP) src/core/plugin_registry/grpc_plugin_registry.cc: $(OPENSSL_DEP) -src/core/tsi/alts/crypt/aes_gcm.cc: $(OPENSSL_DEP) -src/core/tsi/alts/crypt/gsec.cc: $(OPENSSL_DEP) -src/core/tsi/alts/frame_protector/alts_counter.cc: $(OPENSSL_DEP) -src/core/tsi/alts/frame_protector/alts_crypter.cc: $(OPENSSL_DEP) -src/core/tsi/alts/frame_protector/alts_frame_protector.cc: $(OPENSSL_DEP) -src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc: $(OPENSSL_DEP) -src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc: $(OPENSSL_DEP) -src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc: $(OPENSSL_DEP) -src/core/tsi/alts/frame_protector/frame_handler.cc: $(OPENSSL_DEP) -src/core/tsi/alts/handshaker/alts_handshaker_client.cc: $(OPENSSL_DEP) -src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc: $(OPENSSL_DEP) -src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc: $(OPENSSL_DEP) -src/core/tsi/alts/handshaker/alts_tsi_event.cc: $(OPENSSL_DEP) -src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc: $(OPENSSL_DEP) -src/core/tsi/alts/handshaker/alts_tsi_utils.cc: $(OPENSSL_DEP) -src/core/tsi/alts/handshaker/altscontext.pb.c: $(OPENSSL_DEP) -src/core/tsi/alts/handshaker/handshaker.pb.c: $(OPENSSL_DEP) -src/core/tsi/alts/handshaker/transport_security_common.pb.c: $(OPENSSL_DEP) -src/core/tsi/alts/handshaker/transport_security_common_api.cc: $(OPENSSL_DEP) -src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc: $(OPENSSL_DEP) -src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc: $(OPENSSL_DEP) -src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc: $(OPENSSL_DEP) -src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc: $(OPENSSL_DEP) -src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc: $(OPENSSL_DEP) src/core/tsi/alts_transport_security.cc: $(OPENSSL_DEP) src/core/tsi/fake_transport_security.cc: $(OPENSSL_DEP) src/core/tsi/ssl_transport_security.cc: $(OPENSSL_DEP) @@ -23419,8 +22454,6 @@ test/core/end2end/data/test_root_cert.cc: $(OPENSSL_DEP) test/core/end2end/end2end_tests.cc: $(OPENSSL_DEP) test/core/end2end/tests/call_creds.cc: $(OPENSSL_DEP) test/core/security/oauth2_utils.cc: $(OPENSSL_DEP) -test/core/tsi/alts/crypt/gsec_test_util.cc: $(OPENSSL_DEP) -test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc: $(OPENSSL_DEP) test/core/util/reconnect_server.cc: $(OPENSSL_DEP) test/core/util/test_tcp_server.cc: $(OPENSSL_DEP) test/cpp/end2end/test_service_impl.cc: $(OPENSSL_DEP) diff --git a/bazel/grpc_build_system.bzl b/bazel/grpc_build_system.bzl index 662068ad2a..7bc186265d 100644 --- a/bazel/grpc_build_system.bzl +++ b/bazel/grpc_build_system.bzl @@ -57,12 +57,6 @@ def _maybe_update_cc_library_hdrs(hdrs): ret.append(h) return ret -def _maybe_update_cc_library_defines(name): - ret = [] - if name == "alts_proto": - ret += ["PB_FIELD_16BIT=1"] - return ret - def grpc_cc_library(name, srcs = [], public_hdrs = [], hdrs = [], external_deps = [], deps = [], standalone = False, language = "C++", testonly = False, visibility = None, @@ -70,11 +64,10 @@ def grpc_cc_library(name, srcs = [], public_hdrs = [], hdrs = [], copts = [] if language.upper() == "C": copts = if_not_windows(["-std=c99"]) - defines = _maybe_update_cc_library_defines(name) native.cc_library( name = name, srcs = srcs, - defines = defines + select({"//:grpc_no_ares": ["GRPC_ARES=0"], + defines = select({"//:grpc_no_ares": ["GRPC_ARES=0"], "//conditions:default": [],}) + select({"//:remote_execution": ["GRPC_PORT_ISOLATED_RUNTIME=1"], "//conditions:default": [],}) + diff --git a/build.yaml b/build.yaml index e2bb8bfa9f..e2d194041a 100644 --- a/build.yaml +++ b/build.yaml @@ -16,84 +16,6 @@ settings: g_stands_for: gorgeous version: 1.11.0-dev filegroups: -- name: alts_proto - headers: - - src/core/tsi/alts/handshaker/altscontext.pb.h - - src/core/tsi/alts/handshaker/handshaker.pb.h - - src/core/tsi/alts/handshaker/transport_security_common.pb.h - src: - - src/core/tsi/alts/handshaker/altscontext.pb.c - - src/core/tsi/alts/handshaker/handshaker.pb.c - - src/core/tsi/alts/handshaker/transport_security_common.pb.c - uses: - - nanopb -- name: alts_tsi - headers: - - src/core/tsi/alts/crypt/gsec.h - - src/core/tsi/alts/frame_protector/alts_counter.h - - src/core/tsi/alts/frame_protector/alts_crypter.h - - src/core/tsi/alts/frame_protector/alts_frame_protector.h - - src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h - - src/core/tsi/alts/frame_protector/frame_handler.h - - src/core/tsi/alts/handshaker/alts_handshaker_client.h - - src/core/tsi/alts/handshaker/alts_tsi_event.h - - src/core/tsi/alts/handshaker/alts_tsi_handshaker.h - - src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h - - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h - - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h - - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h - - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h - - src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h - - src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h - src: - - src/core/tsi/alts/crypt/aes_gcm.cc - - src/core/tsi/alts/crypt/gsec.cc - - src/core/tsi/alts/frame_protector/alts_counter.cc - - src/core/tsi/alts/frame_protector/alts_crypter.cc - - src/core/tsi/alts/frame_protector/alts_frame_protector.cc - - src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc - - src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc - - src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc - - src/core/tsi/alts/frame_protector/frame_handler.cc - - src/core/tsi/alts/handshaker/alts_handshaker_client.cc - - src/core/tsi/alts/handshaker/alts_tsi_event.cc - - src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc - - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc - - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc - - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc - - src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc - - src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc - uses: - - alts_util - - grpc_base - - grpc_transport_chttp2_client_insecure - - tsi_interface - - tsi -- name: alts_util - headers: - - src/core/lib/security/credentials/alts/check_gcp_environment.h - - src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h - - src/core/tsi/alts/handshaker/alts_handshaker_service_api.h - - src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h - - src/core/tsi/alts/handshaker/alts_tsi_utils.h - - src/core/tsi/alts/handshaker/transport_security_common_api.h - src: - - src/core/lib/security/credentials/alts/check_gcp_environment.cc - - src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc - - src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc - - src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc - - src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc - - src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc - - src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc - - src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc - - src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc - - src/core/tsi/alts/handshaker/alts_tsi_utils.cc - - src/core/tsi/alts/handshaker/transport_security_common_api.cc - uses: - - alts_proto - - grpc_base - - tsi_interface - - nanopb - name: census public_headers: - include/grpc/census.h @@ -720,7 +642,6 @@ filegroups: - include/grpc/grpc_security.h headers: - src/core/lib/security/context/security_context.h - - src/core/lib/security/credentials/alts/alts_credentials.h - src/core/lib/security/credentials/composite/composite_credentials.h - src/core/lib/security/credentials/credentials.h - src/core/lib/security/credentials/fake/fake_credentials.h @@ -732,7 +653,6 @@ filegroups: - src/core/lib/security/credentials/oauth2/oauth2_credentials.h - src/core/lib/security/credentials/plugin/plugin_credentials.h - src/core/lib/security/credentials/ssl/ssl_credentials.h - - src/core/lib/security/security_connector/alts_security_connector.h - src/core/lib/security/security_connector/security_connector.h - src/core/lib/security/transport/auth_filters.h - src/core/lib/security/transport/secure_endpoint.h @@ -743,7 +663,6 @@ filegroups: src: - src/core/lib/http/httpcli_security_connector.cc - src/core/lib/security/context/security_context.cc - - src/core/lib/security/credentials/alts/alts_credentials.cc - src/core/lib/security/credentials/composite/composite_credentials.cc - src/core/lib/security/credentials/credentials.cc - src/core/lib/security/credentials/credentials_metadata.cc @@ -757,7 +676,6 @@ filegroups: - src/core/lib/security/credentials/oauth2/oauth2_credentials.cc - src/core/lib/security/credentials/plugin/plugin_credentials.cc - src/core/lib/security/credentials/ssl/ssl_credentials.cc - - src/core/lib/security/security_connector/alts_security_connector.cc - src/core/lib/security/security_connector/security_connector.cc - src/core/lib/security/transport/client_auth_filter.cc - src/core/lib/security/transport/secure_endpoint.cc @@ -769,7 +687,6 @@ filegroups: - src/core/lib/surface/init_secure.cc secure: true uses: - - alts_tsi - grpc_base - grpc_transport_chttp2_alpn - tsi @@ -1294,18 +1211,6 @@ filegroups: - grpc++ - grpc libs: -- name: alts_test_util - build: private - language: c - headers: - - test/core/tsi/alts/crypt/gsec_test_util.h - - test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h - src: - - test/core/tsi/alts/crypt/gsec_test_util.cc - - test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc - deps: - - grpc - secure: true - name: gpr build: all language: c @@ -3591,125 +3496,6 @@ targets: - grpc_unsecure - gpr_test_util - gpr -- name: alts_counter_test - build: test - language: c++ - src: - - test/core/tsi/alts/frame_protector/alts_counter_test.cc - deps: - - alts_test_util - - gpr - - grpc -- name: alts_crypt_test - build: test - language: c++ - src: - - test/core/tsi/alts/crypt/aes_gcm_test.cc - deps: - - alts_test_util - - gpr_test_util - - gpr - - grpc -- name: alts_crypter_test - build: test - language: c++ - src: - - test/core/tsi/alts/frame_protector/alts_crypter_test.cc - deps: - - alts_test_util - - gpr - - grpc -- name: alts_frame_handler_test - build: test - language: c++ - src: - - test/core/tsi/alts/frame_protector/frame_handler_test.cc - deps: - - alts_test_util - - gpr - - grpc -- name: alts_frame_protector_test - build: test - language: c++ - src: - - test/core/tsi/alts/frame_protector/alts_frame_protector_test.cc - deps: - - alts_test_util - - gpr - - grpc - filegroups: - - transport_security_test_lib -- name: alts_grpc_record_protocol_test - build: test - language: c++ - src: - - test/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_test.cc - deps: - - alts_test_util - - gpr - - grpc -- name: alts_handshaker_client_test - build: test - language: c++ - src: - - test/core/tsi/alts/handshaker/alts_handshaker_client_test.cc - deps: - - alts_test_util - - gpr - - grpc -- name: alts_handshaker_service_api_test - build: test - language: c++ - src: - - test/core/tsi/alts/handshaker/alts_handshaker_service_api_test.cc - deps: - - alts_test_util - - gpr - - grpc -- name: alts_iovec_record_protocol_test - build: test - language: c++ - src: - - test/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol_test.cc - deps: - - alts_test_util - - gpr - - grpc -- name: alts_security_connector_test - build: test - language: c++ - src: - - test/core/security/alts_security_connector_test.cc - deps: - - gpr - - grpc -- name: alts_tsi_handshaker_test - build: test - language: c++ - src: - - test/core/tsi/alts/handshaker/alts_tsi_handshaker_test.cc - deps: - - alts_test_util - - gpr - - grpc -- name: alts_tsi_utils_test - build: test - language: c++ - src: - - test/core/tsi/alts/handshaker/alts_tsi_utils_test.cc - deps: - - alts_test_util - - gpr - - grpc -- name: alts_zero_copy_grpc_protector_test - build: test - language: c++ - src: - - test/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector_test.cc - deps: - - alts_test_util - - gpr - - grpc - name: async_end2end_test gtest: true build: test @@ -4093,22 +3879,6 @@ targets: - grpc - gpr uses_polling: false -- name: check_gcp_environment_linux_test - build: test - language: c++ - src: - - test/core/security/check_gcp_environment_linux_test.cc - deps: - - grpc - - gpr -- name: check_gcp_environment_windows_test - build: test - language: c++ - src: - - test/core/security/check_gcp_environment_windows_test.cc - deps: - - grpc - - gpr - name: chttp2_settings_timeout_test gtest: true build: test @@ -4367,14 +4137,6 @@ targets: args: - --generated_file_path=gens/src/proto/grpc/testing/ uses_polling: false -- name: grpc_alts_credentials_options_test - build: test - language: c++ - src: - - test/core/security/grpc_alts_credentials_options_test.cc - deps: - - grpc - - gpr - name: grpc_cli build: test run: false @@ -5210,15 +4972,6 @@ targets: - grpc - gpr_test_util - gpr -- name: transport_security_common_api_test - build: test - language: c++ - src: - - test/core/tsi/alts/handshaker/transport_security_common_api_test.cc - deps: - - alts_test_util - - gpr - - grpc - name: writes_per_rpc_test gtest: true cpu_cost: 0.5 diff --git a/config.m4 b/config.m4 index 57fc2dbab9..1a055845eb 100644 --- a/config.m4 +++ b/config.m4 @@ -244,7 +244,6 @@ if test "$PHP_GRPC" != "no"; then src/core/ext/filters/http/server/http_server_filter.cc \ src/core/lib/http/httpcli_security_connector.cc \ src/core/lib/security/context/security_context.cc \ - src/core/lib/security/credentials/alts/alts_credentials.cc \ src/core/lib/security/credentials/composite/composite_credentials.cc \ src/core/lib/security/credentials/credentials.cc \ src/core/lib/security/credentials/credentials_metadata.cc \ @@ -258,7 +257,6 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/security/credentials/oauth2/oauth2_credentials.cc \ src/core/lib/security/credentials/plugin/plugin_credentials.cc \ src/core/lib/security/credentials/ssl/ssl_credentials.cc \ - src/core/lib/security/security_connector/alts_security_connector.cc \ src/core/lib/security/security_connector/security_connector.cc \ src/core/lib/security/transport/client_auth_filter.cc \ src/core/lib/security/transport/secure_endpoint.cc \ @@ -268,45 +266,14 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/security/transport/tsi_error.cc \ src/core/lib/security/util/json_util.cc \ src/core/lib/surface/init_secure.cc \ - src/core/tsi/alts/crypt/aes_gcm.cc \ - src/core/tsi/alts/crypt/gsec.cc \ - src/core/tsi/alts/frame_protector/alts_counter.cc \ - src/core/tsi/alts/frame_protector/alts_crypter.cc \ - src/core/tsi/alts/frame_protector/alts_frame_protector.cc \ - src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc \ - src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc \ - src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc \ - src/core/tsi/alts/frame_protector/frame_handler.cc \ - src/core/tsi/alts/handshaker/alts_handshaker_client.cc \ - src/core/tsi/alts/handshaker/alts_tsi_event.cc \ - src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc \ - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc \ - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc \ - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc \ - src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc \ - src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc \ - src/core/lib/security/credentials/alts/check_gcp_environment.cc \ - src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc \ - src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc \ - src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc \ - src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc \ - src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc \ - src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc \ - src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc \ - src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc \ - src/core/tsi/alts/handshaker/alts_tsi_utils.cc \ - src/core/tsi/alts/handshaker/transport_security_common_api.cc \ - src/core/tsi/alts/handshaker/altscontext.pb.c \ - src/core/tsi/alts/handshaker/handshaker.pb.c \ - src/core/tsi/alts/handshaker/transport_security_common.pb.c \ - third_party/nanopb/pb_common.c \ - third_party/nanopb/pb_decode.c \ - third_party/nanopb/pb_encode.c \ + src/core/tsi/alts_transport_security.cc \ + src/core/tsi/fake_transport_security.cc \ + src/core/tsi/ssl_transport_security.cc \ + src/core/tsi/transport_security_grpc.cc \ src/core/tsi/transport_security.cc \ src/core/tsi/transport_security_adapter.cc \ - src/core/ext/transport/chttp2/client/insecure/channel_create.cc \ - src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \ - src/core/ext/transport/chttp2/client/chttp2_connector.cc \ + src/core/ext/transport/chttp2/server/chttp2_server.cc \ + src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ src/core/ext/filters/client_channel/client_channel.cc \ @@ -330,14 +297,11 @@ if test "$PHP_GRPC" != "no"; then src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ src/core/ext/filters/deadline/deadline_filter.cc \ - src/core/tsi/alts_transport_security.cc \ - src/core/tsi/fake_transport_security.cc \ - src/core/tsi/ssl_transport_security.cc \ - src/core/tsi/transport_security_grpc.cc \ - src/core/ext/transport/chttp2/server/chttp2_server.cc \ - src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc \ + src/core/ext/transport/chttp2/client/chttp2_connector.cc \ src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc \ src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc \ + src/core/ext/transport/chttp2/client/insecure/channel_create.cc \ + src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \ src/core/ext/transport/inproc/inproc_plugin.cc \ src/core/ext/transport/inproc/inproc_transport.cc \ src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc \ @@ -346,6 +310,9 @@ if test "$PHP_GRPC" != "no"; then src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc \ src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc \ src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c \ + third_party/nanopb/pb_common.c \ + third_party/nanopb/pb_decode.c \ + third_party/nanopb/pb_encode.c \ src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc \ src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc \ src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc \ @@ -668,7 +635,6 @@ if test "$PHP_GRPC" != "no"; then PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/profiling) PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/security/context) PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/security/credentials) - PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/security/credentials/alts) PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/security/credentials/composite) PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/security/credentials/fake) PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/security/credentials/google_default) @@ -685,10 +651,6 @@ if test "$PHP_GRPC" != "no"; then PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/transport) PHP_ADD_BUILD_DIR($ext_builddir/src/core/plugin_registry) PHP_ADD_BUILD_DIR($ext_builddir/src/core/tsi) - PHP_ADD_BUILD_DIR($ext_builddir/src/core/tsi/alts/crypt) - PHP_ADD_BUILD_DIR($ext_builddir/src/core/tsi/alts/frame_protector) - PHP_ADD_BUILD_DIR($ext_builddir/src/core/tsi/alts/handshaker) - PHP_ADD_BUILD_DIR($ext_builddir/src/core/tsi/alts/zero_copy_frame_protector) PHP_ADD_BUILD_DIR($ext_builddir/third_party/boringssl/crypto) PHP_ADD_BUILD_DIR($ext_builddir/third_party/boringssl/crypto/asn1) PHP_ADD_BUILD_DIR($ext_builddir/third_party/boringssl/crypto/base64) diff --git a/config.w32 b/config.w32 index 580607dd3d..5e41295cbf 100644 --- a/config.w32 +++ b/config.w32 @@ -221,7 +221,6 @@ if (PHP_GRPC != "no") { "src\\core\\ext\\filters\\http\\server\\http_server_filter.cc " + "src\\core\\lib\\http\\httpcli_security_connector.cc " + "src\\core\\lib\\security\\context\\security_context.cc " + - "src\\core\\lib\\security\\credentials\\alts\\alts_credentials.cc " + "src\\core\\lib\\security\\credentials\\composite\\composite_credentials.cc " + "src\\core\\lib\\security\\credentials\\credentials.cc " + "src\\core\\lib\\security\\credentials\\credentials_metadata.cc " + @@ -235,7 +234,6 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\security\\credentials\\oauth2\\oauth2_credentials.cc " + "src\\core\\lib\\security\\credentials\\plugin\\plugin_credentials.cc " + "src\\core\\lib\\security\\credentials\\ssl\\ssl_credentials.cc " + - "src\\core\\lib\\security\\security_connector\\alts_security_connector.cc " + "src\\core\\lib\\security\\security_connector\\security_connector.cc " + "src\\core\\lib\\security\\transport\\client_auth_filter.cc " + "src\\core\\lib\\security\\transport\\secure_endpoint.cc " + @@ -245,45 +243,14 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\security\\transport\\tsi_error.cc " + "src\\core\\lib\\security\\util\\json_util.cc " + "src\\core\\lib\\surface\\init_secure.cc " + - "src\\core\\tsi\\alts\\crypt\\aes_gcm.cc " + - "src\\core\\tsi\\alts\\crypt\\gsec.cc " + - "src\\core\\tsi\\alts\\frame_protector\\alts_counter.cc " + - "src\\core\\tsi\\alts\\frame_protector\\alts_crypter.cc " + - "src\\core\\tsi\\alts\\frame_protector\\alts_frame_protector.cc " + - "src\\core\\tsi\\alts\\frame_protector\\alts_record_protocol_crypter_common.cc " + - "src\\core\\tsi\\alts\\frame_protector\\alts_seal_privacy_integrity_crypter.cc " + - "src\\core\\tsi\\alts\\frame_protector\\alts_unseal_privacy_integrity_crypter.cc " + - "src\\core\\tsi\\alts\\frame_protector\\frame_handler.cc " + - "src\\core\\tsi\\alts\\handshaker\\alts_handshaker_client.cc " + - "src\\core\\tsi\\alts\\handshaker\\alts_tsi_event.cc " + - "src\\core\\tsi\\alts\\handshaker\\alts_tsi_handshaker.cc " + - "src\\core\\tsi\\alts\\zero_copy_frame_protector\\alts_grpc_integrity_only_record_protocol.cc " + - "src\\core\\tsi\\alts\\zero_copy_frame_protector\\alts_grpc_privacy_integrity_record_protocol.cc " + - "src\\core\\tsi\\alts\\zero_copy_frame_protector\\alts_grpc_record_protocol_common.cc " + - "src\\core\\tsi\\alts\\zero_copy_frame_protector\\alts_iovec_record_protocol.cc " + - "src\\core\\tsi\\alts\\zero_copy_frame_protector\\alts_zero_copy_grpc_protector.cc " + - "src\\core\\lib\\security\\credentials\\alts\\check_gcp_environment.cc " + - "src\\core\\lib\\security\\credentials\\alts\\check_gcp_environment_linux.cc " + - "src\\core\\lib\\security\\credentials\\alts\\check_gcp_environment_no_op.cc " + - "src\\core\\lib\\security\\credentials\\alts\\check_gcp_environment_windows.cc " + - "src\\core\\lib\\security\\credentials\\alts\\grpc_alts_credentials_client_options.cc " + - "src\\core\\lib\\security\\credentials\\alts\\grpc_alts_credentials_options.cc " + - "src\\core\\lib\\security\\credentials\\alts\\grpc_alts_credentials_server_options.cc " + - "src\\core\\tsi\\alts\\handshaker\\alts_handshaker_service_api.cc " + - "src\\core\\tsi\\alts\\handshaker\\alts_handshaker_service_api_util.cc " + - "src\\core\\tsi\\alts\\handshaker\\alts_tsi_utils.cc " + - "src\\core\\tsi\\alts\\handshaker\\transport_security_common_api.cc " + - "src\\core\\tsi\\alts\\handshaker\\altscontext.pb.c " + - "src\\core\\tsi\\alts\\handshaker\\handshaker.pb.c " + - "src\\core\\tsi\\alts\\handshaker\\transport_security_common.pb.c " + - "third_party\\nanopb\\pb_common.c " + - "third_party\\nanopb\\pb_decode.c " + - "third_party\\nanopb\\pb_encode.c " + + "src\\core\\tsi\\alts_transport_security.cc " + + "src\\core\\tsi\\fake_transport_security.cc " + + "src\\core\\tsi\\ssl_transport_security.cc " + + "src\\core\\tsi\\transport_security_grpc.cc " + "src\\core\\tsi\\transport_security.cc " + "src\\core\\tsi\\transport_security_adapter.cc " + - "src\\core\\ext\\transport\\chttp2\\client\\insecure\\channel_create.cc " + - "src\\core\\ext\\transport\\chttp2\\client\\insecure\\channel_create_posix.cc " + - "src\\core\\ext\\transport\\chttp2\\client\\chttp2_connector.cc " + + "src\\core\\ext\\transport\\chttp2\\server\\chttp2_server.cc " + + "src\\core\\ext\\transport\\chttp2\\client\\secure\\secure_channel_create.cc " + "src\\core\\ext\\filters\\client_channel\\backup_poller.cc " + "src\\core\\ext\\filters\\client_channel\\channel_connectivity.cc " + "src\\core\\ext\\filters\\client_channel\\client_channel.cc " + @@ -307,14 +274,11 @@ if (PHP_GRPC != "no") { "src\\core\\ext\\filters\\client_channel\\subchannel_index.cc " + "src\\core\\ext\\filters\\client_channel\\uri_parser.cc " + "src\\core\\ext\\filters\\deadline\\deadline_filter.cc " + - "src\\core\\tsi\\alts_transport_security.cc " + - "src\\core\\tsi\\fake_transport_security.cc " + - "src\\core\\tsi\\ssl_transport_security.cc " + - "src\\core\\tsi\\transport_security_grpc.cc " + - "src\\core\\ext\\transport\\chttp2\\server\\chttp2_server.cc " + - "src\\core\\ext\\transport\\chttp2\\client\\secure\\secure_channel_create.cc " + + "src\\core\\ext\\transport\\chttp2\\client\\chttp2_connector.cc " + "src\\core\\ext\\transport\\chttp2\\server\\insecure\\server_chttp2.cc " + "src\\core\\ext\\transport\\chttp2\\server\\insecure\\server_chttp2_posix.cc " + + "src\\core\\ext\\transport\\chttp2\\client\\insecure\\channel_create.cc " + + "src\\core\\ext\\transport\\chttp2\\client\\insecure\\channel_create_posix.cc " + "src\\core\\ext\\transport\\inproc\\inproc_plugin.cc " + "src\\core\\ext\\transport\\inproc\\inproc_transport.cc " + "src\\core\\ext\\filters\\client_channel\\lb_policy\\grpclb\\client_load_reporting_filter.cc " + @@ -323,6 +287,9 @@ if (PHP_GRPC != "no") { "src\\core\\ext\\filters\\client_channel\\lb_policy\\grpclb\\grpclb_client_stats.cc " + "src\\core\\ext\\filters\\client_channel\\lb_policy\\grpclb\\load_balancer_api.cc " + "src\\core\\ext\\filters\\client_channel\\lb_policy\\grpclb\\proto\\grpc\\lb\\v1\\load_balancer.pb.c " + + "third_party\\nanopb\\pb_common.c " + + "third_party\\nanopb\\pb_decode.c " + + "third_party\\nanopb\\pb_encode.c " + "src\\core\\ext\\filters\\client_channel\\resolver\\fake\\fake_resolver.cc " + "src\\core\\ext\\filters\\client_channel\\lb_policy\\pick_first\\pick_first.cc " + "src\\core\\ext\\filters\\client_channel\\lb_policy\\subchannel_list.cc " + @@ -681,7 +648,6 @@ if (PHP_GRPC != "no") { FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\security"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\security\\context"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\security\\credentials"); - FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\security\\credentials\\alts"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\security\\credentials\\composite"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\security\\credentials\\fake"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\security\\credentials\\google_default"); @@ -698,11 +664,6 @@ if (PHP_GRPC != "no") { FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\transport"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\plugin_registry"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\tsi"); - FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\tsi\\alts"); - FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\tsi\\alts\\crypt"); - FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\tsi\\alts\\frame_protector"); - FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\tsi\\alts\\handshaker"); - FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\tsi\\alts\\zero_copy_frame_protector"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\php"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\php\\ext"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\php\\ext\\grpc"); diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 65a5dc66b4..821c16da45 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -260,7 +260,6 @@ Pod::Spec.new do |s| 'src/core/ext/filters/http/message_compress/message_compress_filter.h', 'src/core/ext/filters/http/server/http_server_filter.h', 'src/core/lib/security/context/security_context.h', - 'src/core/lib/security/credentials/alts/alts_credentials.h', 'src/core/lib/security/credentials/composite/composite_credentials.h', 'src/core/lib/security/credentials/credentials.h', 'src/core/lib/security/credentials/fake/fake_credentials.h', @@ -272,7 +271,6 @@ Pod::Spec.new do |s| 'src/core/lib/security/credentials/oauth2/oauth2_credentials.h', 'src/core/lib/security/credentials/plugin/plugin_credentials.h', 'src/core/lib/security/credentials/ssl/ssl_credentials.h', - 'src/core/lib/security/security_connector/alts_security_connector.h', 'src/core/lib/security/security_connector/security_connector.h', 'src/core/lib/security/transport/auth_filters.h', 'src/core/lib/security/transport/secure_endpoint.h', @@ -280,35 +278,15 @@ Pod::Spec.new do |s| 'src/core/lib/security/transport/target_authority_table.h', 'src/core/lib/security/transport/tsi_error.h', 'src/core/lib/security/util/json_util.h', - 'src/core/tsi/alts/crypt/gsec.h', - 'src/core/tsi/alts/frame_protector/alts_counter.h', - 'src/core/tsi/alts/frame_protector/alts_crypter.h', - 'src/core/tsi/alts/frame_protector/alts_frame_protector.h', - 'src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h', - 'src/core/tsi/alts/frame_protector/frame_handler.h', - 'src/core/tsi/alts/handshaker/alts_handshaker_client.h', - 'src/core/tsi/alts/handshaker/alts_tsi_event.h', - 'src/core/tsi/alts/handshaker/alts_tsi_handshaker.h', - 'src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h', - 'src/core/lib/security/credentials/alts/check_gcp_environment.h', - 'src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h', - 'src/core/tsi/alts/handshaker/alts_handshaker_service_api.h', - 'src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h', - 'src/core/tsi/alts/handshaker/alts_tsi_utils.h', - 'src/core/tsi/alts/handshaker/transport_security_common_api.h', - 'src/core/tsi/alts/handshaker/altscontext.pb.h', - 'src/core/tsi/alts/handshaker/handshaker.pb.h', - 'src/core/tsi/alts/handshaker/transport_security_common.pb.h', + 'src/core/tsi/alts_transport_security.h', + 'src/core/tsi/fake_transport_security.h', + 'src/core/tsi/ssl_transport_security.h', + 'src/core/tsi/ssl_types.h', + 'src/core/tsi/transport_security_grpc.h', 'src/core/tsi/transport_security.h', 'src/core/tsi/transport_security_adapter.h', 'src/core/tsi/transport_security_interface.h', - 'src/core/ext/transport/chttp2/client/chttp2_connector.h', + 'src/core/ext/transport/chttp2/server/chttp2_server.h', 'src/core/ext/filters/client_channel/backup_poller.h', 'src/core/ext/filters/client_channel/client_channel.h', 'src/core/ext/filters/client_channel/client_channel_factory.h', @@ -331,12 +309,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/subchannel_index.h', 'src/core/ext/filters/client_channel/uri_parser.h', 'src/core/ext/filters/deadline/deadline_filter.h', - 'src/core/tsi/alts_transport_security.h', - 'src/core/tsi/fake_transport_security.h', - 'src/core/tsi/ssl_transport_security.h', - 'src/core/tsi/ssl_types.h', - 'src/core/tsi/transport_security_grpc.h', - 'src/core/ext/transport/chttp2/server/chttp2_server.h', + 'src/core/ext/transport/chttp2/client/chttp2_connector.h', 'src/core/ext/transport/inproc/inproc_transport.h', 'src/core/lib/avl/avl.h', 'src/core/lib/backoff/backoff.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 7f61719cb1..6c6c76991c 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -93,7 +93,7 @@ Pod::Spec.new do |s| } s.default_subspecs = 'Interface', 'Implementation' - s.compiler_flags = '-DGRPC_ARES=0', '-DPB_FIELD_16BIT' + s.compiler_flags = '-DGRPC_ARES=0' s.libraries = 'c++' # Like many other C libraries, gRPC-Core has its public headers under `include//` and its @@ -271,7 +271,6 @@ Pod::Spec.new do |s| 'src/core/ext/filters/http/message_compress/message_compress_filter.h', 'src/core/ext/filters/http/server/http_server_filter.h', 'src/core/lib/security/context/security_context.h', - 'src/core/lib/security/credentials/alts/alts_credentials.h', 'src/core/lib/security/credentials/composite/composite_credentials.h', 'src/core/lib/security/credentials/credentials.h', 'src/core/lib/security/credentials/fake/fake_credentials.h', @@ -283,7 +282,6 @@ Pod::Spec.new do |s| 'src/core/lib/security/credentials/oauth2/oauth2_credentials.h', 'src/core/lib/security/credentials/plugin/plugin_credentials.h', 'src/core/lib/security/credentials/ssl/ssl_credentials.h', - 'src/core/lib/security/security_connector/alts_security_connector.h', 'src/core/lib/security/security_connector/security_connector.h', 'src/core/lib/security/transport/auth_filters.h', 'src/core/lib/security/transport/secure_endpoint.h', @@ -291,35 +289,15 @@ Pod::Spec.new do |s| 'src/core/lib/security/transport/target_authority_table.h', 'src/core/lib/security/transport/tsi_error.h', 'src/core/lib/security/util/json_util.h', - 'src/core/tsi/alts/crypt/gsec.h', - 'src/core/tsi/alts/frame_protector/alts_counter.h', - 'src/core/tsi/alts/frame_protector/alts_crypter.h', - 'src/core/tsi/alts/frame_protector/alts_frame_protector.h', - 'src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h', - 'src/core/tsi/alts/frame_protector/frame_handler.h', - 'src/core/tsi/alts/handshaker/alts_handshaker_client.h', - 'src/core/tsi/alts/handshaker/alts_tsi_event.h', - 'src/core/tsi/alts/handshaker/alts_tsi_handshaker.h', - 'src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h', - 'src/core/lib/security/credentials/alts/check_gcp_environment.h', - 'src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h', - 'src/core/tsi/alts/handshaker/alts_handshaker_service_api.h', - 'src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h', - 'src/core/tsi/alts/handshaker/alts_tsi_utils.h', - 'src/core/tsi/alts/handshaker/transport_security_common_api.h', - 'src/core/tsi/alts/handshaker/altscontext.pb.h', - 'src/core/tsi/alts/handshaker/handshaker.pb.h', - 'src/core/tsi/alts/handshaker/transport_security_common.pb.h', + 'src/core/tsi/alts_transport_security.h', + 'src/core/tsi/fake_transport_security.h', + 'src/core/tsi/ssl_transport_security.h', + 'src/core/tsi/ssl_types.h', + 'src/core/tsi/transport_security_grpc.h', 'src/core/tsi/transport_security.h', 'src/core/tsi/transport_security_adapter.h', 'src/core/tsi/transport_security_interface.h', - 'src/core/ext/transport/chttp2/client/chttp2_connector.h', + 'src/core/ext/transport/chttp2/server/chttp2_server.h', 'src/core/ext/filters/client_channel/backup_poller.h', 'src/core/ext/filters/client_channel/client_channel.h', 'src/core/ext/filters/client_channel/client_channel_factory.h', @@ -342,12 +320,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/subchannel_index.h', 'src/core/ext/filters/client_channel/uri_parser.h', 'src/core/ext/filters/deadline/deadline_filter.h', - 'src/core/tsi/alts_transport_security.h', - 'src/core/tsi/fake_transport_security.h', - 'src/core/tsi/ssl_transport_security.h', - 'src/core/tsi/ssl_types.h', - 'src/core/tsi/transport_security_grpc.h', - 'src/core/ext/transport/chttp2/server/chttp2_server.h', + 'src/core/ext/transport/chttp2/client/chttp2_connector.h', 'src/core/ext/transport/inproc/inproc_transport.h', 'src/core/lib/avl/avl.h', 'src/core/lib/backoff/backoff.h', @@ -658,7 +631,6 @@ Pod::Spec.new do |s| 'src/core/ext/filters/http/server/http_server_filter.cc', 'src/core/lib/http/httpcli_security_connector.cc', 'src/core/lib/security/context/security_context.cc', - 'src/core/lib/security/credentials/alts/alts_credentials.cc', 'src/core/lib/security/credentials/composite/composite_credentials.cc', 'src/core/lib/security/credentials/credentials.cc', 'src/core/lib/security/credentials/credentials_metadata.cc', @@ -672,7 +644,6 @@ Pod::Spec.new do |s| 'src/core/lib/security/credentials/oauth2/oauth2_credentials.cc', 'src/core/lib/security/credentials/plugin/plugin_credentials.cc', 'src/core/lib/security/credentials/ssl/ssl_credentials.cc', - 'src/core/lib/security/security_connector/alts_security_connector.cc', 'src/core/lib/security/security_connector/security_connector.cc', 'src/core/lib/security/transport/client_auth_filter.cc', 'src/core/lib/security/transport/secure_endpoint.cc', @@ -682,42 +653,14 @@ Pod::Spec.new do |s| 'src/core/lib/security/transport/tsi_error.cc', 'src/core/lib/security/util/json_util.cc', 'src/core/lib/surface/init_secure.cc', - 'src/core/tsi/alts/crypt/aes_gcm.cc', - 'src/core/tsi/alts/crypt/gsec.cc', - 'src/core/tsi/alts/frame_protector/alts_counter.cc', - 'src/core/tsi/alts/frame_protector/alts_crypter.cc', - 'src/core/tsi/alts/frame_protector/alts_frame_protector.cc', - 'src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc', - 'src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc', - 'src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc', - 'src/core/tsi/alts/frame_protector/frame_handler.cc', - 'src/core/tsi/alts/handshaker/alts_handshaker_client.cc', - 'src/core/tsi/alts/handshaker/alts_tsi_event.cc', - 'src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc', - 'src/core/lib/security/credentials/alts/check_gcp_environment.cc', - 'src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc', - 'src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc', - 'src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc', - 'src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc', - 'src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc', - 'src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc', - 'src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc', - 'src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc', - 'src/core/tsi/alts/handshaker/alts_tsi_utils.cc', - 'src/core/tsi/alts/handshaker/transport_security_common_api.cc', - 'src/core/tsi/alts/handshaker/altscontext.pb.c', - 'src/core/tsi/alts/handshaker/handshaker.pb.c', - 'src/core/tsi/alts/handshaker/transport_security_common.pb.c', + 'src/core/tsi/alts_transport_security.cc', + 'src/core/tsi/fake_transport_security.cc', + 'src/core/tsi/ssl_transport_security.cc', + 'src/core/tsi/transport_security_grpc.cc', 'src/core/tsi/transport_security.cc', 'src/core/tsi/transport_security_adapter.cc', - 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', - 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', - 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', + 'src/core/ext/transport/chttp2/server/chttp2_server.cc', + 'src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc', 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', 'src/core/ext/filters/client_channel/client_channel.cc', @@ -741,14 +684,11 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', 'src/core/ext/filters/deadline/deadline_filter.cc', - 'src/core/tsi/alts_transport_security.cc', - 'src/core/tsi/fake_transport_security.cc', - 'src/core/tsi/ssl_transport_security.cc', - 'src/core/tsi/transport_security_grpc.cc', - 'src/core/ext/transport/chttp2/server/chttp2_server.cc', - 'src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc', + 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', 'src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc', 'src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc', + 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', + 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', 'src/core/ext/transport/inproc/inproc_plugin.cc', 'src/core/ext/transport/inproc/inproc_transport.cc', 'src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc', @@ -825,7 +765,6 @@ Pod::Spec.new do |s| 'src/core/ext/filters/http/message_compress/message_compress_filter.h', 'src/core/ext/filters/http/server/http_server_filter.h', 'src/core/lib/security/context/security_context.h', - 'src/core/lib/security/credentials/alts/alts_credentials.h', 'src/core/lib/security/credentials/composite/composite_credentials.h', 'src/core/lib/security/credentials/credentials.h', 'src/core/lib/security/credentials/fake/fake_credentials.h', @@ -837,7 +776,6 @@ Pod::Spec.new do |s| 'src/core/lib/security/credentials/oauth2/oauth2_credentials.h', 'src/core/lib/security/credentials/plugin/plugin_credentials.h', 'src/core/lib/security/credentials/ssl/ssl_credentials.h', - 'src/core/lib/security/security_connector/alts_security_connector.h', 'src/core/lib/security/security_connector/security_connector.h', 'src/core/lib/security/transport/auth_filters.h', 'src/core/lib/security/transport/secure_endpoint.h', @@ -845,35 +783,15 @@ Pod::Spec.new do |s| 'src/core/lib/security/transport/target_authority_table.h', 'src/core/lib/security/transport/tsi_error.h', 'src/core/lib/security/util/json_util.h', - 'src/core/tsi/alts/crypt/gsec.h', - 'src/core/tsi/alts/frame_protector/alts_counter.h', - 'src/core/tsi/alts/frame_protector/alts_crypter.h', - 'src/core/tsi/alts/frame_protector/alts_frame_protector.h', - 'src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h', - 'src/core/tsi/alts/frame_protector/frame_handler.h', - 'src/core/tsi/alts/handshaker/alts_handshaker_client.h', - 'src/core/tsi/alts/handshaker/alts_tsi_event.h', - 'src/core/tsi/alts/handshaker/alts_tsi_handshaker.h', - 'src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h', - 'src/core/lib/security/credentials/alts/check_gcp_environment.h', - 'src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h', - 'src/core/tsi/alts/handshaker/alts_handshaker_service_api.h', - 'src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h', - 'src/core/tsi/alts/handshaker/alts_tsi_utils.h', - 'src/core/tsi/alts/handshaker/transport_security_common_api.h', - 'src/core/tsi/alts/handshaker/altscontext.pb.h', - 'src/core/tsi/alts/handshaker/handshaker.pb.h', - 'src/core/tsi/alts/handshaker/transport_security_common.pb.h', + 'src/core/tsi/alts_transport_security.h', + 'src/core/tsi/fake_transport_security.h', + 'src/core/tsi/ssl_transport_security.h', + 'src/core/tsi/ssl_types.h', + 'src/core/tsi/transport_security_grpc.h', 'src/core/tsi/transport_security.h', 'src/core/tsi/transport_security_adapter.h', 'src/core/tsi/transport_security_interface.h', - 'src/core/ext/transport/chttp2/client/chttp2_connector.h', + 'src/core/ext/transport/chttp2/server/chttp2_server.h', 'src/core/ext/filters/client_channel/backup_poller.h', 'src/core/ext/filters/client_channel/client_channel.h', 'src/core/ext/filters/client_channel/client_channel_factory.h', @@ -896,12 +814,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/subchannel_index.h', 'src/core/ext/filters/client_channel/uri_parser.h', 'src/core/ext/filters/deadline/deadline_filter.h', - 'src/core/tsi/alts_transport_security.h', - 'src/core/tsi/fake_transport_security.h', - 'src/core/tsi/ssl_transport_security.h', - 'src/core/tsi/ssl_types.h', - 'src/core/tsi/transport_security_grpc.h', - 'src/core/ext/transport/chttp2/server/chttp2_server.h', + 'src/core/ext/transport/chttp2/client/chttp2_connector.h', 'src/core/ext/transport/inproc/inproc_transport.h', 'src/core/lib/avl/avl.h', 'src/core/lib/backoff/backoff.h', @@ -1062,15 +975,8 @@ Pod::Spec.new do |s| ss.source_files = 'src/core/ext/transport/cronet/client/secure/cronet_channel_create.cc', 'src/core/ext/transport/cronet/transport/cronet_transport.cc', - 'third_party/nanopb/pb_common.c', - 'third_party/nanopb/pb_decode.c', - 'third_party/nanopb/pb_encode.c', 'src/core/ext/transport/cronet/transport/cronet_transport.h', - 'third_party/objective_c/Cronet/bidirectional_stream_c.h', - 'third_party/nanopb/pb.h', - 'third_party/nanopb/pb_common.h', - 'third_party/nanopb/pb_decode.h', - 'third_party/nanopb/pb_encode.h' + 'third_party/objective_c/Cronet/bidirectional_stream_c.h' end s.subspec 'Tests' do |ss| diff --git a/grpc.gemspec b/grpc.gemspec index 3df7cea33f..fbe70aa795 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -197,7 +197,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/http/message_compress/message_compress_filter.h ) s.files += %w( src/core/ext/filters/http/server/http_server_filter.h ) s.files += %w( src/core/lib/security/context/security_context.h ) - s.files += %w( src/core/lib/security/credentials/alts/alts_credentials.h ) s.files += %w( src/core/lib/security/credentials/composite/composite_credentials.h ) s.files += %w( src/core/lib/security/credentials/credentials.h ) s.files += %w( src/core/lib/security/credentials/fake/fake_credentials.h ) @@ -209,7 +208,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/security/credentials/oauth2/oauth2_credentials.h ) s.files += %w( src/core/lib/security/credentials/plugin/plugin_credentials.h ) s.files += %w( src/core/lib/security/credentials/ssl/ssl_credentials.h ) - s.files += %w( src/core/lib/security/security_connector/alts_security_connector.h ) s.files += %w( src/core/lib/security/security_connector/security_connector.h ) s.files += %w( src/core/lib/security/transport/auth_filters.h ) s.files += %w( src/core/lib/security/transport/secure_endpoint.h ) @@ -217,39 +215,15 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/security/transport/target_authority_table.h ) s.files += %w( src/core/lib/security/transport/tsi_error.h ) s.files += %w( src/core/lib/security/util/json_util.h ) - s.files += %w( src/core/tsi/alts/crypt/gsec.h ) - s.files += %w( src/core/tsi/alts/frame_protector/alts_counter.h ) - s.files += %w( src/core/tsi/alts/frame_protector/alts_crypter.h ) - s.files += %w( src/core/tsi/alts/frame_protector/alts_frame_protector.h ) - s.files += %w( src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h ) - s.files += %w( src/core/tsi/alts/frame_protector/frame_handler.h ) - s.files += %w( src/core/tsi/alts/handshaker/alts_handshaker_client.h ) - s.files += %w( src/core/tsi/alts/handshaker/alts_tsi_event.h ) - s.files += %w( src/core/tsi/alts/handshaker/alts_tsi_handshaker.h ) - s.files += %w( src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h ) - s.files += %w( src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h ) - s.files += %w( src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h ) - s.files += %w( src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h ) - s.files += %w( src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h ) - s.files += %w( src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h ) - s.files += %w( src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h ) - s.files += %w( src/core/lib/security/credentials/alts/check_gcp_environment.h ) - s.files += %w( src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h ) - s.files += %w( src/core/tsi/alts/handshaker/alts_handshaker_service_api.h ) - s.files += %w( src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h ) - s.files += %w( src/core/tsi/alts/handshaker/alts_tsi_utils.h ) - s.files += %w( src/core/tsi/alts/handshaker/transport_security_common_api.h ) - s.files += %w( src/core/tsi/alts/handshaker/altscontext.pb.h ) - s.files += %w( src/core/tsi/alts/handshaker/handshaker.pb.h ) - s.files += %w( src/core/tsi/alts/handshaker/transport_security_common.pb.h ) - s.files += %w( third_party/nanopb/pb.h ) - s.files += %w( third_party/nanopb/pb_common.h ) - s.files += %w( third_party/nanopb/pb_decode.h ) - s.files += %w( third_party/nanopb/pb_encode.h ) + s.files += %w( src/core/tsi/alts_transport_security.h ) + s.files += %w( src/core/tsi/fake_transport_security.h ) + s.files += %w( src/core/tsi/ssl_transport_security.h ) + s.files += %w( src/core/tsi/ssl_types.h ) + s.files += %w( src/core/tsi/transport_security_grpc.h ) s.files += %w( src/core/tsi/transport_security.h ) s.files += %w( src/core/tsi/transport_security_adapter.h ) s.files += %w( src/core/tsi/transport_security_interface.h ) - s.files += %w( src/core/ext/transport/chttp2/client/chttp2_connector.h ) + s.files += %w( src/core/ext/transport/chttp2/server/chttp2_server.h ) s.files += %w( src/core/ext/filters/client_channel/backup_poller.h ) s.files += %w( src/core/ext/filters/client_channel/client_channel.h ) s.files += %w( src/core/ext/filters/client_channel/client_channel_factory.h ) @@ -272,12 +246,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/client_channel/subchannel_index.h ) s.files += %w( src/core/ext/filters/client_channel/uri_parser.h ) s.files += %w( src/core/ext/filters/deadline/deadline_filter.h ) - s.files += %w( src/core/tsi/alts_transport_security.h ) - s.files += %w( src/core/tsi/fake_transport_security.h ) - s.files += %w( src/core/tsi/ssl_transport_security.h ) - s.files += %w( src/core/tsi/ssl_types.h ) - s.files += %w( src/core/tsi/transport_security_grpc.h ) - s.files += %w( src/core/ext/transport/chttp2/server/chttp2_server.h ) + s.files += %w( src/core/ext/transport/chttp2/client/chttp2_connector.h ) s.files += %w( src/core/ext/transport/inproc/inproc_transport.h ) s.files += %w( src/core/lib/avl/avl.h ) s.files += %w( src/core/lib/backoff/backoff.h ) @@ -412,6 +381,10 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h ) + s.files += %w( third_party/nanopb/pb.h ) + s.files += %w( third_party/nanopb/pb_common.h ) + s.files += %w( third_party/nanopb/pb_decode.h ) + s.files += %w( third_party/nanopb/pb_encode.h ) s.files += %w( src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/subchannel_list.h ) s.files += %w( src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h ) @@ -588,7 +561,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/http/server/http_server_filter.cc ) s.files += %w( src/core/lib/http/httpcli_security_connector.cc ) s.files += %w( src/core/lib/security/context/security_context.cc ) - s.files += %w( src/core/lib/security/credentials/alts/alts_credentials.cc ) s.files += %w( src/core/lib/security/credentials/composite/composite_credentials.cc ) s.files += %w( src/core/lib/security/credentials/credentials.cc ) s.files += %w( src/core/lib/security/credentials/credentials_metadata.cc ) @@ -602,7 +574,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/security/credentials/oauth2/oauth2_credentials.cc ) s.files += %w( src/core/lib/security/credentials/plugin/plugin_credentials.cc ) s.files += %w( src/core/lib/security/credentials/ssl/ssl_credentials.cc ) - s.files += %w( src/core/lib/security/security_connector/alts_security_connector.cc ) s.files += %w( src/core/lib/security/security_connector/security_connector.cc ) s.files += %w( src/core/lib/security/transport/client_auth_filter.cc ) s.files += %w( src/core/lib/security/transport/secure_endpoint.cc ) @@ -612,45 +583,14 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/security/transport/tsi_error.cc ) s.files += %w( src/core/lib/security/util/json_util.cc ) s.files += %w( src/core/lib/surface/init_secure.cc ) - s.files += %w( src/core/tsi/alts/crypt/aes_gcm.cc ) - s.files += %w( src/core/tsi/alts/crypt/gsec.cc ) - s.files += %w( src/core/tsi/alts/frame_protector/alts_counter.cc ) - s.files += %w( src/core/tsi/alts/frame_protector/alts_crypter.cc ) - s.files += %w( src/core/tsi/alts/frame_protector/alts_frame_protector.cc ) - s.files += %w( src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc ) - s.files += %w( src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc ) - s.files += %w( src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc ) - s.files += %w( src/core/tsi/alts/frame_protector/frame_handler.cc ) - s.files += %w( src/core/tsi/alts/handshaker/alts_handshaker_client.cc ) - s.files += %w( src/core/tsi/alts/handshaker/alts_tsi_event.cc ) - s.files += %w( src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc ) - s.files += %w( src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc ) - s.files += %w( src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc ) - s.files += %w( src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc ) - s.files += %w( src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc ) - s.files += %w( src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc ) - s.files += %w( src/core/lib/security/credentials/alts/check_gcp_environment.cc ) - s.files += %w( src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc ) - s.files += %w( src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc ) - s.files += %w( src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc ) - s.files += %w( src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc ) - s.files += %w( src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc ) - s.files += %w( src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc ) - s.files += %w( src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc ) - s.files += %w( src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc ) - s.files += %w( src/core/tsi/alts/handshaker/alts_tsi_utils.cc ) - s.files += %w( src/core/tsi/alts/handshaker/transport_security_common_api.cc ) - s.files += %w( src/core/tsi/alts/handshaker/altscontext.pb.c ) - s.files += %w( src/core/tsi/alts/handshaker/handshaker.pb.c ) - s.files += %w( src/core/tsi/alts/handshaker/transport_security_common.pb.c ) - s.files += %w( third_party/nanopb/pb_common.c ) - s.files += %w( third_party/nanopb/pb_decode.c ) - s.files += %w( third_party/nanopb/pb_encode.c ) + s.files += %w( src/core/tsi/alts_transport_security.cc ) + s.files += %w( src/core/tsi/fake_transport_security.cc ) + s.files += %w( src/core/tsi/ssl_transport_security.cc ) + s.files += %w( src/core/tsi/transport_security_grpc.cc ) s.files += %w( src/core/tsi/transport_security.cc ) s.files += %w( src/core/tsi/transport_security_adapter.cc ) - s.files += %w( src/core/ext/transport/chttp2/client/insecure/channel_create.cc ) - s.files += %w( src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc ) - s.files += %w( src/core/ext/transport/chttp2/client/chttp2_connector.cc ) + s.files += %w( src/core/ext/transport/chttp2/server/chttp2_server.cc ) + s.files += %w( src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc ) s.files += %w( src/core/ext/filters/client_channel/backup_poller.cc ) s.files += %w( src/core/ext/filters/client_channel/channel_connectivity.cc ) s.files += %w( src/core/ext/filters/client_channel/client_channel.cc ) @@ -674,14 +614,11 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/client_channel/subchannel_index.cc ) s.files += %w( src/core/ext/filters/client_channel/uri_parser.cc ) s.files += %w( src/core/ext/filters/deadline/deadline_filter.cc ) - s.files += %w( src/core/tsi/alts_transport_security.cc ) - s.files += %w( src/core/tsi/fake_transport_security.cc ) - s.files += %w( src/core/tsi/ssl_transport_security.cc ) - s.files += %w( src/core/tsi/transport_security_grpc.cc ) - s.files += %w( src/core/ext/transport/chttp2/server/chttp2_server.cc ) - s.files += %w( src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc ) + s.files += %w( src/core/ext/transport/chttp2/client/chttp2_connector.cc ) s.files += %w( src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc ) s.files += %w( src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc ) + s.files += %w( src/core/ext/transport/chttp2/client/insecure/channel_create.cc ) + s.files += %w( src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc ) s.files += %w( src/core/ext/transport/inproc/inproc_plugin.cc ) s.files += %w( src/core/ext/transport/inproc/inproc_transport.cc ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc ) @@ -690,6 +627,9 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c ) + s.files += %w( third_party/nanopb/pb_common.c ) + s.files += %w( third_party/nanopb/pb_decode.c ) + s.files += %w( third_party/nanopb/pb_encode.c ) s.files += %w( src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc ) diff --git a/grpc.gyp b/grpc.gyp index 38597a5b4f..cd3deddb0e 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -64,11 +64,11 @@ ], 'cflags_c': [ '-Werror', - '-std=c99', + '-std=c99' ], 'cflags_cc': [ '-Werror', - '-std=c++11', + '-std=c++11' ], 'include_dirs': [ '.', @@ -148,24 +148,13 @@ '-Wno-deprecated-declarations', '-stdlib=libc++', '-std=c++11', - '-Wno-error=deprecated-declarations', + '-Wno-error=deprecated-declarations' ], }, }] ] }, 'targets': [ - { - 'target_name': 'alts_test_util', - 'type': 'static_library', - 'dependencies': [ - 'grpc', - ], - 'sources': [ - 'test/core/tsi/alts/crypt/gsec_test_util.cc', - 'test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc', - ], - }, { 'target_name': 'gpr', 'type': 'static_library', @@ -396,7 +385,6 @@ 'src/core/ext/filters/http/server/http_server_filter.cc', 'src/core/lib/http/httpcli_security_connector.cc', 'src/core/lib/security/context/security_context.cc', - 'src/core/lib/security/credentials/alts/alts_credentials.cc', 'src/core/lib/security/credentials/composite/composite_credentials.cc', 'src/core/lib/security/credentials/credentials.cc', 'src/core/lib/security/credentials/credentials_metadata.cc', @@ -410,7 +398,6 @@ 'src/core/lib/security/credentials/oauth2/oauth2_credentials.cc', 'src/core/lib/security/credentials/plugin/plugin_credentials.cc', 'src/core/lib/security/credentials/ssl/ssl_credentials.cc', - 'src/core/lib/security/security_connector/alts_security_connector.cc', 'src/core/lib/security/security_connector/security_connector.cc', 'src/core/lib/security/transport/client_auth_filter.cc', 'src/core/lib/security/transport/secure_endpoint.cc', @@ -420,45 +407,14 @@ 'src/core/lib/security/transport/tsi_error.cc', 'src/core/lib/security/util/json_util.cc', 'src/core/lib/surface/init_secure.cc', - 'src/core/tsi/alts/crypt/aes_gcm.cc', - 'src/core/tsi/alts/crypt/gsec.cc', - 'src/core/tsi/alts/frame_protector/alts_counter.cc', - 'src/core/tsi/alts/frame_protector/alts_crypter.cc', - 'src/core/tsi/alts/frame_protector/alts_frame_protector.cc', - 'src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc', - 'src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc', - 'src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc', - 'src/core/tsi/alts/frame_protector/frame_handler.cc', - 'src/core/tsi/alts/handshaker/alts_handshaker_client.cc', - 'src/core/tsi/alts/handshaker/alts_tsi_event.cc', - 'src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc', - 'src/core/lib/security/credentials/alts/check_gcp_environment.cc', - 'src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc', - 'src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc', - 'src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc', - 'src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc', - 'src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc', - 'src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc', - 'src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc', - 'src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc', - 'src/core/tsi/alts/handshaker/alts_tsi_utils.cc', - 'src/core/tsi/alts/handshaker/transport_security_common_api.cc', - 'src/core/tsi/alts/handshaker/altscontext.pb.c', - 'src/core/tsi/alts/handshaker/handshaker.pb.c', - 'src/core/tsi/alts/handshaker/transport_security_common.pb.c', - 'third_party/nanopb/pb_common.c', - 'third_party/nanopb/pb_decode.c', - 'third_party/nanopb/pb_encode.c', + 'src/core/tsi/alts_transport_security.cc', + 'src/core/tsi/fake_transport_security.cc', + 'src/core/tsi/ssl_transport_security.cc', + 'src/core/tsi/transport_security_grpc.cc', 'src/core/tsi/transport_security.cc', 'src/core/tsi/transport_security_adapter.cc', - 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', - 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', - 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', + 'src/core/ext/transport/chttp2/server/chttp2_server.cc', + 'src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc', 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', 'src/core/ext/filters/client_channel/client_channel.cc', @@ -482,14 +438,11 @@ 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', 'src/core/ext/filters/deadline/deadline_filter.cc', - 'src/core/tsi/alts_transport_security.cc', - 'src/core/tsi/fake_transport_security.cc', - 'src/core/tsi/ssl_transport_security.cc', - 'src/core/tsi/transport_security_grpc.cc', - 'src/core/ext/transport/chttp2/server/chttp2_server.cc', - 'src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc', + 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', 'src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc', 'src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc', + 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', + 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', 'src/core/ext/transport/inproc/inproc_plugin.cc', 'src/core/ext/transport/inproc/inproc_transport.cc', 'src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc', @@ -498,6 +451,9 @@ 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc', 'src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc', 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c', + 'third_party/nanopb/pb_common.c', + 'third_party/nanopb/pb_decode.c', + 'third_party/nanopb/pb_encode.c', 'src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc', 'src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc', 'src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc', diff --git a/package.xml b/package.xml index c4a6f6fc92..db03230eba 100644 --- a/package.xml +++ b/package.xml @@ -204,7 +204,6 @@ - @@ -216,7 +215,6 @@ - @@ -224,39 +222,15 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - + @@ -279,12 +253,7 @@ - - - - - - + @@ -419,6 +388,10 @@ + + + + @@ -595,7 +568,6 @@ - @@ -609,7 +581,6 @@ - @@ -619,45 +590,14 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - + + @@ -681,14 +621,11 @@ - - - - - - + + + @@ -697,6 +634,9 @@ + + + diff --git a/setup.py b/setup.py index 7c07c5614c..4f67f82275 100644 --- a/setup.py +++ b/setup.py @@ -118,7 +118,6 @@ if EXTRA_ENV_COMPILE_ARGS is None: EXTRA_ENV_COMPILE_ARGS += ' -std=c++11 -std=gnu99 -fvisibility=hidden -fno-wrapv -fno-exceptions' elif "darwin" in sys.platform: EXTRA_ENV_COMPILE_ARGS += ' -fvisibility=hidden -fno-wrapv -fno-exceptions' -EXTRA_ENV_COMPILE_ARGS += ' -DPB_FIELD_16BIT' if EXTRA_ENV_LINK_ARGS is None: EXTRA_ENV_LINK_ARGS = '' @@ -161,7 +160,7 @@ if "win32" in sys.platform: DEFINE_MACROS = ( ('OPENSSL_NO_ASM', 1), ('_WIN32_WINNT', 0x600), - ('GPR_BACKWARDS_COMPATIBILITY_MODE', 1)) + ('GPR_BACKWARDS_COMPATIBILITY_MODE', 1),) if "win32" in sys.platform: # TODO(zyc): Re-enble c-ares on x64 and x86 windows after fixing the # ares_library_init compilation issue diff --git a/src/core/lib/security/credentials/alts/alts_credentials.cc b/src/core/lib/security/credentials/alts/alts_credentials.cc deleted file mode 100644 index fa05d901bf..0000000000 --- a/src/core/lib/security/credentials/alts/alts_credentials.cc +++ /dev/null @@ -1,119 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/lib/security/credentials/alts/alts_credentials.h" - -#include - -#include -#include -#include -#include - -#include "src/core/lib/security/credentials/alts/check_gcp_environment.h" -#include "src/core/lib/security/security_connector/alts_security_connector.h" - -#define GRPC_CREDENTIALS_TYPE_ALTS "Alts" -#define GRPC_ALTS_HANDSHAKER_SERVICE_URL "metadata.google.internal:8080" - -static void alts_credentials_destruct(grpc_channel_credentials* creds) { - grpc_alts_credentials* alts_creds = - reinterpret_cast(creds); - grpc_alts_credentials_options_destroy(alts_creds->options); - gpr_free(alts_creds->handshaker_service_url); -} - -static void alts_server_credentials_destruct(grpc_server_credentials* creds) { - grpc_alts_server_credentials* alts_creds = - reinterpret_cast(creds); - grpc_alts_credentials_options_destroy(alts_creds->options); - gpr_free(alts_creds->handshaker_service_url); -} - -static grpc_security_status alts_create_security_connector( - grpc_channel_credentials* creds, - grpc_call_credentials* request_metadata_creds, const char* target_name, - const grpc_channel_args* args, grpc_channel_security_connector** sc, - grpc_channel_args** new_args) { - return grpc_alts_channel_security_connector_create( - creds, request_metadata_creds, target_name, sc); -} - -static grpc_security_status alts_server_create_security_connector( - grpc_server_credentials* creds, grpc_server_security_connector** sc) { - return grpc_alts_server_security_connector_create(creds, sc); -} - -static const grpc_channel_credentials_vtable alts_credentials_vtable = { - alts_credentials_destruct, alts_create_security_connector, - /*duplicate_without_call_credentials=*/nullptr}; - -static const grpc_server_credentials_vtable alts_server_credentials_vtable = { - alts_server_credentials_destruct, alts_server_create_security_connector}; - -grpc_channel_credentials* grpc_alts_credentials_create_customized( - const grpc_alts_credentials_options* options, - const char* handshaker_service_url, bool enable_untrusted_alts) { - if (!enable_untrusted_alts && !grpc_alts_is_running_on_gcp()) { - return nullptr; - } - auto creds = static_cast( - gpr_zalloc(sizeof(grpc_alts_credentials))); - creds->options = grpc_alts_credentials_options_copy(options); - creds->handshaker_service_url = - handshaker_service_url == nullptr - ? gpr_strdup(GRPC_ALTS_HANDSHAKER_SERVICE_URL) - : gpr_strdup(handshaker_service_url); - creds->base.type = GRPC_CREDENTIALS_TYPE_ALTS; - creds->base.vtable = &alts_credentials_vtable; - gpr_ref_init(&creds->base.refcount, 1); - return &creds->base; -} - -grpc_server_credentials* grpc_alts_server_credentials_create_customized( - const grpc_alts_credentials_options* options, - const char* handshaker_service_url, bool enable_untrusted_alts) { - if (!enable_untrusted_alts && !grpc_alts_is_running_on_gcp()) { - return nullptr; - } - auto creds = static_cast( - gpr_zalloc(sizeof(grpc_alts_server_credentials))); - creds->options = grpc_alts_credentials_options_copy(options); - creds->handshaker_service_url = - handshaker_service_url == nullptr - ? gpr_strdup(GRPC_ALTS_HANDSHAKER_SERVICE_URL) - : gpr_strdup(handshaker_service_url); - creds->base.type = GRPC_CREDENTIALS_TYPE_ALTS; - creds->base.vtable = &alts_server_credentials_vtable; - gpr_ref_init(&creds->base.refcount, 1); - return &creds->base; -} - -grpc_channel_credentials* grpc_alts_credentials_create( - const grpc_alts_credentials_options* options) { - return grpc_alts_credentials_create_customized( - options, GRPC_ALTS_HANDSHAKER_SERVICE_URL, false); -} - -grpc_server_credentials* grpc_alts_server_credentials_create( - const grpc_alts_credentials_options* options) { - return grpc_alts_server_credentials_create_customized( - options, GRPC_ALTS_HANDSHAKER_SERVICE_URL, false); -} diff --git a/src/core/lib/security/credentials/alts/alts_credentials.h b/src/core/lib/security/credentials/alts/alts_credentials.h deleted file mode 100644 index 621789cf65..0000000000 --- a/src/core/lib/security/credentials/alts/alts_credentials.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_LIB_SECURITY_CREDENTIALS_ALTS_ALTS_CREDENTIALS_H -#define GRPC_CORE_LIB_SECURITY_CREDENTIALS_ALTS_ALTS_CREDENTIALS_H - -#include - -#include - -#include "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h" -#include "src/core/lib/security/credentials/credentials.h" - -/* Main struct for grpc ALTS channel credential. */ -typedef struct grpc_alts_credentials { - grpc_channel_credentials base; - grpc_alts_credentials_options* options; - char* handshaker_service_url; -} grpc_alts_credentials; - -/* Main struct for grpc ALTS server credential. */ -typedef struct grpc_alts_server_credentials { - grpc_server_credentials base; - grpc_alts_credentials_options* options; - char* handshaker_service_url; -} grpc_alts_server_credentials; - -/** - * This method creates an ALTS channel credential object. - * - * - options: grpc ALTS credentials options instance for client. - * - * It returns the created ALTS channel credential object. - */ -grpc_channel_credentials* grpc_alts_credentials_create( - const grpc_alts_credentials_options* options); - -/** - * This method creates an ALTS server credential object. - * - * - options: grpc ALTS credentials options instance for server. - * - * It returns the created ALTS server credential object. - */ -grpc_server_credentials* grpc_alts_server_credentials_create( - const grpc_alts_credentials_options* options); - -/** - * This method creates an ALTS channel credential object with customized - * information provided by caller. - * - * - options: grpc ALTS credentials options instance for client. - * - handshaker_service_url: address of ALTS handshaker service in the format of - * "host:port". If it's nullptr, the address of default metadata server will - * be used. - * - enable_untrusted_alts: a boolean flag used to enable ALTS in untrusted - * mode. This mode can be enabled when we are sure ALTS is running on GCP or - * for testing purpose. - * - * It returns nullptr if the flag is disabled AND ALTS is not running on GCP. - * Otherwise, it returns the created credential object. - */ - -grpc_channel_credentials* grpc_alts_credentials_create_customized( - const grpc_alts_credentials_options* options, - const char* handshaker_service_url, bool enable_untrusted_alts); - -/** - * This method creates an ALTS server credential object with customized - * information provided by caller. - * - * - options: grpc ALTS credentials options instance for server. - * - handshaker_service_url: address of ALTS handshaker service in the format of - * "host:port". If it's nullptr, the address of default metadata server will - * be used. - * - enable_untrusted_alts: a boolean flag used to enable ALTS in untrusted - * mode. This mode can be enabled when we are sure ALTS is running on GCP or - * for testing purpose. - * - * It returns nullptr if the flag is disabled and ALTS is not running on GCP. - * Otherwise, it returns the created credential object. - */ -grpc_server_credentials* grpc_alts_server_credentials_create_customized( - const grpc_alts_credentials_options* options, - const char* handshaker_service_url, bool enable_untrusted_alts); - -#endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_ALTS_ALTS_CREDENTIALS_H */ diff --git a/src/core/lib/security/credentials/alts/check_gcp_environment.cc b/src/core/lib/security/credentials/alts/check_gcp_environment.cc deleted file mode 100644 index 96807876cf..0000000000 --- a/src/core/lib/security/credentials/alts/check_gcp_environment.cc +++ /dev/null @@ -1,72 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/lib/security/credentials/alts/check_gcp_environment.h" - -#include -#include -#include - -#include -#include - -const size_t kBiosDataBufferSize = 256; - -static char* trim(const char* src) { - if (src == nullptr) { - return nullptr; - } - char* des = nullptr; - size_t start = 0, end = strlen(src) - 1; - /* find the last character that is not a whitespace. */ - while (end != 0 && isspace(src[end])) { - end--; - } - /* find the first character that is not a whitespace. */ - while (start < strlen(src) && isspace(src[start])) { - start++; - } - if (start <= end) { - des = static_cast( - gpr_zalloc(sizeof(char) * (end - start + 2 /* '\0' */))); - memcpy(des, src + start, end - start + 1); - } - return des; -} - -namespace grpc_core { -namespace internal { - -char* read_bios_file(const char* bios_file) { - FILE* fp = fopen(bios_file, "r"); - if (!fp) { - gpr_log(GPR_ERROR, "BIOS data file cannot be opened."); - return nullptr; - } - char buf[kBiosDataBufferSize + 1]; - size_t ret = fread(buf, sizeof(char), kBiosDataBufferSize, fp); - buf[ret] = '\0'; - char* trimmed_buf = trim(buf); - fclose(fp); - return trimmed_buf; -} - -} // namespace internal -} // namespace grpc_core diff --git a/src/core/lib/security/credentials/alts/check_gcp_environment.h b/src/core/lib/security/credentials/alts/check_gcp_environment.h deleted file mode 100644 index aea4cea643..0000000000 --- a/src/core/lib/security/credentials/alts/check_gcp_environment.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_LIB_SECURITY_CREDENTIALS_ALTS_CHECK_GCP_ENVIRONMENT_H -#define GRPC_CORE_LIB_SECURITY_CREDENTIALS_ALTS_CHECK_GCP_ENVIRONMENT_H - -namespace grpc_core { -namespace internal { - -/** - * This method is a helper function that reads a file containing system bios - * data. Exposed for testing only. - * - * - bios_file: a file containing BIOS data used to determine GCE tenancy - * information. - * - * It returns a buffer containing the data read from the file. - */ -char* read_bios_file(const char* bios_file); - -/** - * This method checks if system BIOS data contains Google-specific phrases. - * Exposed for testing only. - * - * - bios_data: a buffer containing system BIOS data. - * - * It returns true if the BIOS data contains Google-specific phrases, and false - * otherwise. - */ -bool check_bios_data(const char* bios_data); - -} // namespace internal -} // namespace grpc_core - -/** - * This method checks if a VM (Windows or Linux) is running within Google - * compute Engine (GCE) or not. It returns true if the VM is running in GCE and - * false otherwise. - */ -bool grpc_alts_is_running_on_gcp(); - -#endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_ALTS_CHECK_GCP_ENVIRONMENT_H */ diff --git a/src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc b/src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc deleted file mode 100644 index 7c4d7a71cd..0000000000 --- a/src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc +++ /dev/null @@ -1,67 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#ifdef GPR_LINUX - -#include "src/core/lib/security/credentials/alts/check_gcp_environment.h" - -#include -#include - -#include - -#define GRPC_ALTS_EXPECT_NAME_GOOGLE "Google" -#define GRPC_ALTS_EXPECT_NAME_GCE "Google Compute Engine" -#define GRPC_ALTS_PRODUCT_NAME_FILE "/sys/class/dmi/id/product_name" - -static bool g_compute_engine_detection_done = false; -static bool g_is_on_compute_engine = false; -static gpr_mu g_mu; -static gpr_once g_once = GPR_ONCE_INIT; - -namespace grpc_core { -namespace internal { - -bool check_bios_data(const char* bios_data_file) { - char* bios_data = read_bios_file(bios_data_file); - bool result = (!strcmp(bios_data, GRPC_ALTS_EXPECT_NAME_GOOGLE)) || - (!strcmp(bios_data, GRPC_ALTS_EXPECT_NAME_GCE)); - gpr_free(bios_data); - return result; -} - -} // namespace internal -} // namespace grpc_core - -static void init_mu(void) { gpr_mu_init(&g_mu); } - -bool grpc_alts_is_running_on_gcp() { - gpr_once_init(&g_once, init_mu); - gpr_mu_lock(&g_mu); - if (!g_compute_engine_detection_done) { - g_is_on_compute_engine = - grpc_core::internal::check_bios_data(GRPC_ALTS_PRODUCT_NAME_FILE); - g_compute_engine_detection_done = true; - } - gpr_mu_unlock(&g_mu); - return g_is_on_compute_engine; -} - -#endif // GPR_LINUX diff --git a/src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc b/src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc deleted file mode 100644 index d97681b86d..0000000000 --- a/src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc +++ /dev/null @@ -1,33 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#if !defined(GPR_LINUX) && !defined(GPR_WINDOWS) - -#include "src/core/lib/security/credentials/alts/check_gcp_environment.h" - -#include - -bool grpc_alts_is_running_on_gcp() { - gpr_log(GPR_ERROR, - "Platforms other than Linux and Windows are not supported"); - return false; -} - -#endif // !defined(LINUX) && !defined(GPR_WINDOWS) diff --git a/src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc b/src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc deleted file mode 100644 index 55efe0e9dd..0000000000 --- a/src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc +++ /dev/null @@ -1,114 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#ifdef GPR_WINDOWS - -#include "src/core/lib/security/credentials/alts/check_gcp_environment.h" - -#include -#include -#include -#include - -#include -#include -#include - -#define GRPC_ALTS_EXPECT_NAME_GOOGLE "Google" -#define GRPC_ALTS_WINDOWS_CHECK_COMMAND "powershell.exe" -#define GRPC_ALTS_WINDOWS_CHECK_COMMAND_ARGS \ - "(Get-WmiObject -Class Win32_BIOS).Manufacturer" -#define GRPC_ALTS_WINDOWS_CHECK_BIOS_FILE "windows_bios.data" - -const size_t kBiosDataBufferSize = 256; - -static bool g_compute_engine_detection_done = false; -static bool g_is_on_compute_engine = false; -static gpr_mu g_mu; -static gpr_once g_once = GPR_ONCE_INIT; - -namespace grpc_core { -namespace internal { - -bool check_bios_data(const char* bios_data_file) { - char* bios_data = read_bios_file(bios_data_file); - bool result = !strcmp(bios_data, GRPC_ALTS_EXPECT_NAME_GOOGLE); - remove(GRPC_ALTS_WINDOWS_CHECK_BIOS_FILE); - gpr_free(bios_data); - return result; -} - -} // namespace internal -} // namespace grpc_core - -static void init_mu(void) { gpr_mu_init(&g_mu); } - -static bool run_powershell() { - SECURITY_ATTRIBUTES sa; - sa.nLength = sizeof(sa); - sa.lpSecurityDescriptor = NULL; - sa.bInheritHandle = TRUE; - HANDLE h = CreateFile(_T(GRPC_ALTS_WINDOWS_CHECK_BIOS_FILE), GENERIC_WRITE, - FILE_SHARE_WRITE | FILE_SHARE_READ, &sa, OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL, NULL); - if (h == INVALID_HANDLE_VALUE) { - gpr_log(GPR_ERROR, "CreateFile failed (%d).", GetLastError()); - return false; - } - PROCESS_INFORMATION pi; - STARTUPINFO si; - DWORD flags = CREATE_NO_WINDOW; - ZeroMemory(&pi, sizeof(pi)); - ZeroMemory(&si, sizeof(si)); - si.cb = sizeof(si); - si.dwFlags |= STARTF_USESTDHANDLES; - si.hStdInput = NULL; - si.hStdError = h; - si.hStdOutput = h; - TCHAR cmd[kBiosDataBufferSize]; - _sntprintf(cmd, kBiosDataBufferSize, _T("%s %s"), - _T(GRPC_ALTS_WINDOWS_CHECK_COMMAND), - _T(GRPC_ALTS_WINDOWS_CHECK_COMMAND_ARGS)); - if (!CreateProcess(NULL, cmd, NULL, NULL, TRUE, flags, NULL, NULL, &si, - &pi)) { - gpr_log(GPR_ERROR, "CreateProcess failed (%d).\n", GetLastError()); - return false; - } - WaitForSingleObject(pi.hProcess, INFINITE); - CloseHandle(pi.hProcess); - CloseHandle(pi.hThread); - CloseHandle(h); - return true; -} - -bool grpc_alts_is_running_on_gcp() { - gpr_once_init(&g_once, init_mu); - gpr_mu_lock(&g_mu); - if (!g_compute_engine_detection_done) { - g_is_on_compute_engine = - run_powershell() && - grpc_core::internal::check_bios_data(GRPC_ALTS_WINDOWS_CHECK_BIOS_FILE); - g_compute_engine_detection_done = true; - } - gpr_mu_unlock(&g_mu); - return g_is_on_compute_engine; -} - -#endif // GPR_WINDOWS diff --git a/src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc b/src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc deleted file mode 100644 index 7d54e8346f..0000000000 --- a/src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc +++ /dev/null @@ -1,126 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include -#include - -#include -#include -#include - -#include "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h" -#include "src/core/tsi/alts/handshaker/transport_security_common_api.h" - -static grpc_alts_credentials_options* alts_client_options_copy( - const grpc_alts_credentials_options* options); - -static void alts_client_options_destroy(grpc_alts_credentials_options* options); - -static target_service_account* target_service_account_create( - const char* service_account) { - if (service_account == nullptr) { - return nullptr; - } - auto* sa = static_cast( - gpr_zalloc(sizeof(target_service_account))); - sa->data = gpr_strdup(service_account); - return sa; -} - -bool grpc_alts_credentials_client_options_add_target_service_account( - grpc_alts_credentials_client_options* options, - const char* service_account) { - if (options == nullptr || service_account == nullptr) { - gpr_log( - GPR_ERROR, - "Invalid nullptr arguments to " - "grpc_alts_credentials_client_options_add_target_service_account()"); - return false; - } - target_service_account* node = target_service_account_create(service_account); - node->next = options->target_account_list_head; - options->target_account_list_head = node; - return true; -} - -static void target_service_account_destroy( - target_service_account* service_account) { - if (service_account == nullptr) { - return; - } - gpr_free(service_account->data); - gpr_free(service_account); -} - -static const grpc_alts_credentials_options_vtable vtable = { - alts_client_options_copy, alts_client_options_destroy}; - -grpc_alts_credentials_options* grpc_alts_credentials_client_options_create() { - auto client_options = static_cast( - gpr_zalloc(sizeof(grpc_alts_credentials_client_options))); - client_options->base.vtable = &vtable; - return &client_options->base; -} - -static grpc_alts_credentials_options* alts_client_options_copy( - const grpc_alts_credentials_options* options) { - if (options == nullptr) { - return nullptr; - } - grpc_alts_credentials_options* new_options = - grpc_alts_credentials_client_options_create(); - auto new_client_options = - reinterpret_cast(new_options); - /* Copy target service accounts. */ - target_service_account* prev = nullptr; - auto node = - (reinterpret_cast(options)) - ->target_account_list_head; - while (node != nullptr) { - target_service_account* new_node = - target_service_account_create(node->data); - if (prev == nullptr) { - new_client_options->target_account_list_head = new_node; - } else { - prev->next = new_node; - } - prev = new_node; - node = node->next; - } - /* Copy rpc protocol versions. */ - grpc_gcp_rpc_protocol_versions_copy(&options->rpc_versions, - &new_options->rpc_versions); - return new_options; -} - -static void alts_client_options_destroy( - grpc_alts_credentials_options* options) { - if (options == nullptr) { - return; - } - auto* client_options = - reinterpret_cast(options); - target_service_account* node = client_options->target_account_list_head; - while (node != nullptr) { - target_service_account* next_node = node->next; - target_service_account_destroy(node); - node = next_node; - } -} diff --git a/src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc b/src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc deleted file mode 100644 index d428171540..0000000000 --- a/src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc +++ /dev/null @@ -1,46 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h" - -#include -#include - -grpc_alts_credentials_options* grpc_alts_credentials_options_copy( - const grpc_alts_credentials_options* options) { - if (options != nullptr && options->vtable != nullptr && - options->vtable->copy != nullptr) { - return options->vtable->copy(options); - } - /* An error occurred. */ - gpr_log(GPR_ERROR, - "Invalid arguments to grpc_alts_credentials_options_copy()"); - return nullptr; -} - -void grpc_alts_credentials_options_destroy( - grpc_alts_credentials_options* options) { - if (options != nullptr) { - if (options->vtable != nullptr && options->vtable->destruct != nullptr) { - options->vtable->destruct(options); - } - gpr_free(options); - } -} diff --git a/src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h b/src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h deleted file mode 100644 index 4e46d9f2de..0000000000 --- a/src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_LIB_SECURITY_CREDENTIALS_ALTS_GRPC_ALTS_CREDENTIALS_OPTIONS_H -#define GRPC_CORE_LIB_SECURITY_CREDENTIALS_ALTS_GRPC_ALTS_CREDENTIALS_OPTIONS_H - -#include - -#include - -#include "src/core/tsi/alts/handshaker/transport_security_common_api.h" - -/** - * Main interface for ALTS credentials options. The options will contain - * information that will be passed from grpc to TSI layer such as RPC protocol - * versions. ALTS client (channel) and server credentials will have their own - * implementation of this interface. The APIs listed in this header are - * thread-compatible. - */ -typedef struct grpc_alts_credentials_options grpc_alts_credentials_options; - -/* V-table for grpc_alts_credentials_options */ -typedef struct grpc_alts_credentials_options_vtable { - grpc_alts_credentials_options* (*copy)( - const grpc_alts_credentials_options* options); - void (*destruct)(grpc_alts_credentials_options* options); -} grpc_alts_credentials_options_vtable; - -struct grpc_alts_credentials_options { - const struct grpc_alts_credentials_options_vtable* vtable; - grpc_gcp_rpc_protocol_versions rpc_versions; -}; - -typedef struct target_service_account { - struct target_service_account* next; - char* data; -} target_service_account; - -/** - * Main struct for ALTS client credentials options. The options contain a - * a list of target service accounts (if specified) used for secure naming - * check. - */ -typedef struct grpc_alts_credentials_client_options { - grpc_alts_credentials_options base; - target_service_account* target_account_list_head; -} grpc_alts_credentials_client_options; - -/** - * Main struct for ALTS server credentials options. The options currently - * do not contain any server-specific fields. - */ -typedef struct grpc_alts_credentials_server_options { - grpc_alts_credentials_options base; -} grpc_alts_credentials_server_options; - -/** - * This method performs a deep copy on grpc_alts_credentials_options instance. - * - * - options: a grpc_alts_credentials_options instance that needs to be copied. - * - * It returns a new grpc_alts_credentials_options instance on success and NULL - * on failure. - */ -grpc_alts_credentials_options* grpc_alts_credentials_options_copy( - const grpc_alts_credentials_options* options); - -/** - * This method destroys a grpc_alts_credentials_options instance by - * de-allocating all of its occupied memory. - * - * - options: a grpc_alts_credentials_options instance that needs to be - * destroyed. - */ -void grpc_alts_credentials_options_destroy( - grpc_alts_credentials_options* options); - -/* This method creates a grpc ALTS credentials client options instance. */ -grpc_alts_credentials_options* grpc_alts_credentials_client_options_create(); - -/* This method creates a grpc ALTS credentials server options instance. */ -grpc_alts_credentials_options* grpc_alts_credentials_server_options_create(); - -/** - * This method adds a target service account to grpc ALTS credentials client - * options instance. - * - * - options: grpc ALTS credentials client options instance. - * - service_account: service account of target endpoint. - * - * It returns true on success and false on failure. - */ -bool grpc_alts_credentials_client_options_add_target_service_account( - grpc_alts_credentials_client_options* options, const char* service_account); - -#endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_ALTS_GRPC_ALTS_CREDENTIALS_OPTIONS_H \ - */ diff --git a/src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc b/src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc deleted file mode 100644 index 62aa7a620a..0000000000 --- a/src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc +++ /dev/null @@ -1,58 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include -#include - -#include -#include - -#include "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h" -#include "src/core/tsi/alts/handshaker/transport_security_common_api.h" - -static grpc_alts_credentials_options* alts_server_options_copy( - const grpc_alts_credentials_options* options); - -static void alts_server_options_destroy( - grpc_alts_credentials_options* options) {} - -static const grpc_alts_credentials_options_vtable vtable = { - alts_server_options_copy, alts_server_options_destroy}; - -grpc_alts_credentials_options* grpc_alts_credentials_server_options_create() { - grpc_alts_credentials_server_options* server_options = - static_cast( - gpr_zalloc(sizeof(*server_options))); - server_options->base.vtable = &vtable; - return &server_options->base; -} - -static grpc_alts_credentials_options* alts_server_options_copy( - const grpc_alts_credentials_options* options) { - if (options == nullptr) { - return nullptr; - } - grpc_alts_credentials_options* new_options = - grpc_alts_credentials_server_options_create(); - /* Copy rpc protocol versions. */ - grpc_gcp_rpc_protocol_versions_copy(&options->rpc_versions, - &new_options->rpc_versions); - return new_options; -} diff --git a/src/core/lib/security/security_connector/alts_security_connector.cc b/src/core/lib/security/security_connector/alts_security_connector.cc deleted file mode 100644 index 5ff7d7938b..0000000000 --- a/src/core/lib/security/security_connector/alts_security_connector.cc +++ /dev/null @@ -1,287 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/lib/security/security_connector/alts_security_connector.h" - -#include -#include - -#include -#include -#include -#include - -#include "src/core/lib/security/credentials/alts/alts_credentials.h" -#include "src/core/lib/security/transport/security_handshaker.h" -#include "src/core/lib/transport/transport.h" -#include "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h" - -typedef struct { - grpc_channel_security_connector base; - char* target_name; -} grpc_alts_channel_security_connector; - -typedef struct { - grpc_server_security_connector base; -} grpc_alts_server_security_connector; - -static void alts_channel_destroy(grpc_security_connector* sc) { - if (sc == nullptr) { - return; - } - auto c = reinterpret_cast(sc); - grpc_call_credentials_unref(c->base.request_metadata_creds); - grpc_channel_credentials_unref(c->base.channel_creds); - gpr_free(c->target_name); - gpr_free(sc); -} - -static void alts_server_destroy(grpc_security_connector* sc) { - if (sc == nullptr) { - return; - } - auto c = reinterpret_cast(sc); - grpc_server_credentials_unref(c->base.server_creds); - gpr_free(sc); -} - -static void alts_channel_add_handshakers( - grpc_channel_security_connector* sc, - grpc_handshake_manager* handshake_manager) { - tsi_handshaker* handshaker = nullptr; - auto c = reinterpret_cast(sc); - grpc_alts_credentials* creds = - reinterpret_cast(c->base.channel_creds); - GPR_ASSERT(alts_tsi_handshaker_create(creds->options, c->target_name, - creds->handshaker_service_url, true, - &handshaker) == TSI_OK); - grpc_handshake_manager_add(handshake_manager, grpc_security_handshaker_create( - handshaker, &sc->base)); -} - -static void alts_server_add_handshakers( - grpc_server_security_connector* sc, - grpc_handshake_manager* handshake_manager) { - tsi_handshaker* handshaker = nullptr; - auto c = reinterpret_cast(sc); - grpc_alts_server_credentials* creds = - reinterpret_cast(c->base.server_creds); - GPR_ASSERT(alts_tsi_handshaker_create(creds->options, nullptr, - creds->handshaker_service_url, false, - &handshaker) == TSI_OK); - grpc_handshake_manager_add(handshake_manager, grpc_security_handshaker_create( - handshaker, &sc->base)); -} - -static void alts_set_rpc_protocol_versions( - grpc_gcp_rpc_protocol_versions* rpc_versions) { - grpc_gcp_rpc_protocol_versions_set_max(rpc_versions, - GRPC_PROTOCOL_VERSION_MAX_MAJOR, - GRPC_PROTOCOL_VERSION_MAX_MINOR); - grpc_gcp_rpc_protocol_versions_set_min(rpc_versions, - GRPC_PROTOCOL_VERSION_MIN_MAJOR, - GRPC_PROTOCOL_VERSION_MIN_MINOR); -} - -namespace grpc_core { -namespace internal { - -grpc_security_status grpc_alts_auth_context_from_tsi_peer( - const tsi_peer* peer, grpc_auth_context** ctx) { - if (peer == nullptr || ctx == nullptr) { - gpr_log(GPR_ERROR, - "Invalid arguments to grpc_alts_auth_context_from_tsi_peer()"); - return GRPC_SECURITY_ERROR; - } - *ctx = nullptr; - /* Validate certificate type. */ - const tsi_peer_property* cert_type_prop = - tsi_peer_get_property_by_name(peer, TSI_CERTIFICATE_TYPE_PEER_PROPERTY); - if (cert_type_prop == nullptr || - strncmp(cert_type_prop->value.data, TSI_ALTS_CERTIFICATE_TYPE, - cert_type_prop->value.length) != 0) { - gpr_log(GPR_ERROR, "Invalid or missing certificate type property."); - return GRPC_SECURITY_ERROR; - } - /* Validate RPC protocol versions. */ - const tsi_peer_property* rpc_versions_prop = - tsi_peer_get_property_by_name(peer, TSI_ALTS_RPC_VERSIONS); - if (rpc_versions_prop == nullptr) { - gpr_log(GPR_ERROR, "Missing rpc protocol versions property."); - return GRPC_SECURITY_ERROR; - } - grpc_gcp_rpc_protocol_versions local_versions, peer_versions; - alts_set_rpc_protocol_versions(&local_versions); - grpc_slice slice = grpc_slice_from_copied_buffer( - rpc_versions_prop->value.data, rpc_versions_prop->value.length); - bool decode_result = - grpc_gcp_rpc_protocol_versions_decode(slice, &peer_versions); - grpc_slice_unref(slice); - if (!decode_result) { - gpr_log(GPR_ERROR, "Invalid peer rpc protocol versions."); - return GRPC_SECURITY_ERROR; - } - /* TODO: Pass highest common rpc protocol version to grpc caller. */ - bool check_result = grpc_gcp_rpc_protocol_versions_check( - &local_versions, &peer_versions, nullptr); - if (!check_result) { - gpr_log(GPR_ERROR, "Mismatch of local and peer rpc protocol versions."); - return GRPC_SECURITY_ERROR; - } - /* Create auth context. */ - *ctx = grpc_auth_context_create(nullptr); - grpc_auth_context_add_cstring_property( - *ctx, GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME, - GRPC_ALTS_TRANSPORT_SECURITY_TYPE); - size_t i = 0; - for (i = 0; i < peer->property_count; i++) { - const tsi_peer_property* tsi_prop = &peer->properties[i]; - /* Add service account to auth context. */ - if (strcmp(tsi_prop->name, TSI_ALTS_SERVICE_ACCOUNT_PEER_PROPERTY) == 0) { - grpc_auth_context_add_property( - *ctx, TSI_ALTS_SERVICE_ACCOUNT_PEER_PROPERTY, tsi_prop->value.data, - tsi_prop->value.length); - GPR_ASSERT(grpc_auth_context_set_peer_identity_property_name( - *ctx, TSI_ALTS_SERVICE_ACCOUNT_PEER_PROPERTY) == 1); - } - } - if (!grpc_auth_context_peer_is_authenticated(*ctx)) { - gpr_log(GPR_ERROR, "Invalid unauthenticated peer."); - GRPC_AUTH_CONTEXT_UNREF(*ctx, "test"); - *ctx = nullptr; - return GRPC_SECURITY_ERROR; - } - return GRPC_SECURITY_OK; -} - -} // namespace internal -} // namespace grpc_core - -static void alts_check_peer(grpc_security_connector* sc, tsi_peer peer, - grpc_auth_context** auth_context, - grpc_closure* on_peer_checked) { - grpc_security_status status; - status = grpc_core::internal::grpc_alts_auth_context_from_tsi_peer( - &peer, auth_context); - tsi_peer_destruct(&peer); - grpc_error* error = - status == GRPC_SECURITY_OK - ? GRPC_ERROR_NONE - : GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "Could not get ALTS auth context from TSI peer"); - GRPC_CLOSURE_SCHED(on_peer_checked, error); -} - -static int alts_channel_cmp(grpc_security_connector* sc1, - grpc_security_connector* sc2) { - grpc_alts_channel_security_connector* c1 = - reinterpret_cast(sc1); - grpc_alts_channel_security_connector* c2 = - reinterpret_cast(sc2); - int c = grpc_channel_security_connector_cmp(&c1->base, &c2->base); - if (c != 0) return c; - return strcmp(c1->target_name, c2->target_name); -} - -static int alts_server_cmp(grpc_security_connector* sc1, - grpc_security_connector* sc2) { - grpc_alts_server_security_connector* c1 = - reinterpret_cast(sc1); - grpc_alts_server_security_connector* c2 = - reinterpret_cast(sc2); - return grpc_server_security_connector_cmp(&c1->base, &c2->base); -} - -static grpc_security_connector_vtable alts_channel_vtable = { - alts_channel_destroy, alts_check_peer, alts_channel_cmp}; - -static grpc_security_connector_vtable alts_server_vtable = { - alts_server_destroy, alts_check_peer, alts_server_cmp}; - -static bool alts_check_call_host(grpc_channel_security_connector* sc, - const char* host, - grpc_auth_context* auth_context, - grpc_closure* on_call_host_checked, - grpc_error** error) { - grpc_alts_channel_security_connector* alts_sc = - reinterpret_cast(sc); - if (host == nullptr || alts_sc == nullptr || - strcmp(host, alts_sc->target_name) != 0) { - *error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "ALTS call host does not match target name"); - } - return true; -} - -static void alts_cancel_check_call_host(grpc_channel_security_connector* sc, - grpc_closure* on_call_host_checked, - grpc_error* error) { - GRPC_ERROR_UNREF(error); -} - -grpc_security_status grpc_alts_channel_security_connector_create( - grpc_channel_credentials* channel_creds, - grpc_call_credentials* request_metadata_creds, const char* target_name, - grpc_channel_security_connector** sc) { - if (channel_creds == nullptr || sc == nullptr || target_name == nullptr) { - gpr_log( - GPR_ERROR, - "Invalid arguments to grpc_alts_channel_security_connector_create()"); - return GRPC_SECURITY_ERROR; - } - auto c = static_cast( - gpr_zalloc(sizeof(grpc_alts_channel_security_connector))); - gpr_ref_init(&c->base.base.refcount, 1); - c->base.base.vtable = &alts_channel_vtable; - c->base.add_handshakers = alts_channel_add_handshakers; - c->base.channel_creds = grpc_channel_credentials_ref(channel_creds); - c->base.request_metadata_creds = - grpc_call_credentials_ref(request_metadata_creds); - c->base.check_call_host = alts_check_call_host; - c->base.cancel_check_call_host = alts_cancel_check_call_host; - grpc_alts_credentials* creds = - reinterpret_cast(c->base.channel_creds); - alts_set_rpc_protocol_versions(&creds->options->rpc_versions); - c->target_name = gpr_strdup(target_name); - *sc = &c->base; - return GRPC_SECURITY_OK; -} - -grpc_security_status grpc_alts_server_security_connector_create( - grpc_server_credentials* server_creds, - grpc_server_security_connector** sc) { - if (server_creds == nullptr || sc == nullptr) { - gpr_log( - GPR_ERROR, - "Invalid arguments to grpc_alts_server_security_connector_create()"); - return GRPC_SECURITY_ERROR; - } - auto c = static_cast( - gpr_zalloc(sizeof(grpc_alts_server_security_connector))); - gpr_ref_init(&c->base.base.refcount, 1); - c->base.base.vtable = &alts_server_vtable; - c->base.server_creds = grpc_server_credentials_ref(server_creds); - c->base.add_handshakers = alts_server_add_handshakers; - grpc_alts_server_credentials* creds = - reinterpret_cast(c->base.server_creds); - alts_set_rpc_protocol_versions(&creds->options->rpc_versions); - *sc = &c->base; - return GRPC_SECURITY_OK; -} diff --git a/src/core/lib/security/security_connector/alts_security_connector.h b/src/core/lib/security/security_connector/alts_security_connector.h deleted file mode 100644 index e7e4cffe2a..0000000000 --- a/src/core/lib/security/security_connector/alts_security_connector.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_LIB_SECURITY_SECURITY_CONNECTOR_ALTS_SECURITY_CONNECTOR_H -#define GRPC_CORE_LIB_SECURITY_SECURITY_CONNECTOR_ALTS_SECURITY_CONNECTOR_H - -#include - -#include "src/core/lib/security/context/security_context.h" -#include "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h" - -#define GRPC_ALTS_TRANSPORT_SECURITY_TYPE "alts" - -/** - * This method creates an ALTS channel security connector. - * - * - channel_creds: channel credential instance. - * - request_metadata_creds: credential object which will be sent with each - * request. This parameter can be nullptr. - * - target_name: the name of the endpoint that the channel is connecting to. - * - sc: address of ALTS channel security connector instance to be returned from - * the method. - * - * It returns GRPC_SECURITY_OK on success, and an error stauts code on failure. - */ -grpc_security_status grpc_alts_channel_security_connector_create( - grpc_channel_credentials* channel_creds, - grpc_call_credentials* request_metadata_creds, const char* target_name, - grpc_channel_security_connector** sc); - -/** - * This method creates an ALTS server security connector. - * - * - server_creds: server credential instance. - * - sc: address of ALTS server security connector instance to be returned from - * the method. - * - * It returns GRPC_SECURITY_OK on success, and an error status code on failure. - */ -grpc_security_status grpc_alts_server_security_connector_create( - grpc_server_credentials* server_creds, grpc_server_security_connector** sc); - -namespace grpc_core { -namespace internal { - -/* Exposed only for testing. */ -grpc_security_status grpc_alts_auth_context_from_tsi_peer( - const tsi_peer* peer, grpc_auth_context** ctx); - -} // namespace internal -} // namespace grpc_core - -#endif /* GRPC_CORE_LIB_SECURITY_SECURITY_CONNECTOR_ALTS_SECURITY_CONNECTOR_H \ - */ diff --git a/src/core/plugin_registry/grpc_plugin_registry.cc b/src/core/plugin_registry/grpc_plugin_registry.cc index 6f11e6bb5b..ccf5f79a8e 100644 --- a/src/core/plugin_registry/grpc_plugin_registry.cc +++ b/src/core/plugin_registry/grpc_plugin_registry.cc @@ -24,12 +24,12 @@ void grpc_http_filters_init(void); void grpc_http_filters_shutdown(void); void grpc_chttp2_plugin_init(void); void grpc_chttp2_plugin_shutdown(void); +void grpc_tsi_alts_init(void); +void grpc_tsi_alts_shutdown(void); void grpc_deadline_filter_init(void); void grpc_deadline_filter_shutdown(void); void grpc_client_channel_init(void); void grpc_client_channel_shutdown(void); -void grpc_tsi_alts_init(void); -void grpc_tsi_alts_shutdown(void); void grpc_inproc_plugin_init(void); void grpc_inproc_plugin_shutdown(void); void grpc_resolver_fake_init(void); @@ -60,12 +60,12 @@ void grpc_register_built_in_plugins(void) { grpc_http_filters_shutdown); grpc_register_plugin(grpc_chttp2_plugin_init, grpc_chttp2_plugin_shutdown); + grpc_register_plugin(grpc_tsi_alts_init, + grpc_tsi_alts_shutdown); grpc_register_plugin(grpc_deadline_filter_init, grpc_deadline_filter_shutdown); grpc_register_plugin(grpc_client_channel_init, grpc_client_channel_shutdown); - grpc_register_plugin(grpc_tsi_alts_init, - grpc_tsi_alts_shutdown); grpc_register_plugin(grpc_inproc_plugin_init, grpc_inproc_plugin_shutdown); grpc_register_plugin(grpc_resolver_fake_init, diff --git a/src/core/tsi/alts/crypt/aes_gcm.cc b/src/core/tsi/alts/crypt/aes_gcm.cc deleted file mode 100644 index 02b1ac4492..0000000000 --- a/src/core/tsi/alts/crypt/aes_gcm.cc +++ /dev/null @@ -1,687 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/tsi/alts/crypt/gsec.h" - -#include -#include -#include -#include -#include -#include - -#include - -constexpr size_t kKdfKeyLen = 32; -constexpr size_t kKdfCounterLen = 6; -constexpr size_t kKdfCounterOffset = 2; -constexpr size_t kRekeyAeadKeyLen = kAes128GcmKeyLength; - -/* Struct for additional data required if rekeying is enabled. */ -struct gsec_aes_gcm_aead_rekey_data { - uint8_t kdf_counter[kKdfCounterLen]; - uint8_t nonce_mask[kAesGcmNonceLength]; -}; - -/* Main struct for AES_GCM crypter interface. */ -struct gsec_aes_gcm_aead_crypter { - gsec_aead_crypter crypter; - size_t key_length; - size_t nonce_length; - size_t tag_length; - uint8_t* key; - gsec_aes_gcm_aead_rekey_data* rekey_data; - EVP_CIPHER_CTX* ctx; -}; - -static char* aes_gcm_get_openssl_errors() { - BIO* bio = BIO_new(BIO_s_mem()); - ERR_print_errors(bio); - BUF_MEM* mem = nullptr; - char* error_msg = nullptr; - BIO_get_mem_ptr(bio, &mem); - if (mem != nullptr) { - error_msg = static_cast(gpr_malloc(mem->length + 1)); - memcpy(error_msg, mem->data, mem->length); - error_msg[mem->length] = '\0'; - } - BIO_free_all(bio); - return error_msg; -} - -static void aes_gcm_format_errors(const char* error_msg, char** error_details) { - if (error_details == nullptr) { - return; - } - unsigned long error = ERR_get_error(); - if (error == 0 && error_msg != nullptr) { - *error_details = static_cast(gpr_malloc(strlen(error_msg) + 1)); - memcpy(*error_details, error_msg, strlen(error_msg) + 1); - return; - } - char* openssl_errors = aes_gcm_get_openssl_errors(); - if (openssl_errors != nullptr && error_msg != nullptr) { - size_t len = strlen(error_msg) + strlen(openssl_errors) + 2; /* ", " */ - *error_details = static_cast(gpr_malloc(len + 1)); - snprintf(*error_details, len + 1, "%s, %s", error_msg, openssl_errors); - gpr_free(openssl_errors); - } -} - -static grpc_status_code gsec_aes_gcm_aead_crypter_max_ciphertext_and_tag_length( - const gsec_aead_crypter* crypter, size_t plaintext_length, - size_t* max_ciphertext_and_tag_length, char** error_details) { - if (max_ciphertext_and_tag_length == nullptr) { - aes_gcm_format_errors("max_ciphertext_and_tag_length is nullptr.", - error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - gsec_aes_gcm_aead_crypter* aes_gcm_crypter = - reinterpret_cast( - const_cast(crypter)); - *max_ciphertext_and_tag_length = - plaintext_length + aes_gcm_crypter->tag_length; - return GRPC_STATUS_OK; -} - -static grpc_status_code gsec_aes_gcm_aead_crypter_max_plaintext_length( - const gsec_aead_crypter* crypter, size_t ciphertext_and_tag_length, - size_t* max_plaintext_length, char** error_details) { - if (max_plaintext_length == nullptr) { - aes_gcm_format_errors("max_plaintext_length is nullptr.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - gsec_aes_gcm_aead_crypter* aes_gcm_crypter = - reinterpret_cast( - const_cast(crypter)); - if (ciphertext_and_tag_length < aes_gcm_crypter->tag_length) { - *max_plaintext_length = 0; - aes_gcm_format_errors( - "ciphertext_and_tag_length is smaller than tag_length.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - *max_plaintext_length = - ciphertext_and_tag_length - aes_gcm_crypter->tag_length; - return GRPC_STATUS_OK; -} - -static grpc_status_code gsec_aes_gcm_aead_crypter_nonce_length( - const gsec_aead_crypter* crypter, size_t* nonce_length, - char** error_details) { - if (nonce_length == nullptr) { - aes_gcm_format_errors("nonce_length is nullptr.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - gsec_aes_gcm_aead_crypter* aes_gcm_crypter = - reinterpret_cast( - const_cast(crypter)); - *nonce_length = aes_gcm_crypter->nonce_length; - return GRPC_STATUS_OK; -} - -static grpc_status_code gsec_aes_gcm_aead_crypter_key_length( - const gsec_aead_crypter* crypter, size_t* key_length, - char** error_details) { - if (key_length == nullptr) { - aes_gcm_format_errors("key_length is nullptr.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - gsec_aes_gcm_aead_crypter* aes_gcm_crypter = - reinterpret_cast( - const_cast(crypter)); - *key_length = aes_gcm_crypter->key_length; - return GRPC_STATUS_OK; -} - -static grpc_status_code gsec_aes_gcm_aead_crypter_tag_length( - const gsec_aead_crypter* crypter, size_t* tag_length, - char** error_details) { - if (tag_length == nullptr) { - aes_gcm_format_errors("tag_length is nullptr.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - gsec_aes_gcm_aead_crypter* aes_gcm_crypter = - reinterpret_cast( - const_cast(crypter)); - *tag_length = aes_gcm_crypter->tag_length; - return GRPC_STATUS_OK; -} - -static void aes_gcm_mask_nonce(uint8_t* dst, const uint8_t* nonce, - const uint8_t* mask) { - uint64_t mask1; - uint32_t mask2; - memcpy(&mask1, mask, sizeof(mask1)); - memcpy(&mask2, mask + sizeof(mask1), sizeof(mask2)); - uint64_t nonce1; - uint32_t nonce2; - memcpy(&nonce1, nonce, sizeof(nonce1)); - memcpy(&nonce2, nonce + sizeof(nonce1), sizeof(nonce2)); - nonce1 ^= mask1; - nonce2 ^= mask2; - memcpy(dst, &nonce1, sizeof(nonce1)); - memcpy(dst + sizeof(nonce1), &nonce2, sizeof(nonce2)); -} - -static grpc_status_code aes_gcm_derive_aead_key(uint8_t* dst, - const uint8_t* kdf_key, - const uint8_t* kdf_counter) { - unsigned char buf[EVP_MAX_MD_SIZE]; - unsigned char ctr = 1; -#if OPENSSL_VERSION_NUMBER < 0x10100000L - HMAC_CTX hmac; - HMAC_CTX_init(&hmac); - if (!HMAC_Init_ex(&hmac, kdf_key, kKdfKeyLen, EVP_sha256(), nullptr) || - !HMAC_Update(&hmac, kdf_counter, kKdfCounterLen) || - !HMAC_Update(&hmac, &ctr, 1) || !HMAC_Final(&hmac, buf, nullptr)) { - HMAC_CTX_cleanup(&hmac); - return GRPC_STATUS_INTERNAL; - } - HMAC_CTX_cleanup(&hmac); -#else - HMAC_CTX* hmac = HMAC_CTX_new(); - if (hmac == nullptr) { - return GRPC_STATUS_INTERNAL; - } - if (!HMAC_Init_ex(hmac, kdf_key, kKdfKeyLen, EVP_sha256(), nullptr) || - !HMAC_Update(hmac, kdf_counter, kKdfCounterLen) || - !HMAC_Update(hmac, &ctr, 1) || !HMAC_Final(hmac, buf, nullptr)) { - HMAC_CTX_free(hmac); - return GRPC_STATUS_INTERNAL; - } - HMAC_CTX_free(hmac); -#endif - memcpy(dst, buf, kRekeyAeadKeyLen); - return GRPC_STATUS_OK; -} - -static grpc_status_code aes_gcm_rekey_if_required( - gsec_aes_gcm_aead_crypter* aes_gcm_crypter, const uint8_t* nonce, - char** error_details) { - // If rekey_data is nullptr, then rekeying is not supported and not required. - // If bytes 2-7 of kdf_counter differ from the (per message) nonce, then the - // encryption key is recomputed from a new kdf_counter to ensure that we don't - // encrypt more than 2^16 messages per encryption key (in each direction). - if (aes_gcm_crypter->rekey_data == nullptr || - memcmp(aes_gcm_crypter->rekey_data->kdf_counter, - nonce + kKdfCounterOffset, kKdfCounterLen) == 0) { - return GRPC_STATUS_OK; - } - memcpy(aes_gcm_crypter->rekey_data->kdf_counter, nonce + kKdfCounterOffset, - kKdfCounterLen); - uint8_t aead_key[kRekeyAeadKeyLen]; - if (aes_gcm_derive_aead_key(aead_key, aes_gcm_crypter->key, - aes_gcm_crypter->rekey_data->kdf_counter) != - GRPC_STATUS_OK) { - aes_gcm_format_errors("Rekeying failed in key derivation.", error_details); - return GRPC_STATUS_INTERNAL; - } - if (!EVP_DecryptInit_ex(aes_gcm_crypter->ctx, nullptr, nullptr, aead_key, - nullptr)) { - aes_gcm_format_errors("Rekeying failed in context update.", error_details); - return GRPC_STATUS_INTERNAL; - } - return GRPC_STATUS_OK; -} - -static grpc_status_code gsec_aes_gcm_aead_crypter_encrypt_iovec( - gsec_aead_crypter* crypter, const uint8_t* nonce, size_t nonce_length, - const struct iovec* aad_vec, size_t aad_vec_length, - const struct iovec* plaintext_vec, size_t plaintext_vec_length, - struct iovec ciphertext_vec, size_t* ciphertext_bytes_written, - char** error_details) { - gsec_aes_gcm_aead_crypter* aes_gcm_crypter = - reinterpret_cast(crypter); - // Input checks - if (nonce == nullptr) { - aes_gcm_format_errors("Nonce buffer is nullptr.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - if (kAesGcmNonceLength != nonce_length) { - aes_gcm_format_errors("Nonce buffer has the wrong length.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - if (aad_vec_length > 0 && aad_vec == nullptr) { - aes_gcm_format_errors("Non-zero aad_vec_length but aad_vec is nullptr.", - error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - if (plaintext_vec_length > 0 && plaintext_vec == nullptr) { - aes_gcm_format_errors( - "Non-zero plaintext_vec_length but plaintext_vec is nullptr.", - error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - if (ciphertext_bytes_written == nullptr) { - aes_gcm_format_errors("bytes_written is nullptr.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - *ciphertext_bytes_written = 0; - // rekey if required - if (aes_gcm_rekey_if_required(aes_gcm_crypter, nonce, error_details) != - GRPC_STATUS_OK) { - return GRPC_STATUS_INTERNAL; - } - // mask nonce if required - const uint8_t* nonce_aead = nonce; - uint8_t nonce_masked[kAesGcmNonceLength]; - if (aes_gcm_crypter->rekey_data != nullptr) { - aes_gcm_mask_nonce(nonce_masked, aes_gcm_crypter->rekey_data->nonce_mask, - nonce); - nonce_aead = nonce_masked; - } - // init openssl context - if (!EVP_EncryptInit_ex(aes_gcm_crypter->ctx, nullptr, nullptr, nullptr, - nonce_aead)) { - aes_gcm_format_errors("Initializing nonce failed", error_details); - return GRPC_STATUS_INTERNAL; - } - // process aad - size_t i; - for (i = 0; i < aad_vec_length; i++) { - const uint8_t* aad = static_cast(aad_vec[i].iov_base); - size_t aad_length = aad_vec[i].iov_len; - if (aad_length == 0) { - continue; - } - size_t aad_bytes_read = 0; - if (aad == nullptr) { - aes_gcm_format_errors("aad is nullptr.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - if (!EVP_EncryptUpdate(aes_gcm_crypter->ctx, nullptr, - reinterpret_cast(&aad_bytes_read), aad, - static_cast(aad_length)) || - aad_bytes_read != aad_length) { - aes_gcm_format_errors("Setting authenticated associated data failed", - error_details); - return GRPC_STATUS_INTERNAL; - } - } - uint8_t* ciphertext = static_cast(ciphertext_vec.iov_base); - size_t ciphertext_length = ciphertext_vec.iov_len; - if (ciphertext == nullptr) { - aes_gcm_format_errors("ciphertext is nullptr.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - // process plaintext - for (i = 0; i < plaintext_vec_length; i++) { - const uint8_t* plaintext = static_cast(plaintext_vec[i].iov_base); - size_t plaintext_length = plaintext_vec[i].iov_len; - if (plaintext == nullptr) { - if (plaintext_length == 0) { - continue; - } - aes_gcm_format_errors("plaintext is nullptr.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - if (ciphertext_length < plaintext_length) { - aes_gcm_format_errors( - "ciphertext is not large enough to hold the result.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - int bytes_written = 0; - int bytes_to_write = static_cast(plaintext_length); - if (!EVP_EncryptUpdate(aes_gcm_crypter->ctx, ciphertext, &bytes_written, - plaintext, bytes_to_write)) { - aes_gcm_format_errors("Encrypting plaintext failed.", error_details); - return GRPC_STATUS_INTERNAL; - } - if (bytes_written > bytes_to_write) { - aes_gcm_format_errors("More bytes written than expected.", error_details); - return GRPC_STATUS_INTERNAL; - } - ciphertext += bytes_written; - ciphertext_length -= bytes_written; - } - int bytes_written_temp = 0; - if (!EVP_EncryptFinal_ex(aes_gcm_crypter->ctx, nullptr, - &bytes_written_temp)) { - aes_gcm_format_errors("Finalizing encryption failed.", error_details); - return GRPC_STATUS_INTERNAL; - } - if (bytes_written_temp != 0) { - aes_gcm_format_errors("Openssl wrote some unexpected bytes.", - error_details); - return GRPC_STATUS_INTERNAL; - } - if (ciphertext_length < kAesGcmTagLength) { - aes_gcm_format_errors("ciphertext is too small to hold a tag.", - error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - - if (!EVP_CIPHER_CTX_ctrl(aes_gcm_crypter->ctx, EVP_CTRL_GCM_GET_TAG, - kAesGcmTagLength, ciphertext)) { - aes_gcm_format_errors("Writing tag failed.", error_details); - return GRPC_STATUS_INTERNAL; - } - ciphertext += kAesGcmTagLength; - ciphertext_length -= kAesGcmTagLength; - *ciphertext_bytes_written = ciphertext_vec.iov_len - ciphertext_length; - return GRPC_STATUS_OK; -} - -static grpc_status_code gsec_aes_gcm_aead_crypter_decrypt_iovec( - gsec_aead_crypter* crypter, const uint8_t* nonce, size_t nonce_length, - const struct iovec* aad_vec, size_t aad_vec_length, - const struct iovec* ciphertext_vec, size_t ciphertext_vec_length, - struct iovec plaintext_vec, size_t* plaintext_bytes_written, - char** error_details) { - gsec_aes_gcm_aead_crypter* aes_gcm_crypter = - reinterpret_cast( - const_cast(crypter)); - if (nonce == nullptr) { - aes_gcm_format_errors("Nonce buffer is nullptr.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - if (kAesGcmNonceLength != nonce_length) { - aes_gcm_format_errors("Nonce buffer has the wrong length.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - if (aad_vec_length > 0 && aad_vec == nullptr) { - aes_gcm_format_errors("Non-zero aad_vec_length but aad_vec is nullptr.", - error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - if (ciphertext_vec_length > 0 && ciphertext_vec == nullptr) { - aes_gcm_format_errors( - "Non-zero plaintext_vec_length but plaintext_vec is nullptr.", - error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - // Compute the total length so we can ensure we don't pass the tag into - // EVP_decrypt. - size_t total_ciphertext_length = 0; - size_t i; - for (i = 0; i < ciphertext_vec_length; i++) { - total_ciphertext_length += ciphertext_vec[i].iov_len; - } - if (total_ciphertext_length < kAesGcmTagLength) { - aes_gcm_format_errors("ciphertext is too small to hold a tag.", - error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - if (plaintext_bytes_written == nullptr) { - aes_gcm_format_errors("bytes_written is nullptr.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - *plaintext_bytes_written = 0; - // rekey if required - if (aes_gcm_rekey_if_required(aes_gcm_crypter, nonce, error_details) != - GRPC_STATUS_OK) { - aes_gcm_format_errors("Rekeying failed.", error_details); - return GRPC_STATUS_INTERNAL; - } - // mask nonce if required - const uint8_t* nonce_aead = nonce; - uint8_t nonce_masked[kAesGcmNonceLength]; - if (aes_gcm_crypter->rekey_data != nullptr) { - aes_gcm_mask_nonce(nonce_masked, aes_gcm_crypter->rekey_data->nonce_mask, - nonce); - nonce_aead = nonce_masked; - } - // init openssl context - if (!EVP_DecryptInit_ex(aes_gcm_crypter->ctx, nullptr, nullptr, nullptr, - nonce_aead)) { - aes_gcm_format_errors("Initializing nonce failed.", error_details); - return GRPC_STATUS_INTERNAL; - } - // process aad - for (i = 0; i < aad_vec_length; i++) { - const uint8_t* aad = static_cast(aad_vec[i].iov_base); - size_t aad_length = aad_vec[i].iov_len; - if (aad_length == 0) { - continue; - } - size_t aad_bytes_read = 0; - if (aad == nullptr) { - aes_gcm_format_errors("aad is nullptr.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - if (!EVP_DecryptUpdate(aes_gcm_crypter->ctx, nullptr, - reinterpret_cast(&aad_bytes_read), aad, - static_cast(aad_length)) || - aad_bytes_read != aad_length) { - aes_gcm_format_errors("Setting authenticated associated data failed.", - error_details); - return GRPC_STATUS_INTERNAL; - } - } - // process ciphertext - uint8_t* plaintext = static_cast(plaintext_vec.iov_base); - size_t plaintext_length = plaintext_vec.iov_len; - if (plaintext_length > 0 && plaintext == nullptr) { - aes_gcm_format_errors( - "plaintext is nullptr, but plaintext_length is positive.", - error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - const uint8_t* ciphertext = nullptr; - size_t ciphertext_length = 0; - for (i = 0; - i < ciphertext_vec_length && total_ciphertext_length > kAesGcmTagLength; - i++) { - ciphertext = static_cast(ciphertext_vec[i].iov_base); - ciphertext_length = ciphertext_vec[i].iov_len; - if (ciphertext == nullptr) { - if (ciphertext_length == 0) { - continue; - } - aes_gcm_format_errors("ciphertext is nullptr.", error_details); - memset(plaintext_vec.iov_base, 0x00, plaintext_vec.iov_len); - return GRPC_STATUS_INVALID_ARGUMENT; - } - size_t bytes_written = 0; - size_t bytes_to_write = ciphertext_length; - // Don't include the tag - if (bytes_to_write > total_ciphertext_length - kAesGcmTagLength) { - bytes_to_write = total_ciphertext_length - kAesGcmTagLength; - } - if (plaintext_length < bytes_to_write) { - aes_gcm_format_errors( - "Not enough plaintext buffer to hold encrypted ciphertext.", - error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - if (!EVP_DecryptUpdate(aes_gcm_crypter->ctx, plaintext, - reinterpret_cast(&bytes_written), ciphertext, - static_cast(bytes_to_write))) { - aes_gcm_format_errors("Decrypting ciphertext failed.", error_details); - memset(plaintext_vec.iov_base, 0x00, plaintext_vec.iov_len); - return GRPC_STATUS_INTERNAL; - } - if (bytes_written > ciphertext_length) { - aes_gcm_format_errors("More bytes written than expected.", error_details); - memset(plaintext_vec.iov_base, 0x00, plaintext_vec.iov_len); - return GRPC_STATUS_INTERNAL; - } - ciphertext += bytes_written; - ciphertext_length -= bytes_written; - total_ciphertext_length -= bytes_written; - plaintext += bytes_written; - plaintext_length -= bytes_written; - } - if (total_ciphertext_length > kAesGcmTagLength) { - aes_gcm_format_errors( - "Not enough plaintext buffer to hold encrypted ciphertext.", - error_details); - memset(plaintext_vec.iov_base, 0x00, plaintext_vec.iov_len); - return GRPC_STATUS_INVALID_ARGUMENT; - } - uint8_t tag[kAesGcmTagLength]; - uint8_t* tag_tmp = tag; - if (ciphertext_length > 0) { - memcpy(tag_tmp, ciphertext, ciphertext_length); - tag_tmp += ciphertext_length; - total_ciphertext_length -= ciphertext_length; - } - for (; i < ciphertext_vec_length; i++) { - ciphertext = static_cast(ciphertext_vec[i].iov_base); - ciphertext_length = ciphertext_vec[i].iov_len; - if (ciphertext == nullptr) { - if (ciphertext_length == 0) { - continue; - } - aes_gcm_format_errors("ciphertext is nullptr.", error_details); - memset(plaintext_vec.iov_base, 0x00, plaintext_vec.iov_len); - return GRPC_STATUS_INVALID_ARGUMENT; - } - memcpy(tag_tmp, ciphertext, ciphertext_length); - tag_tmp += ciphertext_length; - total_ciphertext_length -= ciphertext_length; - } - if (!EVP_CIPHER_CTX_ctrl(aes_gcm_crypter->ctx, EVP_CTRL_GCM_SET_TAG, - kAesGcmTagLength, reinterpret_cast(tag))) { - aes_gcm_format_errors("Setting tag failed.", error_details); - memset(plaintext_vec.iov_base, 0x00, plaintext_vec.iov_len); - return GRPC_STATUS_INTERNAL; - } - int bytes_written_temp = 0; - if (!EVP_DecryptFinal_ex(aes_gcm_crypter->ctx, nullptr, - &bytes_written_temp)) { - aes_gcm_format_errors("Checking tag failed.", error_details); - memset(plaintext_vec.iov_base, 0x00, plaintext_vec.iov_len); - return GRPC_STATUS_FAILED_PRECONDITION; - } - if (bytes_written_temp != 0) { - aes_gcm_format_errors("Openssl wrote some unexpected bytes.", - error_details); - memset(plaintext_vec.iov_base, 0x00, plaintext_vec.iov_len); - return GRPC_STATUS_INTERNAL; - } - *plaintext_bytes_written = plaintext_vec.iov_len - plaintext_length; - return GRPC_STATUS_OK; -} - -static void gsec_aes_gcm_aead_crypter_destroy(gsec_aead_crypter* crypter) { - gsec_aes_gcm_aead_crypter* aes_gcm_crypter = - reinterpret_cast( - const_cast(crypter)); - gpr_free(aes_gcm_crypter->key); - gpr_free(aes_gcm_crypter->rekey_data); - EVP_CIPHER_CTX_free(aes_gcm_crypter->ctx); -} - -static const gsec_aead_crypter_vtable vtable = { - gsec_aes_gcm_aead_crypter_encrypt_iovec, - gsec_aes_gcm_aead_crypter_decrypt_iovec, - gsec_aes_gcm_aead_crypter_max_ciphertext_and_tag_length, - gsec_aes_gcm_aead_crypter_max_plaintext_length, - gsec_aes_gcm_aead_crypter_nonce_length, - gsec_aes_gcm_aead_crypter_key_length, - gsec_aes_gcm_aead_crypter_tag_length, - gsec_aes_gcm_aead_crypter_destroy}; - -static grpc_status_code aes_gcm_new_evp_cipher_ctx( - gsec_aes_gcm_aead_crypter* aes_gcm_crypter, char** error_details) { - const EVP_CIPHER* cipher = nullptr; - bool is_rekey = aes_gcm_crypter->rekey_data != nullptr; - switch (is_rekey ? kRekeyAeadKeyLen : aes_gcm_crypter->key_length) { - case kAes128GcmKeyLength: - cipher = EVP_aes_128_gcm(); - break; - case kAes256GcmKeyLength: - cipher = EVP_aes_256_gcm(); - break; - } - const uint8_t* aead_key = aes_gcm_crypter->key; - uint8_t aead_key_rekey[kRekeyAeadKeyLen]; - if (is_rekey) { - if (aes_gcm_derive_aead_key(aead_key_rekey, aes_gcm_crypter->key, - aes_gcm_crypter->rekey_data->kdf_counter) != - GRPC_STATUS_OK) { - aes_gcm_format_errors("Deriving key failed.", error_details); - return GRPC_STATUS_INTERNAL; - } - aead_key = aead_key_rekey; - } - if (!EVP_DecryptInit_ex(aes_gcm_crypter->ctx, cipher, nullptr, aead_key, - nullptr)) { - aes_gcm_format_errors("Setting key failed.", error_details); - return GRPC_STATUS_INTERNAL; - } - if (!EVP_CIPHER_CTX_ctrl(aes_gcm_crypter->ctx, EVP_CTRL_GCM_SET_IVLEN, - static_cast(aes_gcm_crypter->nonce_length), - nullptr)) { - aes_gcm_format_errors("Setting nonce length failed.", error_details); - return GRPC_STATUS_INTERNAL; - } - return GRPC_STATUS_OK; -} - -grpc_status_code gsec_aes_gcm_aead_crypter_create(const uint8_t* key, - size_t key_length, - size_t nonce_length, - size_t tag_length, bool rekey, - gsec_aead_crypter** crypter, - char** error_details) { - if (key == nullptr) { - aes_gcm_format_errors("key is nullptr.", error_details); - return GRPC_STATUS_FAILED_PRECONDITION; - } - if (crypter == nullptr) { - aes_gcm_format_errors("crypter is nullptr.", error_details); - return GRPC_STATUS_FAILED_PRECONDITION; - } - *crypter = nullptr; - if ((rekey && key_length != kAes128GcmRekeyKeyLength) || - (!rekey && key_length != kAes128GcmKeyLength && - key_length != kAes256GcmKeyLength) || - (tag_length != kAesGcmTagLength) || - (nonce_length != kAesGcmNonceLength)) { - aes_gcm_format_errors( - "Invalid key and/or nonce and/or tag length are provided at AEAD " - "crypter instance construction time.", - error_details); - return GRPC_STATUS_FAILED_PRECONDITION; - } - gsec_aes_gcm_aead_crypter* aes_gcm_crypter = - static_cast( - gpr_malloc(sizeof(gsec_aes_gcm_aead_crypter))); - aes_gcm_crypter->crypter.vtable = &vtable; - aes_gcm_crypter->nonce_length = nonce_length; - aes_gcm_crypter->tag_length = tag_length; - if (rekey) { - aes_gcm_crypter->key_length = kKdfKeyLen; - aes_gcm_crypter->rekey_data = static_cast( - gpr_malloc(sizeof(gsec_aes_gcm_aead_rekey_data))); - memcpy(aes_gcm_crypter->rekey_data->nonce_mask, key + kKdfKeyLen, - kAesGcmNonceLength); - // Set kdf_counter to all-zero for initial key derivation. - memset(aes_gcm_crypter->rekey_data->kdf_counter, 0, kKdfCounterLen); - } else { - aes_gcm_crypter->key_length = key_length; - aes_gcm_crypter->rekey_data = nullptr; - } - aes_gcm_crypter->key = - static_cast(gpr_malloc(aes_gcm_crypter->key_length)); - memcpy(aes_gcm_crypter->key, key, aes_gcm_crypter->key_length); - aes_gcm_crypter->ctx = EVP_CIPHER_CTX_new(); - grpc_status_code status = - aes_gcm_new_evp_cipher_ctx(aes_gcm_crypter, error_details); - if (status != GRPC_STATUS_OK) { - gsec_aes_gcm_aead_crypter_destroy(&aes_gcm_crypter->crypter); - gpr_free(aes_gcm_crypter); - return status; - } - *crypter = &aes_gcm_crypter->crypter; - return GRPC_STATUS_OK; -} diff --git a/src/core/tsi/alts/crypt/gsec.cc b/src/core/tsi/alts/crypt/gsec.cc deleted file mode 100644 index 6236591a97..0000000000 --- a/src/core/tsi/alts/crypt/gsec.cc +++ /dev/null @@ -1,189 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/tsi/alts/crypt/gsec.h" - -#include -#include - -#include - -static const char vtable_error_msg[] = - "crypter or crypter->vtable has not been initialized properly"; - -static void maybe_copy_error_msg(const char* src, char** dst) { - if (dst != nullptr && src != nullptr) { - *dst = static_cast(gpr_malloc(strlen(src) + 1)); - memcpy(*dst, src, strlen(src) + 1); - } -} - -grpc_status_code gsec_aead_crypter_encrypt( - gsec_aead_crypter* crypter, const uint8_t* nonce, size_t nonce_length, - const uint8_t* aad, size_t aad_length, const uint8_t* plaintext, - size_t plaintext_length, uint8_t* ciphertext_and_tag, - size_t ciphertext_and_tag_length, size_t* bytes_written, - char** error_details) { - if (crypter != nullptr && crypter->vtable != nullptr && - crypter->vtable->encrypt_iovec != nullptr) { - struct iovec aad_vec = {(void*)aad, aad_length}; - struct iovec plaintext_vec = {(void*)plaintext, plaintext_length}; - struct iovec ciphertext_vec = {ciphertext_and_tag, - ciphertext_and_tag_length}; - return crypter->vtable->encrypt_iovec( - crypter, nonce, nonce_length, &aad_vec, 1, &plaintext_vec, 1, - ciphertext_vec, bytes_written, error_details); - } - /* An error occurred. */ - maybe_copy_error_msg(vtable_error_msg, error_details); - return GRPC_STATUS_INVALID_ARGUMENT; -} - -grpc_status_code gsec_aead_crypter_encrypt_iovec( - gsec_aead_crypter* crypter, const uint8_t* nonce, size_t nonce_length, - const struct iovec* aad_vec, size_t aad_vec_length, - const struct iovec* plaintext_vec, size_t plaintext_vec_length, - struct iovec ciphertext_vec, size_t* ciphertext_bytes_written, - char** error_details) { - if (crypter != nullptr && crypter->vtable != nullptr && - crypter->vtable->encrypt_iovec != nullptr) { - return crypter->vtable->encrypt_iovec( - crypter, nonce, nonce_length, aad_vec, aad_vec_length, plaintext_vec, - plaintext_vec_length, ciphertext_vec, ciphertext_bytes_written, - error_details); - } - /* An error occurred. */ - maybe_copy_error_msg(vtable_error_msg, error_details); - return GRPC_STATUS_INVALID_ARGUMENT; -} - -grpc_status_code gsec_aead_crypter_decrypt( - gsec_aead_crypter* crypter, const uint8_t* nonce, size_t nonce_length, - const uint8_t* aad, size_t aad_length, const uint8_t* ciphertext_and_tag, - size_t ciphertext_and_tag_length, uint8_t* plaintext, - size_t plaintext_length, size_t* bytes_written, char** error_details) { - if (crypter != nullptr && crypter->vtable != nullptr && - crypter->vtable->decrypt_iovec != nullptr) { - struct iovec aad_vec = {(void*)aad, aad_length}; - struct iovec ciphertext_vec = {(void*)ciphertext_and_tag, - ciphertext_and_tag_length}; - struct iovec plaintext_vec = {plaintext, plaintext_length}; - return crypter->vtable->decrypt_iovec( - crypter, nonce, nonce_length, &aad_vec, 1, &ciphertext_vec, 1, - plaintext_vec, bytes_written, error_details); - } - /* An error occurred. */ - maybe_copy_error_msg(vtable_error_msg, error_details); - return GRPC_STATUS_INVALID_ARGUMENT; -} - -grpc_status_code gsec_aead_crypter_decrypt_iovec( - gsec_aead_crypter* crypter, const uint8_t* nonce, size_t nonce_length, - const struct iovec* aad_vec, size_t aad_vec_length, - const struct iovec* ciphertext_vec, size_t ciphertext_vec_length, - struct iovec plaintext_vec, size_t* plaintext_bytes_written, - char** error_details) { - if (crypter != nullptr && crypter->vtable != nullptr && - crypter->vtable->encrypt_iovec != nullptr) { - return crypter->vtable->decrypt_iovec( - crypter, nonce, nonce_length, aad_vec, aad_vec_length, ciphertext_vec, - ciphertext_vec_length, plaintext_vec, plaintext_bytes_written, - error_details); - } - /* An error occurred. */ - maybe_copy_error_msg(vtable_error_msg, error_details); - return GRPC_STATUS_INVALID_ARGUMENT; -} - -grpc_status_code gsec_aead_crypter_max_ciphertext_and_tag_length( - const gsec_aead_crypter* crypter, size_t plaintext_length, - size_t* max_ciphertext_and_tag_length_to_return, char** error_details) { - if (crypter != nullptr && crypter->vtable != nullptr && - crypter->vtable->max_ciphertext_and_tag_length != nullptr) { - return crypter->vtable->max_ciphertext_and_tag_length( - crypter, plaintext_length, max_ciphertext_and_tag_length_to_return, - error_details); - } - /* An error occurred. */ - maybe_copy_error_msg(vtable_error_msg, error_details); - return GRPC_STATUS_INVALID_ARGUMENT; -} - -grpc_status_code gsec_aead_crypter_max_plaintext_length( - const gsec_aead_crypter* crypter, size_t ciphertext_and_tag_length, - size_t* max_plaintext_length_to_return, char** error_details) { - if (crypter != nullptr && crypter->vtable != nullptr && - crypter->vtable->max_plaintext_length != nullptr) { - return crypter->vtable->max_plaintext_length( - crypter, ciphertext_and_tag_length, max_plaintext_length_to_return, - error_details); - } - /* An error occurred. */ - maybe_copy_error_msg(vtable_error_msg, error_details); - return GRPC_STATUS_INVALID_ARGUMENT; -} - -grpc_status_code gsec_aead_crypter_nonce_length( - const gsec_aead_crypter* crypter, size_t* nonce_length_to_return, - char** error_details) { - if (crypter != nullptr && crypter->vtable != nullptr && - crypter->vtable->nonce_length != nullptr) { - return crypter->vtable->nonce_length(crypter, nonce_length_to_return, - error_details); - } - /* An error occurred. */ - maybe_copy_error_msg(vtable_error_msg, error_details); - return GRPC_STATUS_INVALID_ARGUMENT; -} - -grpc_status_code gsec_aead_crypter_key_length(const gsec_aead_crypter* crypter, - size_t* key_length_to_return, - char** error_details) { - if (crypter != nullptr && crypter->vtable != nullptr && - crypter->vtable->key_length != nullptr) { - return crypter->vtable->key_length(crypter, key_length_to_return, - error_details); - } - /* An error occurred */ - maybe_copy_error_msg(vtable_error_msg, error_details); - return GRPC_STATUS_INVALID_ARGUMENT; -} - -grpc_status_code gsec_aead_crypter_tag_length(const gsec_aead_crypter* crypter, - size_t* tag_length_to_return, - char** error_details) { - if (crypter != nullptr && crypter->vtable != nullptr && - crypter->vtable->tag_length != nullptr) { - return crypter->vtable->tag_length(crypter, tag_length_to_return, - error_details); - } - /* An error occurred. */ - maybe_copy_error_msg(vtable_error_msg, error_details); - return GRPC_STATUS_INVALID_ARGUMENT; -} - -void gsec_aead_crypter_destroy(gsec_aead_crypter* crypter) { - if (crypter != nullptr) { - if (crypter->vtable != nullptr && crypter->vtable->destruct != nullptr) { - crypter->vtable->destruct(crypter); - } - gpr_free(crypter); - } -} diff --git a/src/core/tsi/alts/crypt/gsec.h b/src/core/tsi/alts/crypt/gsec.h deleted file mode 100644 index 4d65caa944..0000000000 --- a/src/core/tsi/alts/crypt/gsec.h +++ /dev/null @@ -1,454 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_TSI_ALTS_CRYPT_GSEC_H -#define GRPC_CORE_TSI_ALTS_CRYPT_GSEC_H - -#include - -#include -#include -#include - -#include - -struct iovec { - void* iov_base; - size_t iov_len; -}; - -/** - * A gsec interface for AEAD encryption schemes. The API is thread-compatible. - * Each implementation of this interface should specify supported values for - * key, nonce, and tag lengths. - */ - -/* Key, nonce, and tag length in bytes */ -const size_t kAesGcmNonceLength = 12; -const size_t kAesGcmTagLength = 16; -const size_t kAes128GcmKeyLength = 16; -const size_t kAes256GcmKeyLength = 32; - -// The first 32 bytes are used as a KDF key and the remaining 12 bytes are used -// to mask the nonce. -const size_t kAes128GcmRekeyKeyLength = 44; - -typedef struct gsec_aead_crypter gsec_aead_crypter; - -/** - * The gsec_aead_crypter is an API for different AEAD implementations such as - * AES_GCM. It encapsulates all AEAD-related operations in the format of - * V-table that stores pointers to functions implementing those operations. - * It also provides helper functions to wrap each of those function pointers. - * - * A typical usage of this object would be: - * - *------------------------------------------------------------------------------ - * // Declare a gsec_aead_crypter object, and create and assign an instance - * // of specific AEAD implementation e.g., AES_GCM to it. We assume both - * // key and nonce contain cryptographically secure random bytes, and the key - * // can be derived from an upper-layer application. - * gsec_aead_crypter* crypter; - * char* error_in_creation; - * // User can populate the message with any 100 bytes data. - * uint8_t* message = gpr_malloc(100); - * grpc_status_code creation_status = gsec_aes_gcm_aead_crypter_create(key, - * kAes128GcmKeyLength, - * kAesGcmNonceLength, - * kAesGcmTagLength, - * &crypter, - * false, - * 0 - * &error_in_creation); - * - * if (creation_status == GRPC_STATUS_OK) { - * // Allocate a correct amount of memory to hold a ciphertext. - * size_t clength = 0; - * gsec_aead_crypter_max_ciphertext_and_tag_length(crypter, 100, &clength, - * nullptr); - * uint8_t* ciphertext = gpr_malloc(clength); - * - * // Perform encryption - * size_t num_encrypted_bytes = 0; - * char* error_in_encryption = nullptr; - * grpc_status_code status = gsec_aead_crypter_encrypt(crypter, nonce, - * kAesGcmNonceLength, - * nullptr, 0, message, - * 100, ciphertext, - * clength, - * &num_encrypted_bytes, - * &error_in_encryption); - * if (status == GRPC_STATUS_OK) { - * // Allocate a correct amount of memory to hold a plaintext. - * size_t plength = 0; - * gsec_aead_crypter_max_plaintext_length(crypter, num_encrypted_bytes, - * &plength, nullptr); - * uint8_t* plaintext = gpr_malloc(plength); - * - * // Perform decryption. - * size_t num_decrypted_bytes = 0; - * char* error_in_decryption = nullptr; - * status = gsec_aead_crypter_decrypt(crypter, nonce, - * kAesGcmNonceLength, nullptr, 0, - * ciphertext, num_encrypted_bytes, - * plaintext, plength, - * &num_decrypted_bytes, - * &error_in_decryption); - * if (status != GRPC_STATUS_OK) { - * fprintf(stderr, "AEAD decrypt operation failed with error code:" - * "%d, message: %s\n", status, error_in_decryption); - * } - * ... - * gpr_free(plaintext); - * gpr_free(error_in_decryption); - * } else { - * fprintf(stderr, "AEAD encrypt operation failed with error code:" - * "%d, message: %s\n", status, error_in_encryption); - * } - * ... - * gpr_free(ciphertext); - * gpr_free(error_in_encryption); - * } else { - * fprintf(stderr, "Creation of AEAD crypter instance failed with error code:" - * "%d, message: %s\n", creation_status, error_in_creation); - * } - * - * // Destruct AEAD crypter instance. - * if (creation_status == GRPC_STATUS_OK) { - * gsec_aead_crypter_destroy(crypter); - * } - * gpr_free(error_in_creation); - * gpr_free(message); - * ----------------------------------------------------------------------------- - */ - -/* V-table for gsec AEAD operations */ -typedef struct gsec_aead_crypter_vtable { - grpc_status_code (*encrypt_iovec)( - gsec_aead_crypter* crypter, const uint8_t* nonce, size_t nonce_length, - const struct iovec* aad_vec, size_t aad_vec_length, - const struct iovec* plaintext_vec, size_t plaintext_vec_length, - struct iovec ciphertext_vec, size_t* ciphertext_bytes_written, - char** error_details); - grpc_status_code (*decrypt_iovec)( - gsec_aead_crypter* crypter, const uint8_t* nonce, size_t nonce_length, - const struct iovec* aad_vec, size_t aad_vec_length, - const struct iovec* ciphertext_vec, size_t ciphertext_vec_length, - struct iovec plaintext_vec, size_t* plaintext_bytes_written, - char** error_details); - grpc_status_code (*max_ciphertext_and_tag_length)( - const gsec_aead_crypter* crypter, size_t plaintext_length, - size_t* max_ciphertext_and_tag_length_to_return, char** error_details); - grpc_status_code (*max_plaintext_length)( - const gsec_aead_crypter* crypter, size_t ciphertext_and_tag_length, - size_t* max_plaintext_length_to_return, char** error_details); - grpc_status_code (*nonce_length)(const gsec_aead_crypter* crypter, - size_t* nonce_length_to_return, - char** error_details); - grpc_status_code (*key_length)(const gsec_aead_crypter* crypter, - size_t* key_length_to_return, - char** error_details); - grpc_status_code (*tag_length)(const gsec_aead_crypter* crypter, - size_t* tag_length_to_return, - char** error_details); - void (*destruct)(gsec_aead_crypter* crypter); -} gsec_aead_crypter_vtable; - -/* Main struct for gsec interface */ -struct gsec_aead_crypter { - const struct gsec_aead_crypter_vtable* vtable; -}; - -/** - * This method performs an AEAD encrypt operation. - * - * - crypter: AEAD crypter instance. - * - nonce: buffer containing a nonce with its size equal to nonce_length. - * - nonce_length: size of nonce buffer, and must be equal to the value returned - * from method gsec_aead_crypter_nonce_length. - * - aad: buffer containing data that needs to be authenticated but not - * encrypted with its size equal to aad_length. - * - aad_length: size of aad buffer, which should be zero if the buffer is - * nullptr. - * - plaintext: buffer containing data that needs to be both encrypted and - * authenticated with its size equal to plaintext_length. - * - plaintext_length: size of plaintext buffer, which should be zero if - * plaintext is nullptr. - * - ciphertext_and_tag: buffer that will contain ciphertext and tags the method - * produced. The buffer should not overlap the plaintext buffer, and pointers - * to those buffers should not be equal. Also if the ciphertext+tag buffer is - * nullptr, the plaintext_length should be zero. - * - ciphertext_and_tag_length: size of ciphertext+tag buffer, which should be - * at least as long as the one returned from method - * gsec_aead_crypter_max_ciphertext_and_tag_length. - * - bytes_written: the actual number of bytes written to the ciphertext+tag - * buffer. If bytes_written is nullptr, the plaintext_length should be zero. - * - error_details: a buffer containing an error message if the method does not - * function correctly. It is legal to pass nullptr into error_details, and - * otherwise, the parameter should be freed with gpr_free. - * - * On the success of encryption, the method returns GRPC_STATUS_OK. Otherwise, - * it returns an error status code along with its details specified in - * error_details (if error_details is not nullptr). - * - */ -grpc_status_code gsec_aead_crypter_encrypt( - gsec_aead_crypter* crypter, const uint8_t* nonce, size_t nonce_length, - const uint8_t* aad, size_t aad_length, const uint8_t* plaintext, - size_t plaintext_length, uint8_t* ciphertext_and_tag, - size_t ciphertext_and_tag_length, size_t* bytes_written, - char** error_details); - -/** - * This method performs an AEAD encrypt operation. - * - * - crypter: AEAD crypter instance. - * - nonce: buffer containing a nonce with its size equal to nonce_length. - * - nonce_length: size of nonce buffer, and must be equal to the value returned - * from method gsec_aead_crypter_nonce_length. - * - aad_vec: an iovec array containing data that needs to be authenticated but - * not encrypted. - * - aad_vec_length: the array length of aad_vec. - * - plaintext_vec: an iovec array containing data that needs to be both - * encrypted and authenticated. - * - plaintext_vec_length: the array length of plaintext_vec. - * - ciphertext_vec: an iovec containing a ciphertext buffer. The buffer should - * not overlap the plaintext buffer. - * - ciphertext_bytes_written: the actual number of bytes written to - * ciphertext_vec. - * - error_details: a buffer containing an error message if the method does not - * function correctly. It is legal to pass nullptr into error_details, and - * otherwise, the parameter should be freed with gpr_free. - * - * On the success of encryption, the method returns GRPC_STATUS_OK. Otherwise, - * it returns an error status code along with its details specified in - * error_details (if error_details is not nullptr). - * - */ -grpc_status_code gsec_aead_crypter_encrypt_iovec( - gsec_aead_crypter* crypter, const uint8_t* nonce, size_t nonce_length, - const struct iovec* aad_vec, size_t aad_vec_length, - const struct iovec* plaintext_vec, size_t plaintext_vec_length, - struct iovec ciphertext_vec, size_t* ciphertext_bytes_written, - char** error_details); - -/** - * This method performs an AEAD decrypt operation. - * - * - crypter: AEAD crypter instance. - * - nonce: buffer containing a nonce with its size equal to nonce_length. - * - nonce_length: size of nonce buffer, and must be equal to the value returned - * from method gsec_aead_crypter_nonce_length. - * - aad: buffer containing data that needs to be authenticated only. - * - aad_length: size of aad buffer, which should be zero if the buffer is - * nullptr. - * - ciphertext_and_tag: buffer containing ciphertext and tag. - * - ciphertext_and_tag_length: length of ciphertext and tag. It should be zero - * if any of plaintext, ciphertext_and_tag, or bytes_written is nullptr. Also, - * ciphertext_and_tag_length should be at least as large as the tag length set - * at AEAD crypter instance construction time. - * - plaintext: buffer containing decrypted and authenticated data the method - * produced. The buffer should not overlap with the ciphertext+tag buffer, and - * pointers to those buffers should not be equal. - * - plaintext_length: size of plaintext buffer, which should be at least as - * long as the one returned from gsec_aead_crypter_max_plaintext_length - * method. - * - bytes_written: the actual number of bytes written to the plaintext - * buffer. - * - error_details: a buffer containing an error message if the method does not - * function correctly. It is legal to pass nullptr into error_details, and - * otherwise, the parameter should be freed with gpr_free. - * - * On the success of decryption, the method returns GRPC_STATUS_OK. Otherwise, - * it returns an error status code along with its details specified in - * error_details (if error_details is not nullptr). - */ -grpc_status_code gsec_aead_crypter_decrypt( - gsec_aead_crypter* crypter, const uint8_t* nonce, size_t nonce_length, - const uint8_t* aad, size_t aad_length, const uint8_t* ciphertext_and_tag, - size_t ciphertext_and_tag_length, uint8_t* plaintext, - size_t plaintext_length, size_t* bytes_written, char** error_details); - -/** - * This method performs an AEAD decrypt operation. - * - * - crypter: AEAD crypter instance. - * - nonce: buffer containing a nonce with its size equal to nonce_length. - * - nonce_length: size of nonce buffer, and must be equal to the value returned - * from method gsec_aead_crypter_nonce_length. - * - aad_vec: an iovec array containing data that needs to be authenticated but - * not encrypted. - * - aad_vec_length: the array length of aad_vec. - * - ciphertext_vec: an iovec array containing the ciphertext and tag. - * - ciphertext_vec_length: the array length of ciphertext_vec. - * - plaintext_vec: an iovec containing a plaintext buffer. The buffer should - * not overlap the ciphertext buffer. - * - plaintext_bytes_written: the actual number of bytes written to - * plaintext_vec. - * - error_details: a buffer containing an error message if the method does not - * function correctly. It is legal to pass nullptr into error_details, and - * otherwise, the parameter should be freed with gpr_free. - * - * On the success of decryption, the method returns GRPC_STATUS_OK. Otherwise, - * it returns an error status code along with its details specified in - * error_details (if error_details is not nullptr). - */ -grpc_status_code gsec_aead_crypter_decrypt_iovec( - gsec_aead_crypter* crypter, const uint8_t* nonce, size_t nonce_length, - const struct iovec* aad_vec, size_t aad_vec_length, - const struct iovec* ciphertext_vec, size_t ciphertext_vec_length, - struct iovec plaintext_vec, size_t* plaintext_bytes_written, - char** error_details); - -/** - * This method computes the size of ciphertext+tag buffer that must be passed to - * gsec_aead_crypter_encrypt function to ensure correct encryption of a - * plaintext. The actual size of ciphertext+tag written to the buffer could be - * smaller. - * - * - crypter: AEAD crypter instance. - * - plaintext_length: length of plaintext. - * - max_ciphertext_and_tag_length_to_return: the size of ciphertext+tag buffer - * the method returns. - * - error_details: a buffer containing an error message if the method does not - * function correctly. It is legal to pass nullptr into error_details, and - * otherwise, the parameter should be freed with gpr_free. - * - * On the success of execution, the method returns GRPC_STATUS_OK. Otherwise, - * it returns an error status code along with its details specified in - * error_details (if error_details is not nullptr). - */ -grpc_status_code gsec_aead_crypter_max_ciphertext_and_tag_length( - const gsec_aead_crypter* crypter, size_t plaintext_length, - size_t* max_ciphertext_and_tag_length_to_return, char** error_details); - -/** - * This method computes the size of plaintext buffer that must be passed to - * gsec_aead_crypter_decrypt function to ensure correct decryption of a - * ciphertext. The actual size of plaintext written to the buffer could be - * smaller. - * - * - crypter: AEAD crypter instance. - * - ciphertext_and_tag_length: length of ciphertext and tag. - * - max_plaintext_length_to_return: the size of plaintext buffer the method - * returns. - * - error_details: a buffer containing an error message if the method does not - * function correctly. It is legal to pass nullptr into error_details, and - * otherwise, the parameter should be freed with gpr_free. - * - * On the success of execution, the method returns GRPC_STATUS_OK. Otherwise, - * it returns an error status code along with its details specified in - * error_details (if error_details is not nullptr). - */ -grpc_status_code gsec_aead_crypter_max_plaintext_length( - const gsec_aead_crypter* crypter, size_t ciphertext_and_tag_length, - size_t* max_plaintext_length_to_return, char** error_details); - -/** - * This method returns a valid size of nonce array used at the construction of - * AEAD crypter instance. It is also the size that should be passed to encrypt - * and decrypt methods executed on the instance. - * - * - crypter: AEAD crypter instance. - * - nonce_length_to_return: the length of nonce array the method returns. - * - error_details: a buffer containing an error message if the method does not - * function correctly. It is legal to pass nullptr into error_details, and - * otherwise, the parameter should be freed with gpr_free. - * - * On the success of execution, the method returns GRPC_STATUS_OK. Otherwise, - * it returns an error status code along with its details specified in - * error_details (if error_details is not nullptr). - */ -grpc_status_code gsec_aead_crypter_nonce_length( - const gsec_aead_crypter* crypter, size_t* nonce_length_to_return, - char** error_details); - -/** - * This method returns a valid size of key array used at the construction of - * AEAD crypter instance. It is also the size that should be passed to encrypt - * and decrypt methods executed on the instance. - * - * - crypter: AEAD crypter instance. - * - key_length_to_return: the length of key array the method returns. - * - error_details: a buffer containing an error message if the method does not - * function correctly. It is legal to pass nullptr into error_details, and - * otherwise, the parameter should be freed with gpr_free. - * - * On the success of execution, the method returns GRPC_STATUS_OK. Otherwise, - * it returns an error status code along with its details specified in - * error_details (if error_details is not nullptr). - */ -grpc_status_code gsec_aead_crypter_key_length(const gsec_aead_crypter* crypter, - size_t* key_length_to_return, - char** error_details); -/** - * This method returns a valid size of tag array used at the construction of - * AEAD crypter instance. It is also the size that should be passed to encrypt - * and decrypt methods executed on the instance. - * - * - crypter: AEAD crypter instance. - * - tag_length_to_return: the length of tag array the method returns. - * - error_details: a buffer containing an error message if the method does not - * function correctly. It is legal to pass nullptr into error_details, and - * otherwise, the parameter should be freed with gpr_free. - * - * On the success of execution, the method returns GRPC_STATUS_OK. Otherwise, - * it returns an error status code along with its details specified in - * error_details (if error_details is not nullptr). - */ -grpc_status_code gsec_aead_crypter_tag_length(const gsec_aead_crypter* crypter, - size_t* tag_length_to_return, - char** error_details); - -/** - * This method destroys an AEAD crypter instance by de-allocating all of its - * occupied memory. - * - * - crypter: AEAD crypter instance that needs to be destroyed. - */ -void gsec_aead_crypter_destroy(gsec_aead_crypter* crypter); - -/** - * This method creates an AEAD crypter instance of AES-GCM encryption scheme - * which supports 16 and 32 bytes long keys, 12 and 16 bytes long nonces, and - * 16 bytes long tags. It should be noted that once the lengths of key, nonce, - * and tag are determined at construction time, they cannot be modified later. - * - * - key: buffer containing a key which is binded with AEAD crypter instance. - * - key_length: length of a key in bytes, which should be 44 if rekeying is - * enabled and 16 or 32 otherwise. - * - nonce_length: length of a nonce in bytes, which should be either 12 or 16. - * - tag_length: length of a tag in bytes, which should be always 16. - * - rekey: enable nonce-based rekeying and nonce-masking. - * - crypter: address of AES_GCM crypter instance returned from the method. - * - error_details: a buffer containing an error message if the method does not - * function correctly. It is legal to pass nullptr into error_details, and - * otherwise, the parameter should be freed with gpr_free. - * - * On success of instance creation, it stores the address of instance at - * crypter. Otherwise, it returns an error status code together with its details - * specified in error_details. - */ -grpc_status_code gsec_aes_gcm_aead_crypter_create(const uint8_t* key, - size_t key_length, - size_t nonce_length, - size_t tag_length, bool rekey, - gsec_aead_crypter** crypter, - char** error_details); - -#endif /* GRPC_CORE_TSI_ALTS_CRYPT_GSEC_H */ diff --git a/src/core/tsi/alts/frame_protector/alts_counter.cc b/src/core/tsi/alts/frame_protector/alts_counter.cc deleted file mode 100644 index de163e3e08..0000000000 --- a/src/core/tsi/alts/frame_protector/alts_counter.cc +++ /dev/null @@ -1,118 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/tsi/alts/frame_protector/alts_counter.h" - -#include - -#include - -static void maybe_copy_error_msg(const char* src, char** dst) { - if (dst != nullptr && src != nullptr) { - *dst = static_cast(gpr_malloc(strlen(src) + 1)); - memcpy(*dst, src, strlen(src) + 1); - } -} - -grpc_status_code alts_counter_create(bool is_client, size_t counter_size, - size_t overflow_size, - alts_counter** crypter_counter, - char** error_details) { - /* Perform input sanity check. */ - if (counter_size == 0) { - const char error_msg[] = "counter_size is invalid."; - maybe_copy_error_msg(error_msg, error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - if (overflow_size == 0 || overflow_size >= counter_size) { - const char error_msg[] = "overflow_size is invalid."; - maybe_copy_error_msg(error_msg, error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - if (crypter_counter == nullptr) { - const char error_msg[] = "crypter_counter is nullptr."; - maybe_copy_error_msg(error_msg, error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - *crypter_counter = - static_cast(gpr_malloc(sizeof(**crypter_counter))); - (*crypter_counter)->size = counter_size; - (*crypter_counter)->overflow_size = overflow_size; - (*crypter_counter)->counter = - static_cast(gpr_zalloc(counter_size)); - if (is_client) { - ((*crypter_counter)->counter)[counter_size - 1] = 0x80; - } - return GRPC_STATUS_OK; -} - -grpc_status_code alts_counter_increment(alts_counter* crypter_counter, - bool* is_overflow, - char** error_details) { - /* Perform input sanity check. */ - if (crypter_counter == nullptr) { - const char error_msg[] = "crypter_counter is nullptr."; - maybe_copy_error_msg(error_msg, error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - if (is_overflow == nullptr) { - const char error_msg[] = "is_overflow is nullptr."; - maybe_copy_error_msg(error_msg, error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - /* Increment the internal counter. */ - size_t i = 0; - for (; i < crypter_counter->overflow_size; i++) { - (crypter_counter->counter)[i]++; - if ((crypter_counter->counter)[i] != 0x00) { - break; - } - } - /** - * If the lower overflow_size bytes are all zero, the counter has overflowed. - */ - if (i == crypter_counter->overflow_size) { - *is_overflow = true; - return GRPC_STATUS_FAILED_PRECONDITION; - } - *is_overflow = false; - return GRPC_STATUS_OK; -} - -size_t alts_counter_get_size(alts_counter* crypter_counter) { - if (crypter_counter == nullptr) { - return 0; - } - return crypter_counter->size; -} - -unsigned char* alts_counter_get_counter(alts_counter* crypter_counter) { - if (crypter_counter == nullptr) { - return nullptr; - } - return crypter_counter->counter; -} - -void alts_counter_destroy(alts_counter* crypter_counter) { - if (crypter_counter != nullptr) { - gpr_free(crypter_counter->counter); - gpr_free(crypter_counter); - } -} diff --git a/src/core/tsi/alts/frame_protector/alts_counter.h b/src/core/tsi/alts/frame_protector/alts_counter.h deleted file mode 100644 index d705638fa8..0000000000 --- a/src/core/tsi/alts/frame_protector/alts_counter.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_COUNTER_H -#define GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_COUNTER_H - -#include - -#include -#include - -#include - -/* Main struct for a crypter counter managed within seal/unseal operations. */ -typedef struct alts_counter { - size_t size; - size_t overflow_size; - unsigned char* counter; -} alts_counter; - -/** - * This method creates and initializes an alts_counter instance. - * - * - is_client: a flag indicating if the alts_counter instance will be used - * at client (is_client = true) or server (is_client = false) side. - * - counter_size: size of buffer holding the counter value. - * - overflow_size: overflow size in bytes. The counter instance can be used - * to produce at most 2^(overflow_size*8) frames. - * - crypter_counter: an alts_counter instance to be returned from the method. - * - error_details: a buffer containing an error message if the method does not - * function correctly. It is legal to pass nullptr into error_details and - * otherwise, the parameter should be freed with gpr_free. - * - * On success, the method returns GRPC_STATUS_OK. Otherwise, - * it returns an error status code along with its details specified in - * error_details (if error_details is not nullptr). - */ -grpc_status_code alts_counter_create(bool is_client, size_t counter_size, - size_t overflow_size, - alts_counter** crypter_counter, - char** error_details); - -/** - * This method increments the internal counter. - * - * - crypter_counter: an alts_counter instance. - * - is_overflow: after incrementing the internal counter, if an overflow - * occurs, is_overflow is set to true, and no further calls to - * alts_counter_increment() should be made. Otherwise, is_overflow is set to - * false. - * - error_details: a buffer containing an error message if the method does not - * function correctly. It is legal to pass nullptr into error_details and - * otherwise, the parameter should be freed with gpr_free. - * - * On success, the method returns GRPC_STATUS_OK. Otherwise, - * it returns an error status code along with its details specified in - * error_details (if error_details is not nullptr). - */ -grpc_status_code alts_counter_increment(alts_counter* crypter_counter, - bool* is_overflow, - char** error_details); - -/** - * This method returns the size of counter buffer. - * - * - crypter_counter: an alts_counter instance. - */ -size_t alts_counter_get_size(alts_counter* crypter_counter); - -/** - * This method returns the counter buffer. - * - * - crypter_counter: an alts_counter instance. - */ -unsigned char* alts_counter_get_counter(alts_counter* crypter_counter); - -/** - * This method de-allocates all memory allocated to an alts_coutner instance. - * - crypter_counter: an alts_counter instance. - */ -void alts_counter_destroy(alts_counter* crypter_counter); - -#endif /* GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_COUNTER_H */ diff --git a/src/core/tsi/alts/frame_protector/alts_crypter.cc b/src/core/tsi/alts/frame_protector/alts_crypter.cc deleted file mode 100644 index 56f0512186..0000000000 --- a/src/core/tsi/alts/frame_protector/alts_crypter.cc +++ /dev/null @@ -1,66 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/tsi/alts/frame_protector/alts_crypter.h" - -#include - -#include - -static void maybe_copy_error_msg(const char* src, char** dst) { - if (dst != nullptr && src != nullptr) { - *dst = static_cast(gpr_malloc(strlen(src) + 1)); - memcpy(*dst, src, strlen(src) + 1); - } -} - -grpc_status_code alts_crypter_process_in_place( - alts_crypter* crypter, unsigned char* data, size_t data_allocated_size, - size_t data_size, size_t* output_size, char** error_details) { - if (crypter != nullptr && crypter->vtable != nullptr && - crypter->vtable->process_in_place != nullptr) { - return crypter->vtable->process_in_place(crypter, data, data_allocated_size, - data_size, output_size, - error_details); - } - /* An error occurred. */ - const char error_msg[] = - "crypter or crypter->vtable has not been initialized properly."; - maybe_copy_error_msg(error_msg, error_details); - return GRPC_STATUS_INVALID_ARGUMENT; -} - -size_t alts_crypter_num_overhead_bytes(const alts_crypter* crypter) { - if (crypter != nullptr && crypter->vtable != nullptr && - crypter->vtable->num_overhead_bytes != nullptr) { - return crypter->vtable->num_overhead_bytes(crypter); - } - /* An error occurred. */ - return 0; -} - -void alts_crypter_destroy(alts_crypter* crypter) { - if (crypter != nullptr) { - if (crypter->vtable != nullptr && crypter->vtable->destruct != nullptr) { - crypter->vtable->destruct(crypter); - } - gpr_free(crypter); - } -} diff --git a/src/core/tsi/alts/frame_protector/alts_crypter.h b/src/core/tsi/alts/frame_protector/alts_crypter.h deleted file mode 100644 index 3140778f4f..0000000000 --- a/src/core/tsi/alts/frame_protector/alts_crypter.h +++ /dev/null @@ -1,255 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_CRYPTER_H -#define GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_CRYPTER_H - -#include - -#include -#include - -#include - -#include "src/core/tsi/alts/crypt/gsec.h" - -/** - * An alts_crypter interface for an ALTS record protocol providing - * seal/unseal functionality. The interface is thread-compatible. - */ - -typedef struct alts_crypter alts_crypter; - -/** - * A typical usage of the interface would be - *------------------------------------------------------------------------------ - * // Perform a seal operation. We assume the gsec_aead_crypter instance - - * // client_aead_crypter is created beforehand with a 16-byte key and 12-byte - * // nonce length. - * - * alts_crypter* client = nullptr; - * char* client_error_in_creation = nullptr; - * unsigned char* data = nullptr; - * grpc_status_code client_status = - * alts_seal_crypter_create(client_aead_crypter, 1, 5, &client, - * &client_error_in_creation); - * if (client_status == GRPC_STATUS_OK) { - * size_t data_size = 100; - * size_t num_overhead_bytes = alts_crypter_num_overhead_bytes(client); - * size_t data_allocated_size = data_size + num_overhead_bytes; - * data = gpr_malloc(data_allocated_size); - * char* client_error_in_seal = nullptr; - * // Client performs a seal operation. - * client_status = alts_crypter_process_in_place(client, data, - * data_allocated_size, - * &data_size, - * &client_error_in_seal); - * if (client_status != GRPC_STATUS_OK) { - * fprintf(stderr, "seal operation failed with error code:" - * "%d, message: %s\n", client_status, - * client_error_in_seal); - * } - * gpr_free(client_error_in_seal); - * } else { - * fprintf(stderr, "alts_crypter instance creation failed with error" - * "code: %d, message: %s\n", client_status, - * client_error_in_creation); - * } - * - * ... - * - * gpr_free(client_error_in_creation); - * alts_crypter_destroy(client); - * - * ... - * - * // Perform an unseal operation. We assume the gsec_aead_crypter instance - - * // server_aead_crypter is created beforehand with a 16-byte key and 12-byte - * // nonce length. The key used in the creation of gsec_aead_crypter instances - * // at server and client sides should be identical. - * - * alts_crypter* server = nullptr; - * char* server_error_in_creation = nullptr; - * grpc_status_code server_status = - * alts_unseal_crypter_create(server_aead_crypter, 0, 5, &server, - * &server_error_in_creation); - * if (server_status == GRPC_STATUS_OK) { - * size_t num_overhead_bytes = alts_crypter_num_overhead_bytes(server); - * size_t data_size = 100 + num_overhead_bytes; - * size_t data_allocated_size = data_size; - * char* server_error_in_unseal = nullptr; - * // Server performs an unseal operation. - * server_status = alts_crypter_process_in_place(server, data, - * data_allocated_size, - * &data_size, - * &server_error_in_unseal); - * if (server_status != GRPC_STATUS_OK) { - * fprintf(stderr, "unseal operation failed with error code:" - * "%d, message: %s\n", server_status, - * server_error_in_unseal); - * } - * gpr_free(server_error_in_unseal); - * } else { - * fprintf(stderr, "alts_crypter instance creation failed with error" - * "code: %d, message: %s\n", server_status, - * server_error_in_creation); - * } - * - * ... - * - * gpr_free(data); - * gpr_free(server_error_in_creation); - * alts_crypter_destroy(server); - * - * ... - *------------------------------------------------------------------------------ - */ - -/* V-table for alts_crypter operations */ -typedef struct alts_crypter_vtable { - size_t (*num_overhead_bytes)(const alts_crypter* crypter); - grpc_status_code (*process_in_place)(alts_crypter* crypter, - unsigned char* data, - size_t data_allocated_size, - size_t data_size, size_t* output_size, - char** error_details); - void (*destruct)(alts_crypter* crypter); -} alts_crypter_vtable; - -/* Main struct for alts_crypter interface */ -struct alts_crypter { - const alts_crypter_vtable* vtable; -}; - -/** - * This method gets the number of overhead bytes needed for sealing data that - * is the difference in size between the protected and raw data. The counter - * value used in a seal or unseal operation is locally maintained (not sent or - * received from the other peer) and therefore, will not be counted as part of - * overhead bytes. - * - * - crypter: an alts_crypter instance. - * - * On success, the method returns the number of overhead bytes. Otherwise, it - * returns zero. - * - */ -size_t alts_crypter_num_overhead_bytes(const alts_crypter* crypter); - -/** - * This method performs either a seal or an unseal operation depending on the - * alts_crypter instance - crypter passed to the method. If the crypter is - * an instance implementing a seal operation, the method will perform a seal - * operation. That is, it seals raw data and stores the result in-place, and the - * memory allocated for data must be at least data_length + - * alts_crypter_num_overhead_bytes(). If the crypter is an instance - * implementing an unseal operation, the method will perform an unseal - * operation. That is, it unseals protected data and stores the result in-place. - * The size of unsealed data will be data_length - - * alts_crypter_num_overhead_bytes(). Integrity tag will be verified during - * the unseal operation, and if verification fails, the data will be wiped. - * The counters used in both seal and unseal operations are managed internally. - * - * - crypter: an alts_crypter instance. - * - data: if the method performs a seal operation, the data represents raw data - * that needs to be sealed. It also plays the role of buffer to hold the - * protected data as a result of seal. If the method performs an unseal - * operation, the data represents protected data that needs to be unsealed. It - * also plays the role of buffer to hold raw data as a result of unseal. - * - data_allocated_size: the size of data buffer. The parameter is used to - * check whether the result of either seal or unseal can be safely written to - * the data buffer. - * - data_size: if the method performs a seal operation, data_size - * represents the size of raw data that needs to be sealed, and if the method - * performs an unseal operation, data_size represents the size of protected - * data that needs to be unsealed. - * - output_size: size of data written to the data buffer after a seal or an - * unseal operation. - * - error_details: a buffer containing an error message if the method does not - * function correctly. It is legal to pass nullptr into error_details and - * otherwise, the parameter should be freed with gpr_free. - * - * On success, the method returns GRPC_STATUS_OK. Otherwise, - * it returns an error status code along with its details specified in - * error_details (if error_details is not nullptr). - */ -grpc_status_code alts_crypter_process_in_place( - alts_crypter* crypter, unsigned char* data, size_t data_allocated_size, - size_t data_size, size_t* output_size, char** error_details); - -/** - * This method creates an alts_crypter instance to be used to perform a seal - * operation, given a gsec_aead_crypter instance and a flag indicating if the - * created instance will be used at the client or server side. It takes - * ownership of gsec_aead_crypter instance. - * - * - gc: a gsec_aead_crypter instance used to perform AEAD encryption. - * - is_client: a flag indicating if the alts_crypter instance will be - * used at the client (is_client = true) or server (is_client = - * false) side. - * - overflow_size: overflow size of counter in bytes. - * - crypter: an alts_crypter instance to be returned from the method. - * - error_details: a buffer containing an error message if the method does - * not function correctly. It is legal to pass nullptr into error_details, and - * otherwise, the parameter should be freed with gpr_free. - * - * On success of creation, the method returns GRPC_STATUS_OK. - * Otherwise, it returns an error status code along with its details specified - * in error_details (if error_details is not nullptr). - */ -grpc_status_code alts_seal_crypter_create(gsec_aead_crypter* gc, bool is_client, - size_t overflow_size, - alts_crypter** crypter, - char** error_details); - -/** - * This method creates an alts_crypter instance used to perform an unseal - * operation, given a gsec_aead_crypter instance and a flag indicating if the - * created instance will be used at the client or server side. It takes - * ownership of gsec_aead_crypter instance. - * - * - gc: a gsec_aead_crypter instance used to perform AEAD decryption. - * - is_client: a flag indicating if the alts_crypter instance will be - * used at the client (is_client = true) or server (is_client = - * false) side. - * - overflow_size: overflow size of counter in bytes. - * - crypter: an alts_crypter instance to be returned from the method. - * - error_details: a buffer containing an error message if the method does - * not function correctly. It is legal to pass nullptr into error_details, and - * otherwise, the parameter should be freed with gpr_free. - * - * On success of creation, the method returns GRPC_STATUS_OK. - * Otherwise, it returns an error status code along with its details specified - * in error_details (if error_details is not nullptr). - */ -grpc_status_code alts_unseal_crypter_create(gsec_aead_crypter* gc, - bool is_client, - size_t overflow_size, - alts_crypter** crypter, - char** error_details); - -/** - * This method destroys an alts_crypter instance by de-allocating all of its - * occupied memory. A gsec_aead_crypter instance passed in at alts_crypter - * instance creation time will be destroyed in this method. - * - * - crypter: an alts_crypter instance. - */ -void alts_crypter_destroy(alts_crypter* crypter); - -#endif /* GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_CRYPTER_H */ diff --git a/src/core/tsi/alts/frame_protector/alts_frame_protector.cc b/src/core/tsi/alts/frame_protector/alts_frame_protector.cc deleted file mode 100644 index bfa0b7a720..0000000000 --- a/src/core/tsi/alts/frame_protector/alts_frame_protector.cc +++ /dev/null @@ -1,407 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/tsi/alts/frame_protector/alts_frame_protector.h" - -#include -#include - -#include -#include - -#include "src/core/lib/gpr/useful.h" -#include "src/core/tsi/alts/crypt/gsec.h" -#include "src/core/tsi/alts/frame_protector/alts_crypter.h" -#include "src/core/tsi/alts/frame_protector/frame_handler.h" -#include "src/core/tsi/transport_security.h" - -constexpr size_t kMinFrameLength = 1024; -constexpr size_t kDefaultFrameLength = 16 * 1024; -constexpr size_t kMaxFrameLength = 1024 * 1024; - -// Limit k on number of frames such that at most 2^(8 * k) frames can be sent. -constexpr size_t kAltsRecordProtocolRekeyFrameLimit = 8; -constexpr size_t kAltsRecordProtocolFrameLimit = 5; - -/* Main struct for alts_frame_protector. */ -struct alts_frame_protector { - tsi_frame_protector base; - alts_crypter* seal_crypter; - alts_crypter* unseal_crypter; - alts_frame_writer* writer; - alts_frame_reader* reader; - unsigned char* in_place_protect_buffer; - unsigned char* in_place_unprotect_buffer; - size_t in_place_protect_bytes_buffered; - size_t in_place_unprotect_bytes_processed; - size_t max_protected_frame_size; - size_t max_unprotected_frame_size; - size_t overhead_length; - size_t counter_overflow; -}; - -static tsi_result seal(alts_frame_protector* impl) { - char* error_details = nullptr; - size_t output_size = 0; - grpc_status_code status = alts_crypter_process_in_place( - impl->seal_crypter, impl->in_place_protect_buffer, - impl->max_protected_frame_size, impl->in_place_protect_bytes_buffered, - &output_size, &error_details); - impl->in_place_protect_bytes_buffered = output_size; - if (status != GRPC_STATUS_OK) { - gpr_log(GPR_ERROR, "%s", error_details); - gpr_free(error_details); - return TSI_INTERNAL_ERROR; - } - return TSI_OK; -} - -static size_t max_encrypted_payload_bytes(alts_frame_protector* impl) { - return impl->max_protected_frame_size - kFrameHeaderSize; -} - -static tsi_result alts_protect_flush(tsi_frame_protector* self, - unsigned char* protected_output_frames, - size_t* protected_output_frames_size, - size_t* still_pending_size) { - if (self == nullptr || protected_output_frames == nullptr || - protected_output_frames_size == nullptr || - still_pending_size == nullptr) { - gpr_log(GPR_ERROR, "Invalid nullptr arguments to alts_protect_flush()."); - return TSI_INVALID_ARGUMENT; - } - alts_frame_protector* impl = reinterpret_cast(self); - /** - * If there's nothing to flush (i.e., in_place_protect_buffer is empty), - * we're done. - */ - if (impl->in_place_protect_bytes_buffered == 0) { - *protected_output_frames_size = 0; - *still_pending_size = 0; - return TSI_OK; - } - /** - * If a new frame can start being processed, we encrypt the payload and reset - * the frame writer to point to in_place_protect_buffer that holds the newly - * sealed frame. - */ - if (alts_is_frame_writer_done(impl->writer)) { - tsi_result result = seal(impl); - if (result != TSI_OK) { - return result; - } - if (!alts_reset_frame_writer(impl->writer, impl->in_place_protect_buffer, - impl->in_place_protect_bytes_buffered)) { - gpr_log(GPR_ERROR, "Couldn't reset frame writer."); - return TSI_INTERNAL_ERROR; - } - } - /** - * Write the sealed frame as much as possible to protected_output_frames. It's - * possible a frame will not be written out completely by a single flush - * (i.e., still_pending_size != 0), in which case the flush should be called - * iteratively until a complete frame has been written out. - */ - size_t written_frame_bytes = *protected_output_frames_size; - if (!alts_write_frame_bytes(impl->writer, protected_output_frames, - &written_frame_bytes)) { - gpr_log(GPR_ERROR, "Couldn't write frame bytes."); - return TSI_INTERNAL_ERROR; - } - *protected_output_frames_size = written_frame_bytes; - *still_pending_size = alts_get_num_writer_bytes_remaining(impl->writer); - /** - * If the current frame has been finished processing (i.e., sealed and written - * out completely), we empty in_place_protect_buffer. - */ - if (alts_is_frame_writer_done(impl->writer)) { - impl->in_place_protect_bytes_buffered = 0; - } - return TSI_OK; -} - -static tsi_result alts_protect(tsi_frame_protector* self, - const unsigned char* unprotected_bytes, - size_t* unprotected_bytes_size, - unsigned char* protected_output_frames, - size_t* protected_output_frames_size) { - if (self == nullptr || unprotected_bytes == nullptr || - unprotected_bytes_size == nullptr || protected_output_frames == nullptr || - protected_output_frames_size == nullptr) { - gpr_log(GPR_ERROR, "Invalid nullptr arguments to alts_protect()."); - return TSI_INVALID_ARGUMENT; - } - alts_frame_protector* impl = reinterpret_cast(self); - - /** - * If more payload can be buffered, we buffer it as much as possible to - * in_place_protect_buffer. - */ - if (impl->in_place_protect_bytes_buffered + impl->overhead_length < - max_encrypted_payload_bytes(impl)) { - size_t bytes_to_buffer = GPR_MIN(*unprotected_bytes_size, - max_encrypted_payload_bytes(impl) - - impl->in_place_protect_bytes_buffered - - impl->overhead_length); - *unprotected_bytes_size = bytes_to_buffer; - if (bytes_to_buffer > 0) { - memcpy( - impl->in_place_protect_buffer + impl->in_place_protect_bytes_buffered, - unprotected_bytes, bytes_to_buffer); - impl->in_place_protect_bytes_buffered += bytes_to_buffer; - } - } else { - *unprotected_bytes_size = 0; - } - /** - * If a full frame has been buffered, we output it. If the first condition - * holds, then there exists an unencrypted full frame. If the second - * condition holds, then there exists a full frame that has already been - * encrypted. - */ - if (max_encrypted_payload_bytes(impl) == - impl->in_place_protect_bytes_buffered + impl->overhead_length || - max_encrypted_payload_bytes(impl) == - impl->in_place_protect_bytes_buffered) { - size_t still_pending_size = 0; - return alts_protect_flush(self, protected_output_frames, - protected_output_frames_size, - &still_pending_size); - } else { - *protected_output_frames_size = 0; - return TSI_OK; - } -} - -static tsi_result unseal(alts_frame_protector* impl) { - char* error_details = nullptr; - size_t output_size = 0; - grpc_status_code status = alts_crypter_process_in_place( - impl->unseal_crypter, impl->in_place_unprotect_buffer, - impl->max_unprotected_frame_size, - alts_get_output_bytes_read(impl->reader), &output_size, &error_details); - if (status != GRPC_STATUS_OK) { - gpr_log(GPR_ERROR, "%s", error_details); - gpr_free(error_details); - return TSI_DATA_CORRUPTED; - } - return TSI_OK; -} - -static void ensure_buffer_size(alts_frame_protector* impl) { - if (!alts_has_read_frame_length(impl->reader)) { - return; - } - size_t buffer_space_remaining = impl->max_unprotected_frame_size - - alts_get_output_bytes_read(impl->reader); - /** - * Check if we need to resize in_place_unprotect_buffer in order to hold - * remaining bytes of a full frame. - */ - if (buffer_space_remaining < alts_get_reader_bytes_remaining(impl->reader)) { - size_t buffer_len = alts_get_output_bytes_read(impl->reader) + - alts_get_reader_bytes_remaining(impl->reader); - unsigned char* buffer = static_cast(gpr_malloc(buffer_len)); - memcpy(buffer, impl->in_place_unprotect_buffer, - alts_get_output_bytes_read(impl->reader)); - impl->max_unprotected_frame_size = buffer_len; - gpr_free(impl->in_place_unprotect_buffer); - impl->in_place_unprotect_buffer = buffer; - alts_reset_reader_output_buffer( - impl->reader, buffer + alts_get_output_bytes_read(impl->reader)); - } -} - -static tsi_result alts_unprotect(tsi_frame_protector* self, - const unsigned char* protected_frames_bytes, - size_t* protected_frames_bytes_size, - unsigned char* unprotected_bytes, - size_t* unprotected_bytes_size) { - if (self == nullptr || protected_frames_bytes == nullptr || - protected_frames_bytes_size == nullptr || unprotected_bytes == nullptr || - unprotected_bytes_size == nullptr) { - gpr_log(GPR_ERROR, "Invalid nullptr arguments to alts_unprotect()."); - return TSI_INVALID_ARGUMENT; - } - alts_frame_protector* impl = reinterpret_cast(self); - /** - * If a new frame can start being processed, we reset the frame reader to - * point to in_place_unprotect_buffer that will be used to hold deframed - * result. - */ - if (alts_is_frame_reader_done(impl->reader) && - ((alts_get_output_buffer(impl->reader) == nullptr) || - (alts_get_output_bytes_read(impl->reader) == - impl->in_place_unprotect_bytes_processed + impl->overhead_length))) { - if (!alts_reset_frame_reader(impl->reader, - impl->in_place_unprotect_buffer)) { - gpr_log(GPR_ERROR, "Couldn't reset frame reader."); - return TSI_INTERNAL_ERROR; - } - impl->in_place_unprotect_bytes_processed = 0; - } - /** - * If a full frame has not yet been read, we read more bytes from - * protected_frames_bytes until a full frame has been read. We also need to - * make sure in_place_unprotect_buffer is large enough to hold a complete - * frame. - */ - if (!alts_is_frame_reader_done(impl->reader)) { - ensure_buffer_size(impl); - *protected_frames_bytes_size = - GPR_MIN(impl->max_unprotected_frame_size - - alts_get_output_bytes_read(impl->reader), - *protected_frames_bytes_size); - size_t read_frames_bytes_size = *protected_frames_bytes_size; - if (!alts_read_frame_bytes(impl->reader, protected_frames_bytes, - &read_frames_bytes_size)) { - gpr_log(GPR_ERROR, "Failed to process frame."); - return TSI_INTERNAL_ERROR; - } - *protected_frames_bytes_size = read_frames_bytes_size; - } else { - *protected_frames_bytes_size = 0; - } - /** - * If a full frame has been read, we unseal it, and write out the - * deframed result to unprotected_bytes. - */ - if (alts_is_frame_reader_done(impl->reader)) { - if (impl->in_place_unprotect_bytes_processed == 0) { - tsi_result result = unseal(impl); - if (result != TSI_OK) { - return result; - } - } - size_t bytes_to_write = GPR_MIN( - *unprotected_bytes_size, alts_get_output_bytes_read(impl->reader) - - impl->in_place_unprotect_bytes_processed - - impl->overhead_length); - if (bytes_to_write > 0) { - memcpy(unprotected_bytes, - impl->in_place_unprotect_buffer + - impl->in_place_unprotect_bytes_processed, - bytes_to_write); - } - *unprotected_bytes_size = bytes_to_write; - impl->in_place_unprotect_bytes_processed += bytes_to_write; - return TSI_OK; - } else { - *unprotected_bytes_size = 0; - return TSI_OK; - } -} - -static void alts_destroy(tsi_frame_protector* self) { - alts_frame_protector* impl = reinterpret_cast(self); - if (impl != nullptr) { - alts_crypter_destroy(impl->seal_crypter); - alts_crypter_destroy(impl->unseal_crypter); - gpr_free(impl->in_place_protect_buffer); - gpr_free(impl->in_place_unprotect_buffer); - alts_destroy_frame_writer(impl->writer); - alts_destroy_frame_reader(impl->reader); - gpr_free(impl); - } -} - -static const tsi_frame_protector_vtable alts_frame_protector_vtable = { - alts_protect, alts_protect_flush, alts_unprotect, alts_destroy}; - -static grpc_status_code create_alts_crypters(const uint8_t* key, - size_t key_size, bool is_client, - bool is_rekey, - alts_frame_protector* impl, - char** error_details) { - grpc_status_code status; - gsec_aead_crypter* aead_crypter_seal = nullptr; - gsec_aead_crypter* aead_crypter_unseal = nullptr; - status = gsec_aes_gcm_aead_crypter_create(key, key_size, kAesGcmNonceLength, - kAesGcmTagLength, is_rekey, - &aead_crypter_seal, error_details); - if (status != GRPC_STATUS_OK) { - return status; - } - status = gsec_aes_gcm_aead_crypter_create( - key, key_size, kAesGcmNonceLength, kAesGcmTagLength, is_rekey, - &aead_crypter_unseal, error_details); - if (status != GRPC_STATUS_OK) { - return status; - } - size_t overflow_size = is_rekey ? kAltsRecordProtocolRekeyFrameLimit - : kAltsRecordProtocolFrameLimit; - status = alts_seal_crypter_create(aead_crypter_seal, is_client, overflow_size, - &impl->seal_crypter, error_details); - if (status != GRPC_STATUS_OK) { - return status; - } - status = - alts_unseal_crypter_create(aead_crypter_unseal, is_client, overflow_size, - &impl->unseal_crypter, error_details); - return status; -} - -tsi_result alts_create_frame_protector(const uint8_t* key, size_t key_size, - bool is_client, bool is_rekey, - size_t* max_protected_frame_size, - tsi_frame_protector** self) { - if (key == nullptr || self == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr arguments to alts_create_frame_protector()."); - return TSI_INTERNAL_ERROR; - } - char* error_details = nullptr; - alts_frame_protector* impl = - static_cast(gpr_zalloc(sizeof(*impl))); - grpc_status_code status = create_alts_crypters( - key, key_size, is_client, is_rekey, impl, &error_details); - if (status != GRPC_STATUS_OK) { - gpr_log(GPR_ERROR, "Failed to create ALTS crypters, %s.", error_details); - gpr_free(error_details); - return TSI_INTERNAL_ERROR; - } - /** - * Set maximum frame size to be used by a frame protector. If it is nullptr, a - * default frame size will be used. Otherwise, the provided frame size will be - * adjusted (if not falling into a valid frame range) and used. - */ - size_t max_protected_frame_size_to_set = kDefaultFrameLength; - if (max_protected_frame_size != nullptr) { - *max_protected_frame_size = - GPR_MIN(*max_protected_frame_size, kMaxFrameLength); - *max_protected_frame_size = - GPR_MAX(*max_protected_frame_size, kMinFrameLength); - max_protected_frame_size_to_set = *max_protected_frame_size; - } - impl->max_protected_frame_size = max_protected_frame_size_to_set; - impl->max_unprotected_frame_size = max_protected_frame_size_to_set; - impl->in_place_protect_bytes_buffered = 0; - impl->in_place_unprotect_bytes_processed = 0; - impl->in_place_protect_buffer = static_cast( - gpr_malloc(sizeof(unsigned char) * max_protected_frame_size_to_set)); - impl->in_place_unprotect_buffer = static_cast( - gpr_malloc(sizeof(unsigned char) * max_protected_frame_size_to_set)); - impl->overhead_length = alts_crypter_num_overhead_bytes(impl->seal_crypter); - impl->writer = alts_create_frame_writer(); - impl->reader = alts_create_frame_reader(); - impl->base.vtable = &alts_frame_protector_vtable; - *self = &impl->base; - return TSI_OK; -} diff --git a/src/core/tsi/alts/frame_protector/alts_frame_protector.h b/src/core/tsi/alts/frame_protector/alts_frame_protector.h deleted file mode 100644 index 321bffaed8..0000000000 --- a/src/core/tsi/alts/frame_protector/alts_frame_protector.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_FRAME_PROTECTOR_H -#define GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_FRAME_PROTECTOR_H - -#include - -#include - -#include "src/core/tsi/transport_security_interface.h" - -typedef struct alts_frame_protector alts_frame_protector; - -/** - * TODO: Add a parameter to the interface to support the use of - * different record protocols within a frame protector. - * - * This method creates a frame protector. - * - * - key: a symmetric key used to seal/unseal frames. - * - key_size: the size of symmetric key. - * - is_client: a flag indicating if the frame protector will be used at client - * (is_client = true) or server (is_client = false) side. - * - is_rekey: a flag indicating if the frame protector will use an AEAD with - * rekeying. - * - max_protected_frame_size: an in/out parameter indicating max frame size - * to be used by the frame protector. If it is nullptr, the default frame - * size will be used. Otherwise, the provided frame size will be adjusted (if - * not falling into a valid frame range) and used. - * - self: a pointer to the frame protector returned from the method. - * - * This method returns TSI_OK on success and TSI_INTERNAL_ERROR otherwise. - */ -tsi_result alts_create_frame_protector(const uint8_t* key, size_t key_size, - bool is_client, bool is_rekey, - size_t* max_protected_frame_size, - tsi_frame_protector** self); - -#endif /* GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_FRAME_PROTECTOR_H */ diff --git a/src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc b/src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc deleted file mode 100644 index 0574ed5012..0000000000 --- a/src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc +++ /dev/null @@ -1,114 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h" - -#include - -static void maybe_copy_error_msg(const char* src, char** dst) { - if (dst != nullptr && src != nullptr) { - *dst = static_cast(gpr_malloc(strlen(src) + 1)); - memcpy(*dst, src, strlen(src) + 1); - } -} - -grpc_status_code input_sanity_check( - const alts_record_protocol_crypter* rp_crypter, const unsigned char* data, - size_t* output_size, char** error_details) { - if (rp_crypter == nullptr) { - maybe_copy_error_msg("alts_crypter instance is nullptr.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } else if (data == nullptr) { - maybe_copy_error_msg("data is nullptr.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } else if (output_size == nullptr) { - maybe_copy_error_msg("output_size is nullptr.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - return GRPC_STATUS_OK; -} - -grpc_status_code increment_counter(alts_record_protocol_crypter* rp_crypter, - char** error_details) { - bool is_overflow = false; - grpc_status_code status = - alts_counter_increment(rp_crypter->ctr, &is_overflow, error_details); - if (status != GRPC_STATUS_OK) { - return status; - } - if (is_overflow) { - const char error_msg[] = - "crypter counter is wrapped. The connection" - "should be closed and the key should be deleted."; - maybe_copy_error_msg(error_msg, error_details); - return GRPC_STATUS_INTERNAL; - } - return GRPC_STATUS_OK; -} - -size_t alts_record_protocol_crypter_num_overhead_bytes(const alts_crypter* c) { - if (c != nullptr) { - size_t num_overhead_bytes = 0; - char* error_details = nullptr; - const alts_record_protocol_crypter* rp_crypter = - reinterpret_cast(c); - grpc_status_code status = gsec_aead_crypter_tag_length( - rp_crypter->crypter, &num_overhead_bytes, &error_details); - if (status == GRPC_STATUS_OK) { - return num_overhead_bytes; - } - } - return 0; -} - -void alts_record_protocol_crypter_destruct(alts_crypter* c) { - if (c != nullptr) { - alts_record_protocol_crypter* rp_crypter = - reinterpret_cast(c); - alts_counter_destroy(rp_crypter->ctr); - gsec_aead_crypter_destroy(rp_crypter->crypter); - } -} - -alts_record_protocol_crypter* alts_crypter_create_common( - gsec_aead_crypter* crypter, bool is_client, size_t overflow_size, - char** error_details) { - if (crypter != nullptr) { - auto* rp_crypter = static_cast( - gpr_malloc(sizeof(alts_record_protocol_crypter))); - size_t counter_size = 0; - grpc_status_code status = - gsec_aead_crypter_nonce_length(crypter, &counter_size, error_details); - if (status != GRPC_STATUS_OK) { - return nullptr; - } - /* Create a counter. */ - status = alts_counter_create(is_client, counter_size, overflow_size, - &rp_crypter->ctr, error_details); - if (status != GRPC_STATUS_OK) { - return nullptr; - } - rp_crypter->crypter = crypter; - return rp_crypter; - } - const char error_msg[] = "crypter is nullptr."; - maybe_copy_error_msg(error_msg, error_details); - return nullptr; -} diff --git a/src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h b/src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h deleted file mode 100644 index 682a8f7e7a..0000000000 --- a/src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_RECORD_PROTOCOL_CRYPTER_COMMON_H -#define GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_RECORD_PROTOCOL_CRYPTER_COMMON_H - -#include - -#include - -#include "src/core/tsi/alts/frame_protector/alts_counter.h" -#include "src/core/tsi/alts/frame_protector/alts_crypter.h" - -/** - * This file contains common implementation that will be used in both seal and - * unseal operations. - */ - -/** - * Main struct for alts_record_protocol_crypter that will be used in both - * seal and unseal operations. - */ -typedef struct alts_record_protocol_crypter { - alts_crypter base; - gsec_aead_crypter* crypter; - alts_counter* ctr; -} alts_record_protocol_crypter; - -/** - * This method performs input sanity checks on a subset of inputs to - * alts_crypter_process_in_place() for both seal and unseal operations. - * - * - rp_crypter: an alts_record_protocol_crypter instance. - * - data: it represents raw data that needs to be sealed in a seal operation or - * protected data that needs to be unsealed in an unseal operation. - * - output_size: size of data written to the data buffer after a seal or - * unseal operation. - * - error_details: a buffer containing an error message if any of checked - * inputs is nullptr. It is legal to pass nullptr into error_details and - * otherwise, the parameter should be freed with gpr_free. - * - * On success, the method returns GRPC_STATUS_OK. Otherwise, - * it returns an error status code along with its details specified in - * error_details (if error_details is not nullptr). - */ -grpc_status_code input_sanity_check( - const alts_record_protocol_crypter* rp_crypter, const unsigned char* data, - size_t* output_size, char** error_details); - -/** - * This method increments the counter within an alts_record_protocol_crypter - * instance. - * - * - rp_crypter: an alts_record_protocol_crypter instance. - * - error_details: a buffer containing an error message if the method does not - * function correctly or the counter is wrapped. It is legal to pass nullptr - * into error_details and otherwise, the parameter should be freed with - * gpr_free. - * - * On success, the method returns GRPC_STATUS_OK. Otherwise, - * it returns an error status code along with its details specified in - * error_details (if error_details is not nullptr). - */ -grpc_status_code increment_counter(alts_record_protocol_crypter* rp_crypter, - char** error_details); - -/** - * This method creates an alts_crypter instance, and populates the fields - * that are common to both seal and unseal operations. - * - * - crypter: a gsec_aead_crypter instance used to perform AEAD decryption. The - * function does not take ownership of crypter. - * - is_client: a flag indicating if the alts_crypter instance will be - * used at the client (is_client = true) or server (is_client = - * false) side. - * - overflow_size: overflow size of counter in bytes. - * - error_details: a buffer containing an error message if the method does - * not function correctly. It is legal to pass nullptr into error_details, and - * otherwise, the parameter should be freed with gpr_free. - * - * On success of creation, the method returns alts_record_protocol_crypter - * instance. Otherwise, it returns nullptr with its details specified in - * error_details (if error_details is not nullptr). - * - */ -alts_record_protocol_crypter* alts_crypter_create_common( - gsec_aead_crypter* crypter, bool is_client, size_t overflow_size, - char** error_details); - -/** - * For the following two methods, please refer to the corresponding API in - * alts_crypter.h for detailed specifications. - */ -size_t alts_record_protocol_crypter_num_overhead_bytes(const alts_crypter* c); - -void alts_record_protocol_crypter_destruct(alts_crypter* c); - -#endif /* GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_RECORD_PROTOCOL_CRYPTER_COMMON_H \ - */ diff --git a/src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc b/src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc deleted file mode 100644 index f407831613..0000000000 --- a/src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc +++ /dev/null @@ -1,105 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include - -#include "src/core/tsi/alts/frame_protector/alts_counter.h" -#include "src/core/tsi/alts/frame_protector/alts_crypter.h" -#include "src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h" - -static void maybe_copy_error_msg(const char* src, char** dst) { - if (dst != nullptr && src != nullptr) { - *dst = static_cast(gpr_malloc(strlen(src) + 1)); - memcpy(*dst, src, strlen(src) + 1); - } -} - -/* Perform input santity check for a seal operation. */ -static grpc_status_code seal_check(alts_crypter* c, const unsigned char* data, - size_t data_allocated_size, size_t data_size, - size_t* output_size, char** error_details) { - /* Do common input sanity check. */ - grpc_status_code status = input_sanity_check( - reinterpret_cast(c), data, - output_size, error_details); - if (status != GRPC_STATUS_OK) return status; - /* Do seal-specific check. */ - size_t num_overhead_bytes = - alts_crypter_num_overhead_bytes(reinterpret_cast(c)); - if (data_size == 0) { - const char error_msg[] = "data_size is zero."; - maybe_copy_error_msg(error_msg, error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - if (data_size + num_overhead_bytes > data_allocated_size) { - const char error_msg[] = - "data_allocated_size is smaller than sum of data_size and " - "num_overhead_bytes."; - maybe_copy_error_msg(error_msg, error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - return GRPC_STATUS_OK; -} - -static grpc_status_code alts_seal_crypter_process_in_place( - alts_crypter* c, unsigned char* data, size_t data_allocated_size, - size_t data_size, size_t* output_size, char** error_details) { - grpc_status_code status = seal_check(c, data, data_allocated_size, data_size, - output_size, error_details); - if (status != GRPC_STATUS_OK) { - return status; - } - /* Do AEAD encryption. */ - alts_record_protocol_crypter* rp_crypter = - reinterpret_cast(c); - status = gsec_aead_crypter_encrypt( - rp_crypter->crypter, alts_counter_get_counter(rp_crypter->ctr), - alts_counter_get_size(rp_crypter->ctr), nullptr /* aad */, - 0 /* aad_length */, data, data_size, data, data_allocated_size, - output_size, error_details); - if (status != GRPC_STATUS_OK) { - return status; - } - /* Increment the crypter counter. */ - return increment_counter(rp_crypter, error_details); -} - -static const alts_crypter_vtable vtable = { - alts_record_protocol_crypter_num_overhead_bytes, - alts_seal_crypter_process_in_place, alts_record_protocol_crypter_destruct}; - -grpc_status_code alts_seal_crypter_create(gsec_aead_crypter* gc, bool is_client, - size_t overflow_size, - alts_crypter** crypter, - char** error_details) { - if (crypter == nullptr) { - const char error_msg[] = "crypter is nullptr."; - maybe_copy_error_msg(error_msg, error_details); - return GRPC_STATUS_FAILED_PRECONDITION; - } - alts_record_protocol_crypter* rp_crypter = - alts_crypter_create_common(gc, !is_client, overflow_size, error_details); - if (rp_crypter == nullptr) { - return GRPC_STATUS_FAILED_PRECONDITION; - } - rp_crypter->base.vtable = &vtable; - *crypter = &rp_crypter->base; - return GRPC_STATUS_OK; -} diff --git a/src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc b/src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc deleted file mode 100644 index 51bea24f1f..0000000000 --- a/src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc +++ /dev/null @@ -1,103 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include - -#include "src/core/tsi/alts/frame_protector/alts_counter.h" -#include "src/core/tsi/alts/frame_protector/alts_crypter.h" -#include "src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h" - -static void maybe_copy_error_msg(const char* src, char** dst) { - if (dst != nullptr && src != nullptr) { - *dst = static_cast(gpr_malloc(strlen(src) + 1)); - memcpy(*dst, src, strlen(src) + 1); - } -} - -/* Perform input santity check. */ -static grpc_status_code unseal_check(alts_crypter* c, const unsigned char* data, - size_t data_allocated_size, - size_t data_size, size_t* output_size, - char** error_details) { - /* Do common input sanity check. */ - grpc_status_code status = input_sanity_check( - reinterpret_cast(c), data, - output_size, error_details); - if (status != GRPC_STATUS_OK) { - return status; - } - /* Do unseal-specific input check. */ - size_t num_overhead_bytes = - alts_crypter_num_overhead_bytes(reinterpret_cast(c)); - if (num_overhead_bytes > data_size) { - const char error_msg[] = "data_size is smaller than num_overhead_bytes."; - maybe_copy_error_msg(error_msg, error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - return GRPC_STATUS_OK; -} - -static grpc_status_code alts_unseal_crypter_process_in_place( - alts_crypter* c, unsigned char* data, size_t data_allocated_size, - size_t data_size, size_t* output_size, char** error_details) { - grpc_status_code status = unseal_check(c, data, data_allocated_size, - data_size, output_size, error_details); - if (status != GRPC_STATUS_OK) { - return status; - } - /* Do AEAD decryption. */ - alts_record_protocol_crypter* rp_crypter = - reinterpret_cast(c); - status = gsec_aead_crypter_decrypt( - rp_crypter->crypter, alts_counter_get_counter(rp_crypter->ctr), - alts_counter_get_size(rp_crypter->ctr), nullptr /* aad */, - 0 /* aad_length */, data, data_size, data, data_allocated_size, - output_size, error_details); - if (status != GRPC_STATUS_OK) { - return status; - } - /* Increment the crypter counter. */ - return increment_counter(rp_crypter, error_details); -} - -static const alts_crypter_vtable vtable = { - alts_record_protocol_crypter_num_overhead_bytes, - alts_unseal_crypter_process_in_place, - alts_record_protocol_crypter_destruct}; - -grpc_status_code alts_unseal_crypter_create(gsec_aead_crypter* gc, - bool is_client, - size_t overflow_size, - alts_crypter** crypter, - char** error_details) { - if (crypter == nullptr) { - const char error_msg[] = "crypter is nullptr."; - maybe_copy_error_msg(error_msg, error_details); - return GRPC_STATUS_FAILED_PRECONDITION; - } - alts_record_protocol_crypter* rp_crypter = - alts_crypter_create_common(gc, is_client, overflow_size, error_details); - if (rp_crypter == nullptr) { - return GRPC_STATUS_FAILED_PRECONDITION; - } - rp_crypter->base.vtable = &vtable; - *crypter = &rp_crypter->base; - return GRPC_STATUS_OK; -} diff --git a/src/core/tsi/alts/frame_protector/frame_handler.cc b/src/core/tsi/alts/frame_protector/frame_handler.cc deleted file mode 100644 index d3fda63b3d..0000000000 --- a/src/core/tsi/alts/frame_protector/frame_handler.cc +++ /dev/null @@ -1,218 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/tsi/alts/frame_protector/frame_handler.h" - -#include -#include -#include - -#include -#include - -#include "src/core/lib/gpr/useful.h" - -/* Use little endian to interpret a string of bytes as uint32_t. */ -static uint32_t load_32_le(const unsigned char* buffer) { - return (((uint32_t)buffer[3]) << 24) | (((uint32_t)buffer[2]) << 16) | - (((uint32_t)buffer[1]) << 8) | ((uint32_t)buffer[0]); -} - -/* Store uint32_t as a string of little endian bytes. */ -static void store_32_le(uint32_t value, unsigned char* buffer) { - buffer[3] = (unsigned char)(value >> 24) & 0xFF; - buffer[2] = (unsigned char)(value >> 16) & 0xFF; - buffer[1] = (unsigned char)(value >> 8) & 0xFF; - buffer[0] = (unsigned char)(value)&0xFF; -} - -/* Frame writer implementation. */ -alts_frame_writer* alts_create_frame_writer() { - alts_frame_writer* writer = - static_cast(gpr_zalloc(sizeof(*writer))); - return writer; -} - -bool alts_reset_frame_writer(alts_frame_writer* writer, - const unsigned char* buffer, size_t length) { - if (buffer == nullptr) return false; - size_t max_input_size = SIZE_MAX - kFrameLengthFieldSize; - if (length > max_input_size) { - gpr_log(GPR_ERROR, "length must be at most %zu", max_input_size); - return false; - } - writer->input_buffer = buffer; - writer->input_size = length; - writer->input_bytes_written = 0; - writer->header_bytes_written = 0; - store_32_le( - static_cast(writer->input_size + kFrameMessageTypeFieldSize), - writer->header_buffer); - store_32_le(kFrameMessageType, writer->header_buffer + kFrameLengthFieldSize); - return true; -} - -bool alts_write_frame_bytes(alts_frame_writer* writer, unsigned char* output, - size_t* bytes_size) { - if (bytes_size == nullptr || output == nullptr) return false; - if (alts_is_frame_writer_done(writer)) { - *bytes_size = 0; - return true; - } - size_t bytes_written = 0; - /* Write some header bytes, if needed. */ - if (writer->header_bytes_written != sizeof(writer->header_buffer)) { - size_t bytes_to_write = - GPR_MIN(*bytes_size, - sizeof(writer->header_buffer) - writer->header_bytes_written); - memcpy(output, writer->header_buffer + writer->header_bytes_written, - bytes_to_write); - bytes_written += bytes_to_write; - *bytes_size -= bytes_to_write; - writer->header_bytes_written += bytes_to_write; - output += bytes_to_write; - if (writer->header_bytes_written != sizeof(writer->header_buffer)) { - *bytes_size = bytes_written; - return true; - } - } - /* Write some non-header bytes. */ - size_t bytes_to_write = - GPR_MIN(writer->input_size - writer->input_bytes_written, *bytes_size); - memcpy(output, writer->input_buffer, bytes_to_write); - writer->input_buffer += bytes_to_write; - bytes_written += bytes_to_write; - writer->input_bytes_written += bytes_to_write; - *bytes_size = bytes_written; - return true; -} - -bool alts_is_frame_writer_done(alts_frame_writer* writer) { - return writer->input_buffer == nullptr || - writer->input_size == writer->input_bytes_written; -} - -size_t alts_get_num_writer_bytes_remaining(alts_frame_writer* writer) { - return (sizeof(writer->header_buffer) - writer->header_bytes_written) + - (writer->input_size - writer->input_bytes_written); -} - -void alts_destroy_frame_writer(alts_frame_writer* writer) { gpr_free(writer); } - -/* Frame reader implementation. */ -alts_frame_reader* alts_create_frame_reader() { - alts_frame_reader* reader = - static_cast(gpr_zalloc(sizeof(*reader))); - return reader; -} - -bool alts_is_frame_reader_done(alts_frame_reader* reader) { - return reader->output_buffer == nullptr || - (reader->header_bytes_read == sizeof(reader->header_buffer) && - reader->bytes_remaining == 0); -} - -bool alts_has_read_frame_length(alts_frame_reader* reader) { - return sizeof(reader->header_buffer) == reader->header_bytes_read; -} - -size_t alts_get_reader_bytes_remaining(alts_frame_reader* reader) { - return alts_has_read_frame_length(reader) ? reader->bytes_remaining : 0; -} - -void alts_reset_reader_output_buffer(alts_frame_reader* reader, - unsigned char* buffer) { - reader->output_buffer = buffer; -} - -bool alts_reset_frame_reader(alts_frame_reader* reader, unsigned char* buffer) { - if (buffer == nullptr) return false; - reader->output_buffer = buffer; - reader->bytes_remaining = 0; - reader->header_bytes_read = 0; - reader->output_bytes_read = 0; - return true; -} - -bool alts_read_frame_bytes(alts_frame_reader* reader, - const unsigned char* bytes, size_t* bytes_size) { - if (bytes_size == nullptr) return false; - if (bytes == nullptr) { - *bytes_size = 0; - return false; - } - if (alts_is_frame_reader_done(reader)) { - *bytes_size = 0; - return true; - } - size_t bytes_processed = 0; - /* Process the header, if needed. */ - if (reader->header_bytes_read != sizeof(reader->header_buffer)) { - size_t bytes_to_write = GPR_MIN( - *bytes_size, sizeof(reader->header_buffer) - reader->header_bytes_read); - memcpy(reader->header_buffer + reader->header_bytes_read, bytes, - bytes_to_write); - reader->header_bytes_read += bytes_to_write; - bytes_processed += bytes_to_write; - bytes += bytes_to_write; - *bytes_size -= bytes_to_write; - if (reader->header_bytes_read != sizeof(reader->header_buffer)) { - *bytes_size = bytes_processed; - return true; - } - size_t frame_length = load_32_le(reader->header_buffer); - if (frame_length < kFrameMessageTypeFieldSize || - frame_length > kFrameMaxSize) { - gpr_log(GPR_ERROR, - "Bad frame length (should be at least %zu, and at most %zu)", - kFrameMessageTypeFieldSize, kFrameMaxSize); - *bytes_size = 0; - return false; - } - size_t message_type = - load_32_le(reader->header_buffer + kFrameLengthFieldSize); - if (message_type != kFrameMessageType) { - gpr_log(GPR_ERROR, "Unsupported message type %zu (should be %zu)", - message_type, kFrameMessageType); - *bytes_size = 0; - return false; - } - reader->bytes_remaining = frame_length - kFrameMessageTypeFieldSize; - } - /* Process the non-header bytes. */ - size_t bytes_to_write = GPR_MIN(*bytes_size, reader->bytes_remaining); - memcpy(reader->output_buffer, bytes, bytes_to_write); - reader->output_buffer += bytes_to_write; - bytes_processed += bytes_to_write; - reader->bytes_remaining -= bytes_to_write; - reader->output_bytes_read += bytes_to_write; - *bytes_size = bytes_processed; - return true; -} - -size_t alts_get_output_bytes_read(alts_frame_reader* reader) { - return reader->output_bytes_read; -} - -unsigned char* alts_get_output_buffer(alts_frame_reader* reader) { - return reader->output_buffer; -} - -void alts_destroy_frame_reader(alts_frame_reader* reader) { gpr_free(reader); } diff --git a/src/core/tsi/alts/frame_protector/frame_handler.h b/src/core/tsi/alts/frame_protector/frame_handler.h deleted file mode 100644 index a703ff40d3..0000000000 --- a/src/core/tsi/alts/frame_protector/frame_handler.h +++ /dev/null @@ -1,236 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_FRAME_HANDLER_H -#define GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_FRAME_HANDLER_H - -#include - -#include -#include - -const size_t kFrameMessageType = 0x06; -const size_t kFrameLengthFieldSize = 4; -const size_t kFrameMessageTypeFieldSize = 4; -const size_t kFrameMaxSize = 1024 * 1024; -const size_t kFrameHeaderSize = - kFrameLengthFieldSize + kFrameMessageTypeFieldSize; - -/** - * Implementation of frame reader and frame writer. All APIs in the - * header are thread-compatible. - */ - -/** - * Main struct for a frame writer. It reads frames from an input buffer, and - * writes the contents as raw bytes. It does not own the input buffer. - */ -typedef struct alts_frame_writer { - const unsigned char* input_buffer; - unsigned char header_buffer[kFrameHeaderSize]; - size_t input_bytes_written; - size_t header_bytes_written; - size_t input_size; -} alts_frame_writer; - -/** - * Main struct for a frame reader. It reads raw bytes and puts the framed - * result into an output buffer. It does not own the output buffer. - */ -typedef struct alts_frame_reader { - unsigned char* output_buffer; - unsigned char header_buffer[kFrameHeaderSize]; - size_t header_bytes_read; - size_t output_bytes_read; - size_t bytes_remaining; -} alts_frame_reader; - -/** - * This method creates a frame writer instance and initializes its internal - * states. - */ -alts_frame_writer* alts_create_frame_writer(); - -/** - * This method resets internal states of a frame writer and prepares to write - * a single frame. It does not take ownership of payload_buffer. - * The payload_buffer must outlive the writer. - * - * - writer: a frame writer instance. - * - buffer: a buffer storing full payload data to be framed. - * - length: size of payload data. - * - * The method returns true on success and false otherwise. - */ -bool alts_reset_frame_writer(alts_frame_writer* writer, - const unsigned char* buffer, size_t length); - -/** - * This method writes up to bytes_size bytes of a frame to output. - * - * - writer: a frame writer instance. - * - output: an output buffer used to store the frame. - * - bytes_size: an in/out parameter that stores the size of output buffer - * before the call, and gets written the number of frame bytes written to the - * buffer. - * - * The method returns true on success and false otherwise. - */ -bool alts_write_frame_bytes(alts_frame_writer* writer, unsigned char* output, - size_t* bytes_size); - -/** - * This method checks if a reset can be called to write a new frame. It returns - * true if it's the first time to frame a payload, or the current frame has - * been finished processing. It returns false if it's not ready yet to start a - * new frame (e.g., more payload data needs to be accumulated to process the - * current frame). - * - * if (alts_is_frame_writer_done(writer)) { - * // a new frame can be written, call reset. - * alts_reset_frame_writer(writer, payload_buffer, payload_size); - * } else { - * // accumulate more payload data until a full frame can be written. - * } - * - * - writer: a frame writer instance. - */ -bool alts_is_frame_writer_done(alts_frame_writer* writer); - -/** - * This method returns the number of bytes left to write before a complete frame - * is formed. - * - * - writer: a frame writer instance. - */ -size_t alts_get_num_writer_bytes_remaining(alts_frame_writer* writer); - -/** - * This method destroys a frame writer instance. - * - * - writer: a frame writer instance. - */ -void alts_destroy_frame_writer(alts_frame_writer* writer); - -/** - * This method creates a frame reader instance and initializes its internal - * states. - */ -alts_frame_reader* alts_create_frame_reader(); - -/** - * This method resets internal states of a frame reader (including setting its - * output_buffer with buffer), and prepares to write processed bytes to - * an output_buffer. It does not take ownership of buffer. The buffer must - * outlive reader. - * - * - reader: a frame reader instance. - * - buffer: an output buffer used to store deframed results. - * - * The method returns true on success and false otherwise. - */ -bool alts_reset_frame_reader(alts_frame_reader* reader, unsigned char* buffer); - -/** - * This method processes up to the number of bytes given in bytes_size. It may - * choose not to process all the bytes, if, for instance, more bytes are - * given to the method than required to complete the current frame. - * - * - reader: a frame reader instance. - * - bytes: a buffer that stores data to be processed. - * - bytes_size: an in/out parameter that stores the size of bytes before the - * call and gets written the number of bytes processed. - * - * The method returns true on success and false otherwise. - */ -bool alts_read_frame_bytes(alts_frame_reader* reader, - const unsigned char* bytes, size_t* bytes_size); - -/** - * This method checks if a frame length has been read. - * - * - reader: a frame reader instance. - * - * The method returns true if a frame length has been read and false otherwise. - */ -bool alts_has_read_frame_length(alts_frame_reader* reader); - -/** - * This method returns the number of bytes the frame reader intends to write. - * It may only be called if alts_has_read_frame_length() returns true. - * - * - reader: a frame reader instance. - */ -size_t alts_get_reader_bytes_remaining(alts_frame_reader* reader); - -/** - * This method resets output_buffer but does not otherwise modify other internal - * states of a frame reader instance. After being set, the new output_buffer - * will hold the deframed payload held by the original output_buffer. It does - * not take ownership of buffer. The buffer must outlive the reader. - * To distinguish between two reset methods on a frame reader, - * - * if (alts_fh_is_frame_reader_done(reader)) { - * // if buffer contains a full payload to be deframed, call reset. - * alts_reset_frame_reader(reader, buffer); - * } - * - * // if remaining buffer space is not enough to hold a full payload - * if (buffer_space_remaining < alts_get_reader_bytes_remaining(reader)) { - * // allocate enough space for a new buffer, copy back data processed so far, - * // and call reset. - * alts_reset_reader_output_buffer(reader, new_buffer). - * } - * - * - reader: a frame reader instance. - * - buffer: a buffer used to set reader's output_buffer. - */ -void alts_reset_reader_output_buffer(alts_frame_reader* reader, - unsigned char* buffer); - -/** - * This method checks if reset can be called to start processing a new frame. - * If true and reset was previously called, a full frame has been processed and - * the content of the frame is available in output_buffer. - - * - reader: a frame reader instance. - */ -bool alts_is_frame_reader_done(alts_frame_reader* reader); - -/** - * This method returns output_bytes_read of a frame reader instance. - * - * - reader: a frame reader instance. - */ -size_t alts_get_output_bytes_read(alts_frame_reader* reader); - -/** - * This method returns output_buffer of a frame reader instance. - * - * - reader: a frame reader instance. - */ -unsigned char* alts_get_output_buffer(alts_frame_reader* reader); - -/** - * This method destroys a frame reader instance. - * - * - reader: a frame reader instance. - */ -void alts_destroy_frame_reader(alts_frame_reader* reader); - -#endif /* GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_FRAME_HANDLER_H */ diff --git a/src/core/tsi/alts/handshaker/alts_handshaker_client.cc b/src/core/tsi/alts/handshaker/alts_handshaker_client.cc deleted file mode 100644 index 40f30e41ca..0000000000 --- a/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +++ /dev/null @@ -1,316 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/tsi/alts/handshaker/alts_handshaker_client.h" - -#include -#include -#include - -#include "src/core/tsi/alts/handshaker/alts_handshaker_service_api.h" - -const int kHandshakerClientOpNum = 4; - -typedef struct alts_grpc_handshaker_client { - alts_handshaker_client base; - grpc_call* call; - alts_grpc_caller grpc_caller; -} alts_grpc_handshaker_client; - -static grpc_call_error grpc_start_batch(grpc_call* call, const grpc_op* ops, - size_t nops, void* tag) { - return grpc_call_start_batch(call, ops, nops, tag, nullptr); -} - -/** - * Populate grpc operation data with the fields of ALTS TSI event and make a - * grpc call. - */ -static tsi_result make_grpc_call(alts_handshaker_client* client, - alts_tsi_event* event, bool is_start) { - GPR_ASSERT(client != nullptr && event != nullptr); - alts_grpc_handshaker_client* grpc_client = - reinterpret_cast(client); - grpc_op ops[kHandshakerClientOpNum]; - memset(ops, 0, sizeof(ops)); - grpc_op* op = ops; - if (is_start) { - op->op = GRPC_OP_SEND_INITIAL_METADATA; - op->data.send_initial_metadata.count = 0; - op++; - GPR_ASSERT(op - ops <= kHandshakerClientOpNum); - op->op = GRPC_OP_RECV_INITIAL_METADATA; - op->data.recv_initial_metadata.recv_initial_metadata = - &event->initial_metadata; - op++; - GPR_ASSERT(op - ops <= kHandshakerClientOpNum); - } - op->op = GRPC_OP_SEND_MESSAGE; - op->data.send_message.send_message = event->send_buffer; - op++; - GPR_ASSERT(op - ops <= kHandshakerClientOpNum); - op->op = GRPC_OP_RECV_MESSAGE; - op->data.recv_message.recv_message = &event->recv_buffer; - op++; - GPR_ASSERT(op - ops <= kHandshakerClientOpNum); - GPR_ASSERT(grpc_client->grpc_caller != nullptr); - if (grpc_client->grpc_caller(grpc_client->call, ops, - static_cast(op - ops), - (void*)event) != GRPC_CALL_OK) { - gpr_log(GPR_ERROR, "Start batch operation failed"); - return TSI_INTERNAL_ERROR; - } - return TSI_OK; -} - -/* Create and populate a client_start handshaker request, then serialize it. */ -static grpc_byte_buffer* get_serialized_start_client(alts_tsi_event* event) { - bool ok = true; - grpc_gcp_handshaker_req* req = - grpc_gcp_handshaker_req_create(CLIENT_START_REQ); - ok &= grpc_gcp_handshaker_req_set_handshake_protocol( - req, grpc_gcp_HandshakeProtocol_ALTS); - ok &= grpc_gcp_handshaker_req_add_application_protocol( - req, ALTS_APPLICATION_PROTOCOL); - ok &= grpc_gcp_handshaker_req_add_record_protocol(req, ALTS_RECORD_PROTOCOL); - grpc_gcp_rpc_protocol_versions* versions = &event->options->rpc_versions; - ok &= grpc_gcp_handshaker_req_set_rpc_versions( - req, versions->max_rpc_version.major, versions->max_rpc_version.minor, - versions->min_rpc_version.major, versions->min_rpc_version.minor); - char* target_name = grpc_slice_to_c_string(event->target_name); - ok &= grpc_gcp_handshaker_req_set_target_name(req, target_name); - target_service_account* ptr = - (reinterpret_cast(event->options)) - ->target_account_list_head; - while (ptr != nullptr) { - grpc_gcp_handshaker_req_add_target_identity_service_account(req, ptr->data); - ptr = ptr->next; - } - grpc_slice slice; - ok &= grpc_gcp_handshaker_req_encode(req, &slice); - grpc_byte_buffer* buffer = nullptr; - if (ok) { - buffer = grpc_raw_byte_buffer_create(&slice, 1 /* number of slices */); - } - grpc_slice_unref(slice); - gpr_free(target_name); - grpc_gcp_handshaker_req_destroy(req); - return buffer; -} - -static tsi_result handshaker_client_start_client(alts_handshaker_client* client, - alts_tsi_event* event) { - if (client == nullptr || event == nullptr) { - gpr_log(GPR_ERROR, - "Invalid arguments to alts_grpc_handshaker_client_start_client()"); - return TSI_INVALID_ARGUMENT; - } - grpc_byte_buffer* buffer = get_serialized_start_client(event); - if (buffer == nullptr) { - gpr_log(GPR_ERROR, "get_serialized_start_client() failed"); - return TSI_INTERNAL_ERROR; - } - event->send_buffer = buffer; - tsi_result result = make_grpc_call(client, event, true /* is_start */); - if (result != TSI_OK) { - gpr_log(GPR_ERROR, "make_grpc_call() failed"); - } - return result; -} - -/* Create and populate a start_server handshaker request, then serialize it. */ -static grpc_byte_buffer* get_serialized_start_server( - alts_tsi_event* event, grpc_slice* bytes_received) { - GPR_ASSERT(bytes_received != nullptr); - grpc_gcp_handshaker_req* req = - grpc_gcp_handshaker_req_create(SERVER_START_REQ); - bool ok = grpc_gcp_handshaker_req_add_application_protocol( - req, ALTS_APPLICATION_PROTOCOL); - ok &= grpc_gcp_handshaker_req_param_add_record_protocol( - req, grpc_gcp_HandshakeProtocol_ALTS, ALTS_RECORD_PROTOCOL); - ok &= grpc_gcp_handshaker_req_set_in_bytes( - req, reinterpret_cast GRPC_SLICE_START_PTR(*bytes_received), - GRPC_SLICE_LENGTH(*bytes_received)); - grpc_gcp_rpc_protocol_versions* versions = &event->options->rpc_versions; - ok &= grpc_gcp_handshaker_req_set_rpc_versions( - req, versions->max_rpc_version.major, versions->max_rpc_version.minor, - versions->min_rpc_version.major, versions->min_rpc_version.minor); - grpc_slice req_slice; - ok &= grpc_gcp_handshaker_req_encode(req, &req_slice); - grpc_byte_buffer* buffer = nullptr; - if (ok) { - buffer = grpc_raw_byte_buffer_create(&req_slice, 1 /* number of slices */); - } - grpc_slice_unref(req_slice); - grpc_gcp_handshaker_req_destroy(req); - return buffer; -} - -static tsi_result handshaker_client_start_server(alts_handshaker_client* client, - alts_tsi_event* event, - grpc_slice* bytes_received) { - if (client == nullptr || event == nullptr || bytes_received == nullptr) { - gpr_log(GPR_ERROR, - "Invalid arguments to alts_grpc_handshaker_client_start_server()"); - return TSI_INVALID_ARGUMENT; - } - grpc_byte_buffer* buffer = get_serialized_start_server(event, bytes_received); - if (buffer == nullptr) { - gpr_log(GPR_ERROR, "get_serialized_start_server() failed"); - return TSI_INTERNAL_ERROR; - } - event->send_buffer = buffer; - tsi_result result = make_grpc_call(client, event, true /* is_start */); - if (result != TSI_OK) { - gpr_log(GPR_ERROR, "make_grpc_call() failed"); - } - return result; -} - -/* Create and populate a next handshaker request, then serialize it. */ -static grpc_byte_buffer* get_serialized_next(grpc_slice* bytes_received) { - GPR_ASSERT(bytes_received != nullptr); - grpc_gcp_handshaker_req* req = grpc_gcp_handshaker_req_create(NEXT_REQ); - bool ok = grpc_gcp_handshaker_req_set_in_bytes( - req, reinterpret_cast GRPC_SLICE_START_PTR(*bytes_received), - GRPC_SLICE_LENGTH(*bytes_received)); - grpc_slice req_slice; - ok &= grpc_gcp_handshaker_req_encode(req, &req_slice); - grpc_byte_buffer* buffer = nullptr; - if (ok) { - buffer = grpc_raw_byte_buffer_create(&req_slice, 1 /* number of slices */); - } - grpc_slice_unref(req_slice); - grpc_gcp_handshaker_req_destroy(req); - return buffer; -} - -static tsi_result handshaker_client_next(alts_handshaker_client* client, - alts_tsi_event* event, - grpc_slice* bytes_received) { - if (client == nullptr || event == nullptr || bytes_received == nullptr) { - gpr_log(GPR_ERROR, - "Invalid arguments to alts_grpc_handshaker_client_next()"); - return TSI_INVALID_ARGUMENT; - } - grpc_byte_buffer* buffer = get_serialized_next(bytes_received); - if (buffer == nullptr) { - gpr_log(GPR_ERROR, "get_serialized_next() failed"); - return TSI_INTERNAL_ERROR; - } - event->send_buffer = buffer; - tsi_result result = make_grpc_call(client, event, false /* is_start */); - if (result != TSI_OK) { - gpr_log(GPR_ERROR, "make_grpc_call() failed"); - } - return result; -} - -static void handshaker_client_destruct(alts_handshaker_client* client) { - if (client == nullptr) { - return; - } - alts_grpc_handshaker_client* grpc_client = - reinterpret_cast(client); - grpc_call_unref(grpc_client->call); -} - -static const alts_handshaker_client_vtable vtable = { - handshaker_client_start_client, handshaker_client_start_server, - handshaker_client_next, handshaker_client_destruct}; - -alts_handshaker_client* alts_grpc_handshaker_client_create( - grpc_channel* channel, grpc_completion_queue* queue, - const char* handshaker_service_url) { - if (channel == nullptr || queue == nullptr || - handshaker_service_url == nullptr) { - gpr_log(GPR_ERROR, "Invalid arguments to alts_handshaker_client_create()"); - return nullptr; - } - alts_grpc_handshaker_client* client = - static_cast(gpr_zalloc(sizeof(*client))); - client->grpc_caller = grpc_start_batch; - grpc_slice slice = grpc_slice_from_copied_string(handshaker_service_url); - client->call = grpc_channel_create_call( - channel, nullptr, GRPC_PROPAGATE_DEFAULTS, queue, - grpc_slice_from_static_string(ALTS_SERVICE_METHOD), &slice, - gpr_inf_future(GPR_CLOCK_REALTIME), nullptr); - client->base.vtable = &vtable; - grpc_slice_unref(slice); - return &client->base; -} - -namespace grpc_core { -namespace internal { - -void alts_handshaker_client_set_grpc_caller_for_testing( - alts_handshaker_client* client, alts_grpc_caller caller) { - GPR_ASSERT(client != nullptr && caller != nullptr); - alts_grpc_handshaker_client* grpc_client = - reinterpret_cast(client); - grpc_client->grpc_caller = caller; -} - -} // namespace internal -} // namespace grpc_core - -tsi_result alts_handshaker_client_start_client(alts_handshaker_client* client, - alts_tsi_event* event) { - if (client != nullptr && client->vtable != nullptr && - client->vtable->client_start != nullptr) { - return client->vtable->client_start(client, event); - } - gpr_log(GPR_ERROR, - "client or client->vtable has not been initialized properly"); - return TSI_INVALID_ARGUMENT; -} - -tsi_result alts_handshaker_client_start_server(alts_handshaker_client* client, - alts_tsi_event* event, - grpc_slice* bytes_received) { - if (client != nullptr && client->vtable != nullptr && - client->vtable->server_start != nullptr) { - return client->vtable->server_start(client, event, bytes_received); - } - gpr_log(GPR_ERROR, - "client or client->vtable has not been initialized properly"); - return TSI_INVALID_ARGUMENT; -} - -tsi_result alts_handshaker_client_next(alts_handshaker_client* client, - alts_tsi_event* event, - grpc_slice* bytes_received) { - if (client != nullptr && client->vtable != nullptr && - client->vtable->next != nullptr) { - return client->vtable->next(client, event, bytes_received); - } - gpr_log(GPR_ERROR, - "client or client->vtable has not been initialized properly"); - return TSI_INVALID_ARGUMENT; -} - -void alts_handshaker_client_destroy(alts_handshaker_client* client) { - if (client != nullptr) { - if (client->vtable != nullptr && client->vtable->destruct != nullptr) { - client->vtable->destruct(client); - } - gpr_free(client); - } -} diff --git a/src/core/tsi/alts/handshaker/alts_handshaker_client.h b/src/core/tsi/alts/handshaker/alts_handshaker_client.h deleted file mode 100644 index fb2d2cf68e..0000000000 --- a/src/core/tsi/alts/handshaker/alts_handshaker_client.h +++ /dev/null @@ -1,137 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_CLIENT_H -#define GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_CLIENT_H - -#include - -#include - -#include "src/core/tsi/alts/handshaker/alts_tsi_event.h" - -#define ALTS_SERVICE_METHOD "/grpc.gcp.HandshakerService/DoHandshake" -#define ALTS_APPLICATION_PROTOCOL "grpc" -#define ALTS_RECORD_PROTOCOL "ALTSRP_GCM_AES128_REKEY" - -const size_t kAltsAes128GcmRekeyKeyLength = 44; - -/** - * A ALTS handshaker client interface. It is used to communicate with - * ALTS handshaker service by scheduling a handshaker request that could be one - * of client_start, server_start, and next handshaker requests. All APIs in the - * header are thread-compatible. - */ -typedef struct alts_handshaker_client alts_handshaker_client; - -/* A function that makes the grpc call to the handshaker service. */ -typedef grpc_call_error (*alts_grpc_caller)(grpc_call* call, const grpc_op* ops, - size_t nops, void* tag); - -/* V-table for ALTS handshaker client operations. */ -typedef struct alts_handshaker_client_vtable { - tsi_result (*client_start)(alts_handshaker_client* client, - alts_tsi_event* event); - tsi_result (*server_start)(alts_handshaker_client* client, - alts_tsi_event* event, grpc_slice* bytes_received); - tsi_result (*next)(alts_handshaker_client* client, alts_tsi_event* event, - grpc_slice* bytes_received); - void (*destruct)(alts_handshaker_client* client); -} alts_handshaker_client_vtable; - -struct alts_handshaker_client { - const alts_handshaker_client_vtable* vtable; -}; - -/** - * This method schedules a client_start handshaker request to ALTS handshaker - * service. - * - * - client: ALTS handshaker client instance. - * - event: ALTS TSI event instance. - * - * It returns TSI_OK on success and an error status code on failure. - */ -tsi_result alts_handshaker_client_start_client(alts_handshaker_client* client, - alts_tsi_event* event); - -/** - * This method schedules a server_start handshaker request to ALTS handshaker - * service. - * - * - client: ALTS handshaker client instance. - * - event: ALTS TSI event instance. - * - bytes_received: bytes in out_frames returned from the peer's handshaker - * response. - * - * It returns TSI_OK on success and an error status code on failure. - */ -tsi_result alts_handshaker_client_start_server(alts_handshaker_client* client, - alts_tsi_event* event, - grpc_slice* bytes_received); - -/** - * This method schedules a next handshaker request to ALTS handshaker service. - * - * - client: ALTS handshaker client instance. - * - event: ALTS TSI event instance. - * - bytes_received: bytes in out_frames returned from the peer's handshaker - * response. - * - * It returns TSI_OK on success and an error status code on failure. - */ -tsi_result alts_handshaker_client_next(alts_handshaker_client* client, - alts_tsi_event* event, - grpc_slice* bytes_received); - -/** - * This method destroys a ALTS handshaker client. - * - * - client: a ALTS handshaker client instance. - */ -void alts_handshaker_client_destroy(alts_handshaker_client* client); - -/** - * This method creates a ALTS handshaker client. - * - * - channel: grpc channel to ALTS handshaker service. - * - queue: grpc completion queue. - * - handshaker_service_url: address of ALTS handshaker service in the format of - * "host:port". - * - * It returns the created ALTS handshaker client on success, and NULL on - * failure. - */ -alts_handshaker_client* alts_grpc_handshaker_client_create( - grpc_channel* channel, grpc_completion_queue* queue, - const char* handshaker_service_url); - -namespace grpc_core { -namespace internal { - -/** - * Unsafe, use for testing only. It allows the caller to change the way that - * GRPC calls are made to the handshaker service. - */ -void alts_handshaker_client_set_grpc_caller_for_testing( - alts_handshaker_client* client, alts_grpc_caller caller); - -} // namespace internal -} // namespace grpc_core - -#endif /* GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_CLIENT_H */ diff --git a/src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc b/src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc deleted file mode 100644 index 256e414ae4..0000000000 --- a/src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc +++ /dev/null @@ -1,520 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/tsi/alts/handshaker/alts_handshaker_service_api.h" - -#include -#include - -#include "src/core/tsi/alts/handshaker/transport_security_common_api.h" - -/* HandshakerReq */ -grpc_gcp_handshaker_req* grpc_gcp_handshaker_req_create( - grpc_gcp_handshaker_req_type type) { - grpc_gcp_handshaker_req* req = - static_cast(gpr_zalloc(sizeof(*req))); - switch (type) { - case CLIENT_START_REQ: - req->has_client_start = true; - break; - case SERVER_START_REQ: - req->has_server_start = true; - break; - case NEXT_REQ: - req->has_next = true; - break; - } - return req; -} - -void grpc_gcp_handshaker_req_destroy(grpc_gcp_handshaker_req* req) { - if (req == nullptr) { - return; - } - if (req->has_client_start) { - /* Destroy client_start request. */ - destroy_repeated_field_list_identity( - static_cast(req->client_start.target_identities.arg)); - destroy_repeated_field_list_string(static_cast( - req->client_start.application_protocols.arg)); - destroy_repeated_field_list_string( - static_cast(req->client_start.record_protocols.arg)); - if (req->client_start.has_local_identity) { - destroy_slice(static_cast( - req->client_start.local_identity.hostname.arg)); - destroy_slice(static_cast( - req->client_start.local_identity.service_account.arg)); - } - if (req->client_start.has_local_endpoint) { - destroy_slice(static_cast( - req->client_start.local_endpoint.ip_address.arg)); - } - if (req->client_start.has_remote_endpoint) { - destroy_slice(static_cast( - req->client_start.remote_endpoint.ip_address.arg)); - } - destroy_slice(static_cast(req->client_start.target_name.arg)); - } else if (req->has_server_start) { - /* Destroy server_start request. */ - size_t i = 0; - for (i = 0; i < req->server_start.handshake_parameters_count; i++) { - destroy_repeated_field_list_identity( - static_cast(req->server_start.handshake_parameters[i] - .value.local_identities.arg)); - destroy_repeated_field_list_string( - static_cast(req->server_start.handshake_parameters[i] - .value.record_protocols.arg)); - } - destroy_repeated_field_list_string(static_cast( - req->server_start.application_protocols.arg)); - if (req->server_start.has_local_endpoint) { - destroy_slice(static_cast( - req->server_start.local_endpoint.ip_address.arg)); - } - if (req->server_start.has_remote_endpoint) { - destroy_slice(static_cast( - req->server_start.remote_endpoint.ip_address.arg)); - } - destroy_slice(static_cast(req->server_start.in_bytes.arg)); - } else { - /* Destroy next request. */ - destroy_slice(static_cast(req->next.in_bytes.arg)); - } - gpr_free(req); -} - -bool grpc_gcp_handshaker_req_set_handshake_protocol( - grpc_gcp_handshaker_req* req, - grpc_gcp_handshake_protocol handshake_protocol) { - if (req == nullptr || !req->has_client_start) { - gpr_log(GPR_ERROR, - "Invalid arguments to " - "grpc_gcp_handshaker_req_set_handshake_protocol()."); - return false; - } - req->client_start.has_handshake_security_protocol = true; - req->client_start.handshake_security_protocol = handshake_protocol; - return true; -} - -bool grpc_gcp_handshaker_req_set_target_name(grpc_gcp_handshaker_req* req, - const char* target_name) { - if (req == nullptr || target_name == nullptr || !req->has_client_start) { - gpr_log(GPR_ERROR, - "Invalid arguments to " - "grpc_gcp_handshaker_req_set_target_name()."); - return false; - } - grpc_slice* slice = create_slice(target_name, strlen(target_name)); - req->client_start.target_name.arg = slice; - req->client_start.target_name.funcs.encode = encode_string_or_bytes_cb; - return true; -} - -bool grpc_gcp_handshaker_req_add_application_protocol( - grpc_gcp_handshaker_req* req, const char* application_protocol) { - if (req == nullptr || application_protocol == nullptr || req->has_next) { - gpr_log(GPR_ERROR, - "Invalid arguments to " - "grpc_gcp_handshaker_req_add_application_protocol()."); - return false; - } - grpc_slice* slice = - create_slice(application_protocol, strlen(application_protocol)); - if (req->has_client_start) { - add_repeated_field(reinterpret_cast( - &req->client_start.application_protocols.arg), - slice); - req->client_start.application_protocols.funcs.encode = - encode_repeated_string_cb; - } else { - add_repeated_field(reinterpret_cast( - &req->server_start.application_protocols.arg), - slice); - req->server_start.application_protocols.funcs.encode = - encode_repeated_string_cb; - } - return true; -} - -bool grpc_gcp_handshaker_req_add_record_protocol(grpc_gcp_handshaker_req* req, - const char* record_protocol) { - if (req == nullptr || record_protocol == nullptr || !req->has_client_start) { - gpr_log(GPR_ERROR, - "Invalid arguments to " - "grpc_gcp_handshaker_req_add_record_protocol()."); - return false; - } - grpc_slice* slice = create_slice(record_protocol, strlen(record_protocol)); - add_repeated_field(reinterpret_cast( - &req->client_start.record_protocols.arg), - slice); - req->client_start.record_protocols.funcs.encode = encode_repeated_string_cb; - return true; -} - -static void set_identity_hostname(grpc_gcp_identity* identity, - const char* hostname) { - grpc_slice* slice = create_slice(hostname, strlen(hostname)); - identity->hostname.arg = slice; - identity->hostname.funcs.encode = encode_string_or_bytes_cb; -} - -static void set_identity_service_account(grpc_gcp_identity* identity, - const char* service_account) { - grpc_slice* slice = create_slice(service_account, strlen(service_account)); - identity->service_account.arg = slice; - identity->service_account.funcs.encode = encode_string_or_bytes_cb; -} - -bool grpc_gcp_handshaker_req_add_target_identity_hostname( - grpc_gcp_handshaker_req* req, const char* hostname) { - if (req == nullptr || hostname == nullptr || !req->has_client_start) { - gpr_log(GPR_ERROR, - "Invalid nullptr arguments to " - "grpc_gcp_handshaker_req_add_target_identity_hostname()."); - return false; - } - grpc_gcp_identity* target_identity = - static_cast(gpr_zalloc(sizeof(*target_identity))); - set_identity_hostname(target_identity, hostname); - req->client_start.target_identities.funcs.encode = - encode_repeated_identity_cb; - add_repeated_field(reinterpret_cast( - &req->client_start.target_identities.arg), - target_identity); - return true; -} - -bool grpc_gcp_handshaker_req_add_target_identity_service_account( - grpc_gcp_handshaker_req* req, const char* service_account) { - if (req == nullptr || service_account == nullptr || !req->has_client_start) { - gpr_log(GPR_ERROR, - "Invalid nullptr arguments to " - "grpc_gcp_handshaker_req_add_target_identity_service_account()."); - return false; - } - grpc_gcp_identity* target_identity = - static_cast(gpr_zalloc(sizeof(*target_identity))); - set_identity_service_account(target_identity, service_account); - req->client_start.target_identities.funcs.encode = - encode_repeated_identity_cb; - add_repeated_field(reinterpret_cast( - &req->client_start.target_identities.arg), - target_identity); - return true; -} - -bool grpc_gcp_handshaker_req_set_local_identity_hostname( - grpc_gcp_handshaker_req* req, const char* hostname) { - if (req == nullptr || hostname == nullptr || !req->has_client_start) { - gpr_log(GPR_ERROR, - "Invalid nullptr arguments to " - "grpc_gcp_handshaker_req_set_local_identity_hostname()."); - return false; - } - req->client_start.has_local_identity = true; - set_identity_hostname(&req->client_start.local_identity, hostname); - return true; -} - -bool grpc_gcp_handshaker_req_set_local_identity_service_account( - grpc_gcp_handshaker_req* req, const char* service_account) { - if (req == nullptr || service_account == nullptr || !req->has_client_start) { - gpr_log(GPR_ERROR, - "Invalid nullptr arguments to " - "grpc_gcp_handshaker_req_set_local_identity_service_account()."); - return false; - } - req->client_start.has_local_identity = true; - set_identity_service_account(&req->client_start.local_identity, - service_account); - return true; -} - -static void set_endpoint(grpc_gcp_endpoint* endpoint, const char* ip_address, - size_t port, grpc_gcp_network_protocol protocol) { - grpc_slice* slice = create_slice(ip_address, strlen(ip_address)); - endpoint->ip_address.arg = slice; - endpoint->ip_address.funcs.encode = encode_string_or_bytes_cb; - endpoint->has_port = true; - endpoint->port = static_cast(port); - endpoint->has_protocol = true; - endpoint->protocol = protocol; -} - -bool grpc_gcp_handshaker_req_set_rpc_versions(grpc_gcp_handshaker_req* req, - uint32_t max_major, - uint32_t max_minor, - uint32_t min_major, - uint32_t min_minor) { - if (req == nullptr || req->has_next) { - gpr_log(GPR_ERROR, - "Invalid arguments to " - "grpc_gcp_handshaker_req_set_rpc_versions()."); - return false; - } - if (req->has_client_start) { - req->client_start.has_rpc_versions = true; - grpc_gcp_rpc_protocol_versions_set_max(&req->client_start.rpc_versions, - max_major, max_minor); - grpc_gcp_rpc_protocol_versions_set_min(&req->client_start.rpc_versions, - min_major, min_minor); - } else { - req->server_start.has_rpc_versions = true; - grpc_gcp_rpc_protocol_versions_set_max(&req->server_start.rpc_versions, - max_major, max_minor); - grpc_gcp_rpc_protocol_versions_set_min(&req->server_start.rpc_versions, - min_major, min_minor); - } - return true; -} - -bool grpc_gcp_handshaker_req_set_local_endpoint( - grpc_gcp_handshaker_req* req, const char* ip_address, size_t port, - grpc_gcp_network_protocol protocol) { - if (req == nullptr || ip_address == nullptr || port > 65535 || - req->has_next) { - gpr_log(GPR_ERROR, - "Invalid arguments to " - "grpc_gcp_handshaker_req_set_local_endpoint()."); - return false; - } - if (req->has_client_start) { - req->client_start.has_local_endpoint = true; - set_endpoint(&req->client_start.local_endpoint, ip_address, port, protocol); - } else { - req->server_start.has_local_endpoint = true; - set_endpoint(&req->server_start.local_endpoint, ip_address, port, protocol); - } - return true; -} - -bool grpc_gcp_handshaker_req_set_remote_endpoint( - grpc_gcp_handshaker_req* req, const char* ip_address, size_t port, - grpc_gcp_network_protocol protocol) { - if (req == nullptr || ip_address == nullptr || port > 65535 || - req->has_next) { - gpr_log(GPR_ERROR, - "Invalid arguments to " - "grpc_gcp_handshaker_req_set_remote_endpoint()."); - return false; - } - if (req->has_client_start) { - req->client_start.has_remote_endpoint = true; - set_endpoint(&req->client_start.remote_endpoint, ip_address, port, - protocol); - } else { - req->server_start.has_remote_endpoint = true; - set_endpoint(&req->server_start.remote_endpoint, ip_address, port, - protocol); - } - return true; -} - -bool grpc_gcp_handshaker_req_set_in_bytes(grpc_gcp_handshaker_req* req, - const char* in_bytes, size_t size) { - if (req == nullptr || in_bytes == nullptr || req->has_client_start) { - gpr_log(GPR_ERROR, - "Invalid arguments to " - "grpc_gcp_handshaker_req_set_in_bytes()."); - return false; - } - grpc_slice* slice = create_slice(in_bytes, size); - if (req->has_next) { - req->next.in_bytes.arg = slice; - req->next.in_bytes.funcs.encode = &encode_string_or_bytes_cb; - } else { - req->server_start.in_bytes.arg = slice; - req->server_start.in_bytes.funcs.encode = &encode_string_or_bytes_cb; - } - return true; -} - -static grpc_gcp_server_handshake_parameters* server_start_find_param( - grpc_gcp_handshaker_req* req, int32_t key) { - size_t i = 0; - for (i = 0; i < req->server_start.handshake_parameters_count; i++) { - if (req->server_start.handshake_parameters[i].key == key) { - return &req->server_start.handshake_parameters[i].value; - } - } - req->server_start - .handshake_parameters[req->server_start.handshake_parameters_count] - .has_key = true; - req->server_start - .handshake_parameters[req->server_start.handshake_parameters_count] - .has_value = true; - req->server_start - .handshake_parameters[req->server_start.handshake_parameters_count++] - .key = key; - return &req->server_start - .handshake_parameters - [req->server_start.handshake_parameters_count - 1] - .value; -} - -bool grpc_gcp_handshaker_req_param_add_record_protocol( - grpc_gcp_handshaker_req* req, grpc_gcp_handshake_protocol key, - const char* record_protocol) { - if (req == nullptr || record_protocol == nullptr || !req->has_server_start) { - gpr_log(GPR_ERROR, - "Invalid arguments to " - "grpc_gcp_handshaker_req_param_add_record_protocol()."); - return false; - } - grpc_gcp_server_handshake_parameters* param = - server_start_find_param(req, key); - grpc_slice* slice = create_slice(record_protocol, strlen(record_protocol)); - add_repeated_field( - reinterpret_cast(¶m->record_protocols.arg), slice); - param->record_protocols.funcs.encode = &encode_repeated_string_cb; - return true; -} - -bool grpc_gcp_handshaker_req_param_add_local_identity_hostname( - grpc_gcp_handshaker_req* req, grpc_gcp_handshake_protocol key, - const char* hostname) { - if (req == nullptr || hostname == nullptr || !req->has_server_start) { - gpr_log(GPR_ERROR, - "Invalid arguments to " - "grpc_gcp_handshaker_req_param_add_local_identity_hostname()."); - return false; - } - grpc_gcp_server_handshake_parameters* param = - server_start_find_param(req, key); - grpc_gcp_identity* local_identity = - static_cast(gpr_zalloc(sizeof(*local_identity))); - set_identity_hostname(local_identity, hostname); - add_repeated_field( - reinterpret_cast(¶m->local_identities.arg), - local_identity); - param->local_identities.funcs.encode = &encode_repeated_identity_cb; - return true; -} - -bool grpc_gcp_handshaker_req_param_add_local_identity_service_account( - grpc_gcp_handshaker_req* req, grpc_gcp_handshake_protocol key, - const char* service_account) { - if (req == nullptr || service_account == nullptr || !req->has_server_start) { - gpr_log( - GPR_ERROR, - "Invalid arguments to " - "grpc_gcp_handshaker_req_param_add_local_identity_service_account()."); - return false; - } - grpc_gcp_server_handshake_parameters* param = - server_start_find_param(req, key); - grpc_gcp_identity* local_identity = - static_cast(gpr_zalloc(sizeof(*local_identity))); - set_identity_service_account(local_identity, service_account); - add_repeated_field( - reinterpret_cast(¶m->local_identities.arg), - local_identity); - param->local_identities.funcs.encode = &encode_repeated_identity_cb; - return true; -} - -bool grpc_gcp_handshaker_req_encode(grpc_gcp_handshaker_req* req, - grpc_slice* slice) { - if (req == nullptr || slice == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr arguments to grpc_gcp_handshaker_req_encode()."); - return false; - } - pb_ostream_t size_stream; - memset(&size_stream, 0, sizeof(pb_ostream_t)); - if (!pb_encode(&size_stream, grpc_gcp_HandshakerReq_fields, req)) { - gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&size_stream)); - return false; - } - size_t encoded_length = size_stream.bytes_written; - *slice = grpc_slice_malloc(encoded_length); - pb_ostream_t output_stream = - pb_ostream_from_buffer(GRPC_SLICE_START_PTR(*slice), encoded_length); - if (!pb_encode(&output_stream, grpc_gcp_HandshakerReq_fields, req) != 0) { - gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&output_stream)); - return false; - } - return true; -} - -/* HandshakerResp. */ -grpc_gcp_handshaker_resp* grpc_gcp_handshaker_resp_create(void) { - grpc_gcp_handshaker_resp* resp = - static_cast(gpr_zalloc(sizeof(*resp))); - return resp; -} - -void grpc_gcp_handshaker_resp_destroy(grpc_gcp_handshaker_resp* resp) { - if (resp != nullptr) { - destroy_slice(static_cast(resp->out_frames.arg)); - if (resp->has_status) { - destroy_slice(static_cast(resp->status.details.arg)); - } - if (resp->has_result) { - destroy_slice( - static_cast(resp->result.application_protocol.arg)); - destroy_slice(static_cast(resp->result.record_protocol.arg)); - destroy_slice(static_cast(resp->result.key_data.arg)); - if (resp->result.has_local_identity) { - destroy_slice( - static_cast(resp->result.local_identity.hostname.arg)); - destroy_slice(static_cast( - resp->result.local_identity.service_account.arg)); - } - if (resp->result.has_peer_identity) { - destroy_slice( - static_cast(resp->result.peer_identity.hostname.arg)); - destroy_slice(static_cast( - resp->result.peer_identity.service_account.arg)); - } - } - gpr_free(resp); - } -} - -bool grpc_gcp_handshaker_resp_decode(grpc_slice encoded_handshaker_resp, - grpc_gcp_handshaker_resp* resp) { - if (resp == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr argument to grpc_gcp_handshaker_resp_decode()."); - return false; - } - pb_istream_t stream = - pb_istream_from_buffer(GRPC_SLICE_START_PTR(encoded_handshaker_resp), - GRPC_SLICE_LENGTH(encoded_handshaker_resp)); - resp->out_frames.funcs.decode = decode_string_or_bytes_cb; - resp->status.details.funcs.decode = decode_string_or_bytes_cb; - resp->result.application_protocol.funcs.decode = decode_string_or_bytes_cb; - resp->result.record_protocol.funcs.decode = decode_string_or_bytes_cb; - resp->result.key_data.funcs.decode = decode_string_or_bytes_cb; - resp->result.peer_identity.hostname.funcs.decode = decode_string_or_bytes_cb; - resp->result.peer_identity.service_account.funcs.decode = - decode_string_or_bytes_cb; - resp->result.local_identity.hostname.funcs.decode = decode_string_or_bytes_cb; - resp->result.local_identity.service_account.funcs.decode = - decode_string_or_bytes_cb; - if (!pb_decode(&stream, grpc_gcp_HandshakerResp_fields, resp)) { - gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&stream)); - return false; - } - return true; -} diff --git a/src/core/tsi/alts/handshaker/alts_handshaker_service_api.h b/src/core/tsi/alts/handshaker/alts_handshaker_service_api.h deleted file mode 100644 index 5df56a86fa..0000000000 --- a/src/core/tsi/alts/handshaker/alts_handshaker_service_api.h +++ /dev/null @@ -1,323 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_SERVICE_API_H -#define GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_SERVICE_API_H - -#include - -#include "src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h" - -/** - * An implementation of nanopb thin wrapper used to set/get and - * serialize/de-serialize of ALTS handshake requests and responses. - * - * All APIs in the header are thread-compatible. A typical usage of this API at - * the client side is as follows: - * - * ----------------------------------------------------------------------------- - * // Create, populate, and serialize an ALTS client_start handshake request to - * // send to the server. - * grpc_gcp_handshaker_req* req = - * grpc_gcp_handshaker_req_create(CLIENT_START_REQ); - * grpc_gcp_handshaker_req_set_handshake_protocol( - req, grpc_gcp_HandshakeProtocol_ALTS); - * grpc_gcp_handshaker_req_add_application_protocol(req, "grpc"); - * grpc_gcp_handshaker_req_add_record_protocol(req, "ALTSRP_GCM_AES128"); - * grpc_slice client_slice; - * if (!grpc_gcp_handshaker_req_encode(req, &client_slice)) { - * fprintf(stderr, "ALTS handshake request encoding failed."; - * } - * - * // De-serialize a data stream received from the server, and store the result - * // at ALTS handshake response. - * grpc_gcp_handshaker_resp* resp = grpc_gcp_handshaker_resp_create(); - * if (!grpc_gcp_handshaker_resp_decode(server_slice, resp)) { - * fprintf(stderr, "ALTS handshake response decoding failed."); - * } - * // To access a variable-length datatype field (i.e., pb_callback_t), - * // access its "arg" subfield (if it has been set). - * if (resp->out_frames.arg != nullptr) { - * grpc_slice* slice = resp->out_frames.arg; - * } - * // To access a fixed-length datatype field (i.e., not pb_calback_t), - * // access the field directly (if it has been set). - * if (resp->has_status && resp->status->has_code) { - * uint32_t code = resp->status->code; - * } - *------------------------------------------------------------------------------ - */ - -/** - * This method creates an ALTS handshake request. - * - * - type: an enum type value that can be either CLIENT_START_REQ, - * SERVER_START_REQ, or NEXT_REQ to indicate the created instance will be - * client_start, server_start, and next handshake request message - * respectively. - * - * The method returns a pointer to the created instance. - */ -grpc_gcp_handshaker_req* grpc_gcp_handshaker_req_create( - grpc_gcp_handshaker_req_type type); - -/** - * This method sets the value for handshake_security_protocol field of ALTS - * client_start handshake request. - * - * - req: an ALTS handshake request. - * - handshake_protocol: a enum type value representing the handshake security - * protocol. - * - * The method returns true on success and false otherwise. - */ -bool grpc_gcp_handshaker_req_set_handshake_protocol( - grpc_gcp_handshaker_req* req, - grpc_gcp_handshake_protocol handshake_protocol); - -/** - * This method sets the value for target_name field of ALTS client_start - * handshake request. - * - * - req: an ALTS handshake request. - * - target_name: a target name to be set. - * - * The method returns true on success and false otherwise. - */ -bool grpc_gcp_handshaker_req_set_target_name(grpc_gcp_handshaker_req* req, - const char* target_name); - -/** - * This method adds an application protocol supported by the server (or - * client) to ALTS server_start (or client_start) handshake request. - * - * - req: an ALTS handshake request. - * - application_protocol: an application protocol (e.g., grpc) to be added. - * - * The method returns true on success and false otherwise. - */ -bool grpc_gcp_handshaker_req_add_application_protocol( - grpc_gcp_handshaker_req* req, const char* application_protocol); - -/** - * This method adds a record protocol supported by the client to ALTS - * client_start handshake request. - * - * - req: an ALTS handshake request. - * - record_protocol: a record protocol (e.g., ALTSRP_GCM_AES128) to be - * added. - * - * The method returns true on success and false otherwise. - */ -bool grpc_gcp_handshaker_req_add_record_protocol(grpc_gcp_handshaker_req* req, - const char* record_protocol); - -/** - * This method adds a target server identity represented as hostname and - * acceptable by a client to ALTS client_start handshake request. - * - * - req: an ALTS handshake request. - * - hostname: a string representation of hostname at the connection - * endpoint to be added. - * - * The method returns true on success and false otherwise. - */ -bool grpc_gcp_handshaker_req_add_target_identity_hostname( - grpc_gcp_handshaker_req* req, const char* hostname); - -/** - * This method adds a target server identity represented as service account and - * acceptable by a client to ALTS client_start handshake request. - * - * - req: an ALTS handshake request. - * - service_account: a string representation of service account at the - * connection endpoint to be added. - * - * The method returns true on success and false otherwise. - */ -bool grpc_gcp_handshaker_req_add_target_identity_service_account( - grpc_gcp_handshaker_req* req, const char* service_account); - -/** - * This method sets the hostname for local_identity field of ALTS client_start - * handshake request. - * - * - req: an ALTS handshake request. - * - hostname: a string representation of hostname. - * - * The method returns true on success and false otherwise. - */ -bool grpc_gcp_handshaker_req_set_local_identity_hostname( - grpc_gcp_handshaker_req* req, const char* hostname); - -/** - * This method sets the service account for local_identity field of ALTS - * client_start handshake request. - * - * - req: an ALTS handshake request. - * - service_account: a string representation of service account. - * - * The method returns true on success and false otherwise. - */ -bool grpc_gcp_handshaker_req_set_local_identity_service_account( - grpc_gcp_handshaker_req* req, const char* service_account); - -/** - * This method sets the value for local_endpoint field of either ALTS - * client_start or server_start handshake request. - * - * - req: an ALTS handshake request. - * - ip_address: a string representation of ip address associated with the - * local endpoint, that could be either IPv4 or IPv6. - * - port: a port number associated with the local endpoint. - * - protocol: a network protocol (e.g., TCP or UDP) associated with the - * local endpoint. - * - * The method returns true on success and false otherwise. - */ -bool grpc_gcp_handshaker_req_set_local_endpoint( - grpc_gcp_handshaker_req* req, const char* ip_address, size_t port, - grpc_gcp_network_protocol protocol); - -/** - * This method sets the value for remote_endpoint field of either ALTS - * client_start or server_start handshake request. - * - * - req: an ALTS handshake request. - * - ip_address: a string representation of ip address associated with the - * remote endpoint, that could be either IPv4 or IPv6. - * - port: a port number associated with the remote endpoint. - * - protocol: a network protocol (e.g., TCP or UDP) associated with the - * remote endpoint. - * - * The method returns true on success and false otherwise. - */ -bool grpc_gcp_handshaker_req_set_remote_endpoint( - grpc_gcp_handshaker_req* req, const char* ip_address, size_t port, - grpc_gcp_network_protocol protocol); - -/** - * This method sets the value for in_bytes field of either ALTS server_start or - * next handshake request. - * - * - req: an ALTS handshake request. - * - in_bytes: a buffer containing bytes taken from out_frames of the peer's - * ALTS handshake response. It is possible that the peer's out_frames are - * split into multiple handshake request messages. - * - size: size of in_bytes buffer. - * - * The method returns true on success and false otherwise. - */ -bool grpc_gcp_handshaker_req_set_in_bytes(grpc_gcp_handshaker_req* req, - const char* in_bytes, size_t size); - -/** - * This method adds a record protocol to handshake parameters mapped by the - * handshake protocol for ALTS server_start handshake request. - * - * - req: an ALTS handshake request. - * - key: an enum type value representing a handshake security protocol. - * - record_protocol: a record protocol to be added. - * - * The method returns true on success and false otherwise. - */ -bool grpc_gcp_handshaker_req_param_add_record_protocol( - grpc_gcp_handshaker_req* req, grpc_gcp_handshake_protocol key, - const char* record_protocol); - -/** - * This method adds a local identity represented as hostname to handshake - * parameters mapped by the handshake protocol for ALTS server_start handshake - * request. - * - * - req: an ALTS handshake request. - * - key: an enum type value representing a handshake security protocol. - * - hostname: a string representation of hostname to be added. - * - * The method returns true on success and false otherwise. - */ -bool grpc_gcp_handshaker_req_param_add_local_identity_hostname( - grpc_gcp_handshaker_req* req, grpc_gcp_handshake_protocol key, - const char* hostname); - -/** - * This method adds a local identity represented as service account to handshake - * parameters mapped by the handshake protocol for ALTS server_start handshake - * request. - * - * - req: an ALTS handshake request. - * - key: an enum type value representing a handshake security protocol. - * - service_account: a string representation of service account to be added. - * - * The method returns true on success and false otherwise. - */ -bool grpc_gcp_handshaker_req_param_add_local_identity_service_account( - grpc_gcp_handshaker_req* req, grpc_gcp_handshake_protocol key, - const char* service_account); - -/** - * This method sets the value for rpc_versions field of either ALTS - * client_start or server_start handshake request. - * - * - req: an ALTS handshake request. - * - max_major: a major version of maximum supported RPC version. - * - max_minor: a minor version of maximum supported RPC version. - * - min_major: a major version of minimum supported RPC version. - * - min_minor: a minor version of minimum supported RPC version. - * - * The method returns true on success and false otherwise. - */ -bool grpc_gcp_handshaker_req_set_rpc_versions(grpc_gcp_handshaker_req* req, - uint32_t max_major, - uint32_t max_minor, - uint32_t min_major, - uint32_t min_minor); - -/** - * This method serializes an ALTS handshake request and returns a data stream. - * - * - req: an ALTS handshake request. - * - slice: a data stream where the serialized result will be written. - * - * The method returns true on success and false otherwise. - */ -bool grpc_gcp_handshaker_req_encode(grpc_gcp_handshaker_req* req, - grpc_slice* slice); - -/* This method destroys an ALTS handshake request. */ -void grpc_gcp_handshaker_req_destroy(grpc_gcp_handshaker_req* req); - -/* This method creates an ALTS handshake response. */ -grpc_gcp_handshaker_resp* grpc_gcp_handshaker_resp_create(void); - -/** - * This method de-serializes a data stream and stores the result - * in an ALTS handshake response. - * - * - slice: a data stream containing a serialized ALTS handshake response. - * - resp: an ALTS handshake response used to hold de-serialized result. - * - * The method returns true on success and false otherwise. - */ -bool grpc_gcp_handshaker_resp_decode(grpc_slice slice, - grpc_gcp_handshaker_resp* resp); - -/* This method destroys an ALTS handshake response. */ -void grpc_gcp_handshaker_resp_destroy(grpc_gcp_handshaker_resp* resp); - -#endif /* GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_SERVICE_API_H */ diff --git a/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc b/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc deleted file mode 100644 index e0e4184686..0000000000 --- a/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc +++ /dev/null @@ -1,143 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h" - -void add_repeated_field(repeated_field** head, const void* data) { - repeated_field* field = - static_cast(gpr_zalloc(sizeof(*field))); - field->data = data; - if (*head == nullptr) { - *head = field; - (*head)->next = nullptr; - } else { - field->next = *head; - *head = field; - } -} - -void destroy_repeated_field_list_identity(repeated_field* head) { - repeated_field* field = head; - while (field != nullptr) { - repeated_field* next_field = field->next; - const grpc_gcp_identity* identity = - static_cast(field->data); - destroy_slice(static_cast(identity->hostname.arg)); - destroy_slice(static_cast(identity->service_account.arg)); - gpr_free((void*)identity); - gpr_free(field); - field = next_field; - } -} - -void destroy_repeated_field_list_string(repeated_field* head) { - repeated_field* field = head; - while (field != nullptr) { - repeated_field* next_field = field->next; - destroy_slice((grpc_slice*)field->data); - gpr_free(field); - field = next_field; - } -} - -grpc_slice* create_slice(const char* data, size_t size) { - grpc_slice slice = grpc_slice_from_copied_buffer(data, size); - grpc_slice* cb_slice = - static_cast(gpr_zalloc(sizeof(*cb_slice))); - memcpy(cb_slice, &slice, sizeof(*cb_slice)); - return cb_slice; -} - -void destroy_slice(grpc_slice* slice) { - if (slice != nullptr) { - grpc_slice_unref(*slice); - gpr_free(slice); - } -} - -bool encode_string_or_bytes_cb(pb_ostream_t* stream, const pb_field_t* field, - void* const* arg) { - grpc_slice* slice = static_cast(*arg); - if (!pb_encode_tag_for_field(stream, field)) return false; - return pb_encode_string(stream, GRPC_SLICE_START_PTR(*slice), - GRPC_SLICE_LENGTH(*slice)); -} - -bool encode_repeated_identity_cb(pb_ostream_t* stream, const pb_field_t* field, - void* const* arg) { - repeated_field* var = static_cast(*arg); - while (var != nullptr) { - if (!pb_encode_tag_for_field(stream, field)) return false; - if (!pb_encode_submessage(stream, grpc_gcp_Identity_fields, - (grpc_gcp_identity*)var->data)) - return false; - var = var->next; - } - return true; -} - -bool encode_repeated_string_cb(pb_ostream_t* stream, const pb_field_t* field, - void* const* arg) { - repeated_field* var = static_cast(*arg); - while (var != nullptr) { - if (!pb_encode_tag_for_field(stream, field)) return false; - const grpc_slice* slice = static_cast(var->data); - if (!pb_encode_string(stream, GRPC_SLICE_START_PTR(*slice), - GRPC_SLICE_LENGTH(*slice))) - return false; - var = var->next; - } - return true; -} - -bool decode_string_or_bytes_cb(pb_istream_t* stream, const pb_field_t* field, - void** arg) { - grpc_slice slice = grpc_slice_malloc(stream->bytes_left); - grpc_slice* cb_slice = - static_cast(gpr_zalloc(sizeof(*cb_slice))); - memcpy(cb_slice, &slice, sizeof(*cb_slice)); - if (!pb_read(stream, GRPC_SLICE_START_PTR(*cb_slice), stream->bytes_left)) - return false; - *arg = cb_slice; - return true; -} - -bool decode_repeated_identity_cb(pb_istream_t* stream, const pb_field_t* field, - void** arg) { - grpc_gcp_identity* identity = - static_cast(gpr_zalloc(sizeof(*identity))); - identity->hostname.funcs.decode = decode_string_or_bytes_cb; - identity->service_account.funcs.decode = decode_string_or_bytes_cb; - add_repeated_field(reinterpret_cast(arg), identity); - if (!pb_decode(stream, grpc_gcp_Identity_fields, identity)) return false; - return true; -} - -bool decode_repeated_string_cb(pb_istream_t* stream, const pb_field_t* field, - void** arg) { - grpc_slice slice = grpc_slice_malloc(stream->bytes_left); - grpc_slice* cb_slice = - static_cast(gpr_zalloc(sizeof(*cb_slice))); - memcpy(cb_slice, &slice, sizeof(grpc_slice)); - if (!pb_read(stream, GRPC_SLICE_START_PTR(*cb_slice), stream->bytes_left)) - return false; - add_repeated_field(reinterpret_cast(arg), cb_slice); - return true; -} diff --git a/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h b/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h deleted file mode 100644 index 8fe8f73f8b..0000000000 --- a/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h +++ /dev/null @@ -1,149 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_SERVICE_API_UTIL_H -#define GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_SERVICE_API_UTIL_H - -#include - -#include "third_party/nanopb/pb_decode.h" -#include "third_party/nanopb/pb_encode.h" - -#include -#include -#include -#include - -#include "src/core/tsi/alts/handshaker/handshaker.pb.h" - -/** - * An implementation of utility functions used to serialize/ - * de-serialize ALTS handshake requests/responses. All APIs in the header - * are thread-compatible. - */ - -/* Renaming of message/field structs generated by nanopb compiler. */ -typedef grpc_gcp_HandshakeProtocol grpc_gcp_handshake_protocol; -typedef grpc_gcp_NetworkProtocol grpc_gcp_network_protocol; -typedef grpc_gcp_Identity grpc_gcp_identity; -typedef grpc_gcp_NextHandshakeMessageReq grpc_gcp_next_handshake_message_req; -typedef grpc_gcp_ServerHandshakeParameters grpc_gcp_server_handshake_parameters; -typedef grpc_gcp_Endpoint grpc_gcp_endpoint; -typedef grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry - grpc_gcp_handshake_parameters_entry; -typedef grpc_gcp_StartClientHandshakeReq grpc_gcp_start_client_handshake_req; -typedef grpc_gcp_StartServerHandshakeReq grpc_gcp_start_server_handshake_req; -typedef grpc_gcp_HandshakerReq grpc_gcp_handshaker_req; -typedef grpc_gcp_HandshakerResult grpc_gcp_handshaker_result; -typedef grpc_gcp_HandshakerStatus grpc_gcp_handshaker_status; -typedef grpc_gcp_HandshakerResp grpc_gcp_handshaker_resp; - -typedef enum { - CLIENT_START_REQ = 0, /* StartClientHandshakeReq. */ - SERVER_START_REQ = 1, /* StartServerHandshakeReq. */ - NEXT_REQ = 2, /* NextHandshakeMessageReq. */ -} grpc_gcp_handshaker_req_type; - -/** - * A struct representing a repeated field. The struct is used to organize all - * instances of a specific repeated field into a linked list, which then will - * be used at encode/decode phase. For instance at the encode phase, the encode - * function will iterate through the list, encode each field, and then output - * the result to the stream. - */ -typedef struct repeated_field_ { - struct repeated_field_* next; - const void* data; -} repeated_field; - -/** - * This method adds a repeated field to the head of repeated field list. - * - * - head: a head of repeated field list. - * - field: a repeated field to be added to the list. - */ -void add_repeated_field(repeated_field** head, const void* field); - -/** - * This method destroys a repeated field list that consists of string type - * fields. - * - * - head: a head of repeated field list. - */ -void destroy_repeated_field_list_string(repeated_field* head); - -/** - * This method destroys a repeated field list that consists of - * grpc_gcp_identity type fields. - * - * - head: a head of repeated field list. - */ -void destroy_repeated_field_list_identity(repeated_field* head); - -/** - * This method creates a grpc_slice instance by copying a data buffer. It is - * similar to grpc_slice_from_copied_buffer() except that it returns an instance - * allocated from the heap. - * - * - data: a data buffer to be copied to grpc_slice instance. - * - size: size of data buffer. - */ -grpc_slice* create_slice(const char* data, size_t size); - -/* This method destroys a grpc_slice instance. */ -void destroy_slice(grpc_slice* slice); - -/** - * The following encode/decode functions will be assigned to encode/decode - * function pointers of pb_callback_t struct (defined in - * //third_party/nanopb/pb.h), that represent a repeated field with a dynamic - * length (e.g., a string type or repeated field). - */ - -/* This method is an encode callback function for a string or byte array. */ -bool encode_string_or_bytes_cb(pb_ostream_t* stream, const pb_field_t* field, - void* const* arg); - -/** - * This method is an encode callback function for a repeated grpc_gcp_identity - * field. - */ -bool encode_repeated_identity_cb(pb_ostream_t* stream, const pb_field_t* field, - void* const* arg); - -/* This method is an encode callback function for a repeated string field. */ -bool encode_repeated_string_cb(pb_ostream_t* stream, const pb_field_t* field, - void* const* arg); - -/** - * This method is a decode callback function for a string or byte array field. - */ -bool decode_string_or_bytes_cb(pb_istream_t* stream, const pb_field_t* field, - void** arg); -/** - * This method is a decode callback function for a repeated grpc_gcp_identity - * field. - */ -bool decode_repeated_identity_cb(pb_istream_t* stream, const pb_field_t* field, - void** arg); - -/* This method is a decode callback function for a repeated string field. */ -bool decode_repeated_string_cb(pb_istream_t* stream, const pb_field_t* field, - void** arg); - -#endif /* GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_SERVICE_API_UTIL_H */ diff --git a/src/core/tsi/alts/handshaker/alts_tsi_event.cc b/src/core/tsi/alts/handshaker/alts_tsi_event.cc deleted file mode 100644 index ec0bf12b95..0000000000 --- a/src/core/tsi/alts/handshaker/alts_tsi_event.cc +++ /dev/null @@ -1,73 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/tsi/alts/handshaker/alts_tsi_event.h" - -#include -#include -#include - -tsi_result alts_tsi_event_create(alts_tsi_handshaker* handshaker, - tsi_handshaker_on_next_done_cb cb, - void* user_data, - grpc_alts_credentials_options* options, - grpc_slice target_name, - alts_tsi_event** event) { - if (event == nullptr || handshaker == nullptr || cb == nullptr) { - gpr_log(GPR_ERROR, "Invalid arguments to alts_tsi_event_create()"); - return TSI_INVALID_ARGUMENT; - } - alts_tsi_event* e = static_cast(gpr_zalloc(sizeof(*e))); - e->handshaker = handshaker; - e->cb = cb; - e->user_data = user_data; - e->options = grpc_alts_credentials_options_copy(options); - e->target_name = grpc_slice_copy(target_name); - grpc_metadata_array_init(&e->initial_metadata); - grpc_metadata_array_init(&e->trailing_metadata); - *event = e; - return TSI_OK; -} - -void alts_tsi_event_dispatch_to_handshaker(alts_tsi_event* event, bool is_ok) { - if (event == nullptr) { - gpr_log( - GPR_ERROR, - "ALTS TSI event is nullptr in alts_tsi_event_dispatch_to_handshaker()"); - return; - } - alts_tsi_handshaker_handle_response(event->handshaker, event->recv_buffer, - event->status, &event->details, event->cb, - event->user_data, is_ok); -} - -void alts_tsi_event_destroy(alts_tsi_event* event) { - if (event == nullptr) { - return; - } - grpc_byte_buffer_destroy(event->send_buffer); - grpc_byte_buffer_destroy(event->recv_buffer); - grpc_metadata_array_destroy(&event->initial_metadata); - grpc_metadata_array_destroy(&event->trailing_metadata); - grpc_slice_unref(event->details); - grpc_slice_unref(event->target_name); - grpc_alts_credentials_options_destroy(event->options); - gpr_free(event); -} diff --git a/src/core/tsi/alts/handshaker/alts_tsi_event.h b/src/core/tsi/alts/handshaker/alts_tsi_event.h deleted file mode 100644 index 043e75d4a9..0000000000 --- a/src/core/tsi/alts/handshaker/alts_tsi_event.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_EVENT_H -#define GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_EVENT_H - -#include - -#include -#include - -#include "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h" -#include "src/core/tsi/transport_security_interface.h" - -/** - * A ALTS TSI event interface. In asynchronous implementation of - * tsi_handshaker_next(), the function will exit after scheduling a handshaker - * request to ALTS handshaker service without waiting for response to return. - * The event is used to link the scheduled handshaker request with the - * corresponding response so that enough context information can be inferred - * from it to handle the response. All APIs in the header are thread-compatible. - */ - -/** - * Main struct for ALTS TSI event. It retains ownership on send_buffer and - * recv_buffer, but not on handshaker. - */ -typedef struct alts_tsi_event { - alts_tsi_handshaker* handshaker; - grpc_byte_buffer* send_buffer; - grpc_byte_buffer* recv_buffer; - grpc_status_code status; - grpc_slice details; - grpc_metadata_array initial_metadata; - grpc_metadata_array trailing_metadata; - tsi_handshaker_on_next_done_cb cb; - void* user_data; - grpc_alts_credentials_options* options; - grpc_slice target_name; -} alts_tsi_event; - -/** - * This method creates a ALTS TSI event. - * - * - handshaker: ALTS TSI handshaker instance associated with the event to be - * created. The created event does not own the handshaker instance. - * - cb: callback function to be called when handling data received from ALTS - * handshaker service. - * - user_data: argument to callback function. - * - options: ALTS credentials options. - * - target_name: name of endpoint used for secure naming check. - * - event: address of ALTS TSI event instance to be returned from the method. - * - * It returns TSI_OK on success and an error status code on failure. - */ -tsi_result alts_tsi_event_create(alts_tsi_handshaker* handshaker, - tsi_handshaker_on_next_done_cb cb, - void* user_data, - grpc_alts_credentials_options* options, - grpc_slice target_name, - alts_tsi_event** event); - -/** - * This method dispatches a ALTS TSI event received from the handshaker service, - * and a boolean flag indicating if the event is valid to read to ALTS TSI - * handshaker to process. It is called by TSI thread. - * - * - event: ALTS TSI event instance. - * - is_ok: a boolean value indicating if the event is valid to read. - */ -void alts_tsi_event_dispatch_to_handshaker(alts_tsi_event* event, bool is_ok); - -/** - * This method destroys the ALTS TSI event. - */ -void alts_tsi_event_destroy(alts_tsi_event* event); - -#endif /* GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_EVENT_H */ diff --git a/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc b/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc deleted file mode 100644 index 529f2103c7..0000000000 --- a/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +++ /dev/null @@ -1,483 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h" - -#include -#include -#include - -#include -#include -#include -#include - -#include "src/core/lib/gpr/host_port.h" -#include "src/core/lib/gprpp/thd.h" -#include "src/core/tsi/alts/frame_protector/alts_frame_protector.h" -#include "src/core/tsi/alts/handshaker/alts_handshaker_client.h" -#include "src/core/tsi/alts/handshaker/alts_tsi_utils.h" -#include "src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h" -#include "src/core/tsi/alts_transport_security.h" - -#define TSI_ALTS_INITIAL_BUFFER_SIZE 256 - -static alts_shared_resource* kSharedResource = alts_get_shared_resource(); - -/* Main struct for ALTS TSI handshaker. */ -typedef struct alts_tsi_handshaker { - tsi_handshaker base; - alts_handshaker_client* client; - grpc_slice recv_bytes; - grpc_slice target_name; - unsigned char* buffer; - size_t buffer_size; - bool is_client; - bool has_sent_start_message; - grpc_alts_credentials_options* options; -} alts_tsi_handshaker; - -/* Main struct for ALTS TSI handshaker result. */ -typedef struct alts_tsi_handshaker_result { - tsi_handshaker_result base; - char* peer_identity; - char* key_data; - unsigned char* unused_bytes; - size_t unused_bytes_size; - grpc_slice rpc_versions; - bool is_client; -} alts_tsi_handshaker_result; - -static tsi_result handshaker_result_extract_peer( - const tsi_handshaker_result* self, tsi_peer* peer) { - if (self == nullptr || peer == nullptr) { - gpr_log(GPR_ERROR, "Invalid argument to handshaker_result_extract_peer()"); - return TSI_INVALID_ARGUMENT; - } - alts_tsi_handshaker_result* result = - reinterpret_cast( - const_cast(self)); - GPR_ASSERT(kTsiAltsNumOfPeerProperties == 3); - tsi_result ok = tsi_construct_peer(kTsiAltsNumOfPeerProperties, peer); - int index = 0; - if (ok != TSI_OK) { - gpr_log(GPR_ERROR, "Failed to construct tsi peer"); - return ok; - } - GPR_ASSERT(&peer->properties[index] != nullptr); - ok = tsi_construct_string_peer_property_from_cstring( - TSI_CERTIFICATE_TYPE_PEER_PROPERTY, TSI_ALTS_CERTIFICATE_TYPE, - &peer->properties[index]); - if (ok != TSI_OK) { - tsi_peer_destruct(peer); - gpr_log(GPR_ERROR, "Failed to set tsi peer property"); - return ok; - } - index++; - GPR_ASSERT(&peer->properties[index] != nullptr); - ok = tsi_construct_string_peer_property_from_cstring( - TSI_ALTS_SERVICE_ACCOUNT_PEER_PROPERTY, result->peer_identity, - &peer->properties[index]); - if (ok != TSI_OK) { - tsi_peer_destruct(peer); - gpr_log(GPR_ERROR, "Failed to set tsi peer property"); - } - index++; - GPR_ASSERT(&peer->properties[index] != nullptr); - ok = tsi_construct_string_peer_property( - TSI_ALTS_RPC_VERSIONS, - reinterpret_cast(GRPC_SLICE_START_PTR(result->rpc_versions)), - GRPC_SLICE_LENGTH(result->rpc_versions), &peer->properties[2]); - if (ok != TSI_OK) { - tsi_peer_destruct(peer); - gpr_log(GPR_ERROR, "Failed to set tsi peer property"); - } - GPR_ASSERT(++index == kTsiAltsNumOfPeerProperties); - return ok; -} - -static tsi_result handshaker_result_create_zero_copy_grpc_protector( - const tsi_handshaker_result* self, size_t* max_output_protected_frame_size, - tsi_zero_copy_grpc_protector** protector) { - if (self == nullptr || protector == nullptr) { - gpr_log(GPR_ERROR, - "Invalid arguments to create_zero_copy_grpc_protector()"); - return TSI_INVALID_ARGUMENT; - } - alts_tsi_handshaker_result* result = - reinterpret_cast( - const_cast(self)); - tsi_result ok = alts_zero_copy_grpc_protector_create( - reinterpret_cast(result->key_data), - kAltsAes128GcmRekeyKeyLength, /*is_rekey=*/true, result->is_client, - /*is_integrity_only=*/false, max_output_protected_frame_size, protector); - if (ok != TSI_OK) { - gpr_log(GPR_ERROR, "Failed to create zero-copy grpc protector"); - } - return ok; -} - -static tsi_result handshaker_result_create_frame_protector( - const tsi_handshaker_result* self, size_t* max_output_protected_frame_size, - tsi_frame_protector** protector) { - if (self == nullptr || protector == nullptr) { - gpr_log(GPR_ERROR, - "Invalid arguments to handshaker_result_create_frame_protector()"); - return TSI_INVALID_ARGUMENT; - } - alts_tsi_handshaker_result* result = - reinterpret_cast( - const_cast(self)); - tsi_result ok = alts_create_frame_protector( - reinterpret_cast(result->key_data), - kAltsAes128GcmRekeyKeyLength, result->is_client, /*is_rekey=*/true, - max_output_protected_frame_size, protector); - if (ok != TSI_OK) { - gpr_log(GPR_ERROR, "Failed to create frame protector"); - } - return ok; -} - -static tsi_result handshaker_result_get_unused_bytes( - const tsi_handshaker_result* self, const unsigned char** bytes, - size_t* bytes_size) { - if (self == nullptr || bytes == nullptr || bytes_size == nullptr) { - gpr_log(GPR_ERROR, - "Invalid arguments to handshaker_result_get_unused_bytes()"); - return TSI_INVALID_ARGUMENT; - } - alts_tsi_handshaker_result* result = - reinterpret_cast( - const_cast(self)); - *bytes = result->unused_bytes; - *bytes_size = result->unused_bytes_size; - return TSI_OK; -} - -static void handshaker_result_destroy(tsi_handshaker_result* self) { - if (self == nullptr) { - return; - } - alts_tsi_handshaker_result* result = - reinterpret_cast( - const_cast(self)); - gpr_free(result->peer_identity); - gpr_free(result->key_data); - gpr_free(result->unused_bytes); - grpc_slice_unref(result->rpc_versions); - gpr_free(result); -} - -static const tsi_handshaker_result_vtable result_vtable = { - handshaker_result_extract_peer, - handshaker_result_create_zero_copy_grpc_protector, - handshaker_result_create_frame_protector, - handshaker_result_get_unused_bytes, handshaker_result_destroy}; - -static tsi_result create_handshaker_result(grpc_gcp_handshaker_resp* resp, - bool is_client, - tsi_handshaker_result** self) { - if (self == nullptr || resp == nullptr) { - gpr_log(GPR_ERROR, "Invalid arguments to create_handshaker_result()"); - return TSI_INVALID_ARGUMENT; - } - grpc_slice* key = static_cast(resp->result.key_data.arg); - GPR_ASSERT(key != nullptr); - grpc_slice* identity = - static_cast(resp->result.peer_identity.service_account.arg); - if (identity == nullptr) { - gpr_log(GPR_ERROR, "Invalid service account"); - return TSI_FAILED_PRECONDITION; - } - if (GRPC_SLICE_LENGTH(*key) < kAltsAes128GcmRekeyKeyLength) { - gpr_log(GPR_ERROR, "Bad key length"); - return TSI_FAILED_PRECONDITION; - } - alts_tsi_handshaker_result* result = - static_cast(gpr_zalloc(sizeof(*result))); - result->key_data = - static_cast(gpr_zalloc(kAltsAes128GcmRekeyKeyLength)); - memcpy(result->key_data, GRPC_SLICE_START_PTR(*key), - kAltsAes128GcmRekeyKeyLength); - result->peer_identity = grpc_slice_to_c_string(*identity); - if (!resp->result.has_peer_rpc_versions) { - gpr_log(GPR_ERROR, "Peer does not set RPC protocol versions."); - return TSI_FAILED_PRECONDITION; - } - if (!grpc_gcp_rpc_protocol_versions_encode(&resp->result.peer_rpc_versions, - &result->rpc_versions)) { - gpr_log(GPR_ERROR, "Failed to serialize peer's RPC protocol versions."); - return TSI_FAILED_PRECONDITION; - } - result->is_client = is_client; - result->base.vtable = &result_vtable; - *self = &result->base; - return TSI_OK; -} - -static tsi_result handshaker_next( - tsi_handshaker* self, const unsigned char* received_bytes, - size_t received_bytes_size, const unsigned char** bytes_to_send, - size_t* bytes_to_send_size, tsi_handshaker_result** result, - tsi_handshaker_on_next_done_cb cb, void* user_data) { - if (self == nullptr || cb == nullptr) { - gpr_log(GPR_ERROR, "Invalid arguments to handshaker_next()"); - return TSI_INVALID_ARGUMENT; - } - alts_tsi_handshaker* handshaker = - reinterpret_cast(self); - tsi_result ok = TSI_OK; - alts_tsi_event* event = nullptr; - ok = alts_tsi_event_create(handshaker, cb, user_data, handshaker->options, - handshaker->target_name, &event); - if (ok != TSI_OK) { - gpr_log(GPR_ERROR, "Failed to create ALTS TSI event"); - return ok; - } - grpc_slice slice = (received_bytes == nullptr || received_bytes_size == 0) - ? grpc_empty_slice() - : grpc_slice_from_copied_buffer( - reinterpret_cast(received_bytes), - received_bytes_size); - if (!handshaker->has_sent_start_message) { - ok = handshaker->is_client - ? alts_handshaker_client_start_client(handshaker->client, event) - : alts_handshaker_client_start_server(handshaker->client, event, - &slice); - handshaker->has_sent_start_message = true; - } else { - if (!GRPC_SLICE_IS_EMPTY(handshaker->recv_bytes)) { - grpc_slice_unref(handshaker->recv_bytes); - } - handshaker->recv_bytes = grpc_slice_ref(slice); - ok = alts_handshaker_client_next(handshaker->client, event, &slice); - } - grpc_slice_unref(slice); - if (ok != TSI_OK) { - gpr_log(GPR_ERROR, "Failed to schedule ALTS handshaker requests"); - return ok; - } - return TSI_ASYNC; -} - -static void handshaker_destroy(tsi_handshaker* self) { - if (self == nullptr) { - return; - } - alts_tsi_handshaker* handshaker = - reinterpret_cast(self); - alts_handshaker_client_destroy(handshaker->client); - grpc_slice_unref(handshaker->recv_bytes); - grpc_slice_unref(handshaker->target_name); - grpc_alts_credentials_options_destroy(handshaker->options); - gpr_free(handshaker->buffer); - gpr_free(handshaker); -} - -static const tsi_handshaker_vtable handshaker_vtable = { - nullptr, nullptr, nullptr, nullptr, nullptr, handshaker_destroy, - handshaker_next}; - -static void thread_worker(void* arg) { - while (true) { - grpc_event event = grpc_completion_queue_next( - kSharedResource->cq, gpr_inf_future(GPR_CLOCK_REALTIME), nullptr); - GPR_ASSERT(event.type != GRPC_QUEUE_TIMEOUT); - if (event.type == GRPC_QUEUE_SHUTDOWN) { - /* signal alts_tsi_shutdown() to destroy completion queue. */ - grpc_tsi_alts_signal_for_cq_destroy(); - break; - } - /* event.type == GRPC_OP_COMPLETE. */ - alts_tsi_event* alts_event = static_cast(event.tag); - alts_tsi_event_dispatch_to_handshaker(alts_event, event.success); - alts_tsi_event_destroy(alts_event); - } -} - -static void init_shared_resources(const char* handshaker_service_url) { - GPR_ASSERT(handshaker_service_url != nullptr); - gpr_mu_lock(&kSharedResource->mu); - if (kSharedResource->channel == nullptr) { - gpr_cv_init(&kSharedResource->cv); - kSharedResource->channel = - grpc_insecure_channel_create(handshaker_service_url, nullptr, nullptr); - kSharedResource->cq = grpc_completion_queue_create_for_next(nullptr); - kSharedResource->thread = - grpc_core::Thread("alts_tsi_handshaker", &thread_worker, nullptr); - kSharedResource->thread.Start(); - } - gpr_mu_unlock(&kSharedResource->mu); -} - -tsi_result alts_tsi_handshaker_create( - const grpc_alts_credentials_options* options, const char* target_name, - const char* handshaker_service_url, bool is_client, tsi_handshaker** self) { - if (handshaker_service_url == nullptr || self == nullptr || - options == nullptr || (is_client && target_name == nullptr)) { - gpr_log(GPR_ERROR, "Invalid arguments to alts_tsi_handshaker_create()"); - return TSI_INVALID_ARGUMENT; - } - init_shared_resources(handshaker_service_url); - alts_handshaker_client* client = alts_grpc_handshaker_client_create( - kSharedResource->channel, kSharedResource->cq, handshaker_service_url); - if (client == nullptr) { - gpr_log(GPR_ERROR, "Failed to create ALTS handshaker client"); - return TSI_FAILED_PRECONDITION; - } - alts_tsi_handshaker* handshaker = - static_cast(gpr_zalloc(sizeof(*handshaker))); - handshaker->client = client; - handshaker->buffer_size = TSI_ALTS_INITIAL_BUFFER_SIZE; - handshaker->buffer = - static_cast(gpr_zalloc(handshaker->buffer_size)); - handshaker->is_client = is_client; - handshaker->has_sent_start_message = false; - handshaker->target_name = target_name == nullptr - ? grpc_empty_slice() - : grpc_slice_from_static_string(target_name); - handshaker->options = grpc_alts_credentials_options_copy(options); - handshaker->base.vtable = &handshaker_vtable; - *self = &handshaker->base; - return TSI_OK; -} - -static bool is_handshake_finished_properly(grpc_gcp_handshaker_resp* resp) { - GPR_ASSERT(resp != nullptr); - if (resp->has_result) { - return true; - } - return false; -} - -static void set_unused_bytes(tsi_handshaker_result* self, - grpc_slice* recv_bytes, size_t bytes_consumed) { - GPR_ASSERT(recv_bytes != nullptr && self != nullptr); - if (GRPC_SLICE_LENGTH(*recv_bytes) == bytes_consumed) { - return; - } - alts_tsi_handshaker_result* result = - reinterpret_cast(self); - result->unused_bytes_size = GRPC_SLICE_LENGTH(*recv_bytes) - bytes_consumed; - result->unused_bytes = - static_cast(gpr_zalloc(result->unused_bytes_size)); - memcpy(result->unused_bytes, - GRPC_SLICE_START_PTR(*recv_bytes) + bytes_consumed, - result->unused_bytes_size); -} - -void alts_tsi_handshaker_handle_response(alts_tsi_handshaker* handshaker, - grpc_byte_buffer* recv_buffer, - grpc_status_code status, - grpc_slice* details, - tsi_handshaker_on_next_done_cb cb, - void* user_data, bool is_ok) { - /* Invalid input check. */ - if (cb == nullptr) { - gpr_log(GPR_ERROR, - "cb is nullptr in alts_tsi_handshaker_handle_response()"); - return; - } - if (handshaker == nullptr || recv_buffer == nullptr) { - gpr_log(GPR_ERROR, - "Invalid arguments to alts_tsi_handshaker_handle_response()"); - cb(TSI_INTERNAL_ERROR, user_data, nullptr, 0, nullptr); - return; - } - /* Failed grpc call check. */ - if (!is_ok || status != GRPC_STATUS_OK) { - gpr_log(GPR_ERROR, "grpc call made to handshaker service failed"); - if (details != nullptr) { - char* error_details = grpc_slice_to_c_string(*details); - gpr_log(GPR_ERROR, "error details:%s", error_details); - gpr_free(error_details); - } - cb(TSI_INTERNAL_ERROR, user_data, nullptr, 0, nullptr); - return; - } - grpc_gcp_handshaker_resp* resp = - alts_tsi_utils_deserialize_response(recv_buffer); - /* Invalid handshaker response check. */ - if (resp == nullptr) { - gpr_log(GPR_ERROR, "alts_tsi_utils_deserialize_response() failed"); - cb(TSI_DATA_CORRUPTED, user_data, nullptr, 0, nullptr); - return; - } - grpc_slice* slice = static_cast(resp->out_frames.arg); - unsigned char* bytes_to_send = nullptr; - size_t bytes_to_send_size = 0; - if (slice != nullptr) { - bytes_to_send_size = GRPC_SLICE_LENGTH(*slice); - while (bytes_to_send_size > handshaker->buffer_size) { - handshaker->buffer_size *= 2; - handshaker->buffer = static_cast( - gpr_realloc(handshaker->buffer, handshaker->buffer_size)); - } - memcpy(handshaker->buffer, GRPC_SLICE_START_PTR(*slice), - bytes_to_send_size); - bytes_to_send = handshaker->buffer; - } - tsi_handshaker_result* result = nullptr; - if (is_handshake_finished_properly(resp)) { - create_handshaker_result(resp, handshaker->is_client, &result); - set_unused_bytes(result, &handshaker->recv_bytes, resp->bytes_consumed); - } - grpc_status_code code = static_cast(resp->status.code); - grpc_gcp_handshaker_resp_destroy(resp); - cb(alts_tsi_utils_convert_to_tsi_result(code), user_data, bytes_to_send, - bytes_to_send_size, result); -} - -namespace grpc_core { -namespace internal { - -bool alts_tsi_handshaker_get_has_sent_start_message_for_testing( - alts_tsi_handshaker* handshaker) { - GPR_ASSERT(handshaker != nullptr); - return handshaker->has_sent_start_message; -} - -bool alts_tsi_handshaker_get_is_client_for_testing( - alts_tsi_handshaker* handshaker) { - GPR_ASSERT(handshaker != nullptr); - return handshaker->is_client; -} - -void alts_tsi_handshaker_set_recv_bytes_for_testing( - alts_tsi_handshaker* handshaker, grpc_slice* slice) { - GPR_ASSERT(handshaker != nullptr && slice != nullptr); - handshaker->recv_bytes = grpc_slice_ref(*slice); -} - -grpc_slice alts_tsi_handshaker_get_recv_bytes_for_testing( - alts_tsi_handshaker* handshaker) { - GPR_ASSERT(handshaker != nullptr); - return handshaker->recv_bytes; -} - -void alts_tsi_handshaker_set_client_for_testing( - alts_tsi_handshaker* handshaker, alts_handshaker_client* client) { - GPR_ASSERT(handshaker != nullptr && client != nullptr); - alts_handshaker_client_destroy(handshaker->client); - handshaker->client = client; -} - -} // namespace internal -} // namespace grpc_core diff --git a/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h b/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h deleted file mode 100644 index 227b30ce53..0000000000 --- a/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_HANDSHAKER_H -#define GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_HANDSHAKER_H - -#include - -#include - -#include "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h" -#include "src/core/tsi/alts_transport_security.h" -#include "src/core/tsi/transport_security.h" -#include "src/core/tsi/transport_security_interface.h" - -#define TSI_ALTS_SERVICE_ACCOUNT_PEER_PROPERTY "service_accont" -#define TSI_ALTS_CERTIFICATE_TYPE "ALTS" -#define TSI_ALTS_RPC_VERSIONS "rpc_versions" - -const size_t kTsiAltsNumOfPeerProperties = 3; - -/** - * Main struct for ALTS TSI handshaker. All APIs in the header are - * thread-comptabile. - */ -typedef struct alts_tsi_handshaker alts_tsi_handshaker; - -/** - * This method creates a ALTS TSI handshaker instance. - * - * - options: ALTS credentials options containing information passed from TSI - * caller (e.g., rpc protocol versions). - * - target_name: the name of the endpoint that the channel is connecting to, - * and will be used for secure naming check. - * - handshaker_service_url: address of ALTS handshaker service in the format of - * "host:port". - * - is_client: boolean value indicating if the handshaker is used at the client - * (is_client = true) or server (is_client = false) side. - * - self: address of ALTS TSI handshaker instance to be returned from the - * method. - * - * It returns TSI_OK on success and an error status code on failure. - */ -tsi_result alts_tsi_handshaker_create( - const grpc_alts_credentials_options* options, const char* target_name, - const char* handshaker_service_url, bool is_client, tsi_handshaker** self); - -/** - * This method handles handshaker response returned from ALTS handshaker - * service. - * - * - handshaker: ALTS TSI handshaker instance. - * - recv_buffer: buffer holding data received from the handshaker service. - * - status: status of the grpc call made to the handshaker service. - * - details: error details of the grpc call made to the handshaker service. - * - cb: callback function of ALTS TSI event. - * - user_data: argument of callback function. - * - is_ok: a boolean value indicating if the handshaker response is ok to read. - * - */ -void alts_tsi_handshaker_handle_response(alts_tsi_handshaker* handshaker, - grpc_byte_buffer* recv_buffer, - grpc_status_code status, - grpc_slice* details, - tsi_handshaker_on_next_done_cb cb, - void* user_data, bool is_ok); - -#endif /* GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_HANDSHAKER_H */ diff --git a/src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h b/src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h deleted file mode 100644 index 9b7b9bb6b1..0000000000 --- a/src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_HANDSHAKER_PRIVATE_H -#define GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_HANDSHAKER_PRIVATE_H - -#include - -#include "src/core/tsi/alts/handshaker/alts_handshaker_client.h" - -namespace grpc_core { -namespace internal { - -/** - * Unsafe, use for testing only. It allows the caller to change the way the - * ALTS TSI handshaker schedules handshaker requests. - */ -void alts_tsi_handshaker_set_client_for_testing(alts_tsi_handshaker* handshaker, - alts_handshaker_client* client); - -/* For testing only. */ -bool alts_tsi_handshaker_get_has_sent_start_message_for_testing( - alts_tsi_handshaker* handshaker); - -bool alts_tsi_handshaker_get_is_client_for_testing( - alts_tsi_handshaker* handshaker); - -void alts_tsi_handshaker_set_recv_bytes_for_testing( - alts_tsi_handshaker* handshaker, grpc_slice* slice); - -grpc_slice alts_tsi_handshaker_get_recv_bytes_for_testing( - alts_tsi_handshaker* handshaker); - -} // namespace internal -} // namespace grpc_core - -#endif /* GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_HANDSHAKER_PRIVATE_H */ diff --git a/src/core/tsi/alts/handshaker/alts_tsi_utils.cc b/src/core/tsi/alts/handshaker/alts_tsi_utils.cc deleted file mode 100644 index d9b5e6c945..0000000000 --- a/src/core/tsi/alts/handshaker/alts_tsi_utils.cc +++ /dev/null @@ -1,58 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/tsi/alts/handshaker/alts_tsi_utils.h" - -#include - -tsi_result alts_tsi_utils_convert_to_tsi_result(grpc_status_code code) { - switch (code) { - case GRPC_STATUS_OK: - return TSI_OK; - case GRPC_STATUS_UNKNOWN: - return TSI_UNKNOWN_ERROR; - case GRPC_STATUS_INVALID_ARGUMENT: - return TSI_INVALID_ARGUMENT; - case GRPC_STATUS_NOT_FOUND: - return TSI_NOT_FOUND; - case GRPC_STATUS_INTERNAL: - return TSI_INTERNAL_ERROR; - default: - return TSI_UNKNOWN_ERROR; - } -} - -grpc_gcp_handshaker_resp* alts_tsi_utils_deserialize_response( - grpc_byte_buffer* resp_buffer) { - GPR_ASSERT(resp_buffer != nullptr); - grpc_byte_buffer_reader bbr; - grpc_byte_buffer_reader_init(&bbr, resp_buffer); - grpc_slice slice = grpc_byte_buffer_reader_readall(&bbr); - grpc_gcp_handshaker_resp* resp = grpc_gcp_handshaker_resp_create(); - bool ok = grpc_gcp_handshaker_resp_decode(slice, resp); - grpc_slice_unref(slice); - grpc_byte_buffer_reader_destroy(&bbr); - if (!ok) { - grpc_gcp_handshaker_resp_destroy(resp); - gpr_log(GPR_ERROR, "grpc_gcp_handshaker_resp_decode() failed"); - return nullptr; - } - return resp; -} diff --git a/src/core/tsi/alts/handshaker/alts_tsi_utils.h b/src/core/tsi/alts/handshaker/alts_tsi_utils.h deleted file mode 100644 index 9ef649de2b..0000000000 --- a/src/core/tsi/alts/handshaker/alts_tsi_utils.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_UTILS_H -#define GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_UTILS_H - -#include - -#include -#include - -#include "src/core/tsi/alts/handshaker/alts_handshaker_service_api.h" -#include "src/core/tsi/transport_security_interface.h" - -/** - * This method converts grpc_status_code code to the corresponding tsi_result - * code. - * - * - code: grpc_status_code code. - * - * It returns the converted tsi_result code. - */ -tsi_result alts_tsi_utils_convert_to_tsi_result(grpc_status_code code); - -/** - * This method deserializes a handshaker response returned from ALTS handshaker - * service. - * - * - bytes_received: data returned from ALTS handshaker service. - * - * It returns a deserialized handshaker response on success and nullptr on - * failure. - */ -grpc_gcp_handshaker_resp* alts_tsi_utils_deserialize_response( - grpc_byte_buffer* resp_buffer); - -#endif /* GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_UTILS_H */ diff --git a/src/core/tsi/alts/handshaker/altscontext.pb.c b/src/core/tsi/alts/handshaker/altscontext.pb.c deleted file mode 100644 index 81a82f5992..0000000000 --- a/src/core/tsi/alts/handshaker/altscontext.pb.c +++ /dev/null @@ -1,48 +0,0 @@ -/* Automatically generated nanopb constant definitions */ -/* Generated by nanopb-0.3.7-dev */ - -#include "src/core/tsi/alts/handshaker/altscontext.pb.h" - -/* @@protoc_insertion_point(includes) */ -#if PB_PROTO_HEADER_VERSION != 30 -#error Regenerate this file with the current version of nanopb generator. -#endif - - - -const pb_field_t grpc_gcp_AltsContext_fields[7] = { - PB_FIELD( 1, STRING , OPTIONAL, CALLBACK, FIRST, grpc_gcp_AltsContext, application_protocol, application_protocol, 0), - PB_FIELD( 2, STRING , OPTIONAL, CALLBACK, OTHER, grpc_gcp_AltsContext, record_protocol, application_protocol, 0), - PB_FIELD( 3, UENUM , OPTIONAL, STATIC , OTHER, grpc_gcp_AltsContext, security_level, record_protocol, 0), - PB_FIELD( 4, STRING , OPTIONAL, CALLBACK, OTHER, grpc_gcp_AltsContext, peer_service_account, security_level, 0), - PB_FIELD( 5, STRING , OPTIONAL, CALLBACK, OTHER, grpc_gcp_AltsContext, local_service_account, peer_service_account, 0), - PB_FIELD( 6, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_AltsContext, peer_rpc_versions, local_service_account, &grpc_gcp_RpcProtocolVersions_fields), - PB_LAST_FIELD -}; - - -/* Check that field information fits in pb_field_t */ -#if !defined(PB_FIELD_32BIT) -/* If you get an error here, it means that you need to define PB_FIELD_32BIT - * compile-time option. You can do that in pb.h or on compiler command line. - * - * The reason you need to do this is that some of your messages contain tag - * numbers or field sizes that are larger than what can fit in 8 or 16 bit - * field descriptors. - */ -PB_STATIC_ASSERT((pb_membersize(grpc_gcp_AltsContext, peer_rpc_versions) < 65536), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_grpc_gcp_AltsContext) -#endif - -#if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT) -/* If you get an error here, it means that you need to define PB_FIELD_16BIT - * compile-time option. You can do that in pb.h or on compiler command line. - * - * The reason you need to do this is that some of your messages contain tag - * numbers or field sizes that are larger than what can fit in the default - * 8 bit descriptors. - */ -PB_STATIC_ASSERT((pb_membersize(grpc_gcp_AltsContext, peer_rpc_versions) < 256), YOU_MUST_DEFINE_PB_FIELD_16BIT_FOR_MESSAGES_grpc_gcp_AltsContext) -#endif - - -/* @@protoc_insertion_point(eof) */ diff --git a/src/core/tsi/alts/handshaker/altscontext.pb.h b/src/core/tsi/alts/handshaker/altscontext.pb.h deleted file mode 100644 index 3e72d7f678..0000000000 --- a/src/core/tsi/alts/handshaker/altscontext.pb.h +++ /dev/null @@ -1,64 +0,0 @@ -/* Automatically generated nanopb header */ -/* Generated by nanopb-0.3.7-dev */ - -#ifndef PB_GRPC_GCP_ALTSCONTEXT_PB_H_INCLUDED -#define PB_GRPC_GCP_ALTSCONTEXT_PB_H_INCLUDED -#include "third_party/nanopb/pb.h" -#include "src/core/tsi/alts/handshaker/transport_security_common.pb.h" - -/* @@protoc_insertion_point(includes) */ -#if PB_PROTO_HEADER_VERSION != 30 -#error Regenerate this file with the current version of nanopb generator. -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* Struct definitions */ -typedef struct _grpc_gcp_AltsContext { - pb_callback_t application_protocol; - pb_callback_t record_protocol; - bool has_security_level; - grpc_gcp_SecurityLevel security_level; - pb_callback_t peer_service_account; - pb_callback_t local_service_account; - bool has_peer_rpc_versions; - grpc_gcp_RpcProtocolVersions peer_rpc_versions; -/* @@protoc_insertion_point(struct:grpc_gcp_AltsContext) */ -} grpc_gcp_AltsContext; - -/* Default values for struct fields */ - -/* Initializer values for message structs */ -#define grpc_gcp_AltsContext_init_default {{{NULL}, NULL}, {{NULL}, NULL}, false, (grpc_gcp_SecurityLevel)0, {{NULL}, NULL}, {{NULL}, NULL}, false, grpc_gcp_RpcProtocolVersions_init_default} -#define grpc_gcp_AltsContext_init_zero {{{NULL}, NULL}, {{NULL}, NULL}, false, (grpc_gcp_SecurityLevel)0, {{NULL}, NULL}, {{NULL}, NULL}, false, grpc_gcp_RpcProtocolVersions_init_zero} - -/* Field tags (for use in manual encoding/decoding) */ -#define grpc_gcp_AltsContext_application_protocol_tag 1 -#define grpc_gcp_AltsContext_record_protocol_tag 2 -#define grpc_gcp_AltsContext_security_level_tag 3 -#define grpc_gcp_AltsContext_peer_service_account_tag 4 -#define grpc_gcp_AltsContext_local_service_account_tag 5 -#define grpc_gcp_AltsContext_peer_rpc_versions_tag 6 - -/* Struct field encoding specification for nanopb */ -extern const pb_field_t grpc_gcp_AltsContext_fields[7]; - -/* Maximum encoded size of messages (where known) */ -/* grpc_gcp_AltsContext_size depends on runtime parameters */ - -/* Message IDs (where set with "msgid" option) */ -#ifdef PB_MSGID - -#define ALTSCONTEXT_MESSAGES \ - - -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif -/* @@protoc_insertion_point(eof) */ - -#endif diff --git a/src/core/tsi/alts/handshaker/handshaker.pb.c b/src/core/tsi/alts/handshaker/handshaker.pb.c deleted file mode 100644 index bd992dfa4a..0000000000 --- a/src/core/tsi/alts/handshaker/handshaker.pb.c +++ /dev/null @@ -1,123 +0,0 @@ -/* Automatically generated nanopb constant definitions */ -/* Generated by nanopb-0.3.7-dev */ - -#include "src/core/tsi/alts/handshaker/handshaker.pb.h" - -/* @@protoc_insertion_point(includes) */ -#if PB_PROTO_HEADER_VERSION != 30 -#error Regenerate this file with the current version of nanopb generator. -#endif - - - -const pb_field_t grpc_gcp_Endpoint_fields[4] = { - PB_FIELD( 1, STRING , OPTIONAL, CALLBACK, FIRST, grpc_gcp_Endpoint, ip_address, ip_address, 0), - PB_FIELD( 2, INT32 , OPTIONAL, STATIC , OTHER, grpc_gcp_Endpoint, port, ip_address, 0), - PB_FIELD( 3, UENUM , OPTIONAL, STATIC , OTHER, grpc_gcp_Endpoint, protocol, port, 0), - PB_LAST_FIELD -}; - -const pb_field_t grpc_gcp_Identity_fields[3] = { - PB_FIELD( 1, STRING , OPTIONAL, CALLBACK, FIRST, grpc_gcp_Identity, service_account, service_account, 0), - PB_FIELD( 2, STRING , OPTIONAL, CALLBACK, OTHER, grpc_gcp_Identity, hostname, service_account, 0), - PB_LAST_FIELD -}; - -const pb_field_t grpc_gcp_StartClientHandshakeReq_fields[10] = { - PB_FIELD( 1, UENUM , OPTIONAL, STATIC , FIRST, grpc_gcp_StartClientHandshakeReq, handshake_security_protocol, handshake_security_protocol, 0), - PB_FIELD( 2, STRING , REPEATED, CALLBACK, OTHER, grpc_gcp_StartClientHandshakeReq, application_protocols, handshake_security_protocol, 0), - PB_FIELD( 3, STRING , REPEATED, CALLBACK, OTHER, grpc_gcp_StartClientHandshakeReq, record_protocols, application_protocols, 0), - PB_FIELD( 4, MESSAGE , REPEATED, CALLBACK, OTHER, grpc_gcp_StartClientHandshakeReq, target_identities, record_protocols, &grpc_gcp_Identity_fields), - PB_FIELD( 5, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_StartClientHandshakeReq, local_identity, target_identities, &grpc_gcp_Identity_fields), - PB_FIELD( 6, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_StartClientHandshakeReq, local_endpoint, local_identity, &grpc_gcp_Endpoint_fields), - PB_FIELD( 7, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_StartClientHandshakeReq, remote_endpoint, local_endpoint, &grpc_gcp_Endpoint_fields), - PB_FIELD( 8, STRING , OPTIONAL, CALLBACK, OTHER, grpc_gcp_StartClientHandshakeReq, target_name, remote_endpoint, 0), - PB_FIELD( 9, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_StartClientHandshakeReq, rpc_versions, target_name, &grpc_gcp_RpcProtocolVersions_fields), - PB_LAST_FIELD -}; - -const pb_field_t grpc_gcp_ServerHandshakeParameters_fields[3] = { - PB_FIELD( 1, STRING , REPEATED, CALLBACK, FIRST, grpc_gcp_ServerHandshakeParameters, record_protocols, record_protocols, 0), - PB_FIELD( 2, MESSAGE , REPEATED, CALLBACK, OTHER, grpc_gcp_ServerHandshakeParameters, local_identities, record_protocols, &grpc_gcp_Identity_fields), - PB_LAST_FIELD -}; - -const pb_field_t grpc_gcp_StartServerHandshakeReq_fields[7] = { - PB_FIELD( 1, STRING , REPEATED, CALLBACK, FIRST, grpc_gcp_StartServerHandshakeReq, application_protocols, application_protocols, 0), - PB_FIELD( 2, MESSAGE , REPEATED, STATIC , OTHER, grpc_gcp_StartServerHandshakeReq, handshake_parameters, application_protocols, &grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_fields), - PB_FIELD( 3, BYTES , OPTIONAL, CALLBACK, OTHER, grpc_gcp_StartServerHandshakeReq, in_bytes, handshake_parameters, 0), - PB_FIELD( 4, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_StartServerHandshakeReq, local_endpoint, in_bytes, &grpc_gcp_Endpoint_fields), - PB_FIELD( 5, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_StartServerHandshakeReq, remote_endpoint, local_endpoint, &grpc_gcp_Endpoint_fields), - PB_FIELD( 6, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_StartServerHandshakeReq, rpc_versions, remote_endpoint, &grpc_gcp_RpcProtocolVersions_fields), - PB_LAST_FIELD -}; - -const pb_field_t grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_fields[3] = { - PB_FIELD( 1, INT32 , OPTIONAL, STATIC , FIRST, grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry, key, key, 0), - PB_FIELD( 2, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry, value, key, &grpc_gcp_ServerHandshakeParameters_fields), - PB_LAST_FIELD -}; - -const pb_field_t grpc_gcp_NextHandshakeMessageReq_fields[2] = { - PB_FIELD( 1, BYTES , OPTIONAL, CALLBACK, FIRST, grpc_gcp_NextHandshakeMessageReq, in_bytes, in_bytes, 0), - PB_LAST_FIELD -}; - -const pb_field_t grpc_gcp_HandshakerReq_fields[4] = { - PB_FIELD( 1, MESSAGE , OPTIONAL, STATIC , FIRST, grpc_gcp_HandshakerReq, client_start, client_start, &grpc_gcp_StartClientHandshakeReq_fields), - PB_FIELD( 2, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_HandshakerReq, server_start, client_start, &grpc_gcp_StartServerHandshakeReq_fields), - PB_FIELD( 3, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_HandshakerReq, next, server_start, &grpc_gcp_NextHandshakeMessageReq_fields), - PB_LAST_FIELD -}; - -const pb_field_t grpc_gcp_HandshakerResult_fields[8] = { - PB_FIELD( 1, STRING , OPTIONAL, CALLBACK, FIRST, grpc_gcp_HandshakerResult, application_protocol, application_protocol, 0), - PB_FIELD( 2, STRING , OPTIONAL, CALLBACK, OTHER, grpc_gcp_HandshakerResult, record_protocol, application_protocol, 0), - PB_FIELD( 3, BYTES , OPTIONAL, CALLBACK, OTHER, grpc_gcp_HandshakerResult, key_data, record_protocol, 0), - PB_FIELD( 4, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_HandshakerResult, peer_identity, key_data, &grpc_gcp_Identity_fields), - PB_FIELD( 5, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_HandshakerResult, local_identity, peer_identity, &grpc_gcp_Identity_fields), - PB_FIELD( 6, BOOL , OPTIONAL, STATIC , OTHER, grpc_gcp_HandshakerResult, keep_channel_open, local_identity, 0), - PB_FIELD( 7, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_HandshakerResult, peer_rpc_versions, keep_channel_open, &grpc_gcp_RpcProtocolVersions_fields), - PB_LAST_FIELD -}; - -const pb_field_t grpc_gcp_HandshakerStatus_fields[3] = { - PB_FIELD( 1, UINT32 , OPTIONAL, STATIC , FIRST, grpc_gcp_HandshakerStatus, code, code, 0), - PB_FIELD( 2, STRING , OPTIONAL, CALLBACK, OTHER, grpc_gcp_HandshakerStatus, details, code, 0), - PB_LAST_FIELD -}; - -const pb_field_t grpc_gcp_HandshakerResp_fields[5] = { - PB_FIELD( 1, BYTES , OPTIONAL, CALLBACK, FIRST, grpc_gcp_HandshakerResp, out_frames, out_frames, 0), - PB_FIELD( 2, UINT32 , OPTIONAL, STATIC , OTHER, grpc_gcp_HandshakerResp, bytes_consumed, out_frames, 0), - PB_FIELD( 3, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_HandshakerResp, result, bytes_consumed, &grpc_gcp_HandshakerResult_fields), - PB_FIELD( 4, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_HandshakerResp, status, result, &grpc_gcp_HandshakerStatus_fields), - PB_LAST_FIELD -}; - - -/* Check that field information fits in pb_field_t */ -#if !defined(PB_FIELD_32BIT) -/* If you get an error here, it means that you need to define PB_FIELD_32BIT - * compile-time option. You can do that in pb.h or on compiler command line. - * - * The reason you need to do this is that some of your messages contain tag - * numbers or field sizes that are larger than what can fit in 8 or 16 bit - * field descriptors. - */ -PB_STATIC_ASSERT((pb_membersize(grpc_gcp_StartClientHandshakeReq, target_identities) < 65536 && pb_membersize(grpc_gcp_StartClientHandshakeReq, local_identity) < 65536 && pb_membersize(grpc_gcp_StartClientHandshakeReq, local_endpoint) < 65536 && pb_membersize(grpc_gcp_StartClientHandshakeReq, remote_endpoint) < 65536 && pb_membersize(grpc_gcp_StartClientHandshakeReq, rpc_versions) < 65536 && pb_membersize(grpc_gcp_ServerHandshakeParameters, local_identities) < 65536 && pb_membersize(grpc_gcp_StartServerHandshakeReq, handshake_parameters[0]) < 65536 && pb_membersize(grpc_gcp_StartServerHandshakeReq, local_endpoint) < 65536 && pb_membersize(grpc_gcp_StartServerHandshakeReq, remote_endpoint) < 65536 && pb_membersize(grpc_gcp_StartServerHandshakeReq, rpc_versions) < 65536 && pb_membersize(grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry, value) < 65536 && pb_membersize(grpc_gcp_HandshakerReq, client_start) < 65536 && pb_membersize(grpc_gcp_HandshakerReq, server_start) < 65536 && pb_membersize(grpc_gcp_HandshakerReq, next) < 65536 && pb_membersize(grpc_gcp_HandshakerResult, peer_identity) < 65536 && pb_membersize(grpc_gcp_HandshakerResult, local_identity) < 65536 && pb_membersize(grpc_gcp_HandshakerResult, peer_rpc_versions) < 65536 && pb_membersize(grpc_gcp_HandshakerResp, result) < 65536 && pb_membersize(grpc_gcp_HandshakerResp, status) < 65536), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_grpc_gcp_Endpoint_grpc_gcp_Identity_grpc_gcp_StartClientHandshakeReq_grpc_gcp_ServerHandshakeParameters_grpc_gcp_StartServerHandshakeReq_grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_grpc_gcp_NextHandshakeMessageReq_grpc_gcp_HandshakerReq_grpc_gcp_HandshakerResult_grpc_gcp_HandshakerStatus_grpc_gcp_HandshakerResp) -#endif - -#if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT) -/* If you get an error here, it means that you need to define PB_FIELD_16BIT - * compile-time option. You can do that in pb.h or on compiler command line. - * - * The reason you need to do this is that some of your messages contain tag - * numbers or field sizes that are larger than what can fit in the default - * 8 bit descriptors. - */ -PB_STATIC_ASSERT((pb_membersize(grpc_gcp_StartClientHandshakeReq, target_identities) < 256 && pb_membersize(grpc_gcp_StartClientHandshakeReq, local_identity) < 256 && pb_membersize(grpc_gcp_StartClientHandshakeReq, local_endpoint) < 256 && pb_membersize(grpc_gcp_StartClientHandshakeReq, remote_endpoint) < 256 && pb_membersize(grpc_gcp_StartClientHandshakeReq, rpc_versions) < 256 && pb_membersize(grpc_gcp_ServerHandshakeParameters, local_identities) < 256 && pb_membersize(grpc_gcp_StartServerHandshakeReq, handshake_parameters[0]) < 256 && pb_membersize(grpc_gcp_StartServerHandshakeReq, local_endpoint) < 256 && pb_membersize(grpc_gcp_StartServerHandshakeReq, remote_endpoint) < 256 && pb_membersize(grpc_gcp_StartServerHandshakeReq, rpc_versions) < 256 && pb_membersize(grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry, value) < 256 && pb_membersize(grpc_gcp_HandshakerReq, client_start) < 256 && pb_membersize(grpc_gcp_HandshakerReq, server_start) < 256 && pb_membersize(grpc_gcp_HandshakerReq, next) < 256 && pb_membersize(grpc_gcp_HandshakerResult, peer_identity) < 256 && pb_membersize(grpc_gcp_HandshakerResult, local_identity) < 256 && pb_membersize(grpc_gcp_HandshakerResult, peer_rpc_versions) < 256 && pb_membersize(grpc_gcp_HandshakerResp, result) < 256 && pb_membersize(grpc_gcp_HandshakerResp, status) < 256), YOU_MUST_DEFINE_PB_FIELD_16BIT_FOR_MESSAGES_grpc_gcp_Endpoint_grpc_gcp_Identity_grpc_gcp_StartClientHandshakeReq_grpc_gcp_ServerHandshakeParameters_grpc_gcp_StartServerHandshakeReq_grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_grpc_gcp_NextHandshakeMessageReq_grpc_gcp_HandshakerReq_grpc_gcp_HandshakerResult_grpc_gcp_HandshakerStatus_grpc_gcp_HandshakerResp) -#endif - - -/* @@protoc_insertion_point(eof) */ diff --git a/src/core/tsi/alts/handshaker/handshaker.pb.h b/src/core/tsi/alts/handshaker/handshaker.pb.h deleted file mode 100644 index 0805a144de..0000000000 --- a/src/core/tsi/alts/handshaker/handshaker.pb.h +++ /dev/null @@ -1,255 +0,0 @@ -/* Automatically generated nanopb header */ -/* Generated by nanopb-0.3.7-dev */ - -#ifndef PB_GRPC_GCP_HANDSHAKER_PB_H_INCLUDED -#define PB_GRPC_GCP_HANDSHAKER_PB_H_INCLUDED -#include "third_party/nanopb/pb.h" -#include "src/core/tsi/alts/handshaker/transport_security_common.pb.h" - -/* @@protoc_insertion_point(includes) */ -#if PB_PROTO_HEADER_VERSION != 30 -#error Regenerate this file with the current version of nanopb generator. -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* Enum definitions */ -typedef enum _grpc_gcp_HandshakeProtocol { - grpc_gcp_HandshakeProtocol_HANDSHAKE_PROTOCOL_UNSPECIFIED = 0, - grpc_gcp_HandshakeProtocol_TLS = 1, - grpc_gcp_HandshakeProtocol_ALTS = 2 -} grpc_gcp_HandshakeProtocol; -#define _grpc_gcp_HandshakeProtocol_MIN grpc_gcp_HandshakeProtocol_HANDSHAKE_PROTOCOL_UNSPECIFIED -#define _grpc_gcp_HandshakeProtocol_MAX grpc_gcp_HandshakeProtocol_ALTS -#define _grpc_gcp_HandshakeProtocol_ARRAYSIZE ((grpc_gcp_HandshakeProtocol)(grpc_gcp_HandshakeProtocol_ALTS+1)) - -typedef enum _grpc_gcp_NetworkProtocol { - grpc_gcp_NetworkProtocol_NETWORK_PROTOCOL_UNSPECIFIED = 0, - grpc_gcp_NetworkProtocol_TCP = 1, - grpc_gcp_NetworkProtocol_UDP = 2 -} grpc_gcp_NetworkProtocol; -#define _grpc_gcp_NetworkProtocol_MIN grpc_gcp_NetworkProtocol_NETWORK_PROTOCOL_UNSPECIFIED -#define _grpc_gcp_NetworkProtocol_MAX grpc_gcp_NetworkProtocol_UDP -#define _grpc_gcp_NetworkProtocol_ARRAYSIZE ((grpc_gcp_NetworkProtocol)(grpc_gcp_NetworkProtocol_UDP+1)) - -/* Struct definitions */ -typedef struct _grpc_gcp_Identity { - pb_callback_t service_account; - pb_callback_t hostname; -/* @@protoc_insertion_point(struct:grpc_gcp_Identity) */ -} grpc_gcp_Identity; - -typedef struct _grpc_gcp_NextHandshakeMessageReq { - pb_callback_t in_bytes; -/* @@protoc_insertion_point(struct:grpc_gcp_NextHandshakeMessageReq) */ -} grpc_gcp_NextHandshakeMessageReq; - -typedef struct _grpc_gcp_ServerHandshakeParameters { - pb_callback_t record_protocols; - pb_callback_t local_identities; -/* @@protoc_insertion_point(struct:grpc_gcp_ServerHandshakeParameters) */ -} grpc_gcp_ServerHandshakeParameters; - -typedef struct _grpc_gcp_Endpoint { - pb_callback_t ip_address; - bool has_port; - int32_t port; - bool has_protocol; - grpc_gcp_NetworkProtocol protocol; -/* @@protoc_insertion_point(struct:grpc_gcp_Endpoint) */ -} grpc_gcp_Endpoint; - -typedef struct _grpc_gcp_HandshakerResult { - pb_callback_t application_protocol; - pb_callback_t record_protocol; - pb_callback_t key_data; - bool has_peer_identity; - grpc_gcp_Identity peer_identity; - bool has_local_identity; - grpc_gcp_Identity local_identity; - bool has_keep_channel_open; - bool keep_channel_open; - bool has_peer_rpc_versions; - grpc_gcp_RpcProtocolVersions peer_rpc_versions; -/* @@protoc_insertion_point(struct:grpc_gcp_HandshakerResult) */ -} grpc_gcp_HandshakerResult; - -typedef struct _grpc_gcp_HandshakerStatus { - bool has_code; - uint32_t code; - pb_callback_t details; -/* @@protoc_insertion_point(struct:grpc_gcp_HandshakerStatus) */ -} grpc_gcp_HandshakerStatus; - -typedef struct _grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry { - bool has_key; - int32_t key; - bool has_value; - grpc_gcp_ServerHandshakeParameters value; -/* @@protoc_insertion_point(struct:grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry) */ -} grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry; - -typedef struct _grpc_gcp_HandshakerResp { - pb_callback_t out_frames; - bool has_bytes_consumed; - uint32_t bytes_consumed; - bool has_result; - grpc_gcp_HandshakerResult result; - bool has_status; - grpc_gcp_HandshakerStatus status; -/* @@protoc_insertion_point(struct:grpc_gcp_HandshakerResp) */ -} grpc_gcp_HandshakerResp; - -typedef struct _grpc_gcp_StartClientHandshakeReq { - bool has_handshake_security_protocol; - grpc_gcp_HandshakeProtocol handshake_security_protocol; - pb_callback_t application_protocols; - pb_callback_t record_protocols; - pb_callback_t target_identities; - bool has_local_identity; - grpc_gcp_Identity local_identity; - bool has_local_endpoint; - grpc_gcp_Endpoint local_endpoint; - bool has_remote_endpoint; - grpc_gcp_Endpoint remote_endpoint; - pb_callback_t target_name; - bool has_rpc_versions; - grpc_gcp_RpcProtocolVersions rpc_versions; -/* @@protoc_insertion_point(struct:grpc_gcp_StartClientHandshakeReq) */ -} grpc_gcp_StartClientHandshakeReq; - -typedef struct _grpc_gcp_StartServerHandshakeReq { - pb_callback_t application_protocols; - pb_size_t handshake_parameters_count; - grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry handshake_parameters[3]; - pb_callback_t in_bytes; - bool has_local_endpoint; - grpc_gcp_Endpoint local_endpoint; - bool has_remote_endpoint; - grpc_gcp_Endpoint remote_endpoint; - bool has_rpc_versions; - grpc_gcp_RpcProtocolVersions rpc_versions; -/* @@protoc_insertion_point(struct:grpc_gcp_StartServerHandshakeReq) */ -} grpc_gcp_StartServerHandshakeReq; - -typedef struct _grpc_gcp_HandshakerReq { - bool has_client_start; - grpc_gcp_StartClientHandshakeReq client_start; - bool has_server_start; - grpc_gcp_StartServerHandshakeReq server_start; - bool has_next; - grpc_gcp_NextHandshakeMessageReq next; -/* @@protoc_insertion_point(struct:grpc_gcp_HandshakerReq) */ -} grpc_gcp_HandshakerReq; - -/* Default values for struct fields */ - -/* Initializer values for message structs */ -#define grpc_gcp_Endpoint_init_default {{{NULL}, NULL}, false, 0, false, (grpc_gcp_NetworkProtocol)0} -#define grpc_gcp_Identity_init_default {{{NULL}, NULL}, {{NULL}, NULL}} -#define grpc_gcp_StartClientHandshakeReq_init_default {false, (grpc_gcp_HandshakeProtocol)0, {{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, grpc_gcp_Identity_init_default, false, grpc_gcp_Endpoint_init_default, false, grpc_gcp_Endpoint_init_default, {{NULL}, NULL}, false, grpc_gcp_RpcProtocolVersions_init_default} -#define grpc_gcp_ServerHandshakeParameters_init_default {{{NULL}, NULL}, {{NULL}, NULL}} -#define grpc_gcp_StartServerHandshakeReq_init_default {{{NULL}, NULL}, 0, {grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_init_default, grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_init_default, grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_init_default}, {{NULL}, NULL}, false, grpc_gcp_Endpoint_init_default, false, grpc_gcp_Endpoint_init_default, false, grpc_gcp_RpcProtocolVersions_init_default} -#define grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_init_default {false, 0, false, grpc_gcp_ServerHandshakeParameters_init_default} -#define grpc_gcp_NextHandshakeMessageReq_init_default {{{NULL}, NULL}} -#define grpc_gcp_HandshakerReq_init_default {false, grpc_gcp_StartClientHandshakeReq_init_default, false, grpc_gcp_StartServerHandshakeReq_init_default, false, grpc_gcp_NextHandshakeMessageReq_init_default} -#define grpc_gcp_HandshakerResult_init_default {{{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, grpc_gcp_Identity_init_default, false, grpc_gcp_Identity_init_default, false, 0, false, grpc_gcp_RpcProtocolVersions_init_default} -#define grpc_gcp_HandshakerStatus_init_default {false, 0, {{NULL}, NULL}} -#define grpc_gcp_HandshakerResp_init_default {{{NULL}, NULL}, false, 0, false, grpc_gcp_HandshakerResult_init_default, false, grpc_gcp_HandshakerStatus_init_default} -#define grpc_gcp_Endpoint_init_zero {{{NULL}, NULL}, false, 0, false, (grpc_gcp_NetworkProtocol)0} -#define grpc_gcp_Identity_init_zero {{{NULL}, NULL}, {{NULL}, NULL}} -#define grpc_gcp_StartClientHandshakeReq_init_zero {false, (grpc_gcp_HandshakeProtocol)0, {{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, grpc_gcp_Identity_init_zero, false, grpc_gcp_Endpoint_init_zero, false, grpc_gcp_Endpoint_init_zero, {{NULL}, NULL}, false, grpc_gcp_RpcProtocolVersions_init_zero} -#define grpc_gcp_ServerHandshakeParameters_init_zero {{{NULL}, NULL}, {{NULL}, NULL}} -#define grpc_gcp_StartServerHandshakeReq_init_zero {{{NULL}, NULL}, 0, {grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_init_zero, grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_init_zero, grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_init_zero}, {{NULL}, NULL}, false, grpc_gcp_Endpoint_init_zero, false, grpc_gcp_Endpoint_init_zero, false, grpc_gcp_RpcProtocolVersions_init_zero} -#define grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_init_zero {false, 0, false, grpc_gcp_ServerHandshakeParameters_init_zero} -#define grpc_gcp_NextHandshakeMessageReq_init_zero {{{NULL}, NULL}} -#define grpc_gcp_HandshakerReq_init_zero {false, grpc_gcp_StartClientHandshakeReq_init_zero, false, grpc_gcp_StartServerHandshakeReq_init_zero, false, grpc_gcp_NextHandshakeMessageReq_init_zero} -#define grpc_gcp_HandshakerResult_init_zero {{{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, grpc_gcp_Identity_init_zero, false, grpc_gcp_Identity_init_zero, false, 0, false, grpc_gcp_RpcProtocolVersions_init_zero} -#define grpc_gcp_HandshakerStatus_init_zero {false, 0, {{NULL}, NULL}} -#define grpc_gcp_HandshakerResp_init_zero {{{NULL}, NULL}, false, 0, false, grpc_gcp_HandshakerResult_init_zero, false, grpc_gcp_HandshakerStatus_init_zero} - -/* Field tags (for use in manual encoding/decoding) */ -#define grpc_gcp_Identity_service_account_tag 1 -#define grpc_gcp_Identity_hostname_tag 2 -#define grpc_gcp_NextHandshakeMessageReq_in_bytes_tag 1 -#define grpc_gcp_ServerHandshakeParameters_record_protocols_tag 1 -#define grpc_gcp_ServerHandshakeParameters_local_identities_tag 2 -#define grpc_gcp_Endpoint_ip_address_tag 1 -#define grpc_gcp_Endpoint_port_tag 2 -#define grpc_gcp_Endpoint_protocol_tag 3 -#define grpc_gcp_HandshakerResult_application_protocol_tag 1 -#define grpc_gcp_HandshakerResult_record_protocol_tag 2 -#define grpc_gcp_HandshakerResult_key_data_tag 3 -#define grpc_gcp_HandshakerResult_peer_identity_tag 4 -#define grpc_gcp_HandshakerResult_local_identity_tag 5 -#define grpc_gcp_HandshakerResult_keep_channel_open_tag 6 -#define grpc_gcp_HandshakerResult_peer_rpc_versions_tag 7 -#define grpc_gcp_HandshakerStatus_code_tag 1 -#define grpc_gcp_HandshakerStatus_details_tag 2 -#define grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_key_tag 1 -#define grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_value_tag 2 -#define grpc_gcp_HandshakerResp_out_frames_tag 1 -#define grpc_gcp_HandshakerResp_bytes_consumed_tag 2 -#define grpc_gcp_HandshakerResp_result_tag 3 -#define grpc_gcp_HandshakerResp_status_tag 4 -#define grpc_gcp_StartClientHandshakeReq_handshake_security_protocol_tag 1 -#define grpc_gcp_StartClientHandshakeReq_application_protocols_tag 2 -#define grpc_gcp_StartClientHandshakeReq_record_protocols_tag 3 -#define grpc_gcp_StartClientHandshakeReq_target_identities_tag 4 -#define grpc_gcp_StartClientHandshakeReq_local_identity_tag 5 -#define grpc_gcp_StartClientHandshakeReq_local_endpoint_tag 6 -#define grpc_gcp_StartClientHandshakeReq_remote_endpoint_tag 7 -#define grpc_gcp_StartClientHandshakeReq_target_name_tag 8 -#define grpc_gcp_StartClientHandshakeReq_rpc_versions_tag 9 -#define grpc_gcp_StartServerHandshakeReq_application_protocols_tag 1 -#define grpc_gcp_StartServerHandshakeReq_handshake_parameters_tag 2 -#define grpc_gcp_StartServerHandshakeReq_in_bytes_tag 3 -#define grpc_gcp_StartServerHandshakeReq_local_endpoint_tag 4 -#define grpc_gcp_StartServerHandshakeReq_remote_endpoint_tag 5 -#define grpc_gcp_StartServerHandshakeReq_rpc_versions_tag 6 -#define grpc_gcp_HandshakerReq_client_start_tag 1 -#define grpc_gcp_HandshakerReq_server_start_tag 2 -#define grpc_gcp_HandshakerReq_next_tag 3 - -/* Struct field encoding specification for nanopb */ -extern const pb_field_t grpc_gcp_Endpoint_fields[4]; -extern const pb_field_t grpc_gcp_Identity_fields[3]; -extern const pb_field_t grpc_gcp_StartClientHandshakeReq_fields[10]; -extern const pb_field_t grpc_gcp_ServerHandshakeParameters_fields[3]; -extern const pb_field_t grpc_gcp_StartServerHandshakeReq_fields[7]; -extern const pb_field_t grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_fields[3]; -extern const pb_field_t grpc_gcp_NextHandshakeMessageReq_fields[2]; -extern const pb_field_t grpc_gcp_HandshakerReq_fields[4]; -extern const pb_field_t grpc_gcp_HandshakerResult_fields[8]; -extern const pb_field_t grpc_gcp_HandshakerStatus_fields[3]; -extern const pb_field_t grpc_gcp_HandshakerResp_fields[5]; - -/* Maximum encoded size of messages (where known) */ -/* grpc_gcp_Endpoint_size depends on runtime parameters */ -/* grpc_gcp_Identity_size depends on runtime parameters */ -/* grpc_gcp_StartClientHandshakeReq_size depends on runtime parameters */ -/* grpc_gcp_ServerHandshakeParameters_size depends on runtime parameters */ -/* grpc_gcp_StartServerHandshakeReq_size depends on runtime parameters */ -#define grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_size (17 + grpc_gcp_ServerHandshakeParameters_size) -/* grpc_gcp_NextHandshakeMessageReq_size depends on runtime parameters */ -#define grpc_gcp_HandshakerReq_size (18 + grpc_gcp_StartClientHandshakeReq_size + grpc_gcp_StartServerHandshakeReq_size + grpc_gcp_NextHandshakeMessageReq_size) -/* grpc_gcp_HandshakerResult_size depends on runtime parameters */ -/* grpc_gcp_HandshakerStatus_size depends on runtime parameters */ -/* grpc_gcp_HandshakerResp_size depends on runtime parameters */ - -/* Message IDs (where set with "msgid" option) */ -#ifdef PB_MSGID - -#define HANDSHAKER_MESSAGES \ - - -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif -/* @@protoc_insertion_point(eof) */ - -#endif diff --git a/src/core/tsi/alts/handshaker/proto/altscontext.proto b/src/core/tsi/alts/handshaker/proto/altscontext.proto deleted file mode 100644 index d195b37e08..0000000000 --- a/src/core/tsi/alts/handshaker/proto/altscontext.proto +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2018 gRPC authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -syntax = "proto3"; - -import "transport_security_common.proto"; - -package grpc.gcp; - -option java_package = "io.grpc.alts"; - -message AltsContext { - // The application protocol negotiated for this connection. - string application_protocol = 1; - - // The record protocol negotiated for this connection. - string record_protocol = 2; - - // The security level of the created secure channel. - SecurityLevel security_level = 3; - - // The peer service account. - string peer_service_account = 4; - - // The local service account. - string local_service_account = 5; - - // The RPC protocol versions supported by the peer. - RpcProtocolVersions peer_rpc_versions = 6; -} diff --git a/src/core/tsi/alts/handshaker/proto/handshaker.options b/src/core/tsi/alts/handshaker/proto/handshaker.options deleted file mode 100644 index 702ba3802a..0000000000 --- a/src/core/tsi/alts/handshaker/proto/handshaker.options +++ /dev/null @@ -1,2 +0,0 @@ -handshaker.proto no_unions:true -grpc.gcp.StartServerHandshakeReq.handshake_parameters max_count:3 diff --git a/src/core/tsi/alts/handshaker/proto/handshaker.proto b/src/core/tsi/alts/handshaker/proto/handshaker.proto deleted file mode 100644 index 46b8b09eb0..0000000000 --- a/src/core/tsi/alts/handshaker/proto/handshaker.proto +++ /dev/null @@ -1,220 +0,0 @@ -// Copyright 2018 gRPC authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -syntax = "proto3"; - -import "transport_security_common.proto"; - -package grpc.gcp; - -option java_package = "io.grpc.alts"; - -enum HandshakeProtocol { - // Default value. - HANDSHAKE_PROTOCOL_UNSPECIFIED = 0; - - // TLS handshake protocol. - TLS = 1; - - // Application Layer Transport Security handshake protocol. - ALTS = 2; -} - -enum NetworkProtocol { - NETWORK_PROTOCOL_UNSPECIFIED = 0; - TCP = 1; - UDP = 2; -} - -message Endpoint { - // IP address. It should contain an IPv4 or IPv6 string literal, e.g. - // "192.168.0.1" or "2001:db8::1". - string ip_address = 1; - - // Port number. - int32 port = 2; - - // Network protocol (e.g., TCP, UDP) associated with this endpoint. - NetworkProtocol protocol = 3; -} - -message Identity { - oneof identity_oneof { - // Service account of a connection endpoint. - string service_account = 1; - - // Hostname of a connection endpoint. - string hostname = 2; - } -} - -message StartClientHandshakeReq { - // Handshake security protocol requested by the client. - HandshakeProtocol handshake_security_protocol = 1; - - // The application protocols supported by the client, e.g., "h2" (for http2), - // "grpc". - repeated string application_protocols = 2; - - // The record protocols supported by the client, e.g., - // "ALTSRP_GCM_AES128". - repeated string record_protocols = 3; - - // (Optional) Describes which server identities are acceptable by the client. - // If target identities are provided and none of them matches the peer - // identity of the server, handshake will fail. - repeated Identity target_identities = 4; - - // (Optional) Application may specify a local identity. Otherwise, the - // handshaker chooses a default local identity. - Identity local_identity = 5; - - // (Optional) Local endpoint information of the connection to the server, - // such as local IP address, port number, and network protocol. - Endpoint local_endpoint = 6; - - // (Optional) Endpoint information of the remote server, such as IP address, - // port number, and network protocool. - Endpoint remote_endpoint = 7; - - // (Optional) If target name is provided, a secure naming check is performed - // to verify that the peer authenticated identity is indeed authorized to run - // the target name. - string target_name = 8; - - // (Optional) RPC protocol versions supported by the client. - RpcProtocolVersions rpc_versions = 9; -} - -message ServerHandshakeParameters { - // The record protocols supported by the server, e.g., - // "ALTSRP_GCM_AES128". - repeated string record_protocols = 1; - - // (Optional) A list of local identities supported by the server, if - // specified. Otherwise, the handshaker chooses a default local identity. - repeated Identity local_identities = 2; -} - -message StartServerHandshakeReq { - // The application protocols supported by the server, e.g., "h2" (for http2), - // "grpc". - repeated string application_protocols = 1; - - // Handshake parameters (record protocols and local identities supported by - // the server) mapped by the handshake protocol. Each handshake security - // protocol (e.g., TLS or ALTS) has its own set of record protocols and local - // identities. Since protobuf does not support enum as key to the map, the key - // to handshake_parameters is the integer value of HandshakeProtocol enum. - map handshake_parameters = 2; - - // Bytes in out_frames returned from the peer's HandshakerResp. It is possible - // that the peer's out_frames are split into multiple HandshakReq messages. - bytes in_bytes = 3; - - // (Optional) Local endpoint information of the connection to the client, - // such as local IP address, port number, and network protocol. - Endpoint local_endpoint = 4; - - // (Optional) Endpoint information of the remote client, such as IP address, - // port number, and network protocool. - Endpoint remote_endpoint = 5; - - // (Optional) RPC protocol versions supported by the server. - RpcProtocolVersions rpc_versions = 6; -} - -message NextHandshakeMessageReq { - // Bytes in out_frames returned from the peer's HandshakerResp. It is possible - // that the peer's out_frames are split into multiple NextHandshakerMessageReq - // messages. - bytes in_bytes = 1; -} - -message HandshakerReq { - oneof req_oneof { - // The start client handshake request message. - StartClientHandshakeReq client_start = 1; - - // The start server handshake request message. - StartServerHandshakeReq server_start = 2; - - // The next handshake request message. - NextHandshakeMessageReq next = 3; - } -} - -message HandshakerResult { - // The application protocol negotiated for this connection. - string application_protocol = 1; - - // The record protocol negotiated for this connection. - string record_protocol = 2; - - // Cryptographic key data. The key data may be more than the key length - // required for the record protocol, thus the client of the handshaker - // service needs to truncate the key data into the right key length. - bytes key_data = 3; - - // The authenticated identity of the peer. - Identity peer_identity = 4; - - // The local identity used in the handshake. - Identity local_identity = 5; - - // Indicate whether the handshaker service client should keep the channel - // between the handshaker service open, e.g., in order to handle - // post-handshake messages in the future. - bool keep_channel_open = 6; - - // The RPC protocol versions supported by the peer. - RpcProtocolVersions peer_rpc_versions = 7; -} - -message HandshakerStatus { - // The status code. This could be the gRPC status code. - uint32 code = 1; - - // The status details. - string details = 2; -} - -message HandshakerResp { - // Frames to be given to the peer for the NextHandshakeMessageReq. May be - // empty if no out_frames have to be sent to the peer or if in_bytes in the - // HandshakerReq are incomplete. All the non-empty out frames must be sent to - // the peer even if the handshaker status is not OK as these frames may - // contain the alert frames. - bytes out_frames = 1; - - // Number of bytes in the in_bytes consumed by the handshaker. It is possible - // that part of in_bytes in HandshakerReq was unrelated to the handshake - // process. - uint32 bytes_consumed = 2; - - // This is set iff the handshake was successful. out_frames may still be set - // to frames that needs to be forwarded to the peer. - HandshakerResult result = 3; - - // Status of the handshaker. - HandshakerStatus status = 4; -} - -service HandshakerService { - // Accepts a stream of handshaker request, returning a stream of handshaker - // response. - rpc DoHandshake(stream HandshakerReq) - returns (stream HandshakerResp) { - } -} diff --git a/src/core/tsi/alts/handshaker/proto/transport_security_common.proto b/src/core/tsi/alts/handshaker/proto/transport_security_common.proto deleted file mode 100644 index 41983ab9f9..0000000000 --- a/src/core/tsi/alts/handshaker/proto/transport_security_common.proto +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2018 gRPC authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -syntax = "proto3"; - -package grpc.gcp; - -option java_package = "io.grpc.alts"; - -// The security level of the created channel. The list is sorted in increasing -// level of security. This order must always be maintained. -enum SecurityLevel { - SECURITY_NONE = 0; - INTEGRITY_ONLY = 1; - INTEGRITY_AND_PRIVACY = 2; -} - -// Max and min supported RPC protocol versions. -message RpcProtocolVersions { - // RPC version contains a major version and a minor version. - message Version { - uint32 major = 1; - uint32 minor = 2; - } - // Maximum supported RPC version. - Version max_rpc_version = 1; - // Minimum supported RPC version. - Version min_rpc_version = 2; -} diff --git a/src/core/tsi/alts/handshaker/transport_security_common.pb.c b/src/core/tsi/alts/handshaker/transport_security_common.pb.c deleted file mode 100644 index 6063c7625e..0000000000 --- a/src/core/tsi/alts/handshaker/transport_security_common.pb.c +++ /dev/null @@ -1,50 +0,0 @@ -/* Automatically generated nanopb constant definitions */ -/* Generated by nanopb-0.3.7-dev */ - -#include "src/core/tsi/alts/handshaker/transport_security_common.pb.h" - -/* @@protoc_insertion_point(includes) */ -#if PB_PROTO_HEADER_VERSION != 30 -#error Regenerate this file with the current version of nanopb generator. -#endif - - - -const pb_field_t grpc_gcp_RpcProtocolVersions_fields[3] = { - PB_FIELD( 1, MESSAGE , OPTIONAL, STATIC , FIRST, grpc_gcp_RpcProtocolVersions, max_rpc_version, max_rpc_version, &grpc_gcp_RpcProtocolVersions_Version_fields), - PB_FIELD( 2, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_RpcProtocolVersions, min_rpc_version, max_rpc_version, &grpc_gcp_RpcProtocolVersions_Version_fields), - PB_LAST_FIELD -}; - -const pb_field_t grpc_gcp_RpcProtocolVersions_Version_fields[3] = { - PB_FIELD( 1, UINT32 , OPTIONAL, STATIC , FIRST, grpc_gcp_RpcProtocolVersions_Version, major, major, 0), - PB_FIELD( 2, UINT32 , OPTIONAL, STATIC , OTHER, grpc_gcp_RpcProtocolVersions_Version, minor, major, 0), - PB_LAST_FIELD -}; - - -/* Check that field information fits in pb_field_t */ -#if !defined(PB_FIELD_32BIT) -/* If you get an error here, it means that you need to define PB_FIELD_32BIT - * compile-time option. You can do that in pb.h or on compiler command line. - * - * The reason you need to do this is that some of your messages contain tag - * numbers or field sizes that are larger than what can fit in 8 or 16 bit - * field descriptors. - */ -PB_STATIC_ASSERT((pb_membersize(grpc_gcp_RpcProtocolVersions, max_rpc_version) < 65536 && pb_membersize(grpc_gcp_RpcProtocolVersions, min_rpc_version) < 65536), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_grpc_gcp_RpcProtocolVersions_grpc_gcp_RpcProtocolVersions_Version) -#endif - -#if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT) -/* If you get an error here, it means that you need to define PB_FIELD_16BIT - * compile-time option. You can do that in pb.h or on compiler command line. - * - * The reason you need to do this is that some of your messages contain tag - * numbers or field sizes that are larger than what can fit in the default - * 8 bit descriptors. - */ -PB_STATIC_ASSERT((pb_membersize(grpc_gcp_RpcProtocolVersions, max_rpc_version) < 256 && pb_membersize(grpc_gcp_RpcProtocolVersions, min_rpc_version) < 256), YOU_MUST_DEFINE_PB_FIELD_16BIT_FOR_MESSAGES_grpc_gcp_RpcProtocolVersions_grpc_gcp_RpcProtocolVersions_Version) -#endif - - -/* @@protoc_insertion_point(eof) */ diff --git a/src/core/tsi/alts/handshaker/transport_security_common.pb.h b/src/core/tsi/alts/handshaker/transport_security_common.pb.h deleted file mode 100644 index 49096dffa3..0000000000 --- a/src/core/tsi/alts/handshaker/transport_security_common.pb.h +++ /dev/null @@ -1,78 +0,0 @@ -/* Automatically generated nanopb header */ -/* Generated by nanopb-0.3.7-dev */ - -#ifndef PB_GRPC_GCP_TRANSPORT_SECURITY_COMMON_PB_H_INCLUDED -#define PB_GRPC_GCP_TRANSPORT_SECURITY_COMMON_PB_H_INCLUDED -#include "third_party/nanopb/pb.h" -/* @@protoc_insertion_point(includes) */ -#if PB_PROTO_HEADER_VERSION != 30 -#error Regenerate this file with the current version of nanopb generator. -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* Enum definitions */ -typedef enum _grpc_gcp_SecurityLevel { - grpc_gcp_SecurityLevel_SECURITY_NONE = 0, - grpc_gcp_SecurityLevel_INTEGRITY_ONLY = 1, - grpc_gcp_SecurityLevel_INTEGRITY_AND_PRIVACY = 2 -} grpc_gcp_SecurityLevel; -#define _grpc_gcp_SecurityLevel_MIN grpc_gcp_SecurityLevel_SECURITY_NONE -#define _grpc_gcp_SecurityLevel_MAX grpc_gcp_SecurityLevel_INTEGRITY_AND_PRIVACY -#define _grpc_gcp_SecurityLevel_ARRAYSIZE ((grpc_gcp_SecurityLevel)(grpc_gcp_SecurityLevel_INTEGRITY_AND_PRIVACY+1)) - -/* Struct definitions */ -typedef struct _grpc_gcp_RpcProtocolVersions_Version { - bool has_major; - uint32_t major; - bool has_minor; - uint32_t minor; -/* @@protoc_insertion_point(struct:grpc_gcp_RpcProtocolVersions_Version) */ -} grpc_gcp_RpcProtocolVersions_Version; - -typedef struct _grpc_gcp_RpcProtocolVersions { - bool has_max_rpc_version; - grpc_gcp_RpcProtocolVersions_Version max_rpc_version; - bool has_min_rpc_version; - grpc_gcp_RpcProtocolVersions_Version min_rpc_version; -/* @@protoc_insertion_point(struct:grpc_gcp_RpcProtocolVersions) */ -} grpc_gcp_RpcProtocolVersions; - -/* Default values for struct fields */ - -/* Initializer values for message structs */ -#define grpc_gcp_RpcProtocolVersions_init_default {false, grpc_gcp_RpcProtocolVersions_Version_init_default, false, grpc_gcp_RpcProtocolVersions_Version_init_default} -#define grpc_gcp_RpcProtocolVersions_Version_init_default {false, 0, false, 0} -#define grpc_gcp_RpcProtocolVersions_init_zero {false, grpc_gcp_RpcProtocolVersions_Version_init_zero, false, grpc_gcp_RpcProtocolVersions_Version_init_zero} -#define grpc_gcp_RpcProtocolVersions_Version_init_zero {false, 0, false, 0} - -/* Field tags (for use in manual encoding/decoding) */ -#define grpc_gcp_RpcProtocolVersions_Version_major_tag 1 -#define grpc_gcp_RpcProtocolVersions_Version_minor_tag 2 -#define grpc_gcp_RpcProtocolVersions_max_rpc_version_tag 1 -#define grpc_gcp_RpcProtocolVersions_min_rpc_version_tag 2 - -/* Struct field encoding specification for nanopb */ -extern const pb_field_t grpc_gcp_RpcProtocolVersions_fields[3]; -extern const pb_field_t grpc_gcp_RpcProtocolVersions_Version_fields[3]; - -/* Maximum encoded size of messages (where known) */ -#define grpc_gcp_RpcProtocolVersions_size 28 -#define grpc_gcp_RpcProtocolVersions_Version_size 12 - -/* Message IDs (where set with "msgid" option) */ -#ifdef PB_MSGID - -#define TRANSPORT_SECURITY_COMMON_MESSAGES \ - - -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif -/* @@protoc_insertion_point(eof) */ - -#endif diff --git a/src/core/tsi/alts/handshaker/transport_security_common_api.cc b/src/core/tsi/alts/handshaker/transport_security_common_api.cc deleted file mode 100644 index 8a7edb53d4..0000000000 --- a/src/core/tsi/alts/handshaker/transport_security_common_api.cc +++ /dev/null @@ -1,196 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/tsi/alts/handshaker/transport_security_common_api.h" - -bool grpc_gcp_rpc_protocol_versions_set_max( - grpc_gcp_rpc_protocol_versions* versions, uint32_t max_major, - uint32_t max_minor) { - if (versions == nullptr) { - gpr_log(GPR_ERROR, - "versions is nullptr in " - "grpc_gcp_rpc_protocol_versions_set_max()."); - return false; - } - versions->has_max_rpc_version = true; - versions->max_rpc_version.has_major = true; - versions->max_rpc_version.has_minor = true; - versions->max_rpc_version.major = max_major; - versions->max_rpc_version.minor = max_minor; - return true; -} - -bool grpc_gcp_rpc_protocol_versions_set_min( - grpc_gcp_rpc_protocol_versions* versions, uint32_t min_major, - uint32_t min_minor) { - if (versions == nullptr) { - gpr_log(GPR_ERROR, - "versions is nullptr in " - "grpc_gcp_rpc_protocol_versions_set_min()."); - return false; - } - versions->has_min_rpc_version = true; - versions->min_rpc_version.has_major = true; - versions->min_rpc_version.has_minor = true; - versions->min_rpc_version.major = min_major; - versions->min_rpc_version.minor = min_minor; - return true; -} - -size_t grpc_gcp_rpc_protocol_versions_encode_length( - const grpc_gcp_rpc_protocol_versions* versions) { - if (versions == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr arguments to " - "grpc_gcp_rpc_protocol_versions_encode_length()."); - return 0; - } - pb_ostream_t size_stream; - memset(&size_stream, 0, sizeof(pb_ostream_t)); - if (!pb_encode(&size_stream, grpc_gcp_RpcProtocolVersions_fields, versions)) { - gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&size_stream)); - return 0; - } - return size_stream.bytes_written; -} - -bool grpc_gcp_rpc_protocol_versions_encode_to_raw_bytes( - const grpc_gcp_rpc_protocol_versions* versions, uint8_t* bytes, - size_t bytes_length) { - if (versions == nullptr || bytes == nullptr || bytes_length == 0) { - gpr_log(GPR_ERROR, - "Invalid nullptr arguments to " - "grpc_gcp_rpc_protocol_versions_encode_to_raw_bytes()."); - return false; - } - pb_ostream_t output_stream = pb_ostream_from_buffer(bytes, bytes_length); - if (!pb_encode(&output_stream, grpc_gcp_RpcProtocolVersions_fields, - versions)) { - gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&output_stream)); - return false; - } - return true; -} - -bool grpc_gcp_rpc_protocol_versions_encode( - const grpc_gcp_rpc_protocol_versions* versions, grpc_slice* slice) { - if (versions == nullptr || slice == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr arguments to " - "grpc_gcp_rpc_protocol_versions_encode()."); - return false; - } - size_t encoded_length = - grpc_gcp_rpc_protocol_versions_encode_length(versions); - if (encoded_length == 0) return false; - *slice = grpc_slice_malloc(encoded_length); - return grpc_gcp_rpc_protocol_versions_encode_to_raw_bytes( - versions, GRPC_SLICE_START_PTR(*slice), encoded_length); -} - -bool grpc_gcp_rpc_protocol_versions_decode( - grpc_slice slice, grpc_gcp_rpc_protocol_versions* versions) { - if (versions == nullptr) { - gpr_log(GPR_ERROR, - "version is nullptr in " - "grpc_gcp_rpc_protocol_versions_decode()."); - return false; - } - pb_istream_t stream = pb_istream_from_buffer(GRPC_SLICE_START_PTR(slice), - GRPC_SLICE_LENGTH(slice)); - if (!pb_decode(&stream, grpc_gcp_RpcProtocolVersions_fields, versions)) { - gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&stream)); - return false; - } - return true; -} - -bool grpc_gcp_rpc_protocol_versions_copy( - const grpc_gcp_rpc_protocol_versions* src, - grpc_gcp_rpc_protocol_versions* dst) { - if ((src == nullptr && dst != nullptr) || - (src != nullptr && dst == nullptr)) { - gpr_log(GPR_ERROR, - "Invalid arguments to " - "grpc_gcp_rpc_protocol_versions_copy()."); - return false; - } - if (src == nullptr) { - return true; - } - grpc_gcp_rpc_protocol_versions_set_max(dst, src->max_rpc_version.major, - src->max_rpc_version.minor); - grpc_gcp_rpc_protocol_versions_set_min(dst, src->min_rpc_version.major, - src->min_rpc_version.minor); - return true; -} - -namespace grpc_core { -namespace internal { - -int grpc_gcp_rpc_protocol_version_compare( - const grpc_gcp_rpc_protocol_versions_version* v1, - const grpc_gcp_rpc_protocol_versions_version* v2) { - if ((v1->major > v2->major) || - (v1->major == v2->major && v1->minor > v2->minor)) { - return 1; - } - if ((v1->major < v2->major) || - (v1->major == v2->major && v1->minor < v2->minor)) { - return -1; - } - return 0; -} - -} // namespace internal -} // namespace grpc_core - -bool grpc_gcp_rpc_protocol_versions_check( - const grpc_gcp_rpc_protocol_versions* local_versions, - const grpc_gcp_rpc_protocol_versions* peer_versions, - grpc_gcp_rpc_protocol_versions_version* highest_common_version) { - if (local_versions == nullptr || peer_versions == nullptr) { - gpr_log(GPR_ERROR, - "Invalid arguments to " - "grpc_gcp_rpc_protocol_versions_check()."); - return false; - } - /* max_common_version is MIN(local.max, peer.max) */ - const grpc_gcp_rpc_protocol_versions_version* max_common_version = - grpc_core::internal::grpc_gcp_rpc_protocol_version_compare( - &local_versions->max_rpc_version, &peer_versions->max_rpc_version) > 0 - ? &peer_versions->max_rpc_version - : &local_versions->max_rpc_version; - /* min_common_version is MAX(local.min, peer.min) */ - const grpc_gcp_rpc_protocol_versions_version* min_common_version = - grpc_core::internal::grpc_gcp_rpc_protocol_version_compare( - &local_versions->min_rpc_version, &peer_versions->min_rpc_version) > 0 - ? &local_versions->min_rpc_version - : &peer_versions->min_rpc_version; - bool result = grpc_core::internal::grpc_gcp_rpc_protocol_version_compare( - max_common_version, min_common_version) >= 0 - ? true - : false; - if (result && highest_common_version != nullptr) { - memcpy(highest_common_version, max_common_version, - sizeof(grpc_gcp_rpc_protocol_versions_version)); - } - return result; -} diff --git a/src/core/tsi/alts/handshaker/transport_security_common_api.h b/src/core/tsi/alts/handshaker/transport_security_common_api.h deleted file mode 100644 index 68228cb3b5..0000000000 --- a/src/core/tsi/alts/handshaker/transport_security_common_api.h +++ /dev/null @@ -1,163 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_TSI_ALTS_HANDSHAKER_TRANSPORT_SECURITY_COMMON_API_H -#define GRPC_CORE_TSI_ALTS_HANDSHAKER_TRANSPORT_SECURITY_COMMON_API_H - -#include - -#include "third_party/nanopb/pb_decode.h" -#include "third_party/nanopb/pb_encode.h" - -#include -#include -#include -#include - -#include "src/core/tsi/alts/handshaker/transport_security_common.pb.h" - -typedef grpc_gcp_RpcProtocolVersions grpc_gcp_rpc_protocol_versions; - -typedef grpc_gcp_RpcProtocolVersions_Version - grpc_gcp_rpc_protocol_versions_version; - -/** - * This method sets the value for max_rpc_versions field of rpc protocol - * versions. - * - * - versions: an rpc protocol version instance. - * - max_major: a major version of maximum supported RPC version. - * - max_minor: a minor version of maximum supported RPC version. - * - * The method returns true on success and false otherwise. - */ -bool grpc_gcp_rpc_protocol_versions_set_max( - grpc_gcp_rpc_protocol_versions* versions, uint32_t max_major, - uint32_t max_minor); - -/** - * This method sets the value for min_rpc_versions field of rpc protocol - * versions. - * - * - versions: an rpc protocol version instance. - * - min_major: a major version of minimum supported RPC version. - * - min_minor: a minor version of minimum supported RPC version. - * - * The method returns true on success and false otherwise. - */ -bool grpc_gcp_rpc_protocol_versions_set_min( - grpc_gcp_rpc_protocol_versions* versions, uint32_t min_major, - uint32_t min_minor); - -/** - * This method computes serialized byte length of rpc protocol versions. - * - * - versions: an rpc protocol versions instance. - * - * The method returns serialized byte length. It returns 0 on failure. - */ -size_t grpc_gcp_rpc_protocol_versions_encode_length( - const grpc_gcp_rpc_protocol_versions* versions); - -/** - * This method serializes rpc protocol versions and writes the result to - * the memory buffer provided by the caller. Caller is responsible for - * allocating sufficient memory to store the serialized data. - * - * - versions: an rpc protocol versions instance. - * - bytes: bytes buffer where the result will be written to. - * - bytes_length: length of the bytes buffer. - * - * The method returns true on success and false otherwise. - */ -bool grpc_gcp_rpc_protocol_versions_encode_to_raw_bytes( - const grpc_gcp_rpc_protocol_versions* versions, uint8_t* bytes, - size_t bytes_length); - -/** - * This method serializes an rpc protocol version and returns serialized rpc - * versions in grpc slice. - * - * - versions: an rpc protocol versions instance. - * - slice: grpc slice where the serialized result will be written. - * - * The method returns true on success and false otherwise. - */ -bool grpc_gcp_rpc_protocol_versions_encode( - const grpc_gcp_rpc_protocol_versions* versions, grpc_slice* slice); - -/** - * This method de-serializes input in grpc slice form and stores the result - * in rpc protocol versions. - * - * - slice: a data stream containing a serialized rpc protocol version. - * - versions: an rpc protocol version instance used to hold de-serialized - * result. - * - * The method returns true on success and false otherwise. - */ -bool grpc_gcp_rpc_protocol_versions_decode( - grpc_slice slice, grpc_gcp_rpc_protocol_versions* versions); - -/** - * This method performs a deep copy operation on rpc protocol versions - * instance. - * - * - src: rpc protocol versions instance that needs to be copied. - * - dst: rpc protocol versions instance that stores the copied result. - * - * The method returns true on success and false otherwise. - */ -bool grpc_gcp_rpc_protocol_versions_copy( - const grpc_gcp_rpc_protocol_versions* src, - grpc_gcp_rpc_protocol_versions* dst); - -/** - * This method performs a version check between local and peer rpc protocol - * versions. - * - * - local_versions: local rpc protocol versions instance. - * - peer_versions: peer rpc protocol versions instance. - * - highest_common_version: an output parameter that will store the highest - * common rpc protocol version both parties agreed on. - * - * The method returns true if the check passes which means both parties agreed - * on a common rpc protocol to use, and false otherwise. - */ -bool grpc_gcp_rpc_protocol_versions_check( - const grpc_gcp_rpc_protocol_versions* local_versions, - const grpc_gcp_rpc_protocol_versions* peer_versions, - grpc_gcp_rpc_protocol_versions_version* highest_common_version); - -namespace grpc_core { -namespace internal { - -/** - * Exposed for testing only. - * The method returns 0 if v1 = v2, - * returns 1 if v1 > v2, - * returns -1 if v1 < v2. - */ -int grpc_gcp_rpc_protocol_version_compare( - const grpc_gcp_rpc_protocol_versions_version* v1, - const grpc_gcp_rpc_protocol_versions_version* v2); - -} // namespace internal -} // namespace grpc_core - -#endif /* GRPC_CORE_TSI_ALTS_HANDSHAKER_TRANSPORT_SECURITY_COMMON_API_H */ diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc deleted file mode 100644 index 7ba03eb7f0..0000000000 --- a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc +++ /dev/null @@ -1,180 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h" - -#include -#include - -#include "src/core/lib/slice/slice_internal.h" -#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h" -#include "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h" - -/* Main struct for alts_grpc_integrity_only_record_protocol. */ -typedef struct alts_grpc_integrity_only_record_protocol { - alts_grpc_record_protocol base; - grpc_slice_buffer data_sb; - unsigned char* tag_buf; -} alts_grpc_integrity_only_record_protocol; - -/* --- alts_grpc_record_protocol methods implementation. --- */ - -static tsi_result alts_grpc_integrity_only_protect( - alts_grpc_record_protocol* rp, grpc_slice_buffer* unprotected_slices, - grpc_slice_buffer* protected_slices) { - /* Input sanity check. */ - if (rp == nullptr || unprotected_slices == nullptr || - protected_slices == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr arguments to alts_grpc_record_protocol protect."); - return TSI_INVALID_ARGUMENT; - } - /* Allocates memory for header and tag slices. */ - grpc_slice header_slice = GRPC_SLICE_MALLOC(rp->header_length); - grpc_slice tag_slice = GRPC_SLICE_MALLOC(rp->tag_length); - /* Calls alts_iovec_record_protocol protect. */ - char* error_details = nullptr; - iovec_t header_iovec = {GRPC_SLICE_START_PTR(header_slice), - GRPC_SLICE_LENGTH(header_slice)}; - iovec_t tag_iovec = {GRPC_SLICE_START_PTR(tag_slice), - GRPC_SLICE_LENGTH(tag_slice)}; - alts_grpc_record_protocol_convert_slice_buffer_to_iovec(rp, - unprotected_slices); - grpc_status_code status = alts_iovec_record_protocol_integrity_only_protect( - rp->iovec_rp, rp->iovec_buf, unprotected_slices->count, header_iovec, - tag_iovec, &error_details); - if (status != GRPC_STATUS_OK) { - gpr_log(GPR_ERROR, "Failed to protect, %s", error_details); - gpr_free(error_details); - return TSI_INTERNAL_ERROR; - } - /* Appends result to protected_slices. */ - grpc_slice_buffer_add(protected_slices, header_slice); - grpc_slice_buffer_move_into(unprotected_slices, protected_slices); - grpc_slice_buffer_add(protected_slices, tag_slice); - return TSI_OK; -} - -static tsi_result alts_grpc_integrity_only_unprotect( - alts_grpc_record_protocol* rp, grpc_slice_buffer* protected_slices, - grpc_slice_buffer* unprotected_slices) { - /* Input sanity check. */ - if (rp == nullptr || protected_slices == nullptr || - unprotected_slices == nullptr) { - gpr_log( - GPR_ERROR, - "Invalid nullptr arguments to alts_grpc_record_protocol unprotect."); - return TSI_INVALID_ARGUMENT; - } - if (protected_slices->length < rp->header_length + rp->tag_length) { - gpr_log(GPR_ERROR, "Protected slices do not have sufficient data."); - return TSI_INVALID_ARGUMENT; - } - /* In this method, rp points to alts_grpc_record_protocol struct - * and integrity_only_record_protocol points to - * alts_grpc_integrity_only_record_protocol struct. */ - alts_grpc_integrity_only_record_protocol* integrity_only_record_protocol = - reinterpret_cast(rp); - /* Strips frame header from protected slices. */ - grpc_slice_buffer_reset_and_unref_internal(&rp->header_sb); - grpc_slice_buffer_move_first(protected_slices, rp->header_length, - &rp->header_sb); - GPR_ASSERT(rp->header_sb.length == rp->header_length); - iovec_t header_iovec = alts_grpc_record_protocol_get_header_iovec(rp); - /* Moves protected slices data to data_sb and leaves the remaining tag. */ - grpc_slice_buffer_reset_and_unref_internal( - &integrity_only_record_protocol->data_sb); - grpc_slice_buffer_move_first(protected_slices, - protected_slices->length - rp->tag_length, - &integrity_only_record_protocol->data_sb); - GPR_ASSERT(protected_slices->length == rp->tag_length); - iovec_t tag_iovec = {nullptr, rp->tag_length}; - if (protected_slices->count == 1) { - tag_iovec.iov_base = GRPC_SLICE_START_PTR(protected_slices->slices[0]); - } else { - /* Frame tag is in multiple slices, copies the tag bytes from slice - * buffer to a single flat buffer. */ - alts_grpc_record_protocol_copy_slice_buffer( - protected_slices, integrity_only_record_protocol->tag_buf); - tag_iovec.iov_base = integrity_only_record_protocol->tag_buf; - } - /* Calls alts_iovec_record_protocol unprotect. */ - char* error_details = nullptr; - alts_grpc_record_protocol_convert_slice_buffer_to_iovec( - rp, &integrity_only_record_protocol->data_sb); - grpc_status_code status = alts_iovec_record_protocol_integrity_only_unprotect( - rp->iovec_rp, rp->iovec_buf, - integrity_only_record_protocol->data_sb.count, header_iovec, tag_iovec, - &error_details); - if (status != GRPC_STATUS_OK) { - gpr_log(GPR_ERROR, "Failed to unprotect, %s", error_details); - gpr_free(error_details); - return TSI_INTERNAL_ERROR; - } - grpc_slice_buffer_reset_and_unref_internal(&rp->header_sb); - grpc_slice_buffer_reset_and_unref_internal(protected_slices); - grpc_slice_buffer_move_into(&integrity_only_record_protocol->data_sb, - unprotected_slices); - return TSI_OK; -} - -static void alts_grpc_integrity_only_destruct(alts_grpc_record_protocol* rp) { - if (rp == nullptr) { - return; - } - alts_grpc_integrity_only_record_protocol* integrity_only_rp = - reinterpret_cast(rp); - grpc_slice_buffer_destroy_internal(&integrity_only_rp->data_sb); - gpr_free(integrity_only_rp->tag_buf); -} - -static const alts_grpc_record_protocol_vtable - alts_grpc_integrity_only_record_protocol_vtable = { - alts_grpc_integrity_only_protect, alts_grpc_integrity_only_unprotect, - alts_grpc_integrity_only_destruct}; - -tsi_result alts_grpc_integrity_only_record_protocol_create( - gsec_aead_crypter* crypter, size_t overflow_size, bool is_client, - bool is_protect, alts_grpc_record_protocol** rp) { - if (crypter == nullptr || rp == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr arguments to alts_grpc_record_protocol create."); - return TSI_INVALID_ARGUMENT; - } - alts_grpc_integrity_only_record_protocol* impl = - static_cast( - gpr_zalloc(sizeof(alts_grpc_integrity_only_record_protocol))); - /* Calls alts_grpc_record_protocol init. */ - tsi_result result = alts_grpc_record_protocol_init( - &impl->base, crypter, overflow_size, is_client, - /*is_integrity_only=*/true, is_protect); - if (result != TSI_OK) { - gpr_free(impl); - return result; - } - /* Initializes slice buffer for data_sb. */ - grpc_slice_buffer_init(&impl->data_sb); - /* Allocates tag buffer. */ - impl->tag_buf = - static_cast(gpr_malloc(impl->base.tag_length)); - impl->base.vtable = &alts_grpc_integrity_only_record_protocol_vtable; - *rp = &impl->base; - return TSI_OK; -} diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h deleted file mode 100644 index 8d68b27e07..0000000000 --- a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_INTEGRITY_ONLY_RECORD_PROTOCOL_H -#define GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_INTEGRITY_ONLY_RECORD_PROTOCOL_H - -#include - -#include - -#include "src/core/tsi/alts/crypt/gsec.h" -#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h" - -/** - * This method creates an integrity-only alts_grpc_record_protocol instance, - * given a gsec_aead_crypter instance and a flag indicating if the created - * instance will be used at the client or server side. The ownership of - * gsec_aead_crypter instance is transferred to this new object. - * - * - crypter: a gsec_aead_crypter instance used to perform AEAD decryption. - * - overflow_size: overflow size of counter in bytes. - * - is_client: a flag indicating if the alts_grpc_record_protocol instance will - * be used at the client or server side. - * - is_protect: a flag indicating if the alts_grpc_record_protocol instance - * will be used for protect or unprotect. - * - rp: an alts_grpc_record_protocol instance to be returned from - * the method. - * - * This method returns TSI_OK in case of success or a specific error code in - * case of failure. - */ -tsi_result alts_grpc_integrity_only_record_protocol_create( - gsec_aead_crypter* crypter, size_t overflow_size, bool is_client, - bool is_protect, alts_grpc_record_protocol** rp); - -#endif /* GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_INTEGRITY_ONLY_RECORD_PROTOCOL_H \ - */ diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc deleted file mode 100644 index d4fd88d1e2..0000000000 --- a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc +++ /dev/null @@ -1,144 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h" - -#include -#include - -#include "src/core/lib/slice/slice_internal.h" -#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h" -#include "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h" - -/* Privacy-integrity alts_grpc_record_protocol object uses the same struct - * defined in alts_grpc_record_protocol_common.h. */ - -/* --- alts_grpc_record_protocol methods implementation. --- */ - -static tsi_result alts_grpc_privacy_integrity_protect( - alts_grpc_record_protocol* rp, grpc_slice_buffer* unprotected_slices, - grpc_slice_buffer* protected_slices) { - /* Input sanity check. */ - if (rp == nullptr || unprotected_slices == nullptr || - protected_slices == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr arguments to alts_grpc_record_protocol protect."); - return TSI_INVALID_ARGUMENT; - } - /* Allocates memory for output frame. In privacy-integrity protect, the - * protected frame is stored in a newly allocated buffer. */ - size_t protected_frame_size = - unprotected_slices->length + rp->header_length + - alts_iovec_record_protocol_get_tag_length(rp->iovec_rp); - grpc_slice protected_slice = GRPC_SLICE_MALLOC(protected_frame_size); - iovec_t protected_iovec = {GRPC_SLICE_START_PTR(protected_slice), - GRPC_SLICE_LENGTH(protected_slice)}; - /* Calls alts_iovec_record_protocol protect. */ - char* error_details = nullptr; - alts_grpc_record_protocol_convert_slice_buffer_to_iovec(rp, - unprotected_slices); - grpc_status_code status = - alts_iovec_record_protocol_privacy_integrity_protect( - rp->iovec_rp, rp->iovec_buf, unprotected_slices->count, - protected_iovec, &error_details); - if (status != GRPC_STATUS_OK) { - gpr_log(GPR_ERROR, "Failed to protect, %s", error_details); - gpr_free(error_details); - grpc_slice_unref(protected_slice); - return TSI_INTERNAL_ERROR; - } - grpc_slice_buffer_add(protected_slices, protected_slice); - grpc_slice_buffer_reset_and_unref_internal(unprotected_slices); - return TSI_OK; -} - -static tsi_result alts_grpc_privacy_integrity_unprotect( - alts_grpc_record_protocol* rp, grpc_slice_buffer* protected_slices, - grpc_slice_buffer* unprotected_slices) { - /* Input sanity check. */ - if (rp == nullptr || protected_slices == nullptr || - unprotected_slices == nullptr) { - gpr_log( - GPR_ERROR, - "Invalid nullptr arguments to alts_grpc_record_protocol unprotect."); - return TSI_INVALID_ARGUMENT; - } - /* Allocates memory for output frame. In privacy-integrity unprotect, the - * unprotected data are stored in a newly allocated buffer. */ - if (protected_slices->length < rp->header_length + rp->tag_length) { - gpr_log(GPR_ERROR, "Protected slices do not have sufficient data."); - return TSI_INVALID_ARGUMENT; - } - size_t unprotected_frame_size = - protected_slices->length - rp->header_length - rp->tag_length; - grpc_slice unprotected_slice = GRPC_SLICE_MALLOC(unprotected_frame_size); - iovec_t unprotected_iovec = {GRPC_SLICE_START_PTR(unprotected_slice), - GRPC_SLICE_LENGTH(unprotected_slice)}; - /* Strips frame header from protected slices. */ - grpc_slice_buffer_reset_and_unref_internal(&rp->header_sb); - grpc_slice_buffer_move_first(protected_slices, rp->header_length, - &rp->header_sb); - iovec_t header_iovec = alts_grpc_record_protocol_get_header_iovec(rp); - /* Calls alts_iovec_record_protocol unprotect. */ - char* error_details = nullptr; - alts_grpc_record_protocol_convert_slice_buffer_to_iovec(rp, protected_slices); - grpc_status_code status = - alts_iovec_record_protocol_privacy_integrity_unprotect( - rp->iovec_rp, header_iovec, rp->iovec_buf, protected_slices->count, - unprotected_iovec, &error_details); - if (status != GRPC_STATUS_OK) { - gpr_log(GPR_ERROR, "Failed to unprotect, %s", error_details); - gpr_free(error_details); - grpc_slice_unref(unprotected_slice); - return TSI_INTERNAL_ERROR; - } - grpc_slice_buffer_reset_and_unref_internal(&rp->header_sb); - grpc_slice_buffer_reset_and_unref_internal(protected_slices); - grpc_slice_buffer_add(unprotected_slices, unprotected_slice); - return TSI_OK; -} - -static const alts_grpc_record_protocol_vtable - alts_grpc_privacy_integrity_record_protocol_vtable = { - alts_grpc_privacy_integrity_protect, - alts_grpc_privacy_integrity_unprotect, nullptr}; - -tsi_result alts_grpc_privacy_integrity_record_protocol_create( - gsec_aead_crypter* crypter, size_t overflow_size, bool is_client, - bool is_protect, alts_grpc_record_protocol** rp) { - if (crypter == nullptr || rp == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr arguments to alts_grpc_record_protocol create."); - return TSI_INVALID_ARGUMENT; - } - auto* impl = static_cast( - gpr_zalloc(sizeof(alts_grpc_record_protocol))); - /* Calls alts_grpc_record_protocol init. */ - tsi_result result = - alts_grpc_record_protocol_init(impl, crypter, overflow_size, is_client, - /*is_integrity_only=*/false, is_protect); - if (result != TSI_OK) { - gpr_free(impl); - return result; - } - impl->vtable = &alts_grpc_privacy_integrity_record_protocol_vtable; - *rp = impl; - return TSI_OK; -} diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h deleted file mode 100644 index 1e34aef2d8..0000000000 --- a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_PRIVACY_INTEGRITY_RECORD_PROTOCOL_H -#define GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_PRIVACY_INTEGRITY_RECORD_PROTOCOL_H - -#include - -#include - -#include "src/core/tsi/alts/crypt/gsec.h" -#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h" - -/** - * This method creates a privacy-integrity alts_grpc_record_protocol instance, - * given a gsec_aead_crypter instance and a flag indicating if the created - * instance will be used at the client or server side. The ownership of - * gsec_aead_crypter instance is transferred to this new object. - * - * - crypter: a gsec_aead_crypter instance used to perform AEAD decryption. - * - is_client: a flag indicating if the alts_grpc_record_protocol instance will - * be used at the client or server side. - * - rp: an alts_grpc_record_protocol instance to be returned from - * the method. - * - * This method returns TSI_OK in case of success or a specific error code in - * case of failure. - */ -tsi_result alts_grpc_privacy_integrity_record_protocol_create( - gsec_aead_crypter* crypter, size_t overflow_size, bool is_client, - bool is_protect, alts_grpc_record_protocol** rp); - -#endif /* GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_PRIVACY_INTEGRITY_RECORD_PROTOCOL_H \ - */ diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h deleted file mode 100644 index d1e433dac4..0000000000 --- a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_RECORD_PROTOCOL_H -#define GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_RECORD_PROTOCOL_H - -#include - -#include - -#include "src/core/tsi/transport_security_interface.h" - -/** - * This alts_grpc_record_protocol object protects and unprotects a single frame - * stored in grpc slice buffer with zero or minimized memory copy. - * Implementations of this object must be thread compatible. - */ -typedef struct alts_grpc_record_protocol alts_grpc_record_protocol; - -/** - * This methods performs protect operation on unprotected data and appends the - * protected frame to protected_slices. The caller needs to ensure the length - * of unprotected data plus the frame overhead is less than or equal to the - * maximum frame length. The input unprotected data slice buffer will be - * cleared, although the actual unprotected data bytes are not modified. - * - * - self: an alts_grpc_record_protocol instance. - * - unprotected_slices: the unprotected data to be protected. - * - protected_slices: slice buffer where the protected frame is appended. - * - * This method returns TSI_OK in case of success or a specific error code in - * case of failure. - */ -tsi_result alts_grpc_record_protocol_protect( - alts_grpc_record_protocol* self, grpc_slice_buffer* unprotected_slices, - grpc_slice_buffer* protected_slices); - -/** - * This methods performs unprotect operation on a full frame of protected data - * and appends unprotected data to unprotected_slices. It is the caller's - * responsibility to prepare a full frame of data before calling this method. - * The input protected frame slice buffer will be cleared, although the actual - * protected data bytes are not modified. - * - * - self: an alts_grpc_record_protocol instance. - * - protected_slices: a full frame of protected data in grpc slices. - * - unprotected_slices: slice buffer where unprotected data is appended. - * - * This method returns TSI_OK in case of success or a specific error code in - * case of failure. - */ -tsi_result alts_grpc_record_protocol_unprotect( - alts_grpc_record_protocol* self, grpc_slice_buffer* protected_slices, - grpc_slice_buffer* unprotected_slices); - -/** - * This method returns maximum allowed unprotected data size, given maximum - * protected frame size. - * - * - self: an alts_grpc_record_protocol instance. - * - max_protected_frame_size: maximum protected frame size. - * - * On success, the method returns the maximum allowed unprotected data size. - * Otherwise, it returns zero. - */ -size_t alts_grpc_record_protocol_max_unprotected_data_size( - const alts_grpc_record_protocol* self, size_t max_protected_frame_size); - -/** - * This method destroys an alts_grpc_record_protocol instance by de-allocating - * all of its occupied memory. - */ -void alts_grpc_record_protocol_destroy(alts_grpc_record_protocol* self); - -#endif /* GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_RECORD_PROTOCOL_H \ - */ diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc deleted file mode 100644 index ff91aea350..0000000000 --- a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc +++ /dev/null @@ -1,173 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h" - -#include - -#include -#include - -#include "src/core/lib/gpr/useful.h" -#include "src/core/lib/slice/slice_internal.h" - -const size_t kInitialIovecBufferSize = 8; - -/* Makes sure iovec_buf in alts_grpc_record_protocol is large enough. */ -static void ensure_iovec_buf_size(alts_grpc_record_protocol* rp, - const grpc_slice_buffer* sb) { - GPR_ASSERT(rp != nullptr && sb != nullptr); - if (sb->count <= rp->iovec_buf_length) { - return; - } - /* At least double the iovec buffer size. */ - rp->iovec_buf_length = GPR_MAX(sb->count, 2 * rp->iovec_buf_length); - rp->iovec_buf = static_cast( - gpr_realloc(rp->iovec_buf, rp->iovec_buf_length * sizeof(iovec_t))); -} - -/* --- Implementation of methods defined in tsi_grpc_record_protocol_common.h. - * --- */ - -void alts_grpc_record_protocol_convert_slice_buffer_to_iovec( - alts_grpc_record_protocol* rp, const grpc_slice_buffer* sb) { - GPR_ASSERT(rp != nullptr && sb != nullptr); - ensure_iovec_buf_size(rp, sb); - for (size_t i = 0; i < sb->count; i++) { - rp->iovec_buf[i].iov_base = GRPC_SLICE_START_PTR(sb->slices[i]); - rp->iovec_buf[i].iov_len = GRPC_SLICE_LENGTH(sb->slices[i]); - } -} - -void alts_grpc_record_protocol_copy_slice_buffer(const grpc_slice_buffer* src, - unsigned char* dst) { - GPR_ASSERT(src != nullptr && dst != nullptr); - for (size_t i = 0; i < src->count; i++) { - size_t slice_length = GRPC_SLICE_LENGTH(src->slices[i]); - memcpy(dst, GRPC_SLICE_START_PTR(src->slices[i]), slice_length); - dst += slice_length; - } -} - -iovec_t alts_grpc_record_protocol_get_header_iovec( - alts_grpc_record_protocol* rp) { - iovec_t header_iovec = {nullptr, 0}; - if (rp == nullptr) { - return header_iovec; - } - header_iovec.iov_len = rp->header_length; - if (rp->header_sb.count == 1) { - header_iovec.iov_base = GRPC_SLICE_START_PTR(rp->header_sb.slices[0]); - } else { - /* Frame header is in multiple slices, copies the header bytes from slice - * buffer to a single flat buffer. */ - alts_grpc_record_protocol_copy_slice_buffer(&rp->header_sb, rp->header_buf); - header_iovec.iov_base = rp->header_buf; - } - return header_iovec; -} - -tsi_result alts_grpc_record_protocol_init(alts_grpc_record_protocol* rp, - gsec_aead_crypter* crypter, - size_t overflow_size, bool is_client, - bool is_integrity_only, - bool is_protect) { - if (rp == nullptr || crypter == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr arguments to alts_grpc_record_protocol init."); - return TSI_INVALID_ARGUMENT; - } - /* Creates alts_iovec_record_protocol. */ - char* error_details = nullptr; - grpc_status_code status = alts_iovec_record_protocol_create( - crypter, overflow_size, is_client, is_integrity_only, is_protect, - &rp->iovec_rp, &error_details); - if (status != GRPC_STATUS_OK) { - gpr_log(GPR_ERROR, "Failed to create alts_iovec_record_protocol, %s.", - error_details); - gpr_free(error_details); - return TSI_INTERNAL_ERROR; - } - /* Allocates header slice buffer. */ - grpc_slice_buffer_init(&rp->header_sb); - /* Allocates header buffer. */ - rp->header_length = alts_iovec_record_protocol_get_header_length(); - rp->header_buf = static_cast(gpr_malloc(rp->header_length)); - rp->tag_length = alts_iovec_record_protocol_get_tag_length(rp->iovec_rp); - /* Allocates iovec buffer. */ - rp->iovec_buf_length = kInitialIovecBufferSize; - rp->iovec_buf = - static_cast(gpr_malloc(rp->iovec_buf_length * sizeof(iovec_t))); - return TSI_OK; -} - -/* --- Implementation of methods defined in tsi_grpc_record_protocol.h. --- */ -tsi_result alts_grpc_record_protocol_protect( - alts_grpc_record_protocol* self, grpc_slice_buffer* unprotected_slices, - grpc_slice_buffer* protected_slices) { - if (grpc_core::ExecCtx::Get() == nullptr || self == nullptr || - self->vtable == nullptr || unprotected_slices == nullptr || - protected_slices == nullptr) { - return TSI_INVALID_ARGUMENT; - } - if (self->vtable->protect == nullptr) { - return TSI_UNIMPLEMENTED; - } - return self->vtable->protect(self, unprotected_slices, protected_slices); -} - -tsi_result alts_grpc_record_protocol_unprotect( - alts_grpc_record_protocol* self, grpc_slice_buffer* protected_slices, - grpc_slice_buffer* unprotected_slices) { - if (grpc_core::ExecCtx::Get() == nullptr || self == nullptr || - self->vtable == nullptr || protected_slices == nullptr || - unprotected_slices == nullptr) { - return TSI_INVALID_ARGUMENT; - } - if (self->vtable->unprotect == nullptr) { - return TSI_UNIMPLEMENTED; - } - return self->vtable->unprotect(self, protected_slices, unprotected_slices); -} - -void alts_grpc_record_protocol_destroy(alts_grpc_record_protocol* self) { - if (self == nullptr) { - return; - } - if (self->vtable->destruct != nullptr) { - self->vtable->destruct(self); - } - alts_iovec_record_protocol_destroy(self->iovec_rp); - grpc_slice_buffer_destroy_internal(&self->header_sb); - gpr_free(self->header_buf); - gpr_free(self->iovec_buf); - gpr_free(self); -} - -/* Integrity-only and privacy-integrity share the same implementation. No need - * to call vtable. */ -size_t alts_grpc_record_protocol_max_unprotected_data_size( - const alts_grpc_record_protocol* self, size_t max_protected_frame_size) { - if (self == nullptr) { - return 0; - } - return alts_iovec_record_protocol_max_unprotected_data_size( - self->iovec_rp, max_protected_frame_size); -} diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h deleted file mode 100644 index 43b8a4a2b8..0000000000 --- a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_RECORD_PROTOCOL_COMMON_H -#define GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_RECORD_PROTOCOL_COMMON_H - -/** - * this file contains alts_grpc_record_protocol internals and internal-only - * helper functions. The public functions of alts_grpc_record_protocol are - * defined in the alts_grpc_record_protocol.h. - */ - -#include - -#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h" -#include "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h" - -/* V-table for alts_grpc_record_protocol implementations. */ -typedef struct { - tsi_result (*protect)(alts_grpc_record_protocol* self, - grpc_slice_buffer* unprotected_slices, - grpc_slice_buffer* protected_slices); - tsi_result (*unprotect)(alts_grpc_record_protocol* self, - grpc_slice_buffer* protected_slices, - grpc_slice_buffer* unprotected_slices); - void (*destruct)(alts_grpc_record_protocol* self); -} alts_grpc_record_protocol_vtable; - -/* Main struct for alts_grpc_record_protocol implementation, shared by both - * integrity-only record protocol and privacy-integrity record protocol. - * Integrity-only record protocol has additional data elements. - * Privacy-integrity record protocol uses this struct directly. */ -struct alts_grpc_record_protocol { - const alts_grpc_record_protocol_vtable* vtable; - alts_iovec_record_protocol* iovec_rp; - grpc_slice_buffer header_sb; - unsigned char* header_buf; - size_t header_length; - size_t tag_length; - iovec_t* iovec_buf; - size_t iovec_buf_length; -}; - -/** - * Converts the slices of input sb into iovec_t's and puts the result into - * rp->iovec_buf. Note that the actual data are not copied, only - * pointers and lengths are copied. - */ -void alts_grpc_record_protocol_convert_slice_buffer_to_iovec( - alts_grpc_record_protocol* rp, const grpc_slice_buffer* sb); - -/** - * Copies bytes from slice buffer to destination buffer. Caller is responsible - * for allocating enough memory of destination buffer. This method is used for - * copying frame header and tag in case they are stored in multiple slices. - */ -void alts_grpc_record_protocol_copy_slice_buffer(const grpc_slice_buffer* src, - unsigned char* dst); - -/** - * This method returns an iovec object pointing to the frame header stored in - * rp->header_sb. If the frame header is stored in multiple slices, - * this method will copy the bytes in rp->header_sb to - * rp->header_buf, and return an iovec object pointing to - * rp->header_buf. - */ -iovec_t alts_grpc_record_protocol_get_header_iovec( - alts_grpc_record_protocol* rp); - -/** - * Initializes an alts_grpc_record_protocol object, given a gsec_aead_crypter - * instance, the overflow size of the counter in bytes, a flag indicating if the - * object is used for client or server side, a flag indicating if it is used for - * integrity-only or privacy-integrity mode, and a flag indicating if it is for - * protect or unprotect. The ownership of gsec_aead_crypter object is - * transferred to the alts_grpc_record_protocol object. - */ -tsi_result alts_grpc_record_protocol_init(alts_grpc_record_protocol* rp, - gsec_aead_crypter* crypter, - size_t overflow_size, bool is_client, - bool is_integrity_only, - bool is_protect); - -#endif /* GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_RECORD_PROTOCOL_COMMON_H \ - */ diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc b/src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc deleted file mode 100644 index 6a548e50dd..0000000000 --- a/src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc +++ /dev/null @@ -1,476 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h" - -#include -#include - -#include -#include - -#include "src/core/tsi/alts/frame_protector/alts_counter.h" - -struct alts_iovec_record_protocol { - alts_counter* ctr; - gsec_aead_crypter* crypter; - size_t tag_length; - bool is_integrity_only; - bool is_protect; -}; - -/* Copies error message to destination. */ -static void maybe_copy_error_msg(const char* src, char** dst) { - if (dst != nullptr && src != nullptr) { - *dst = static_cast(gpr_malloc(strlen(src) + 1)); - memcpy(*dst, src, strlen(src) + 1); - } -} - -/* Appends error message to destination. */ -static void maybe_append_error_msg(const char* appendix, char** dst) { - if (dst != nullptr && appendix != nullptr) { - int dst_len = static_cast(strlen(*dst)); - *dst = static_cast(realloc(*dst, dst_len + strlen(appendix) + 1)); - assert(*dst != nullptr); - memcpy(*dst + dst_len, appendix, strlen(appendix) + 1); - } -} - -/* Use little endian to interpret a string of bytes as uint32_t. */ -static uint32_t load_32_le(const unsigned char* buffer) { - return (((uint32_t)buffer[3]) << 24) | (((uint32_t)buffer[2]) << 16) | - (((uint32_t)buffer[1]) << 8) | ((uint32_t)buffer[0]); -} - -/* Store uint32_t as a string of little endian bytes. */ -static void store_32_le(uint32_t value, unsigned char* buffer) { - buffer[3] = (unsigned char)(value >> 24) & 0xFF; - buffer[2] = (unsigned char)(value >> 16) & 0xFF; - buffer[1] = (unsigned char)(value >> 8) & 0xFF; - buffer[0] = (unsigned char)(value)&0xFF; -} - -/* Ensures header and tag iovec have sufficient length. */ -static grpc_status_code ensure_header_and_tag_length( - const alts_iovec_record_protocol* rp, iovec_t header, iovec_t tag, - char** error_details) { - if (rp == nullptr) { - return GRPC_STATUS_FAILED_PRECONDITION; - } - if (header.iov_base == nullptr) { - maybe_copy_error_msg("Header is nullptr.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - if (header.iov_len != alts_iovec_record_protocol_get_header_length()) { - maybe_copy_error_msg("Header length is incorrect.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - if (tag.iov_base == nullptr) { - maybe_copy_error_msg("Tag is nullptr.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - if (tag.iov_len != rp->tag_length) { - maybe_copy_error_msg("Tag length is incorrect.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - return GRPC_STATUS_OK; -} - -/* Increments crypter counter and checks overflow. */ -static grpc_status_code increment_counter(alts_counter* counter, - char** error_details) { - if (counter == nullptr) { - return GRPC_STATUS_FAILED_PRECONDITION; - } - bool is_overflow = false; - grpc_status_code status = - alts_counter_increment(counter, &is_overflow, error_details); - if (status != GRPC_STATUS_OK) { - return status; - } - if (is_overflow) { - maybe_copy_error_msg("Crypter counter is overflowed.", error_details); - return GRPC_STATUS_INTERNAL; - } - return GRPC_STATUS_OK; -} - -/* Given an array of iovec, computes the total length of buffer. */ -static size_t get_total_length(const iovec_t* vec, size_t vec_length) { - size_t total_length = 0; - for (size_t i = 0; i < vec_length; ++i) { - total_length += vec[i].iov_len; - } - return total_length; -} - -/* Writes frame header given data and tag length. */ -static grpc_status_code write_frame_header(size_t data_length, - unsigned char* header, - char** error_details) { - if (header == nullptr) { - maybe_copy_error_msg("Header is nullptr.", error_details); - return GRPC_STATUS_FAILED_PRECONDITION; - } - size_t frame_length = kZeroCopyFrameMessageTypeFieldSize + data_length; - store_32_le(static_cast(frame_length), header); - store_32_le(kZeroCopyFrameMessageType, - header + kZeroCopyFrameLengthFieldSize); - return GRPC_STATUS_OK; -} - -/* Verifies frame header given protected data length. */ -static grpc_status_code verify_frame_header(size_t data_length, - unsigned char* header, - char** error_details) { - if (header == nullptr) { - maybe_copy_error_msg("Header is nullptr.", error_details); - return GRPC_STATUS_FAILED_PRECONDITION; - } - size_t frame_length = load_32_le(header); - if (frame_length != kZeroCopyFrameMessageTypeFieldSize + data_length) { - maybe_copy_error_msg("Bad frame length.", error_details); - return GRPC_STATUS_INTERNAL; - } - size_t message_type = load_32_le(header + kZeroCopyFrameLengthFieldSize); - if (message_type != kZeroCopyFrameMessageType) { - maybe_copy_error_msg("Unsupported message type.", error_details); - return GRPC_STATUS_INTERNAL; - } - return GRPC_STATUS_OK; -} - -/* --- alts_iovec_record_protocol methods implementation. --- */ - -size_t alts_iovec_record_protocol_get_header_length() { - return kZeroCopyFrameHeaderSize; -} - -size_t alts_iovec_record_protocol_get_tag_length( - const alts_iovec_record_protocol* rp) { - if (rp != nullptr) { - return rp->tag_length; - } - return 0; -} - -size_t alts_iovec_record_protocol_max_unprotected_data_size( - const alts_iovec_record_protocol* rp, size_t max_protected_frame_size) { - if (rp == nullptr) { - return 0; - } - size_t overhead_bytes_size = - kZeroCopyFrameMessageTypeFieldSize + rp->tag_length; - if (max_protected_frame_size <= overhead_bytes_size) return 0; - return max_protected_frame_size - overhead_bytes_size; -} - -grpc_status_code alts_iovec_record_protocol_integrity_only_protect( - alts_iovec_record_protocol* rp, const iovec_t* unprotected_vec, - size_t unprotected_vec_length, iovec_t header, iovec_t tag, - char** error_details) { - /* Input sanity checks. */ - if (rp == nullptr) { - maybe_copy_error_msg("Input iovec_record_protocol is nullptr.", - error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - if (!rp->is_integrity_only) { - maybe_copy_error_msg( - "Integrity-only operations are not allowed for this object.", - error_details); - return GRPC_STATUS_FAILED_PRECONDITION; - } - if (!rp->is_protect) { - maybe_copy_error_msg("Protect operations are not allowed for this object.", - error_details); - return GRPC_STATUS_FAILED_PRECONDITION; - } - grpc_status_code status = - ensure_header_and_tag_length(rp, header, tag, error_details); - if (status != GRPC_STATUS_OK) { - return status; - } - /* Unprotected data should not be zero length. */ - size_t data_length = - get_total_length(unprotected_vec, unprotected_vec_length); - /* Sets frame header. */ - status = write_frame_header(data_length + rp->tag_length, - static_cast(header.iov_base), - error_details); - if (status != GRPC_STATUS_OK) { - return status; - } - /* Computes frame tag by calling AEAD crypter. */ - size_t bytes_written = 0; - status = gsec_aead_crypter_encrypt_iovec( - rp->crypter, alts_counter_get_counter(rp->ctr), - alts_counter_get_size(rp->ctr), unprotected_vec, unprotected_vec_length, - /* plaintext_vec = */ nullptr, /* plaintext_vec_length = */ 0, tag, - &bytes_written, error_details); - if (status != GRPC_STATUS_OK) { - return status; - } - if (bytes_written != rp->tag_length) { - maybe_copy_error_msg("Bytes written expects to be the same as tag length.", - error_details); - return GRPC_STATUS_INTERNAL; - } - /* Increments the crypter counter. */ - return increment_counter(rp->ctr, error_details); -} - -grpc_status_code alts_iovec_record_protocol_integrity_only_unprotect( - alts_iovec_record_protocol* rp, const iovec_t* protected_vec, - size_t protected_vec_length, iovec_t header, iovec_t tag, - char** error_details) { - /* Input sanity checks. */ - if (rp == nullptr) { - maybe_copy_error_msg("Input iovec_record_protocol is nullptr.", - error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - if (!rp->is_integrity_only) { - maybe_copy_error_msg( - "Integrity-only operations are not allowed for this object.", - error_details); - return GRPC_STATUS_FAILED_PRECONDITION; - } - if (rp->is_protect) { - maybe_copy_error_msg( - "Unprotect operations are not allowed for this object.", error_details); - return GRPC_STATUS_FAILED_PRECONDITION; - } - grpc_status_code status = - ensure_header_and_tag_length(rp, header, tag, error_details); - if (status != GRPC_STATUS_OK) return status; - /* Protected data should not be zero length. */ - size_t data_length = get_total_length(protected_vec, protected_vec_length); - /* Verifies frame header. */ - status = verify_frame_header(data_length + rp->tag_length, - static_cast(header.iov_base), - error_details); - if (status != GRPC_STATUS_OK) { - return status; - } - /* Verifies frame tag by calling AEAD crypter. */ - iovec_t plaintext = {nullptr, 0}; - size_t bytes_written = 0; - status = gsec_aead_crypter_decrypt_iovec( - rp->crypter, alts_counter_get_counter(rp->ctr), - alts_counter_get_size(rp->ctr), protected_vec, protected_vec_length, &tag, - 1, plaintext, &bytes_written, error_details); - if (status != GRPC_STATUS_OK || bytes_written != 0) { - maybe_append_error_msg(" Frame tag verification failed.", error_details); - return GRPC_STATUS_INTERNAL; - } - /* Increments the crypter counter. */ - return increment_counter(rp->ctr, error_details); -} - -grpc_status_code alts_iovec_record_protocol_privacy_integrity_protect( - alts_iovec_record_protocol* rp, const iovec_t* unprotected_vec, - size_t unprotected_vec_length, iovec_t protected_frame, - char** error_details) { - /* Input sanity checks. */ - if (rp == nullptr) { - maybe_copy_error_msg("Input iovec_record_protocol is nullptr.", - error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - if (rp->is_integrity_only) { - maybe_copy_error_msg( - "Privacy-integrity operations are not allowed for this object.", - error_details); - return GRPC_STATUS_FAILED_PRECONDITION; - } - if (!rp->is_protect) { - maybe_copy_error_msg("Protect operations are not allowed for this object.", - error_details); - return GRPC_STATUS_FAILED_PRECONDITION; - } - /* Unprotected data should not be zero length. */ - size_t data_length = - get_total_length(unprotected_vec, unprotected_vec_length); - /* Ensures protected frame iovec has sufficient size. */ - if (protected_frame.iov_base == nullptr) { - maybe_copy_error_msg("Protected frame is nullptr.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - if (protected_frame.iov_len != - alts_iovec_record_protocol_get_header_length() + data_length + - rp->tag_length) { - maybe_copy_error_msg("Protected frame size is incorrect.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - /* Writer frame header. */ - grpc_status_code status = write_frame_header( - data_length + rp->tag_length, - static_cast(protected_frame.iov_base), error_details); - if (status != GRPC_STATUS_OK) { - return status; - } - /* Encrypt unprotected data by calling AEAD crypter. */ - unsigned char* ciphertext_buffer = - static_cast(protected_frame.iov_base) + - alts_iovec_record_protocol_get_header_length(); - iovec_t ciphertext = {ciphertext_buffer, data_length + rp->tag_length}; - size_t bytes_written = 0; - status = gsec_aead_crypter_encrypt_iovec( - rp->crypter, alts_counter_get_counter(rp->ctr), - alts_counter_get_size(rp->ctr), /* aad_vec = */ nullptr, - /* aad_vec_length = */ 0, unprotected_vec, unprotected_vec_length, - ciphertext, &bytes_written, error_details); - if (status != GRPC_STATUS_OK) { - return status; - } - if (bytes_written != data_length + rp->tag_length) { - maybe_copy_error_msg( - "Bytes written expects to be data length plus tag length.", - error_details); - return GRPC_STATUS_INTERNAL; - } - /* Increments the crypter counter. */ - return increment_counter(rp->ctr, error_details); -} - -grpc_status_code alts_iovec_record_protocol_privacy_integrity_unprotect( - alts_iovec_record_protocol* rp, iovec_t header, - const iovec_t* protected_vec, size_t protected_vec_length, - iovec_t unprotected_data, char** error_details) { - /* Input sanity checks. */ - if (rp == nullptr) { - maybe_copy_error_msg("Input iovec_record_protocol is nullptr.", - error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - if (rp->is_integrity_only) { - maybe_copy_error_msg( - "Privacy-integrity operations are not allowed for this object.", - error_details); - return GRPC_STATUS_FAILED_PRECONDITION; - } - if (rp->is_protect) { - maybe_copy_error_msg( - "Unprotect operations are not allowed for this object.", error_details); - return GRPC_STATUS_FAILED_PRECONDITION; - } - /* Protected data size should be no less than tag size. */ - size_t protected_data_length = - get_total_length(protected_vec, protected_vec_length); - if (protected_data_length < rp->tag_length) { - maybe_copy_error_msg( - "Protected data length should be more than the tag length.", - error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - /* Ensures header has sufficient size. */ - if (header.iov_base == nullptr) { - maybe_copy_error_msg("Header is nullptr.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - if (header.iov_len != alts_iovec_record_protocol_get_header_length()) { - maybe_copy_error_msg("Header length is incorrect.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - /* Ensures unprotected data iovec has sufficient size. */ - if (unprotected_data.iov_len != protected_data_length - rp->tag_length) { - maybe_copy_error_msg("Unprotected data size is incorrect.", error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - /* Verify frame header. */ - grpc_status_code status = verify_frame_header( - protected_data_length, static_cast(header.iov_base), - error_details); - if (status != GRPC_STATUS_OK) { - return status; - } - /* Decrypt protected data by calling AEAD crypter. */ - size_t bytes_written = 0; - status = gsec_aead_crypter_decrypt_iovec( - rp->crypter, alts_counter_get_counter(rp->ctr), - alts_counter_get_size(rp->ctr), /* aad_vec = */ nullptr, - /* aad_vec_length = */ 0, protected_vec, protected_vec_length, - unprotected_data, &bytes_written, error_details); - if (status != GRPC_STATUS_OK) { - maybe_append_error_msg(" Frame decryption failed.", error_details); - return GRPC_STATUS_INTERNAL; - } - if (bytes_written != protected_data_length - rp->tag_length) { - maybe_copy_error_msg( - "Bytes written expects to be protected data length minus tag length.", - error_details); - return GRPC_STATUS_INTERNAL; - } - /* Increments the crypter counter. */ - return increment_counter(rp->ctr, error_details); -} - -grpc_status_code alts_iovec_record_protocol_create( - gsec_aead_crypter* crypter, size_t overflow_size, bool is_client, - bool is_integrity_only, bool is_protect, alts_iovec_record_protocol** rp, - char** error_details) { - if (crypter == nullptr || rp == nullptr) { - maybe_copy_error_msg( - "Invalid nullptr arguments to alts_iovec_record_protocol create.", - error_details); - return GRPC_STATUS_INVALID_ARGUMENT; - } - alts_iovec_record_protocol* impl = static_cast( - gpr_zalloc(sizeof(alts_iovec_record_protocol))); - /* Gets counter length. */ - size_t counter_length = 0; - grpc_status_code status = - gsec_aead_crypter_nonce_length(crypter, &counter_length, error_details); - if (status != GRPC_STATUS_OK) { - goto cleanup; - } - /* Creates counters. */ - status = - alts_counter_create(is_protect ? !is_client : is_client, counter_length, - overflow_size, &impl->ctr, error_details); - if (status != GRPC_STATUS_OK) { - goto cleanup; - } - /* Gets tag length. */ - status = - gsec_aead_crypter_tag_length(crypter, &impl->tag_length, error_details); - if (status != GRPC_STATUS_OK) { - goto cleanup; - } - impl->crypter = crypter; - impl->is_integrity_only = is_integrity_only; - impl->is_protect = is_protect; - *rp = impl; - return GRPC_STATUS_OK; -cleanup: - alts_counter_destroy(impl->ctr); - gpr_free(impl); - return GRPC_STATUS_FAILED_PRECONDITION; -} - -void alts_iovec_record_protocol_destroy(alts_iovec_record_protocol* rp) { - if (rp != nullptr) { - alts_counter_destroy(rp->ctr); - gsec_aead_crypter_destroy(rp->crypter); - gpr_free(rp); - } -} diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h b/src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h deleted file mode 100644 index 0b7d1bf5bf..0000000000 --- a/src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h +++ /dev/null @@ -1,199 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_IOVEC_RECORD_PROTOCOL_H -#define GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_IOVEC_RECORD_PROTOCOL_H - -#include - -#include - -#include "src/core/tsi/alts/crypt/gsec.h" - -constexpr size_t kZeroCopyFrameMessageType = 0x06; -constexpr size_t kZeroCopyFrameLengthFieldSize = 4; -constexpr size_t kZeroCopyFrameMessageTypeFieldSize = 4; -constexpr size_t kZeroCopyFrameHeaderSize = - kZeroCopyFrameLengthFieldSize + kZeroCopyFrameMessageTypeFieldSize; - -// Limit k on number of frames such that at most 2^(8 * k) frames can be sent. -constexpr size_t kAltsRecordProtocolRekeyFrameLimit = 8; -constexpr size_t kAltsRecordProtocolFrameLimit = 5; - -/* An implementation of alts record protocol. The API is thread-compatible. */ - -typedef struct iovec iovec_t; - -typedef struct alts_iovec_record_protocol alts_iovec_record_protocol; - -/** - * This method gets the length of record protocol frame header. - */ -size_t alts_iovec_record_protocol_get_header_length(); - -/** - * This method gets the length of record protocol frame tag. - * - * - rp: an alts_iovec_record_protocol instance. - * - * On success, the method returns the length of record protocol frame tag. - * Otherwise, it returns zero. - */ -size_t alts_iovec_record_protocol_get_tag_length( - const alts_iovec_record_protocol* rp); - -/** - * This method returns maximum allowed unprotected data size, given maximum - * protected frame size. - * - * - rp: an alts_iovec_record_protocol instance. - * - max_protected_frame_size: maximum protected frame size. - * - * On success, the method returns the maximum allowed unprotected data size. - * Otherwise, it returns zero. - */ -size_t alts_iovec_record_protocol_max_unprotected_data_size( - const alts_iovec_record_protocol* rp, size_t max_protected_frame_size); - -/** - * This method performs integrity-only protect operation on a - * alts_iovec_record_protocol instance, i.e., compute frame header and tag. The - * caller needs to allocate the memory for header and tag prior to calling this - * method. - * - * - rp: an alts_iovec_record_protocol instance. - * - unprotected_vec: an iovec array containing unprotected data. - * - unprotected_vec_length: the array length of unprotected_vec. - * - header: an iovec containing the output frame header. - * - tag: an iovec containing the output frame tag. - * - error_details: a buffer containing an error message if the method does not - * function correctly. It is OK to pass nullptr into error_details. - * - * On success, the method returns GRPC_STATUS_OK. Otherwise, it returns an - * error status code along with its details specified in error_details (if - * error_details is not nullptr). - */ -grpc_status_code alts_iovec_record_protocol_integrity_only_protect( - alts_iovec_record_protocol* rp, const iovec_t* unprotected_vec, - size_t unprotected_vec_length, iovec_t header, iovec_t tag, - char** error_details); - -/** - * This method performs integrity-only unprotect operation on a - * alts_iovec_record_protocol instance, i.e., verify frame header and tag. - * - * - rp: an alts_iovec_record_protocol instance. - * - protected_vec: an iovec array containing protected data. - * - protected_vec_length: the array length of protected_vec. - * - header: an iovec containing the frame header. - * - tag: an iovec containing the frame tag. - * - error_details: a buffer containing an error message if the method does not - * function correctly. It is OK to pass nullptr into error_details. - * - * On success, the method returns GRPC_STATUS_OK. Otherwise, it returns an - * error status code along with its details specified in error_details (if - * error_details is not nullptr). - */ -grpc_status_code alts_iovec_record_protocol_integrity_only_unprotect( - alts_iovec_record_protocol* rp, const iovec_t* protected_vec, - size_t protected_vec_length, iovec_t header, iovec_t tag, - char** error_details); - -/** - * This method performs privacy-integrity protect operation on a - * alts_iovec_record_protocol instance, i.e., compute a protected frame. The - * caller needs to allocate the memory for the protected frame prior to calling - * this method. - * - * - rp: an alts_iovec_record_protocol instance. - * - unprotected_vec: an iovec array containing unprotected data. - * - unprotected_vec_length: the array length of unprotected_vec. - * - protected_frame: an iovec containing the output protected frame. - * - error_details: a buffer containing an error message if the method does not - * function correctly. It is OK to pass nullptr into error_details. - * - * On success, the method returns GRPC_STATUS_OK. Otherwise, it returns an - * error status code along with its details specified in error_details (if - * error_details is not nullptr). - */ -grpc_status_code alts_iovec_record_protocol_privacy_integrity_protect( - alts_iovec_record_protocol* rp, const iovec_t* unprotected_vec, - size_t unprotected_vec_length, iovec_t protected_frame, - char** error_details); - -/** - * This method performs privacy-integrity unprotect operation on a - * alts_iovec_record_protocol instance given a full protected frame, i.e., - * compute the unprotected data. The caller needs to allocated the memory for - * the unprotected data prior to calling this method. - * - * - rp: an alts_iovec_record_protocol instance. - * - header: an iovec containing the frame header. - * - protected_vec: an iovec array containing protected data including the tag. - * - protected_vec_length: the array length of protected_vec. - * - unprotected_data: an iovec containing the output unprotected data. - * - error_details: a buffer containing an error message if the method does not - * function correctly. It is OK to pass nullptr into error_details. - * - * On success, the method returns GRPC_STATUS_OK. Otherwise, it returns an - * error status code along with its details specified in error_details (if - * error_details is not nullptr). - */ -grpc_status_code alts_iovec_record_protocol_privacy_integrity_unprotect( - alts_iovec_record_protocol* rp, iovec_t header, - const iovec_t* protected_vec, size_t protected_vec_length, - iovec_t unprotected_data, char** error_details); - -/** - * This method creates an alts_iovec_record_protocol instance, given a - * gsec_aead_crypter instance, a flag indicating if the created instance will be - * used at the client or server side, and a flag indicating if the created - * instance will be used for integrity-only mode or privacy-integrity mode. The - * ownership of gsec_aead_crypter instance is transferred to this new object. - * - * - crypter: a gsec_aead_crypter instance used to perform AEAD decryption. - * - overflow_size: overflow size of counter in bytes. - * - is_client: a flag indicating if the alts_iovec_record_protocol instance - * will be used at the client or server side. - * - is_integrity_only: a flag indicating if the alts_iovec_record_protocol - * instance will be used for integrity-only or privacy-integrity mode. - * - is_protect: a flag indicating if the alts_grpc_record_protocol instance - * will be used for protect or unprotect. - * - rp: an alts_iovec_record_protocol instance to be returned from - * the method. - * - error_details: a buffer containing an error message if the method does not - * function correctly. It is OK to pass nullptr into error_details. - * - * On success, the method returns GRPC_STATUS_OK. Otherwise, it returns an - * error status code along with its details specified in error_details (if - * error_details is not nullptr). - */ -grpc_status_code alts_iovec_record_protocol_create( - gsec_aead_crypter* crypter, size_t overflow_size, bool is_client, - bool is_integrity_only, bool is_protect, alts_iovec_record_protocol** rp, - char** error_details); - -/** - * This method destroys an alts_iovec_record_protocol instance by de-allocating - * all of its occupied memory. A gsec_aead_crypter instance passed in at - * gsec_alts_crypter instance creation time will be destroyed in this method. - */ -void alts_iovec_record_protocol_destroy(alts_iovec_record_protocol* rp); - -#endif /* GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_IOVEC_RECORD_PROTOCOL_H \ - */ diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc b/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc deleted file mode 100644 index 8c764961b3..0000000000 --- a/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +++ /dev/null @@ -1,295 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h" - -#include - -#include -#include - -#include "src/core/lib/gpr/useful.h" -#include "src/core/lib/slice/slice_internal.h" -#include "src/core/tsi/alts/crypt/gsec.h" -#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h" -#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h" -#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h" -#include "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h" -#include "src/core/tsi/transport_security_grpc.h" - -constexpr size_t kMinFrameLength = 1024; -constexpr size_t kDefaultFrameLength = 16 * 1024; -constexpr size_t kMaxFrameLength = 1024 * 1024; - -/** - * Main struct for alts_zero_copy_grpc_protector. - * We choose to have two alts_grpc_record_protocol objects and two sets of slice - * buffers: one for protect and the other for unprotect, so that protect and - * unprotect can be executed in parallel. Implementations of this object must be - * thread compatible. - */ -typedef struct alts_zero_copy_grpc_protector { - tsi_zero_copy_grpc_protector base; - alts_grpc_record_protocol* record_protocol; - alts_grpc_record_protocol* unrecord_protocol; - size_t max_protected_frame_size; - size_t max_unprotected_data_size; - grpc_slice_buffer unprotected_staging_sb; - grpc_slice_buffer protected_sb; - grpc_slice_buffer protected_staging_sb; - uint32_t parsed_frame_size; -} alts_zero_copy_grpc_protector; - -/** - * Given a slice buffer, parses the first 4 bytes little-endian unsigned frame - * size and returns the total frame size including the frame field. Caller - * needs to make sure the input slice buffer has at least 4 bytes. Returns true - * on success and false on failure. - */ -static bool read_frame_size(const grpc_slice_buffer* sb, - uint32_t* total_frame_size) { - if (sb == nullptr || sb->length < kZeroCopyFrameLengthFieldSize) { - return false; - } - uint8_t frame_size_buffer[kZeroCopyFrameLengthFieldSize]; - uint8_t* buf = frame_size_buffer; - /* Copies the first 4 bytes to a temporary buffer. */ - size_t remaining = kZeroCopyFrameLengthFieldSize; - for (size_t i = 0; i < sb->count; i++) { - size_t slice_length = GRPC_SLICE_LENGTH(sb->slices[i]); - if (remaining <= slice_length) { - memcpy(buf, GRPC_SLICE_START_PTR(sb->slices[i]), remaining); - remaining = 0; - break; - } else { - memcpy(buf, GRPC_SLICE_START_PTR(sb->slices[i]), slice_length); - buf += slice_length; - remaining -= slice_length; - } - } - GPR_ASSERT(remaining == 0); - /* Gets little-endian frame size. */ - uint32_t frame_size = (((uint32_t)frame_size_buffer[3]) << 24) | - (((uint32_t)frame_size_buffer[2]) << 16) | - (((uint32_t)frame_size_buffer[1]) << 8) | - ((uint32_t)frame_size_buffer[0]); - if (frame_size > kMaxFrameLength) { - gpr_log(GPR_ERROR, "Frame size is larger than maximum frame size"); - return false; - } - /* Returns frame size including frame length field. */ - *total_frame_size = - static_cast(frame_size + kZeroCopyFrameLengthFieldSize); - return true; -} - -/** - * Creates an alts_grpc_record_protocol object, given key, key size, and flags - * to indicate whether the record_protocol object uses the rekeying AEAD, - * whether the object is for client or server, whether the object is for - * integrity-only or privacy-integrity mode, and whether the object is is used - * for protect or unprotect. - */ -static tsi_result create_alts_grpc_record_protocol( - const uint8_t* key, size_t key_size, bool is_rekey, bool is_client, - bool is_integrity_only, bool is_protect, - alts_grpc_record_protocol** record_protocol) { - if (key == nullptr || record_protocol == nullptr) { - return TSI_INVALID_ARGUMENT; - } - grpc_status_code status; - gsec_aead_crypter* crypter = nullptr; - char* error_details = nullptr; - status = gsec_aes_gcm_aead_crypter_create(key, key_size, kAesGcmNonceLength, - kAesGcmTagLength, is_rekey, - &crypter, &error_details); - if (status != GRPC_STATUS_OK) { - gpr_log(GPR_ERROR, "Failed to create AEAD crypter, %s", error_details); - gpr_free(error_details); - return TSI_INTERNAL_ERROR; - } - size_t overflow_limit = is_rekey ? kAltsRecordProtocolRekeyFrameLimit - : kAltsRecordProtocolFrameLimit; - /* Creates alts_grpc_record_protocol with AEAD crypter ownership transferred. - */ - tsi_result result = - is_integrity_only - ? alts_grpc_integrity_only_record_protocol_create( - crypter, overflow_limit, is_client, is_protect, record_protocol) - : alts_grpc_privacy_integrity_record_protocol_create( - crypter, overflow_limit, is_client, is_protect, - record_protocol); - if (result != TSI_OK) { - gsec_aead_crypter_destroy(crypter); - return result; - } - return TSI_OK; -} - -/* --- tsi_zero_copy_grpc_protector methods implementation. --- */ - -static tsi_result alts_zero_copy_grpc_protector_protect( - tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* unprotected_slices, - grpc_slice_buffer* protected_slices) { - if (self == nullptr || unprotected_slices == nullptr || - protected_slices == nullptr) { - gpr_log(GPR_ERROR, "Invalid nullptr arguments to zero-copy grpc protect."); - return TSI_INVALID_ARGUMENT; - } - alts_zero_copy_grpc_protector* protector = - reinterpret_cast(self); - /* Calls alts_grpc_record_protocol protect repeatly. */ - while (unprotected_slices->length > protector->max_unprotected_data_size) { - grpc_slice_buffer_move_first(unprotected_slices, - protector->max_unprotected_data_size, - &protector->unprotected_staging_sb); - tsi_result status = alts_grpc_record_protocol_protect( - protector->record_protocol, &protector->unprotected_staging_sb, - protected_slices); - if (status != TSI_OK) { - return status; - } - } - return alts_grpc_record_protocol_protect( - protector->record_protocol, unprotected_slices, protected_slices); -} - -static tsi_result alts_zero_copy_grpc_protector_unprotect( - tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* protected_slices, - grpc_slice_buffer* unprotected_slices) { - if (self == nullptr || unprotected_slices == nullptr || - protected_slices == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr arguments to zero-copy grpc unprotect."); - return TSI_INVALID_ARGUMENT; - } - alts_zero_copy_grpc_protector* protector = - reinterpret_cast(self); - grpc_slice_buffer_move_into(protected_slices, &protector->protected_sb); - /* Keep unprotecting each frame if possible. */ - while (protector->protected_sb.length >= kZeroCopyFrameLengthFieldSize) { - if (protector->parsed_frame_size == 0) { - /* We have not parsed frame size yet. Parses frame size. */ - if (!read_frame_size(&protector->protected_sb, - &protector->parsed_frame_size)) { - grpc_slice_buffer_reset_and_unref_internal(&protector->protected_sb); - return TSI_DATA_CORRUPTED; - } - } - if (protector->protected_sb.length < protector->parsed_frame_size) break; - /* At this point, protected_sb contains at least one frame of data. */ - tsi_result status; - if (protector->protected_sb.length == protector->parsed_frame_size) { - status = alts_grpc_record_protocol_unprotect(protector->unrecord_protocol, - &protector->protected_sb, - unprotected_slices); - } else { - grpc_slice_buffer_move_first(&protector->protected_sb, - protector->parsed_frame_size, - &protector->protected_staging_sb); - status = alts_grpc_record_protocol_unprotect( - protector->unrecord_protocol, &protector->protected_staging_sb, - unprotected_slices); - } - protector->parsed_frame_size = 0; - if (status != TSI_OK) { - grpc_slice_buffer_reset_and_unref_internal(&protector->protected_sb); - return status; - } - } - return TSI_OK; -} - -static void alts_zero_copy_grpc_protector_destroy( - tsi_zero_copy_grpc_protector* self) { - if (self == nullptr) { - return; - } - alts_zero_copy_grpc_protector* protector = - reinterpret_cast(self); - alts_grpc_record_protocol_destroy(protector->record_protocol); - alts_grpc_record_protocol_destroy(protector->unrecord_protocol); - grpc_slice_buffer_destroy_internal(&protector->unprotected_staging_sb); - grpc_slice_buffer_destroy_internal(&protector->protected_sb); - grpc_slice_buffer_destroy_internal(&protector->protected_staging_sb); - gpr_free(protector); -} - -static const tsi_zero_copy_grpc_protector_vtable - alts_zero_copy_grpc_protector_vtable = { - alts_zero_copy_grpc_protector_protect, - alts_zero_copy_grpc_protector_unprotect, - alts_zero_copy_grpc_protector_destroy}; - -tsi_result alts_zero_copy_grpc_protector_create( - const uint8_t* key, size_t key_size, bool is_rekey, bool is_client, - bool is_integrity_only, size_t* max_protected_frame_size, - tsi_zero_copy_grpc_protector** protector) { - if (grpc_core::ExecCtx::Get() == nullptr || key == nullptr || - protector == nullptr) { - gpr_log( - GPR_ERROR, - "Invalid nullptr arguments to alts_zero_copy_grpc_protector create."); - return TSI_INVALID_ARGUMENT; - } - /* Creates alts_zero_copy_protector. */ - alts_zero_copy_grpc_protector* impl = - static_cast( - gpr_zalloc(sizeof(alts_zero_copy_grpc_protector))); - /* Creates alts_grpc_record_protocol objects. */ - tsi_result status = create_alts_grpc_record_protocol( - key, key_size, is_rekey, is_client, is_integrity_only, - /*is_protect=*/true, &impl->record_protocol); - if (status == TSI_OK) { - status = create_alts_grpc_record_protocol( - key, key_size, is_rekey, is_client, is_integrity_only, - /*is_protect=*/false, &impl->unrecord_protocol); - if (status == TSI_OK) { - /* Sets maximum frame size. */ - size_t max_protected_frame_size_to_set = kDefaultFrameLength; - if (max_protected_frame_size != nullptr) { - *max_protected_frame_size = - GPR_MIN(*max_protected_frame_size, kMaxFrameLength); - *max_protected_frame_size = - GPR_MAX(*max_protected_frame_size, kMinFrameLength); - max_protected_frame_size_to_set = *max_protected_frame_size; - } - impl->max_protected_frame_size = max_protected_frame_size_to_set; - impl->max_unprotected_data_size = - alts_grpc_record_protocol_max_unprotected_data_size( - impl->record_protocol, max_protected_frame_size_to_set); - GPR_ASSERT(impl->max_unprotected_data_size > 0); - /* Allocates internal slice buffers. */ - grpc_slice_buffer_init(&impl->unprotected_staging_sb); - grpc_slice_buffer_init(&impl->protected_sb); - grpc_slice_buffer_init(&impl->protected_staging_sb); - impl->parsed_frame_size = 0; - impl->base.vtable = &alts_zero_copy_grpc_protector_vtable; - *protector = &impl->base; - return TSI_OK; - } - } - - /* Cleanup if create failed. */ - alts_grpc_record_protocol_destroy(impl->record_protocol); - alts_grpc_record_protocol_destroy(impl->unrecord_protocol); - gpr_free(impl); - return TSI_INTERNAL_ERROR; -} diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h b/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h deleted file mode 100644 index 71e953cfc1..0000000000 --- a/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_ZERO_COPY_GRPC_PROTECTOR_H -#define GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_ZERO_COPY_GRPC_PROTECTOR_H - -#include - -#include - -#include "src/core/tsi/transport_security_grpc.h" - -/** - * This method creates an ALTS zero-copy grpc protector. - * - * - key: a symmetric key used to seal/unseal frames. - * - key_size: the size of symmetric key. - * - is_rekey: use rekeying AEAD crypter. - * - is_client: a flag indicating if the protector will be used at client or - * server side. - * - is_integrity_only: a flag indicating if the protector instance will be - * used for integrity-only or privacy-integrity mode. - * - max_protected_frame_size: an in/out parameter indicating max frame size - * to be used by the protector. If it is nullptr, the default frame size will - * be used. Otherwise, the provided frame size will be adjusted (if not - * falling into a valid frame range) and used. - * - protector: a pointer to the zero-copy protector returned from the method. - * - * This method returns TSI_OK on success or a specific error code otherwise. - */ -tsi_result alts_zero_copy_grpc_protector_create( - const uint8_t* key, size_t key_size, bool is_rekey, bool is_client, - bool is_integrity_only, size_t* max_protected_frame_size, - tsi_zero_copy_grpc_protector** protector); - -#endif /* GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_ZERO_COPY_GRPC_PROTECTOR_H \ - */ diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index dd3a8f963f..75156793f1 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -220,7 +220,6 @@ CORE_SOURCE_FILES = [ 'src/core/ext/filters/http/server/http_server_filter.cc', 'src/core/lib/http/httpcli_security_connector.cc', 'src/core/lib/security/context/security_context.cc', - 'src/core/lib/security/credentials/alts/alts_credentials.cc', 'src/core/lib/security/credentials/composite/composite_credentials.cc', 'src/core/lib/security/credentials/credentials.cc', 'src/core/lib/security/credentials/credentials_metadata.cc', @@ -234,7 +233,6 @@ CORE_SOURCE_FILES = [ 'src/core/lib/security/credentials/oauth2/oauth2_credentials.cc', 'src/core/lib/security/credentials/plugin/plugin_credentials.cc', 'src/core/lib/security/credentials/ssl/ssl_credentials.cc', - 'src/core/lib/security/security_connector/alts_security_connector.cc', 'src/core/lib/security/security_connector/security_connector.cc', 'src/core/lib/security/transport/client_auth_filter.cc', 'src/core/lib/security/transport/secure_endpoint.cc', @@ -244,45 +242,14 @@ CORE_SOURCE_FILES = [ 'src/core/lib/security/transport/tsi_error.cc', 'src/core/lib/security/util/json_util.cc', 'src/core/lib/surface/init_secure.cc', - 'src/core/tsi/alts/crypt/aes_gcm.cc', - 'src/core/tsi/alts/crypt/gsec.cc', - 'src/core/tsi/alts/frame_protector/alts_counter.cc', - 'src/core/tsi/alts/frame_protector/alts_crypter.cc', - 'src/core/tsi/alts/frame_protector/alts_frame_protector.cc', - 'src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc', - 'src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc', - 'src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc', - 'src/core/tsi/alts/frame_protector/frame_handler.cc', - 'src/core/tsi/alts/handshaker/alts_handshaker_client.cc', - 'src/core/tsi/alts/handshaker/alts_tsi_event.cc', - 'src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc', - 'src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc', - 'src/core/lib/security/credentials/alts/check_gcp_environment.cc', - 'src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc', - 'src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc', - 'src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc', - 'src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc', - 'src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc', - 'src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc', - 'src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc', - 'src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc', - 'src/core/tsi/alts/handshaker/alts_tsi_utils.cc', - 'src/core/tsi/alts/handshaker/transport_security_common_api.cc', - 'src/core/tsi/alts/handshaker/altscontext.pb.c', - 'src/core/tsi/alts/handshaker/handshaker.pb.c', - 'src/core/tsi/alts/handshaker/transport_security_common.pb.c', - 'third_party/nanopb/pb_common.c', - 'third_party/nanopb/pb_decode.c', - 'third_party/nanopb/pb_encode.c', + 'src/core/tsi/alts_transport_security.cc', + 'src/core/tsi/fake_transport_security.cc', + 'src/core/tsi/ssl_transport_security.cc', + 'src/core/tsi/transport_security_grpc.cc', 'src/core/tsi/transport_security.cc', 'src/core/tsi/transport_security_adapter.cc', - 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', - 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', - 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', + 'src/core/ext/transport/chttp2/server/chttp2_server.cc', + 'src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc', 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', 'src/core/ext/filters/client_channel/client_channel.cc', @@ -306,14 +273,11 @@ CORE_SOURCE_FILES = [ 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', 'src/core/ext/filters/deadline/deadline_filter.cc', - 'src/core/tsi/alts_transport_security.cc', - 'src/core/tsi/fake_transport_security.cc', - 'src/core/tsi/ssl_transport_security.cc', - 'src/core/tsi/transport_security_grpc.cc', - 'src/core/ext/transport/chttp2/server/chttp2_server.cc', - 'src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc', + 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', 'src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc', 'src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc', + 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', + 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', 'src/core/ext/transport/inproc/inproc_plugin.cc', 'src/core/ext/transport/inproc/inproc_transport.cc', 'src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc', @@ -322,6 +286,9 @@ CORE_SOURCE_FILES = [ 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc', 'src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc', 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c', + 'third_party/nanopb/pb_common.c', + 'third_party/nanopb/pb_decode.c', + 'third_party/nanopb/pb_encode.c', 'src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc', 'src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc', 'src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc', diff --git a/templates/CMakeLists.txt.template b/templates/CMakeLists.txt.template index ef4d7d710c..0f088436d1 100644 --- a/templates/CMakeLists.txt.template +++ b/templates/CMakeLists.txt.template @@ -138,8 +138,6 @@ ## Some libraries are shared even with BUILD_SHARED_LIBRARIES=OFF set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) - - add_definitions(-DPB_FIELD_16BIT) if (MSVC) include(cmake/msvc_static_runtime.cmake) diff --git a/templates/Makefile.template b/templates/Makefile.template index 196d12f678..390847b4f2 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -221,8 +221,6 @@ % endif % endfor - DEFINES += PB_FIELD_16BIT - CPPFLAGS += $(CPPFLAGS_$(CONFIG)) CFLAGS += $(CFLAGS_$(CONFIG)) CXXFLAGS += $(CXXFLAGS_$(CONFIG)) diff --git a/templates/gRPC-Core.podspec.template b/templates/gRPC-Core.podspec.template index 3e80d602e1..c28b78dbdf 100644 --- a/templates/gRPC-Core.podspec.template +++ b/templates/gRPC-Core.podspec.template @@ -144,7 +144,7 @@ } s.default_subspecs = 'Interface', 'Implementation' - s.compiler_flags = '-DGRPC_ARES=0', '-DPB_FIELD_16BIT' + s.compiler_flags = '-DGRPC_ARES=0' s.libraries = 'c++' # Like many other C libraries, gRPC-Core has its public headers under `include//` and its diff --git a/templates/grpc.gyp.template b/templates/grpc.gyp.template index 2ea0d06ebd..3363082a83 100644 --- a/templates/grpc.gyp.template +++ b/templates/grpc.gyp.template @@ -60,11 +60,11 @@ % endfor 'cflags_c': [ '-Werror', - '-std=c99', + '-std=c99' ], 'cflags_cc': [ '-Werror', - '-std=c++11', + '-std=c++11' ], 'include_dirs': [ '.', @@ -127,7 +127,7 @@ % endfor '-stdlib=libc++', '-std=c++11', - '-Wno-error=deprecated-declarations', + '-Wno-error=deprecated-declarations' ], % endif }, diff --git a/test/core/security/BUILD b/test/core/security/BUILD index 68de2d169f..9776e6d5fd 100644 --- a/test/core/security/BUILD +++ b/test/core/security/BUILD @@ -161,39 +161,3 @@ grpc_cc_binary( "//test/core/util:grpc_test_util", ], ) - -grpc_cc_test( - name = "check_gcp_environment_linux_test", - srcs = ["check_gcp_environment_linux_test.cc"], - language = "C++", - deps = [ - "//:grpc", - ], -) - -grpc_cc_test( - name = "check_gcp_environment_windows_test", - srcs = ["check_gcp_environment_windows_test.cc"], - language = "C++", - deps = [ - "//:grpc", - ], -) - -grpc_cc_test( - name = "grpc_alts_credentials_options_test", - srcs = ["grpc_alts_credentials_options_test.cc"], - language = "C++", - deps = [ - "//:grpc", - ], -) - -grpc_cc_test( - name = "alts_security_connector_test", - srcs = ["alts_security_connector_test.cc"], - language = "C++", - deps = [ - "//:grpc", - ], -) diff --git a/test/core/security/alts_security_connector_test.cc b/test/core/security/alts_security_connector_test.cc deleted file mode 100644 index 103a493526..0000000000 --- a/test/core/security/alts_security_connector_test.cc +++ /dev/null @@ -1,166 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include - -#include -#include -#include - -#include "src/core/lib/security/security_connector/alts_security_connector.h" -#include "src/core/lib/transport/transport.h" -#include "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h" -#include "src/core/tsi/transport_security.h" - -using grpc_core::internal::grpc_alts_auth_context_from_tsi_peer; - -/* This file contains unit tests of grpc_alts_auth_context_from_tsi_peer(). */ -static void test_invalid_input_failure() { - tsi_peer peer; - grpc_auth_context* ctx; - GPR_ASSERT(grpc_alts_auth_context_from_tsi_peer(nullptr, &ctx) == - GRPC_SECURITY_ERROR); - GPR_ASSERT(grpc_alts_auth_context_from_tsi_peer(&peer, nullptr) == - GRPC_SECURITY_ERROR); -} - -static void test_empty_certificate_type_failure() { - tsi_peer peer; - grpc_auth_context* ctx = nullptr; - GPR_ASSERT(tsi_construct_peer(0, &peer) == TSI_OK); - GPR_ASSERT(grpc_alts_auth_context_from_tsi_peer(&peer, &ctx) == - GRPC_SECURITY_ERROR); - GPR_ASSERT(ctx == nullptr); - tsi_peer_destruct(&peer); -} - -static void test_empty_peer_property_failure() { - tsi_peer peer; - grpc_auth_context* ctx; - GPR_ASSERT(tsi_construct_peer(1, &peer) == TSI_OK); - GPR_ASSERT(tsi_construct_string_peer_property_from_cstring( - TSI_CERTIFICATE_TYPE_PEER_PROPERTY, TSI_ALTS_CERTIFICATE_TYPE, - &peer.properties[0]) == TSI_OK); - GPR_ASSERT(grpc_alts_auth_context_from_tsi_peer(&peer, &ctx) == - GRPC_SECURITY_ERROR); - GPR_ASSERT(ctx == nullptr); - tsi_peer_destruct(&peer); -} - -static void test_missing_rpc_protocol_versions_property_failure() { - tsi_peer peer; - grpc_auth_context* ctx; - GPR_ASSERT(tsi_construct_peer(kTsiAltsNumOfPeerProperties, &peer) == TSI_OK); - GPR_ASSERT(tsi_construct_string_peer_property_from_cstring( - TSI_CERTIFICATE_TYPE_PEER_PROPERTY, TSI_ALTS_CERTIFICATE_TYPE, - &peer.properties[0]) == TSI_OK); - GPR_ASSERT(tsi_construct_string_peer_property_from_cstring( - TSI_ALTS_SERVICE_ACCOUNT_PEER_PROPERTY, "alice", - &peer.properties[1]) == TSI_OK); - GPR_ASSERT(grpc_alts_auth_context_from_tsi_peer(&peer, &ctx) == - GRPC_SECURITY_ERROR); - GPR_ASSERT(ctx == nullptr); - tsi_peer_destruct(&peer); -} - -static void test_unknown_peer_property_failure() { - tsi_peer peer; - grpc_auth_context* ctx; - GPR_ASSERT(tsi_construct_peer(kTsiAltsNumOfPeerProperties, &peer) == TSI_OK); - GPR_ASSERT(tsi_construct_string_peer_property_from_cstring( - TSI_CERTIFICATE_TYPE_PEER_PROPERTY, TSI_ALTS_CERTIFICATE_TYPE, - &peer.properties[0]) == TSI_OK); - GPR_ASSERT(tsi_construct_string_peer_property_from_cstring( - "unknown", "alice", &peer.properties[1]) == TSI_OK); - GPR_ASSERT(grpc_alts_auth_context_from_tsi_peer(&peer, &ctx) == - GRPC_SECURITY_ERROR); - GPR_ASSERT(ctx == nullptr); - tsi_peer_destruct(&peer); -} - -static bool test_identity(const grpc_auth_context* ctx, - const char* expected_property_name, - const char* expected_identity) { - grpc_auth_property_iterator it; - const grpc_auth_property* prop; - GPR_ASSERT(grpc_auth_context_peer_is_authenticated(ctx)); - it = grpc_auth_context_peer_identity(ctx); - prop = grpc_auth_property_iterator_next(&it); - GPR_ASSERT(prop != nullptr); - 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 false; - } - if (strncmp(prop->value, expected_identity, prop->value_length) != 0) { - gpr_log(GPR_ERROR, "Expected peer identity %s and got got %s.", - expected_identity, prop->value); - return false; - } - return true; -} - -static void test_alts_peer_to_auth_context_success() { - tsi_peer peer; - grpc_auth_context* ctx; - GPR_ASSERT(tsi_construct_peer(kTsiAltsNumOfPeerProperties, &peer) == TSI_OK); - GPR_ASSERT(tsi_construct_string_peer_property_from_cstring( - TSI_CERTIFICATE_TYPE_PEER_PROPERTY, TSI_ALTS_CERTIFICATE_TYPE, - &peer.properties[0]) == TSI_OK); - GPR_ASSERT(tsi_construct_string_peer_property_from_cstring( - TSI_ALTS_SERVICE_ACCOUNT_PEER_PROPERTY, "alice", - &peer.properties[1]) == TSI_OK); - grpc_gcp_rpc_protocol_versions peer_versions; - grpc_gcp_rpc_protocol_versions_set_max(&peer_versions, - GRPC_PROTOCOL_VERSION_MAX_MAJOR, - GRPC_PROTOCOL_VERSION_MAX_MINOR); - grpc_gcp_rpc_protocol_versions_set_min(&peer_versions, - GRPC_PROTOCOL_VERSION_MIN_MAJOR, - GRPC_PROTOCOL_VERSION_MIN_MINOR); - grpc_slice serialized_peer_versions; - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_encode(&peer_versions, - &serialized_peer_versions)); - - GPR_ASSERT(tsi_construct_string_peer_property( - TSI_ALTS_RPC_VERSIONS, - reinterpret_cast( - GRPC_SLICE_START_PTR(serialized_peer_versions)), - GRPC_SLICE_LENGTH(serialized_peer_versions), - &peer.properties[2]) == TSI_OK); - GPR_ASSERT(grpc_alts_auth_context_from_tsi_peer(&peer, &ctx) == - GRPC_SECURITY_OK); - GPR_ASSERT( - test_identity(ctx, TSI_ALTS_SERVICE_ACCOUNT_PEER_PROPERTY, "alice")); - GRPC_AUTH_CONTEXT_UNREF(ctx, "test"); - grpc_slice_unref(serialized_peer_versions); - tsi_peer_destruct(&peer); -} - -int main(int argc, char** argv) { - /* Test. */ - test_invalid_input_failure(); - test_empty_certificate_type_failure(); - test_empty_peer_property_failure(); - test_unknown_peer_property_failure(); - test_missing_rpc_protocol_versions_property_failure(); - test_alts_peer_to_auth_context_success(); - - return 0; -} diff --git a/test/core/security/check_gcp_environment_linux_test.cc b/test/core/security/check_gcp_environment_linux_test.cc deleted file mode 100644 index 6c436a3945..0000000000 --- a/test/core/security/check_gcp_environment_linux_test.cc +++ /dev/null @@ -1,83 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "src/core/lib/security/credentials/alts/check_gcp_environment.h" - -#if GPR_LINUX - -#include -#include - -#include -#include - -#include "src/core/lib/gpr/tmpfile.h" - -static bool check_bios_data_linux_test(const char* data) { - /* Create a file with contents data. */ - char* filename = nullptr; - FILE* fp = gpr_tmpfile("check_gcp_environment_test", &filename); - GPR_ASSERT(filename != nullptr); - GPR_ASSERT(fp != nullptr); - GPR_ASSERT(fwrite(data, 1, strlen(data), fp) == strlen(data)); - fclose(fp); - bool result = grpc_core::internal::check_bios_data( - reinterpret_cast(filename)); - /* Cleanup. */ - remove(filename); - gpr_free(filename); - return result; -} - -static void test_gcp_environment_check_success() { - /* Exact match. */ - GPR_ASSERT(check_bios_data_linux_test("Google")); - GPR_ASSERT(check_bios_data_linux_test("Google Compute Engine")); - /* With leading and trailing whitespaces. */ - GPR_ASSERT(check_bios_data_linux_test(" Google ")); - GPR_ASSERT(check_bios_data_linux_test("Google ")); - GPR_ASSERT(check_bios_data_linux_test(" Google")); - GPR_ASSERT(check_bios_data_linux_test(" Google Compute Engine ")); - GPR_ASSERT(check_bios_data_linux_test("Google Compute Engine ")); - GPR_ASSERT(check_bios_data_linux_test(" Google Compute Engine")); - /* With leading and trailing \t and \n. */ - GPR_ASSERT(check_bios_data_linux_test("\t\tGoogle Compute Engine\t")); - GPR_ASSERT(check_bios_data_linux_test("Google Compute Engine\n")); - GPR_ASSERT(check_bios_data_linux_test("\n\n\tGoogle Compute Engine \n\t\t")); -} - -static void test_gcp_environment_check_failure() { - GPR_ASSERT(!check_bios_data_linux_test("non_existing-file")); - GPR_ASSERT(!check_bios_data_linux_test("Google-Chrome")); - GPR_ASSERT(!check_bios_data_linux_test("Amazon")); - GPR_ASSERT(!check_bios_data_linux_test("Google-Chrome\t\t")); - GPR_ASSERT(!check_bios_data_linux_test("Amazon")); -} - -int main(int argc, char** argv) { - /* Tests. */ - test_gcp_environment_check_success(); - test_gcp_environment_check_failure(); - return 0; -} - -#else // GPR_LINUX - -int main(int argc, char** argv) { return 0; } - -#endif // GPR_LINUX diff --git a/test/core/security/check_gcp_environment_windows_test.cc b/test/core/security/check_gcp_environment_windows_test.cc deleted file mode 100644 index 46179b747d..0000000000 --- a/test/core/security/check_gcp_environment_windows_test.cc +++ /dev/null @@ -1,71 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "src/core/lib/security/credentials/alts/check_gcp_environment.h" - -#ifdef GPR_WINDOWS - -#include -#include - -#include -#include -#include "src/core/lib/gpr/tmpfile.h" - -static bool check_bios_data_windows_test(const char* data) { - /* Create a file with contents data. */ - char* filename = nullptr; - FILE* fp = gpr_tmpfile("check_gcp_environment_test", &filename); - GPR_ASSERT(filename != nullptr); - GPR_ASSERT(fp != nullptr); - GPR_ASSERT(fwrite(data, 1, strlen(data), fp) == strlen(data)); - fclose(fp); - bool result = grpc_core::internal::check_bios_data( - reinterpret_cast(filename)); - /* Cleanup. */ - remove(filename); - gpr_free(filename); - return result; -} - -static void test_gcp_environment_check_success() { - GPR_ASSERT(check_bios_data_windows_test("Google")); - GPR_ASSERT(check_bios_data_windows_test("Google\n")); - GPR_ASSERT(check_bios_data_windows_test("Google\r")); - GPR_ASSERT(check_bios_data_windows_test("Google\r\n")); - GPR_ASSERT(check_bios_data_windows_test(" Google \r\n")); - GPR_ASSERT(check_bios_data_windows_test(" \t\t Google\r\n")); - GPR_ASSERT(check_bios_data_windows_test(" \t\t Google\t\t \r\n")); -} - -static void test_gcp_environment_check_failure() { - GPR_ASSERT(!check_bios_data_windows_test("\t\tAmazon\n")); - GPR_ASSERT(!check_bios_data_windows_test(" Amazon\r\n")); -} - -int main(int argc, char** argv) { - /* Tests. */ - test_gcp_environment_check_success(); - test_gcp_environment_check_failure(); - return 0; -} -#else // GPR_WINDOWS - -int main(int argc, char** argv) { return 0; } - -#endif // GPR_WINDOWS diff --git a/test/core/security/grpc_alts_credentials_options_test.cc b/test/core/security/grpc_alts_credentials_options_test.cc deleted file mode 100644 index 1217065507..0000000000 --- a/test/core/security/grpc_alts_credentials_options_test.cc +++ /dev/null @@ -1,118 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include - -#include -#include - -#include "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h" - -#define ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_1 "abc@google.com" -#define ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_2 "def@google.com" - -const size_t kTargetServiceAccountNum = 2; - -static void test_add_target_service_account_failure() { - /* Initialization. */ - grpc_alts_credentials_options* options = - grpc_alts_credentials_client_options_create(); - auto client_options = - reinterpret_cast(options); - - /* Test. */ - GPR_ASSERT(!grpc_alts_credentials_client_options_add_target_service_account( - client_options, nullptr)); - GPR_ASSERT(!grpc_alts_credentials_client_options_add_target_service_account( - nullptr, ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_1)); - - /* Cleanup. */ - grpc_alts_credentials_options_destroy(options); -} - -static void test_copy_client_options_failure() { - /* Initialization. */ - grpc_alts_credentials_options* options = - grpc_alts_credentials_client_options_create(); - - /* Test. */ - GPR_ASSERT(grpc_alts_credentials_options_copy(nullptr) == nullptr); - - /* Cleanup. */ - grpc_alts_credentials_options_destroy(options); -} - -static size_t get_target_service_account_num( - grpc_alts_credentials_client_options* options) { - size_t num = 0; - target_service_account* node = options->target_account_list_head; - while (node != nullptr) { - num++; - node = node->next; - } - return num; -} - -static void test_client_options_api_success() { - /* Initialization. */ - grpc_alts_credentials_options* options = - grpc_alts_credentials_client_options_create(); - auto client_options = - reinterpret_cast(options); - - /* Set client options fields. */ - grpc_alts_credentials_client_options_add_target_service_account( - client_options, ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_1); - grpc_alts_credentials_client_options_add_target_service_account( - client_options, ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_2); - - /* Validate client option fields. */ - GPR_ASSERT(get_target_service_account_num(client_options) == - kTargetServiceAccountNum); - GPR_ASSERT(strcmp(client_options->target_account_list_head->data, - ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_2) == 0); - GPR_ASSERT(strcmp(client_options->target_account_list_head->next->data, - ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_1) == 0); - - /* Perform a copy operation and validate its correctness. */ - grpc_alts_credentials_options* new_options = - grpc_alts_credentials_options_copy(options); - auto new_client_options = - reinterpret_cast(new_options); - - GPR_ASSERT(get_target_service_account_num(new_client_options) == - kTargetServiceAccountNum); - GPR_ASSERT(strcmp(new_client_options->target_account_list_head->data, - ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_2) == 0); - GPR_ASSERT(strcmp(new_client_options->target_account_list_head->next->data, - ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_1) == 0); - - /* Cleanup.*/ - grpc_alts_credentials_options_destroy(options); - grpc_alts_credentials_options_destroy(new_options); -} - -int main(int argc, char** argv) { - /* Test. */ - test_add_target_service_account_failure(); - test_copy_client_options_failure(); - test_client_options_api_success(); - return 0; -} diff --git a/test/core/tsi/BUILD b/test/core/tsi/BUILD index 8ac3e7687c..e28c0b5f84 100644 --- a/test/core/tsi/BUILD +++ b/test/core/tsi/BUILD @@ -16,7 +16,7 @@ load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_c licenses(["notice"]) # Apache v2 -grpc_package(name = "test/core/tsi", visibility = "public") +grpc_package(name = "test/core/tsi") grpc_cc_library( name = "transport_security_test_lib", diff --git a/test/core/tsi/alts/crypt/BUILD b/test/core/tsi/alts/crypt/BUILD deleted file mode 100644 index 0057d7f6e6..0000000000 --- a/test/core/tsi/alts/crypt/BUILD +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright 2018 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_package") - -licenses(["notice"]) # Apache v2 - -grpc_package(name = "crypt", visibility = "public") - -grpc_cc_library( - name = "alts_crypt_test_util", - srcs = ["gsec_test_util.cc"], - hdrs = ["gsec_test_util.h"], - deps = [ - "//:grpc", - ], -) - -grpc_cc_test( - name = "alts_crypt_test", - srcs = ["aes_gcm_test.cc"], - language = "C++", - deps = [ - ":alts_crypt_test_util", - "//:grpc", - ], -) diff --git a/test/core/tsi/alts/crypt/aes_gcm_test.cc b/test/core/tsi/alts/crypt/aes_gcm_test.cc deleted file mode 100644 index 576dd8f27b..0000000000 --- a/test/core/tsi/alts/crypt/aes_gcm_test.cc +++ /dev/null @@ -1,2105 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "src/core/tsi/alts/crypt/gsec.h" -#include "test/core/tsi/alts/crypt/gsec_test_util.h" - -#include -#include - -const size_t kTestMinTagLengthForCorruption = 8; -const size_t kTestNumCrypters = 3; -const size_t kTestMaxSlices = 5; -const size_t kTestMaxLength = 1024; -const size_t kTestNumEncryptions = 100; - -/* Struct for pre-generated test vector */ -typedef struct gsec_aead_test_vector { - uint8_t* nonce; - uint8_t* aad; - uint8_t* key; - uint8_t* plaintext; - uint8_t* ciphertext_and_tag; - size_t nonce_length; - size_t aad_length; - size_t key_length; - size_t plaintext_length; - size_t ciphertext_and_tag_length; -} gsec_aead_test_vector; - -static void gsec_randomly_slice(uint8_t* input, size_t input_length, - struct iovec** output, size_t* output_length) { - if (input_length == 0) { - *output = nullptr; - *output_length = 0; - return; - } - *output_length = gsec_test_bias_random_uint32(kTestMaxSlices) + 1; - *output = - static_cast(malloc(*output_length * sizeof(**output))); - size_t i; - for (i = 0; i < *output_length - 1; i++) { - size_t slice_length = - gsec_test_bias_random_uint32(static_cast(input_length)); - struct iovec slice = {input, slice_length}; - (*output)[i] = slice; - input += slice_length; - input_length -= slice_length; - } - struct iovec slice = {input, input_length}; - (*output)[*output_length - 1] = slice; -} - -static void gsec_assert_ok(grpc_status_code status, const char* error_detail) { - char empty_string[] = ""; - if (error_detail == nullptr) { - error_detail = empty_string; - } - if (status != GRPC_STATUS_OK) { - fprintf(stderr, "Status is not ok: %s\n", error_detail); - } - GPR_ASSERT(status == GRPC_STATUS_OK); -} - -static void gsec_test_random_encrypt_decrypt(gsec_aead_crypter* crypter, - size_t aad_length, - size_t message_length) { - GPR_ASSERT(crypter != nullptr); - size_t nonce_length, tag_length; - uint8_t *nonce, *aad, *message; - gsec_aead_crypter_nonce_length(crypter, &nonce_length, nullptr); - gsec_aead_crypter_tag_length(crypter, &tag_length, nullptr); - - gsec_test_random_array(&nonce, nonce_length); - gsec_test_random_array(&aad, aad_length); - gsec_test_random_array(&message, message_length); - - /* Test encryption */ - size_t ciphertext_and_tag_length, ciphertext_bytes_written = 0; - gsec_aead_crypter_max_ciphertext_and_tag_length( - crypter, message_length, &ciphertext_and_tag_length, nullptr); - - uint8_t* ciphertext_and_tag = - static_cast(gpr_malloc(ciphertext_and_tag_length)); - - char* error_buffer = nullptr; - gsec_assert_ok( - gsec_aead_crypter_encrypt(crypter, nonce, nonce_length, aad, aad_length, - message, message_length, ciphertext_and_tag, - ciphertext_and_tag_length, - &ciphertext_bytes_written, &error_buffer), - error_buffer); - GPR_ASSERT(message_length + tag_length == ciphertext_and_tag_length); - GPR_ASSERT(ciphertext_bytes_written == ciphertext_and_tag_length); - - /* Test decryption */ - size_t plaintext_length, plaintext_bytes_written = 0; - gsec_aead_crypter_max_plaintext_length(crypter, ciphertext_bytes_written, - &plaintext_length, nullptr); - uint8_t* plaintext = static_cast(gpr_malloc(plaintext_length)); - grpc_status_code status = gsec_aead_crypter_decrypt( - crypter, nonce, nonce_length, aad, aad_length, ciphertext_and_tag, - ciphertext_bytes_written, plaintext, plaintext_length, - &plaintext_bytes_written, nullptr); - - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(message_length == plaintext_bytes_written); - GPR_ASSERT(memcmp(message, plaintext, message_length) == 0); - - /** - * The returned plaintext will be zeroed if there was an authentication error. - */ - uint8_t* zero_message = static_cast(gpr_zalloc(plaintext_length)); - if (tag_length >= kTestMinTagLengthForCorruption) { - char* error_message; - /* Corrupt nonce */ - if (nonce_length > 0) { - plaintext_bytes_written = 0; - uint8_t* corrupt_nonce; - gsec_test_copy_and_alter_random_byte(nonce, &corrupt_nonce, nonce_length); - status = gsec_aead_crypter_decrypt( - crypter, corrupt_nonce, nonce_length, aad, aad_length, - ciphertext_and_tag, ciphertext_bytes_written, plaintext, - plaintext_length, &plaintext_bytes_written, &error_message); - - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_FAILED_PRECONDITION, "Checking tag failed.", - error_message)); - GPR_ASSERT(plaintext_bytes_written == 0); - GPR_ASSERT(memcmp(zero_message, plaintext, plaintext_length) == 0); - gpr_free(corrupt_nonce); - gpr_free(error_message); - } - - /* Corrupt ciphertext_and_tag */ - plaintext_bytes_written = 0; - uint8_t* corrupt_ciphertext_and_tag; - gsec_test_copy_and_alter_random_byte(ciphertext_and_tag, - &corrupt_ciphertext_and_tag, - ciphertext_and_tag_length); - status = gsec_aead_crypter_decrypt( - crypter, nonce, nonce_length, aad, aad_length, - corrupt_ciphertext_and_tag, ciphertext_bytes_written, plaintext, - plaintext_length, &plaintext_bytes_written, &error_message); - - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_FAILED_PRECONDITION, error_message, - "Checking tag failed")); - GPR_ASSERT(plaintext_bytes_written == 0); - GPR_ASSERT(memcmp(zero_message, plaintext, plaintext_length) == 0); - gpr_free(error_message); - gpr_free(corrupt_ciphertext_and_tag); - - /* Corrupt start of ciphertext_and_tag */ - plaintext_bytes_written = 0; - gsec_test_copy(ciphertext_and_tag, &corrupt_ciphertext_and_tag, - ciphertext_and_tag_length); - (*corrupt_ciphertext_and_tag)++; - status = gsec_aead_crypter_decrypt( - crypter, nonce, nonce_length, aad, aad_length, - corrupt_ciphertext_and_tag, ciphertext_bytes_written, plaintext, - plaintext_length, &plaintext_bytes_written, &error_message); - GPR_ASSERT(plaintext_bytes_written == 0); - GPR_ASSERT(memcmp(zero_message, plaintext, plaintext_length) == 0); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_FAILED_PRECONDITION, error_message, - "Checking tag failed")); - gpr_free(error_message); - gpr_free(corrupt_ciphertext_and_tag); - - /* Corrupt end of ciphertext_and_tag */ - plaintext_bytes_written = 0; - gsec_test_copy(ciphertext_and_tag, &corrupt_ciphertext_and_tag, - ciphertext_and_tag_length); - (*(corrupt_ciphertext_and_tag + ciphertext_and_tag_length - 1))++; - - status = gsec_aead_crypter_decrypt( - crypter, nonce, nonce_length, aad, aad_length, - corrupt_ciphertext_and_tag, ciphertext_bytes_written, plaintext, - plaintext_length, &plaintext_bytes_written, &error_message); - - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_FAILED_PRECONDITION, error_message, - "Checking tag failed")); - GPR_ASSERT(plaintext_bytes_written == 0); - GPR_ASSERT(memcmp(zero_message, plaintext, plaintext_length) == 0); - gpr_free(error_message); - gpr_free(corrupt_ciphertext_and_tag); - } - - gpr_free(zero_message); - gpr_free(nonce); - gpr_free(aad); - gpr_free(message); - gpr_free(plaintext); - gpr_free(ciphertext_and_tag); -} - -static void gsec_test_encrypt_decrypt(gsec_aead_crypter* crypter) { - GPR_ASSERT(crypter != nullptr); - size_t aad_length, message_length; - aad_length = gsec_test_bias_random_uint32(kTestMaxLength); - message_length = gsec_test_bias_random_uint32(kTestMaxLength); - gsec_test_random_encrypt_decrypt(crypter, aad_length, message_length); - gsec_test_random_encrypt_decrypt(crypter, 0, message_length); - gsec_test_random_encrypt_decrypt(crypter, aad_length, 0); -} - -static void gsec_test_multiple_random_encrypt_decrypt( - gsec_aead_crypter* crypter, size_t* aad_lengths, size_t* message_lengths, - size_t count) { - GPR_ASSERT(crypter != nullptr); - size_t nonce_length, tag_length; - uint8_t **nonces, **aads, **messages; - nonces = static_cast(gpr_malloc(sizeof(uint8_t*) * count)); - aads = static_cast(gpr_malloc(sizeof(uint8_t*) * count)); - messages = static_cast(gpr_malloc(sizeof(uint8_t*) * count)); - - gsec_aead_crypter_nonce_length(crypter, &nonce_length, nullptr); - gsec_aead_crypter_tag_length(crypter, &tag_length, nullptr); - - size_t ind; - for (ind = 0; ind < count; ind++) { - size_t aad_length = (aad_lengths == nullptr) ? 0 : aad_lengths[ind]; - size_t message_length = - (message_lengths == nullptr) ? 0 : message_lengths[ind]; - gsec_test_random_array(&(nonces[ind]), nonce_length); - gsec_test_random_array(&(aads[ind]), aad_length); - gsec_test_random_array(&(messages[ind]), message_length); - } - - size_t* ciphertext_and_tag_lengths = - static_cast(gpr_malloc(sizeof(size_t) * count)); - size_t* ciphertext_bytes_writtens = - static_cast(gpr_malloc(sizeof(size_t) * count)); - size_t* plaintext_lengths = - static_cast(gpr_malloc(sizeof(size_t) * count)); - size_t* plaintext_bytes_writtens = - static_cast(gpr_malloc(sizeof(size_t) * count)); - uint8_t** ciphertext_and_tags = - static_cast(gpr_malloc(sizeof(uint8_t*) * count)); - uint8_t** plaintexts = - static_cast(gpr_malloc(sizeof(uint8_t*) * count)); - - /* Do encryption */ - for (ind = 0; ind < count; ind++) { - size_t aad_length = (aad_lengths == nullptr) ? 0 : aad_lengths[ind]; - size_t message_length = - (message_lengths == nullptr) ? 0 : message_lengths[ind]; - gsec_aead_crypter_max_ciphertext_and_tag_length( - crypter, message_length, &(ciphertext_and_tag_lengths[ind]), nullptr); - ciphertext_and_tags[ind] = - static_cast(gpr_malloc(ciphertext_and_tag_lengths[ind])); - grpc_status_code status = gsec_aead_crypter_encrypt( - crypter, nonces[ind], nonce_length, aads[ind], aad_length, - messages[ind], message_length, ciphertext_and_tags[ind], - ciphertext_and_tag_lengths[ind], &(ciphertext_bytes_writtens[ind]), - nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(message_length + tag_length == ciphertext_and_tag_lengths[ind]); - GPR_ASSERT(ciphertext_bytes_writtens[ind] == - ciphertext_and_tag_lengths[ind]); - } - /* Do Decryption */ - for (ind = 0; ind < count; ind++) { - size_t aad_length = (aad_lengths == nullptr) ? 0 : aad_lengths[ind]; - size_t message_length = - (message_lengths == nullptr) ? 0 : message_lengths[ind]; - gsec_aead_crypter_max_plaintext_length(crypter, - ciphertext_bytes_writtens[ind], - &(plaintext_lengths[ind]), nullptr); - plaintexts[ind] = static_cast(gpr_malloc(plaintext_lengths[ind])); - grpc_status_code status = gsec_aead_crypter_decrypt( - crypter, nonces[ind], nonce_length, aads[ind], aad_length, - ciphertext_and_tags[ind], ciphertext_bytes_writtens[ind], - plaintexts[ind], plaintext_lengths[ind], - &(plaintext_bytes_writtens[ind]), nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(message_length == plaintext_bytes_writtens[ind]); - GPR_ASSERT(memcmp(messages[ind], plaintexts[ind], message_length) == 0); - } - - /* Slice the plaintext and encrypt with iovecs */ - for (ind = 0; ind < count; ind++) { - size_t aad_length = (aad_lengths == nullptr) ? 0 : aad_lengths[ind]; - struct iovec* aad_vecs = nullptr; - size_t aad_vecs_length = 0; - gsec_randomly_slice(aads[ind], aad_length, &aad_vecs, &aad_vecs_length); - size_t message_length = - (message_lengths == nullptr) ? 0 : message_lengths[ind]; - struct iovec* message_vecs = nullptr; - size_t message_vecs_length = 0; - gsec_randomly_slice(messages[ind], message_length, &message_vecs, - &message_vecs_length); - - size_t ciphertext_length = ciphertext_and_tag_lengths[ind]; - uint8_t* another_ciphertext = - static_cast(malloc(ciphertext_length)); - struct iovec another_ciphertext_vec = {another_ciphertext, - ciphertext_length}; - - char* error_details = nullptr; - size_t ciphertext_bytes_written = 0; - gsec_assert_ok( - gsec_aead_crypter_encrypt_iovec( - crypter, nonces[ind], nonce_length, aad_vecs, aad_vecs_length, - message_vecs, message_vecs_length, another_ciphertext_vec, - &ciphertext_bytes_written, &error_details), - error_details); - GPR_ASSERT(memcmp(ciphertext_and_tags[ind], another_ciphertext_vec.iov_base, - ciphertext_length) == 0); - free(another_ciphertext); - free(aad_vecs); - free(message_vecs); - } - - /* Slice the ciphertext and decrypt with iovecs */ - for (ind = 0; ind < count; ind++) { - size_t message_length = - (message_lengths == nullptr) ? 0 : message_lengths[ind]; - message_length = message_length + 0; - - size_t aad_length = (aad_lengths == nullptr) ? 0 : aad_lengths[ind]; - - struct iovec* aad_vecs = nullptr; - size_t aad_vecs_length = 0; - gsec_randomly_slice(aads[ind], aad_length, &aad_vecs, &aad_vecs_length); - - struct iovec* ciphertext_vecs = nullptr; - size_t ciphertext_vecs_length = 0; - gsec_randomly_slice(ciphertext_and_tags[ind], - ciphertext_bytes_writtens[ind], &ciphertext_vecs, - &ciphertext_vecs_length); - - size_t decrypted_length = plaintext_lengths[ind]; - uint8_t* decrypted = static_cast(malloc(decrypted_length)); - struct iovec decrypted_vec = {decrypted, decrypted_length}; - - char* error_details = nullptr; - gsec_assert_ok(gsec_aead_crypter_decrypt_iovec( - crypter, nonces[ind], nonce_length, aad_vecs, - aad_vecs_length, ciphertext_vecs, ciphertext_vecs_length, - decrypted_vec, &decrypted_length, &error_details), - error_details); - GPR_ASSERT(decrypted_vec.iov_len == message_length); - GPR_ASSERT(memcmp(decrypted_vec.iov_base, messages[ind], message_length) == - 0); - free(decrypted); - free(aad_vecs); - free(ciphertext_vecs); - } - - for (ind = 0; ind < count; ind++) { - gpr_free(nonces[ind]); - gpr_free(aads[ind]); - gpr_free(messages[ind]); - gpr_free(ciphertext_and_tags[ind]); - gpr_free(plaintexts[ind]); - } - gpr_free(nonces); - gpr_free(aads); - gpr_free(messages); - gpr_free(ciphertext_and_tag_lengths); - gpr_free(ciphertext_bytes_writtens); - gpr_free(plaintext_lengths); - gpr_free(plaintext_bytes_writtens); - gpr_free(ciphertext_and_tags); - gpr_free(plaintexts); -} - -static void gsec_test_multiple_encrypt_decrypt(gsec_aead_crypter* crypter) { - GPR_ASSERT(crypter != nullptr); - size_t count = kTestNumEncryptions; - size_t* aad_lengths = - static_cast(gpr_malloc(sizeof(size_t) * count)); - size_t* message_lengths = - static_cast(gpr_malloc(sizeof(size_t) * count)); - size_t ind; - for (ind = 0; ind < count; ind++) { - aad_lengths[ind] = gsec_test_bias_random_uint32(kTestMaxLength); - message_lengths[ind] = gsec_test_bias_random_uint32(kTestMaxLength); - } - gsec_test_multiple_random_encrypt_decrypt(crypter, aad_lengths, - message_lengths, count); - gsec_test_multiple_random_encrypt_decrypt(crypter, aad_lengths, nullptr, - count); - gsec_test_multiple_random_encrypt_decrypt(crypter, nullptr, message_lengths, - count); - gpr_free(aad_lengths); - gpr_free(message_lengths); -} - -static void gsec_test_encryption_failure(gsec_aead_crypter* crypter) { - GPR_ASSERT(crypter != nullptr); - size_t aad_length = kTestMaxLength; - size_t message_length = kTestMaxLength; - size_t nonce_length; - - char* error_message; - uint8_t *nonce, *aad, *message; - - gsec_aead_crypter_nonce_length(crypter, &nonce_length, nullptr); - gsec_test_random_array(&nonce, nonce_length); - gsec_test_random_array(&aad, aad_length); - gsec_test_random_array(&message, message_length); - - size_t ciphertext_and_tag_length, ciphertext_bytes_written = 0; - gsec_aead_crypter_max_ciphertext_and_tag_length( - crypter, message_length, &ciphertext_and_tag_length, nullptr); - uint8_t* ciphertext_and_tag = - static_cast(gpr_malloc(ciphertext_and_tag_length)); - - /* nullptr nonce */ - grpc_status_code status = gsec_aead_crypter_encrypt( - crypter, nullptr, nonce_length, aad, aad_length, message, message_length, - ciphertext_and_tag, ciphertext_and_tag_length, &ciphertext_bytes_written, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "Nonce buffer is nullptr.")); - gpr_free(error_message); - - /* Big nonce */ - status = gsec_aead_crypter_encrypt( - crypter, nonce, nonce_length + 1, aad, aad_length, message, - message_length, ciphertext_and_tag, ciphertext_and_tag_length, - &ciphertext_bytes_written, &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "Nonce buffer has the wrong length.")); - gpr_free(error_message); - - /* Small nonce */ - status = gsec_aead_crypter_encrypt( - crypter, nonce, nonce_length - 1, aad, aad_length, message, - message_length, ciphertext_and_tag, ciphertext_and_tag_length, - &ciphertext_bytes_written, &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "Nonce buffer has the wrong length.")); - gpr_free(error_message); - - /* nullptr aad */ - status = gsec_aead_crypter_encrypt( - crypter, nonce, nonce_length, nullptr, aad_length, message, - message_length, ciphertext_and_tag, ciphertext_and_tag_length, - &ciphertext_bytes_written, &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, "aad is nullptr.")); - gpr_free(error_message); - - /* nullptr aad with zero length */ - gsec_assert_ok( - gsec_aead_crypter_encrypt(crypter, nonce, nonce_length, nullptr, 0, - message, message_length, ciphertext_and_tag, - ciphertext_and_tag_length, - &ciphertext_bytes_written, &error_message), - error_message); - - /* nullptr plaintext */ - status = gsec_aead_crypter_encrypt( - crypter, nonce, nonce_length, aad, aad_length, nullptr, message_length, - ciphertext_and_tag, ciphertext_and_tag_length, &ciphertext_bytes_written, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "plaintext is nullptr.")); - gpr_free(error_message); - - /* nullptr ciphertext */ - status = gsec_aead_crypter_encrypt(crypter, nonce, nonce_length, aad, - aad_length, message, message_length, - nullptr, ciphertext_and_tag_length, - &ciphertext_bytes_written, &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "ciphertext is nullptr.")); - gpr_free(error_message); - - /* Short ciphertext */ - status = gsec_aead_crypter_encrypt( - crypter, nonce, nonce_length, aad, aad_length, message, message_length, - ciphertext_and_tag, ciphertext_and_tag_length - 1, - &ciphertext_bytes_written, &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "ciphertext is too small to hold a tag.")); - gpr_free(error_message); - - /* nullptr ciphertext_bytes_written */ - status = gsec_aead_crypter_encrypt( - crypter, nonce, nonce_length, aad, aad_length, message, message_length, - ciphertext_and_tag, ciphertext_and_tag_length, nullptr, &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "bytes_written is nullptr.")); - gpr_free(error_message); - - /* nullptr plaintext/ciphertext encrypt with zero length */ - gsec_assert_ok(gsec_aead_crypter_encrypt( - crypter, nonce, nonce_length, aad, aad_length, nullptr, 0, - ciphertext_and_tag, ciphertext_and_tag_length, - &ciphertext_bytes_written, &error_message), - error_message); - - /* Success */ - status = gsec_aead_crypter_encrypt( - crypter, nonce, nonce_length, aad, aad_length, message, message_length, - ciphertext_and_tag, ciphertext_and_tag_length, &ciphertext_bytes_written, - &error_message); - GPR_ASSERT(status == GRPC_STATUS_OK); - - gpr_free(message); - gpr_free(aad); - gpr_free(nonce); - gpr_free(ciphertext_and_tag); -} - -static void gsec_test_decryption_failure(gsec_aead_crypter* crypter) { - GPR_ASSERT(crypter != nullptr); - size_t aad_length = kTestMaxLength; - size_t message_length = kTestMaxLength; - size_t nonce_length, tag_length; - uint8_t *nonce, *aad, *message; - - gsec_aead_crypter_nonce_length(crypter, &nonce_length, nullptr); - gsec_aead_crypter_tag_length(crypter, &tag_length, nullptr); - gsec_test_random_array(&nonce, nonce_length); - gsec_test_random_array(&aad, aad_length); - gsec_test_random_array(&message, message_length); - - /* Test encryption */ - size_t ciphertext_and_tag_length, ciphertext_bytes_written = 0; - gsec_aead_crypter_max_ciphertext_and_tag_length( - crypter, message_length, &ciphertext_and_tag_length, nullptr); - uint8_t* ciphertext_and_tag = - static_cast(gpr_malloc(ciphertext_and_tag_length)); - - grpc_status_code status = gsec_aead_crypter_encrypt( - crypter, nonce, nonce_length, aad, aad_length, message, message_length, - ciphertext_and_tag, ciphertext_and_tag_length, &ciphertext_bytes_written, - nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(ciphertext_bytes_written == ciphertext_and_tag_length); - - size_t plaintext_length, plaintext_bytes_written = 0; - gsec_aead_crypter_max_plaintext_length(crypter, ciphertext_bytes_written, - &plaintext_length, nullptr); - uint8_t* plaintext = static_cast(gpr_malloc(plaintext_length)); - - char* error_message; - /* nullptr nonce */ - status = gsec_aead_crypter_decrypt( - crypter, nullptr, nonce_length, aad, aad_length, ciphertext_and_tag, - ciphertext_and_tag_length, plaintext, plaintext_length, - &plaintext_bytes_written, &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "Nonce buffer is nullptr.")); - gpr_free(error_message); - - /* Big nonce */ - status = gsec_aead_crypter_decrypt( - crypter, nonce, nonce_length + 1, aad, aad_length, ciphertext_and_tag, - ciphertext_and_tag_length, plaintext, plaintext_length, - &plaintext_bytes_written, &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "Nonce buffer has the wrong length.")); - gpr_free(error_message); - - /* Small nonce */ - status = gsec_aead_crypter_decrypt( - crypter, nonce, nonce_length - 1, aad, aad_length, ciphertext_and_tag, - ciphertext_and_tag_length, plaintext, plaintext_length, - &plaintext_bytes_written, &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "Nonce buffer has the wrong length.")); - gpr_free(error_message); - - /* nullptr aad */ - status = gsec_aead_crypter_decrypt( - crypter, nonce, nonce_length, nullptr, aad_length, ciphertext_and_tag, - ciphertext_and_tag_length, plaintext, plaintext_length, - &plaintext_bytes_written, &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, "aad is nullptr.")); - gpr_free(error_message); - - /* nullptr aad with zero length */ - status = gsec_aead_crypter_encrypt( - crypter, nonce, nonce_length, nullptr, 0, message, message_length, - ciphertext_and_tag, ciphertext_and_tag_length, &ciphertext_bytes_written, - &error_message); - GPR_ASSERT(status == GRPC_STATUS_OK); - - status = gsec_aead_crypter_decrypt( - crypter, nonce, nonce_length, nullptr, 0, ciphertext_and_tag, - ciphertext_and_tag_length, plaintext, plaintext_length, - &plaintext_bytes_written, &error_message); - GPR_ASSERT(status == GRPC_STATUS_OK); - - /* Small ciphertext */ - if (tag_length > 0) { - status = gsec_aead_crypter_decrypt( - crypter, nonce, nonce_length, aad, aad_length, ciphertext_and_tag, - tag_length - 1, plaintext, plaintext_length, &plaintext_bytes_written, - &error_message); - - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "ciphertext is too small to hold a tag.")); - gpr_free(error_message); - } - - /* nullptr ciphertext */ - status = gsec_aead_crypter_decrypt( - crypter, nonce, nonce_length, aad, aad_length, nullptr, - ciphertext_and_tag_length, plaintext, plaintext_length, - &plaintext_bytes_written, &error_message); - - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "ciphertext is nullptr.")); - gpr_free(error_message); - - /* nullptr plaintext */ - status = gsec_aead_crypter_decrypt( - crypter, nonce, nonce_length, aad, aad_length, ciphertext_and_tag, - ciphertext_and_tag_length, nullptr, plaintext_length, - &plaintext_bytes_written, &error_message); - - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "plaintext is nullptr, but plaintext_length is positive.")); - gpr_free(error_message); - - /* Short plaintext */ - status = gsec_aead_crypter_decrypt( - crypter, nonce, nonce_length, aad, aad_length, ciphertext_and_tag, - ciphertext_and_tag_length, plaintext, plaintext_length - 1, - &plaintext_bytes_written, &error_message); - - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "Not enough plaintext buffer to hold encrypted ciphertext.")); - gpr_free(error_message); - - /* nullptr plaintext_bytes_written */ - status = gsec_aead_crypter_decrypt(crypter, nonce, nonce_length, aad, - aad_length, ciphertext_and_tag, - ciphertext_and_tag_length, plaintext, - plaintext_length, nullptr, &error_message); - - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "bytes_written is nullptr.")); - gpr_free(error_message); - - gpr_free(message); - gpr_free(plaintext); - gpr_free(ciphertext_and_tag); - gpr_free(aad); - gpr_free(nonce); -} - -static void gsec_test_encrypt_decrypt_test_vector( - gsec_aead_crypter* crypter, gsec_aead_test_vector* test_vector) { - GPR_ASSERT(crypter != nullptr); - /* Test byte-based encryption interface. */ - size_t ciphertext_and_tag_length, ciphertext_bytes_written = 0; - gsec_aead_crypter_max_ciphertext_and_tag_length( - crypter, test_vector->plaintext_length, &ciphertext_and_tag_length, - nullptr); - uint8_t* ciphertext_and_tag_bytes = - static_cast(gpr_malloc(ciphertext_and_tag_length)); - grpc_status_code status = gsec_aead_crypter_encrypt( - crypter, test_vector->nonce, test_vector->nonce_length, test_vector->aad, - test_vector->aad_length, test_vector->plaintext, - test_vector->plaintext_length, ciphertext_and_tag_bytes, - ciphertext_and_tag_length, &ciphertext_bytes_written, nullptr); - - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(ciphertext_bytes_written == ciphertext_and_tag_length); - GPR_ASSERT(memcmp(test_vector->ciphertext_and_tag, ciphertext_and_tag_bytes, - ciphertext_and_tag_length) == 0); - - /* Test byte-based decryption interface */ - size_t plaintext_length, plaintext_bytes_written = 0; - gsec_aead_crypter_max_plaintext_length(crypter, ciphertext_and_tag_length, - &plaintext_length, nullptr); - uint8_t* plaintext_bytes = - static_cast(gpr_malloc(plaintext_length)); - status = gsec_aead_crypter_decrypt( - crypter, test_vector->nonce, test_vector->nonce_length, test_vector->aad, - test_vector->aad_length, test_vector->ciphertext_and_tag, - test_vector->ciphertext_and_tag_length, plaintext_bytes, plaintext_length, - &plaintext_bytes_written, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(memcmp(test_vector->plaintext, plaintext_bytes, - plaintext_bytes_written) == 0); - - gpr_free(ciphertext_and_tag_bytes); - gpr_free(plaintext_bytes); -} - -static void gsec_test_get_crypter_from_test_vector( - gsec_aead_crypter** crypter, gsec_aead_test_vector* test_vector, - bool rekey = false) { - size_t key_length = test_vector->key_length; - GPR_ASSERT(key_length == kAes128GcmKeyLength || - key_length == kAes256GcmKeyLength || - key_length == kAes128GcmRekeyKeyLength); - size_t nonce_length = test_vector->nonce_length; - GPR_ASSERT(nonce_length == kAesGcmNonceLength); - size_t plaintext_length = test_vector->plaintext_length; - size_t ciphertext_and_tag_length = test_vector->ciphertext_and_tag_length; - GPR_ASSERT(ciphertext_and_tag_length == plaintext_length + kAesGcmTagLength); - size_t tag_length = ciphertext_and_tag_length - plaintext_length; - gsec_aes_gcm_aead_crypter_create(test_vector->key, key_length, nonce_length, - tag_length, rekey, crypter, nullptr); -} - -static void gsec_test_verify_crypter_on_test_vector( - gsec_aead_test_vector* test_vector, bool rekey = false) { - gsec_aead_crypter* crypter; - gsec_test_get_crypter_from_test_vector(&crypter, test_vector, rekey); - gsec_test_encrypt_decrypt_test_vector(crypter, test_vector); - gsec_aead_crypter_destroy(crypter); -} - -static void gsec_aead_malloc_test_vector( - gsec_aead_test_vector** test_vector, const uint8_t* key, size_t key_length, - const uint8_t* nonce, size_t nonce_length, const uint8_t* aad, - size_t aad_length, const uint8_t* plaintext, size_t plaintext_length, - const uint8_t* ciphertext_and_tag, size_t ciphertext_and_tag_length) { - *test_vector = static_cast( - gpr_malloc(sizeof(gsec_aead_test_vector))); - (*test_vector)->key_length = key_length; - (*test_vector)->nonce_length = nonce_length; - (*test_vector)->aad_length = aad_length; - (*test_vector)->plaintext_length = plaintext_length; - (*test_vector)->ciphertext_and_tag_length = ciphertext_and_tag_length; - gsec_test_copy(key, &((*test_vector)->key), key_length); - gsec_test_copy(nonce, &((*test_vector)->nonce), nonce_length); - gsec_test_copy(aad, &((*test_vector)->aad), aad_length); - gsec_test_copy(plaintext, &((*test_vector)->plaintext), plaintext_length); - gsec_test_copy(ciphertext_and_tag, &((*test_vector)->ciphertext_and_tag), - ciphertext_and_tag_length); -} - -static void gsec_aead_free_test_vector(gsec_aead_test_vector* test_vector) { - gpr_free(test_vector->key); - gpr_free(test_vector->nonce); - gpr_free(test_vector->aad); - gpr_free(test_vector->plaintext); - gpr_free(test_vector->ciphertext_and_tag); - gpr_free(test_vector); -} - -static void gsec_test_create_random_aes_gcm_crypter(gsec_aead_crypter** crypter, - size_t key_length, - size_t nonce_length, - size_t tag_length, - bool rekey) { - uint8_t* key; - gsec_test_random_array(&key, key_length); - gsec_aes_gcm_aead_crypter_create(key, key_length, nonce_length, tag_length, - rekey, crypter, nullptr); - gpr_free(key); -} - -static void gsec_test_get_random_aes_gcm_crypters( - gsec_aead_crypter*** crypters) { - *crypters = static_cast( - gpr_malloc(sizeof(gsec_aead_crypter*) * kTestNumCrypters)); - gsec_test_create_random_aes_gcm_crypter( - &((*crypters)[0]), kAes128GcmKeyLength, kAesGcmNonceLength, - kAesGcmTagLength, /*rekey=*/false); - gsec_test_create_random_aes_gcm_crypter( - &((*crypters)[1]), kAes256GcmKeyLength, kAesGcmNonceLength, - kAesGcmTagLength, /*rekey=*/false); - gsec_test_create_random_aes_gcm_crypter( - &((*crypters)[2]), kAes128GcmRekeyKeyLength, kAesGcmNonceLength, - kAesGcmTagLength, /*rekey=*/true); -} - -static void gsec_test_do_generic_crypter_tests() { - gsec_aead_crypter** crypters; - gsec_test_get_random_aes_gcm_crypters(&crypters); - size_t ind; - for (ind = 0; ind < kTestNumCrypters; ind++) { - gsec_test_encrypt_decrypt(crypters[ind]); - gsec_test_multiple_encrypt_decrypt(crypters[ind]); - gsec_test_encryption_failure(crypters[ind]); - gsec_test_decryption_failure(crypters[ind]); - } - for (ind = 0; ind < kTestNumCrypters; ind++) { - gsec_aead_crypter_destroy(crypters[ind]); - } - gpr_free(crypters); -} - -static void gsec_test_do_vector_tests_rekey_nist() { - // NIST vectors from: - // http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm-revised-spec.pdf - // - // IEEE vectors from: - // http://www.ieee802.org/1/files/public/docs2011/bn-randall-test-vectors-0511-v1.pdf - // - // Key expanded by setting expandedKey = (key||(key ^ {0x01, .., 0x01})||key ^ - // {0x02,..,0x02}))[0:44]. - - gsec_aead_test_vector vec; - - // Derived from NIST test vector 1 - uint8_t nonce_0[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; - uint8_t aad_0[1] = {}; - uint8_t key_0[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, - 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x2, - 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2}; - uint8_t plaintext_0[1] = {}; - uint8_t ciphertext_0[] = {0x85, 0xE8, 0x73, 0xE0, 0x2, 0xF6, 0xEB, 0xDC, - 0x40, 0x60, 0x95, 0x4E, 0xB8, 0x67, 0x55, 0x8}; - vec = {nonce_0, aad_0, key_0, plaintext_0, ciphertext_0, 12, 0, 44, 0, 16}; - gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); - - // Derived from NIST test vector 2 - uint8_t nonce_1[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; - uint8_t aad_1[1] = {}; - uint8_t key_1[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, - 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x2, - 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2}; - uint8_t plaintext_1[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; - uint8_t ciphertext_1[] = {0x51, 0xE9, 0xA8, 0xCB, 0x23, 0xCA, 0x25, 0x12, - 0xC8, 0x25, 0x6A, 0xFF, 0xF8, 0xE7, 0x2D, 0x68, - 0x1A, 0xCA, 0x19, 0xA1, 0x14, 0x8A, 0xC1, 0x15, - 0xE8, 0x3D, 0xF4, 0x88, 0x8C, 0xC0, 0xD, 0x11}; - vec = {nonce_1, aad_1, key_1, plaintext_1, ciphertext_1, 12, 0, 44, 16, 32}; - gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); - - // Derived from NIST test vector 3 - uint8_t nonce_2[] = {0xCA, 0xFE, 0xBA, 0xBE, 0xFA, 0xCE, - 0xDB, 0xAD, 0xDE, 0xCA, 0xF8, 0x88}; - uint8_t aad_2[1] = {}; - uint8_t key_2[] = {0xFE, 0xFF, 0xE9, 0x92, 0x86, 0x65, 0x73, 0x1C, 0x6D, - 0x6A, 0x8F, 0x94, 0x67, 0x30, 0x83, 0x8, 0xFF, 0xFE, - 0xE8, 0x93, 0x87, 0x64, 0x72, 0x1D, 0x6C, 0x6B, 0x8E, - 0x95, 0x66, 0x31, 0x82, 0x9, 0xFC, 0xFD, 0xEB, 0x90, - 0x84, 0x67, 0x71, 0x1E, 0x6F, 0x68, 0x8D, 0x96}; - uint8_t plaintext_2[] = { - 0xD9, 0x31, 0x32, 0x25, 0xF8, 0x84, 0x6, 0xE5, 0xA5, 0x59, 0x9, - 0xC5, 0xAF, 0xF5, 0x26, 0x9A, 0x86, 0xA7, 0xA9, 0x53, 0x15, 0x34, - 0xF7, 0xDA, 0x2E, 0x4C, 0x30, 0x3D, 0x8A, 0x31, 0x8A, 0x72, 0x1C, - 0x3C, 0xC, 0x95, 0x95, 0x68, 0x9, 0x53, 0x2F, 0xCF, 0xE, 0x24, - 0x49, 0xA6, 0xB5, 0x25, 0xB1, 0x6A, 0xED, 0xF5, 0xAA, 0xD, 0xE6, - 0x57, 0xBA, 0x63, 0x7B, 0x39, 0x1A, 0xAF, 0xD2, 0x55}; - uint8_t ciphertext_2[] = { - 0x10, 0x18, 0xED, 0x5A, 0x14, 0x2, 0xA8, 0x65, 0x16, 0xD6, 0x57, 0x6D, - 0x70, 0xB2, 0xFF, 0xCC, 0xCA, 0x26, 0x1B, 0x94, 0xDF, 0x88, 0xB5, 0x8F, - 0x53, 0xB6, 0x4D, 0xFB, 0xA4, 0x35, 0xD1, 0x8B, 0x2F, 0x6E, 0x3B, 0x78, - 0x69, 0xF9, 0x35, 0x3D, 0x4A, 0xC8, 0xCF, 0x9, 0xAF, 0xB1, 0x66, 0x3D, - 0xAA, 0x7B, 0x40, 0x17, 0xE6, 0xFC, 0x2C, 0x17, 0x7C, 0xC, 0x8, 0x7C, - 0xD, 0xF1, 0x16, 0x21, 0x29, 0x95, 0x22, 0x13, 0xCE, 0xE1, 0xBC, 0x6E, - 0x9C, 0x84, 0x95, 0xDD, 0x70, 0x5E, 0x1F, 0x3D}; - vec = {nonce_2, aad_2, key_2, plaintext_2, ciphertext_2, 12, 0, 44, 64, 80}; - gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); - - // Derived from NIST test vector 4 - uint8_t nonce_3[] = {0xCA, 0xFE, 0xBA, 0xBE, 0xFA, 0xCE, - 0xDB, 0xAD, 0xDE, 0xCA, 0xF8, 0x88}; - uint8_t aad_3[] = {0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, - 0xEF, 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, - 0xBE, 0xEF, 0xAB, 0xAD, 0xDA, 0xD2}; - uint8_t key_3[] = {0xFE, 0xFF, 0xE9, 0x92, 0x86, 0x65, 0x73, 0x1C, 0x6D, - 0x6A, 0x8F, 0x94, 0x67, 0x30, 0x83, 0x8, 0xFF, 0xFE, - 0xE8, 0x93, 0x87, 0x64, 0x72, 0x1D, 0x6C, 0x6B, 0x8E, - 0x95, 0x66, 0x31, 0x82, 0x9, 0xFC, 0xFD, 0xEB, 0x90, - 0x84, 0x67, 0x71, 0x1E, 0x6F, 0x68, 0x8D, 0x96}; - uint8_t plaintext_3[] = { - 0xD9, 0x31, 0x32, 0x25, 0xF8, 0x84, 0x6, 0xE5, 0xA5, 0x59, 0x9, 0xC5, - 0xAF, 0xF5, 0x26, 0x9A, 0x86, 0xA7, 0xA9, 0x53, 0x15, 0x34, 0xF7, 0xDA, - 0x2E, 0x4C, 0x30, 0x3D, 0x8A, 0x31, 0x8A, 0x72, 0x1C, 0x3C, 0xC, 0x95, - 0x95, 0x68, 0x9, 0x53, 0x2F, 0xCF, 0xE, 0x24, 0x49, 0xA6, 0xB5, 0x25, - 0xB1, 0x6A, 0xED, 0xF5, 0xAA, 0xD, 0xE6, 0x57, 0xBA, 0x63, 0x7B, 0x39}; - uint8_t ciphertext_3[] = { - 0x10, 0x18, 0xED, 0x5A, 0x14, 0x2, 0xA8, 0x65, 0x16, 0xD6, 0x57, - 0x6D, 0x70, 0xB2, 0xFF, 0xCC, 0xCA, 0x26, 0x1B, 0x94, 0xDF, 0x88, - 0xB5, 0x8F, 0x53, 0xB6, 0x4D, 0xFB, 0xA4, 0x35, 0xD1, 0x8B, 0x2F, - 0x6E, 0x3B, 0x78, 0x69, 0xF9, 0x35, 0x3D, 0x4A, 0xC8, 0xCF, 0x9, - 0xAF, 0xB1, 0x66, 0x3D, 0xAA, 0x7B, 0x40, 0x17, 0xE6, 0xFC, 0x2C, - 0x17, 0x7C, 0xC, 0x8, 0x7C, 0x47, 0x64, 0x56, 0x5D, 0x7, 0x7E, - 0x91, 0x24, 0x0, 0x1D, 0xDB, 0x27, 0xFC, 0x8, 0x48, 0xC5}; - vec = {nonce_3, aad_3, key_3, plaintext_3, ciphertext_3, 12, 20, 44, 60, 76}; - gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); - - // Derived from adapted NIST test vector 4 for KDF counter boundary (flip - // nonce bit 15) - uint8_t nonce_4[] = {0xCA, 0x7E, 0xBA, 0xBE, 0xFA, 0xCE, - 0xDB, 0xAD, 0xDE, 0xCA, 0xF8, 0x88}; - uint8_t aad_4[] = {0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, - 0xEF, 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, - 0xBE, 0xEF, 0xAB, 0xAD, 0xDA, 0xD2}; - uint8_t key_4[] = {0xFE, 0xFF, 0xE9, 0x92, 0x86, 0x65, 0x73, 0x1C, 0x6D, - 0x6A, 0x8F, 0x94, 0x67, 0x30, 0x83, 0x8, 0xFF, 0xFE, - 0xE8, 0x93, 0x87, 0x64, 0x72, 0x1D, 0x6C, 0x6B, 0x8E, - 0x95, 0x66, 0x31, 0x82, 0x9, 0xFC, 0xFD, 0xEB, 0x90, - 0x84, 0x67, 0x71, 0x1E, 0x6F, 0x68, 0x8D, 0x96}; - uint8_t plaintext_4[] = { - 0xD9, 0x31, 0x32, 0x25, 0xF8, 0x84, 0x6, 0xE5, 0xA5, 0x59, 0x9, 0xC5, - 0xAF, 0xF5, 0x26, 0x9A, 0x86, 0xA7, 0xA9, 0x53, 0x15, 0x34, 0xF7, 0xDA, - 0x2E, 0x4C, 0x30, 0x3D, 0x8A, 0x31, 0x8A, 0x72, 0x1C, 0x3C, 0xC, 0x95, - 0x95, 0x68, 0x9, 0x53, 0x2F, 0xCF, 0xE, 0x24, 0x49, 0xA6, 0xB5, 0x25, - 0xB1, 0x6A, 0xED, 0xF5, 0xAA, 0xD, 0xE6, 0x57, 0xBA, 0x63, 0x7B, 0x39}; - uint8_t ciphertext_4[] = { - 0xE6, 0x50, 0xD3, 0xC0, 0xFB, 0x87, 0x93, 0x27, 0xF2, 0xD0, 0x32, - 0x87, 0xFA, 0x93, 0xCD, 0x7, 0x34, 0x2B, 0x13, 0x62, 0x15, 0xAD, - 0xBC, 0xA0, 0xC, 0x3B, 0xD5, 0x9, 0x9E, 0xC4, 0x18, 0x32, 0xB1, - 0xD1, 0x8E, 0x4, 0x23, 0xED, 0x26, 0xBB, 0x12, 0xC6, 0xCD, 0x9, - 0xDE, 0xBB, 0x29, 0x23, 0xA, 0x94, 0xC0, 0xCE, 0xE1, 0x59, 0x3, - 0x65, 0x6F, 0x85, 0xED, 0xB6, 0xFC, 0x50, 0x9B, 0x1B, 0x28, 0x21, - 0x63, 0x82, 0x17, 0x2E, 0xCB, 0xCC, 0x31, 0xE1, 0xE9, 0xB1}; - vec = {nonce_4, aad_4, key_4, plaintext_4, ciphertext_4, 12, 20, 44, 60, 76}; - gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); - - // Derived from adapted NIST test vector 4 for KDF counter boundary (flip - // nonce bit 16) - uint8_t nonce_5[] = {0xCA, 0xFE, 0xBB, 0xBE, 0xFA, 0xCE, - 0xDB, 0xAD, 0xDE, 0xCA, 0xF8, 0x88}; - uint8_t aad_5[] = {0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, - 0xEF, 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, - 0xBE, 0xEF, 0xAB, 0xAD, 0xDA, 0xD2}; - uint8_t key_5[] = {0xFE, 0xFF, 0xE9, 0x92, 0x86, 0x65, 0x73, 0x1C, 0x6D, - 0x6A, 0x8F, 0x94, 0x67, 0x30, 0x83, 0x8, 0xFF, 0xFE, - 0xE8, 0x93, 0x87, 0x64, 0x72, 0x1D, 0x6C, 0x6B, 0x8E, - 0x95, 0x66, 0x31, 0x82, 0x9, 0xFC, 0xFD, 0xEB, 0x90, - 0x84, 0x67, 0x71, 0x1E, 0x6F, 0x68, 0x8D, 0x96}; - uint8_t plaintext_5[] = { - 0xD9, 0x31, 0x32, 0x25, 0xF8, 0x84, 0x6, 0xE5, 0xA5, 0x59, 0x9, 0xC5, - 0xAF, 0xF5, 0x26, 0x9A, 0x86, 0xA7, 0xA9, 0x53, 0x15, 0x34, 0xF7, 0xDA, - 0x2E, 0x4C, 0x30, 0x3D, 0x8A, 0x31, 0x8A, 0x72, 0x1C, 0x3C, 0xC, 0x95, - 0x95, 0x68, 0x9, 0x53, 0x2F, 0xCF, 0xE, 0x24, 0x49, 0xA6, 0xB5, 0x25, - 0xB1, 0x6A, 0xED, 0xF5, 0xAA, 0xD, 0xE6, 0x57, 0xBA, 0x63, 0x7B, 0x39}; - uint8_t ciphertext_5[] = { - 0xC0, 0x12, 0x1E, 0x6C, 0x95, 0x4D, 0x7, 0x67, 0xF9, 0x66, 0x30, - 0xC3, 0x34, 0x50, 0x99, 0x97, 0x91, 0xB2, 0xDA, 0x2A, 0xD0, 0x5C, - 0x41, 0x90, 0x16, 0x9C, 0xCA, 0xD9, 0xAC, 0x86, 0xFF, 0x1C, 0x72, - 0x1E, 0x3D, 0x82, 0xF2, 0xAD, 0x22, 0xAB, 0x46, 0x3B, 0xAB, 0x4A, - 0x7, 0x54, 0xB7, 0xDD, 0x68, 0xCA, 0x4D, 0xE7, 0xEA, 0x25, 0x31, - 0xB6, 0x25, 0xED, 0xA0, 0x1F, 0x89, 0x31, 0x2B, 0x2A, 0xB9, 0x57, - 0xD5, 0xC7, 0xF8, 0x56, 0x8D, 0xD9, 0x5F, 0xCD, 0xCD, 0x1F}; - vec = {nonce_5, aad_5, key_5, plaintext_5, ciphertext_5, 12, 20, 44, 60, 76}; - gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); - - // Derived from adapted NIST test vector 4 for KDF counter boundary (flip - // nonce bit 63) - uint8_t nonce_6[] = {0xCA, 0xFE, 0xBA, 0xBE, 0xFA, 0xCE, - 0xDB, 0x2D, 0xDE, 0xCA, 0xF8, 0x88}; - uint8_t aad_6[] = {0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, - 0xEF, 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, - 0xBE, 0xEF, 0xAB, 0xAD, 0xDA, 0xD2}; - uint8_t key_6[] = {0xFE, 0xFF, 0xE9, 0x92, 0x86, 0x65, 0x73, 0x1C, 0x6D, - 0x6A, 0x8F, 0x94, 0x67, 0x30, 0x83, 0x8, 0xFF, 0xFE, - 0xE8, 0x93, 0x87, 0x64, 0x72, 0x1D, 0x6C, 0x6B, 0x8E, - 0x95, 0x66, 0x31, 0x82, 0x9, 0xFC, 0xFD, 0xEB, 0x90, - 0x84, 0x67, 0x71, 0x1E, 0x6F, 0x68, 0x8D, 0x96}; - uint8_t plaintext_6[] = { - 0xD9, 0x31, 0x32, 0x25, 0xF8, 0x84, 0x6, 0xE5, 0xA5, 0x59, 0x9, 0xC5, - 0xAF, 0xF5, 0x26, 0x9A, 0x86, 0xA7, 0xA9, 0x53, 0x15, 0x34, 0xF7, 0xDA, - 0x2E, 0x4C, 0x30, 0x3D, 0x8A, 0x31, 0x8A, 0x72, 0x1C, 0x3C, 0xC, 0x95, - 0x95, 0x68, 0x9, 0x53, 0x2F, 0xCF, 0xE, 0x24, 0x49, 0xA6, 0xB5, 0x25, - 0xB1, 0x6A, 0xED, 0xF5, 0xAA, 0xD, 0xE6, 0x57, 0xBA, 0x63, 0x7B, 0x39}; - uint8_t ciphertext_6[] = { - 0x8A, 0xF3, 0x7E, 0xA5, 0x68, 0x4A, 0x4D, 0x81, 0xD4, 0xFD, 0x81, - 0x72, 0x61, 0xFD, 0x97, 0x43, 0x9, 0x9E, 0x7E, 0x6A, 0x2, 0x5E, - 0xAA, 0xCF, 0x8E, 0x54, 0xB1, 0x24, 0xFB, 0x57, 0x43, 0x14, 0x9E, - 0x5, 0xCB, 0x89, 0xF4, 0xA4, 0x94, 0x67, 0xFE, 0x2E, 0x5E, 0x59, - 0x65, 0xF2, 0x9A, 0x19, 0xF9, 0x94, 0x16, 0xB0, 0x1, 0x6B, 0x54, - 0x58, 0x5D, 0x12, 0x55, 0x37, 0x83, 0xBA, 0x59, 0xE9, 0xF7, 0x82, - 0xE8, 0x2E, 0x9, 0x7C, 0x33, 0x6B, 0xF7, 0x98, 0x9F, 0x8}; - vec = {nonce_6, aad_6, key_6, plaintext_6, ciphertext_6, 12, 20, 44, 60, 76}; - gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); - - // Derived from adapted NIST test vector 4 for KDF counter boundary (flip - // nonce bit 64) - uint8_t nonce_7[] = {0xCA, 0xFE, 0xBA, 0xBE, 0xFA, 0xCE, - 0xDB, 0xAD, 0xDF, 0xCA, 0xF8, 0x88}; - uint8_t aad_7[] = {0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, - 0xEF, 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, - 0xBE, 0xEF, 0xAB, 0xAD, 0xDA, 0xD2}; - uint8_t key_7[] = {0xFE, 0xFF, 0xE9, 0x92, 0x86, 0x65, 0x73, 0x1C, 0x6D, - 0x6A, 0x8F, 0x94, 0x67, 0x30, 0x83, 0x8, 0xFF, 0xFE, - 0xE8, 0x93, 0x87, 0x64, 0x72, 0x1D, 0x6C, 0x6B, 0x8E, - 0x95, 0x66, 0x31, 0x82, 0x9, 0xFC, 0xFD, 0xEB, 0x90, - 0x84, 0x67, 0x71, 0x1E, 0x6F, 0x68, 0x8D, 0x96}; - uint8_t plaintext_7[] = { - 0xD9, 0x31, 0x32, 0x25, 0xF8, 0x84, 0x6, 0xE5, 0xA5, 0x59, 0x9, 0xC5, - 0xAF, 0xF5, 0x26, 0x9A, 0x86, 0xA7, 0xA9, 0x53, 0x15, 0x34, 0xF7, 0xDA, - 0x2E, 0x4C, 0x30, 0x3D, 0x8A, 0x31, 0x8A, 0x72, 0x1C, 0x3C, 0xC, 0x95, - 0x95, 0x68, 0x9, 0x53, 0x2F, 0xCF, 0xE, 0x24, 0x49, 0xA6, 0xB5, 0x25, - 0xB1, 0x6A, 0xED, 0xF5, 0xAA, 0xD, 0xE6, 0x57, 0xBA, 0x63, 0x7B, 0x39}; - uint8_t ciphertext_7[] = { - 0xFB, 0xD5, 0x28, 0x44, 0x8D, 0x3, 0x46, 0xBF, 0xA8, 0x78, 0x63, - 0x48, 0x64, 0xD4, 0x7, 0xA3, 0x5A, 0x3, 0x9D, 0xE9, 0xDB, 0x2F, - 0x1F, 0xEB, 0x8E, 0x96, 0x5B, 0x3A, 0xE9, 0x35, 0x6C, 0xE6, 0x28, - 0x94, 0x41, 0xD7, 0x7F, 0x8F, 0xD, 0xF2, 0x94, 0x89, 0x1F, 0x37, - 0xEA, 0x43, 0x8B, 0x22, 0x3E, 0x3B, 0xF2, 0xBD, 0xC5, 0x3D, 0x4C, - 0x5A, 0x74, 0xFB, 0x68, 0xB, 0xB3, 0x12, 0xA8, 0xDE, 0xC6, 0xF7, - 0x25, 0x2C, 0xBC, 0xD7, 0xF5, 0x79, 0x97, 0x50, 0xAD, 0x78}; - vec = {nonce_7, aad_7, key_7, plaintext_7, ciphertext_7, 12, 20, 44, 60, 76}; - gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); -} - -static void gsec_test_do_vector_tests_rekey_ieee() { - // IEEE vectors from: - // http://www.ieee802.org/1/files/public/docs2011/bn-randall-test-vectors-0511-v1.pdf - // - // Key expanded by setting expandedKey = (key||(key ^ {0x01, .., 0x01})||key ^ - // {0x02,..,0x02}))[0:44]. - - gsec_aead_test_vector vec; - - // Derived from IEEE 2.1.1 54-byte auth - uint8_t nonce_8[] = {0x12, 0x15, 0x35, 0x24, 0xC0, 0x89, - 0x5E, 0x81, 0xB2, 0xC2, 0x84, 0x65}; - uint8_t aad_8[] = {0xD6, 0x9, 0xB1, 0xF0, 0x56, 0x63, 0x7A, 0xD, 0x46, 0xDF, - 0x99, 0x8D, 0x88, 0xE5, 0x22, 0x2A, 0xB2, 0xC2, 0x84, 0x65, - 0x12, 0x15, 0x35, 0x24, 0xC0, 0x89, 0x5E, 0x81, 0x8, 0x0, - 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, - 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, - 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, - 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x0, 0x1}; - uint8_t key_8[] = {0xAD, 0x7A, 0x2B, 0xD0, 0x3E, 0xAC, 0x83, 0x5A, 0x6F, - 0x62, 0xF, 0xDC, 0xB5, 0x6, 0xB3, 0x45, 0xAC, 0x7B, - 0x2A, 0xD1, 0x3F, 0xAD, 0x82, 0x5B, 0x6E, 0x63, 0xE, - 0xDD, 0xB4, 0x7, 0xB2, 0x44, 0xAF, 0x78, 0x29, 0xD2, - 0x3C, 0xAE, 0x81, 0x58, 0x6D, 0x60, 0xD, 0xDE}; - uint8_t plaintext_8[1] = {}; - uint8_t ciphertext_8[] = {0x3E, 0xA0, 0xB5, 0x84, 0xF3, 0xC8, 0x5E, 0x93, - 0xF9, 0x32, 0xE, 0xA5, 0x91, 0x69, 0x9E, 0xFB}; - vec = {nonce_8, aad_8, key_8, plaintext_8, ciphertext_8, 12, 70, 44, 0, 16}; - gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); - - // Derived from IEEE 2.1.2 54-byte auth - uint8_t nonce_9[] = {0x12, 0x15, 0x35, 0x24, 0xC0, 0x89, - 0x5E, 0x81, 0xB2, 0xC2, 0x84, 0x65}; - uint8_t aad_9[] = {0xD6, 0x9, 0xB1, 0xF0, 0x56, 0x63, 0x7A, 0xD, 0x46, 0xDF, - 0x99, 0x8D, 0x88, 0xE5, 0x22, 0x2A, 0xB2, 0xC2, 0x84, 0x65, - 0x12, 0x15, 0x35, 0x24, 0xC0, 0x89, 0x5E, 0x81, 0x8, 0x0, - 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, - 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, - 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, - 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x0, 0x1}; - uint8_t key_9[] = {0xE3, 0xC0, 0x8A, 0x8F, 0x6, 0xC6, 0xE3, 0xAD, 0x95, - 0xA7, 0x5, 0x57, 0xB2, 0x3F, 0x75, 0x48, 0x3C, 0xE3, - 0x30, 0x21, 0xA9, 0xC7, 0x2B, 0x70, 0x25, 0x66, 0x62, - 0x4, 0xC6, 0x9C, 0xB, 0x72, 0xE1, 0xC2, 0x88, 0x8D, - 0x4, 0xC4, 0xE1, 0xAF, 0x97, 0xA5, 0x7, 0x55}; - uint8_t plaintext_9[1] = {}; - uint8_t ciphertext_9[] = {0x29, 0x4E, 0x2, 0x8B, 0xF1, 0xFE, 0x6F, 0x14, - 0xC4, 0xE8, 0xF7, 0x30, 0x5C, 0x93, 0x3E, 0xB5}; - vec = {nonce_9, aad_9, key_9, plaintext_9, ciphertext_9, 12, 70, 44, 0, 16}; - gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); - - // Derived from IEEE 2.2.1 60-byte crypt - uint8_t nonce_10[] = {0x12, 0x15, 0x35, 0x24, 0xC0, 0x89, - 0x5E, 0x81, 0xB2, 0xC2, 0x84, 0x65}; - uint8_t aad_10[] = {0xD6, 0x9, 0xB1, 0xF0, 0x56, 0x63, 0x7A, - 0xD, 0x46, 0xDF, 0x99, 0x8D, 0x88, 0xE5, - 0x2E, 0x0, 0xB2, 0xC2, 0x84, 0x65, 0x12, - 0x15, 0x35, 0x24, 0xC0, 0x89, 0x5E, 0x81}; - uint8_t key_10[] = {0xAD, 0x7A, 0x2B, 0xD0, 0x3E, 0xAC, 0x83, 0x5A, 0x6F, - 0x62, 0xF, 0xDC, 0xB5, 0x6, 0xB3, 0x45, 0xAC, 0x7B, - 0x2A, 0xD1, 0x3F, 0xAD, 0x82, 0x5B, 0x6E, 0x63, 0xE, - 0xDD, 0xB4, 0x7, 0xB2, 0x44, 0xAF, 0x78, 0x29, 0xD2, - 0x3C, 0xAE, 0x81, 0x58, 0x6D, 0x60, 0xD, 0xDE}; - uint8_t plaintext_10[] = { - 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, - 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, - 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, - 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x0, 0x2}; - uint8_t ciphertext_10[] = { - 0xDB, 0x3D, 0x25, 0x71, 0x9C, 0x6B, 0xA, 0x3C, 0xA6, 0x14, 0x5C, - 0x15, 0x9D, 0x5C, 0x6E, 0xD9, 0xAF, 0xF9, 0xC6, 0xE0, 0xB7, 0x9F, - 0x17, 0x1, 0x9E, 0xA9, 0x23, 0xB8, 0x66, 0x5D, 0xDF, 0x52, 0x13, - 0x7A, 0xD6, 0x11, 0xF0, 0xD1, 0xBF, 0x41, 0x7A, 0x7C, 0xA8, 0x5E, - 0x45, 0xAF, 0xE1, 0x6, 0xFF, 0x9C, 0x75, 0x69, 0xD3, 0x35, 0xD0, - 0x86, 0xAE, 0x6C, 0x3, 0xF0, 0x9, 0x87, 0xCC, 0xD6}; - vec = {nonce_10, aad_10, key_10, plaintext_10, ciphertext_10, - 12, 28, 44, 48, 64}; - gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); - - // Derived from IEEE 2.2.2 60-byte crypt - uint8_t nonce_11[] = {0x12, 0x15, 0x35, 0x24, 0xC0, 0x89, - 0x5E, 0x81, 0xB2, 0xC2, 0x84, 0x65}; - uint8_t aad_11[] = {0xD6, 0x9, 0xB1, 0xF0, 0x56, 0x63, 0x7A, - 0xD, 0x46, 0xDF, 0x99, 0x8D, 0x88, 0xE5, - 0x2E, 0x0, 0xB2, 0xC2, 0x84, 0x65, 0x12, - 0x15, 0x35, 0x24, 0xC0, 0x89, 0x5E, 0x81}; - uint8_t key_11[] = {0xE3, 0xC0, 0x8A, 0x8F, 0x6, 0xC6, 0xE3, 0xAD, 0x95, - 0xA7, 0x5, 0x57, 0xB2, 0x3F, 0x75, 0x48, 0x3C, 0xE3, - 0x30, 0x21, 0xA9, 0xC7, 0x2B, 0x70, 0x25, 0x66, 0x62, - 0x4, 0xC6, 0x9C, 0xB, 0x72, 0xE1, 0xC2, 0x88, 0x8D, - 0x4, 0xC4, 0xE1, 0xAF, 0x97, 0xA5, 0x7, 0x55}; - uint8_t plaintext_11[] = { - 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, - 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, - 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, - 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x0, 0x2}; - uint8_t ciphertext_11[] = { - 0x16, 0x41, 0xF2, 0x8E, 0xC1, 0x3A, 0xFC, 0xC8, 0xF7, 0x90, 0x33, - 0x89, 0x78, 0x72, 0x1, 0x5, 0x16, 0x44, 0x91, 0x49, 0x33, 0xE9, - 0x20, 0x2B, 0xB9, 0xD0, 0x6A, 0xA0, 0x20, 0xC2, 0xA6, 0x7E, 0xF5, - 0x1D, 0xFE, 0x7B, 0xC0, 0xA, 0x85, 0x6C, 0x55, 0xB8, 0xF8, 0x13, - 0x3E, 0x77, 0xF6, 0x59, 0x13, 0x25, 0x2, 0xBA, 0xD6, 0x3F, 0x57, - 0x13, 0xD5, 0x7D, 0xC, 0x11, 0xE0, 0xF8, 0x71, 0xED}; - vec = {nonce_11, aad_11, key_11, plaintext_11, ciphertext_11, - 12, 28, 44, 48, 64}; - gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); - - // Derived from IEEE 2.3.1 60-byte auth - uint8_t nonce_12[] = {0xF0, 0x76, 0x1E, 0x8D, 0xCD, 0x3D, - 0x0, 0x1, 0x76, 0xD4, 0x57, 0xED}; - uint8_t aad_12[] = { - 0xE2, 0x1, 0x6, 0xD7, 0xCD, 0xD, 0xF0, 0x76, 0x1E, 0x8D, 0xCD, 0x3D, - 0x88, 0xE5, 0x40, 0x0, 0x76, 0xD4, 0x57, 0xED, 0x8, 0x0, 0xF, 0x10, - 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, - 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, - 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, - 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x0, 0x3}; - uint8_t key_12[] = {0x7, 0x1B, 0x11, 0x3B, 0xC, 0xA7, 0x43, 0xFE, 0xCC, - 0xCF, 0x3D, 0x5, 0x1F, 0x73, 0x73, 0x82, 0x6, 0x1A, - 0x10, 0x3A, 0xD, 0xA6, 0x42, 0xFF, 0xCD, 0xCE, 0x3C, - 0x4, 0x1E, 0x72, 0x72, 0x83, 0x5, 0x19, 0x13, 0x39, - 0xE, 0xA5, 0x41, 0xFC, 0xCE, 0xCD, 0x3F, 0x7}; - uint8_t plaintext_12[1] = {}; - uint8_t ciphertext_12[] = {0x58, 0x83, 0x7A, 0x10, 0x56, 0x2B, 0xF, 0x1F, - 0x8E, 0xDB, 0xE5, 0x8C, 0xA5, 0x58, 0x11, 0xD3}; - vec = {nonce_12, aad_12, key_12, plaintext_12, ciphertext_12, 12, 68, - 44, 0, 16}; - gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); - - // Derived from IEEE 2.3.2 60-byte auth - uint8_t nonce_13[] = {0xF0, 0x76, 0x1E, 0x8D, 0xCD, 0x3D, - 0x0, 0x1, 0x76, 0xD4, 0x57, 0xED}; - uint8_t aad_13[] = { - 0xE2, 0x1, 0x6, 0xD7, 0xCD, 0xD, 0xF0, 0x76, 0x1E, 0x8D, 0xCD, 0x3D, - 0x88, 0xE5, 0x40, 0x0, 0x76, 0xD4, 0x57, 0xED, 0x8, 0x0, 0xF, 0x10, - 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, - 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, - 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, - 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x0, 0x3}; - uint8_t key_13[] = {0x69, 0x1D, 0x3E, 0xE9, 0x9, 0xD7, 0xF5, 0x41, 0x67, - 0xFD, 0x1C, 0xA0, 0xB5, 0xD7, 0x69, 0x8, 0x1F, 0x2B, - 0xDE, 0x1A, 0xEE, 0x65, 0x5F, 0xDB, 0xAB, 0x80, 0xBD, - 0x52, 0x95, 0xAE, 0x6B, 0xE7, 0x6B, 0x1F, 0x3C, 0xEB, - 0xB, 0xD5, 0xF7, 0x43, 0x65, 0xFF, 0x1E, 0xA2}; - uint8_t plaintext_13[1] = {}; - uint8_t ciphertext_13[] = {0xC2, 0x72, 0x2F, 0xF6, 0xCA, 0x29, 0xA2, 0x57, - 0x71, 0x8A, 0x52, 0x9D, 0x1F, 0xC, 0x6A, 0x3B}; - vec = {nonce_13, aad_13, key_13, plaintext_13, ciphertext_13, 12, 68, - 44, 0, 16}; - gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); - - // Derived from IEEE 2.4.1 54-byte crypt - uint8_t nonce_14[] = {0xF0, 0x76, 0x1E, 0x8D, 0xCD, 0x3D, - 0x0, 0x1, 0x76, 0xD4, 0x57, 0xED}; - uint8_t aad_14[] = {0xE2, 0x1, 0x6, 0xD7, 0xCD, 0xD, 0xF0, - 0x76, 0x1E, 0x8D, 0xCD, 0x3D, 0x88, 0xE5, - 0x4C, 0x2A, 0x76, 0xD4, 0x57, 0xED}; - uint8_t key_14[] = {0x7, 0x1B, 0x11, 0x3B, 0xC, 0xA7, 0x43, 0xFE, 0xCC, - 0xCF, 0x3D, 0x5, 0x1F, 0x73, 0x73, 0x82, 0x6, 0x1A, - 0x10, 0x3A, 0xD, 0xA6, 0x42, 0xFF, 0xCD, 0xCE, 0x3C, - 0x4, 0x1E, 0x72, 0x72, 0x83, 0x5, 0x19, 0x13, 0x39, - 0xE, 0xA5, 0x41, 0xFC, 0xCE, 0xCD, 0x3F, 0x7}; - uint8_t plaintext_14[] = { - 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, - 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, - 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x0, 0x4}; - uint8_t ciphertext_14[] = { - 0xFD, 0x96, 0xB7, 0x15, 0xB9, 0x3A, 0x13, 0x34, 0x6A, 0xF5, 0x1E, 0x8A, - 0xCD, 0xF7, 0x92, 0xCD, 0xC7, 0xB2, 0x68, 0x6F, 0x85, 0x74, 0xC7, 0xE, - 0x6B, 0xC, 0xBF, 0x16, 0x29, 0x1D, 0xED, 0x42, 0x7A, 0xD7, 0x3F, 0xEC, - 0x48, 0xCD, 0x29, 0x8E, 0x5, 0x28, 0xA1, 0xF4, 0xC6, 0x44, 0xA9, 0x49, - 0xFC, 0x31, 0xDC, 0x92, 0x79, 0x70, 0x6D, 0xDB, 0xA3, 0x3F}; - vec = {nonce_14, aad_14, key_14, plaintext_14, ciphertext_14, - 12, 20, 44, 42, 58}; - gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); - - // Derived from IEEE 2.4.2 54-byte crypt - uint8_t nonce_15[] = {0xF0, 0x76, 0x1E, 0x8D, 0xCD, 0x3D, - 0x0, 0x1, 0x76, 0xD4, 0x57, 0xED}; - uint8_t aad_15[] = {0xE2, 0x1, 0x6, 0xD7, 0xCD, 0xD, 0xF0, - 0x76, 0x1E, 0x8D, 0xCD, 0x3D, 0x88, 0xE5, - 0x4C, 0x2A, 0x76, 0xD4, 0x57, 0xED}; - uint8_t key_15[] = {0x69, 0x1D, 0x3E, 0xE9, 0x9, 0xD7, 0xF5, 0x41, 0x67, - 0xFD, 0x1C, 0xA0, 0xB5, 0xD7, 0x69, 0x8, 0x1F, 0x2B, - 0xDE, 0x1A, 0xEE, 0x65, 0x5F, 0xDB, 0xAB, 0x80, 0xBD, - 0x52, 0x95, 0xAE, 0x6B, 0xE7, 0x6B, 0x1F, 0x3C, 0xEB, - 0xB, 0xD5, 0xF7, 0x43, 0x65, 0xFF, 0x1E, 0xA2}; - uint8_t plaintext_15[] = { - 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, - 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, - 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x0, 0x4}; - uint8_t ciphertext_15[] = { - 0xB6, 0x8F, 0x63, 0x0, 0xC2, 0xE9, 0xAE, 0x83, 0x3B, 0xDC, 0x7, 0xE, - 0x24, 0x2, 0x1A, 0x34, 0x77, 0x11, 0x8E, 0x78, 0xCC, 0xF8, 0x4E, 0x11, - 0xA4, 0x85, 0xD8, 0x61, 0x47, 0x6C, 0x30, 0xF, 0x17, 0x53, 0x53, 0xD5, - 0xCD, 0xF9, 0x20, 0x8, 0xA4, 0xF8, 0x78, 0xE6, 0xCC, 0x35, 0x77, 0x76, - 0x80, 0x85, 0xC5, 0xA, 0xE, 0x98, 0xFD, 0xA6, 0xCB, 0xB8}; - vec = {nonce_15, aad_15, key_15, plaintext_15, ciphertext_15, - 12, 20, 44, 42, 58}; - gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); - - // Derived from IEEE 2.5.1 65-byte auth - uint8_t nonce_16[] = {0x7C, 0xFD, 0xE9, 0xF9, 0xE3, 0x37, - 0x24, 0xC6, 0x89, 0x32, 0xD6, 0x12}; - uint8_t aad_16[] = { - 0x84, 0xC5, 0xD5, 0x13, 0xD2, 0xAA, 0xF6, 0xE5, 0xBB, 0xD2, 0x72, 0x77, - 0x88, 0xE5, 0x23, 0x0, 0x89, 0x32, 0xD6, 0x12, 0x7C, 0xFD, 0xE9, 0xF9, - 0xE3, 0x37, 0x24, 0xC6, 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, - 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, - 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, - 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, - 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x0, 0x5}; - uint8_t key_16[] = {0x1, 0x3F, 0xE0, 0xB, 0x5F, 0x11, 0xBE, 0x7F, 0x86, - 0x6D, 0xC, 0xBB, 0xC5, 0x5A, 0x7A, 0x90, 0x0, 0x3E, - 0xE1, 0xA, 0x5E, 0x10, 0xBF, 0x7E, 0x87, 0x6C, 0xD, - 0xBA, 0xC4, 0x5B, 0x7B, 0x91, 0x3, 0x3D, 0xE2, 0x9, - 0x5D, 0x13, 0xBC, 0x7D, 0x84, 0x6F, 0xE, 0xB9}; - uint8_t plaintext_16[1] = {}; - uint8_t ciphertext_16[] = {0xCC, 0xA2, 0xE, 0xEC, 0xDA, 0x62, 0x83, 0xF0, - 0x9B, 0xB3, 0x54, 0x3D, 0xD9, 0x9E, 0xDB, 0x9B}; - vec = {nonce_16, aad_16, key_16, plaintext_16, ciphertext_16, 12, 81, - 44, 0, 16}; - gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); - - // Derived from IEEE 2.5.2 65-byte auth - uint8_t nonce_17[] = {0x7C, 0xFD, 0xE9, 0xF9, 0xE3, 0x37, - 0x24, 0xC6, 0x89, 0x32, 0xD6, 0x12}; - uint8_t aad_17[] = { - 0x84, 0xC5, 0xD5, 0x13, 0xD2, 0xAA, 0xF6, 0xE5, 0xBB, 0xD2, 0x72, 0x77, - 0x88, 0xE5, 0x23, 0x0, 0x89, 0x32, 0xD6, 0x12, 0x7C, 0xFD, 0xE9, 0xF9, - 0xE3, 0x37, 0x24, 0xC6, 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, - 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, - 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, - 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, - 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x0, 0x5}; - uint8_t key_17[] = {0x83, 0xC0, 0x93, 0xB5, 0x8D, 0xE7, 0xFF, 0xE1, 0xC0, - 0xDA, 0x92, 0x6A, 0xC4, 0x3F, 0xB3, 0x60, 0x9A, 0xC1, - 0xC8, 0xF, 0xEE, 0x1B, 0x62, 0x44, 0x97, 0xEF, 0x94, - 0x2E, 0x2F, 0x79, 0xA8, 0x23, 0x81, 0xC2, 0x91, 0xB7, - 0x8F, 0xE5, 0xFD, 0xE3, 0xC2, 0xD8, 0x90, 0x68}; - uint8_t plaintext_17[1] = {}; - uint8_t ciphertext_17[] = {0xB2, 0x32, 0xCC, 0x1D, 0xA5, 0x11, 0x7B, 0xF1, - 0x50, 0x3, 0x73, 0x4F, 0xA5, 0x99, 0xD2, 0x71}; - vec = {nonce_17, aad_17, key_17, plaintext_17, ciphertext_17, 12, 81, - 44, 0, 16}; - gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); - - // Derived from IEEE 2.6.1 61-byte crypt - uint8_t nonce_18[] = {0x7C, 0xFD, 0xE9, 0xF9, 0xE3, 0x37, - 0x24, 0xC6, 0x89, 0x32, 0xD6, 0x12}; - uint8_t aad_18[] = {0x84, 0xC5, 0xD5, 0x13, 0xD2, 0xAA, 0xF6, - 0xE5, 0xBB, 0xD2, 0x72, 0x77, 0x88, 0xE5, - 0x2F, 0x0, 0x89, 0x32, 0xD6, 0x12, 0x7C, - 0xFD, 0xE9, 0xF9, 0xE3, 0x37, 0x24, 0xC6}; - uint8_t key_18[] = {0x1, 0x3F, 0xE0, 0xB, 0x5F, 0x11, 0xBE, 0x7F, 0x86, - 0x6D, 0xC, 0xBB, 0xC5, 0x5A, 0x7A, 0x90, 0x0, 0x3E, - 0xE1, 0xA, 0x5E, 0x10, 0xBF, 0x7E, 0x87, 0x6C, 0xD, - 0xBA, 0xC4, 0x5B, 0x7B, 0x91, 0x3, 0x3D, 0xE2, 0x9, - 0x5D, 0x13, 0xBC, 0x7D, 0x84, 0x6F, 0xE, 0xB9}; - uint8_t plaintext_18[] = { - 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, - 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, - 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, - 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, - 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x0, 0x6}; - uint8_t ciphertext_18[] = { - 0xFF, 0x19, 0x10, 0xD3, 0x5A, 0xD7, 0xE5, 0x65, 0x78, 0x90, 0xC7, - 0xC5, 0x60, 0x14, 0x6F, 0xD0, 0x38, 0x70, 0x7F, 0x20, 0x4B, 0x66, - 0xED, 0xBC, 0x3D, 0x16, 0x1F, 0x8A, 0xCE, 0x24, 0x4B, 0x98, 0x59, - 0x21, 0x2, 0x3C, 0x43, 0x6E, 0x3A, 0x1C, 0x35, 0x32, 0xEC, 0xD5, - 0xD0, 0x9A, 0x5, 0x6D, 0x70, 0xBE, 0x58, 0x3F, 0xD, 0x10, 0x82, - 0x9D, 0x93, 0x87, 0xD0, 0x7D, 0x33, 0xD8, 0x72, 0xE4, 0x90}; - vec = {nonce_18, aad_18, key_18, plaintext_18, ciphertext_18, - 12, 28, 44, 49, 65}; - gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); - - // Derived from IEEE 2.6.2 61-byte crypt - uint8_t nonce_19[] = {0x7C, 0xFD, 0xE9, 0xF9, 0xE3, 0x37, - 0x24, 0xC6, 0x89, 0x32, 0xD6, 0x12}; - uint8_t aad_19[] = {0x84, 0xC5, 0xD5, 0x13, 0xD2, 0xAA, 0xF6, - 0xE5, 0xBB, 0xD2, 0x72, 0x77, 0x88, 0xE5, - 0x2F, 0x0, 0x89, 0x32, 0xD6, 0x12, 0x7C, - 0xFD, 0xE9, 0xF9, 0xE3, 0x37, 0x24, 0xC6}; - uint8_t key_19[] = {0x83, 0xC0, 0x93, 0xB5, 0x8D, 0xE7, 0xFF, 0xE1, 0xC0, - 0xDA, 0x92, 0x6A, 0xC4, 0x3F, 0xB3, 0x60, 0x9A, 0xC1, - 0xC8, 0xF, 0xEE, 0x1B, 0x62, 0x44, 0x97, 0xEF, 0x94, - 0x2E, 0x2F, 0x79, 0xA8, 0x23, 0x81, 0xC2, 0x91, 0xB7, - 0x8F, 0xE5, 0xFD, 0xE3, 0xC2, 0xD8, 0x90, 0x68}; - uint8_t plaintext_19[] = { - 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, - 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, - 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, - 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, - 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x0, 0x6}; - uint8_t ciphertext_19[] = { - 0xD, 0xB4, 0xCF, 0x95, 0x6B, 0x5F, 0x97, 0xEC, 0xA4, 0xEA, 0xB8, - 0x2A, 0x69, 0x55, 0x30, 0x7F, 0x9A, 0xE0, 0x2A, 0x32, 0xDD, 0x7D, - 0x93, 0xF8, 0x3D, 0x66, 0xAD, 0x4, 0xE1, 0xCF, 0xDC, 0x51, 0x82, - 0xAD, 0x12, 0xAB, 0xDE, 0xA5, 0xBB, 0xB6, 0x19, 0xA1, 0xBD, 0x5F, - 0xB9, 0xA5, 0x73, 0x59, 0xF, 0xBA, 0x90, 0x8E, 0x9C, 0x7A, 0x46, - 0xC1, 0xF7, 0xBA, 0x9, 0x5, 0xD1, 0xB5, 0x5F, 0xFD, 0xA4}; - vec = {nonce_19, aad_19, key_19, plaintext_19, ciphertext_19, - 12, 28, 44, 49, 65}; - gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); - - // Derived from IEEE 2.7.1 79-byte crypt - uint8_t nonce_20[] = {0x7A, 0xE8, 0xE2, 0xCA, 0x4E, 0xC5, - 0x0, 0x1, 0x2E, 0x58, 0x49, 0x5C}; - uint8_t aad_20[] = { - 0x68, 0xF2, 0xE7, 0x76, 0x96, 0xCE, 0x7A, 0xE8, 0xE2, 0xCA, 0x4E, - 0xC5, 0x88, 0xE5, 0x41, 0x0, 0x2E, 0x58, 0x49, 0x5C, 0x8, 0x0, - 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, - 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, - 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, - 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, - 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x0, 0x7}; - uint8_t key_20[] = {0x88, 0xEE, 0x8, 0x7F, 0xD9, 0x5D, 0xA9, 0xFB, 0xF6, - 0x72, 0x5A, 0xA9, 0xD7, 0x57, 0xB0, 0xCD, 0x89, 0xEF, - 0x9, 0x7E, 0xD8, 0x5C, 0xA8, 0xFA, 0xF7, 0x73, 0x5B, - 0xA8, 0xD6, 0x56, 0xB1, 0xCC, 0x8A, 0xEC, 0xA, 0x7D, - 0xDB, 0x5F, 0xAB, 0xF9, 0xF4, 0x70, 0x58, 0xAB}; - uint8_t plaintext_20[1] = {}; - uint8_t ciphertext_20[] = {0x81, 0x3F, 0xE, 0x63, 0xF, 0x96, 0xFB, 0x2D, - 0x3, 0xF, 0x58, 0xD8, 0x3F, 0x5C, 0xDF, 0xD0}; - vec = {nonce_20, aad_20, key_20, plaintext_20, ciphertext_20, 12, 87, - 44, 0, 16}; - gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); - - // Derived from IEEE 2.7.2 79-byte crypt - uint8_t nonce_21[] = {0x7A, 0xE8, 0xE2, 0xCA, 0x4E, 0xC5, - 0x0, 0x1, 0x2E, 0x58, 0x49, 0x5C}; - uint8_t aad_21[] = { - 0x68, 0xF2, 0xE7, 0x76, 0x96, 0xCE, 0x7A, 0xE8, 0xE2, 0xCA, 0x4E, - 0xC5, 0x88, 0xE5, 0x41, 0x0, 0x2E, 0x58, 0x49, 0x5C, 0x8, 0x0, - 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, - 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, - 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, - 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, - 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x0, 0x7}; - uint8_t key_21[] = {0x4C, 0x97, 0x3D, 0xBC, 0x73, 0x64, 0x62, 0x16, 0x74, - 0xF8, 0xB5, 0xB8, 0x9E, 0x5C, 0x15, 0x51, 0x1F, 0xCE, - 0xD9, 0x21, 0x64, 0x90, 0xFB, 0x1C, 0x1A, 0x2C, 0xAA, - 0xF, 0xFE, 0x4, 0x7, 0xE5, 0x4E, 0x95, 0x3F, 0xBE, - 0x71, 0x66, 0x60, 0x14, 0x76, 0xFA, 0xB7, 0xBA}; - uint8_t plaintext_21[1] = {}; - uint8_t ciphertext_21[] = {0x77, 0xE5, 0xA4, 0x4C, 0x21, 0xEB, 0x7, 0x18, - 0x8A, 0xAC, 0xBD, 0x74, 0xD1, 0x98, 0xE, 0x97}; - vec = {nonce_21, aad_21, key_21, plaintext_21, ciphertext_21, 12, 87, - 44, 0, 16}; - gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); - - // Derived from IEEE 2.8.1 61-byte crypt - uint8_t nonce_22[] = {0x7A, 0xE8, 0xE2, 0xCA, 0x4E, 0xC5, - 0x0, 0x1, 0x2E, 0x58, 0x49, 0x5C}; - uint8_t aad_22[] = {0x68, 0xF2, 0xE7, 0x76, 0x96, 0xCE, 0x7A, - 0xE8, 0xE2, 0xCA, 0x4E, 0xC5, 0x88, 0xE5, - 0x4D, 0x0, 0x2E, 0x58, 0x49, 0x5C}; - uint8_t key_22[] = {0x88, 0xEE, 0x8, 0x7F, 0xD9, 0x5D, 0xA9, 0xFB, 0xF6, - 0x72, 0x5A, 0xA9, 0xD7, 0x57, 0xB0, 0xCD, 0x89, 0xEF, - 0x9, 0x7E, 0xD8, 0x5C, 0xA8, 0xFA, 0xF7, 0x73, 0x5B, - 0xA8, 0xD6, 0x56, 0xB1, 0xCC, 0x8A, 0xEC, 0xA, 0x7D, - 0xDB, 0x5F, 0xAB, 0xF9, 0xF4, 0x70, 0x58, 0xAB}; - uint8_t plaintext_22[] = { - 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, - 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, - 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, - 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, - 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x0, 0x8}; - uint8_t ciphertext_22[] = { - 0x95, 0x8E, 0xC3, 0xF6, 0xD6, 0xA, 0xFE, 0xDA, 0x99, 0xEF, 0xD8, 0x88, - 0xF1, 0x75, 0xE5, 0xFC, 0xD4, 0xC8, 0x7B, 0x9B, 0xCC, 0x5C, 0x2F, 0x54, - 0x26, 0x25, 0x3A, 0x8B, 0x50, 0x62, 0x96, 0xC8, 0xC4, 0x33, 0x9, 0xAB, - 0x2A, 0xDB, 0x59, 0x39, 0x46, 0x25, 0x41, 0xD9, 0x5E, 0x80, 0x81, 0x1E, - 0x4, 0xE7, 0x6, 0xB1, 0x49, 0x8F, 0x2C, 0x40, 0x7C, 0x7F, 0xB2, 0x34, - 0xF8, 0xCC, 0x1, 0xA6, 0x47, 0x55, 0xE, 0xE6, 0xB5, 0x57, 0xB3, 0x5A, - 0x7E, 0x39, 0x45, 0x38, 0x18, 0x21, 0xF4}; - vec = {nonce_22, aad_22, key_22, plaintext_22, ciphertext_22, - 12, 20, 44, 63, 79}; - gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); - - // Derived from IEEE 2.8.2 61-byte crypt - uint8_t nonce_23[] = {0x7A, 0xE8, 0xE2, 0xCA, 0x4E, 0xC5, - 0x0, 0x1, 0x2E, 0x58, 0x49, 0x5C}; - uint8_t aad_23[] = {0x68, 0xF2, 0xE7, 0x76, 0x96, 0xCE, 0x7A, - 0xE8, 0xE2, 0xCA, 0x4E, 0xC5, 0x88, 0xE5, - 0x4D, 0x0, 0x2E, 0x58, 0x49, 0x5C}; - uint8_t key_23[] = {0x4C, 0x97, 0x3D, 0xBC, 0x73, 0x64, 0x62, 0x16, 0x74, - 0xF8, 0xB5, 0xB8, 0x9E, 0x5C, 0x15, 0x51, 0x1F, 0xCE, - 0xD9, 0x21, 0x64, 0x90, 0xFB, 0x1C, 0x1A, 0x2C, 0xAA, - 0xF, 0xFE, 0x4, 0x7, 0xE5, 0x4E, 0x95, 0x3F, 0xBE, - 0x71, 0x66, 0x60, 0x14, 0x76, 0xFA, 0xB7, 0xBA}; - uint8_t plaintext_23[] = { - 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, - 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, - 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, - 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, - 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x0, 0x8}; - uint8_t ciphertext_23[] = { - 0xB4, 0x4D, 0x7, 0x20, 0x11, 0xCD, 0x36, 0xD2, 0x72, 0xA9, 0xB7, 0xA9, - 0x8D, 0xB9, 0xAA, 0x90, 0xCB, 0xC5, 0xC6, 0x7B, 0x93, 0xDD, 0xCE, 0x67, - 0xC8, 0x54, 0x50, 0x32, 0x14, 0xE2, 0xE8, 0x96, 0xEC, 0x7E, 0x9D, 0xB6, - 0x49, 0xED, 0x4B, 0xCF, 0x6F, 0x85, 0xA, 0xAC, 0x2, 0x23, 0xD0, 0xCF, - 0x92, 0xC8, 0x3D, 0xB8, 0x7, 0x95, 0xC3, 0xA1, 0x7E, 0xCC, 0x12, 0x48, - 0xBB, 0x0, 0x59, 0x17, 0x12, 0xB1, 0xAE, 0x71, 0xE2, 0x68, 0x16, 0x41, - 0x96, 0x25, 0x21, 0x62, 0x81, 0xB, 0x0}; - vec = {nonce_23, aad_23, key_23, plaintext_23, ciphertext_23, - 12, 20, 44, 63, 79}; - gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); -} - -static void gsec_test_do_vector_tests_nist() { - /** - * From: - * http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/ - * gcm-revised-spec.pdf - */ - - /* Test vector 1 */ - gsec_aead_test_vector* test_vector_1; - const uint8_t test_vector_1_key[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00}; - const uint8_t test_vector_1_nonce[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - const uint8_t test_vector_1_aad[1] = {}; - const uint8_t test_vector_1_plaintext[1] = {}; - const uint8_t test_vector_1_ciphertext_and_tag[] = { - 0x58, 0xe2, 0xfc, 0xce, 0xfa, 0x7e, 0x30, 0x61, - 0x36, 0x7f, 0x1d, 0x57, 0xa4, 0xe7, 0x45, 0x5a}; - gsec_aead_malloc_test_vector( - &test_vector_1, test_vector_1_key, - sizeof(test_vector_1_key) / sizeof(uint8_t), test_vector_1_nonce, - sizeof(test_vector_1_nonce) / sizeof(uint8_t), test_vector_1_aad, 0, - test_vector_1_plaintext, 0, test_vector_1_ciphertext_and_tag, - sizeof(test_vector_1_ciphertext_and_tag) / sizeof(uint8_t)); - gsec_test_verify_crypter_on_test_vector(test_vector_1); - gsec_aead_free_test_vector(test_vector_1); - - /* Test vector 2 */ - gsec_aead_test_vector* test_vector_2; - const uint8_t test_vector_2_key[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00}; - const uint8_t test_vector_2_nonce[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - const uint8_t test_vector_2_aad[1] = {}; - const uint8_t test_vector_2_plaintext[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00}; - const uint8_t test_vector_2_ciphertext_and_tag[] = { - 0x03, 0x88, 0xda, 0xce, 0x60, 0xb6, 0xa3, 0x92, 0xf3, 0x28, 0xc2, - 0xb9, 0x71, 0xb2, 0xfe, 0x78, 0xab, 0x6e, 0x47, 0xd4, 0x2c, 0xec, - 0x13, 0xbd, 0xf5, 0x3a, 0x67, 0xb2, 0x12, 0x57, 0xbd, 0xdf}; - gsec_aead_malloc_test_vector( - &test_vector_2, test_vector_2_key, - sizeof(test_vector_2_key) / sizeof(uint8_t), test_vector_2_nonce, - sizeof(test_vector_2_nonce) / sizeof(uint8_t), test_vector_2_aad, 0, - test_vector_2_plaintext, - sizeof(test_vector_2_plaintext) / sizeof(uint8_t), - test_vector_2_ciphertext_and_tag, - sizeof(test_vector_2_ciphertext_and_tag) / sizeof(uint8_t)); - gsec_test_verify_crypter_on_test_vector(test_vector_2); - gsec_aead_free_test_vector(test_vector_2); - - /* Test vector 3 */ - gsec_aead_test_vector* test_vector_3; - const uint8_t test_vector_3_key[] = {0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, - 0x73, 0x1c, 0x6d, 0x6a, 0x8f, 0x94, - 0x67, 0x30, 0x83, 0x08}; - const uint8_t test_vector_3_nonce[] = {0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, - 0xdb, 0xad, 0xde, 0xca, 0xf8, 0x88}; - const uint8_t test_vector_3_aad[1] = {}; - const uint8_t test_vector_3_plaintext[] = { - 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, 0xa5, 0x59, 0x09, - 0xc5, 0xaf, 0xf5, 0x26, 0x9a, 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, - 0xf7, 0xda, 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, 0x1c, - 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, 0x2f, 0xcf, 0x0e, 0x24, - 0x49, 0xa6, 0xb5, 0x25, 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, - 0x57, 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55}; - const uint8_t test_vector_3_ciphertext_and_tag[] = { - 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24, 0x4b, 0x72, 0x21, 0xb7, - 0x84, 0xd0, 0xd4, 0x9c, 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0, - 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e, 0x21, 0xd5, 0x14, 0xb2, - 0x54, 0x66, 0x93, 0x1c, 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05, - 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97, 0x3d, 0x58, 0xe0, 0x91, - 0x47, 0x3f, 0x59, 0x85, 0x4d, 0x5c, 0x2a, 0xf3, 0x27, 0xcd, 0x64, 0xa6, - 0x2c, 0xf3, 0x5a, 0xbd, 0x2b, 0xa6, 0xfa, 0xb4}; - gsec_aead_malloc_test_vector( - &test_vector_3, test_vector_3_key, - sizeof(test_vector_3_key) / sizeof(uint8_t), test_vector_3_nonce, - sizeof(test_vector_3_nonce) / sizeof(uint8_t), test_vector_3_aad, 0, - test_vector_3_plaintext, - sizeof(test_vector_3_plaintext) / sizeof(uint8_t), - test_vector_3_ciphertext_and_tag, - sizeof(test_vector_3_ciphertext_and_tag) / sizeof(uint8_t)); - gsec_test_verify_crypter_on_test_vector(test_vector_3); - gsec_aead_free_test_vector(test_vector_3); - - /* Test vector 4 */ - gsec_aead_test_vector* test_vector_4; - const uint8_t test_vector_4_key[] = {0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, - 0x73, 0x1c, 0x6d, 0x6a, 0x8f, 0x94, - 0x67, 0x30, 0x83, 0x08}; - const uint8_t test_vector_4_nonce[] = {0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, - 0xdb, 0xad, 0xde, 0xca, 0xf8, 0x88}; - const uint8_t test_vector_4_aad[] = {0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, - 0xef, 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, - 0xbe, 0xef, 0xab, 0xad, 0xda, 0xd2}; - const uint8_t test_vector_4_plaintext[] = { - 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, 0xa5, 0x59, 0x09, 0xc5, - 0xaf, 0xf5, 0x26, 0x9a, 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, - 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, 0x1c, 0x3c, 0x0c, 0x95, - 0x95, 0x68, 0x09, 0x53, 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, - 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, 0xba, 0x63, 0x7b, 0x39}; - const uint8_t test_vector_4_ciphertext_and_tag[] = { - 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24, 0x4b, 0x72, 0x21, - 0xb7, 0x84, 0xd0, 0xd4, 0x9c, 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, - 0xa4, 0xe0, 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e, 0x21, - 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c, 0x7d, 0x8f, 0x6a, 0x5a, - 0xac, 0x84, 0xaa, 0x05, 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, - 0x97, 0x3d, 0x58, 0xe0, 0x91, 0x5b, 0xc9, 0x4f, 0xbc, 0x32, 0x21, - 0xa5, 0xdb, 0x94, 0xfa, 0xe9, 0x5a, 0xe7, 0x12, 0x1a, 0x47}; - gsec_aead_malloc_test_vector( - &test_vector_4, test_vector_4_key, - sizeof(test_vector_4_key) / sizeof(uint8_t), test_vector_4_nonce, - sizeof(test_vector_4_nonce) / sizeof(uint8_t), test_vector_4_aad, - sizeof(test_vector_4_aad) / sizeof(uint8_t), test_vector_4_plaintext, - sizeof(test_vector_4_plaintext) / sizeof(uint8_t), - test_vector_4_ciphertext_and_tag, - sizeof(test_vector_4_ciphertext_and_tag) / sizeof(uint8_t)); - gsec_test_verify_crypter_on_test_vector(test_vector_4); - gsec_aead_free_test_vector(test_vector_4); -} - -static void gsec_test_do_vector_tests_ieee() { - /** - * From: - * http://www.ieee802.org/1/files/public/docs2011/ - * bn-randall-test-vectors-0511-v1.pdf - */ - - /* 2.1.1 54-byte auth */ - gsec_aead_test_vector* test_vector_5; - const uint8_t test_vector_5_key[] = {0xad, 0x7a, 0x2b, 0xd0, 0x3e, 0xac, - 0x83, 0x5a, 0x6f, 0x62, 0x0f, 0xdc, - 0xb5, 0x06, 0xb3, 0x45}; - const uint8_t test_vector_5_nonce[] = {0x12, 0x15, 0x35, 0x24, 0xc0, 0x89, - 0x5e, 0x81, 0xb2, 0xc2, 0x84, 0x65}; - const uint8_t test_vector_5_aad[] = { - 0xd6, 0x09, 0xb1, 0xf0, 0x56, 0x63, 0x7a, 0x0d, 0x46, 0xdf, 0x99, 0x8d, - 0x88, 0xe5, 0x22, 0x2a, 0xb2, 0xc2, 0x84, 0x65, 0x12, 0x15, 0x35, 0x24, - 0xc0, 0x89, 0x5e, 0x81, 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, - 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, - 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, - 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x00, 0x01}; - const uint8_t test_vector_5_plaintext[1] = {}; - const uint8_t test_vector_5_ciphertext_and_tag[] = { - 0xf0, 0x94, 0x78, 0xa9, 0xb0, 0x90, 0x07, 0xd0, - 0x6f, 0x46, 0xe9, 0xb6, 0xa1, 0xda, 0x25, 0xdd}; - gsec_aead_malloc_test_vector( - &test_vector_5, test_vector_5_key, - sizeof(test_vector_5_key) / sizeof(uint8_t), test_vector_5_nonce, - sizeof(test_vector_5_nonce) / sizeof(uint8_t), test_vector_5_aad, - sizeof(test_vector_5_aad) / sizeof(uint8_t), test_vector_5_plaintext, 0, - test_vector_5_ciphertext_and_tag, - sizeof(test_vector_5_ciphertext_and_tag) / sizeof(uint8_t)); - gsec_test_verify_crypter_on_test_vector(test_vector_5); - gsec_aead_free_test_vector(test_vector_5); - - /* 2.1.2 54-byte auth */ - gsec_aead_test_vector* test_vector_6; - const uint8_t test_vector_6_key[] = { - 0xe3, 0xc0, 0x8a, 0x8f, 0x06, 0xc6, 0xe3, 0xad, 0x95, 0xa7, 0x05, - 0x57, 0xb2, 0x3f, 0x75, 0x48, 0x3c, 0xe3, 0x30, 0x21, 0xa9, 0xc7, - 0x2b, 0x70, 0x25, 0x66, 0x62, 0x04, 0xc6, 0x9c, 0x0b, 0x72}; - - const uint8_t test_vector_6_nonce[] = {0x12, 0x15, 0x35, 0x24, 0xc0, 0x89, - 0x5e, 0x81, 0xb2, 0xc2, 0x84, 0x65}; - const uint8_t test_vector_6_aad[] = { - 0xd6, 0x09, 0xb1, 0xf0, 0x56, 0x63, 0x7a, 0x0d, 0x46, 0xdf, 0x99, 0x8d, - 0x88, 0xe5, 0x22, 0x2a, 0xb2, 0xc2, 0x84, 0x65, 0x12, 0x15, 0x35, 0x24, - 0xc0, 0x89, 0x5e, 0x81, 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, - 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, - 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, - 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x00, 0x01}; - const uint8_t test_vector_6_plaintext[1] = {}; - const uint8_t test_vector_6_ciphertext_and_tag[] = { - 0x2f, 0x0b, 0xc5, 0xaf, 0x40, 0x9e, 0x06, 0xd6, - 0x09, 0xea, 0x8b, 0x7d, 0x0f, 0xa5, 0xea, 0x50}; - gsec_aead_malloc_test_vector( - &test_vector_6, test_vector_6_key, - sizeof(test_vector_6_key) / sizeof(uint8_t), test_vector_6_nonce, - sizeof(test_vector_6_nonce) / sizeof(uint8_t), test_vector_6_aad, - sizeof(test_vector_6_aad) / sizeof(uint8_t), test_vector_6_plaintext, 0, - test_vector_6_ciphertext_and_tag, - sizeof(test_vector_6_ciphertext_and_tag) / sizeof(uint8_t)); - gsec_test_verify_crypter_on_test_vector(test_vector_6); - gsec_aead_free_test_vector(test_vector_6); - - /* 2.2.1 60-byte crypt */ - gsec_aead_test_vector* test_vector_7; - const uint8_t test_vector_7_key[] = {0xad, 0x7a, 0x2b, 0xd0, 0x3e, 0xac, - 0x83, 0x5a, 0x6f, 0x62, 0x0f, 0xdc, - 0xb5, 0x06, 0xb3, 0x45}; - - const uint8_t test_vector_7_nonce[] = {0x12, 0x15, 0x35, 0x24, 0xc0, 0x89, - 0x5e, 0x81, 0xb2, 0xc2, 0x84, 0x65}; - const uint8_t test_vector_7_aad[] = { - 0xd6, 0x09, 0xb1, 0xf0, 0x56, 0x63, 0x7a, 0x0d, 0x46, 0xdf, - 0x99, 0x8d, 0x88, 0xe5, 0x2e, 0x00, 0xb2, 0xc2, 0x84, 0x65, - 0x12, 0x15, 0x35, 0x24, 0xc0, 0x89, 0x5e, 0x81}; - const uint8_t test_vector_7_plaintext[] = { - 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, - 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, - 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, - 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x00, 0x02}; - const uint8_t test_vector_7_ciphertext_and_tag[] = { - 0x70, 0x1a, 0xfa, 0x1c, 0xc0, 0x39, 0xc0, 0xd7, 0x65, 0x12, 0x8a, - 0x66, 0x5d, 0xab, 0x69, 0x24, 0x38, 0x99, 0xbf, 0x73, 0x18, 0xcc, - 0xdc, 0x81, 0xc9, 0x93, 0x1d, 0xa1, 0x7f, 0xbe, 0x8e, 0xdd, 0x7d, - 0x17, 0xcb, 0x8b, 0x4c, 0x26, 0xfc, 0x81, 0xe3, 0x28, 0x4f, 0x2b, - 0x7f, 0xba, 0x71, 0x3d, 0x4f, 0x8d, 0x55, 0xe7, 0xd3, 0xf0, 0x6f, - 0xd5, 0xa1, 0x3c, 0x0c, 0x29, 0xb9, 0xd5, 0xb8, 0x80}; - gsec_aead_malloc_test_vector( - &test_vector_7, test_vector_7_key, - sizeof(test_vector_7_key) / sizeof(uint8_t), test_vector_7_nonce, - sizeof(test_vector_7_nonce) / sizeof(uint8_t), test_vector_7_aad, - sizeof(test_vector_7_aad) / sizeof(uint8_t), test_vector_7_plaintext, - sizeof(test_vector_7_plaintext) / sizeof(uint8_t), - test_vector_7_ciphertext_and_tag, - sizeof(test_vector_7_ciphertext_and_tag) / sizeof(uint8_t)); - gsec_test_verify_crypter_on_test_vector(test_vector_7); - gsec_aead_free_test_vector(test_vector_7); - - /* 2.2.2 60-byte crypt */ - gsec_aead_test_vector* test_vector_8; - const uint8_t test_vector_8_key[] = { - 0xe3, 0xc0, 0x8a, 0x8f, 0x06, 0xc6, 0xe3, 0xad, 0x95, 0xa7, 0x05, - 0x57, 0xb2, 0x3f, 0x75, 0x48, 0x3c, 0xe3, 0x30, 0x21, 0xa9, 0xc7, - 0x2b, 0x70, 0x25, 0x66, 0x62, 0x04, 0xc6, 0x9c, 0x0b, 0x72}; - const uint8_t test_vector_8_nonce[] = {0x12, 0x15, 0x35, 0x24, 0xc0, 0x89, - 0x5e, 0x81, 0xb2, 0xc2, 0x84, 0x65}; - const uint8_t test_vector_8_aad[] = { - 0xd6, 0x09, 0xb1, 0xf0, 0x56, 0x63, 0x7a, 0x0d, 0x46, 0xdf, - 0x99, 0x8d, 0x88, 0xe5, 0x2e, 0x00, 0xb2, 0xc2, 0x84, 0x65, - 0x12, 0x15, 0x35, 0x24, 0xc0, 0x89, 0x5e, 0x81}; - const uint8_t test_vector_8_plaintext[] = { - 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, - 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, - 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, - 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x00, 0x02}; - const uint8_t test_vector_8_ciphertext_and_tag[] = { - 0xe2, 0x00, 0x6e, 0xb4, 0x2f, 0x52, 0x77, 0x02, 0x2d, 0x9b, 0x19, - 0x92, 0x5b, 0xc4, 0x19, 0xd7, 0xa5, 0x92, 0x66, 0x6c, 0x92, 0x5f, - 0xe2, 0xef, 0x71, 0x8e, 0xb4, 0xe3, 0x08, 0xef, 0xea, 0xa7, 0xc5, - 0x27, 0x3b, 0x39, 0x41, 0x18, 0x86, 0x0a, 0x5b, 0xe2, 0xa9, 0x7f, - 0x56, 0xab, 0x78, 0x36, 0x5c, 0xa5, 0x97, 0xcd, 0xbb, 0x3e, 0xdb, - 0x8d, 0x1a, 0x11, 0x51, 0xea, 0x0a, 0xf7, 0xb4, 0x36}; - gsec_aead_malloc_test_vector( - &test_vector_8, test_vector_8_key, - sizeof(test_vector_8_key) / sizeof(uint8_t), test_vector_8_nonce, - sizeof(test_vector_8_nonce) / sizeof(uint8_t), test_vector_8_aad, - sizeof(test_vector_8_aad) / sizeof(uint8_t), test_vector_8_plaintext, - sizeof(test_vector_8_plaintext) / sizeof(uint8_t), - test_vector_8_ciphertext_and_tag, - sizeof(test_vector_8_ciphertext_and_tag) / sizeof(uint8_t)); - gsec_test_verify_crypter_on_test_vector(test_vector_8); - gsec_aead_free_test_vector(test_vector_8); - - /* 2.3.1 60-byte auth */ - gsec_aead_test_vector* test_vector_9; - const uint8_t test_vector_9_key[] = {0x07, 0x1b, 0x11, 0x3b, 0x0c, 0xa7, - 0x43, 0xfe, 0xcc, 0xcf, 0x3d, 0x05, - 0x1f, 0x73, 0x73, 0x82}; - const uint8_t test_vector_9_nonce[] = {0xf0, 0x76, 0x1e, 0x8d, 0xcd, 0x3d, - 0x00, 0x01, 0x76, 0xd4, 0x57, 0xed}; - const uint8_t test_vector_9_aad[] = { - 0xe2, 0x01, 0x06, 0xd7, 0xcd, 0x0d, 0xf0, 0x76, 0x1e, 0x8d, 0xcd, 0x3d, - 0x88, 0xe5, 0x40, 0x00, 0x76, 0xd4, 0x57, 0xed, 0x08, 0x00, 0x0f, 0x10, - 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, - 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, - 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, - 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x00, 0x03}; - const uint8_t test_vector_9_plaintext[1] = {}; - const uint8_t test_vector_9_ciphertext_and_tag[] = { - 0x0c, 0x01, 0x7b, 0xc7, 0x3b, 0x22, 0x7d, 0xfc, - 0xc9, 0xba, 0xfa, 0x1c, 0x41, 0xac, 0xc3, 0x53}; - gsec_aead_malloc_test_vector( - &test_vector_9, test_vector_9_key, - sizeof(test_vector_9_key) / sizeof(uint8_t), test_vector_9_nonce, - sizeof(test_vector_9_nonce) / sizeof(uint8_t), test_vector_9_aad, - sizeof(test_vector_9_aad) / sizeof(uint8_t), test_vector_9_plaintext, 0, - test_vector_9_ciphertext_and_tag, - sizeof(test_vector_9_ciphertext_and_tag) / sizeof(uint8_t)); - gsec_test_verify_crypter_on_test_vector(test_vector_9); - gsec_aead_free_test_vector(test_vector_9); - - /* 2.3.2 60-byte auth */ - gsec_aead_test_vector* test_vector_10; - const uint8_t test_vector_10_key[] = { - 0x69, 0x1d, 0x3e, 0xe9, 0x09, 0xd7, 0xf5, 0x41, 0x67, 0xfd, 0x1c, - 0xa0, 0xb5, 0xd7, 0x69, 0x08, 0x1f, 0x2b, 0xde, 0x1a, 0xee, 0x65, - 0x5f, 0xdb, 0xab, 0x80, 0xbd, 0x52, 0x95, 0xae, 0x6b, 0xe7}; - const uint8_t test_vector_10_nonce[] = {0xf0, 0x76, 0x1e, 0x8d, 0xcd, 0x3d, - 0x00, 0x01, 0x76, 0xd4, 0x57, 0xed}; - const uint8_t test_vector_10_aad[] = { - 0xe2, 0x01, 0x06, 0xd7, 0xcd, 0x0d, 0xf0, 0x76, 0x1e, 0x8d, 0xcd, 0x3d, - 0x88, 0xe5, 0x40, 0x00, 0x76, 0xd4, 0x57, 0xed, 0x08, 0x00, 0x0f, 0x10, - 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, - 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, - 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, - 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x00, 0x03}; - const uint8_t test_vector_10_plaintext[1] = {}; - const uint8_t test_vector_10_ciphertext_and_tag[] = { - 0x35, 0x21, 0x7c, 0x77, 0x4b, 0xbc, 0x31, 0xb6, - 0x31, 0x66, 0xbc, 0xf9, 0xd4, 0xab, 0xed, 0x07}; - gsec_aead_malloc_test_vector( - &test_vector_10, test_vector_10_key, - sizeof(test_vector_10_key) / sizeof(uint8_t), test_vector_10_nonce, - sizeof(test_vector_10_nonce) / sizeof(uint8_t), test_vector_10_aad, - sizeof(test_vector_10_aad) / sizeof(uint8_t), test_vector_10_plaintext, 0, - test_vector_10_ciphertext_and_tag, - sizeof(test_vector_10_ciphertext_and_tag) / sizeof(uint8_t)); - gsec_test_verify_crypter_on_test_vector(test_vector_10); - gsec_aead_free_test_vector(test_vector_10); - - /* 2.4.1 54-byte crypt */ - gsec_aead_test_vector* test_vector_11; - const uint8_t test_vector_11_key[] = {0x07, 0x1b, 0x11, 0x3b, 0x0c, 0xa7, - 0x43, 0xfe, 0xcc, 0xcf, 0x3d, 0x05, - 0x1f, 0x73, 0x73, 0x82}; - const uint8_t test_vector_11_nonce[] = {0xf0, 0x76, 0x1e, 0x8d, 0xcd, 0x3d, - 0x00, 0x01, 0x76, 0xd4, 0x57, 0xed}; - const uint8_t test_vector_11_aad[] = { - 0xe2, 0x01, 0x06, 0xd7, 0xcd, 0x0d, 0xf0, 0x76, 0x1e, 0x8d, - 0xcd, 0x3d, 0x88, 0xe5, 0x4c, 0x2a, 0x76, 0xd4, 0x57, 0xed}; - const uint8_t test_vector_11_plaintext[] = { - 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, - 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, - 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x00, 0x04}; - const uint8_t test_vector_11_ciphertext_and_tag[] = { - 0x13, 0xb4, 0xc7, 0x2b, 0x38, 0x9d, 0xc5, 0x01, 0x8e, 0x72, 0xa1, 0x71, - 0xdd, 0x85, 0xa5, 0xd3, 0x75, 0x22, 0x74, 0xd3, 0xa0, 0x19, 0xfb, 0xca, - 0xed, 0x09, 0xa4, 0x25, 0xcd, 0x9b, 0x2e, 0x1c, 0x9b, 0x72, 0xee, 0xe7, - 0xc9, 0xde, 0x7d, 0x52, 0xb3, 0xf3, 0xd6, 0xa5, 0x28, 0x4f, 0x4a, 0x6d, - 0x3f, 0xe2, 0x2a, 0x5d, 0x6c, 0x2b, 0x96, 0x04, 0x94, 0xc3}; - gsec_aead_malloc_test_vector( - &test_vector_11, test_vector_11_key, - sizeof(test_vector_11_key) / sizeof(uint8_t), test_vector_11_nonce, - sizeof(test_vector_11_nonce) / sizeof(uint8_t), test_vector_11_aad, - sizeof(test_vector_11_aad) / sizeof(uint8_t), test_vector_11_plaintext, - sizeof(test_vector_11_plaintext) / sizeof(uint8_t), - test_vector_11_ciphertext_and_tag, - sizeof(test_vector_11_ciphertext_and_tag) / sizeof(uint8_t)); - gsec_test_verify_crypter_on_test_vector(test_vector_11); - gsec_aead_free_test_vector(test_vector_11); - - /* 2.4.2 54-byte crypt */ - gsec_aead_test_vector* test_vector_12; - const uint8_t test_vector_12_key[] = { - 0x69, 0x1d, 0x3e, 0xe9, 0x09, 0xd7, 0xf5, 0x41, 0x67, 0xfd, 0x1c, - 0xa0, 0xb5, 0xd7, 0x69, 0x08, 0x1f, 0x2b, 0xde, 0x1a, 0xee, 0x65, - 0x5f, 0xdb, 0xab, 0x80, 0xbd, 0x52, 0x95, 0xae, 0x6b, 0xe7}; - const uint8_t test_vector_12_nonce[] = {0xf0, 0x76, 0x1e, 0x8d, 0xcd, 0x3d, - 0x00, 0x01, 0x76, 0xd4, 0x57, 0xed}; - const uint8_t test_vector_12_aad[] = { - 0xe2, 0x01, 0x06, 0xd7, 0xcd, 0x0d, 0xf0, 0x76, 0x1e, 0x8d, - 0xcd, 0x3d, 0x88, 0xe5, 0x4c, 0x2a, 0x76, 0xd4, 0x57, 0xed}; - const uint8_t test_vector_12_plaintext[] = { - 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, - 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, - 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x00, 0x04}; - const uint8_t test_vector_12_ciphertext_and_tag[] = { - 0xc1, 0x62, 0x3f, 0x55, 0x73, 0x0c, 0x93, 0x53, 0x30, 0x97, 0xad, 0xda, - 0xd2, 0x56, 0x64, 0x96, 0x61, 0x25, 0x35, 0x2b, 0x43, 0xad, 0xac, 0xbd, - 0x61, 0xc5, 0xef, 0x3a, 0xc9, 0x0b, 0x5b, 0xee, 0x92, 0x9c, 0xe4, 0x63, - 0x0e, 0xa7, 0x9f, 0x6c, 0xe5, 0x19, 0x12, 0xaf, 0x39, 0xc2, 0xd1, 0xfd, - 0xc2, 0x05, 0x1f, 0x8b, 0x7b, 0x3c, 0x9d, 0x39, 0x7e, 0xf2}; - gsec_aead_malloc_test_vector( - &test_vector_12, test_vector_12_key, - sizeof(test_vector_12_key) / sizeof(uint8_t), test_vector_12_nonce, - sizeof(test_vector_12_nonce) / sizeof(uint8_t), test_vector_12_aad, - sizeof(test_vector_12_aad) / sizeof(uint8_t), test_vector_12_plaintext, - sizeof(test_vector_12_plaintext) / sizeof(uint8_t), - test_vector_12_ciphertext_and_tag, - sizeof(test_vector_12_ciphertext_and_tag) / sizeof(uint8_t)); - gsec_test_verify_crypter_on_test_vector(test_vector_12); - gsec_aead_free_test_vector(test_vector_12); - - /* 2.5.1 65-byte auth */ - gsec_aead_test_vector* test_vector_13; - const uint8_t test_vector_13_key[] = {0x01, 0x3f, 0xe0, 0x0b, 0x5f, 0x11, - 0xbe, 0x7f, 0x86, 0x6d, 0x0c, 0xbb, - 0xc5, 0x5a, 0x7a, 0x90}; - const uint8_t test_vector_13_nonce[] = {0x7c, 0xfd, 0xe9, 0xf9, 0xe3, 0x37, - 0x24, 0xc6, 0x89, 0x32, 0xd6, 0x12}; - const uint8_t test_vector_13_aad[] = { - 0x84, 0xc5, 0xd5, 0x13, 0xd2, 0xaa, 0xf6, 0xe5, 0xbb, 0xd2, 0x72, 0x77, - 0x88, 0xe5, 0x23, 0x00, 0x89, 0x32, 0xd6, 0x12, 0x7c, 0xfd, 0xe9, 0xf9, - 0xe3, 0x37, 0x24, 0xc6, 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, - 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, - 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, - 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, - 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x00, 0x05}; - const uint8_t test_vector_13_plaintext[1] = {}; - const uint8_t test_vector_13_ciphertext_and_tag[] = { - 0x21, 0x78, 0x67, 0xe5, 0x0c, 0x2d, 0xad, 0x74, - 0xc2, 0x8c, 0x3b, 0x50, 0xab, 0xdf, 0x69, 0x5a}; - gsec_aead_malloc_test_vector( - &test_vector_13, test_vector_13_key, - sizeof(test_vector_13_key) / sizeof(uint8_t), test_vector_13_nonce, - sizeof(test_vector_13_nonce) / sizeof(uint8_t), test_vector_13_aad, - sizeof(test_vector_13_aad) / sizeof(uint8_t), test_vector_13_plaintext, 0, - test_vector_13_ciphertext_and_tag, - sizeof(test_vector_13_ciphertext_and_tag) / sizeof(uint8_t)); - gsec_test_verify_crypter_on_test_vector(test_vector_13); - gsec_aead_free_test_vector(test_vector_13); - - /* 2.5.2 65-byte auth */ - gsec_aead_test_vector* test_vector_14; - const uint8_t test_vector_14_key[] = { - 0x83, 0xc0, 0x93, 0xb5, 0x8d, 0xe7, 0xff, 0xe1, 0xc0, 0xda, 0x92, - 0x6a, 0xc4, 0x3f, 0xb3, 0x60, 0x9a, 0xc1, 0xc8, 0x0f, 0xee, 0x1b, - 0x62, 0x44, 0x97, 0xef, 0x94, 0x2e, 0x2f, 0x79, 0xa8, 0x23}; - const uint8_t test_vector_14_nonce[] = {0x7c, 0xfd, 0xe9, 0xf9, 0xe3, 0x37, - 0x24, 0xc6, 0x89, 0x32, 0xd6, 0x12}; - const uint8_t test_vector_14_aad[] = { - 0x84, 0xc5, 0xd5, 0x13, 0xd2, 0xaa, 0xf6, 0xe5, 0xbb, 0xd2, 0x72, 0x77, - 0x88, 0xe5, 0x23, 0x00, 0x89, 0x32, 0xd6, 0x12, 0x7c, 0xfd, 0xe9, 0xf9, - 0xe3, 0x37, 0x24, 0xc6, 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, - 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, - 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, - 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, - 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x00, 0x05}; - const uint8_t test_vector_14_plaintext[1] = {}; - const uint8_t test_vector_14_ciphertext_and_tag[] = { - 0x6e, 0xe1, 0x60, 0xe8, 0xfa, 0xec, 0xa4, 0xb3, - 0x6c, 0x86, 0xb2, 0x34, 0x92, 0x0c, 0xa9, 0x75}; - gsec_aead_malloc_test_vector( - &test_vector_14, test_vector_14_key, - sizeof(test_vector_14_key) / sizeof(uint8_t), test_vector_14_nonce, - sizeof(test_vector_14_nonce) / sizeof(uint8_t), test_vector_14_aad, - sizeof(test_vector_14_aad) / sizeof(uint8_t), test_vector_14_plaintext, 0, - test_vector_14_ciphertext_and_tag, - sizeof(test_vector_14_ciphertext_and_tag) / sizeof(uint8_t)); - gsec_test_verify_crypter_on_test_vector(test_vector_14); - gsec_aead_free_test_vector(test_vector_14); - - /* 2.6.1 61-byte crypt */ - gsec_aead_test_vector* test_vector_15; - const uint8_t test_vector_15_key[] = {0x01, 0x3f, 0xe0, 0x0b, 0x5f, 0x11, - 0xbe, 0x7f, 0x86, 0x6d, 0x0c, 0xbb, - 0xc5, 0x5a, 0x7a, 0x90}; - const uint8_t test_vector_15_nonce[] = {0x7c, 0xfd, 0xe9, 0xf9, 0xe3, 0x37, - 0x24, 0xc6, 0x89, 0x32, 0xd6, 0x12}; - const uint8_t test_vector_15_aad[] = { - 0x84, 0xc5, 0xd5, 0x13, 0xd2, 0xaa, 0xf6, 0xe5, 0xbb, 0xd2, - 0x72, 0x77, 0x88, 0xe5, 0x2f, 0x00, 0x89, 0x32, 0xd6, 0x12, - 0x7c, 0xfd, 0xe9, 0xf9, 0xe3, 0x37, 0x24, 0xc6}; - const uint8_t test_vector_15_plaintext[] = { - 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, - 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, - 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, - 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, - 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x00, 0x06}; - const uint8_t test_vector_15_ciphertext_and_tag[] = { - 0x3a, 0x4d, 0xe6, 0xfa, 0x32, 0x19, 0x10, 0x14, 0xdb, 0xb3, 0x03, - 0xd9, 0x2e, 0xe3, 0xa9, 0xe8, 0xa1, 0xb5, 0x99, 0xc1, 0x4d, 0x22, - 0xfb, 0x08, 0x00, 0x96, 0xe1, 0x38, 0x11, 0x81, 0x6a, 0x3c, 0x9c, - 0x9b, 0xcf, 0x7c, 0x1b, 0x9b, 0x96, 0xda, 0x80, 0x92, 0x04, 0xe2, - 0x9d, 0x0e, 0x2a, 0x76, 0x42, 0xbf, 0xd3, 0x10, 0xa4, 0x83, 0x7c, - 0x81, 0x6c, 0xcf, 0xa5, 0xac, 0x23, 0xab, 0x00, 0x39, 0x88}; - gsec_aead_malloc_test_vector( - &test_vector_15, test_vector_15_key, - sizeof(test_vector_15_key) / sizeof(uint8_t), test_vector_15_nonce, - sizeof(test_vector_15_nonce) / sizeof(uint8_t), test_vector_15_aad, - sizeof(test_vector_15_aad) / sizeof(uint8_t), test_vector_15_plaintext, - sizeof(test_vector_15_plaintext) / sizeof(uint8_t), - test_vector_15_ciphertext_and_tag, - sizeof(test_vector_15_ciphertext_and_tag) / sizeof(uint8_t)); - gsec_test_verify_crypter_on_test_vector(test_vector_15); - gsec_aead_free_test_vector(test_vector_15); - - /* 2.6.2 61-byte crypt */ - gsec_aead_test_vector* test_vector_16; - const uint8_t test_vector_16_key[] = { - 0x83, 0xc0, 0x93, 0xb5, 0x8d, 0xe7, 0xff, 0xe1, 0xc0, 0xda, 0x92, - 0x6a, 0xc4, 0x3f, 0xb3, 0x60, 0x9a, 0xc1, 0xc8, 0x0f, 0xee, 0x1b, - 0x62, 0x44, 0x97, 0xef, 0x94, 0x2e, 0x2f, 0x79, 0xa8, 0x23}; - const uint8_t test_vector_16_nonce[] = {0x7c, 0xfd, 0xe9, 0xf9, 0xe3, 0x37, - 0x24, 0xc6, 0x89, 0x32, 0xd6, 0x12}; - const uint8_t test_vector_16_aad[] = { - 0x84, 0xc5, 0xd5, 0x13, 0xd2, 0xaa, 0xf6, 0xe5, 0xbb, 0xd2, - 0x72, 0x77, 0x88, 0xe5, 0x2f, 0x00, 0x89, 0x32, 0xd6, 0x12, - 0x7c, 0xfd, 0xe9, 0xf9, 0xe3, 0x37, 0x24, 0xc6}; - const uint8_t test_vector_16_plaintext[] = { - 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, - 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, - 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, - 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, - 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x00, 0x06}; - const uint8_t test_vector_16_ciphertext_and_tag[] = { - 0x11, 0x02, 0x22, 0xff, 0x80, 0x50, 0xcb, 0xec, 0xe6, 0x6a, 0x81, - 0x3a, 0xd0, 0x9a, 0x73, 0xed, 0x7a, 0x9a, 0x08, 0x9c, 0x10, 0x6b, - 0x95, 0x93, 0x89, 0x16, 0x8e, 0xd6, 0xe8, 0x69, 0x8e, 0xa9, 0x02, - 0xeb, 0x12, 0x77, 0xdb, 0xec, 0x2e, 0x68, 0xe4, 0x73, 0x15, 0x5a, - 0x15, 0xa7, 0xda, 0xee, 0xd4, 0xa1, 0x0f, 0x4e, 0x05, 0x13, 0x9c, - 0x23, 0xdf, 0x00, 0xb3, 0xaa, 0xdc, 0x71, 0xf0, 0x59, 0x6a}; - gsec_aead_malloc_test_vector( - &test_vector_16, test_vector_16_key, - sizeof(test_vector_16_key) / sizeof(uint8_t), test_vector_16_nonce, - sizeof(test_vector_16_nonce) / sizeof(uint8_t), test_vector_16_aad, - sizeof(test_vector_16_aad) / sizeof(uint8_t), test_vector_16_plaintext, - sizeof(test_vector_16_plaintext) / sizeof(uint8_t), - test_vector_16_ciphertext_and_tag, - sizeof(test_vector_16_ciphertext_and_tag) / sizeof(uint8_t)); - gsec_test_verify_crypter_on_test_vector(test_vector_16); - gsec_aead_free_test_vector(test_vector_16); - - /* 2.7.1 79-byte crypt */ - gsec_aead_test_vector* test_vector_17; - const uint8_t test_vector_17_key[] = {0x88, 0xee, 0x08, 0x7f, 0xd9, 0x5d, - 0xa9, 0xfb, 0xf6, 0x72, 0x5a, 0xa9, - 0xd7, 0x57, 0xb0, 0xcd}; - const uint8_t test_vector_17_nonce[] = {0x7a, 0xe8, 0xe2, 0xca, 0x4e, 0xc5, - 0x00, 0x01, 0x2e, 0x58, 0x49, 0x5c}; - const uint8_t test_vector_17_aad[] = { - 0x68, 0xf2, 0xe7, 0x76, 0x96, 0xce, 0x7a, 0xe8, 0xe2, 0xca, 0x4e, - 0xc5, 0x88, 0xe5, 0x41, 0x00, 0x2e, 0x58, 0x49, 0x5c, 0x08, 0x00, - 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, - 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, - 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, - 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, - 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x00, 0x07}; - const uint8_t test_vector_17_plaintext[1] = {}; - const uint8_t test_vector_17_ciphertext_and_tag[] = { - 0x07, 0x92, 0x2b, 0x8e, 0xbc, 0xf1, 0x0b, 0xb2, - 0x29, 0x75, 0x88, 0xca, 0x4c, 0x61, 0x45, 0x23}; - gsec_aead_malloc_test_vector( - &test_vector_17, test_vector_17_key, - sizeof(test_vector_17_key) / sizeof(uint8_t), test_vector_17_nonce, - sizeof(test_vector_17_nonce) / sizeof(uint8_t), test_vector_17_aad, - sizeof(test_vector_17_aad) / sizeof(uint8_t), test_vector_17_plaintext, 0, - test_vector_17_ciphertext_and_tag, - sizeof(test_vector_17_ciphertext_and_tag) / sizeof(uint8_t)); - gsec_test_verify_crypter_on_test_vector(test_vector_17); - gsec_aead_free_test_vector(test_vector_17); - - /* 2.7.2 79-byte crypt */ - gsec_aead_test_vector* test_vector_18; - const uint8_t test_vector_18_key[] = { - 0x4c, 0x97, 0x3d, 0xbc, 0x73, 0x64, 0x62, 0x16, 0x74, 0xf8, 0xb5, - 0xb8, 0x9e, 0x5c, 0x15, 0x51, 0x1f, 0xce, 0xd9, 0x21, 0x64, 0x90, - 0xfb, 0x1c, 0x1a, 0x2c, 0xaa, 0x0f, 0xfe, 0x04, 0x07, 0xe5}; - const uint8_t test_vector_18_nonce[] = {0x7a, 0xe8, 0xe2, 0xca, 0x4e, 0xc5, - 0x00, 0x01, 0x2e, 0x58, 0x49, 0x5c}; - const uint8_t test_vector_18_aad[] = { - 0x68, 0xf2, 0xe7, 0x76, 0x96, 0xce, 0x7a, 0xe8, 0xe2, 0xca, 0x4e, - 0xc5, 0x88, 0xe5, 0x41, 0x00, 0x2e, 0x58, 0x49, 0x5c, 0x08, 0x00, - 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, - 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, - 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, - 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, - 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x00, 0x07}; - const uint8_t test_vector_18_plaintext[1] = {}; - const uint8_t test_vector_18_ciphertext_and_tag[] = { - 0x00, 0xbd, 0xa1, 0xb7, 0xe8, 0x76, 0x08, 0xbc, - 0xbf, 0x47, 0x0f, 0x12, 0x15, 0x7f, 0x4c, 0x07}; - gsec_aead_malloc_test_vector( - &test_vector_18, test_vector_18_key, - sizeof(test_vector_18_key) / sizeof(uint8_t), test_vector_18_nonce, - sizeof(test_vector_18_nonce) / sizeof(uint8_t), test_vector_18_aad, - sizeof(test_vector_18_aad) / sizeof(uint8_t), test_vector_18_plaintext, 0, - test_vector_18_ciphertext_and_tag, - sizeof(test_vector_18_ciphertext_and_tag) / sizeof(uint8_t)); - gsec_test_verify_crypter_on_test_vector(test_vector_18); - gsec_aead_free_test_vector(test_vector_18); - - /* 2.8.1 61-byte crypt */ - gsec_aead_test_vector* test_vector_19; - const uint8_t test_vector_19_key[] = {0x88, 0xee, 0x08, 0x7f, 0xd9, 0x5d, - 0xa9, 0xfb, 0xf6, 0x72, 0x5a, 0xa9, - 0xd7, 0x57, 0xb0, 0xcd}; - const uint8_t test_vector_19_nonce[] = {0x7a, 0xe8, 0xe2, 0xca, 0x4e, 0xc5, - 0x00, 0x01, 0x2e, 0x58, 0x49, 0x5c}; - const uint8_t test_vector_19_aad[] = { - 0x68, 0xf2, 0xe7, 0x76, 0x96, 0xce, 0x7a, 0xe8, 0xe2, 0xca, - 0x4e, 0xc5, 0x88, 0xe5, 0x4d, 0x00, 0x2e, 0x58, 0x49, 0x5c}; - const uint8_t test_vector_19_plaintext[] = { - 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, - 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, - 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, - 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, - 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x00, 0x08}; - const uint8_t test_vector_19_ciphertext_and_tag[] = { - 0xc3, 0x1f, 0x53, 0xd9, 0x9e, 0x56, 0x87, 0xf7, 0x36, 0x51, 0x19, 0xb8, - 0x32, 0xd2, 0xaa, 0xe7, 0x07, 0x41, 0xd5, 0x93, 0xf1, 0xf9, 0xe2, 0xab, - 0x34, 0x55, 0x77, 0x9b, 0x07, 0x8e, 0xb8, 0xfe, 0xac, 0xdf, 0xec, 0x1f, - 0x8e, 0x3e, 0x52, 0x77, 0xf8, 0x18, 0x0b, 0x43, 0x36, 0x1f, 0x65, 0x12, - 0xad, 0xb1, 0x6d, 0x2e, 0x38, 0x54, 0x8a, 0x2c, 0x71, 0x9d, 0xba, 0x72, - 0x28, 0xd8, 0x40, 0x88, 0xf8, 0x75, 0x7a, 0xdb, 0x8a, 0xa7, 0x88, 0xd8, - 0xf6, 0x5a, 0xd6, 0x68, 0xbe, 0x70, 0xe7}; - gsec_aead_malloc_test_vector( - &test_vector_19, test_vector_19_key, - sizeof(test_vector_19_key) / sizeof(uint8_t), test_vector_19_nonce, - sizeof(test_vector_19_nonce) / sizeof(uint8_t), test_vector_19_aad, - sizeof(test_vector_19_aad) / sizeof(uint8_t), test_vector_19_plaintext, - sizeof(test_vector_19_plaintext) / sizeof(uint8_t), - test_vector_19_ciphertext_and_tag, - sizeof(test_vector_19_ciphertext_and_tag) / sizeof(uint8_t)); - gsec_test_verify_crypter_on_test_vector(test_vector_19); - gsec_aead_free_test_vector(test_vector_19); - - /* 2.8.2 61-byte crypt */ - gsec_aead_test_vector* test_vector_20; - const uint8_t test_vector_20_key[] = { - 0x4c, 0x97, 0x3d, 0xbc, 0x73, 0x64, 0x62, 0x16, 0x74, 0xf8, 0xb5, - 0xb8, 0x9e, 0x5c, 0x15, 0x51, 0x1f, 0xce, 0xd9, 0x21, 0x64, 0x90, - 0xfb, 0x1c, 0x1a, 0x2c, 0xaa, 0x0f, 0xfe, 0x04, 0x07, 0xe5}; - const uint8_t test_vector_20_nonce[] = {0x7a, 0xe8, 0xe2, 0xca, 0x4e, 0xc5, - 0x00, 0x01, 0x2e, 0x58, 0x49, 0x5c}; - const uint8_t test_vector_20_aad[] = { - 0x68, 0xf2, 0xe7, 0x76, 0x96, 0xce, 0x7a, 0xe8, 0xe2, 0xca, - 0x4e, 0xc5, 0x88, 0xe5, 0x4d, 0x00, 0x2e, 0x58, 0x49, 0x5c}; - const uint8_t test_vector_20_plaintext[] = { - 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, - 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, - 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, - 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, - 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x00, 0x08}; - const uint8_t test_vector_20_ciphertext_and_tag[] = { - 0xba, 0x8a, 0xe3, 0x1b, 0xc5, 0x06, 0x48, 0x6d, 0x68, 0x73, 0xe4, 0xfc, - 0xe4, 0x60, 0xe7, 0xdc, 0x57, 0x59, 0x1f, 0xf0, 0x06, 0x11, 0xf3, 0x1c, - 0x38, 0x34, 0xfe, 0x1c, 0x04, 0xad, 0x80, 0xb6, 0x68, 0x03, 0xaf, 0xcf, - 0x5b, 0x27, 0xe6, 0x33, 0x3f, 0xa6, 0x7c, 0x99, 0xda, 0x47, 0xc2, 0xf0, - 0xce, 0xd6, 0x8d, 0x53, 0x1b, 0xd7, 0x41, 0xa9, 0x43, 0xcf, 0xf7, 0xa6, - 0x71, 0x3b, 0xd0, 0x26, 0x11, 0xcd, 0x7d, 0xaa, 0x01, 0xd6, 0x1c, 0x5c, - 0x88, 0x6d, 0xc1, 0xa8, 0x17, 0x01, 0x07}; - gsec_aead_malloc_test_vector( - &test_vector_20, test_vector_20_key, - sizeof(test_vector_20_key) / sizeof(uint8_t), test_vector_20_nonce, - sizeof(test_vector_20_nonce) / sizeof(uint8_t), test_vector_20_aad, - sizeof(test_vector_20_aad) / sizeof(uint8_t), test_vector_20_plaintext, - sizeof(test_vector_20_plaintext) / sizeof(uint8_t), - test_vector_20_ciphertext_and_tag, - sizeof(test_vector_20_ciphertext_and_tag) / sizeof(uint8_t)); - gsec_test_verify_crypter_on_test_vector(test_vector_20); - gsec_aead_free_test_vector(test_vector_20); -} - -int main(int argc, char** argv) { - grpc_init(); - gsec_test_do_generic_crypter_tests(); - gsec_test_do_vector_tests_nist(); - gsec_test_do_vector_tests_ieee(); - gsec_test_do_vector_tests_rekey_nist(); - gsec_test_do_vector_tests_rekey_ieee(); - grpc_shutdown(); - return 0; -} diff --git a/test/core/tsi/alts/crypt/gsec_test_util.cc b/test/core/tsi/alts/crypt/gsec_test_util.cc deleted file mode 100644 index 992c91e6bc..0000000000 --- a/test/core/tsi/alts/crypt/gsec_test_util.cc +++ /dev/null @@ -1,87 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "test/core/tsi/alts/crypt/gsec_test_util.h" - -#include - -void gsec_test_random_bytes(uint8_t* bytes, size_t length) { - if (!RAND_bytes(bytes, static_cast(length))) { - fprintf(stderr, - "Random bytes generation failed in gsec_test_random_bytes()."); - abort(); - } -} - -void gsec_test_random_array(uint8_t** bytes, size_t length) { - if (bytes != nullptr) { - *bytes = static_cast(gpr_malloc(length)); - gsec_test_random_bytes(*bytes, length); - } else { - fprintf(stderr, "bytes buffer is nullptr in gsec_test_random_array()."); - abort(); - } -} - -uint32_t gsec_test_bias_random_uint32(uint32_t max_length) { - uint32_t value; - gsec_test_random_bytes((uint8_t*)(&value), sizeof(value)); - return value % max_length; -} - -void gsec_test_copy(const uint8_t* src, uint8_t** des, size_t source_len) { - if (src != nullptr && des != nullptr) { - *des = static_cast(gpr_malloc(source_len)); - memcpy(*des, src, source_len); - } else { - fprintf(stderr, "Either src or des buffer is nullptr in gsec_test_copy()."); - abort(); - } -} - -void gsec_test_copy_and_alter_random_byte(const uint8_t* src, uint8_t** des, - size_t source_len) { - if (src != nullptr && des != nullptr) { - *des = static_cast(gpr_malloc(source_len)); - memcpy(*des, src, source_len); - uint32_t offset; - offset = gsec_test_bias_random_uint32(static_cast(source_len)); - (*(*des + offset))++; - } else { - fprintf(stderr, - "Either src or des is nullptr in " - "gsec_test_copy_and_alter_random_byte()."); - abort(); - } -} - -int gsec_test_expect_compare_code_and_substr(grpc_status_code status1, - grpc_status_code status2, - const char* msg1, - const char* msg2) { - int failure = 1; - if (status1 != status2) { - fprintf(stderr, "Status %d does not equal %d.\n", status1, status2); - failure = 0; - } - if (strstr(msg1, msg2) == nullptr) { - fprintf(stderr, "Status message <%s> does not contain <%s>.\n", msg1, msg2); - failure = 0; - } - return failure; -} diff --git a/test/core/tsi/alts/crypt/gsec_test_util.h b/test/core/tsi/alts/crypt/gsec_test_util.h deleted file mode 100644 index 206ae2fda8..0000000000 --- a/test/core/tsi/alts/crypt/gsec_test_util.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_TEST_CORE_TSI_ALTS_CRYPT_GSEC_TEST_UTIL_H_ -#define GRPC_TEST_CORE_TSI_ALTS_CRYPT_GSEC_TEST_UTIL_H_ - -#include -#include -#include -#include - -#include - -#include - -/** - * This method returns random bytes of certain length. - * - * - bytes: buffer to hold random bytes. - * - length: length of buffer to be populated. - */ -void gsec_test_random_bytes(uint8_t* bytes, size_t length); - -/** - * This method returns an array of random bytes. - * - * - bytes: array to hold random bytes. - * - length: length of array to be populated. - */ -void gsec_test_random_array(uint8_t** bytes, size_t length); - -/** - * This method returns a uint32 that's not quite uniformly random, but good - * enough for tests. - * - * - max_length: a max value the returned random number can choose. - */ -uint32_t gsec_test_bias_random_uint32(uint32_t max_length); - -/** - * This method copies data from a source to a destination buffer. - * - * - src: a source buffer. - * - des: a destination buffer. - * - length: the length of source buffer to be copied from its beginning. - */ -void gsec_test_copy(const uint8_t* src, uint8_t** des, size_t length); - -/** - * This method copies data from a source to a destination buffer, and flips one - * byte in the destination buffer randomly. - * - * - src: a source buffer. - * - des: a destination buffer. - * - length: the length of source buffer to be copied from its beginning. - */ -void gsec_test_copy_and_alter_random_byte(const uint8_t* src, uint8_t** des, - size_t source_len); - -/** - * This method compares two grpc_status_code values, and verifies if one string - * is a substring of the other. - * - * - status1: the first grpc_status_code to be compared. - * - status2: the second grpc_status_code to be compared. - * - msg1: a string to be scanned. - * - msg2: a small string to be searched within msg1. - * - * If both checks succeed, the method returns 1 and otherwise, it returns 0. - */ -int gsec_test_expect_compare_code_and_substr(grpc_status_code status1, - grpc_status_code status2, - const char* msg1, - const char* msg2); - -#endif // GRPC_TEST_CORE_TSI_ALTS_CRYPT_GSEC_TEST_UTIL_H_ */ diff --git a/test/core/tsi/alts/frame_protector/BUILD b/test/core/tsi/alts/frame_protector/BUILD deleted file mode 100644 index 8bbc8c6e5e..0000000000 --- a/test/core/tsi/alts/frame_protector/BUILD +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright 2018 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_package") - -licenses(["notice"]) # Apache v2 - -grpc_package(name = "frame_protector") - -grpc_cc_test( - name = "alts_counter_test", - srcs = ["alts_counter_test.cc"], - language = "C++", - deps = [ - "//:grpc", - "//test/core/tsi/alts/crypt:alts_crypt_test_util", - ], -) - -grpc_cc_test( - name = "alts_crypter_test", - srcs = ["alts_crypter_test.cc"], - language = "C++", - deps = [ - "//:grpc", - "//test/core/tsi/alts/crypt:alts_crypt_test_util", - ], -) - -grpc_cc_test( - name = "alts_frame_protector_test", - srcs = ["alts_frame_protector_test.cc"], - language = "C++", - deps = [ - "//:grpc", - "//test/core/tsi/alts/crypt:alts_crypt_test_util", - "//test/core/tsi:transport_security_test_lib", - ], -) - -grpc_cc_test( - name = "frame_handler_test", - srcs = ["frame_handler_test.cc"], - language = "C++", - deps = [ - "//:grpc", - "//test/core/tsi/alts/crypt:alts_crypt_test_util", - ], -) diff --git a/test/core/tsi/alts/frame_protector/alts_counter_test.cc b/test/core/tsi/alts/frame_protector/alts_counter_test.cc deleted file mode 100644 index 49ff82108b..0000000000 --- a/test/core/tsi/alts/frame_protector/alts_counter_test.cc +++ /dev/null @@ -1,180 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include - -#include "src/core/tsi/alts/frame_protector/alts_counter.h" -#include "test/core/tsi/alts/crypt/gsec_test_util.h" - -const size_t kSmallCounterSize = 4; -const size_t kSmallOverflowSize = 1; -const size_t kGcmCounterSize = 12; -const size_t kGcmOverflowSize = 5; - -static bool do_bytes_represent_client(alts_counter* ctr, unsigned char* counter, - size_t size) { - return (ctr->counter[size - 1] & 0x80) == 0x80; -} - -static void alts_counter_test_input_sanity_check(size_t counter_size, - size_t overflow_size) { - alts_counter* ctr = nullptr; - char* error_details = nullptr; - - /* Input sanity check on alts_counter_create(). */ - /* Invalid counter size. */ - grpc_status_code status = - alts_counter_create(true, 0, overflow_size, &ctr, &error_details); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_details, - "counter_size is invalid.")); - gpr_free(error_details); - - /* Invalid overflow size. */ - status = alts_counter_create(true, counter_size, 0, &ctr, &error_details); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_details, - "overflow_size is invalid.")); - gpr_free(error_details); - - /* alts_counter is nullptr. */ - status = alts_counter_create(true, counter_size, overflow_size, nullptr, - &error_details); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_details, - "crypter_counter is nullptr.")); - gpr_free(error_details); - - status = alts_counter_create(true, counter_size, overflow_size, &ctr, - &error_details); - GPR_ASSERT(status == GRPC_STATUS_OK); - - /* Input sanity check on alts_counter_increment(). */ - /* crypter_counter is nullptr. */ - bool is_overflow = false; - status = alts_counter_increment(nullptr, &is_overflow, &error_details); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_details, - "crypter_counter is nullptr.")); - gpr_free(error_details); - /* is_overflow is nullptr. */ - status = alts_counter_increment(ctr, nullptr, &error_details); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_details, - "is_overflow is nullptr.")); - gpr_free(error_details); - alts_counter_destroy(ctr); -} - -static void alts_counter_test_overflow_full_range(bool is_client, - size_t counter_size, - size_t overflow_size) { - alts_counter* ctr = nullptr; - char* error_details = nullptr; - grpc_status_code status = alts_counter_create( - is_client, counter_size, overflow_size, &ctr, &error_details); - GPR_ASSERT(status == GRPC_STATUS_OK); - unsigned char* expected = - static_cast(gpr_zalloc(counter_size)); - if (is_client) { - expected[counter_size - 1] = 0x80; - } - /* Do a single iteration to ensure the counter is initialized as expected. */ - GPR_ASSERT(do_bytes_represent_client(ctr, alts_counter_get_counter(ctr), - counter_size) == is_client); - GPR_ASSERT(memcmp(alts_counter_get_counter(ctr), expected, counter_size) == - 0); - bool is_overflow = false; - GPR_ASSERT(alts_counter_increment(ctr, &is_overflow, &error_details) == - GRPC_STATUS_OK); - GPR_ASSERT(!is_overflow); - /** - * The counter can return 2^{overflow_size * 8} counters. The - * high-order bit is fixed to the client/server. The last call will yield a - * useable counter, but overflow the counter object. - */ - int iterations = 1 << (overflow_size * 8); - int ind = 1; - for (ind = 1; ind < iterations - 1; ind++) { - GPR_ASSERT(do_bytes_represent_client(ctr, alts_counter_get_counter(ctr), - counter_size) == is_client); - GPR_ASSERT(alts_counter_increment(ctr, &is_overflow, &error_details) == - GRPC_STATUS_OK); - GPR_ASSERT(!is_overflow); - } - GPR_ASSERT(do_bytes_represent_client(ctr, alts_counter_get_counter(ctr), - counter_size) == is_client); - GPR_ASSERT(alts_counter_increment(ctr, &is_overflow, &error_details) == - GRPC_STATUS_FAILED_PRECONDITION); - GPR_ASSERT(is_overflow); - gpr_free(expected); - alts_counter_destroy(ctr); -} - -/* Set the counter manually and make sure it overflows as expected. */ -static void alts_counter_test_overflow_single_increment(bool is_client, - size_t counter_size, - size_t overflow_size) { - alts_counter* ctr = nullptr; - char* error_details = nullptr; - grpc_status_code status = alts_counter_create( - is_client, counter_size, overflow_size, &ctr, &error_details); - GPR_ASSERT(status == GRPC_STATUS_OK); - unsigned char* expected = - static_cast(gpr_zalloc(counter_size)); - memset(expected, 0xFF, overflow_size); - expected[0] = 0xFE; - - if (is_client) { - expected[counter_size - 1] = 0x80; - } - memcpy(ctr->counter, expected, counter_size); - GPR_ASSERT(do_bytes_represent_client(ctr, alts_counter_get_counter(ctr), - counter_size) == is_client); - GPR_ASSERT(memcmp(expected, alts_counter_get_counter(ctr), counter_size) == - 0); - bool is_overflow = false; - GPR_ASSERT(alts_counter_increment(ctr, &is_overflow, &error_details) == - GRPC_STATUS_OK); - GPR_ASSERT(!is_overflow); - GPR_ASSERT(do_bytes_represent_client(ctr, alts_counter_get_counter(ctr), - counter_size) == is_client); - expected[0] = static_cast(expected[0] + 1); - GPR_ASSERT(memcmp(expected, alts_counter_get_counter(ctr), counter_size) == - 0); - GPR_ASSERT(alts_counter_increment(ctr, &is_overflow, &error_details) == - GRPC_STATUS_FAILED_PRECONDITION); - GPR_ASSERT(is_overflow); - gpr_free(expected); - alts_counter_destroy(ctr); -} - -int main(int argc, char** argv) { - alts_counter_test_input_sanity_check(kGcmCounterSize, kGcmOverflowSize); - alts_counter_test_overflow_full_range(true, kSmallCounterSize, - kSmallOverflowSize); - alts_counter_test_overflow_full_range(false, kSmallCounterSize, - kSmallOverflowSize); - alts_counter_test_overflow_single_increment(true, kGcmCounterSize, - kGcmOverflowSize); - alts_counter_test_overflow_single_increment(false, kGcmCounterSize, - kGcmOverflowSize); - - return 0; -} diff --git a/test/core/tsi/alts/frame_protector/alts_crypter_test.cc b/test/core/tsi/alts/frame_protector/alts_crypter_test.cc deleted file mode 100644 index 0ad616bcd6..0000000000 --- a/test/core/tsi/alts/frame_protector/alts_crypter_test.cc +++ /dev/null @@ -1,493 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include - -#include -#include - -#include "src/core/tsi/alts/frame_protector/alts_crypter.h" -#include "test/core/tsi/alts/crypt/gsec_test_util.h" - -static void alts_crypter_test_random_seal_unseal(alts_crypter* server_seal, - alts_crypter* server_unseal, - alts_crypter* client_seal, - alts_crypter* client_unseal) { - size_t data_size = gsec_test_bias_random_uint32(1024) + 1; - size_t num_overhead_bytes = alts_crypter_num_overhead_bytes(server_seal); - size_t protected_data_size = data_size + num_overhead_bytes; - uint8_t* data_buffer = static_cast(gpr_malloc(protected_data_size)); - gsec_test_random_bytes(data_buffer, data_size); - uint8_t* duplicate_buffer = nullptr; - gsec_test_copy(data_buffer, &duplicate_buffer, data_size); - - /* Client seal and server unseal */ - size_t size = data_size; - grpc_status_code status = alts_crypter_process_in_place( - client_seal, data_buffer, protected_data_size, size, &size, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(size == protected_data_size); - status = alts_crypter_process_in_place( - server_unseal, data_buffer, protected_data_size, size, &size, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(memcmp(data_buffer, duplicate_buffer, data_size) == 0); - GPR_ASSERT(size == data_size); - /* Server seal and client unseal */ - status = alts_crypter_process_in_place( - server_seal, data_buffer, protected_data_size, size, &size, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(size == protected_data_size); - status = alts_crypter_process_in_place( - client_unseal, data_buffer, protected_data_size, size, &size, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(memcmp(data_buffer, duplicate_buffer, data_size) == 0); - GPR_ASSERT(size == data_size); - gpr_free(data_buffer); - gpr_free(duplicate_buffer); -} - -static void alts_crypter_test_multiple_random_seal_unseal( - alts_crypter* server_seal, alts_crypter* server_unseal, - alts_crypter* client_seal, alts_crypter* client_unseal) { - size_t data_size = gsec_test_bias_random_uint32(1024) + 1; - size_t num_overhead_bytes = alts_crypter_num_overhead_bytes(server_seal); - size_t protected_data_size = data_size + num_overhead_bytes; - - uint8_t* data_buffer1 = - static_cast(gpr_malloc(protected_data_size)); - uint8_t* data_buffer2 = - static_cast(gpr_malloc(protected_data_size)); - uint8_t* duplicate_buffer1 = nullptr; - uint8_t* duplicate_buffer2 = nullptr; - gsec_test_random_bytes(data_buffer1, data_size); - gsec_test_random_bytes(data_buffer2, data_size); - gsec_test_copy(data_buffer1, &duplicate_buffer1, data_size); - gsec_test_copy(data_buffer2, &duplicate_buffer2, data_size); - - /* Client seal and server unseal */ - size_t size1 = data_size, size2 = data_size; - grpc_status_code status = alts_crypter_process_in_place( - client_seal, data_buffer1, protected_data_size, size1, &size1, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(size1 == protected_data_size); - status = alts_crypter_process_in_place( - client_seal, data_buffer2, protected_data_size, size2, &size2, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(size2 == protected_data_size); - status = alts_crypter_process_in_place( - server_unseal, data_buffer1, protected_data_size, size1, &size1, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(memcmp(data_buffer1, duplicate_buffer1, data_size) == 0); - GPR_ASSERT(size1 == data_size); - status = alts_crypter_process_in_place( - server_unseal, data_buffer2, protected_data_size, size2, &size2, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(memcmp(data_buffer2, duplicate_buffer2, data_size) == 0); - GPR_ASSERT(size2 == data_size); - - /* Server seal and client unseal */ - status = alts_crypter_process_in_place( - server_seal, data_buffer1, protected_data_size, size1, &size1, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(size1 == protected_data_size); - status = alts_crypter_process_in_place( - server_seal, data_buffer2, protected_data_size, size2, &size2, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(size2 == protected_data_size); - status = alts_crypter_process_in_place( - client_unseal, data_buffer1, protected_data_size, size1, &size1, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(memcmp(data_buffer1, duplicate_buffer1, data_size) == 0); - GPR_ASSERT(size1 == data_size); - status = alts_crypter_process_in_place( - client_unseal, data_buffer2, protected_data_size, size2, &size2, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(memcmp(data_buffer2, duplicate_buffer2, data_size) == 0); - GPR_ASSERT(size2 == data_size); - - gpr_free(data_buffer1); - gpr_free(data_buffer2); - gpr_free(duplicate_buffer1); - gpr_free(duplicate_buffer2); -} - -static void alts_crypter_test_corrupted_unseal(alts_crypter* server_seal, - alts_crypter* server_unseal, - alts_crypter* client_seal, - alts_crypter* client_unseal) { - size_t data_size = gsec_test_bias_random_uint32(1024) + 1; - size_t num_overhead_bytes = alts_crypter_num_overhead_bytes(server_seal); - size_t protected_data_size = data_size + num_overhead_bytes; - auto* data_buffer = static_cast(gpr_malloc(protected_data_size)); - auto* zero_buffer = static_cast(gpr_zalloc(data_size)); - - /* Corrupt a random byte in protected data. */ - size_t size = data_size; - gsec_test_random_bytes(data_buffer, data_size); - grpc_status_code status = alts_crypter_process_in_place( - client_seal, data_buffer, protected_data_size, size, &size, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(size == protected_data_size); - uint8_t* corrupted_data_buffer; - char* error_message = nullptr; - gsec_test_copy_and_alter_random_byte(data_buffer, &corrupted_data_buffer, - protected_data_size); - status = alts_crypter_process_in_place(server_unseal, corrupted_data_buffer, - protected_data_size, size, &size, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_FAILED_PRECONDITION, error_message, - "Checking tag failed")); - GPR_ASSERT(memcmp(corrupted_data_buffer, zero_buffer, data_size) == 0); - gpr_free(corrupted_data_buffer); - gpr_free(error_message); - - /* Corrupt the beginning of protected data. */ - size = data_size; - gsec_test_random_bytes(data_buffer, data_size); - status = alts_crypter_process_in_place( - client_seal, data_buffer, protected_data_size, size, &size, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(size == protected_data_size); - gsec_test_copy(data_buffer, &corrupted_data_buffer, protected_data_size); - (*corrupted_data_buffer)++; - status = alts_crypter_process_in_place(server_unseal, corrupted_data_buffer, - protected_data_size, size, &size, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_FAILED_PRECONDITION, error_message, - "Checking tag failed")); - GPR_ASSERT(memcmp(corrupted_data_buffer, zero_buffer, data_size) == 0); - gpr_free(corrupted_data_buffer); - gpr_free(error_message); - - /* Corrupt the end of protected data. */ - size = data_size; - gsec_test_random_bytes(data_buffer, data_size); - status = alts_crypter_process_in_place( - client_seal, data_buffer, protected_data_size, size, &size, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(size == protected_data_size); - gsec_test_copy(data_buffer, &corrupted_data_buffer, protected_data_size); - (*(corrupted_data_buffer + protected_data_size - 1))++; - status = alts_crypter_process_in_place(server_unseal, corrupted_data_buffer, - protected_data_size, size, &size, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_FAILED_PRECONDITION, error_message, - "Checking tag failed")); - GPR_ASSERT(memcmp(corrupted_data_buffer, zero_buffer, data_size) == 0); - gpr_free(corrupted_data_buffer); - gpr_free(error_message); - - gpr_free(data_buffer); - gpr_free(zero_buffer); -} - -static void alts_crypter_test_unsync_seal_unseal(alts_crypter* server_seal, - alts_crypter* server_unseal, - alts_crypter* client_seal, - alts_crypter* client_unseal) { - size_t data_size = gsec_test_bias_random_uint32(1024) + 1; - size_t num_overhead_bytes = alts_crypter_num_overhead_bytes(server_seal); - size_t protected_data_size = data_size + num_overhead_bytes; - auto* data_buffer = static_cast(gpr_malloc(protected_data_size)); - auto* zero_buffer = static_cast(gpr_zalloc(data_size)); - - /* Perform two seals at client, one unseal at server. */ - size_t size = data_size; - gsec_test_random_bytes(data_buffer, data_size); - grpc_status_code status = alts_crypter_process_in_place( - client_seal, data_buffer, protected_data_size, size, &size, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(size == protected_data_size); - - size = data_size; - gsec_test_random_bytes(data_buffer, data_size); - status = alts_crypter_process_in_place( - client_seal, data_buffer, protected_data_size, size, &size, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(size == protected_data_size); - - char* error_message = nullptr; - status = alts_crypter_process_in_place(server_unseal, data_buffer, - protected_data_size, size, &size, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_FAILED_PRECONDITION, error_message, - "Checking tag failed")); - GPR_ASSERT(memcmp(data_buffer, zero_buffer, data_size) == 0); - gpr_free(error_message); - - /* Perform two seals at server, one unseal at client. */ - size = data_size; - gsec_test_random_bytes(data_buffer, data_size); - status = alts_crypter_process_in_place( - server_seal, data_buffer, protected_data_size, size, &size, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(size == protected_data_size); - - size = data_size; - gsec_test_random_bytes(data_buffer, data_size); - status = alts_crypter_process_in_place( - server_seal, data_buffer, protected_data_size, size, &size, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(size == protected_data_size); - - status = alts_crypter_process_in_place(client_unseal, data_buffer, - protected_data_size, size, &size, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_FAILED_PRECONDITION, error_message, - "Checking tag failed")); - GPR_ASSERT(memcmp(data_buffer, zero_buffer, data_size) == 0); - gpr_free(error_message); - gpr_free(data_buffer); - gpr_free(zero_buffer); -} - -static void alts_crypter_test_input_sanity_check(alts_crypter* crypter_seal, - alts_crypter* crypter_unseal) { - size_t data_size = gsec_test_bias_random_uint32(1024) + 1; - size_t num_overhead_bytes = alts_crypter_num_overhead_bytes(crypter_seal); - size_t protected_data_size = data_size + num_overhead_bytes; - auto* data_buffer = static_cast(gpr_malloc(protected_data_size)); - gsec_test_random_bytes(data_buffer, data_size); - char* error_message = nullptr; - size_t size = data_size; - - /* Crypter is nullptr. */ - grpc_status_code status = alts_crypter_process_in_place( - nullptr, data_buffer, protected_data_size, size, &size, &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "crypter or crypter->vtable has not been initialized properly.")); - gpr_free(error_message); - - /* Seal data is nullptr. */ - size = data_size; - status = alts_crypter_process_in_place( - crypter_seal, nullptr, protected_data_size, size, &size, &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, "data is nullptr.")); - gpr_free(error_message); - - /* Seal data size is 0. */ - size = 0; - status = alts_crypter_process_in_place(crypter_seal, data_buffer, - protected_data_size, size, &size, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "data_size is zero.")); - gpr_free(error_message); - - /* Seal data buffer has a size smaller than the required. */ - size = data_size; - status = alts_crypter_process_in_place(crypter_seal, data_buffer, - protected_data_size - 1, size, &size, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "data_allocated_size is smaller than sum of data_size and " - "num_overhead_bytes.")); - gpr_free(error_message); - - /* Unseal data is nullptr. */ - size = data_size; - status = alts_crypter_process_in_place(crypter_unseal, nullptr, - protected_data_size, size, &size, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, "data is nullptr.")); - gpr_free(error_message); - - /* Unseal data size is 0. */ - size = 0; - status = alts_crypter_process_in_place(crypter_unseal, data_buffer, - protected_data_size, size, &size, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "data_size is smaller than num_overhead_bytes.")); - gpr_free(error_message); - - /* Unseal data size is smaller than number of overhead bytes. */ - size = num_overhead_bytes - 1; - status = alts_crypter_process_in_place(crypter_unseal, data_buffer, - protected_data_size, size, &size, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "data_size is smaller than num_overhead_bytes.")); - gpr_free(error_message); - gpr_free(data_buffer); -} - -static void create_random_alts_seal_crypter( - alts_crypter** server_seal, alts_crypter** server_unseal, - alts_crypter** client_seal, alts_crypter** client_unseal, - gsec_aead_crypter** server_crypter_seal, - gsec_aead_crypter** server_crypter_unseal, - gsec_aead_crypter** client_crypter_seal, - gsec_aead_crypter** client_crypter_unseal, bool rekey) { - size_t key_length = rekey ? kAes128GcmRekeyKeyLength : kAes128GcmKeyLength; - uint8_t* key; - gsec_test_random_array(&key, key_length); - gsec_aes_gcm_aead_crypter_create(key, key_length, kAesGcmNonceLength, - kAesGcmTagLength, rekey, server_crypter_seal, - nullptr); - gsec_aes_gcm_aead_crypter_create(key, key_length, kAesGcmNonceLength, - kAesGcmTagLength, rekey, - server_crypter_unseal, nullptr); - gsec_aes_gcm_aead_crypter_create(key, key_length, kAesGcmNonceLength, - kAesGcmTagLength, rekey, client_crypter_seal, - nullptr); - gsec_aes_gcm_aead_crypter_create(key, key_length, kAesGcmNonceLength, - kAesGcmTagLength, rekey, - client_crypter_unseal, nullptr); - - size_t overflow_size = rekey ? 8 : 5; - alts_seal_crypter_create(*client_crypter_seal, /*is_client=*/true, - overflow_size, client_seal, nullptr); - alts_unseal_crypter_create(*client_crypter_unseal, /*is_client=*/true, - overflow_size, client_unseal, nullptr); - alts_seal_crypter_create(*server_crypter_seal, /*is_client=*/false, - overflow_size, server_seal, nullptr); - alts_unseal_crypter_create(*server_crypter_unseal, /*is_client=*/false, - overflow_size, server_unseal, nullptr); - gpr_free(key); -} - -static void destroy_random_alts_seal_crypter(alts_crypter* server_seal, - alts_crypter* server_unseal, - alts_crypter* client_seal, - alts_crypter* client_unseal) { - alts_crypter_destroy(server_seal); - alts_crypter_destroy(server_unseal); - alts_crypter_destroy(client_seal); - alts_crypter_destroy(client_unseal); -} - -static void alts_crypter_do_generic_tests() { - alts_crypter *server_seal = nullptr, *server_unseal = nullptr, - *client_seal = nullptr, *client_unseal = nullptr; - gsec_aead_crypter *server_crypter_seal = nullptr, - *server_crypter_unseal = nullptr, - *client_crypter_seal = nullptr, - *client_crypter_unseal = nullptr; - /* Random seal and unseal tests */ - create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal, - &client_unseal, &server_crypter_seal, - &server_crypter_unseal, &client_crypter_seal, - &client_crypter_unseal, /*rekey=*/false); - alts_crypter_test_random_seal_unseal(server_seal, server_unseal, client_seal, - client_unseal); - destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal, - client_unseal); - - create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal, - &client_unseal, &server_crypter_seal, - &server_crypter_unseal, &client_crypter_seal, - &client_crypter_unseal, /*rekey=*/true); - alts_crypter_test_random_seal_unseal(server_seal, server_unseal, client_seal, - client_unseal); - destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal, - client_unseal); - - /* Multiple random seal and unseal tests */ - create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal, - &client_unseal, &server_crypter_seal, - &server_crypter_unseal, &client_crypter_seal, - &client_crypter_unseal, /*rekey=*/false); - alts_crypter_test_multiple_random_seal_unseal(server_seal, server_unseal, - client_seal, client_unseal); - destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal, - client_unseal); - - create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal, - &client_unseal, &server_crypter_seal, - &server_crypter_unseal, &client_crypter_seal, - &client_crypter_unseal, /*rekey=*/true); - alts_crypter_test_multiple_random_seal_unseal(server_seal, server_unseal, - client_seal, client_unseal); - destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal, - client_unseal); - - /* Corrupted unseal tests */ - create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal, - &client_unseal, &server_crypter_seal, - &server_crypter_unseal, &client_crypter_seal, - &client_crypter_unseal, /*rekey=*/false); - alts_crypter_test_corrupted_unseal(server_seal, server_unseal, client_seal, - client_unseal); - destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal, - client_unseal); - - create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal, - &client_unseal, &server_crypter_seal, - &server_crypter_unseal, &client_crypter_seal, - &client_crypter_unseal, /*rekey=*/true); - alts_crypter_test_corrupted_unseal(server_seal, server_unseal, client_seal, - client_unseal); - destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal, - client_unseal); - - /* Unsync seal and unseal tests */ - create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal, - &client_unseal, &server_crypter_seal, - &server_crypter_unseal, &client_crypter_seal, - &client_crypter_unseal, /*rekey=*/false); - alts_crypter_test_unsync_seal_unseal(server_seal, server_unseal, client_seal, - client_unseal); - destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal, - client_unseal); - - create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal, - &client_unseal, &server_crypter_seal, - &server_crypter_unseal, &client_crypter_seal, - &client_crypter_unseal, /*rekey=*/true); - alts_crypter_test_unsync_seal_unseal(server_seal, server_unseal, client_seal, - client_unseal); - destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal, - client_unseal); - - /* Input sanity check tests */ - create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal, - &client_unseal, &server_crypter_seal, - &server_crypter_unseal, &client_crypter_seal, - &client_crypter_unseal, /*rekey=*/false); - alts_crypter_test_input_sanity_check(server_seal, server_unseal); - destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal, - client_unseal); - - create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal, - &client_unseal, &server_crypter_seal, - &server_crypter_unseal, &client_crypter_seal, - &client_crypter_unseal, /*rekey=*/true); - alts_crypter_test_input_sanity_check(server_seal, server_unseal); - destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal, - client_unseal); -} - -int main(int argc, char** argv) { - alts_crypter_do_generic_tests(); - return 0; -} diff --git a/test/core/tsi/alts/frame_protector/alts_frame_protector_test.cc b/test/core/tsi/alts/frame_protector/alts_frame_protector_test.cc deleted file mode 100644 index 2bd4958763..0000000000 --- a/test/core/tsi/alts/frame_protector/alts_frame_protector_test.cc +++ /dev/null @@ -1,394 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include - -#include - -#include "src/core/tsi/alts/crypt/gsec.h" -#include "src/core/tsi/alts/frame_protector/alts_frame_protector.h" -#include "src/core/tsi/transport_security_interface.h" -#include "test/core/tsi/alts/crypt/gsec_test_util.h" -#include "test/core/tsi/transport_security_test_lib.h" - -const size_t kChannelSize = 32768; - -static void alts_test_do_round_trip_check_frames( - tsi_test_frame_protector_fixture* fixture, const uint8_t* key, - const size_t key_size, bool rekey, const uint8_t* client_message, - const size_t client_message_size, const uint8_t* client_expected_frames, - const size_t client_frame_size, const uint8_t* server_message, - const size_t server_message_size, const uint8_t* server_expected_frames, - const size_t server_frame_size) { - GPR_ASSERT(fixture != nullptr); - GPR_ASSERT(fixture->config != nullptr); - tsi_frame_protector* client_frame_protector = nullptr; - tsi_frame_protector* server_frame_protector = nullptr; - tsi_test_frame_protector_config* config = fixture->config; - tsi_test_channel* channel = fixture->channel; - /* Create a client frame protector. */ - size_t client_max_output_protected_frame_size = - config->client_max_output_protected_frame_size; - GPR_ASSERT( - alts_create_frame_protector(key, key_size, /*is_client=*/true, rekey, - client_max_output_protected_frame_size == 0 - ? nullptr - : &client_max_output_protected_frame_size, - &client_frame_protector) == TSI_OK); - /* Create a server frame protector. */ - size_t server_max_output_protected_frame_size = - config->server_max_output_protected_frame_size; - GPR_ASSERT( - alts_create_frame_protector(key, key_size, /*is_client=*/false, rekey, - server_max_output_protected_frame_size == 0 - ? nullptr - : &server_max_output_protected_frame_size, - &server_frame_protector) == TSI_OK); - tsi_test_frame_protector_fixture_init(fixture, client_frame_protector, - server_frame_protector); - /* Client sends a message to server. */ - uint8_t* saved_client_message = config->client_message; - config->client_message = const_cast(client_message); - config->client_message_size = client_message_size; - tsi_test_frame_protector_send_message_to_peer(config, channel, - client_frame_protector, - /*is_client=*/true); - /* Verify if the generated frame is the same as the expected. */ - GPR_ASSERT(channel->bytes_written_to_server_channel == client_frame_size); - GPR_ASSERT(memcmp(client_expected_frames, channel->server_channel, - client_frame_size) == 0); - unsigned char* server_received_message = - static_cast(gpr_malloc(kChannelSize)); - size_t server_received_message_size = 0; - tsi_test_frame_protector_receive_message_from_peer( - config, channel, server_frame_protector, server_received_message, - &server_received_message_size, /*is_client=*/false); - GPR_ASSERT(config->client_message_size == server_received_message_size); - GPR_ASSERT(memcmp(config->client_message, server_received_message, - server_received_message_size) == 0); - /* Server sends a message to client. */ - uint8_t* saved_server_message = config->server_message; - config->server_message = const_cast(server_message); - config->server_message_size = server_message_size; - tsi_test_frame_protector_send_message_to_peer(config, channel, - server_frame_protector, - /*is_client=*/false); - /* Verify if the generated frame is the same as the expected. */ - GPR_ASSERT(channel->bytes_written_to_client_channel == server_frame_size); - GPR_ASSERT(memcmp(server_expected_frames, channel->client_channel, - server_frame_size) == 0); - unsigned char* client_received_message = - static_cast(gpr_malloc(kChannelSize)); - size_t client_received_message_size = 0; - tsi_test_frame_protector_receive_message_from_peer( - config, channel, client_frame_protector, client_received_message, - &client_received_message_size, - /*is_client=*/true); - GPR_ASSERT(config->server_message_size == client_received_message_size); - GPR_ASSERT(memcmp(config->server_message, client_received_message, - client_received_message_size) == 0); - config->client_message = saved_client_message; - config->server_message = saved_server_message; - /* Destroy server and client frame protectors. */ - gpr_free(server_received_message); - gpr_free(client_received_message); -} - -static void alts_test_do_round_trip_vector_tests() { - const uint8_t key[] = {0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, - 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08}; - const char small_message[] = {'C', 'h', 'a', 'p', 'i', ' ', - 'C', 'h', 'a', 'p', 'o'}; - const uint8_t large_message[] = { - 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, 0xa5, 0x59, 0x09, 0xc5, - 0xaf, 0xf5, 0x26, 0x9a, 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, - 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, 0x1c, 0x3c, 0x0c, 0x95, - 0x95, 0x68, 0x09, 0x53, 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, - 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, 0xba, 0x63, 0x7b, 0x39, - 0x1a, 0xaf, 0xd2, 0x55, 0xd6, 0x09, 0xb1, 0xf0, 0x56, 0x63, 0x7a, 0x0d, - 0x46, 0xdf, 0x99, 0x8d, 0x88, 0xe5, 0x22, 0x2a, 0xb2, 0xc2, 0x84, 0x65, - 0x12, 0x15, 0x35, 0x24, 0xc0, 0x89, 0x5e, 0x81, 0x08, 0x06, 0x0f, 0x10, - 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, - 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, - 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30}; - const size_t small_message_size = sizeof(small_message) / sizeof(uint8_t); - const size_t large_message_size = sizeof(large_message) / sizeof(uint8_t); - /* Test small client message and large server message. */ - const uint8_t client_expected_frame1[] = { - 0x1f, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x09, 0xd8, 0xd5, 0x92, - 0x4d, 0x50, 0x32, 0xb7, 0x1f, 0xb8, 0xf2, 0xbb, 0x43, 0xc7, 0xe2, 0x94, - 0x3d, 0x3e, 0x9a, 0x78, 0x76, 0xaa, 0x0a, 0x6b, 0xfa, 0x98, 0x3a}; - const uint8_t server_expected_frame1[] = { - 0x94, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xa9, 0x4b, 0xf8, 0xc8, - 0xe7, 0x8f, 0x1a, 0x26, 0x37, 0x44, 0xa2, 0x5c, 0x55, 0x94, 0x30, 0x4e, - 0x3e, 0x16, 0xe7, 0x9e, 0x96, 0xe8, 0x1b, 0xc0, 0xdd, 0x52, 0x30, 0x06, - 0xc2, 0x72, 0x9a, 0xa1, 0x0b, 0xdb, 0xdc, 0x19, 0x8c, 0x93, 0x5e, 0x84, - 0x1f, 0x4b, 0x97, 0x26, 0xf0, 0x73, 0x85, 0x59, 0x00, 0x95, 0xc1, 0xc5, - 0x22, 0x2f, 0x70, 0x85, 0x68, 0x2c, 0x4f, 0xfe, 0x30, 0x26, 0x91, 0xde, - 0x62, 0x55, 0x1d, 0x35, 0x01, 0x96, 0x1c, 0xe7, 0xa2, 0x8b, 0x14, 0x8a, - 0x5e, 0x1b, 0x4a, 0x3b, 0x4f, 0x65, 0x0f, 0xca, 0x79, 0x10, 0xb4, 0xdd, - 0xf7, 0xa4, 0x8b, 0x64, 0x2f, 0x00, 0x39, 0x60, 0x03, 0xfc, 0xe1, 0x8b, - 0x5c, 0x19, 0xba, 0xcc, 0x46, 0xba, 0x88, 0xdd, 0x40, 0x42, 0x27, 0x4f, - 0xe4, 0x1a, 0x6a, 0x31, 0x6c, 0x1c, 0xb0, 0xb6, 0x5c, 0x3e, 0xca, 0x84, - 0x9b, 0x5f, 0x04, 0x84, 0x11, 0xa9, 0xf8, 0x39, 0xe7, 0xe7, 0xc5, 0xc4, - 0x33, 0x9f, 0x63, 0x21, 0x9a, 0x7c, 0x9c, 0x64}; - const size_t client_frame_size1 = - sizeof(client_expected_frame1) / sizeof(uint8_t); - const size_t server_frame_size1 = - sizeof(server_expected_frame1) / sizeof(uint8_t); - tsi_test_frame_protector_fixture* fixture = - tsi_test_frame_protector_fixture_create(); - alts_test_do_round_trip_check_frames( - fixture, key, kAes128GcmKeyLength, /*rekey=*/false, - reinterpret_cast(small_message), small_message_size, - client_expected_frame1, client_frame_size1, large_message, - large_message_size, server_expected_frame1, server_frame_size1); - tsi_test_frame_protector_fixture_destroy(fixture); - /** - * Test large client message, small server message, and small - * message_buffer_allocated_size. - */ - const uint8_t client_expected_frame2[] = { - 0x94, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x93, 0x81, 0x86, 0xc7, - 0xdc, 0xf4, 0x77, 0x3a, 0xdb, 0x91, 0x94, 0x61, 0xba, 0xed, 0xd5, 0x37, - 0x47, 0x53, 0x0c, 0xe1, 0xbf, 0x59, 0x23, 0x20, 0xde, 0x8b, 0x25, 0x13, - 0x72, 0xe7, 0x8a, 0x4f, 0x32, 0x61, 0xc6, 0xda, 0xc3, 0xe9, 0xff, 0x31, - 0x33, 0x53, 0x4a, 0xf8, 0xc9, 0x98, 0xe4, 0x19, 0x71, 0x9c, 0x5e, 0x72, - 0xc7, 0x35, 0x97, 0x78, 0x30, 0xf2, 0xc4, 0xd1, 0x53, 0xd5, 0x6e, 0x8f, - 0x4f, 0xd9, 0x28, 0x5a, 0xfd, 0x22, 0x57, 0x7f, 0x95, 0xb4, 0x8a, 0x5e, - 0x7c, 0x47, 0xa8, 0xcf, 0x64, 0x3d, 0x83, 0xa5, 0xcf, 0xc3, 0xfe, 0x54, - 0xc2, 0x6a, 0x40, 0xc4, 0xfb, 0x8e, 0x07, 0x77, 0x70, 0x8f, 0x99, 0x94, - 0xb1, 0xd5, 0xa7, 0xf9, 0x0d, 0xc7, 0x11, 0xc5, 0x6f, 0x4a, 0x4f, 0x56, - 0xd5, 0xe2, 0x9c, 0xbb, 0x95, 0x7a, 0xd0, 0x9f, 0x30, 0x54, 0xca, 0x6d, - 0x5c, 0x8e, 0x83, 0xa0, 0x04, 0x5e, 0xd0, 0x22, 0x8c, 0x2a, 0x7f, 0xdb, - 0xfe, 0xb3, 0x2e, 0xae, 0x22, 0xe6, 0xf4, 0xb7}; - const uint8_t server_expected_frame2[] = { - 0x1f, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x33, 0x12, 0xab, 0x9d, - 0x76, 0x2b, 0x5f, 0xab, 0xf3, 0x6d, 0xc4, 0xaa, 0xe5, 0x1e, 0x63, 0xc1, - 0x7b, 0x7b, 0x10, 0xd5, 0x63, 0x0f, 0x29, 0xad, 0x17, 0x33, 0x73}; - const size_t client_frame_size2 = - sizeof(client_expected_frame2) / sizeof(uint8_t); - const size_t server_frame_size2 = - sizeof(server_expected_frame2) / sizeof(uint8_t); - fixture = tsi_test_frame_protector_fixture_create(); - alts_test_do_round_trip_check_frames( - fixture, key, kAes128GcmKeyLength, /*rekey=*/false, large_message, - large_message_size, client_expected_frame2, client_frame_size2, - reinterpret_cast(small_message), small_message_size, - server_expected_frame2, server_frame_size2); - tsi_test_frame_protector_fixture_destroy(fixture); - /** - * Test large client message, small server message, and small - * protected_buffer_size. - */ - const uint8_t client_expected_frame3[] = { - 0x94, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x93, 0x81, 0x86, 0xc7, - 0xdc, 0xf4, 0x77, 0x3a, 0xdb, 0x91, 0x94, 0x61, 0xba, 0xed, 0xd5, 0x37, - 0x47, 0x53, 0x0c, 0xe1, 0xbf, 0x59, 0x23, 0x20, 0xde, 0x8b, 0x25, 0x13, - 0x72, 0xe7, 0x8a, 0x4f, 0x32, 0x61, 0xc6, 0xda, 0xc3, 0xe9, 0xff, 0x31, - 0x33, 0x53, 0x4a, 0xf8, 0xc9, 0x98, 0xe4, 0x19, 0x71, 0x9c, 0x5e, 0x72, - 0xc7, 0x35, 0x97, 0x78, 0x30, 0xf2, 0xc4, 0xd1, 0x53, 0xd5, 0x6e, 0x8f, - 0x4f, 0xd9, 0x28, 0x5a, 0xfd, 0x22, 0x57, 0x7f, 0x95, 0xb4, 0x8a, 0x5e, - 0x7c, 0x47, 0xa8, 0xcf, 0x64, 0x3d, 0x83, 0xa5, 0xcf, 0xc3, 0xfe, 0x54, - 0xc2, 0x6a, 0x40, 0xc4, 0xfb, 0x8e, 0x07, 0x77, 0x70, 0x8f, 0x99, 0x94, - 0xb1, 0xd5, 0xa7, 0xf9, 0x0d, 0xc7, 0x11, 0xc5, 0x6f, 0x4a, 0x4f, 0x56, - 0xd5, 0xe2, 0x9c, 0xbb, 0x95, 0x7a, 0xd0, 0x9f, 0x30, 0x54, 0xca, 0x6d, - 0x5c, 0x8e, 0x83, 0xa0, 0x04, 0x5e, 0xd0, 0x22, 0x8c, 0x2a, 0x7f, 0xdb, - 0xfe, 0xb3, 0x2e, 0xae, 0x22, 0xe6, 0xf4, 0xb7}; - const uint8_t server_expected_frame3[] = { - 0x1f, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x33, 0x12, 0xab, 0x9d, - 0x76, 0x2b, 0x5f, 0xab, 0xf3, 0x6d, 0xc4, 0xaa, 0xe5, 0x1e, 0x63, 0xc1, - 0x7b, 0x7b, 0x10, 0xd5, 0x63, 0x0f, 0x29, 0xad, 0x17, 0x33, 0x73}; - const size_t client_frame_size3 = - sizeof(client_expected_frame3) / sizeof(uint8_t); - const size_t server_frame_size3 = - sizeof(server_expected_frame3) / sizeof(uint8_t); - fixture = tsi_test_frame_protector_fixture_create(); - alts_test_do_round_trip_check_frames( - fixture, key, kAes128GcmKeyLength, /*rekey=*/false, large_message, - large_message_size, client_expected_frame3, client_frame_size3, - reinterpret_cast(small_message), small_message_size, - server_expected_frame3, server_frame_size3); - tsi_test_frame_protector_fixture_destroy(fixture); - /** - * Test large client message, small server message, and small - * read_buffer_allocated_size. - */ - const uint8_t client_expected_frame4[] = { - 0x94, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x93, 0x81, 0x86, 0xc7, - 0xdc, 0xf4, 0x77, 0x3a, 0xdb, 0x91, 0x94, 0x61, 0xba, 0xed, 0xd5, 0x37, - 0x47, 0x53, 0x0c, 0xe1, 0xbf, 0x59, 0x23, 0x20, 0xde, 0x8b, 0x25, 0x13, - 0x72, 0xe7, 0x8a, 0x4f, 0x32, 0x61, 0xc6, 0xda, 0xc3, 0xe9, 0xff, 0x31, - 0x33, 0x53, 0x4a, 0xf8, 0xc9, 0x98, 0xe4, 0x19, 0x71, 0x9c, 0x5e, 0x72, - 0xc7, 0x35, 0x97, 0x78, 0x30, 0xf2, 0xc4, 0xd1, 0x53, 0xd5, 0x6e, 0x8f, - 0x4f, 0xd9, 0x28, 0x5a, 0xfd, 0x22, 0x57, 0x7f, 0x95, 0xb4, 0x8a, 0x5e, - 0x7c, 0x47, 0xa8, 0xcf, 0x64, 0x3d, 0x83, 0xa5, 0xcf, 0xc3, 0xfe, 0x54, - 0xc2, 0x6a, 0x40, 0xc4, 0xfb, 0x8e, 0x07, 0x77, 0x70, 0x8f, 0x99, 0x94, - 0xb1, 0xd5, 0xa7, 0xf9, 0x0d, 0xc7, 0x11, 0xc5, 0x6f, 0x4a, 0x4f, 0x56, - 0xd5, 0xe2, 0x9c, 0xbb, 0x95, 0x7a, 0xd0, 0x9f, 0x30, 0x54, 0xca, 0x6d, - 0x5c, 0x8e, 0x83, 0xa0, 0x04, 0x5e, 0xd0, 0x22, 0x8c, 0x2a, 0x7f, 0xdb, - 0xfe, 0xb3, 0x2e, 0xae, 0x22, 0xe6, 0xf4, 0xb7}; - const uint8_t server_expected_frame4[] = { - 0x1f, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x33, 0x12, 0xab, 0x9d, - 0x76, 0x2b, 0x5f, 0xab, 0xf3, 0x6d, 0xc4, 0xaa, 0xe5, 0x1e, 0x63, 0xc1, - 0x7b, 0x7b, 0x10, 0xd5, 0x63, 0x0f, 0x29, 0xad, 0x17, 0x33, 0x73}; - const size_t client_frame_size4 = - sizeof(client_expected_frame4) / sizeof(uint8_t); - const size_t server_frame_size4 = - sizeof(server_expected_frame4) / sizeof(uint8_t); - fixture = tsi_test_frame_protector_fixture_create(); - alts_test_do_round_trip_check_frames( - fixture, key, kAes128GcmKeyLength, /*rekey=*/false, large_message, - large_message_size, client_expected_frame4, client_frame_size4, - reinterpret_cast(small_message), small_message_size, - server_expected_frame4, server_frame_size4); - tsi_test_frame_protector_fixture_destroy(fixture); - /** - * Test large client message, small server message, and small - * client_max_output_protected_frame_size. - */ - const uint8_t client_expected_frame5[] = { - 0x94, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x93, 0x81, 0x86, 0xc7, - 0xdc, 0xf4, 0x77, 0x3a, 0xdb, 0x91, 0x94, 0x61, 0xba, 0xed, 0xd5, 0x37, - 0x47, 0x53, 0x0c, 0xe1, 0xbf, 0x59, 0x23, 0x20, 0xde, 0x8b, 0x25, 0x13, - 0x72, 0xe7, 0x8a, 0x4f, 0x32, 0x61, 0xc6, 0xda, 0xc3, 0xe9, 0xff, 0x31, - 0x33, 0x53, 0x4a, 0xf8, 0xc9, 0x98, 0xe4, 0x19, 0x71, 0x9c, 0x5e, 0x72, - 0xc7, 0x35, 0x97, 0x78, 0x30, 0xf2, 0xc4, 0xd1, 0x53, 0xd5, 0x6e, 0x8f, - 0x4f, 0xd9, 0x28, 0x5a, 0xfd, 0x22, 0x57, 0x7f, 0x95, 0xb4, 0x8a, 0x5e, - 0x7c, 0x47, 0xa8, 0xcf, 0x64, 0x3d, 0x83, 0xa5, 0xcf, 0xc3, 0xfe, 0x54, - 0xc2, 0x6a, 0x40, 0xc4, 0xfb, 0x8e, 0x07, 0x77, 0x70, 0x8f, 0x99, 0x94, - 0xb1, 0xd5, 0xa7, 0xf9, 0x0d, 0xc7, 0x11, 0xc5, 0x6f, 0x4a, 0x4f, 0x56, - 0xd5, 0xe2, 0x9c, 0xbb, 0x95, 0x7a, 0xd0, 0x9f, 0x30, 0x54, 0xca, 0x6d, - 0x5c, 0x8e, 0x83, 0xa0, 0x04, 0x5e, 0xd0, 0x22, 0x8c, 0x2a, 0x7f, 0xdb, - 0xfe, 0xb3, 0x2e, 0xae, 0x22, 0xe6, 0xf4, 0xb7}; - const uint8_t server_expected_frame5[] = { - 0x1f, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x33, 0x12, 0xab, 0x9d, - 0x76, 0x2b, 0x5f, 0xab, 0xf3, 0x6d, 0xc4, 0xaa, 0xe5, 0x1e, 0x63, 0xc1, - 0x7b, 0x7b, 0x10, 0xd5, 0x63, 0x0f, 0x29, 0xad, 0x17, 0x33, 0x73}; - const size_t client_frame_size5 = - sizeof(client_expected_frame5) / sizeof(uint8_t); - const size_t server_frame_size5 = - sizeof(server_expected_frame5) / sizeof(uint8_t); - fixture = tsi_test_frame_protector_fixture_create(); - alts_test_do_round_trip_check_frames( - fixture, key, kAes128GcmKeyLength, /*rekey=*/false, large_message, - large_message_size, client_expected_frame5, client_frame_size5, - reinterpret_cast(small_message), small_message_size, - server_expected_frame5, server_frame_size5); - tsi_test_frame_protector_fixture_destroy(fixture); - /** - * Test small client message, large server message, and small - * server_max_output_protected_frame_size. - */ - const uint8_t client_expected_frame6[] = { - 0x1f, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x09, 0xd8, 0xd5, 0x92, - 0x4d, 0x50, 0x32, 0xb7, 0x1f, 0xb8, 0xf2, 0xbb, 0x43, 0xc7, 0xe2, 0x94, - 0x3d, 0x3e, 0x9a, 0x78, 0x76, 0xaa, 0x0a, 0x6b, 0xfa, 0x98, 0x3a}; - const uint8_t server_expected_frame6[] = { - 0x94, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xa9, 0x4b, 0xf8, 0xc8, - 0xe7, 0x8f, 0x1a, 0x26, 0x37, 0x44, 0xa2, 0x5c, 0x55, 0x94, 0x30, 0x4e, - 0x3e, 0x16, 0xe7, 0x9e, 0x96, 0xe8, 0x1b, 0xc0, 0xdd, 0x52, 0x30, 0x06, - 0xc2, 0x72, 0x9a, 0xa1, 0x0b, 0xdb, 0xdc, 0x19, 0x8c, 0x93, 0x5e, 0x84, - 0x1f, 0x4b, 0x97, 0x26, 0xf0, 0x73, 0x85, 0x59, 0x00, 0x95, 0xc1, 0xc5, - 0x22, 0x2f, 0x70, 0x85, 0x68, 0x2c, 0x4f, 0xfe, 0x30, 0x26, 0x91, 0xde, - 0x62, 0x55, 0x1d, 0x35, 0x01, 0x96, 0x1c, 0xe7, 0xa2, 0x8b, 0x14, 0x8a, - 0x5e, 0x1b, 0x4a, 0x3b, 0x4f, 0x65, 0x0f, 0xca, 0x79, 0x10, 0xb4, 0xdd, - 0xf7, 0xa4, 0x8b, 0x64, 0x2f, 0x00, 0x39, 0x60, 0x03, 0xfc, 0xe1, 0x8b, - 0x5c, 0x19, 0xba, 0xcc, 0x46, 0xba, 0x88, 0xdd, 0x40, 0x42, 0x27, 0x4f, - 0xe4, 0x1a, 0x6a, 0x31, 0x6c, 0x1c, 0xb0, 0xb6, 0x5c, 0x3e, 0xca, 0x84, - 0x9b, 0x5f, 0x04, 0x84, 0x11, 0xa9, 0xf8, 0x39, 0xe7, 0xe7, 0xc5, 0xc4, - 0x33, 0x9f, 0x63, 0x21, 0x9a, 0x7c, 0x9c, 0x64}; - const size_t client_frame_size6 = - sizeof(client_expected_frame6) / sizeof(uint8_t); - const size_t server_frame_size6 = - sizeof(server_expected_frame6) / sizeof(uint8_t); - fixture = tsi_test_frame_protector_fixture_create(); - alts_test_do_round_trip_check_frames( - fixture, key, kAes128GcmKeyLength, /*rekey=*/false, - reinterpret_cast(small_message), small_message_size, - client_expected_frame6, client_frame_size6, large_message, - large_message_size, server_expected_frame6, server_frame_size6); - tsi_test_frame_protector_fixture_destroy(fixture); -} - -static void alts_test_do_round_trip(tsi_test_frame_protector_fixture* fixture, - bool rekey) { - GPR_ASSERT(fixture != nullptr); - GPR_ASSERT(fixture->config != nullptr); - tsi_frame_protector* client_frame_protector = nullptr; - tsi_frame_protector* server_frame_protector = nullptr; - tsi_test_frame_protector_config* config = fixture->config; - /* Create a key to be used by both client and server. */ - uint8_t* key = nullptr; - size_t key_length = rekey ? kAes128GcmRekeyKeyLength : kAes128GcmKeyLength; - gsec_test_random_array(&key, key_length); - /* Create a client frame protector. */ - size_t client_max_output_protected_frame_size = - config->client_max_output_protected_frame_size; - GPR_ASSERT( - alts_create_frame_protector(key, key_length, /*is_client=*/true, rekey, - client_max_output_protected_frame_size == 0 - ? nullptr - : &client_max_output_protected_frame_size, - &client_frame_protector) == TSI_OK); - /* Create a server frame protector. */ - size_t server_max_output_protected_frame_size = - config->server_max_output_protected_frame_size; - GPR_ASSERT( - alts_create_frame_protector(key, key_length, /*is_client=*/false, rekey, - server_max_output_protected_frame_size == 0 - ? nullptr - : &server_max_output_protected_frame_size, - &server_frame_protector) == TSI_OK); - tsi_test_frame_protector_fixture_init(fixture, client_frame_protector, - server_frame_protector); - tsi_test_frame_protector_do_round_trip_no_handshake(fixture); - gpr_free(key); -} - -/* Run all combinations of different arguments of test config. */ -static void alts_test_do_round_trip_all(bool rekey) { - unsigned int* bit_array = static_cast( - gpr_malloc(sizeof(unsigned int) * TSI_TEST_NUM_OF_ARGUMENTS)); - unsigned int mask = 1U << (TSI_TEST_NUM_OF_ARGUMENTS - 1); - unsigned int val = 0, ind = 0; - for (val = 0; val < TSI_TEST_NUM_OF_COMBINATIONS; val++) { - unsigned int v = val; - for (ind = 0; ind < TSI_TEST_NUM_OF_ARGUMENTS; ind++) { - bit_array[ind] = (v & mask) ? 1 : 0; - v <<= 1; - } - tsi_test_frame_protector_fixture* fixture = - tsi_test_frame_protector_fixture_create(); - tsi_test_frame_protector_config_destroy(fixture->config); - fixture->config = tsi_test_frame_protector_config_create( - bit_array[0], bit_array[1], bit_array[2], bit_array[3], bit_array[4], - bit_array[5], bit_array[6]); - alts_test_do_round_trip(fixture, rekey); - tsi_test_frame_protector_fixture_destroy(fixture); - } - gpr_free(bit_array); -} - -int main(int argc, char** argv) { - alts_test_do_round_trip_vector_tests(); - alts_test_do_round_trip_all(/*rekey=*/false); - alts_test_do_round_trip_all(/*rekey=*/true); - return 0; -} diff --git a/test/core/tsi/alts/frame_protector/frame_handler_test.cc b/test/core/tsi/alts/frame_protector/frame_handler_test.cc deleted file mode 100644 index 6434ea1d31..0000000000 --- a/test/core/tsi/alts/frame_protector/frame_handler_test.cc +++ /dev/null @@ -1,244 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include - -#include -#include - -#include "src/core/lib/gpr/useful.h" -#include "src/core/tsi/alts/frame_protector/frame_handler.h" -#include "test/core/tsi/alts/crypt/gsec_test_util.h" - -const size_t kFrameHandlerTestBufferSize = 1024; - -typedef struct frame_handler { - alts_frame_writer* writer; - alts_frame_reader* reader; - unsigned char* buffer; - size_t buffer_size; -} frame_handler; - -static size_t frame_length(size_t payload_length) { - return payload_length + kFrameHeaderSize; -} - -static frame_handler* create_frame_handler() { - frame_handler* handler = - static_cast(gpr_malloc(sizeof(frame_handler))); - handler->writer = alts_create_frame_writer(); - handler->reader = alts_create_frame_reader(); - handler->buffer = nullptr; - handler->buffer_size = 0; - return handler; -} - -static void destroy_frame_handler(frame_handler* handler) { - if (handler != nullptr) { - alts_destroy_frame_reader(handler->reader); - alts_destroy_frame_writer(handler->writer); - if (handler->buffer != nullptr) gpr_free(handler->buffer); - gpr_free(handler); - } -} - -static void frame(frame_handler* handler, unsigned char* payload, - size_t payload_length, size_t write_length) { - handler->buffer_size = frame_length(payload_length); - handler->buffer = - static_cast(gpr_malloc(handler->buffer_size)); - GPR_ASSERT(alts_reset_frame_writer(handler->writer, payload, payload_length)); - size_t offset = 0; - while (offset < handler->buffer_size && - !alts_is_frame_writer_done(handler->writer)) { - size_t bytes_written = GPR_MIN(write_length, handler->buffer_size - offset); - GPR_ASSERT(alts_write_frame_bytes(handler->writer, handler->buffer + offset, - &bytes_written)); - offset += bytes_written; - } - GPR_ASSERT(alts_is_frame_writer_done(handler->writer)); - GPR_ASSERT(handler->buffer_size == offset); -} - -static size_t deframe(frame_handler* handler, unsigned char* bytes, - size_t read_length) { - GPR_ASSERT(alts_reset_frame_reader(handler->reader, bytes)); - size_t offset = 0; - while (offset < handler->buffer_size && - !alts_is_frame_reader_done(handler->reader)) { - size_t bytes_read = GPR_MIN(read_length, handler->buffer_size - offset); - GPR_ASSERT(alts_read_frame_bytes(handler->reader, handler->buffer + offset, - &bytes_read)); - offset += bytes_read; - } - GPR_ASSERT(alts_is_frame_reader_done(handler->reader)); - GPR_ASSERT(handler->buffer_size == offset); - return offset - handler->reader->header_bytes_read; -} - -static void frame_n_deframe(frame_handler* handler, unsigned char* payload, - size_t payload_length, size_t write_length, - size_t read_length) { - frame(handler, payload, payload_length, write_length); - unsigned char* bytes = - static_cast(gpr_malloc(kFrameHandlerTestBufferSize)); - size_t deframed_payload_length = deframe(handler, bytes, read_length); - GPR_ASSERT(payload_length == deframed_payload_length); - GPR_ASSERT(memcmp(payload, bytes, payload_length) == 0); - gpr_free(bytes); -} - -static void frame_handler_test_frame_deframe() { - unsigned char payload[] = "hello world"; - size_t payload_length = strlen((char*)payload) + 1; - frame_handler* handler = create_frame_handler(); - frame_n_deframe(handler, payload, payload_length, - frame_length(payload_length), frame_length(payload_length)); - destroy_frame_handler(handler); -} - -static void frame_handler_test_small_buffer() { - unsigned char payload[] = "hello world"; - size_t payload_length = strlen(reinterpret_cast(payload)) + 1; - frame_handler* handler = create_frame_handler(); - frame_n_deframe(handler, payload, payload_length, 1, 1); - destroy_frame_handler(handler); -} - -static void frame_handler_test_null_input_stream() { - frame_handler* handler = create_frame_handler(); - GPR_ASSERT(!alts_reset_frame_writer(handler->writer, nullptr, 0)); - destroy_frame_handler(handler); -} - -static void frame_handler_test_bad_input_length() { - unsigned char payload[] = "hello world"; - frame_handler* handler = create_frame_handler(); - GPR_ASSERT(!alts_reset_frame_writer(handler->writer, payload, SIZE_MAX)); - destroy_frame_handler(handler); -} - -static void frame_handler_test_null_writer_byte_length() { - unsigned char payload[] = "hello world"; - size_t payload_length = strlen(reinterpret_cast(payload)) + 1; - frame_handler* handler = create_frame_handler(); - GPR_ASSERT(alts_reset_frame_writer(handler->writer, payload, payload_length)); - GPR_ASSERT( - !alts_write_frame_bytes(handler->writer, handler->buffer, nullptr)); - destroy_frame_handler(handler); -} - -static void frame_handler_test_null_writer_bytes() { - unsigned char payload[] = "hello world"; - size_t payload_length = strlen(reinterpret_cast(payload)) + 1; - frame_handler* handler = create_frame_handler(); - GPR_ASSERT(alts_reset_frame_writer(handler->writer, payload, payload_length)); - GPR_ASSERT( - !alts_write_frame_bytes(handler->writer, nullptr, &payload_length)); - destroy_frame_handler(handler); -} - -static void frame_handler_test_bad_frame_length() { - unsigned char payload[] = "hello world"; - size_t payload_length = strlen(reinterpret_cast(payload)) + 1; - frame_handler* handler = create_frame_handler(); - frame(handler, payload, payload_length, payload_length); - memset(handler->buffer, 0x00, kFrameLengthFieldSize); - unsigned char* bytes = - static_cast(gpr_malloc(kFrameHandlerTestBufferSize)); - GPR_ASSERT(alts_reset_frame_reader(handler->reader, bytes)); - size_t bytes_read = handler->buffer_size; - GPR_ASSERT( - !alts_read_frame_bytes(handler->reader, handler->buffer, &bytes_read)); - GPR_ASSERT(alts_is_frame_reader_done(handler->reader)); - GPR_ASSERT(bytes_read == 0); - gpr_free(bytes); - destroy_frame_handler(handler); -} - -static void frame_handler_test_unsupported_message_type() { - unsigned char payload[] = "hello world"; - size_t payload_length = strlen(reinterpret_cast(payload)) + 1; - frame_handler* handler = create_frame_handler(); - frame(handler, payload, payload_length, payload_length); - memset(handler->buffer + kFrameLengthFieldSize, 0x00, - kFrameMessageTypeFieldSize); - unsigned char* bytes = - static_cast(gpr_malloc(kFrameHandlerTestBufferSize)); - GPR_ASSERT(alts_reset_frame_reader(handler->reader, bytes)); - size_t bytes_read = handler->buffer_size; - GPR_ASSERT( - !alts_read_frame_bytes(handler->reader, handler->buffer, &bytes_read)); - GPR_ASSERT(alts_is_frame_reader_done(handler->reader)); - GPR_ASSERT(bytes_read == 0); - gpr_free(bytes); - destroy_frame_handler(handler); -} - -static void frame_handler_test_null_output_stream() { - unsigned char payload[] = "hello world"; - size_t payload_length = strlen(reinterpret_cast(payload)) + 1; - frame_handler* handler = create_frame_handler(); - frame(handler, payload, payload_length, payload_length); - GPR_ASSERT(!alts_reset_frame_reader(handler->reader, nullptr)); - destroy_frame_handler(handler); -} - -static void frame_handler_test_null_reader_byte_length() { - unsigned char payload[] = "hello world"; - size_t payload_length = strlen(reinterpret_cast(payload)) + 1; - frame_handler* handler = create_frame_handler(); - frame(handler, payload, payload_length, payload_length); - unsigned char* bytes = - static_cast(gpr_malloc(kFrameHandlerTestBufferSize)); - GPR_ASSERT(alts_reset_frame_reader(handler->reader, bytes)); - GPR_ASSERT(!alts_read_frame_bytes(handler->reader, handler->buffer, nullptr)); - gpr_free(bytes); - destroy_frame_handler(handler); -} - -static void frame_handler_test_null_reader_bytes() { - unsigned char payload[] = "hello world"; - size_t payload_length = strlen(reinterpret_cast(payload)) + 1; - frame_handler* handler = create_frame_handler(); - frame(handler, payload, payload_length, payload_length); - unsigned char* bytes = - static_cast(gpr_malloc(kFrameHandlerTestBufferSize)); - GPR_ASSERT(alts_reset_frame_reader(handler->reader, bytes)); - size_t bytes_read = handler->buffer_size; - GPR_ASSERT(!alts_read_frame_bytes(handler->reader, nullptr, &bytes_read)); - gpr_free(bytes); - destroy_frame_handler(handler); -} - -int main(int argc, char** argv) { - frame_handler_test_frame_deframe(); - frame_handler_test_small_buffer(); - frame_handler_test_null_input_stream(); - frame_handler_test_bad_input_length(); - frame_handler_test_null_writer_byte_length(); - frame_handler_test_null_writer_bytes(); - frame_handler_test_bad_frame_length(); - frame_handler_test_unsupported_message_type(); - frame_handler_test_null_output_stream(); - frame_handler_test_null_reader_byte_length(); - frame_handler_test_null_reader_bytes(); - return 0; -} diff --git a/test/core/tsi/alts/handshaker/BUILD b/test/core/tsi/alts/handshaker/BUILD deleted file mode 100644 index db39732c43..0000000000 --- a/test/core/tsi/alts/handshaker/BUILD +++ /dev/null @@ -1,78 +0,0 @@ -# Copyright 2018 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_package") - -licenses(["notice"]) # Apache v2 - -grpc_package(name = "handshaker") - -grpc_cc_library( - name = "alts_handshaker_service_api_test_lib", - srcs = ["alts_handshaker_service_api_test_lib.cc"], - hdrs = ["alts_handshaker_service_api_test_lib.h"], - deps = [ - "//:grpc", - ], -) - -grpc_cc_test( - name = "alts_handshaker_client_test", - srcs = ["alts_handshaker_client_test.cc"], - language = "C++", - deps = [ - ":alts_handshaker_service_api_test_lib", - "//:grpc", - ], -) - -grpc_cc_test( - name = "alts_handshaker_service_api_test", - srcs = ["alts_handshaker_service_api_test.cc"], - language = "C++", - deps = [ - ":alts_handshaker_service_api_test_lib", - "//:grpc", - ], -) - -grpc_cc_test( - name = "alts_tsi_handshaker_test", - srcs = ["alts_tsi_handshaker_test.cc"], - language = "C++", - deps = [ - ":alts_handshaker_service_api_test_lib", - "//:grpc", - ], -) - -grpc_cc_test( - name = "alts_tsi_utils_test", - srcs = ["alts_tsi_utils_test.cc"], - language = "C++", - deps = [ - ":alts_handshaker_service_api_test_lib", - "//:grpc", - ], -) - -grpc_cc_test( - name = "transport_security_common_api_test", - srcs = ["transport_security_common_api_test.cc"], - language = "C++", - deps = [ - "//:grpc", - ], -) - diff --git a/test/core/tsi/alts/handshaker/alts_handshaker_client_test.cc b/test/core/tsi/alts/handshaker/alts_handshaker_client_test.cc deleted file mode 100644 index 7072be6e3a..0000000000 --- a/test/core/tsi/alts/handshaker/alts_handshaker_client_test.cc +++ /dev/null @@ -1,412 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/tsi/alts/handshaker/alts_handshaker_client.h" -#include "src/core/tsi/alts/handshaker/alts_tsi_event.h" -#include "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h" -#include "src/core/tsi/transport_security.h" -#include "src/core/tsi/transport_security_interface.h" -#include "test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h" - -#define ALTS_HANDSHAKER_CLIENT_TEST_OUT_FRAME "Hello Google" -#define ALTS_HANDSHAKER_CLIENT_TEST_HANDSHAKER_SERVICE_URL "lame" -#define ALTS_HANDSHAKER_CLIENT_TEST_TARGET_NAME "bigtable.google.api.com" -#define ALTS_HANDSHAKER_CLIENT_TEST_TARGET_SERVICE_ACCOUNT1 "A@google.com" -#define ALTS_HANDSHAKER_CLIENT_TEST_TARGET_SERVICE_ACCOUNT2 "B@google.com" - -const size_t kHandshakerClientOpNum = 4; -const size_t kMaxRpcVersionMajor = 3; -const size_t kMaxRpcVersionMinor = 2; -const size_t kMinRpcVersionMajor = 2; -const size_t kMinRpcVersionMinor = 1; - -using grpc_core::internal::alts_handshaker_client_set_grpc_caller_for_testing; - -typedef struct alts_handshaker_client_test_config { - grpc_channel* channel; - grpc_completion_queue* cq; - alts_handshaker_client* client; - grpc_slice out_frame; -} alts_handshaker_client_test_config; - -static alts_tsi_event* alts_tsi_event_create_for_testing(bool is_client) { - alts_tsi_event* e = static_cast(gpr_zalloc(sizeof(*e))); - grpc_metadata_array_init(&e->initial_metadata); - grpc_metadata_array_init(&e->trailing_metadata); - e->options = is_client ? grpc_alts_credentials_client_options_create() - : grpc_alts_credentials_server_options_create(); - if (is_client) { - grpc_alts_credentials_client_options_add_target_service_account( - reinterpret_cast(e->options), - ALTS_HANDSHAKER_CLIENT_TEST_TARGET_SERVICE_ACCOUNT1); - grpc_alts_credentials_client_options_add_target_service_account( - reinterpret_cast(e->options), - ALTS_HANDSHAKER_CLIENT_TEST_TARGET_SERVICE_ACCOUNT2); - } - grpc_gcp_rpc_protocol_versions* versions = &e->options->rpc_versions; - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_max( - versions, kMaxRpcVersionMajor, kMaxRpcVersionMinor)); - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_min( - versions, kMinRpcVersionMajor, kMinRpcVersionMinor)); - e->target_name = - grpc_slice_from_static_string(ALTS_HANDSHAKER_CLIENT_TEST_TARGET_NAME); - return e; -} - -static void validate_rpc_protocol_versions( - grpc_gcp_rpc_protocol_versions* versions) { - GPR_ASSERT(versions != nullptr); - GPR_ASSERT(versions->max_rpc_version.major == kMaxRpcVersionMajor); - GPR_ASSERT(versions->max_rpc_version.minor == kMaxRpcVersionMinor); - GPR_ASSERT(versions->min_rpc_version.major == kMinRpcVersionMajor); - GPR_ASSERT(versions->min_rpc_version.minor == kMinRpcVersionMinor); -} - -static void validate_target_identities( - const repeated_field* target_identity_head) { - grpc_gcp_identity* target_identity1 = static_cast( - const_cast(target_identity_head->next->data)); - grpc_gcp_identity* target_identity2 = static_cast( - const_cast(target_identity_head->data)); - grpc_slice* service_account1 = - static_cast(target_identity1->service_account.arg); - grpc_slice* service_account2 = - static_cast(target_identity2->service_account.arg); - GPR_ASSERT(memcmp(GRPC_SLICE_START_PTR(*service_account1), - ALTS_HANDSHAKER_CLIENT_TEST_TARGET_SERVICE_ACCOUNT1, - GRPC_SLICE_LENGTH(*service_account1)) == 0); - GPR_ASSERT(strlen(ALTS_HANDSHAKER_CLIENT_TEST_TARGET_SERVICE_ACCOUNT1) == - GRPC_SLICE_LENGTH(*service_account1)); - GPR_ASSERT(memcmp(GRPC_SLICE_START_PTR(*service_account2), - ALTS_HANDSHAKER_CLIENT_TEST_TARGET_SERVICE_ACCOUNT2, - GRPC_SLICE_LENGTH(*service_account2)) == 0); - GPR_ASSERT(strlen(ALTS_HANDSHAKER_CLIENT_TEST_TARGET_SERVICE_ACCOUNT2) == - GRPC_SLICE_LENGTH(*service_account2)); -} - -/** - * Validate if grpc operation data is correctly populated with the fields of - * ALTS TSI event. - */ -static bool validate_op(alts_tsi_event* event, const grpc_op* op, size_t nops, - bool is_start) { - GPR_ASSERT(event != nullptr && op != nullptr && nops != 0); - bool ok = true; - grpc_op* start_op = const_cast(op); - if (is_start) { - ok &= (op->op == GRPC_OP_SEND_INITIAL_METADATA); - ok &= (op->data.send_initial_metadata.count == 0); - op++; - GPR_ASSERT((size_t)(op - start_op) <= kHandshakerClientOpNum); - - ok &= (op->op == GRPC_OP_RECV_INITIAL_METADATA); - ok &= (op->data.recv_initial_metadata.recv_initial_metadata == - &event->initial_metadata); - op++; - GPR_ASSERT((size_t)(op - start_op) <= kHandshakerClientOpNum); - } - ok &= (op->op == GRPC_OP_SEND_MESSAGE); - ok &= (op->data.send_message.send_message == event->send_buffer); - op++; - GPR_ASSERT((size_t)(op - start_op) <= kHandshakerClientOpNum); - - ok &= (op->op == GRPC_OP_RECV_MESSAGE); - ok &= (op->data.recv_message.recv_message == &event->recv_buffer); - op++; - GPR_ASSERT((size_t)(op - start_op) <= kHandshakerClientOpNum); - - return ok; -} - -static grpc_gcp_handshaker_req* deserialize_handshaker_req( - grpc_gcp_handshaker_req_type type, grpc_byte_buffer* buffer) { - GPR_ASSERT(buffer != nullptr); - grpc_gcp_handshaker_req* req = grpc_gcp_handshaker_decoded_req_create(type); - grpc_byte_buffer_reader bbr; - GPR_ASSERT(grpc_byte_buffer_reader_init(&bbr, buffer)); - grpc_slice slice = grpc_byte_buffer_reader_readall(&bbr); - GPR_ASSERT(grpc_gcp_handshaker_req_decode(slice, req)); - grpc_slice_unref(slice); - grpc_byte_buffer_reader_destroy(&bbr); - return req; -} - -/** - * A mock grpc_caller used to check if client_start, server_start, and next - * operations correctly handle invalid arguments. It should not be called. - */ -static grpc_call_error check_must_not_be_called(grpc_call* call, - const grpc_op* ops, size_t nops, - void* tag) { - GPR_ASSERT(0); -} - -/** - * A mock grpc_caller used to check correct execution of client_start operation. - * It checks if the client_start handshaker request is populated with correct - * handshake_security_protocol, application_protocol, and record_protocol, and - * op is correctly populated. - */ -static grpc_call_error check_client_start_success(grpc_call* call, - const grpc_op* op, - size_t nops, void* tag) { - alts_tsi_event* event = static_cast(tag); - grpc_gcp_handshaker_req* req = - deserialize_handshaker_req(CLIENT_START_REQ, event->send_buffer); - GPR_ASSERT(req->client_start.handshake_security_protocol == - grpc_gcp_HandshakeProtocol_ALTS); - const void* data = (static_cast( - req->client_start.application_protocols.arg)) - ->data; - GPR_ASSERT(data != nullptr); - grpc_slice* application_protocol = (grpc_slice*)data; - data = (static_cast(req->client_start.record_protocols.arg)) - ->data; - grpc_slice* record_protocol = (grpc_slice*)data; - GPR_ASSERT(memcmp(GRPC_SLICE_START_PTR(*application_protocol), - ALTS_APPLICATION_PROTOCOL, - GRPC_SLICE_LENGTH(*application_protocol)) == 0); - GPR_ASSERT(memcmp(GRPC_SLICE_START_PTR(*record_protocol), - ALTS_RECORD_PROTOCOL, - GRPC_SLICE_LENGTH(*record_protocol)) == 0); - validate_rpc_protocol_versions(&req->client_start.rpc_versions); - validate_target_identities( - static_cast(req->client_start.target_identities.arg)); - grpc_slice* target_name = - static_cast(req->client_start.target_name.arg); - GPR_ASSERT(memcmp(GRPC_SLICE_START_PTR(*target_name), - ALTS_HANDSHAKER_CLIENT_TEST_TARGET_NAME, - GRPC_SLICE_LENGTH(*target_name)) == 0); - GPR_ASSERT(GRPC_SLICE_LENGTH(*target_name) == - strlen(ALTS_HANDSHAKER_CLIENT_TEST_TARGET_NAME)); - GPR_ASSERT(validate_op(event, op, nops, true /* is_start */)); - grpc_gcp_handshaker_req_destroy(req); - return GRPC_CALL_OK; -} - -/** - * A mock grpc_caller used to check correct execution of server_start operation. - * It checks if the server_start handshaker request is populated with correct - * handshake_security_protocol, application_protocol, and record_protocol, and - * op is correctly populated. - */ -static grpc_call_error check_server_start_success(grpc_call* call, - const grpc_op* op, - size_t nops, void* tag) { - alts_tsi_event* event = static_cast(tag); - grpc_gcp_handshaker_req* req = - deserialize_handshaker_req(SERVER_START_REQ, event->send_buffer); - const void* data = (static_cast( - req->server_start.application_protocols.arg)) - ->data; - GPR_ASSERT(data != nullptr); - grpc_slice* application_protocol = (grpc_slice*)data; - GPR_ASSERT(memcmp(GRPC_SLICE_START_PTR(*application_protocol), - ALTS_APPLICATION_PROTOCOL, - GRPC_SLICE_LENGTH(*application_protocol)) == 0); - GPR_ASSERT(req->server_start.handshake_parameters_count == 1); - GPR_ASSERT(req->server_start.handshake_parameters[0].key == - grpc_gcp_HandshakeProtocol_ALTS); - data = (static_cast(req->server_start.handshake_parameters[0] - .value.record_protocols.arg)) - ->data; - GPR_ASSERT(data != nullptr); - grpc_slice* record_protocol = (grpc_slice*)data; - GPR_ASSERT(memcmp(GRPC_SLICE_START_PTR(*record_protocol), - ALTS_RECORD_PROTOCOL, - GRPC_SLICE_LENGTH(*record_protocol)) == 0); - validate_rpc_protocol_versions(&req->server_start.rpc_versions); - GPR_ASSERT(validate_op(event, op, nops, true /* is_start */)); - grpc_gcp_handshaker_req_destroy(req); - return GRPC_CALL_OK; -} - -/** - * A mock grpc_caller used to check correct execution of next operation. It - * checks if the next handshaker request is populated with correct information, - * and op is correctly populated. - */ -static grpc_call_error check_next_success(grpc_call* call, const grpc_op* op, - size_t nops, void* tag) { - alts_tsi_event* event = static_cast(tag); - grpc_gcp_handshaker_req* req = - deserialize_handshaker_req(NEXT_REQ, event->send_buffer); - grpc_slice* in_bytes = static_cast(req->next.in_bytes.arg); - GPR_ASSERT(in_bytes != nullptr); - GPR_ASSERT(memcmp(GRPC_SLICE_START_PTR(*in_bytes), - ALTS_HANDSHAKER_CLIENT_TEST_OUT_FRAME, - GRPC_SLICE_LENGTH(*in_bytes)) == 0); - GPR_ASSERT(validate_op(event, op, nops, false /* is_start */)); - grpc_gcp_handshaker_req_destroy(req); - return GRPC_CALL_OK; -} -/** - * A mock grpc_caller used to check if client_start, server_start, and next - * operations correctly handle the situation when the grpc call made to the - * handshaker service fails. - */ -static grpc_call_error check_grpc_call_failure(grpc_call* call, - const grpc_op* op, size_t nops, - void* tag) { - return GRPC_CALL_ERROR; -} - -static alts_handshaker_client_test_config* create_config() { - alts_handshaker_client_test_config* config = - static_cast( - gpr_zalloc(sizeof(*config))); - config->channel = grpc_insecure_channel_create( - ALTS_HANDSHAKER_CLIENT_TEST_HANDSHAKER_SERVICE_URL, nullptr, nullptr); - config->cq = grpc_completion_queue_create_for_next(nullptr); - config->client = alts_grpc_handshaker_client_create( - config->channel, config->cq, - ALTS_HANDSHAKER_CLIENT_TEST_HANDSHAKER_SERVICE_URL); - GPR_ASSERT(config->client != nullptr); - config->out_frame = - grpc_slice_from_static_string(ALTS_HANDSHAKER_CLIENT_TEST_OUT_FRAME); - return config; -} - -static void destroy_config(alts_handshaker_client_test_config* config) { - if (config == nullptr) { - return; - } - grpc_completion_queue_destroy(config->cq); - grpc_channel_destroy(config->channel); - alts_handshaker_client_destroy(config->client); - grpc_slice_unref(config->out_frame); - gpr_free(config); -} - -static void schedule_request_invalid_arg_test() { - /* Initialization. */ - alts_handshaker_client_test_config* config = create_config(); - alts_tsi_event* event = nullptr; - - /* Tests. */ - alts_handshaker_client_set_grpc_caller_for_testing(config->client, - check_must_not_be_called); - event = alts_tsi_event_create_for_testing(true /* is_client */); - /* Check client_start. */ - GPR_ASSERT(alts_handshaker_client_start_client(nullptr, event) == - TSI_INVALID_ARGUMENT); - GPR_ASSERT(alts_handshaker_client_start_client(config->client, nullptr) == - TSI_INVALID_ARGUMENT); - - /* Check server_start. */ - GPR_ASSERT(alts_handshaker_client_start_server( - config->client, event, nullptr) == TSI_INVALID_ARGUMENT); - GPR_ASSERT(alts_handshaker_client_start_server(config->client, nullptr, - &config->out_frame) == - TSI_INVALID_ARGUMENT); - GPR_ASSERT(alts_handshaker_client_start_server( - nullptr, event, &config->out_frame) == TSI_INVALID_ARGUMENT); - - /* Check next. */ - GPR_ASSERT(alts_handshaker_client_next(config->client, event, nullptr) == - TSI_INVALID_ARGUMENT); - GPR_ASSERT(alts_handshaker_client_next(config->client, nullptr, - &config->out_frame) == - TSI_INVALID_ARGUMENT); - GPR_ASSERT(alts_handshaker_client_next(nullptr, event, &config->out_frame) == - TSI_INVALID_ARGUMENT); - - /* Cleanup. */ - alts_tsi_event_destroy(event); - destroy_config(config); -} - -static void schedule_request_success_test() { - /* Initialization. */ - alts_handshaker_client_test_config* config = create_config(); - alts_tsi_event* event = nullptr; - - /* Check client_start success. */ - alts_handshaker_client_set_grpc_caller_for_testing( - config->client, check_client_start_success); - event = alts_tsi_event_create_for_testing(true /* is_client. */); - GPR_ASSERT(alts_handshaker_client_start_client(config->client, event) == - TSI_OK); - alts_tsi_event_destroy(event); - - /* Check server_start success. */ - alts_handshaker_client_set_grpc_caller_for_testing( - config->client, check_server_start_success); - event = alts_tsi_event_create_for_testing(false /* is_client. */); - GPR_ASSERT(alts_handshaker_client_start_server(config->client, event, - &config->out_frame) == TSI_OK); - alts_tsi_event_destroy(event); - - /* Check next success. */ - alts_handshaker_client_set_grpc_caller_for_testing(config->client, - check_next_success); - event = alts_tsi_event_create_for_testing(true /* is_client. */); - GPR_ASSERT(alts_handshaker_client_next(config->client, event, - &config->out_frame) == TSI_OK); - alts_tsi_event_destroy(event); - - /* Cleanup. */ - destroy_config(config); -} - -static void schedule_request_grpc_call_failure_test() { - /* Initialization. */ - alts_handshaker_client_test_config* config = create_config(); - alts_tsi_event* event = nullptr; - - /* Check client_start failure. */ - alts_handshaker_client_set_grpc_caller_for_testing(config->client, - check_grpc_call_failure); - event = alts_tsi_event_create_for_testing(true /* is_client. */); - GPR_ASSERT(alts_handshaker_client_start_client(config->client, event) == - TSI_INTERNAL_ERROR); - alts_tsi_event_destroy(event); - - /* Check server_start failure. */ - event = alts_tsi_event_create_for_testing(false /* is_client. */); - GPR_ASSERT(alts_handshaker_client_start_server(config->client, event, - &config->out_frame) == - TSI_INTERNAL_ERROR); - alts_tsi_event_destroy(event); - - /* Check next failure. */ - event = alts_tsi_event_create_for_testing(true /* is_cleint. */); - GPR_ASSERT( - alts_handshaker_client_next(config->client, event, &config->out_frame) == - TSI_INTERNAL_ERROR); - alts_tsi_event_destroy(event); - - /* Cleanup. */ - destroy_config(config); -} - -int main(int argc, char** argv) { - /* Initialization. */ - grpc_init(); - - /* Tests. */ - schedule_request_invalid_arg_test(); - schedule_request_success_test(); - schedule_request_grpc_call_failure_test(); - - /* Cleanup. */ - grpc_shutdown(); - return 0; -} diff --git a/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test.cc b/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test.cc deleted file mode 100644 index 3506264f52..0000000000 --- a/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test.cc +++ /dev/null @@ -1,149 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include - -#include "test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h" - -int main(int argc, char** argv) { - const char in_bytes[] = "HELLO GOOGLE!"; - const char out_frames[] = "HELLO WORLD!"; - const char key_data[] = "THIS IS KEY DATA."; - const char details[] = "DETAILS NEED TO BE POPULATED"; - const uint32_t max_rpc_version_major = 3; - const uint32_t max_rpc_version_minor = 2; - const uint32_t min_rpc_version_major = 2; - const uint32_t min_rpc_version_minor = 1; - - /* handshaker_req_next. */ - grpc_gcp_handshaker_req* req = grpc_gcp_handshaker_req_create(NEXT_REQ); - grpc_gcp_handshaker_req* decoded_req = - grpc_gcp_handshaker_decoded_req_create(NEXT_REQ); - GPR_ASSERT( - grpc_gcp_handshaker_req_set_in_bytes(req, in_bytes, strlen(in_bytes))); - grpc_slice encoded_req; - GPR_ASSERT(grpc_gcp_handshaker_req_encode(req, &encoded_req)); - GPR_ASSERT(grpc_gcp_handshaker_req_decode(encoded_req, decoded_req)); - GPR_ASSERT(grpc_gcp_handshaker_req_equals(req, decoded_req)); - grpc_gcp_handshaker_req_destroy(req); - grpc_gcp_handshaker_req_destroy(decoded_req); - grpc_slice_unref(encoded_req); - - /* handshaker_req_client_start. */ - req = grpc_gcp_handshaker_req_create(CLIENT_START_REQ); - decoded_req = grpc_gcp_handshaker_decoded_req_create(CLIENT_START_REQ); - GPR_ASSERT(grpc_gcp_handshaker_req_set_handshake_protocol( - req, grpc_gcp_HandshakeProtocol_TLS)); - GPR_ASSERT(grpc_gcp_handshaker_req_set_local_identity_hostname( - req, "www.google.com")); - GPR_ASSERT(grpc_gcp_handshaker_req_set_local_endpoint( - req, "2001:db8::8:800:200C:417a", 9876, grpc_gcp_NetworkProtocol_TCP)); - GPR_ASSERT(grpc_gcp_handshaker_req_set_remote_endpoint( - req, "2001:db8::bac5::fed0:84a2", 1234, grpc_gcp_NetworkProtocol_TCP)); - GPR_ASSERT(grpc_gcp_handshaker_req_add_application_protocol(req, "grpc")); - GPR_ASSERT(grpc_gcp_handshaker_req_add_application_protocol(req, "http2")); - GPR_ASSERT( - grpc_gcp_handshaker_req_add_record_protocol(req, "ALTSRP_GCM_AES256")); - GPR_ASSERT( - grpc_gcp_handshaker_req_add_record_protocol(req, "ALTSRP_GCM_AES384")); - GPR_ASSERT(grpc_gcp_handshaker_req_add_target_identity_service_account( - req, "foo@google.com")); - GPR_ASSERT(grpc_gcp_handshaker_req_set_target_name( - req, "google.example.library.service")); - GPR_ASSERT(grpc_gcp_handshaker_req_set_rpc_versions( - req, max_rpc_version_major, max_rpc_version_minor, min_rpc_version_major, - min_rpc_version_minor)); - GPR_ASSERT(grpc_gcp_handshaker_req_encode(req, &encoded_req)); - GPR_ASSERT(grpc_gcp_handshaker_req_decode(encoded_req, decoded_req)); - GPR_ASSERT(grpc_gcp_handshaker_req_equals(req, decoded_req)); - grpc_gcp_handshaker_req_destroy(req); - grpc_gcp_handshaker_req_destroy(decoded_req); - grpc_slice_unref(encoded_req); - - /* handshaker_req_server_start. */ - req = grpc_gcp_handshaker_req_create(SERVER_START_REQ); - decoded_req = grpc_gcp_handshaker_decoded_req_create(SERVER_START_REQ); - GPR_ASSERT(grpc_gcp_handshaker_req_add_application_protocol(req, "grpc")); - GPR_ASSERT(grpc_gcp_handshaker_req_add_application_protocol(req, "http2")); - GPR_ASSERT(grpc_gcp_handshaker_req_set_local_endpoint( - req, "2001:db8::8:800:200C:417a", 9876, grpc_gcp_NetworkProtocol_TCP)); - GPR_ASSERT(grpc_gcp_handshaker_req_set_remote_endpoint( - req, "2001:db8::bac5::fed0:84a2", 1234, grpc_gcp_NetworkProtocol_UDP)); - GPR_ASSERT( - grpc_gcp_handshaker_req_set_in_bytes(req, in_bytes, strlen(in_bytes))); - GPR_ASSERT(grpc_gcp_handshaker_req_param_add_record_protocol( - req, grpc_gcp_HandshakeProtocol_TLS, "ALTSRP_GCM_AES128")); - GPR_ASSERT(grpc_gcp_handshaker_req_param_add_local_identity_service_account( - req, grpc_gcp_HandshakeProtocol_TLS, "foo@google.com")); - GPR_ASSERT(grpc_gcp_handshaker_req_param_add_local_identity_hostname( - req, grpc_gcp_HandshakeProtocol_TLS, "yihuaz0.mtv.corp.google.com")); - GPR_ASSERT(grpc_gcp_handshaker_req_param_add_record_protocol( - req, grpc_gcp_HandshakeProtocol_ALTS, "ALTSRP_GCM_AES128")); - GPR_ASSERT(grpc_gcp_handshaker_req_param_add_local_identity_hostname( - req, grpc_gcp_HandshakeProtocol_ALTS, "www.amazon.com")); - GPR_ASSERT(grpc_gcp_handshaker_req_set_rpc_versions( - req, max_rpc_version_major, max_rpc_version_minor, min_rpc_version_major, - min_rpc_version_minor)); - - GPR_ASSERT(grpc_gcp_handshaker_req_encode(req, &encoded_req)); - GPR_ASSERT(grpc_gcp_handshaker_req_decode(encoded_req, decoded_req)); - GPR_ASSERT(grpc_gcp_handshaker_req_equals(req, decoded_req)); - grpc_gcp_handshaker_req_destroy(req); - grpc_gcp_handshaker_req_destroy(decoded_req); - grpc_slice_unref(encoded_req); - - /* handshaker_resp. */ - grpc_gcp_handshaker_resp* resp = grpc_gcp_handshaker_resp_create(); - grpc_gcp_handshaker_resp* decoded_resp = grpc_gcp_handshaker_resp_create(); - GPR_ASSERT(grpc_gcp_handshaker_resp_set_out_frames(resp, out_frames, - strlen(out_frames))); - GPR_ASSERT(grpc_gcp_handshaker_resp_set_bytes_consumed(resp, 1024)); - GPR_ASSERT(grpc_gcp_handshaker_resp_set_application_protocol(resp, "http")); - GPR_ASSERT( - grpc_gcp_handshaker_resp_set_record_protocol(resp, "ALTSRP_GCM_AES128")); - GPR_ASSERT( - grpc_gcp_handshaker_resp_set_key_data(resp, key_data, strlen(key_data))); - GPR_ASSERT(grpc_gcp_handshaker_resp_set_local_identity_hostname( - resp, "www.faceboook.com")); - GPR_ASSERT(grpc_gcp_handshaker_resp_set_peer_identity_hostname( - resp, "www.amazon.com")); - GPR_ASSERT(grpc_gcp_handshaker_resp_set_channel_open( - resp, false /* channel_open */)); - GPR_ASSERT(grpc_gcp_handshaker_resp_set_code(resp, 1023)); - GPR_ASSERT(grpc_gcp_handshaker_resp_set_details(resp, details)); - GPR_ASSERT(grpc_gcp_handshaker_resp_set_peer_rpc_versions( - resp, max_rpc_version_major, max_rpc_version_minor, min_rpc_version_major, - min_rpc_version_minor)); - grpc_slice encoded_resp; - GPR_ASSERT(grpc_gcp_handshaker_resp_encode(resp, &encoded_resp)); - GPR_ASSERT(grpc_gcp_handshaker_resp_decode(encoded_resp, decoded_resp)); - GPR_ASSERT(grpc_gcp_handshaker_resp_equals(resp, decoded_resp)); - grpc_gcp_handshaker_resp_destroy(resp); - grpc_gcp_handshaker_resp_destroy(decoded_resp); - grpc_slice_unref(encoded_resp); - /* Test invalid arguments. */ - GPR_ASSERT(!grpc_gcp_handshaker_req_set_in_bytes(nullptr, in_bytes, - strlen(in_bytes))); - GPR_ASSERT(!grpc_gcp_handshaker_req_param_add_record_protocol( - req, grpc_gcp_HandshakeProtocol_TLS, nullptr)); - GPR_ASSERT(!grpc_gcp_handshaker_req_param_add_local_identity_service_account( - nullptr, grpc_gcp_HandshakeProtocol_TLS, nullptr)); - GPR_ASSERT(!grpc_gcp_handshaker_resp_set_record_protocol(nullptr, nullptr)); -} diff --git a/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc b/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc deleted file mode 100644 index ecca04defa..0000000000 --- a/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc +++ /dev/null @@ -1,642 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h" - -const size_t kHandshakeProtocolNum = 3; - -grpc_gcp_handshaker_req* grpc_gcp_handshaker_decoded_req_create( - grpc_gcp_handshaker_req_type type) { - grpc_gcp_handshaker_req* req = - static_cast(gpr_zalloc(sizeof(*req))); - switch (type) { - case CLIENT_START_REQ: - req->has_client_start = true; - req->client_start.target_identities.funcs.decode = - decode_repeated_identity_cb; - req->client_start.application_protocols.funcs.decode = - decode_repeated_string_cb; - req->client_start.record_protocols.funcs.decode = - decode_repeated_string_cb; - req->client_start.local_identity.hostname.funcs.decode = - decode_string_or_bytes_cb; - req->client_start.local_identity.service_account.funcs.decode = - decode_string_or_bytes_cb; - req->client_start.local_endpoint.ip_address.funcs.decode = - decode_string_or_bytes_cb; - req->client_start.remote_endpoint.ip_address.funcs.decode = - decode_string_or_bytes_cb; - req->client_start.target_name.funcs.decode = decode_string_or_bytes_cb; - break; - case SERVER_START_REQ: - req->has_server_start = true; - req->server_start.application_protocols.funcs.decode = - &decode_repeated_string_cb; - for (size_t i = 0; i < kHandshakeProtocolNum; i++) { - req->server_start.handshake_parameters[i] - .value.local_identities.funcs.decode = &decode_repeated_identity_cb; - req->server_start.handshake_parameters[i] - .value.record_protocols.funcs.decode = &decode_repeated_string_cb; - } - req->server_start.in_bytes.funcs.decode = decode_string_or_bytes_cb; - req->server_start.local_endpoint.ip_address.funcs.decode = - decode_string_or_bytes_cb; - req->server_start.remote_endpoint.ip_address.funcs.decode = - decode_string_or_bytes_cb; - break; - case NEXT_REQ: - req->has_next = true; - break; - } - return req; -} - -bool grpc_gcp_handshaker_resp_set_application_protocol( - grpc_gcp_handshaker_resp* resp, const char* application_protocol) { - if (resp == nullptr || application_protocol == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr arguments to " - "handshaker_resp_set_application_protocol()."); - return false; - } - resp->has_result = true; - grpc_slice* slice = - create_slice(application_protocol, strlen(application_protocol)); - resp->result.application_protocol.arg = slice; - resp->result.application_protocol.funcs.encode = encode_string_or_bytes_cb; - return true; -} - -bool grpc_gcp_handshaker_resp_set_record_protocol( - grpc_gcp_handshaker_resp* resp, const char* record_protocol) { - if (resp == nullptr || record_protocol == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr arguments to " - "handshaker_resp_set_record_protocol()."); - return false; - } - resp->has_result = true; - grpc_slice* slice = create_slice(record_protocol, strlen(record_protocol)); - resp->result.record_protocol.arg = slice; - resp->result.record_protocol.funcs.encode = encode_string_or_bytes_cb; - return true; -} - -bool grpc_gcp_handshaker_resp_set_key_data(grpc_gcp_handshaker_resp* resp, - const char* key_data, size_t size) { - if (resp == nullptr || key_data == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr arguments to handshaker_resp_set_key_data()."); - return false; - } - resp->has_result = true; - grpc_slice* slice = create_slice(key_data, size); - resp->result.key_data.arg = slice; - resp->result.key_data.funcs.encode = encode_string_or_bytes_cb; - return true; -} - -static void set_identity_hostname(grpc_gcp_identity* identity, - const char* hostname) { - grpc_slice* slice = create_slice(hostname, strlen(hostname)); - identity->hostname.arg = slice; - identity->hostname.funcs.encode = encode_string_or_bytes_cb; -} - -static void set_identity_service_account(grpc_gcp_identity* identity, - const char* service_account) { - grpc_slice* slice = create_slice(service_account, strlen(service_account)); - identity->service_account.arg = slice; - identity->service_account.funcs.encode = encode_string_or_bytes_cb; -} - -bool grpc_gcp_handshaker_resp_set_local_identity_hostname( - grpc_gcp_handshaker_resp* resp, const char* hostname) { - if (resp == nullptr || hostname == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr arguments to " - "grpc_gcp_handshaker_resp_set_local_identity_hostname()."); - return false; - } - resp->has_result = true; - resp->result.has_local_identity = true; - set_identity_hostname(&resp->result.local_identity, hostname); - return true; -} - -bool grpc_gcp_handshaker_resp_set_local_identity_service_account( - grpc_gcp_handshaker_resp* resp, const char* service_account) { - if (resp == nullptr || service_account == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr arguments to " - "grpc_gcp_handshaker_resp_set_local_identity_service_account()."); - return false; - } - resp->has_result = true; - resp->result.has_local_identity = true; - set_identity_service_account(&resp->result.local_identity, service_account); - return true; -} - -bool grpc_gcp_handshaker_resp_set_peer_identity_hostname( - grpc_gcp_handshaker_resp* resp, const char* hostname) { - if (resp == nullptr || hostname == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr arguments to " - "grpc_gcp_handshaker_resp_set_peer_identity_hostname()."); - return false; - } - resp->has_result = true; - resp->result.has_peer_identity = true; - set_identity_hostname(&resp->result.peer_identity, hostname); - return true; -} - -bool grpc_gcp_handshaker_resp_set_peer_identity_service_account( - grpc_gcp_handshaker_resp* resp, const char* service_account) { - if (resp == nullptr || service_account == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr arguments to " - "grpc_gcp_handshaker_resp_set_peer_identity_service_account()."); - return false; - } - resp->has_result = true; - resp->result.has_peer_identity = true; - set_identity_service_account(&resp->result.peer_identity, service_account); - return true; -} - -bool grpc_gcp_handshaker_resp_set_channel_open(grpc_gcp_handshaker_resp* resp, - bool keep_channel_open) { - if (resp == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr argument to " - "grpc_gcp_handshaker_resp_set_channel_open()."); - return false; - } - resp->has_result = true; - resp->result.has_keep_channel_open = true; - resp->result.keep_channel_open = keep_channel_open; - return true; -} - -bool grpc_gcp_handshaker_resp_set_code(grpc_gcp_handshaker_resp* resp, - uint32_t code) { - if (resp == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr argument to grpc_gcp_handshaker_resp_set_code()."); - return false; - } - resp->has_status = true; - resp->status.has_code = true; - resp->status.code = code; - return true; -} - -bool grpc_gcp_handshaker_resp_set_details(grpc_gcp_handshaker_resp* resp, - const char* details) { - if (resp == nullptr || details == nullptr) { - gpr_log( - GPR_ERROR, - "Invalid nullptr arguments to grpc_gcp_handshaker_resp_set_details()."); - return false; - } - resp->has_status = true; - grpc_slice* slice = create_slice(details, strlen(details)); - resp->status.details.arg = slice; - resp->status.details.funcs.encode = encode_string_or_bytes_cb; - return true; -} - -bool grpc_gcp_handshaker_resp_set_out_frames(grpc_gcp_handshaker_resp* resp, - const char* out_frames, - size_t size) { - if (resp == nullptr || out_frames == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr arguments to " - "grpc_gcp_handshaker_resp_set_out_frames()."); - return false; - } - grpc_slice* slice = create_slice(out_frames, size); - resp->out_frames.arg = slice; - resp->out_frames.funcs.encode = encode_string_or_bytes_cb; - return true; -} - -bool grpc_gcp_handshaker_resp_set_bytes_consumed(grpc_gcp_handshaker_resp* resp, - int32_t bytes_consumed) { - if (resp == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr argument to " - "grpc_gcp_handshaker_resp_set_bytes_consumed()."); - return false; - } - resp->has_bytes_consumed = true; - resp->bytes_consumed = bytes_consumed; - return true; -} - -bool grpc_gcp_handshaker_resp_set_peer_rpc_versions( - grpc_gcp_handshaker_resp* resp, uint32_t max_major, uint32_t max_minor, - uint32_t min_major, uint32_t min_minor) { - if (resp == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr argument to " - "grpc_gcp_handshaker_resp_set_peer_rpc_versions()."); - return false; - } - resp->has_result = true; - resp->result.has_peer_rpc_versions = true; - grpc_gcp_rpc_protocol_versions* versions = &resp->result.peer_rpc_versions; - versions->has_max_rpc_version = true; - versions->has_min_rpc_version = true; - versions->max_rpc_version.has_major = true; - versions->max_rpc_version.has_minor = true; - versions->min_rpc_version.has_major = true; - versions->min_rpc_version.has_minor = true; - versions->max_rpc_version.major = max_major; - versions->max_rpc_version.minor = max_minor; - versions->min_rpc_version.major = min_major; - versions->min_rpc_version.minor = min_minor; - return true; -} - -bool grpc_gcp_handshaker_resp_encode(grpc_gcp_handshaker_resp* resp, - grpc_slice* slice) { - if (resp == nullptr || slice == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr arguments to grpc_gcp_handshaker_resp_encode()."); - return false; - } - pb_ostream_t size_stream; - memset(&size_stream, 0, sizeof(pb_ostream_t)); - if (!pb_encode(&size_stream, grpc_gcp_HandshakerResp_fields, resp)) { - gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&size_stream)); - return false; - } - size_t encoded_length = size_stream.bytes_written; - *slice = grpc_slice_malloc(encoded_length); - pb_ostream_t output_stream = - pb_ostream_from_buffer(GRPC_SLICE_START_PTR(*slice), encoded_length); - if (!pb_encode(&output_stream, grpc_gcp_HandshakerResp_fields, resp)) { - gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&size_stream)); - return false; - } - return true; -} - -bool grpc_gcp_handshaker_req_decode(grpc_slice slice, - grpc_gcp_handshaker_req* req) { - if (req == nullptr) { - gpr_log(GPR_ERROR, - "Invalid nullptr argument to grpc_gcp_handshaker_req_decode()."); - return false; - } - pb_istream_t stream = pb_istream_from_buffer(GRPC_SLICE_START_PTR(slice), - GRPC_SLICE_LENGTH(slice)); - req->next.in_bytes.funcs.decode = decode_string_or_bytes_cb; - if (!pb_decode(&stream, grpc_gcp_HandshakerReq_fields, req)) { - gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&stream)); - return false; - } - return true; -} - -/* Check equality of a pair of grpc_slice fields. */ -static bool slice_equals(grpc_slice* l_slice, grpc_slice* r_slice) { - if (l_slice == nullptr && r_slice == nullptr) { - return true; - } - if (l_slice != nullptr && r_slice != nullptr) { - return grpc_slice_eq(*l_slice, *r_slice); - } - return false; -} - -/* Check equality of a pair of grpc_gcp_identity fields. */ -static bool handshaker_identity_equals(const grpc_gcp_identity* l_id, - const grpc_gcp_identity* r_id) { - if (!((l_id->hostname.arg != nullptr) != (r_id->hostname.arg != nullptr))) { - if (l_id->hostname.arg != nullptr) { - return slice_equals(static_cast(l_id->hostname.arg), - static_cast(r_id->hostname.arg)); - } - } else { - return false; - } - if (!((l_id->service_account.arg != nullptr) != - (r_id->service_account.arg != nullptr))) { - if (l_id->service_account.arg != nullptr) { - return slice_equals(static_cast(l_id->service_account.arg), - static_cast(r_id->service_account.arg)); - } - } else { - return false; - } - return true; -} - -static bool handshaker_rpc_versions_equals( - const grpc_gcp_rpc_protocol_versions* l_version, - const grpc_gcp_rpc_protocol_versions* r_version) { - bool result = true; - result &= - (l_version->max_rpc_version.major == r_version->max_rpc_version.major); - result &= - (l_version->max_rpc_version.minor == r_version->max_rpc_version.minor); - result &= - (l_version->min_rpc_version.major == r_version->min_rpc_version.major); - result &= - (l_version->min_rpc_version.minor == r_version->min_rpc_version.minor); - return result; -} - -/* Check equality of a pair of grpc_gcp_endpoint fields. */ -static bool handshaker_endpoint_equals(const grpc_gcp_endpoint* l_end, - const grpc_gcp_endpoint* r_end) { - bool result = true; - result &= (l_end->port == r_end->port); - result &= (l_end->protocol == r_end->protocol); - if (!((l_end->ip_address.arg != nullptr) != - (r_end->ip_address.arg != nullptr))) { - if (l_end->ip_address.arg != nullptr) { - result &= slice_equals(static_cast(l_end->ip_address.arg), - static_cast(r_end->ip_address.arg)); - } - } else { - return false; - } - return result; -} -/** - * Check if a specific repeated field (i.e., target) is contained in a repeated - * field list (i.e., head). - */ -static bool repeated_field_list_contains_identity( - const repeated_field* head, const repeated_field* target) { - repeated_field* field = const_cast(head); - while (field != nullptr) { - if (handshaker_identity_equals( - static_cast(field->data), - static_cast(target->data))) { - return true; - } - field = field->next; - } - return false; -} - -static bool repeated_field_list_contains_string(const repeated_field* head, - const repeated_field* target) { - repeated_field* field = const_cast(head); - while (field != nullptr) { - if (slice_equals((grpc_slice*)field->data, (grpc_slice*)target->data)) { - return true; - } - field = field->next; - } - return false; -} - -/* Return a length of repeated field list. */ -static size_t repeated_field_list_get_length(const repeated_field* head) { - repeated_field* field = const_cast(head); - size_t len = 0; - while (field != nullptr) { - len++; - field = field->next; - } - return len; -} - -/** - * Check if a pair of repeated field lists contain the same set of repeated - * fields. - */ -static bool repeated_field_list_equals_identity(const repeated_field* l_head, - const repeated_field* r_head) { - if (repeated_field_list_get_length(l_head) != - repeated_field_list_get_length(r_head)) { - return false; - } - repeated_field* field = const_cast(l_head); - repeated_field* head = const_cast(r_head); - while (field != nullptr) { - if (!repeated_field_list_contains_identity(head, field)) { - return false; - } - field = field->next; - } - return true; -} - -static bool repeated_field_list_equals_string(const repeated_field* l_head, - const repeated_field* r_head) { - if (repeated_field_list_get_length(l_head) != - repeated_field_list_get_length(r_head)) { - return false; - } - repeated_field* field = const_cast(l_head); - repeated_field* head = const_cast(r_head); - while (field != nullptr) { - if (!repeated_field_list_contains_string(head, field)) { - return false; - } - field = field->next; - } - return true; -} - -/* Check equality of a pair of ALTS client_start handshake requests. */ -bool grpc_gcp_handshaker_client_start_req_equals( - grpc_gcp_start_client_handshake_req* l_req, - grpc_gcp_start_client_handshake_req* r_req) { - bool result = true; - /* Compare handshake_security_protocol. */ - result &= - l_req->handshake_security_protocol == r_req->handshake_security_protocol; - /* Compare application_protocols, record_protocols, and target_identities. */ - result &= repeated_field_list_equals_string( - static_cast(l_req->application_protocols.arg), - static_cast(r_req->application_protocols.arg)); - result &= repeated_field_list_equals_string( - static_cast(l_req->record_protocols.arg), - static_cast(r_req->record_protocols.arg)); - result &= repeated_field_list_equals_identity( - static_cast(l_req->target_identities.arg), - static_cast(r_req->target_identities.arg)); - if ((l_req->has_local_identity ^ r_req->has_local_identity) | - (l_req->has_local_endpoint ^ r_req->has_local_endpoint) | - ((l_req->has_remote_endpoint ^ r_req->has_remote_endpoint)) | - (l_req->has_rpc_versions ^ r_req->has_rpc_versions)) { - return false; - } - /* Compare local_identity, local_endpoint, and remote_endpoint. */ - if (l_req->has_local_identity) { - result &= handshaker_identity_equals(&l_req->local_identity, - &r_req->local_identity); - } - if (l_req->has_local_endpoint) { - result &= handshaker_endpoint_equals(&l_req->local_endpoint, - &r_req->local_endpoint); - } - if (l_req->has_remote_endpoint) { - result &= handshaker_endpoint_equals(&l_req->remote_endpoint, - &r_req->remote_endpoint); - } - if (l_req->has_rpc_versions) { - result &= handshaker_rpc_versions_equals(&l_req->rpc_versions, - &r_req->rpc_versions); - } - return result; -} - -/* Check equality of a pair of ALTS server_start handshake requests. */ -bool grpc_gcp_handshaker_server_start_req_equals( - grpc_gcp_start_server_handshake_req* l_req, - grpc_gcp_start_server_handshake_req* r_req) { - bool result = true; - /* Compare application_protocols. */ - result &= repeated_field_list_equals_string( - static_cast(l_req->application_protocols.arg), - static_cast(r_req->application_protocols.arg)); - /* Compare handshake_parameters. */ - size_t i = 0, j = 0; - result &= - (l_req->handshake_parameters_count == r_req->handshake_parameters_count); - for (i = 0; i < l_req->handshake_parameters_count; i++) { - bool found = false; - for (j = 0; j < r_req->handshake_parameters_count; j++) { - if (l_req->handshake_parameters[i].key == - r_req->handshake_parameters[j].key) { - found = true; - result &= repeated_field_list_equals_string( - static_cast( - l_req->handshake_parameters[i].value.record_protocols.arg), - static_cast( - r_req->handshake_parameters[j].value.record_protocols.arg)); - result &= repeated_field_list_equals_identity( - static_cast( - l_req->handshake_parameters[i].value.local_identities.arg), - static_cast( - r_req->handshake_parameters[j].value.local_identities.arg)); - } - } - if (!found) { - return false; - } - } - /* Compare in_bytes, local_endpoint, remote_endpoint. */ - result &= slice_equals(static_cast(l_req->in_bytes.arg), - static_cast(r_req->in_bytes.arg)); - if ((l_req->has_local_endpoint ^ r_req->has_local_endpoint) | - (l_req->has_remote_endpoint ^ r_req->has_remote_endpoint) | - (l_req->has_rpc_versions ^ r_req->has_rpc_versions)) - return false; - if (l_req->has_local_endpoint) { - result &= handshaker_endpoint_equals(&l_req->local_endpoint, - &r_req->local_endpoint); - } - if (l_req->has_remote_endpoint) { - result &= handshaker_endpoint_equals(&l_req->remote_endpoint, - &r_req->remote_endpoint); - } - if (l_req->has_rpc_versions) { - result &= handshaker_rpc_versions_equals(&l_req->rpc_versions, - &r_req->rpc_versions); - } - return result; -} - -/* Check equality of a pair of ALTS handshake requests. */ -bool grpc_gcp_handshaker_req_equals(grpc_gcp_handshaker_req* l_req, - grpc_gcp_handshaker_req* r_req) { - if (l_req->has_next && r_req->has_next) { - return slice_equals(static_cast(l_req->next.in_bytes.arg), - static_cast(r_req->next.in_bytes.arg)); - } else if (l_req->has_client_start && r_req->has_client_start) { - return grpc_gcp_handshaker_client_start_req_equals(&l_req->client_start, - &r_req->client_start); - } else if (l_req->has_server_start && r_req->has_server_start) { - return grpc_gcp_handshaker_server_start_req_equals(&l_req->server_start, - &r_req->server_start); - } - return false; -} - -/* Check equality of a pair of ALTS handshake results. */ -bool grpc_gcp_handshaker_resp_result_equals( - grpc_gcp_handshaker_result* l_result, - grpc_gcp_handshaker_result* r_result) { - bool result = true; - /* Compare application_protocol, record_protocol, and key_data. */ - result &= slice_equals( - static_cast(l_result->application_protocol.arg), - static_cast(r_result->application_protocol.arg)); - result &= - slice_equals(static_cast(l_result->record_protocol.arg), - static_cast(r_result->record_protocol.arg)); - result &= slice_equals(static_cast(l_result->key_data.arg), - static_cast(r_result->key_data.arg)); - /* Compare local_identity, peer_identity, and keep_channel_open. */ - if ((l_result->has_local_identity ^ r_result->has_local_identity) | - (l_result->has_peer_identity ^ r_result->has_peer_identity) | - (l_result->has_peer_rpc_versions ^ r_result->has_peer_rpc_versions)) { - return false; - } - if (l_result->has_local_identity) { - result &= handshaker_identity_equals(&l_result->local_identity, - &r_result->local_identity); - } - if (l_result->has_peer_identity) { - result &= handshaker_identity_equals(&l_result->peer_identity, - &r_result->peer_identity); - } - if (l_result->has_peer_rpc_versions) { - result &= handshaker_rpc_versions_equals(&l_result->peer_rpc_versions, - &r_result->peer_rpc_versions); - } - result &= (l_result->keep_channel_open == r_result->keep_channel_open); - return result; -} - -/* Check equality of a pair of ALTS handshake responses. */ -bool grpc_gcp_handshaker_resp_equals(grpc_gcp_handshaker_resp* l_resp, - grpc_gcp_handshaker_resp* r_resp) { - bool result = true; - /* Compare out_frames and bytes_consumed. */ - result &= slice_equals(static_cast(l_resp->out_frames.arg), - static_cast(r_resp->out_frames.arg)); - result &= (l_resp->bytes_consumed == r_resp->bytes_consumed); - /* Compare result and status. */ - if ((l_resp->has_result ^ r_resp->has_result) | - (l_resp->has_status ^ r_resp->has_status)) { - return false; - } - if (l_resp->has_result) { - result &= grpc_gcp_handshaker_resp_result_equals(&l_resp->result, - &r_resp->result); - } - if (l_resp->has_status) { - result &= (l_resp->status.code == r_resp->status.code); - result &= - slice_equals(static_cast(l_resp->status.details.arg), - static_cast(r_resp->status.details.arg)); - } - return result; -} diff --git a/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h b/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h deleted file mode 100644 index 2fcbb4ea99..0000000000 --- a/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_TEST_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_SERVICE_API_TEST_LIB_H -#define GRPC_TEST_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_SERVICE_API_TEST_LIB_H - -#include "src/core/tsi/alts/handshaker/alts_handshaker_service_api.h" -#include "src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h" -#include "src/core/tsi/alts/handshaker/transport_security_common_api.h" - -/** - * The first part of this file contains function signatures for de-serializing - * ALTS handshake requests and setting/serializing ALTS handshake responses, - * which simulate the behaviour of grpc server that runs ALTS handshaker - * service. - */ - -/** - * This method creates a ALTS handshaker request that is used to hold - * de-serialized result. - */ -grpc_gcp_handshaker_req* grpc_gcp_handshaker_decoded_req_create( - grpc_gcp_handshaker_req_type type); - -/* This method de-serializes a ALTS handshaker request. */ -bool grpc_gcp_handshaker_req_decode(grpc_slice slice, - grpc_gcp_handshaker_req* req); - -/* This method serializes a ALTS handshaker response. */ -bool grpc_gcp_handshaker_resp_encode(grpc_gcp_handshaker_resp* resp, - grpc_slice* slice); - -/* This method sets application protocol of ALTS handshaker response. */ -bool grpc_gcp_handshaker_resp_set_application_protocol( - grpc_gcp_handshaker_resp* resp, const char* application_protocol); - -/* This method sets record protocol of ALTS handshaker response. */ -bool grpc_gcp_handshaker_resp_set_record_protocol( - grpc_gcp_handshaker_resp* resp, const char* record_protocol); - -/* This method sets key_data of ALTS handshaker response. */ -bool grpc_gcp_handshaker_resp_set_key_data(grpc_gcp_handshaker_resp* resp, - const char* key_data, size_t size); - -/* This method sets local identity's hostname for ALTS handshaker response. */ -bool grpc_gcp_handshaker_resp_set_local_identity_hostname( - grpc_gcp_handshaker_resp* resp, const char* hostname); - -/** - * This method sets local identity's service account for ALTS handshaker - * response. - */ -bool grpc_gcp_handshaker_resp_set_local_identity_service_account( - grpc_gcp_handshaker_resp* resp, const char* service_account); - -/* This method sets peer identity's hostname for ALTS handshaker response. */ -bool grpc_gcp_handshaker_resp_set_peer_identity_hostname( - grpc_gcp_handshaker_resp* resp, const char* hostname); - -/** - * This method sets peer identity's service account for ALTS handshaker - * response. - */ -bool grpc_gcp_handshaker_resp_set_peer_identity_service_account( - grpc_gcp_handshaker_resp* resp, const char* service_account); - -/* This method sets keep_channel_open for ALTS handshaker response. */ -bool grpc_gcp_handshaker_resp_set_channel_open(grpc_gcp_handshaker_resp* resp, - bool keep_channel_open); - -/* This method sets code for ALTS handshaker response. */ -bool grpc_gcp_handshaker_resp_set_code(grpc_gcp_handshaker_resp* resp, - uint32_t code); - -/* This method sets details for ALTS handshaker response. */ -bool grpc_gcp_handshaker_resp_set_details(grpc_gcp_handshaker_resp* resp, - const char* details); - -/* This method sets out_frames for ALTS handshaker response. */ -bool grpc_gcp_handshaker_resp_set_out_frames(grpc_gcp_handshaker_resp* resp, - const char* out_frames, - size_t size); - -/* This method sets peer_rpc_versions for ALTS handshaker response. */ -bool grpc_gcp_handshaker_resp_set_peer_rpc_versions( - grpc_gcp_handshaker_resp* resp, uint32_t max_major, uint32_t max_minor, - uint32_t min_major, uint32_t min_minor); - -/* This method sets bytes_consumed for ALTS handshaker response. */ -bool grpc_gcp_handshaker_resp_set_bytes_consumed(grpc_gcp_handshaker_resp* resp, - int32_t bytes_consumed); - -/* This method serializes ALTS handshaker response. */ -bool grpc_gcp_handshaker_resp_encode(grpc_gcp_handshaker_resp* resp, - grpc_slice* slice); - -/* This method de-serializes ALTS handshaker request. */ -bool grpc_gcp_handshaker_req_decode(grpc_slice slice, - grpc_gcp_handshaker_req* req); - -/** - * The second part contains function signatures for checking equality of a pair - * of ALTS handshake requests/responses. - */ - -/* This method checks equality of two client_start handshaker requests. */ -bool grpc_gcp_handshaker_client_start_req_equals( - grpc_gcp_start_client_handshake_req* l_req, - grpc_gcp_start_client_handshake_req* r_req); - -/* This method checks equality of two server_start handshaker requests. */ -bool grpc_gcp_handshaker_server_start_req_equals( - grpc_gcp_start_server_handshake_req* l_req, - grpc_gcp_start_server_handshake_req* r_req); - -/* This method checks equality of two ALTS handshaker requests. */ -bool grpc_gcp_handshaker_req_equals(grpc_gcp_handshaker_req* l_req, - grpc_gcp_handshaker_req* r_req); - -/* This method checks equality of two handshaker response results. */ -bool grpc_gcp_handshaker_resp_result_equals( - grpc_gcp_handshaker_result* l_result, grpc_gcp_handshaker_result* r_result); - -/* This method checks equality of two ALTS handshaker responses. */ -bool grpc_gcp_handshaker_resp_equals(grpc_gcp_handshaker_resp* l_resp, - grpc_gcp_handshaker_resp* r_resp); - -#endif // GRPC_TEST_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_SERVICE_API_TEST_LIB_H diff --git a/test/core/tsi/alts/handshaker/alts_tsi_handshaker_test.cc b/test/core/tsi/alts/handshaker/alts_tsi_handshaker_test.cc deleted file mode 100644 index 95724f84f4..0000000000 --- a/test/core/tsi/alts/handshaker/alts_tsi_handshaker_test.cc +++ /dev/null @@ -1,682 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include - -#include -#include - -#include "src/core/lib/gprpp/thd.h" -#include "src/core/tsi/alts/handshaker/alts_handshaker_client.h" -#include "src/core/tsi/alts/handshaker/alts_tsi_event.h" -#include "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h" -#include "src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h" -#include "test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h" - -#define ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES "Hello World" -#define ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME "Hello Google" -#define ALTS_TSI_HANDSHAKER_TEST_CONSUMED_BYTES "Hello " -#define ALTS_TSI_HANDSHAKER_TEST_REMAIN_BYTES "Google" -#define ALTS_TSI_HANDSHAKER_TEST_PEER_IDENTITY "chapi@service.google.com" -#define ALTS_TSI_HANDSHAKER_TEST_KEY_DATA \ - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKL" -#define ALTS_TSI_HANDSHAKER_TEST_BUFFER_SIZE 100 -#define ALTS_TSI_HANDSHAKER_TEST_SLEEP_TIME_IN_SECONDS 2 -#define ALTS_TSI_HANDSHAKER_TEST_MAX_RPC_VERSION_MAJOR 3 -#define ALTS_TSI_HANDSHAKER_TEST_MAX_RPC_VERSION_MINOR 2 -#define ALTS_TSI_HANDSHAKER_TEST_MIN_RPC_VERSION_MAJOR 2 -#define ALTS_TSI_HANDSHAKER_TEST_MIN_RPC_VERSION_MINOR 1 - -using grpc_core::internal:: - alts_tsi_handshaker_get_has_sent_start_message_for_testing; -using grpc_core::internal::alts_tsi_handshaker_get_is_client_for_testing; -using grpc_core::internal::alts_tsi_handshaker_get_recv_bytes_for_testing; -using grpc_core::internal::alts_tsi_handshaker_set_client_for_testing; -using grpc_core::internal::alts_tsi_handshaker_set_recv_bytes_for_testing; - -/* ALTS mock notification. */ -typedef struct notification { - gpr_cv cv; - gpr_mu mu; - bool notified; -} notification; - -/* ALTS mock handshaker client. */ -typedef struct alts_mock_handshaker_client { - alts_handshaker_client base; - bool used_for_success_test; -} alts_mock_handshaker_client; - -/* Type of ALTS handshaker response. */ -typedef enum { - INVALID, - FAILED, - CLIENT_START, - SERVER_START, - CLIENT_NEXT, - SERVER_NEXT, -} alts_handshaker_response_type; - -static alts_tsi_event* client_start_event; -static alts_tsi_event* client_next_event; -static alts_tsi_event* server_start_event; -static alts_tsi_event* server_next_event; -static notification caller_to_tsi_notification; -static notification tsi_to_caller_notification; - -static void notification_init(notification* n) { - gpr_mu_init(&n->mu); - gpr_cv_init(&n->cv); - n->notified = false; -} - -static void notification_destroy(notification* n) { - gpr_mu_destroy(&n->mu); - gpr_cv_destroy(&n->cv); -} - -static void signal(notification* n) { - gpr_mu_lock(&n->mu); - n->notified = true; - gpr_cv_signal(&n->cv); - gpr_mu_unlock(&n->mu); -} - -static void wait(notification* n) { - gpr_mu_lock(&n->mu); - while (!n->notified) { - gpr_cv_wait(&n->cv, &n->mu, gpr_inf_future(GPR_CLOCK_REALTIME)); - } - n->notified = false; - gpr_mu_unlock(&n->mu); -} - -/** - * This method mocks ALTS handshaker service to generate handshaker response - * for a specific request. - */ -static grpc_byte_buffer* generate_handshaker_response( - alts_handshaker_response_type type) { - grpc_gcp_handshaker_resp* resp = grpc_gcp_handshaker_resp_create(); - GPR_ASSERT(grpc_gcp_handshaker_resp_set_code(resp, 0)); - switch (type) { - case INVALID: - break; - case CLIENT_START: - case SERVER_START: - GPR_ASSERT(grpc_gcp_handshaker_resp_set_out_frames( - resp, ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME, - strlen(ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME))); - break; - case CLIENT_NEXT: - GPR_ASSERT(grpc_gcp_handshaker_resp_set_out_frames( - resp, ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME, - strlen(ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME))); - GPR_ASSERT(grpc_gcp_handshaker_resp_set_peer_identity_service_account( - resp, ALTS_TSI_HANDSHAKER_TEST_PEER_IDENTITY)); - GPR_ASSERT(grpc_gcp_handshaker_resp_set_bytes_consumed( - resp, strlen(ALTS_TSI_HANDSHAKER_TEST_CONSUMED_BYTES))); - GPR_ASSERT(grpc_gcp_handshaker_resp_set_key_data( - resp, ALTS_TSI_HANDSHAKER_TEST_KEY_DATA, - strlen(ALTS_TSI_HANDSHAKER_TEST_KEY_DATA))); - GPR_ASSERT(grpc_gcp_handshaker_resp_set_peer_rpc_versions( - resp, ALTS_TSI_HANDSHAKER_TEST_MAX_RPC_VERSION_MAJOR, - ALTS_TSI_HANDSHAKER_TEST_MAX_RPC_VERSION_MINOR, - ALTS_TSI_HANDSHAKER_TEST_MIN_RPC_VERSION_MAJOR, - ALTS_TSI_HANDSHAKER_TEST_MIN_RPC_VERSION_MINOR)); - break; - case SERVER_NEXT: - GPR_ASSERT(grpc_gcp_handshaker_resp_set_peer_identity_service_account( - resp, ALTS_TSI_HANDSHAKER_TEST_PEER_IDENTITY)); - GPR_ASSERT(grpc_gcp_handshaker_resp_set_bytes_consumed( - resp, strlen(ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME))); - GPR_ASSERT(grpc_gcp_handshaker_resp_set_key_data( - resp, ALTS_TSI_HANDSHAKER_TEST_KEY_DATA, - strlen(ALTS_TSI_HANDSHAKER_TEST_KEY_DATA))); - GPR_ASSERT(grpc_gcp_handshaker_resp_set_peer_rpc_versions( - resp, ALTS_TSI_HANDSHAKER_TEST_MAX_RPC_VERSION_MAJOR, - ALTS_TSI_HANDSHAKER_TEST_MAX_RPC_VERSION_MINOR, - ALTS_TSI_HANDSHAKER_TEST_MIN_RPC_VERSION_MAJOR, - ALTS_TSI_HANDSHAKER_TEST_MIN_RPC_VERSION_MINOR)); - break; - case FAILED: - GPR_ASSERT( - grpc_gcp_handshaker_resp_set_code(resp, 3 /* INVALID ARGUMENT */)); - break; - } - grpc_slice slice; - GPR_ASSERT(grpc_gcp_handshaker_resp_encode(resp, &slice)); - if (type == INVALID) { - grpc_slice bad_slice = - grpc_slice_split_head(&slice, GRPC_SLICE_LENGTH(slice) - 1); - grpc_slice_unref(slice); - slice = grpc_slice_ref(bad_slice); - grpc_slice_unref(bad_slice); - } - grpc_byte_buffer* buffer = - grpc_raw_byte_buffer_create(&slice, 1 /* number of slices */); - grpc_slice_unref(slice); - grpc_gcp_handshaker_resp_destroy(resp); - return buffer; -} - -static void check_must_not_be_called(tsi_result status, void* user_data, - const unsigned char* bytes_to_send, - size_t bytes_to_send_size, - tsi_handshaker_result* result) { - GPR_ASSERT(0); -} - -static void on_client_start_success_cb(tsi_result status, void* user_data, - const unsigned char* bytes_to_send, - size_t bytes_to_send_size, - tsi_handshaker_result* result) { - GPR_ASSERT(status == TSI_OK); - GPR_ASSERT(user_data == nullptr); - GPR_ASSERT(bytes_to_send_size == strlen(ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME)); - GPR_ASSERT(memcmp(bytes_to_send, ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME, - bytes_to_send_size) == 0); - GPR_ASSERT(result == nullptr); - /* Validate peer identity. */ - tsi_peer peer; - GPR_ASSERT(tsi_handshaker_result_extract_peer(result, &peer) == - TSI_INVALID_ARGUMENT); - /* Validate frame protector. */ - tsi_frame_protector* protector = nullptr; - GPR_ASSERT(tsi_handshaker_result_create_frame_protector( - result, nullptr, &protector) == TSI_INVALID_ARGUMENT); - /* Validate unused bytes. */ - const unsigned char* unused_bytes = nullptr; - size_t unused_bytes_size = 0; - GPR_ASSERT(tsi_handshaker_result_get_unused_bytes(result, &unused_bytes, - &unused_bytes_size) == - TSI_INVALID_ARGUMENT); - signal(&tsi_to_caller_notification); -} - -static void on_server_start_success_cb(tsi_result status, void* user_data, - const unsigned char* bytes_to_send, - size_t bytes_to_send_size, - tsi_handshaker_result* result) { - GPR_ASSERT(status == TSI_OK); - GPR_ASSERT(user_data == nullptr); - GPR_ASSERT(bytes_to_send_size == strlen(ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME)); - GPR_ASSERT(memcmp(bytes_to_send, ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME, - bytes_to_send_size) == 0); - GPR_ASSERT(result == nullptr); - /* Validate peer identity. */ - tsi_peer peer; - GPR_ASSERT(tsi_handshaker_result_extract_peer(result, &peer) == - TSI_INVALID_ARGUMENT); - /* Validate frame protector. */ - tsi_frame_protector* protector = nullptr; - GPR_ASSERT(tsi_handshaker_result_create_frame_protector( - result, nullptr, &protector) == TSI_INVALID_ARGUMENT); - /* Validate unused bytes. */ - const unsigned char* unused_bytes = nullptr; - size_t unused_bytes_size = 0; - GPR_ASSERT(tsi_handshaker_result_get_unused_bytes(result, &unused_bytes, - &unused_bytes_size) == - TSI_INVALID_ARGUMENT); - signal(&tsi_to_caller_notification); -} - -static void on_client_next_success_cb(tsi_result status, void* user_data, - const unsigned char* bytes_to_send, - size_t bytes_to_send_size, - tsi_handshaker_result* result) { - GPR_ASSERT(status == TSI_OK); - GPR_ASSERT(user_data == nullptr); - GPR_ASSERT(bytes_to_send_size == strlen(ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME)); - GPR_ASSERT(memcmp(bytes_to_send, ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME, - bytes_to_send_size) == 0); - GPR_ASSERT(result != nullptr); - /* Validate peer identity. */ - tsi_peer peer; - GPR_ASSERT(tsi_handshaker_result_extract_peer(result, &peer) == TSI_OK); - GPR_ASSERT(peer.property_count == kTsiAltsNumOfPeerProperties); - GPR_ASSERT(memcmp(TSI_ALTS_CERTIFICATE_TYPE, peer.properties[0].value.data, - peer.properties[0].value.length) == 0); - GPR_ASSERT(memcmp(ALTS_TSI_HANDSHAKER_TEST_PEER_IDENTITY, - peer.properties[1].value.data, - peer.properties[1].value.length) == 0); - tsi_peer_destruct(&peer); - /* Validate unused bytes. */ - const unsigned char* bytes = nullptr; - size_t bytes_size = 0; - GPR_ASSERT(tsi_handshaker_result_get_unused_bytes(result, &bytes, - &bytes_size) == TSI_OK); - GPR_ASSERT(bytes_size == strlen(ALTS_TSI_HANDSHAKER_TEST_REMAIN_BYTES)); - GPR_ASSERT(memcmp(bytes, ALTS_TSI_HANDSHAKER_TEST_REMAIN_BYTES, bytes_size) == - 0); - /* Validate frame protector. */ - tsi_frame_protector* protector = nullptr; - GPR_ASSERT(tsi_handshaker_result_create_frame_protector( - result, nullptr, &protector) == TSI_OK); - GPR_ASSERT(protector != nullptr); - tsi_frame_protector_destroy(protector); - tsi_handshaker_result_destroy(result); - signal(&tsi_to_caller_notification); -} - -static void on_server_next_success_cb(tsi_result status, void* user_data, - const unsigned char* bytes_to_send, - size_t bytes_to_send_size, - tsi_handshaker_result* result) { - GPR_ASSERT(status == TSI_OK); - GPR_ASSERT(user_data == nullptr); - GPR_ASSERT(bytes_to_send_size == 0); - GPR_ASSERT(bytes_to_send == nullptr); - GPR_ASSERT(result != nullptr); - /* Validate peer identity. */ - tsi_peer peer; - GPR_ASSERT(tsi_handshaker_result_extract_peer(result, &peer) == TSI_OK); - GPR_ASSERT(peer.property_count == kTsiAltsNumOfPeerProperties); - GPR_ASSERT(memcmp(TSI_ALTS_CERTIFICATE_TYPE, peer.properties[0].value.data, - peer.properties[0].value.length) == 0); - GPR_ASSERT(memcmp(ALTS_TSI_HANDSHAKER_TEST_PEER_IDENTITY, - peer.properties[1].value.data, - peer.properties[1].value.length) == 0); - tsi_peer_destruct(&peer); - /* Validate unused bytes. */ - const unsigned char* bytes = nullptr; - size_t bytes_size = 0; - GPR_ASSERT(tsi_handshaker_result_get_unused_bytes(result, &bytes, - &bytes_size) == TSI_OK); - GPR_ASSERT(bytes_size == 0); - GPR_ASSERT(bytes == nullptr); - /* Validate frame protector. */ - tsi_frame_protector* protector = nullptr; - GPR_ASSERT(tsi_handshaker_result_create_frame_protector( - result, nullptr, &protector) == TSI_OK); - GPR_ASSERT(protector != nullptr); - tsi_frame_protector_destroy(protector); - tsi_handshaker_result_destroy(result); - signal(&tsi_to_caller_notification); -} - -static tsi_result mock_client_start(alts_handshaker_client* self, - alts_tsi_event* event) { - alts_mock_handshaker_client* client = - reinterpret_cast(self); - if (!client->used_for_success_test) { - alts_tsi_event_destroy(event); - return TSI_INTERNAL_ERROR; - } - GPR_ASSERT(event->cb == on_client_start_success_cb); - GPR_ASSERT(event->user_data == nullptr); - GPR_ASSERT(!alts_tsi_handshaker_get_has_sent_start_message_for_testing( - event->handshaker)); - /* Populate handshaker response for client_start request. */ - event->recv_buffer = generate_handshaker_response(CLIENT_START); - client_start_event = event; - signal(&caller_to_tsi_notification); - return TSI_OK; -} - -static tsi_result mock_server_start(alts_handshaker_client* self, - alts_tsi_event* event, - grpc_slice* bytes_received) { - alts_mock_handshaker_client* client = - reinterpret_cast(self); - if (!client->used_for_success_test) { - alts_tsi_event_destroy(event); - return TSI_INTERNAL_ERROR; - } - GPR_ASSERT(event->cb == on_server_start_success_cb); - GPR_ASSERT(event->user_data == nullptr); - grpc_slice slice = grpc_empty_slice(); - GPR_ASSERT(grpc_slice_cmp(*bytes_received, slice) == 0); - GPR_ASSERT(!alts_tsi_handshaker_get_has_sent_start_message_for_testing( - event->handshaker)); - /* Populate handshaker response for server_start request. */ - event->recv_buffer = generate_handshaker_response(SERVER_START); - server_start_event = event; - grpc_slice_unref(slice); - signal(&caller_to_tsi_notification); - return TSI_OK; -} - -static tsi_result mock_next(alts_handshaker_client* self, alts_tsi_event* event, - grpc_slice* bytes_received) { - alts_mock_handshaker_client* client = - reinterpret_cast(self); - if (!client->used_for_success_test) { - alts_tsi_event_destroy(event); - return TSI_INTERNAL_ERROR; - } - bool is_client = - alts_tsi_handshaker_get_is_client_for_testing(event->handshaker); - if (is_client) { - GPR_ASSERT(event->cb == on_client_next_success_cb); - } else { - GPR_ASSERT(event->cb == on_server_next_success_cb); - } - GPR_ASSERT(event->user_data == nullptr); - GPR_ASSERT(bytes_received != nullptr); - GPR_ASSERT(memcmp(GRPC_SLICE_START_PTR(*bytes_received), - ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES, - GRPC_SLICE_LENGTH(*bytes_received)) == 0); - GPR_ASSERT(grpc_slice_cmp(alts_tsi_handshaker_get_recv_bytes_for_testing( - event->handshaker), - *bytes_received) == 0); - GPR_ASSERT(alts_tsi_handshaker_get_has_sent_start_message_for_testing( - event->handshaker)); - /* Populate handshaker response for next request. */ - grpc_slice out_frame = - grpc_slice_from_static_string(ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME); - if (is_client) { - event->recv_buffer = generate_handshaker_response(CLIENT_NEXT); - } else { - event->recv_buffer = generate_handshaker_response(SERVER_NEXT); - } - alts_tsi_handshaker_set_recv_bytes_for_testing(event->handshaker, &out_frame); - if (is_client) { - client_next_event = event; - } else { - server_next_event = event; - } - signal(&caller_to_tsi_notification); - grpc_slice_unref(out_frame); - return TSI_OK; -} - -static void mock_destruct(alts_handshaker_client* client) {} - -static const alts_handshaker_client_vtable vtable = { - mock_client_start, mock_server_start, mock_next, mock_destruct}; - -static alts_handshaker_client* alts_mock_handshaker_client_create( - bool used_for_success_test) { - alts_mock_handshaker_client* client = - static_cast(gpr_zalloc(sizeof(*client))); - client->base.vtable = &vtable; - client->used_for_success_test = used_for_success_test; - return &client->base; -} - -static tsi_handshaker* create_test_handshaker(bool used_for_success_test, - bool is_client) { - tsi_handshaker* handshaker = nullptr; - alts_handshaker_client* client = - alts_mock_handshaker_client_create(used_for_success_test); - grpc_alts_credentials_options* options = - grpc_alts_credentials_client_options_create(); - alts_tsi_handshaker_create(options, "target_name", "lame", is_client, - &handshaker); - alts_tsi_handshaker* alts_handshaker = - reinterpret_cast(handshaker); - alts_tsi_handshaker_set_client_for_testing(alts_handshaker, client); - grpc_alts_credentials_options_destroy(options); - return handshaker; -} - -static void check_handshaker_next_invalid_input() { - /* Initialization. */ - tsi_handshaker* handshaker = create_test_handshaker(true, true); - /* Check nullptr handshaker. */ - GPR_ASSERT(tsi_handshaker_next(nullptr, nullptr, 0, nullptr, nullptr, nullptr, - check_must_not_be_called, - nullptr) == TSI_INVALID_ARGUMENT); - /* Check nullptr callback. */ - GPR_ASSERT(tsi_handshaker_next(handshaker, nullptr, 0, nullptr, nullptr, - nullptr, nullptr, - nullptr) == TSI_INVALID_ARGUMENT); - /* Cleanup. */ - tsi_handshaker_destroy(handshaker); -} - -static void check_handshaker_next_success() { - /** - * Create handshakers for which internal mock client is going to do - * correctness check. - */ - tsi_handshaker* client_handshaker = create_test_handshaker( - true /* used_for_success_test */, true /* is_client */); - tsi_handshaker* server_handshaker = create_test_handshaker( - true /* used_for_success_test */, false /* is_client */); - /* Client start. */ - GPR_ASSERT(tsi_handshaker_next(client_handshaker, nullptr, 0, nullptr, - nullptr, nullptr, on_client_start_success_cb, - nullptr) == TSI_ASYNC); - wait(&tsi_to_caller_notification); - /* Client next. */ - GPR_ASSERT(tsi_handshaker_next( - client_handshaker, - (const unsigned char*)ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES, - strlen(ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES), nullptr, nullptr, - nullptr, on_client_next_success_cb, nullptr) == TSI_ASYNC); - wait(&tsi_to_caller_notification); - /* Server start. */ - GPR_ASSERT(tsi_handshaker_next(server_handshaker, nullptr, 0, nullptr, - nullptr, nullptr, on_server_start_success_cb, - nullptr) == TSI_ASYNC); - wait(&tsi_to_caller_notification); - /* Server next. */ - GPR_ASSERT(tsi_handshaker_next( - server_handshaker, - (const unsigned char*)ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES, - strlen(ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES), nullptr, nullptr, - nullptr, on_server_next_success_cb, nullptr) == TSI_ASYNC); - wait(&tsi_to_caller_notification); - /* Cleanup. */ - tsi_handshaker_destroy(server_handshaker); - tsi_handshaker_destroy(client_handshaker); -} - -static void check_handshaker_next_failure() { - /** - * Create handshakers for which internal mock client is always going to fail. - */ - tsi_handshaker* client_handshaker = create_test_handshaker( - false /* used_for_success_test */, true /* is_client */); - tsi_handshaker* server_handshaker = create_test_handshaker( - false /* used_for_success_test */, false /* is_client */); - /* Client start. */ - GPR_ASSERT(tsi_handshaker_next(client_handshaker, nullptr, 0, nullptr, - nullptr, nullptr, check_must_not_be_called, - nullptr) == TSI_INTERNAL_ERROR); - /* Server start. */ - GPR_ASSERT(tsi_handshaker_next(server_handshaker, nullptr, 0, nullptr, - nullptr, nullptr, check_must_not_be_called, - nullptr) == TSI_INTERNAL_ERROR); - /* Server next. */ - GPR_ASSERT(tsi_handshaker_next( - server_handshaker, - (const unsigned char*)ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES, - strlen(ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES), nullptr, nullptr, - nullptr, check_must_not_be_called, - nullptr) == TSI_INTERNAL_ERROR); - /* Client next. */ - GPR_ASSERT(tsi_handshaker_next( - client_handshaker, - (const unsigned char*)ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES, - strlen(ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES), nullptr, nullptr, - nullptr, check_must_not_be_called, - nullptr) == TSI_INTERNAL_ERROR); - /* Cleanup. */ - tsi_handshaker_destroy(server_handshaker); - tsi_handshaker_destroy(client_handshaker); -} - -static void on_invalid_input_cb(tsi_result status, void* user_data, - const unsigned char* bytes_to_send, - size_t bytes_to_send_size, - tsi_handshaker_result* result) { - GPR_ASSERT(status == TSI_INTERNAL_ERROR); - GPR_ASSERT(user_data == nullptr); - GPR_ASSERT(bytes_to_send == nullptr); - GPR_ASSERT(bytes_to_send_size == 0); - GPR_ASSERT(result == nullptr); -} - -static void on_failed_grpc_call_cb(tsi_result status, void* user_data, - const unsigned char* bytes_to_send, - size_t bytes_to_send_size, - tsi_handshaker_result* result) { - GPR_ASSERT(status == TSI_INTERNAL_ERROR); - GPR_ASSERT(user_data == nullptr); - GPR_ASSERT(bytes_to_send == nullptr); - GPR_ASSERT(bytes_to_send_size == 0); - GPR_ASSERT(result == nullptr); -} - -static void check_handle_response_invalid_input() { - /** - * Create a handshaker at the client side, for which internal mock client is - * always going to fail. - */ - tsi_handshaker* handshaker = create_test_handshaker( - false /* used_for_success_test */, true /* is_client */); - alts_tsi_handshaker* alts_handshaker = - reinterpret_cast(handshaker); - grpc_byte_buffer recv_buffer; - /* Check nullptr handshaker. */ - alts_tsi_handshaker_handle_response(nullptr, &recv_buffer, GRPC_STATUS_OK, - nullptr, on_invalid_input_cb, nullptr, - true); - /* Check nullptr recv_bytes. */ - alts_tsi_handshaker_handle_response(alts_handshaker, nullptr, GRPC_STATUS_OK, - nullptr, on_invalid_input_cb, nullptr, - true); - /* Check failed grpc call made to handshaker service. */ - alts_tsi_handshaker_handle_response(alts_handshaker, &recv_buffer, - GRPC_STATUS_UNKNOWN, nullptr, - on_failed_grpc_call_cb, nullptr, true); - - alts_tsi_handshaker_handle_response(alts_handshaker, &recv_buffer, - GRPC_STATUS_OK, nullptr, - on_failed_grpc_call_cb, nullptr, false); - - /* Cleanup. */ - tsi_handshaker_destroy(handshaker); -} - -static void on_invalid_resp_cb(tsi_result status, void* user_data, - const unsigned char* bytes_to_send, - size_t bytes_to_send_size, - tsi_handshaker_result* result) { - GPR_ASSERT(status == TSI_DATA_CORRUPTED); - GPR_ASSERT(user_data == nullptr); - GPR_ASSERT(bytes_to_send == nullptr); - GPR_ASSERT(bytes_to_send_size == 0); - GPR_ASSERT(result == nullptr); -} - -static void check_handle_response_invalid_resp() { - /** - * Create a handshaker at the client side, for which internal mock client is - * always going to fail. - */ - tsi_handshaker* handshaker = create_test_handshaker( - false /* used_for_success_test */, true /* is_client */); - alts_tsi_handshaker* alts_handshaker = - reinterpret_cast(handshaker); - /* Tests. */ - grpc_byte_buffer* recv_buffer = generate_handshaker_response(INVALID); - alts_tsi_handshaker_handle_response(alts_handshaker, recv_buffer, - GRPC_STATUS_OK, nullptr, - on_invalid_resp_cb, nullptr, true); - /* Cleanup. */ - grpc_byte_buffer_destroy(recv_buffer); - tsi_handshaker_destroy(handshaker); -} - -static void check_handle_response_success(void* unused) { - /* Client start. */ - wait(&caller_to_tsi_notification); - alts_tsi_event_dispatch_to_handshaker(client_start_event, true /* is_ok */); - alts_tsi_event_destroy(client_start_event); - /* Client next. */ - wait(&caller_to_tsi_notification); - alts_tsi_event_dispatch_to_handshaker(client_next_event, true /* is_ok */); - alts_tsi_event_destroy(client_next_event); - /* Server start. */ - wait(&caller_to_tsi_notification); - alts_tsi_event_dispatch_to_handshaker(server_start_event, true /* is_ok */); - alts_tsi_event_destroy(server_start_event); - /* Server next. */ - wait(&caller_to_tsi_notification); - alts_tsi_event_dispatch_to_handshaker(server_next_event, true /* is_ok */); - alts_tsi_event_destroy(server_next_event); -} - -static void on_failed_resp_cb(tsi_result status, void* user_data, - const unsigned char* bytes_to_send, - size_t bytes_to_send_size, - tsi_handshaker_result* result) { - GPR_ASSERT(status == TSI_INVALID_ARGUMENT); - GPR_ASSERT(user_data == nullptr); - GPR_ASSERT(bytes_to_send == nullptr); - GPR_ASSERT(bytes_to_send_size == 0); - GPR_ASSERT(result == nullptr); -} - -static void check_handle_response_failure() { - /** - * Create a handshaker at the client side, for which internal mock client is - * always going to fail. - */ - tsi_handshaker* handshaker = create_test_handshaker( - false /* used_for_success_test */, true /* is_client */); - alts_tsi_handshaker* alts_handshaker = - reinterpret_cast(handshaker); - /* Tests. */ - grpc_byte_buffer* recv_buffer = generate_handshaker_response(FAILED); - alts_tsi_handshaker_handle_response(alts_handshaker, recv_buffer, - GRPC_STATUS_OK, nullptr, - on_failed_resp_cb, nullptr, true); - grpc_byte_buffer_destroy(recv_buffer); - /* Cleanup. */ - tsi_handshaker_destroy(handshaker); -} - -void check_handshaker_success() { - /* Initialization. */ - notification_init(&caller_to_tsi_notification); - notification_init(&tsi_to_caller_notification); - client_start_event = nullptr; - client_next_event = nullptr; - server_start_event = nullptr; - server_next_event = nullptr; - /* Tests. */ - grpc_core::Thread thd("alts_tsi_handshaker_test", - &check_handle_response_success, nullptr); - thd.Start(); - check_handshaker_next_success(); - thd.Join(); - /* Cleanup. */ - notification_destroy(&caller_to_tsi_notification); - notification_destroy(&tsi_to_caller_notification); -} - -int main(int argc, char** argv) { - /* Initialization. */ - grpc_init(); - /* Tests. */ - check_handshaker_success(); - check_handshaker_next_invalid_input(); - check_handshaker_next_failure(); - check_handle_response_invalid_input(); - check_handle_response_invalid_resp(); - check_handle_response_failure(); - /* Cleanup. */ - grpc_shutdown(); - return 0; -} diff --git a/test/core/tsi/alts/handshaker/alts_tsi_utils_test.cc b/test/core/tsi/alts/handshaker/alts_tsi_utils_test.cc deleted file mode 100644 index 98c5d23641..0000000000 --- a/test/core/tsi/alts/handshaker/alts_tsi_utils_test.cc +++ /dev/null @@ -1,73 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "src/core/tsi/alts/handshaker/alts_tsi_utils.h" -#include "test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h" - -#define ALTS_TSI_UTILS_TEST_OUT_FRAME "Hello Google" - -static void convert_to_tsi_result_test() { - GPR_ASSERT(alts_tsi_utils_convert_to_tsi_result(GRPC_STATUS_OK) == TSI_OK); - GPR_ASSERT(alts_tsi_utils_convert_to_tsi_result(GRPC_STATUS_UNKNOWN) == - TSI_UNKNOWN_ERROR); - GPR_ASSERT(alts_tsi_utils_convert_to_tsi_result( - GRPC_STATUS_INVALID_ARGUMENT) == TSI_INVALID_ARGUMENT); - GPR_ASSERT(alts_tsi_utils_convert_to_tsi_result(GRPC_STATUS_OUT_OF_RANGE) == - TSI_UNKNOWN_ERROR); - GPR_ASSERT(alts_tsi_utils_convert_to_tsi_result(GRPC_STATUS_INTERNAL) == - TSI_INTERNAL_ERROR); - GPR_ASSERT(alts_tsi_utils_convert_to_tsi_result(GRPC_STATUS_NOT_FOUND) == - TSI_NOT_FOUND); -} - -static void deserialize_response_test() { - grpc_gcp_handshaker_resp* resp = grpc_gcp_handshaker_resp_create(); - GPR_ASSERT(grpc_gcp_handshaker_resp_set_out_frames( - resp, ALTS_TSI_UTILS_TEST_OUT_FRAME, - strlen(ALTS_TSI_UTILS_TEST_OUT_FRAME))); - grpc_slice slice; - GPR_ASSERT(grpc_gcp_handshaker_resp_encode(resp, &slice)); - - /* Valid serialization. */ - grpc_byte_buffer* buffer = - grpc_raw_byte_buffer_create(&slice, 1 /* number of slices */); - grpc_gcp_handshaker_resp* decoded_resp = - alts_tsi_utils_deserialize_response(buffer); - GPR_ASSERT(grpc_gcp_handshaker_resp_equals(resp, decoded_resp)); - grpc_byte_buffer_destroy(buffer); - - /* Invalid serializaiton. */ - grpc_slice bad_slice = - grpc_slice_split_head(&slice, GRPC_SLICE_LENGTH(slice) - 1); - buffer = grpc_raw_byte_buffer_create(&bad_slice, 1 /* number of slices */); - GPR_ASSERT(alts_tsi_utils_deserialize_response(buffer) == nullptr); - - /* Clean up. */ - grpc_slice_unref(slice); - grpc_slice_unref(bad_slice); - grpc_byte_buffer_destroy(buffer); - grpc_gcp_handshaker_resp_destroy(resp); - grpc_gcp_handshaker_resp_destroy(decoded_resp); -} - -int main(int argc, char** argv) { - /* Tests. */ - deserialize_response_test(); - convert_to_tsi_result_test(); - return 0; -} diff --git a/test/core/tsi/alts/handshaker/transport_security_common_api_test.cc b/test/core/tsi/alts/handshaker/transport_security_common_api_test.cc deleted file mode 100644 index 6ff1357c27..0000000000 --- a/test/core/tsi/alts/handshaker/transport_security_common_api_test.cc +++ /dev/null @@ -1,196 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include - -#include "src/core/tsi/alts/handshaker/transport_security_common_api.h" - -const size_t kMaxRpcVersionMajor = 3; -const size_t kMaxRpcVersionMinor = 2; -const size_t kMinRpcVersionMajor = 2; -const size_t kMinRpcVersionMinor = 1; - -static bool grpc_gcp_rpc_protocol_versions_equal( - grpc_gcp_rpc_protocol_versions* l_versions, - grpc_gcp_rpc_protocol_versions* r_versions) { - GPR_ASSERT(l_versions != nullptr && r_versions != nullptr); - if ((l_versions->has_max_rpc_version ^ r_versions->has_max_rpc_version) | - (l_versions->has_min_rpc_version ^ r_versions->has_min_rpc_version)) { - return false; - } - if (l_versions->has_max_rpc_version) { - if ((l_versions->max_rpc_version.major != - r_versions->max_rpc_version.major) || - (l_versions->max_rpc_version.minor != - r_versions->max_rpc_version.minor)) { - return false; - } - } - if (l_versions->has_min_rpc_version) { - if ((l_versions->min_rpc_version.major != - r_versions->min_rpc_version.major) || - (l_versions->min_rpc_version.minor != - r_versions->min_rpc_version.minor)) { - return false; - } - } - return true; -} - -static void test_success() { - grpc_gcp_rpc_protocol_versions version; - grpc_gcp_rpc_protocol_versions decoded_version; - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_max( - &version, kMaxRpcVersionMajor, kMaxRpcVersionMinor)); - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_min( - &version, kMinRpcVersionMajor, kMinRpcVersionMinor)); - /* Serializes to raw bytes. */ - size_t encoded_length = - grpc_gcp_rpc_protocol_versions_encode_length(&version); - uint8_t* encoded_bytes = static_cast(gpr_malloc(encoded_length)); - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_encode_to_raw_bytes( - &version, encoded_bytes, encoded_length)); - grpc_slice encoded_slice; - /* Serializes to grpc slice. */ - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_encode(&version, &encoded_slice)); - /* Checks serialized raw bytes and serialized grpc slice have same content. */ - GPR_ASSERT(encoded_length == GRPC_SLICE_LENGTH(encoded_slice)); - GPR_ASSERT(memcmp(encoded_bytes, GRPC_SLICE_START_PTR(encoded_slice), - encoded_length) == 0); - /* Deserializes and compares with the original version. */ - GPR_ASSERT( - grpc_gcp_rpc_protocol_versions_decode(encoded_slice, &decoded_version)); - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_equal(&version, &decoded_version)); - grpc_slice_unref(encoded_slice); - gpr_free(encoded_bytes); -} - -static void test_failure() { - grpc_gcp_rpc_protocol_versions version, decoded_version; - grpc_slice encoded_slice; - /* Test for invalid arguments. */ - GPR_ASSERT(!grpc_gcp_rpc_protocol_versions_set_max( - nullptr, kMaxRpcVersionMajor, kMaxRpcVersionMinor)); - GPR_ASSERT(!grpc_gcp_rpc_protocol_versions_set_min( - nullptr, kMinRpcVersionMajor, kMinRpcVersionMinor)); - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_encode_length(nullptr) == 0); - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_max( - &version, kMaxRpcVersionMajor, kMaxRpcVersionMinor)); - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_min( - &version, kMinRpcVersionMajor, kMinRpcVersionMinor)); - size_t encoded_length = - grpc_gcp_rpc_protocol_versions_encode_length(&version); - uint8_t* encoded_bytes = static_cast(gpr_malloc(encoded_length)); - GPR_ASSERT(!grpc_gcp_rpc_protocol_versions_encode_to_raw_bytes( - nullptr, encoded_bytes, encoded_length)); - GPR_ASSERT(!grpc_gcp_rpc_protocol_versions_encode_to_raw_bytes( - &version, nullptr, encoded_length)); - GPR_ASSERT(!grpc_gcp_rpc_protocol_versions_encode_to_raw_bytes( - &version, encoded_bytes, 0)); - GPR_ASSERT(!grpc_gcp_rpc_protocol_versions_encode(nullptr, &encoded_slice)); - GPR_ASSERT(!grpc_gcp_rpc_protocol_versions_encode(&version, nullptr)); - GPR_ASSERT(!grpc_gcp_rpc_protocol_versions_decode(encoded_slice, nullptr)); - /* Test for nanopb decode. */ - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_encode(&version, &encoded_slice)); - grpc_slice bad_slice = grpc_slice_split_head( - &encoded_slice, GRPC_SLICE_LENGTH(encoded_slice) - 1); - grpc_slice_unref(encoded_slice); - GPR_ASSERT( - !grpc_gcp_rpc_protocol_versions_decode(bad_slice, &decoded_version)); - grpc_slice_unref(bad_slice); - gpr_free(encoded_bytes); -} - -static void test_copy() { - grpc_gcp_rpc_protocol_versions src; - grpc_gcp_rpc_protocol_versions des; - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_max(&src, kMaxRpcVersionMajor, - kMaxRpcVersionMinor)); - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_min(&src, kMinRpcVersionMajor, - kMinRpcVersionMinor)); - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_copy(&src, &des)); - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_equal(&src, &des)); -} - -static void test_check_success() { - grpc_gcp_rpc_protocol_versions v1; - grpc_gcp_rpc_protocol_versions v2; - grpc_gcp_rpc_protocol_versions_version highest_common_version; - /* test equality. */ - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_max(&v1, kMaxRpcVersionMajor, - kMaxRpcVersionMinor)); - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_min(&v1, kMaxRpcVersionMajor, - kMaxRpcVersionMinor)); - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_max(&v2, kMaxRpcVersionMajor, - kMaxRpcVersionMinor)); - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_min(&v2, kMaxRpcVersionMajor, - kMaxRpcVersionMinor)); - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_check( - (const grpc_gcp_rpc_protocol_versions*)&v1, - (const grpc_gcp_rpc_protocol_versions*)&v2, - &highest_common_version) == 1); - GPR_ASSERT(grpc_core::internal::grpc_gcp_rpc_protocol_version_compare( - &highest_common_version, &v1.max_rpc_version) == 0); - - /* test inequality. */ - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_max(&v1, kMaxRpcVersionMajor, - kMaxRpcVersionMinor)); - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_min(&v1, kMinRpcVersionMinor, - kMinRpcVersionMinor)); - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_max(&v2, kMaxRpcVersionMajor, - kMinRpcVersionMinor)); - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_min(&v2, kMinRpcVersionMajor, - kMaxRpcVersionMinor)); - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_check( - (const grpc_gcp_rpc_protocol_versions*)&v1, - (const grpc_gcp_rpc_protocol_versions*)&v2, - &highest_common_version) == 1); - GPR_ASSERT(grpc_core::internal::grpc_gcp_rpc_protocol_version_compare( - &highest_common_version, &v2.max_rpc_version) == 0); -} - -static void test_check_failure() { - grpc_gcp_rpc_protocol_versions v1; - grpc_gcp_rpc_protocol_versions v2; - grpc_gcp_rpc_protocol_versions_version highest_common_version; - - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_max(&v1, kMinRpcVersionMajor, - kMinRpcVersionMinor)); - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_min(&v1, kMinRpcVersionMajor, - kMinRpcVersionMinor)); - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_max(&v2, kMaxRpcVersionMajor, - kMaxRpcVersionMinor)); - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_min(&v2, kMaxRpcVersionMajor, - kMaxRpcVersionMinor)); - GPR_ASSERT(grpc_gcp_rpc_protocol_versions_check( - (const grpc_gcp_rpc_protocol_versions*)&v1, - (const grpc_gcp_rpc_protocol_versions*)&v2, - &highest_common_version) == 0); -} - -int main(int argc, char** argv) { - /* Run tests. */ - test_success(); - test_failure(); - test_copy(); - test_check_success(); - test_check_failure(); - return 0; -} diff --git a/test/core/tsi/alts/zero_copy_frame_protector/BUILD b/test/core/tsi/alts/zero_copy_frame_protector/BUILD deleted file mode 100644 index 80f4572d94..0000000000 --- a/test/core/tsi/alts/zero_copy_frame_protector/BUILD +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright 2018 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_package") - -licenses(["notice"]) # Apache v2 - -grpc_package(name = "zero_copy_frame_protector") - -grpc_cc_test( - name = "alts_grpc_record_protocol_test", - srcs = ["alts_grpc_record_protocol_test.cc"], - language = "C++", - deps = [ - "//:grpc", - "//test/core/tsi/alts/crypt:alts_crypt_test_util", - ], -) - -grpc_cc_test( - name = "alts_iovec_record_protocol_test", - srcs = ["alts_iovec_record_protocol_test.cc"], - language = "C++", - deps = [ - "//:grpc", - "//test/core/tsi/alts/crypt:alts_crypt_test_util", - ], -) - -grpc_cc_test( - name = "alts_zero_copy_grpc_protector_test", - srcs = ["alts_zero_copy_grpc_protector_test.cc"], - language = "C++", - deps = [ - "//:grpc", - "//test/core/tsi/alts/crypt:alts_crypt_test_util", - ], -) diff --git a/test/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_test.cc b/test/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_test.cc deleted file mode 100644 index fbbea71cb7..0000000000 --- a/test/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_test.cc +++ /dev/null @@ -1,449 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include - -#include "src/core/lib/slice/slice_internal.h" -#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h" -#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h" -#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h" -#include "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h" -#include "test/core/tsi/alts/crypt/gsec_test_util.h" - -constexpr size_t kMaxSliceLength = 256; -constexpr size_t kMaxSlices = 10; -constexpr size_t kSealRepeatTimes = 5; -constexpr size_t kTagLength = 16; - -/* Test fixtures for each test cases. */ -struct alts_grpc_record_protocol_test_fixture { - alts_grpc_record_protocol* client_protect; - alts_grpc_record_protocol* client_unprotect; - alts_grpc_record_protocol* server_protect; - alts_grpc_record_protocol* server_unprotect; -}; - -/* Test input variables for protect/unprotect operations. */ -struct alts_grpc_record_protocol_test_var { - size_t header_length; - size_t tag_length; - grpc_slice_buffer original_sb; - grpc_slice_buffer duplicate_sb; - grpc_slice_buffer protected_sb; - grpc_slice_buffer unprotected_sb; -}; - -/* --- Test utility functions. --- */ - -static void create_random_slice_buffer(grpc_slice_buffer* sb) { - GPR_ASSERT(sb != nullptr); - size_t slice_count = gsec_test_bias_random_uint32(kMaxSlices) + 1; - for (size_t i = 0; i < slice_count; i++) { - size_t slice_length = gsec_test_bias_random_uint32(kMaxSliceLength) + 1; - grpc_slice slice = GRPC_SLICE_MALLOC(slice_length); - gsec_test_random_bytes(GRPC_SLICE_START_PTR(slice), slice_length); - grpc_slice_buffer_add(sb, slice); - } -} - -static uint8_t* pointer_to_nth_byte(grpc_slice_buffer* sb, size_t index) { - GPR_ASSERT(sb != nullptr); - GPR_ASSERT(index < sb->length); - for (size_t i = 0; i < sb->count; i++) { - if (index < GRPC_SLICE_LENGTH(sb->slices[i])) { - return GRPC_SLICE_START_PTR(sb->slices[i]) + index; - } else { - index -= GRPC_SLICE_LENGTH(sb->slices[i]); - } - } - return nullptr; -} - -/* Checks if two slice buffer contents are the same. It is not super efficient, - * but OK for testing. */ -static bool are_slice_buffers_equal(grpc_slice_buffer* first, - grpc_slice_buffer* second) { - GPR_ASSERT(first != nullptr); - GPR_ASSERT(second != nullptr); - if (first->length != second->length) { - return false; - } - for (size_t i = 0; i < first->length; i++) { - uint8_t* first_ptr = pointer_to_nth_byte(first, i); - uint8_t* second_ptr = pointer_to_nth_byte(second, i); - GPR_ASSERT(first_ptr != nullptr); - GPR_ASSERT(second_ptr != nullptr); - if ((*first_ptr) != (*second_ptr)) { - return false; - } - } - return true; -} - -static void alter_random_byte(grpc_slice_buffer* sb) { - GPR_ASSERT(sb != nullptr); - if (sb->length == 0) { - return; - } - uint32_t offset = - gsec_test_bias_random_uint32(static_cast(sb->length)); - uint8_t* ptr = pointer_to_nth_byte(sb, offset); - (*ptr)++; -} - -static alts_grpc_record_protocol_test_fixture* -test_fixture_integrity_only_create(bool rekey) { - alts_grpc_record_protocol_test_fixture* fixture = - static_cast( - gpr_zalloc(sizeof(alts_grpc_record_protocol_test_fixture))); - size_t key_length = rekey ? kAes128GcmRekeyKeyLength : kAes128GcmKeyLength; - uint8_t* key; - gsec_test_random_array(&key, key_length); - gsec_aead_crypter* crypter = nullptr; - - /* Create client record protocol for protect. */ - GPR_ASSERT(gsec_aes_gcm_aead_crypter_create( - key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey, - &crypter, nullptr) == GRPC_STATUS_OK); - GPR_ASSERT(alts_grpc_integrity_only_record_protocol_create( - crypter, 8, /*is_client=*/true, /*is_protect=*/true, - &fixture->client_protect) == TSI_OK); - /* Create client record protocol for unprotect. */ - GPR_ASSERT(gsec_aes_gcm_aead_crypter_create( - key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey, - &crypter, nullptr) == GRPC_STATUS_OK); - GPR_ASSERT(alts_grpc_integrity_only_record_protocol_create( - crypter, 8, /*is_client=*/true, /*is_protect=*/false, - &fixture->client_unprotect) == TSI_OK); - /* Create server record protocol for protect. */ - GPR_ASSERT(gsec_aes_gcm_aead_crypter_create( - key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey, - &crypter, nullptr) == GRPC_STATUS_OK); - GPR_ASSERT(alts_grpc_integrity_only_record_protocol_create( - crypter, 8, /*is_client=*/false, /*is_protect=*/true, - &fixture->server_protect) == TSI_OK); - /* Create server record protocol for unprotect. */ - GPR_ASSERT(gsec_aes_gcm_aead_crypter_create( - key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey, - &crypter, nullptr) == GRPC_STATUS_OK); - GPR_ASSERT(alts_grpc_integrity_only_record_protocol_create( - crypter, 8, /*is_client=*/false, /*is_protect=*/false, - &fixture->server_unprotect) == TSI_OK); - - gpr_free(key); - return fixture; -} - -static alts_grpc_record_protocol_test_fixture* -test_fixture_integrity_only_no_rekey_create() { - return test_fixture_integrity_only_create(false); -} - -static alts_grpc_record_protocol_test_fixture* -test_fixture_integrity_only_rekey_create() { - return test_fixture_integrity_only_create(true); -} - -static alts_grpc_record_protocol_test_fixture* -test_fixture_privacy_integrity_create(bool rekey) { - alts_grpc_record_protocol_test_fixture* fixture = - static_cast( - gpr_zalloc(sizeof(alts_grpc_record_protocol_test_fixture))); - size_t key_length = rekey ? kAes128GcmRekeyKeyLength : kAes128GcmKeyLength; - uint8_t* key; - gsec_test_random_array(&key, key_length); - gsec_aead_crypter* crypter = nullptr; - - /* Create client record protocol for protect. */ - GPR_ASSERT(gsec_aes_gcm_aead_crypter_create( - key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey, - &crypter, nullptr) == GRPC_STATUS_OK); - GPR_ASSERT(alts_grpc_privacy_integrity_record_protocol_create( - crypter, 8, /*is_client=*/true, /*is_protect=*/true, - &fixture->client_protect) == TSI_OK); - /* Create client record protocol for unprotect. */ - GPR_ASSERT(gsec_aes_gcm_aead_crypter_create( - key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey, - &crypter, nullptr) == GRPC_STATUS_OK); - GPR_ASSERT(alts_grpc_privacy_integrity_record_protocol_create( - crypter, 8, /*is_client=*/true, /*is_protect=*/false, - &fixture->client_unprotect) == TSI_OK); - /* Create server record protocol for protect. */ - GPR_ASSERT(gsec_aes_gcm_aead_crypter_create( - key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey, - &crypter, nullptr) == GRPC_STATUS_OK); - GPR_ASSERT(alts_grpc_privacy_integrity_record_protocol_create( - crypter, 8, /*is_client=*/false, /*is_protect=*/true, - &fixture->server_protect) == TSI_OK); - /* Create server record protocol for unprotect. */ - GPR_ASSERT(gsec_aes_gcm_aead_crypter_create( - key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey, - &crypter, nullptr) == GRPC_STATUS_OK); - GPR_ASSERT(alts_grpc_privacy_integrity_record_protocol_create( - crypter, 8, /*is_client=*/false, /*is_protect=*/false, - &fixture->server_unprotect) == TSI_OK); - - gpr_free(key); - return fixture; -} - -static alts_grpc_record_protocol_test_fixture* -test_fixture_privacy_integrity_no_rekey_create() { - return test_fixture_privacy_integrity_create(false); -} - -static alts_grpc_record_protocol_test_fixture* -test_fixture_privacy_integrity_rekey_create() { - return test_fixture_privacy_integrity_create(true); -} - -static void alts_grpc_record_protocol_test_fixture_destroy( - alts_grpc_record_protocol_test_fixture* fixture) { - if (fixture == nullptr) { - return; - } - grpc_core::ExecCtx exec_ctx; - alts_grpc_record_protocol_destroy(fixture->client_protect); - alts_grpc_record_protocol_destroy(fixture->client_unprotect); - alts_grpc_record_protocol_destroy(fixture->server_protect); - alts_grpc_record_protocol_destroy(fixture->server_unprotect); - grpc_core::ExecCtx::Get()->Flush(); - gpr_free(fixture); -} - -static alts_grpc_record_protocol_test_var* -alts_grpc_record_protocol_test_var_create() { - alts_grpc_record_protocol_test_var* var = - static_cast( - gpr_zalloc(sizeof(alts_grpc_record_protocol_test_var))); - var->header_length = alts_iovec_record_protocol_get_header_length(); - var->tag_length = kTagLength; - /* Initialized slice buffers. */ - grpc_slice_buffer_init(&var->original_sb); - grpc_slice_buffer_init(&var->duplicate_sb); - grpc_slice_buffer_init(&var->protected_sb); - grpc_slice_buffer_init(&var->unprotected_sb); - /* Randomly sets content of original_sb, and copies into duplicate_sb. */ - create_random_slice_buffer(&var->original_sb); - for (size_t i = 0; i < var->original_sb.count; i++) { - grpc_slice_buffer_add(&var->duplicate_sb, - grpc_slice_ref(var->original_sb.slices[i])); - } - return var; -} - -static void alts_grpc_record_protocol_test_var_destroy( - alts_grpc_record_protocol_test_var* var) { - if (var == nullptr) { - return; - } - grpc_slice_buffer_destroy_internal(&var->original_sb); - grpc_slice_buffer_destroy_internal(&var->duplicate_sb); - grpc_slice_buffer_destroy_internal(&var->protected_sb); - grpc_slice_buffer_destroy_internal(&var->unprotected_sb); - gpr_free(var); -} - -/* --- alts grpc record protocol tests. --- */ - -static void random_seal_unseal(alts_grpc_record_protocol* sender, - alts_grpc_record_protocol* receiver) { - grpc_core::ExecCtx exec_ctx; - for (size_t i = 0; i < kSealRepeatTimes; i++) { - alts_grpc_record_protocol_test_var* var = - alts_grpc_record_protocol_test_var_create(); - /* Seals and then unseals. */ - size_t data_length = var->original_sb.length; - tsi_result status = alts_grpc_record_protocol_protect( - sender, &var->original_sb, &var->protected_sb); - GPR_ASSERT(status == TSI_OK); - GPR_ASSERT(var->protected_sb.length == - data_length + var->header_length + var->tag_length); - status = alts_grpc_record_protocol_unprotect(receiver, &var->protected_sb, - &var->unprotected_sb); - GPR_ASSERT(status == TSI_OK); - GPR_ASSERT( - are_slice_buffers_equal(&var->unprotected_sb, &var->duplicate_sb)); - alts_grpc_record_protocol_test_var_destroy(var); - } - grpc_core::ExecCtx::Get()->Flush(); -} - -static void empty_seal_unseal(alts_grpc_record_protocol* sender, - alts_grpc_record_protocol* receiver) { - grpc_core::ExecCtx exec_ctx; - for (size_t i = 0; i < kSealRepeatTimes; i++) { - alts_grpc_record_protocol_test_var* var = - alts_grpc_record_protocol_test_var_create(); - /* Seals and then unseals empty payload. */ - grpc_slice_buffer_reset_and_unref_internal(&var->original_sb); - grpc_slice_buffer_reset_and_unref_internal(&var->duplicate_sb); - tsi_result status = alts_grpc_record_protocol_protect( - sender, &var->original_sb, &var->protected_sb); - GPR_ASSERT(status == TSI_OK); - GPR_ASSERT(var->protected_sb.length == - var->header_length + var->tag_length); - status = alts_grpc_record_protocol_unprotect(receiver, &var->protected_sb, - &var->unprotected_sb); - GPR_ASSERT(status == TSI_OK); - GPR_ASSERT( - are_slice_buffers_equal(&var->unprotected_sb, &var->duplicate_sb)); - alts_grpc_record_protocol_test_var_destroy(var); - } - grpc_core::ExecCtx::Get()->Flush(); -} - -static void unsync_seal_unseal(alts_grpc_record_protocol* sender, - alts_grpc_record_protocol* receiver) { - grpc_core::ExecCtx exec_ctx; - tsi_result status; - alts_grpc_record_protocol_test_var* var = - alts_grpc_record_protocol_test_var_create(); - /* Seals once. */ - status = alts_grpc_record_protocol_protect(sender, &var->original_sb, - &var->protected_sb); - GPR_ASSERT(status == TSI_OK); - grpc_slice_buffer_reset_and_unref_internal(&var->protected_sb); - /* Seals again. */ - status = alts_grpc_record_protocol_protect(sender, &var->duplicate_sb, - &var->protected_sb); - GPR_ASSERT(status == TSI_OK); - /* Unseals the second frame. */ - status = alts_grpc_record_protocol_unprotect(receiver, &var->protected_sb, - &var->unprotected_sb); - GPR_ASSERT(status == TSI_INTERNAL_ERROR); - alts_grpc_record_protocol_test_var_destroy(var); - grpc_core::ExecCtx::Get()->Flush(); -} - -static void corrupted_data(alts_grpc_record_protocol* sender, - alts_grpc_record_protocol* receiver) { - grpc_core::ExecCtx exec_ctx; - tsi_result status; - alts_grpc_record_protocol_test_var* var = - alts_grpc_record_protocol_test_var_create(); - /* Seals once. */ - status = alts_grpc_record_protocol_protect(sender, &var->original_sb, - &var->protected_sb); - GPR_ASSERT(status == TSI_OK); - /* Corrupts one byte in protected_sb and tries to unprotect. */ - alter_random_byte(&var->protected_sb); - status = alts_grpc_record_protocol_unprotect(receiver, &var->protected_sb, - &var->unprotected_sb); - GPR_ASSERT(status == TSI_INTERNAL_ERROR); - alts_grpc_record_protocol_test_var_destroy(var); - grpc_core::ExecCtx::Get()->Flush(); -} - -static void input_check(alts_grpc_record_protocol* rp) { - grpc_core::ExecCtx exec_ctx; - tsi_result status; - alts_grpc_record_protocol_test_var* var = - alts_grpc_record_protocol_test_var_create(); - /* Protects with nullptr input. */ - status = alts_grpc_record_protocol_protect(rp, nullptr, &var->protected_sb); - GPR_ASSERT(status == TSI_INVALID_ARGUMENT); - status = alts_grpc_record_protocol_protect(rp, &var->original_sb, nullptr); - GPR_ASSERT(status == TSI_INVALID_ARGUMENT); - /* Unprotects with nullptr input. */ - status = alts_grpc_record_protocol_protect(rp, &var->original_sb, - &var->protected_sb); - GPR_ASSERT(status == TSI_OK); - status = - alts_grpc_record_protocol_unprotect(rp, nullptr, &var->unprotected_sb); - GPR_ASSERT(status == TSI_INVALID_ARGUMENT); - status = alts_grpc_record_protocol_unprotect(rp, &var->protected_sb, nullptr); - GPR_ASSERT(status == TSI_INVALID_ARGUMENT); - /* Unprotects on a temporary slice buffer which length is smaller than header - * length plus tag length. */ - grpc_slice_buffer temp_sb; - grpc_slice_buffer_init(&temp_sb); - grpc_slice_buffer_move_first( - &var->protected_sb, var->header_length + var->tag_length - 1, &temp_sb); - status = - alts_grpc_record_protocol_unprotect(rp, &temp_sb, &var->unprotected_sb); - GPR_ASSERT(status == TSI_INVALID_ARGUMENT); - grpc_slice_buffer_destroy_internal(&temp_sb); - alts_grpc_record_protocol_test_var_destroy(var); - grpc_core::ExecCtx::Get()->Flush(); -} - -/* --- Test cases. --- */ - -static void alts_grpc_record_protocol_random_seal_unseal_tests( - alts_grpc_record_protocol_test_fixture* fixture) { - random_seal_unseal(fixture->client_protect, fixture->server_unprotect); - random_seal_unseal(fixture->server_protect, fixture->client_unprotect); -} - -static void alts_grpc_record_protocol_empty_seal_unseal_tests( - alts_grpc_record_protocol_test_fixture* fixture) { - empty_seal_unseal(fixture->client_protect, fixture->server_unprotect); - empty_seal_unseal(fixture->server_protect, fixture->client_unprotect); -} - -static void alts_grpc_record_protocol_unsync_seal_unseal_tests( - alts_grpc_record_protocol_test_fixture* fixture) { - unsync_seal_unseal(fixture->client_protect, fixture->server_unprotect); - unsync_seal_unseal(fixture->server_protect, fixture->client_unprotect); -} - -static void alts_grpc_record_protocol_corrupted_data_tests( - alts_grpc_record_protocol_test_fixture* fixture) { - corrupted_data(fixture->client_protect, fixture->server_unprotect); - corrupted_data(fixture->server_protect, fixture->client_unprotect); -} - -static void alts_grpc_record_protocol_input_check_tests( - alts_grpc_record_protocol_test_fixture* fixture) { - input_check(fixture->client_protect); -} - -static void alts_grpc_record_protocol_tests( - alts_grpc_record_protocol_test_fixture* (*fixture_create)()) { - auto* fixture_1 = fixture_create(); - alts_grpc_record_protocol_random_seal_unseal_tests(fixture_1); - alts_grpc_record_protocol_test_fixture_destroy(fixture_1); - - auto* fixture_2 = fixture_create(); - alts_grpc_record_protocol_empty_seal_unseal_tests(fixture_2); - alts_grpc_record_protocol_test_fixture_destroy(fixture_2); - - auto* fixture_3 = fixture_create(); - alts_grpc_record_protocol_unsync_seal_unseal_tests(fixture_3); - alts_grpc_record_protocol_test_fixture_destroy(fixture_3); - - auto* fixture_4 = fixture_create(); - alts_grpc_record_protocol_corrupted_data_tests(fixture_4); - alts_grpc_record_protocol_test_fixture_destroy(fixture_4); - - auto* fixture_5 = fixture_create(); - alts_grpc_record_protocol_input_check_tests(fixture_5); - alts_grpc_record_protocol_test_fixture_destroy(fixture_5); -} - -int main(int argc, char** argv) { - alts_grpc_record_protocol_tests(&test_fixture_integrity_only_no_rekey_create); - alts_grpc_record_protocol_tests(&test_fixture_integrity_only_rekey_create); - alts_grpc_record_protocol_tests( - &test_fixture_privacy_integrity_no_rekey_create); - alts_grpc_record_protocol_tests(&test_fixture_privacy_integrity_rekey_create); - - return 0; -} diff --git a/test/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol_test.cc b/test/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol_test.cc deleted file mode 100644 index db1934bbae..0000000000 --- a/test/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol_test.cc +++ /dev/null @@ -1,928 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include - -#include "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h" -#include "test/core/tsi/alts/crypt/gsec_test_util.h" - -constexpr size_t kMaxDataSize = 1024; -constexpr size_t kMaxSlices = 10; -constexpr size_t kSealRepeatTimes = 5; -constexpr size_t kTagLength = 16; - -/* Test fixtures for each test cases. */ -struct alts_iovec_record_protocol_test_fixture { - alts_iovec_record_protocol* client_protect; - alts_iovec_record_protocol* client_unprotect; - alts_iovec_record_protocol* server_protect; - alts_iovec_record_protocol* server_unprotect; -}; - -/* Test variables for protect/unprotect operations. */ -struct alts_iovec_record_protocol_test_var { - uint8_t* header_buf; - size_t header_length; - iovec_t header_iovec; - uint8_t* tag_buf; - size_t tag_length; - iovec_t tag_iovec; - uint8_t* data_buf; - uint8_t* dup_buf; - size_t data_length; - iovec_t* data_iovec; - size_t data_iovec_length; - uint8_t* protected_buf; - iovec_t protected_iovec; - iovec_t unprotected_iovec; -}; - -/* --- Test utility functions. --- */ - -static void randomly_slice(uint8_t* input, size_t input_length, - iovec_t** output, size_t* output_length) { - if (input_length == 0) { - *output = nullptr; - *output_length = 0; - return; - } - *output_length = gsec_test_bias_random_uint32(kMaxSlices) + 1; - *output = static_cast(gpr_malloc(*output_length * sizeof(iovec_t))); - for (size_t i = 0; i < *output_length - 1; i++) { - size_t slice_length = - gsec_test_bias_random_uint32(static_cast(input_length)); - iovec_t slice = {input, slice_length}; - (*output)[i] = slice; - input += slice_length; - input_length -= slice_length; - } - iovec_t slice = {input, input_length}; - (*output)[*output_length - 1] = slice; -} - -static size_t alter_random_byte(uint8_t* buf, size_t buf_length) { - GPR_ASSERT(buf != nullptr); - uint32_t offset = - gsec_test_bias_random_uint32(static_cast(buf_length)); - (*(buf + offset))++; - return offset; -} - -static void revert_back_alter(uint8_t* buf, size_t offset) { - GPR_ASSERT(buf != nullptr); - (*(buf + offset))--; -} - -static alts_iovec_record_protocol_test_fixture* -alts_iovec_record_protocol_test_fixture_create(bool rekey, - bool integrity_only) { - alts_iovec_record_protocol_test_fixture* fixture = - static_cast( - gpr_malloc(sizeof(alts_iovec_record_protocol_test_fixture))); - size_t overflow_size = 8; - size_t key_length = rekey ? kAes128GcmRekeyKeyLength : kAes128GcmKeyLength; - uint8_t* key; - gsec_test_random_array(&key, key_length); - gsec_aead_crypter* crypter = nullptr; - /* Create client record protocol for protect. */ - GPR_ASSERT(gsec_aes_gcm_aead_crypter_create( - key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey, - &crypter, nullptr) == GRPC_STATUS_OK); - GPR_ASSERT(alts_iovec_record_protocol_create( - crypter, overflow_size, /*is_client=*/true, integrity_only, - /*is_protect=*/true, &fixture->client_protect, - nullptr) == GRPC_STATUS_OK); - /* Create client record protocol for unprotect. */ - GPR_ASSERT(gsec_aes_gcm_aead_crypter_create( - key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey, - &crypter, nullptr) == GRPC_STATUS_OK); - GPR_ASSERT(alts_iovec_record_protocol_create( - crypter, overflow_size, /*is_client=*/true, integrity_only, - /*is_protect=*/false, &fixture->client_unprotect, - nullptr) == GRPC_STATUS_OK); - /* Create server record protocol for protect. */ - GPR_ASSERT(gsec_aes_gcm_aead_crypter_create( - key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey, - &crypter, nullptr) == GRPC_STATUS_OK); - GPR_ASSERT(alts_iovec_record_protocol_create( - crypter, overflow_size, /*is_client=*/false, integrity_only, - /*is_protect=*/true, &fixture->server_protect, - nullptr) == GRPC_STATUS_OK); - /* Create server record protocol for unprotect. */ - GPR_ASSERT(gsec_aes_gcm_aead_crypter_create( - key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey, - &crypter, nullptr) == GRPC_STATUS_OK); - GPR_ASSERT(alts_iovec_record_protocol_create( - crypter, overflow_size, /*is_client=*/false, integrity_only, - /*is_protect=*/false, &fixture->server_unprotect, - nullptr) == GRPC_STATUS_OK); - - gpr_free(key); - return fixture; -} - -static void alts_iovec_record_protocol_test_fixture_destroy( - alts_iovec_record_protocol_test_fixture* fixture) { - if (fixture == nullptr) { - return; - } - alts_iovec_record_protocol_destroy(fixture->client_protect); - alts_iovec_record_protocol_destroy(fixture->client_unprotect); - alts_iovec_record_protocol_destroy(fixture->server_protect); - alts_iovec_record_protocol_destroy(fixture->server_unprotect); - gpr_free(fixture); -} - -static alts_iovec_record_protocol_test_var* -alts_iovec_record_protocol_test_var_create() { - auto* var = static_cast( - gpr_zalloc(sizeof(alts_iovec_record_protocol_test_var))); - /* Sets header buffer. */ - var->header_length = alts_iovec_record_protocol_get_header_length(); - var->header_buf = static_cast(gpr_malloc(var->header_length)); - var->header_iovec.iov_base = var->header_buf; - var->header_iovec.iov_len = var->header_length; - /* Sets tag buffer. */ - var->tag_length = kTagLength; - var->tag_buf = static_cast(gpr_malloc(var->tag_length)); - var->tag_iovec.iov_base = var->tag_buf; - var->tag_iovec.iov_len = var->tag_length; - /* Randomly sets data buffer and duplicates to dup_buf. */ - var->data_length = gsec_test_bias_random_uint32(kMaxDataSize) + 1; - var->data_buf = static_cast(gpr_malloc(var->data_length)); - gsec_test_random_bytes(var->data_buf, var->data_length); - gsec_test_copy(var->data_buf, &var->dup_buf, var->data_length); - var->data_iovec = nullptr; - var->data_iovec_length = 0; - randomly_slice(var->data_buf, var->data_length, &var->data_iovec, - &var->data_iovec_length); - /* Sets protected iovec. */ - size_t protected_buf_length = - var->header_length + var->data_length + var->tag_length; - var->protected_buf = static_cast(gpr_malloc(protected_buf_length)); - var->protected_iovec.iov_base = var->protected_buf; - var->protected_iovec.iov_len = protected_buf_length; - /* Unprotected iovec points to data_buf. */ - var->unprotected_iovec.iov_base = var->data_buf; - var->unprotected_iovec.iov_len = var->data_length; - return var; -} - -static void alts_iovec_record_protocol_test_var_destroy( - alts_iovec_record_protocol_test_var* var) { - if (var == nullptr) { - return; - } - gpr_free(var->header_buf); - gpr_free(var->tag_buf); - gpr_free(var->data_buf); - gpr_free(var->dup_buf); - gpr_free(var->data_iovec); - gpr_free(var->protected_buf); - gpr_free(var); -} - -/* --- Integrity-only protect/unprotect tests. --- */ - -static void integrity_only_random_seal_unseal( - alts_iovec_record_protocol* sender, alts_iovec_record_protocol* receiver) { - for (size_t i = 0; i < kSealRepeatTimes; i++) { - alts_iovec_record_protocol_test_var* var = - alts_iovec_record_protocol_test_var_create(); - /* Seals and then unseals. */ - grpc_status_code status = alts_iovec_record_protocol_integrity_only_protect( - sender, var->data_iovec, var->data_iovec_length, var->header_iovec, - var->tag_iovec, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - gpr_free(var->data_iovec); - /* Randomly slices data buffer again. */ - randomly_slice(var->data_buf, var->data_length, &var->data_iovec, - &var->data_iovec_length); - status = alts_iovec_record_protocol_integrity_only_unprotect( - receiver, var->data_iovec, var->data_iovec_length, var->header_iovec, - var->tag_iovec, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - /* Makes sure data buffer has not been modified during - * seal/unseal. */ - GPR_ASSERT(memcmp(var->data_buf, var->dup_buf, var->data_length) == 0); - alts_iovec_record_protocol_test_var_destroy(var); - } -} - -static void integrity_only_empty_seal_unseal( - alts_iovec_record_protocol* sender, alts_iovec_record_protocol* receiver) { - for (size_t i = 0; i < kSealRepeatTimes; i++) { - alts_iovec_record_protocol_test_var* var = - alts_iovec_record_protocol_test_var_create(); - /* Seals and then unseals empty payload. */ - grpc_status_code status = alts_iovec_record_protocol_integrity_only_protect( - sender, nullptr, 0, var->header_iovec, var->tag_iovec, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - status = alts_iovec_record_protocol_integrity_only_unprotect( - receiver, nullptr, 0, var->header_iovec, var->tag_iovec, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - alts_iovec_record_protocol_test_var_destroy(var); - } -} - -static void integrity_only_unsync_seal_unseal( - alts_iovec_record_protocol* sender, alts_iovec_record_protocol* receiver) { - /* Seals once. */ - alts_iovec_record_protocol_test_var* var = - alts_iovec_record_protocol_test_var_create(); - grpc_status_code status = alts_iovec_record_protocol_integrity_only_protect( - sender, var->data_iovec, var->data_iovec_length, var->header_iovec, - var->tag_iovec, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - alts_iovec_record_protocol_test_var_destroy(var); - /* Seals again. */ - var = alts_iovec_record_protocol_test_var_create(); - status = alts_iovec_record_protocol_integrity_only_protect( - sender, var->data_iovec, var->data_iovec_length, var->header_iovec, - var->tag_iovec, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - /* Unseals the second frame. */ - char* error_message = nullptr; - status = alts_iovec_record_protocol_integrity_only_unprotect( - receiver, var->data_iovec, var->data_iovec_length, var->header_iovec, - var->tag_iovec, &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INTERNAL, error_message, - "Frame tag verification failed.")); - gpr_free(error_message); - alts_iovec_record_protocol_test_var_destroy(var); -} - -static void integrity_only_corrupted_data( - alts_iovec_record_protocol* sender, alts_iovec_record_protocol* receiver) { - /* Seals the data first. */ - alts_iovec_record_protocol_test_var* var = - alts_iovec_record_protocol_test_var_create(); - grpc_status_code status = alts_iovec_record_protocol_integrity_only_protect( - sender, var->data_iovec, var->data_iovec_length, var->header_iovec, - var->tag_iovec, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - /* Alter frame length field. */ - char* error_message = nullptr; - size_t offset = - alter_random_byte(var->header_buf, kZeroCopyFrameLengthFieldSize); - status = alts_iovec_record_protocol_integrity_only_unprotect( - receiver, var->data_iovec, var->data_iovec_length, var->header_iovec, - var->tag_iovec, &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INTERNAL, error_message, "Bad frame length.")); - gpr_free(error_message); - revert_back_alter(var->header_buf, offset); - /* Alter message type field. */ - offset = alter_random_byte(var->header_buf + kZeroCopyFrameLengthFieldSize, - kZeroCopyFrameMessageTypeFieldSize); - status = alts_iovec_record_protocol_integrity_only_unprotect( - receiver, var->data_iovec, var->data_iovec_length, var->header_iovec, - var->tag_iovec, &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INTERNAL, error_message, - "Unsupported message type.")); - gpr_free(error_message); - revert_back_alter(var->header_buf + kZeroCopyFrameLengthFieldSize, offset); - /* Alter data. */ - offset = alter_random_byte(var->data_buf, var->data_length); - status = alts_iovec_record_protocol_integrity_only_unprotect( - receiver, var->data_iovec, var->data_iovec_length, var->header_iovec, - var->tag_iovec, &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INTERNAL, error_message, - "Frame tag verification failed.")); - gpr_free(error_message); - revert_back_alter(var->data_buf, offset); - /* Alter tag. */ - offset = alter_random_byte(var->tag_buf, var->tag_length); - status = alts_iovec_record_protocol_integrity_only_unprotect( - receiver, var->data_iovec, var->data_iovec_length, var->header_iovec, - var->tag_iovec, &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INTERNAL, error_message, - "Frame tag verification failed.")); - gpr_free(error_message); - revert_back_alter(var->tag_buf, offset); - /* Reverted protected data should be verified correctly. */ - status = alts_iovec_record_protocol_integrity_only_unprotect( - receiver, var->data_iovec, var->data_iovec_length, var->header_iovec, - var->tag_iovec, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(memcmp(var->data_buf, var->dup_buf, var->data_length) == 0); - alts_iovec_record_protocol_test_var_destroy(var); -} - -static void integrity_only_protect_input_check(alts_iovec_record_protocol* rp) { - alts_iovec_record_protocol_test_var* var = - alts_iovec_record_protocol_test_var_create(); - char* error_message = nullptr; - /* Header buffer is nullptr. */ - iovec_t header_iovec = {nullptr, var->header_length}; - grpc_status_code status = alts_iovec_record_protocol_integrity_only_protect( - rp, var->data_iovec, var->data_iovec_length, header_iovec, var->tag_iovec, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "Header is nullptr.")); - gpr_free(error_message); - /* Header buffer length is 0. */ - header_iovec.iov_base = var->header_buf; - header_iovec.iov_len = 0; - status = alts_iovec_record_protocol_integrity_only_protect( - rp, var->data_iovec, var->data_iovec_length, header_iovec, var->tag_iovec, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "Header length is incorrect.")); - gpr_free(error_message); - /* Tag buffer is nullptr. */ - iovec_t tag_iovec = {nullptr, var->tag_length}; - status = alts_iovec_record_protocol_integrity_only_protect( - rp, var->data_iovec, var->data_iovec_length, var->header_iovec, tag_iovec, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, "Tag is nullptr.")); - gpr_free(error_message); - /* Tag buffer length is 0. */ - tag_iovec.iov_base = var->tag_buf; - tag_iovec.iov_len = 0; - status = alts_iovec_record_protocol_integrity_only_protect( - rp, var->data_iovec, var->data_iovec_length, var->header_iovec, tag_iovec, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "Tag length is incorrect.")); - gpr_free(error_message); - alts_iovec_record_protocol_test_var_destroy(var); -} - -static void integrity_only_unprotect_input_check( - alts_iovec_record_protocol* rp) { - alts_iovec_record_protocol_test_var* var = - alts_iovec_record_protocol_test_var_create(); - char* error_message = nullptr; - /* Header buffer is nullptr. */ - iovec_t header_iovec = {nullptr, var->header_length}; - grpc_status_code status = alts_iovec_record_protocol_integrity_only_unprotect( - rp, var->data_iovec, var->data_iovec_length, header_iovec, var->tag_iovec, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "Header is nullptr.")); - gpr_free(error_message); - /* Header buffer length is 0. */ - header_iovec.iov_base = var->header_buf; - header_iovec.iov_len = 0; - status = alts_iovec_record_protocol_integrity_only_unprotect( - rp, var->data_iovec, var->data_iovec_length, header_iovec, var->tag_iovec, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "Header length is incorrect.")); - gpr_free(error_message); - /* Tag buffer is nullptr. */ - iovec_t tag_iovec = {nullptr, var->tag_length}; - status = alts_iovec_record_protocol_integrity_only_unprotect( - rp, var->data_iovec, var->data_iovec_length, var->header_iovec, tag_iovec, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, "Tag is nullptr.")); - gpr_free(error_message); - /* Tag buffer length is 0. */ - tag_iovec.iov_base = var->tag_buf; - tag_iovec.iov_len = 0; - status = alts_iovec_record_protocol_integrity_only_unprotect( - rp, var->data_iovec, var->data_iovec_length, var->header_iovec, tag_iovec, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "Tag length is incorrect.")); - gpr_free(error_message); - alts_iovec_record_protocol_test_var_destroy(var); -} - -/* --- Privacy-integrity protect/unprotect tests. --- */ - -static void privacy_integrity_random_seal_unseal( - alts_iovec_record_protocol* sender, alts_iovec_record_protocol* receiver) { - for (size_t i = 0; i < kSealRepeatTimes; i++) { - alts_iovec_record_protocol_test_var* var = - alts_iovec_record_protocol_test_var_create(); - /* Seals and then unseals. */ - grpc_status_code status = - alts_iovec_record_protocol_privacy_integrity_protect( - sender, var->data_iovec, var->data_iovec_length, - var->protected_iovec, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - iovec_t header_iovec = {var->protected_buf, var->header_length}; - gpr_free(var->data_iovec); - /* Randomly slices protected buffer, excluding the header. */ - randomly_slice(var->protected_buf + var->header_length, - var->data_length + var->tag_length, &var->data_iovec, - &var->data_iovec_length); - status = alts_iovec_record_protocol_privacy_integrity_unprotect( - receiver, header_iovec, var->data_iovec, var->data_iovec_length, - var->unprotected_iovec, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - /* Makes sure unprotected data are the same as the original. */ - GPR_ASSERT(memcmp(var->data_buf, var->dup_buf, var->data_length) == 0); - alts_iovec_record_protocol_test_var_destroy(var); - } -} - -static void privacy_integrity_empty_seal_unseal( - alts_iovec_record_protocol* sender, alts_iovec_record_protocol* receiver) { - alts_iovec_record_protocol_test_var* var = - alts_iovec_record_protocol_test_var_create(); - size_t empty_payload_frame_size = var->header_length + var->tag_length; - auto* protected_buf = - static_cast(gpr_malloc(empty_payload_frame_size)); - for (size_t i = 0; i < kSealRepeatTimes; i++) { - iovec_t protected_iovec = {protected_buf, empty_payload_frame_size}; - iovec_t unprotected_iovec = {nullptr, 0}; - iovec_t data_iovec = {protected_buf + var->header_length, var->tag_length}; - /* Seals and then unseals empty payload. */ - grpc_status_code status = - alts_iovec_record_protocol_privacy_integrity_protect( - sender, nullptr, 0, protected_iovec, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - iovec_t header_iovec = {protected_buf, var->header_length}; - status = alts_iovec_record_protocol_privacy_integrity_unprotect( - receiver, header_iovec, &data_iovec, 1, unprotected_iovec, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - } - gpr_free(protected_buf); - alts_iovec_record_protocol_test_var_destroy(var); -} - -static void privacy_integrity_unsync_seal_unseal( - alts_iovec_record_protocol* sender, alts_iovec_record_protocol* receiver) { - /* Seals once. */ - alts_iovec_record_protocol_test_var* var = - alts_iovec_record_protocol_test_var_create(); - grpc_status_code status = - alts_iovec_record_protocol_privacy_integrity_protect( - sender, var->data_iovec, var->data_iovec_length, var->protected_iovec, - nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - alts_iovec_record_protocol_test_var_destroy(var); - /* Seals again. */ - var = alts_iovec_record_protocol_test_var_create(); - status = alts_iovec_record_protocol_privacy_integrity_protect( - sender, var->data_iovec, var->data_iovec_length, var->protected_iovec, - nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - /* Unseals the second frame. */ - char* error_message = nullptr; - iovec_t header_iovec = {var->protected_buf, var->header_length}; - iovec_t protected_iovec = {var->protected_buf + var->header_length, - var->data_length + var->tag_length}; - status = alts_iovec_record_protocol_privacy_integrity_unprotect( - receiver, header_iovec, &protected_iovec, 1, var->unprotected_iovec, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INTERNAL, error_message, "Frame decryption failed.")); - gpr_free(error_message); - alts_iovec_record_protocol_test_var_destroy(var); -} - -static void privacy_integrity_corrupted_data( - alts_iovec_record_protocol* sender, alts_iovec_record_protocol* receiver) { - /* Seals the data first. */ - alts_iovec_record_protocol_test_var* var = - alts_iovec_record_protocol_test_var_create(); - grpc_status_code status = - alts_iovec_record_protocol_privacy_integrity_protect( - sender, var->data_iovec, var->data_iovec_length, var->protected_iovec, - nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - char* error_message = nullptr; - uint8_t* header_buf = var->protected_buf; - size_t header_length = var->header_length; - iovec_t header_iovec = {header_buf, header_length}; - /* The following protected_buf and protected_length excludes header. */ - uint8_t* protected_buf = var->protected_buf + var->header_length; - size_t protected_length = var->data_length + var->tag_length; - iovec_t protected_iovec = {protected_buf, protected_length}; - /* Alter frame length field. */ - size_t offset = alter_random_byte(header_buf, kZeroCopyFrameLengthFieldSize); - status = alts_iovec_record_protocol_privacy_integrity_unprotect( - receiver, header_iovec, &protected_iovec, 1, var->unprotected_iovec, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INTERNAL, error_message, "Bad frame length.")); - gpr_free(error_message); - revert_back_alter(header_buf, offset); - /* Alter message type field. */ - offset = alter_random_byte(header_buf + kZeroCopyFrameLengthFieldSize, - kZeroCopyFrameMessageTypeFieldSize); - status = alts_iovec_record_protocol_privacy_integrity_unprotect( - receiver, header_iovec, &protected_iovec, 1, var->unprotected_iovec, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INTERNAL, error_message, - "Unsupported message type.")); - gpr_free(error_message); - revert_back_alter(header_buf + kZeroCopyFrameLengthFieldSize, offset); - /* Alter protected data. */ - offset = alter_random_byte(protected_buf, protected_length); - status = alts_iovec_record_protocol_privacy_integrity_unprotect( - receiver, header_iovec, &protected_iovec, 1, var->unprotected_iovec, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INTERNAL, error_message, "Frame decryption failed.")); - gpr_free(error_message); - revert_back_alter(protected_buf, offset); - /* Reverted protected data should be verified correctly. */ - status = alts_iovec_record_protocol_privacy_integrity_unprotect( - receiver, header_iovec, &protected_iovec, 1, var->unprotected_iovec, - nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(memcmp(var->data_buf, var->dup_buf, var->data_length) == 0); - alts_iovec_record_protocol_test_var_destroy(var); -} - -static void privacy_integrity_protect_input_check( - alts_iovec_record_protocol* rp) { - alts_iovec_record_protocol_test_var* var = - alts_iovec_record_protocol_test_var_create(); - char* error_message = nullptr; - /* Protected output buffer is nullptr. */ - iovec_t protected_iovec = {nullptr, var->protected_iovec.iov_len}; - grpc_status_code status = - alts_iovec_record_protocol_privacy_integrity_protect( - rp, var->data_iovec, var->data_iovec_length, protected_iovec, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "Protected frame is nullptr.")); - gpr_free(error_message); - /* Protected output buffer length incorrect. */ - protected_iovec.iov_base = var->protected_buf; - protected_iovec.iov_len = var->header_length + var->data_length; - status = alts_iovec_record_protocol_privacy_integrity_protect( - rp, var->data_iovec, var->data_iovec_length, protected_iovec, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "Protected frame size is incorrect.")); - gpr_free(error_message); - alts_iovec_record_protocol_test_var_destroy(var); -} - -static void privacy_integrity_unprotect_input_check( - alts_iovec_record_protocol* rp) { - alts_iovec_record_protocol_test_var* var = - alts_iovec_record_protocol_test_var_create(); - char* error_message = nullptr; - /* Header buffer is nullptr. */ - iovec_t header_iovec = {var->protected_buf, var->header_length}; - iovec_t protected_iovec = {var->protected_buf + var->header_length, - var->data_length + var->tag_length}; - header_iovec.iov_base = nullptr; - grpc_status_code status = - alts_iovec_record_protocol_privacy_integrity_unprotect( - rp, header_iovec, &protected_iovec, 1, var->unprotected_iovec, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "Header is nullptr.")); - gpr_free(error_message); - header_iovec.iov_base = var->protected_buf; - /* Header buffer length is 0. */ - header_iovec.iov_len = 0; - status = alts_iovec_record_protocol_privacy_integrity_unprotect( - rp, header_iovec, &protected_iovec, 1, var->unprotected_iovec, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "Header length is incorrect.")); - gpr_free(error_message); - header_iovec.iov_len = var->header_length; - /* Unprotected output buffer length is incorrect. */ - iovec_t unprotected_iovec = {var->data_buf, var->data_length - 1}; - status = alts_iovec_record_protocol_privacy_integrity_unprotect( - rp, header_iovec, &protected_iovec, 1, unprotected_iovec, &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INVALID_ARGUMENT, error_message, - "Unprotected data size is incorrect.")); - gpr_free(error_message); - alts_iovec_record_protocol_test_var_destroy(var); -} - -/* --- Integrity-only and privacy-integrity mixed. --- */ - -static void record_protocol_wrong_mode( - alts_iovec_record_protocol* integrity_only_protect_rp, - alts_iovec_record_protocol* integrity_only_unprotect_rp, - alts_iovec_record_protocol* privacy_integrity_protect_rp, - alts_iovec_record_protocol* privacy_integrity_unprotect_rp) { - alts_iovec_record_protocol_test_var* var = - alts_iovec_record_protocol_test_var_create(); - grpc_status_code status; - char* error_message = nullptr; - /* Call integrity-only protect on privacy-integrity record protocol. */ - status = alts_iovec_record_protocol_integrity_only_protect( - privacy_integrity_protect_rp, var->data_iovec, var->data_iovec_length, - var->header_iovec, var->tag_iovec, &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_FAILED_PRECONDITION, error_message, - "Integrity-only operations are not allowed for this object.")); - gpr_free(error_message); - /* Call integrity-only unprotect on privacy-integrity record protocol. */ - status = alts_iovec_record_protocol_integrity_only_unprotect( - privacy_integrity_unprotect_rp, var->data_iovec, var->data_iovec_length, - var->header_iovec, var->tag_iovec, &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_FAILED_PRECONDITION, error_message, - "Integrity-only operations are not allowed for this object.")); - gpr_free(error_message); - /* Call privacy-integrity protect on integrity-only record protocol. */ - status = alts_iovec_record_protocol_privacy_integrity_protect( - integrity_only_protect_rp, var->data_iovec, var->data_iovec_length, - var->protected_iovec, &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_FAILED_PRECONDITION, error_message, - "Privacy-integrity operations are not allowed for this object.")); - gpr_free(error_message); - /* Call privacy-integrity unprotect on integrity-only record protocol. */ - status = alts_iovec_record_protocol_privacy_integrity_unprotect( - integrity_only_unprotect_rp, var->header_iovec, var->data_iovec, - var->data_iovec_length, var->unprotected_iovec, &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_FAILED_PRECONDITION, error_message, - "Privacy-integrity operations are not allowed for this object.")); - gpr_free(error_message); - alts_iovec_record_protocol_test_var_destroy(var); -} - -static void integrity_seal_privacy_unseal( - alts_iovec_record_protocol* integrity_only_sender, - alts_iovec_record_protocol* privacy_integrity_receiver) { - alts_iovec_record_protocol_test_var* var = - alts_iovec_record_protocol_test_var_create(); - grpc_status_code status; - char* error_message = nullptr; - /* Seals with integrity-only protect. */ - status = alts_iovec_record_protocol_integrity_only_protect( - integrity_only_sender, var->data_iovec, var->data_iovec_length, - var->header_iovec, var->tag_iovec, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - /* Unseal with privacy-integrity unprotect. */ - memcpy(var->protected_buf, var->data_buf, var->data_length); - memcpy(var->protected_buf + var->data_length, var->tag_buf, var->tag_length); - iovec_t protected_iovec = {var->protected_buf, - var->data_length + var->tag_length}; - status = alts_iovec_record_protocol_privacy_integrity_unprotect( - privacy_integrity_receiver, var->header_iovec, &protected_iovec, 1, - var->unprotected_iovec, &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INTERNAL, error_message, "Frame decryption failed.")); - gpr_free(error_message); - alts_iovec_record_protocol_test_var_destroy(var); -} - -static void privacy_seal_integrity_unseal( - alts_iovec_record_protocol* privacy_integrity_sender, - alts_iovec_record_protocol* integrity_only_receiver) { - alts_iovec_record_protocol_test_var* var = - alts_iovec_record_protocol_test_var_create(); - grpc_status_code status; - char* error_message = nullptr; - /* Seals with privacy-integrity protect. */ - status = alts_iovec_record_protocol_privacy_integrity_protect( - privacy_integrity_sender, var->data_iovec, var->data_iovec_length, - var->protected_iovec, nullptr); - GPR_ASSERT(status == GRPC_STATUS_OK); - /* Unseal with integrity-only unprotect. */ - iovec_t header_iovec = {var->protected_buf, var->header_length}; - iovec_t data_iovec = {var->protected_buf + var->header_length, - var->data_length}; - iovec_t tag_iovec = { - var->protected_buf + var->header_length + var->data_length, - var->tag_length}; - status = alts_iovec_record_protocol_integrity_only_unprotect( - integrity_only_receiver, &data_iovec, 1, header_iovec, tag_iovec, - &error_message); - GPR_ASSERT(gsec_test_expect_compare_code_and_substr( - status, GRPC_STATUS_INTERNAL, error_message, - "Frame tag verification failed.")); - gpr_free(error_message); - alts_iovec_record_protocol_test_var_destroy(var); -} - -/* --- Test cases. --- */ - -static void alts_iovec_record_protocol_random_seal_unseal_tests() { - alts_iovec_record_protocol_test_fixture* fixture = - alts_iovec_record_protocol_test_fixture_create( - /*rekey=*/false, /*integrity_only=*/true); - integrity_only_random_seal_unseal(fixture->client_protect, - fixture->server_unprotect); - integrity_only_random_seal_unseal(fixture->server_protect, - fixture->client_unprotect); - alts_iovec_record_protocol_test_fixture_destroy(fixture); - - fixture = alts_iovec_record_protocol_test_fixture_create( - /*rekey=*/true, /*integrity_only=*/true); - integrity_only_random_seal_unseal(fixture->client_protect, - fixture->server_unprotect); - integrity_only_random_seal_unseal(fixture->server_protect, - fixture->client_unprotect); - alts_iovec_record_protocol_test_fixture_destroy(fixture); - - fixture = alts_iovec_record_protocol_test_fixture_create( - /*rekey=*/false, /*integrity_only=*/false); - privacy_integrity_random_seal_unseal(fixture->client_protect, - fixture->server_unprotect); - privacy_integrity_random_seal_unseal(fixture->server_protect, - fixture->client_unprotect); - alts_iovec_record_protocol_test_fixture_destroy(fixture); - - fixture = alts_iovec_record_protocol_test_fixture_create( - /*rekey=*/true, /*integrity_only=*/false); - privacy_integrity_random_seal_unseal(fixture->client_protect, - fixture->server_unprotect); - privacy_integrity_random_seal_unseal(fixture->server_protect, - fixture->client_unprotect); - alts_iovec_record_protocol_test_fixture_destroy(fixture); -} - -static void alts_iovec_record_protocol_empty_seal_unseal_tests() { - alts_iovec_record_protocol_test_fixture* fixture = - alts_iovec_record_protocol_test_fixture_create( - /*rekey=*/false, /*integrity_only=*/true); - integrity_only_empty_seal_unseal(fixture->client_protect, - fixture->server_unprotect); - integrity_only_empty_seal_unseal(fixture->server_protect, - fixture->client_unprotect); - alts_iovec_record_protocol_test_fixture_destroy(fixture); - - fixture = alts_iovec_record_protocol_test_fixture_create( - /*rekey=*/true, /*integrity_only=*/true); - integrity_only_empty_seal_unseal(fixture->client_protect, - fixture->server_unprotect); - integrity_only_empty_seal_unseal(fixture->server_protect, - fixture->client_unprotect); - alts_iovec_record_protocol_test_fixture_destroy(fixture); - - fixture = alts_iovec_record_protocol_test_fixture_create( - /*rekey=*/false, /*integrity_only=*/false); - privacy_integrity_empty_seal_unseal(fixture->client_protect, - fixture->server_unprotect); - privacy_integrity_empty_seal_unseal(fixture->server_protect, - fixture->client_unprotect); - alts_iovec_record_protocol_test_fixture_destroy(fixture); - - fixture = alts_iovec_record_protocol_test_fixture_create( - /*rekey=*/true, /*integrity_only=*/false); - privacy_integrity_empty_seal_unseal(fixture->client_protect, - fixture->server_unprotect); - privacy_integrity_empty_seal_unseal(fixture->server_protect, - fixture->client_unprotect); - alts_iovec_record_protocol_test_fixture_destroy(fixture); -} - -static void alts_iovec_record_protocol_unsync_seal_unseal_tests() { - alts_iovec_record_protocol_test_fixture* fixture = - alts_iovec_record_protocol_test_fixture_create( - /*rekey=*/false, /*integrity_only=*/true); - integrity_only_unsync_seal_unseal(fixture->client_protect, - fixture->server_unprotect); - integrity_only_unsync_seal_unseal(fixture->server_protect, - fixture->client_unprotect); - alts_iovec_record_protocol_test_fixture_destroy(fixture); - - fixture = alts_iovec_record_protocol_test_fixture_create( - /*rekey=*/true, /*integrity_only=*/true); - integrity_only_unsync_seal_unseal(fixture->client_protect, - fixture->server_unprotect); - integrity_only_unsync_seal_unseal(fixture->server_protect, - fixture->client_unprotect); - alts_iovec_record_protocol_test_fixture_destroy(fixture); - - fixture = alts_iovec_record_protocol_test_fixture_create( - /*rekey=*/false, /*integrity_only=*/false); - privacy_integrity_unsync_seal_unseal(fixture->client_protect, - fixture->server_unprotect); - privacy_integrity_unsync_seal_unseal(fixture->server_protect, - fixture->client_unprotect); - alts_iovec_record_protocol_test_fixture_destroy(fixture); - - fixture = alts_iovec_record_protocol_test_fixture_create( - /*rekey=*/true, /*integrity_only=*/false); - privacy_integrity_unsync_seal_unseal(fixture->client_protect, - fixture->server_unprotect); - privacy_integrity_unsync_seal_unseal(fixture->server_protect, - fixture->client_unprotect); - alts_iovec_record_protocol_test_fixture_destroy(fixture); -} - -static void alts_iovec_record_protocol_corrupted_data_tests() { - alts_iovec_record_protocol_test_fixture* fixture = - alts_iovec_record_protocol_test_fixture_create( - /*rekey=*/false, /*integrity_only=*/true); - integrity_only_corrupted_data(fixture->client_protect, - fixture->server_unprotect); - integrity_only_corrupted_data(fixture->server_protect, - fixture->client_unprotect); - alts_iovec_record_protocol_test_fixture_destroy(fixture); - - fixture = alts_iovec_record_protocol_test_fixture_create( - /*rekey=*/true, /*integrity_only=*/true); - integrity_only_corrupted_data(fixture->client_protect, - fixture->server_unprotect); - integrity_only_corrupted_data(fixture->server_protect, - fixture->client_unprotect); - alts_iovec_record_protocol_test_fixture_destroy(fixture); - - fixture = alts_iovec_record_protocol_test_fixture_create( - /*rekey=*/false, /*integrity_only=*/false); - privacy_integrity_corrupted_data(fixture->client_protect, - fixture->server_unprotect); - privacy_integrity_corrupted_data(fixture->server_protect, - fixture->client_unprotect); - alts_iovec_record_protocol_test_fixture_destroy(fixture); - - fixture = alts_iovec_record_protocol_test_fixture_create( - /*rekey=*/true, /*integrity_only=*/false); - privacy_integrity_corrupted_data(fixture->client_protect, - fixture->server_unprotect); - privacy_integrity_corrupted_data(fixture->server_protect, - fixture->client_unprotect); - alts_iovec_record_protocol_test_fixture_destroy(fixture); -} - -static void alts_iovec_record_protocol_input_check_tests() { - alts_iovec_record_protocol_test_fixture* fixture = - alts_iovec_record_protocol_test_fixture_create( - /*rekey=*/false, /*integrity_only=*/true); - integrity_only_protect_input_check(fixture->client_protect); - integrity_only_unprotect_input_check(fixture->client_unprotect); - alts_iovec_record_protocol_test_fixture_destroy(fixture); - - fixture = alts_iovec_record_protocol_test_fixture_create( - /*rekey=*/true, /*integrity_only=*/true); - integrity_only_protect_input_check(fixture->client_protect); - integrity_only_unprotect_input_check(fixture->client_unprotect); - alts_iovec_record_protocol_test_fixture_destroy(fixture); - - fixture = alts_iovec_record_protocol_test_fixture_create( - /*rekey=*/false, /*integrity_only=*/false); - privacy_integrity_protect_input_check(fixture->client_protect); - privacy_integrity_unprotect_input_check(fixture->client_unprotect); - alts_iovec_record_protocol_test_fixture_destroy(fixture); - - fixture = alts_iovec_record_protocol_test_fixture_create( - /*rekey=*/true, /*integrity_only=*/false); - privacy_integrity_protect_input_check(fixture->client_protect); - privacy_integrity_unprotect_input_check(fixture->client_unprotect); - alts_iovec_record_protocol_test_fixture_destroy(fixture); -} - -static void alts_iovec_record_protocol_mix_operations_tests() { - alts_iovec_record_protocol_test_fixture* fixture_1 = - alts_iovec_record_protocol_test_fixture_create( - /*rekey=*/false, /*integrity_only=*/true); - alts_iovec_record_protocol_test_fixture* fixture_2 = - alts_iovec_record_protocol_test_fixture_create( - /*rekey=*/false, /*integrity_only=*/false); - - record_protocol_wrong_mode( - fixture_1->client_protect, fixture_1->client_unprotect, - fixture_2->client_protect, fixture_2->client_unprotect); - integrity_seal_privacy_unseal(fixture_1->client_protect, - fixture_2->server_unprotect); - privacy_seal_integrity_unseal(fixture_2->client_protect, - fixture_1->server_unprotect); - - alts_iovec_record_protocol_test_fixture_destroy(fixture_1); - alts_iovec_record_protocol_test_fixture_destroy(fixture_2); -} - -int main(int argc, char** argv) { - alts_iovec_record_protocol_random_seal_unseal_tests(); - alts_iovec_record_protocol_empty_seal_unseal_tests(); - alts_iovec_record_protocol_unsync_seal_unseal_tests(); - alts_iovec_record_protocol_corrupted_data_tests(); - alts_iovec_record_protocol_input_check_tests(); - alts_iovec_record_protocol_mix_operations_tests(); - return 0; -} diff --git a/test/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector_test.cc b/test/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector_test.cc deleted file mode 100644 index 2388be95cd..0000000000 --- a/test/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector_test.cc +++ /dev/null @@ -1,289 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include - -#include "src/core/lib/slice/slice_internal.h" -#include "src/core/tsi/alts/crypt/gsec.h" -#include "src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h" -#include "src/core/tsi/transport_security_grpc.h" -#include "test/core/tsi/alts/crypt/gsec_test_util.h" - -/* TODO: tests zero_copy_grpc_protector under TSI test library, which - * has more comprehensive tests. */ - -constexpr size_t kSealRepeatTimes = 50; -constexpr size_t kSmallBufferSize = 16; -constexpr size_t kLargeBufferSize = 16384; -constexpr size_t kChannelMaxSize = 2048; -constexpr size_t kChannelMinSize = 128; - -/* Test fixtures for each test cases. */ -struct alts_zero_copy_grpc_protector_test_fixture { - tsi_zero_copy_grpc_protector* client; - tsi_zero_copy_grpc_protector* server; -}; - -/* Test input variables for protect/unprotect operations. */ -struct alts_zero_copy_grpc_protector_test_var { - grpc_slice_buffer original_sb; - grpc_slice_buffer duplicate_sb; - grpc_slice_buffer staging_sb; - grpc_slice_buffer protected_sb; - grpc_slice_buffer unprotected_sb; -}; - -/* --- Test utility functions. --- */ - -static void create_random_slice_buffer(grpc_slice_buffer* sb, - grpc_slice_buffer* dup_sb, - size_t length) { - GPR_ASSERT(sb != nullptr); - GPR_ASSERT(dup_sb != nullptr); - GPR_ASSERT(length > 0); - grpc_slice slice = GRPC_SLICE_MALLOC(length); - gsec_test_random_bytes(GRPC_SLICE_START_PTR(slice), length); - grpc_slice_buffer_add(sb, grpc_slice_ref(slice)); - grpc_slice_buffer_add(dup_sb, slice); -} - -static uint8_t* pointer_to_nth_byte(grpc_slice_buffer* sb, size_t index) { - GPR_ASSERT(sb != nullptr); - GPR_ASSERT(index < sb->length); - for (size_t i = 0; i < sb->count; i++) { - if (index < GRPC_SLICE_LENGTH(sb->slices[i])) { - return GRPC_SLICE_START_PTR(sb->slices[i]) + index; - } else { - index -= GRPC_SLICE_LENGTH(sb->slices[i]); - } - } - return nullptr; -} - -/* Checks if two slice buffer contents are the same. It is not super efficient, - * but OK for testing. */ -static bool are_slice_buffers_equal(grpc_slice_buffer* first, - grpc_slice_buffer* second) { - GPR_ASSERT(first != nullptr); - GPR_ASSERT(second != nullptr); - if (first->length != second->length) { - return false; - } - for (size_t i = 0; i < first->length; i++) { - uint8_t* first_ptr = pointer_to_nth_byte(first, i); - uint8_t* second_ptr = pointer_to_nth_byte(second, i); - GPR_ASSERT(first_ptr != nullptr && second_ptr != nullptr); - if ((*first_ptr) != (*second_ptr)) { - return false; - } - } - return true; -} - -static alts_zero_copy_grpc_protector_test_fixture* -alts_zero_copy_grpc_protector_test_fixture_create(bool rekey, - bool integrity_only) { - alts_zero_copy_grpc_protector_test_fixture* fixture = - static_cast( - gpr_zalloc(sizeof(alts_zero_copy_grpc_protector_test_fixture))); - grpc_core::ExecCtx exec_ctx; - size_t key_length = rekey ? kAes128GcmRekeyKeyLength : kAes128GcmKeyLength; - uint8_t* key; - size_t max_protected_frame_size = 1024; - gsec_test_random_array(&key, key_length); - GPR_ASSERT(alts_zero_copy_grpc_protector_create( - key, key_length, rekey, /*is_client=*/true, integrity_only, - &max_protected_frame_size, &fixture->client) == TSI_OK); - GPR_ASSERT(alts_zero_copy_grpc_protector_create( - key, key_length, rekey, /*is_client=*/false, integrity_only, - &max_protected_frame_size, &fixture->server) == TSI_OK); - gpr_free(key); - grpc_core::ExecCtx::Get()->Flush(); - return fixture; -} - -static void alts_zero_copy_grpc_protector_test_fixture_destroy( - alts_zero_copy_grpc_protector_test_fixture* fixture) { - if (fixture == nullptr) { - return; - } - grpc_core::ExecCtx exec_ctx; - tsi_zero_copy_grpc_protector_destroy(fixture->client); - tsi_zero_copy_grpc_protector_destroy(fixture->server); - grpc_core::ExecCtx::Get()->Flush(); - gpr_free(fixture); -} - -static alts_zero_copy_grpc_protector_test_var* -alts_zero_copy_grpc_protector_test_var_create() { - alts_zero_copy_grpc_protector_test_var* var = - static_cast( - gpr_zalloc(sizeof(alts_zero_copy_grpc_protector_test_var))); - grpc_slice_buffer_init(&var->original_sb); - grpc_slice_buffer_init(&var->duplicate_sb); - grpc_slice_buffer_init(&var->staging_sb); - grpc_slice_buffer_init(&var->protected_sb); - grpc_slice_buffer_init(&var->unprotected_sb); - return var; -} - -static void alts_zero_copy_grpc_protector_test_var_destroy( - alts_zero_copy_grpc_protector_test_var* var) { - if (var == nullptr) { - return; - } - grpc_slice_buffer_destroy_internal(&var->original_sb); - grpc_slice_buffer_destroy_internal(&var->duplicate_sb); - grpc_slice_buffer_destroy_internal(&var->staging_sb); - grpc_slice_buffer_destroy_internal(&var->protected_sb); - grpc_slice_buffer_destroy_internal(&var->unprotected_sb); - gpr_free(var); -} - -/* --- ALTS zero-copy protector tests. --- */ - -static void seal_unseal_small_buffer(tsi_zero_copy_grpc_protector* sender, - tsi_zero_copy_grpc_protector* receiver) { - grpc_core::ExecCtx exec_ctx; - for (size_t i = 0; i < kSealRepeatTimes; i++) { - alts_zero_copy_grpc_protector_test_var* var = - alts_zero_copy_grpc_protector_test_var_create(); - /* Creates a random small slice buffer and calls protect(). */ - create_random_slice_buffer(&var->original_sb, &var->duplicate_sb, - kSmallBufferSize); - GPR_ASSERT(tsi_zero_copy_grpc_protector_protect( - sender, &var->original_sb, &var->protected_sb) == TSI_OK); - /* Splits protected slice buffer into two: first one is staging_sb, and - * second one is is protected_sb. */ - uint32_t staging_sb_size = - gsec_test_bias_random_uint32( - static_cast(var->protected_sb.length - 1)) + - 1; - grpc_slice_buffer_move_first(&var->protected_sb, staging_sb_size, - &var->staging_sb); - /* Unprotects one by one. */ - GPR_ASSERT(tsi_zero_copy_grpc_protector_unprotect( - receiver, &var->staging_sb, &var->unprotected_sb) == TSI_OK); - GPR_ASSERT(var->unprotected_sb.length == 0); - GPR_ASSERT(tsi_zero_copy_grpc_protector_unprotect( - receiver, &var->protected_sb, &var->unprotected_sb) == - TSI_OK); - GPR_ASSERT( - are_slice_buffers_equal(&var->unprotected_sb, &var->duplicate_sb)); - alts_zero_copy_grpc_protector_test_var_destroy(var); - } - grpc_core::ExecCtx::Get()->Flush(); -} - -static void seal_unseal_large_buffer(tsi_zero_copy_grpc_protector* sender, - tsi_zero_copy_grpc_protector* receiver) { - grpc_core::ExecCtx exec_ctx; - for (size_t i = 0; i < kSealRepeatTimes; i++) { - alts_zero_copy_grpc_protector_test_var* var = - alts_zero_copy_grpc_protector_test_var_create(); - /* Creates a random large slice buffer and calls protect(). */ - create_random_slice_buffer(&var->original_sb, &var->duplicate_sb, - kLargeBufferSize); - GPR_ASSERT(tsi_zero_copy_grpc_protector_protect( - sender, &var->original_sb, &var->protected_sb) == TSI_OK); - /* Splits protected slice buffer into multiple pieces. Receiver unprotects - * each slice buffer one by one. */ - uint32_t channel_size = gsec_test_bias_random_uint32(static_cast( - kChannelMaxSize + 1 - kChannelMinSize)) + - static_cast(kChannelMinSize); - while (var->protected_sb.length > channel_size) { - grpc_slice_buffer_reset_and_unref_internal(&var->staging_sb); - grpc_slice_buffer_move_first(&var->protected_sb, channel_size, - &var->staging_sb); - GPR_ASSERT(tsi_zero_copy_grpc_protector_unprotect( - receiver, &var->staging_sb, &var->unprotected_sb) == - TSI_OK); - } - GPR_ASSERT(tsi_zero_copy_grpc_protector_unprotect( - receiver, &var->protected_sb, &var->unprotected_sb) == - TSI_OK); - GPR_ASSERT( - are_slice_buffers_equal(&var->unprotected_sb, &var->duplicate_sb)); - alts_zero_copy_grpc_protector_test_var_destroy(var); - } - grpc_core::ExecCtx::Get()->Flush(); -} - -/* --- Test cases. --- */ - -static void alts_zero_copy_protector_seal_unseal_small_buffer_tests() { - alts_zero_copy_grpc_protector_test_fixture* fixture = - alts_zero_copy_grpc_protector_test_fixture_create( - /*rekey=*/false, /*integrity_only=*/true); - seal_unseal_small_buffer(fixture->client, fixture->server); - seal_unseal_small_buffer(fixture->server, fixture->client); - alts_zero_copy_grpc_protector_test_fixture_destroy(fixture); - - fixture = alts_zero_copy_grpc_protector_test_fixture_create( - /*rekey=*/false, /*integrity_only=*/false); - seal_unseal_small_buffer(fixture->client, fixture->server); - seal_unseal_small_buffer(fixture->server, fixture->client); - alts_zero_copy_grpc_protector_test_fixture_destroy(fixture); - - fixture = alts_zero_copy_grpc_protector_test_fixture_create( - /*rekey=*/true, /*integrity_only=*/true); - seal_unseal_small_buffer(fixture->client, fixture->server); - seal_unseal_small_buffer(fixture->server, fixture->client); - alts_zero_copy_grpc_protector_test_fixture_destroy(fixture); - - fixture = alts_zero_copy_grpc_protector_test_fixture_create( - /*rekey=*/true, /*integrity_only=*/false); - seal_unseal_small_buffer(fixture->client, fixture->server); - seal_unseal_small_buffer(fixture->server, fixture->client); - alts_zero_copy_grpc_protector_test_fixture_destroy(fixture); -} - -static void alts_zero_copy_protector_seal_unseal_large_buffer_tests() { - alts_zero_copy_grpc_protector_test_fixture* fixture = - alts_zero_copy_grpc_protector_test_fixture_create( - /*rekey=*/false, /*integrity_only=*/true); - seal_unseal_large_buffer(fixture->client, fixture->server); - seal_unseal_large_buffer(fixture->server, fixture->client); - alts_zero_copy_grpc_protector_test_fixture_destroy(fixture); - - fixture = alts_zero_copy_grpc_protector_test_fixture_create( - /*rekey=*/false, /*integrity_only=*/false); - seal_unseal_large_buffer(fixture->client, fixture->server); - seal_unseal_large_buffer(fixture->server, fixture->client); - alts_zero_copy_grpc_protector_test_fixture_destroy(fixture); - - fixture = alts_zero_copy_grpc_protector_test_fixture_create( - /*rekey=*/true, /*integrity_only=*/true); - seal_unseal_large_buffer(fixture->client, fixture->server); - seal_unseal_large_buffer(fixture->server, fixture->client); - alts_zero_copy_grpc_protector_test_fixture_destroy(fixture); - - fixture = alts_zero_copy_grpc_protector_test_fixture_create( - /*rekey=*/true, /*integrity_only=*/false); - seal_unseal_large_buffer(fixture->client, fixture->server); - seal_unseal_large_buffer(fixture->server, fixture->client); - alts_zero_copy_grpc_protector_test_fixture_destroy(fixture); -} - -int main(int argc, char** argv) { - alts_zero_copy_protector_seal_unseal_small_buffer_tests(); - alts_zero_copy_protector_seal_unseal_large_buffer_tests(); - return 0; -} diff --git a/test/core/tsi/fake_transport_security_test.cc b/test/core/tsi/fake_transport_security_test.cc index 5e6671965d..bec81ed42f 100644 --- a/test/core/tsi/fake_transport_security_test.cc +++ b/test/core/tsi/fake_transport_security_test.cc @@ -107,7 +107,7 @@ void fake_tsi_test_do_round_trip_for_all_configs() { tsi_test_frame_protector_config_destroy(fake_fixture->base.config); fake_fixture->base.config = tsi_test_frame_protector_config_create( bit_array[0], bit_array[1], bit_array[2], bit_array[3], bit_array[4], - bit_array[5], bit_array[6]); + bit_array[5], bit_array[6], bit_array[7]); tsi_test_do_round_trip(&fake_fixture->base); tsi_test_fixture_destroy(fixture); } diff --git a/test/core/tsi/ssl_transport_security_test.cc b/test/core/tsi/ssl_transport_security_test.cc index d9eb7470d5..8f255a3d35 100644 --- a/test/core/tsi/ssl_transport_security_test.cc +++ b/test/core/tsi/ssl_transport_security_test.cc @@ -528,7 +528,7 @@ void ssl_tsi_test_do_round_trip_for_all_configs() { tsi_test_frame_protector_config_destroy(ssl_fixture->base.config); ssl_fixture->base.config = tsi_test_frame_protector_config_create( bit_array[0], bit_array[1], bit_array[2], bit_array[3], bit_array[4], - bit_array[5], bit_array[6]); + bit_array[5], bit_array[6], bit_array[7]); tsi_test_do_round_trip(&ssl_fixture->base); tsi_test_fixture_destroy(fixture); } diff --git a/test/core/tsi/transport_security_test_lib.cc b/test/core/tsi/transport_security_test_lib.cc index 26349dbfca..8ea83f7088 100644 --- a/test/core/tsi/transport_security_test_lib.cc +++ b/test/core/tsi/transport_security_test_lib.cc @@ -110,29 +110,27 @@ static void check_handshake_results(tsi_test_fixture* fixture) { fixture->vtable->check_handshaker_peers(fixture); /* Check unused bytes. */ if (fixture->test_unused_bytes) { - tsi_test_channel* channel = fixture->channel; if (fixture->server_result != nullptr && fixture->client_result != nullptr) { check_unused_bytes(fixture); } - channel->bytes_written_to_server_channel = 0; - channel->bytes_written_to_client_channel = 0; - channel->bytes_read_from_client_channel = 0; - channel->bytes_read_from_server_channel = 0; + fixture->bytes_written_to_server_channel = 0; + fixture->bytes_written_to_client_channel = 0; + fixture->bytes_read_from_client_channel = 0; + fixture->bytes_read_from_server_channel = 0; } } -static void send_bytes_to_peer(tsi_test_channel* test_channel, +static void send_bytes_to_peer(tsi_test_fixture* fixture, const unsigned char* buf, size_t buf_size, bool is_client) { - GPR_ASSERT(test_channel != nullptr); + GPR_ASSERT(fixture != nullptr); GPR_ASSERT(buf != nullptr); uint8_t* channel = - is_client ? test_channel->server_channel : test_channel->client_channel; + is_client ? fixture->server_channel : fixture->client_channel; GPR_ASSERT(channel != nullptr); - size_t* bytes_written = is_client - ? &test_channel->bytes_written_to_server_channel - : &test_channel->bytes_written_to_client_channel; + size_t* bytes_written = is_client ? &fixture->bytes_written_to_server_channel + : &fixture->bytes_written_to_client_channel; GPR_ASSERT(bytes_written != nullptr); GPR_ASSERT(*bytes_written + buf_size <= TSI_TEST_DEFAULT_CHANNEL_SIZE); /* Write data to channel. */ @@ -147,8 +145,7 @@ static void maybe_append_unused_bytes(handshaker_args* args) { if (fixture->test_unused_bytes && !args->appended_unused_bytes) { args->appended_unused_bytes = true; send_bytes_to_peer( - fixture->channel, - reinterpret_cast(TSI_TEST_UNUSED_BYTES), + fixture, reinterpret_cast(TSI_TEST_UNUSED_BYTES), strlen(TSI_TEST_UNUSED_BYTES), args->is_client); if (fixture->client_result != nullptr && fixture->server_result == nullptr) { @@ -157,21 +154,19 @@ static void maybe_append_unused_bytes(handshaker_args* args) { } } -static void receive_bytes_from_peer(tsi_test_channel* test_channel, +static void receive_bytes_from_peer(tsi_test_fixture* fixture, unsigned char** buf, size_t* buf_size, bool is_client) { - GPR_ASSERT(test_channel != nullptr); + GPR_ASSERT(fixture != nullptr); GPR_ASSERT(*buf != nullptr); GPR_ASSERT(buf_size != nullptr); uint8_t* channel = - is_client ? test_channel->client_channel : test_channel->server_channel; + is_client ? fixture->client_channel : fixture->server_channel; GPR_ASSERT(channel != nullptr); - size_t* bytes_read = is_client - ? &test_channel->bytes_read_from_client_channel - : &test_channel->bytes_read_from_server_channel; - size_t* bytes_written = is_client - ? &test_channel->bytes_written_to_client_channel - : &test_channel->bytes_written_to_server_channel; + size_t* bytes_read = is_client ? &fixture->bytes_read_from_client_channel + : &fixture->bytes_read_from_server_channel; + size_t* bytes_written = is_client ? &fixture->bytes_written_to_client_channel + : &fixture->bytes_written_to_server_channel; GPR_ASSERT(bytes_read != nullptr); GPR_ASSERT(bytes_written != nullptr); size_t to_read = *buf_size < *bytes_written - *bytes_read @@ -183,13 +178,14 @@ static void receive_bytes_from_peer(tsi_test_channel* test_channel, *bytes_read += to_read; } -void tsi_test_frame_protector_send_message_to_peer( - tsi_test_frame_protector_config* config, tsi_test_channel* channel, - tsi_frame_protector* protector, bool is_client) { +static void send_message_to_peer(tsi_test_fixture* fixture, + tsi_frame_protector* protector, + bool is_client) { /* Initialization. */ - GPR_ASSERT(config != nullptr); - GPR_ASSERT(channel != nullptr); + GPR_ASSERT(fixture != nullptr); + GPR_ASSERT(fixture->config != nullptr); GPR_ASSERT(protector != nullptr); + tsi_test_frame_protector_config* config = fixture->config; unsigned char* protected_buffer = static_cast(gpr_zalloc(config->protected_buffer_size)); size_t message_size = @@ -209,7 +205,7 @@ void tsi_test_frame_protector_send_message_to_peer( &protected_buffer_size_to_send); GPR_ASSERT(result == TSI_OK); /* Send protected data to peer. */ - send_bytes_to_peer(channel, protected_buffer, protected_buffer_size_to_send, + send_bytes_to_peer(fixture, protected_buffer, protected_buffer_size_to_send, is_client); message_bytes += processed_message_size; message_size -= processed_message_size; @@ -222,7 +218,7 @@ void tsi_test_frame_protector_send_message_to_peer( protector, protected_buffer, &protected_buffer_size_to_send, &still_pending_size); GPR_ASSERT(result == TSI_OK); - send_bytes_to_peer(channel, protected_buffer, + send_bytes_to_peer(fixture, protected_buffer, protected_buffer_size_to_send, is_client); } while (still_pending_size > 0 && result == TSI_OK); GPR_ASSERT(result == TSI_OK); @@ -232,16 +228,17 @@ void tsi_test_frame_protector_send_message_to_peer( gpr_free(protected_buffer); } -void tsi_test_frame_protector_receive_message_from_peer( - tsi_test_frame_protector_config* config, tsi_test_channel* channel, - tsi_frame_protector* protector, unsigned char* message, - size_t* bytes_received, bool is_client) { +static void receive_message_from_peer(tsi_test_fixture* fixture, + tsi_frame_protector* protector, + unsigned char* message, + size_t* bytes_received, bool is_client) { /* Initialization. */ - GPR_ASSERT(config != nullptr); - GPR_ASSERT(channel != nullptr); + GPR_ASSERT(fixture != nullptr); GPR_ASSERT(protector != nullptr); GPR_ASSERT(message != nullptr); GPR_ASSERT(bytes_received != nullptr); + GPR_ASSERT(fixture->config != nullptr); + tsi_test_frame_protector_config* config = fixture->config; size_t read_offset = 0; size_t message_offset = 0; size_t read_from_peer_size = 0; @@ -256,7 +253,7 @@ void tsi_test_frame_protector_receive_message_from_peer( /* Receive data from peer. */ if (read_from_peer_size == 0) { read_from_peer_size = config->read_buffer_allocated_size; - receive_bytes_from_peer(channel, &read_buffer, &read_from_peer_size, + receive_bytes_from_peer(fixture, &read_buffer, &read_from_peer_size, is_client); read_offset = 0; } @@ -317,7 +314,7 @@ grpc_error* on_handshake_next_done(tsi_result result, void* user_data, } /* Send data to peer, if needed. */ if (bytes_to_send_size > 0) { - send_bytes_to_peer(fixture->channel, bytes_to_send, bytes_to_send_size, + send_bytes_to_peer(args->fixture, bytes_to_send, bytes_to_send_size, args->is_client); args->transferred_data = true; } @@ -364,8 +361,8 @@ static void do_handshaker_next(handshaker_args* args) { /* Receive data from peer, if available. */ do { size_t buf_size = args->handshake_buffer_size; - receive_bytes_from_peer(fixture->channel, &args->handshake_buffer, - &buf_size, args->is_client); + receive_bytes_from_peer(args->fixture, &args->handshake_buffer, &buf_size, + args->is_client); if (buf_size > 0) { args->transferred_data = true; } @@ -414,50 +411,6 @@ void tsi_test_do_handshake(tsi_test_fixture* fixture) { handshaker_args_destroy(server_args); } -static void tsi_test_do_ping_pong(tsi_test_frame_protector_config* config, - tsi_test_channel* channel, - tsi_frame_protector* client_frame_protector, - tsi_frame_protector* server_frame_protector) { - GPR_ASSERT(config != nullptr); - GPR_ASSERT(channel != nullptr); - GPR_ASSERT(client_frame_protector != nullptr); - GPR_ASSERT(server_frame_protector != nullptr); - /* Client sends a message to server. */ - tsi_test_frame_protector_send_message_to_peer( - config, channel, client_frame_protector, true /* is_client */); - unsigned char* server_received_message = - static_cast(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE)); - size_t server_received_message_size = 0; - tsi_test_frame_protector_receive_message_from_peer( - config, channel, server_frame_protector, server_received_message, - &server_received_message_size, false /* is_client */); - GPR_ASSERT(config->client_message_size == server_received_message_size); - GPR_ASSERT(memcmp(config->client_message, server_received_message, - server_received_message_size) == 0); - /* Server sends a message to client. */ - tsi_test_frame_protector_send_message_to_peer( - config, channel, server_frame_protector, false /* is_client */); - unsigned char* client_received_message = - static_cast(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE)); - size_t client_received_message_size = 0; - tsi_test_frame_protector_receive_message_from_peer( - config, channel, client_frame_protector, client_received_message, - &client_received_message_size, true /* is_client */); - GPR_ASSERT(config->server_message_size == client_received_message_size); - GPR_ASSERT(memcmp(config->server_message, client_received_message, - client_received_message_size) == 0); - gpr_free(server_received_message); - gpr_free(client_received_message); -} - -void tsi_test_frame_protector_do_round_trip_no_handshake( - tsi_test_frame_protector_fixture* fixture) { - GPR_ASSERT(fixture != nullptr); - tsi_test_do_ping_pong(fixture->config, fixture->channel, - fixture->client_frame_protector, - fixture->server_frame_protector); -} - void tsi_test_do_round_trip(tsi_test_fixture* fixture) { /* Initialization. */ GPR_ASSERT(fixture != nullptr); @@ -484,11 +437,33 @@ void tsi_test_do_round_trip(tsi_test_fixture* fixture) { ? nullptr : &server_max_output_protected_frame_size, &server_frame_protector) == TSI_OK); - tsi_test_do_ping_pong(config, fixture->channel, client_frame_protector, - server_frame_protector); + /* Client sends a message to server. */ + send_message_to_peer(fixture, client_frame_protector, true /* is_client */); + unsigned char* server_received_message = + static_cast(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE)); + size_t server_received_message_size = 0; + receive_message_from_peer( + fixture, server_frame_protector, server_received_message, + &server_received_message_size, false /* is_client */); + GPR_ASSERT(config->client_message_size == server_received_message_size); + GPR_ASSERT(memcmp(config->client_message, server_received_message, + server_received_message_size) == 0); + /* Server sends a message to client. */ + send_message_to_peer(fixture, server_frame_protector, false /* is_client */); + unsigned char* client_received_message = + static_cast(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE)); + size_t client_received_message_size = 0; + receive_message_from_peer( + fixture, client_frame_protector, client_received_message, + &client_received_message_size, true /* is_client */); + GPR_ASSERT(config->server_message_size == client_received_message_size); + GPR_ASSERT(memcmp(config->server_message, client_received_message, + client_received_message_size) == 0); /* Destroy server and client frame protectors. */ tsi_frame_protector_destroy(client_frame_protector); tsi_frame_protector_destroy(server_frame_protector); + gpr_free(server_received_message); + gpr_free(client_received_message); } static unsigned char* generate_random_message(size_t size) { @@ -508,7 +483,8 @@ tsi_test_frame_protector_config* tsi_test_frame_protector_config_create( bool use_default_protected_buffer_size, bool use_default_client_message, bool use_default_server_message, bool use_default_client_max_output_protected_frame_size, - bool use_default_server_max_output_protected_frame_size) { + bool use_default_server_max_output_protected_frame_size, + bool use_default_handshake_buffer_size) { tsi_test_frame_protector_config* config = static_cast( gpr_zalloc(sizeof(*config))); @@ -576,42 +552,24 @@ void tsi_test_frame_protector_config_set_buffer_size( void tsi_test_frame_protector_config_destroy( tsi_test_frame_protector_config* config) { - if (config == nullptr) { - return; - } + GPR_ASSERT(config != nullptr); gpr_free(config->client_message); gpr_free(config->server_message); gpr_free(config); } -static tsi_test_channel* tsi_test_channel_create() { - tsi_test_channel* channel = - static_cast(gpr_zalloc(sizeof(*channel))); - channel->client_channel = - static_cast(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE)); - channel->server_channel = - static_cast(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE)); - channel->bytes_written_to_client_channel = 0; - channel->bytes_written_to_server_channel = 0; - channel->bytes_read_from_client_channel = 0; - channel->bytes_read_from_server_channel = 0; - return channel; -} - -static void tsi_test_channel_destroy(tsi_test_channel* channel) { - if (channel == nullptr) { - return; - } - gpr_free(channel->client_channel); - gpr_free(channel->server_channel); - gpr_free(channel); -} - void tsi_test_fixture_init(tsi_test_fixture* fixture) { fixture->config = tsi_test_frame_protector_config_create( - true, true, true, true, true, true, true); + true, true, true, true, true, true, true, true); fixture->handshake_buffer_size = TSI_TEST_DEFAULT_BUFFER_SIZE; - fixture->channel = tsi_test_channel_create(); + fixture->client_channel = + static_cast(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE)); + fixture->server_channel = + static_cast(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE)); + fixture->bytes_written_to_client_channel = 0; + fixture->bytes_written_to_server_channel = 0; + fixture->bytes_read_from_client_channel = 0; + fixture->bytes_read_from_server_channel = 0; fixture->test_unused_bytes = true; fixture->has_client_finished_first = false; gpr_mu_init(&fixture->mu); @@ -620,15 +578,14 @@ void tsi_test_fixture_init(tsi_test_fixture* fixture) { } void tsi_test_fixture_destroy(tsi_test_fixture* fixture) { - if (fixture == nullptr) { - return; - } + GPR_ASSERT(fixture != nullptr); tsi_test_frame_protector_config_destroy(fixture->config); tsi_handshaker_destroy(fixture->client_handshaker); tsi_handshaker_destroy(fixture->server_handshaker); tsi_handshaker_result_destroy(fixture->client_result); tsi_handshaker_result_destroy(fixture->server_result); - tsi_test_channel_destroy(fixture->channel); + gpr_free(fixture->client_channel); + gpr_free(fixture->server_channel); GPR_ASSERT(fixture->vtable != nullptr); GPR_ASSERT(fixture->vtable->destruct != nullptr); fixture->vtable->destruct(fixture); @@ -636,34 +593,3 @@ void tsi_test_fixture_destroy(tsi_test_fixture* fixture) { gpr_cv_destroy(&fixture->cv); gpr_free(fixture); } - -tsi_test_frame_protector_fixture* tsi_test_frame_protector_fixture_create() { - tsi_test_frame_protector_fixture* fixture = - static_cast( - gpr_zalloc(sizeof(*fixture))); - fixture->config = tsi_test_frame_protector_config_create( - true, true, true, true, true, true, true); - fixture->channel = tsi_test_channel_create(); - return fixture; -} - -void tsi_test_frame_protector_fixture_init( - tsi_test_frame_protector_fixture* fixture, - tsi_frame_protector* client_frame_protector, - tsi_frame_protector* server_frame_protector) { - GPR_ASSERT(fixture != nullptr); - fixture->client_frame_protector = client_frame_protector; - fixture->server_frame_protector = server_frame_protector; -} - -void tsi_test_frame_protector_fixture_destroy( - tsi_test_frame_protector_fixture* fixture) { - if (fixture == nullptr) { - return; - } - tsi_test_frame_protector_config_destroy(fixture->config); - tsi_test_channel_destroy(fixture->channel); - tsi_frame_protector_destroy(fixture->client_frame_protector); - tsi_frame_protector_destroy(fixture->server_frame_protector); - gpr_free(fixture); -} diff --git a/test/core/tsi/transport_security_test_lib.h b/test/core/tsi/transport_security_test_lib.h index b6a431f5a0..9b07448cc5 100644 --- a/test/core/tsi/transport_security_test_lib.h +++ b/test/core/tsi/transport_security_test_lib.h @@ -35,8 +35,8 @@ #define TSI_TEST_DEFAULT_CHANNEL_SIZE 32768 #define TSI_TEST_BIG_MESSAGE_SIZE 17000 #define TSI_TEST_SMALL_MESSAGE_SIZE 10 -#define TSI_TEST_NUM_OF_ARGUMENTS 7 -#define TSI_TEST_NUM_OF_COMBINATIONS 128 +#define TSI_TEST_NUM_OF_ARGUMENTS 8 +#define TSI_TEST_NUM_OF_COMBINATIONS 256 #define TSI_TEST_UNUSED_BYTES "HELLO GOOGLE" /* --- tsi_test_fixture object --- @@ -46,22 +46,12 @@ protect/unprotect operations with respect to TSI implementations. */ typedef struct tsi_test_fixture tsi_test_fixture; -/* --- tsi_test_frame_protector_fixture object --- - The object wraps all necessary information used to test correctness of TSI - frame protector implementations. */ -typedef struct tsi_test_frame_protector_fixture - tsi_test_frame_protector_fixture; - /* --- tsi_test_frame_protector_config object --- + This object is used to configure different parameters of TSI frame protector APIs. */ typedef struct tsi_test_frame_protector_config tsi_test_frame_protector_config; -/* --- tsi_test_channel object --- - This object represents simulated channels between the client and server - from/to which they could read/write the exchanged information. */ -typedef struct tsi_test_channel tsi_test_channel; - /* V-table for tsi_test_fixture operations that are implemented differently in different TSI implementations. */ typedef struct tsi_test_fixture_vtable { @@ -83,8 +73,17 @@ struct tsi_test_fixture { tsi_handshaker_result* server_result; /* size of buffer used to store data received from the peer. */ size_t handshake_buffer_size; - /* tsi_test_channel instance. */ - tsi_test_channel* channel; + /* simulated channels between client and server. If the server (client) + wants to send data to the client (server), he will write data to + client_channel (server_channel), which will be read by client (server). */ + uint8_t* client_channel; + uint8_t* server_channel; + /* size of data written to the client/server channel. */ + size_t bytes_written_to_client_channel; + size_t bytes_written_to_server_channel; + /* size of data read from the client/server channel */ + size_t bytes_read_from_client_channel; + size_t bytes_read_from_server_channel; /* tsi_test_frame_protector_config instance */ tsi_test_frame_protector_config* config; /* a flag indicating if client has finished TSI handshake first (i.e., before @@ -107,30 +106,6 @@ struct tsi_test_fixture { bool notified; }; -struct tsi_test_frame_protector_fixture { - /* client/server TSI frame protectors whose ownership are transferred. */ - tsi_frame_protector* client_frame_protector; - tsi_frame_protector* server_frame_protector; - /* tsi_test_channel instance. */ - tsi_test_channel* channel; - /* tsi_test_frame_protector_config instance */ - tsi_test_frame_protector_config* config; -}; - -struct tsi_test_channel { - /* simulated channels between client and server. If the server (client) - wants to send data to the client (server), he will write data to - client_channel (server_channel), which will be read by client (server). */ - uint8_t* client_channel; - uint8_t* server_channel; - /* size of data written to the client/server channel. */ - size_t bytes_written_to_client_channel; - size_t bytes_written_to_server_channel; - /* size of data read from the client/server channel */ - size_t bytes_read_from_client_channel; - size_t bytes_read_from_server_channel; -}; - struct tsi_test_frame_protector_config { /* size of buffer used to store protected frames to be unprotected. */ size_t read_buffer_allocated_size; @@ -160,7 +135,8 @@ tsi_test_frame_protector_config* tsi_test_frame_protector_config_create( bool use_default_protected_buffer_size, bool use_default_client_message, bool use_default_server_message, bool use_default_client_max_output_protected_frame_size, - bool use_default_server_max_output_protected_frame_size); + bool use_default_server_max_output_protected_frame_size, + bool use_default_handshake_buffer_size); /* This method sets different buffer and frame sizes of a tsi_test_frame_protector_config instance with user provided values. */ @@ -184,35 +160,6 @@ void tsi_test_fixture_init(tsi_test_fixture* fixture); this function. */ void tsi_test_fixture_destroy(tsi_test_fixture* fixture); -/* This method creates a tsi_test_frame_protector_fixture instance. */ -tsi_test_frame_protector_fixture* tsi_test_frame_protector_fixture_create(); - -/* This method initializes members of tsi_test_frame_protector_fixture instance. - Note that the struct instance should be allocated before making - this call. */ -void tsi_test_frame_protector_fixture_init( - tsi_test_frame_protector_fixture* fixture, - tsi_frame_protector* client_frame_protector, - tsi_frame_protector* server_frame_protector); - -/* This method destroys a tsi_test_frame_protector_fixture instance. Note that - the fixture intance must be dynamically allocated and will be freed by this - function. */ -void tsi_test_frame_protector_fixture_destroy( - tsi_test_frame_protector_fixture* fixture); - -/* This method performs a protect opeation on raw data and sends the result to - peer. */ -void tsi_test_frame_protector_send_message_to_peer( - tsi_test_frame_protector_config* config, tsi_test_channel* channel, - tsi_frame_protector* protector, bool is_client); - -/* This method receives message from peer and unprotects it. */ -void tsi_test_frame_protector_receive_message_from_peer( - tsi_test_frame_protector_config* config, tsi_test_channel* channel, - tsi_frame_protector* protector, unsigned char* message, - size_t* bytes_received, bool is_client); - /* This method performs a full TSI handshake between a client and a server. Note that the test library will implement the new TSI handshaker API to perform handshakes. */ @@ -224,8 +171,4 @@ void tsi_test_do_handshake(tsi_test_fixture* fixture); the client and server switching its role. */ void tsi_test_do_round_trip(tsi_test_fixture* fixture); -/* This method performs the above round trip test without doing handshakes. */ -void tsi_test_frame_protector_do_round_trip_no_handshake( - tsi_test_frame_protector_fixture* fixture); - #endif // GRPC_TEST_CORE_TSI_TRANSPORT_SECURITY_TEST_LIB_H_ diff --git a/third_party/nanopb/pb.h b/third_party/nanopb/pb.h index 62dca73f4f..4576f79abc 100644 --- a/third_party/nanopb/pb.h +++ b/third_party/nanopb/pb.h @@ -25,7 +25,7 @@ /* #define PB_FIELD_16BIT 1 */ /* Add support for tag numbers > 65536 and fields larger than 65536 bytes. */ -/* #define PB_FIELD_32BIT 1 */ +/* #define PB_FIELD_32BIT 1 */ /* Disable support for error messages in order to save some code space. */ /* #define PB_NO_ERRMSG 1 */ diff --git a/tools/codegen/core/gen_nano_proto.sh b/tools/codegen/core/gen_nano_proto.sh index 6ce15178bd..4246840173 100755 --- a/tools/codegen/core/gen_nano_proto.sh +++ b/tools/codegen/core/gen_nano_proto.sh @@ -43,9 +43,9 @@ if [[ ! -f "$INPUT_PROTO" ]]; then echo "Input proto file '$INPUT_PROTO' doesn't exist." exit 2 fi - if [[ ! -f "${EXPECTED_OPTIONS_FILE_PATH}" ]]; then - echo "Input proto file may need .options file to be correctly compiled." + echo "Expected nanopb options file '${EXPECTED_OPTIONS_FILE_PATH}' missing" + exit 3 fi if [[ "${OUTPUT_DIR:0:1}" != '/' ]]; then @@ -81,11 +81,6 @@ readonly PROTO_BASENAME=$(basename $INPUT_PROTO .proto) sed -i "s:$PROTO_BASENAME.pb.h:${GRPC_OUTPUT_DIR}/$PROTO_BASENAME.pb.h:g" \ "$OUTPUT_DIR/$PROTO_BASENAME.pb.c" -if [ $PROTO_BASENAME == "handshaker" ] || [ $PROTO_BASENAME == "altscontext" ]; then - sed -i "s:transport_security_common.pb.h:${GRPC_OUTPUT_DIR}/transport_security_common.pb.h:g" \ - "$OUTPUT_DIR/$PROTO_BASENAME.pb.h" -fi - # Fix up the include guards such that they pass the check_include_guards.py # test. Assumes that the generated files are being placed in gRPC src dir. readonly INCLUDE_GUARD_BASE=`echo $GRPC_OUTPUT_DIR | tr [a-z/] [A-Z_] | sed s:^.*SRC_::` diff --git a/tools/distrib/check_copyright.py b/tools/distrib/check_copyright.py index e7893a1fd5..6e1a303fb0 100755 --- a/tools/distrib/check_copyright.py +++ b/tools/distrib/check_copyright.py @@ -77,12 +77,6 @@ _EXEMPT = frozenset(( 'examples/python/route_guide/route_guide_pb2_grpc.py', 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h', 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c', - 'src/core/tsi/alts/handshaker/altscontext.pb.h', - 'src/core/tsi/alts/handshaker/altscontext.pb.c', - 'src/core/tsi/alts/handshaker/handshaker.pb.h', - 'src/core/tsi/alts/handshaker/handshaker.pb.c', - 'src/core/tsi/alts/handshaker/transport_security_common.pb.h', - 'src/core/tsi/alts/handshaker/transport_security_common.pb.c', 'src/cpp/server/health/health.pb.h', 'src/cpp/server/health/health.pb.c', diff --git a/tools/distrib/check_include_guards.py b/tools/distrib/check_include_guards.py index b356a74d2d..05d34c2b28 100755 --- a/tools/distrib/check_include_guards.py +++ b/tools/distrib/check_include_guards.py @@ -157,9 +157,6 @@ args = argp.parse_args() KNOWN_BAD = set([ 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h', - 'src/core/tsi/alts/handshaker/altscontext.pb.h', - 'src/core/tsi/alts/handshaker/handshaker.pb.h', - 'src/core/tsi/alts/handshaker/transport_security_common.pb.h', 'include/grpc++/ext/reflection.grpc.pb.h', 'include/grpc++/ext/reflection.pb.h', ]) diff --git a/tools/distrib/check_nanopb_output.sh b/tools/distrib/check_nanopb_output.sh index 8b5823b938..a30b73f689 100755 --- a/tools/distrib/check_nanopb_output.sh +++ b/tools/distrib/check_nanopb_output.sh @@ -15,7 +15,6 @@ set -ex -readonly NANOPB_ALTS_TMP_OUTPUT="$(mktemp -d)" readonly NANOPB_TMP_OUTPUT="$(mktemp -d)" readonly PROTOBUF_INSTALL_PREFIX="$(mktemp -d)" @@ -56,29 +55,3 @@ if ! diff -r "$NANOPB_TMP_OUTPUT" src/core/ext/filters/client_channel/lb_policy/ echo "Outputs differ: $NANOPB_TMP_OUTPUT vs $LOAD_BALANCER_GRPC_OUTPUT_PATH" exit 2 fi - -# -# Checks for handshaker.proto and transport_security_common.proto -# -readonly HANDSHAKER_GRPC_OUTPUT_PATH='src/core/tsi/alts/handshaker' -# nanopb-compile the proto to a temp location -./tools/codegen/core/gen_nano_proto.sh \ - src/core/tsi/alts/handshaker/proto/handshaker.proto \ - "$NANOPB_ALTS_TMP_OUTPUT" \ - "$HANDSHAKER_GRPC_OUTPUT_PATH" -./tools/codegen/core/gen_nano_proto.sh \ - src/core/tsi/alts/handshaker/proto/transport_security_common.proto \ - "$NANOPB_ALTS_TMP_OUTPUT" \ - "$HANDSHAKER_GRPC_OUTPUT_PATH" -./tools/codegen/core/gen_nano_proto.sh \ - src/core/tsi/alts/handshaker/proto/altscontext.proto \ - "$NANOPB_ALTS_TMP_OUTPUT" \ - "$HANDSHAKER_GRPC_OUTPUT_PATH" - -# compare outputs to checked compiled code -for NANOPB_OUTPUT_FILE in $NANOPB_ALTS_TMP_OUTPUT/*.pb.*; do - if ! diff "$NANOPB_OUTPUT_FILE" "src/core/tsi/alts/handshaker/$(basename $NANOPB_OUTPUT_FILE)"; then - echo "Outputs differ: $NANOPB_ALTS_TMP_OUTPUT vs $HANDSHAKER_GRPC_OUTPUT_PATH" - exit 2 - fi -done diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index e7e9e04979..57f9147f44 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -1284,17 +1284,6 @@ src/core/lib/profiling/stap_timers.cc \ src/core/lib/profiling/timers.h \ src/core/lib/security/context/security_context.cc \ src/core/lib/security/context/security_context.h \ -src/core/lib/security/credentials/alts/alts_credentials.cc \ -src/core/lib/security/credentials/alts/alts_credentials.h \ -src/core/lib/security/credentials/alts/check_gcp_environment.cc \ -src/core/lib/security/credentials/alts/check_gcp_environment.h \ -src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc \ -src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc \ -src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc \ -src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc \ -src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc \ -src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h \ -src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc \ src/core/lib/security/credentials/composite/composite_credentials.cc \ src/core/lib/security/credentials/composite/composite_credentials.h \ src/core/lib/security/credentials/credentials.cc \ @@ -1319,8 +1308,6 @@ src/core/lib/security/credentials/plugin/plugin_credentials.cc \ src/core/lib/security/credentials/plugin/plugin_credentials.h \ src/core/lib/security/credentials/ssl/ssl_credentials.cc \ src/core/lib/security/credentials/ssl/ssl_credentials.h \ -src/core/lib/security/security_connector/alts_security_connector.cc \ -src/core/lib/security/security_connector/alts_security_connector.h \ src/core/lib/security/security_connector/security_connector.cc \ src/core/lib/security/security_connector/security_connector.h \ src/core/lib/security/transport/auth_filters.h \ @@ -1414,53 +1401,6 @@ src/core/lib/transport/transport_impl.h \ src/core/lib/transport/transport_op_string.cc \ src/core/plugin_registry/grpc_plugin_registry.cc \ src/core/tsi/README.md \ -src/core/tsi/alts/crypt/aes_gcm.cc \ -src/core/tsi/alts/crypt/gsec.cc \ -src/core/tsi/alts/crypt/gsec.h \ -src/core/tsi/alts/frame_protector/alts_counter.cc \ -src/core/tsi/alts/frame_protector/alts_counter.h \ -src/core/tsi/alts/frame_protector/alts_crypter.cc \ -src/core/tsi/alts/frame_protector/alts_crypter.h \ -src/core/tsi/alts/frame_protector/alts_frame_protector.cc \ -src/core/tsi/alts/frame_protector/alts_frame_protector.h \ -src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc \ -src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h \ -src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc \ -src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc \ -src/core/tsi/alts/frame_protector/frame_handler.cc \ -src/core/tsi/alts/frame_protector/frame_handler.h \ -src/core/tsi/alts/handshaker/alts_handshaker_client.cc \ -src/core/tsi/alts/handshaker/alts_handshaker_client.h \ -src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc \ -src/core/tsi/alts/handshaker/alts_handshaker_service_api.h \ -src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc \ -src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h \ -src/core/tsi/alts/handshaker/alts_tsi_event.cc \ -src/core/tsi/alts/handshaker/alts_tsi_event.h \ -src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc \ -src/core/tsi/alts/handshaker/alts_tsi_handshaker.h \ -src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h \ -src/core/tsi/alts/handshaker/alts_tsi_utils.cc \ -src/core/tsi/alts/handshaker/alts_tsi_utils.h \ -src/core/tsi/alts/handshaker/altscontext.pb.c \ -src/core/tsi/alts/handshaker/altscontext.pb.h \ -src/core/tsi/alts/handshaker/handshaker.pb.c \ -src/core/tsi/alts/handshaker/handshaker.pb.h \ -src/core/tsi/alts/handshaker/transport_security_common.pb.c \ -src/core/tsi/alts/handshaker/transport_security_common.pb.h \ -src/core/tsi/alts/handshaker/transport_security_common_api.cc \ -src/core/tsi/alts/handshaker/transport_security_common_api.h \ -src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc \ -src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h \ -src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc \ -src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h \ -src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h \ -src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc \ -src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h \ -src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc \ -src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h \ -src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc \ -src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h \ src/core/tsi/alts_transport_security.cc \ src/core/tsi/alts_transport_security.h \ src/core/tsi/fake_transport_security.cc \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 724967145e..6b8b26f41b 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -2415,215 +2415,6 @@ "third_party": false, "type": "target" }, - { - "deps": [ - "alts_test_util", - "gpr", - "grpc" - ], - "headers": [], - "is_filegroup": false, - "language": "c++", - "name": "alts_counter_test", - "src": [ - "test/core/tsi/alts/frame_protector/alts_counter_test.cc" - ], - "third_party": false, - "type": "target" - }, - { - "deps": [ - "alts_test_util", - "gpr", - "gpr_test_util", - "grpc" - ], - "headers": [], - "is_filegroup": false, - "language": "c++", - "name": "alts_crypt_test", - "src": [ - "test/core/tsi/alts/crypt/aes_gcm_test.cc" - ], - "third_party": false, - "type": "target" - }, - { - "deps": [ - "alts_test_util", - "gpr", - "grpc" - ], - "headers": [], - "is_filegroup": false, - "language": "c++", - "name": "alts_crypter_test", - "src": [ - "test/core/tsi/alts/frame_protector/alts_crypter_test.cc" - ], - "third_party": false, - "type": "target" - }, - { - "deps": [ - "alts_test_util", - "gpr", - "grpc" - ], - "headers": [], - "is_filegroup": false, - "language": "c++", - "name": "alts_frame_handler_test", - "src": [ - "test/core/tsi/alts/frame_protector/frame_handler_test.cc" - ], - "third_party": false, - "type": "target" - }, - { - "deps": [ - "alts_test_util", - "gpr", - "grpc", - "transport_security_test_lib" - ], - "headers": [], - "is_filegroup": false, - "language": "c++", - "name": "alts_frame_protector_test", - "src": [ - "test/core/tsi/alts/frame_protector/alts_frame_protector_test.cc" - ], - "third_party": false, - "type": "target" - }, - { - "deps": [ - "alts_test_util", - "gpr", - "grpc" - ], - "headers": [], - "is_filegroup": false, - "language": "c++", - "name": "alts_grpc_record_protocol_test", - "src": [ - "test/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_test.cc" - ], - "third_party": false, - "type": "target" - }, - { - "deps": [ - "alts_test_util", - "gpr", - "grpc" - ], - "headers": [], - "is_filegroup": false, - "language": "c++", - "name": "alts_handshaker_client_test", - "src": [ - "test/core/tsi/alts/handshaker/alts_handshaker_client_test.cc" - ], - "third_party": false, - "type": "target" - }, - { - "deps": [ - "alts_test_util", - "gpr", - "grpc" - ], - "headers": [], - "is_filegroup": false, - "language": "c++", - "name": "alts_handshaker_service_api_test", - "src": [ - "test/core/tsi/alts/handshaker/alts_handshaker_service_api_test.cc" - ], - "third_party": false, - "type": "target" - }, - { - "deps": [ - "alts_test_util", - "gpr", - "grpc" - ], - "headers": [], - "is_filegroup": false, - "language": "c++", - "name": "alts_iovec_record_protocol_test", - "src": [ - "test/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol_test.cc" - ], - "third_party": false, - "type": "target" - }, - { - "deps": [ - "gpr", - "grpc" - ], - "headers": [], - "is_filegroup": false, - "language": "c++", - "name": "alts_security_connector_test", - "src": [ - "test/core/security/alts_security_connector_test.cc" - ], - "third_party": false, - "type": "target" - }, - { - "deps": [ - "alts_test_util", - "gpr", - "grpc" - ], - "headers": [], - "is_filegroup": false, - "language": "c++", - "name": "alts_tsi_handshaker_test", - "src": [ - "test/core/tsi/alts/handshaker/alts_tsi_handshaker_test.cc" - ], - "third_party": false, - "type": "target" - }, - { - "deps": [ - "alts_test_util", - "gpr", - "grpc" - ], - "headers": [], - "is_filegroup": false, - "language": "c++", - "name": "alts_tsi_utils_test", - "src": [ - "test/core/tsi/alts/handshaker/alts_tsi_utils_test.cc" - ], - "third_party": false, - "type": "target" - }, - { - "deps": [ - "alts_test_util", - "gpr", - "grpc" - ], - "headers": [], - "is_filegroup": false, - "language": "c++", - "name": "alts_zero_copy_grpc_protector_test", - "src": [ - "test/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector_test.cc" - ], - "third_party": false, - "type": "target" - }, { "deps": [ "gpr", @@ -3034,36 +2825,6 @@ "third_party": false, "type": "target" }, - { - "deps": [ - "gpr", - "grpc" - ], - "headers": [], - "is_filegroup": false, - "language": "c++", - "name": "check_gcp_environment_linux_test", - "src": [ - "test/core/security/check_gcp_environment_linux_test.cc" - ], - "third_party": false, - "type": "target" - }, - { - "deps": [ - "gpr", - "grpc" - ], - "headers": [], - "is_filegroup": false, - "language": "c++", - "name": "check_gcp_environment_windows_test", - "src": [ - "test/core/security/check_gcp_environment_windows_test.cc" - ], - "third_party": false, - "type": "target" - }, { "deps": [ "gpr", @@ -3449,21 +3210,6 @@ "third_party": false, "type": "target" }, - { - "deps": [ - "gpr", - "grpc" - ], - "headers": [], - "is_filegroup": false, - "language": "c++", - "name": "grpc_alts_credentials_options_test", - "src": [ - "test/core/security/grpc_alts_credentials_options_test.cc" - ], - "third_party": false, - "type": "target" - }, { "deps": [ "gpr", @@ -4625,22 +4371,6 @@ "third_party": false, "type": "target" }, - { - "deps": [ - "alts_test_util", - "gpr", - "grpc" - ], - "headers": [], - "is_filegroup": false, - "language": "c++", - "name": "transport_security_common_api_test", - "src": [ - "test/core/tsi/alts/handshaker/transport_security_common_api_test.cc" - ], - "third_party": false, - "type": "target" - }, { "deps": [ "gpr", @@ -6559,26 +6289,6 @@ "third_party": false, "type": "target" }, - { - "deps": [ - "grpc" - ], - "headers": [ - "test/core/tsi/alts/crypt/gsec_test_util.h", - "test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h" - ], - "is_filegroup": false, - "language": "c", - "name": "alts_test_util", - "src": [ - "test/core/tsi/alts/crypt/gsec_test_util.cc", - "test/core/tsi/alts/crypt/gsec_test_util.h", - "test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc", - "test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h" - ], - "third_party": false, - "type": "lib" - }, { "deps": [ "gpr_base" @@ -8577,138 +8287,6 @@ "third_party": false, "type": "lib" }, - { - "deps": [ - "nanopb" - ], - "headers": [ - "src/core/tsi/alts/handshaker/altscontext.pb.h", - "src/core/tsi/alts/handshaker/handshaker.pb.h", - "src/core/tsi/alts/handshaker/transport_security_common.pb.h" - ], - "is_filegroup": true, - "language": "c", - "name": "alts_proto", - "src": [ - "src/core/tsi/alts/handshaker/altscontext.pb.c", - "src/core/tsi/alts/handshaker/altscontext.pb.h", - "src/core/tsi/alts/handshaker/handshaker.pb.c", - "src/core/tsi/alts/handshaker/handshaker.pb.h", - "src/core/tsi/alts/handshaker/transport_security_common.pb.c", - "src/core/tsi/alts/handshaker/transport_security_common.pb.h" - ], - "third_party": false, - "type": "filegroup" - }, - { - "deps": [ - "alts_util", - "gpr", - "grpc_base", - "grpc_transport_chttp2_client_insecure", - "tsi", - "tsi_interface" - ], - "headers": [ - "src/core/tsi/alts/crypt/gsec.h", - "src/core/tsi/alts/frame_protector/alts_counter.h", - "src/core/tsi/alts/frame_protector/alts_crypter.h", - "src/core/tsi/alts/frame_protector/alts_frame_protector.h", - "src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h", - "src/core/tsi/alts/frame_protector/frame_handler.h", - "src/core/tsi/alts/handshaker/alts_handshaker_client.h", - "src/core/tsi/alts/handshaker/alts_tsi_event.h", - "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h", - "src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h", - "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h", - "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h", - "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h", - "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h", - "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h", - "src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h" - ], - "is_filegroup": true, - "language": "c", - "name": "alts_tsi", - "src": [ - "src/core/tsi/alts/crypt/aes_gcm.cc", - "src/core/tsi/alts/crypt/gsec.cc", - "src/core/tsi/alts/crypt/gsec.h", - "src/core/tsi/alts/frame_protector/alts_counter.cc", - "src/core/tsi/alts/frame_protector/alts_counter.h", - "src/core/tsi/alts/frame_protector/alts_crypter.cc", - "src/core/tsi/alts/frame_protector/alts_crypter.h", - "src/core/tsi/alts/frame_protector/alts_frame_protector.cc", - "src/core/tsi/alts/frame_protector/alts_frame_protector.h", - "src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc", - "src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h", - "src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc", - "src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc", - "src/core/tsi/alts/frame_protector/frame_handler.cc", - "src/core/tsi/alts/frame_protector/frame_handler.h", - "src/core/tsi/alts/handshaker/alts_handshaker_client.cc", - "src/core/tsi/alts/handshaker/alts_handshaker_client.h", - "src/core/tsi/alts/handshaker/alts_tsi_event.cc", - "src/core/tsi/alts/handshaker/alts_tsi_event.h", - "src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc", - "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h", - "src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h", - "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc", - "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h", - "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc", - "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h", - "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h", - "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc", - "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h", - "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc", - "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h", - "src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc", - "src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h" - ], - "third_party": false, - "type": "filegroup" - }, - { - "deps": [ - "alts_proto", - "gpr", - "grpc_base", - "nanopb", - "tsi_interface" - ], - "headers": [ - "src/core/lib/security/credentials/alts/check_gcp_environment.h", - "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h", - "src/core/tsi/alts/handshaker/alts_handshaker_service_api.h", - "src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h", - "src/core/tsi/alts/handshaker/alts_tsi_utils.h", - "src/core/tsi/alts/handshaker/transport_security_common_api.h" - ], - "is_filegroup": true, - "language": "c", - "name": "alts_util", - "src": [ - "src/core/lib/security/credentials/alts/check_gcp_environment.cc", - "src/core/lib/security/credentials/alts/check_gcp_environment.h", - "src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc", - "src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc", - "src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc", - "src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc", - "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc", - "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h", - "src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc", - "src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc", - "src/core/tsi/alts/handshaker/alts_handshaker_service_api.h", - "src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc", - "src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h", - "src/core/tsi/alts/handshaker/alts_tsi_utils.cc", - "src/core/tsi/alts/handshaker/alts_tsi_utils.h", - "src/core/tsi/alts/handshaker/transport_security_common_api.cc", - "src/core/tsi/alts/handshaker/transport_security_common_api.h" - ], - "third_party": false, - "type": "filegroup" - }, { "deps": [ "gpr", @@ -9793,7 +9371,6 @@ }, { "deps": [ - "alts_tsi", "gpr", "grpc_base", "grpc_transport_chttp2_alpn", @@ -9802,7 +9379,6 @@ "headers": [ "include/grpc/grpc_security.h", "src/core/lib/security/context/security_context.h", - "src/core/lib/security/credentials/alts/alts_credentials.h", "src/core/lib/security/credentials/composite/composite_credentials.h", "src/core/lib/security/credentials/credentials.h", "src/core/lib/security/credentials/fake/fake_credentials.h", @@ -9814,7 +9390,6 @@ "src/core/lib/security/credentials/oauth2/oauth2_credentials.h", "src/core/lib/security/credentials/plugin/plugin_credentials.h", "src/core/lib/security/credentials/ssl/ssl_credentials.h", - "src/core/lib/security/security_connector/alts_security_connector.h", "src/core/lib/security/security_connector/security_connector.h", "src/core/lib/security/transport/auth_filters.h", "src/core/lib/security/transport/secure_endpoint.h", @@ -9831,8 +9406,6 @@ "src/core/lib/http/httpcli_security_connector.cc", "src/core/lib/security/context/security_context.cc", "src/core/lib/security/context/security_context.h", - "src/core/lib/security/credentials/alts/alts_credentials.cc", - "src/core/lib/security/credentials/alts/alts_credentials.h", "src/core/lib/security/credentials/composite/composite_credentials.cc", "src/core/lib/security/credentials/composite/composite_credentials.h", "src/core/lib/security/credentials/credentials.cc", @@ -9857,8 +9430,6 @@ "src/core/lib/security/credentials/plugin/plugin_credentials.h", "src/core/lib/security/credentials/ssl/ssl_credentials.cc", "src/core/lib/security/credentials/ssl/ssl_credentials.h", - "src/core/lib/security/security_connector/alts_security_connector.cc", - "src/core/lib/security/security_connector/alts_security_connector.h", "src/core/lib/security/security_connector/security_connector.cc", "src/core/lib/security/security_connector/security_connector.h", "src/core/lib/security/transport/auth_filters.h", diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index b7fdb6f579..6ce7ec28c4 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -2863,318 +2863,6 @@ ], "uses_polling": true }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": false, - "language": "c++", - "name": "alts_counter_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": true - }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": false, - "language": "c++", - "name": "alts_crypt_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": true - }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": false, - "language": "c++", - "name": "alts_crypter_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": true - }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": false, - "language": "c++", - "name": "alts_frame_handler_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": true - }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": false, - "language": "c++", - "name": "alts_frame_protector_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": true - }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": false, - "language": "c++", - "name": "alts_grpc_record_protocol_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": true - }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": false, - "language": "c++", - "name": "alts_handshaker_client_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": true - }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": false, - "language": "c++", - "name": "alts_handshaker_service_api_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": true - }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": false, - "language": "c++", - "name": "alts_iovec_record_protocol_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": true - }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": false, - "language": "c++", - "name": "alts_security_connector_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": true - }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": false, - "language": "c++", - "name": "alts_tsi_handshaker_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": true - }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": false, - "language": "c++", - "name": "alts_tsi_utils_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": true - }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": false, - "language": "c++", - "name": "alts_zero_copy_grpc_protector_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": true - }, { "args": [], "benchmark": false, @@ -3649,54 +3337,6 @@ ], "uses_polling": false }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": false, - "language": "c++", - "name": "check_gcp_environment_linux_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": true - }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": false, - "language": "c++", - "name": "check_gcp_environment_windows_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": true - }, { "args": [], "benchmark": false, @@ -4129,30 +3769,6 @@ ], "uses_polling": false }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": false, - "language": "c++", - "name": "grpc_alts_credentials_options_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": true - }, { "args": [], "benchmark": false, @@ -5056,30 +4672,6 @@ ], "uses_polling": true }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": false, - "language": "c++", - "name": "transport_security_common_api_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": true - }, { "args": [], "benchmark": false, -- cgit v1.2.3 From 04fb58efbd62e11466b79dbdf4f1433cc2c75a89 Mon Sep 17 00:00:00 2001 From: Yihua Zhang Date: Thu, 8 Mar 2018 06:49:24 -0800 Subject: Add ALTS code to grpc/core --- BUILD | 112 ++ CMakeLists.txt | 1081 ++++++++-- Makefile | 1329 ++++++++++-- bazel/grpc_build_system.bzl | 9 +- build.yaml | 247 +++ config.m4 | 62 +- config.w32 | 63 +- gRPC-C++.podspec | 41 +- gRPC-Core.podspec | 144 +- grpc.gemspec | 106 +- grpc.gyp | 74 +- package.xml | 106 +- setup.py | 3 +- .../security/credentials/alts/alts_credentials.cc | 119 ++ .../security/credentials/alts/alts_credentials.h | 102 + .../credentials/alts/check_gcp_environment.cc | 72 + .../credentials/alts/check_gcp_environment.h | 57 + .../alts/check_gcp_environment_linux.cc | 67 + .../alts/check_gcp_environment_no_op.cc | 33 + .../alts/check_gcp_environment_windows.cc | 114 ++ .../alts/grpc_alts_credentials_client_options.cc | 126 ++ .../alts/grpc_alts_credentials_options.cc | 46 + .../alts/grpc_alts_credentials_options.h | 112 ++ .../alts/grpc_alts_credentials_server_options.cc | 58 + .../security_connector/alts_security_connector.cc | 287 +++ .../security_connector/alts_security_connector.h | 69 + src/core/plugin_registry/grpc_plugin_registry.cc | 8 +- src/core/tsi/alts/crypt/aes_gcm.cc | 687 +++++++ src/core/tsi/alts/crypt/gsec.cc | 189 ++ src/core/tsi/alts/crypt/gsec.h | 454 +++++ src/core/tsi/alts/frame_protector/alts_counter.cc | 118 ++ src/core/tsi/alts/frame_protector/alts_counter.h | 98 + src/core/tsi/alts/frame_protector/alts_crypter.cc | 66 + src/core/tsi/alts/frame_protector/alts_crypter.h | 255 +++ .../alts/frame_protector/alts_frame_protector.cc | 407 ++++ .../alts/frame_protector/alts_frame_protector.h | 55 + .../alts_record_protocol_crypter_common.cc | 114 ++ .../alts_record_protocol_crypter_common.h | 114 ++ .../alts_seal_privacy_integrity_crypter.cc | 105 + .../alts_unseal_privacy_integrity_crypter.cc | 103 + src/core/tsi/alts/frame_protector/frame_handler.cc | 218 ++ src/core/tsi/alts/frame_protector/frame_handler.h | 236 +++ .../tsi/alts/handshaker/alts_handshaker_client.cc | 316 +++ .../tsi/alts/handshaker/alts_handshaker_client.h | 137 ++ .../alts/handshaker/alts_handshaker_service_api.cc | 520 +++++ .../alts/handshaker/alts_handshaker_service_api.h | 323 +++ .../handshaker/alts_handshaker_service_api_util.cc | 143 ++ .../handshaker/alts_handshaker_service_api_util.h | 149 ++ src/core/tsi/alts/handshaker/alts_tsi_event.cc | 73 + src/core/tsi/alts/handshaker/alts_tsi_event.h | 93 + .../tsi/alts/handshaker/alts_tsi_handshaker.cc | 483 +++++ src/core/tsi/alts/handshaker/alts_tsi_handshaker.h | 83 + .../alts/handshaker/alts_tsi_handshaker_private.h | 52 + src/core/tsi/alts/handshaker/alts_tsi_utils.cc | 58 + src/core/tsi/alts/handshaker/alts_tsi_utils.h | 52 + src/core/tsi/alts/handshaker/altscontext.pb.c | 48 + src/core/tsi/alts/handshaker/altscontext.pb.h | 64 + src/core/tsi/alts/handshaker/handshaker.pb.c | 123 ++ src/core/tsi/alts/handshaker/handshaker.pb.h | 255 +++ .../tsi/alts/handshaker/proto/altscontext.proto | 41 + .../tsi/alts/handshaker/proto/handshaker.options | 2 + .../tsi/alts/handshaker/proto/handshaker.proto | 220 ++ .../proto/transport_security_common.proto | 40 + .../alts/handshaker/transport_security_common.pb.c | 50 + .../alts/handshaker/transport_security_common.pb.h | 78 + .../handshaker/transport_security_common_api.cc | 196 ++ .../handshaker/transport_security_common_api.h | 163 ++ .../alts_grpc_integrity_only_record_protocol.cc | 180 ++ .../alts_grpc_integrity_only_record_protocol.h | 52 + .../alts_grpc_privacy_integrity_record_protocol.cc | 144 ++ .../alts_grpc_privacy_integrity_record_protocol.h | 49 + .../alts_grpc_record_protocol.h | 91 + .../alts_grpc_record_protocol_common.cc | 173 ++ .../alts_grpc_record_protocol_common.h | 100 + .../alts_iovec_record_protocol.cc | 476 +++++ .../alts_iovec_record_protocol.h | 199 ++ .../alts_zero_copy_grpc_protector.cc | 295 +++ .../alts_zero_copy_grpc_protector.h | 52 + src/python/grpcio/grpc_core_dependencies.py | 57 +- templates/CMakeLists.txt.template | 2 + templates/Makefile.template | 2 + templates/gRPC-Core.podspec.template | 2 +- templates/grpc.gyp.template | 6 +- test/core/security/BUILD | 49 + test/core/security/alts_security_connector_test.cc | 166 ++ .../security/check_gcp_environment_linux_test.cc | 83 + .../security/check_gcp_environment_windows_test.cc | 71 + .../security/grpc_alts_credentials_options_test.cc | 118 ++ test/core/tsi/BUILD | 2 +- test/core/tsi/alts/crypt/BUILD | 42 + test/core/tsi/alts/crypt/aes_gcm_test.cc | 2105 ++++++++++++++++++++ test/core/tsi/alts/crypt/gsec_test_util.cc | 89 + test/core/tsi/alts/crypt/gsec_test_util.h | 89 + test/core/tsi/alts/frame_protector/BUILD | 71 + .../tsi/alts/frame_protector/alts_counter_test.cc | 180 ++ .../tsi/alts/frame_protector/alts_crypter_test.cc | 493 +++++ .../frame_protector/alts_frame_protector_test.cc | 394 ++++ .../tsi/alts/frame_protector/frame_handler_test.cc | 244 +++ test/core/tsi/alts/handshaker/BUILD | 86 + .../alts/handshaker/alts_handshaker_client_test.cc | 412 ++++ .../handshaker/alts_handshaker_service_api_test.cc | 149 ++ .../alts_handshaker_service_api_test_lib.cc | 642 ++++++ .../alts_handshaker_service_api_test_lib.h | 143 ++ .../alts/handshaker/alts_tsi_handshaker_test.cc | 682 +++++++ .../tsi/alts/handshaker/alts_tsi_utils_test.cc | 73 + .../transport_security_common_api_test.cc | 196 ++ test/core/tsi/alts/zero_copy_frame_protector/BUILD | 57 + .../alts_grpc_record_protocol_test.cc | 449 +++++ .../alts_iovec_record_protocol_test.cc | 928 +++++++++ .../alts_zero_copy_grpc_protector_test.cc | 289 +++ test/core/tsi/fake_transport_security_test.cc | 2 +- test/core/tsi/ssl_transport_security_test.cc | 2 +- test/core/tsi/transport_security_test_lib.cc | 224 ++- test/core/tsi/transport_security_test_lib.h | 89 +- third_party/nanopb/pb.h | 2 +- tools/codegen/core/gen_nano_proto.sh | 9 +- tools/distrib/check_copyright.py | 6 + tools/distrib/check_include_guards.py | 3 + tools/distrib/check_nanopb_output.sh | 27 + tools/doxygen/Doxyfile.core.internal | 60 + tools/run_tests/generated/sources_and_headers.json | 429 ++++ tools/run_tests/generated/tests.json | 408 ++++ 122 files changed, 22474 insertions(+), 597 deletions(-) create mode 100644 src/core/lib/security/credentials/alts/alts_credentials.cc create mode 100644 src/core/lib/security/credentials/alts/alts_credentials.h create mode 100644 src/core/lib/security/credentials/alts/check_gcp_environment.cc create mode 100644 src/core/lib/security/credentials/alts/check_gcp_environment.h create mode 100644 src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc create mode 100644 src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc create mode 100644 src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc create mode 100644 src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc create mode 100644 src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc create mode 100644 src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h create mode 100644 src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc create mode 100644 src/core/lib/security/security_connector/alts_security_connector.cc create mode 100644 src/core/lib/security/security_connector/alts_security_connector.h create mode 100644 src/core/tsi/alts/crypt/aes_gcm.cc create mode 100644 src/core/tsi/alts/crypt/gsec.cc create mode 100644 src/core/tsi/alts/crypt/gsec.h create mode 100644 src/core/tsi/alts/frame_protector/alts_counter.cc create mode 100644 src/core/tsi/alts/frame_protector/alts_counter.h create mode 100644 src/core/tsi/alts/frame_protector/alts_crypter.cc create mode 100644 src/core/tsi/alts/frame_protector/alts_crypter.h create mode 100644 src/core/tsi/alts/frame_protector/alts_frame_protector.cc create mode 100644 src/core/tsi/alts/frame_protector/alts_frame_protector.h create mode 100644 src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc create mode 100644 src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h create mode 100644 src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc create mode 100644 src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc create mode 100644 src/core/tsi/alts/frame_protector/frame_handler.cc create mode 100644 src/core/tsi/alts/frame_protector/frame_handler.h create mode 100644 src/core/tsi/alts/handshaker/alts_handshaker_client.cc create mode 100644 src/core/tsi/alts/handshaker/alts_handshaker_client.h create mode 100644 src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc create mode 100644 src/core/tsi/alts/handshaker/alts_handshaker_service_api.h create mode 100644 src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc create mode 100644 src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h create mode 100644 src/core/tsi/alts/handshaker/alts_tsi_event.cc create mode 100644 src/core/tsi/alts/handshaker/alts_tsi_event.h create mode 100644 src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc create mode 100644 src/core/tsi/alts/handshaker/alts_tsi_handshaker.h create mode 100644 src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h create mode 100644 src/core/tsi/alts/handshaker/alts_tsi_utils.cc create mode 100644 src/core/tsi/alts/handshaker/alts_tsi_utils.h create mode 100644 src/core/tsi/alts/handshaker/altscontext.pb.c create mode 100644 src/core/tsi/alts/handshaker/altscontext.pb.h create mode 100644 src/core/tsi/alts/handshaker/handshaker.pb.c create mode 100644 src/core/tsi/alts/handshaker/handshaker.pb.h create mode 100644 src/core/tsi/alts/handshaker/proto/altscontext.proto create mode 100644 src/core/tsi/alts/handshaker/proto/handshaker.options create mode 100644 src/core/tsi/alts/handshaker/proto/handshaker.proto create mode 100644 src/core/tsi/alts/handshaker/proto/transport_security_common.proto create mode 100644 src/core/tsi/alts/handshaker/transport_security_common.pb.c create mode 100644 src/core/tsi/alts/handshaker/transport_security_common.pb.h create mode 100644 src/core/tsi/alts/handshaker/transport_security_common_api.cc create mode 100644 src/core/tsi/alts/handshaker/transport_security_common_api.h create mode 100644 src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc create mode 100644 src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h create mode 100644 src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc create mode 100644 src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h create mode 100644 src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h create mode 100644 src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc create mode 100644 src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h create mode 100644 src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc create mode 100644 src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h create mode 100644 src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc create mode 100644 src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h create mode 100644 test/core/security/alts_security_connector_test.cc create mode 100644 test/core/security/check_gcp_environment_linux_test.cc create mode 100644 test/core/security/check_gcp_environment_windows_test.cc create mode 100644 test/core/security/grpc_alts_credentials_options_test.cc create mode 100644 test/core/tsi/alts/crypt/BUILD create mode 100644 test/core/tsi/alts/crypt/aes_gcm_test.cc create mode 100644 test/core/tsi/alts/crypt/gsec_test_util.cc create mode 100644 test/core/tsi/alts/crypt/gsec_test_util.h create mode 100644 test/core/tsi/alts/frame_protector/BUILD create mode 100644 test/core/tsi/alts/frame_protector/alts_counter_test.cc create mode 100644 test/core/tsi/alts/frame_protector/alts_crypter_test.cc create mode 100644 test/core/tsi/alts/frame_protector/alts_frame_protector_test.cc create mode 100644 test/core/tsi/alts/frame_protector/frame_handler_test.cc create mode 100644 test/core/tsi/alts/handshaker/BUILD create mode 100644 test/core/tsi/alts/handshaker/alts_handshaker_client_test.cc create mode 100644 test/core/tsi/alts/handshaker/alts_handshaker_service_api_test.cc create mode 100644 test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc create mode 100644 test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h create mode 100644 test/core/tsi/alts/handshaker/alts_tsi_handshaker_test.cc create mode 100644 test/core/tsi/alts/handshaker/alts_tsi_utils_test.cc create mode 100644 test/core/tsi/alts/handshaker/transport_security_common_api_test.cc create mode 100644 test/core/tsi/alts/zero_copy_frame_protector/BUILD create mode 100644 test/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_test.cc create mode 100644 test/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol_test.cc create mode 100644 test/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector_test.cc (limited to 'gRPC-C++.podspec') diff --git a/BUILD b/BUILD index 4fe3dc660e..9c99f95fcd 100644 --- a/BUILD +++ b/BUILD @@ -1326,6 +1326,8 @@ grpc_cc_library( "src/core/lib/security/credentials/oauth2/oauth2_credentials.cc", "src/core/lib/security/credentials/plugin/plugin_credentials.cc", "src/core/lib/security/credentials/ssl/ssl_credentials.cc", + "src/core/lib/security/credentials/alts/alts_credentials.cc", + "src/core/lib/security/security_connector/alts_security_connector.cc", "src/core/lib/security/security_connector/security_connector.cc", "src/core/lib/security/transport/client_auth_filter.cc", "src/core/lib/security/transport/secure_endpoint.cc", @@ -1349,6 +1351,8 @@ grpc_cc_library( "src/core/lib/security/credentials/oauth2/oauth2_credentials.h", "src/core/lib/security/credentials/plugin/plugin_credentials.h", "src/core/lib/security/credentials/ssl/ssl_credentials.h", + "src/core/lib/security/credentials/alts/alts_credentials.h", + "src/core/lib/security/security_connector/alts_security_connector.h", "src/core/lib/security/security_connector/security_connector.h", "src/core/lib/security/transport/auth_filters.h", "src/core/lib/security/transport/secure_endpoint.h", @@ -1360,6 +1364,7 @@ grpc_cc_library( language = "c++", public_hdrs = GRPC_SECURE_PUBLIC_HDRS, deps = [ + "alts_util", "grpc_base", "grpc_transport_chttp2_alpn", "tsi", @@ -1582,16 +1587,119 @@ grpc_cc_library( ], ) +grpc_cc_library( + name = "alts_frame_protector", + srcs = [ + "src/core/tsi/alts/crypt/aes_gcm.cc", + "src/core/tsi/alts/crypt/gsec.cc", + "src/core/tsi/alts/frame_protector/alts_counter.cc", + "src/core/tsi/alts/frame_protector/alts_crypter.cc", + "src/core/tsi/alts/frame_protector/alts_frame_protector.cc", + "src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc", + "src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc", + "src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc", + "src/core/tsi/alts/frame_protector/frame_handler.cc", + "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc", + "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc", + "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc", + "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc", + "src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc", + ], + hdrs = [ + "src/core/tsi/alts/crypt/gsec.h", + "src/core/tsi/alts/frame_protector/alts_counter.h", + "src/core/tsi/alts/frame_protector/alts_crypter.h", + "src/core/tsi/alts/frame_protector/alts_frame_protector.h", + "src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h", + "src/core/tsi/alts/frame_protector/frame_handler.h", + "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h", + "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h", + "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h", + "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h", + "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h", + "src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h", + "src/core/tsi/transport_security_grpc.h", + ], + external_deps = [ + "libssl", + ], + language = "c++", + deps = [ + "gpr", + "grpc_base", + "tsi_interface", + ], +) + +grpc_cc_library( + name = "alts_proto", + srcs = [ + "src/core/tsi/alts/handshaker/altscontext.pb.c", + "src/core/tsi/alts/handshaker/handshaker.pb.c", + "src/core/tsi/alts/handshaker/transport_security_common.pb.c", + ], + hdrs = [ + "src/core/tsi/alts/handshaker/altscontext.pb.h", + "src/core/tsi/alts/handshaker/handshaker.pb.h", + "src/core/tsi/alts/handshaker/transport_security_common.pb.h", + ], + external_deps = [ + "nanopb", + ], + language = "c++", +) + +grpc_cc_library( + name = "alts_util", + srcs = [ + "src/core/lib/security/credentials/alts/check_gcp_environment.cc", + "src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc", + "src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc", + "src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc", + "src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc", + "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc", + "src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc", + "src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc", + "src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc", + "src/core/tsi/alts/handshaker/transport_security_common_api.cc", + ], + hdrs = [ + "src/core/lib/security/credentials/alts/check_gcp_environment.h", + "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h", + "src/core/tsi/alts/handshaker/alts_handshaker_service_api.h", + "src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h", + "src/core/tsi/alts/handshaker/transport_security_common_api.h", + ], + external_deps = [ + "nanopb", + ], + language = "c++", + deps = [ + "alts_proto", + "gpr", + "grpc_base", + ], +) + grpc_cc_library( name = "tsi", srcs = [ "src/core/tsi/alts_transport_security.cc", + "src/core/tsi/alts/handshaker/alts_handshaker_client.cc", + "src/core/tsi/alts/handshaker/alts_tsi_event.cc", + "src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc", + "src/core/tsi/alts/handshaker/alts_tsi_utils.cc", "src/core/tsi/fake_transport_security.cc", "src/core/tsi/ssl_transport_security.cc", "src/core/tsi/transport_security_grpc.cc", ], hdrs = [ "src/core/tsi/alts_transport_security.h", + "src/core/tsi/alts/handshaker/alts_handshaker_client.h", + "src/core/tsi/alts/handshaker/alts_tsi_event.h", + "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h", + "src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h", + "src/core/tsi/alts/handshaker/alts_tsi_utils.h", "src/core/tsi/fake_transport_security.h", "src/core/tsi/ssl_transport_security.h", "src/core/tsi/ssl_types.h", @@ -1602,7 +1710,11 @@ grpc_cc_library( ], language = "c++", deps = [ + "alts_frame_protector", + "alts_util", + "gpr", "grpc_base", + "grpc_transport_chttp2_client_insecure", "tsi_interface", ], ) diff --git a/CMakeLists.txt b/CMakeLists.txt index ab4fa8a253..5dfbdcb85a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,6 +91,8 @@ endif() set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) +add_definitions(-DPB_FIELD_16BIT) + if (MSVC) include(cmake/msvc_static_runtime.cmake) add_definitions(-D_WIN32_WINNT=0x600 -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS) @@ -469,6 +471,19 @@ add_dependencies(buildtests_c uri_fuzzer_test_one_entry) add_custom_target(buildtests_cxx) add_dependencies(buildtests_cxx alarm_test) +add_dependencies(buildtests_cxx alts_counter_test) +add_dependencies(buildtests_cxx alts_crypt_test) +add_dependencies(buildtests_cxx alts_crypter_test) +add_dependencies(buildtests_cxx alts_frame_handler_test) +add_dependencies(buildtests_cxx alts_frame_protector_test) +add_dependencies(buildtests_cxx alts_grpc_record_protocol_test) +add_dependencies(buildtests_cxx alts_handshaker_client_test) +add_dependencies(buildtests_cxx alts_handshaker_service_api_test) +add_dependencies(buildtests_cxx alts_iovec_record_protocol_test) +add_dependencies(buildtests_cxx alts_security_connector_test) +add_dependencies(buildtests_cxx alts_tsi_handshaker_test) +add_dependencies(buildtests_cxx alts_tsi_utils_test) +add_dependencies(buildtests_cxx alts_zero_copy_grpc_protector_test) add_dependencies(buildtests_cxx async_end2end_test) add_dependencies(buildtests_cxx auth_property_iterator_test) add_dependencies(buildtests_cxx backoff_test) @@ -517,6 +532,8 @@ add_dependencies(buildtests_cxx bm_pollset) endif() add_dependencies(buildtests_cxx channel_arguments_test) add_dependencies(buildtests_cxx channel_filter_test) +add_dependencies(buildtests_cxx check_gcp_environment_linux_test) +add_dependencies(buildtests_cxx check_gcp_environment_windows_test) add_dependencies(buildtests_cxx chttp2_settings_timeout_test) add_dependencies(buildtests_cxx cli_call_test) add_dependencies(buildtests_cxx client_channel_stress_test) @@ -538,6 +555,7 @@ add_dependencies(buildtests_cxx exception_test) add_dependencies(buildtests_cxx filter_end2end_test) add_dependencies(buildtests_cxx generic_end2end_test) add_dependencies(buildtests_cxx golden_file_test) +add_dependencies(buildtests_cxx grpc_alts_credentials_options_test) add_dependencies(buildtests_cxx grpc_cli) add_dependencies(buildtests_cxx grpc_tool_test) add_dependencies(buildtests_cxx grpclb_api_test) @@ -611,6 +629,7 @@ add_dependencies(buildtests_cxx stress_test) add_dependencies(buildtests_cxx thread_manager_test) add_dependencies(buildtests_cxx thread_stress_test) add_dependencies(buildtests_cxx transport_pid_controller_test) +add_dependencies(buildtests_cxx transport_security_common_api_test) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) add_dependencies(buildtests_cxx writes_per_rpc_test) endif() @@ -631,6 +650,44 @@ add_custom_target(buildtests DEPENDS buildtests_c buildtests_cxx) endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(alts_test_util + test/core/tsi/alts/crypt/gsec_test_util.cc + test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc +) + +if(WIN32 AND MSVC) + set_target_properties(alts_test_util PROPERTIES COMPILE_PDB_NAME "alts_test_util" + COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" + ) + if (gRPC_INSTALL) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/alts_test_util.pdb + DESTINATION ${gRPC_INSTALL_LIBDIR} OPTIONAL + ) + endif() +endif() + + +target_include_directories(alts_test_util + PUBLIC $ $ + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${_gRPC_SSL_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} + PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} + PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} + PRIVATE ${_gRPC_CARES_INCLUDE_DIR} + PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} +) + +target_link_libraries(alts_test_util + ${_gRPC_SSL_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc +) + + +endif (gRPC_BUILD_TESTS) add_library(gpr src/core/lib/gpr/alloc.cc @@ -959,6 +1016,7 @@ add_library(grpc src/core/ext/filters/http/server/http_server_filter.cc src/core/lib/http/httpcli_security_connector.cc src/core/lib/security/context/security_context.cc + src/core/lib/security/credentials/alts/alts_credentials.cc src/core/lib/security/credentials/composite/composite_credentials.cc src/core/lib/security/credentials/credentials.cc src/core/lib/security/credentials/credentials_metadata.cc @@ -972,6 +1030,7 @@ add_library(grpc src/core/lib/security/credentials/oauth2/oauth2_credentials.cc src/core/lib/security/credentials/plugin/plugin_credentials.cc src/core/lib/security/credentials/ssl/ssl_credentials.cc + src/core/lib/security/security_connector/alts_security_connector.cc src/core/lib/security/security_connector/security_connector.cc src/core/lib/security/transport/client_auth_filter.cc src/core/lib/security/transport/secure_endpoint.cc @@ -981,14 +1040,45 @@ add_library(grpc src/core/lib/security/transport/tsi_error.cc src/core/lib/security/util/json_util.cc src/core/lib/surface/init_secure.cc - src/core/tsi/alts_transport_security.cc - src/core/tsi/fake_transport_security.cc - src/core/tsi/ssl_transport_security.cc - src/core/tsi/transport_security_grpc.cc + src/core/tsi/alts/crypt/aes_gcm.cc + src/core/tsi/alts/crypt/gsec.cc + src/core/tsi/alts/frame_protector/alts_counter.cc + src/core/tsi/alts/frame_protector/alts_crypter.cc + src/core/tsi/alts/frame_protector/alts_frame_protector.cc + src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc + src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc + src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc + src/core/tsi/alts/frame_protector/frame_handler.cc + src/core/tsi/alts/handshaker/alts_handshaker_client.cc + src/core/tsi/alts/handshaker/alts_tsi_event.cc + src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc + src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc + src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc + src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc + src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc + src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc + src/core/lib/security/credentials/alts/check_gcp_environment.cc + src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc + src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc + src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc + src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc + src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc + src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc + src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc + src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc + src/core/tsi/alts/handshaker/alts_tsi_utils.cc + src/core/tsi/alts/handshaker/transport_security_common_api.cc + src/core/tsi/alts/handshaker/altscontext.pb.c + src/core/tsi/alts/handshaker/handshaker.pb.c + src/core/tsi/alts/handshaker/transport_security_common.pb.c + third_party/nanopb/pb_common.c + third_party/nanopb/pb_decode.c + third_party/nanopb/pb_encode.c src/core/tsi/transport_security.cc src/core/tsi/transport_security_adapter.cc - src/core/ext/transport/chttp2/server/chttp2_server.cc - src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc + src/core/ext/transport/chttp2/client/insecure/channel_create.cc + src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc + src/core/ext/transport/chttp2/client/chttp2_connector.cc src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc src/core/ext/filters/client_channel/client_channel.cc @@ -1012,11 +1102,14 @@ add_library(grpc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc src/core/ext/filters/deadline/deadline_filter.cc - src/core/ext/transport/chttp2/client/chttp2_connector.cc + src/core/tsi/alts_transport_security.cc + src/core/tsi/fake_transport_security.cc + src/core/tsi/ssl_transport_security.cc + src/core/tsi/transport_security_grpc.cc + src/core/ext/transport/chttp2/server/chttp2_server.cc + src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc - src/core/ext/transport/chttp2/client/insecure/channel_create.cc - src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc src/core/ext/transport/inproc/inproc_plugin.cc src/core/ext/transport/inproc/inproc_transport.cc src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc @@ -1025,9 +1118,6 @@ add_library(grpc src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c - third_party/nanopb/pb_common.c - third_party/nanopb/pb_decode.c - third_party/nanopb/pb_encode.c src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc @@ -1327,6 +1417,7 @@ add_library(grpc_cronet src/core/ext/filters/deadline/deadline_filter.cc src/core/lib/http/httpcli_security_connector.cc src/core/lib/security/context/security_context.cc + src/core/lib/security/credentials/alts/alts_credentials.cc src/core/lib/security/credentials/composite/composite_credentials.cc src/core/lib/security/credentials/credentials.cc src/core/lib/security/credentials/credentials_metadata.cc @@ -1340,6 +1431,7 @@ add_library(grpc_cronet src/core/lib/security/credentials/oauth2/oauth2_credentials.cc src/core/lib/security/credentials/plugin/plugin_credentials.cc src/core/lib/security/credentials/ssl/ssl_credentials.cc + src/core/lib/security/security_connector/alts_security_connector.cc src/core/lib/security/security_connector/security_connector.cc src/core/lib/security/transport/client_auth_filter.cc src/core/lib/security/transport/secure_endpoint.cc @@ -1349,13 +1441,49 @@ add_library(grpc_cronet src/core/lib/security/transport/tsi_error.cc src/core/lib/security/util/json_util.cc src/core/lib/surface/init_secure.cc + src/core/tsi/alts/crypt/aes_gcm.cc + src/core/tsi/alts/crypt/gsec.cc + src/core/tsi/alts/frame_protector/alts_counter.cc + src/core/tsi/alts/frame_protector/alts_crypter.cc + src/core/tsi/alts/frame_protector/alts_frame_protector.cc + src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc + src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc + src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc + src/core/tsi/alts/frame_protector/frame_handler.cc + src/core/tsi/alts/handshaker/alts_handshaker_client.cc + src/core/tsi/alts/handshaker/alts_tsi_event.cc + src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc + src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc + src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc + src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc + src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc + src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc + src/core/lib/security/credentials/alts/check_gcp_environment.cc + src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc + src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc + src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc + src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc + src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc + src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc + src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc + src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc + src/core/tsi/alts/handshaker/alts_tsi_utils.cc + src/core/tsi/alts/handshaker/transport_security_common_api.cc + src/core/tsi/alts/handshaker/altscontext.pb.c + src/core/tsi/alts/handshaker/handshaker.pb.c + src/core/tsi/alts/handshaker/transport_security_common.pb.c + third_party/nanopb/pb_common.c + third_party/nanopb/pb_decode.c + third_party/nanopb/pb_encode.c + src/core/tsi/transport_security.cc + src/core/tsi/transport_security_adapter.cc + src/core/ext/transport/chttp2/client/insecure/channel_create.cc + src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc + src/core/ext/transport/chttp2/client/chttp2_connector.cc src/core/tsi/alts_transport_security.cc src/core/tsi/fake_transport_security.cc src/core/tsi/ssl_transport_security.cc src/core/tsi/transport_security_grpc.cc - src/core/tsi/transport_security.cc - src/core/tsi/transport_security_adapter.cc - src/core/ext/transport/chttp2/client/chttp2_connector.cc src/core/ext/filters/load_reporting/server_load_reporting_filter.cc src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc src/core/plugin_registry/grpc_cronet_plugin_registry.cc @@ -8661,14 +8789,14 @@ target_link_libraries(alarm_test endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -add_executable(async_end2end_test - test/cpp/end2end/async_end2end_test.cc +add_executable(alts_counter_test + test/core/tsi/alts/frame_protector/alts_counter_test.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(async_end2end_test +target_include_directories(alts_counter_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -8684,29 +8812,26 @@ target_include_directories(async_end2end_test PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(async_end2end_test +target_link_libraries(alts_counter_test ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - grpc++_test_util - grpc_test_util - grpc++ - grpc - gpr_test_util + alts_test_util gpr + grpc ${_gRPC_GFLAGS_LIBRARIES} ) endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -add_executable(auth_property_iterator_test - test/cpp/common/auth_property_iterator_test.cc +add_executable(alts_crypt_test + test/core/tsi/alts/crypt/aes_gcm_test.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(auth_property_iterator_test +target_include_directories(alts_crypt_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -8722,29 +8847,27 @@ target_include_directories(auth_property_iterator_test PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(auth_property_iterator_test +target_link_libraries(alts_crypt_test ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - grpc++_test_util - grpc_test_util - grpc++ - grpc + alts_test_util gpr_test_util gpr + grpc ${_gRPC_GFLAGS_LIBRARIES} ) endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -add_executable(backoff_test - test/core/backoff/backoff_test.cc +add_executable(alts_crypter_test + test/core/tsi/alts/frame_protector/alts_crypter_test.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(backoff_test +target_include_directories(alts_crypter_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -8760,27 +8883,26 @@ target_include_directories(backoff_test PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(backoff_test +target_link_libraries(alts_crypter_test ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_test_util - grpc - gpr_test_util + alts_test_util gpr + grpc ${_gRPC_GFLAGS_LIBRARIES} ) endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -add_executable(bdp_estimator_test - test/core/transport/bdp_estimator_test.cc +add_executable(alts_frame_handler_test + test/core/tsi/alts/frame_protector/frame_handler_test.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(bdp_estimator_test +target_include_directories(alts_frame_handler_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -8796,30 +8918,27 @@ target_include_directories(bdp_estimator_test PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(bdp_estimator_test +target_link_libraries(alts_frame_handler_test ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - grpc++_test_util - grpc++ - grpc_test_util - grpc - gpr_test_util + alts_test_util gpr + grpc ${_gRPC_GFLAGS_LIBRARIES} ) endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) -add_executable(bm_arena - test/cpp/microbenchmarks/bm_arena.cc +add_executable(alts_frame_protector_test + test/core/tsi/alts/frame_protector/alts_frame_protector_test.cc + test/core/tsi/transport_security_test_lib.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(bm_arena +target_include_directories(alts_frame_protector_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -8835,33 +8954,26 @@ target_include_directories(bm_arena PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(bm_arena +target_link_libraries(alts_frame_protector_test ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_benchmark - ${_gRPC_BENCHMARK_LIBRARIES} - grpc++_test_util_unsecure - grpc_test_util_unsecure - grpc++_unsecure - grpc_unsecure - gpr_test_util + alts_test_util gpr + grpc ${_gRPC_GFLAGS_LIBRARIES} ) -endif() endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) -add_executable(bm_call_create - test/cpp/microbenchmarks/bm_call_create.cc +add_executable(alts_grpc_record_protocol_test + test/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_test.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(bm_call_create +target_include_directories(alts_grpc_record_protocol_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -8877,33 +8989,26 @@ target_include_directories(bm_call_create PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(bm_call_create +target_link_libraries(alts_grpc_record_protocol_test ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_benchmark - ${_gRPC_BENCHMARK_LIBRARIES} - grpc++_test_util_unsecure - grpc_test_util_unsecure - grpc++_unsecure - grpc_unsecure - gpr_test_util + alts_test_util gpr + grpc ${_gRPC_GFLAGS_LIBRARIES} ) -endif() endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) -add_executable(bm_chttp2_hpack - test/cpp/microbenchmarks/bm_chttp2_hpack.cc +add_executable(alts_handshaker_client_test + test/core/tsi/alts/handshaker/alts_handshaker_client_test.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(bm_chttp2_hpack +target_include_directories(alts_handshaker_client_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -8919,33 +9024,26 @@ target_include_directories(bm_chttp2_hpack PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(bm_chttp2_hpack +target_link_libraries(alts_handshaker_client_test ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_benchmark - ${_gRPC_BENCHMARK_LIBRARIES} - grpc++_test_util_unsecure - grpc_test_util_unsecure - grpc++_unsecure - grpc_unsecure - gpr_test_util + alts_test_util gpr + grpc ${_gRPC_GFLAGS_LIBRARIES} ) -endif() endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) -add_executable(bm_chttp2_transport - test/cpp/microbenchmarks/bm_chttp2_transport.cc +add_executable(alts_handshaker_service_api_test + test/core/tsi/alts/handshaker/alts_handshaker_service_api_test.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(bm_chttp2_transport +target_include_directories(alts_handshaker_service_api_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -8961,33 +9059,26 @@ target_include_directories(bm_chttp2_transport PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(bm_chttp2_transport +target_link_libraries(alts_handshaker_service_api_test ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_benchmark - ${_gRPC_BENCHMARK_LIBRARIES} - grpc++_test_util_unsecure - grpc_test_util_unsecure - grpc++_unsecure - grpc_unsecure - gpr_test_util + alts_test_util gpr + grpc ${_gRPC_GFLAGS_LIBRARIES} ) -endif() endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) -add_executable(bm_closure - test/cpp/microbenchmarks/bm_closure.cc +add_executable(alts_iovec_record_protocol_test + test/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol_test.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(bm_closure +target_include_directories(alts_iovec_record_protocol_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -9003,33 +9094,26 @@ target_include_directories(bm_closure PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(bm_closure +target_link_libraries(alts_iovec_record_protocol_test ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_benchmark - ${_gRPC_BENCHMARK_LIBRARIES} - grpc++_test_util_unsecure - grpc_test_util_unsecure - grpc++_unsecure - grpc_unsecure - gpr_test_util + alts_test_util gpr + grpc ${_gRPC_GFLAGS_LIBRARIES} ) -endif() endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) -add_executable(bm_cq - test/cpp/microbenchmarks/bm_cq.cc +add_executable(alts_security_connector_test + test/core/security/alts_security_connector_test.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(bm_cq +target_include_directories(alts_security_connector_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -9045,33 +9129,25 @@ target_include_directories(bm_cq PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(bm_cq +target_link_libraries(alts_security_connector_test ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_benchmark - ${_gRPC_BENCHMARK_LIBRARIES} - grpc++_test_util_unsecure - grpc_test_util_unsecure - grpc++_unsecure - grpc_unsecure - gpr_test_util gpr + grpc ${_gRPC_GFLAGS_LIBRARIES} ) -endif() endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) -add_executable(bm_cq_multiple_threads - test/cpp/microbenchmarks/bm_cq_multiple_threads.cc +add_executable(alts_tsi_handshaker_test + test/core/tsi/alts/handshaker/alts_tsi_handshaker_test.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(bm_cq_multiple_threads +target_include_directories(alts_tsi_handshaker_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -9087,33 +9163,26 @@ target_include_directories(bm_cq_multiple_threads PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(bm_cq_multiple_threads +target_link_libraries(alts_tsi_handshaker_test ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_benchmark - ${_gRPC_BENCHMARK_LIBRARIES} - grpc++_test_util_unsecure - grpc_test_util_unsecure - grpc++_unsecure - grpc_unsecure - gpr_test_util + alts_test_util gpr + grpc ${_gRPC_GFLAGS_LIBRARIES} ) -endif() endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) -add_executable(bm_error - test/cpp/microbenchmarks/bm_error.cc +add_executable(alts_tsi_utils_test + test/core/tsi/alts/handshaker/alts_tsi_utils_test.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(bm_error +target_include_directories(alts_tsi_utils_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -9129,33 +9198,26 @@ target_include_directories(bm_error PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(bm_error +target_link_libraries(alts_tsi_utils_test ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_benchmark - ${_gRPC_BENCHMARK_LIBRARIES} - grpc++_test_util_unsecure - grpc_test_util_unsecure - grpc++_unsecure - grpc_unsecure - gpr_test_util + alts_test_util gpr + grpc ${_gRPC_GFLAGS_LIBRARIES} ) -endif() endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) -add_executable(bm_fullstack_streaming_ping_pong - test/cpp/microbenchmarks/bm_fullstack_streaming_ping_pong.cc +add_executable(alts_zero_copy_grpc_protector_test + test/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector_test.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(bm_fullstack_streaming_ping_pong +target_include_directories(alts_zero_copy_grpc_protector_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -9171,33 +9233,26 @@ target_include_directories(bm_fullstack_streaming_ping_pong PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(bm_fullstack_streaming_ping_pong +target_link_libraries(alts_zero_copy_grpc_protector_test ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_benchmark - ${_gRPC_BENCHMARK_LIBRARIES} - grpc++_test_util_unsecure - grpc_test_util_unsecure - grpc++_unsecure - grpc_unsecure - gpr_test_util + alts_test_util gpr + grpc ${_gRPC_GFLAGS_LIBRARIES} ) -endif() endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) -add_executable(bm_fullstack_streaming_pump - test/cpp/microbenchmarks/bm_fullstack_streaming_pump.cc +add_executable(async_end2end_test + test/cpp/end2end/async_end2end_test.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) -target_include_directories(bm_fullstack_streaming_pump +target_include_directories(async_end2end_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${_gRPC_SSL_INCLUDE_DIR} @@ -9213,27 +9268,556 @@ target_include_directories(bm_fullstack_streaming_pump PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(bm_fullstack_streaming_pump +target_link_libraries(async_end2end_test ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_benchmark - ${_gRPC_BENCHMARK_LIBRARIES} - grpc++_test_util_unsecure - grpc_test_util_unsecure - grpc++_unsecure - grpc_unsecure + grpc++_test_util + grpc_test_util + grpc++ + grpc gpr_test_util gpr ${_gRPC_GFLAGS_LIBRARIES} ) -endif() endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) -add_executable(bm_fullstack_trickle - test/cpp/microbenchmarks/bm_fullstack_trickle.cc +add_executable(auth_property_iterator_test + test/cpp/common/auth_property_iterator_test.cc + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + + +target_include_directories(auth_property_iterator_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${_gRPC_SSL_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} + PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} + PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} + PRIVATE ${_gRPC_CARES_INCLUDE_DIR} + PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} + PRIVATE third_party/googletest/googletest/include + PRIVATE third_party/googletest/googletest + PRIVATE third_party/googletest/googlemock/include + PRIVATE third_party/googletest/googlemock + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(auth_property_iterator_test + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(backoff_test + test/core/backoff/backoff_test.cc + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + + +target_include_directories(backoff_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${_gRPC_SSL_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} + PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} + PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} + PRIVATE ${_gRPC_CARES_INCLUDE_DIR} + PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} + PRIVATE third_party/googletest/googletest/include + PRIVATE third_party/googletest/googletest + PRIVATE third_party/googletest/googlemock/include + PRIVATE third_party/googletest/googlemock + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(backoff_test + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc_test_util + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(bdp_estimator_test + test/core/transport/bdp_estimator_test.cc + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + + +target_include_directories(bdp_estimator_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${_gRPC_SSL_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} + PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} + PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} + PRIVATE ${_gRPC_CARES_INCLUDE_DIR} + PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} + PRIVATE third_party/googletest/googletest/include + PRIVATE third_party/googletest/googletest + PRIVATE third_party/googletest/googlemock/include + PRIVATE third_party/googletest/googlemock + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(bdp_estimator_test + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc++_test_util + grpc++ + grpc_test_util + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) +if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) + +add_executable(bm_arena + test/cpp/microbenchmarks/bm_arena.cc + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + + +target_include_directories(bm_arena + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${_gRPC_SSL_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} + PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} + PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} + PRIVATE ${_gRPC_CARES_INCLUDE_DIR} + PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} + PRIVATE third_party/googletest/googletest/include + PRIVATE third_party/googletest/googletest + PRIVATE third_party/googletest/googlemock/include + PRIVATE third_party/googletest/googlemock + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(bm_arena + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc_benchmark + ${_gRPC_BENCHMARK_LIBRARIES} + grpc++_test_util_unsecure + grpc_test_util_unsecure + grpc++_unsecure + grpc_unsecure + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif() +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) +if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) + +add_executable(bm_call_create + test/cpp/microbenchmarks/bm_call_create.cc + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + + +target_include_directories(bm_call_create + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${_gRPC_SSL_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} + PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} + PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} + PRIVATE ${_gRPC_CARES_INCLUDE_DIR} + PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} + PRIVATE third_party/googletest/googletest/include + PRIVATE third_party/googletest/googletest + PRIVATE third_party/googletest/googlemock/include + PRIVATE third_party/googletest/googlemock + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(bm_call_create + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc_benchmark + ${_gRPC_BENCHMARK_LIBRARIES} + grpc++_test_util_unsecure + grpc_test_util_unsecure + grpc++_unsecure + grpc_unsecure + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif() +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) +if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) + +add_executable(bm_chttp2_hpack + test/cpp/microbenchmarks/bm_chttp2_hpack.cc + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + + +target_include_directories(bm_chttp2_hpack + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${_gRPC_SSL_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} + PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} + PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} + PRIVATE ${_gRPC_CARES_INCLUDE_DIR} + PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} + PRIVATE third_party/googletest/googletest/include + PRIVATE third_party/googletest/googletest + PRIVATE third_party/googletest/googlemock/include + PRIVATE third_party/googletest/googlemock + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(bm_chttp2_hpack + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc_benchmark + ${_gRPC_BENCHMARK_LIBRARIES} + grpc++_test_util_unsecure + grpc_test_util_unsecure + grpc++_unsecure + grpc_unsecure + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif() +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) +if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) + +add_executable(bm_chttp2_transport + test/cpp/microbenchmarks/bm_chttp2_transport.cc + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + + +target_include_directories(bm_chttp2_transport + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${_gRPC_SSL_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} + PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} + PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} + PRIVATE ${_gRPC_CARES_INCLUDE_DIR} + PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} + PRIVATE third_party/googletest/googletest/include + PRIVATE third_party/googletest/googletest + PRIVATE third_party/googletest/googlemock/include + PRIVATE third_party/googletest/googlemock + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(bm_chttp2_transport + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc_benchmark + ${_gRPC_BENCHMARK_LIBRARIES} + grpc++_test_util_unsecure + grpc_test_util_unsecure + grpc++_unsecure + grpc_unsecure + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif() +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) +if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) + +add_executable(bm_closure + test/cpp/microbenchmarks/bm_closure.cc + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + + +target_include_directories(bm_closure + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${_gRPC_SSL_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} + PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} + PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} + PRIVATE ${_gRPC_CARES_INCLUDE_DIR} + PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} + PRIVATE third_party/googletest/googletest/include + PRIVATE third_party/googletest/googletest + PRIVATE third_party/googletest/googlemock/include + PRIVATE third_party/googletest/googlemock + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(bm_closure + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc_benchmark + ${_gRPC_BENCHMARK_LIBRARIES} + grpc++_test_util_unsecure + grpc_test_util_unsecure + grpc++_unsecure + grpc_unsecure + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif() +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) +if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) + +add_executable(bm_cq + test/cpp/microbenchmarks/bm_cq.cc + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + + +target_include_directories(bm_cq + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${_gRPC_SSL_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} + PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} + PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} + PRIVATE ${_gRPC_CARES_INCLUDE_DIR} + PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} + PRIVATE third_party/googletest/googletest/include + PRIVATE third_party/googletest/googletest + PRIVATE third_party/googletest/googlemock/include + PRIVATE third_party/googletest/googlemock + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(bm_cq + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc_benchmark + ${_gRPC_BENCHMARK_LIBRARIES} + grpc++_test_util_unsecure + grpc_test_util_unsecure + grpc++_unsecure + grpc_unsecure + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif() +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) +if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) + +add_executable(bm_cq_multiple_threads + test/cpp/microbenchmarks/bm_cq_multiple_threads.cc + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + + +target_include_directories(bm_cq_multiple_threads + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${_gRPC_SSL_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} + PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} + PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} + PRIVATE ${_gRPC_CARES_INCLUDE_DIR} + PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} + PRIVATE third_party/googletest/googletest/include + PRIVATE third_party/googletest/googletest + PRIVATE third_party/googletest/googlemock/include + PRIVATE third_party/googletest/googlemock + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(bm_cq_multiple_threads + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc_benchmark + ${_gRPC_BENCHMARK_LIBRARIES} + grpc++_test_util_unsecure + grpc_test_util_unsecure + grpc++_unsecure + grpc_unsecure + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif() +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) +if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) + +add_executable(bm_error + test/cpp/microbenchmarks/bm_error.cc + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + + +target_include_directories(bm_error + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${_gRPC_SSL_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} + PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} + PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} + PRIVATE ${_gRPC_CARES_INCLUDE_DIR} + PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} + PRIVATE third_party/googletest/googletest/include + PRIVATE third_party/googletest/googletest + PRIVATE third_party/googletest/googlemock/include + PRIVATE third_party/googletest/googlemock + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(bm_error + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc_benchmark + ${_gRPC_BENCHMARK_LIBRARIES} + grpc++_test_util_unsecure + grpc_test_util_unsecure + grpc++_unsecure + grpc_unsecure + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif() +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) +if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) + +add_executable(bm_fullstack_streaming_ping_pong + test/cpp/microbenchmarks/bm_fullstack_streaming_ping_pong.cc + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + + +target_include_directories(bm_fullstack_streaming_ping_pong + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${_gRPC_SSL_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} + PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} + PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} + PRIVATE ${_gRPC_CARES_INCLUDE_DIR} + PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} + PRIVATE third_party/googletest/googletest/include + PRIVATE third_party/googletest/googletest + PRIVATE third_party/googletest/googlemock/include + PRIVATE third_party/googletest/googlemock + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(bm_fullstack_streaming_ping_pong + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc_benchmark + ${_gRPC_BENCHMARK_LIBRARIES} + grpc++_test_util_unsecure + grpc_test_util_unsecure + grpc++_unsecure + grpc_unsecure + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif() +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) +if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) + +add_executable(bm_fullstack_streaming_pump + test/cpp/microbenchmarks/bm_fullstack_streaming_pump.cc + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + + +target_include_directories(bm_fullstack_streaming_pump + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${_gRPC_SSL_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} + PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} + PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} + PRIVATE ${_gRPC_CARES_INCLUDE_DIR} + PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} + PRIVATE third_party/googletest/googletest/include + PRIVATE third_party/googletest/googletest + PRIVATE third_party/googletest/googlemock/include + PRIVATE third_party/googletest/googlemock + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(bm_fullstack_streaming_pump + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc_benchmark + ${_gRPC_BENCHMARK_LIBRARIES} + grpc++_test_util_unsecure + grpc_test_util_unsecure + grpc++_unsecure + grpc_unsecure + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif() +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) +if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) + +add_executable(bm_fullstack_trickle + test/cpp/microbenchmarks/bm_fullstack_trickle.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) @@ -9470,6 +10054,74 @@ target_link_libraries(channel_filter_test endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +add_executable(check_gcp_environment_linux_test + test/core/security/check_gcp_environment_linux_test.cc + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + + +target_include_directories(check_gcp_environment_linux_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${_gRPC_SSL_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} + PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} + PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} + PRIVATE ${_gRPC_CARES_INCLUDE_DIR} + PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} + PRIVATE third_party/googletest/googletest/include + PRIVATE third_party/googletest/googletest + PRIVATE third_party/googletest/googlemock/include + PRIVATE third_party/googletest/googlemock + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(check_gcp_environment_linux_test + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(check_gcp_environment_windows_test + test/core/security/check_gcp_environment_windows_test.cc + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + + +target_include_directories(check_gcp_environment_windows_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${_gRPC_SSL_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} + PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} + PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} + PRIVATE ${_gRPC_CARES_INCLUDE_DIR} + PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} + PRIVATE third_party/googletest/googletest/include + PRIVATE third_party/googletest/googletest + PRIVATE third_party/googletest/googlemock/include + PRIVATE third_party/googletest/googlemock + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(check_gcp_environment_windows_test + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + add_executable(chttp2_settings_timeout_test test/core/transport/chttp2/settings_timeout_test.cc third_party/googletest/googletest/src/gtest-all.cc @@ -10263,6 +10915,40 @@ target_link_libraries(golden_file_test endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +add_executable(grpc_alts_credentials_options_test + test/core/security/grpc_alts_credentials_options_test.cc + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + + +target_include_directories(grpc_alts_credentials_options_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${_gRPC_SSL_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} + PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} + PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} + PRIVATE ${_gRPC_CARES_INCLUDE_DIR} + PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} + PRIVATE third_party/googletest/googletest/include + PRIVATE third_party/googletest/googletest + PRIVATE third_party/googletest/googlemock/include + PRIVATE third_party/googletest/googlemock + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(grpc_alts_credentials_options_test + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + add_executable(grpc_cli test/cpp/util/grpc_cli.cc third_party/googletest/googletest/src/gtest-all.cc @@ -12601,6 +13287,41 @@ target_link_libraries(transport_pid_controller_test ${_gRPC_GFLAGS_LIBRARIES} ) +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(transport_security_common_api_test + test/core/tsi/alts/handshaker/transport_security_common_api_test.cc + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + + +target_include_directories(transport_security_common_api_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${_gRPC_SSL_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} + PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} + PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} + PRIVATE ${_gRPC_CARES_INCLUDE_DIR} + PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} + PRIVATE third_party/googletest/googletest/include + PRIVATE third_party/googletest/googletest + PRIVATE third_party/googletest/googlemock/include + PRIVATE third_party/googletest/googlemock + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(transport_security_common_api_test + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + alts_test_util + gpr + grpc + ${_gRPC_GFLAGS_LIBRARIES} +) + endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) diff --git a/Makefile b/Makefile index dfaf11ea0d..a298fafd6b 100644 --- a/Makefile +++ b/Makefile @@ -338,6 +338,8 @@ CPPFLAGS += -g -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter -DOSAT COREFLAGS += -fno-rtti -fno-exceptions LDFLAGS += -g +DEFINES += PB_FIELD_16BIT + CPPFLAGS += $(CPPFLAGS_$(CONFIG)) CFLAGS += $(CFLAGS_$(CONFIG)) CXXFLAGS += $(CXXFLAGS_$(CONFIG)) @@ -1094,6 +1096,19 @@ uri_fuzzer_test: $(BINDIR)/$(CONFIG)/uri_fuzzer_test uri_parser_test: $(BINDIR)/$(CONFIG)/uri_parser_test wakeup_fd_cv_test: $(BINDIR)/$(CONFIG)/wakeup_fd_cv_test alarm_test: $(BINDIR)/$(CONFIG)/alarm_test +alts_counter_test: $(BINDIR)/$(CONFIG)/alts_counter_test +alts_crypt_test: $(BINDIR)/$(CONFIG)/alts_crypt_test +alts_crypter_test: $(BINDIR)/$(CONFIG)/alts_crypter_test +alts_frame_handler_test: $(BINDIR)/$(CONFIG)/alts_frame_handler_test +alts_frame_protector_test: $(BINDIR)/$(CONFIG)/alts_frame_protector_test +alts_grpc_record_protocol_test: $(BINDIR)/$(CONFIG)/alts_grpc_record_protocol_test +alts_handshaker_client_test: $(BINDIR)/$(CONFIG)/alts_handshaker_client_test +alts_handshaker_service_api_test: $(BINDIR)/$(CONFIG)/alts_handshaker_service_api_test +alts_iovec_record_protocol_test: $(BINDIR)/$(CONFIG)/alts_iovec_record_protocol_test +alts_security_connector_test: $(BINDIR)/$(CONFIG)/alts_security_connector_test +alts_tsi_handshaker_test: $(BINDIR)/$(CONFIG)/alts_tsi_handshaker_test +alts_tsi_utils_test: $(BINDIR)/$(CONFIG)/alts_tsi_utils_test +alts_zero_copy_grpc_protector_test: $(BINDIR)/$(CONFIG)/alts_zero_copy_grpc_protector_test async_end2end_test: $(BINDIR)/$(CONFIG)/async_end2end_test auth_property_iterator_test: $(BINDIR)/$(CONFIG)/auth_property_iterator_test backoff_test: $(BINDIR)/$(CONFIG)/backoff_test @@ -1114,6 +1129,8 @@ bm_metadata: $(BINDIR)/$(CONFIG)/bm_metadata bm_pollset: $(BINDIR)/$(CONFIG)/bm_pollset channel_arguments_test: $(BINDIR)/$(CONFIG)/channel_arguments_test channel_filter_test: $(BINDIR)/$(CONFIG)/channel_filter_test +check_gcp_environment_linux_test: $(BINDIR)/$(CONFIG)/check_gcp_environment_linux_test +check_gcp_environment_windows_test: $(BINDIR)/$(CONFIG)/check_gcp_environment_windows_test chttp2_settings_timeout_test: $(BINDIR)/$(CONFIG)/chttp2_settings_timeout_test cli_call_test: $(BINDIR)/$(CONFIG)/cli_call_test client_channel_stress_test: $(BINDIR)/$(CONFIG)/client_channel_stress_test @@ -1133,6 +1150,7 @@ exception_test: $(BINDIR)/$(CONFIG)/exception_test filter_end2end_test: $(BINDIR)/$(CONFIG)/filter_end2end_test generic_end2end_test: $(BINDIR)/$(CONFIG)/generic_end2end_test golden_file_test: $(BINDIR)/$(CONFIG)/golden_file_test +grpc_alts_credentials_options_test: $(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test grpc_cli: $(BINDIR)/$(CONFIG)/grpc_cli grpc_cpp_plugin: $(BINDIR)/$(CONFIG)/grpc_cpp_plugin grpc_csharp_plugin: $(BINDIR)/$(CONFIG)/grpc_csharp_plugin @@ -1191,6 +1209,7 @@ stress_test: $(BINDIR)/$(CONFIG)/stress_test thread_manager_test: $(BINDIR)/$(CONFIG)/thread_manager_test thread_stress_test: $(BINDIR)/$(CONFIG)/thread_stress_test transport_pid_controller_test: $(BINDIR)/$(CONFIG)/transport_pid_controller_test +transport_security_common_api_test: $(BINDIR)/$(CONFIG)/transport_security_common_api_test writes_per_rpc_test: $(BINDIR)/$(CONFIG)/writes_per_rpc_test public_headers_must_be_c89: $(BINDIR)/$(CONFIG)/public_headers_must_be_c89 gen_hpack_tables: $(BINDIR)/$(CONFIG)/gen_hpack_tables @@ -1353,7 +1372,7 @@ plugins: $(PROTOC_PLUGINS) privatelibs: privatelibs_c privatelibs_cxx -privatelibs_c: $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libreconnect_server.a $(LIBDIR)/$(CONFIG)/libtest_tcp_server.a $(LIBDIR)/$(CONFIG)/libz.a $(LIBDIR)/$(CONFIG)/libares.a $(LIBDIR)/$(CONFIG)/libbad_client_test.a $(LIBDIR)/$(CONFIG)/libbad_ssl_test_server.a $(LIBDIR)/$(CONFIG)/libend2end_tests.a $(LIBDIR)/$(CONFIG)/libend2end_nosec_tests.a +privatelibs_c: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libreconnect_server.a $(LIBDIR)/$(CONFIG)/libtest_tcp_server.a $(LIBDIR)/$(CONFIG)/libz.a $(LIBDIR)/$(CONFIG)/libares.a $(LIBDIR)/$(CONFIG)/libbad_client_test.a $(LIBDIR)/$(CONFIG)/libbad_ssl_test_server.a $(LIBDIR)/$(CONFIG)/libend2end_tests.a $(LIBDIR)/$(CONFIG)/libend2end_nosec_tests.a pc_c: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc pc_c_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc @@ -1563,6 +1582,19 @@ buildtests_c: privatelibs_c \ ifeq ($(EMBED_OPENSSL),true) buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/alarm_test \ + $(BINDIR)/$(CONFIG)/alts_counter_test \ + $(BINDIR)/$(CONFIG)/alts_crypt_test \ + $(BINDIR)/$(CONFIG)/alts_crypter_test \ + $(BINDIR)/$(CONFIG)/alts_frame_handler_test \ + $(BINDIR)/$(CONFIG)/alts_frame_protector_test \ + $(BINDIR)/$(CONFIG)/alts_grpc_record_protocol_test \ + $(BINDIR)/$(CONFIG)/alts_handshaker_client_test \ + $(BINDIR)/$(CONFIG)/alts_handshaker_service_api_test \ + $(BINDIR)/$(CONFIG)/alts_iovec_record_protocol_test \ + $(BINDIR)/$(CONFIG)/alts_security_connector_test \ + $(BINDIR)/$(CONFIG)/alts_tsi_handshaker_test \ + $(BINDIR)/$(CONFIG)/alts_tsi_utils_test \ + $(BINDIR)/$(CONFIG)/alts_zero_copy_grpc_protector_test \ $(BINDIR)/$(CONFIG)/async_end2end_test \ $(BINDIR)/$(CONFIG)/auth_property_iterator_test \ $(BINDIR)/$(CONFIG)/backoff_test \ @@ -1583,6 +1615,8 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/bm_pollset \ $(BINDIR)/$(CONFIG)/channel_arguments_test \ $(BINDIR)/$(CONFIG)/channel_filter_test \ + $(BINDIR)/$(CONFIG)/check_gcp_environment_linux_test \ + $(BINDIR)/$(CONFIG)/check_gcp_environment_windows_test \ $(BINDIR)/$(CONFIG)/chttp2_settings_timeout_test \ $(BINDIR)/$(CONFIG)/cli_call_test \ $(BINDIR)/$(CONFIG)/client_channel_stress_test \ @@ -1602,6 +1636,7 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/filter_end2end_test \ $(BINDIR)/$(CONFIG)/generic_end2end_test \ $(BINDIR)/$(CONFIG)/golden_file_test \ + $(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test \ $(BINDIR)/$(CONFIG)/grpc_cli \ $(BINDIR)/$(CONFIG)/grpc_tool_test \ $(BINDIR)/$(CONFIG)/grpclb_api_test \ @@ -1653,6 +1688,7 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/thread_manager_test \ $(BINDIR)/$(CONFIG)/thread_stress_test \ $(BINDIR)/$(CONFIG)/transport_pid_controller_test \ + $(BINDIR)/$(CONFIG)/transport_security_common_api_test \ $(BINDIR)/$(CONFIG)/writes_per_rpc_test \ $(BINDIR)/$(CONFIG)/boringssl_crypto_test_data \ $(BINDIR)/$(CONFIG)/boringssl_asn1_test \ @@ -1712,6 +1748,19 @@ buildtests_cxx: privatelibs_cxx \ else buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/alarm_test \ + $(BINDIR)/$(CONFIG)/alts_counter_test \ + $(BINDIR)/$(CONFIG)/alts_crypt_test \ + $(BINDIR)/$(CONFIG)/alts_crypter_test \ + $(BINDIR)/$(CONFIG)/alts_frame_handler_test \ + $(BINDIR)/$(CONFIG)/alts_frame_protector_test \ + $(BINDIR)/$(CONFIG)/alts_grpc_record_protocol_test \ + $(BINDIR)/$(CONFIG)/alts_handshaker_client_test \ + $(BINDIR)/$(CONFIG)/alts_handshaker_service_api_test \ + $(BINDIR)/$(CONFIG)/alts_iovec_record_protocol_test \ + $(BINDIR)/$(CONFIG)/alts_security_connector_test \ + $(BINDIR)/$(CONFIG)/alts_tsi_handshaker_test \ + $(BINDIR)/$(CONFIG)/alts_tsi_utils_test \ + $(BINDIR)/$(CONFIG)/alts_zero_copy_grpc_protector_test \ $(BINDIR)/$(CONFIG)/async_end2end_test \ $(BINDIR)/$(CONFIG)/auth_property_iterator_test \ $(BINDIR)/$(CONFIG)/backoff_test \ @@ -1732,6 +1781,8 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/bm_pollset \ $(BINDIR)/$(CONFIG)/channel_arguments_test \ $(BINDIR)/$(CONFIG)/channel_filter_test \ + $(BINDIR)/$(CONFIG)/check_gcp_environment_linux_test \ + $(BINDIR)/$(CONFIG)/check_gcp_environment_windows_test \ $(BINDIR)/$(CONFIG)/chttp2_settings_timeout_test \ $(BINDIR)/$(CONFIG)/cli_call_test \ $(BINDIR)/$(CONFIG)/client_channel_stress_test \ @@ -1751,6 +1802,7 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/filter_end2end_test \ $(BINDIR)/$(CONFIG)/generic_end2end_test \ $(BINDIR)/$(CONFIG)/golden_file_test \ + $(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test \ $(BINDIR)/$(CONFIG)/grpc_cli \ $(BINDIR)/$(CONFIG)/grpc_tool_test \ $(BINDIR)/$(CONFIG)/grpclb_api_test \ @@ -1802,6 +1854,7 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/thread_manager_test \ $(BINDIR)/$(CONFIG)/thread_stress_test \ $(BINDIR)/$(CONFIG)/transport_pid_controller_test \ + $(BINDIR)/$(CONFIG)/transport_security_common_api_test \ $(BINDIR)/$(CONFIG)/writes_per_rpc_test \ $(BINDIR)/$(CONFIG)/resolver_component_test_unsecure \ $(BINDIR)/$(CONFIG)/resolver_component_test \ @@ -2088,6 +2141,32 @@ flaky_test_c: buildtests_c test_cxx: buildtests_cxx $(E) "[RUN] Testing alarm_test" $(Q) $(BINDIR)/$(CONFIG)/alarm_test || ( echo test alarm_test failed ; exit 1 ) + $(E) "[RUN] Testing alts_counter_test" + $(Q) $(BINDIR)/$(CONFIG)/alts_counter_test || ( echo test alts_counter_test failed ; exit 1 ) + $(E) "[RUN] Testing alts_crypt_test" + $(Q) $(BINDIR)/$(CONFIG)/alts_crypt_test || ( echo test alts_crypt_test failed ; exit 1 ) + $(E) "[RUN] Testing alts_crypter_test" + $(Q) $(BINDIR)/$(CONFIG)/alts_crypter_test || ( echo test alts_crypter_test failed ; exit 1 ) + $(E) "[RUN] Testing alts_frame_handler_test" + $(Q) $(BINDIR)/$(CONFIG)/alts_frame_handler_test || ( echo test alts_frame_handler_test failed ; exit 1 ) + $(E) "[RUN] Testing alts_frame_protector_test" + $(Q) $(BINDIR)/$(CONFIG)/alts_frame_protector_test || ( echo test alts_frame_protector_test failed ; exit 1 ) + $(E) "[RUN] Testing alts_grpc_record_protocol_test" + $(Q) $(BINDIR)/$(CONFIG)/alts_grpc_record_protocol_test || ( echo test alts_grpc_record_protocol_test failed ; exit 1 ) + $(E) "[RUN] Testing alts_handshaker_client_test" + $(Q) $(BINDIR)/$(CONFIG)/alts_handshaker_client_test || ( echo test alts_handshaker_client_test failed ; exit 1 ) + $(E) "[RUN] Testing alts_handshaker_service_api_test" + $(Q) $(BINDIR)/$(CONFIG)/alts_handshaker_service_api_test || ( echo test alts_handshaker_service_api_test failed ; exit 1 ) + $(E) "[RUN] Testing alts_iovec_record_protocol_test" + $(Q) $(BINDIR)/$(CONFIG)/alts_iovec_record_protocol_test || ( echo test alts_iovec_record_protocol_test failed ; exit 1 ) + $(E) "[RUN] Testing alts_security_connector_test" + $(Q) $(BINDIR)/$(CONFIG)/alts_security_connector_test || ( echo test alts_security_connector_test failed ; exit 1 ) + $(E) "[RUN] Testing alts_tsi_handshaker_test" + $(Q) $(BINDIR)/$(CONFIG)/alts_tsi_handshaker_test || ( echo test alts_tsi_handshaker_test failed ; exit 1 ) + $(E) "[RUN] Testing alts_tsi_utils_test" + $(Q) $(BINDIR)/$(CONFIG)/alts_tsi_utils_test || ( echo test alts_tsi_utils_test failed ; exit 1 ) + $(E) "[RUN] Testing alts_zero_copy_grpc_protector_test" + $(Q) $(BINDIR)/$(CONFIG)/alts_zero_copy_grpc_protector_test || ( echo test alts_zero_copy_grpc_protector_test failed ; exit 1 ) $(E) "[RUN] Testing async_end2end_test" $(Q) $(BINDIR)/$(CONFIG)/async_end2end_test || ( echo test async_end2end_test failed ; exit 1 ) $(E) "[RUN] Testing auth_property_iterator_test" @@ -2128,6 +2207,10 @@ test_cxx: buildtests_cxx $(Q) $(BINDIR)/$(CONFIG)/channel_arguments_test || ( echo test channel_arguments_test failed ; exit 1 ) $(E) "[RUN] Testing channel_filter_test" $(Q) $(BINDIR)/$(CONFIG)/channel_filter_test || ( echo test channel_filter_test failed ; exit 1 ) + $(E) "[RUN] Testing check_gcp_environment_linux_test" + $(Q) $(BINDIR)/$(CONFIG)/check_gcp_environment_linux_test || ( echo test check_gcp_environment_linux_test failed ; exit 1 ) + $(E) "[RUN] Testing check_gcp_environment_windows_test" + $(Q) $(BINDIR)/$(CONFIG)/check_gcp_environment_windows_test || ( echo test check_gcp_environment_windows_test failed ; exit 1 ) $(E) "[RUN] Testing chttp2_settings_timeout_test" $(Q) $(BINDIR)/$(CONFIG)/chttp2_settings_timeout_test || ( echo test chttp2_settings_timeout_test failed ; exit 1 ) $(E) "[RUN] Testing cli_call_test" @@ -2164,6 +2247,8 @@ test_cxx: buildtests_cxx $(Q) $(BINDIR)/$(CONFIG)/generic_end2end_test || ( echo test generic_end2end_test failed ; exit 1 ) $(E) "[RUN] Testing golden_file_test" $(Q) $(BINDIR)/$(CONFIG)/golden_file_test || ( echo test golden_file_test failed ; exit 1 ) + $(E) "[RUN] Testing grpc_alts_credentials_options_test" + $(Q) $(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test || ( echo test grpc_alts_credentials_options_test failed ; exit 1 ) $(E) "[RUN] Testing grpc_tool_test" $(Q) $(BINDIR)/$(CONFIG)/grpc_tool_test || ( echo test grpc_tool_test failed ; exit 1 ) $(E) "[RUN] Testing grpclb_api_test" @@ -2238,6 +2323,8 @@ test_cxx: buildtests_cxx $(Q) $(BINDIR)/$(CONFIG)/thread_stress_test || ( echo test thread_stress_test failed ; exit 1 ) $(E) "[RUN] Testing transport_pid_controller_test" $(Q) $(BINDIR)/$(CONFIG)/transport_pid_controller_test || ( echo test transport_pid_controller_test failed ; exit 1 ) + $(E) "[RUN] Testing transport_security_common_api_test" + $(Q) $(BINDIR)/$(CONFIG)/transport_security_common_api_test || ( echo test transport_security_common_api_test failed ; exit 1 ) $(E) "[RUN] Testing writes_per_rpc_test" $(Q) $(BINDIR)/$(CONFIG)/writes_per_rpc_test || ( echo test writes_per_rpc_test failed ; exit 1 ) $(E) "[RUN] Testing resolver_component_tests_runner_invoker_unsecure" @@ -2895,6 +2982,46 @@ clean: # The various libraries +LIBALTS_TEST_UTIL_SRC = \ + test/core/tsi/alts/crypt/gsec_test_util.cc \ + test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc \ + +PUBLIC_HEADERS_C += \ + +LIBALTS_TEST_UTIL_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBALTS_TEST_UTIL_SRC)))) + + +ifeq ($(NO_SECURE),true) + +# You can't build secure libraries if you don't have OpenSSL. + +$(LIBDIR)/$(CONFIG)/libalts_test_util.a: openssl_dep_error + + +else + + +$(LIBDIR)/$(CONFIG)/libalts_test_util.a: $(ZLIB_DEP) $(OPENSSL_DEP) $(CARES_DEP) $(LIBALTS_TEST_UTIL_OBJS) + $(E) "[AR] Creating $@" + $(Q) mkdir -p `dirname $@` + $(Q) rm -f $(LIBDIR)/$(CONFIG)/libalts_test_util.a + $(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBALTS_TEST_UTIL_OBJS) +ifeq ($(SYSTEM),Darwin) + $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/libalts_test_util.a +endif + + + + +endif + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(LIBALTS_TEST_UTIL_OBJS:.o=.dep) +endif +endif + + LIBGPR_SRC = \ src/core/lib/gpr/alloc.cc \ src/core/lib/gpr/arena.cc \ @@ -3197,6 +3324,7 @@ LIBGRPC_SRC = \ src/core/ext/filters/http/server/http_server_filter.cc \ src/core/lib/http/httpcli_security_connector.cc \ src/core/lib/security/context/security_context.cc \ + src/core/lib/security/credentials/alts/alts_credentials.cc \ src/core/lib/security/credentials/composite/composite_credentials.cc \ src/core/lib/security/credentials/credentials.cc \ src/core/lib/security/credentials/credentials_metadata.cc \ @@ -3210,6 +3338,7 @@ LIBGRPC_SRC = \ src/core/lib/security/credentials/oauth2/oauth2_credentials.cc \ src/core/lib/security/credentials/plugin/plugin_credentials.cc \ src/core/lib/security/credentials/ssl/ssl_credentials.cc \ + src/core/lib/security/security_connector/alts_security_connector.cc \ src/core/lib/security/security_connector/security_connector.cc \ src/core/lib/security/transport/client_auth_filter.cc \ src/core/lib/security/transport/secure_endpoint.cc \ @@ -3219,14 +3348,45 @@ LIBGRPC_SRC = \ src/core/lib/security/transport/tsi_error.cc \ src/core/lib/security/util/json_util.cc \ src/core/lib/surface/init_secure.cc \ - src/core/tsi/alts_transport_security.cc \ - src/core/tsi/fake_transport_security.cc \ - src/core/tsi/ssl_transport_security.cc \ - src/core/tsi/transport_security_grpc.cc \ + src/core/tsi/alts/crypt/aes_gcm.cc \ + src/core/tsi/alts/crypt/gsec.cc \ + src/core/tsi/alts/frame_protector/alts_counter.cc \ + src/core/tsi/alts/frame_protector/alts_crypter.cc \ + src/core/tsi/alts/frame_protector/alts_frame_protector.cc \ + src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc \ + src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc \ + src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc \ + src/core/tsi/alts/frame_protector/frame_handler.cc \ + src/core/tsi/alts/handshaker/alts_handshaker_client.cc \ + src/core/tsi/alts/handshaker/alts_tsi_event.cc \ + src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc \ + src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc \ + src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc \ + src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc \ + src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc \ + src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc \ + src/core/lib/security/credentials/alts/check_gcp_environment.cc \ + src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc \ + src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc \ + src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc \ + src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc \ + src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc \ + src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc \ + src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc \ + src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc \ + src/core/tsi/alts/handshaker/alts_tsi_utils.cc \ + src/core/tsi/alts/handshaker/transport_security_common_api.cc \ + src/core/tsi/alts/handshaker/altscontext.pb.c \ + src/core/tsi/alts/handshaker/handshaker.pb.c \ + src/core/tsi/alts/handshaker/transport_security_common.pb.c \ + third_party/nanopb/pb_common.c \ + third_party/nanopb/pb_decode.c \ + third_party/nanopb/pb_encode.c \ src/core/tsi/transport_security.cc \ src/core/tsi/transport_security_adapter.cc \ - src/core/ext/transport/chttp2/server/chttp2_server.cc \ - src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc \ + src/core/ext/transport/chttp2/client/insecure/channel_create.cc \ + src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \ + src/core/ext/transport/chttp2/client/chttp2_connector.cc \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ src/core/ext/filters/client_channel/client_channel.cc \ @@ -3250,11 +3410,14 @@ LIBGRPC_SRC = \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ src/core/ext/filters/deadline/deadline_filter.cc \ - src/core/ext/transport/chttp2/client/chttp2_connector.cc \ + src/core/tsi/alts_transport_security.cc \ + src/core/tsi/fake_transport_security.cc \ + src/core/tsi/ssl_transport_security.cc \ + src/core/tsi/transport_security_grpc.cc \ + src/core/ext/transport/chttp2/server/chttp2_server.cc \ + src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc \ src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc \ src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc \ - src/core/ext/transport/chttp2/client/insecure/channel_create.cc \ - src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \ src/core/ext/transport/inproc/inproc_plugin.cc \ src/core/ext/transport/inproc/inproc_transport.cc \ src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc \ @@ -3263,9 +3426,6 @@ LIBGRPC_SRC = \ src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc \ src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc \ src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c \ - third_party/nanopb/pb_common.c \ - third_party/nanopb/pb_decode.c \ - third_party/nanopb/pb_encode.c \ src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc \ src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc \ src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc \ @@ -3567,6 +3727,7 @@ LIBGRPC_CRONET_SRC = \ src/core/ext/filters/deadline/deadline_filter.cc \ src/core/lib/http/httpcli_security_connector.cc \ src/core/lib/security/context/security_context.cc \ + src/core/lib/security/credentials/alts/alts_credentials.cc \ src/core/lib/security/credentials/composite/composite_credentials.cc \ src/core/lib/security/credentials/credentials.cc \ src/core/lib/security/credentials/credentials_metadata.cc \ @@ -3580,6 +3741,7 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/security/credentials/oauth2/oauth2_credentials.cc \ src/core/lib/security/credentials/plugin/plugin_credentials.cc \ src/core/lib/security/credentials/ssl/ssl_credentials.cc \ + src/core/lib/security/security_connector/alts_security_connector.cc \ src/core/lib/security/security_connector/security_connector.cc \ src/core/lib/security/transport/client_auth_filter.cc \ src/core/lib/security/transport/secure_endpoint.cc \ @@ -3589,13 +3751,49 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/security/transport/tsi_error.cc \ src/core/lib/security/util/json_util.cc \ src/core/lib/surface/init_secure.cc \ + src/core/tsi/alts/crypt/aes_gcm.cc \ + src/core/tsi/alts/crypt/gsec.cc \ + src/core/tsi/alts/frame_protector/alts_counter.cc \ + src/core/tsi/alts/frame_protector/alts_crypter.cc \ + src/core/tsi/alts/frame_protector/alts_frame_protector.cc \ + src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc \ + src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc \ + src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc \ + src/core/tsi/alts/frame_protector/frame_handler.cc \ + src/core/tsi/alts/handshaker/alts_handshaker_client.cc \ + src/core/tsi/alts/handshaker/alts_tsi_event.cc \ + src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc \ + src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc \ + src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc \ + src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc \ + src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc \ + src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc \ + src/core/lib/security/credentials/alts/check_gcp_environment.cc \ + src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc \ + src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc \ + src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc \ + src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc \ + src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc \ + src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc \ + src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc \ + src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc \ + src/core/tsi/alts/handshaker/alts_tsi_utils.cc \ + src/core/tsi/alts/handshaker/transport_security_common_api.cc \ + src/core/tsi/alts/handshaker/altscontext.pb.c \ + src/core/tsi/alts/handshaker/handshaker.pb.c \ + src/core/tsi/alts/handshaker/transport_security_common.pb.c \ + third_party/nanopb/pb_common.c \ + third_party/nanopb/pb_decode.c \ + third_party/nanopb/pb_encode.c \ + src/core/tsi/transport_security.cc \ + src/core/tsi/transport_security_adapter.cc \ + src/core/ext/transport/chttp2/client/insecure/channel_create.cc \ + src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \ + src/core/ext/transport/chttp2/client/chttp2_connector.cc \ src/core/tsi/alts_transport_security.cc \ src/core/tsi/fake_transport_security.cc \ src/core/tsi/ssl_transport_security.cc \ src/core/tsi/transport_security_grpc.cc \ - src/core/tsi/transport_security.cc \ - src/core/tsi/transport_security_adapter.cc \ - src/core/ext/transport/chttp2/client/chttp2_connector.cc \ src/core/ext/filters/load_reporting/server_load_reporting_filter.cc \ src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc \ src/core/plugin_registry/grpc_cronet_plugin_registry.cc \ @@ -14282,15 +14480,15 @@ endif endif -ASYNC_END2END_TEST_SRC = \ - test/cpp/end2end/async_end2end_test.cc \ +ALTS_COUNTER_TEST_SRC = \ + test/core/tsi/alts/frame_protector/alts_counter_test.cc \ -ASYNC_END2END_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ASYNC_END2END_TEST_SRC)))) +ALTS_COUNTER_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ALTS_COUNTER_TEST_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/async_end2end_test: openssl_dep_error +$(BINDIR)/$(CONFIG)/alts_counter_test: openssl_dep_error else @@ -14301,39 +14499,39 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/async_end2end_test: protobuf_dep_error +$(BINDIR)/$(CONFIG)/alts_counter_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/async_end2end_test: $(PROTOBUF_DEP) $(ASYNC_END2END_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/alts_counter_test: $(PROTOBUF_DEP) $(ALTS_COUNTER_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(ASYNC_END2END_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/async_end2end_test + $(Q) $(LDXX) $(LDFLAGS) $(ALTS_COUNTER_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/alts_counter_test endif endif -$(OBJDIR)/$(CONFIG)/test/cpp/end2end/async_end2end_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/tsi/alts/frame_protector/alts_counter_test.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a -deps_async_end2end_test: $(ASYNC_END2END_TEST_OBJS:.o=.dep) +deps_alts_counter_test: $(ALTS_COUNTER_TEST_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(ASYNC_END2END_TEST_OBJS:.o=.dep) +-include $(ALTS_COUNTER_TEST_OBJS:.o=.dep) endif endif -AUTH_PROPERTY_ITERATOR_TEST_SRC = \ - test/cpp/common/auth_property_iterator_test.cc \ +ALTS_CRYPT_TEST_SRC = \ + test/core/tsi/alts/crypt/aes_gcm_test.cc \ -AUTH_PROPERTY_ITERATOR_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(AUTH_PROPERTY_ITERATOR_TEST_SRC)))) +ALTS_CRYPT_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ALTS_CRYPT_TEST_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/auth_property_iterator_test: openssl_dep_error +$(BINDIR)/$(CONFIG)/alts_crypt_test: openssl_dep_error else @@ -14344,39 +14542,39 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/auth_property_iterator_test: protobuf_dep_error +$(BINDIR)/$(CONFIG)/alts_crypt_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/auth_property_iterator_test: $(PROTOBUF_DEP) $(AUTH_PROPERTY_ITERATOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/alts_crypt_test: $(PROTOBUF_DEP) $(ALTS_CRYPT_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(AUTH_PROPERTY_ITERATOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/auth_property_iterator_test + $(Q) $(LDXX) $(LDFLAGS) $(ALTS_CRYPT_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/alts_crypt_test endif endif -$(OBJDIR)/$(CONFIG)/test/cpp/common/auth_property_iterator_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/tsi/alts/crypt/aes_gcm_test.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a -deps_auth_property_iterator_test: $(AUTH_PROPERTY_ITERATOR_TEST_OBJS:.o=.dep) +deps_alts_crypt_test: $(ALTS_CRYPT_TEST_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(AUTH_PROPERTY_ITERATOR_TEST_OBJS:.o=.dep) +-include $(ALTS_CRYPT_TEST_OBJS:.o=.dep) endif endif -BACKOFF_TEST_SRC = \ - test/core/backoff/backoff_test.cc \ +ALTS_CRYPTER_TEST_SRC = \ + test/core/tsi/alts/frame_protector/alts_crypter_test.cc \ -BACKOFF_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BACKOFF_TEST_SRC)))) +ALTS_CRYPTER_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ALTS_CRYPTER_TEST_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/backoff_test: openssl_dep_error +$(BINDIR)/$(CONFIG)/alts_crypter_test: openssl_dep_error else @@ -14387,39 +14585,39 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/backoff_test: protobuf_dep_error +$(BINDIR)/$(CONFIG)/alts_crypter_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/backoff_test: $(PROTOBUF_DEP) $(BACKOFF_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/alts_crypter_test: $(PROTOBUF_DEP) $(ALTS_CRYPTER_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(BACKOFF_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/backoff_test + $(Q) $(LDXX) $(LDFLAGS) $(ALTS_CRYPTER_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/alts_crypter_test endif endif -$(OBJDIR)/$(CONFIG)/test/core/backoff/backoff_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/tsi/alts/frame_protector/alts_crypter_test.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a -deps_backoff_test: $(BACKOFF_TEST_OBJS:.o=.dep) +deps_alts_crypter_test: $(ALTS_CRYPTER_TEST_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(BACKOFF_TEST_OBJS:.o=.dep) +-include $(ALTS_CRYPTER_TEST_OBJS:.o=.dep) endif endif -BDP_ESTIMATOR_TEST_SRC = \ - test/core/transport/bdp_estimator_test.cc \ +ALTS_FRAME_HANDLER_TEST_SRC = \ + test/core/tsi/alts/frame_protector/frame_handler_test.cc \ -BDP_ESTIMATOR_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BDP_ESTIMATOR_TEST_SRC)))) +ALTS_FRAME_HANDLER_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ALTS_FRAME_HANDLER_TEST_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/bdp_estimator_test: openssl_dep_error +$(BINDIR)/$(CONFIG)/alts_frame_handler_test: openssl_dep_error else @@ -14430,39 +14628,40 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/bdp_estimator_test: protobuf_dep_error +$(BINDIR)/$(CONFIG)/alts_frame_handler_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/bdp_estimator_test: $(PROTOBUF_DEP) $(BDP_ESTIMATOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/alts_frame_handler_test: $(PROTOBUF_DEP) $(ALTS_FRAME_HANDLER_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(BDP_ESTIMATOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bdp_estimator_test + $(Q) $(LDXX) $(LDFLAGS) $(ALTS_FRAME_HANDLER_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/alts_frame_handler_test endif endif -$(OBJDIR)/$(CONFIG)/test/core/transport/bdp_estimator_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/tsi/alts/frame_protector/frame_handler_test.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a -deps_bdp_estimator_test: $(BDP_ESTIMATOR_TEST_OBJS:.o=.dep) +deps_alts_frame_handler_test: $(ALTS_FRAME_HANDLER_TEST_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(BDP_ESTIMATOR_TEST_OBJS:.o=.dep) +-include $(ALTS_FRAME_HANDLER_TEST_OBJS:.o=.dep) endif endif -BM_ARENA_SRC = \ - test/cpp/microbenchmarks/bm_arena.cc \ +ALTS_FRAME_PROTECTOR_TEST_SRC = \ + test/core/tsi/alts/frame_protector/alts_frame_protector_test.cc \ + test/core/tsi/transport_security_test_lib.cc \ -BM_ARENA_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_ARENA_SRC)))) +ALTS_FRAME_PROTECTOR_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ALTS_FRAME_PROTECTOR_TEST_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/bm_arena: openssl_dep_error +$(BINDIR)/$(CONFIG)/alts_frame_protector_test: openssl_dep_error else @@ -14473,40 +14672,41 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/bm_arena: protobuf_dep_error +$(BINDIR)/$(CONFIG)/alts_frame_protector_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/bm_arena: $(PROTOBUF_DEP) $(BM_ARENA_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/alts_frame_protector_test: $(PROTOBUF_DEP) $(ALTS_FRAME_PROTECTOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(BM_ARENA_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_arena + $(Q) $(LDXX) $(LDFLAGS) $(ALTS_FRAME_PROTECTOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/alts_frame_protector_test endif endif -$(BM_ARENA_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX -$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_arena.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/tsi/alts/frame_protector/alts_frame_protector_test.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a -deps_bm_arena: $(BM_ARENA_OBJS:.o=.dep) +$(OBJDIR)/$(CONFIG)/test/core/tsi/transport_security_test_lib.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a + +deps_alts_frame_protector_test: $(ALTS_FRAME_PROTECTOR_TEST_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(BM_ARENA_OBJS:.o=.dep) +-include $(ALTS_FRAME_PROTECTOR_TEST_OBJS:.o=.dep) endif endif -BM_CALL_CREATE_SRC = \ - test/cpp/microbenchmarks/bm_call_create.cc \ +ALTS_GRPC_RECORD_PROTOCOL_TEST_SRC = \ + test/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_test.cc \ -BM_CALL_CREATE_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_CALL_CREATE_SRC)))) +ALTS_GRPC_RECORD_PROTOCOL_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ALTS_GRPC_RECORD_PROTOCOL_TEST_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/bm_call_create: openssl_dep_error +$(BINDIR)/$(CONFIG)/alts_grpc_record_protocol_test: openssl_dep_error else @@ -14517,40 +14717,39 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/bm_call_create: protobuf_dep_error +$(BINDIR)/$(CONFIG)/alts_grpc_record_protocol_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/bm_call_create: $(PROTOBUF_DEP) $(BM_CALL_CREATE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/alts_grpc_record_protocol_test: $(PROTOBUF_DEP) $(ALTS_GRPC_RECORD_PROTOCOL_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(BM_CALL_CREATE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_call_create + $(Q) $(LDXX) $(LDFLAGS) $(ALTS_GRPC_RECORD_PROTOCOL_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/alts_grpc_record_protocol_test endif endif -$(BM_CALL_CREATE_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX -$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_call_create.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_test.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a -deps_bm_call_create: $(BM_CALL_CREATE_OBJS:.o=.dep) +deps_alts_grpc_record_protocol_test: $(ALTS_GRPC_RECORD_PROTOCOL_TEST_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(BM_CALL_CREATE_OBJS:.o=.dep) +-include $(ALTS_GRPC_RECORD_PROTOCOL_TEST_OBJS:.o=.dep) endif endif -BM_CHTTP2_HPACK_SRC = \ - test/cpp/microbenchmarks/bm_chttp2_hpack.cc \ +ALTS_HANDSHAKER_CLIENT_TEST_SRC = \ + test/core/tsi/alts/handshaker/alts_handshaker_client_test.cc \ -BM_CHTTP2_HPACK_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_CHTTP2_HPACK_SRC)))) +ALTS_HANDSHAKER_CLIENT_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ALTS_HANDSHAKER_CLIENT_TEST_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/bm_chttp2_hpack: openssl_dep_error +$(BINDIR)/$(CONFIG)/alts_handshaker_client_test: openssl_dep_error else @@ -14561,40 +14760,39 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/bm_chttp2_hpack: protobuf_dep_error +$(BINDIR)/$(CONFIG)/alts_handshaker_client_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/bm_chttp2_hpack: $(PROTOBUF_DEP) $(BM_CHTTP2_HPACK_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/alts_handshaker_client_test: $(PROTOBUF_DEP) $(ALTS_HANDSHAKER_CLIENT_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(BM_CHTTP2_HPACK_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_chttp2_hpack + $(Q) $(LDXX) $(LDFLAGS) $(ALTS_HANDSHAKER_CLIENT_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/alts_handshaker_client_test endif endif -$(BM_CHTTP2_HPACK_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX -$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_chttp2_hpack.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/tsi/alts/handshaker/alts_handshaker_client_test.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a -deps_bm_chttp2_hpack: $(BM_CHTTP2_HPACK_OBJS:.o=.dep) +deps_alts_handshaker_client_test: $(ALTS_HANDSHAKER_CLIENT_TEST_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(BM_CHTTP2_HPACK_OBJS:.o=.dep) +-include $(ALTS_HANDSHAKER_CLIENT_TEST_OBJS:.o=.dep) endif endif -BM_CHTTP2_TRANSPORT_SRC = \ - test/cpp/microbenchmarks/bm_chttp2_transport.cc \ +ALTS_HANDSHAKER_SERVICE_API_TEST_SRC = \ + test/core/tsi/alts/handshaker/alts_handshaker_service_api_test.cc \ -BM_CHTTP2_TRANSPORT_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_CHTTP2_TRANSPORT_SRC)))) +ALTS_HANDSHAKER_SERVICE_API_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ALTS_HANDSHAKER_SERVICE_API_TEST_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/bm_chttp2_transport: openssl_dep_error +$(BINDIR)/$(CONFIG)/alts_handshaker_service_api_test: openssl_dep_error else @@ -14605,40 +14803,39 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/bm_chttp2_transport: protobuf_dep_error +$(BINDIR)/$(CONFIG)/alts_handshaker_service_api_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/bm_chttp2_transport: $(PROTOBUF_DEP) $(BM_CHTTP2_TRANSPORT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/alts_handshaker_service_api_test: $(PROTOBUF_DEP) $(ALTS_HANDSHAKER_SERVICE_API_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(BM_CHTTP2_TRANSPORT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_chttp2_transport + $(Q) $(LDXX) $(LDFLAGS) $(ALTS_HANDSHAKER_SERVICE_API_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/alts_handshaker_service_api_test endif endif -$(BM_CHTTP2_TRANSPORT_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX -$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_chttp2_transport.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a -deps_bm_chttp2_transport: $(BM_CHTTP2_TRANSPORT_OBJS:.o=.dep) +deps_alts_handshaker_service_api_test: $(ALTS_HANDSHAKER_SERVICE_API_TEST_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(BM_CHTTP2_TRANSPORT_OBJS:.o=.dep) +-include $(ALTS_HANDSHAKER_SERVICE_API_TEST_OBJS:.o=.dep) endif endif -BM_CLOSURE_SRC = \ - test/cpp/microbenchmarks/bm_closure.cc \ +ALTS_IOVEC_RECORD_PROTOCOL_TEST_SRC = \ + test/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol_test.cc \ -BM_CLOSURE_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_CLOSURE_SRC)))) +ALTS_IOVEC_RECORD_PROTOCOL_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ALTS_IOVEC_RECORD_PROTOCOL_TEST_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/bm_closure: openssl_dep_error +$(BINDIR)/$(CONFIG)/alts_iovec_record_protocol_test: openssl_dep_error else @@ -14649,40 +14846,39 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/bm_closure: protobuf_dep_error +$(BINDIR)/$(CONFIG)/alts_iovec_record_protocol_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/bm_closure: $(PROTOBUF_DEP) $(BM_CLOSURE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/alts_iovec_record_protocol_test: $(PROTOBUF_DEP) $(ALTS_IOVEC_RECORD_PROTOCOL_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(BM_CLOSURE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_closure + $(Q) $(LDXX) $(LDFLAGS) $(ALTS_IOVEC_RECORD_PROTOCOL_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/alts_iovec_record_protocol_test endif endif -$(BM_CLOSURE_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX -$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_closure.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol_test.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a -deps_bm_closure: $(BM_CLOSURE_OBJS:.o=.dep) +deps_alts_iovec_record_protocol_test: $(ALTS_IOVEC_RECORD_PROTOCOL_TEST_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(BM_CLOSURE_OBJS:.o=.dep) +-include $(ALTS_IOVEC_RECORD_PROTOCOL_TEST_OBJS:.o=.dep) endif endif -BM_CQ_SRC = \ - test/cpp/microbenchmarks/bm_cq.cc \ +ALTS_SECURITY_CONNECTOR_TEST_SRC = \ + test/core/security/alts_security_connector_test.cc \ -BM_CQ_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_CQ_SRC)))) +ALTS_SECURITY_CONNECTOR_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ALTS_SECURITY_CONNECTOR_TEST_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/bm_cq: openssl_dep_error +$(BINDIR)/$(CONFIG)/alts_security_connector_test: openssl_dep_error else @@ -14693,40 +14889,39 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/bm_cq: protobuf_dep_error +$(BINDIR)/$(CONFIG)/alts_security_connector_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/bm_cq: $(PROTOBUF_DEP) $(BM_CQ_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/alts_security_connector_test: $(PROTOBUF_DEP) $(ALTS_SECURITY_CONNECTOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(BM_CQ_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_cq + $(Q) $(LDXX) $(LDFLAGS) $(ALTS_SECURITY_CONNECTOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/alts_security_connector_test endif endif -$(BM_CQ_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX -$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_cq.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/security/alts_security_connector_test.o: $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a -deps_bm_cq: $(BM_CQ_OBJS:.o=.dep) +deps_alts_security_connector_test: $(ALTS_SECURITY_CONNECTOR_TEST_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(BM_CQ_OBJS:.o=.dep) +-include $(ALTS_SECURITY_CONNECTOR_TEST_OBJS:.o=.dep) endif endif -BM_CQ_MULTIPLE_THREADS_SRC = \ - test/cpp/microbenchmarks/bm_cq_multiple_threads.cc \ +ALTS_TSI_HANDSHAKER_TEST_SRC = \ + test/core/tsi/alts/handshaker/alts_tsi_handshaker_test.cc \ -BM_CQ_MULTIPLE_THREADS_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_CQ_MULTIPLE_THREADS_SRC)))) +ALTS_TSI_HANDSHAKER_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ALTS_TSI_HANDSHAKER_TEST_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/bm_cq_multiple_threads: openssl_dep_error +$(BINDIR)/$(CONFIG)/alts_tsi_handshaker_test: openssl_dep_error else @@ -14737,40 +14932,39 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/bm_cq_multiple_threads: protobuf_dep_error +$(BINDIR)/$(CONFIG)/alts_tsi_handshaker_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/bm_cq_multiple_threads: $(PROTOBUF_DEP) $(BM_CQ_MULTIPLE_THREADS_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/alts_tsi_handshaker_test: $(PROTOBUF_DEP) $(ALTS_TSI_HANDSHAKER_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(BM_CQ_MULTIPLE_THREADS_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_cq_multiple_threads + $(Q) $(LDXX) $(LDFLAGS) $(ALTS_TSI_HANDSHAKER_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/alts_tsi_handshaker_test endif endif -$(BM_CQ_MULTIPLE_THREADS_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX -$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_cq_multiple_threads.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/tsi/alts/handshaker/alts_tsi_handshaker_test.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a -deps_bm_cq_multiple_threads: $(BM_CQ_MULTIPLE_THREADS_OBJS:.o=.dep) +deps_alts_tsi_handshaker_test: $(ALTS_TSI_HANDSHAKER_TEST_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(BM_CQ_MULTIPLE_THREADS_OBJS:.o=.dep) +-include $(ALTS_TSI_HANDSHAKER_TEST_OBJS:.o=.dep) endif endif -BM_ERROR_SRC = \ - test/cpp/microbenchmarks/bm_error.cc \ +ALTS_TSI_UTILS_TEST_SRC = \ + test/core/tsi/alts/handshaker/alts_tsi_utils_test.cc \ -BM_ERROR_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_ERROR_SRC)))) +ALTS_TSI_UTILS_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ALTS_TSI_UTILS_TEST_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/bm_error: openssl_dep_error +$(BINDIR)/$(CONFIG)/alts_tsi_utils_test: openssl_dep_error else @@ -14781,40 +14975,39 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/bm_error: protobuf_dep_error +$(BINDIR)/$(CONFIG)/alts_tsi_utils_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/bm_error: $(PROTOBUF_DEP) $(BM_ERROR_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/alts_tsi_utils_test: $(PROTOBUF_DEP) $(ALTS_TSI_UTILS_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(BM_ERROR_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_error + $(Q) $(LDXX) $(LDFLAGS) $(ALTS_TSI_UTILS_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/alts_tsi_utils_test endif endif -$(BM_ERROR_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX -$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_error.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/tsi/alts/handshaker/alts_tsi_utils_test.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a -deps_bm_error: $(BM_ERROR_OBJS:.o=.dep) +deps_alts_tsi_utils_test: $(ALTS_TSI_UTILS_TEST_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(BM_ERROR_OBJS:.o=.dep) +-include $(ALTS_TSI_UTILS_TEST_OBJS:.o=.dep) endif endif -BM_FULLSTACK_STREAMING_PING_PONG_SRC = \ - test/cpp/microbenchmarks/bm_fullstack_streaming_ping_pong.cc \ +ALTS_ZERO_COPY_GRPC_PROTECTOR_TEST_SRC = \ + test/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector_test.cc \ -BM_FULLSTACK_STREAMING_PING_PONG_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_FULLSTACK_STREAMING_PING_PONG_SRC)))) +ALTS_ZERO_COPY_GRPC_PROTECTOR_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ALTS_ZERO_COPY_GRPC_PROTECTOR_TEST_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/bm_fullstack_streaming_ping_pong: openssl_dep_error +$(BINDIR)/$(CONFIG)/alts_zero_copy_grpc_protector_test: openssl_dep_error else @@ -14825,40 +15018,39 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/bm_fullstack_streaming_ping_pong: protobuf_dep_error +$(BINDIR)/$(CONFIG)/alts_zero_copy_grpc_protector_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/bm_fullstack_streaming_ping_pong: $(PROTOBUF_DEP) $(BM_FULLSTACK_STREAMING_PING_PONG_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/alts_zero_copy_grpc_protector_test: $(PROTOBUF_DEP) $(ALTS_ZERO_COPY_GRPC_PROTECTOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(BM_FULLSTACK_STREAMING_PING_PONG_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_fullstack_streaming_ping_pong + $(Q) $(LDXX) $(LDFLAGS) $(ALTS_ZERO_COPY_GRPC_PROTECTOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/alts_zero_copy_grpc_protector_test endif endif -$(BM_FULLSTACK_STREAMING_PING_PONG_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX -$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_fullstack_streaming_ping_pong.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector_test.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a -deps_bm_fullstack_streaming_ping_pong: $(BM_FULLSTACK_STREAMING_PING_PONG_OBJS:.o=.dep) +deps_alts_zero_copy_grpc_protector_test: $(ALTS_ZERO_COPY_GRPC_PROTECTOR_TEST_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(BM_FULLSTACK_STREAMING_PING_PONG_OBJS:.o=.dep) +-include $(ALTS_ZERO_COPY_GRPC_PROTECTOR_TEST_OBJS:.o=.dep) endif endif -BM_FULLSTACK_STREAMING_PUMP_SRC = \ - test/cpp/microbenchmarks/bm_fullstack_streaming_pump.cc \ +ASYNC_END2END_TEST_SRC = \ + test/cpp/end2end/async_end2end_test.cc \ -BM_FULLSTACK_STREAMING_PUMP_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_FULLSTACK_STREAMING_PUMP_SRC)))) +ASYNC_END2END_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ASYNC_END2END_TEST_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/bm_fullstack_streaming_pump: openssl_dep_error +$(BINDIR)/$(CONFIG)/async_end2end_test: openssl_dep_error else @@ -14869,40 +15061,39 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/bm_fullstack_streaming_pump: protobuf_dep_error +$(BINDIR)/$(CONFIG)/async_end2end_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/bm_fullstack_streaming_pump: $(PROTOBUF_DEP) $(BM_FULLSTACK_STREAMING_PUMP_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/async_end2end_test: $(PROTOBUF_DEP) $(ASYNC_END2END_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(BM_FULLSTACK_STREAMING_PUMP_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_fullstack_streaming_pump + $(Q) $(LDXX) $(LDFLAGS) $(ASYNC_END2END_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/async_end2end_test endif endif -$(BM_FULLSTACK_STREAMING_PUMP_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX -$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_fullstack_streaming_pump.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/cpp/end2end/async_end2end_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a -deps_bm_fullstack_streaming_pump: $(BM_FULLSTACK_STREAMING_PUMP_OBJS:.o=.dep) +deps_async_end2end_test: $(ASYNC_END2END_TEST_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(BM_FULLSTACK_STREAMING_PUMP_OBJS:.o=.dep) +-include $(ASYNC_END2END_TEST_OBJS:.o=.dep) endif endif -BM_FULLSTACK_TRICKLE_SRC = \ - test/cpp/microbenchmarks/bm_fullstack_trickle.cc \ +AUTH_PROPERTY_ITERATOR_TEST_SRC = \ + test/cpp/common/auth_property_iterator_test.cc \ -BM_FULLSTACK_TRICKLE_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_FULLSTACK_TRICKLE_SRC)))) +AUTH_PROPERTY_ITERATOR_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(AUTH_PROPERTY_ITERATOR_TEST_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/bm_fullstack_trickle: openssl_dep_error +$(BINDIR)/$(CONFIG)/auth_property_iterator_test: openssl_dep_error else @@ -14913,40 +15104,609 @@ ifeq ($(NO_PROTOBUF),true) # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. -$(BINDIR)/$(CONFIG)/bm_fullstack_trickle: protobuf_dep_error +$(BINDIR)/$(CONFIG)/auth_property_iterator_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/bm_fullstack_trickle: $(PROTOBUF_DEP) $(BM_FULLSTACK_TRICKLE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a +$(BINDIR)/$(CONFIG)/auth_property_iterator_test: $(PROTOBUF_DEP) $(AUTH_PROPERTY_ITERATOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(BM_FULLSTACK_TRICKLE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_fullstack_trickle + $(Q) $(LDXX) $(LDFLAGS) $(AUTH_PROPERTY_ITERATOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/auth_property_iterator_test endif endif -$(BM_FULLSTACK_TRICKLE_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX -$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_fullstack_trickle.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a +$(OBJDIR)/$(CONFIG)/test/cpp/common/auth_property_iterator_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a -deps_bm_fullstack_trickle: $(BM_FULLSTACK_TRICKLE_OBJS:.o=.dep) +deps_auth_property_iterator_test: $(AUTH_PROPERTY_ITERATOR_TEST_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(BM_FULLSTACK_TRICKLE_OBJS:.o=.dep) +-include $(AUTH_PROPERTY_ITERATOR_TEST_OBJS:.o=.dep) endif endif -BM_FULLSTACK_UNARY_PING_PONG_SRC = \ - test/cpp/microbenchmarks/bm_fullstack_unary_ping_pong.cc \ +BACKOFF_TEST_SRC = \ + test/core/backoff/backoff_test.cc \ -BM_FULLSTACK_UNARY_PING_PONG_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_FULLSTACK_UNARY_PING_PONG_SRC)))) +BACKOFF_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BACKOFF_TEST_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL. -$(BINDIR)/$(CONFIG)/bm_fullstack_unary_ping_pong: openssl_dep_error +$(BINDIR)/$(CONFIG)/backoff_test: openssl_dep_error + +else + + + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/backoff_test: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/backoff_test: $(PROTOBUF_DEP) $(BACKOFF_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(BACKOFF_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/backoff_test + +endif + +endif + +$(OBJDIR)/$(CONFIG)/test/core/backoff/backoff_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_backoff_test: $(BACKOFF_TEST_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(BACKOFF_TEST_OBJS:.o=.dep) +endif +endif + + +BDP_ESTIMATOR_TEST_SRC = \ + test/core/transport/bdp_estimator_test.cc \ + +BDP_ESTIMATOR_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BDP_ESTIMATOR_TEST_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/bdp_estimator_test: openssl_dep_error + +else + + + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/bdp_estimator_test: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/bdp_estimator_test: $(PROTOBUF_DEP) $(BDP_ESTIMATOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(BDP_ESTIMATOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bdp_estimator_test + +endif + +endif + +$(OBJDIR)/$(CONFIG)/test/core/transport/bdp_estimator_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_bdp_estimator_test: $(BDP_ESTIMATOR_TEST_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(BDP_ESTIMATOR_TEST_OBJS:.o=.dep) +endif +endif + + +BM_ARENA_SRC = \ + test/cpp/microbenchmarks/bm_arena.cc \ + +BM_ARENA_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_ARENA_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/bm_arena: openssl_dep_error + +else + + + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/bm_arena: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/bm_arena: $(PROTOBUF_DEP) $(BM_ARENA_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(BM_ARENA_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_arena + +endif + +endif + +$(BM_ARENA_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX +$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_arena.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_bm_arena: $(BM_ARENA_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(BM_ARENA_OBJS:.o=.dep) +endif +endif + + +BM_CALL_CREATE_SRC = \ + test/cpp/microbenchmarks/bm_call_create.cc \ + +BM_CALL_CREATE_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_CALL_CREATE_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/bm_call_create: openssl_dep_error + +else + + + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/bm_call_create: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/bm_call_create: $(PROTOBUF_DEP) $(BM_CALL_CREATE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(BM_CALL_CREATE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_call_create + +endif + +endif + +$(BM_CALL_CREATE_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX +$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_call_create.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_bm_call_create: $(BM_CALL_CREATE_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(BM_CALL_CREATE_OBJS:.o=.dep) +endif +endif + + +BM_CHTTP2_HPACK_SRC = \ + test/cpp/microbenchmarks/bm_chttp2_hpack.cc \ + +BM_CHTTP2_HPACK_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_CHTTP2_HPACK_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/bm_chttp2_hpack: openssl_dep_error + +else + + + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/bm_chttp2_hpack: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/bm_chttp2_hpack: $(PROTOBUF_DEP) $(BM_CHTTP2_HPACK_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(BM_CHTTP2_HPACK_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_chttp2_hpack + +endif + +endif + +$(BM_CHTTP2_HPACK_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX +$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_chttp2_hpack.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_bm_chttp2_hpack: $(BM_CHTTP2_HPACK_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(BM_CHTTP2_HPACK_OBJS:.o=.dep) +endif +endif + + +BM_CHTTP2_TRANSPORT_SRC = \ + test/cpp/microbenchmarks/bm_chttp2_transport.cc \ + +BM_CHTTP2_TRANSPORT_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_CHTTP2_TRANSPORT_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/bm_chttp2_transport: openssl_dep_error + +else + + + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/bm_chttp2_transport: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/bm_chttp2_transport: $(PROTOBUF_DEP) $(BM_CHTTP2_TRANSPORT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(BM_CHTTP2_TRANSPORT_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_chttp2_transport + +endif + +endif + +$(BM_CHTTP2_TRANSPORT_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX +$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_chttp2_transport.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_bm_chttp2_transport: $(BM_CHTTP2_TRANSPORT_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(BM_CHTTP2_TRANSPORT_OBJS:.o=.dep) +endif +endif + + +BM_CLOSURE_SRC = \ + test/cpp/microbenchmarks/bm_closure.cc \ + +BM_CLOSURE_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_CLOSURE_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/bm_closure: openssl_dep_error + +else + + + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/bm_closure: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/bm_closure: $(PROTOBUF_DEP) $(BM_CLOSURE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(BM_CLOSURE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_closure + +endif + +endif + +$(BM_CLOSURE_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX +$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_closure.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_bm_closure: $(BM_CLOSURE_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(BM_CLOSURE_OBJS:.o=.dep) +endif +endif + + +BM_CQ_SRC = \ + test/cpp/microbenchmarks/bm_cq.cc \ + +BM_CQ_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_CQ_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/bm_cq: openssl_dep_error + +else + + + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/bm_cq: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/bm_cq: $(PROTOBUF_DEP) $(BM_CQ_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(BM_CQ_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_cq + +endif + +endif + +$(BM_CQ_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX +$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_cq.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_bm_cq: $(BM_CQ_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(BM_CQ_OBJS:.o=.dep) +endif +endif + + +BM_CQ_MULTIPLE_THREADS_SRC = \ + test/cpp/microbenchmarks/bm_cq_multiple_threads.cc \ + +BM_CQ_MULTIPLE_THREADS_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_CQ_MULTIPLE_THREADS_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/bm_cq_multiple_threads: openssl_dep_error + +else + + + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/bm_cq_multiple_threads: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/bm_cq_multiple_threads: $(PROTOBUF_DEP) $(BM_CQ_MULTIPLE_THREADS_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(BM_CQ_MULTIPLE_THREADS_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_cq_multiple_threads + +endif + +endif + +$(BM_CQ_MULTIPLE_THREADS_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX +$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_cq_multiple_threads.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_bm_cq_multiple_threads: $(BM_CQ_MULTIPLE_THREADS_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(BM_CQ_MULTIPLE_THREADS_OBJS:.o=.dep) +endif +endif + + +BM_ERROR_SRC = \ + test/cpp/microbenchmarks/bm_error.cc \ + +BM_ERROR_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_ERROR_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/bm_error: openssl_dep_error + +else + + + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/bm_error: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/bm_error: $(PROTOBUF_DEP) $(BM_ERROR_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(BM_ERROR_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_error + +endif + +endif + +$(BM_ERROR_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX +$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_error.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_bm_error: $(BM_ERROR_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(BM_ERROR_OBJS:.o=.dep) +endif +endif + + +BM_FULLSTACK_STREAMING_PING_PONG_SRC = \ + test/cpp/microbenchmarks/bm_fullstack_streaming_ping_pong.cc \ + +BM_FULLSTACK_STREAMING_PING_PONG_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_FULLSTACK_STREAMING_PING_PONG_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/bm_fullstack_streaming_ping_pong: openssl_dep_error + +else + + + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/bm_fullstack_streaming_ping_pong: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/bm_fullstack_streaming_ping_pong: $(PROTOBUF_DEP) $(BM_FULLSTACK_STREAMING_PING_PONG_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(BM_FULLSTACK_STREAMING_PING_PONG_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_fullstack_streaming_ping_pong + +endif + +endif + +$(BM_FULLSTACK_STREAMING_PING_PONG_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX +$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_fullstack_streaming_ping_pong.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_bm_fullstack_streaming_ping_pong: $(BM_FULLSTACK_STREAMING_PING_PONG_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(BM_FULLSTACK_STREAMING_PING_PONG_OBJS:.o=.dep) +endif +endif + + +BM_FULLSTACK_STREAMING_PUMP_SRC = \ + test/cpp/microbenchmarks/bm_fullstack_streaming_pump.cc \ + +BM_FULLSTACK_STREAMING_PUMP_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_FULLSTACK_STREAMING_PUMP_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/bm_fullstack_streaming_pump: openssl_dep_error + +else + + + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/bm_fullstack_streaming_pump: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/bm_fullstack_streaming_pump: $(PROTOBUF_DEP) $(BM_FULLSTACK_STREAMING_PUMP_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(BM_FULLSTACK_STREAMING_PUMP_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_fullstack_streaming_pump + +endif + +endif + +$(BM_FULLSTACK_STREAMING_PUMP_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX +$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_fullstack_streaming_pump.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_bm_fullstack_streaming_pump: $(BM_FULLSTACK_STREAMING_PUMP_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(BM_FULLSTACK_STREAMING_PUMP_OBJS:.o=.dep) +endif +endif + + +BM_FULLSTACK_TRICKLE_SRC = \ + test/cpp/microbenchmarks/bm_fullstack_trickle.cc \ + +BM_FULLSTACK_TRICKLE_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_FULLSTACK_TRICKLE_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/bm_fullstack_trickle: openssl_dep_error + +else + + + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/bm_fullstack_trickle: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/bm_fullstack_trickle: $(PROTOBUF_DEP) $(BM_FULLSTACK_TRICKLE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(BM_FULLSTACK_TRICKLE_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/bm_fullstack_trickle + +endif + +endif + +$(BM_FULLSTACK_TRICKLE_OBJS): CPPFLAGS += -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX +$(OBJDIR)/$(CONFIG)/test/cpp/microbenchmarks/bm_fullstack_trickle.o: $(LIBDIR)/$(CONFIG)/libgrpc_benchmark.a $(LIBDIR)/$(CONFIG)/libbenchmark.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a + +deps_bm_fullstack_trickle: $(BM_FULLSTACK_TRICKLE_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(BM_FULLSTACK_TRICKLE_OBJS:.o=.dep) +endif +endif + + +BM_FULLSTACK_UNARY_PING_PONG_SRC = \ + test/cpp/microbenchmarks/bm_fullstack_unary_ping_pong.cc \ + +BM_FULLSTACK_UNARY_PING_PONG_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(BM_FULLSTACK_UNARY_PING_PONG_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/bm_fullstack_unary_ping_pong: openssl_dep_error else @@ -15156,6 +15916,92 @@ endif endif +CHECK_GCP_ENVIRONMENT_LINUX_TEST_SRC = \ + test/core/security/check_gcp_environment_linux_test.cc \ + +CHECK_GCP_ENVIRONMENT_LINUX_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(CHECK_GCP_ENVIRONMENT_LINUX_TEST_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/check_gcp_environment_linux_test: openssl_dep_error + +else + + + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/check_gcp_environment_linux_test: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/check_gcp_environment_linux_test: $(PROTOBUF_DEP) $(CHECK_GCP_ENVIRONMENT_LINUX_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(CHECK_GCP_ENVIRONMENT_LINUX_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/check_gcp_environment_linux_test + +endif + +endif + +$(OBJDIR)/$(CONFIG)/test/core/security/check_gcp_environment_linux_test.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_check_gcp_environment_linux_test: $(CHECK_GCP_ENVIRONMENT_LINUX_TEST_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(CHECK_GCP_ENVIRONMENT_LINUX_TEST_OBJS:.o=.dep) +endif +endif + + +CHECK_GCP_ENVIRONMENT_WINDOWS_TEST_SRC = \ + test/core/security/check_gcp_environment_windows_test.cc \ + +CHECK_GCP_ENVIRONMENT_WINDOWS_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(CHECK_GCP_ENVIRONMENT_WINDOWS_TEST_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/check_gcp_environment_windows_test: openssl_dep_error + +else + + + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/check_gcp_environment_windows_test: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/check_gcp_environment_windows_test: $(PROTOBUF_DEP) $(CHECK_GCP_ENVIRONMENT_WINDOWS_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(CHECK_GCP_ENVIRONMENT_WINDOWS_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/check_gcp_environment_windows_test + +endif + +endif + +$(OBJDIR)/$(CONFIG)/test/core/security/check_gcp_environment_windows_test.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_check_gcp_environment_windows_test: $(CHECK_GCP_ENVIRONMENT_WINDOWS_TEST_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(CHECK_GCP_ENVIRONMENT_WINDOWS_TEST_OBJS:.o=.dep) +endif +endif + + CHTTP2_SETTINGS_TIMEOUT_TEST_SRC = \ test/core/transport/chttp2/settings_timeout_test.cc \ @@ -16021,6 +16867,49 @@ endif $(OBJDIR)/$(CONFIG)/test/cpp/codegen/golden_file_test.o: $(GENDIR)/src/proto/grpc/testing/compiler_test.pb.cc $(GENDIR)/src/proto/grpc/testing/compiler_test.grpc.pb.cc +GRPC_ALTS_CREDENTIALS_OPTIONS_TEST_SRC = \ + test/core/security/grpc_alts_credentials_options_test.cc \ + +GRPC_ALTS_CREDENTIALS_OPTIONS_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(GRPC_ALTS_CREDENTIALS_OPTIONS_TEST_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test: openssl_dep_error + +else + + + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test: $(PROTOBUF_DEP) $(GRPC_ALTS_CREDENTIALS_OPTIONS_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(GRPC_ALTS_CREDENTIALS_OPTIONS_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test + +endif + +endif + +$(OBJDIR)/$(CONFIG)/test/core/security/grpc_alts_credentials_options_test.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_grpc_alts_credentials_options_test: $(GRPC_ALTS_CREDENTIALS_OPTIONS_TEST_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(GRPC_ALTS_CREDENTIALS_OPTIONS_TEST_OBJS:.o=.dep) +endif +endif + + GRPC_CLI_SRC = \ test/cpp/util/grpc_cli.cc \ @@ -18474,6 +19363,49 @@ endif endif +TRANSPORT_SECURITY_COMMON_API_TEST_SRC = \ + test/core/tsi/alts/handshaker/transport_security_common_api_test.cc \ + +TRANSPORT_SECURITY_COMMON_API_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(TRANSPORT_SECURITY_COMMON_API_TEST_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/transport_security_common_api_test: openssl_dep_error + +else + + + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/transport_security_common_api_test: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/transport_security_common_api_test: $(PROTOBUF_DEP) $(TRANSPORT_SECURITY_COMMON_API_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(TRANSPORT_SECURITY_COMMON_API_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/transport_security_common_api_test + +endif + +endif + +$(OBJDIR)/$(CONFIG)/test/core/tsi/alts/handshaker/transport_security_common_api_test.o: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a + +deps_transport_security_common_api_test: $(TRANSPORT_SECURITY_COMMON_API_TEST_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(TRANSPORT_SECURITY_COMMON_API_TEST_OBJS:.o=.dep) +endif +endif + + WRITES_PER_RPC_TEST_SRC = \ test/cpp/performance/writes_per_rpc_test.cc \ @@ -22484,6 +23416,14 @@ src/core/ext/transport/cronet/transport/cronet_api_dummy.cc: $(OPENSSL_DEP) src/core/ext/transport/cronet/transport/cronet_transport.cc: $(OPENSSL_DEP) src/core/lib/http/httpcli_security_connector.cc: $(OPENSSL_DEP) src/core/lib/security/context/security_context.cc: $(OPENSSL_DEP) +src/core/lib/security/credentials/alts/alts_credentials.cc: $(OPENSSL_DEP) +src/core/lib/security/credentials/alts/check_gcp_environment.cc: $(OPENSSL_DEP) +src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc: $(OPENSSL_DEP) +src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc: $(OPENSSL_DEP) +src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc: $(OPENSSL_DEP) +src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc: $(OPENSSL_DEP) +src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc: $(OPENSSL_DEP) +src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc: $(OPENSSL_DEP) src/core/lib/security/credentials/composite/composite_credentials.cc: $(OPENSSL_DEP) src/core/lib/security/credentials/credentials.cc: $(OPENSSL_DEP) src/core/lib/security/credentials/credentials_metadata.cc: $(OPENSSL_DEP) @@ -22497,6 +23437,7 @@ src/core/lib/security/credentials/jwt/jwt_verifier.cc: $(OPENSSL_DEP) src/core/lib/security/credentials/oauth2/oauth2_credentials.cc: $(OPENSSL_DEP) src/core/lib/security/credentials/plugin/plugin_credentials.cc: $(OPENSSL_DEP) src/core/lib/security/credentials/ssl/ssl_credentials.cc: $(OPENSSL_DEP) +src/core/lib/security/security_connector/alts_security_connector.cc: $(OPENSSL_DEP) src/core/lib/security/security_connector/security_connector.cc: $(OPENSSL_DEP) src/core/lib/security/transport/client_auth_filter.cc: $(OPENSSL_DEP) src/core/lib/security/transport/secure_endpoint.cc: $(OPENSSL_DEP) @@ -22508,6 +23449,30 @@ src/core/lib/security/util/json_util.cc: $(OPENSSL_DEP) src/core/lib/surface/init_secure.cc: $(OPENSSL_DEP) src/core/plugin_registry/grpc_cronet_plugin_registry.cc: $(OPENSSL_DEP) src/core/plugin_registry/grpc_plugin_registry.cc: $(OPENSSL_DEP) +src/core/tsi/alts/crypt/aes_gcm.cc: $(OPENSSL_DEP) +src/core/tsi/alts/crypt/gsec.cc: $(OPENSSL_DEP) +src/core/tsi/alts/frame_protector/alts_counter.cc: $(OPENSSL_DEP) +src/core/tsi/alts/frame_protector/alts_crypter.cc: $(OPENSSL_DEP) +src/core/tsi/alts/frame_protector/alts_frame_protector.cc: $(OPENSSL_DEP) +src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc: $(OPENSSL_DEP) +src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc: $(OPENSSL_DEP) +src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc: $(OPENSSL_DEP) +src/core/tsi/alts/frame_protector/frame_handler.cc: $(OPENSSL_DEP) +src/core/tsi/alts/handshaker/alts_handshaker_client.cc: $(OPENSSL_DEP) +src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc: $(OPENSSL_DEP) +src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc: $(OPENSSL_DEP) +src/core/tsi/alts/handshaker/alts_tsi_event.cc: $(OPENSSL_DEP) +src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc: $(OPENSSL_DEP) +src/core/tsi/alts/handshaker/alts_tsi_utils.cc: $(OPENSSL_DEP) +src/core/tsi/alts/handshaker/altscontext.pb.c: $(OPENSSL_DEP) +src/core/tsi/alts/handshaker/handshaker.pb.c: $(OPENSSL_DEP) +src/core/tsi/alts/handshaker/transport_security_common.pb.c: $(OPENSSL_DEP) +src/core/tsi/alts/handshaker/transport_security_common_api.cc: $(OPENSSL_DEP) +src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc: $(OPENSSL_DEP) +src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc: $(OPENSSL_DEP) +src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc: $(OPENSSL_DEP) +src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc: $(OPENSSL_DEP) +src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc: $(OPENSSL_DEP) src/core/tsi/alts_transport_security.cc: $(OPENSSL_DEP) src/core/tsi/fake_transport_security.cc: $(OPENSSL_DEP) src/core/tsi/ssl_transport_security.cc: $(OPENSSL_DEP) @@ -22535,6 +23500,8 @@ test/core/end2end/data/test_root_cert.cc: $(OPENSSL_DEP) test/core/end2end/end2end_tests.cc: $(OPENSSL_DEP) test/core/end2end/tests/call_creds.cc: $(OPENSSL_DEP) test/core/security/oauth2_utils.cc: $(OPENSSL_DEP) +test/core/tsi/alts/crypt/gsec_test_util.cc: $(OPENSSL_DEP) +test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc: $(OPENSSL_DEP) test/core/util/reconnect_server.cc: $(OPENSSL_DEP) test/core/util/test_tcp_server.cc: $(OPENSSL_DEP) test/cpp/end2end/test_service_impl.cc: $(OPENSSL_DEP) diff --git a/bazel/grpc_build_system.bzl b/bazel/grpc_build_system.bzl index 7bc186265d..662068ad2a 100644 --- a/bazel/grpc_build_system.bzl +++ b/bazel/grpc_build_system.bzl @@ -57,6 +57,12 @@ def _maybe_update_cc_library_hdrs(hdrs): ret.append(h) return ret +def _maybe_update_cc_library_defines(name): + ret = [] + if name == "alts_proto": + ret += ["PB_FIELD_16BIT=1"] + return ret + def grpc_cc_library(name, srcs = [], public_hdrs = [], hdrs = [], external_deps = [], deps = [], standalone = False, language = "C++", testonly = False, visibility = None, @@ -64,10 +70,11 @@ def grpc_cc_library(name, srcs = [], public_hdrs = [], hdrs = [], copts = [] if language.upper() == "C": copts = if_not_windows(["-std=c99"]) + defines = _maybe_update_cc_library_defines(name) native.cc_library( name = name, srcs = srcs, - defines = select({"//:grpc_no_ares": ["GRPC_ARES=0"], + defines = defines + select({"//:grpc_no_ares": ["GRPC_ARES=0"], "//conditions:default": [],}) + select({"//:remote_execution": ["GRPC_PORT_ISOLATED_RUNTIME=1"], "//conditions:default": [],}) + diff --git a/build.yaml b/build.yaml index e2d194041a..e2bb8bfa9f 100644 --- a/build.yaml +++ b/build.yaml @@ -16,6 +16,84 @@ settings: g_stands_for: gorgeous version: 1.11.0-dev filegroups: +- name: alts_proto + headers: + - src/core/tsi/alts/handshaker/altscontext.pb.h + - src/core/tsi/alts/handshaker/handshaker.pb.h + - src/core/tsi/alts/handshaker/transport_security_common.pb.h + src: + - src/core/tsi/alts/handshaker/altscontext.pb.c + - src/core/tsi/alts/handshaker/handshaker.pb.c + - src/core/tsi/alts/handshaker/transport_security_common.pb.c + uses: + - nanopb +- name: alts_tsi + headers: + - src/core/tsi/alts/crypt/gsec.h + - src/core/tsi/alts/frame_protector/alts_counter.h + - src/core/tsi/alts/frame_protector/alts_crypter.h + - src/core/tsi/alts/frame_protector/alts_frame_protector.h + - src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h + - src/core/tsi/alts/frame_protector/frame_handler.h + - src/core/tsi/alts/handshaker/alts_handshaker_client.h + - src/core/tsi/alts/handshaker/alts_tsi_event.h + - src/core/tsi/alts/handshaker/alts_tsi_handshaker.h + - src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h + - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h + - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h + - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h + - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h + - src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h + - src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h + src: + - src/core/tsi/alts/crypt/aes_gcm.cc + - src/core/tsi/alts/crypt/gsec.cc + - src/core/tsi/alts/frame_protector/alts_counter.cc + - src/core/tsi/alts/frame_protector/alts_crypter.cc + - src/core/tsi/alts/frame_protector/alts_frame_protector.cc + - src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc + - src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc + - src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc + - src/core/tsi/alts/frame_protector/frame_handler.cc + - src/core/tsi/alts/handshaker/alts_handshaker_client.cc + - src/core/tsi/alts/handshaker/alts_tsi_event.cc + - src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc + - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc + - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc + - src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc + - src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc + - src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc + uses: + - alts_util + - grpc_base + - grpc_transport_chttp2_client_insecure + - tsi_interface + - tsi +- name: alts_util + headers: + - src/core/lib/security/credentials/alts/check_gcp_environment.h + - src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h + - src/core/tsi/alts/handshaker/alts_handshaker_service_api.h + - src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h + - src/core/tsi/alts/handshaker/alts_tsi_utils.h + - src/core/tsi/alts/handshaker/transport_security_common_api.h + src: + - src/core/lib/security/credentials/alts/check_gcp_environment.cc + - src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc + - src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc + - src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc + - src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc + - src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc + - src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc + - src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc + - src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc + - src/core/tsi/alts/handshaker/alts_tsi_utils.cc + - src/core/tsi/alts/handshaker/transport_security_common_api.cc + uses: + - alts_proto + - grpc_base + - tsi_interface + - nanopb - name: census public_headers: - include/grpc/census.h @@ -642,6 +720,7 @@ filegroups: - include/grpc/grpc_security.h headers: - src/core/lib/security/context/security_context.h + - src/core/lib/security/credentials/alts/alts_credentials.h - src/core/lib/security/credentials/composite/composite_credentials.h - src/core/lib/security/credentials/credentials.h - src/core/lib/security/credentials/fake/fake_credentials.h @@ -653,6 +732,7 @@ filegroups: - src/core/lib/security/credentials/oauth2/oauth2_credentials.h - src/core/lib/security/credentials/plugin/plugin_credentials.h - src/core/lib/security/credentials/ssl/ssl_credentials.h + - src/core/lib/security/security_connector/alts_security_connector.h - src/core/lib/security/security_connector/security_connector.h - src/core/lib/security/transport/auth_filters.h - src/core/lib/security/transport/secure_endpoint.h @@ -663,6 +743,7 @@ filegroups: src: - src/core/lib/http/httpcli_security_connector.cc - src/core/lib/security/context/security_context.cc + - src/core/lib/security/credentials/alts/alts_credentials.cc - src/core/lib/security/credentials/composite/composite_credentials.cc - src/core/lib/security/credentials/credentials.cc - src/core/lib/security/credentials/credentials_metadata.cc @@ -676,6 +757,7 @@ filegroups: - src/core/lib/security/credentials/oauth2/oauth2_credentials.cc - src/core/lib/security/credentials/plugin/plugin_credentials.cc - src/core/lib/security/credentials/ssl/ssl_credentials.cc + - src/core/lib/security/security_connector/alts_security_connector.cc - src/core/lib/security/security_connector/security_connector.cc - src/core/lib/security/transport/client_auth_filter.cc - src/core/lib/security/transport/secure_endpoint.cc @@ -687,6 +769,7 @@ filegroups: - src/core/lib/surface/init_secure.cc secure: true uses: + - alts_tsi - grpc_base - grpc_transport_chttp2_alpn - tsi @@ -1211,6 +1294,18 @@ filegroups: - grpc++ - grpc libs: +- name: alts_test_util + build: private + language: c + headers: + - test/core/tsi/alts/crypt/gsec_test_util.h + - test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h + src: + - test/core/tsi/alts/crypt/gsec_test_util.cc + - test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc + deps: + - grpc + secure: true - name: gpr build: all language: c @@ -3496,6 +3591,125 @@ targets: - grpc_unsecure - gpr_test_util - gpr +- name: alts_counter_test + build: test + language: c++ + src: + - test/core/tsi/alts/frame_protector/alts_counter_test.cc + deps: + - alts_test_util + - gpr + - grpc +- name: alts_crypt_test + build: test + language: c++ + src: + - test/core/tsi/alts/crypt/aes_gcm_test.cc + deps: + - alts_test_util + - gpr_test_util + - gpr + - grpc +- name: alts_crypter_test + build: test + language: c++ + src: + - test/core/tsi/alts/frame_protector/alts_crypter_test.cc + deps: + - alts_test_util + - gpr + - grpc +- name: alts_frame_handler_test + build: test + language: c++ + src: + - test/core/tsi/alts/frame_protector/frame_handler_test.cc + deps: + - alts_test_util + - gpr + - grpc +- name: alts_frame_protector_test + build: test + language: c++ + src: + - test/core/tsi/alts/frame_protector/alts_frame_protector_test.cc + deps: + - alts_test_util + - gpr + - grpc + filegroups: + - transport_security_test_lib +- name: alts_grpc_record_protocol_test + build: test + language: c++ + src: + - test/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_test.cc + deps: + - alts_test_util + - gpr + - grpc +- name: alts_handshaker_client_test + build: test + language: c++ + src: + - test/core/tsi/alts/handshaker/alts_handshaker_client_test.cc + deps: + - alts_test_util + - gpr + - grpc +- name: alts_handshaker_service_api_test + build: test + language: c++ + src: + - test/core/tsi/alts/handshaker/alts_handshaker_service_api_test.cc + deps: + - alts_test_util + - gpr + - grpc +- name: alts_iovec_record_protocol_test + build: test + language: c++ + src: + - test/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol_test.cc + deps: + - alts_test_util + - gpr + - grpc +- name: alts_security_connector_test + build: test + language: c++ + src: + - test/core/security/alts_security_connector_test.cc + deps: + - gpr + - grpc +- name: alts_tsi_handshaker_test + build: test + language: c++ + src: + - test/core/tsi/alts/handshaker/alts_tsi_handshaker_test.cc + deps: + - alts_test_util + - gpr + - grpc +- name: alts_tsi_utils_test + build: test + language: c++ + src: + - test/core/tsi/alts/handshaker/alts_tsi_utils_test.cc + deps: + - alts_test_util + - gpr + - grpc +- name: alts_zero_copy_grpc_protector_test + build: test + language: c++ + src: + - test/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector_test.cc + deps: + - alts_test_util + - gpr + - grpc - name: async_end2end_test gtest: true build: test @@ -3879,6 +4093,22 @@ targets: - grpc - gpr uses_polling: false +- name: check_gcp_environment_linux_test + build: test + language: c++ + src: + - test/core/security/check_gcp_environment_linux_test.cc + deps: + - grpc + - gpr +- name: check_gcp_environment_windows_test + build: test + language: c++ + src: + - test/core/security/check_gcp_environment_windows_test.cc + deps: + - grpc + - gpr - name: chttp2_settings_timeout_test gtest: true build: test @@ -4137,6 +4367,14 @@ targets: args: - --generated_file_path=gens/src/proto/grpc/testing/ uses_polling: false +- name: grpc_alts_credentials_options_test + build: test + language: c++ + src: + - test/core/security/grpc_alts_credentials_options_test.cc + deps: + - grpc + - gpr - name: grpc_cli build: test run: false @@ -4972,6 +5210,15 @@ targets: - grpc - gpr_test_util - gpr +- name: transport_security_common_api_test + build: test + language: c++ + src: + - test/core/tsi/alts/handshaker/transport_security_common_api_test.cc + deps: + - alts_test_util + - gpr + - grpc - name: writes_per_rpc_test gtest: true cpu_cost: 0.5 diff --git a/config.m4 b/config.m4 index 272518bdbe..7270051b0b 100644 --- a/config.m4 +++ b/config.m4 @@ -244,6 +244,7 @@ if test "$PHP_GRPC" != "no"; then src/core/ext/filters/http/server/http_server_filter.cc \ src/core/lib/http/httpcli_security_connector.cc \ src/core/lib/security/context/security_context.cc \ + src/core/lib/security/credentials/alts/alts_credentials.cc \ src/core/lib/security/credentials/composite/composite_credentials.cc \ src/core/lib/security/credentials/credentials.cc \ src/core/lib/security/credentials/credentials_metadata.cc \ @@ -257,6 +258,7 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/security/credentials/oauth2/oauth2_credentials.cc \ src/core/lib/security/credentials/plugin/plugin_credentials.cc \ src/core/lib/security/credentials/ssl/ssl_credentials.cc \ + src/core/lib/security/security_connector/alts_security_connector.cc \ src/core/lib/security/security_connector/security_connector.cc \ src/core/lib/security/transport/client_auth_filter.cc \ src/core/lib/security/transport/secure_endpoint.cc \ @@ -266,14 +268,45 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/security/transport/tsi_error.cc \ src/core/lib/security/util/json_util.cc \ src/core/lib/surface/init_secure.cc \ - src/core/tsi/alts_transport_security.cc \ - src/core/tsi/fake_transport_security.cc \ - src/core/tsi/ssl_transport_security.cc \ - src/core/tsi/transport_security_grpc.cc \ + src/core/tsi/alts/crypt/aes_gcm.cc \ + src/core/tsi/alts/crypt/gsec.cc \ + src/core/tsi/alts/frame_protector/alts_counter.cc \ + src/core/tsi/alts/frame_protector/alts_crypter.cc \ + src/core/tsi/alts/frame_protector/alts_frame_protector.cc \ + src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc \ + src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc \ + src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc \ + src/core/tsi/alts/frame_protector/frame_handler.cc \ + src/core/tsi/alts/handshaker/alts_handshaker_client.cc \ + src/core/tsi/alts/handshaker/alts_tsi_event.cc \ + src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc \ + src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc \ + src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc \ + src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc \ + src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc \ + src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc \ + src/core/lib/security/credentials/alts/check_gcp_environment.cc \ + src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc \ + src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc \ + src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc \ + src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc \ + src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc \ + src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc \ + src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc \ + src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc \ + src/core/tsi/alts/handshaker/alts_tsi_utils.cc \ + src/core/tsi/alts/handshaker/transport_security_common_api.cc \ + src/core/tsi/alts/handshaker/altscontext.pb.c \ + src/core/tsi/alts/handshaker/handshaker.pb.c \ + src/core/tsi/alts/handshaker/transport_security_common.pb.c \ + third_party/nanopb/pb_common.c \ + third_party/nanopb/pb_decode.c \ + third_party/nanopb/pb_encode.c \ src/core/tsi/transport_security.cc \ src/core/tsi/transport_security_adapter.cc \ - src/core/ext/transport/chttp2/server/chttp2_server.cc \ - src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc \ + src/core/ext/transport/chttp2/client/insecure/channel_create.cc \ + src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \ + src/core/ext/transport/chttp2/client/chttp2_connector.cc \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ src/core/ext/filters/client_channel/client_channel.cc \ @@ -297,11 +330,14 @@ if test "$PHP_GRPC" != "no"; then src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ src/core/ext/filters/deadline/deadline_filter.cc \ - src/core/ext/transport/chttp2/client/chttp2_connector.cc \ + src/core/tsi/alts_transport_security.cc \ + src/core/tsi/fake_transport_security.cc \ + src/core/tsi/ssl_transport_security.cc \ + src/core/tsi/transport_security_grpc.cc \ + src/core/ext/transport/chttp2/server/chttp2_server.cc \ + src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc \ src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc \ src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc \ - src/core/ext/transport/chttp2/client/insecure/channel_create.cc \ - src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \ src/core/ext/transport/inproc/inproc_plugin.cc \ src/core/ext/transport/inproc/inproc_transport.cc \ src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc \ @@ -310,9 +346,6 @@ if test "$PHP_GRPC" != "no"; then src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc \ src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc \ src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c \ - third_party/nanopb/pb_common.c \ - third_party/nanopb/pb_decode.c \ - third_party/nanopb/pb_encode.c \ src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc \ src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc \ src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc \ @@ -635,6 +668,7 @@ if test "$PHP_GRPC" != "no"; then PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/profiling) PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/security/context) PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/security/credentials) + PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/security/credentials/alts) PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/security/credentials/composite) PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/security/credentials/fake) PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/security/credentials/google_default) @@ -651,6 +685,10 @@ if test "$PHP_GRPC" != "no"; then PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/transport) PHP_ADD_BUILD_DIR($ext_builddir/src/core/plugin_registry) PHP_ADD_BUILD_DIR($ext_builddir/src/core/tsi) + PHP_ADD_BUILD_DIR($ext_builddir/src/core/tsi/alts/crypt) + PHP_ADD_BUILD_DIR($ext_builddir/src/core/tsi/alts/frame_protector) + PHP_ADD_BUILD_DIR($ext_builddir/src/core/tsi/alts/handshaker) + PHP_ADD_BUILD_DIR($ext_builddir/src/core/tsi/alts/zero_copy_frame_protector) PHP_ADD_BUILD_DIR($ext_builddir/third_party/boringssl/crypto) PHP_ADD_BUILD_DIR($ext_builddir/third_party/boringssl/crypto/asn1) PHP_ADD_BUILD_DIR($ext_builddir/third_party/boringssl/crypto/base64) diff --git a/config.w32 b/config.w32 index 5a60b89b63..d73acc1118 100644 --- a/config.w32 +++ b/config.w32 @@ -221,6 +221,7 @@ if (PHP_GRPC != "no") { "src\\core\\ext\\filters\\http\\server\\http_server_filter.cc " + "src\\core\\lib\\http\\httpcli_security_connector.cc " + "src\\core\\lib\\security\\context\\security_context.cc " + + "src\\core\\lib\\security\\credentials\\alts\\alts_credentials.cc " + "src\\core\\lib\\security\\credentials\\composite\\composite_credentials.cc " + "src\\core\\lib\\security\\credentials\\credentials.cc " + "src\\core\\lib\\security\\credentials\\credentials_metadata.cc " + @@ -234,6 +235,7 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\security\\credentials\\oauth2\\oauth2_credentials.cc " + "src\\core\\lib\\security\\credentials\\plugin\\plugin_credentials.cc " + "src\\core\\lib\\security\\credentials\\ssl\\ssl_credentials.cc " + + "src\\core\\lib\\security\\security_connector\\alts_security_connector.cc " + "src\\core\\lib\\security\\security_connector\\security_connector.cc " + "src\\core\\lib\\security\\transport\\client_auth_filter.cc " + "src\\core\\lib\\security\\transport\\secure_endpoint.cc " + @@ -243,14 +245,45 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\security\\transport\\tsi_error.cc " + "src\\core\\lib\\security\\util\\json_util.cc " + "src\\core\\lib\\surface\\init_secure.cc " + - "src\\core\\tsi\\alts_transport_security.cc " + - "src\\core\\tsi\\fake_transport_security.cc " + - "src\\core\\tsi\\ssl_transport_security.cc " + - "src\\core\\tsi\\transport_security_grpc.cc " + + "src\\core\\tsi\\alts\\crypt\\aes_gcm.cc " + + "src\\core\\tsi\\alts\\crypt\\gsec.cc " + + "src\\core\\tsi\\alts\\frame_protector\\alts_counter.cc " + + "src\\core\\tsi\\alts\\frame_protector\\alts_crypter.cc " + + "src\\core\\tsi\\alts\\frame_protector\\alts_frame_protector.cc " + + "src\\core\\tsi\\alts\\frame_protector\\alts_record_protocol_crypter_common.cc " + + "src\\core\\tsi\\alts\\frame_protector\\alts_seal_privacy_integrity_crypter.cc " + + "src\\core\\tsi\\alts\\frame_protector\\alts_unseal_privacy_integrity_crypter.cc " + + "src\\core\\tsi\\alts\\frame_protector\\frame_handler.cc " + + "src\\core\\tsi\\alts\\handshaker\\alts_handshaker_client.cc " + + "src\\core\\tsi\\alts\\handshaker\\alts_tsi_event.cc " + + "src\\core\\tsi\\alts\\handshaker\\alts_tsi_handshaker.cc " + + "src\\core\\tsi\\alts\\zero_copy_frame_protector\\alts_grpc_integrity_only_record_protocol.cc " + + "src\\core\\tsi\\alts\\zero_copy_frame_protector\\alts_grpc_privacy_integrity_record_protocol.cc " + + "src\\core\\tsi\\alts\\zero_copy_frame_protector\\alts_grpc_record_protocol_common.cc " + + "src\\core\\tsi\\alts\\zero_copy_frame_protector\\alts_iovec_record_protocol.cc " + + "src\\core\\tsi\\alts\\zero_copy_frame_protector\\alts_zero_copy_grpc_protector.cc " + + "src\\core\\lib\\security\\credentials\\alts\\check_gcp_environment.cc " + + "src\\core\\lib\\security\\credentials\\alts\\check_gcp_environment_linux.cc " + + "src\\core\\lib\\security\\credentials\\alts\\check_gcp_environment_no_op.cc " + + "src\\core\\lib\\security\\credentials\\alts\\check_gcp_environment_windows.cc " + + "src\\core\\lib\\security\\credentials\\alts\\grpc_alts_credentials_client_options.cc " + + "src\\core\\lib\\security\\credentials\\alts\\grpc_alts_credentials_options.cc " + + "src\\core\\lib\\security\\credentials\\alts\\grpc_alts_credentials_server_options.cc " + + "src\\core\\tsi\\alts\\handshaker\\alts_handshaker_service_api.cc " + + "src\\core\\tsi\\alts\\handshaker\\alts_handshaker_service_api_util.cc " + + "src\\core\\tsi\\alts\\handshaker\\alts_tsi_utils.cc " + + "src\\core\\tsi\\alts\\handshaker\\transport_security_common_api.cc " + + "src\\core\\tsi\\alts\\handshaker\\altscontext.pb.c " + + "src\\core\\tsi\\alts\\handshaker\\handshaker.pb.c " + + "src\\core\\tsi\\alts\\handshaker\\transport_security_common.pb.c " + + "third_party\\nanopb\\pb_common.c " + + "third_party\\nanopb\\pb_decode.c " + + "third_party\\nanopb\\pb_encode.c " + "src\\core\\tsi\\transport_security.cc " + "src\\core\\tsi\\transport_security_adapter.cc " + - "src\\core\\ext\\transport\\chttp2\\server\\chttp2_server.cc " + - "src\\core\\ext\\transport\\chttp2\\client\\secure\\secure_channel_create.cc " + + "src\\core\\ext\\transport\\chttp2\\client\\insecure\\channel_create.cc " + + "src\\core\\ext\\transport\\chttp2\\client\\insecure\\channel_create_posix.cc " + + "src\\core\\ext\\transport\\chttp2\\client\\chttp2_connector.cc " + "src\\core\\ext\\filters\\client_channel\\backup_poller.cc " + "src\\core\\ext\\filters\\client_channel\\channel_connectivity.cc " + "src\\core\\ext\\filters\\client_channel\\client_channel.cc " + @@ -274,11 +307,14 @@ if (PHP_GRPC != "no") { "src\\core\\ext\\filters\\client_channel\\subchannel_index.cc " + "src\\core\\ext\\filters\\client_channel\\uri_parser.cc " + "src\\core\\ext\\filters\\deadline\\deadline_filter.cc " + - "src\\core\\ext\\transport\\chttp2\\client\\chttp2_connector.cc " + + "src\\core\\tsi\\alts_transport_security.cc " + + "src\\core\\tsi\\fake_transport_security.cc " + + "src\\core\\tsi\\ssl_transport_security.cc " + + "src\\core\\tsi\\transport_security_grpc.cc " + + "src\\core\\ext\\transport\\chttp2\\server\\chttp2_server.cc " + + "src\\core\\ext\\transport\\chttp2\\client\\secure\\secure_channel_create.cc " + "src\\core\\ext\\transport\\chttp2\\server\\insecure\\server_chttp2.cc " + "src\\core\\ext\\transport\\chttp2\\server\\insecure\\server_chttp2_posix.cc " + - "src\\core\\ext\\transport\\chttp2\\client\\insecure\\channel_create.cc " + - "src\\core\\ext\\transport\\chttp2\\client\\insecure\\channel_create_posix.cc " + "src\\core\\ext\\transport\\inproc\\inproc_plugin.cc " + "src\\core\\ext\\transport\\inproc\\inproc_transport.cc " + "src\\core\\ext\\filters\\client_channel\\lb_policy\\grpclb\\client_load_reporting_filter.cc " + @@ -287,9 +323,6 @@ if (PHP_GRPC != "no") { "src\\core\\ext\\filters\\client_channel\\lb_policy\\grpclb\\grpclb_client_stats.cc " + "src\\core\\ext\\filters\\client_channel\\lb_policy\\grpclb\\load_balancer_api.cc " + "src\\core\\ext\\filters\\client_channel\\lb_policy\\grpclb\\proto\\grpc\\lb\\v1\\load_balancer.pb.c " + - "third_party\\nanopb\\pb_common.c " + - "third_party\\nanopb\\pb_decode.c " + - "third_party\\nanopb\\pb_encode.c " + "src\\core\\ext\\filters\\client_channel\\resolver\\fake\\fake_resolver.cc " + "src\\core\\ext\\filters\\client_channel\\lb_policy\\pick_first\\pick_first.cc " + "src\\core\\ext\\filters\\client_channel\\lb_policy\\subchannel_list.cc " + @@ -648,6 +681,7 @@ if (PHP_GRPC != "no") { FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\security"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\security\\context"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\security\\credentials"); + FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\security\\credentials\\alts"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\security\\credentials\\composite"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\security\\credentials\\fake"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\security\\credentials\\google_default"); @@ -664,6 +698,11 @@ if (PHP_GRPC != "no") { FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\transport"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\plugin_registry"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\tsi"); + FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\tsi\\alts"); + FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\tsi\\alts\\crypt"); + FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\tsi\\alts\\frame_protector"); + FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\tsi\\alts\\handshaker"); + FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\tsi\\alts\\zero_copy_frame_protector"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\php"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\php\\ext"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\php\\ext\\grpc"); diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 821c16da45..65a5dc66b4 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -260,6 +260,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/http/message_compress/message_compress_filter.h', 'src/core/ext/filters/http/server/http_server_filter.h', 'src/core/lib/security/context/security_context.h', + 'src/core/lib/security/credentials/alts/alts_credentials.h', 'src/core/lib/security/credentials/composite/composite_credentials.h', 'src/core/lib/security/credentials/credentials.h', 'src/core/lib/security/credentials/fake/fake_credentials.h', @@ -271,6 +272,7 @@ Pod::Spec.new do |s| 'src/core/lib/security/credentials/oauth2/oauth2_credentials.h', 'src/core/lib/security/credentials/plugin/plugin_credentials.h', 'src/core/lib/security/credentials/ssl/ssl_credentials.h', + 'src/core/lib/security/security_connector/alts_security_connector.h', 'src/core/lib/security/security_connector/security_connector.h', 'src/core/lib/security/transport/auth_filters.h', 'src/core/lib/security/transport/secure_endpoint.h', @@ -278,15 +280,35 @@ Pod::Spec.new do |s| 'src/core/lib/security/transport/target_authority_table.h', 'src/core/lib/security/transport/tsi_error.h', 'src/core/lib/security/util/json_util.h', - 'src/core/tsi/alts_transport_security.h', - 'src/core/tsi/fake_transport_security.h', - 'src/core/tsi/ssl_transport_security.h', - 'src/core/tsi/ssl_types.h', - 'src/core/tsi/transport_security_grpc.h', + 'src/core/tsi/alts/crypt/gsec.h', + 'src/core/tsi/alts/frame_protector/alts_counter.h', + 'src/core/tsi/alts/frame_protector/alts_crypter.h', + 'src/core/tsi/alts/frame_protector/alts_frame_protector.h', + 'src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h', + 'src/core/tsi/alts/frame_protector/frame_handler.h', + 'src/core/tsi/alts/handshaker/alts_handshaker_client.h', + 'src/core/tsi/alts/handshaker/alts_tsi_event.h', + 'src/core/tsi/alts/handshaker/alts_tsi_handshaker.h', + 'src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h', + 'src/core/lib/security/credentials/alts/check_gcp_environment.h', + 'src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h', + 'src/core/tsi/alts/handshaker/alts_handshaker_service_api.h', + 'src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h', + 'src/core/tsi/alts/handshaker/alts_tsi_utils.h', + 'src/core/tsi/alts/handshaker/transport_security_common_api.h', + 'src/core/tsi/alts/handshaker/altscontext.pb.h', + 'src/core/tsi/alts/handshaker/handshaker.pb.h', + 'src/core/tsi/alts/handshaker/transport_security_common.pb.h', 'src/core/tsi/transport_security.h', 'src/core/tsi/transport_security_adapter.h', 'src/core/tsi/transport_security_interface.h', - 'src/core/ext/transport/chttp2/server/chttp2_server.h', + 'src/core/ext/transport/chttp2/client/chttp2_connector.h', 'src/core/ext/filters/client_channel/backup_poller.h', 'src/core/ext/filters/client_channel/client_channel.h', 'src/core/ext/filters/client_channel/client_channel_factory.h', @@ -309,7 +331,12 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/subchannel_index.h', 'src/core/ext/filters/client_channel/uri_parser.h', 'src/core/ext/filters/deadline/deadline_filter.h', - 'src/core/ext/transport/chttp2/client/chttp2_connector.h', + 'src/core/tsi/alts_transport_security.h', + 'src/core/tsi/fake_transport_security.h', + 'src/core/tsi/ssl_transport_security.h', + 'src/core/tsi/ssl_types.h', + 'src/core/tsi/transport_security_grpc.h', + 'src/core/ext/transport/chttp2/server/chttp2_server.h', 'src/core/ext/transport/inproc/inproc_transport.h', 'src/core/lib/avl/avl.h', 'src/core/lib/backoff/backoff.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 6c6c76991c..7f61719cb1 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -93,7 +93,7 @@ Pod::Spec.new do |s| } s.default_subspecs = 'Interface', 'Implementation' - s.compiler_flags = '-DGRPC_ARES=0' + s.compiler_flags = '-DGRPC_ARES=0', '-DPB_FIELD_16BIT' s.libraries = 'c++' # Like many other C libraries, gRPC-Core has its public headers under `include//` and its @@ -271,6 +271,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/http/message_compress/message_compress_filter.h', 'src/core/ext/filters/http/server/http_server_filter.h', 'src/core/lib/security/context/security_context.h', + 'src/core/lib/security/credentials/alts/alts_credentials.h', 'src/core/lib/security/credentials/composite/composite_credentials.h', 'src/core/lib/security/credentials/credentials.h', 'src/core/lib/security/credentials/fake/fake_credentials.h', @@ -282,6 +283,7 @@ Pod::Spec.new do |s| 'src/core/lib/security/credentials/oauth2/oauth2_credentials.h', 'src/core/lib/security/credentials/plugin/plugin_credentials.h', 'src/core/lib/security/credentials/ssl/ssl_credentials.h', + 'src/core/lib/security/security_connector/alts_security_connector.h', 'src/core/lib/security/security_connector/security_connector.h', 'src/core/lib/security/transport/auth_filters.h', 'src/core/lib/security/transport/secure_endpoint.h', @@ -289,15 +291,35 @@ Pod::Spec.new do |s| 'src/core/lib/security/transport/target_authority_table.h', 'src/core/lib/security/transport/tsi_error.h', 'src/core/lib/security/util/json_util.h', - 'src/core/tsi/alts_transport_security.h', - 'src/core/tsi/fake_transport_security.h', - 'src/core/tsi/ssl_transport_security.h', - 'src/core/tsi/ssl_types.h', - 'src/core/tsi/transport_security_grpc.h', + 'src/core/tsi/alts/crypt/gsec.h', + 'src/core/tsi/alts/frame_protector/alts_counter.h', + 'src/core/tsi/alts/frame_protector/alts_crypter.h', + 'src/core/tsi/alts/frame_protector/alts_frame_protector.h', + 'src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h', + 'src/core/tsi/alts/frame_protector/frame_handler.h', + 'src/core/tsi/alts/handshaker/alts_handshaker_client.h', + 'src/core/tsi/alts/handshaker/alts_tsi_event.h', + 'src/core/tsi/alts/handshaker/alts_tsi_handshaker.h', + 'src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h', + 'src/core/lib/security/credentials/alts/check_gcp_environment.h', + 'src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h', + 'src/core/tsi/alts/handshaker/alts_handshaker_service_api.h', + 'src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h', + 'src/core/tsi/alts/handshaker/alts_tsi_utils.h', + 'src/core/tsi/alts/handshaker/transport_security_common_api.h', + 'src/core/tsi/alts/handshaker/altscontext.pb.h', + 'src/core/tsi/alts/handshaker/handshaker.pb.h', + 'src/core/tsi/alts/handshaker/transport_security_common.pb.h', 'src/core/tsi/transport_security.h', 'src/core/tsi/transport_security_adapter.h', 'src/core/tsi/transport_security_interface.h', - 'src/core/ext/transport/chttp2/server/chttp2_server.h', + 'src/core/ext/transport/chttp2/client/chttp2_connector.h', 'src/core/ext/filters/client_channel/backup_poller.h', 'src/core/ext/filters/client_channel/client_channel.h', 'src/core/ext/filters/client_channel/client_channel_factory.h', @@ -320,7 +342,12 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/subchannel_index.h', 'src/core/ext/filters/client_channel/uri_parser.h', 'src/core/ext/filters/deadline/deadline_filter.h', - 'src/core/ext/transport/chttp2/client/chttp2_connector.h', + 'src/core/tsi/alts_transport_security.h', + 'src/core/tsi/fake_transport_security.h', + 'src/core/tsi/ssl_transport_security.h', + 'src/core/tsi/ssl_types.h', + 'src/core/tsi/transport_security_grpc.h', + 'src/core/ext/transport/chttp2/server/chttp2_server.h', 'src/core/ext/transport/inproc/inproc_transport.h', 'src/core/lib/avl/avl.h', 'src/core/lib/backoff/backoff.h', @@ -631,6 +658,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/http/server/http_server_filter.cc', 'src/core/lib/http/httpcli_security_connector.cc', 'src/core/lib/security/context/security_context.cc', + 'src/core/lib/security/credentials/alts/alts_credentials.cc', 'src/core/lib/security/credentials/composite/composite_credentials.cc', 'src/core/lib/security/credentials/credentials.cc', 'src/core/lib/security/credentials/credentials_metadata.cc', @@ -644,6 +672,7 @@ Pod::Spec.new do |s| 'src/core/lib/security/credentials/oauth2/oauth2_credentials.cc', 'src/core/lib/security/credentials/plugin/plugin_credentials.cc', 'src/core/lib/security/credentials/ssl/ssl_credentials.cc', + 'src/core/lib/security/security_connector/alts_security_connector.cc', 'src/core/lib/security/security_connector/security_connector.cc', 'src/core/lib/security/transport/client_auth_filter.cc', 'src/core/lib/security/transport/secure_endpoint.cc', @@ -653,14 +682,42 @@ Pod::Spec.new do |s| 'src/core/lib/security/transport/tsi_error.cc', 'src/core/lib/security/util/json_util.cc', 'src/core/lib/surface/init_secure.cc', - 'src/core/tsi/alts_transport_security.cc', - 'src/core/tsi/fake_transport_security.cc', - 'src/core/tsi/ssl_transport_security.cc', - 'src/core/tsi/transport_security_grpc.cc', + 'src/core/tsi/alts/crypt/aes_gcm.cc', + 'src/core/tsi/alts/crypt/gsec.cc', + 'src/core/tsi/alts/frame_protector/alts_counter.cc', + 'src/core/tsi/alts/frame_protector/alts_crypter.cc', + 'src/core/tsi/alts/frame_protector/alts_frame_protector.cc', + 'src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc', + 'src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc', + 'src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc', + 'src/core/tsi/alts/frame_protector/frame_handler.cc', + 'src/core/tsi/alts/handshaker/alts_handshaker_client.cc', + 'src/core/tsi/alts/handshaker/alts_tsi_event.cc', + 'src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc', + 'src/core/lib/security/credentials/alts/check_gcp_environment.cc', + 'src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc', + 'src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc', + 'src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc', + 'src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc', + 'src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc', + 'src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc', + 'src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc', + 'src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc', + 'src/core/tsi/alts/handshaker/alts_tsi_utils.cc', + 'src/core/tsi/alts/handshaker/transport_security_common_api.cc', + 'src/core/tsi/alts/handshaker/altscontext.pb.c', + 'src/core/tsi/alts/handshaker/handshaker.pb.c', + 'src/core/tsi/alts/handshaker/transport_security_common.pb.c', 'src/core/tsi/transport_security.cc', 'src/core/tsi/transport_security_adapter.cc', - 'src/core/ext/transport/chttp2/server/chttp2_server.cc', - 'src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc', + 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', + 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', + 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', 'src/core/ext/filters/client_channel/client_channel.cc', @@ -684,11 +741,14 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', 'src/core/ext/filters/deadline/deadline_filter.cc', - 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', + 'src/core/tsi/alts_transport_security.cc', + 'src/core/tsi/fake_transport_security.cc', + 'src/core/tsi/ssl_transport_security.cc', + 'src/core/tsi/transport_security_grpc.cc', + 'src/core/ext/transport/chttp2/server/chttp2_server.cc', + 'src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc', 'src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc', 'src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc', - 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', - 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', 'src/core/ext/transport/inproc/inproc_plugin.cc', 'src/core/ext/transport/inproc/inproc_transport.cc', 'src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc', @@ -765,6 +825,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/http/message_compress/message_compress_filter.h', 'src/core/ext/filters/http/server/http_server_filter.h', 'src/core/lib/security/context/security_context.h', + 'src/core/lib/security/credentials/alts/alts_credentials.h', 'src/core/lib/security/credentials/composite/composite_credentials.h', 'src/core/lib/security/credentials/credentials.h', 'src/core/lib/security/credentials/fake/fake_credentials.h', @@ -776,6 +837,7 @@ Pod::Spec.new do |s| 'src/core/lib/security/credentials/oauth2/oauth2_credentials.h', 'src/core/lib/security/credentials/plugin/plugin_credentials.h', 'src/core/lib/security/credentials/ssl/ssl_credentials.h', + 'src/core/lib/security/security_connector/alts_security_connector.h', 'src/core/lib/security/security_connector/security_connector.h', 'src/core/lib/security/transport/auth_filters.h', 'src/core/lib/security/transport/secure_endpoint.h', @@ -783,15 +845,35 @@ Pod::Spec.new do |s| 'src/core/lib/security/transport/target_authority_table.h', 'src/core/lib/security/transport/tsi_error.h', 'src/core/lib/security/util/json_util.h', - 'src/core/tsi/alts_transport_security.h', - 'src/core/tsi/fake_transport_security.h', - 'src/core/tsi/ssl_transport_security.h', - 'src/core/tsi/ssl_types.h', - 'src/core/tsi/transport_security_grpc.h', + 'src/core/tsi/alts/crypt/gsec.h', + 'src/core/tsi/alts/frame_protector/alts_counter.h', + 'src/core/tsi/alts/frame_protector/alts_crypter.h', + 'src/core/tsi/alts/frame_protector/alts_frame_protector.h', + 'src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h', + 'src/core/tsi/alts/frame_protector/frame_handler.h', + 'src/core/tsi/alts/handshaker/alts_handshaker_client.h', + 'src/core/tsi/alts/handshaker/alts_tsi_event.h', + 'src/core/tsi/alts/handshaker/alts_tsi_handshaker.h', + 'src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h', + 'src/core/lib/security/credentials/alts/check_gcp_environment.h', + 'src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h', + 'src/core/tsi/alts/handshaker/alts_handshaker_service_api.h', + 'src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h', + 'src/core/tsi/alts/handshaker/alts_tsi_utils.h', + 'src/core/tsi/alts/handshaker/transport_security_common_api.h', + 'src/core/tsi/alts/handshaker/altscontext.pb.h', + 'src/core/tsi/alts/handshaker/handshaker.pb.h', + 'src/core/tsi/alts/handshaker/transport_security_common.pb.h', 'src/core/tsi/transport_security.h', 'src/core/tsi/transport_security_adapter.h', 'src/core/tsi/transport_security_interface.h', - 'src/core/ext/transport/chttp2/server/chttp2_server.h', + 'src/core/ext/transport/chttp2/client/chttp2_connector.h', 'src/core/ext/filters/client_channel/backup_poller.h', 'src/core/ext/filters/client_channel/client_channel.h', 'src/core/ext/filters/client_channel/client_channel_factory.h', @@ -814,7 +896,12 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/subchannel_index.h', 'src/core/ext/filters/client_channel/uri_parser.h', 'src/core/ext/filters/deadline/deadline_filter.h', - 'src/core/ext/transport/chttp2/client/chttp2_connector.h', + 'src/core/tsi/alts_transport_security.h', + 'src/core/tsi/fake_transport_security.h', + 'src/core/tsi/ssl_transport_security.h', + 'src/core/tsi/ssl_types.h', + 'src/core/tsi/transport_security_grpc.h', + 'src/core/ext/transport/chttp2/server/chttp2_server.h', 'src/core/ext/transport/inproc/inproc_transport.h', 'src/core/lib/avl/avl.h', 'src/core/lib/backoff/backoff.h', @@ -975,8 +1062,15 @@ Pod::Spec.new do |s| ss.source_files = 'src/core/ext/transport/cronet/client/secure/cronet_channel_create.cc', 'src/core/ext/transport/cronet/transport/cronet_transport.cc', + 'third_party/nanopb/pb_common.c', + 'third_party/nanopb/pb_decode.c', + 'third_party/nanopb/pb_encode.c', 'src/core/ext/transport/cronet/transport/cronet_transport.h', - 'third_party/objective_c/Cronet/bidirectional_stream_c.h' + 'third_party/objective_c/Cronet/bidirectional_stream_c.h', + 'third_party/nanopb/pb.h', + 'third_party/nanopb/pb_common.h', + 'third_party/nanopb/pb_decode.h', + 'third_party/nanopb/pb_encode.h' end s.subspec 'Tests' do |ss| diff --git a/grpc.gemspec b/grpc.gemspec index 574b871848..89a3812376 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -197,6 +197,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/http/message_compress/message_compress_filter.h ) s.files += %w( src/core/ext/filters/http/server/http_server_filter.h ) s.files += %w( src/core/lib/security/context/security_context.h ) + s.files += %w( src/core/lib/security/credentials/alts/alts_credentials.h ) s.files += %w( src/core/lib/security/credentials/composite/composite_credentials.h ) s.files += %w( src/core/lib/security/credentials/credentials.h ) s.files += %w( src/core/lib/security/credentials/fake/fake_credentials.h ) @@ -208,6 +209,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/security/credentials/oauth2/oauth2_credentials.h ) s.files += %w( src/core/lib/security/credentials/plugin/plugin_credentials.h ) s.files += %w( src/core/lib/security/credentials/ssl/ssl_credentials.h ) + s.files += %w( src/core/lib/security/security_connector/alts_security_connector.h ) s.files += %w( src/core/lib/security/security_connector/security_connector.h ) s.files += %w( src/core/lib/security/transport/auth_filters.h ) s.files += %w( src/core/lib/security/transport/secure_endpoint.h ) @@ -215,15 +217,39 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/security/transport/target_authority_table.h ) s.files += %w( src/core/lib/security/transport/tsi_error.h ) s.files += %w( src/core/lib/security/util/json_util.h ) - s.files += %w( src/core/tsi/alts_transport_security.h ) - s.files += %w( src/core/tsi/fake_transport_security.h ) - s.files += %w( src/core/tsi/ssl_transport_security.h ) - s.files += %w( src/core/tsi/ssl_types.h ) - s.files += %w( src/core/tsi/transport_security_grpc.h ) + s.files += %w( src/core/tsi/alts/crypt/gsec.h ) + s.files += %w( src/core/tsi/alts/frame_protector/alts_counter.h ) + s.files += %w( src/core/tsi/alts/frame_protector/alts_crypter.h ) + s.files += %w( src/core/tsi/alts/frame_protector/alts_frame_protector.h ) + s.files += %w( src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h ) + s.files += %w( src/core/tsi/alts/frame_protector/frame_handler.h ) + s.files += %w( src/core/tsi/alts/handshaker/alts_handshaker_client.h ) + s.files += %w( src/core/tsi/alts/handshaker/alts_tsi_event.h ) + s.files += %w( src/core/tsi/alts/handshaker/alts_tsi_handshaker.h ) + s.files += %w( src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h ) + s.files += %w( src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h ) + s.files += %w( src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h ) + s.files += %w( src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h ) + s.files += %w( src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h ) + s.files += %w( src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h ) + s.files += %w( src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h ) + s.files += %w( src/core/lib/security/credentials/alts/check_gcp_environment.h ) + s.files += %w( src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h ) + s.files += %w( src/core/tsi/alts/handshaker/alts_handshaker_service_api.h ) + s.files += %w( src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h ) + s.files += %w( src/core/tsi/alts/handshaker/alts_tsi_utils.h ) + s.files += %w( src/core/tsi/alts/handshaker/transport_security_common_api.h ) + s.files += %w( src/core/tsi/alts/handshaker/altscontext.pb.h ) + s.files += %w( src/core/tsi/alts/handshaker/handshaker.pb.h ) + s.files += %w( src/core/tsi/alts/handshaker/transport_security_common.pb.h ) + s.files += %w( third_party/nanopb/pb.h ) + s.files += %w( third_party/nanopb/pb_common.h ) + s.files += %w( third_party/nanopb/pb_decode.h ) + s.files += %w( third_party/nanopb/pb_encode.h ) s.files += %w( src/core/tsi/transport_security.h ) s.files += %w( src/core/tsi/transport_security_adapter.h ) s.files += %w( src/core/tsi/transport_security_interface.h ) - s.files += %w( src/core/ext/transport/chttp2/server/chttp2_server.h ) + s.files += %w( src/core/ext/transport/chttp2/client/chttp2_connector.h ) s.files += %w( src/core/ext/filters/client_channel/backup_poller.h ) s.files += %w( src/core/ext/filters/client_channel/client_channel.h ) s.files += %w( src/core/ext/filters/client_channel/client_channel_factory.h ) @@ -246,7 +272,12 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/client_channel/subchannel_index.h ) s.files += %w( src/core/ext/filters/client_channel/uri_parser.h ) s.files += %w( src/core/ext/filters/deadline/deadline_filter.h ) - s.files += %w( src/core/ext/transport/chttp2/client/chttp2_connector.h ) + s.files += %w( src/core/tsi/alts_transport_security.h ) + s.files += %w( src/core/tsi/fake_transport_security.h ) + s.files += %w( src/core/tsi/ssl_transport_security.h ) + s.files += %w( src/core/tsi/ssl_types.h ) + s.files += %w( src/core/tsi/transport_security_grpc.h ) + s.files += %w( src/core/ext/transport/chttp2/server/chttp2_server.h ) s.files += %w( src/core/ext/transport/inproc/inproc_transport.h ) s.files += %w( src/core/lib/avl/avl.h ) s.files += %w( src/core/lib/backoff/backoff.h ) @@ -381,10 +412,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h ) - s.files += %w( third_party/nanopb/pb.h ) - s.files += %w( third_party/nanopb/pb_common.h ) - s.files += %w( third_party/nanopb/pb_decode.h ) - s.files += %w( third_party/nanopb/pb_encode.h ) s.files += %w( src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/subchannel_list.h ) s.files += %w( src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h ) @@ -561,6 +588,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/http/server/http_server_filter.cc ) s.files += %w( src/core/lib/http/httpcli_security_connector.cc ) s.files += %w( src/core/lib/security/context/security_context.cc ) + s.files += %w( src/core/lib/security/credentials/alts/alts_credentials.cc ) s.files += %w( src/core/lib/security/credentials/composite/composite_credentials.cc ) s.files += %w( src/core/lib/security/credentials/credentials.cc ) s.files += %w( src/core/lib/security/credentials/credentials_metadata.cc ) @@ -574,6 +602,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/security/credentials/oauth2/oauth2_credentials.cc ) s.files += %w( src/core/lib/security/credentials/plugin/plugin_credentials.cc ) s.files += %w( src/core/lib/security/credentials/ssl/ssl_credentials.cc ) + s.files += %w( src/core/lib/security/security_connector/alts_security_connector.cc ) s.files += %w( src/core/lib/security/security_connector/security_connector.cc ) s.files += %w( src/core/lib/security/transport/client_auth_filter.cc ) s.files += %w( src/core/lib/security/transport/secure_endpoint.cc ) @@ -583,14 +612,45 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/security/transport/tsi_error.cc ) s.files += %w( src/core/lib/security/util/json_util.cc ) s.files += %w( src/core/lib/surface/init_secure.cc ) - s.files += %w( src/core/tsi/alts_transport_security.cc ) - s.files += %w( src/core/tsi/fake_transport_security.cc ) - s.files += %w( src/core/tsi/ssl_transport_security.cc ) - s.files += %w( src/core/tsi/transport_security_grpc.cc ) + s.files += %w( src/core/tsi/alts/crypt/aes_gcm.cc ) + s.files += %w( src/core/tsi/alts/crypt/gsec.cc ) + s.files += %w( src/core/tsi/alts/frame_protector/alts_counter.cc ) + s.files += %w( src/core/tsi/alts/frame_protector/alts_crypter.cc ) + s.files += %w( src/core/tsi/alts/frame_protector/alts_frame_protector.cc ) + s.files += %w( src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc ) + s.files += %w( src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc ) + s.files += %w( src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc ) + s.files += %w( src/core/tsi/alts/frame_protector/frame_handler.cc ) + s.files += %w( src/core/tsi/alts/handshaker/alts_handshaker_client.cc ) + s.files += %w( src/core/tsi/alts/handshaker/alts_tsi_event.cc ) + s.files += %w( src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc ) + s.files += %w( src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc ) + s.files += %w( src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc ) + s.files += %w( src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc ) + s.files += %w( src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc ) + s.files += %w( src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc ) + s.files += %w( src/core/lib/security/credentials/alts/check_gcp_environment.cc ) + s.files += %w( src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc ) + s.files += %w( src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc ) + s.files += %w( src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc ) + s.files += %w( src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc ) + s.files += %w( src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc ) + s.files += %w( src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc ) + s.files += %w( src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc ) + s.files += %w( src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc ) + s.files += %w( src/core/tsi/alts/handshaker/alts_tsi_utils.cc ) + s.files += %w( src/core/tsi/alts/handshaker/transport_security_common_api.cc ) + s.files += %w( src/core/tsi/alts/handshaker/altscontext.pb.c ) + s.files += %w( src/core/tsi/alts/handshaker/handshaker.pb.c ) + s.files += %w( src/core/tsi/alts/handshaker/transport_security_common.pb.c ) + s.files += %w( third_party/nanopb/pb_common.c ) + s.files += %w( third_party/nanopb/pb_decode.c ) + s.files += %w( third_party/nanopb/pb_encode.c ) s.files += %w( src/core/tsi/transport_security.cc ) s.files += %w( src/core/tsi/transport_security_adapter.cc ) - s.files += %w( src/core/ext/transport/chttp2/server/chttp2_server.cc ) - s.files += %w( src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc ) + s.files += %w( src/core/ext/transport/chttp2/client/insecure/channel_create.cc ) + s.files += %w( src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc ) + s.files += %w( src/core/ext/transport/chttp2/client/chttp2_connector.cc ) s.files += %w( src/core/ext/filters/client_channel/backup_poller.cc ) s.files += %w( src/core/ext/filters/client_channel/channel_connectivity.cc ) s.files += %w( src/core/ext/filters/client_channel/client_channel.cc ) @@ -614,11 +674,14 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/client_channel/subchannel_index.cc ) s.files += %w( src/core/ext/filters/client_channel/uri_parser.cc ) s.files += %w( src/core/ext/filters/deadline/deadline_filter.cc ) - s.files += %w( src/core/ext/transport/chttp2/client/chttp2_connector.cc ) + s.files += %w( src/core/tsi/alts_transport_security.cc ) + s.files += %w( src/core/tsi/fake_transport_security.cc ) + s.files += %w( src/core/tsi/ssl_transport_security.cc ) + s.files += %w( src/core/tsi/transport_security_grpc.cc ) + s.files += %w( src/core/ext/transport/chttp2/server/chttp2_server.cc ) + s.files += %w( src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc ) s.files += %w( src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc ) s.files += %w( src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc ) - s.files += %w( src/core/ext/transport/chttp2/client/insecure/channel_create.cc ) - s.files += %w( src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc ) s.files += %w( src/core/ext/transport/inproc/inproc_plugin.cc ) s.files += %w( src/core/ext/transport/inproc/inproc_transport.cc ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc ) @@ -627,9 +690,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c ) - s.files += %w( third_party/nanopb/pb_common.c ) - s.files += %w( third_party/nanopb/pb_decode.c ) - s.files += %w( third_party/nanopb/pb_encode.c ) s.files += %w( src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc ) s.files += %w( src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc ) diff --git a/grpc.gyp b/grpc.gyp index 643323945e..0b60efe978 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -64,11 +64,11 @@ ], 'cflags_c': [ '-Werror', - '-std=c99' + '-std=c99', ], 'cflags_cc': [ '-Werror', - '-std=c++11' + '-std=c++11', ], 'include_dirs': [ '.', @@ -148,13 +148,24 @@ '-Wno-deprecated-declarations', '-stdlib=libc++', '-std=c++11', - '-Wno-error=deprecated-declarations' + '-Wno-error=deprecated-declarations', ], }, }] ] }, 'targets': [ + { + 'target_name': 'alts_test_util', + 'type': 'static_library', + 'dependencies': [ + 'grpc', + ], + 'sources': [ + 'test/core/tsi/alts/crypt/gsec_test_util.cc', + 'test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc', + ], + }, { 'target_name': 'gpr', 'type': 'static_library', @@ -385,6 +396,7 @@ 'src/core/ext/filters/http/server/http_server_filter.cc', 'src/core/lib/http/httpcli_security_connector.cc', 'src/core/lib/security/context/security_context.cc', + 'src/core/lib/security/credentials/alts/alts_credentials.cc', 'src/core/lib/security/credentials/composite/composite_credentials.cc', 'src/core/lib/security/credentials/credentials.cc', 'src/core/lib/security/credentials/credentials_metadata.cc', @@ -398,6 +410,7 @@ 'src/core/lib/security/credentials/oauth2/oauth2_credentials.cc', 'src/core/lib/security/credentials/plugin/plugin_credentials.cc', 'src/core/lib/security/credentials/ssl/ssl_credentials.cc', + 'src/core/lib/security/security_connector/alts_security_connector.cc', 'src/core/lib/security/security_connector/security_connector.cc', 'src/core/lib/security/transport/client_auth_filter.cc', 'src/core/lib/security/transport/secure_endpoint.cc', @@ -407,14 +420,45 @@ 'src/core/lib/security/transport/tsi_error.cc', 'src/core/lib/security/util/json_util.cc', 'src/core/lib/surface/init_secure.cc', - 'src/core/tsi/alts_transport_security.cc', - 'src/core/tsi/fake_transport_security.cc', - 'src/core/tsi/ssl_transport_security.cc', - 'src/core/tsi/transport_security_grpc.cc', + 'src/core/tsi/alts/crypt/aes_gcm.cc', + 'src/core/tsi/alts/crypt/gsec.cc', + 'src/core/tsi/alts/frame_protector/alts_counter.cc', + 'src/core/tsi/alts/frame_protector/alts_crypter.cc', + 'src/core/tsi/alts/frame_protector/alts_frame_protector.cc', + 'src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc', + 'src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc', + 'src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc', + 'src/core/tsi/alts/frame_protector/frame_handler.cc', + 'src/core/tsi/alts/handshaker/alts_handshaker_client.cc', + 'src/core/tsi/alts/handshaker/alts_tsi_event.cc', + 'src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc', + 'src/core/lib/security/credentials/alts/check_gcp_environment.cc', + 'src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc', + 'src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc', + 'src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc', + 'src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc', + 'src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc', + 'src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc', + 'src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc', + 'src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc', + 'src/core/tsi/alts/handshaker/alts_tsi_utils.cc', + 'src/core/tsi/alts/handshaker/transport_security_common_api.cc', + 'src/core/tsi/alts/handshaker/altscontext.pb.c', + 'src/core/tsi/alts/handshaker/handshaker.pb.c', + 'src/core/tsi/alts/handshaker/transport_security_common.pb.c', + 'third_party/nanopb/pb_common.c', + 'third_party/nanopb/pb_decode.c', + 'third_party/nanopb/pb_encode.c', 'src/core/tsi/transport_security.cc', 'src/core/tsi/transport_security_adapter.cc', - 'src/core/ext/transport/chttp2/server/chttp2_server.cc', - 'src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc', + 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', + 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', + 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', 'src/core/ext/filters/client_channel/client_channel.cc', @@ -438,11 +482,14 @@ 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', 'src/core/ext/filters/deadline/deadline_filter.cc', - 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', + 'src/core/tsi/alts_transport_security.cc', + 'src/core/tsi/fake_transport_security.cc', + 'src/core/tsi/ssl_transport_security.cc', + 'src/core/tsi/transport_security_grpc.cc', + 'src/core/ext/transport/chttp2/server/chttp2_server.cc', + 'src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc', 'src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc', 'src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc', - 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', - 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', 'src/core/ext/transport/inproc/inproc_plugin.cc', 'src/core/ext/transport/inproc/inproc_transport.cc', 'src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc', @@ -451,9 +498,6 @@ 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc', 'src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc', 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c', - 'third_party/nanopb/pb_common.c', - 'third_party/nanopb/pb_decode.c', - 'third_party/nanopb/pb_encode.c', 'src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc', 'src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc', 'src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc', diff --git a/package.xml b/package.xml index 968ba65bef..fc7ba68e8b 100644 --- a/package.xml +++ b/package.xml @@ -204,6 +204,7 @@ + @@ -215,6 +216,7 @@ + @@ -222,15 +224,39 @@ - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -253,7 +279,12 @@ - + + + + + + @@ -388,10 +419,6 @@ - - - - @@ -568,6 +595,7 @@ + @@ -581,6 +609,7 @@ + @@ -590,14 +619,45 @@ - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + @@ -621,11 +681,14 @@ - + + + + + + - - @@ -634,9 +697,6 @@ - - - diff --git a/setup.py b/setup.py index 4f67f82275..7c07c5614c 100644 --- a/setup.py +++ b/setup.py @@ -118,6 +118,7 @@ if EXTRA_ENV_COMPILE_ARGS is None: EXTRA_ENV_COMPILE_ARGS += ' -std=c++11 -std=gnu99 -fvisibility=hidden -fno-wrapv -fno-exceptions' elif "darwin" in sys.platform: EXTRA_ENV_COMPILE_ARGS += ' -fvisibility=hidden -fno-wrapv -fno-exceptions' +EXTRA_ENV_COMPILE_ARGS += ' -DPB_FIELD_16BIT' if EXTRA_ENV_LINK_ARGS is None: EXTRA_ENV_LINK_ARGS = '' @@ -160,7 +161,7 @@ if "win32" in sys.platform: DEFINE_MACROS = ( ('OPENSSL_NO_ASM', 1), ('_WIN32_WINNT', 0x600), - ('GPR_BACKWARDS_COMPATIBILITY_MODE', 1),) + ('GPR_BACKWARDS_COMPATIBILITY_MODE', 1)) if "win32" in sys.platform: # TODO(zyc): Re-enble c-ares on x64 and x86 windows after fixing the # ares_library_init compilation issue diff --git a/src/core/lib/security/credentials/alts/alts_credentials.cc b/src/core/lib/security/credentials/alts/alts_credentials.cc new file mode 100644 index 0000000000..fa05d901bf --- /dev/null +++ b/src/core/lib/security/credentials/alts/alts_credentials.cc @@ -0,0 +1,119 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/lib/security/credentials/alts/alts_credentials.h" + +#include + +#include +#include +#include +#include + +#include "src/core/lib/security/credentials/alts/check_gcp_environment.h" +#include "src/core/lib/security/security_connector/alts_security_connector.h" + +#define GRPC_CREDENTIALS_TYPE_ALTS "Alts" +#define GRPC_ALTS_HANDSHAKER_SERVICE_URL "metadata.google.internal:8080" + +static void alts_credentials_destruct(grpc_channel_credentials* creds) { + grpc_alts_credentials* alts_creds = + reinterpret_cast(creds); + grpc_alts_credentials_options_destroy(alts_creds->options); + gpr_free(alts_creds->handshaker_service_url); +} + +static void alts_server_credentials_destruct(grpc_server_credentials* creds) { + grpc_alts_server_credentials* alts_creds = + reinterpret_cast(creds); + grpc_alts_credentials_options_destroy(alts_creds->options); + gpr_free(alts_creds->handshaker_service_url); +} + +static grpc_security_status alts_create_security_connector( + grpc_channel_credentials* creds, + grpc_call_credentials* request_metadata_creds, const char* target_name, + const grpc_channel_args* args, grpc_channel_security_connector** sc, + grpc_channel_args** new_args) { + return grpc_alts_channel_security_connector_create( + creds, request_metadata_creds, target_name, sc); +} + +static grpc_security_status alts_server_create_security_connector( + grpc_server_credentials* creds, grpc_server_security_connector** sc) { + return grpc_alts_server_security_connector_create(creds, sc); +} + +static const grpc_channel_credentials_vtable alts_credentials_vtable = { + alts_credentials_destruct, alts_create_security_connector, + /*duplicate_without_call_credentials=*/nullptr}; + +static const grpc_server_credentials_vtable alts_server_credentials_vtable = { + alts_server_credentials_destruct, alts_server_create_security_connector}; + +grpc_channel_credentials* grpc_alts_credentials_create_customized( + const grpc_alts_credentials_options* options, + const char* handshaker_service_url, bool enable_untrusted_alts) { + if (!enable_untrusted_alts && !grpc_alts_is_running_on_gcp()) { + return nullptr; + } + auto creds = static_cast( + gpr_zalloc(sizeof(grpc_alts_credentials))); + creds->options = grpc_alts_credentials_options_copy(options); + creds->handshaker_service_url = + handshaker_service_url == nullptr + ? gpr_strdup(GRPC_ALTS_HANDSHAKER_SERVICE_URL) + : gpr_strdup(handshaker_service_url); + creds->base.type = GRPC_CREDENTIALS_TYPE_ALTS; + creds->base.vtable = &alts_credentials_vtable; + gpr_ref_init(&creds->base.refcount, 1); + return &creds->base; +} + +grpc_server_credentials* grpc_alts_server_credentials_create_customized( + const grpc_alts_credentials_options* options, + const char* handshaker_service_url, bool enable_untrusted_alts) { + if (!enable_untrusted_alts && !grpc_alts_is_running_on_gcp()) { + return nullptr; + } + auto creds = static_cast( + gpr_zalloc(sizeof(grpc_alts_server_credentials))); + creds->options = grpc_alts_credentials_options_copy(options); + creds->handshaker_service_url = + handshaker_service_url == nullptr + ? gpr_strdup(GRPC_ALTS_HANDSHAKER_SERVICE_URL) + : gpr_strdup(handshaker_service_url); + creds->base.type = GRPC_CREDENTIALS_TYPE_ALTS; + creds->base.vtable = &alts_server_credentials_vtable; + gpr_ref_init(&creds->base.refcount, 1); + return &creds->base; +} + +grpc_channel_credentials* grpc_alts_credentials_create( + const grpc_alts_credentials_options* options) { + return grpc_alts_credentials_create_customized( + options, GRPC_ALTS_HANDSHAKER_SERVICE_URL, false); +} + +grpc_server_credentials* grpc_alts_server_credentials_create( + const grpc_alts_credentials_options* options) { + return grpc_alts_server_credentials_create_customized( + options, GRPC_ALTS_HANDSHAKER_SERVICE_URL, false); +} diff --git a/src/core/lib/security/credentials/alts/alts_credentials.h b/src/core/lib/security/credentials/alts/alts_credentials.h new file mode 100644 index 0000000000..621789cf65 --- /dev/null +++ b/src/core/lib/security/credentials/alts/alts_credentials.h @@ -0,0 +1,102 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_LIB_SECURITY_CREDENTIALS_ALTS_ALTS_CREDENTIALS_H +#define GRPC_CORE_LIB_SECURITY_CREDENTIALS_ALTS_ALTS_CREDENTIALS_H + +#include + +#include + +#include "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h" +#include "src/core/lib/security/credentials/credentials.h" + +/* Main struct for grpc ALTS channel credential. */ +typedef struct grpc_alts_credentials { + grpc_channel_credentials base; + grpc_alts_credentials_options* options; + char* handshaker_service_url; +} grpc_alts_credentials; + +/* Main struct for grpc ALTS server credential. */ +typedef struct grpc_alts_server_credentials { + grpc_server_credentials base; + grpc_alts_credentials_options* options; + char* handshaker_service_url; +} grpc_alts_server_credentials; + +/** + * This method creates an ALTS channel credential object. + * + * - options: grpc ALTS credentials options instance for client. + * + * It returns the created ALTS channel credential object. + */ +grpc_channel_credentials* grpc_alts_credentials_create( + const grpc_alts_credentials_options* options); + +/** + * This method creates an ALTS server credential object. + * + * - options: grpc ALTS credentials options instance for server. + * + * It returns the created ALTS server credential object. + */ +grpc_server_credentials* grpc_alts_server_credentials_create( + const grpc_alts_credentials_options* options); + +/** + * This method creates an ALTS channel credential object with customized + * information provided by caller. + * + * - options: grpc ALTS credentials options instance for client. + * - handshaker_service_url: address of ALTS handshaker service in the format of + * "host:port". If it's nullptr, the address of default metadata server will + * be used. + * - enable_untrusted_alts: a boolean flag used to enable ALTS in untrusted + * mode. This mode can be enabled when we are sure ALTS is running on GCP or + * for testing purpose. + * + * It returns nullptr if the flag is disabled AND ALTS is not running on GCP. + * Otherwise, it returns the created credential object. + */ + +grpc_channel_credentials* grpc_alts_credentials_create_customized( + const grpc_alts_credentials_options* options, + const char* handshaker_service_url, bool enable_untrusted_alts); + +/** + * This method creates an ALTS server credential object with customized + * information provided by caller. + * + * - options: grpc ALTS credentials options instance for server. + * - handshaker_service_url: address of ALTS handshaker service in the format of + * "host:port". If it's nullptr, the address of default metadata server will + * be used. + * - enable_untrusted_alts: a boolean flag used to enable ALTS in untrusted + * mode. This mode can be enabled when we are sure ALTS is running on GCP or + * for testing purpose. + * + * It returns nullptr if the flag is disabled and ALTS is not running on GCP. + * Otherwise, it returns the created credential object. + */ +grpc_server_credentials* grpc_alts_server_credentials_create_customized( + const grpc_alts_credentials_options* options, + const char* handshaker_service_url, bool enable_untrusted_alts); + +#endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_ALTS_ALTS_CREDENTIALS_H */ diff --git a/src/core/lib/security/credentials/alts/check_gcp_environment.cc b/src/core/lib/security/credentials/alts/check_gcp_environment.cc new file mode 100644 index 0000000000..96807876cf --- /dev/null +++ b/src/core/lib/security/credentials/alts/check_gcp_environment.cc @@ -0,0 +1,72 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/lib/security/credentials/alts/check_gcp_environment.h" + +#include +#include +#include + +#include +#include + +const size_t kBiosDataBufferSize = 256; + +static char* trim(const char* src) { + if (src == nullptr) { + return nullptr; + } + char* des = nullptr; + size_t start = 0, end = strlen(src) - 1; + /* find the last character that is not a whitespace. */ + while (end != 0 && isspace(src[end])) { + end--; + } + /* find the first character that is not a whitespace. */ + while (start < strlen(src) && isspace(src[start])) { + start++; + } + if (start <= end) { + des = static_cast( + gpr_zalloc(sizeof(char) * (end - start + 2 /* '\0' */))); + memcpy(des, src + start, end - start + 1); + } + return des; +} + +namespace grpc_core { +namespace internal { + +char* read_bios_file(const char* bios_file) { + FILE* fp = fopen(bios_file, "r"); + if (!fp) { + gpr_log(GPR_ERROR, "BIOS data file cannot be opened."); + return nullptr; + } + char buf[kBiosDataBufferSize + 1]; + size_t ret = fread(buf, sizeof(char), kBiosDataBufferSize, fp); + buf[ret] = '\0'; + char* trimmed_buf = trim(buf); + fclose(fp); + return trimmed_buf; +} + +} // namespace internal +} // namespace grpc_core diff --git a/src/core/lib/security/credentials/alts/check_gcp_environment.h b/src/core/lib/security/credentials/alts/check_gcp_environment.h new file mode 100644 index 0000000000..aea4cea643 --- /dev/null +++ b/src/core/lib/security/credentials/alts/check_gcp_environment.h @@ -0,0 +1,57 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_LIB_SECURITY_CREDENTIALS_ALTS_CHECK_GCP_ENVIRONMENT_H +#define GRPC_CORE_LIB_SECURITY_CREDENTIALS_ALTS_CHECK_GCP_ENVIRONMENT_H + +namespace grpc_core { +namespace internal { + +/** + * This method is a helper function that reads a file containing system bios + * data. Exposed for testing only. + * + * - bios_file: a file containing BIOS data used to determine GCE tenancy + * information. + * + * It returns a buffer containing the data read from the file. + */ +char* read_bios_file(const char* bios_file); + +/** + * This method checks if system BIOS data contains Google-specific phrases. + * Exposed for testing only. + * + * - bios_data: a buffer containing system BIOS data. + * + * It returns true if the BIOS data contains Google-specific phrases, and false + * otherwise. + */ +bool check_bios_data(const char* bios_data); + +} // namespace internal +} // namespace grpc_core + +/** + * This method checks if a VM (Windows or Linux) is running within Google + * compute Engine (GCE) or not. It returns true if the VM is running in GCE and + * false otherwise. + */ +bool grpc_alts_is_running_on_gcp(); + +#endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_ALTS_CHECK_GCP_ENVIRONMENT_H */ diff --git a/src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc b/src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc new file mode 100644 index 0000000000..7c4d7a71cd --- /dev/null +++ b/src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc @@ -0,0 +1,67 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#ifdef GPR_LINUX + +#include "src/core/lib/security/credentials/alts/check_gcp_environment.h" + +#include +#include + +#include + +#define GRPC_ALTS_EXPECT_NAME_GOOGLE "Google" +#define GRPC_ALTS_EXPECT_NAME_GCE "Google Compute Engine" +#define GRPC_ALTS_PRODUCT_NAME_FILE "/sys/class/dmi/id/product_name" + +static bool g_compute_engine_detection_done = false; +static bool g_is_on_compute_engine = false; +static gpr_mu g_mu; +static gpr_once g_once = GPR_ONCE_INIT; + +namespace grpc_core { +namespace internal { + +bool check_bios_data(const char* bios_data_file) { + char* bios_data = read_bios_file(bios_data_file); + bool result = (!strcmp(bios_data, GRPC_ALTS_EXPECT_NAME_GOOGLE)) || + (!strcmp(bios_data, GRPC_ALTS_EXPECT_NAME_GCE)); + gpr_free(bios_data); + return result; +} + +} // namespace internal +} // namespace grpc_core + +static void init_mu(void) { gpr_mu_init(&g_mu); } + +bool grpc_alts_is_running_on_gcp() { + gpr_once_init(&g_once, init_mu); + gpr_mu_lock(&g_mu); + if (!g_compute_engine_detection_done) { + g_is_on_compute_engine = + grpc_core::internal::check_bios_data(GRPC_ALTS_PRODUCT_NAME_FILE); + g_compute_engine_detection_done = true; + } + gpr_mu_unlock(&g_mu); + return g_is_on_compute_engine; +} + +#endif // GPR_LINUX diff --git a/src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc b/src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc new file mode 100644 index 0000000000..d97681b86d --- /dev/null +++ b/src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc @@ -0,0 +1,33 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#if !defined(GPR_LINUX) && !defined(GPR_WINDOWS) + +#include "src/core/lib/security/credentials/alts/check_gcp_environment.h" + +#include + +bool grpc_alts_is_running_on_gcp() { + gpr_log(GPR_ERROR, + "Platforms other than Linux and Windows are not supported"); + return false; +} + +#endif // !defined(LINUX) && !defined(GPR_WINDOWS) diff --git a/src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc b/src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc new file mode 100644 index 0000000000..55efe0e9dd --- /dev/null +++ b/src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc @@ -0,0 +1,114 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#ifdef GPR_WINDOWS + +#include "src/core/lib/security/credentials/alts/check_gcp_environment.h" + +#include +#include +#include +#include + +#include +#include +#include + +#define GRPC_ALTS_EXPECT_NAME_GOOGLE "Google" +#define GRPC_ALTS_WINDOWS_CHECK_COMMAND "powershell.exe" +#define GRPC_ALTS_WINDOWS_CHECK_COMMAND_ARGS \ + "(Get-WmiObject -Class Win32_BIOS).Manufacturer" +#define GRPC_ALTS_WINDOWS_CHECK_BIOS_FILE "windows_bios.data" + +const size_t kBiosDataBufferSize = 256; + +static bool g_compute_engine_detection_done = false; +static bool g_is_on_compute_engine = false; +static gpr_mu g_mu; +static gpr_once g_once = GPR_ONCE_INIT; + +namespace grpc_core { +namespace internal { + +bool check_bios_data(const char* bios_data_file) { + char* bios_data = read_bios_file(bios_data_file); + bool result = !strcmp(bios_data, GRPC_ALTS_EXPECT_NAME_GOOGLE); + remove(GRPC_ALTS_WINDOWS_CHECK_BIOS_FILE); + gpr_free(bios_data); + return result; +} + +} // namespace internal +} // namespace grpc_core + +static void init_mu(void) { gpr_mu_init(&g_mu); } + +static bool run_powershell() { + SECURITY_ATTRIBUTES sa; + sa.nLength = sizeof(sa); + sa.lpSecurityDescriptor = NULL; + sa.bInheritHandle = TRUE; + HANDLE h = CreateFile(_T(GRPC_ALTS_WINDOWS_CHECK_BIOS_FILE), GENERIC_WRITE, + FILE_SHARE_WRITE | FILE_SHARE_READ, &sa, OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, NULL); + if (h == INVALID_HANDLE_VALUE) { + gpr_log(GPR_ERROR, "CreateFile failed (%d).", GetLastError()); + return false; + } + PROCESS_INFORMATION pi; + STARTUPINFO si; + DWORD flags = CREATE_NO_WINDOW; + ZeroMemory(&pi, sizeof(pi)); + ZeroMemory(&si, sizeof(si)); + si.cb = sizeof(si); + si.dwFlags |= STARTF_USESTDHANDLES; + si.hStdInput = NULL; + si.hStdError = h; + si.hStdOutput = h; + TCHAR cmd[kBiosDataBufferSize]; + _sntprintf(cmd, kBiosDataBufferSize, _T("%s %s"), + _T(GRPC_ALTS_WINDOWS_CHECK_COMMAND), + _T(GRPC_ALTS_WINDOWS_CHECK_COMMAND_ARGS)); + if (!CreateProcess(NULL, cmd, NULL, NULL, TRUE, flags, NULL, NULL, &si, + &pi)) { + gpr_log(GPR_ERROR, "CreateProcess failed (%d).\n", GetLastError()); + return false; + } + WaitForSingleObject(pi.hProcess, INFINITE); + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + CloseHandle(h); + return true; +} + +bool grpc_alts_is_running_on_gcp() { + gpr_once_init(&g_once, init_mu); + gpr_mu_lock(&g_mu); + if (!g_compute_engine_detection_done) { + g_is_on_compute_engine = + run_powershell() && + grpc_core::internal::check_bios_data(GRPC_ALTS_WINDOWS_CHECK_BIOS_FILE); + g_compute_engine_detection_done = true; + } + gpr_mu_unlock(&g_mu); + return g_is_on_compute_engine; +} + +#endif // GPR_WINDOWS diff --git a/src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc b/src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc new file mode 100644 index 0000000000..7d54e8346f --- /dev/null +++ b/src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc @@ -0,0 +1,126 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include +#include + +#include +#include +#include + +#include "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h" +#include "src/core/tsi/alts/handshaker/transport_security_common_api.h" + +static grpc_alts_credentials_options* alts_client_options_copy( + const grpc_alts_credentials_options* options); + +static void alts_client_options_destroy(grpc_alts_credentials_options* options); + +static target_service_account* target_service_account_create( + const char* service_account) { + if (service_account == nullptr) { + return nullptr; + } + auto* sa = static_cast( + gpr_zalloc(sizeof(target_service_account))); + sa->data = gpr_strdup(service_account); + return sa; +} + +bool grpc_alts_credentials_client_options_add_target_service_account( + grpc_alts_credentials_client_options* options, + const char* service_account) { + if (options == nullptr || service_account == nullptr) { + gpr_log( + GPR_ERROR, + "Invalid nullptr arguments to " + "grpc_alts_credentials_client_options_add_target_service_account()"); + return false; + } + target_service_account* node = target_service_account_create(service_account); + node->next = options->target_account_list_head; + options->target_account_list_head = node; + return true; +} + +static void target_service_account_destroy( + target_service_account* service_account) { + if (service_account == nullptr) { + return; + } + gpr_free(service_account->data); + gpr_free(service_account); +} + +static const grpc_alts_credentials_options_vtable vtable = { + alts_client_options_copy, alts_client_options_destroy}; + +grpc_alts_credentials_options* grpc_alts_credentials_client_options_create() { + auto client_options = static_cast( + gpr_zalloc(sizeof(grpc_alts_credentials_client_options))); + client_options->base.vtable = &vtable; + return &client_options->base; +} + +static grpc_alts_credentials_options* alts_client_options_copy( + const grpc_alts_credentials_options* options) { + if (options == nullptr) { + return nullptr; + } + grpc_alts_credentials_options* new_options = + grpc_alts_credentials_client_options_create(); + auto new_client_options = + reinterpret_cast(new_options); + /* Copy target service accounts. */ + target_service_account* prev = nullptr; + auto node = + (reinterpret_cast(options)) + ->target_account_list_head; + while (node != nullptr) { + target_service_account* new_node = + target_service_account_create(node->data); + if (prev == nullptr) { + new_client_options->target_account_list_head = new_node; + } else { + prev->next = new_node; + } + prev = new_node; + node = node->next; + } + /* Copy rpc protocol versions. */ + grpc_gcp_rpc_protocol_versions_copy(&options->rpc_versions, + &new_options->rpc_versions); + return new_options; +} + +static void alts_client_options_destroy( + grpc_alts_credentials_options* options) { + if (options == nullptr) { + return; + } + auto* client_options = + reinterpret_cast(options); + target_service_account* node = client_options->target_account_list_head; + while (node != nullptr) { + target_service_account* next_node = node->next; + target_service_account_destroy(node); + node = next_node; + } +} diff --git a/src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc b/src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc new file mode 100644 index 0000000000..d428171540 --- /dev/null +++ b/src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc @@ -0,0 +1,46 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h" + +#include +#include + +grpc_alts_credentials_options* grpc_alts_credentials_options_copy( + const grpc_alts_credentials_options* options) { + if (options != nullptr && options->vtable != nullptr && + options->vtable->copy != nullptr) { + return options->vtable->copy(options); + } + /* An error occurred. */ + gpr_log(GPR_ERROR, + "Invalid arguments to grpc_alts_credentials_options_copy()"); + return nullptr; +} + +void grpc_alts_credentials_options_destroy( + grpc_alts_credentials_options* options) { + if (options != nullptr) { + if (options->vtable != nullptr && options->vtable->destruct != nullptr) { + options->vtable->destruct(options); + } + gpr_free(options); + } +} diff --git a/src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h b/src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h new file mode 100644 index 0000000000..4e46d9f2de --- /dev/null +++ b/src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h @@ -0,0 +1,112 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_LIB_SECURITY_CREDENTIALS_ALTS_GRPC_ALTS_CREDENTIALS_OPTIONS_H +#define GRPC_CORE_LIB_SECURITY_CREDENTIALS_ALTS_GRPC_ALTS_CREDENTIALS_OPTIONS_H + +#include + +#include + +#include "src/core/tsi/alts/handshaker/transport_security_common_api.h" + +/** + * Main interface for ALTS credentials options. The options will contain + * information that will be passed from grpc to TSI layer such as RPC protocol + * versions. ALTS client (channel) and server credentials will have their own + * implementation of this interface. The APIs listed in this header are + * thread-compatible. + */ +typedef struct grpc_alts_credentials_options grpc_alts_credentials_options; + +/* V-table for grpc_alts_credentials_options */ +typedef struct grpc_alts_credentials_options_vtable { + grpc_alts_credentials_options* (*copy)( + const grpc_alts_credentials_options* options); + void (*destruct)(grpc_alts_credentials_options* options); +} grpc_alts_credentials_options_vtable; + +struct grpc_alts_credentials_options { + const struct grpc_alts_credentials_options_vtable* vtable; + grpc_gcp_rpc_protocol_versions rpc_versions; +}; + +typedef struct target_service_account { + struct target_service_account* next; + char* data; +} target_service_account; + +/** + * Main struct for ALTS client credentials options. The options contain a + * a list of target service accounts (if specified) used for secure naming + * check. + */ +typedef struct grpc_alts_credentials_client_options { + grpc_alts_credentials_options base; + target_service_account* target_account_list_head; +} grpc_alts_credentials_client_options; + +/** + * Main struct for ALTS server credentials options. The options currently + * do not contain any server-specific fields. + */ +typedef struct grpc_alts_credentials_server_options { + grpc_alts_credentials_options base; +} grpc_alts_credentials_server_options; + +/** + * This method performs a deep copy on grpc_alts_credentials_options instance. + * + * - options: a grpc_alts_credentials_options instance that needs to be copied. + * + * It returns a new grpc_alts_credentials_options instance on success and NULL + * on failure. + */ +grpc_alts_credentials_options* grpc_alts_credentials_options_copy( + const grpc_alts_credentials_options* options); + +/** + * This method destroys a grpc_alts_credentials_options instance by + * de-allocating all of its occupied memory. + * + * - options: a grpc_alts_credentials_options instance that needs to be + * destroyed. + */ +void grpc_alts_credentials_options_destroy( + grpc_alts_credentials_options* options); + +/* This method creates a grpc ALTS credentials client options instance. */ +grpc_alts_credentials_options* grpc_alts_credentials_client_options_create(); + +/* This method creates a grpc ALTS credentials server options instance. */ +grpc_alts_credentials_options* grpc_alts_credentials_server_options_create(); + +/** + * This method adds a target service account to grpc ALTS credentials client + * options instance. + * + * - options: grpc ALTS credentials client options instance. + * - service_account: service account of target endpoint. + * + * It returns true on success and false on failure. + */ +bool grpc_alts_credentials_client_options_add_target_service_account( + grpc_alts_credentials_client_options* options, const char* service_account); + +#endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_ALTS_GRPC_ALTS_CREDENTIALS_OPTIONS_H \ + */ diff --git a/src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc b/src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc new file mode 100644 index 0000000000..62aa7a620a --- /dev/null +++ b/src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc @@ -0,0 +1,58 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include +#include + +#include +#include + +#include "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h" +#include "src/core/tsi/alts/handshaker/transport_security_common_api.h" + +static grpc_alts_credentials_options* alts_server_options_copy( + const grpc_alts_credentials_options* options); + +static void alts_server_options_destroy( + grpc_alts_credentials_options* options) {} + +static const grpc_alts_credentials_options_vtable vtable = { + alts_server_options_copy, alts_server_options_destroy}; + +grpc_alts_credentials_options* grpc_alts_credentials_server_options_create() { + grpc_alts_credentials_server_options* server_options = + static_cast( + gpr_zalloc(sizeof(*server_options))); + server_options->base.vtable = &vtable; + return &server_options->base; +} + +static grpc_alts_credentials_options* alts_server_options_copy( + const grpc_alts_credentials_options* options) { + if (options == nullptr) { + return nullptr; + } + grpc_alts_credentials_options* new_options = + grpc_alts_credentials_server_options_create(); + /* Copy rpc protocol versions. */ + grpc_gcp_rpc_protocol_versions_copy(&options->rpc_versions, + &new_options->rpc_versions); + return new_options; +} diff --git a/src/core/lib/security/security_connector/alts_security_connector.cc b/src/core/lib/security/security_connector/alts_security_connector.cc new file mode 100644 index 0000000000..5ff7d7938b --- /dev/null +++ b/src/core/lib/security/security_connector/alts_security_connector.cc @@ -0,0 +1,287 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/lib/security/security_connector/alts_security_connector.h" + +#include +#include + +#include +#include +#include +#include + +#include "src/core/lib/security/credentials/alts/alts_credentials.h" +#include "src/core/lib/security/transport/security_handshaker.h" +#include "src/core/lib/transport/transport.h" +#include "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h" + +typedef struct { + grpc_channel_security_connector base; + char* target_name; +} grpc_alts_channel_security_connector; + +typedef struct { + grpc_server_security_connector base; +} grpc_alts_server_security_connector; + +static void alts_channel_destroy(grpc_security_connector* sc) { + if (sc == nullptr) { + return; + } + auto c = reinterpret_cast(sc); + grpc_call_credentials_unref(c->base.request_metadata_creds); + grpc_channel_credentials_unref(c->base.channel_creds); + gpr_free(c->target_name); + gpr_free(sc); +} + +static void alts_server_destroy(grpc_security_connector* sc) { + if (sc == nullptr) { + return; + } + auto c = reinterpret_cast(sc); + grpc_server_credentials_unref(c->base.server_creds); + gpr_free(sc); +} + +static void alts_channel_add_handshakers( + grpc_channel_security_connector* sc, + grpc_handshake_manager* handshake_manager) { + tsi_handshaker* handshaker = nullptr; + auto c = reinterpret_cast(sc); + grpc_alts_credentials* creds = + reinterpret_cast(c->base.channel_creds); + GPR_ASSERT(alts_tsi_handshaker_create(creds->options, c->target_name, + creds->handshaker_service_url, true, + &handshaker) == TSI_OK); + grpc_handshake_manager_add(handshake_manager, grpc_security_handshaker_create( + handshaker, &sc->base)); +} + +static void alts_server_add_handshakers( + grpc_server_security_connector* sc, + grpc_handshake_manager* handshake_manager) { + tsi_handshaker* handshaker = nullptr; + auto c = reinterpret_cast(sc); + grpc_alts_server_credentials* creds = + reinterpret_cast(c->base.server_creds); + GPR_ASSERT(alts_tsi_handshaker_create(creds->options, nullptr, + creds->handshaker_service_url, false, + &handshaker) == TSI_OK); + grpc_handshake_manager_add(handshake_manager, grpc_security_handshaker_create( + handshaker, &sc->base)); +} + +static void alts_set_rpc_protocol_versions( + grpc_gcp_rpc_protocol_versions* rpc_versions) { + grpc_gcp_rpc_protocol_versions_set_max(rpc_versions, + GRPC_PROTOCOL_VERSION_MAX_MAJOR, + GRPC_PROTOCOL_VERSION_MAX_MINOR); + grpc_gcp_rpc_protocol_versions_set_min(rpc_versions, + GRPC_PROTOCOL_VERSION_MIN_MAJOR, + GRPC_PROTOCOL_VERSION_MIN_MINOR); +} + +namespace grpc_core { +namespace internal { + +grpc_security_status grpc_alts_auth_context_from_tsi_peer( + const tsi_peer* peer, grpc_auth_context** ctx) { + if (peer == nullptr || ctx == nullptr) { + gpr_log(GPR_ERROR, + "Invalid arguments to grpc_alts_auth_context_from_tsi_peer()"); + return GRPC_SECURITY_ERROR; + } + *ctx = nullptr; + /* Validate certificate type. */ + const tsi_peer_property* cert_type_prop = + tsi_peer_get_property_by_name(peer, TSI_CERTIFICATE_TYPE_PEER_PROPERTY); + if (cert_type_prop == nullptr || + strncmp(cert_type_prop->value.data, TSI_ALTS_CERTIFICATE_TYPE, + cert_type_prop->value.length) != 0) { + gpr_log(GPR_ERROR, "Invalid or missing certificate type property."); + return GRPC_SECURITY_ERROR; + } + /* Validate RPC protocol versions. */ + const tsi_peer_property* rpc_versions_prop = + tsi_peer_get_property_by_name(peer, TSI_ALTS_RPC_VERSIONS); + if (rpc_versions_prop == nullptr) { + gpr_log(GPR_ERROR, "Missing rpc protocol versions property."); + return GRPC_SECURITY_ERROR; + } + grpc_gcp_rpc_protocol_versions local_versions, peer_versions; + alts_set_rpc_protocol_versions(&local_versions); + grpc_slice slice = grpc_slice_from_copied_buffer( + rpc_versions_prop->value.data, rpc_versions_prop->value.length); + bool decode_result = + grpc_gcp_rpc_protocol_versions_decode(slice, &peer_versions); + grpc_slice_unref(slice); + if (!decode_result) { + gpr_log(GPR_ERROR, "Invalid peer rpc protocol versions."); + return GRPC_SECURITY_ERROR; + } + /* TODO: Pass highest common rpc protocol version to grpc caller. */ + bool check_result = grpc_gcp_rpc_protocol_versions_check( + &local_versions, &peer_versions, nullptr); + if (!check_result) { + gpr_log(GPR_ERROR, "Mismatch of local and peer rpc protocol versions."); + return GRPC_SECURITY_ERROR; + } + /* Create auth context. */ + *ctx = grpc_auth_context_create(nullptr); + grpc_auth_context_add_cstring_property( + *ctx, GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME, + GRPC_ALTS_TRANSPORT_SECURITY_TYPE); + size_t i = 0; + for (i = 0; i < peer->property_count; i++) { + const tsi_peer_property* tsi_prop = &peer->properties[i]; + /* Add service account to auth context. */ + if (strcmp(tsi_prop->name, TSI_ALTS_SERVICE_ACCOUNT_PEER_PROPERTY) == 0) { + grpc_auth_context_add_property( + *ctx, TSI_ALTS_SERVICE_ACCOUNT_PEER_PROPERTY, tsi_prop->value.data, + tsi_prop->value.length); + GPR_ASSERT(grpc_auth_context_set_peer_identity_property_name( + *ctx, TSI_ALTS_SERVICE_ACCOUNT_PEER_PROPERTY) == 1); + } + } + if (!grpc_auth_context_peer_is_authenticated(*ctx)) { + gpr_log(GPR_ERROR, "Invalid unauthenticated peer."); + GRPC_AUTH_CONTEXT_UNREF(*ctx, "test"); + *ctx = nullptr; + return GRPC_SECURITY_ERROR; + } + return GRPC_SECURITY_OK; +} + +} // namespace internal +} // namespace grpc_core + +static void alts_check_peer(grpc_security_connector* sc, tsi_peer peer, + grpc_auth_context** auth_context, + grpc_closure* on_peer_checked) { + grpc_security_status status; + status = grpc_core::internal::grpc_alts_auth_context_from_tsi_peer( + &peer, auth_context); + tsi_peer_destruct(&peer); + grpc_error* error = + status == GRPC_SECURITY_OK + ? GRPC_ERROR_NONE + : GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "Could not get ALTS auth context from TSI peer"); + GRPC_CLOSURE_SCHED(on_peer_checked, error); +} + +static int alts_channel_cmp(grpc_security_connector* sc1, + grpc_security_connector* sc2) { + grpc_alts_channel_security_connector* c1 = + reinterpret_cast(sc1); + grpc_alts_channel_security_connector* c2 = + reinterpret_cast(sc2); + int c = grpc_channel_security_connector_cmp(&c1->base, &c2->base); + if (c != 0) return c; + return strcmp(c1->target_name, c2->target_name); +} + +static int alts_server_cmp(grpc_security_connector* sc1, + grpc_security_connector* sc2) { + grpc_alts_server_security_connector* c1 = + reinterpret_cast(sc1); + grpc_alts_server_security_connector* c2 = + reinterpret_cast(sc2); + return grpc_server_security_connector_cmp(&c1->base, &c2->base); +} + +static grpc_security_connector_vtable alts_channel_vtable = { + alts_channel_destroy, alts_check_peer, alts_channel_cmp}; + +static grpc_security_connector_vtable alts_server_vtable = { + alts_server_destroy, alts_check_peer, alts_server_cmp}; + +static bool alts_check_call_host(grpc_channel_security_connector* sc, + const char* host, + grpc_auth_context* auth_context, + grpc_closure* on_call_host_checked, + grpc_error** error) { + grpc_alts_channel_security_connector* alts_sc = + reinterpret_cast(sc); + if (host == nullptr || alts_sc == nullptr || + strcmp(host, alts_sc->target_name) != 0) { + *error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "ALTS call host does not match target name"); + } + return true; +} + +static void alts_cancel_check_call_host(grpc_channel_security_connector* sc, + grpc_closure* on_call_host_checked, + grpc_error* error) { + GRPC_ERROR_UNREF(error); +} + +grpc_security_status grpc_alts_channel_security_connector_create( + grpc_channel_credentials* channel_creds, + grpc_call_credentials* request_metadata_creds, const char* target_name, + grpc_channel_security_connector** sc) { + if (channel_creds == nullptr || sc == nullptr || target_name == nullptr) { + gpr_log( + GPR_ERROR, + "Invalid arguments to grpc_alts_channel_security_connector_create()"); + return GRPC_SECURITY_ERROR; + } + auto c = static_cast( + gpr_zalloc(sizeof(grpc_alts_channel_security_connector))); + gpr_ref_init(&c->base.base.refcount, 1); + c->base.base.vtable = &alts_channel_vtable; + c->base.add_handshakers = alts_channel_add_handshakers; + c->base.channel_creds = grpc_channel_credentials_ref(channel_creds); + c->base.request_metadata_creds = + grpc_call_credentials_ref(request_metadata_creds); + c->base.check_call_host = alts_check_call_host; + c->base.cancel_check_call_host = alts_cancel_check_call_host; + grpc_alts_credentials* creds = + reinterpret_cast(c->base.channel_creds); + alts_set_rpc_protocol_versions(&creds->options->rpc_versions); + c->target_name = gpr_strdup(target_name); + *sc = &c->base; + return GRPC_SECURITY_OK; +} + +grpc_security_status grpc_alts_server_security_connector_create( + grpc_server_credentials* server_creds, + grpc_server_security_connector** sc) { + if (server_creds == nullptr || sc == nullptr) { + gpr_log( + GPR_ERROR, + "Invalid arguments to grpc_alts_server_security_connector_create()"); + return GRPC_SECURITY_ERROR; + } + auto c = static_cast( + gpr_zalloc(sizeof(grpc_alts_server_security_connector))); + gpr_ref_init(&c->base.base.refcount, 1); + c->base.base.vtable = &alts_server_vtable; + c->base.server_creds = grpc_server_credentials_ref(server_creds); + c->base.add_handshakers = alts_server_add_handshakers; + grpc_alts_server_credentials* creds = + reinterpret_cast(c->base.server_creds); + alts_set_rpc_protocol_versions(&creds->options->rpc_versions); + *sc = &c->base; + return GRPC_SECURITY_OK; +} diff --git a/src/core/lib/security/security_connector/alts_security_connector.h b/src/core/lib/security/security_connector/alts_security_connector.h new file mode 100644 index 0000000000..e7e4cffe2a --- /dev/null +++ b/src/core/lib/security/security_connector/alts_security_connector.h @@ -0,0 +1,69 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_LIB_SECURITY_SECURITY_CONNECTOR_ALTS_SECURITY_CONNECTOR_H +#define GRPC_CORE_LIB_SECURITY_SECURITY_CONNECTOR_ALTS_SECURITY_CONNECTOR_H + +#include + +#include "src/core/lib/security/context/security_context.h" +#include "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h" + +#define GRPC_ALTS_TRANSPORT_SECURITY_TYPE "alts" + +/** + * This method creates an ALTS channel security connector. + * + * - channel_creds: channel credential instance. + * - request_metadata_creds: credential object which will be sent with each + * request. This parameter can be nullptr. + * - target_name: the name of the endpoint that the channel is connecting to. + * - sc: address of ALTS channel security connector instance to be returned from + * the method. + * + * It returns GRPC_SECURITY_OK on success, and an error stauts code on failure. + */ +grpc_security_status grpc_alts_channel_security_connector_create( + grpc_channel_credentials* channel_creds, + grpc_call_credentials* request_metadata_creds, const char* target_name, + grpc_channel_security_connector** sc); + +/** + * This method creates an ALTS server security connector. + * + * - server_creds: server credential instance. + * - sc: address of ALTS server security connector instance to be returned from + * the method. + * + * It returns GRPC_SECURITY_OK on success, and an error status code on failure. + */ +grpc_security_status grpc_alts_server_security_connector_create( + grpc_server_credentials* server_creds, grpc_server_security_connector** sc); + +namespace grpc_core { +namespace internal { + +/* Exposed only for testing. */ +grpc_security_status grpc_alts_auth_context_from_tsi_peer( + const tsi_peer* peer, grpc_auth_context** ctx); + +} // namespace internal +} // namespace grpc_core + +#endif /* GRPC_CORE_LIB_SECURITY_SECURITY_CONNECTOR_ALTS_SECURITY_CONNECTOR_H \ + */ diff --git a/src/core/plugin_registry/grpc_plugin_registry.cc b/src/core/plugin_registry/grpc_plugin_registry.cc index ccf5f79a8e..6f11e6bb5b 100644 --- a/src/core/plugin_registry/grpc_plugin_registry.cc +++ b/src/core/plugin_registry/grpc_plugin_registry.cc @@ -24,12 +24,12 @@ void grpc_http_filters_init(void); void grpc_http_filters_shutdown(void); void grpc_chttp2_plugin_init(void); void grpc_chttp2_plugin_shutdown(void); -void grpc_tsi_alts_init(void); -void grpc_tsi_alts_shutdown(void); void grpc_deadline_filter_init(void); void grpc_deadline_filter_shutdown(void); void grpc_client_channel_init(void); void grpc_client_channel_shutdown(void); +void grpc_tsi_alts_init(void); +void grpc_tsi_alts_shutdown(void); void grpc_inproc_plugin_init(void); void grpc_inproc_plugin_shutdown(void); void grpc_resolver_fake_init(void); @@ -60,12 +60,12 @@ void grpc_register_built_in_plugins(void) { grpc_http_filters_shutdown); grpc_register_plugin(grpc_chttp2_plugin_init, grpc_chttp2_plugin_shutdown); - grpc_register_plugin(grpc_tsi_alts_init, - grpc_tsi_alts_shutdown); grpc_register_plugin(grpc_deadline_filter_init, grpc_deadline_filter_shutdown); grpc_register_plugin(grpc_client_channel_init, grpc_client_channel_shutdown); + grpc_register_plugin(grpc_tsi_alts_init, + grpc_tsi_alts_shutdown); grpc_register_plugin(grpc_inproc_plugin_init, grpc_inproc_plugin_shutdown); grpc_register_plugin(grpc_resolver_fake_init, diff --git a/src/core/tsi/alts/crypt/aes_gcm.cc b/src/core/tsi/alts/crypt/aes_gcm.cc new file mode 100644 index 0000000000..02b1ac4492 --- /dev/null +++ b/src/core/tsi/alts/crypt/aes_gcm.cc @@ -0,0 +1,687 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/tsi/alts/crypt/gsec.h" + +#include +#include +#include +#include +#include +#include + +#include + +constexpr size_t kKdfKeyLen = 32; +constexpr size_t kKdfCounterLen = 6; +constexpr size_t kKdfCounterOffset = 2; +constexpr size_t kRekeyAeadKeyLen = kAes128GcmKeyLength; + +/* Struct for additional data required if rekeying is enabled. */ +struct gsec_aes_gcm_aead_rekey_data { + uint8_t kdf_counter[kKdfCounterLen]; + uint8_t nonce_mask[kAesGcmNonceLength]; +}; + +/* Main struct for AES_GCM crypter interface. */ +struct gsec_aes_gcm_aead_crypter { + gsec_aead_crypter crypter; + size_t key_length; + size_t nonce_length; + size_t tag_length; + uint8_t* key; + gsec_aes_gcm_aead_rekey_data* rekey_data; + EVP_CIPHER_CTX* ctx; +}; + +static char* aes_gcm_get_openssl_errors() { + BIO* bio = BIO_new(BIO_s_mem()); + ERR_print_errors(bio); + BUF_MEM* mem = nullptr; + char* error_msg = nullptr; + BIO_get_mem_ptr(bio, &mem); + if (mem != nullptr) { + error_msg = static_cast(gpr_malloc(mem->length + 1)); + memcpy(error_msg, mem->data, mem->length); + error_msg[mem->length] = '\0'; + } + BIO_free_all(bio); + return error_msg; +} + +static void aes_gcm_format_errors(const char* error_msg, char** error_details) { + if (error_details == nullptr) { + return; + } + unsigned long error = ERR_get_error(); + if (error == 0 && error_msg != nullptr) { + *error_details = static_cast(gpr_malloc(strlen(error_msg) + 1)); + memcpy(*error_details, error_msg, strlen(error_msg) + 1); + return; + } + char* openssl_errors = aes_gcm_get_openssl_errors(); + if (openssl_errors != nullptr && error_msg != nullptr) { + size_t len = strlen(error_msg) + strlen(openssl_errors) + 2; /* ", " */ + *error_details = static_cast(gpr_malloc(len + 1)); + snprintf(*error_details, len + 1, "%s, %s", error_msg, openssl_errors); + gpr_free(openssl_errors); + } +} + +static grpc_status_code gsec_aes_gcm_aead_crypter_max_ciphertext_and_tag_length( + const gsec_aead_crypter* crypter, size_t plaintext_length, + size_t* max_ciphertext_and_tag_length, char** error_details) { + if (max_ciphertext_and_tag_length == nullptr) { + aes_gcm_format_errors("max_ciphertext_and_tag_length is nullptr.", + error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + gsec_aes_gcm_aead_crypter* aes_gcm_crypter = + reinterpret_cast( + const_cast(crypter)); + *max_ciphertext_and_tag_length = + plaintext_length + aes_gcm_crypter->tag_length; + return GRPC_STATUS_OK; +} + +static grpc_status_code gsec_aes_gcm_aead_crypter_max_plaintext_length( + const gsec_aead_crypter* crypter, size_t ciphertext_and_tag_length, + size_t* max_plaintext_length, char** error_details) { + if (max_plaintext_length == nullptr) { + aes_gcm_format_errors("max_plaintext_length is nullptr.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + gsec_aes_gcm_aead_crypter* aes_gcm_crypter = + reinterpret_cast( + const_cast(crypter)); + if (ciphertext_and_tag_length < aes_gcm_crypter->tag_length) { + *max_plaintext_length = 0; + aes_gcm_format_errors( + "ciphertext_and_tag_length is smaller than tag_length.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + *max_plaintext_length = + ciphertext_and_tag_length - aes_gcm_crypter->tag_length; + return GRPC_STATUS_OK; +} + +static grpc_status_code gsec_aes_gcm_aead_crypter_nonce_length( + const gsec_aead_crypter* crypter, size_t* nonce_length, + char** error_details) { + if (nonce_length == nullptr) { + aes_gcm_format_errors("nonce_length is nullptr.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + gsec_aes_gcm_aead_crypter* aes_gcm_crypter = + reinterpret_cast( + const_cast(crypter)); + *nonce_length = aes_gcm_crypter->nonce_length; + return GRPC_STATUS_OK; +} + +static grpc_status_code gsec_aes_gcm_aead_crypter_key_length( + const gsec_aead_crypter* crypter, size_t* key_length, + char** error_details) { + if (key_length == nullptr) { + aes_gcm_format_errors("key_length is nullptr.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + gsec_aes_gcm_aead_crypter* aes_gcm_crypter = + reinterpret_cast( + const_cast(crypter)); + *key_length = aes_gcm_crypter->key_length; + return GRPC_STATUS_OK; +} + +static grpc_status_code gsec_aes_gcm_aead_crypter_tag_length( + const gsec_aead_crypter* crypter, size_t* tag_length, + char** error_details) { + if (tag_length == nullptr) { + aes_gcm_format_errors("tag_length is nullptr.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + gsec_aes_gcm_aead_crypter* aes_gcm_crypter = + reinterpret_cast( + const_cast(crypter)); + *tag_length = aes_gcm_crypter->tag_length; + return GRPC_STATUS_OK; +} + +static void aes_gcm_mask_nonce(uint8_t* dst, const uint8_t* nonce, + const uint8_t* mask) { + uint64_t mask1; + uint32_t mask2; + memcpy(&mask1, mask, sizeof(mask1)); + memcpy(&mask2, mask + sizeof(mask1), sizeof(mask2)); + uint64_t nonce1; + uint32_t nonce2; + memcpy(&nonce1, nonce, sizeof(nonce1)); + memcpy(&nonce2, nonce + sizeof(nonce1), sizeof(nonce2)); + nonce1 ^= mask1; + nonce2 ^= mask2; + memcpy(dst, &nonce1, sizeof(nonce1)); + memcpy(dst + sizeof(nonce1), &nonce2, sizeof(nonce2)); +} + +static grpc_status_code aes_gcm_derive_aead_key(uint8_t* dst, + const uint8_t* kdf_key, + const uint8_t* kdf_counter) { + unsigned char buf[EVP_MAX_MD_SIZE]; + unsigned char ctr = 1; +#if OPENSSL_VERSION_NUMBER < 0x10100000L + HMAC_CTX hmac; + HMAC_CTX_init(&hmac); + if (!HMAC_Init_ex(&hmac, kdf_key, kKdfKeyLen, EVP_sha256(), nullptr) || + !HMAC_Update(&hmac, kdf_counter, kKdfCounterLen) || + !HMAC_Update(&hmac, &ctr, 1) || !HMAC_Final(&hmac, buf, nullptr)) { + HMAC_CTX_cleanup(&hmac); + return GRPC_STATUS_INTERNAL; + } + HMAC_CTX_cleanup(&hmac); +#else + HMAC_CTX* hmac = HMAC_CTX_new(); + if (hmac == nullptr) { + return GRPC_STATUS_INTERNAL; + } + if (!HMAC_Init_ex(hmac, kdf_key, kKdfKeyLen, EVP_sha256(), nullptr) || + !HMAC_Update(hmac, kdf_counter, kKdfCounterLen) || + !HMAC_Update(hmac, &ctr, 1) || !HMAC_Final(hmac, buf, nullptr)) { + HMAC_CTX_free(hmac); + return GRPC_STATUS_INTERNAL; + } + HMAC_CTX_free(hmac); +#endif + memcpy(dst, buf, kRekeyAeadKeyLen); + return GRPC_STATUS_OK; +} + +static grpc_status_code aes_gcm_rekey_if_required( + gsec_aes_gcm_aead_crypter* aes_gcm_crypter, const uint8_t* nonce, + char** error_details) { + // If rekey_data is nullptr, then rekeying is not supported and not required. + // If bytes 2-7 of kdf_counter differ from the (per message) nonce, then the + // encryption key is recomputed from a new kdf_counter to ensure that we don't + // encrypt more than 2^16 messages per encryption key (in each direction). + if (aes_gcm_crypter->rekey_data == nullptr || + memcmp(aes_gcm_crypter->rekey_data->kdf_counter, + nonce + kKdfCounterOffset, kKdfCounterLen) == 0) { + return GRPC_STATUS_OK; + } + memcpy(aes_gcm_crypter->rekey_data->kdf_counter, nonce + kKdfCounterOffset, + kKdfCounterLen); + uint8_t aead_key[kRekeyAeadKeyLen]; + if (aes_gcm_derive_aead_key(aead_key, aes_gcm_crypter->key, + aes_gcm_crypter->rekey_data->kdf_counter) != + GRPC_STATUS_OK) { + aes_gcm_format_errors("Rekeying failed in key derivation.", error_details); + return GRPC_STATUS_INTERNAL; + } + if (!EVP_DecryptInit_ex(aes_gcm_crypter->ctx, nullptr, nullptr, aead_key, + nullptr)) { + aes_gcm_format_errors("Rekeying failed in context update.", error_details); + return GRPC_STATUS_INTERNAL; + } + return GRPC_STATUS_OK; +} + +static grpc_status_code gsec_aes_gcm_aead_crypter_encrypt_iovec( + gsec_aead_crypter* crypter, const uint8_t* nonce, size_t nonce_length, + const struct iovec* aad_vec, size_t aad_vec_length, + const struct iovec* plaintext_vec, size_t plaintext_vec_length, + struct iovec ciphertext_vec, size_t* ciphertext_bytes_written, + char** error_details) { + gsec_aes_gcm_aead_crypter* aes_gcm_crypter = + reinterpret_cast(crypter); + // Input checks + if (nonce == nullptr) { + aes_gcm_format_errors("Nonce buffer is nullptr.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + if (kAesGcmNonceLength != nonce_length) { + aes_gcm_format_errors("Nonce buffer has the wrong length.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + if (aad_vec_length > 0 && aad_vec == nullptr) { + aes_gcm_format_errors("Non-zero aad_vec_length but aad_vec is nullptr.", + error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + if (plaintext_vec_length > 0 && plaintext_vec == nullptr) { + aes_gcm_format_errors( + "Non-zero plaintext_vec_length but plaintext_vec is nullptr.", + error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + if (ciphertext_bytes_written == nullptr) { + aes_gcm_format_errors("bytes_written is nullptr.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + *ciphertext_bytes_written = 0; + // rekey if required + if (aes_gcm_rekey_if_required(aes_gcm_crypter, nonce, error_details) != + GRPC_STATUS_OK) { + return GRPC_STATUS_INTERNAL; + } + // mask nonce if required + const uint8_t* nonce_aead = nonce; + uint8_t nonce_masked[kAesGcmNonceLength]; + if (aes_gcm_crypter->rekey_data != nullptr) { + aes_gcm_mask_nonce(nonce_masked, aes_gcm_crypter->rekey_data->nonce_mask, + nonce); + nonce_aead = nonce_masked; + } + // init openssl context + if (!EVP_EncryptInit_ex(aes_gcm_crypter->ctx, nullptr, nullptr, nullptr, + nonce_aead)) { + aes_gcm_format_errors("Initializing nonce failed", error_details); + return GRPC_STATUS_INTERNAL; + } + // process aad + size_t i; + for (i = 0; i < aad_vec_length; i++) { + const uint8_t* aad = static_cast(aad_vec[i].iov_base); + size_t aad_length = aad_vec[i].iov_len; + if (aad_length == 0) { + continue; + } + size_t aad_bytes_read = 0; + if (aad == nullptr) { + aes_gcm_format_errors("aad is nullptr.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + if (!EVP_EncryptUpdate(aes_gcm_crypter->ctx, nullptr, + reinterpret_cast(&aad_bytes_read), aad, + static_cast(aad_length)) || + aad_bytes_read != aad_length) { + aes_gcm_format_errors("Setting authenticated associated data failed", + error_details); + return GRPC_STATUS_INTERNAL; + } + } + uint8_t* ciphertext = static_cast(ciphertext_vec.iov_base); + size_t ciphertext_length = ciphertext_vec.iov_len; + if (ciphertext == nullptr) { + aes_gcm_format_errors("ciphertext is nullptr.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + // process plaintext + for (i = 0; i < plaintext_vec_length; i++) { + const uint8_t* plaintext = static_cast(plaintext_vec[i].iov_base); + size_t plaintext_length = plaintext_vec[i].iov_len; + if (plaintext == nullptr) { + if (plaintext_length == 0) { + continue; + } + aes_gcm_format_errors("plaintext is nullptr.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + if (ciphertext_length < plaintext_length) { + aes_gcm_format_errors( + "ciphertext is not large enough to hold the result.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + int bytes_written = 0; + int bytes_to_write = static_cast(plaintext_length); + if (!EVP_EncryptUpdate(aes_gcm_crypter->ctx, ciphertext, &bytes_written, + plaintext, bytes_to_write)) { + aes_gcm_format_errors("Encrypting plaintext failed.", error_details); + return GRPC_STATUS_INTERNAL; + } + if (bytes_written > bytes_to_write) { + aes_gcm_format_errors("More bytes written than expected.", error_details); + return GRPC_STATUS_INTERNAL; + } + ciphertext += bytes_written; + ciphertext_length -= bytes_written; + } + int bytes_written_temp = 0; + if (!EVP_EncryptFinal_ex(aes_gcm_crypter->ctx, nullptr, + &bytes_written_temp)) { + aes_gcm_format_errors("Finalizing encryption failed.", error_details); + return GRPC_STATUS_INTERNAL; + } + if (bytes_written_temp != 0) { + aes_gcm_format_errors("Openssl wrote some unexpected bytes.", + error_details); + return GRPC_STATUS_INTERNAL; + } + if (ciphertext_length < kAesGcmTagLength) { + aes_gcm_format_errors("ciphertext is too small to hold a tag.", + error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + + if (!EVP_CIPHER_CTX_ctrl(aes_gcm_crypter->ctx, EVP_CTRL_GCM_GET_TAG, + kAesGcmTagLength, ciphertext)) { + aes_gcm_format_errors("Writing tag failed.", error_details); + return GRPC_STATUS_INTERNAL; + } + ciphertext += kAesGcmTagLength; + ciphertext_length -= kAesGcmTagLength; + *ciphertext_bytes_written = ciphertext_vec.iov_len - ciphertext_length; + return GRPC_STATUS_OK; +} + +static grpc_status_code gsec_aes_gcm_aead_crypter_decrypt_iovec( + gsec_aead_crypter* crypter, const uint8_t* nonce, size_t nonce_length, + const struct iovec* aad_vec, size_t aad_vec_length, + const struct iovec* ciphertext_vec, size_t ciphertext_vec_length, + struct iovec plaintext_vec, size_t* plaintext_bytes_written, + char** error_details) { + gsec_aes_gcm_aead_crypter* aes_gcm_crypter = + reinterpret_cast( + const_cast(crypter)); + if (nonce == nullptr) { + aes_gcm_format_errors("Nonce buffer is nullptr.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + if (kAesGcmNonceLength != nonce_length) { + aes_gcm_format_errors("Nonce buffer has the wrong length.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + if (aad_vec_length > 0 && aad_vec == nullptr) { + aes_gcm_format_errors("Non-zero aad_vec_length but aad_vec is nullptr.", + error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + if (ciphertext_vec_length > 0 && ciphertext_vec == nullptr) { + aes_gcm_format_errors( + "Non-zero plaintext_vec_length but plaintext_vec is nullptr.", + error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + // Compute the total length so we can ensure we don't pass the tag into + // EVP_decrypt. + size_t total_ciphertext_length = 0; + size_t i; + for (i = 0; i < ciphertext_vec_length; i++) { + total_ciphertext_length += ciphertext_vec[i].iov_len; + } + if (total_ciphertext_length < kAesGcmTagLength) { + aes_gcm_format_errors("ciphertext is too small to hold a tag.", + error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + if (plaintext_bytes_written == nullptr) { + aes_gcm_format_errors("bytes_written is nullptr.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + *plaintext_bytes_written = 0; + // rekey if required + if (aes_gcm_rekey_if_required(aes_gcm_crypter, nonce, error_details) != + GRPC_STATUS_OK) { + aes_gcm_format_errors("Rekeying failed.", error_details); + return GRPC_STATUS_INTERNAL; + } + // mask nonce if required + const uint8_t* nonce_aead = nonce; + uint8_t nonce_masked[kAesGcmNonceLength]; + if (aes_gcm_crypter->rekey_data != nullptr) { + aes_gcm_mask_nonce(nonce_masked, aes_gcm_crypter->rekey_data->nonce_mask, + nonce); + nonce_aead = nonce_masked; + } + // init openssl context + if (!EVP_DecryptInit_ex(aes_gcm_crypter->ctx, nullptr, nullptr, nullptr, + nonce_aead)) { + aes_gcm_format_errors("Initializing nonce failed.", error_details); + return GRPC_STATUS_INTERNAL; + } + // process aad + for (i = 0; i < aad_vec_length; i++) { + const uint8_t* aad = static_cast(aad_vec[i].iov_base); + size_t aad_length = aad_vec[i].iov_len; + if (aad_length == 0) { + continue; + } + size_t aad_bytes_read = 0; + if (aad == nullptr) { + aes_gcm_format_errors("aad is nullptr.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + if (!EVP_DecryptUpdate(aes_gcm_crypter->ctx, nullptr, + reinterpret_cast(&aad_bytes_read), aad, + static_cast(aad_length)) || + aad_bytes_read != aad_length) { + aes_gcm_format_errors("Setting authenticated associated data failed.", + error_details); + return GRPC_STATUS_INTERNAL; + } + } + // process ciphertext + uint8_t* plaintext = static_cast(plaintext_vec.iov_base); + size_t plaintext_length = plaintext_vec.iov_len; + if (plaintext_length > 0 && plaintext == nullptr) { + aes_gcm_format_errors( + "plaintext is nullptr, but plaintext_length is positive.", + error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + const uint8_t* ciphertext = nullptr; + size_t ciphertext_length = 0; + for (i = 0; + i < ciphertext_vec_length && total_ciphertext_length > kAesGcmTagLength; + i++) { + ciphertext = static_cast(ciphertext_vec[i].iov_base); + ciphertext_length = ciphertext_vec[i].iov_len; + if (ciphertext == nullptr) { + if (ciphertext_length == 0) { + continue; + } + aes_gcm_format_errors("ciphertext is nullptr.", error_details); + memset(plaintext_vec.iov_base, 0x00, plaintext_vec.iov_len); + return GRPC_STATUS_INVALID_ARGUMENT; + } + size_t bytes_written = 0; + size_t bytes_to_write = ciphertext_length; + // Don't include the tag + if (bytes_to_write > total_ciphertext_length - kAesGcmTagLength) { + bytes_to_write = total_ciphertext_length - kAesGcmTagLength; + } + if (plaintext_length < bytes_to_write) { + aes_gcm_format_errors( + "Not enough plaintext buffer to hold encrypted ciphertext.", + error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + if (!EVP_DecryptUpdate(aes_gcm_crypter->ctx, plaintext, + reinterpret_cast(&bytes_written), ciphertext, + static_cast(bytes_to_write))) { + aes_gcm_format_errors("Decrypting ciphertext failed.", error_details); + memset(plaintext_vec.iov_base, 0x00, plaintext_vec.iov_len); + return GRPC_STATUS_INTERNAL; + } + if (bytes_written > ciphertext_length) { + aes_gcm_format_errors("More bytes written than expected.", error_details); + memset(plaintext_vec.iov_base, 0x00, plaintext_vec.iov_len); + return GRPC_STATUS_INTERNAL; + } + ciphertext += bytes_written; + ciphertext_length -= bytes_written; + total_ciphertext_length -= bytes_written; + plaintext += bytes_written; + plaintext_length -= bytes_written; + } + if (total_ciphertext_length > kAesGcmTagLength) { + aes_gcm_format_errors( + "Not enough plaintext buffer to hold encrypted ciphertext.", + error_details); + memset(plaintext_vec.iov_base, 0x00, plaintext_vec.iov_len); + return GRPC_STATUS_INVALID_ARGUMENT; + } + uint8_t tag[kAesGcmTagLength]; + uint8_t* tag_tmp = tag; + if (ciphertext_length > 0) { + memcpy(tag_tmp, ciphertext, ciphertext_length); + tag_tmp += ciphertext_length; + total_ciphertext_length -= ciphertext_length; + } + for (; i < ciphertext_vec_length; i++) { + ciphertext = static_cast(ciphertext_vec[i].iov_base); + ciphertext_length = ciphertext_vec[i].iov_len; + if (ciphertext == nullptr) { + if (ciphertext_length == 0) { + continue; + } + aes_gcm_format_errors("ciphertext is nullptr.", error_details); + memset(plaintext_vec.iov_base, 0x00, plaintext_vec.iov_len); + return GRPC_STATUS_INVALID_ARGUMENT; + } + memcpy(tag_tmp, ciphertext, ciphertext_length); + tag_tmp += ciphertext_length; + total_ciphertext_length -= ciphertext_length; + } + if (!EVP_CIPHER_CTX_ctrl(aes_gcm_crypter->ctx, EVP_CTRL_GCM_SET_TAG, + kAesGcmTagLength, reinterpret_cast(tag))) { + aes_gcm_format_errors("Setting tag failed.", error_details); + memset(plaintext_vec.iov_base, 0x00, plaintext_vec.iov_len); + return GRPC_STATUS_INTERNAL; + } + int bytes_written_temp = 0; + if (!EVP_DecryptFinal_ex(aes_gcm_crypter->ctx, nullptr, + &bytes_written_temp)) { + aes_gcm_format_errors("Checking tag failed.", error_details); + memset(plaintext_vec.iov_base, 0x00, plaintext_vec.iov_len); + return GRPC_STATUS_FAILED_PRECONDITION; + } + if (bytes_written_temp != 0) { + aes_gcm_format_errors("Openssl wrote some unexpected bytes.", + error_details); + memset(plaintext_vec.iov_base, 0x00, plaintext_vec.iov_len); + return GRPC_STATUS_INTERNAL; + } + *plaintext_bytes_written = plaintext_vec.iov_len - plaintext_length; + return GRPC_STATUS_OK; +} + +static void gsec_aes_gcm_aead_crypter_destroy(gsec_aead_crypter* crypter) { + gsec_aes_gcm_aead_crypter* aes_gcm_crypter = + reinterpret_cast( + const_cast(crypter)); + gpr_free(aes_gcm_crypter->key); + gpr_free(aes_gcm_crypter->rekey_data); + EVP_CIPHER_CTX_free(aes_gcm_crypter->ctx); +} + +static const gsec_aead_crypter_vtable vtable = { + gsec_aes_gcm_aead_crypter_encrypt_iovec, + gsec_aes_gcm_aead_crypter_decrypt_iovec, + gsec_aes_gcm_aead_crypter_max_ciphertext_and_tag_length, + gsec_aes_gcm_aead_crypter_max_plaintext_length, + gsec_aes_gcm_aead_crypter_nonce_length, + gsec_aes_gcm_aead_crypter_key_length, + gsec_aes_gcm_aead_crypter_tag_length, + gsec_aes_gcm_aead_crypter_destroy}; + +static grpc_status_code aes_gcm_new_evp_cipher_ctx( + gsec_aes_gcm_aead_crypter* aes_gcm_crypter, char** error_details) { + const EVP_CIPHER* cipher = nullptr; + bool is_rekey = aes_gcm_crypter->rekey_data != nullptr; + switch (is_rekey ? kRekeyAeadKeyLen : aes_gcm_crypter->key_length) { + case kAes128GcmKeyLength: + cipher = EVP_aes_128_gcm(); + break; + case kAes256GcmKeyLength: + cipher = EVP_aes_256_gcm(); + break; + } + const uint8_t* aead_key = aes_gcm_crypter->key; + uint8_t aead_key_rekey[kRekeyAeadKeyLen]; + if (is_rekey) { + if (aes_gcm_derive_aead_key(aead_key_rekey, aes_gcm_crypter->key, + aes_gcm_crypter->rekey_data->kdf_counter) != + GRPC_STATUS_OK) { + aes_gcm_format_errors("Deriving key failed.", error_details); + return GRPC_STATUS_INTERNAL; + } + aead_key = aead_key_rekey; + } + if (!EVP_DecryptInit_ex(aes_gcm_crypter->ctx, cipher, nullptr, aead_key, + nullptr)) { + aes_gcm_format_errors("Setting key failed.", error_details); + return GRPC_STATUS_INTERNAL; + } + if (!EVP_CIPHER_CTX_ctrl(aes_gcm_crypter->ctx, EVP_CTRL_GCM_SET_IVLEN, + static_cast(aes_gcm_crypter->nonce_length), + nullptr)) { + aes_gcm_format_errors("Setting nonce length failed.", error_details); + return GRPC_STATUS_INTERNAL; + } + return GRPC_STATUS_OK; +} + +grpc_status_code gsec_aes_gcm_aead_crypter_create(const uint8_t* key, + size_t key_length, + size_t nonce_length, + size_t tag_length, bool rekey, + gsec_aead_crypter** crypter, + char** error_details) { + if (key == nullptr) { + aes_gcm_format_errors("key is nullptr.", error_details); + return GRPC_STATUS_FAILED_PRECONDITION; + } + if (crypter == nullptr) { + aes_gcm_format_errors("crypter is nullptr.", error_details); + return GRPC_STATUS_FAILED_PRECONDITION; + } + *crypter = nullptr; + if ((rekey && key_length != kAes128GcmRekeyKeyLength) || + (!rekey && key_length != kAes128GcmKeyLength && + key_length != kAes256GcmKeyLength) || + (tag_length != kAesGcmTagLength) || + (nonce_length != kAesGcmNonceLength)) { + aes_gcm_format_errors( + "Invalid key and/or nonce and/or tag length are provided at AEAD " + "crypter instance construction time.", + error_details); + return GRPC_STATUS_FAILED_PRECONDITION; + } + gsec_aes_gcm_aead_crypter* aes_gcm_crypter = + static_cast( + gpr_malloc(sizeof(gsec_aes_gcm_aead_crypter))); + aes_gcm_crypter->crypter.vtable = &vtable; + aes_gcm_crypter->nonce_length = nonce_length; + aes_gcm_crypter->tag_length = tag_length; + if (rekey) { + aes_gcm_crypter->key_length = kKdfKeyLen; + aes_gcm_crypter->rekey_data = static_cast( + gpr_malloc(sizeof(gsec_aes_gcm_aead_rekey_data))); + memcpy(aes_gcm_crypter->rekey_data->nonce_mask, key + kKdfKeyLen, + kAesGcmNonceLength); + // Set kdf_counter to all-zero for initial key derivation. + memset(aes_gcm_crypter->rekey_data->kdf_counter, 0, kKdfCounterLen); + } else { + aes_gcm_crypter->key_length = key_length; + aes_gcm_crypter->rekey_data = nullptr; + } + aes_gcm_crypter->key = + static_cast(gpr_malloc(aes_gcm_crypter->key_length)); + memcpy(aes_gcm_crypter->key, key, aes_gcm_crypter->key_length); + aes_gcm_crypter->ctx = EVP_CIPHER_CTX_new(); + grpc_status_code status = + aes_gcm_new_evp_cipher_ctx(aes_gcm_crypter, error_details); + if (status != GRPC_STATUS_OK) { + gsec_aes_gcm_aead_crypter_destroy(&aes_gcm_crypter->crypter); + gpr_free(aes_gcm_crypter); + return status; + } + *crypter = &aes_gcm_crypter->crypter; + return GRPC_STATUS_OK; +} diff --git a/src/core/tsi/alts/crypt/gsec.cc b/src/core/tsi/alts/crypt/gsec.cc new file mode 100644 index 0000000000..6236591a97 --- /dev/null +++ b/src/core/tsi/alts/crypt/gsec.cc @@ -0,0 +1,189 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/tsi/alts/crypt/gsec.h" + +#include +#include + +#include + +static const char vtable_error_msg[] = + "crypter or crypter->vtable has not been initialized properly"; + +static void maybe_copy_error_msg(const char* src, char** dst) { + if (dst != nullptr && src != nullptr) { + *dst = static_cast(gpr_malloc(strlen(src) + 1)); + memcpy(*dst, src, strlen(src) + 1); + } +} + +grpc_status_code gsec_aead_crypter_encrypt( + gsec_aead_crypter* crypter, const uint8_t* nonce, size_t nonce_length, + const uint8_t* aad, size_t aad_length, const uint8_t* plaintext, + size_t plaintext_length, uint8_t* ciphertext_and_tag, + size_t ciphertext_and_tag_length, size_t* bytes_written, + char** error_details) { + if (crypter != nullptr && crypter->vtable != nullptr && + crypter->vtable->encrypt_iovec != nullptr) { + struct iovec aad_vec = {(void*)aad, aad_length}; + struct iovec plaintext_vec = {(void*)plaintext, plaintext_length}; + struct iovec ciphertext_vec = {ciphertext_and_tag, + ciphertext_and_tag_length}; + return crypter->vtable->encrypt_iovec( + crypter, nonce, nonce_length, &aad_vec, 1, &plaintext_vec, 1, + ciphertext_vec, bytes_written, error_details); + } + /* An error occurred. */ + maybe_copy_error_msg(vtable_error_msg, error_details); + return GRPC_STATUS_INVALID_ARGUMENT; +} + +grpc_status_code gsec_aead_crypter_encrypt_iovec( + gsec_aead_crypter* crypter, const uint8_t* nonce, size_t nonce_length, + const struct iovec* aad_vec, size_t aad_vec_length, + const struct iovec* plaintext_vec, size_t plaintext_vec_length, + struct iovec ciphertext_vec, size_t* ciphertext_bytes_written, + char** error_details) { + if (crypter != nullptr && crypter->vtable != nullptr && + crypter->vtable->encrypt_iovec != nullptr) { + return crypter->vtable->encrypt_iovec( + crypter, nonce, nonce_length, aad_vec, aad_vec_length, plaintext_vec, + plaintext_vec_length, ciphertext_vec, ciphertext_bytes_written, + error_details); + } + /* An error occurred. */ + maybe_copy_error_msg(vtable_error_msg, error_details); + return GRPC_STATUS_INVALID_ARGUMENT; +} + +grpc_status_code gsec_aead_crypter_decrypt( + gsec_aead_crypter* crypter, const uint8_t* nonce, size_t nonce_length, + const uint8_t* aad, size_t aad_length, const uint8_t* ciphertext_and_tag, + size_t ciphertext_and_tag_length, uint8_t* plaintext, + size_t plaintext_length, size_t* bytes_written, char** error_details) { + if (crypter != nullptr && crypter->vtable != nullptr && + crypter->vtable->decrypt_iovec != nullptr) { + struct iovec aad_vec = {(void*)aad, aad_length}; + struct iovec ciphertext_vec = {(void*)ciphertext_and_tag, + ciphertext_and_tag_length}; + struct iovec plaintext_vec = {plaintext, plaintext_length}; + return crypter->vtable->decrypt_iovec( + crypter, nonce, nonce_length, &aad_vec, 1, &ciphertext_vec, 1, + plaintext_vec, bytes_written, error_details); + } + /* An error occurred. */ + maybe_copy_error_msg(vtable_error_msg, error_details); + return GRPC_STATUS_INVALID_ARGUMENT; +} + +grpc_status_code gsec_aead_crypter_decrypt_iovec( + gsec_aead_crypter* crypter, const uint8_t* nonce, size_t nonce_length, + const struct iovec* aad_vec, size_t aad_vec_length, + const struct iovec* ciphertext_vec, size_t ciphertext_vec_length, + struct iovec plaintext_vec, size_t* plaintext_bytes_written, + char** error_details) { + if (crypter != nullptr && crypter->vtable != nullptr && + crypter->vtable->encrypt_iovec != nullptr) { + return crypter->vtable->decrypt_iovec( + crypter, nonce, nonce_length, aad_vec, aad_vec_length, ciphertext_vec, + ciphertext_vec_length, plaintext_vec, plaintext_bytes_written, + error_details); + } + /* An error occurred. */ + maybe_copy_error_msg(vtable_error_msg, error_details); + return GRPC_STATUS_INVALID_ARGUMENT; +} + +grpc_status_code gsec_aead_crypter_max_ciphertext_and_tag_length( + const gsec_aead_crypter* crypter, size_t plaintext_length, + size_t* max_ciphertext_and_tag_length_to_return, char** error_details) { + if (crypter != nullptr && crypter->vtable != nullptr && + crypter->vtable->max_ciphertext_and_tag_length != nullptr) { + return crypter->vtable->max_ciphertext_and_tag_length( + crypter, plaintext_length, max_ciphertext_and_tag_length_to_return, + error_details); + } + /* An error occurred. */ + maybe_copy_error_msg(vtable_error_msg, error_details); + return GRPC_STATUS_INVALID_ARGUMENT; +} + +grpc_status_code gsec_aead_crypter_max_plaintext_length( + const gsec_aead_crypter* crypter, size_t ciphertext_and_tag_length, + size_t* max_plaintext_length_to_return, char** error_details) { + if (crypter != nullptr && crypter->vtable != nullptr && + crypter->vtable->max_plaintext_length != nullptr) { + return crypter->vtable->max_plaintext_length( + crypter, ciphertext_and_tag_length, max_plaintext_length_to_return, + error_details); + } + /* An error occurred. */ + maybe_copy_error_msg(vtable_error_msg, error_details); + return GRPC_STATUS_INVALID_ARGUMENT; +} + +grpc_status_code gsec_aead_crypter_nonce_length( + const gsec_aead_crypter* crypter, size_t* nonce_length_to_return, + char** error_details) { + if (crypter != nullptr && crypter->vtable != nullptr && + crypter->vtable->nonce_length != nullptr) { + return crypter->vtable->nonce_length(crypter, nonce_length_to_return, + error_details); + } + /* An error occurred. */ + maybe_copy_error_msg(vtable_error_msg, error_details); + return GRPC_STATUS_INVALID_ARGUMENT; +} + +grpc_status_code gsec_aead_crypter_key_length(const gsec_aead_crypter* crypter, + size_t* key_length_to_return, + char** error_details) { + if (crypter != nullptr && crypter->vtable != nullptr && + crypter->vtable->key_length != nullptr) { + return crypter->vtable->key_length(crypter, key_length_to_return, + error_details); + } + /* An error occurred */ + maybe_copy_error_msg(vtable_error_msg, error_details); + return GRPC_STATUS_INVALID_ARGUMENT; +} + +grpc_status_code gsec_aead_crypter_tag_length(const gsec_aead_crypter* crypter, + size_t* tag_length_to_return, + char** error_details) { + if (crypter != nullptr && crypter->vtable != nullptr && + crypter->vtable->tag_length != nullptr) { + return crypter->vtable->tag_length(crypter, tag_length_to_return, + error_details); + } + /* An error occurred. */ + maybe_copy_error_msg(vtable_error_msg, error_details); + return GRPC_STATUS_INVALID_ARGUMENT; +} + +void gsec_aead_crypter_destroy(gsec_aead_crypter* crypter) { + if (crypter != nullptr) { + if (crypter->vtable != nullptr && crypter->vtable->destruct != nullptr) { + crypter->vtable->destruct(crypter); + } + gpr_free(crypter); + } +} diff --git a/src/core/tsi/alts/crypt/gsec.h b/src/core/tsi/alts/crypt/gsec.h new file mode 100644 index 0000000000..4d65caa944 --- /dev/null +++ b/src/core/tsi/alts/crypt/gsec.h @@ -0,0 +1,454 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_TSI_ALTS_CRYPT_GSEC_H +#define GRPC_CORE_TSI_ALTS_CRYPT_GSEC_H + +#include + +#include +#include +#include + +#include + +struct iovec { + void* iov_base; + size_t iov_len; +}; + +/** + * A gsec interface for AEAD encryption schemes. The API is thread-compatible. + * Each implementation of this interface should specify supported values for + * key, nonce, and tag lengths. + */ + +/* Key, nonce, and tag length in bytes */ +const size_t kAesGcmNonceLength = 12; +const size_t kAesGcmTagLength = 16; +const size_t kAes128GcmKeyLength = 16; +const size_t kAes256GcmKeyLength = 32; + +// The first 32 bytes are used as a KDF key and the remaining 12 bytes are used +// to mask the nonce. +const size_t kAes128GcmRekeyKeyLength = 44; + +typedef struct gsec_aead_crypter gsec_aead_crypter; + +/** + * The gsec_aead_crypter is an API for different AEAD implementations such as + * AES_GCM. It encapsulates all AEAD-related operations in the format of + * V-table that stores pointers to functions implementing those operations. + * It also provides helper functions to wrap each of those function pointers. + * + * A typical usage of this object would be: + * + *------------------------------------------------------------------------------ + * // Declare a gsec_aead_crypter object, and create and assign an instance + * // of specific AEAD implementation e.g., AES_GCM to it. We assume both + * // key and nonce contain cryptographically secure random bytes, and the key + * // can be derived from an upper-layer application. + * gsec_aead_crypter* crypter; + * char* error_in_creation; + * // User can populate the message with any 100 bytes data. + * uint8_t* message = gpr_malloc(100); + * grpc_status_code creation_status = gsec_aes_gcm_aead_crypter_create(key, + * kAes128GcmKeyLength, + * kAesGcmNonceLength, + * kAesGcmTagLength, + * &crypter, + * false, + * 0 + * &error_in_creation); + * + * if (creation_status == GRPC_STATUS_OK) { + * // Allocate a correct amount of memory to hold a ciphertext. + * size_t clength = 0; + * gsec_aead_crypter_max_ciphertext_and_tag_length(crypter, 100, &clength, + * nullptr); + * uint8_t* ciphertext = gpr_malloc(clength); + * + * // Perform encryption + * size_t num_encrypted_bytes = 0; + * char* error_in_encryption = nullptr; + * grpc_status_code status = gsec_aead_crypter_encrypt(crypter, nonce, + * kAesGcmNonceLength, + * nullptr, 0, message, + * 100, ciphertext, + * clength, + * &num_encrypted_bytes, + * &error_in_encryption); + * if (status == GRPC_STATUS_OK) { + * // Allocate a correct amount of memory to hold a plaintext. + * size_t plength = 0; + * gsec_aead_crypter_max_plaintext_length(crypter, num_encrypted_bytes, + * &plength, nullptr); + * uint8_t* plaintext = gpr_malloc(plength); + * + * // Perform decryption. + * size_t num_decrypted_bytes = 0; + * char* error_in_decryption = nullptr; + * status = gsec_aead_crypter_decrypt(crypter, nonce, + * kAesGcmNonceLength, nullptr, 0, + * ciphertext, num_encrypted_bytes, + * plaintext, plength, + * &num_decrypted_bytes, + * &error_in_decryption); + * if (status != GRPC_STATUS_OK) { + * fprintf(stderr, "AEAD decrypt operation failed with error code:" + * "%d, message: %s\n", status, error_in_decryption); + * } + * ... + * gpr_free(plaintext); + * gpr_free(error_in_decryption); + * } else { + * fprintf(stderr, "AEAD encrypt operation failed with error code:" + * "%d, message: %s\n", status, error_in_encryption); + * } + * ... + * gpr_free(ciphertext); + * gpr_free(error_in_encryption); + * } else { + * fprintf(stderr, "Creation of AEAD crypter instance failed with error code:" + * "%d, message: %s\n", creation_status, error_in_creation); + * } + * + * // Destruct AEAD crypter instance. + * if (creation_status == GRPC_STATUS_OK) { + * gsec_aead_crypter_destroy(crypter); + * } + * gpr_free(error_in_creation); + * gpr_free(message); + * ----------------------------------------------------------------------------- + */ + +/* V-table for gsec AEAD operations */ +typedef struct gsec_aead_crypter_vtable { + grpc_status_code (*encrypt_iovec)( + gsec_aead_crypter* crypter, const uint8_t* nonce, size_t nonce_length, + const struct iovec* aad_vec, size_t aad_vec_length, + const struct iovec* plaintext_vec, size_t plaintext_vec_length, + struct iovec ciphertext_vec, size_t* ciphertext_bytes_written, + char** error_details); + grpc_status_code (*decrypt_iovec)( + gsec_aead_crypter* crypter, const uint8_t* nonce, size_t nonce_length, + const struct iovec* aad_vec, size_t aad_vec_length, + const struct iovec* ciphertext_vec, size_t ciphertext_vec_length, + struct iovec plaintext_vec, size_t* plaintext_bytes_written, + char** error_details); + grpc_status_code (*max_ciphertext_and_tag_length)( + const gsec_aead_crypter* crypter, size_t plaintext_length, + size_t* max_ciphertext_and_tag_length_to_return, char** error_details); + grpc_status_code (*max_plaintext_length)( + const gsec_aead_crypter* crypter, size_t ciphertext_and_tag_length, + size_t* max_plaintext_length_to_return, char** error_details); + grpc_status_code (*nonce_length)(const gsec_aead_crypter* crypter, + size_t* nonce_length_to_return, + char** error_details); + grpc_status_code (*key_length)(const gsec_aead_crypter* crypter, + size_t* key_length_to_return, + char** error_details); + grpc_status_code (*tag_length)(const gsec_aead_crypter* crypter, + size_t* tag_length_to_return, + char** error_details); + void (*destruct)(gsec_aead_crypter* crypter); +} gsec_aead_crypter_vtable; + +/* Main struct for gsec interface */ +struct gsec_aead_crypter { + const struct gsec_aead_crypter_vtable* vtable; +}; + +/** + * This method performs an AEAD encrypt operation. + * + * - crypter: AEAD crypter instance. + * - nonce: buffer containing a nonce with its size equal to nonce_length. + * - nonce_length: size of nonce buffer, and must be equal to the value returned + * from method gsec_aead_crypter_nonce_length. + * - aad: buffer containing data that needs to be authenticated but not + * encrypted with its size equal to aad_length. + * - aad_length: size of aad buffer, which should be zero if the buffer is + * nullptr. + * - plaintext: buffer containing data that needs to be both encrypted and + * authenticated with its size equal to plaintext_length. + * - plaintext_length: size of plaintext buffer, which should be zero if + * plaintext is nullptr. + * - ciphertext_and_tag: buffer that will contain ciphertext and tags the method + * produced. The buffer should not overlap the plaintext buffer, and pointers + * to those buffers should not be equal. Also if the ciphertext+tag buffer is + * nullptr, the plaintext_length should be zero. + * - ciphertext_and_tag_length: size of ciphertext+tag buffer, which should be + * at least as long as the one returned from method + * gsec_aead_crypter_max_ciphertext_and_tag_length. + * - bytes_written: the actual number of bytes written to the ciphertext+tag + * buffer. If bytes_written is nullptr, the plaintext_length should be zero. + * - error_details: a buffer containing an error message if the method does not + * function correctly. It is legal to pass nullptr into error_details, and + * otherwise, the parameter should be freed with gpr_free. + * + * On the success of encryption, the method returns GRPC_STATUS_OK. Otherwise, + * it returns an error status code along with its details specified in + * error_details (if error_details is not nullptr). + * + */ +grpc_status_code gsec_aead_crypter_encrypt( + gsec_aead_crypter* crypter, const uint8_t* nonce, size_t nonce_length, + const uint8_t* aad, size_t aad_length, const uint8_t* plaintext, + size_t plaintext_length, uint8_t* ciphertext_and_tag, + size_t ciphertext_and_tag_length, size_t* bytes_written, + char** error_details); + +/** + * This method performs an AEAD encrypt operation. + * + * - crypter: AEAD crypter instance. + * - nonce: buffer containing a nonce with its size equal to nonce_length. + * - nonce_length: size of nonce buffer, and must be equal to the value returned + * from method gsec_aead_crypter_nonce_length. + * - aad_vec: an iovec array containing data that needs to be authenticated but + * not encrypted. + * - aad_vec_length: the array length of aad_vec. + * - plaintext_vec: an iovec array containing data that needs to be both + * encrypted and authenticated. + * - plaintext_vec_length: the array length of plaintext_vec. + * - ciphertext_vec: an iovec containing a ciphertext buffer. The buffer should + * not overlap the plaintext buffer. + * - ciphertext_bytes_written: the actual number of bytes written to + * ciphertext_vec. + * - error_details: a buffer containing an error message if the method does not + * function correctly. It is legal to pass nullptr into error_details, and + * otherwise, the parameter should be freed with gpr_free. + * + * On the success of encryption, the method returns GRPC_STATUS_OK. Otherwise, + * it returns an error status code along with its details specified in + * error_details (if error_details is not nullptr). + * + */ +grpc_status_code gsec_aead_crypter_encrypt_iovec( + gsec_aead_crypter* crypter, const uint8_t* nonce, size_t nonce_length, + const struct iovec* aad_vec, size_t aad_vec_length, + const struct iovec* plaintext_vec, size_t plaintext_vec_length, + struct iovec ciphertext_vec, size_t* ciphertext_bytes_written, + char** error_details); + +/** + * This method performs an AEAD decrypt operation. + * + * - crypter: AEAD crypter instance. + * - nonce: buffer containing a nonce with its size equal to nonce_length. + * - nonce_length: size of nonce buffer, and must be equal to the value returned + * from method gsec_aead_crypter_nonce_length. + * - aad: buffer containing data that needs to be authenticated only. + * - aad_length: size of aad buffer, which should be zero if the buffer is + * nullptr. + * - ciphertext_and_tag: buffer containing ciphertext and tag. + * - ciphertext_and_tag_length: length of ciphertext and tag. It should be zero + * if any of plaintext, ciphertext_and_tag, or bytes_written is nullptr. Also, + * ciphertext_and_tag_length should be at least as large as the tag length set + * at AEAD crypter instance construction time. + * - plaintext: buffer containing decrypted and authenticated data the method + * produced. The buffer should not overlap with the ciphertext+tag buffer, and + * pointers to those buffers should not be equal. + * - plaintext_length: size of plaintext buffer, which should be at least as + * long as the one returned from gsec_aead_crypter_max_plaintext_length + * method. + * - bytes_written: the actual number of bytes written to the plaintext + * buffer. + * - error_details: a buffer containing an error message if the method does not + * function correctly. It is legal to pass nullptr into error_details, and + * otherwise, the parameter should be freed with gpr_free. + * + * On the success of decryption, the method returns GRPC_STATUS_OK. Otherwise, + * it returns an error status code along with its details specified in + * error_details (if error_details is not nullptr). + */ +grpc_status_code gsec_aead_crypter_decrypt( + gsec_aead_crypter* crypter, const uint8_t* nonce, size_t nonce_length, + const uint8_t* aad, size_t aad_length, const uint8_t* ciphertext_and_tag, + size_t ciphertext_and_tag_length, uint8_t* plaintext, + size_t plaintext_length, size_t* bytes_written, char** error_details); + +/** + * This method performs an AEAD decrypt operation. + * + * - crypter: AEAD crypter instance. + * - nonce: buffer containing a nonce with its size equal to nonce_length. + * - nonce_length: size of nonce buffer, and must be equal to the value returned + * from method gsec_aead_crypter_nonce_length. + * - aad_vec: an iovec array containing data that needs to be authenticated but + * not encrypted. + * - aad_vec_length: the array length of aad_vec. + * - ciphertext_vec: an iovec array containing the ciphertext and tag. + * - ciphertext_vec_length: the array length of ciphertext_vec. + * - plaintext_vec: an iovec containing a plaintext buffer. The buffer should + * not overlap the ciphertext buffer. + * - plaintext_bytes_written: the actual number of bytes written to + * plaintext_vec. + * - error_details: a buffer containing an error message if the method does not + * function correctly. It is legal to pass nullptr into error_details, and + * otherwise, the parameter should be freed with gpr_free. + * + * On the success of decryption, the method returns GRPC_STATUS_OK. Otherwise, + * it returns an error status code along with its details specified in + * error_details (if error_details is not nullptr). + */ +grpc_status_code gsec_aead_crypter_decrypt_iovec( + gsec_aead_crypter* crypter, const uint8_t* nonce, size_t nonce_length, + const struct iovec* aad_vec, size_t aad_vec_length, + const struct iovec* ciphertext_vec, size_t ciphertext_vec_length, + struct iovec plaintext_vec, size_t* plaintext_bytes_written, + char** error_details); + +/** + * This method computes the size of ciphertext+tag buffer that must be passed to + * gsec_aead_crypter_encrypt function to ensure correct encryption of a + * plaintext. The actual size of ciphertext+tag written to the buffer could be + * smaller. + * + * - crypter: AEAD crypter instance. + * - plaintext_length: length of plaintext. + * - max_ciphertext_and_tag_length_to_return: the size of ciphertext+tag buffer + * the method returns. + * - error_details: a buffer containing an error message if the method does not + * function correctly. It is legal to pass nullptr into error_details, and + * otherwise, the parameter should be freed with gpr_free. + * + * On the success of execution, the method returns GRPC_STATUS_OK. Otherwise, + * it returns an error status code along with its details specified in + * error_details (if error_details is not nullptr). + */ +grpc_status_code gsec_aead_crypter_max_ciphertext_and_tag_length( + const gsec_aead_crypter* crypter, size_t plaintext_length, + size_t* max_ciphertext_and_tag_length_to_return, char** error_details); + +/** + * This method computes the size of plaintext buffer that must be passed to + * gsec_aead_crypter_decrypt function to ensure correct decryption of a + * ciphertext. The actual size of plaintext written to the buffer could be + * smaller. + * + * - crypter: AEAD crypter instance. + * - ciphertext_and_tag_length: length of ciphertext and tag. + * - max_plaintext_length_to_return: the size of plaintext buffer the method + * returns. + * - error_details: a buffer containing an error message if the method does not + * function correctly. It is legal to pass nullptr into error_details, and + * otherwise, the parameter should be freed with gpr_free. + * + * On the success of execution, the method returns GRPC_STATUS_OK. Otherwise, + * it returns an error status code along with its details specified in + * error_details (if error_details is not nullptr). + */ +grpc_status_code gsec_aead_crypter_max_plaintext_length( + const gsec_aead_crypter* crypter, size_t ciphertext_and_tag_length, + size_t* max_plaintext_length_to_return, char** error_details); + +/** + * This method returns a valid size of nonce array used at the construction of + * AEAD crypter instance. It is also the size that should be passed to encrypt + * and decrypt methods executed on the instance. + * + * - crypter: AEAD crypter instance. + * - nonce_length_to_return: the length of nonce array the method returns. + * - error_details: a buffer containing an error message if the method does not + * function correctly. It is legal to pass nullptr into error_details, and + * otherwise, the parameter should be freed with gpr_free. + * + * On the success of execution, the method returns GRPC_STATUS_OK. Otherwise, + * it returns an error status code along with its details specified in + * error_details (if error_details is not nullptr). + */ +grpc_status_code gsec_aead_crypter_nonce_length( + const gsec_aead_crypter* crypter, size_t* nonce_length_to_return, + char** error_details); + +/** + * This method returns a valid size of key array used at the construction of + * AEAD crypter instance. It is also the size that should be passed to encrypt + * and decrypt methods executed on the instance. + * + * - crypter: AEAD crypter instance. + * - key_length_to_return: the length of key array the method returns. + * - error_details: a buffer containing an error message if the method does not + * function correctly. It is legal to pass nullptr into error_details, and + * otherwise, the parameter should be freed with gpr_free. + * + * On the success of execution, the method returns GRPC_STATUS_OK. Otherwise, + * it returns an error status code along with its details specified in + * error_details (if error_details is not nullptr). + */ +grpc_status_code gsec_aead_crypter_key_length(const gsec_aead_crypter* crypter, + size_t* key_length_to_return, + char** error_details); +/** + * This method returns a valid size of tag array used at the construction of + * AEAD crypter instance. It is also the size that should be passed to encrypt + * and decrypt methods executed on the instance. + * + * - crypter: AEAD crypter instance. + * - tag_length_to_return: the length of tag array the method returns. + * - error_details: a buffer containing an error message if the method does not + * function correctly. It is legal to pass nullptr into error_details, and + * otherwise, the parameter should be freed with gpr_free. + * + * On the success of execution, the method returns GRPC_STATUS_OK. Otherwise, + * it returns an error status code along with its details specified in + * error_details (if error_details is not nullptr). + */ +grpc_status_code gsec_aead_crypter_tag_length(const gsec_aead_crypter* crypter, + size_t* tag_length_to_return, + char** error_details); + +/** + * This method destroys an AEAD crypter instance by de-allocating all of its + * occupied memory. + * + * - crypter: AEAD crypter instance that needs to be destroyed. + */ +void gsec_aead_crypter_destroy(gsec_aead_crypter* crypter); + +/** + * This method creates an AEAD crypter instance of AES-GCM encryption scheme + * which supports 16 and 32 bytes long keys, 12 and 16 bytes long nonces, and + * 16 bytes long tags. It should be noted that once the lengths of key, nonce, + * and tag are determined at construction time, they cannot be modified later. + * + * - key: buffer containing a key which is binded with AEAD crypter instance. + * - key_length: length of a key in bytes, which should be 44 if rekeying is + * enabled and 16 or 32 otherwise. + * - nonce_length: length of a nonce in bytes, which should be either 12 or 16. + * - tag_length: length of a tag in bytes, which should be always 16. + * - rekey: enable nonce-based rekeying and nonce-masking. + * - crypter: address of AES_GCM crypter instance returned from the method. + * - error_details: a buffer containing an error message if the method does not + * function correctly. It is legal to pass nullptr into error_details, and + * otherwise, the parameter should be freed with gpr_free. + * + * On success of instance creation, it stores the address of instance at + * crypter. Otherwise, it returns an error status code together with its details + * specified in error_details. + */ +grpc_status_code gsec_aes_gcm_aead_crypter_create(const uint8_t* key, + size_t key_length, + size_t nonce_length, + size_t tag_length, bool rekey, + gsec_aead_crypter** crypter, + char** error_details); + +#endif /* GRPC_CORE_TSI_ALTS_CRYPT_GSEC_H */ diff --git a/src/core/tsi/alts/frame_protector/alts_counter.cc b/src/core/tsi/alts/frame_protector/alts_counter.cc new file mode 100644 index 0000000000..de163e3e08 --- /dev/null +++ b/src/core/tsi/alts/frame_protector/alts_counter.cc @@ -0,0 +1,118 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/tsi/alts/frame_protector/alts_counter.h" + +#include + +#include + +static void maybe_copy_error_msg(const char* src, char** dst) { + if (dst != nullptr && src != nullptr) { + *dst = static_cast(gpr_malloc(strlen(src) + 1)); + memcpy(*dst, src, strlen(src) + 1); + } +} + +grpc_status_code alts_counter_create(bool is_client, size_t counter_size, + size_t overflow_size, + alts_counter** crypter_counter, + char** error_details) { + /* Perform input sanity check. */ + if (counter_size == 0) { + const char error_msg[] = "counter_size is invalid."; + maybe_copy_error_msg(error_msg, error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + if (overflow_size == 0 || overflow_size >= counter_size) { + const char error_msg[] = "overflow_size is invalid."; + maybe_copy_error_msg(error_msg, error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + if (crypter_counter == nullptr) { + const char error_msg[] = "crypter_counter is nullptr."; + maybe_copy_error_msg(error_msg, error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + *crypter_counter = + static_cast(gpr_malloc(sizeof(**crypter_counter))); + (*crypter_counter)->size = counter_size; + (*crypter_counter)->overflow_size = overflow_size; + (*crypter_counter)->counter = + static_cast(gpr_zalloc(counter_size)); + if (is_client) { + ((*crypter_counter)->counter)[counter_size - 1] = 0x80; + } + return GRPC_STATUS_OK; +} + +grpc_status_code alts_counter_increment(alts_counter* crypter_counter, + bool* is_overflow, + char** error_details) { + /* Perform input sanity check. */ + if (crypter_counter == nullptr) { + const char error_msg[] = "crypter_counter is nullptr."; + maybe_copy_error_msg(error_msg, error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + if (is_overflow == nullptr) { + const char error_msg[] = "is_overflow is nullptr."; + maybe_copy_error_msg(error_msg, error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + /* Increment the internal counter. */ + size_t i = 0; + for (; i < crypter_counter->overflow_size; i++) { + (crypter_counter->counter)[i]++; + if ((crypter_counter->counter)[i] != 0x00) { + break; + } + } + /** + * If the lower overflow_size bytes are all zero, the counter has overflowed. + */ + if (i == crypter_counter->overflow_size) { + *is_overflow = true; + return GRPC_STATUS_FAILED_PRECONDITION; + } + *is_overflow = false; + return GRPC_STATUS_OK; +} + +size_t alts_counter_get_size(alts_counter* crypter_counter) { + if (crypter_counter == nullptr) { + return 0; + } + return crypter_counter->size; +} + +unsigned char* alts_counter_get_counter(alts_counter* crypter_counter) { + if (crypter_counter == nullptr) { + return nullptr; + } + return crypter_counter->counter; +} + +void alts_counter_destroy(alts_counter* crypter_counter) { + if (crypter_counter != nullptr) { + gpr_free(crypter_counter->counter); + gpr_free(crypter_counter); + } +} diff --git a/src/core/tsi/alts/frame_protector/alts_counter.h b/src/core/tsi/alts/frame_protector/alts_counter.h new file mode 100644 index 0000000000..d705638fa8 --- /dev/null +++ b/src/core/tsi/alts/frame_protector/alts_counter.h @@ -0,0 +1,98 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_COUNTER_H +#define GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_COUNTER_H + +#include + +#include +#include + +#include + +/* Main struct for a crypter counter managed within seal/unseal operations. */ +typedef struct alts_counter { + size_t size; + size_t overflow_size; + unsigned char* counter; +} alts_counter; + +/** + * This method creates and initializes an alts_counter instance. + * + * - is_client: a flag indicating if the alts_counter instance will be used + * at client (is_client = true) or server (is_client = false) side. + * - counter_size: size of buffer holding the counter value. + * - overflow_size: overflow size in bytes. The counter instance can be used + * to produce at most 2^(overflow_size*8) frames. + * - crypter_counter: an alts_counter instance to be returned from the method. + * - error_details: a buffer containing an error message if the method does not + * function correctly. It is legal to pass nullptr into error_details and + * otherwise, the parameter should be freed with gpr_free. + * + * On success, the method returns GRPC_STATUS_OK. Otherwise, + * it returns an error status code along with its details specified in + * error_details (if error_details is not nullptr). + */ +grpc_status_code alts_counter_create(bool is_client, size_t counter_size, + size_t overflow_size, + alts_counter** crypter_counter, + char** error_details); + +/** + * This method increments the internal counter. + * + * - crypter_counter: an alts_counter instance. + * - is_overflow: after incrementing the internal counter, if an overflow + * occurs, is_overflow is set to true, and no further calls to + * alts_counter_increment() should be made. Otherwise, is_overflow is set to + * false. + * - error_details: a buffer containing an error message if the method does not + * function correctly. It is legal to pass nullptr into error_details and + * otherwise, the parameter should be freed with gpr_free. + * + * On success, the method returns GRPC_STATUS_OK. Otherwise, + * it returns an error status code along with its details specified in + * error_details (if error_details is not nullptr). + */ +grpc_status_code alts_counter_increment(alts_counter* crypter_counter, + bool* is_overflow, + char** error_details); + +/** + * This method returns the size of counter buffer. + * + * - crypter_counter: an alts_counter instance. + */ +size_t alts_counter_get_size(alts_counter* crypter_counter); + +/** + * This method returns the counter buffer. + * + * - crypter_counter: an alts_counter instance. + */ +unsigned char* alts_counter_get_counter(alts_counter* crypter_counter); + +/** + * This method de-allocates all memory allocated to an alts_coutner instance. + * - crypter_counter: an alts_counter instance. + */ +void alts_counter_destroy(alts_counter* crypter_counter); + +#endif /* GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_COUNTER_H */ diff --git a/src/core/tsi/alts/frame_protector/alts_crypter.cc b/src/core/tsi/alts/frame_protector/alts_crypter.cc new file mode 100644 index 0000000000..56f0512186 --- /dev/null +++ b/src/core/tsi/alts/frame_protector/alts_crypter.cc @@ -0,0 +1,66 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/tsi/alts/frame_protector/alts_crypter.h" + +#include + +#include + +static void maybe_copy_error_msg(const char* src, char** dst) { + if (dst != nullptr && src != nullptr) { + *dst = static_cast(gpr_malloc(strlen(src) + 1)); + memcpy(*dst, src, strlen(src) + 1); + } +} + +grpc_status_code alts_crypter_process_in_place( + alts_crypter* crypter, unsigned char* data, size_t data_allocated_size, + size_t data_size, size_t* output_size, char** error_details) { + if (crypter != nullptr && crypter->vtable != nullptr && + crypter->vtable->process_in_place != nullptr) { + return crypter->vtable->process_in_place(crypter, data, data_allocated_size, + data_size, output_size, + error_details); + } + /* An error occurred. */ + const char error_msg[] = + "crypter or crypter->vtable has not been initialized properly."; + maybe_copy_error_msg(error_msg, error_details); + return GRPC_STATUS_INVALID_ARGUMENT; +} + +size_t alts_crypter_num_overhead_bytes(const alts_crypter* crypter) { + if (crypter != nullptr && crypter->vtable != nullptr && + crypter->vtable->num_overhead_bytes != nullptr) { + return crypter->vtable->num_overhead_bytes(crypter); + } + /* An error occurred. */ + return 0; +} + +void alts_crypter_destroy(alts_crypter* crypter) { + if (crypter != nullptr) { + if (crypter->vtable != nullptr && crypter->vtable->destruct != nullptr) { + crypter->vtable->destruct(crypter); + } + gpr_free(crypter); + } +} diff --git a/src/core/tsi/alts/frame_protector/alts_crypter.h b/src/core/tsi/alts/frame_protector/alts_crypter.h new file mode 100644 index 0000000000..3140778f4f --- /dev/null +++ b/src/core/tsi/alts/frame_protector/alts_crypter.h @@ -0,0 +1,255 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_CRYPTER_H +#define GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_CRYPTER_H + +#include + +#include +#include + +#include + +#include "src/core/tsi/alts/crypt/gsec.h" + +/** + * An alts_crypter interface for an ALTS record protocol providing + * seal/unseal functionality. The interface is thread-compatible. + */ + +typedef struct alts_crypter alts_crypter; + +/** + * A typical usage of the interface would be + *------------------------------------------------------------------------------ + * // Perform a seal operation. We assume the gsec_aead_crypter instance - + * // client_aead_crypter is created beforehand with a 16-byte key and 12-byte + * // nonce length. + * + * alts_crypter* client = nullptr; + * char* client_error_in_creation = nullptr; + * unsigned char* data = nullptr; + * grpc_status_code client_status = + * alts_seal_crypter_create(client_aead_crypter, 1, 5, &client, + * &client_error_in_creation); + * if (client_status == GRPC_STATUS_OK) { + * size_t data_size = 100; + * size_t num_overhead_bytes = alts_crypter_num_overhead_bytes(client); + * size_t data_allocated_size = data_size + num_overhead_bytes; + * data = gpr_malloc(data_allocated_size); + * char* client_error_in_seal = nullptr; + * // Client performs a seal operation. + * client_status = alts_crypter_process_in_place(client, data, + * data_allocated_size, + * &data_size, + * &client_error_in_seal); + * if (client_status != GRPC_STATUS_OK) { + * fprintf(stderr, "seal operation failed with error code:" + * "%d, message: %s\n", client_status, + * client_error_in_seal); + * } + * gpr_free(client_error_in_seal); + * } else { + * fprintf(stderr, "alts_crypter instance creation failed with error" + * "code: %d, message: %s\n", client_status, + * client_error_in_creation); + * } + * + * ... + * + * gpr_free(client_error_in_creation); + * alts_crypter_destroy(client); + * + * ... + * + * // Perform an unseal operation. We assume the gsec_aead_crypter instance - + * // server_aead_crypter is created beforehand with a 16-byte key and 12-byte + * // nonce length. The key used in the creation of gsec_aead_crypter instances + * // at server and client sides should be identical. + * + * alts_crypter* server = nullptr; + * char* server_error_in_creation = nullptr; + * grpc_status_code server_status = + * alts_unseal_crypter_create(server_aead_crypter, 0, 5, &server, + * &server_error_in_creation); + * if (server_status == GRPC_STATUS_OK) { + * size_t num_overhead_bytes = alts_crypter_num_overhead_bytes(server); + * size_t data_size = 100 + num_overhead_bytes; + * size_t data_allocated_size = data_size; + * char* server_error_in_unseal = nullptr; + * // Server performs an unseal operation. + * server_status = alts_crypter_process_in_place(server, data, + * data_allocated_size, + * &data_size, + * &server_error_in_unseal); + * if (server_status != GRPC_STATUS_OK) { + * fprintf(stderr, "unseal operation failed with error code:" + * "%d, message: %s\n", server_status, + * server_error_in_unseal); + * } + * gpr_free(server_error_in_unseal); + * } else { + * fprintf(stderr, "alts_crypter instance creation failed with error" + * "code: %d, message: %s\n", server_status, + * server_error_in_creation); + * } + * + * ... + * + * gpr_free(data); + * gpr_free(server_error_in_creation); + * alts_crypter_destroy(server); + * + * ... + *------------------------------------------------------------------------------ + */ + +/* V-table for alts_crypter operations */ +typedef struct alts_crypter_vtable { + size_t (*num_overhead_bytes)(const alts_crypter* crypter); + grpc_status_code (*process_in_place)(alts_crypter* crypter, + unsigned char* data, + size_t data_allocated_size, + size_t data_size, size_t* output_size, + char** error_details); + void (*destruct)(alts_crypter* crypter); +} alts_crypter_vtable; + +/* Main struct for alts_crypter interface */ +struct alts_crypter { + const alts_crypter_vtable* vtable; +}; + +/** + * This method gets the number of overhead bytes needed for sealing data that + * is the difference in size between the protected and raw data. The counter + * value used in a seal or unseal operation is locally maintained (not sent or + * received from the other peer) and therefore, will not be counted as part of + * overhead bytes. + * + * - crypter: an alts_crypter instance. + * + * On success, the method returns the number of overhead bytes. Otherwise, it + * returns zero. + * + */ +size_t alts_crypter_num_overhead_bytes(const alts_crypter* crypter); + +/** + * This method performs either a seal or an unseal operation depending on the + * alts_crypter instance - crypter passed to the method. If the crypter is + * an instance implementing a seal operation, the method will perform a seal + * operation. That is, it seals raw data and stores the result in-place, and the + * memory allocated for data must be at least data_length + + * alts_crypter_num_overhead_bytes(). If the crypter is an instance + * implementing an unseal operation, the method will perform an unseal + * operation. That is, it unseals protected data and stores the result in-place. + * The size of unsealed data will be data_length - + * alts_crypter_num_overhead_bytes(). Integrity tag will be verified during + * the unseal operation, and if verification fails, the data will be wiped. + * The counters used in both seal and unseal operations are managed internally. + * + * - crypter: an alts_crypter instance. + * - data: if the method performs a seal operation, the data represents raw data + * that needs to be sealed. It also plays the role of buffer to hold the + * protected data as a result of seal. If the method performs an unseal + * operation, the data represents protected data that needs to be unsealed. It + * also plays the role of buffer to hold raw data as a result of unseal. + * - data_allocated_size: the size of data buffer. The parameter is used to + * check whether the result of either seal or unseal can be safely written to + * the data buffer. + * - data_size: if the method performs a seal operation, data_size + * represents the size of raw data that needs to be sealed, and if the method + * performs an unseal operation, data_size represents the size of protected + * data that needs to be unsealed. + * - output_size: size of data written to the data buffer after a seal or an + * unseal operation. + * - error_details: a buffer containing an error message if the method does not + * function correctly. It is legal to pass nullptr into error_details and + * otherwise, the parameter should be freed with gpr_free. + * + * On success, the method returns GRPC_STATUS_OK. Otherwise, + * it returns an error status code along with its details specified in + * error_details (if error_details is not nullptr). + */ +grpc_status_code alts_crypter_process_in_place( + alts_crypter* crypter, unsigned char* data, size_t data_allocated_size, + size_t data_size, size_t* output_size, char** error_details); + +/** + * This method creates an alts_crypter instance to be used to perform a seal + * operation, given a gsec_aead_crypter instance and a flag indicating if the + * created instance will be used at the client or server side. It takes + * ownership of gsec_aead_crypter instance. + * + * - gc: a gsec_aead_crypter instance used to perform AEAD encryption. + * - is_client: a flag indicating if the alts_crypter instance will be + * used at the client (is_client = true) or server (is_client = + * false) side. + * - overflow_size: overflow size of counter in bytes. + * - crypter: an alts_crypter instance to be returned from the method. + * - error_details: a buffer containing an error message if the method does + * not function correctly. It is legal to pass nullptr into error_details, and + * otherwise, the parameter should be freed with gpr_free. + * + * On success of creation, the method returns GRPC_STATUS_OK. + * Otherwise, it returns an error status code along with its details specified + * in error_details (if error_details is not nullptr). + */ +grpc_status_code alts_seal_crypter_create(gsec_aead_crypter* gc, bool is_client, + size_t overflow_size, + alts_crypter** crypter, + char** error_details); + +/** + * This method creates an alts_crypter instance used to perform an unseal + * operation, given a gsec_aead_crypter instance and a flag indicating if the + * created instance will be used at the client or server side. It takes + * ownership of gsec_aead_crypter instance. + * + * - gc: a gsec_aead_crypter instance used to perform AEAD decryption. + * - is_client: a flag indicating if the alts_crypter instance will be + * used at the client (is_client = true) or server (is_client = + * false) side. + * - overflow_size: overflow size of counter in bytes. + * - crypter: an alts_crypter instance to be returned from the method. + * - error_details: a buffer containing an error message if the method does + * not function correctly. It is legal to pass nullptr into error_details, and + * otherwise, the parameter should be freed with gpr_free. + * + * On success of creation, the method returns GRPC_STATUS_OK. + * Otherwise, it returns an error status code along with its details specified + * in error_details (if error_details is not nullptr). + */ +grpc_status_code alts_unseal_crypter_create(gsec_aead_crypter* gc, + bool is_client, + size_t overflow_size, + alts_crypter** crypter, + char** error_details); + +/** + * This method destroys an alts_crypter instance by de-allocating all of its + * occupied memory. A gsec_aead_crypter instance passed in at alts_crypter + * instance creation time will be destroyed in this method. + * + * - crypter: an alts_crypter instance. + */ +void alts_crypter_destroy(alts_crypter* crypter); + +#endif /* GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_CRYPTER_H */ diff --git a/src/core/tsi/alts/frame_protector/alts_frame_protector.cc b/src/core/tsi/alts/frame_protector/alts_frame_protector.cc new file mode 100644 index 0000000000..bfa0b7a720 --- /dev/null +++ b/src/core/tsi/alts/frame_protector/alts_frame_protector.cc @@ -0,0 +1,407 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/tsi/alts/frame_protector/alts_frame_protector.h" + +#include +#include + +#include +#include + +#include "src/core/lib/gpr/useful.h" +#include "src/core/tsi/alts/crypt/gsec.h" +#include "src/core/tsi/alts/frame_protector/alts_crypter.h" +#include "src/core/tsi/alts/frame_protector/frame_handler.h" +#include "src/core/tsi/transport_security.h" + +constexpr size_t kMinFrameLength = 1024; +constexpr size_t kDefaultFrameLength = 16 * 1024; +constexpr size_t kMaxFrameLength = 1024 * 1024; + +// Limit k on number of frames such that at most 2^(8 * k) frames can be sent. +constexpr size_t kAltsRecordProtocolRekeyFrameLimit = 8; +constexpr size_t kAltsRecordProtocolFrameLimit = 5; + +/* Main struct for alts_frame_protector. */ +struct alts_frame_protector { + tsi_frame_protector base; + alts_crypter* seal_crypter; + alts_crypter* unseal_crypter; + alts_frame_writer* writer; + alts_frame_reader* reader; + unsigned char* in_place_protect_buffer; + unsigned char* in_place_unprotect_buffer; + size_t in_place_protect_bytes_buffered; + size_t in_place_unprotect_bytes_processed; + size_t max_protected_frame_size; + size_t max_unprotected_frame_size; + size_t overhead_length; + size_t counter_overflow; +}; + +static tsi_result seal(alts_frame_protector* impl) { + char* error_details = nullptr; + size_t output_size = 0; + grpc_status_code status = alts_crypter_process_in_place( + impl->seal_crypter, impl->in_place_protect_buffer, + impl->max_protected_frame_size, impl->in_place_protect_bytes_buffered, + &output_size, &error_details); + impl->in_place_protect_bytes_buffered = output_size; + if (status != GRPC_STATUS_OK) { + gpr_log(GPR_ERROR, "%s", error_details); + gpr_free(error_details); + return TSI_INTERNAL_ERROR; + } + return TSI_OK; +} + +static size_t max_encrypted_payload_bytes(alts_frame_protector* impl) { + return impl->max_protected_frame_size - kFrameHeaderSize; +} + +static tsi_result alts_protect_flush(tsi_frame_protector* self, + unsigned char* protected_output_frames, + size_t* protected_output_frames_size, + size_t* still_pending_size) { + if (self == nullptr || protected_output_frames == nullptr || + protected_output_frames_size == nullptr || + still_pending_size == nullptr) { + gpr_log(GPR_ERROR, "Invalid nullptr arguments to alts_protect_flush()."); + return TSI_INVALID_ARGUMENT; + } + alts_frame_protector* impl = reinterpret_cast(self); + /** + * If there's nothing to flush (i.e., in_place_protect_buffer is empty), + * we're done. + */ + if (impl->in_place_protect_bytes_buffered == 0) { + *protected_output_frames_size = 0; + *still_pending_size = 0; + return TSI_OK; + } + /** + * If a new frame can start being processed, we encrypt the payload and reset + * the frame writer to point to in_place_protect_buffer that holds the newly + * sealed frame. + */ + if (alts_is_frame_writer_done(impl->writer)) { + tsi_result result = seal(impl); + if (result != TSI_OK) { + return result; + } + if (!alts_reset_frame_writer(impl->writer, impl->in_place_protect_buffer, + impl->in_place_protect_bytes_buffered)) { + gpr_log(GPR_ERROR, "Couldn't reset frame writer."); + return TSI_INTERNAL_ERROR; + } + } + /** + * Write the sealed frame as much as possible to protected_output_frames. It's + * possible a frame will not be written out completely by a single flush + * (i.e., still_pending_size != 0), in which case the flush should be called + * iteratively until a complete frame has been written out. + */ + size_t written_frame_bytes = *protected_output_frames_size; + if (!alts_write_frame_bytes(impl->writer, protected_output_frames, + &written_frame_bytes)) { + gpr_log(GPR_ERROR, "Couldn't write frame bytes."); + return TSI_INTERNAL_ERROR; + } + *protected_output_frames_size = written_frame_bytes; + *still_pending_size = alts_get_num_writer_bytes_remaining(impl->writer); + /** + * If the current frame has been finished processing (i.e., sealed and written + * out completely), we empty in_place_protect_buffer. + */ + if (alts_is_frame_writer_done(impl->writer)) { + impl->in_place_protect_bytes_buffered = 0; + } + return TSI_OK; +} + +static tsi_result alts_protect(tsi_frame_protector* self, + const unsigned char* unprotected_bytes, + size_t* unprotected_bytes_size, + unsigned char* protected_output_frames, + size_t* protected_output_frames_size) { + if (self == nullptr || unprotected_bytes == nullptr || + unprotected_bytes_size == nullptr || protected_output_frames == nullptr || + protected_output_frames_size == nullptr) { + gpr_log(GPR_ERROR, "Invalid nullptr arguments to alts_protect()."); + return TSI_INVALID_ARGUMENT; + } + alts_frame_protector* impl = reinterpret_cast(self); + + /** + * If more payload can be buffered, we buffer it as much as possible to + * in_place_protect_buffer. + */ + if (impl->in_place_protect_bytes_buffered + impl->overhead_length < + max_encrypted_payload_bytes(impl)) { + size_t bytes_to_buffer = GPR_MIN(*unprotected_bytes_size, + max_encrypted_payload_bytes(impl) - + impl->in_place_protect_bytes_buffered - + impl->overhead_length); + *unprotected_bytes_size = bytes_to_buffer; + if (bytes_to_buffer > 0) { + memcpy( + impl->in_place_protect_buffer + impl->in_place_protect_bytes_buffered, + unprotected_bytes, bytes_to_buffer); + impl->in_place_protect_bytes_buffered += bytes_to_buffer; + } + } else { + *unprotected_bytes_size = 0; + } + /** + * If a full frame has been buffered, we output it. If the first condition + * holds, then there exists an unencrypted full frame. If the second + * condition holds, then there exists a full frame that has already been + * encrypted. + */ + if (max_encrypted_payload_bytes(impl) == + impl->in_place_protect_bytes_buffered + impl->overhead_length || + max_encrypted_payload_bytes(impl) == + impl->in_place_protect_bytes_buffered) { + size_t still_pending_size = 0; + return alts_protect_flush(self, protected_output_frames, + protected_output_frames_size, + &still_pending_size); + } else { + *protected_output_frames_size = 0; + return TSI_OK; + } +} + +static tsi_result unseal(alts_frame_protector* impl) { + char* error_details = nullptr; + size_t output_size = 0; + grpc_status_code status = alts_crypter_process_in_place( + impl->unseal_crypter, impl->in_place_unprotect_buffer, + impl->max_unprotected_frame_size, + alts_get_output_bytes_read(impl->reader), &output_size, &error_details); + if (status != GRPC_STATUS_OK) { + gpr_log(GPR_ERROR, "%s", error_details); + gpr_free(error_details); + return TSI_DATA_CORRUPTED; + } + return TSI_OK; +} + +static void ensure_buffer_size(alts_frame_protector* impl) { + if (!alts_has_read_frame_length(impl->reader)) { + return; + } + size_t buffer_space_remaining = impl->max_unprotected_frame_size - + alts_get_output_bytes_read(impl->reader); + /** + * Check if we need to resize in_place_unprotect_buffer in order to hold + * remaining bytes of a full frame. + */ + if (buffer_space_remaining < alts_get_reader_bytes_remaining(impl->reader)) { + size_t buffer_len = alts_get_output_bytes_read(impl->reader) + + alts_get_reader_bytes_remaining(impl->reader); + unsigned char* buffer = static_cast(gpr_malloc(buffer_len)); + memcpy(buffer, impl->in_place_unprotect_buffer, + alts_get_output_bytes_read(impl->reader)); + impl->max_unprotected_frame_size = buffer_len; + gpr_free(impl->in_place_unprotect_buffer); + impl->in_place_unprotect_buffer = buffer; + alts_reset_reader_output_buffer( + impl->reader, buffer + alts_get_output_bytes_read(impl->reader)); + } +} + +static tsi_result alts_unprotect(tsi_frame_protector* self, + const unsigned char* protected_frames_bytes, + size_t* protected_frames_bytes_size, + unsigned char* unprotected_bytes, + size_t* unprotected_bytes_size) { + if (self == nullptr || protected_frames_bytes == nullptr || + protected_frames_bytes_size == nullptr || unprotected_bytes == nullptr || + unprotected_bytes_size == nullptr) { + gpr_log(GPR_ERROR, "Invalid nullptr arguments to alts_unprotect()."); + return TSI_INVALID_ARGUMENT; + } + alts_frame_protector* impl = reinterpret_cast(self); + /** + * If a new frame can start being processed, we reset the frame reader to + * point to in_place_unprotect_buffer that will be used to hold deframed + * result. + */ + if (alts_is_frame_reader_done(impl->reader) && + ((alts_get_output_buffer(impl->reader) == nullptr) || + (alts_get_output_bytes_read(impl->reader) == + impl->in_place_unprotect_bytes_processed + impl->overhead_length))) { + if (!alts_reset_frame_reader(impl->reader, + impl->in_place_unprotect_buffer)) { + gpr_log(GPR_ERROR, "Couldn't reset frame reader."); + return TSI_INTERNAL_ERROR; + } + impl->in_place_unprotect_bytes_processed = 0; + } + /** + * If a full frame has not yet been read, we read more bytes from + * protected_frames_bytes until a full frame has been read. We also need to + * make sure in_place_unprotect_buffer is large enough to hold a complete + * frame. + */ + if (!alts_is_frame_reader_done(impl->reader)) { + ensure_buffer_size(impl); + *protected_frames_bytes_size = + GPR_MIN(impl->max_unprotected_frame_size - + alts_get_output_bytes_read(impl->reader), + *protected_frames_bytes_size); + size_t read_frames_bytes_size = *protected_frames_bytes_size; + if (!alts_read_frame_bytes(impl->reader, protected_frames_bytes, + &read_frames_bytes_size)) { + gpr_log(GPR_ERROR, "Failed to process frame."); + return TSI_INTERNAL_ERROR; + } + *protected_frames_bytes_size = read_frames_bytes_size; + } else { + *protected_frames_bytes_size = 0; + } + /** + * If a full frame has been read, we unseal it, and write out the + * deframed result to unprotected_bytes. + */ + if (alts_is_frame_reader_done(impl->reader)) { + if (impl->in_place_unprotect_bytes_processed == 0) { + tsi_result result = unseal(impl); + if (result != TSI_OK) { + return result; + } + } + size_t bytes_to_write = GPR_MIN( + *unprotected_bytes_size, alts_get_output_bytes_read(impl->reader) - + impl->in_place_unprotect_bytes_processed - + impl->overhead_length); + if (bytes_to_write > 0) { + memcpy(unprotected_bytes, + impl->in_place_unprotect_buffer + + impl->in_place_unprotect_bytes_processed, + bytes_to_write); + } + *unprotected_bytes_size = bytes_to_write; + impl->in_place_unprotect_bytes_processed += bytes_to_write; + return TSI_OK; + } else { + *unprotected_bytes_size = 0; + return TSI_OK; + } +} + +static void alts_destroy(tsi_frame_protector* self) { + alts_frame_protector* impl = reinterpret_cast(self); + if (impl != nullptr) { + alts_crypter_destroy(impl->seal_crypter); + alts_crypter_destroy(impl->unseal_crypter); + gpr_free(impl->in_place_protect_buffer); + gpr_free(impl->in_place_unprotect_buffer); + alts_destroy_frame_writer(impl->writer); + alts_destroy_frame_reader(impl->reader); + gpr_free(impl); + } +} + +static const tsi_frame_protector_vtable alts_frame_protector_vtable = { + alts_protect, alts_protect_flush, alts_unprotect, alts_destroy}; + +static grpc_status_code create_alts_crypters(const uint8_t* key, + size_t key_size, bool is_client, + bool is_rekey, + alts_frame_protector* impl, + char** error_details) { + grpc_status_code status; + gsec_aead_crypter* aead_crypter_seal = nullptr; + gsec_aead_crypter* aead_crypter_unseal = nullptr; + status = gsec_aes_gcm_aead_crypter_create(key, key_size, kAesGcmNonceLength, + kAesGcmTagLength, is_rekey, + &aead_crypter_seal, error_details); + if (status != GRPC_STATUS_OK) { + return status; + } + status = gsec_aes_gcm_aead_crypter_create( + key, key_size, kAesGcmNonceLength, kAesGcmTagLength, is_rekey, + &aead_crypter_unseal, error_details); + if (status != GRPC_STATUS_OK) { + return status; + } + size_t overflow_size = is_rekey ? kAltsRecordProtocolRekeyFrameLimit + : kAltsRecordProtocolFrameLimit; + status = alts_seal_crypter_create(aead_crypter_seal, is_client, overflow_size, + &impl->seal_crypter, error_details); + if (status != GRPC_STATUS_OK) { + return status; + } + status = + alts_unseal_crypter_create(aead_crypter_unseal, is_client, overflow_size, + &impl->unseal_crypter, error_details); + return status; +} + +tsi_result alts_create_frame_protector(const uint8_t* key, size_t key_size, + bool is_client, bool is_rekey, + size_t* max_protected_frame_size, + tsi_frame_protector** self) { + if (key == nullptr || self == nullptr) { + gpr_log(GPR_ERROR, + "Invalid nullptr arguments to alts_create_frame_protector()."); + return TSI_INTERNAL_ERROR; + } + char* error_details = nullptr; + alts_frame_protector* impl = + static_cast(gpr_zalloc(sizeof(*impl))); + grpc_status_code status = create_alts_crypters( + key, key_size, is_client, is_rekey, impl, &error_details); + if (status != GRPC_STATUS_OK) { + gpr_log(GPR_ERROR, "Failed to create ALTS crypters, %s.", error_details); + gpr_free(error_details); + return TSI_INTERNAL_ERROR; + } + /** + * Set maximum frame size to be used by a frame protector. If it is nullptr, a + * default frame size will be used. Otherwise, the provided frame size will be + * adjusted (if not falling into a valid frame range) and used. + */ + size_t max_protected_frame_size_to_set = kDefaultFrameLength; + if (max_protected_frame_size != nullptr) { + *max_protected_frame_size = + GPR_MIN(*max_protected_frame_size, kMaxFrameLength); + *max_protected_frame_size = + GPR_MAX(*max_protected_frame_size, kMinFrameLength); + max_protected_frame_size_to_set = *max_protected_frame_size; + } + impl->max_protected_frame_size = max_protected_frame_size_to_set; + impl->max_unprotected_frame_size = max_protected_frame_size_to_set; + impl->in_place_protect_bytes_buffered = 0; + impl->in_place_unprotect_bytes_processed = 0; + impl->in_place_protect_buffer = static_cast( + gpr_malloc(sizeof(unsigned char) * max_protected_frame_size_to_set)); + impl->in_place_unprotect_buffer = static_cast( + gpr_malloc(sizeof(unsigned char) * max_protected_frame_size_to_set)); + impl->overhead_length = alts_crypter_num_overhead_bytes(impl->seal_crypter); + impl->writer = alts_create_frame_writer(); + impl->reader = alts_create_frame_reader(); + impl->base.vtable = &alts_frame_protector_vtable; + *self = &impl->base; + return TSI_OK; +} diff --git a/src/core/tsi/alts/frame_protector/alts_frame_protector.h b/src/core/tsi/alts/frame_protector/alts_frame_protector.h new file mode 100644 index 0000000000..321bffaed8 --- /dev/null +++ b/src/core/tsi/alts/frame_protector/alts_frame_protector.h @@ -0,0 +1,55 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_FRAME_PROTECTOR_H +#define GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_FRAME_PROTECTOR_H + +#include + +#include + +#include "src/core/tsi/transport_security_interface.h" + +typedef struct alts_frame_protector alts_frame_protector; + +/** + * TODO: Add a parameter to the interface to support the use of + * different record protocols within a frame protector. + * + * This method creates a frame protector. + * + * - key: a symmetric key used to seal/unseal frames. + * - key_size: the size of symmetric key. + * - is_client: a flag indicating if the frame protector will be used at client + * (is_client = true) or server (is_client = false) side. + * - is_rekey: a flag indicating if the frame protector will use an AEAD with + * rekeying. + * - max_protected_frame_size: an in/out parameter indicating max frame size + * to be used by the frame protector. If it is nullptr, the default frame + * size will be used. Otherwise, the provided frame size will be adjusted (if + * not falling into a valid frame range) and used. + * - self: a pointer to the frame protector returned from the method. + * + * This method returns TSI_OK on success and TSI_INTERNAL_ERROR otherwise. + */ +tsi_result alts_create_frame_protector(const uint8_t* key, size_t key_size, + bool is_client, bool is_rekey, + size_t* max_protected_frame_size, + tsi_frame_protector** self); + +#endif /* GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_FRAME_PROTECTOR_H */ diff --git a/src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc b/src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc new file mode 100644 index 0000000000..0574ed5012 --- /dev/null +++ b/src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc @@ -0,0 +1,114 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h" + +#include + +static void maybe_copy_error_msg(const char* src, char** dst) { + if (dst != nullptr && src != nullptr) { + *dst = static_cast(gpr_malloc(strlen(src) + 1)); + memcpy(*dst, src, strlen(src) + 1); + } +} + +grpc_status_code input_sanity_check( + const alts_record_protocol_crypter* rp_crypter, const unsigned char* data, + size_t* output_size, char** error_details) { + if (rp_crypter == nullptr) { + maybe_copy_error_msg("alts_crypter instance is nullptr.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } else if (data == nullptr) { + maybe_copy_error_msg("data is nullptr.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } else if (output_size == nullptr) { + maybe_copy_error_msg("output_size is nullptr.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + return GRPC_STATUS_OK; +} + +grpc_status_code increment_counter(alts_record_protocol_crypter* rp_crypter, + char** error_details) { + bool is_overflow = false; + grpc_status_code status = + alts_counter_increment(rp_crypter->ctr, &is_overflow, error_details); + if (status != GRPC_STATUS_OK) { + return status; + } + if (is_overflow) { + const char error_msg[] = + "crypter counter is wrapped. The connection" + "should be closed and the key should be deleted."; + maybe_copy_error_msg(error_msg, error_details); + return GRPC_STATUS_INTERNAL; + } + return GRPC_STATUS_OK; +} + +size_t alts_record_protocol_crypter_num_overhead_bytes(const alts_crypter* c) { + if (c != nullptr) { + size_t num_overhead_bytes = 0; + char* error_details = nullptr; + const alts_record_protocol_crypter* rp_crypter = + reinterpret_cast(c); + grpc_status_code status = gsec_aead_crypter_tag_length( + rp_crypter->crypter, &num_overhead_bytes, &error_details); + if (status == GRPC_STATUS_OK) { + return num_overhead_bytes; + } + } + return 0; +} + +void alts_record_protocol_crypter_destruct(alts_crypter* c) { + if (c != nullptr) { + alts_record_protocol_crypter* rp_crypter = + reinterpret_cast(c); + alts_counter_destroy(rp_crypter->ctr); + gsec_aead_crypter_destroy(rp_crypter->crypter); + } +} + +alts_record_protocol_crypter* alts_crypter_create_common( + gsec_aead_crypter* crypter, bool is_client, size_t overflow_size, + char** error_details) { + if (crypter != nullptr) { + auto* rp_crypter = static_cast( + gpr_malloc(sizeof(alts_record_protocol_crypter))); + size_t counter_size = 0; + grpc_status_code status = + gsec_aead_crypter_nonce_length(crypter, &counter_size, error_details); + if (status != GRPC_STATUS_OK) { + return nullptr; + } + /* Create a counter. */ + status = alts_counter_create(is_client, counter_size, overflow_size, + &rp_crypter->ctr, error_details); + if (status != GRPC_STATUS_OK) { + return nullptr; + } + rp_crypter->crypter = crypter; + return rp_crypter; + } + const char error_msg[] = "crypter is nullptr."; + maybe_copy_error_msg(error_msg, error_details); + return nullptr; +} diff --git a/src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h b/src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h new file mode 100644 index 0000000000..682a8f7e7a --- /dev/null +++ b/src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h @@ -0,0 +1,114 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_RECORD_PROTOCOL_CRYPTER_COMMON_H +#define GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_RECORD_PROTOCOL_CRYPTER_COMMON_H + +#include + +#include + +#include "src/core/tsi/alts/frame_protector/alts_counter.h" +#include "src/core/tsi/alts/frame_protector/alts_crypter.h" + +/** + * This file contains common implementation that will be used in both seal and + * unseal operations. + */ + +/** + * Main struct for alts_record_protocol_crypter that will be used in both + * seal and unseal operations. + */ +typedef struct alts_record_protocol_crypter { + alts_crypter base; + gsec_aead_crypter* crypter; + alts_counter* ctr; +} alts_record_protocol_crypter; + +/** + * This method performs input sanity checks on a subset of inputs to + * alts_crypter_process_in_place() for both seal and unseal operations. + * + * - rp_crypter: an alts_record_protocol_crypter instance. + * - data: it represents raw data that needs to be sealed in a seal operation or + * protected data that needs to be unsealed in an unseal operation. + * - output_size: size of data written to the data buffer after a seal or + * unseal operation. + * - error_details: a buffer containing an error message if any of checked + * inputs is nullptr. It is legal to pass nullptr into error_details and + * otherwise, the parameter should be freed with gpr_free. + * + * On success, the method returns GRPC_STATUS_OK. Otherwise, + * it returns an error status code along with its details specified in + * error_details (if error_details is not nullptr). + */ +grpc_status_code input_sanity_check( + const alts_record_protocol_crypter* rp_crypter, const unsigned char* data, + size_t* output_size, char** error_details); + +/** + * This method increments the counter within an alts_record_protocol_crypter + * instance. + * + * - rp_crypter: an alts_record_protocol_crypter instance. + * - error_details: a buffer containing an error message if the method does not + * function correctly or the counter is wrapped. It is legal to pass nullptr + * into error_details and otherwise, the parameter should be freed with + * gpr_free. + * + * On success, the method returns GRPC_STATUS_OK. Otherwise, + * it returns an error status code along with its details specified in + * error_details (if error_details is not nullptr). + */ +grpc_status_code increment_counter(alts_record_protocol_crypter* rp_crypter, + char** error_details); + +/** + * This method creates an alts_crypter instance, and populates the fields + * that are common to both seal and unseal operations. + * + * - crypter: a gsec_aead_crypter instance used to perform AEAD decryption. The + * function does not take ownership of crypter. + * - is_client: a flag indicating if the alts_crypter instance will be + * used at the client (is_client = true) or server (is_client = + * false) side. + * - overflow_size: overflow size of counter in bytes. + * - error_details: a buffer containing an error message if the method does + * not function correctly. It is legal to pass nullptr into error_details, and + * otherwise, the parameter should be freed with gpr_free. + * + * On success of creation, the method returns alts_record_protocol_crypter + * instance. Otherwise, it returns nullptr with its details specified in + * error_details (if error_details is not nullptr). + * + */ +alts_record_protocol_crypter* alts_crypter_create_common( + gsec_aead_crypter* crypter, bool is_client, size_t overflow_size, + char** error_details); + +/** + * For the following two methods, please refer to the corresponding API in + * alts_crypter.h for detailed specifications. + */ +size_t alts_record_protocol_crypter_num_overhead_bytes(const alts_crypter* c); + +void alts_record_protocol_crypter_destruct(alts_crypter* c); + +#endif /* GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_RECORD_PROTOCOL_CRYPTER_COMMON_H \ + */ diff --git a/src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc b/src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc new file mode 100644 index 0000000000..f407831613 --- /dev/null +++ b/src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc @@ -0,0 +1,105 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include + +#include "src/core/tsi/alts/frame_protector/alts_counter.h" +#include "src/core/tsi/alts/frame_protector/alts_crypter.h" +#include "src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h" + +static void maybe_copy_error_msg(const char* src, char** dst) { + if (dst != nullptr && src != nullptr) { + *dst = static_cast(gpr_malloc(strlen(src) + 1)); + memcpy(*dst, src, strlen(src) + 1); + } +} + +/* Perform input santity check for a seal operation. */ +static grpc_status_code seal_check(alts_crypter* c, const unsigned char* data, + size_t data_allocated_size, size_t data_size, + size_t* output_size, char** error_details) { + /* Do common input sanity check. */ + grpc_status_code status = input_sanity_check( + reinterpret_cast(c), data, + output_size, error_details); + if (status != GRPC_STATUS_OK) return status; + /* Do seal-specific check. */ + size_t num_overhead_bytes = + alts_crypter_num_overhead_bytes(reinterpret_cast(c)); + if (data_size == 0) { + const char error_msg[] = "data_size is zero."; + maybe_copy_error_msg(error_msg, error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + if (data_size + num_overhead_bytes > data_allocated_size) { + const char error_msg[] = + "data_allocated_size is smaller than sum of data_size and " + "num_overhead_bytes."; + maybe_copy_error_msg(error_msg, error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + return GRPC_STATUS_OK; +} + +static grpc_status_code alts_seal_crypter_process_in_place( + alts_crypter* c, unsigned char* data, size_t data_allocated_size, + size_t data_size, size_t* output_size, char** error_details) { + grpc_status_code status = seal_check(c, data, data_allocated_size, data_size, + output_size, error_details); + if (status != GRPC_STATUS_OK) { + return status; + } + /* Do AEAD encryption. */ + alts_record_protocol_crypter* rp_crypter = + reinterpret_cast(c); + status = gsec_aead_crypter_encrypt( + rp_crypter->crypter, alts_counter_get_counter(rp_crypter->ctr), + alts_counter_get_size(rp_crypter->ctr), nullptr /* aad */, + 0 /* aad_length */, data, data_size, data, data_allocated_size, + output_size, error_details); + if (status != GRPC_STATUS_OK) { + return status; + } + /* Increment the crypter counter. */ + return increment_counter(rp_crypter, error_details); +} + +static const alts_crypter_vtable vtable = { + alts_record_protocol_crypter_num_overhead_bytes, + alts_seal_crypter_process_in_place, alts_record_protocol_crypter_destruct}; + +grpc_status_code alts_seal_crypter_create(gsec_aead_crypter* gc, bool is_client, + size_t overflow_size, + alts_crypter** crypter, + char** error_details) { + if (crypter == nullptr) { + const char error_msg[] = "crypter is nullptr."; + maybe_copy_error_msg(error_msg, error_details); + return GRPC_STATUS_FAILED_PRECONDITION; + } + alts_record_protocol_crypter* rp_crypter = + alts_crypter_create_common(gc, !is_client, overflow_size, error_details); + if (rp_crypter == nullptr) { + return GRPC_STATUS_FAILED_PRECONDITION; + } + rp_crypter->base.vtable = &vtable; + *crypter = &rp_crypter->base; + return GRPC_STATUS_OK; +} diff --git a/src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc b/src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc new file mode 100644 index 0000000000..51bea24f1f --- /dev/null +++ b/src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc @@ -0,0 +1,103 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include + +#include "src/core/tsi/alts/frame_protector/alts_counter.h" +#include "src/core/tsi/alts/frame_protector/alts_crypter.h" +#include "src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h" + +static void maybe_copy_error_msg(const char* src, char** dst) { + if (dst != nullptr && src != nullptr) { + *dst = static_cast(gpr_malloc(strlen(src) + 1)); + memcpy(*dst, src, strlen(src) + 1); + } +} + +/* Perform input santity check. */ +static grpc_status_code unseal_check(alts_crypter* c, const unsigned char* data, + size_t data_allocated_size, + size_t data_size, size_t* output_size, + char** error_details) { + /* Do common input sanity check. */ + grpc_status_code status = input_sanity_check( + reinterpret_cast(c), data, + output_size, error_details); + if (status != GRPC_STATUS_OK) { + return status; + } + /* Do unseal-specific input check. */ + size_t num_overhead_bytes = + alts_crypter_num_overhead_bytes(reinterpret_cast(c)); + if (num_overhead_bytes > data_size) { + const char error_msg[] = "data_size is smaller than num_overhead_bytes."; + maybe_copy_error_msg(error_msg, error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + return GRPC_STATUS_OK; +} + +static grpc_status_code alts_unseal_crypter_process_in_place( + alts_crypter* c, unsigned char* data, size_t data_allocated_size, + size_t data_size, size_t* output_size, char** error_details) { + grpc_status_code status = unseal_check(c, data, data_allocated_size, + data_size, output_size, error_details); + if (status != GRPC_STATUS_OK) { + return status; + } + /* Do AEAD decryption. */ + alts_record_protocol_crypter* rp_crypter = + reinterpret_cast(c); + status = gsec_aead_crypter_decrypt( + rp_crypter->crypter, alts_counter_get_counter(rp_crypter->ctr), + alts_counter_get_size(rp_crypter->ctr), nullptr /* aad */, + 0 /* aad_length */, data, data_size, data, data_allocated_size, + output_size, error_details); + if (status != GRPC_STATUS_OK) { + return status; + } + /* Increment the crypter counter. */ + return increment_counter(rp_crypter, error_details); +} + +static const alts_crypter_vtable vtable = { + alts_record_protocol_crypter_num_overhead_bytes, + alts_unseal_crypter_process_in_place, + alts_record_protocol_crypter_destruct}; + +grpc_status_code alts_unseal_crypter_create(gsec_aead_crypter* gc, + bool is_client, + size_t overflow_size, + alts_crypter** crypter, + char** error_details) { + if (crypter == nullptr) { + const char error_msg[] = "crypter is nullptr."; + maybe_copy_error_msg(error_msg, error_details); + return GRPC_STATUS_FAILED_PRECONDITION; + } + alts_record_protocol_crypter* rp_crypter = + alts_crypter_create_common(gc, is_client, overflow_size, error_details); + if (rp_crypter == nullptr) { + return GRPC_STATUS_FAILED_PRECONDITION; + } + rp_crypter->base.vtable = &vtable; + *crypter = &rp_crypter->base; + return GRPC_STATUS_OK; +} diff --git a/src/core/tsi/alts/frame_protector/frame_handler.cc b/src/core/tsi/alts/frame_protector/frame_handler.cc new file mode 100644 index 0000000000..d3fda63b3d --- /dev/null +++ b/src/core/tsi/alts/frame_protector/frame_handler.cc @@ -0,0 +1,218 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/tsi/alts/frame_protector/frame_handler.h" + +#include +#include +#include + +#include +#include + +#include "src/core/lib/gpr/useful.h" + +/* Use little endian to interpret a string of bytes as uint32_t. */ +static uint32_t load_32_le(const unsigned char* buffer) { + return (((uint32_t)buffer[3]) << 24) | (((uint32_t)buffer[2]) << 16) | + (((uint32_t)buffer[1]) << 8) | ((uint32_t)buffer[0]); +} + +/* Store uint32_t as a string of little endian bytes. */ +static void store_32_le(uint32_t value, unsigned char* buffer) { + buffer[3] = (unsigned char)(value >> 24) & 0xFF; + buffer[2] = (unsigned char)(value >> 16) & 0xFF; + buffer[1] = (unsigned char)(value >> 8) & 0xFF; + buffer[0] = (unsigned char)(value)&0xFF; +} + +/* Frame writer implementation. */ +alts_frame_writer* alts_create_frame_writer() { + alts_frame_writer* writer = + static_cast(gpr_zalloc(sizeof(*writer))); + return writer; +} + +bool alts_reset_frame_writer(alts_frame_writer* writer, + const unsigned char* buffer, size_t length) { + if (buffer == nullptr) return false; + size_t max_input_size = SIZE_MAX - kFrameLengthFieldSize; + if (length > max_input_size) { + gpr_log(GPR_ERROR, "length must be at most %zu", max_input_size); + return false; + } + writer->input_buffer = buffer; + writer->input_size = length; + writer->input_bytes_written = 0; + writer->header_bytes_written = 0; + store_32_le( + static_cast(writer->input_size + kFrameMessageTypeFieldSize), + writer->header_buffer); + store_32_le(kFrameMessageType, writer->header_buffer + kFrameLengthFieldSize); + return true; +} + +bool alts_write_frame_bytes(alts_frame_writer* writer, unsigned char* output, + size_t* bytes_size) { + if (bytes_size == nullptr || output == nullptr) return false; + if (alts_is_frame_writer_done(writer)) { + *bytes_size = 0; + return true; + } + size_t bytes_written = 0; + /* Write some header bytes, if needed. */ + if (writer->header_bytes_written != sizeof(writer->header_buffer)) { + size_t bytes_to_write = + GPR_MIN(*bytes_size, + sizeof(writer->header_buffer) - writer->header_bytes_written); + memcpy(output, writer->header_buffer + writer->header_bytes_written, + bytes_to_write); + bytes_written += bytes_to_write; + *bytes_size -= bytes_to_write; + writer->header_bytes_written += bytes_to_write; + output += bytes_to_write; + if (writer->header_bytes_written != sizeof(writer->header_buffer)) { + *bytes_size = bytes_written; + return true; + } + } + /* Write some non-header bytes. */ + size_t bytes_to_write = + GPR_MIN(writer->input_size - writer->input_bytes_written, *bytes_size); + memcpy(output, writer->input_buffer, bytes_to_write); + writer->input_buffer += bytes_to_write; + bytes_written += bytes_to_write; + writer->input_bytes_written += bytes_to_write; + *bytes_size = bytes_written; + return true; +} + +bool alts_is_frame_writer_done(alts_frame_writer* writer) { + return writer->input_buffer == nullptr || + writer->input_size == writer->input_bytes_written; +} + +size_t alts_get_num_writer_bytes_remaining(alts_frame_writer* writer) { + return (sizeof(writer->header_buffer) - writer->header_bytes_written) + + (writer->input_size - writer->input_bytes_written); +} + +void alts_destroy_frame_writer(alts_frame_writer* writer) { gpr_free(writer); } + +/* Frame reader implementation. */ +alts_frame_reader* alts_create_frame_reader() { + alts_frame_reader* reader = + static_cast(gpr_zalloc(sizeof(*reader))); + return reader; +} + +bool alts_is_frame_reader_done(alts_frame_reader* reader) { + return reader->output_buffer == nullptr || + (reader->header_bytes_read == sizeof(reader->header_buffer) && + reader->bytes_remaining == 0); +} + +bool alts_has_read_frame_length(alts_frame_reader* reader) { + return sizeof(reader->header_buffer) == reader->header_bytes_read; +} + +size_t alts_get_reader_bytes_remaining(alts_frame_reader* reader) { + return alts_has_read_frame_length(reader) ? reader->bytes_remaining : 0; +} + +void alts_reset_reader_output_buffer(alts_frame_reader* reader, + unsigned char* buffer) { + reader->output_buffer = buffer; +} + +bool alts_reset_frame_reader(alts_frame_reader* reader, unsigned char* buffer) { + if (buffer == nullptr) return false; + reader->output_buffer = buffer; + reader->bytes_remaining = 0; + reader->header_bytes_read = 0; + reader->output_bytes_read = 0; + return true; +} + +bool alts_read_frame_bytes(alts_frame_reader* reader, + const unsigned char* bytes, size_t* bytes_size) { + if (bytes_size == nullptr) return false; + if (bytes == nullptr) { + *bytes_size = 0; + return false; + } + if (alts_is_frame_reader_done(reader)) { + *bytes_size = 0; + return true; + } + size_t bytes_processed = 0; + /* Process the header, if needed. */ + if (reader->header_bytes_read != sizeof(reader->header_buffer)) { + size_t bytes_to_write = GPR_MIN( + *bytes_size, sizeof(reader->header_buffer) - reader->header_bytes_read); + memcpy(reader->header_buffer + reader->header_bytes_read, bytes, + bytes_to_write); + reader->header_bytes_read += bytes_to_write; + bytes_processed += bytes_to_write; + bytes += bytes_to_write; + *bytes_size -= bytes_to_write; + if (reader->header_bytes_read != sizeof(reader->header_buffer)) { + *bytes_size = bytes_processed; + return true; + } + size_t frame_length = load_32_le(reader->header_buffer); + if (frame_length < kFrameMessageTypeFieldSize || + frame_length > kFrameMaxSize) { + gpr_log(GPR_ERROR, + "Bad frame length (should be at least %zu, and at most %zu)", + kFrameMessageTypeFieldSize, kFrameMaxSize); + *bytes_size = 0; + return false; + } + size_t message_type = + load_32_le(reader->header_buffer + kFrameLengthFieldSize); + if (message_type != kFrameMessageType) { + gpr_log(GPR_ERROR, "Unsupported message type %zu (should be %zu)", + message_type, kFrameMessageType); + *bytes_size = 0; + return false; + } + reader->bytes_remaining = frame_length - kFrameMessageTypeFieldSize; + } + /* Process the non-header bytes. */ + size_t bytes_to_write = GPR_MIN(*bytes_size, reader->bytes_remaining); + memcpy(reader->output_buffer, bytes, bytes_to_write); + reader->output_buffer += bytes_to_write; + bytes_processed += bytes_to_write; + reader->bytes_remaining -= bytes_to_write; + reader->output_bytes_read += bytes_to_write; + *bytes_size = bytes_processed; + return true; +} + +size_t alts_get_output_bytes_read(alts_frame_reader* reader) { + return reader->output_bytes_read; +} + +unsigned char* alts_get_output_buffer(alts_frame_reader* reader) { + return reader->output_buffer; +} + +void alts_destroy_frame_reader(alts_frame_reader* reader) { gpr_free(reader); } diff --git a/src/core/tsi/alts/frame_protector/frame_handler.h b/src/core/tsi/alts/frame_protector/frame_handler.h new file mode 100644 index 0000000000..a703ff40d3 --- /dev/null +++ b/src/core/tsi/alts/frame_protector/frame_handler.h @@ -0,0 +1,236 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_FRAME_HANDLER_H +#define GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_FRAME_HANDLER_H + +#include + +#include +#include + +const size_t kFrameMessageType = 0x06; +const size_t kFrameLengthFieldSize = 4; +const size_t kFrameMessageTypeFieldSize = 4; +const size_t kFrameMaxSize = 1024 * 1024; +const size_t kFrameHeaderSize = + kFrameLengthFieldSize + kFrameMessageTypeFieldSize; + +/** + * Implementation of frame reader and frame writer. All APIs in the + * header are thread-compatible. + */ + +/** + * Main struct for a frame writer. It reads frames from an input buffer, and + * writes the contents as raw bytes. It does not own the input buffer. + */ +typedef struct alts_frame_writer { + const unsigned char* input_buffer; + unsigned char header_buffer[kFrameHeaderSize]; + size_t input_bytes_written; + size_t header_bytes_written; + size_t input_size; +} alts_frame_writer; + +/** + * Main struct for a frame reader. It reads raw bytes and puts the framed + * result into an output buffer. It does not own the output buffer. + */ +typedef struct alts_frame_reader { + unsigned char* output_buffer; + unsigned char header_buffer[kFrameHeaderSize]; + size_t header_bytes_read; + size_t output_bytes_read; + size_t bytes_remaining; +} alts_frame_reader; + +/** + * This method creates a frame writer instance and initializes its internal + * states. + */ +alts_frame_writer* alts_create_frame_writer(); + +/** + * This method resets internal states of a frame writer and prepares to write + * a single frame. It does not take ownership of payload_buffer. + * The payload_buffer must outlive the writer. + * + * - writer: a frame writer instance. + * - buffer: a buffer storing full payload data to be framed. + * - length: size of payload data. + * + * The method returns true on success and false otherwise. + */ +bool alts_reset_frame_writer(alts_frame_writer* writer, + const unsigned char* buffer, size_t length); + +/** + * This method writes up to bytes_size bytes of a frame to output. + * + * - writer: a frame writer instance. + * - output: an output buffer used to store the frame. + * - bytes_size: an in/out parameter that stores the size of output buffer + * before the call, and gets written the number of frame bytes written to the + * buffer. + * + * The method returns true on success and false otherwise. + */ +bool alts_write_frame_bytes(alts_frame_writer* writer, unsigned char* output, + size_t* bytes_size); + +/** + * This method checks if a reset can be called to write a new frame. It returns + * true if it's the first time to frame a payload, or the current frame has + * been finished processing. It returns false if it's not ready yet to start a + * new frame (e.g., more payload data needs to be accumulated to process the + * current frame). + * + * if (alts_is_frame_writer_done(writer)) { + * // a new frame can be written, call reset. + * alts_reset_frame_writer(writer, payload_buffer, payload_size); + * } else { + * // accumulate more payload data until a full frame can be written. + * } + * + * - writer: a frame writer instance. + */ +bool alts_is_frame_writer_done(alts_frame_writer* writer); + +/** + * This method returns the number of bytes left to write before a complete frame + * is formed. + * + * - writer: a frame writer instance. + */ +size_t alts_get_num_writer_bytes_remaining(alts_frame_writer* writer); + +/** + * This method destroys a frame writer instance. + * + * - writer: a frame writer instance. + */ +void alts_destroy_frame_writer(alts_frame_writer* writer); + +/** + * This method creates a frame reader instance and initializes its internal + * states. + */ +alts_frame_reader* alts_create_frame_reader(); + +/** + * This method resets internal states of a frame reader (including setting its + * output_buffer with buffer), and prepares to write processed bytes to + * an output_buffer. It does not take ownership of buffer. The buffer must + * outlive reader. + * + * - reader: a frame reader instance. + * - buffer: an output buffer used to store deframed results. + * + * The method returns true on success and false otherwise. + */ +bool alts_reset_frame_reader(alts_frame_reader* reader, unsigned char* buffer); + +/** + * This method processes up to the number of bytes given in bytes_size. It may + * choose not to process all the bytes, if, for instance, more bytes are + * given to the method than required to complete the current frame. + * + * - reader: a frame reader instance. + * - bytes: a buffer that stores data to be processed. + * - bytes_size: an in/out parameter that stores the size of bytes before the + * call and gets written the number of bytes processed. + * + * The method returns true on success and false otherwise. + */ +bool alts_read_frame_bytes(alts_frame_reader* reader, + const unsigned char* bytes, size_t* bytes_size); + +/** + * This method checks if a frame length has been read. + * + * - reader: a frame reader instance. + * + * The method returns true if a frame length has been read and false otherwise. + */ +bool alts_has_read_frame_length(alts_frame_reader* reader); + +/** + * This method returns the number of bytes the frame reader intends to write. + * It may only be called if alts_has_read_frame_length() returns true. + * + * - reader: a frame reader instance. + */ +size_t alts_get_reader_bytes_remaining(alts_frame_reader* reader); + +/** + * This method resets output_buffer but does not otherwise modify other internal + * states of a frame reader instance. After being set, the new output_buffer + * will hold the deframed payload held by the original output_buffer. It does + * not take ownership of buffer. The buffer must outlive the reader. + * To distinguish between two reset methods on a frame reader, + * + * if (alts_fh_is_frame_reader_done(reader)) { + * // if buffer contains a full payload to be deframed, call reset. + * alts_reset_frame_reader(reader, buffer); + * } + * + * // if remaining buffer space is not enough to hold a full payload + * if (buffer_space_remaining < alts_get_reader_bytes_remaining(reader)) { + * // allocate enough space for a new buffer, copy back data processed so far, + * // and call reset. + * alts_reset_reader_output_buffer(reader, new_buffer). + * } + * + * - reader: a frame reader instance. + * - buffer: a buffer used to set reader's output_buffer. + */ +void alts_reset_reader_output_buffer(alts_frame_reader* reader, + unsigned char* buffer); + +/** + * This method checks if reset can be called to start processing a new frame. + * If true and reset was previously called, a full frame has been processed and + * the content of the frame is available in output_buffer. + + * - reader: a frame reader instance. + */ +bool alts_is_frame_reader_done(alts_frame_reader* reader); + +/** + * This method returns output_bytes_read of a frame reader instance. + * + * - reader: a frame reader instance. + */ +size_t alts_get_output_bytes_read(alts_frame_reader* reader); + +/** + * This method returns output_buffer of a frame reader instance. + * + * - reader: a frame reader instance. + */ +unsigned char* alts_get_output_buffer(alts_frame_reader* reader); + +/** + * This method destroys a frame reader instance. + * + * - reader: a frame reader instance. + */ +void alts_destroy_frame_reader(alts_frame_reader* reader); + +#endif /* GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_FRAME_HANDLER_H */ diff --git a/src/core/tsi/alts/handshaker/alts_handshaker_client.cc b/src/core/tsi/alts/handshaker/alts_handshaker_client.cc new file mode 100644 index 0000000000..40f30e41ca --- /dev/null +++ b/src/core/tsi/alts/handshaker/alts_handshaker_client.cc @@ -0,0 +1,316 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/tsi/alts/handshaker/alts_handshaker_client.h" + +#include +#include +#include + +#include "src/core/tsi/alts/handshaker/alts_handshaker_service_api.h" + +const int kHandshakerClientOpNum = 4; + +typedef struct alts_grpc_handshaker_client { + alts_handshaker_client base; + grpc_call* call; + alts_grpc_caller grpc_caller; +} alts_grpc_handshaker_client; + +static grpc_call_error grpc_start_batch(grpc_call* call, const grpc_op* ops, + size_t nops, void* tag) { + return grpc_call_start_batch(call, ops, nops, tag, nullptr); +} + +/** + * Populate grpc operation data with the fields of ALTS TSI event and make a + * grpc call. + */ +static tsi_result make_grpc_call(alts_handshaker_client* client, + alts_tsi_event* event, bool is_start) { + GPR_ASSERT(client != nullptr && event != nullptr); + alts_grpc_handshaker_client* grpc_client = + reinterpret_cast(client); + grpc_op ops[kHandshakerClientOpNum]; + memset(ops, 0, sizeof(ops)); + grpc_op* op = ops; + if (is_start) { + op->op = GRPC_OP_SEND_INITIAL_METADATA; + op->data.send_initial_metadata.count = 0; + op++; + GPR_ASSERT(op - ops <= kHandshakerClientOpNum); + op->op = GRPC_OP_RECV_INITIAL_METADATA; + op->data.recv_initial_metadata.recv_initial_metadata = + &event->initial_metadata; + op++; + GPR_ASSERT(op - ops <= kHandshakerClientOpNum); + } + op->op = GRPC_OP_SEND_MESSAGE; + op->data.send_message.send_message = event->send_buffer; + op++; + GPR_ASSERT(op - ops <= kHandshakerClientOpNum); + op->op = GRPC_OP_RECV_MESSAGE; + op->data.recv_message.recv_message = &event->recv_buffer; + op++; + GPR_ASSERT(op - ops <= kHandshakerClientOpNum); + GPR_ASSERT(grpc_client->grpc_caller != nullptr); + if (grpc_client->grpc_caller(grpc_client->call, ops, + static_cast(op - ops), + (void*)event) != GRPC_CALL_OK) { + gpr_log(GPR_ERROR, "Start batch operation failed"); + return TSI_INTERNAL_ERROR; + } + return TSI_OK; +} + +/* Create and populate a client_start handshaker request, then serialize it. */ +static grpc_byte_buffer* get_serialized_start_client(alts_tsi_event* event) { + bool ok = true; + grpc_gcp_handshaker_req* req = + grpc_gcp_handshaker_req_create(CLIENT_START_REQ); + ok &= grpc_gcp_handshaker_req_set_handshake_protocol( + req, grpc_gcp_HandshakeProtocol_ALTS); + ok &= grpc_gcp_handshaker_req_add_application_protocol( + req, ALTS_APPLICATION_PROTOCOL); + ok &= grpc_gcp_handshaker_req_add_record_protocol(req, ALTS_RECORD_PROTOCOL); + grpc_gcp_rpc_protocol_versions* versions = &event->options->rpc_versions; + ok &= grpc_gcp_handshaker_req_set_rpc_versions( + req, versions->max_rpc_version.major, versions->max_rpc_version.minor, + versions->min_rpc_version.major, versions->min_rpc_version.minor); + char* target_name = grpc_slice_to_c_string(event->target_name); + ok &= grpc_gcp_handshaker_req_set_target_name(req, target_name); + target_service_account* ptr = + (reinterpret_cast(event->options)) + ->target_account_list_head; + while (ptr != nullptr) { + grpc_gcp_handshaker_req_add_target_identity_service_account(req, ptr->data); + ptr = ptr->next; + } + grpc_slice slice; + ok &= grpc_gcp_handshaker_req_encode(req, &slice); + grpc_byte_buffer* buffer = nullptr; + if (ok) { + buffer = grpc_raw_byte_buffer_create(&slice, 1 /* number of slices */); + } + grpc_slice_unref(slice); + gpr_free(target_name); + grpc_gcp_handshaker_req_destroy(req); + return buffer; +} + +static tsi_result handshaker_client_start_client(alts_handshaker_client* client, + alts_tsi_event* event) { + if (client == nullptr || event == nullptr) { + gpr_log(GPR_ERROR, + "Invalid arguments to alts_grpc_handshaker_client_start_client()"); + return TSI_INVALID_ARGUMENT; + } + grpc_byte_buffer* buffer = get_serialized_start_client(event); + if (buffer == nullptr) { + gpr_log(GPR_ERROR, "get_serialized_start_client() failed"); + return TSI_INTERNAL_ERROR; + } + event->send_buffer = buffer; + tsi_result result = make_grpc_call(client, event, true /* is_start */); + if (result != TSI_OK) { + gpr_log(GPR_ERROR, "make_grpc_call() failed"); + } + return result; +} + +/* Create and populate a start_server handshaker request, then serialize it. */ +static grpc_byte_buffer* get_serialized_start_server( + alts_tsi_event* event, grpc_slice* bytes_received) { + GPR_ASSERT(bytes_received != nullptr); + grpc_gcp_handshaker_req* req = + grpc_gcp_handshaker_req_create(SERVER_START_REQ); + bool ok = grpc_gcp_handshaker_req_add_application_protocol( + req, ALTS_APPLICATION_PROTOCOL); + ok &= grpc_gcp_handshaker_req_param_add_record_protocol( + req, grpc_gcp_HandshakeProtocol_ALTS, ALTS_RECORD_PROTOCOL); + ok &= grpc_gcp_handshaker_req_set_in_bytes( + req, reinterpret_cast GRPC_SLICE_START_PTR(*bytes_received), + GRPC_SLICE_LENGTH(*bytes_received)); + grpc_gcp_rpc_protocol_versions* versions = &event->options->rpc_versions; + ok &= grpc_gcp_handshaker_req_set_rpc_versions( + req, versions->max_rpc_version.major, versions->max_rpc_version.minor, + versions->min_rpc_version.major, versions->min_rpc_version.minor); + grpc_slice req_slice; + ok &= grpc_gcp_handshaker_req_encode(req, &req_slice); + grpc_byte_buffer* buffer = nullptr; + if (ok) { + buffer = grpc_raw_byte_buffer_create(&req_slice, 1 /* number of slices */); + } + grpc_slice_unref(req_slice); + grpc_gcp_handshaker_req_destroy(req); + return buffer; +} + +static tsi_result handshaker_client_start_server(alts_handshaker_client* client, + alts_tsi_event* event, + grpc_slice* bytes_received) { + if (client == nullptr || event == nullptr || bytes_received == nullptr) { + gpr_log(GPR_ERROR, + "Invalid arguments to alts_grpc_handshaker_client_start_server()"); + return TSI_INVALID_ARGUMENT; + } + grpc_byte_buffer* buffer = get_serialized_start_server(event, bytes_received); + if (buffer == nullptr) { + gpr_log(GPR_ERROR, "get_serialized_start_server() failed"); + return TSI_INTERNAL_ERROR; + } + event->send_buffer = buffer; + tsi_result result = make_grpc_call(client, event, true /* is_start */); + if (result != TSI_OK) { + gpr_log(GPR_ERROR, "make_grpc_call() failed"); + } + return result; +} + +/* Create and populate a next handshaker request, then serialize it. */ +static grpc_byte_buffer* get_serialized_next(grpc_slice* bytes_received) { + GPR_ASSERT(bytes_received != nullptr); + grpc_gcp_handshaker_req* req = grpc_gcp_handshaker_req_create(NEXT_REQ); + bool ok = grpc_gcp_handshaker_req_set_in_bytes( + req, reinterpret_cast GRPC_SLICE_START_PTR(*bytes_received), + GRPC_SLICE_LENGTH(*bytes_received)); + grpc_slice req_slice; + ok &= grpc_gcp_handshaker_req_encode(req, &req_slice); + grpc_byte_buffer* buffer = nullptr; + if (ok) { + buffer = grpc_raw_byte_buffer_create(&req_slice, 1 /* number of slices */); + } + grpc_slice_unref(req_slice); + grpc_gcp_handshaker_req_destroy(req); + return buffer; +} + +static tsi_result handshaker_client_next(alts_handshaker_client* client, + alts_tsi_event* event, + grpc_slice* bytes_received) { + if (client == nullptr || event == nullptr || bytes_received == nullptr) { + gpr_log(GPR_ERROR, + "Invalid arguments to alts_grpc_handshaker_client_next()"); + return TSI_INVALID_ARGUMENT; + } + grpc_byte_buffer* buffer = get_serialized_next(bytes_received); + if (buffer == nullptr) { + gpr_log(GPR_ERROR, "get_serialized_next() failed"); + return TSI_INTERNAL_ERROR; + } + event->send_buffer = buffer; + tsi_result result = make_grpc_call(client, event, false /* is_start */); + if (result != TSI_OK) { + gpr_log(GPR_ERROR, "make_grpc_call() failed"); + } + return result; +} + +static void handshaker_client_destruct(alts_handshaker_client* client) { + if (client == nullptr) { + return; + } + alts_grpc_handshaker_client* grpc_client = + reinterpret_cast(client); + grpc_call_unref(grpc_client->call); +} + +static const alts_handshaker_client_vtable vtable = { + handshaker_client_start_client, handshaker_client_start_server, + handshaker_client_next, handshaker_client_destruct}; + +alts_handshaker_client* alts_grpc_handshaker_client_create( + grpc_channel* channel, grpc_completion_queue* queue, + const char* handshaker_service_url) { + if (channel == nullptr || queue == nullptr || + handshaker_service_url == nullptr) { + gpr_log(GPR_ERROR, "Invalid arguments to alts_handshaker_client_create()"); + return nullptr; + } + alts_grpc_handshaker_client* client = + static_cast(gpr_zalloc(sizeof(*client))); + client->grpc_caller = grpc_start_batch; + grpc_slice slice = grpc_slice_from_copied_string(handshaker_service_url); + client->call = grpc_channel_create_call( + channel, nullptr, GRPC_PROPAGATE_DEFAULTS, queue, + grpc_slice_from_static_string(ALTS_SERVICE_METHOD), &slice, + gpr_inf_future(GPR_CLOCK_REALTIME), nullptr); + client->base.vtable = &vtable; + grpc_slice_unref(slice); + return &client->base; +} + +namespace grpc_core { +namespace internal { + +void alts_handshaker_client_set_grpc_caller_for_testing( + alts_handshaker_client* client, alts_grpc_caller caller) { + GPR_ASSERT(client != nullptr && caller != nullptr); + alts_grpc_handshaker_client* grpc_client = + reinterpret_cast(client); + grpc_client->grpc_caller = caller; +} + +} // namespace internal +} // namespace grpc_core + +tsi_result alts_handshaker_client_start_client(alts_handshaker_client* client, + alts_tsi_event* event) { + if (client != nullptr && client->vtable != nullptr && + client->vtable->client_start != nullptr) { + return client->vtable->client_start(client, event); + } + gpr_log(GPR_ERROR, + "client or client->vtable has not been initialized properly"); + return TSI_INVALID_ARGUMENT; +} + +tsi_result alts_handshaker_client_start_server(alts_handshaker_client* client, + alts_tsi_event* event, + grpc_slice* bytes_received) { + if (client != nullptr && client->vtable != nullptr && + client->vtable->server_start != nullptr) { + return client->vtable->server_start(client, event, bytes_received); + } + gpr_log(GPR_ERROR, + "client or client->vtable has not been initialized properly"); + return TSI_INVALID_ARGUMENT; +} + +tsi_result alts_handshaker_client_next(alts_handshaker_client* client, + alts_tsi_event* event, + grpc_slice* bytes_received) { + if (client != nullptr && client->vtable != nullptr && + client->vtable->next != nullptr) { + return client->vtable->next(client, event, bytes_received); + } + gpr_log(GPR_ERROR, + "client or client->vtable has not been initialized properly"); + return TSI_INVALID_ARGUMENT; +} + +void alts_handshaker_client_destroy(alts_handshaker_client* client) { + if (client != nullptr) { + if (client->vtable != nullptr && client->vtable->destruct != nullptr) { + client->vtable->destruct(client); + } + gpr_free(client); + } +} diff --git a/src/core/tsi/alts/handshaker/alts_handshaker_client.h b/src/core/tsi/alts/handshaker/alts_handshaker_client.h new file mode 100644 index 0000000000..fb2d2cf68e --- /dev/null +++ b/src/core/tsi/alts/handshaker/alts_handshaker_client.h @@ -0,0 +1,137 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_CLIENT_H +#define GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_CLIENT_H + +#include + +#include + +#include "src/core/tsi/alts/handshaker/alts_tsi_event.h" + +#define ALTS_SERVICE_METHOD "/grpc.gcp.HandshakerService/DoHandshake" +#define ALTS_APPLICATION_PROTOCOL "grpc" +#define ALTS_RECORD_PROTOCOL "ALTSRP_GCM_AES128_REKEY" + +const size_t kAltsAes128GcmRekeyKeyLength = 44; + +/** + * A ALTS handshaker client interface. It is used to communicate with + * ALTS handshaker service by scheduling a handshaker request that could be one + * of client_start, server_start, and next handshaker requests. All APIs in the + * header are thread-compatible. + */ +typedef struct alts_handshaker_client alts_handshaker_client; + +/* A function that makes the grpc call to the handshaker service. */ +typedef grpc_call_error (*alts_grpc_caller)(grpc_call* call, const grpc_op* ops, + size_t nops, void* tag); + +/* V-table for ALTS handshaker client operations. */ +typedef struct alts_handshaker_client_vtable { + tsi_result (*client_start)(alts_handshaker_client* client, + alts_tsi_event* event); + tsi_result (*server_start)(alts_handshaker_client* client, + alts_tsi_event* event, grpc_slice* bytes_received); + tsi_result (*next)(alts_handshaker_client* client, alts_tsi_event* event, + grpc_slice* bytes_received); + void (*destruct)(alts_handshaker_client* client); +} alts_handshaker_client_vtable; + +struct alts_handshaker_client { + const alts_handshaker_client_vtable* vtable; +}; + +/** + * This method schedules a client_start handshaker request to ALTS handshaker + * service. + * + * - client: ALTS handshaker client instance. + * - event: ALTS TSI event instance. + * + * It returns TSI_OK on success and an error status code on failure. + */ +tsi_result alts_handshaker_client_start_client(alts_handshaker_client* client, + alts_tsi_event* event); + +/** + * This method schedules a server_start handshaker request to ALTS handshaker + * service. + * + * - client: ALTS handshaker client instance. + * - event: ALTS TSI event instance. + * - bytes_received: bytes in out_frames returned from the peer's handshaker + * response. + * + * It returns TSI_OK on success and an error status code on failure. + */ +tsi_result alts_handshaker_client_start_server(alts_handshaker_client* client, + alts_tsi_event* event, + grpc_slice* bytes_received); + +/** + * This method schedules a next handshaker request to ALTS handshaker service. + * + * - client: ALTS handshaker client instance. + * - event: ALTS TSI event instance. + * - bytes_received: bytes in out_frames returned from the peer's handshaker + * response. + * + * It returns TSI_OK on success and an error status code on failure. + */ +tsi_result alts_handshaker_client_next(alts_handshaker_client* client, + alts_tsi_event* event, + grpc_slice* bytes_received); + +/** + * This method destroys a ALTS handshaker client. + * + * - client: a ALTS handshaker client instance. + */ +void alts_handshaker_client_destroy(alts_handshaker_client* client); + +/** + * This method creates a ALTS handshaker client. + * + * - channel: grpc channel to ALTS handshaker service. + * - queue: grpc completion queue. + * - handshaker_service_url: address of ALTS handshaker service in the format of + * "host:port". + * + * It returns the created ALTS handshaker client on success, and NULL on + * failure. + */ +alts_handshaker_client* alts_grpc_handshaker_client_create( + grpc_channel* channel, grpc_completion_queue* queue, + const char* handshaker_service_url); + +namespace grpc_core { +namespace internal { + +/** + * Unsafe, use for testing only. It allows the caller to change the way that + * GRPC calls are made to the handshaker service. + */ +void alts_handshaker_client_set_grpc_caller_for_testing( + alts_handshaker_client* client, alts_grpc_caller caller); + +} // namespace internal +} // namespace grpc_core + +#endif /* GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_CLIENT_H */ diff --git a/src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc b/src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc new file mode 100644 index 0000000000..256e414ae4 --- /dev/null +++ b/src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc @@ -0,0 +1,520 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/tsi/alts/handshaker/alts_handshaker_service_api.h" + +#include +#include + +#include "src/core/tsi/alts/handshaker/transport_security_common_api.h" + +/* HandshakerReq */ +grpc_gcp_handshaker_req* grpc_gcp_handshaker_req_create( + grpc_gcp_handshaker_req_type type) { + grpc_gcp_handshaker_req* req = + static_cast(gpr_zalloc(sizeof(*req))); + switch (type) { + case CLIENT_START_REQ: + req->has_client_start = true; + break; + case SERVER_START_REQ: + req->has_server_start = true; + break; + case NEXT_REQ: + req->has_next = true; + break; + } + return req; +} + +void grpc_gcp_handshaker_req_destroy(grpc_gcp_handshaker_req* req) { + if (req == nullptr) { + return; + } + if (req->has_client_start) { + /* Destroy client_start request. */ + destroy_repeated_field_list_identity( + static_cast(req->client_start.target_identities.arg)); + destroy_repeated_field_list_string(static_cast( + req->client_start.application_protocols.arg)); + destroy_repeated_field_list_string( + static_cast(req->client_start.record_protocols.arg)); + if (req->client_start.has_local_identity) { + destroy_slice(static_cast( + req->client_start.local_identity.hostname.arg)); + destroy_slice(static_cast( + req->client_start.local_identity.service_account.arg)); + } + if (req->client_start.has_local_endpoint) { + destroy_slice(static_cast( + req->client_start.local_endpoint.ip_address.arg)); + } + if (req->client_start.has_remote_endpoint) { + destroy_slice(static_cast( + req->client_start.remote_endpoint.ip_address.arg)); + } + destroy_slice(static_cast(req->client_start.target_name.arg)); + } else if (req->has_server_start) { + /* Destroy server_start request. */ + size_t i = 0; + for (i = 0; i < req->server_start.handshake_parameters_count; i++) { + destroy_repeated_field_list_identity( + static_cast(req->server_start.handshake_parameters[i] + .value.local_identities.arg)); + destroy_repeated_field_list_string( + static_cast(req->server_start.handshake_parameters[i] + .value.record_protocols.arg)); + } + destroy_repeated_field_list_string(static_cast( + req->server_start.application_protocols.arg)); + if (req->server_start.has_local_endpoint) { + destroy_slice(static_cast( + req->server_start.local_endpoint.ip_address.arg)); + } + if (req->server_start.has_remote_endpoint) { + destroy_slice(static_cast( + req->server_start.remote_endpoint.ip_address.arg)); + } + destroy_slice(static_cast(req->server_start.in_bytes.arg)); + } else { + /* Destroy next request. */ + destroy_slice(static_cast(req->next.in_bytes.arg)); + } + gpr_free(req); +} + +bool grpc_gcp_handshaker_req_set_handshake_protocol( + grpc_gcp_handshaker_req* req, + grpc_gcp_handshake_protocol handshake_protocol) { + if (req == nullptr || !req->has_client_start) { + gpr_log(GPR_ERROR, + "Invalid arguments to " + "grpc_gcp_handshaker_req_set_handshake_protocol()."); + return false; + } + req->client_start.has_handshake_security_protocol = true; + req->client_start.handshake_security_protocol = handshake_protocol; + return true; +} + +bool grpc_gcp_handshaker_req_set_target_name(grpc_gcp_handshaker_req* req, + const char* target_name) { + if (req == nullptr || target_name == nullptr || !req->has_client_start) { + gpr_log(GPR_ERROR, + "Invalid arguments to " + "grpc_gcp_handshaker_req_set_target_name()."); + return false; + } + grpc_slice* slice = create_slice(target_name, strlen(target_name)); + req->client_start.target_name.arg = slice; + req->client_start.target_name.funcs.encode = encode_string_or_bytes_cb; + return true; +} + +bool grpc_gcp_handshaker_req_add_application_protocol( + grpc_gcp_handshaker_req* req, const char* application_protocol) { + if (req == nullptr || application_protocol == nullptr || req->has_next) { + gpr_log(GPR_ERROR, + "Invalid arguments to " + "grpc_gcp_handshaker_req_add_application_protocol()."); + return false; + } + grpc_slice* slice = + create_slice(application_protocol, strlen(application_protocol)); + if (req->has_client_start) { + add_repeated_field(reinterpret_cast( + &req->client_start.application_protocols.arg), + slice); + req->client_start.application_protocols.funcs.encode = + encode_repeated_string_cb; + } else { + add_repeated_field(reinterpret_cast( + &req->server_start.application_protocols.arg), + slice); + req->server_start.application_protocols.funcs.encode = + encode_repeated_string_cb; + } + return true; +} + +bool grpc_gcp_handshaker_req_add_record_protocol(grpc_gcp_handshaker_req* req, + const char* record_protocol) { + if (req == nullptr || record_protocol == nullptr || !req->has_client_start) { + gpr_log(GPR_ERROR, + "Invalid arguments to " + "grpc_gcp_handshaker_req_add_record_protocol()."); + return false; + } + grpc_slice* slice = create_slice(record_protocol, strlen(record_protocol)); + add_repeated_field(reinterpret_cast( + &req->client_start.record_protocols.arg), + slice); + req->client_start.record_protocols.funcs.encode = encode_repeated_string_cb; + return true; +} + +static void set_identity_hostname(grpc_gcp_identity* identity, + const char* hostname) { + grpc_slice* slice = create_slice(hostname, strlen(hostname)); + identity->hostname.arg = slice; + identity->hostname.funcs.encode = encode_string_or_bytes_cb; +} + +static void set_identity_service_account(grpc_gcp_identity* identity, + const char* service_account) { + grpc_slice* slice = create_slice(service_account, strlen(service_account)); + identity->service_account.arg = slice; + identity->service_account.funcs.encode = encode_string_or_bytes_cb; +} + +bool grpc_gcp_handshaker_req_add_target_identity_hostname( + grpc_gcp_handshaker_req* req, const char* hostname) { + if (req == nullptr || hostname == nullptr || !req->has_client_start) { + gpr_log(GPR_ERROR, + "Invalid nullptr arguments to " + "grpc_gcp_handshaker_req_add_target_identity_hostname()."); + return false; + } + grpc_gcp_identity* target_identity = + static_cast(gpr_zalloc(sizeof(*target_identity))); + set_identity_hostname(target_identity, hostname); + req->client_start.target_identities.funcs.encode = + encode_repeated_identity_cb; + add_repeated_field(reinterpret_cast( + &req->client_start.target_identities.arg), + target_identity); + return true; +} + +bool grpc_gcp_handshaker_req_add_target_identity_service_account( + grpc_gcp_handshaker_req* req, const char* service_account) { + if (req == nullptr || service_account == nullptr || !req->has_client_start) { + gpr_log(GPR_ERROR, + "Invalid nullptr arguments to " + "grpc_gcp_handshaker_req_add_target_identity_service_account()."); + return false; + } + grpc_gcp_identity* target_identity = + static_cast(gpr_zalloc(sizeof(*target_identity))); + set_identity_service_account(target_identity, service_account); + req->client_start.target_identities.funcs.encode = + encode_repeated_identity_cb; + add_repeated_field(reinterpret_cast( + &req->client_start.target_identities.arg), + target_identity); + return true; +} + +bool grpc_gcp_handshaker_req_set_local_identity_hostname( + grpc_gcp_handshaker_req* req, const char* hostname) { + if (req == nullptr || hostname == nullptr || !req->has_client_start) { + gpr_log(GPR_ERROR, + "Invalid nullptr arguments to " + "grpc_gcp_handshaker_req_set_local_identity_hostname()."); + return false; + } + req->client_start.has_local_identity = true; + set_identity_hostname(&req->client_start.local_identity, hostname); + return true; +} + +bool grpc_gcp_handshaker_req_set_local_identity_service_account( + grpc_gcp_handshaker_req* req, const char* service_account) { + if (req == nullptr || service_account == nullptr || !req->has_client_start) { + gpr_log(GPR_ERROR, + "Invalid nullptr arguments to " + "grpc_gcp_handshaker_req_set_local_identity_service_account()."); + return false; + } + req->client_start.has_local_identity = true; + set_identity_service_account(&req->client_start.local_identity, + service_account); + return true; +} + +static void set_endpoint(grpc_gcp_endpoint* endpoint, const char* ip_address, + size_t port, grpc_gcp_network_protocol protocol) { + grpc_slice* slice = create_slice(ip_address, strlen(ip_address)); + endpoint->ip_address.arg = slice; + endpoint->ip_address.funcs.encode = encode_string_or_bytes_cb; + endpoint->has_port = true; + endpoint->port = static_cast(port); + endpoint->has_protocol = true; + endpoint->protocol = protocol; +} + +bool grpc_gcp_handshaker_req_set_rpc_versions(grpc_gcp_handshaker_req* req, + uint32_t max_major, + uint32_t max_minor, + uint32_t min_major, + uint32_t min_minor) { + if (req == nullptr || req->has_next) { + gpr_log(GPR_ERROR, + "Invalid arguments to " + "grpc_gcp_handshaker_req_set_rpc_versions()."); + return false; + } + if (req->has_client_start) { + req->client_start.has_rpc_versions = true; + grpc_gcp_rpc_protocol_versions_set_max(&req->client_start.rpc_versions, + max_major, max_minor); + grpc_gcp_rpc_protocol_versions_set_min(&req->client_start.rpc_versions, + min_major, min_minor); + } else { + req->server_start.has_rpc_versions = true; + grpc_gcp_rpc_protocol_versions_set_max(&req->server_start.rpc_versions, + max_major, max_minor); + grpc_gcp_rpc_protocol_versions_set_min(&req->server_start.rpc_versions, + min_major, min_minor); + } + return true; +} + +bool grpc_gcp_handshaker_req_set_local_endpoint( + grpc_gcp_handshaker_req* req, const char* ip_address, size_t port, + grpc_gcp_network_protocol protocol) { + if (req == nullptr || ip_address == nullptr || port > 65535 || + req->has_next) { + gpr_log(GPR_ERROR, + "Invalid arguments to " + "grpc_gcp_handshaker_req_set_local_endpoint()."); + return false; + } + if (req->has_client_start) { + req->client_start.has_local_endpoint = true; + set_endpoint(&req->client_start.local_endpoint, ip_address, port, protocol); + } else { + req->server_start.has_local_endpoint = true; + set_endpoint(&req->server_start.local_endpoint, ip_address, port, protocol); + } + return true; +} + +bool grpc_gcp_handshaker_req_set_remote_endpoint( + grpc_gcp_handshaker_req* req, const char* ip_address, size_t port, + grpc_gcp_network_protocol protocol) { + if (req == nullptr || ip_address == nullptr || port > 65535 || + req->has_next) { + gpr_log(GPR_ERROR, + "Invalid arguments to " + "grpc_gcp_handshaker_req_set_remote_endpoint()."); + return false; + } + if (req->has_client_start) { + req->client_start.has_remote_endpoint = true; + set_endpoint(&req->client_start.remote_endpoint, ip_address, port, + protocol); + } else { + req->server_start.has_remote_endpoint = true; + set_endpoint(&req->server_start.remote_endpoint, ip_address, port, + protocol); + } + return true; +} + +bool grpc_gcp_handshaker_req_set_in_bytes(grpc_gcp_handshaker_req* req, + const char* in_bytes, size_t size) { + if (req == nullptr || in_bytes == nullptr || req->has_client_start) { + gpr_log(GPR_ERROR, + "Invalid arguments to " + "grpc_gcp_handshaker_req_set_in_bytes()."); + return false; + } + grpc_slice* slice = create_slice(in_bytes, size); + if (req->has_next) { + req->next.in_bytes.arg = slice; + req->next.in_bytes.funcs.encode = &encode_string_or_bytes_cb; + } else { + req->server_start.in_bytes.arg = slice; + req->server_start.in_bytes.funcs.encode = &encode_string_or_bytes_cb; + } + return true; +} + +static grpc_gcp_server_handshake_parameters* server_start_find_param( + grpc_gcp_handshaker_req* req, int32_t key) { + size_t i = 0; + for (i = 0; i < req->server_start.handshake_parameters_count; i++) { + if (req->server_start.handshake_parameters[i].key == key) { + return &req->server_start.handshake_parameters[i].value; + } + } + req->server_start + .handshake_parameters[req->server_start.handshake_parameters_count] + .has_key = true; + req->server_start + .handshake_parameters[req->server_start.handshake_parameters_count] + .has_value = true; + req->server_start + .handshake_parameters[req->server_start.handshake_parameters_count++] + .key = key; + return &req->server_start + .handshake_parameters + [req->server_start.handshake_parameters_count - 1] + .value; +} + +bool grpc_gcp_handshaker_req_param_add_record_protocol( + grpc_gcp_handshaker_req* req, grpc_gcp_handshake_protocol key, + const char* record_protocol) { + if (req == nullptr || record_protocol == nullptr || !req->has_server_start) { + gpr_log(GPR_ERROR, + "Invalid arguments to " + "grpc_gcp_handshaker_req_param_add_record_protocol()."); + return false; + } + grpc_gcp_server_handshake_parameters* param = + server_start_find_param(req, key); + grpc_slice* slice = create_slice(record_protocol, strlen(record_protocol)); + add_repeated_field( + reinterpret_cast(¶m->record_protocols.arg), slice); + param->record_protocols.funcs.encode = &encode_repeated_string_cb; + return true; +} + +bool grpc_gcp_handshaker_req_param_add_local_identity_hostname( + grpc_gcp_handshaker_req* req, grpc_gcp_handshake_protocol key, + const char* hostname) { + if (req == nullptr || hostname == nullptr || !req->has_server_start) { + gpr_log(GPR_ERROR, + "Invalid arguments to " + "grpc_gcp_handshaker_req_param_add_local_identity_hostname()."); + return false; + } + grpc_gcp_server_handshake_parameters* param = + server_start_find_param(req, key); + grpc_gcp_identity* local_identity = + static_cast(gpr_zalloc(sizeof(*local_identity))); + set_identity_hostname(local_identity, hostname); + add_repeated_field( + reinterpret_cast(¶m->local_identities.arg), + local_identity); + param->local_identities.funcs.encode = &encode_repeated_identity_cb; + return true; +} + +bool grpc_gcp_handshaker_req_param_add_local_identity_service_account( + grpc_gcp_handshaker_req* req, grpc_gcp_handshake_protocol key, + const char* service_account) { + if (req == nullptr || service_account == nullptr || !req->has_server_start) { + gpr_log( + GPR_ERROR, + "Invalid arguments to " + "grpc_gcp_handshaker_req_param_add_local_identity_service_account()."); + return false; + } + grpc_gcp_server_handshake_parameters* param = + server_start_find_param(req, key); + grpc_gcp_identity* local_identity = + static_cast(gpr_zalloc(sizeof(*local_identity))); + set_identity_service_account(local_identity, service_account); + add_repeated_field( + reinterpret_cast(¶m->local_identities.arg), + local_identity); + param->local_identities.funcs.encode = &encode_repeated_identity_cb; + return true; +} + +bool grpc_gcp_handshaker_req_encode(grpc_gcp_handshaker_req* req, + grpc_slice* slice) { + if (req == nullptr || slice == nullptr) { + gpr_log(GPR_ERROR, + "Invalid nullptr arguments to grpc_gcp_handshaker_req_encode()."); + return false; + } + pb_ostream_t size_stream; + memset(&size_stream, 0, sizeof(pb_ostream_t)); + if (!pb_encode(&size_stream, grpc_gcp_HandshakerReq_fields, req)) { + gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&size_stream)); + return false; + } + size_t encoded_length = size_stream.bytes_written; + *slice = grpc_slice_malloc(encoded_length); + pb_ostream_t output_stream = + pb_ostream_from_buffer(GRPC_SLICE_START_PTR(*slice), encoded_length); + if (!pb_encode(&output_stream, grpc_gcp_HandshakerReq_fields, req) != 0) { + gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&output_stream)); + return false; + } + return true; +} + +/* HandshakerResp. */ +grpc_gcp_handshaker_resp* grpc_gcp_handshaker_resp_create(void) { + grpc_gcp_handshaker_resp* resp = + static_cast(gpr_zalloc(sizeof(*resp))); + return resp; +} + +void grpc_gcp_handshaker_resp_destroy(grpc_gcp_handshaker_resp* resp) { + if (resp != nullptr) { + destroy_slice(static_cast(resp->out_frames.arg)); + if (resp->has_status) { + destroy_slice(static_cast(resp->status.details.arg)); + } + if (resp->has_result) { + destroy_slice( + static_cast(resp->result.application_protocol.arg)); + destroy_slice(static_cast(resp->result.record_protocol.arg)); + destroy_slice(static_cast(resp->result.key_data.arg)); + if (resp->result.has_local_identity) { + destroy_slice( + static_cast(resp->result.local_identity.hostname.arg)); + destroy_slice(static_cast( + resp->result.local_identity.service_account.arg)); + } + if (resp->result.has_peer_identity) { + destroy_slice( + static_cast(resp->result.peer_identity.hostname.arg)); + destroy_slice(static_cast( + resp->result.peer_identity.service_account.arg)); + } + } + gpr_free(resp); + } +} + +bool grpc_gcp_handshaker_resp_decode(grpc_slice encoded_handshaker_resp, + grpc_gcp_handshaker_resp* resp) { + if (resp == nullptr) { + gpr_log(GPR_ERROR, + "Invalid nullptr argument to grpc_gcp_handshaker_resp_decode()."); + return false; + } + pb_istream_t stream = + pb_istream_from_buffer(GRPC_SLICE_START_PTR(encoded_handshaker_resp), + GRPC_SLICE_LENGTH(encoded_handshaker_resp)); + resp->out_frames.funcs.decode = decode_string_or_bytes_cb; + resp->status.details.funcs.decode = decode_string_or_bytes_cb; + resp->result.application_protocol.funcs.decode = decode_string_or_bytes_cb; + resp->result.record_protocol.funcs.decode = decode_string_or_bytes_cb; + resp->result.key_data.funcs.decode = decode_string_or_bytes_cb; + resp->result.peer_identity.hostname.funcs.decode = decode_string_or_bytes_cb; + resp->result.peer_identity.service_account.funcs.decode = + decode_string_or_bytes_cb; + resp->result.local_identity.hostname.funcs.decode = decode_string_or_bytes_cb; + resp->result.local_identity.service_account.funcs.decode = + decode_string_or_bytes_cb; + if (!pb_decode(&stream, grpc_gcp_HandshakerResp_fields, resp)) { + gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&stream)); + return false; + } + return true; +} diff --git a/src/core/tsi/alts/handshaker/alts_handshaker_service_api.h b/src/core/tsi/alts/handshaker/alts_handshaker_service_api.h new file mode 100644 index 0000000000..5df56a86fa --- /dev/null +++ b/src/core/tsi/alts/handshaker/alts_handshaker_service_api.h @@ -0,0 +1,323 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_SERVICE_API_H +#define GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_SERVICE_API_H + +#include + +#include "src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h" + +/** + * An implementation of nanopb thin wrapper used to set/get and + * serialize/de-serialize of ALTS handshake requests and responses. + * + * All APIs in the header are thread-compatible. A typical usage of this API at + * the client side is as follows: + * + * ----------------------------------------------------------------------------- + * // Create, populate, and serialize an ALTS client_start handshake request to + * // send to the server. + * grpc_gcp_handshaker_req* req = + * grpc_gcp_handshaker_req_create(CLIENT_START_REQ); + * grpc_gcp_handshaker_req_set_handshake_protocol( + req, grpc_gcp_HandshakeProtocol_ALTS); + * grpc_gcp_handshaker_req_add_application_protocol(req, "grpc"); + * grpc_gcp_handshaker_req_add_record_protocol(req, "ALTSRP_GCM_AES128"); + * grpc_slice client_slice; + * if (!grpc_gcp_handshaker_req_encode(req, &client_slice)) { + * fprintf(stderr, "ALTS handshake request encoding failed."; + * } + * + * // De-serialize a data stream received from the server, and store the result + * // at ALTS handshake response. + * grpc_gcp_handshaker_resp* resp = grpc_gcp_handshaker_resp_create(); + * if (!grpc_gcp_handshaker_resp_decode(server_slice, resp)) { + * fprintf(stderr, "ALTS handshake response decoding failed."); + * } + * // To access a variable-length datatype field (i.e., pb_callback_t), + * // access its "arg" subfield (if it has been set). + * if (resp->out_frames.arg != nullptr) { + * grpc_slice* slice = resp->out_frames.arg; + * } + * // To access a fixed-length datatype field (i.e., not pb_calback_t), + * // access the field directly (if it has been set). + * if (resp->has_status && resp->status->has_code) { + * uint32_t code = resp->status->code; + * } + *------------------------------------------------------------------------------ + */ + +/** + * This method creates an ALTS handshake request. + * + * - type: an enum type value that can be either CLIENT_START_REQ, + * SERVER_START_REQ, or NEXT_REQ to indicate the created instance will be + * client_start, server_start, and next handshake request message + * respectively. + * + * The method returns a pointer to the created instance. + */ +grpc_gcp_handshaker_req* grpc_gcp_handshaker_req_create( + grpc_gcp_handshaker_req_type type); + +/** + * This method sets the value for handshake_security_protocol field of ALTS + * client_start handshake request. + * + * - req: an ALTS handshake request. + * - handshake_protocol: a enum type value representing the handshake security + * protocol. + * + * The method returns true on success and false otherwise. + */ +bool grpc_gcp_handshaker_req_set_handshake_protocol( + grpc_gcp_handshaker_req* req, + grpc_gcp_handshake_protocol handshake_protocol); + +/** + * This method sets the value for target_name field of ALTS client_start + * handshake request. + * + * - req: an ALTS handshake request. + * - target_name: a target name to be set. + * + * The method returns true on success and false otherwise. + */ +bool grpc_gcp_handshaker_req_set_target_name(grpc_gcp_handshaker_req* req, + const char* target_name); + +/** + * This method adds an application protocol supported by the server (or + * client) to ALTS server_start (or client_start) handshake request. + * + * - req: an ALTS handshake request. + * - application_protocol: an application protocol (e.g., grpc) to be added. + * + * The method returns true on success and false otherwise. + */ +bool grpc_gcp_handshaker_req_add_application_protocol( + grpc_gcp_handshaker_req* req, const char* application_protocol); + +/** + * This method adds a record protocol supported by the client to ALTS + * client_start handshake request. + * + * - req: an ALTS handshake request. + * - record_protocol: a record protocol (e.g., ALTSRP_GCM_AES128) to be + * added. + * + * The method returns true on success and false otherwise. + */ +bool grpc_gcp_handshaker_req_add_record_protocol(grpc_gcp_handshaker_req* req, + const char* record_protocol); + +/** + * This method adds a target server identity represented as hostname and + * acceptable by a client to ALTS client_start handshake request. + * + * - req: an ALTS handshake request. + * - hostname: a string representation of hostname at the connection + * endpoint to be added. + * + * The method returns true on success and false otherwise. + */ +bool grpc_gcp_handshaker_req_add_target_identity_hostname( + grpc_gcp_handshaker_req* req, const char* hostname); + +/** + * This method adds a target server identity represented as service account and + * acceptable by a client to ALTS client_start handshake request. + * + * - req: an ALTS handshake request. + * - service_account: a string representation of service account at the + * connection endpoint to be added. + * + * The method returns true on success and false otherwise. + */ +bool grpc_gcp_handshaker_req_add_target_identity_service_account( + grpc_gcp_handshaker_req* req, const char* service_account); + +/** + * This method sets the hostname for local_identity field of ALTS client_start + * handshake request. + * + * - req: an ALTS handshake request. + * - hostname: a string representation of hostname. + * + * The method returns true on success and false otherwise. + */ +bool grpc_gcp_handshaker_req_set_local_identity_hostname( + grpc_gcp_handshaker_req* req, const char* hostname); + +/** + * This method sets the service account for local_identity field of ALTS + * client_start handshake request. + * + * - req: an ALTS handshake request. + * - service_account: a string representation of service account. + * + * The method returns true on success and false otherwise. + */ +bool grpc_gcp_handshaker_req_set_local_identity_service_account( + grpc_gcp_handshaker_req* req, const char* service_account); + +/** + * This method sets the value for local_endpoint field of either ALTS + * client_start or server_start handshake request. + * + * - req: an ALTS handshake request. + * - ip_address: a string representation of ip address associated with the + * local endpoint, that could be either IPv4 or IPv6. + * - port: a port number associated with the local endpoint. + * - protocol: a network protocol (e.g., TCP or UDP) associated with the + * local endpoint. + * + * The method returns true on success and false otherwise. + */ +bool grpc_gcp_handshaker_req_set_local_endpoint( + grpc_gcp_handshaker_req* req, const char* ip_address, size_t port, + grpc_gcp_network_protocol protocol); + +/** + * This method sets the value for remote_endpoint field of either ALTS + * client_start or server_start handshake request. + * + * - req: an ALTS handshake request. + * - ip_address: a string representation of ip address associated with the + * remote endpoint, that could be either IPv4 or IPv6. + * - port: a port number associated with the remote endpoint. + * - protocol: a network protocol (e.g., TCP or UDP) associated with the + * remote endpoint. + * + * The method returns true on success and false otherwise. + */ +bool grpc_gcp_handshaker_req_set_remote_endpoint( + grpc_gcp_handshaker_req* req, const char* ip_address, size_t port, + grpc_gcp_network_protocol protocol); + +/** + * This method sets the value for in_bytes field of either ALTS server_start or + * next handshake request. + * + * - req: an ALTS handshake request. + * - in_bytes: a buffer containing bytes taken from out_frames of the peer's + * ALTS handshake response. It is possible that the peer's out_frames are + * split into multiple handshake request messages. + * - size: size of in_bytes buffer. + * + * The method returns true on success and false otherwise. + */ +bool grpc_gcp_handshaker_req_set_in_bytes(grpc_gcp_handshaker_req* req, + const char* in_bytes, size_t size); + +/** + * This method adds a record protocol to handshake parameters mapped by the + * handshake protocol for ALTS server_start handshake request. + * + * - req: an ALTS handshake request. + * - key: an enum type value representing a handshake security protocol. + * - record_protocol: a record protocol to be added. + * + * The method returns true on success and false otherwise. + */ +bool grpc_gcp_handshaker_req_param_add_record_protocol( + grpc_gcp_handshaker_req* req, grpc_gcp_handshake_protocol key, + const char* record_protocol); + +/** + * This method adds a local identity represented as hostname to handshake + * parameters mapped by the handshake protocol for ALTS server_start handshake + * request. + * + * - req: an ALTS handshake request. + * - key: an enum type value representing a handshake security protocol. + * - hostname: a string representation of hostname to be added. + * + * The method returns true on success and false otherwise. + */ +bool grpc_gcp_handshaker_req_param_add_local_identity_hostname( + grpc_gcp_handshaker_req* req, grpc_gcp_handshake_protocol key, + const char* hostname); + +/** + * This method adds a local identity represented as service account to handshake + * parameters mapped by the handshake protocol for ALTS server_start handshake + * request. + * + * - req: an ALTS handshake request. + * - key: an enum type value representing a handshake security protocol. + * - service_account: a string representation of service account to be added. + * + * The method returns true on success and false otherwise. + */ +bool grpc_gcp_handshaker_req_param_add_local_identity_service_account( + grpc_gcp_handshaker_req* req, grpc_gcp_handshake_protocol key, + const char* service_account); + +/** + * This method sets the value for rpc_versions field of either ALTS + * client_start or server_start handshake request. + * + * - req: an ALTS handshake request. + * - max_major: a major version of maximum supported RPC version. + * - max_minor: a minor version of maximum supported RPC version. + * - min_major: a major version of minimum supported RPC version. + * - min_minor: a minor version of minimum supported RPC version. + * + * The method returns true on success and false otherwise. + */ +bool grpc_gcp_handshaker_req_set_rpc_versions(grpc_gcp_handshaker_req* req, + uint32_t max_major, + uint32_t max_minor, + uint32_t min_major, + uint32_t min_minor); + +/** + * This method serializes an ALTS handshake request and returns a data stream. + * + * - req: an ALTS handshake request. + * - slice: a data stream where the serialized result will be written. + * + * The method returns true on success and false otherwise. + */ +bool grpc_gcp_handshaker_req_encode(grpc_gcp_handshaker_req* req, + grpc_slice* slice); + +/* This method destroys an ALTS handshake request. */ +void grpc_gcp_handshaker_req_destroy(grpc_gcp_handshaker_req* req); + +/* This method creates an ALTS handshake response. */ +grpc_gcp_handshaker_resp* grpc_gcp_handshaker_resp_create(void); + +/** + * This method de-serializes a data stream and stores the result + * in an ALTS handshake response. + * + * - slice: a data stream containing a serialized ALTS handshake response. + * - resp: an ALTS handshake response used to hold de-serialized result. + * + * The method returns true on success and false otherwise. + */ +bool grpc_gcp_handshaker_resp_decode(grpc_slice slice, + grpc_gcp_handshaker_resp* resp); + +/* This method destroys an ALTS handshake response. */ +void grpc_gcp_handshaker_resp_destroy(grpc_gcp_handshaker_resp* resp); + +#endif /* GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_SERVICE_API_H */ diff --git a/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc b/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc new file mode 100644 index 0000000000..e0e4184686 --- /dev/null +++ b/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc @@ -0,0 +1,143 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h" + +void add_repeated_field(repeated_field** head, const void* data) { + repeated_field* field = + static_cast(gpr_zalloc(sizeof(*field))); + field->data = data; + if (*head == nullptr) { + *head = field; + (*head)->next = nullptr; + } else { + field->next = *head; + *head = field; + } +} + +void destroy_repeated_field_list_identity(repeated_field* head) { + repeated_field* field = head; + while (field != nullptr) { + repeated_field* next_field = field->next; + const grpc_gcp_identity* identity = + static_cast(field->data); + destroy_slice(static_cast(identity->hostname.arg)); + destroy_slice(static_cast(identity->service_account.arg)); + gpr_free((void*)identity); + gpr_free(field); + field = next_field; + } +} + +void destroy_repeated_field_list_string(repeated_field* head) { + repeated_field* field = head; + while (field != nullptr) { + repeated_field* next_field = field->next; + destroy_slice((grpc_slice*)field->data); + gpr_free(field); + field = next_field; + } +} + +grpc_slice* create_slice(const char* data, size_t size) { + grpc_slice slice = grpc_slice_from_copied_buffer(data, size); + grpc_slice* cb_slice = + static_cast(gpr_zalloc(sizeof(*cb_slice))); + memcpy(cb_slice, &slice, sizeof(*cb_slice)); + return cb_slice; +} + +void destroy_slice(grpc_slice* slice) { + if (slice != nullptr) { + grpc_slice_unref(*slice); + gpr_free(slice); + } +} + +bool encode_string_or_bytes_cb(pb_ostream_t* stream, const pb_field_t* field, + void* const* arg) { + grpc_slice* slice = static_cast(*arg); + if (!pb_encode_tag_for_field(stream, field)) return false; + return pb_encode_string(stream, GRPC_SLICE_START_PTR(*slice), + GRPC_SLICE_LENGTH(*slice)); +} + +bool encode_repeated_identity_cb(pb_ostream_t* stream, const pb_field_t* field, + void* const* arg) { + repeated_field* var = static_cast(*arg); + while (var != nullptr) { + if (!pb_encode_tag_for_field(stream, field)) return false; + if (!pb_encode_submessage(stream, grpc_gcp_Identity_fields, + (grpc_gcp_identity*)var->data)) + return false; + var = var->next; + } + return true; +} + +bool encode_repeated_string_cb(pb_ostream_t* stream, const pb_field_t* field, + void* const* arg) { + repeated_field* var = static_cast(*arg); + while (var != nullptr) { + if (!pb_encode_tag_for_field(stream, field)) return false; + const grpc_slice* slice = static_cast(var->data); + if (!pb_encode_string(stream, GRPC_SLICE_START_PTR(*slice), + GRPC_SLICE_LENGTH(*slice))) + return false; + var = var->next; + } + return true; +} + +bool decode_string_or_bytes_cb(pb_istream_t* stream, const pb_field_t* field, + void** arg) { + grpc_slice slice = grpc_slice_malloc(stream->bytes_left); + grpc_slice* cb_slice = + static_cast(gpr_zalloc(sizeof(*cb_slice))); + memcpy(cb_slice, &slice, sizeof(*cb_slice)); + if (!pb_read(stream, GRPC_SLICE_START_PTR(*cb_slice), stream->bytes_left)) + return false; + *arg = cb_slice; + return true; +} + +bool decode_repeated_identity_cb(pb_istream_t* stream, const pb_field_t* field, + void** arg) { + grpc_gcp_identity* identity = + static_cast(gpr_zalloc(sizeof(*identity))); + identity->hostname.funcs.decode = decode_string_or_bytes_cb; + identity->service_account.funcs.decode = decode_string_or_bytes_cb; + add_repeated_field(reinterpret_cast(arg), identity); + if (!pb_decode(stream, grpc_gcp_Identity_fields, identity)) return false; + return true; +} + +bool decode_repeated_string_cb(pb_istream_t* stream, const pb_field_t* field, + void** arg) { + grpc_slice slice = grpc_slice_malloc(stream->bytes_left); + grpc_slice* cb_slice = + static_cast(gpr_zalloc(sizeof(*cb_slice))); + memcpy(cb_slice, &slice, sizeof(grpc_slice)); + if (!pb_read(stream, GRPC_SLICE_START_PTR(*cb_slice), stream->bytes_left)) + return false; + add_repeated_field(reinterpret_cast(arg), cb_slice); + return true; +} diff --git a/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h b/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h new file mode 100644 index 0000000000..8fe8f73f8b --- /dev/null +++ b/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h @@ -0,0 +1,149 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_SERVICE_API_UTIL_H +#define GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_SERVICE_API_UTIL_H + +#include + +#include "third_party/nanopb/pb_decode.h" +#include "third_party/nanopb/pb_encode.h" + +#include +#include +#include +#include + +#include "src/core/tsi/alts/handshaker/handshaker.pb.h" + +/** + * An implementation of utility functions used to serialize/ + * de-serialize ALTS handshake requests/responses. All APIs in the header + * are thread-compatible. + */ + +/* Renaming of message/field structs generated by nanopb compiler. */ +typedef grpc_gcp_HandshakeProtocol grpc_gcp_handshake_protocol; +typedef grpc_gcp_NetworkProtocol grpc_gcp_network_protocol; +typedef grpc_gcp_Identity grpc_gcp_identity; +typedef grpc_gcp_NextHandshakeMessageReq grpc_gcp_next_handshake_message_req; +typedef grpc_gcp_ServerHandshakeParameters grpc_gcp_server_handshake_parameters; +typedef grpc_gcp_Endpoint grpc_gcp_endpoint; +typedef grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry + grpc_gcp_handshake_parameters_entry; +typedef grpc_gcp_StartClientHandshakeReq grpc_gcp_start_client_handshake_req; +typedef grpc_gcp_StartServerHandshakeReq grpc_gcp_start_server_handshake_req; +typedef grpc_gcp_HandshakerReq grpc_gcp_handshaker_req; +typedef grpc_gcp_HandshakerResult grpc_gcp_handshaker_result; +typedef grpc_gcp_HandshakerStatus grpc_gcp_handshaker_status; +typedef grpc_gcp_HandshakerResp grpc_gcp_handshaker_resp; + +typedef enum { + CLIENT_START_REQ = 0, /* StartClientHandshakeReq. */ + SERVER_START_REQ = 1, /* StartServerHandshakeReq. */ + NEXT_REQ = 2, /* NextHandshakeMessageReq. */ +} grpc_gcp_handshaker_req_type; + +/** + * A struct representing a repeated field. The struct is used to organize all + * instances of a specific repeated field into a linked list, which then will + * be used at encode/decode phase. For instance at the encode phase, the encode + * function will iterate through the list, encode each field, and then output + * the result to the stream. + */ +typedef struct repeated_field_ { + struct repeated_field_* next; + const void* data; +} repeated_field; + +/** + * This method adds a repeated field to the head of repeated field list. + * + * - head: a head of repeated field list. + * - field: a repeated field to be added to the list. + */ +void add_repeated_field(repeated_field** head, const void* field); + +/** + * This method destroys a repeated field list that consists of string type + * fields. + * + * - head: a head of repeated field list. + */ +void destroy_repeated_field_list_string(repeated_field* head); + +/** + * This method destroys a repeated field list that consists of + * grpc_gcp_identity type fields. + * + * - head: a head of repeated field list. + */ +void destroy_repeated_field_list_identity(repeated_field* head); + +/** + * This method creates a grpc_slice instance by copying a data buffer. It is + * similar to grpc_slice_from_copied_buffer() except that it returns an instance + * allocated from the heap. + * + * - data: a data buffer to be copied to grpc_slice instance. + * - size: size of data buffer. + */ +grpc_slice* create_slice(const char* data, size_t size); + +/* This method destroys a grpc_slice instance. */ +void destroy_slice(grpc_slice* slice); + +/** + * The following encode/decode functions will be assigned to encode/decode + * function pointers of pb_callback_t struct (defined in + * //third_party/nanopb/pb.h), that represent a repeated field with a dynamic + * length (e.g., a string type or repeated field). + */ + +/* This method is an encode callback function for a string or byte array. */ +bool encode_string_or_bytes_cb(pb_ostream_t* stream, const pb_field_t* field, + void* const* arg); + +/** + * This method is an encode callback function for a repeated grpc_gcp_identity + * field. + */ +bool encode_repeated_identity_cb(pb_ostream_t* stream, const pb_field_t* field, + void* const* arg); + +/* This method is an encode callback function for a repeated string field. */ +bool encode_repeated_string_cb(pb_ostream_t* stream, const pb_field_t* field, + void* const* arg); + +/** + * This method is a decode callback function for a string or byte array field. + */ +bool decode_string_or_bytes_cb(pb_istream_t* stream, const pb_field_t* field, + void** arg); +/** + * This method is a decode callback function for a repeated grpc_gcp_identity + * field. + */ +bool decode_repeated_identity_cb(pb_istream_t* stream, const pb_field_t* field, + void** arg); + +/* This method is a decode callback function for a repeated string field. */ +bool decode_repeated_string_cb(pb_istream_t* stream, const pb_field_t* field, + void** arg); + +#endif /* GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_SERVICE_API_UTIL_H */ diff --git a/src/core/tsi/alts/handshaker/alts_tsi_event.cc b/src/core/tsi/alts/handshaker/alts_tsi_event.cc new file mode 100644 index 0000000000..ec0bf12b95 --- /dev/null +++ b/src/core/tsi/alts/handshaker/alts_tsi_event.cc @@ -0,0 +1,73 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/tsi/alts/handshaker/alts_tsi_event.h" + +#include +#include +#include + +tsi_result alts_tsi_event_create(alts_tsi_handshaker* handshaker, + tsi_handshaker_on_next_done_cb cb, + void* user_data, + grpc_alts_credentials_options* options, + grpc_slice target_name, + alts_tsi_event** event) { + if (event == nullptr || handshaker == nullptr || cb == nullptr) { + gpr_log(GPR_ERROR, "Invalid arguments to alts_tsi_event_create()"); + return TSI_INVALID_ARGUMENT; + } + alts_tsi_event* e = static_cast(gpr_zalloc(sizeof(*e))); + e->handshaker = handshaker; + e->cb = cb; + e->user_data = user_data; + e->options = grpc_alts_credentials_options_copy(options); + e->target_name = grpc_slice_copy(target_name); + grpc_metadata_array_init(&e->initial_metadata); + grpc_metadata_array_init(&e->trailing_metadata); + *event = e; + return TSI_OK; +} + +void alts_tsi_event_dispatch_to_handshaker(alts_tsi_event* event, bool is_ok) { + if (event == nullptr) { + gpr_log( + GPR_ERROR, + "ALTS TSI event is nullptr in alts_tsi_event_dispatch_to_handshaker()"); + return; + } + alts_tsi_handshaker_handle_response(event->handshaker, event->recv_buffer, + event->status, &event->details, event->cb, + event->user_data, is_ok); +} + +void alts_tsi_event_destroy(alts_tsi_event* event) { + if (event == nullptr) { + return; + } + grpc_byte_buffer_destroy(event->send_buffer); + grpc_byte_buffer_destroy(event->recv_buffer); + grpc_metadata_array_destroy(&event->initial_metadata); + grpc_metadata_array_destroy(&event->trailing_metadata); + grpc_slice_unref(event->details); + grpc_slice_unref(event->target_name); + grpc_alts_credentials_options_destroy(event->options); + gpr_free(event); +} diff --git a/src/core/tsi/alts/handshaker/alts_tsi_event.h b/src/core/tsi/alts/handshaker/alts_tsi_event.h new file mode 100644 index 0000000000..043e75d4a9 --- /dev/null +++ b/src/core/tsi/alts/handshaker/alts_tsi_event.h @@ -0,0 +1,93 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_EVENT_H +#define GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_EVENT_H + +#include + +#include +#include + +#include "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h" +#include "src/core/tsi/transport_security_interface.h" + +/** + * A ALTS TSI event interface. In asynchronous implementation of + * tsi_handshaker_next(), the function will exit after scheduling a handshaker + * request to ALTS handshaker service without waiting for response to return. + * The event is used to link the scheduled handshaker request with the + * corresponding response so that enough context information can be inferred + * from it to handle the response. All APIs in the header are thread-compatible. + */ + +/** + * Main struct for ALTS TSI event. It retains ownership on send_buffer and + * recv_buffer, but not on handshaker. + */ +typedef struct alts_tsi_event { + alts_tsi_handshaker* handshaker; + grpc_byte_buffer* send_buffer; + grpc_byte_buffer* recv_buffer; + grpc_status_code status; + grpc_slice details; + grpc_metadata_array initial_metadata; + grpc_metadata_array trailing_metadata; + tsi_handshaker_on_next_done_cb cb; + void* user_data; + grpc_alts_credentials_options* options; + grpc_slice target_name; +} alts_tsi_event; + +/** + * This method creates a ALTS TSI event. + * + * - handshaker: ALTS TSI handshaker instance associated with the event to be + * created. The created event does not own the handshaker instance. + * - cb: callback function to be called when handling data received from ALTS + * handshaker service. + * - user_data: argument to callback function. + * - options: ALTS credentials options. + * - target_name: name of endpoint used for secure naming check. + * - event: address of ALTS TSI event instance to be returned from the method. + * + * It returns TSI_OK on success and an error status code on failure. + */ +tsi_result alts_tsi_event_create(alts_tsi_handshaker* handshaker, + tsi_handshaker_on_next_done_cb cb, + void* user_data, + grpc_alts_credentials_options* options, + grpc_slice target_name, + alts_tsi_event** event); + +/** + * This method dispatches a ALTS TSI event received from the handshaker service, + * and a boolean flag indicating if the event is valid to read to ALTS TSI + * handshaker to process. It is called by TSI thread. + * + * - event: ALTS TSI event instance. + * - is_ok: a boolean value indicating if the event is valid to read. + */ +void alts_tsi_event_dispatch_to_handshaker(alts_tsi_event* event, bool is_ok); + +/** + * This method destroys the ALTS TSI event. + */ +void alts_tsi_event_destroy(alts_tsi_event* event); + +#endif /* GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_EVENT_H */ diff --git a/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc b/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc new file mode 100644 index 0000000000..529f2103c7 --- /dev/null +++ b/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc @@ -0,0 +1,483 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h" + +#include +#include +#include + +#include +#include +#include +#include + +#include "src/core/lib/gpr/host_port.h" +#include "src/core/lib/gprpp/thd.h" +#include "src/core/tsi/alts/frame_protector/alts_frame_protector.h" +#include "src/core/tsi/alts/handshaker/alts_handshaker_client.h" +#include "src/core/tsi/alts/handshaker/alts_tsi_utils.h" +#include "src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h" +#include "src/core/tsi/alts_transport_security.h" + +#define TSI_ALTS_INITIAL_BUFFER_SIZE 256 + +static alts_shared_resource* kSharedResource = alts_get_shared_resource(); + +/* Main struct for ALTS TSI handshaker. */ +typedef struct alts_tsi_handshaker { + tsi_handshaker base; + alts_handshaker_client* client; + grpc_slice recv_bytes; + grpc_slice target_name; + unsigned char* buffer; + size_t buffer_size; + bool is_client; + bool has_sent_start_message; + grpc_alts_credentials_options* options; +} alts_tsi_handshaker; + +/* Main struct for ALTS TSI handshaker result. */ +typedef struct alts_tsi_handshaker_result { + tsi_handshaker_result base; + char* peer_identity; + char* key_data; + unsigned char* unused_bytes; + size_t unused_bytes_size; + grpc_slice rpc_versions; + bool is_client; +} alts_tsi_handshaker_result; + +static tsi_result handshaker_result_extract_peer( + const tsi_handshaker_result* self, tsi_peer* peer) { + if (self == nullptr || peer == nullptr) { + gpr_log(GPR_ERROR, "Invalid argument to handshaker_result_extract_peer()"); + return TSI_INVALID_ARGUMENT; + } + alts_tsi_handshaker_result* result = + reinterpret_cast( + const_cast(self)); + GPR_ASSERT(kTsiAltsNumOfPeerProperties == 3); + tsi_result ok = tsi_construct_peer(kTsiAltsNumOfPeerProperties, peer); + int index = 0; + if (ok != TSI_OK) { + gpr_log(GPR_ERROR, "Failed to construct tsi peer"); + return ok; + } + GPR_ASSERT(&peer->properties[index] != nullptr); + ok = tsi_construct_string_peer_property_from_cstring( + TSI_CERTIFICATE_TYPE_PEER_PROPERTY, TSI_ALTS_CERTIFICATE_TYPE, + &peer->properties[index]); + if (ok != TSI_OK) { + tsi_peer_destruct(peer); + gpr_log(GPR_ERROR, "Failed to set tsi peer property"); + return ok; + } + index++; + GPR_ASSERT(&peer->properties[index] != nullptr); + ok = tsi_construct_string_peer_property_from_cstring( + TSI_ALTS_SERVICE_ACCOUNT_PEER_PROPERTY, result->peer_identity, + &peer->properties[index]); + if (ok != TSI_OK) { + tsi_peer_destruct(peer); + gpr_log(GPR_ERROR, "Failed to set tsi peer property"); + } + index++; + GPR_ASSERT(&peer->properties[index] != nullptr); + ok = tsi_construct_string_peer_property( + TSI_ALTS_RPC_VERSIONS, + reinterpret_cast(GRPC_SLICE_START_PTR(result->rpc_versions)), + GRPC_SLICE_LENGTH(result->rpc_versions), &peer->properties[2]); + if (ok != TSI_OK) { + tsi_peer_destruct(peer); + gpr_log(GPR_ERROR, "Failed to set tsi peer property"); + } + GPR_ASSERT(++index == kTsiAltsNumOfPeerProperties); + return ok; +} + +static tsi_result handshaker_result_create_zero_copy_grpc_protector( + const tsi_handshaker_result* self, size_t* max_output_protected_frame_size, + tsi_zero_copy_grpc_protector** protector) { + if (self == nullptr || protector == nullptr) { + gpr_log(GPR_ERROR, + "Invalid arguments to create_zero_copy_grpc_protector()"); + return TSI_INVALID_ARGUMENT; + } + alts_tsi_handshaker_result* result = + reinterpret_cast( + const_cast(self)); + tsi_result ok = alts_zero_copy_grpc_protector_create( + reinterpret_cast(result->key_data), + kAltsAes128GcmRekeyKeyLength, /*is_rekey=*/true, result->is_client, + /*is_integrity_only=*/false, max_output_protected_frame_size, protector); + if (ok != TSI_OK) { + gpr_log(GPR_ERROR, "Failed to create zero-copy grpc protector"); + } + return ok; +} + +static tsi_result handshaker_result_create_frame_protector( + const tsi_handshaker_result* self, size_t* max_output_protected_frame_size, + tsi_frame_protector** protector) { + if (self == nullptr || protector == nullptr) { + gpr_log(GPR_ERROR, + "Invalid arguments to handshaker_result_create_frame_protector()"); + return TSI_INVALID_ARGUMENT; + } + alts_tsi_handshaker_result* result = + reinterpret_cast( + const_cast(self)); + tsi_result ok = alts_create_frame_protector( + reinterpret_cast(result->key_data), + kAltsAes128GcmRekeyKeyLength, result->is_client, /*is_rekey=*/true, + max_output_protected_frame_size, protector); + if (ok != TSI_OK) { + gpr_log(GPR_ERROR, "Failed to create frame protector"); + } + return ok; +} + +static tsi_result handshaker_result_get_unused_bytes( + const tsi_handshaker_result* self, const unsigned char** bytes, + size_t* bytes_size) { + if (self == nullptr || bytes == nullptr || bytes_size == nullptr) { + gpr_log(GPR_ERROR, + "Invalid arguments to handshaker_result_get_unused_bytes()"); + return TSI_INVALID_ARGUMENT; + } + alts_tsi_handshaker_result* result = + reinterpret_cast( + const_cast(self)); + *bytes = result->unused_bytes; + *bytes_size = result->unused_bytes_size; + return TSI_OK; +} + +static void handshaker_result_destroy(tsi_handshaker_result* self) { + if (self == nullptr) { + return; + } + alts_tsi_handshaker_result* result = + reinterpret_cast( + const_cast(self)); + gpr_free(result->peer_identity); + gpr_free(result->key_data); + gpr_free(result->unused_bytes); + grpc_slice_unref(result->rpc_versions); + gpr_free(result); +} + +static const tsi_handshaker_result_vtable result_vtable = { + handshaker_result_extract_peer, + handshaker_result_create_zero_copy_grpc_protector, + handshaker_result_create_frame_protector, + handshaker_result_get_unused_bytes, handshaker_result_destroy}; + +static tsi_result create_handshaker_result(grpc_gcp_handshaker_resp* resp, + bool is_client, + tsi_handshaker_result** self) { + if (self == nullptr || resp == nullptr) { + gpr_log(GPR_ERROR, "Invalid arguments to create_handshaker_result()"); + return TSI_INVALID_ARGUMENT; + } + grpc_slice* key = static_cast(resp->result.key_data.arg); + GPR_ASSERT(key != nullptr); + grpc_slice* identity = + static_cast(resp->result.peer_identity.service_account.arg); + if (identity == nullptr) { + gpr_log(GPR_ERROR, "Invalid service account"); + return TSI_FAILED_PRECONDITION; + } + if (GRPC_SLICE_LENGTH(*key) < kAltsAes128GcmRekeyKeyLength) { + gpr_log(GPR_ERROR, "Bad key length"); + return TSI_FAILED_PRECONDITION; + } + alts_tsi_handshaker_result* result = + static_cast(gpr_zalloc(sizeof(*result))); + result->key_data = + static_cast(gpr_zalloc(kAltsAes128GcmRekeyKeyLength)); + memcpy(result->key_data, GRPC_SLICE_START_PTR(*key), + kAltsAes128GcmRekeyKeyLength); + result->peer_identity = grpc_slice_to_c_string(*identity); + if (!resp->result.has_peer_rpc_versions) { + gpr_log(GPR_ERROR, "Peer does not set RPC protocol versions."); + return TSI_FAILED_PRECONDITION; + } + if (!grpc_gcp_rpc_protocol_versions_encode(&resp->result.peer_rpc_versions, + &result->rpc_versions)) { + gpr_log(GPR_ERROR, "Failed to serialize peer's RPC protocol versions."); + return TSI_FAILED_PRECONDITION; + } + result->is_client = is_client; + result->base.vtable = &result_vtable; + *self = &result->base; + return TSI_OK; +} + +static tsi_result handshaker_next( + tsi_handshaker* self, const unsigned char* received_bytes, + size_t received_bytes_size, const unsigned char** bytes_to_send, + size_t* bytes_to_send_size, tsi_handshaker_result** result, + tsi_handshaker_on_next_done_cb cb, void* user_data) { + if (self == nullptr || cb == nullptr) { + gpr_log(GPR_ERROR, "Invalid arguments to handshaker_next()"); + return TSI_INVALID_ARGUMENT; + } + alts_tsi_handshaker* handshaker = + reinterpret_cast(self); + tsi_result ok = TSI_OK; + alts_tsi_event* event = nullptr; + ok = alts_tsi_event_create(handshaker, cb, user_data, handshaker->options, + handshaker->target_name, &event); + if (ok != TSI_OK) { + gpr_log(GPR_ERROR, "Failed to create ALTS TSI event"); + return ok; + } + grpc_slice slice = (received_bytes == nullptr || received_bytes_size == 0) + ? grpc_empty_slice() + : grpc_slice_from_copied_buffer( + reinterpret_cast(received_bytes), + received_bytes_size); + if (!handshaker->has_sent_start_message) { + ok = handshaker->is_client + ? alts_handshaker_client_start_client(handshaker->client, event) + : alts_handshaker_client_start_server(handshaker->client, event, + &slice); + handshaker->has_sent_start_message = true; + } else { + if (!GRPC_SLICE_IS_EMPTY(handshaker->recv_bytes)) { + grpc_slice_unref(handshaker->recv_bytes); + } + handshaker->recv_bytes = grpc_slice_ref(slice); + ok = alts_handshaker_client_next(handshaker->client, event, &slice); + } + grpc_slice_unref(slice); + if (ok != TSI_OK) { + gpr_log(GPR_ERROR, "Failed to schedule ALTS handshaker requests"); + return ok; + } + return TSI_ASYNC; +} + +static void handshaker_destroy(tsi_handshaker* self) { + if (self == nullptr) { + return; + } + alts_tsi_handshaker* handshaker = + reinterpret_cast(self); + alts_handshaker_client_destroy(handshaker->client); + grpc_slice_unref(handshaker->recv_bytes); + grpc_slice_unref(handshaker->target_name); + grpc_alts_credentials_options_destroy(handshaker->options); + gpr_free(handshaker->buffer); + gpr_free(handshaker); +} + +static const tsi_handshaker_vtable handshaker_vtable = { + nullptr, nullptr, nullptr, nullptr, nullptr, handshaker_destroy, + handshaker_next}; + +static void thread_worker(void* arg) { + while (true) { + grpc_event event = grpc_completion_queue_next( + kSharedResource->cq, gpr_inf_future(GPR_CLOCK_REALTIME), nullptr); + GPR_ASSERT(event.type != GRPC_QUEUE_TIMEOUT); + if (event.type == GRPC_QUEUE_SHUTDOWN) { + /* signal alts_tsi_shutdown() to destroy completion queue. */ + grpc_tsi_alts_signal_for_cq_destroy(); + break; + } + /* event.type == GRPC_OP_COMPLETE. */ + alts_tsi_event* alts_event = static_cast(event.tag); + alts_tsi_event_dispatch_to_handshaker(alts_event, event.success); + alts_tsi_event_destroy(alts_event); + } +} + +static void init_shared_resources(const char* handshaker_service_url) { + GPR_ASSERT(handshaker_service_url != nullptr); + gpr_mu_lock(&kSharedResource->mu); + if (kSharedResource->channel == nullptr) { + gpr_cv_init(&kSharedResource->cv); + kSharedResource->channel = + grpc_insecure_channel_create(handshaker_service_url, nullptr, nullptr); + kSharedResource->cq = grpc_completion_queue_create_for_next(nullptr); + kSharedResource->thread = + grpc_core::Thread("alts_tsi_handshaker", &thread_worker, nullptr); + kSharedResource->thread.Start(); + } + gpr_mu_unlock(&kSharedResource->mu); +} + +tsi_result alts_tsi_handshaker_create( + const grpc_alts_credentials_options* options, const char* target_name, + const char* handshaker_service_url, bool is_client, tsi_handshaker** self) { + if (handshaker_service_url == nullptr || self == nullptr || + options == nullptr || (is_client && target_name == nullptr)) { + gpr_log(GPR_ERROR, "Invalid arguments to alts_tsi_handshaker_create()"); + return TSI_INVALID_ARGUMENT; + } + init_shared_resources(handshaker_service_url); + alts_handshaker_client* client = alts_grpc_handshaker_client_create( + kSharedResource->channel, kSharedResource->cq, handshaker_service_url); + if (client == nullptr) { + gpr_log(GPR_ERROR, "Failed to create ALTS handshaker client"); + return TSI_FAILED_PRECONDITION; + } + alts_tsi_handshaker* handshaker = + static_cast(gpr_zalloc(sizeof(*handshaker))); + handshaker->client = client; + handshaker->buffer_size = TSI_ALTS_INITIAL_BUFFER_SIZE; + handshaker->buffer = + static_cast(gpr_zalloc(handshaker->buffer_size)); + handshaker->is_client = is_client; + handshaker->has_sent_start_message = false; + handshaker->target_name = target_name == nullptr + ? grpc_empty_slice() + : grpc_slice_from_static_string(target_name); + handshaker->options = grpc_alts_credentials_options_copy(options); + handshaker->base.vtable = &handshaker_vtable; + *self = &handshaker->base; + return TSI_OK; +} + +static bool is_handshake_finished_properly(grpc_gcp_handshaker_resp* resp) { + GPR_ASSERT(resp != nullptr); + if (resp->has_result) { + return true; + } + return false; +} + +static void set_unused_bytes(tsi_handshaker_result* self, + grpc_slice* recv_bytes, size_t bytes_consumed) { + GPR_ASSERT(recv_bytes != nullptr && self != nullptr); + if (GRPC_SLICE_LENGTH(*recv_bytes) == bytes_consumed) { + return; + } + alts_tsi_handshaker_result* result = + reinterpret_cast(self); + result->unused_bytes_size = GRPC_SLICE_LENGTH(*recv_bytes) - bytes_consumed; + result->unused_bytes = + static_cast(gpr_zalloc(result->unused_bytes_size)); + memcpy(result->unused_bytes, + GRPC_SLICE_START_PTR(*recv_bytes) + bytes_consumed, + result->unused_bytes_size); +} + +void alts_tsi_handshaker_handle_response(alts_tsi_handshaker* handshaker, + grpc_byte_buffer* recv_buffer, + grpc_status_code status, + grpc_slice* details, + tsi_handshaker_on_next_done_cb cb, + void* user_data, bool is_ok) { + /* Invalid input check. */ + if (cb == nullptr) { + gpr_log(GPR_ERROR, + "cb is nullptr in alts_tsi_handshaker_handle_response()"); + return; + } + if (handshaker == nullptr || recv_buffer == nullptr) { + gpr_log(GPR_ERROR, + "Invalid arguments to alts_tsi_handshaker_handle_response()"); + cb(TSI_INTERNAL_ERROR, user_data, nullptr, 0, nullptr); + return; + } + /* Failed grpc call check. */ + if (!is_ok || status != GRPC_STATUS_OK) { + gpr_log(GPR_ERROR, "grpc call made to handshaker service failed"); + if (details != nullptr) { + char* error_details = grpc_slice_to_c_string(*details); + gpr_log(GPR_ERROR, "error details:%s", error_details); + gpr_free(error_details); + } + cb(TSI_INTERNAL_ERROR, user_data, nullptr, 0, nullptr); + return; + } + grpc_gcp_handshaker_resp* resp = + alts_tsi_utils_deserialize_response(recv_buffer); + /* Invalid handshaker response check. */ + if (resp == nullptr) { + gpr_log(GPR_ERROR, "alts_tsi_utils_deserialize_response() failed"); + cb(TSI_DATA_CORRUPTED, user_data, nullptr, 0, nullptr); + return; + } + grpc_slice* slice = static_cast(resp->out_frames.arg); + unsigned char* bytes_to_send = nullptr; + size_t bytes_to_send_size = 0; + if (slice != nullptr) { + bytes_to_send_size = GRPC_SLICE_LENGTH(*slice); + while (bytes_to_send_size > handshaker->buffer_size) { + handshaker->buffer_size *= 2; + handshaker->buffer = static_cast( + gpr_realloc(handshaker->buffer, handshaker->buffer_size)); + } + memcpy(handshaker->buffer, GRPC_SLICE_START_PTR(*slice), + bytes_to_send_size); + bytes_to_send = handshaker->buffer; + } + tsi_handshaker_result* result = nullptr; + if (is_handshake_finished_properly(resp)) { + create_handshaker_result(resp, handshaker->is_client, &result); + set_unused_bytes(result, &handshaker->recv_bytes, resp->bytes_consumed); + } + grpc_status_code code = static_cast(resp->status.code); + grpc_gcp_handshaker_resp_destroy(resp); + cb(alts_tsi_utils_convert_to_tsi_result(code), user_data, bytes_to_send, + bytes_to_send_size, result); +} + +namespace grpc_core { +namespace internal { + +bool alts_tsi_handshaker_get_has_sent_start_message_for_testing( + alts_tsi_handshaker* handshaker) { + GPR_ASSERT(handshaker != nullptr); + return handshaker->has_sent_start_message; +} + +bool alts_tsi_handshaker_get_is_client_for_testing( + alts_tsi_handshaker* handshaker) { + GPR_ASSERT(handshaker != nullptr); + return handshaker->is_client; +} + +void alts_tsi_handshaker_set_recv_bytes_for_testing( + alts_tsi_handshaker* handshaker, grpc_slice* slice) { + GPR_ASSERT(handshaker != nullptr && slice != nullptr); + handshaker->recv_bytes = grpc_slice_ref(*slice); +} + +grpc_slice alts_tsi_handshaker_get_recv_bytes_for_testing( + alts_tsi_handshaker* handshaker) { + GPR_ASSERT(handshaker != nullptr); + return handshaker->recv_bytes; +} + +void alts_tsi_handshaker_set_client_for_testing( + alts_tsi_handshaker* handshaker, alts_handshaker_client* client) { + GPR_ASSERT(handshaker != nullptr && client != nullptr); + alts_handshaker_client_destroy(handshaker->client); + handshaker->client = client; +} + +} // namespace internal +} // namespace grpc_core diff --git a/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h b/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h new file mode 100644 index 0000000000..227b30ce53 --- /dev/null +++ b/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h @@ -0,0 +1,83 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_HANDSHAKER_H +#define GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_HANDSHAKER_H + +#include + +#include + +#include "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h" +#include "src/core/tsi/alts_transport_security.h" +#include "src/core/tsi/transport_security.h" +#include "src/core/tsi/transport_security_interface.h" + +#define TSI_ALTS_SERVICE_ACCOUNT_PEER_PROPERTY "service_accont" +#define TSI_ALTS_CERTIFICATE_TYPE "ALTS" +#define TSI_ALTS_RPC_VERSIONS "rpc_versions" + +const size_t kTsiAltsNumOfPeerProperties = 3; + +/** + * Main struct for ALTS TSI handshaker. All APIs in the header are + * thread-comptabile. + */ +typedef struct alts_tsi_handshaker alts_tsi_handshaker; + +/** + * This method creates a ALTS TSI handshaker instance. + * + * - options: ALTS credentials options containing information passed from TSI + * caller (e.g., rpc protocol versions). + * - target_name: the name of the endpoint that the channel is connecting to, + * and will be used for secure naming check. + * - handshaker_service_url: address of ALTS handshaker service in the format of + * "host:port". + * - is_client: boolean value indicating if the handshaker is used at the client + * (is_client = true) or server (is_client = false) side. + * - self: address of ALTS TSI handshaker instance to be returned from the + * method. + * + * It returns TSI_OK on success and an error status code on failure. + */ +tsi_result alts_tsi_handshaker_create( + const grpc_alts_credentials_options* options, const char* target_name, + const char* handshaker_service_url, bool is_client, tsi_handshaker** self); + +/** + * This method handles handshaker response returned from ALTS handshaker + * service. + * + * - handshaker: ALTS TSI handshaker instance. + * - recv_buffer: buffer holding data received from the handshaker service. + * - status: status of the grpc call made to the handshaker service. + * - details: error details of the grpc call made to the handshaker service. + * - cb: callback function of ALTS TSI event. + * - user_data: argument of callback function. + * - is_ok: a boolean value indicating if the handshaker response is ok to read. + * + */ +void alts_tsi_handshaker_handle_response(alts_tsi_handshaker* handshaker, + grpc_byte_buffer* recv_buffer, + grpc_status_code status, + grpc_slice* details, + tsi_handshaker_on_next_done_cb cb, + void* user_data, bool is_ok); + +#endif /* GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_HANDSHAKER_H */ diff --git a/src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h b/src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h new file mode 100644 index 0000000000..9b7b9bb6b1 --- /dev/null +++ b/src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h @@ -0,0 +1,52 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_HANDSHAKER_PRIVATE_H +#define GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_HANDSHAKER_PRIVATE_H + +#include + +#include "src/core/tsi/alts/handshaker/alts_handshaker_client.h" + +namespace grpc_core { +namespace internal { + +/** + * Unsafe, use for testing only. It allows the caller to change the way the + * ALTS TSI handshaker schedules handshaker requests. + */ +void alts_tsi_handshaker_set_client_for_testing(alts_tsi_handshaker* handshaker, + alts_handshaker_client* client); + +/* For testing only. */ +bool alts_tsi_handshaker_get_has_sent_start_message_for_testing( + alts_tsi_handshaker* handshaker); + +bool alts_tsi_handshaker_get_is_client_for_testing( + alts_tsi_handshaker* handshaker); + +void alts_tsi_handshaker_set_recv_bytes_for_testing( + alts_tsi_handshaker* handshaker, grpc_slice* slice); + +grpc_slice alts_tsi_handshaker_get_recv_bytes_for_testing( + alts_tsi_handshaker* handshaker); + +} // namespace internal +} // namespace grpc_core + +#endif /* GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_HANDSHAKER_PRIVATE_H */ diff --git a/src/core/tsi/alts/handshaker/alts_tsi_utils.cc b/src/core/tsi/alts/handshaker/alts_tsi_utils.cc new file mode 100644 index 0000000000..d9b5e6c945 --- /dev/null +++ b/src/core/tsi/alts/handshaker/alts_tsi_utils.cc @@ -0,0 +1,58 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/tsi/alts/handshaker/alts_tsi_utils.h" + +#include + +tsi_result alts_tsi_utils_convert_to_tsi_result(grpc_status_code code) { + switch (code) { + case GRPC_STATUS_OK: + return TSI_OK; + case GRPC_STATUS_UNKNOWN: + return TSI_UNKNOWN_ERROR; + case GRPC_STATUS_INVALID_ARGUMENT: + return TSI_INVALID_ARGUMENT; + case GRPC_STATUS_NOT_FOUND: + return TSI_NOT_FOUND; + case GRPC_STATUS_INTERNAL: + return TSI_INTERNAL_ERROR; + default: + return TSI_UNKNOWN_ERROR; + } +} + +grpc_gcp_handshaker_resp* alts_tsi_utils_deserialize_response( + grpc_byte_buffer* resp_buffer) { + GPR_ASSERT(resp_buffer != nullptr); + grpc_byte_buffer_reader bbr; + grpc_byte_buffer_reader_init(&bbr, resp_buffer); + grpc_slice slice = grpc_byte_buffer_reader_readall(&bbr); + grpc_gcp_handshaker_resp* resp = grpc_gcp_handshaker_resp_create(); + bool ok = grpc_gcp_handshaker_resp_decode(slice, resp); + grpc_slice_unref(slice); + grpc_byte_buffer_reader_destroy(&bbr); + if (!ok) { + grpc_gcp_handshaker_resp_destroy(resp); + gpr_log(GPR_ERROR, "grpc_gcp_handshaker_resp_decode() failed"); + return nullptr; + } + return resp; +} diff --git a/src/core/tsi/alts/handshaker/alts_tsi_utils.h b/src/core/tsi/alts/handshaker/alts_tsi_utils.h new file mode 100644 index 0000000000..9ef649de2b --- /dev/null +++ b/src/core/tsi/alts/handshaker/alts_tsi_utils.h @@ -0,0 +1,52 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_UTILS_H +#define GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_UTILS_H + +#include + +#include +#include + +#include "src/core/tsi/alts/handshaker/alts_handshaker_service_api.h" +#include "src/core/tsi/transport_security_interface.h" + +/** + * This method converts grpc_status_code code to the corresponding tsi_result + * code. + * + * - code: grpc_status_code code. + * + * It returns the converted tsi_result code. + */ +tsi_result alts_tsi_utils_convert_to_tsi_result(grpc_status_code code); + +/** + * This method deserializes a handshaker response returned from ALTS handshaker + * service. + * + * - bytes_received: data returned from ALTS handshaker service. + * + * It returns a deserialized handshaker response on success and nullptr on + * failure. + */ +grpc_gcp_handshaker_resp* alts_tsi_utils_deserialize_response( + grpc_byte_buffer* resp_buffer); + +#endif /* GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_TSI_UTILS_H */ diff --git a/src/core/tsi/alts/handshaker/altscontext.pb.c b/src/core/tsi/alts/handshaker/altscontext.pb.c new file mode 100644 index 0000000000..81a82f5992 --- /dev/null +++ b/src/core/tsi/alts/handshaker/altscontext.pb.c @@ -0,0 +1,48 @@ +/* Automatically generated nanopb constant definitions */ +/* Generated by nanopb-0.3.7-dev */ + +#include "src/core/tsi/alts/handshaker/altscontext.pb.h" + +/* @@protoc_insertion_point(includes) */ +#if PB_PROTO_HEADER_VERSION != 30 +#error Regenerate this file with the current version of nanopb generator. +#endif + + + +const pb_field_t grpc_gcp_AltsContext_fields[7] = { + PB_FIELD( 1, STRING , OPTIONAL, CALLBACK, FIRST, grpc_gcp_AltsContext, application_protocol, application_protocol, 0), + PB_FIELD( 2, STRING , OPTIONAL, CALLBACK, OTHER, grpc_gcp_AltsContext, record_protocol, application_protocol, 0), + PB_FIELD( 3, UENUM , OPTIONAL, STATIC , OTHER, grpc_gcp_AltsContext, security_level, record_protocol, 0), + PB_FIELD( 4, STRING , OPTIONAL, CALLBACK, OTHER, grpc_gcp_AltsContext, peer_service_account, security_level, 0), + PB_FIELD( 5, STRING , OPTIONAL, CALLBACK, OTHER, grpc_gcp_AltsContext, local_service_account, peer_service_account, 0), + PB_FIELD( 6, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_AltsContext, peer_rpc_versions, local_service_account, &grpc_gcp_RpcProtocolVersions_fields), + PB_LAST_FIELD +}; + + +/* Check that field information fits in pb_field_t */ +#if !defined(PB_FIELD_32BIT) +/* If you get an error here, it means that you need to define PB_FIELD_32BIT + * compile-time option. You can do that in pb.h or on compiler command line. + * + * The reason you need to do this is that some of your messages contain tag + * numbers or field sizes that are larger than what can fit in 8 or 16 bit + * field descriptors. + */ +PB_STATIC_ASSERT((pb_membersize(grpc_gcp_AltsContext, peer_rpc_versions) < 65536), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_grpc_gcp_AltsContext) +#endif + +#if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT) +/* If you get an error here, it means that you need to define PB_FIELD_16BIT + * compile-time option. You can do that in pb.h or on compiler command line. + * + * The reason you need to do this is that some of your messages contain tag + * numbers or field sizes that are larger than what can fit in the default + * 8 bit descriptors. + */ +PB_STATIC_ASSERT((pb_membersize(grpc_gcp_AltsContext, peer_rpc_versions) < 256), YOU_MUST_DEFINE_PB_FIELD_16BIT_FOR_MESSAGES_grpc_gcp_AltsContext) +#endif + + +/* @@protoc_insertion_point(eof) */ diff --git a/src/core/tsi/alts/handshaker/altscontext.pb.h b/src/core/tsi/alts/handshaker/altscontext.pb.h new file mode 100644 index 0000000000..3e72d7f678 --- /dev/null +++ b/src/core/tsi/alts/handshaker/altscontext.pb.h @@ -0,0 +1,64 @@ +/* Automatically generated nanopb header */ +/* Generated by nanopb-0.3.7-dev */ + +#ifndef PB_GRPC_GCP_ALTSCONTEXT_PB_H_INCLUDED +#define PB_GRPC_GCP_ALTSCONTEXT_PB_H_INCLUDED +#include "third_party/nanopb/pb.h" +#include "src/core/tsi/alts/handshaker/transport_security_common.pb.h" + +/* @@protoc_insertion_point(includes) */ +#if PB_PROTO_HEADER_VERSION != 30 +#error Regenerate this file with the current version of nanopb generator. +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* Struct definitions */ +typedef struct _grpc_gcp_AltsContext { + pb_callback_t application_protocol; + pb_callback_t record_protocol; + bool has_security_level; + grpc_gcp_SecurityLevel security_level; + pb_callback_t peer_service_account; + pb_callback_t local_service_account; + bool has_peer_rpc_versions; + grpc_gcp_RpcProtocolVersions peer_rpc_versions; +/* @@protoc_insertion_point(struct:grpc_gcp_AltsContext) */ +} grpc_gcp_AltsContext; + +/* Default values for struct fields */ + +/* Initializer values for message structs */ +#define grpc_gcp_AltsContext_init_default {{{NULL}, NULL}, {{NULL}, NULL}, false, (grpc_gcp_SecurityLevel)0, {{NULL}, NULL}, {{NULL}, NULL}, false, grpc_gcp_RpcProtocolVersions_init_default} +#define grpc_gcp_AltsContext_init_zero {{{NULL}, NULL}, {{NULL}, NULL}, false, (grpc_gcp_SecurityLevel)0, {{NULL}, NULL}, {{NULL}, NULL}, false, grpc_gcp_RpcProtocolVersions_init_zero} + +/* Field tags (for use in manual encoding/decoding) */ +#define grpc_gcp_AltsContext_application_protocol_tag 1 +#define grpc_gcp_AltsContext_record_protocol_tag 2 +#define grpc_gcp_AltsContext_security_level_tag 3 +#define grpc_gcp_AltsContext_peer_service_account_tag 4 +#define grpc_gcp_AltsContext_local_service_account_tag 5 +#define grpc_gcp_AltsContext_peer_rpc_versions_tag 6 + +/* Struct field encoding specification for nanopb */ +extern const pb_field_t grpc_gcp_AltsContext_fields[7]; + +/* Maximum encoded size of messages (where known) */ +/* grpc_gcp_AltsContext_size depends on runtime parameters */ + +/* Message IDs (where set with "msgid" option) */ +#ifdef PB_MSGID + +#define ALTSCONTEXT_MESSAGES \ + + +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif +/* @@protoc_insertion_point(eof) */ + +#endif diff --git a/src/core/tsi/alts/handshaker/handshaker.pb.c b/src/core/tsi/alts/handshaker/handshaker.pb.c new file mode 100644 index 0000000000..bd992dfa4a --- /dev/null +++ b/src/core/tsi/alts/handshaker/handshaker.pb.c @@ -0,0 +1,123 @@ +/* Automatically generated nanopb constant definitions */ +/* Generated by nanopb-0.3.7-dev */ + +#include "src/core/tsi/alts/handshaker/handshaker.pb.h" + +/* @@protoc_insertion_point(includes) */ +#if PB_PROTO_HEADER_VERSION != 30 +#error Regenerate this file with the current version of nanopb generator. +#endif + + + +const pb_field_t grpc_gcp_Endpoint_fields[4] = { + PB_FIELD( 1, STRING , OPTIONAL, CALLBACK, FIRST, grpc_gcp_Endpoint, ip_address, ip_address, 0), + PB_FIELD( 2, INT32 , OPTIONAL, STATIC , OTHER, grpc_gcp_Endpoint, port, ip_address, 0), + PB_FIELD( 3, UENUM , OPTIONAL, STATIC , OTHER, grpc_gcp_Endpoint, protocol, port, 0), + PB_LAST_FIELD +}; + +const pb_field_t grpc_gcp_Identity_fields[3] = { + PB_FIELD( 1, STRING , OPTIONAL, CALLBACK, FIRST, grpc_gcp_Identity, service_account, service_account, 0), + PB_FIELD( 2, STRING , OPTIONAL, CALLBACK, OTHER, grpc_gcp_Identity, hostname, service_account, 0), + PB_LAST_FIELD +}; + +const pb_field_t grpc_gcp_StartClientHandshakeReq_fields[10] = { + PB_FIELD( 1, UENUM , OPTIONAL, STATIC , FIRST, grpc_gcp_StartClientHandshakeReq, handshake_security_protocol, handshake_security_protocol, 0), + PB_FIELD( 2, STRING , REPEATED, CALLBACK, OTHER, grpc_gcp_StartClientHandshakeReq, application_protocols, handshake_security_protocol, 0), + PB_FIELD( 3, STRING , REPEATED, CALLBACK, OTHER, grpc_gcp_StartClientHandshakeReq, record_protocols, application_protocols, 0), + PB_FIELD( 4, MESSAGE , REPEATED, CALLBACK, OTHER, grpc_gcp_StartClientHandshakeReq, target_identities, record_protocols, &grpc_gcp_Identity_fields), + PB_FIELD( 5, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_StartClientHandshakeReq, local_identity, target_identities, &grpc_gcp_Identity_fields), + PB_FIELD( 6, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_StartClientHandshakeReq, local_endpoint, local_identity, &grpc_gcp_Endpoint_fields), + PB_FIELD( 7, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_StartClientHandshakeReq, remote_endpoint, local_endpoint, &grpc_gcp_Endpoint_fields), + PB_FIELD( 8, STRING , OPTIONAL, CALLBACK, OTHER, grpc_gcp_StartClientHandshakeReq, target_name, remote_endpoint, 0), + PB_FIELD( 9, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_StartClientHandshakeReq, rpc_versions, target_name, &grpc_gcp_RpcProtocolVersions_fields), + PB_LAST_FIELD +}; + +const pb_field_t grpc_gcp_ServerHandshakeParameters_fields[3] = { + PB_FIELD( 1, STRING , REPEATED, CALLBACK, FIRST, grpc_gcp_ServerHandshakeParameters, record_protocols, record_protocols, 0), + PB_FIELD( 2, MESSAGE , REPEATED, CALLBACK, OTHER, grpc_gcp_ServerHandshakeParameters, local_identities, record_protocols, &grpc_gcp_Identity_fields), + PB_LAST_FIELD +}; + +const pb_field_t grpc_gcp_StartServerHandshakeReq_fields[7] = { + PB_FIELD( 1, STRING , REPEATED, CALLBACK, FIRST, grpc_gcp_StartServerHandshakeReq, application_protocols, application_protocols, 0), + PB_FIELD( 2, MESSAGE , REPEATED, STATIC , OTHER, grpc_gcp_StartServerHandshakeReq, handshake_parameters, application_protocols, &grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_fields), + PB_FIELD( 3, BYTES , OPTIONAL, CALLBACK, OTHER, grpc_gcp_StartServerHandshakeReq, in_bytes, handshake_parameters, 0), + PB_FIELD( 4, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_StartServerHandshakeReq, local_endpoint, in_bytes, &grpc_gcp_Endpoint_fields), + PB_FIELD( 5, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_StartServerHandshakeReq, remote_endpoint, local_endpoint, &grpc_gcp_Endpoint_fields), + PB_FIELD( 6, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_StartServerHandshakeReq, rpc_versions, remote_endpoint, &grpc_gcp_RpcProtocolVersions_fields), + PB_LAST_FIELD +}; + +const pb_field_t grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_fields[3] = { + PB_FIELD( 1, INT32 , OPTIONAL, STATIC , FIRST, grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry, key, key, 0), + PB_FIELD( 2, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry, value, key, &grpc_gcp_ServerHandshakeParameters_fields), + PB_LAST_FIELD +}; + +const pb_field_t grpc_gcp_NextHandshakeMessageReq_fields[2] = { + PB_FIELD( 1, BYTES , OPTIONAL, CALLBACK, FIRST, grpc_gcp_NextHandshakeMessageReq, in_bytes, in_bytes, 0), + PB_LAST_FIELD +}; + +const pb_field_t grpc_gcp_HandshakerReq_fields[4] = { + PB_FIELD( 1, MESSAGE , OPTIONAL, STATIC , FIRST, grpc_gcp_HandshakerReq, client_start, client_start, &grpc_gcp_StartClientHandshakeReq_fields), + PB_FIELD( 2, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_HandshakerReq, server_start, client_start, &grpc_gcp_StartServerHandshakeReq_fields), + PB_FIELD( 3, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_HandshakerReq, next, server_start, &grpc_gcp_NextHandshakeMessageReq_fields), + PB_LAST_FIELD +}; + +const pb_field_t grpc_gcp_HandshakerResult_fields[8] = { + PB_FIELD( 1, STRING , OPTIONAL, CALLBACK, FIRST, grpc_gcp_HandshakerResult, application_protocol, application_protocol, 0), + PB_FIELD( 2, STRING , OPTIONAL, CALLBACK, OTHER, grpc_gcp_HandshakerResult, record_protocol, application_protocol, 0), + PB_FIELD( 3, BYTES , OPTIONAL, CALLBACK, OTHER, grpc_gcp_HandshakerResult, key_data, record_protocol, 0), + PB_FIELD( 4, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_HandshakerResult, peer_identity, key_data, &grpc_gcp_Identity_fields), + PB_FIELD( 5, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_HandshakerResult, local_identity, peer_identity, &grpc_gcp_Identity_fields), + PB_FIELD( 6, BOOL , OPTIONAL, STATIC , OTHER, grpc_gcp_HandshakerResult, keep_channel_open, local_identity, 0), + PB_FIELD( 7, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_HandshakerResult, peer_rpc_versions, keep_channel_open, &grpc_gcp_RpcProtocolVersions_fields), + PB_LAST_FIELD +}; + +const pb_field_t grpc_gcp_HandshakerStatus_fields[3] = { + PB_FIELD( 1, UINT32 , OPTIONAL, STATIC , FIRST, grpc_gcp_HandshakerStatus, code, code, 0), + PB_FIELD( 2, STRING , OPTIONAL, CALLBACK, OTHER, grpc_gcp_HandshakerStatus, details, code, 0), + PB_LAST_FIELD +}; + +const pb_field_t grpc_gcp_HandshakerResp_fields[5] = { + PB_FIELD( 1, BYTES , OPTIONAL, CALLBACK, FIRST, grpc_gcp_HandshakerResp, out_frames, out_frames, 0), + PB_FIELD( 2, UINT32 , OPTIONAL, STATIC , OTHER, grpc_gcp_HandshakerResp, bytes_consumed, out_frames, 0), + PB_FIELD( 3, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_HandshakerResp, result, bytes_consumed, &grpc_gcp_HandshakerResult_fields), + PB_FIELD( 4, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_HandshakerResp, status, result, &grpc_gcp_HandshakerStatus_fields), + PB_LAST_FIELD +}; + + +/* Check that field information fits in pb_field_t */ +#if !defined(PB_FIELD_32BIT) +/* If you get an error here, it means that you need to define PB_FIELD_32BIT + * compile-time option. You can do that in pb.h or on compiler command line. + * + * The reason you need to do this is that some of your messages contain tag + * numbers or field sizes that are larger than what can fit in 8 or 16 bit + * field descriptors. + */ +PB_STATIC_ASSERT((pb_membersize(grpc_gcp_StartClientHandshakeReq, target_identities) < 65536 && pb_membersize(grpc_gcp_StartClientHandshakeReq, local_identity) < 65536 && pb_membersize(grpc_gcp_StartClientHandshakeReq, local_endpoint) < 65536 && pb_membersize(grpc_gcp_StartClientHandshakeReq, remote_endpoint) < 65536 && pb_membersize(grpc_gcp_StartClientHandshakeReq, rpc_versions) < 65536 && pb_membersize(grpc_gcp_ServerHandshakeParameters, local_identities) < 65536 && pb_membersize(grpc_gcp_StartServerHandshakeReq, handshake_parameters[0]) < 65536 && pb_membersize(grpc_gcp_StartServerHandshakeReq, local_endpoint) < 65536 && pb_membersize(grpc_gcp_StartServerHandshakeReq, remote_endpoint) < 65536 && pb_membersize(grpc_gcp_StartServerHandshakeReq, rpc_versions) < 65536 && pb_membersize(grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry, value) < 65536 && pb_membersize(grpc_gcp_HandshakerReq, client_start) < 65536 && pb_membersize(grpc_gcp_HandshakerReq, server_start) < 65536 && pb_membersize(grpc_gcp_HandshakerReq, next) < 65536 && pb_membersize(grpc_gcp_HandshakerResult, peer_identity) < 65536 && pb_membersize(grpc_gcp_HandshakerResult, local_identity) < 65536 && pb_membersize(grpc_gcp_HandshakerResult, peer_rpc_versions) < 65536 && pb_membersize(grpc_gcp_HandshakerResp, result) < 65536 && pb_membersize(grpc_gcp_HandshakerResp, status) < 65536), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_grpc_gcp_Endpoint_grpc_gcp_Identity_grpc_gcp_StartClientHandshakeReq_grpc_gcp_ServerHandshakeParameters_grpc_gcp_StartServerHandshakeReq_grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_grpc_gcp_NextHandshakeMessageReq_grpc_gcp_HandshakerReq_grpc_gcp_HandshakerResult_grpc_gcp_HandshakerStatus_grpc_gcp_HandshakerResp) +#endif + +#if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT) +/* If you get an error here, it means that you need to define PB_FIELD_16BIT + * compile-time option. You can do that in pb.h or on compiler command line. + * + * The reason you need to do this is that some of your messages contain tag + * numbers or field sizes that are larger than what can fit in the default + * 8 bit descriptors. + */ +PB_STATIC_ASSERT((pb_membersize(grpc_gcp_StartClientHandshakeReq, target_identities) < 256 && pb_membersize(grpc_gcp_StartClientHandshakeReq, local_identity) < 256 && pb_membersize(grpc_gcp_StartClientHandshakeReq, local_endpoint) < 256 && pb_membersize(grpc_gcp_StartClientHandshakeReq, remote_endpoint) < 256 && pb_membersize(grpc_gcp_StartClientHandshakeReq, rpc_versions) < 256 && pb_membersize(grpc_gcp_ServerHandshakeParameters, local_identities) < 256 && pb_membersize(grpc_gcp_StartServerHandshakeReq, handshake_parameters[0]) < 256 && pb_membersize(grpc_gcp_StartServerHandshakeReq, local_endpoint) < 256 && pb_membersize(grpc_gcp_StartServerHandshakeReq, remote_endpoint) < 256 && pb_membersize(grpc_gcp_StartServerHandshakeReq, rpc_versions) < 256 && pb_membersize(grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry, value) < 256 && pb_membersize(grpc_gcp_HandshakerReq, client_start) < 256 && pb_membersize(grpc_gcp_HandshakerReq, server_start) < 256 && pb_membersize(grpc_gcp_HandshakerReq, next) < 256 && pb_membersize(grpc_gcp_HandshakerResult, peer_identity) < 256 && pb_membersize(grpc_gcp_HandshakerResult, local_identity) < 256 && pb_membersize(grpc_gcp_HandshakerResult, peer_rpc_versions) < 256 && pb_membersize(grpc_gcp_HandshakerResp, result) < 256 && pb_membersize(grpc_gcp_HandshakerResp, status) < 256), YOU_MUST_DEFINE_PB_FIELD_16BIT_FOR_MESSAGES_grpc_gcp_Endpoint_grpc_gcp_Identity_grpc_gcp_StartClientHandshakeReq_grpc_gcp_ServerHandshakeParameters_grpc_gcp_StartServerHandshakeReq_grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_grpc_gcp_NextHandshakeMessageReq_grpc_gcp_HandshakerReq_grpc_gcp_HandshakerResult_grpc_gcp_HandshakerStatus_grpc_gcp_HandshakerResp) +#endif + + +/* @@protoc_insertion_point(eof) */ diff --git a/src/core/tsi/alts/handshaker/handshaker.pb.h b/src/core/tsi/alts/handshaker/handshaker.pb.h new file mode 100644 index 0000000000..0805a144de --- /dev/null +++ b/src/core/tsi/alts/handshaker/handshaker.pb.h @@ -0,0 +1,255 @@ +/* Automatically generated nanopb header */ +/* Generated by nanopb-0.3.7-dev */ + +#ifndef PB_GRPC_GCP_HANDSHAKER_PB_H_INCLUDED +#define PB_GRPC_GCP_HANDSHAKER_PB_H_INCLUDED +#include "third_party/nanopb/pb.h" +#include "src/core/tsi/alts/handshaker/transport_security_common.pb.h" + +/* @@protoc_insertion_point(includes) */ +#if PB_PROTO_HEADER_VERSION != 30 +#error Regenerate this file with the current version of nanopb generator. +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* Enum definitions */ +typedef enum _grpc_gcp_HandshakeProtocol { + grpc_gcp_HandshakeProtocol_HANDSHAKE_PROTOCOL_UNSPECIFIED = 0, + grpc_gcp_HandshakeProtocol_TLS = 1, + grpc_gcp_HandshakeProtocol_ALTS = 2 +} grpc_gcp_HandshakeProtocol; +#define _grpc_gcp_HandshakeProtocol_MIN grpc_gcp_HandshakeProtocol_HANDSHAKE_PROTOCOL_UNSPECIFIED +#define _grpc_gcp_HandshakeProtocol_MAX grpc_gcp_HandshakeProtocol_ALTS +#define _grpc_gcp_HandshakeProtocol_ARRAYSIZE ((grpc_gcp_HandshakeProtocol)(grpc_gcp_HandshakeProtocol_ALTS+1)) + +typedef enum _grpc_gcp_NetworkProtocol { + grpc_gcp_NetworkProtocol_NETWORK_PROTOCOL_UNSPECIFIED = 0, + grpc_gcp_NetworkProtocol_TCP = 1, + grpc_gcp_NetworkProtocol_UDP = 2 +} grpc_gcp_NetworkProtocol; +#define _grpc_gcp_NetworkProtocol_MIN grpc_gcp_NetworkProtocol_NETWORK_PROTOCOL_UNSPECIFIED +#define _grpc_gcp_NetworkProtocol_MAX grpc_gcp_NetworkProtocol_UDP +#define _grpc_gcp_NetworkProtocol_ARRAYSIZE ((grpc_gcp_NetworkProtocol)(grpc_gcp_NetworkProtocol_UDP+1)) + +/* Struct definitions */ +typedef struct _grpc_gcp_Identity { + pb_callback_t service_account; + pb_callback_t hostname; +/* @@protoc_insertion_point(struct:grpc_gcp_Identity) */ +} grpc_gcp_Identity; + +typedef struct _grpc_gcp_NextHandshakeMessageReq { + pb_callback_t in_bytes; +/* @@protoc_insertion_point(struct:grpc_gcp_NextHandshakeMessageReq) */ +} grpc_gcp_NextHandshakeMessageReq; + +typedef struct _grpc_gcp_ServerHandshakeParameters { + pb_callback_t record_protocols; + pb_callback_t local_identities; +/* @@protoc_insertion_point(struct:grpc_gcp_ServerHandshakeParameters) */ +} grpc_gcp_ServerHandshakeParameters; + +typedef struct _grpc_gcp_Endpoint { + pb_callback_t ip_address; + bool has_port; + int32_t port; + bool has_protocol; + grpc_gcp_NetworkProtocol protocol; +/* @@protoc_insertion_point(struct:grpc_gcp_Endpoint) */ +} grpc_gcp_Endpoint; + +typedef struct _grpc_gcp_HandshakerResult { + pb_callback_t application_protocol; + pb_callback_t record_protocol; + pb_callback_t key_data; + bool has_peer_identity; + grpc_gcp_Identity peer_identity; + bool has_local_identity; + grpc_gcp_Identity local_identity; + bool has_keep_channel_open; + bool keep_channel_open; + bool has_peer_rpc_versions; + grpc_gcp_RpcProtocolVersions peer_rpc_versions; +/* @@protoc_insertion_point(struct:grpc_gcp_HandshakerResult) */ +} grpc_gcp_HandshakerResult; + +typedef struct _grpc_gcp_HandshakerStatus { + bool has_code; + uint32_t code; + pb_callback_t details; +/* @@protoc_insertion_point(struct:grpc_gcp_HandshakerStatus) */ +} grpc_gcp_HandshakerStatus; + +typedef struct _grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry { + bool has_key; + int32_t key; + bool has_value; + grpc_gcp_ServerHandshakeParameters value; +/* @@protoc_insertion_point(struct:grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry) */ +} grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry; + +typedef struct _grpc_gcp_HandshakerResp { + pb_callback_t out_frames; + bool has_bytes_consumed; + uint32_t bytes_consumed; + bool has_result; + grpc_gcp_HandshakerResult result; + bool has_status; + grpc_gcp_HandshakerStatus status; +/* @@protoc_insertion_point(struct:grpc_gcp_HandshakerResp) */ +} grpc_gcp_HandshakerResp; + +typedef struct _grpc_gcp_StartClientHandshakeReq { + bool has_handshake_security_protocol; + grpc_gcp_HandshakeProtocol handshake_security_protocol; + pb_callback_t application_protocols; + pb_callback_t record_protocols; + pb_callback_t target_identities; + bool has_local_identity; + grpc_gcp_Identity local_identity; + bool has_local_endpoint; + grpc_gcp_Endpoint local_endpoint; + bool has_remote_endpoint; + grpc_gcp_Endpoint remote_endpoint; + pb_callback_t target_name; + bool has_rpc_versions; + grpc_gcp_RpcProtocolVersions rpc_versions; +/* @@protoc_insertion_point(struct:grpc_gcp_StartClientHandshakeReq) */ +} grpc_gcp_StartClientHandshakeReq; + +typedef struct _grpc_gcp_StartServerHandshakeReq { + pb_callback_t application_protocols; + pb_size_t handshake_parameters_count; + grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry handshake_parameters[3]; + pb_callback_t in_bytes; + bool has_local_endpoint; + grpc_gcp_Endpoint local_endpoint; + bool has_remote_endpoint; + grpc_gcp_Endpoint remote_endpoint; + bool has_rpc_versions; + grpc_gcp_RpcProtocolVersions rpc_versions; +/* @@protoc_insertion_point(struct:grpc_gcp_StartServerHandshakeReq) */ +} grpc_gcp_StartServerHandshakeReq; + +typedef struct _grpc_gcp_HandshakerReq { + bool has_client_start; + grpc_gcp_StartClientHandshakeReq client_start; + bool has_server_start; + grpc_gcp_StartServerHandshakeReq server_start; + bool has_next; + grpc_gcp_NextHandshakeMessageReq next; +/* @@protoc_insertion_point(struct:grpc_gcp_HandshakerReq) */ +} grpc_gcp_HandshakerReq; + +/* Default values for struct fields */ + +/* Initializer values for message structs */ +#define grpc_gcp_Endpoint_init_default {{{NULL}, NULL}, false, 0, false, (grpc_gcp_NetworkProtocol)0} +#define grpc_gcp_Identity_init_default {{{NULL}, NULL}, {{NULL}, NULL}} +#define grpc_gcp_StartClientHandshakeReq_init_default {false, (grpc_gcp_HandshakeProtocol)0, {{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, grpc_gcp_Identity_init_default, false, grpc_gcp_Endpoint_init_default, false, grpc_gcp_Endpoint_init_default, {{NULL}, NULL}, false, grpc_gcp_RpcProtocolVersions_init_default} +#define grpc_gcp_ServerHandshakeParameters_init_default {{{NULL}, NULL}, {{NULL}, NULL}} +#define grpc_gcp_StartServerHandshakeReq_init_default {{{NULL}, NULL}, 0, {grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_init_default, grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_init_default, grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_init_default}, {{NULL}, NULL}, false, grpc_gcp_Endpoint_init_default, false, grpc_gcp_Endpoint_init_default, false, grpc_gcp_RpcProtocolVersions_init_default} +#define grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_init_default {false, 0, false, grpc_gcp_ServerHandshakeParameters_init_default} +#define grpc_gcp_NextHandshakeMessageReq_init_default {{{NULL}, NULL}} +#define grpc_gcp_HandshakerReq_init_default {false, grpc_gcp_StartClientHandshakeReq_init_default, false, grpc_gcp_StartServerHandshakeReq_init_default, false, grpc_gcp_NextHandshakeMessageReq_init_default} +#define grpc_gcp_HandshakerResult_init_default {{{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, grpc_gcp_Identity_init_default, false, grpc_gcp_Identity_init_default, false, 0, false, grpc_gcp_RpcProtocolVersions_init_default} +#define grpc_gcp_HandshakerStatus_init_default {false, 0, {{NULL}, NULL}} +#define grpc_gcp_HandshakerResp_init_default {{{NULL}, NULL}, false, 0, false, grpc_gcp_HandshakerResult_init_default, false, grpc_gcp_HandshakerStatus_init_default} +#define grpc_gcp_Endpoint_init_zero {{{NULL}, NULL}, false, 0, false, (grpc_gcp_NetworkProtocol)0} +#define grpc_gcp_Identity_init_zero {{{NULL}, NULL}, {{NULL}, NULL}} +#define grpc_gcp_StartClientHandshakeReq_init_zero {false, (grpc_gcp_HandshakeProtocol)0, {{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, grpc_gcp_Identity_init_zero, false, grpc_gcp_Endpoint_init_zero, false, grpc_gcp_Endpoint_init_zero, {{NULL}, NULL}, false, grpc_gcp_RpcProtocolVersions_init_zero} +#define grpc_gcp_ServerHandshakeParameters_init_zero {{{NULL}, NULL}, {{NULL}, NULL}} +#define grpc_gcp_StartServerHandshakeReq_init_zero {{{NULL}, NULL}, 0, {grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_init_zero, grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_init_zero, grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_init_zero}, {{NULL}, NULL}, false, grpc_gcp_Endpoint_init_zero, false, grpc_gcp_Endpoint_init_zero, false, grpc_gcp_RpcProtocolVersions_init_zero} +#define grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_init_zero {false, 0, false, grpc_gcp_ServerHandshakeParameters_init_zero} +#define grpc_gcp_NextHandshakeMessageReq_init_zero {{{NULL}, NULL}} +#define grpc_gcp_HandshakerReq_init_zero {false, grpc_gcp_StartClientHandshakeReq_init_zero, false, grpc_gcp_StartServerHandshakeReq_init_zero, false, grpc_gcp_NextHandshakeMessageReq_init_zero} +#define grpc_gcp_HandshakerResult_init_zero {{{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}, false, grpc_gcp_Identity_init_zero, false, grpc_gcp_Identity_init_zero, false, 0, false, grpc_gcp_RpcProtocolVersions_init_zero} +#define grpc_gcp_HandshakerStatus_init_zero {false, 0, {{NULL}, NULL}} +#define grpc_gcp_HandshakerResp_init_zero {{{NULL}, NULL}, false, 0, false, grpc_gcp_HandshakerResult_init_zero, false, grpc_gcp_HandshakerStatus_init_zero} + +/* Field tags (for use in manual encoding/decoding) */ +#define grpc_gcp_Identity_service_account_tag 1 +#define grpc_gcp_Identity_hostname_tag 2 +#define grpc_gcp_NextHandshakeMessageReq_in_bytes_tag 1 +#define grpc_gcp_ServerHandshakeParameters_record_protocols_tag 1 +#define grpc_gcp_ServerHandshakeParameters_local_identities_tag 2 +#define grpc_gcp_Endpoint_ip_address_tag 1 +#define grpc_gcp_Endpoint_port_tag 2 +#define grpc_gcp_Endpoint_protocol_tag 3 +#define grpc_gcp_HandshakerResult_application_protocol_tag 1 +#define grpc_gcp_HandshakerResult_record_protocol_tag 2 +#define grpc_gcp_HandshakerResult_key_data_tag 3 +#define grpc_gcp_HandshakerResult_peer_identity_tag 4 +#define grpc_gcp_HandshakerResult_local_identity_tag 5 +#define grpc_gcp_HandshakerResult_keep_channel_open_tag 6 +#define grpc_gcp_HandshakerResult_peer_rpc_versions_tag 7 +#define grpc_gcp_HandshakerStatus_code_tag 1 +#define grpc_gcp_HandshakerStatus_details_tag 2 +#define grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_key_tag 1 +#define grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_value_tag 2 +#define grpc_gcp_HandshakerResp_out_frames_tag 1 +#define grpc_gcp_HandshakerResp_bytes_consumed_tag 2 +#define grpc_gcp_HandshakerResp_result_tag 3 +#define grpc_gcp_HandshakerResp_status_tag 4 +#define grpc_gcp_StartClientHandshakeReq_handshake_security_protocol_tag 1 +#define grpc_gcp_StartClientHandshakeReq_application_protocols_tag 2 +#define grpc_gcp_StartClientHandshakeReq_record_protocols_tag 3 +#define grpc_gcp_StartClientHandshakeReq_target_identities_tag 4 +#define grpc_gcp_StartClientHandshakeReq_local_identity_tag 5 +#define grpc_gcp_StartClientHandshakeReq_local_endpoint_tag 6 +#define grpc_gcp_StartClientHandshakeReq_remote_endpoint_tag 7 +#define grpc_gcp_StartClientHandshakeReq_target_name_tag 8 +#define grpc_gcp_StartClientHandshakeReq_rpc_versions_tag 9 +#define grpc_gcp_StartServerHandshakeReq_application_protocols_tag 1 +#define grpc_gcp_StartServerHandshakeReq_handshake_parameters_tag 2 +#define grpc_gcp_StartServerHandshakeReq_in_bytes_tag 3 +#define grpc_gcp_StartServerHandshakeReq_local_endpoint_tag 4 +#define grpc_gcp_StartServerHandshakeReq_remote_endpoint_tag 5 +#define grpc_gcp_StartServerHandshakeReq_rpc_versions_tag 6 +#define grpc_gcp_HandshakerReq_client_start_tag 1 +#define grpc_gcp_HandshakerReq_server_start_tag 2 +#define grpc_gcp_HandshakerReq_next_tag 3 + +/* Struct field encoding specification for nanopb */ +extern const pb_field_t grpc_gcp_Endpoint_fields[4]; +extern const pb_field_t grpc_gcp_Identity_fields[3]; +extern const pb_field_t grpc_gcp_StartClientHandshakeReq_fields[10]; +extern const pb_field_t grpc_gcp_ServerHandshakeParameters_fields[3]; +extern const pb_field_t grpc_gcp_StartServerHandshakeReq_fields[7]; +extern const pb_field_t grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_fields[3]; +extern const pb_field_t grpc_gcp_NextHandshakeMessageReq_fields[2]; +extern const pb_field_t grpc_gcp_HandshakerReq_fields[4]; +extern const pb_field_t grpc_gcp_HandshakerResult_fields[8]; +extern const pb_field_t grpc_gcp_HandshakerStatus_fields[3]; +extern const pb_field_t grpc_gcp_HandshakerResp_fields[5]; + +/* Maximum encoded size of messages (where known) */ +/* grpc_gcp_Endpoint_size depends on runtime parameters */ +/* grpc_gcp_Identity_size depends on runtime parameters */ +/* grpc_gcp_StartClientHandshakeReq_size depends on runtime parameters */ +/* grpc_gcp_ServerHandshakeParameters_size depends on runtime parameters */ +/* grpc_gcp_StartServerHandshakeReq_size depends on runtime parameters */ +#define grpc_gcp_StartServerHandshakeReq_HandshakeParametersEntry_size (17 + grpc_gcp_ServerHandshakeParameters_size) +/* grpc_gcp_NextHandshakeMessageReq_size depends on runtime parameters */ +#define grpc_gcp_HandshakerReq_size (18 + grpc_gcp_StartClientHandshakeReq_size + grpc_gcp_StartServerHandshakeReq_size + grpc_gcp_NextHandshakeMessageReq_size) +/* grpc_gcp_HandshakerResult_size depends on runtime parameters */ +/* grpc_gcp_HandshakerStatus_size depends on runtime parameters */ +/* grpc_gcp_HandshakerResp_size depends on runtime parameters */ + +/* Message IDs (where set with "msgid" option) */ +#ifdef PB_MSGID + +#define HANDSHAKER_MESSAGES \ + + +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif +/* @@protoc_insertion_point(eof) */ + +#endif diff --git a/src/core/tsi/alts/handshaker/proto/altscontext.proto b/src/core/tsi/alts/handshaker/proto/altscontext.proto new file mode 100644 index 0000000000..d195b37e08 --- /dev/null +++ b/src/core/tsi/alts/handshaker/proto/altscontext.proto @@ -0,0 +1,41 @@ +// Copyright 2018 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +import "transport_security_common.proto"; + +package grpc.gcp; + +option java_package = "io.grpc.alts"; + +message AltsContext { + // The application protocol negotiated for this connection. + string application_protocol = 1; + + // The record protocol negotiated for this connection. + string record_protocol = 2; + + // The security level of the created secure channel. + SecurityLevel security_level = 3; + + // The peer service account. + string peer_service_account = 4; + + // The local service account. + string local_service_account = 5; + + // The RPC protocol versions supported by the peer. + RpcProtocolVersions peer_rpc_versions = 6; +} diff --git a/src/core/tsi/alts/handshaker/proto/handshaker.options b/src/core/tsi/alts/handshaker/proto/handshaker.options new file mode 100644 index 0000000000..702ba3802a --- /dev/null +++ b/src/core/tsi/alts/handshaker/proto/handshaker.options @@ -0,0 +1,2 @@ +handshaker.proto no_unions:true +grpc.gcp.StartServerHandshakeReq.handshake_parameters max_count:3 diff --git a/src/core/tsi/alts/handshaker/proto/handshaker.proto b/src/core/tsi/alts/handshaker/proto/handshaker.proto new file mode 100644 index 0000000000..46b8b09eb0 --- /dev/null +++ b/src/core/tsi/alts/handshaker/proto/handshaker.proto @@ -0,0 +1,220 @@ +// Copyright 2018 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +import "transport_security_common.proto"; + +package grpc.gcp; + +option java_package = "io.grpc.alts"; + +enum HandshakeProtocol { + // Default value. + HANDSHAKE_PROTOCOL_UNSPECIFIED = 0; + + // TLS handshake protocol. + TLS = 1; + + // Application Layer Transport Security handshake protocol. + ALTS = 2; +} + +enum NetworkProtocol { + NETWORK_PROTOCOL_UNSPECIFIED = 0; + TCP = 1; + UDP = 2; +} + +message Endpoint { + // IP address. It should contain an IPv4 or IPv6 string literal, e.g. + // "192.168.0.1" or "2001:db8::1". + string ip_address = 1; + + // Port number. + int32 port = 2; + + // Network protocol (e.g., TCP, UDP) associated with this endpoint. + NetworkProtocol protocol = 3; +} + +message Identity { + oneof identity_oneof { + // Service account of a connection endpoint. + string service_account = 1; + + // Hostname of a connection endpoint. + string hostname = 2; + } +} + +message StartClientHandshakeReq { + // Handshake security protocol requested by the client. + HandshakeProtocol handshake_security_protocol = 1; + + // The application protocols supported by the client, e.g., "h2" (for http2), + // "grpc". + repeated string application_protocols = 2; + + // The record protocols supported by the client, e.g., + // "ALTSRP_GCM_AES128". + repeated string record_protocols = 3; + + // (Optional) Describes which server identities are acceptable by the client. + // If target identities are provided and none of them matches the peer + // identity of the server, handshake will fail. + repeated Identity target_identities = 4; + + // (Optional) Application may specify a local identity. Otherwise, the + // handshaker chooses a default local identity. + Identity local_identity = 5; + + // (Optional) Local endpoint information of the connection to the server, + // such as local IP address, port number, and network protocol. + Endpoint local_endpoint = 6; + + // (Optional) Endpoint information of the remote server, such as IP address, + // port number, and network protocool. + Endpoint remote_endpoint = 7; + + // (Optional) If target name is provided, a secure naming check is performed + // to verify that the peer authenticated identity is indeed authorized to run + // the target name. + string target_name = 8; + + // (Optional) RPC protocol versions supported by the client. + RpcProtocolVersions rpc_versions = 9; +} + +message ServerHandshakeParameters { + // The record protocols supported by the server, e.g., + // "ALTSRP_GCM_AES128". + repeated string record_protocols = 1; + + // (Optional) A list of local identities supported by the server, if + // specified. Otherwise, the handshaker chooses a default local identity. + repeated Identity local_identities = 2; +} + +message StartServerHandshakeReq { + // The application protocols supported by the server, e.g., "h2" (for http2), + // "grpc". + repeated string application_protocols = 1; + + // Handshake parameters (record protocols and local identities supported by + // the server) mapped by the handshake protocol. Each handshake security + // protocol (e.g., TLS or ALTS) has its own set of record protocols and local + // identities. Since protobuf does not support enum as key to the map, the key + // to handshake_parameters is the integer value of HandshakeProtocol enum. + map handshake_parameters = 2; + + // Bytes in out_frames returned from the peer's HandshakerResp. It is possible + // that the peer's out_frames are split into multiple HandshakReq messages. + bytes in_bytes = 3; + + // (Optional) Local endpoint information of the connection to the client, + // such as local IP address, port number, and network protocol. + Endpoint local_endpoint = 4; + + // (Optional) Endpoint information of the remote client, such as IP address, + // port number, and network protocool. + Endpoint remote_endpoint = 5; + + // (Optional) RPC protocol versions supported by the server. + RpcProtocolVersions rpc_versions = 6; +} + +message NextHandshakeMessageReq { + // Bytes in out_frames returned from the peer's HandshakerResp. It is possible + // that the peer's out_frames are split into multiple NextHandshakerMessageReq + // messages. + bytes in_bytes = 1; +} + +message HandshakerReq { + oneof req_oneof { + // The start client handshake request message. + StartClientHandshakeReq client_start = 1; + + // The start server handshake request message. + StartServerHandshakeReq server_start = 2; + + // The next handshake request message. + NextHandshakeMessageReq next = 3; + } +} + +message HandshakerResult { + // The application protocol negotiated for this connection. + string application_protocol = 1; + + // The record protocol negotiated for this connection. + string record_protocol = 2; + + // Cryptographic key data. The key data may be more than the key length + // required for the record protocol, thus the client of the handshaker + // service needs to truncate the key data into the right key length. + bytes key_data = 3; + + // The authenticated identity of the peer. + Identity peer_identity = 4; + + // The local identity used in the handshake. + Identity local_identity = 5; + + // Indicate whether the handshaker service client should keep the channel + // between the handshaker service open, e.g., in order to handle + // post-handshake messages in the future. + bool keep_channel_open = 6; + + // The RPC protocol versions supported by the peer. + RpcProtocolVersions peer_rpc_versions = 7; +} + +message HandshakerStatus { + // The status code. This could be the gRPC status code. + uint32 code = 1; + + // The status details. + string details = 2; +} + +message HandshakerResp { + // Frames to be given to the peer for the NextHandshakeMessageReq. May be + // empty if no out_frames have to be sent to the peer or if in_bytes in the + // HandshakerReq are incomplete. All the non-empty out frames must be sent to + // the peer even if the handshaker status is not OK as these frames may + // contain the alert frames. + bytes out_frames = 1; + + // Number of bytes in the in_bytes consumed by the handshaker. It is possible + // that part of in_bytes in HandshakerReq was unrelated to the handshake + // process. + uint32 bytes_consumed = 2; + + // This is set iff the handshake was successful. out_frames may still be set + // to frames that needs to be forwarded to the peer. + HandshakerResult result = 3; + + // Status of the handshaker. + HandshakerStatus status = 4; +} + +service HandshakerService { + // Accepts a stream of handshaker request, returning a stream of handshaker + // response. + rpc DoHandshake(stream HandshakerReq) + returns (stream HandshakerResp) { + } +} diff --git a/src/core/tsi/alts/handshaker/proto/transport_security_common.proto b/src/core/tsi/alts/handshaker/proto/transport_security_common.proto new file mode 100644 index 0000000000..41983ab9f9 --- /dev/null +++ b/src/core/tsi/alts/handshaker/proto/transport_security_common.proto @@ -0,0 +1,40 @@ +// Copyright 2018 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package grpc.gcp; + +option java_package = "io.grpc.alts"; + +// The security level of the created channel. The list is sorted in increasing +// level of security. This order must always be maintained. +enum SecurityLevel { + SECURITY_NONE = 0; + INTEGRITY_ONLY = 1; + INTEGRITY_AND_PRIVACY = 2; +} + +// Max and min supported RPC protocol versions. +message RpcProtocolVersions { + // RPC version contains a major version and a minor version. + message Version { + uint32 major = 1; + uint32 minor = 2; + } + // Maximum supported RPC version. + Version max_rpc_version = 1; + // Minimum supported RPC version. + Version min_rpc_version = 2; +} diff --git a/src/core/tsi/alts/handshaker/transport_security_common.pb.c b/src/core/tsi/alts/handshaker/transport_security_common.pb.c new file mode 100644 index 0000000000..6063c7625e --- /dev/null +++ b/src/core/tsi/alts/handshaker/transport_security_common.pb.c @@ -0,0 +1,50 @@ +/* Automatically generated nanopb constant definitions */ +/* Generated by nanopb-0.3.7-dev */ + +#include "src/core/tsi/alts/handshaker/transport_security_common.pb.h" + +/* @@protoc_insertion_point(includes) */ +#if PB_PROTO_HEADER_VERSION != 30 +#error Regenerate this file with the current version of nanopb generator. +#endif + + + +const pb_field_t grpc_gcp_RpcProtocolVersions_fields[3] = { + PB_FIELD( 1, MESSAGE , OPTIONAL, STATIC , FIRST, grpc_gcp_RpcProtocolVersions, max_rpc_version, max_rpc_version, &grpc_gcp_RpcProtocolVersions_Version_fields), + PB_FIELD( 2, MESSAGE , OPTIONAL, STATIC , OTHER, grpc_gcp_RpcProtocolVersions, min_rpc_version, max_rpc_version, &grpc_gcp_RpcProtocolVersions_Version_fields), + PB_LAST_FIELD +}; + +const pb_field_t grpc_gcp_RpcProtocolVersions_Version_fields[3] = { + PB_FIELD( 1, UINT32 , OPTIONAL, STATIC , FIRST, grpc_gcp_RpcProtocolVersions_Version, major, major, 0), + PB_FIELD( 2, UINT32 , OPTIONAL, STATIC , OTHER, grpc_gcp_RpcProtocolVersions_Version, minor, major, 0), + PB_LAST_FIELD +}; + + +/* Check that field information fits in pb_field_t */ +#if !defined(PB_FIELD_32BIT) +/* If you get an error here, it means that you need to define PB_FIELD_32BIT + * compile-time option. You can do that in pb.h or on compiler command line. + * + * The reason you need to do this is that some of your messages contain tag + * numbers or field sizes that are larger than what can fit in 8 or 16 bit + * field descriptors. + */ +PB_STATIC_ASSERT((pb_membersize(grpc_gcp_RpcProtocolVersions, max_rpc_version) < 65536 && pb_membersize(grpc_gcp_RpcProtocolVersions, min_rpc_version) < 65536), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_grpc_gcp_RpcProtocolVersions_grpc_gcp_RpcProtocolVersions_Version) +#endif + +#if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT) +/* If you get an error here, it means that you need to define PB_FIELD_16BIT + * compile-time option. You can do that in pb.h or on compiler command line. + * + * The reason you need to do this is that some of your messages contain tag + * numbers or field sizes that are larger than what can fit in the default + * 8 bit descriptors. + */ +PB_STATIC_ASSERT((pb_membersize(grpc_gcp_RpcProtocolVersions, max_rpc_version) < 256 && pb_membersize(grpc_gcp_RpcProtocolVersions, min_rpc_version) < 256), YOU_MUST_DEFINE_PB_FIELD_16BIT_FOR_MESSAGES_grpc_gcp_RpcProtocolVersions_grpc_gcp_RpcProtocolVersions_Version) +#endif + + +/* @@protoc_insertion_point(eof) */ diff --git a/src/core/tsi/alts/handshaker/transport_security_common.pb.h b/src/core/tsi/alts/handshaker/transport_security_common.pb.h new file mode 100644 index 0000000000..49096dffa3 --- /dev/null +++ b/src/core/tsi/alts/handshaker/transport_security_common.pb.h @@ -0,0 +1,78 @@ +/* Automatically generated nanopb header */ +/* Generated by nanopb-0.3.7-dev */ + +#ifndef PB_GRPC_GCP_TRANSPORT_SECURITY_COMMON_PB_H_INCLUDED +#define PB_GRPC_GCP_TRANSPORT_SECURITY_COMMON_PB_H_INCLUDED +#include "third_party/nanopb/pb.h" +/* @@protoc_insertion_point(includes) */ +#if PB_PROTO_HEADER_VERSION != 30 +#error Regenerate this file with the current version of nanopb generator. +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* Enum definitions */ +typedef enum _grpc_gcp_SecurityLevel { + grpc_gcp_SecurityLevel_SECURITY_NONE = 0, + grpc_gcp_SecurityLevel_INTEGRITY_ONLY = 1, + grpc_gcp_SecurityLevel_INTEGRITY_AND_PRIVACY = 2 +} grpc_gcp_SecurityLevel; +#define _grpc_gcp_SecurityLevel_MIN grpc_gcp_SecurityLevel_SECURITY_NONE +#define _grpc_gcp_SecurityLevel_MAX grpc_gcp_SecurityLevel_INTEGRITY_AND_PRIVACY +#define _grpc_gcp_SecurityLevel_ARRAYSIZE ((grpc_gcp_SecurityLevel)(grpc_gcp_SecurityLevel_INTEGRITY_AND_PRIVACY+1)) + +/* Struct definitions */ +typedef struct _grpc_gcp_RpcProtocolVersions_Version { + bool has_major; + uint32_t major; + bool has_minor; + uint32_t minor; +/* @@protoc_insertion_point(struct:grpc_gcp_RpcProtocolVersions_Version) */ +} grpc_gcp_RpcProtocolVersions_Version; + +typedef struct _grpc_gcp_RpcProtocolVersions { + bool has_max_rpc_version; + grpc_gcp_RpcProtocolVersions_Version max_rpc_version; + bool has_min_rpc_version; + grpc_gcp_RpcProtocolVersions_Version min_rpc_version; +/* @@protoc_insertion_point(struct:grpc_gcp_RpcProtocolVersions) */ +} grpc_gcp_RpcProtocolVersions; + +/* Default values for struct fields */ + +/* Initializer values for message structs */ +#define grpc_gcp_RpcProtocolVersions_init_default {false, grpc_gcp_RpcProtocolVersions_Version_init_default, false, grpc_gcp_RpcProtocolVersions_Version_init_default} +#define grpc_gcp_RpcProtocolVersions_Version_init_default {false, 0, false, 0} +#define grpc_gcp_RpcProtocolVersions_init_zero {false, grpc_gcp_RpcProtocolVersions_Version_init_zero, false, grpc_gcp_RpcProtocolVersions_Version_init_zero} +#define grpc_gcp_RpcProtocolVersions_Version_init_zero {false, 0, false, 0} + +/* Field tags (for use in manual encoding/decoding) */ +#define grpc_gcp_RpcProtocolVersions_Version_major_tag 1 +#define grpc_gcp_RpcProtocolVersions_Version_minor_tag 2 +#define grpc_gcp_RpcProtocolVersions_max_rpc_version_tag 1 +#define grpc_gcp_RpcProtocolVersions_min_rpc_version_tag 2 + +/* Struct field encoding specification for nanopb */ +extern const pb_field_t grpc_gcp_RpcProtocolVersions_fields[3]; +extern const pb_field_t grpc_gcp_RpcProtocolVersions_Version_fields[3]; + +/* Maximum encoded size of messages (where known) */ +#define grpc_gcp_RpcProtocolVersions_size 28 +#define grpc_gcp_RpcProtocolVersions_Version_size 12 + +/* Message IDs (where set with "msgid" option) */ +#ifdef PB_MSGID + +#define TRANSPORT_SECURITY_COMMON_MESSAGES \ + + +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif +/* @@protoc_insertion_point(eof) */ + +#endif diff --git a/src/core/tsi/alts/handshaker/transport_security_common_api.cc b/src/core/tsi/alts/handshaker/transport_security_common_api.cc new file mode 100644 index 0000000000..8a7edb53d4 --- /dev/null +++ b/src/core/tsi/alts/handshaker/transport_security_common_api.cc @@ -0,0 +1,196 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/tsi/alts/handshaker/transport_security_common_api.h" + +bool grpc_gcp_rpc_protocol_versions_set_max( + grpc_gcp_rpc_protocol_versions* versions, uint32_t max_major, + uint32_t max_minor) { + if (versions == nullptr) { + gpr_log(GPR_ERROR, + "versions is nullptr in " + "grpc_gcp_rpc_protocol_versions_set_max()."); + return false; + } + versions->has_max_rpc_version = true; + versions->max_rpc_version.has_major = true; + versions->max_rpc_version.has_minor = true; + versions->max_rpc_version.major = max_major; + versions->max_rpc_version.minor = max_minor; + return true; +} + +bool grpc_gcp_rpc_protocol_versions_set_min( + grpc_gcp_rpc_protocol_versions* versions, uint32_t min_major, + uint32_t min_minor) { + if (versions == nullptr) { + gpr_log(GPR_ERROR, + "versions is nullptr in " + "grpc_gcp_rpc_protocol_versions_set_min()."); + return false; + } + versions->has_min_rpc_version = true; + versions->min_rpc_version.has_major = true; + versions->min_rpc_version.has_minor = true; + versions->min_rpc_version.major = min_major; + versions->min_rpc_version.minor = min_minor; + return true; +} + +size_t grpc_gcp_rpc_protocol_versions_encode_length( + const grpc_gcp_rpc_protocol_versions* versions) { + if (versions == nullptr) { + gpr_log(GPR_ERROR, + "Invalid nullptr arguments to " + "grpc_gcp_rpc_protocol_versions_encode_length()."); + return 0; + } + pb_ostream_t size_stream; + memset(&size_stream, 0, sizeof(pb_ostream_t)); + if (!pb_encode(&size_stream, grpc_gcp_RpcProtocolVersions_fields, versions)) { + gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&size_stream)); + return 0; + } + return size_stream.bytes_written; +} + +bool grpc_gcp_rpc_protocol_versions_encode_to_raw_bytes( + const grpc_gcp_rpc_protocol_versions* versions, uint8_t* bytes, + size_t bytes_length) { + if (versions == nullptr || bytes == nullptr || bytes_length == 0) { + gpr_log(GPR_ERROR, + "Invalid nullptr arguments to " + "grpc_gcp_rpc_protocol_versions_encode_to_raw_bytes()."); + return false; + } + pb_ostream_t output_stream = pb_ostream_from_buffer(bytes, bytes_length); + if (!pb_encode(&output_stream, grpc_gcp_RpcProtocolVersions_fields, + versions)) { + gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&output_stream)); + return false; + } + return true; +} + +bool grpc_gcp_rpc_protocol_versions_encode( + const grpc_gcp_rpc_protocol_versions* versions, grpc_slice* slice) { + if (versions == nullptr || slice == nullptr) { + gpr_log(GPR_ERROR, + "Invalid nullptr arguments to " + "grpc_gcp_rpc_protocol_versions_encode()."); + return false; + } + size_t encoded_length = + grpc_gcp_rpc_protocol_versions_encode_length(versions); + if (encoded_length == 0) return false; + *slice = grpc_slice_malloc(encoded_length); + return grpc_gcp_rpc_protocol_versions_encode_to_raw_bytes( + versions, GRPC_SLICE_START_PTR(*slice), encoded_length); +} + +bool grpc_gcp_rpc_protocol_versions_decode( + grpc_slice slice, grpc_gcp_rpc_protocol_versions* versions) { + if (versions == nullptr) { + gpr_log(GPR_ERROR, + "version is nullptr in " + "grpc_gcp_rpc_protocol_versions_decode()."); + return false; + } + pb_istream_t stream = pb_istream_from_buffer(GRPC_SLICE_START_PTR(slice), + GRPC_SLICE_LENGTH(slice)); + if (!pb_decode(&stream, grpc_gcp_RpcProtocolVersions_fields, versions)) { + gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&stream)); + return false; + } + return true; +} + +bool grpc_gcp_rpc_protocol_versions_copy( + const grpc_gcp_rpc_protocol_versions* src, + grpc_gcp_rpc_protocol_versions* dst) { + if ((src == nullptr && dst != nullptr) || + (src != nullptr && dst == nullptr)) { + gpr_log(GPR_ERROR, + "Invalid arguments to " + "grpc_gcp_rpc_protocol_versions_copy()."); + return false; + } + if (src == nullptr) { + return true; + } + grpc_gcp_rpc_protocol_versions_set_max(dst, src->max_rpc_version.major, + src->max_rpc_version.minor); + grpc_gcp_rpc_protocol_versions_set_min(dst, src->min_rpc_version.major, + src->min_rpc_version.minor); + return true; +} + +namespace grpc_core { +namespace internal { + +int grpc_gcp_rpc_protocol_version_compare( + const grpc_gcp_rpc_protocol_versions_version* v1, + const grpc_gcp_rpc_protocol_versions_version* v2) { + if ((v1->major > v2->major) || + (v1->major == v2->major && v1->minor > v2->minor)) { + return 1; + } + if ((v1->major < v2->major) || + (v1->major == v2->major && v1->minor < v2->minor)) { + return -1; + } + return 0; +} + +} // namespace internal +} // namespace grpc_core + +bool grpc_gcp_rpc_protocol_versions_check( + const grpc_gcp_rpc_protocol_versions* local_versions, + const grpc_gcp_rpc_protocol_versions* peer_versions, + grpc_gcp_rpc_protocol_versions_version* highest_common_version) { + if (local_versions == nullptr || peer_versions == nullptr) { + gpr_log(GPR_ERROR, + "Invalid arguments to " + "grpc_gcp_rpc_protocol_versions_check()."); + return false; + } + /* max_common_version is MIN(local.max, peer.max) */ + const grpc_gcp_rpc_protocol_versions_version* max_common_version = + grpc_core::internal::grpc_gcp_rpc_protocol_version_compare( + &local_versions->max_rpc_version, &peer_versions->max_rpc_version) > 0 + ? &peer_versions->max_rpc_version + : &local_versions->max_rpc_version; + /* min_common_version is MAX(local.min, peer.min) */ + const grpc_gcp_rpc_protocol_versions_version* min_common_version = + grpc_core::internal::grpc_gcp_rpc_protocol_version_compare( + &local_versions->min_rpc_version, &peer_versions->min_rpc_version) > 0 + ? &local_versions->min_rpc_version + : &peer_versions->min_rpc_version; + bool result = grpc_core::internal::grpc_gcp_rpc_protocol_version_compare( + max_common_version, min_common_version) >= 0 + ? true + : false; + if (result && highest_common_version != nullptr) { + memcpy(highest_common_version, max_common_version, + sizeof(grpc_gcp_rpc_protocol_versions_version)); + } + return result; +} diff --git a/src/core/tsi/alts/handshaker/transport_security_common_api.h b/src/core/tsi/alts/handshaker/transport_security_common_api.h new file mode 100644 index 0000000000..68228cb3b5 --- /dev/null +++ b/src/core/tsi/alts/handshaker/transport_security_common_api.h @@ -0,0 +1,163 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_TSI_ALTS_HANDSHAKER_TRANSPORT_SECURITY_COMMON_API_H +#define GRPC_CORE_TSI_ALTS_HANDSHAKER_TRANSPORT_SECURITY_COMMON_API_H + +#include + +#include "third_party/nanopb/pb_decode.h" +#include "third_party/nanopb/pb_encode.h" + +#include +#include +#include +#include + +#include "src/core/tsi/alts/handshaker/transport_security_common.pb.h" + +typedef grpc_gcp_RpcProtocolVersions grpc_gcp_rpc_protocol_versions; + +typedef grpc_gcp_RpcProtocolVersions_Version + grpc_gcp_rpc_protocol_versions_version; + +/** + * This method sets the value for max_rpc_versions field of rpc protocol + * versions. + * + * - versions: an rpc protocol version instance. + * - max_major: a major version of maximum supported RPC version. + * - max_minor: a minor version of maximum supported RPC version. + * + * The method returns true on success and false otherwise. + */ +bool grpc_gcp_rpc_protocol_versions_set_max( + grpc_gcp_rpc_protocol_versions* versions, uint32_t max_major, + uint32_t max_minor); + +/** + * This method sets the value for min_rpc_versions field of rpc protocol + * versions. + * + * - versions: an rpc protocol version instance. + * - min_major: a major version of minimum supported RPC version. + * - min_minor: a minor version of minimum supported RPC version. + * + * The method returns true on success and false otherwise. + */ +bool grpc_gcp_rpc_protocol_versions_set_min( + grpc_gcp_rpc_protocol_versions* versions, uint32_t min_major, + uint32_t min_minor); + +/** + * This method computes serialized byte length of rpc protocol versions. + * + * - versions: an rpc protocol versions instance. + * + * The method returns serialized byte length. It returns 0 on failure. + */ +size_t grpc_gcp_rpc_protocol_versions_encode_length( + const grpc_gcp_rpc_protocol_versions* versions); + +/** + * This method serializes rpc protocol versions and writes the result to + * the memory buffer provided by the caller. Caller is responsible for + * allocating sufficient memory to store the serialized data. + * + * - versions: an rpc protocol versions instance. + * - bytes: bytes buffer where the result will be written to. + * - bytes_length: length of the bytes buffer. + * + * The method returns true on success and false otherwise. + */ +bool grpc_gcp_rpc_protocol_versions_encode_to_raw_bytes( + const grpc_gcp_rpc_protocol_versions* versions, uint8_t* bytes, + size_t bytes_length); + +/** + * This method serializes an rpc protocol version and returns serialized rpc + * versions in grpc slice. + * + * - versions: an rpc protocol versions instance. + * - slice: grpc slice where the serialized result will be written. + * + * The method returns true on success and false otherwise. + */ +bool grpc_gcp_rpc_protocol_versions_encode( + const grpc_gcp_rpc_protocol_versions* versions, grpc_slice* slice); + +/** + * This method de-serializes input in grpc slice form and stores the result + * in rpc protocol versions. + * + * - slice: a data stream containing a serialized rpc protocol version. + * - versions: an rpc protocol version instance used to hold de-serialized + * result. + * + * The method returns true on success and false otherwise. + */ +bool grpc_gcp_rpc_protocol_versions_decode( + grpc_slice slice, grpc_gcp_rpc_protocol_versions* versions); + +/** + * This method performs a deep copy operation on rpc protocol versions + * instance. + * + * - src: rpc protocol versions instance that needs to be copied. + * - dst: rpc protocol versions instance that stores the copied result. + * + * The method returns true on success and false otherwise. + */ +bool grpc_gcp_rpc_protocol_versions_copy( + const grpc_gcp_rpc_protocol_versions* src, + grpc_gcp_rpc_protocol_versions* dst); + +/** + * This method performs a version check between local and peer rpc protocol + * versions. + * + * - local_versions: local rpc protocol versions instance. + * - peer_versions: peer rpc protocol versions instance. + * - highest_common_version: an output parameter that will store the highest + * common rpc protocol version both parties agreed on. + * + * The method returns true if the check passes which means both parties agreed + * on a common rpc protocol to use, and false otherwise. + */ +bool grpc_gcp_rpc_protocol_versions_check( + const grpc_gcp_rpc_protocol_versions* local_versions, + const grpc_gcp_rpc_protocol_versions* peer_versions, + grpc_gcp_rpc_protocol_versions_version* highest_common_version); + +namespace grpc_core { +namespace internal { + +/** + * Exposed for testing only. + * The method returns 0 if v1 = v2, + * returns 1 if v1 > v2, + * returns -1 if v1 < v2. + */ +int grpc_gcp_rpc_protocol_version_compare( + const grpc_gcp_rpc_protocol_versions_version* v1, + const grpc_gcp_rpc_protocol_versions_version* v2); + +} // namespace internal +} // namespace grpc_core + +#endif /* GRPC_CORE_TSI_ALTS_HANDSHAKER_TRANSPORT_SECURITY_COMMON_API_H */ diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc new file mode 100644 index 0000000000..7ba03eb7f0 --- /dev/null +++ b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc @@ -0,0 +1,180 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h" + +#include +#include + +#include "src/core/lib/slice/slice_internal.h" +#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h" +#include "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h" + +/* Main struct for alts_grpc_integrity_only_record_protocol. */ +typedef struct alts_grpc_integrity_only_record_protocol { + alts_grpc_record_protocol base; + grpc_slice_buffer data_sb; + unsigned char* tag_buf; +} alts_grpc_integrity_only_record_protocol; + +/* --- alts_grpc_record_protocol methods implementation. --- */ + +static tsi_result alts_grpc_integrity_only_protect( + alts_grpc_record_protocol* rp, grpc_slice_buffer* unprotected_slices, + grpc_slice_buffer* protected_slices) { + /* Input sanity check. */ + if (rp == nullptr || unprotected_slices == nullptr || + protected_slices == nullptr) { + gpr_log(GPR_ERROR, + "Invalid nullptr arguments to alts_grpc_record_protocol protect."); + return TSI_INVALID_ARGUMENT; + } + /* Allocates memory for header and tag slices. */ + grpc_slice header_slice = GRPC_SLICE_MALLOC(rp->header_length); + grpc_slice tag_slice = GRPC_SLICE_MALLOC(rp->tag_length); + /* Calls alts_iovec_record_protocol protect. */ + char* error_details = nullptr; + iovec_t header_iovec = {GRPC_SLICE_START_PTR(header_slice), + GRPC_SLICE_LENGTH(header_slice)}; + iovec_t tag_iovec = {GRPC_SLICE_START_PTR(tag_slice), + GRPC_SLICE_LENGTH(tag_slice)}; + alts_grpc_record_protocol_convert_slice_buffer_to_iovec(rp, + unprotected_slices); + grpc_status_code status = alts_iovec_record_protocol_integrity_only_protect( + rp->iovec_rp, rp->iovec_buf, unprotected_slices->count, header_iovec, + tag_iovec, &error_details); + if (status != GRPC_STATUS_OK) { + gpr_log(GPR_ERROR, "Failed to protect, %s", error_details); + gpr_free(error_details); + return TSI_INTERNAL_ERROR; + } + /* Appends result to protected_slices. */ + grpc_slice_buffer_add(protected_slices, header_slice); + grpc_slice_buffer_move_into(unprotected_slices, protected_slices); + grpc_slice_buffer_add(protected_slices, tag_slice); + return TSI_OK; +} + +static tsi_result alts_grpc_integrity_only_unprotect( + alts_grpc_record_protocol* rp, grpc_slice_buffer* protected_slices, + grpc_slice_buffer* unprotected_slices) { + /* Input sanity check. */ + if (rp == nullptr || protected_slices == nullptr || + unprotected_slices == nullptr) { + gpr_log( + GPR_ERROR, + "Invalid nullptr arguments to alts_grpc_record_protocol unprotect."); + return TSI_INVALID_ARGUMENT; + } + if (protected_slices->length < rp->header_length + rp->tag_length) { + gpr_log(GPR_ERROR, "Protected slices do not have sufficient data."); + return TSI_INVALID_ARGUMENT; + } + /* In this method, rp points to alts_grpc_record_protocol struct + * and integrity_only_record_protocol points to + * alts_grpc_integrity_only_record_protocol struct. */ + alts_grpc_integrity_only_record_protocol* integrity_only_record_protocol = + reinterpret_cast(rp); + /* Strips frame header from protected slices. */ + grpc_slice_buffer_reset_and_unref_internal(&rp->header_sb); + grpc_slice_buffer_move_first(protected_slices, rp->header_length, + &rp->header_sb); + GPR_ASSERT(rp->header_sb.length == rp->header_length); + iovec_t header_iovec = alts_grpc_record_protocol_get_header_iovec(rp); + /* Moves protected slices data to data_sb and leaves the remaining tag. */ + grpc_slice_buffer_reset_and_unref_internal( + &integrity_only_record_protocol->data_sb); + grpc_slice_buffer_move_first(protected_slices, + protected_slices->length - rp->tag_length, + &integrity_only_record_protocol->data_sb); + GPR_ASSERT(protected_slices->length == rp->tag_length); + iovec_t tag_iovec = {nullptr, rp->tag_length}; + if (protected_slices->count == 1) { + tag_iovec.iov_base = GRPC_SLICE_START_PTR(protected_slices->slices[0]); + } else { + /* Frame tag is in multiple slices, copies the tag bytes from slice + * buffer to a single flat buffer. */ + alts_grpc_record_protocol_copy_slice_buffer( + protected_slices, integrity_only_record_protocol->tag_buf); + tag_iovec.iov_base = integrity_only_record_protocol->tag_buf; + } + /* Calls alts_iovec_record_protocol unprotect. */ + char* error_details = nullptr; + alts_grpc_record_protocol_convert_slice_buffer_to_iovec( + rp, &integrity_only_record_protocol->data_sb); + grpc_status_code status = alts_iovec_record_protocol_integrity_only_unprotect( + rp->iovec_rp, rp->iovec_buf, + integrity_only_record_protocol->data_sb.count, header_iovec, tag_iovec, + &error_details); + if (status != GRPC_STATUS_OK) { + gpr_log(GPR_ERROR, "Failed to unprotect, %s", error_details); + gpr_free(error_details); + return TSI_INTERNAL_ERROR; + } + grpc_slice_buffer_reset_and_unref_internal(&rp->header_sb); + grpc_slice_buffer_reset_and_unref_internal(protected_slices); + grpc_slice_buffer_move_into(&integrity_only_record_protocol->data_sb, + unprotected_slices); + return TSI_OK; +} + +static void alts_grpc_integrity_only_destruct(alts_grpc_record_protocol* rp) { + if (rp == nullptr) { + return; + } + alts_grpc_integrity_only_record_protocol* integrity_only_rp = + reinterpret_cast(rp); + grpc_slice_buffer_destroy_internal(&integrity_only_rp->data_sb); + gpr_free(integrity_only_rp->tag_buf); +} + +static const alts_grpc_record_protocol_vtable + alts_grpc_integrity_only_record_protocol_vtable = { + alts_grpc_integrity_only_protect, alts_grpc_integrity_only_unprotect, + alts_grpc_integrity_only_destruct}; + +tsi_result alts_grpc_integrity_only_record_protocol_create( + gsec_aead_crypter* crypter, size_t overflow_size, bool is_client, + bool is_protect, alts_grpc_record_protocol** rp) { + if (crypter == nullptr || rp == nullptr) { + gpr_log(GPR_ERROR, + "Invalid nullptr arguments to alts_grpc_record_protocol create."); + return TSI_INVALID_ARGUMENT; + } + alts_grpc_integrity_only_record_protocol* impl = + static_cast( + gpr_zalloc(sizeof(alts_grpc_integrity_only_record_protocol))); + /* Calls alts_grpc_record_protocol init. */ + tsi_result result = alts_grpc_record_protocol_init( + &impl->base, crypter, overflow_size, is_client, + /*is_integrity_only=*/true, is_protect); + if (result != TSI_OK) { + gpr_free(impl); + return result; + } + /* Initializes slice buffer for data_sb. */ + grpc_slice_buffer_init(&impl->data_sb); + /* Allocates tag buffer. */ + impl->tag_buf = + static_cast(gpr_malloc(impl->base.tag_length)); + impl->base.vtable = &alts_grpc_integrity_only_record_protocol_vtable; + *rp = &impl->base; + return TSI_OK; +} diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h new file mode 100644 index 0000000000..8d68b27e07 --- /dev/null +++ b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h @@ -0,0 +1,52 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_INTEGRITY_ONLY_RECORD_PROTOCOL_H +#define GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_INTEGRITY_ONLY_RECORD_PROTOCOL_H + +#include + +#include + +#include "src/core/tsi/alts/crypt/gsec.h" +#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h" + +/** + * This method creates an integrity-only alts_grpc_record_protocol instance, + * given a gsec_aead_crypter instance and a flag indicating if the created + * instance will be used at the client or server side. The ownership of + * gsec_aead_crypter instance is transferred to this new object. + * + * - crypter: a gsec_aead_crypter instance used to perform AEAD decryption. + * - overflow_size: overflow size of counter in bytes. + * - is_client: a flag indicating if the alts_grpc_record_protocol instance will + * be used at the client or server side. + * - is_protect: a flag indicating if the alts_grpc_record_protocol instance + * will be used for protect or unprotect. + * - rp: an alts_grpc_record_protocol instance to be returned from + * the method. + * + * This method returns TSI_OK in case of success or a specific error code in + * case of failure. + */ +tsi_result alts_grpc_integrity_only_record_protocol_create( + gsec_aead_crypter* crypter, size_t overflow_size, bool is_client, + bool is_protect, alts_grpc_record_protocol** rp); + +#endif /* GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_INTEGRITY_ONLY_RECORD_PROTOCOL_H \ + */ diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc new file mode 100644 index 0000000000..d4fd88d1e2 --- /dev/null +++ b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc @@ -0,0 +1,144 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h" + +#include +#include + +#include "src/core/lib/slice/slice_internal.h" +#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h" +#include "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h" + +/* Privacy-integrity alts_grpc_record_protocol object uses the same struct + * defined in alts_grpc_record_protocol_common.h. */ + +/* --- alts_grpc_record_protocol methods implementation. --- */ + +static tsi_result alts_grpc_privacy_integrity_protect( + alts_grpc_record_protocol* rp, grpc_slice_buffer* unprotected_slices, + grpc_slice_buffer* protected_slices) { + /* Input sanity check. */ + if (rp == nullptr || unprotected_slices == nullptr || + protected_slices == nullptr) { + gpr_log(GPR_ERROR, + "Invalid nullptr arguments to alts_grpc_record_protocol protect."); + return TSI_INVALID_ARGUMENT; + } + /* Allocates memory for output frame. In privacy-integrity protect, the + * protected frame is stored in a newly allocated buffer. */ + size_t protected_frame_size = + unprotected_slices->length + rp->header_length + + alts_iovec_record_protocol_get_tag_length(rp->iovec_rp); + grpc_slice protected_slice = GRPC_SLICE_MALLOC(protected_frame_size); + iovec_t protected_iovec = {GRPC_SLICE_START_PTR(protected_slice), + GRPC_SLICE_LENGTH(protected_slice)}; + /* Calls alts_iovec_record_protocol protect. */ + char* error_details = nullptr; + alts_grpc_record_protocol_convert_slice_buffer_to_iovec(rp, + unprotected_slices); + grpc_status_code status = + alts_iovec_record_protocol_privacy_integrity_protect( + rp->iovec_rp, rp->iovec_buf, unprotected_slices->count, + protected_iovec, &error_details); + if (status != GRPC_STATUS_OK) { + gpr_log(GPR_ERROR, "Failed to protect, %s", error_details); + gpr_free(error_details); + grpc_slice_unref(protected_slice); + return TSI_INTERNAL_ERROR; + } + grpc_slice_buffer_add(protected_slices, protected_slice); + grpc_slice_buffer_reset_and_unref_internal(unprotected_slices); + return TSI_OK; +} + +static tsi_result alts_grpc_privacy_integrity_unprotect( + alts_grpc_record_protocol* rp, grpc_slice_buffer* protected_slices, + grpc_slice_buffer* unprotected_slices) { + /* Input sanity check. */ + if (rp == nullptr || protected_slices == nullptr || + unprotected_slices == nullptr) { + gpr_log( + GPR_ERROR, + "Invalid nullptr arguments to alts_grpc_record_protocol unprotect."); + return TSI_INVALID_ARGUMENT; + } + /* Allocates memory for output frame. In privacy-integrity unprotect, the + * unprotected data are stored in a newly allocated buffer. */ + if (protected_slices->length < rp->header_length + rp->tag_length) { + gpr_log(GPR_ERROR, "Protected slices do not have sufficient data."); + return TSI_INVALID_ARGUMENT; + } + size_t unprotected_frame_size = + protected_slices->length - rp->header_length - rp->tag_length; + grpc_slice unprotected_slice = GRPC_SLICE_MALLOC(unprotected_frame_size); + iovec_t unprotected_iovec = {GRPC_SLICE_START_PTR(unprotected_slice), + GRPC_SLICE_LENGTH(unprotected_slice)}; + /* Strips frame header from protected slices. */ + grpc_slice_buffer_reset_and_unref_internal(&rp->header_sb); + grpc_slice_buffer_move_first(protected_slices, rp->header_length, + &rp->header_sb); + iovec_t header_iovec = alts_grpc_record_protocol_get_header_iovec(rp); + /* Calls alts_iovec_record_protocol unprotect. */ + char* error_details = nullptr; + alts_grpc_record_protocol_convert_slice_buffer_to_iovec(rp, protected_slices); + grpc_status_code status = + alts_iovec_record_protocol_privacy_integrity_unprotect( + rp->iovec_rp, header_iovec, rp->iovec_buf, protected_slices->count, + unprotected_iovec, &error_details); + if (status != GRPC_STATUS_OK) { + gpr_log(GPR_ERROR, "Failed to unprotect, %s", error_details); + gpr_free(error_details); + grpc_slice_unref(unprotected_slice); + return TSI_INTERNAL_ERROR; + } + grpc_slice_buffer_reset_and_unref_internal(&rp->header_sb); + grpc_slice_buffer_reset_and_unref_internal(protected_slices); + grpc_slice_buffer_add(unprotected_slices, unprotected_slice); + return TSI_OK; +} + +static const alts_grpc_record_protocol_vtable + alts_grpc_privacy_integrity_record_protocol_vtable = { + alts_grpc_privacy_integrity_protect, + alts_grpc_privacy_integrity_unprotect, nullptr}; + +tsi_result alts_grpc_privacy_integrity_record_protocol_create( + gsec_aead_crypter* crypter, size_t overflow_size, bool is_client, + bool is_protect, alts_grpc_record_protocol** rp) { + if (crypter == nullptr || rp == nullptr) { + gpr_log(GPR_ERROR, + "Invalid nullptr arguments to alts_grpc_record_protocol create."); + return TSI_INVALID_ARGUMENT; + } + auto* impl = static_cast( + gpr_zalloc(sizeof(alts_grpc_record_protocol))); + /* Calls alts_grpc_record_protocol init. */ + tsi_result result = + alts_grpc_record_protocol_init(impl, crypter, overflow_size, is_client, + /*is_integrity_only=*/false, is_protect); + if (result != TSI_OK) { + gpr_free(impl); + return result; + } + impl->vtable = &alts_grpc_privacy_integrity_record_protocol_vtable; + *rp = impl; + return TSI_OK; +} diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h new file mode 100644 index 0000000000..1e34aef2d8 --- /dev/null +++ b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h @@ -0,0 +1,49 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_PRIVACY_INTEGRITY_RECORD_PROTOCOL_H +#define GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_PRIVACY_INTEGRITY_RECORD_PROTOCOL_H + +#include + +#include + +#include "src/core/tsi/alts/crypt/gsec.h" +#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h" + +/** + * This method creates a privacy-integrity alts_grpc_record_protocol instance, + * given a gsec_aead_crypter instance and a flag indicating if the created + * instance will be used at the client or server side. The ownership of + * gsec_aead_crypter instance is transferred to this new object. + * + * - crypter: a gsec_aead_crypter instance used to perform AEAD decryption. + * - is_client: a flag indicating if the alts_grpc_record_protocol instance will + * be used at the client or server side. + * - rp: an alts_grpc_record_protocol instance to be returned from + * the method. + * + * This method returns TSI_OK in case of success or a specific error code in + * case of failure. + */ +tsi_result alts_grpc_privacy_integrity_record_protocol_create( + gsec_aead_crypter* crypter, size_t overflow_size, bool is_client, + bool is_protect, alts_grpc_record_protocol** rp); + +#endif /* GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_PRIVACY_INTEGRITY_RECORD_PROTOCOL_H \ + */ diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h new file mode 100644 index 0000000000..d1e433dac4 --- /dev/null +++ b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h @@ -0,0 +1,91 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_RECORD_PROTOCOL_H +#define GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_RECORD_PROTOCOL_H + +#include + +#include + +#include "src/core/tsi/transport_security_interface.h" + +/** + * This alts_grpc_record_protocol object protects and unprotects a single frame + * stored in grpc slice buffer with zero or minimized memory copy. + * Implementations of this object must be thread compatible. + */ +typedef struct alts_grpc_record_protocol alts_grpc_record_protocol; + +/** + * This methods performs protect operation on unprotected data and appends the + * protected frame to protected_slices. The caller needs to ensure the length + * of unprotected data plus the frame overhead is less than or equal to the + * maximum frame length. The input unprotected data slice buffer will be + * cleared, although the actual unprotected data bytes are not modified. + * + * - self: an alts_grpc_record_protocol instance. + * - unprotected_slices: the unprotected data to be protected. + * - protected_slices: slice buffer where the protected frame is appended. + * + * This method returns TSI_OK in case of success or a specific error code in + * case of failure. + */ +tsi_result alts_grpc_record_protocol_protect( + alts_grpc_record_protocol* self, grpc_slice_buffer* unprotected_slices, + grpc_slice_buffer* protected_slices); + +/** + * This methods performs unprotect operation on a full frame of protected data + * and appends unprotected data to unprotected_slices. It is the caller's + * responsibility to prepare a full frame of data before calling this method. + * The input protected frame slice buffer will be cleared, although the actual + * protected data bytes are not modified. + * + * - self: an alts_grpc_record_protocol instance. + * - protected_slices: a full frame of protected data in grpc slices. + * - unprotected_slices: slice buffer where unprotected data is appended. + * + * This method returns TSI_OK in case of success or a specific error code in + * case of failure. + */ +tsi_result alts_grpc_record_protocol_unprotect( + alts_grpc_record_protocol* self, grpc_slice_buffer* protected_slices, + grpc_slice_buffer* unprotected_slices); + +/** + * This method returns maximum allowed unprotected data size, given maximum + * protected frame size. + * + * - self: an alts_grpc_record_protocol instance. + * - max_protected_frame_size: maximum protected frame size. + * + * On success, the method returns the maximum allowed unprotected data size. + * Otherwise, it returns zero. + */ +size_t alts_grpc_record_protocol_max_unprotected_data_size( + const alts_grpc_record_protocol* self, size_t max_protected_frame_size); + +/** + * This method destroys an alts_grpc_record_protocol instance by de-allocating + * all of its occupied memory. + */ +void alts_grpc_record_protocol_destroy(alts_grpc_record_protocol* self); + +#endif /* GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_RECORD_PROTOCOL_H \ + */ diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc new file mode 100644 index 0000000000..ff91aea350 --- /dev/null +++ b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc @@ -0,0 +1,173 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h" + +#include + +#include +#include + +#include "src/core/lib/gpr/useful.h" +#include "src/core/lib/slice/slice_internal.h" + +const size_t kInitialIovecBufferSize = 8; + +/* Makes sure iovec_buf in alts_grpc_record_protocol is large enough. */ +static void ensure_iovec_buf_size(alts_grpc_record_protocol* rp, + const grpc_slice_buffer* sb) { + GPR_ASSERT(rp != nullptr && sb != nullptr); + if (sb->count <= rp->iovec_buf_length) { + return; + } + /* At least double the iovec buffer size. */ + rp->iovec_buf_length = GPR_MAX(sb->count, 2 * rp->iovec_buf_length); + rp->iovec_buf = static_cast( + gpr_realloc(rp->iovec_buf, rp->iovec_buf_length * sizeof(iovec_t))); +} + +/* --- Implementation of methods defined in tsi_grpc_record_protocol_common.h. + * --- */ + +void alts_grpc_record_protocol_convert_slice_buffer_to_iovec( + alts_grpc_record_protocol* rp, const grpc_slice_buffer* sb) { + GPR_ASSERT(rp != nullptr && sb != nullptr); + ensure_iovec_buf_size(rp, sb); + for (size_t i = 0; i < sb->count; i++) { + rp->iovec_buf[i].iov_base = GRPC_SLICE_START_PTR(sb->slices[i]); + rp->iovec_buf[i].iov_len = GRPC_SLICE_LENGTH(sb->slices[i]); + } +} + +void alts_grpc_record_protocol_copy_slice_buffer(const grpc_slice_buffer* src, + unsigned char* dst) { + GPR_ASSERT(src != nullptr && dst != nullptr); + for (size_t i = 0; i < src->count; i++) { + size_t slice_length = GRPC_SLICE_LENGTH(src->slices[i]); + memcpy(dst, GRPC_SLICE_START_PTR(src->slices[i]), slice_length); + dst += slice_length; + } +} + +iovec_t alts_grpc_record_protocol_get_header_iovec( + alts_grpc_record_protocol* rp) { + iovec_t header_iovec = {nullptr, 0}; + if (rp == nullptr) { + return header_iovec; + } + header_iovec.iov_len = rp->header_length; + if (rp->header_sb.count == 1) { + header_iovec.iov_base = GRPC_SLICE_START_PTR(rp->header_sb.slices[0]); + } else { + /* Frame header is in multiple slices, copies the header bytes from slice + * buffer to a single flat buffer. */ + alts_grpc_record_protocol_copy_slice_buffer(&rp->header_sb, rp->header_buf); + header_iovec.iov_base = rp->header_buf; + } + return header_iovec; +} + +tsi_result alts_grpc_record_protocol_init(alts_grpc_record_protocol* rp, + gsec_aead_crypter* crypter, + size_t overflow_size, bool is_client, + bool is_integrity_only, + bool is_protect) { + if (rp == nullptr || crypter == nullptr) { + gpr_log(GPR_ERROR, + "Invalid nullptr arguments to alts_grpc_record_protocol init."); + return TSI_INVALID_ARGUMENT; + } + /* Creates alts_iovec_record_protocol. */ + char* error_details = nullptr; + grpc_status_code status = alts_iovec_record_protocol_create( + crypter, overflow_size, is_client, is_integrity_only, is_protect, + &rp->iovec_rp, &error_details); + if (status != GRPC_STATUS_OK) { + gpr_log(GPR_ERROR, "Failed to create alts_iovec_record_protocol, %s.", + error_details); + gpr_free(error_details); + return TSI_INTERNAL_ERROR; + } + /* Allocates header slice buffer. */ + grpc_slice_buffer_init(&rp->header_sb); + /* Allocates header buffer. */ + rp->header_length = alts_iovec_record_protocol_get_header_length(); + rp->header_buf = static_cast(gpr_malloc(rp->header_length)); + rp->tag_length = alts_iovec_record_protocol_get_tag_length(rp->iovec_rp); + /* Allocates iovec buffer. */ + rp->iovec_buf_length = kInitialIovecBufferSize; + rp->iovec_buf = + static_cast(gpr_malloc(rp->iovec_buf_length * sizeof(iovec_t))); + return TSI_OK; +} + +/* --- Implementation of methods defined in tsi_grpc_record_protocol.h. --- */ +tsi_result alts_grpc_record_protocol_protect( + alts_grpc_record_protocol* self, grpc_slice_buffer* unprotected_slices, + grpc_slice_buffer* protected_slices) { + if (grpc_core::ExecCtx::Get() == nullptr || self == nullptr || + self->vtable == nullptr || unprotected_slices == nullptr || + protected_slices == nullptr) { + return TSI_INVALID_ARGUMENT; + } + if (self->vtable->protect == nullptr) { + return TSI_UNIMPLEMENTED; + } + return self->vtable->protect(self, unprotected_slices, protected_slices); +} + +tsi_result alts_grpc_record_protocol_unprotect( + alts_grpc_record_protocol* self, grpc_slice_buffer* protected_slices, + grpc_slice_buffer* unprotected_slices) { + if (grpc_core::ExecCtx::Get() == nullptr || self == nullptr || + self->vtable == nullptr || protected_slices == nullptr || + unprotected_slices == nullptr) { + return TSI_INVALID_ARGUMENT; + } + if (self->vtable->unprotect == nullptr) { + return TSI_UNIMPLEMENTED; + } + return self->vtable->unprotect(self, protected_slices, unprotected_slices); +} + +void alts_grpc_record_protocol_destroy(alts_grpc_record_protocol* self) { + if (self == nullptr) { + return; + } + if (self->vtable->destruct != nullptr) { + self->vtable->destruct(self); + } + alts_iovec_record_protocol_destroy(self->iovec_rp); + grpc_slice_buffer_destroy_internal(&self->header_sb); + gpr_free(self->header_buf); + gpr_free(self->iovec_buf); + gpr_free(self); +} + +/* Integrity-only and privacy-integrity share the same implementation. No need + * to call vtable. */ +size_t alts_grpc_record_protocol_max_unprotected_data_size( + const alts_grpc_record_protocol* self, size_t max_protected_frame_size) { + if (self == nullptr) { + return 0; + } + return alts_iovec_record_protocol_max_unprotected_data_size( + self->iovec_rp, max_protected_frame_size); +} diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h new file mode 100644 index 0000000000..43b8a4a2b8 --- /dev/null +++ b/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h @@ -0,0 +1,100 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_RECORD_PROTOCOL_COMMON_H +#define GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_RECORD_PROTOCOL_COMMON_H + +/** + * this file contains alts_grpc_record_protocol internals and internal-only + * helper functions. The public functions of alts_grpc_record_protocol are + * defined in the alts_grpc_record_protocol.h. + */ + +#include + +#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h" +#include "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h" + +/* V-table for alts_grpc_record_protocol implementations. */ +typedef struct { + tsi_result (*protect)(alts_grpc_record_protocol* self, + grpc_slice_buffer* unprotected_slices, + grpc_slice_buffer* protected_slices); + tsi_result (*unprotect)(alts_grpc_record_protocol* self, + grpc_slice_buffer* protected_slices, + grpc_slice_buffer* unprotected_slices); + void (*destruct)(alts_grpc_record_protocol* self); +} alts_grpc_record_protocol_vtable; + +/* Main struct for alts_grpc_record_protocol implementation, shared by both + * integrity-only record protocol and privacy-integrity record protocol. + * Integrity-only record protocol has additional data elements. + * Privacy-integrity record protocol uses this struct directly. */ +struct alts_grpc_record_protocol { + const alts_grpc_record_protocol_vtable* vtable; + alts_iovec_record_protocol* iovec_rp; + grpc_slice_buffer header_sb; + unsigned char* header_buf; + size_t header_length; + size_t tag_length; + iovec_t* iovec_buf; + size_t iovec_buf_length; +}; + +/** + * Converts the slices of input sb into iovec_t's and puts the result into + * rp->iovec_buf. Note that the actual data are not copied, only + * pointers and lengths are copied. + */ +void alts_grpc_record_protocol_convert_slice_buffer_to_iovec( + alts_grpc_record_protocol* rp, const grpc_slice_buffer* sb); + +/** + * Copies bytes from slice buffer to destination buffer. Caller is responsible + * for allocating enough memory of destination buffer. This method is used for + * copying frame header and tag in case they are stored in multiple slices. + */ +void alts_grpc_record_protocol_copy_slice_buffer(const grpc_slice_buffer* src, + unsigned char* dst); + +/** + * This method returns an iovec object pointing to the frame header stored in + * rp->header_sb. If the frame header is stored in multiple slices, + * this method will copy the bytes in rp->header_sb to + * rp->header_buf, and return an iovec object pointing to + * rp->header_buf. + */ +iovec_t alts_grpc_record_protocol_get_header_iovec( + alts_grpc_record_protocol* rp); + +/** + * Initializes an alts_grpc_record_protocol object, given a gsec_aead_crypter + * instance, the overflow size of the counter in bytes, a flag indicating if the + * object is used for client or server side, a flag indicating if it is used for + * integrity-only or privacy-integrity mode, and a flag indicating if it is for + * protect or unprotect. The ownership of gsec_aead_crypter object is + * transferred to the alts_grpc_record_protocol object. + */ +tsi_result alts_grpc_record_protocol_init(alts_grpc_record_protocol* rp, + gsec_aead_crypter* crypter, + size_t overflow_size, bool is_client, + bool is_integrity_only, + bool is_protect); + +#endif /* GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_RECORD_PROTOCOL_COMMON_H \ + */ diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc b/src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc new file mode 100644 index 0000000000..6a548e50dd --- /dev/null +++ b/src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc @@ -0,0 +1,476 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h" + +#include +#include + +#include +#include + +#include "src/core/tsi/alts/frame_protector/alts_counter.h" + +struct alts_iovec_record_protocol { + alts_counter* ctr; + gsec_aead_crypter* crypter; + size_t tag_length; + bool is_integrity_only; + bool is_protect; +}; + +/* Copies error message to destination. */ +static void maybe_copy_error_msg(const char* src, char** dst) { + if (dst != nullptr && src != nullptr) { + *dst = static_cast(gpr_malloc(strlen(src) + 1)); + memcpy(*dst, src, strlen(src) + 1); + } +} + +/* Appends error message to destination. */ +static void maybe_append_error_msg(const char* appendix, char** dst) { + if (dst != nullptr && appendix != nullptr) { + int dst_len = static_cast(strlen(*dst)); + *dst = static_cast(realloc(*dst, dst_len + strlen(appendix) + 1)); + assert(*dst != nullptr); + memcpy(*dst + dst_len, appendix, strlen(appendix) + 1); + } +} + +/* Use little endian to interpret a string of bytes as uint32_t. */ +static uint32_t load_32_le(const unsigned char* buffer) { + return (((uint32_t)buffer[3]) << 24) | (((uint32_t)buffer[2]) << 16) | + (((uint32_t)buffer[1]) << 8) | ((uint32_t)buffer[0]); +} + +/* Store uint32_t as a string of little endian bytes. */ +static void store_32_le(uint32_t value, unsigned char* buffer) { + buffer[3] = (unsigned char)(value >> 24) & 0xFF; + buffer[2] = (unsigned char)(value >> 16) & 0xFF; + buffer[1] = (unsigned char)(value >> 8) & 0xFF; + buffer[0] = (unsigned char)(value)&0xFF; +} + +/* Ensures header and tag iovec have sufficient length. */ +static grpc_status_code ensure_header_and_tag_length( + const alts_iovec_record_protocol* rp, iovec_t header, iovec_t tag, + char** error_details) { + if (rp == nullptr) { + return GRPC_STATUS_FAILED_PRECONDITION; + } + if (header.iov_base == nullptr) { + maybe_copy_error_msg("Header is nullptr.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + if (header.iov_len != alts_iovec_record_protocol_get_header_length()) { + maybe_copy_error_msg("Header length is incorrect.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + if (tag.iov_base == nullptr) { + maybe_copy_error_msg("Tag is nullptr.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + if (tag.iov_len != rp->tag_length) { + maybe_copy_error_msg("Tag length is incorrect.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + return GRPC_STATUS_OK; +} + +/* Increments crypter counter and checks overflow. */ +static grpc_status_code increment_counter(alts_counter* counter, + char** error_details) { + if (counter == nullptr) { + return GRPC_STATUS_FAILED_PRECONDITION; + } + bool is_overflow = false; + grpc_status_code status = + alts_counter_increment(counter, &is_overflow, error_details); + if (status != GRPC_STATUS_OK) { + return status; + } + if (is_overflow) { + maybe_copy_error_msg("Crypter counter is overflowed.", error_details); + return GRPC_STATUS_INTERNAL; + } + return GRPC_STATUS_OK; +} + +/* Given an array of iovec, computes the total length of buffer. */ +static size_t get_total_length(const iovec_t* vec, size_t vec_length) { + size_t total_length = 0; + for (size_t i = 0; i < vec_length; ++i) { + total_length += vec[i].iov_len; + } + return total_length; +} + +/* Writes frame header given data and tag length. */ +static grpc_status_code write_frame_header(size_t data_length, + unsigned char* header, + char** error_details) { + if (header == nullptr) { + maybe_copy_error_msg("Header is nullptr.", error_details); + return GRPC_STATUS_FAILED_PRECONDITION; + } + size_t frame_length = kZeroCopyFrameMessageTypeFieldSize + data_length; + store_32_le(static_cast(frame_length), header); + store_32_le(kZeroCopyFrameMessageType, + header + kZeroCopyFrameLengthFieldSize); + return GRPC_STATUS_OK; +} + +/* Verifies frame header given protected data length. */ +static grpc_status_code verify_frame_header(size_t data_length, + unsigned char* header, + char** error_details) { + if (header == nullptr) { + maybe_copy_error_msg("Header is nullptr.", error_details); + return GRPC_STATUS_FAILED_PRECONDITION; + } + size_t frame_length = load_32_le(header); + if (frame_length != kZeroCopyFrameMessageTypeFieldSize + data_length) { + maybe_copy_error_msg("Bad frame length.", error_details); + return GRPC_STATUS_INTERNAL; + } + size_t message_type = load_32_le(header + kZeroCopyFrameLengthFieldSize); + if (message_type != kZeroCopyFrameMessageType) { + maybe_copy_error_msg("Unsupported message type.", error_details); + return GRPC_STATUS_INTERNAL; + } + return GRPC_STATUS_OK; +} + +/* --- alts_iovec_record_protocol methods implementation. --- */ + +size_t alts_iovec_record_protocol_get_header_length() { + return kZeroCopyFrameHeaderSize; +} + +size_t alts_iovec_record_protocol_get_tag_length( + const alts_iovec_record_protocol* rp) { + if (rp != nullptr) { + return rp->tag_length; + } + return 0; +} + +size_t alts_iovec_record_protocol_max_unprotected_data_size( + const alts_iovec_record_protocol* rp, size_t max_protected_frame_size) { + if (rp == nullptr) { + return 0; + } + size_t overhead_bytes_size = + kZeroCopyFrameMessageTypeFieldSize + rp->tag_length; + if (max_protected_frame_size <= overhead_bytes_size) return 0; + return max_protected_frame_size - overhead_bytes_size; +} + +grpc_status_code alts_iovec_record_protocol_integrity_only_protect( + alts_iovec_record_protocol* rp, const iovec_t* unprotected_vec, + size_t unprotected_vec_length, iovec_t header, iovec_t tag, + char** error_details) { + /* Input sanity checks. */ + if (rp == nullptr) { + maybe_copy_error_msg("Input iovec_record_protocol is nullptr.", + error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + if (!rp->is_integrity_only) { + maybe_copy_error_msg( + "Integrity-only operations are not allowed for this object.", + error_details); + return GRPC_STATUS_FAILED_PRECONDITION; + } + if (!rp->is_protect) { + maybe_copy_error_msg("Protect operations are not allowed for this object.", + error_details); + return GRPC_STATUS_FAILED_PRECONDITION; + } + grpc_status_code status = + ensure_header_and_tag_length(rp, header, tag, error_details); + if (status != GRPC_STATUS_OK) { + return status; + } + /* Unprotected data should not be zero length. */ + size_t data_length = + get_total_length(unprotected_vec, unprotected_vec_length); + /* Sets frame header. */ + status = write_frame_header(data_length + rp->tag_length, + static_cast(header.iov_base), + error_details); + if (status != GRPC_STATUS_OK) { + return status; + } + /* Computes frame tag by calling AEAD crypter. */ + size_t bytes_written = 0; + status = gsec_aead_crypter_encrypt_iovec( + rp->crypter, alts_counter_get_counter(rp->ctr), + alts_counter_get_size(rp->ctr), unprotected_vec, unprotected_vec_length, + /* plaintext_vec = */ nullptr, /* plaintext_vec_length = */ 0, tag, + &bytes_written, error_details); + if (status != GRPC_STATUS_OK) { + return status; + } + if (bytes_written != rp->tag_length) { + maybe_copy_error_msg("Bytes written expects to be the same as tag length.", + error_details); + return GRPC_STATUS_INTERNAL; + } + /* Increments the crypter counter. */ + return increment_counter(rp->ctr, error_details); +} + +grpc_status_code alts_iovec_record_protocol_integrity_only_unprotect( + alts_iovec_record_protocol* rp, const iovec_t* protected_vec, + size_t protected_vec_length, iovec_t header, iovec_t tag, + char** error_details) { + /* Input sanity checks. */ + if (rp == nullptr) { + maybe_copy_error_msg("Input iovec_record_protocol is nullptr.", + error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + if (!rp->is_integrity_only) { + maybe_copy_error_msg( + "Integrity-only operations are not allowed for this object.", + error_details); + return GRPC_STATUS_FAILED_PRECONDITION; + } + if (rp->is_protect) { + maybe_copy_error_msg( + "Unprotect operations are not allowed for this object.", error_details); + return GRPC_STATUS_FAILED_PRECONDITION; + } + grpc_status_code status = + ensure_header_and_tag_length(rp, header, tag, error_details); + if (status != GRPC_STATUS_OK) return status; + /* Protected data should not be zero length. */ + size_t data_length = get_total_length(protected_vec, protected_vec_length); + /* Verifies frame header. */ + status = verify_frame_header(data_length + rp->tag_length, + static_cast(header.iov_base), + error_details); + if (status != GRPC_STATUS_OK) { + return status; + } + /* Verifies frame tag by calling AEAD crypter. */ + iovec_t plaintext = {nullptr, 0}; + size_t bytes_written = 0; + status = gsec_aead_crypter_decrypt_iovec( + rp->crypter, alts_counter_get_counter(rp->ctr), + alts_counter_get_size(rp->ctr), protected_vec, protected_vec_length, &tag, + 1, plaintext, &bytes_written, error_details); + if (status != GRPC_STATUS_OK || bytes_written != 0) { + maybe_append_error_msg(" Frame tag verification failed.", error_details); + return GRPC_STATUS_INTERNAL; + } + /* Increments the crypter counter. */ + return increment_counter(rp->ctr, error_details); +} + +grpc_status_code alts_iovec_record_protocol_privacy_integrity_protect( + alts_iovec_record_protocol* rp, const iovec_t* unprotected_vec, + size_t unprotected_vec_length, iovec_t protected_frame, + char** error_details) { + /* Input sanity checks. */ + if (rp == nullptr) { + maybe_copy_error_msg("Input iovec_record_protocol is nullptr.", + error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + if (rp->is_integrity_only) { + maybe_copy_error_msg( + "Privacy-integrity operations are not allowed for this object.", + error_details); + return GRPC_STATUS_FAILED_PRECONDITION; + } + if (!rp->is_protect) { + maybe_copy_error_msg("Protect operations are not allowed for this object.", + error_details); + return GRPC_STATUS_FAILED_PRECONDITION; + } + /* Unprotected data should not be zero length. */ + size_t data_length = + get_total_length(unprotected_vec, unprotected_vec_length); + /* Ensures protected frame iovec has sufficient size. */ + if (protected_frame.iov_base == nullptr) { + maybe_copy_error_msg("Protected frame is nullptr.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + if (protected_frame.iov_len != + alts_iovec_record_protocol_get_header_length() + data_length + + rp->tag_length) { + maybe_copy_error_msg("Protected frame size is incorrect.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + /* Writer frame header. */ + grpc_status_code status = write_frame_header( + data_length + rp->tag_length, + static_cast(protected_frame.iov_base), error_details); + if (status != GRPC_STATUS_OK) { + return status; + } + /* Encrypt unprotected data by calling AEAD crypter. */ + unsigned char* ciphertext_buffer = + static_cast(protected_frame.iov_base) + + alts_iovec_record_protocol_get_header_length(); + iovec_t ciphertext = {ciphertext_buffer, data_length + rp->tag_length}; + size_t bytes_written = 0; + status = gsec_aead_crypter_encrypt_iovec( + rp->crypter, alts_counter_get_counter(rp->ctr), + alts_counter_get_size(rp->ctr), /* aad_vec = */ nullptr, + /* aad_vec_length = */ 0, unprotected_vec, unprotected_vec_length, + ciphertext, &bytes_written, error_details); + if (status != GRPC_STATUS_OK) { + return status; + } + if (bytes_written != data_length + rp->tag_length) { + maybe_copy_error_msg( + "Bytes written expects to be data length plus tag length.", + error_details); + return GRPC_STATUS_INTERNAL; + } + /* Increments the crypter counter. */ + return increment_counter(rp->ctr, error_details); +} + +grpc_status_code alts_iovec_record_protocol_privacy_integrity_unprotect( + alts_iovec_record_protocol* rp, iovec_t header, + const iovec_t* protected_vec, size_t protected_vec_length, + iovec_t unprotected_data, char** error_details) { + /* Input sanity checks. */ + if (rp == nullptr) { + maybe_copy_error_msg("Input iovec_record_protocol is nullptr.", + error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + if (rp->is_integrity_only) { + maybe_copy_error_msg( + "Privacy-integrity operations are not allowed for this object.", + error_details); + return GRPC_STATUS_FAILED_PRECONDITION; + } + if (rp->is_protect) { + maybe_copy_error_msg( + "Unprotect operations are not allowed for this object.", error_details); + return GRPC_STATUS_FAILED_PRECONDITION; + } + /* Protected data size should be no less than tag size. */ + size_t protected_data_length = + get_total_length(protected_vec, protected_vec_length); + if (protected_data_length < rp->tag_length) { + maybe_copy_error_msg( + "Protected data length should be more than the tag length.", + error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + /* Ensures header has sufficient size. */ + if (header.iov_base == nullptr) { + maybe_copy_error_msg("Header is nullptr.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + if (header.iov_len != alts_iovec_record_protocol_get_header_length()) { + maybe_copy_error_msg("Header length is incorrect.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + /* Ensures unprotected data iovec has sufficient size. */ + if (unprotected_data.iov_len != protected_data_length - rp->tag_length) { + maybe_copy_error_msg("Unprotected data size is incorrect.", error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + /* Verify frame header. */ + grpc_status_code status = verify_frame_header( + protected_data_length, static_cast(header.iov_base), + error_details); + if (status != GRPC_STATUS_OK) { + return status; + } + /* Decrypt protected data by calling AEAD crypter. */ + size_t bytes_written = 0; + status = gsec_aead_crypter_decrypt_iovec( + rp->crypter, alts_counter_get_counter(rp->ctr), + alts_counter_get_size(rp->ctr), /* aad_vec = */ nullptr, + /* aad_vec_length = */ 0, protected_vec, protected_vec_length, + unprotected_data, &bytes_written, error_details); + if (status != GRPC_STATUS_OK) { + maybe_append_error_msg(" Frame decryption failed.", error_details); + return GRPC_STATUS_INTERNAL; + } + if (bytes_written != protected_data_length - rp->tag_length) { + maybe_copy_error_msg( + "Bytes written expects to be protected data length minus tag length.", + error_details); + return GRPC_STATUS_INTERNAL; + } + /* Increments the crypter counter. */ + return increment_counter(rp->ctr, error_details); +} + +grpc_status_code alts_iovec_record_protocol_create( + gsec_aead_crypter* crypter, size_t overflow_size, bool is_client, + bool is_integrity_only, bool is_protect, alts_iovec_record_protocol** rp, + char** error_details) { + if (crypter == nullptr || rp == nullptr) { + maybe_copy_error_msg( + "Invalid nullptr arguments to alts_iovec_record_protocol create.", + error_details); + return GRPC_STATUS_INVALID_ARGUMENT; + } + alts_iovec_record_protocol* impl = static_cast( + gpr_zalloc(sizeof(alts_iovec_record_protocol))); + /* Gets counter length. */ + size_t counter_length = 0; + grpc_status_code status = + gsec_aead_crypter_nonce_length(crypter, &counter_length, error_details); + if (status != GRPC_STATUS_OK) { + goto cleanup; + } + /* Creates counters. */ + status = + alts_counter_create(is_protect ? !is_client : is_client, counter_length, + overflow_size, &impl->ctr, error_details); + if (status != GRPC_STATUS_OK) { + goto cleanup; + } + /* Gets tag length. */ + status = + gsec_aead_crypter_tag_length(crypter, &impl->tag_length, error_details); + if (status != GRPC_STATUS_OK) { + goto cleanup; + } + impl->crypter = crypter; + impl->is_integrity_only = is_integrity_only; + impl->is_protect = is_protect; + *rp = impl; + return GRPC_STATUS_OK; +cleanup: + alts_counter_destroy(impl->ctr); + gpr_free(impl); + return GRPC_STATUS_FAILED_PRECONDITION; +} + +void alts_iovec_record_protocol_destroy(alts_iovec_record_protocol* rp) { + if (rp != nullptr) { + alts_counter_destroy(rp->ctr); + gsec_aead_crypter_destroy(rp->crypter); + gpr_free(rp); + } +} diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h b/src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h new file mode 100644 index 0000000000..0b7d1bf5bf --- /dev/null +++ b/src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h @@ -0,0 +1,199 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_IOVEC_RECORD_PROTOCOL_H +#define GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_IOVEC_RECORD_PROTOCOL_H + +#include + +#include + +#include "src/core/tsi/alts/crypt/gsec.h" + +constexpr size_t kZeroCopyFrameMessageType = 0x06; +constexpr size_t kZeroCopyFrameLengthFieldSize = 4; +constexpr size_t kZeroCopyFrameMessageTypeFieldSize = 4; +constexpr size_t kZeroCopyFrameHeaderSize = + kZeroCopyFrameLengthFieldSize + kZeroCopyFrameMessageTypeFieldSize; + +// Limit k on number of frames such that at most 2^(8 * k) frames can be sent. +constexpr size_t kAltsRecordProtocolRekeyFrameLimit = 8; +constexpr size_t kAltsRecordProtocolFrameLimit = 5; + +/* An implementation of alts record protocol. The API is thread-compatible. */ + +typedef struct iovec iovec_t; + +typedef struct alts_iovec_record_protocol alts_iovec_record_protocol; + +/** + * This method gets the length of record protocol frame header. + */ +size_t alts_iovec_record_protocol_get_header_length(); + +/** + * This method gets the length of record protocol frame tag. + * + * - rp: an alts_iovec_record_protocol instance. + * + * On success, the method returns the length of record protocol frame tag. + * Otherwise, it returns zero. + */ +size_t alts_iovec_record_protocol_get_tag_length( + const alts_iovec_record_protocol* rp); + +/** + * This method returns maximum allowed unprotected data size, given maximum + * protected frame size. + * + * - rp: an alts_iovec_record_protocol instance. + * - max_protected_frame_size: maximum protected frame size. + * + * On success, the method returns the maximum allowed unprotected data size. + * Otherwise, it returns zero. + */ +size_t alts_iovec_record_protocol_max_unprotected_data_size( + const alts_iovec_record_protocol* rp, size_t max_protected_frame_size); + +/** + * This method performs integrity-only protect operation on a + * alts_iovec_record_protocol instance, i.e., compute frame header and tag. The + * caller needs to allocate the memory for header and tag prior to calling this + * method. + * + * - rp: an alts_iovec_record_protocol instance. + * - unprotected_vec: an iovec array containing unprotected data. + * - unprotected_vec_length: the array length of unprotected_vec. + * - header: an iovec containing the output frame header. + * - tag: an iovec containing the output frame tag. + * - error_details: a buffer containing an error message if the method does not + * function correctly. It is OK to pass nullptr into error_details. + * + * On success, the method returns GRPC_STATUS_OK. Otherwise, it returns an + * error status code along with its details specified in error_details (if + * error_details is not nullptr). + */ +grpc_status_code alts_iovec_record_protocol_integrity_only_protect( + alts_iovec_record_protocol* rp, const iovec_t* unprotected_vec, + size_t unprotected_vec_length, iovec_t header, iovec_t tag, + char** error_details); + +/** + * This method performs integrity-only unprotect operation on a + * alts_iovec_record_protocol instance, i.e., verify frame header and tag. + * + * - rp: an alts_iovec_record_protocol instance. + * - protected_vec: an iovec array containing protected data. + * - protected_vec_length: the array length of protected_vec. + * - header: an iovec containing the frame header. + * - tag: an iovec containing the frame tag. + * - error_details: a buffer containing an error message if the method does not + * function correctly. It is OK to pass nullptr into error_details. + * + * On success, the method returns GRPC_STATUS_OK. Otherwise, it returns an + * error status code along with its details specified in error_details (if + * error_details is not nullptr). + */ +grpc_status_code alts_iovec_record_protocol_integrity_only_unprotect( + alts_iovec_record_protocol* rp, const iovec_t* protected_vec, + size_t protected_vec_length, iovec_t header, iovec_t tag, + char** error_details); + +/** + * This method performs privacy-integrity protect operation on a + * alts_iovec_record_protocol instance, i.e., compute a protected frame. The + * caller needs to allocate the memory for the protected frame prior to calling + * this method. + * + * - rp: an alts_iovec_record_protocol instance. + * - unprotected_vec: an iovec array containing unprotected data. + * - unprotected_vec_length: the array length of unprotected_vec. + * - protected_frame: an iovec containing the output protected frame. + * - error_details: a buffer containing an error message if the method does not + * function correctly. It is OK to pass nullptr into error_details. + * + * On success, the method returns GRPC_STATUS_OK. Otherwise, it returns an + * error status code along with its details specified in error_details (if + * error_details is not nullptr). + */ +grpc_status_code alts_iovec_record_protocol_privacy_integrity_protect( + alts_iovec_record_protocol* rp, const iovec_t* unprotected_vec, + size_t unprotected_vec_length, iovec_t protected_frame, + char** error_details); + +/** + * This method performs privacy-integrity unprotect operation on a + * alts_iovec_record_protocol instance given a full protected frame, i.e., + * compute the unprotected data. The caller needs to allocated the memory for + * the unprotected data prior to calling this method. + * + * - rp: an alts_iovec_record_protocol instance. + * - header: an iovec containing the frame header. + * - protected_vec: an iovec array containing protected data including the tag. + * - protected_vec_length: the array length of protected_vec. + * - unprotected_data: an iovec containing the output unprotected data. + * - error_details: a buffer containing an error message if the method does not + * function correctly. It is OK to pass nullptr into error_details. + * + * On success, the method returns GRPC_STATUS_OK. Otherwise, it returns an + * error status code along with its details specified in error_details (if + * error_details is not nullptr). + */ +grpc_status_code alts_iovec_record_protocol_privacy_integrity_unprotect( + alts_iovec_record_protocol* rp, iovec_t header, + const iovec_t* protected_vec, size_t protected_vec_length, + iovec_t unprotected_data, char** error_details); + +/** + * This method creates an alts_iovec_record_protocol instance, given a + * gsec_aead_crypter instance, a flag indicating if the created instance will be + * used at the client or server side, and a flag indicating if the created + * instance will be used for integrity-only mode or privacy-integrity mode. The + * ownership of gsec_aead_crypter instance is transferred to this new object. + * + * - crypter: a gsec_aead_crypter instance used to perform AEAD decryption. + * - overflow_size: overflow size of counter in bytes. + * - is_client: a flag indicating if the alts_iovec_record_protocol instance + * will be used at the client or server side. + * - is_integrity_only: a flag indicating if the alts_iovec_record_protocol + * instance will be used for integrity-only or privacy-integrity mode. + * - is_protect: a flag indicating if the alts_grpc_record_protocol instance + * will be used for protect or unprotect. + * - rp: an alts_iovec_record_protocol instance to be returned from + * the method. + * - error_details: a buffer containing an error message if the method does not + * function correctly. It is OK to pass nullptr into error_details. + * + * On success, the method returns GRPC_STATUS_OK. Otherwise, it returns an + * error status code along with its details specified in error_details (if + * error_details is not nullptr). + */ +grpc_status_code alts_iovec_record_protocol_create( + gsec_aead_crypter* crypter, size_t overflow_size, bool is_client, + bool is_integrity_only, bool is_protect, alts_iovec_record_protocol** rp, + char** error_details); + +/** + * This method destroys an alts_iovec_record_protocol instance by de-allocating + * all of its occupied memory. A gsec_aead_crypter instance passed in at + * gsec_alts_crypter instance creation time will be destroyed in this method. + */ +void alts_iovec_record_protocol_destroy(alts_iovec_record_protocol* rp); + +#endif /* GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_IOVEC_RECORD_PROTOCOL_H \ + */ diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc b/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc new file mode 100644 index 0000000000..8c764961b3 --- /dev/null +++ b/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc @@ -0,0 +1,295 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h" + +#include + +#include +#include + +#include "src/core/lib/gpr/useful.h" +#include "src/core/lib/slice/slice_internal.h" +#include "src/core/tsi/alts/crypt/gsec.h" +#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h" +#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h" +#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h" +#include "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h" +#include "src/core/tsi/transport_security_grpc.h" + +constexpr size_t kMinFrameLength = 1024; +constexpr size_t kDefaultFrameLength = 16 * 1024; +constexpr size_t kMaxFrameLength = 1024 * 1024; + +/** + * Main struct for alts_zero_copy_grpc_protector. + * We choose to have two alts_grpc_record_protocol objects and two sets of slice + * buffers: one for protect and the other for unprotect, so that protect and + * unprotect can be executed in parallel. Implementations of this object must be + * thread compatible. + */ +typedef struct alts_zero_copy_grpc_protector { + tsi_zero_copy_grpc_protector base; + alts_grpc_record_protocol* record_protocol; + alts_grpc_record_protocol* unrecord_protocol; + size_t max_protected_frame_size; + size_t max_unprotected_data_size; + grpc_slice_buffer unprotected_staging_sb; + grpc_slice_buffer protected_sb; + grpc_slice_buffer protected_staging_sb; + uint32_t parsed_frame_size; +} alts_zero_copy_grpc_protector; + +/** + * Given a slice buffer, parses the first 4 bytes little-endian unsigned frame + * size and returns the total frame size including the frame field. Caller + * needs to make sure the input slice buffer has at least 4 bytes. Returns true + * on success and false on failure. + */ +static bool read_frame_size(const grpc_slice_buffer* sb, + uint32_t* total_frame_size) { + if (sb == nullptr || sb->length < kZeroCopyFrameLengthFieldSize) { + return false; + } + uint8_t frame_size_buffer[kZeroCopyFrameLengthFieldSize]; + uint8_t* buf = frame_size_buffer; + /* Copies the first 4 bytes to a temporary buffer. */ + size_t remaining = kZeroCopyFrameLengthFieldSize; + for (size_t i = 0; i < sb->count; i++) { + size_t slice_length = GRPC_SLICE_LENGTH(sb->slices[i]); + if (remaining <= slice_length) { + memcpy(buf, GRPC_SLICE_START_PTR(sb->slices[i]), remaining); + remaining = 0; + break; + } else { + memcpy(buf, GRPC_SLICE_START_PTR(sb->slices[i]), slice_length); + buf += slice_length; + remaining -= slice_length; + } + } + GPR_ASSERT(remaining == 0); + /* Gets little-endian frame size. */ + uint32_t frame_size = (((uint32_t)frame_size_buffer[3]) << 24) | + (((uint32_t)frame_size_buffer[2]) << 16) | + (((uint32_t)frame_size_buffer[1]) << 8) | + ((uint32_t)frame_size_buffer[0]); + if (frame_size > kMaxFrameLength) { + gpr_log(GPR_ERROR, "Frame size is larger than maximum frame size"); + return false; + } + /* Returns frame size including frame length field. */ + *total_frame_size = + static_cast(frame_size + kZeroCopyFrameLengthFieldSize); + return true; +} + +/** + * Creates an alts_grpc_record_protocol object, given key, key size, and flags + * to indicate whether the record_protocol object uses the rekeying AEAD, + * whether the object is for client or server, whether the object is for + * integrity-only or privacy-integrity mode, and whether the object is is used + * for protect or unprotect. + */ +static tsi_result create_alts_grpc_record_protocol( + const uint8_t* key, size_t key_size, bool is_rekey, bool is_client, + bool is_integrity_only, bool is_protect, + alts_grpc_record_protocol** record_protocol) { + if (key == nullptr || record_protocol == nullptr) { + return TSI_INVALID_ARGUMENT; + } + grpc_status_code status; + gsec_aead_crypter* crypter = nullptr; + char* error_details = nullptr; + status = gsec_aes_gcm_aead_crypter_create(key, key_size, kAesGcmNonceLength, + kAesGcmTagLength, is_rekey, + &crypter, &error_details); + if (status != GRPC_STATUS_OK) { + gpr_log(GPR_ERROR, "Failed to create AEAD crypter, %s", error_details); + gpr_free(error_details); + return TSI_INTERNAL_ERROR; + } + size_t overflow_limit = is_rekey ? kAltsRecordProtocolRekeyFrameLimit + : kAltsRecordProtocolFrameLimit; + /* Creates alts_grpc_record_protocol with AEAD crypter ownership transferred. + */ + tsi_result result = + is_integrity_only + ? alts_grpc_integrity_only_record_protocol_create( + crypter, overflow_limit, is_client, is_protect, record_protocol) + : alts_grpc_privacy_integrity_record_protocol_create( + crypter, overflow_limit, is_client, is_protect, + record_protocol); + if (result != TSI_OK) { + gsec_aead_crypter_destroy(crypter); + return result; + } + return TSI_OK; +} + +/* --- tsi_zero_copy_grpc_protector methods implementation. --- */ + +static tsi_result alts_zero_copy_grpc_protector_protect( + tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* unprotected_slices, + grpc_slice_buffer* protected_slices) { + if (self == nullptr || unprotected_slices == nullptr || + protected_slices == nullptr) { + gpr_log(GPR_ERROR, "Invalid nullptr arguments to zero-copy grpc protect."); + return TSI_INVALID_ARGUMENT; + } + alts_zero_copy_grpc_protector* protector = + reinterpret_cast(self); + /* Calls alts_grpc_record_protocol protect repeatly. */ + while (unprotected_slices->length > protector->max_unprotected_data_size) { + grpc_slice_buffer_move_first(unprotected_slices, + protector->max_unprotected_data_size, + &protector->unprotected_staging_sb); + tsi_result status = alts_grpc_record_protocol_protect( + protector->record_protocol, &protector->unprotected_staging_sb, + protected_slices); + if (status != TSI_OK) { + return status; + } + } + return alts_grpc_record_protocol_protect( + protector->record_protocol, unprotected_slices, protected_slices); +} + +static tsi_result alts_zero_copy_grpc_protector_unprotect( + tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* protected_slices, + grpc_slice_buffer* unprotected_slices) { + if (self == nullptr || unprotected_slices == nullptr || + protected_slices == nullptr) { + gpr_log(GPR_ERROR, + "Invalid nullptr arguments to zero-copy grpc unprotect."); + return TSI_INVALID_ARGUMENT; + } + alts_zero_copy_grpc_protector* protector = + reinterpret_cast(self); + grpc_slice_buffer_move_into(protected_slices, &protector->protected_sb); + /* Keep unprotecting each frame if possible. */ + while (protector->protected_sb.length >= kZeroCopyFrameLengthFieldSize) { + if (protector->parsed_frame_size == 0) { + /* We have not parsed frame size yet. Parses frame size. */ + if (!read_frame_size(&protector->protected_sb, + &protector->parsed_frame_size)) { + grpc_slice_buffer_reset_and_unref_internal(&protector->protected_sb); + return TSI_DATA_CORRUPTED; + } + } + if (protector->protected_sb.length < protector->parsed_frame_size) break; + /* At this point, protected_sb contains at least one frame of data. */ + tsi_result status; + if (protector->protected_sb.length == protector->parsed_frame_size) { + status = alts_grpc_record_protocol_unprotect(protector->unrecord_protocol, + &protector->protected_sb, + unprotected_slices); + } else { + grpc_slice_buffer_move_first(&protector->protected_sb, + protector->parsed_frame_size, + &protector->protected_staging_sb); + status = alts_grpc_record_protocol_unprotect( + protector->unrecord_protocol, &protector->protected_staging_sb, + unprotected_slices); + } + protector->parsed_frame_size = 0; + if (status != TSI_OK) { + grpc_slice_buffer_reset_and_unref_internal(&protector->protected_sb); + return status; + } + } + return TSI_OK; +} + +static void alts_zero_copy_grpc_protector_destroy( + tsi_zero_copy_grpc_protector* self) { + if (self == nullptr) { + return; + } + alts_zero_copy_grpc_protector* protector = + reinterpret_cast(self); + alts_grpc_record_protocol_destroy(protector->record_protocol); + alts_grpc_record_protocol_destroy(protector->unrecord_protocol); + grpc_slice_buffer_destroy_internal(&protector->unprotected_staging_sb); + grpc_slice_buffer_destroy_internal(&protector->protected_sb); + grpc_slice_buffer_destroy_internal(&protector->protected_staging_sb); + gpr_free(protector); +} + +static const tsi_zero_copy_grpc_protector_vtable + alts_zero_copy_grpc_protector_vtable = { + alts_zero_copy_grpc_protector_protect, + alts_zero_copy_grpc_protector_unprotect, + alts_zero_copy_grpc_protector_destroy}; + +tsi_result alts_zero_copy_grpc_protector_create( + const uint8_t* key, size_t key_size, bool is_rekey, bool is_client, + bool is_integrity_only, size_t* max_protected_frame_size, + tsi_zero_copy_grpc_protector** protector) { + if (grpc_core::ExecCtx::Get() == nullptr || key == nullptr || + protector == nullptr) { + gpr_log( + GPR_ERROR, + "Invalid nullptr arguments to alts_zero_copy_grpc_protector create."); + return TSI_INVALID_ARGUMENT; + } + /* Creates alts_zero_copy_protector. */ + alts_zero_copy_grpc_protector* impl = + static_cast( + gpr_zalloc(sizeof(alts_zero_copy_grpc_protector))); + /* Creates alts_grpc_record_protocol objects. */ + tsi_result status = create_alts_grpc_record_protocol( + key, key_size, is_rekey, is_client, is_integrity_only, + /*is_protect=*/true, &impl->record_protocol); + if (status == TSI_OK) { + status = create_alts_grpc_record_protocol( + key, key_size, is_rekey, is_client, is_integrity_only, + /*is_protect=*/false, &impl->unrecord_protocol); + if (status == TSI_OK) { + /* Sets maximum frame size. */ + size_t max_protected_frame_size_to_set = kDefaultFrameLength; + if (max_protected_frame_size != nullptr) { + *max_protected_frame_size = + GPR_MIN(*max_protected_frame_size, kMaxFrameLength); + *max_protected_frame_size = + GPR_MAX(*max_protected_frame_size, kMinFrameLength); + max_protected_frame_size_to_set = *max_protected_frame_size; + } + impl->max_protected_frame_size = max_protected_frame_size_to_set; + impl->max_unprotected_data_size = + alts_grpc_record_protocol_max_unprotected_data_size( + impl->record_protocol, max_protected_frame_size_to_set); + GPR_ASSERT(impl->max_unprotected_data_size > 0); + /* Allocates internal slice buffers. */ + grpc_slice_buffer_init(&impl->unprotected_staging_sb); + grpc_slice_buffer_init(&impl->protected_sb); + grpc_slice_buffer_init(&impl->protected_staging_sb); + impl->parsed_frame_size = 0; + impl->base.vtable = &alts_zero_copy_grpc_protector_vtable; + *protector = &impl->base; + return TSI_OK; + } + } + + /* Cleanup if create failed. */ + alts_grpc_record_protocol_destroy(impl->record_protocol); + alts_grpc_record_protocol_destroy(impl->unrecord_protocol); + gpr_free(impl); + return TSI_INTERNAL_ERROR; +} diff --git a/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h b/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h new file mode 100644 index 0000000000..71e953cfc1 --- /dev/null +++ b/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h @@ -0,0 +1,52 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_ZERO_COPY_GRPC_PROTECTOR_H +#define GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_ZERO_COPY_GRPC_PROTECTOR_H + +#include + +#include + +#include "src/core/tsi/transport_security_grpc.h" + +/** + * This method creates an ALTS zero-copy grpc protector. + * + * - key: a symmetric key used to seal/unseal frames. + * - key_size: the size of symmetric key. + * - is_rekey: use rekeying AEAD crypter. + * - is_client: a flag indicating if the protector will be used at client or + * server side. + * - is_integrity_only: a flag indicating if the protector instance will be + * used for integrity-only or privacy-integrity mode. + * - max_protected_frame_size: an in/out parameter indicating max frame size + * to be used by the protector. If it is nullptr, the default frame size will + * be used. Otherwise, the provided frame size will be adjusted (if not + * falling into a valid frame range) and used. + * - protector: a pointer to the zero-copy protector returned from the method. + * + * This method returns TSI_OK on success or a specific error code otherwise. + */ +tsi_result alts_zero_copy_grpc_protector_create( + const uint8_t* key, size_t key_size, bool is_rekey, bool is_client, + bool is_integrity_only, size_t* max_protected_frame_size, + tsi_zero_copy_grpc_protector** protector); + +#endif /* GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_ZERO_COPY_GRPC_PROTECTOR_H \ + */ diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 8922f3ad4f..994443c651 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -220,6 +220,7 @@ CORE_SOURCE_FILES = [ 'src/core/ext/filters/http/server/http_server_filter.cc', 'src/core/lib/http/httpcli_security_connector.cc', 'src/core/lib/security/context/security_context.cc', + 'src/core/lib/security/credentials/alts/alts_credentials.cc', 'src/core/lib/security/credentials/composite/composite_credentials.cc', 'src/core/lib/security/credentials/credentials.cc', 'src/core/lib/security/credentials/credentials_metadata.cc', @@ -233,6 +234,7 @@ CORE_SOURCE_FILES = [ 'src/core/lib/security/credentials/oauth2/oauth2_credentials.cc', 'src/core/lib/security/credentials/plugin/plugin_credentials.cc', 'src/core/lib/security/credentials/ssl/ssl_credentials.cc', + 'src/core/lib/security/security_connector/alts_security_connector.cc', 'src/core/lib/security/security_connector/security_connector.cc', 'src/core/lib/security/transport/client_auth_filter.cc', 'src/core/lib/security/transport/secure_endpoint.cc', @@ -242,14 +244,45 @@ CORE_SOURCE_FILES = [ 'src/core/lib/security/transport/tsi_error.cc', 'src/core/lib/security/util/json_util.cc', 'src/core/lib/surface/init_secure.cc', - 'src/core/tsi/alts_transport_security.cc', - 'src/core/tsi/fake_transport_security.cc', - 'src/core/tsi/ssl_transport_security.cc', - 'src/core/tsi/transport_security_grpc.cc', + 'src/core/tsi/alts/crypt/aes_gcm.cc', + 'src/core/tsi/alts/crypt/gsec.cc', + 'src/core/tsi/alts/frame_protector/alts_counter.cc', + 'src/core/tsi/alts/frame_protector/alts_crypter.cc', + 'src/core/tsi/alts/frame_protector/alts_frame_protector.cc', + 'src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc', + 'src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc', + 'src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc', + 'src/core/tsi/alts/frame_protector/frame_handler.cc', + 'src/core/tsi/alts/handshaker/alts_handshaker_client.cc', + 'src/core/tsi/alts/handshaker/alts_tsi_event.cc', + 'src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc', + 'src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc', + 'src/core/lib/security/credentials/alts/check_gcp_environment.cc', + 'src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc', + 'src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc', + 'src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc', + 'src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc', + 'src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc', + 'src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc', + 'src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc', + 'src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc', + 'src/core/tsi/alts/handshaker/alts_tsi_utils.cc', + 'src/core/tsi/alts/handshaker/transport_security_common_api.cc', + 'src/core/tsi/alts/handshaker/altscontext.pb.c', + 'src/core/tsi/alts/handshaker/handshaker.pb.c', + 'src/core/tsi/alts/handshaker/transport_security_common.pb.c', + 'third_party/nanopb/pb_common.c', + 'third_party/nanopb/pb_decode.c', + 'third_party/nanopb/pb_encode.c', 'src/core/tsi/transport_security.cc', 'src/core/tsi/transport_security_adapter.cc', - 'src/core/ext/transport/chttp2/server/chttp2_server.cc', - 'src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc', + 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', + 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', + 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', 'src/core/ext/filters/client_channel/client_channel.cc', @@ -273,11 +306,14 @@ CORE_SOURCE_FILES = [ 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', 'src/core/ext/filters/deadline/deadline_filter.cc', - 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', + 'src/core/tsi/alts_transport_security.cc', + 'src/core/tsi/fake_transport_security.cc', + 'src/core/tsi/ssl_transport_security.cc', + 'src/core/tsi/transport_security_grpc.cc', + 'src/core/ext/transport/chttp2/server/chttp2_server.cc', + 'src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc', 'src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc', 'src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc', - 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', - 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', 'src/core/ext/transport/inproc/inproc_plugin.cc', 'src/core/ext/transport/inproc/inproc_transport.cc', 'src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc', @@ -286,9 +322,6 @@ CORE_SOURCE_FILES = [ 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc', 'src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc', 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c', - 'third_party/nanopb/pb_common.c', - 'third_party/nanopb/pb_decode.c', - 'third_party/nanopb/pb_encode.c', 'src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc', 'src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc', 'src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc', diff --git a/templates/CMakeLists.txt.template b/templates/CMakeLists.txt.template index 0f088436d1..ef4d7d710c 100644 --- a/templates/CMakeLists.txt.template +++ b/templates/CMakeLists.txt.template @@ -138,6 +138,8 @@ ## Some libraries are shared even with BUILD_SHARED_LIBRARIES=OFF set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) + + add_definitions(-DPB_FIELD_16BIT) if (MSVC) include(cmake/msvc_static_runtime.cmake) diff --git a/templates/Makefile.template b/templates/Makefile.template index 390847b4f2..196d12f678 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -221,6 +221,8 @@ % endif % endfor + DEFINES += PB_FIELD_16BIT + CPPFLAGS += $(CPPFLAGS_$(CONFIG)) CFLAGS += $(CFLAGS_$(CONFIG)) CXXFLAGS += $(CXXFLAGS_$(CONFIG)) diff --git a/templates/gRPC-Core.podspec.template b/templates/gRPC-Core.podspec.template index c28b78dbdf..3e80d602e1 100644 --- a/templates/gRPC-Core.podspec.template +++ b/templates/gRPC-Core.podspec.template @@ -144,7 +144,7 @@ } s.default_subspecs = 'Interface', 'Implementation' - s.compiler_flags = '-DGRPC_ARES=0' + s.compiler_flags = '-DGRPC_ARES=0', '-DPB_FIELD_16BIT' s.libraries = 'c++' # Like many other C libraries, gRPC-Core has its public headers under `include//` and its diff --git a/templates/grpc.gyp.template b/templates/grpc.gyp.template index 3363082a83..2ea0d06ebd 100644 --- a/templates/grpc.gyp.template +++ b/templates/grpc.gyp.template @@ -60,11 +60,11 @@ % endfor 'cflags_c': [ '-Werror', - '-std=c99' + '-std=c99', ], 'cflags_cc': [ '-Werror', - '-std=c++11' + '-std=c++11', ], 'include_dirs': [ '.', @@ -127,7 +127,7 @@ % endfor '-stdlib=libc++', '-std=c++11', - '-Wno-error=deprecated-declarations' + '-Wno-error=deprecated-declarations', ], % endif }, diff --git a/test/core/security/BUILD b/test/core/security/BUILD index 9776e6d5fd..9db73b9123 100644 --- a/test/core/security/BUILD +++ b/test/core/security/BUILD @@ -161,3 +161,52 @@ grpc_cc_binary( "//test/core/util:grpc_test_util", ], ) + +grpc_cc_test( + name = "check_gcp_environment_linux_test", + srcs = ["check_gcp_environment_linux_test.cc"], + language = "C++", + deps = [ + "//:alts_util", + "//:gpr", + "//:gpr_base", + "//:grpc", + ], +) + +grpc_cc_test( + name = "check_gcp_environment_windows_test", + srcs = ["check_gcp_environment_windows_test.cc"], + language = "C++", + deps = [ + "//:alts_util", + "//:gpr", + "//:gpr_base", + "//:grpc", + ], +) + +grpc_cc_test( + name = "grpc_alts_credentials_options_test", + srcs = ["grpc_alts_credentials_options_test.cc"], + language = "C++", + deps = [ + "//:alts_util", + "//:gpr", + "//:grpc", + ], +) + +grpc_cc_test( + name = "alts_security_connector_test", + srcs = ["alts_security_connector_test.cc"], + language = "C++", + deps = [ + "//:gpr", + "//:grpc", + "//:grpc_base_c", + "//:grpc_secure", + "//:tsi", + "//:tsi_interface", + ], +) diff --git a/test/core/security/alts_security_connector_test.cc b/test/core/security/alts_security_connector_test.cc new file mode 100644 index 0000000000..103a493526 --- /dev/null +++ b/test/core/security/alts_security_connector_test.cc @@ -0,0 +1,166 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include + +#include +#include +#include + +#include "src/core/lib/security/security_connector/alts_security_connector.h" +#include "src/core/lib/transport/transport.h" +#include "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h" +#include "src/core/tsi/transport_security.h" + +using grpc_core::internal::grpc_alts_auth_context_from_tsi_peer; + +/* This file contains unit tests of grpc_alts_auth_context_from_tsi_peer(). */ +static void test_invalid_input_failure() { + tsi_peer peer; + grpc_auth_context* ctx; + GPR_ASSERT(grpc_alts_auth_context_from_tsi_peer(nullptr, &ctx) == + GRPC_SECURITY_ERROR); + GPR_ASSERT(grpc_alts_auth_context_from_tsi_peer(&peer, nullptr) == + GRPC_SECURITY_ERROR); +} + +static void test_empty_certificate_type_failure() { + tsi_peer peer; + grpc_auth_context* ctx = nullptr; + GPR_ASSERT(tsi_construct_peer(0, &peer) == TSI_OK); + GPR_ASSERT(grpc_alts_auth_context_from_tsi_peer(&peer, &ctx) == + GRPC_SECURITY_ERROR); + GPR_ASSERT(ctx == nullptr); + tsi_peer_destruct(&peer); +} + +static void test_empty_peer_property_failure() { + tsi_peer peer; + grpc_auth_context* ctx; + GPR_ASSERT(tsi_construct_peer(1, &peer) == TSI_OK); + GPR_ASSERT(tsi_construct_string_peer_property_from_cstring( + TSI_CERTIFICATE_TYPE_PEER_PROPERTY, TSI_ALTS_CERTIFICATE_TYPE, + &peer.properties[0]) == TSI_OK); + GPR_ASSERT(grpc_alts_auth_context_from_tsi_peer(&peer, &ctx) == + GRPC_SECURITY_ERROR); + GPR_ASSERT(ctx == nullptr); + tsi_peer_destruct(&peer); +} + +static void test_missing_rpc_protocol_versions_property_failure() { + tsi_peer peer; + grpc_auth_context* ctx; + GPR_ASSERT(tsi_construct_peer(kTsiAltsNumOfPeerProperties, &peer) == TSI_OK); + GPR_ASSERT(tsi_construct_string_peer_property_from_cstring( + TSI_CERTIFICATE_TYPE_PEER_PROPERTY, TSI_ALTS_CERTIFICATE_TYPE, + &peer.properties[0]) == TSI_OK); + GPR_ASSERT(tsi_construct_string_peer_property_from_cstring( + TSI_ALTS_SERVICE_ACCOUNT_PEER_PROPERTY, "alice", + &peer.properties[1]) == TSI_OK); + GPR_ASSERT(grpc_alts_auth_context_from_tsi_peer(&peer, &ctx) == + GRPC_SECURITY_ERROR); + GPR_ASSERT(ctx == nullptr); + tsi_peer_destruct(&peer); +} + +static void test_unknown_peer_property_failure() { + tsi_peer peer; + grpc_auth_context* ctx; + GPR_ASSERT(tsi_construct_peer(kTsiAltsNumOfPeerProperties, &peer) == TSI_OK); + GPR_ASSERT(tsi_construct_string_peer_property_from_cstring( + TSI_CERTIFICATE_TYPE_PEER_PROPERTY, TSI_ALTS_CERTIFICATE_TYPE, + &peer.properties[0]) == TSI_OK); + GPR_ASSERT(tsi_construct_string_peer_property_from_cstring( + "unknown", "alice", &peer.properties[1]) == TSI_OK); + GPR_ASSERT(grpc_alts_auth_context_from_tsi_peer(&peer, &ctx) == + GRPC_SECURITY_ERROR); + GPR_ASSERT(ctx == nullptr); + tsi_peer_destruct(&peer); +} + +static bool test_identity(const grpc_auth_context* ctx, + const char* expected_property_name, + const char* expected_identity) { + grpc_auth_property_iterator it; + const grpc_auth_property* prop; + GPR_ASSERT(grpc_auth_context_peer_is_authenticated(ctx)); + it = grpc_auth_context_peer_identity(ctx); + prop = grpc_auth_property_iterator_next(&it); + GPR_ASSERT(prop != nullptr); + 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 false; + } + if (strncmp(prop->value, expected_identity, prop->value_length) != 0) { + gpr_log(GPR_ERROR, "Expected peer identity %s and got got %s.", + expected_identity, prop->value); + return false; + } + return true; +} + +static void test_alts_peer_to_auth_context_success() { + tsi_peer peer; + grpc_auth_context* ctx; + GPR_ASSERT(tsi_construct_peer(kTsiAltsNumOfPeerProperties, &peer) == TSI_OK); + GPR_ASSERT(tsi_construct_string_peer_property_from_cstring( + TSI_CERTIFICATE_TYPE_PEER_PROPERTY, TSI_ALTS_CERTIFICATE_TYPE, + &peer.properties[0]) == TSI_OK); + GPR_ASSERT(tsi_construct_string_peer_property_from_cstring( + TSI_ALTS_SERVICE_ACCOUNT_PEER_PROPERTY, "alice", + &peer.properties[1]) == TSI_OK); + grpc_gcp_rpc_protocol_versions peer_versions; + grpc_gcp_rpc_protocol_versions_set_max(&peer_versions, + GRPC_PROTOCOL_VERSION_MAX_MAJOR, + GRPC_PROTOCOL_VERSION_MAX_MINOR); + grpc_gcp_rpc_protocol_versions_set_min(&peer_versions, + GRPC_PROTOCOL_VERSION_MIN_MAJOR, + GRPC_PROTOCOL_VERSION_MIN_MINOR); + grpc_slice serialized_peer_versions; + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_encode(&peer_versions, + &serialized_peer_versions)); + + GPR_ASSERT(tsi_construct_string_peer_property( + TSI_ALTS_RPC_VERSIONS, + reinterpret_cast( + GRPC_SLICE_START_PTR(serialized_peer_versions)), + GRPC_SLICE_LENGTH(serialized_peer_versions), + &peer.properties[2]) == TSI_OK); + GPR_ASSERT(grpc_alts_auth_context_from_tsi_peer(&peer, &ctx) == + GRPC_SECURITY_OK); + GPR_ASSERT( + test_identity(ctx, TSI_ALTS_SERVICE_ACCOUNT_PEER_PROPERTY, "alice")); + GRPC_AUTH_CONTEXT_UNREF(ctx, "test"); + grpc_slice_unref(serialized_peer_versions); + tsi_peer_destruct(&peer); +} + +int main(int argc, char** argv) { + /* Test. */ + test_invalid_input_failure(); + test_empty_certificate_type_failure(); + test_empty_peer_property_failure(); + test_unknown_peer_property_failure(); + test_missing_rpc_protocol_versions_property_failure(); + test_alts_peer_to_auth_context_success(); + + return 0; +} diff --git a/test/core/security/check_gcp_environment_linux_test.cc b/test/core/security/check_gcp_environment_linux_test.cc new file mode 100644 index 0000000000..6c436a3945 --- /dev/null +++ b/test/core/security/check_gcp_environment_linux_test.cc @@ -0,0 +1,83 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "src/core/lib/security/credentials/alts/check_gcp_environment.h" + +#if GPR_LINUX + +#include +#include + +#include +#include + +#include "src/core/lib/gpr/tmpfile.h" + +static bool check_bios_data_linux_test(const char* data) { + /* Create a file with contents data. */ + char* filename = nullptr; + FILE* fp = gpr_tmpfile("check_gcp_environment_test", &filename); + GPR_ASSERT(filename != nullptr); + GPR_ASSERT(fp != nullptr); + GPR_ASSERT(fwrite(data, 1, strlen(data), fp) == strlen(data)); + fclose(fp); + bool result = grpc_core::internal::check_bios_data( + reinterpret_cast(filename)); + /* Cleanup. */ + remove(filename); + gpr_free(filename); + return result; +} + +static void test_gcp_environment_check_success() { + /* Exact match. */ + GPR_ASSERT(check_bios_data_linux_test("Google")); + GPR_ASSERT(check_bios_data_linux_test("Google Compute Engine")); + /* With leading and trailing whitespaces. */ + GPR_ASSERT(check_bios_data_linux_test(" Google ")); + GPR_ASSERT(check_bios_data_linux_test("Google ")); + GPR_ASSERT(check_bios_data_linux_test(" Google")); + GPR_ASSERT(check_bios_data_linux_test(" Google Compute Engine ")); + GPR_ASSERT(check_bios_data_linux_test("Google Compute Engine ")); + GPR_ASSERT(check_bios_data_linux_test(" Google Compute Engine")); + /* With leading and trailing \t and \n. */ + GPR_ASSERT(check_bios_data_linux_test("\t\tGoogle Compute Engine\t")); + GPR_ASSERT(check_bios_data_linux_test("Google Compute Engine\n")); + GPR_ASSERT(check_bios_data_linux_test("\n\n\tGoogle Compute Engine \n\t\t")); +} + +static void test_gcp_environment_check_failure() { + GPR_ASSERT(!check_bios_data_linux_test("non_existing-file")); + GPR_ASSERT(!check_bios_data_linux_test("Google-Chrome")); + GPR_ASSERT(!check_bios_data_linux_test("Amazon")); + GPR_ASSERT(!check_bios_data_linux_test("Google-Chrome\t\t")); + GPR_ASSERT(!check_bios_data_linux_test("Amazon")); +} + +int main(int argc, char** argv) { + /* Tests. */ + test_gcp_environment_check_success(); + test_gcp_environment_check_failure(); + return 0; +} + +#else // GPR_LINUX + +int main(int argc, char** argv) { return 0; } + +#endif // GPR_LINUX diff --git a/test/core/security/check_gcp_environment_windows_test.cc b/test/core/security/check_gcp_environment_windows_test.cc new file mode 100644 index 0000000000..46179b747d --- /dev/null +++ b/test/core/security/check_gcp_environment_windows_test.cc @@ -0,0 +1,71 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "src/core/lib/security/credentials/alts/check_gcp_environment.h" + +#ifdef GPR_WINDOWS + +#include +#include + +#include +#include +#include "src/core/lib/gpr/tmpfile.h" + +static bool check_bios_data_windows_test(const char* data) { + /* Create a file with contents data. */ + char* filename = nullptr; + FILE* fp = gpr_tmpfile("check_gcp_environment_test", &filename); + GPR_ASSERT(filename != nullptr); + GPR_ASSERT(fp != nullptr); + GPR_ASSERT(fwrite(data, 1, strlen(data), fp) == strlen(data)); + fclose(fp); + bool result = grpc_core::internal::check_bios_data( + reinterpret_cast(filename)); + /* Cleanup. */ + remove(filename); + gpr_free(filename); + return result; +} + +static void test_gcp_environment_check_success() { + GPR_ASSERT(check_bios_data_windows_test("Google")); + GPR_ASSERT(check_bios_data_windows_test("Google\n")); + GPR_ASSERT(check_bios_data_windows_test("Google\r")); + GPR_ASSERT(check_bios_data_windows_test("Google\r\n")); + GPR_ASSERT(check_bios_data_windows_test(" Google \r\n")); + GPR_ASSERT(check_bios_data_windows_test(" \t\t Google\r\n")); + GPR_ASSERT(check_bios_data_windows_test(" \t\t Google\t\t \r\n")); +} + +static void test_gcp_environment_check_failure() { + GPR_ASSERT(!check_bios_data_windows_test("\t\tAmazon\n")); + GPR_ASSERT(!check_bios_data_windows_test(" Amazon\r\n")); +} + +int main(int argc, char** argv) { + /* Tests. */ + test_gcp_environment_check_success(); + test_gcp_environment_check_failure(); + return 0; +} +#else // GPR_WINDOWS + +int main(int argc, char** argv) { return 0; } + +#endif // GPR_WINDOWS diff --git a/test/core/security/grpc_alts_credentials_options_test.cc b/test/core/security/grpc_alts_credentials_options_test.cc new file mode 100644 index 0000000000..1217065507 --- /dev/null +++ b/test/core/security/grpc_alts_credentials_options_test.cc @@ -0,0 +1,118 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include + +#include +#include + +#include "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h" + +#define ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_1 "abc@google.com" +#define ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_2 "def@google.com" + +const size_t kTargetServiceAccountNum = 2; + +static void test_add_target_service_account_failure() { + /* Initialization. */ + grpc_alts_credentials_options* options = + grpc_alts_credentials_client_options_create(); + auto client_options = + reinterpret_cast(options); + + /* Test. */ + GPR_ASSERT(!grpc_alts_credentials_client_options_add_target_service_account( + client_options, nullptr)); + GPR_ASSERT(!grpc_alts_credentials_client_options_add_target_service_account( + nullptr, ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_1)); + + /* Cleanup. */ + grpc_alts_credentials_options_destroy(options); +} + +static void test_copy_client_options_failure() { + /* Initialization. */ + grpc_alts_credentials_options* options = + grpc_alts_credentials_client_options_create(); + + /* Test. */ + GPR_ASSERT(grpc_alts_credentials_options_copy(nullptr) == nullptr); + + /* Cleanup. */ + grpc_alts_credentials_options_destroy(options); +} + +static size_t get_target_service_account_num( + grpc_alts_credentials_client_options* options) { + size_t num = 0; + target_service_account* node = options->target_account_list_head; + while (node != nullptr) { + num++; + node = node->next; + } + return num; +} + +static void test_client_options_api_success() { + /* Initialization. */ + grpc_alts_credentials_options* options = + grpc_alts_credentials_client_options_create(); + auto client_options = + reinterpret_cast(options); + + /* Set client options fields. */ + grpc_alts_credentials_client_options_add_target_service_account( + client_options, ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_1); + grpc_alts_credentials_client_options_add_target_service_account( + client_options, ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_2); + + /* Validate client option fields. */ + GPR_ASSERT(get_target_service_account_num(client_options) == + kTargetServiceAccountNum); + GPR_ASSERT(strcmp(client_options->target_account_list_head->data, + ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_2) == 0); + GPR_ASSERT(strcmp(client_options->target_account_list_head->next->data, + ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_1) == 0); + + /* Perform a copy operation and validate its correctness. */ + grpc_alts_credentials_options* new_options = + grpc_alts_credentials_options_copy(options); + auto new_client_options = + reinterpret_cast(new_options); + + GPR_ASSERT(get_target_service_account_num(new_client_options) == + kTargetServiceAccountNum); + GPR_ASSERT(strcmp(new_client_options->target_account_list_head->data, + ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_2) == 0); + GPR_ASSERT(strcmp(new_client_options->target_account_list_head->next->data, + ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_1) == 0); + + /* Cleanup.*/ + grpc_alts_credentials_options_destroy(options); + grpc_alts_credentials_options_destroy(new_options); +} + +int main(int argc, char** argv) { + /* Test. */ + test_add_target_service_account_failure(); + test_copy_client_options_failure(); + test_client_options_api_success(); + return 0; +} diff --git a/test/core/tsi/BUILD b/test/core/tsi/BUILD index e28c0b5f84..8ac3e7687c 100644 --- a/test/core/tsi/BUILD +++ b/test/core/tsi/BUILD @@ -16,7 +16,7 @@ load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_c licenses(["notice"]) # Apache v2 -grpc_package(name = "test/core/tsi") +grpc_package(name = "test/core/tsi", visibility = "public") grpc_cc_library( name = "transport_security_test_lib", diff --git a/test/core/tsi/alts/crypt/BUILD b/test/core/tsi/alts/crypt/BUILD new file mode 100644 index 0000000000..b2fcb65adb --- /dev/null +++ b/test/core/tsi/alts/crypt/BUILD @@ -0,0 +1,42 @@ +# Copyright 2018 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_package") + +licenses(["notice"]) # Apache v2 + +grpc_package(name = "crypt", visibility = "public") + +grpc_cc_test( + name = "alts_crypt_test", + srcs = ["aes_gcm_test.cc"], + language = "C++", + deps = [ + ":alts_crypt_test_util", + "//:alts_frame_protector", + "//:gpr", + "//:grpc", + ], +) + +grpc_cc_library( + name = "alts_crypt_test_util", + srcs = ["gsec_test_util.cc"], + hdrs = ["gsec_test_util.h"], + deps = [ + "//:gpr", + "//:grpc", + ], +) + diff --git a/test/core/tsi/alts/crypt/aes_gcm_test.cc b/test/core/tsi/alts/crypt/aes_gcm_test.cc new file mode 100644 index 0000000000..576dd8f27b --- /dev/null +++ b/test/core/tsi/alts/crypt/aes_gcm_test.cc @@ -0,0 +1,2105 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "src/core/tsi/alts/crypt/gsec.h" +#include "test/core/tsi/alts/crypt/gsec_test_util.h" + +#include +#include + +const size_t kTestMinTagLengthForCorruption = 8; +const size_t kTestNumCrypters = 3; +const size_t kTestMaxSlices = 5; +const size_t kTestMaxLength = 1024; +const size_t kTestNumEncryptions = 100; + +/* Struct for pre-generated test vector */ +typedef struct gsec_aead_test_vector { + uint8_t* nonce; + uint8_t* aad; + uint8_t* key; + uint8_t* plaintext; + uint8_t* ciphertext_and_tag; + size_t nonce_length; + size_t aad_length; + size_t key_length; + size_t plaintext_length; + size_t ciphertext_and_tag_length; +} gsec_aead_test_vector; + +static void gsec_randomly_slice(uint8_t* input, size_t input_length, + struct iovec** output, size_t* output_length) { + if (input_length == 0) { + *output = nullptr; + *output_length = 0; + return; + } + *output_length = gsec_test_bias_random_uint32(kTestMaxSlices) + 1; + *output = + static_cast(malloc(*output_length * sizeof(**output))); + size_t i; + for (i = 0; i < *output_length - 1; i++) { + size_t slice_length = + gsec_test_bias_random_uint32(static_cast(input_length)); + struct iovec slice = {input, slice_length}; + (*output)[i] = slice; + input += slice_length; + input_length -= slice_length; + } + struct iovec slice = {input, input_length}; + (*output)[*output_length - 1] = slice; +} + +static void gsec_assert_ok(grpc_status_code status, const char* error_detail) { + char empty_string[] = ""; + if (error_detail == nullptr) { + error_detail = empty_string; + } + if (status != GRPC_STATUS_OK) { + fprintf(stderr, "Status is not ok: %s\n", error_detail); + } + GPR_ASSERT(status == GRPC_STATUS_OK); +} + +static void gsec_test_random_encrypt_decrypt(gsec_aead_crypter* crypter, + size_t aad_length, + size_t message_length) { + GPR_ASSERT(crypter != nullptr); + size_t nonce_length, tag_length; + uint8_t *nonce, *aad, *message; + gsec_aead_crypter_nonce_length(crypter, &nonce_length, nullptr); + gsec_aead_crypter_tag_length(crypter, &tag_length, nullptr); + + gsec_test_random_array(&nonce, nonce_length); + gsec_test_random_array(&aad, aad_length); + gsec_test_random_array(&message, message_length); + + /* Test encryption */ + size_t ciphertext_and_tag_length, ciphertext_bytes_written = 0; + gsec_aead_crypter_max_ciphertext_and_tag_length( + crypter, message_length, &ciphertext_and_tag_length, nullptr); + + uint8_t* ciphertext_and_tag = + static_cast(gpr_malloc(ciphertext_and_tag_length)); + + char* error_buffer = nullptr; + gsec_assert_ok( + gsec_aead_crypter_encrypt(crypter, nonce, nonce_length, aad, aad_length, + message, message_length, ciphertext_and_tag, + ciphertext_and_tag_length, + &ciphertext_bytes_written, &error_buffer), + error_buffer); + GPR_ASSERT(message_length + tag_length == ciphertext_and_tag_length); + GPR_ASSERT(ciphertext_bytes_written == ciphertext_and_tag_length); + + /* Test decryption */ + size_t plaintext_length, plaintext_bytes_written = 0; + gsec_aead_crypter_max_plaintext_length(crypter, ciphertext_bytes_written, + &plaintext_length, nullptr); + uint8_t* plaintext = static_cast(gpr_malloc(plaintext_length)); + grpc_status_code status = gsec_aead_crypter_decrypt( + crypter, nonce, nonce_length, aad, aad_length, ciphertext_and_tag, + ciphertext_bytes_written, plaintext, plaintext_length, + &plaintext_bytes_written, nullptr); + + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(message_length == plaintext_bytes_written); + GPR_ASSERT(memcmp(message, plaintext, message_length) == 0); + + /** + * The returned plaintext will be zeroed if there was an authentication error. + */ + uint8_t* zero_message = static_cast(gpr_zalloc(plaintext_length)); + if (tag_length >= kTestMinTagLengthForCorruption) { + char* error_message; + /* Corrupt nonce */ + if (nonce_length > 0) { + plaintext_bytes_written = 0; + uint8_t* corrupt_nonce; + gsec_test_copy_and_alter_random_byte(nonce, &corrupt_nonce, nonce_length); + status = gsec_aead_crypter_decrypt( + crypter, corrupt_nonce, nonce_length, aad, aad_length, + ciphertext_and_tag, ciphertext_bytes_written, plaintext, + plaintext_length, &plaintext_bytes_written, &error_message); + + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_FAILED_PRECONDITION, "Checking tag failed.", + error_message)); + GPR_ASSERT(plaintext_bytes_written == 0); + GPR_ASSERT(memcmp(zero_message, plaintext, plaintext_length) == 0); + gpr_free(corrupt_nonce); + gpr_free(error_message); + } + + /* Corrupt ciphertext_and_tag */ + plaintext_bytes_written = 0; + uint8_t* corrupt_ciphertext_and_tag; + gsec_test_copy_and_alter_random_byte(ciphertext_and_tag, + &corrupt_ciphertext_and_tag, + ciphertext_and_tag_length); + status = gsec_aead_crypter_decrypt( + crypter, nonce, nonce_length, aad, aad_length, + corrupt_ciphertext_and_tag, ciphertext_bytes_written, plaintext, + plaintext_length, &plaintext_bytes_written, &error_message); + + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_FAILED_PRECONDITION, error_message, + "Checking tag failed")); + GPR_ASSERT(plaintext_bytes_written == 0); + GPR_ASSERT(memcmp(zero_message, plaintext, plaintext_length) == 0); + gpr_free(error_message); + gpr_free(corrupt_ciphertext_and_tag); + + /* Corrupt start of ciphertext_and_tag */ + plaintext_bytes_written = 0; + gsec_test_copy(ciphertext_and_tag, &corrupt_ciphertext_and_tag, + ciphertext_and_tag_length); + (*corrupt_ciphertext_and_tag)++; + status = gsec_aead_crypter_decrypt( + crypter, nonce, nonce_length, aad, aad_length, + corrupt_ciphertext_and_tag, ciphertext_bytes_written, plaintext, + plaintext_length, &plaintext_bytes_written, &error_message); + GPR_ASSERT(plaintext_bytes_written == 0); + GPR_ASSERT(memcmp(zero_message, plaintext, plaintext_length) == 0); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_FAILED_PRECONDITION, error_message, + "Checking tag failed")); + gpr_free(error_message); + gpr_free(corrupt_ciphertext_and_tag); + + /* Corrupt end of ciphertext_and_tag */ + plaintext_bytes_written = 0; + gsec_test_copy(ciphertext_and_tag, &corrupt_ciphertext_and_tag, + ciphertext_and_tag_length); + (*(corrupt_ciphertext_and_tag + ciphertext_and_tag_length - 1))++; + + status = gsec_aead_crypter_decrypt( + crypter, nonce, nonce_length, aad, aad_length, + corrupt_ciphertext_and_tag, ciphertext_bytes_written, plaintext, + plaintext_length, &plaintext_bytes_written, &error_message); + + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_FAILED_PRECONDITION, error_message, + "Checking tag failed")); + GPR_ASSERT(plaintext_bytes_written == 0); + GPR_ASSERT(memcmp(zero_message, plaintext, plaintext_length) == 0); + gpr_free(error_message); + gpr_free(corrupt_ciphertext_and_tag); + } + + gpr_free(zero_message); + gpr_free(nonce); + gpr_free(aad); + gpr_free(message); + gpr_free(plaintext); + gpr_free(ciphertext_and_tag); +} + +static void gsec_test_encrypt_decrypt(gsec_aead_crypter* crypter) { + GPR_ASSERT(crypter != nullptr); + size_t aad_length, message_length; + aad_length = gsec_test_bias_random_uint32(kTestMaxLength); + message_length = gsec_test_bias_random_uint32(kTestMaxLength); + gsec_test_random_encrypt_decrypt(crypter, aad_length, message_length); + gsec_test_random_encrypt_decrypt(crypter, 0, message_length); + gsec_test_random_encrypt_decrypt(crypter, aad_length, 0); +} + +static void gsec_test_multiple_random_encrypt_decrypt( + gsec_aead_crypter* crypter, size_t* aad_lengths, size_t* message_lengths, + size_t count) { + GPR_ASSERT(crypter != nullptr); + size_t nonce_length, tag_length; + uint8_t **nonces, **aads, **messages; + nonces = static_cast(gpr_malloc(sizeof(uint8_t*) * count)); + aads = static_cast(gpr_malloc(sizeof(uint8_t*) * count)); + messages = static_cast(gpr_malloc(sizeof(uint8_t*) * count)); + + gsec_aead_crypter_nonce_length(crypter, &nonce_length, nullptr); + gsec_aead_crypter_tag_length(crypter, &tag_length, nullptr); + + size_t ind; + for (ind = 0; ind < count; ind++) { + size_t aad_length = (aad_lengths == nullptr) ? 0 : aad_lengths[ind]; + size_t message_length = + (message_lengths == nullptr) ? 0 : message_lengths[ind]; + gsec_test_random_array(&(nonces[ind]), nonce_length); + gsec_test_random_array(&(aads[ind]), aad_length); + gsec_test_random_array(&(messages[ind]), message_length); + } + + size_t* ciphertext_and_tag_lengths = + static_cast(gpr_malloc(sizeof(size_t) * count)); + size_t* ciphertext_bytes_writtens = + static_cast(gpr_malloc(sizeof(size_t) * count)); + size_t* plaintext_lengths = + static_cast(gpr_malloc(sizeof(size_t) * count)); + size_t* plaintext_bytes_writtens = + static_cast(gpr_malloc(sizeof(size_t) * count)); + uint8_t** ciphertext_and_tags = + static_cast(gpr_malloc(sizeof(uint8_t*) * count)); + uint8_t** plaintexts = + static_cast(gpr_malloc(sizeof(uint8_t*) * count)); + + /* Do encryption */ + for (ind = 0; ind < count; ind++) { + size_t aad_length = (aad_lengths == nullptr) ? 0 : aad_lengths[ind]; + size_t message_length = + (message_lengths == nullptr) ? 0 : message_lengths[ind]; + gsec_aead_crypter_max_ciphertext_and_tag_length( + crypter, message_length, &(ciphertext_and_tag_lengths[ind]), nullptr); + ciphertext_and_tags[ind] = + static_cast(gpr_malloc(ciphertext_and_tag_lengths[ind])); + grpc_status_code status = gsec_aead_crypter_encrypt( + crypter, nonces[ind], nonce_length, aads[ind], aad_length, + messages[ind], message_length, ciphertext_and_tags[ind], + ciphertext_and_tag_lengths[ind], &(ciphertext_bytes_writtens[ind]), + nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(message_length + tag_length == ciphertext_and_tag_lengths[ind]); + GPR_ASSERT(ciphertext_bytes_writtens[ind] == + ciphertext_and_tag_lengths[ind]); + } + /* Do Decryption */ + for (ind = 0; ind < count; ind++) { + size_t aad_length = (aad_lengths == nullptr) ? 0 : aad_lengths[ind]; + size_t message_length = + (message_lengths == nullptr) ? 0 : message_lengths[ind]; + gsec_aead_crypter_max_plaintext_length(crypter, + ciphertext_bytes_writtens[ind], + &(plaintext_lengths[ind]), nullptr); + plaintexts[ind] = static_cast(gpr_malloc(plaintext_lengths[ind])); + grpc_status_code status = gsec_aead_crypter_decrypt( + crypter, nonces[ind], nonce_length, aads[ind], aad_length, + ciphertext_and_tags[ind], ciphertext_bytes_writtens[ind], + plaintexts[ind], plaintext_lengths[ind], + &(plaintext_bytes_writtens[ind]), nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(message_length == plaintext_bytes_writtens[ind]); + GPR_ASSERT(memcmp(messages[ind], plaintexts[ind], message_length) == 0); + } + + /* Slice the plaintext and encrypt with iovecs */ + for (ind = 0; ind < count; ind++) { + size_t aad_length = (aad_lengths == nullptr) ? 0 : aad_lengths[ind]; + struct iovec* aad_vecs = nullptr; + size_t aad_vecs_length = 0; + gsec_randomly_slice(aads[ind], aad_length, &aad_vecs, &aad_vecs_length); + size_t message_length = + (message_lengths == nullptr) ? 0 : message_lengths[ind]; + struct iovec* message_vecs = nullptr; + size_t message_vecs_length = 0; + gsec_randomly_slice(messages[ind], message_length, &message_vecs, + &message_vecs_length); + + size_t ciphertext_length = ciphertext_and_tag_lengths[ind]; + uint8_t* another_ciphertext = + static_cast(malloc(ciphertext_length)); + struct iovec another_ciphertext_vec = {another_ciphertext, + ciphertext_length}; + + char* error_details = nullptr; + size_t ciphertext_bytes_written = 0; + gsec_assert_ok( + gsec_aead_crypter_encrypt_iovec( + crypter, nonces[ind], nonce_length, aad_vecs, aad_vecs_length, + message_vecs, message_vecs_length, another_ciphertext_vec, + &ciphertext_bytes_written, &error_details), + error_details); + GPR_ASSERT(memcmp(ciphertext_and_tags[ind], another_ciphertext_vec.iov_base, + ciphertext_length) == 0); + free(another_ciphertext); + free(aad_vecs); + free(message_vecs); + } + + /* Slice the ciphertext and decrypt with iovecs */ + for (ind = 0; ind < count; ind++) { + size_t message_length = + (message_lengths == nullptr) ? 0 : message_lengths[ind]; + message_length = message_length + 0; + + size_t aad_length = (aad_lengths == nullptr) ? 0 : aad_lengths[ind]; + + struct iovec* aad_vecs = nullptr; + size_t aad_vecs_length = 0; + gsec_randomly_slice(aads[ind], aad_length, &aad_vecs, &aad_vecs_length); + + struct iovec* ciphertext_vecs = nullptr; + size_t ciphertext_vecs_length = 0; + gsec_randomly_slice(ciphertext_and_tags[ind], + ciphertext_bytes_writtens[ind], &ciphertext_vecs, + &ciphertext_vecs_length); + + size_t decrypted_length = plaintext_lengths[ind]; + uint8_t* decrypted = static_cast(malloc(decrypted_length)); + struct iovec decrypted_vec = {decrypted, decrypted_length}; + + char* error_details = nullptr; + gsec_assert_ok(gsec_aead_crypter_decrypt_iovec( + crypter, nonces[ind], nonce_length, aad_vecs, + aad_vecs_length, ciphertext_vecs, ciphertext_vecs_length, + decrypted_vec, &decrypted_length, &error_details), + error_details); + GPR_ASSERT(decrypted_vec.iov_len == message_length); + GPR_ASSERT(memcmp(decrypted_vec.iov_base, messages[ind], message_length) == + 0); + free(decrypted); + free(aad_vecs); + free(ciphertext_vecs); + } + + for (ind = 0; ind < count; ind++) { + gpr_free(nonces[ind]); + gpr_free(aads[ind]); + gpr_free(messages[ind]); + gpr_free(ciphertext_and_tags[ind]); + gpr_free(plaintexts[ind]); + } + gpr_free(nonces); + gpr_free(aads); + gpr_free(messages); + gpr_free(ciphertext_and_tag_lengths); + gpr_free(ciphertext_bytes_writtens); + gpr_free(plaintext_lengths); + gpr_free(plaintext_bytes_writtens); + gpr_free(ciphertext_and_tags); + gpr_free(plaintexts); +} + +static void gsec_test_multiple_encrypt_decrypt(gsec_aead_crypter* crypter) { + GPR_ASSERT(crypter != nullptr); + size_t count = kTestNumEncryptions; + size_t* aad_lengths = + static_cast(gpr_malloc(sizeof(size_t) * count)); + size_t* message_lengths = + static_cast(gpr_malloc(sizeof(size_t) * count)); + size_t ind; + for (ind = 0; ind < count; ind++) { + aad_lengths[ind] = gsec_test_bias_random_uint32(kTestMaxLength); + message_lengths[ind] = gsec_test_bias_random_uint32(kTestMaxLength); + } + gsec_test_multiple_random_encrypt_decrypt(crypter, aad_lengths, + message_lengths, count); + gsec_test_multiple_random_encrypt_decrypt(crypter, aad_lengths, nullptr, + count); + gsec_test_multiple_random_encrypt_decrypt(crypter, nullptr, message_lengths, + count); + gpr_free(aad_lengths); + gpr_free(message_lengths); +} + +static void gsec_test_encryption_failure(gsec_aead_crypter* crypter) { + GPR_ASSERT(crypter != nullptr); + size_t aad_length = kTestMaxLength; + size_t message_length = kTestMaxLength; + size_t nonce_length; + + char* error_message; + uint8_t *nonce, *aad, *message; + + gsec_aead_crypter_nonce_length(crypter, &nonce_length, nullptr); + gsec_test_random_array(&nonce, nonce_length); + gsec_test_random_array(&aad, aad_length); + gsec_test_random_array(&message, message_length); + + size_t ciphertext_and_tag_length, ciphertext_bytes_written = 0; + gsec_aead_crypter_max_ciphertext_and_tag_length( + crypter, message_length, &ciphertext_and_tag_length, nullptr); + uint8_t* ciphertext_and_tag = + static_cast(gpr_malloc(ciphertext_and_tag_length)); + + /* nullptr nonce */ + grpc_status_code status = gsec_aead_crypter_encrypt( + crypter, nullptr, nonce_length, aad, aad_length, message, message_length, + ciphertext_and_tag, ciphertext_and_tag_length, &ciphertext_bytes_written, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "Nonce buffer is nullptr.")); + gpr_free(error_message); + + /* Big nonce */ + status = gsec_aead_crypter_encrypt( + crypter, nonce, nonce_length + 1, aad, aad_length, message, + message_length, ciphertext_and_tag, ciphertext_and_tag_length, + &ciphertext_bytes_written, &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "Nonce buffer has the wrong length.")); + gpr_free(error_message); + + /* Small nonce */ + status = gsec_aead_crypter_encrypt( + crypter, nonce, nonce_length - 1, aad, aad_length, message, + message_length, ciphertext_and_tag, ciphertext_and_tag_length, + &ciphertext_bytes_written, &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "Nonce buffer has the wrong length.")); + gpr_free(error_message); + + /* nullptr aad */ + status = gsec_aead_crypter_encrypt( + crypter, nonce, nonce_length, nullptr, aad_length, message, + message_length, ciphertext_and_tag, ciphertext_and_tag_length, + &ciphertext_bytes_written, &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, "aad is nullptr.")); + gpr_free(error_message); + + /* nullptr aad with zero length */ + gsec_assert_ok( + gsec_aead_crypter_encrypt(crypter, nonce, nonce_length, nullptr, 0, + message, message_length, ciphertext_and_tag, + ciphertext_and_tag_length, + &ciphertext_bytes_written, &error_message), + error_message); + + /* nullptr plaintext */ + status = gsec_aead_crypter_encrypt( + crypter, nonce, nonce_length, aad, aad_length, nullptr, message_length, + ciphertext_and_tag, ciphertext_and_tag_length, &ciphertext_bytes_written, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "plaintext is nullptr.")); + gpr_free(error_message); + + /* nullptr ciphertext */ + status = gsec_aead_crypter_encrypt(crypter, nonce, nonce_length, aad, + aad_length, message, message_length, + nullptr, ciphertext_and_tag_length, + &ciphertext_bytes_written, &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "ciphertext is nullptr.")); + gpr_free(error_message); + + /* Short ciphertext */ + status = gsec_aead_crypter_encrypt( + crypter, nonce, nonce_length, aad, aad_length, message, message_length, + ciphertext_and_tag, ciphertext_and_tag_length - 1, + &ciphertext_bytes_written, &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "ciphertext is too small to hold a tag.")); + gpr_free(error_message); + + /* nullptr ciphertext_bytes_written */ + status = gsec_aead_crypter_encrypt( + crypter, nonce, nonce_length, aad, aad_length, message, message_length, + ciphertext_and_tag, ciphertext_and_tag_length, nullptr, &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "bytes_written is nullptr.")); + gpr_free(error_message); + + /* nullptr plaintext/ciphertext encrypt with zero length */ + gsec_assert_ok(gsec_aead_crypter_encrypt( + crypter, nonce, nonce_length, aad, aad_length, nullptr, 0, + ciphertext_and_tag, ciphertext_and_tag_length, + &ciphertext_bytes_written, &error_message), + error_message); + + /* Success */ + status = gsec_aead_crypter_encrypt( + crypter, nonce, nonce_length, aad, aad_length, message, message_length, + ciphertext_and_tag, ciphertext_and_tag_length, &ciphertext_bytes_written, + &error_message); + GPR_ASSERT(status == GRPC_STATUS_OK); + + gpr_free(message); + gpr_free(aad); + gpr_free(nonce); + gpr_free(ciphertext_and_tag); +} + +static void gsec_test_decryption_failure(gsec_aead_crypter* crypter) { + GPR_ASSERT(crypter != nullptr); + size_t aad_length = kTestMaxLength; + size_t message_length = kTestMaxLength; + size_t nonce_length, tag_length; + uint8_t *nonce, *aad, *message; + + gsec_aead_crypter_nonce_length(crypter, &nonce_length, nullptr); + gsec_aead_crypter_tag_length(crypter, &tag_length, nullptr); + gsec_test_random_array(&nonce, nonce_length); + gsec_test_random_array(&aad, aad_length); + gsec_test_random_array(&message, message_length); + + /* Test encryption */ + size_t ciphertext_and_tag_length, ciphertext_bytes_written = 0; + gsec_aead_crypter_max_ciphertext_and_tag_length( + crypter, message_length, &ciphertext_and_tag_length, nullptr); + uint8_t* ciphertext_and_tag = + static_cast(gpr_malloc(ciphertext_and_tag_length)); + + grpc_status_code status = gsec_aead_crypter_encrypt( + crypter, nonce, nonce_length, aad, aad_length, message, message_length, + ciphertext_and_tag, ciphertext_and_tag_length, &ciphertext_bytes_written, + nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(ciphertext_bytes_written == ciphertext_and_tag_length); + + size_t plaintext_length, plaintext_bytes_written = 0; + gsec_aead_crypter_max_plaintext_length(crypter, ciphertext_bytes_written, + &plaintext_length, nullptr); + uint8_t* plaintext = static_cast(gpr_malloc(plaintext_length)); + + char* error_message; + /* nullptr nonce */ + status = gsec_aead_crypter_decrypt( + crypter, nullptr, nonce_length, aad, aad_length, ciphertext_and_tag, + ciphertext_and_tag_length, plaintext, plaintext_length, + &plaintext_bytes_written, &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "Nonce buffer is nullptr.")); + gpr_free(error_message); + + /* Big nonce */ + status = gsec_aead_crypter_decrypt( + crypter, nonce, nonce_length + 1, aad, aad_length, ciphertext_and_tag, + ciphertext_and_tag_length, plaintext, plaintext_length, + &plaintext_bytes_written, &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "Nonce buffer has the wrong length.")); + gpr_free(error_message); + + /* Small nonce */ + status = gsec_aead_crypter_decrypt( + crypter, nonce, nonce_length - 1, aad, aad_length, ciphertext_and_tag, + ciphertext_and_tag_length, plaintext, plaintext_length, + &plaintext_bytes_written, &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "Nonce buffer has the wrong length.")); + gpr_free(error_message); + + /* nullptr aad */ + status = gsec_aead_crypter_decrypt( + crypter, nonce, nonce_length, nullptr, aad_length, ciphertext_and_tag, + ciphertext_and_tag_length, plaintext, plaintext_length, + &plaintext_bytes_written, &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, "aad is nullptr.")); + gpr_free(error_message); + + /* nullptr aad with zero length */ + status = gsec_aead_crypter_encrypt( + crypter, nonce, nonce_length, nullptr, 0, message, message_length, + ciphertext_and_tag, ciphertext_and_tag_length, &ciphertext_bytes_written, + &error_message); + GPR_ASSERT(status == GRPC_STATUS_OK); + + status = gsec_aead_crypter_decrypt( + crypter, nonce, nonce_length, nullptr, 0, ciphertext_and_tag, + ciphertext_and_tag_length, plaintext, plaintext_length, + &plaintext_bytes_written, &error_message); + GPR_ASSERT(status == GRPC_STATUS_OK); + + /* Small ciphertext */ + if (tag_length > 0) { + status = gsec_aead_crypter_decrypt( + crypter, nonce, nonce_length, aad, aad_length, ciphertext_and_tag, + tag_length - 1, plaintext, plaintext_length, &plaintext_bytes_written, + &error_message); + + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "ciphertext is too small to hold a tag.")); + gpr_free(error_message); + } + + /* nullptr ciphertext */ + status = gsec_aead_crypter_decrypt( + crypter, nonce, nonce_length, aad, aad_length, nullptr, + ciphertext_and_tag_length, plaintext, plaintext_length, + &plaintext_bytes_written, &error_message); + + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "ciphertext is nullptr.")); + gpr_free(error_message); + + /* nullptr plaintext */ + status = gsec_aead_crypter_decrypt( + crypter, nonce, nonce_length, aad, aad_length, ciphertext_and_tag, + ciphertext_and_tag_length, nullptr, plaintext_length, + &plaintext_bytes_written, &error_message); + + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "plaintext is nullptr, but plaintext_length is positive.")); + gpr_free(error_message); + + /* Short plaintext */ + status = gsec_aead_crypter_decrypt( + crypter, nonce, nonce_length, aad, aad_length, ciphertext_and_tag, + ciphertext_and_tag_length, plaintext, plaintext_length - 1, + &plaintext_bytes_written, &error_message); + + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "Not enough plaintext buffer to hold encrypted ciphertext.")); + gpr_free(error_message); + + /* nullptr plaintext_bytes_written */ + status = gsec_aead_crypter_decrypt(crypter, nonce, nonce_length, aad, + aad_length, ciphertext_and_tag, + ciphertext_and_tag_length, plaintext, + plaintext_length, nullptr, &error_message); + + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "bytes_written is nullptr.")); + gpr_free(error_message); + + gpr_free(message); + gpr_free(plaintext); + gpr_free(ciphertext_and_tag); + gpr_free(aad); + gpr_free(nonce); +} + +static void gsec_test_encrypt_decrypt_test_vector( + gsec_aead_crypter* crypter, gsec_aead_test_vector* test_vector) { + GPR_ASSERT(crypter != nullptr); + /* Test byte-based encryption interface. */ + size_t ciphertext_and_tag_length, ciphertext_bytes_written = 0; + gsec_aead_crypter_max_ciphertext_and_tag_length( + crypter, test_vector->plaintext_length, &ciphertext_and_tag_length, + nullptr); + uint8_t* ciphertext_and_tag_bytes = + static_cast(gpr_malloc(ciphertext_and_tag_length)); + grpc_status_code status = gsec_aead_crypter_encrypt( + crypter, test_vector->nonce, test_vector->nonce_length, test_vector->aad, + test_vector->aad_length, test_vector->plaintext, + test_vector->plaintext_length, ciphertext_and_tag_bytes, + ciphertext_and_tag_length, &ciphertext_bytes_written, nullptr); + + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(ciphertext_bytes_written == ciphertext_and_tag_length); + GPR_ASSERT(memcmp(test_vector->ciphertext_and_tag, ciphertext_and_tag_bytes, + ciphertext_and_tag_length) == 0); + + /* Test byte-based decryption interface */ + size_t plaintext_length, plaintext_bytes_written = 0; + gsec_aead_crypter_max_plaintext_length(crypter, ciphertext_and_tag_length, + &plaintext_length, nullptr); + uint8_t* plaintext_bytes = + static_cast(gpr_malloc(plaintext_length)); + status = gsec_aead_crypter_decrypt( + crypter, test_vector->nonce, test_vector->nonce_length, test_vector->aad, + test_vector->aad_length, test_vector->ciphertext_and_tag, + test_vector->ciphertext_and_tag_length, plaintext_bytes, plaintext_length, + &plaintext_bytes_written, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(memcmp(test_vector->plaintext, plaintext_bytes, + plaintext_bytes_written) == 0); + + gpr_free(ciphertext_and_tag_bytes); + gpr_free(plaintext_bytes); +} + +static void gsec_test_get_crypter_from_test_vector( + gsec_aead_crypter** crypter, gsec_aead_test_vector* test_vector, + bool rekey = false) { + size_t key_length = test_vector->key_length; + GPR_ASSERT(key_length == kAes128GcmKeyLength || + key_length == kAes256GcmKeyLength || + key_length == kAes128GcmRekeyKeyLength); + size_t nonce_length = test_vector->nonce_length; + GPR_ASSERT(nonce_length == kAesGcmNonceLength); + size_t plaintext_length = test_vector->plaintext_length; + size_t ciphertext_and_tag_length = test_vector->ciphertext_and_tag_length; + GPR_ASSERT(ciphertext_and_tag_length == plaintext_length + kAesGcmTagLength); + size_t tag_length = ciphertext_and_tag_length - plaintext_length; + gsec_aes_gcm_aead_crypter_create(test_vector->key, key_length, nonce_length, + tag_length, rekey, crypter, nullptr); +} + +static void gsec_test_verify_crypter_on_test_vector( + gsec_aead_test_vector* test_vector, bool rekey = false) { + gsec_aead_crypter* crypter; + gsec_test_get_crypter_from_test_vector(&crypter, test_vector, rekey); + gsec_test_encrypt_decrypt_test_vector(crypter, test_vector); + gsec_aead_crypter_destroy(crypter); +} + +static void gsec_aead_malloc_test_vector( + gsec_aead_test_vector** test_vector, const uint8_t* key, size_t key_length, + const uint8_t* nonce, size_t nonce_length, const uint8_t* aad, + size_t aad_length, const uint8_t* plaintext, size_t plaintext_length, + const uint8_t* ciphertext_and_tag, size_t ciphertext_and_tag_length) { + *test_vector = static_cast( + gpr_malloc(sizeof(gsec_aead_test_vector))); + (*test_vector)->key_length = key_length; + (*test_vector)->nonce_length = nonce_length; + (*test_vector)->aad_length = aad_length; + (*test_vector)->plaintext_length = plaintext_length; + (*test_vector)->ciphertext_and_tag_length = ciphertext_and_tag_length; + gsec_test_copy(key, &((*test_vector)->key), key_length); + gsec_test_copy(nonce, &((*test_vector)->nonce), nonce_length); + gsec_test_copy(aad, &((*test_vector)->aad), aad_length); + gsec_test_copy(plaintext, &((*test_vector)->plaintext), plaintext_length); + gsec_test_copy(ciphertext_and_tag, &((*test_vector)->ciphertext_and_tag), + ciphertext_and_tag_length); +} + +static void gsec_aead_free_test_vector(gsec_aead_test_vector* test_vector) { + gpr_free(test_vector->key); + gpr_free(test_vector->nonce); + gpr_free(test_vector->aad); + gpr_free(test_vector->plaintext); + gpr_free(test_vector->ciphertext_and_tag); + gpr_free(test_vector); +} + +static void gsec_test_create_random_aes_gcm_crypter(gsec_aead_crypter** crypter, + size_t key_length, + size_t nonce_length, + size_t tag_length, + bool rekey) { + uint8_t* key; + gsec_test_random_array(&key, key_length); + gsec_aes_gcm_aead_crypter_create(key, key_length, nonce_length, tag_length, + rekey, crypter, nullptr); + gpr_free(key); +} + +static void gsec_test_get_random_aes_gcm_crypters( + gsec_aead_crypter*** crypters) { + *crypters = static_cast( + gpr_malloc(sizeof(gsec_aead_crypter*) * kTestNumCrypters)); + gsec_test_create_random_aes_gcm_crypter( + &((*crypters)[0]), kAes128GcmKeyLength, kAesGcmNonceLength, + kAesGcmTagLength, /*rekey=*/false); + gsec_test_create_random_aes_gcm_crypter( + &((*crypters)[1]), kAes256GcmKeyLength, kAesGcmNonceLength, + kAesGcmTagLength, /*rekey=*/false); + gsec_test_create_random_aes_gcm_crypter( + &((*crypters)[2]), kAes128GcmRekeyKeyLength, kAesGcmNonceLength, + kAesGcmTagLength, /*rekey=*/true); +} + +static void gsec_test_do_generic_crypter_tests() { + gsec_aead_crypter** crypters; + gsec_test_get_random_aes_gcm_crypters(&crypters); + size_t ind; + for (ind = 0; ind < kTestNumCrypters; ind++) { + gsec_test_encrypt_decrypt(crypters[ind]); + gsec_test_multiple_encrypt_decrypt(crypters[ind]); + gsec_test_encryption_failure(crypters[ind]); + gsec_test_decryption_failure(crypters[ind]); + } + for (ind = 0; ind < kTestNumCrypters; ind++) { + gsec_aead_crypter_destroy(crypters[ind]); + } + gpr_free(crypters); +} + +static void gsec_test_do_vector_tests_rekey_nist() { + // NIST vectors from: + // http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm-revised-spec.pdf + // + // IEEE vectors from: + // http://www.ieee802.org/1/files/public/docs2011/bn-randall-test-vectors-0511-v1.pdf + // + // Key expanded by setting expandedKey = (key||(key ^ {0x01, .., 0x01})||key ^ + // {0x02,..,0x02}))[0:44]. + + gsec_aead_test_vector vec; + + // Derived from NIST test vector 1 + uint8_t nonce_0[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; + uint8_t aad_0[1] = {}; + uint8_t key_0[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, + 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x2, + 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2}; + uint8_t plaintext_0[1] = {}; + uint8_t ciphertext_0[] = {0x85, 0xE8, 0x73, 0xE0, 0x2, 0xF6, 0xEB, 0xDC, + 0x40, 0x60, 0x95, 0x4E, 0xB8, 0x67, 0x55, 0x8}; + vec = {nonce_0, aad_0, key_0, plaintext_0, ciphertext_0, 12, 0, 44, 0, 16}; + gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); + + // Derived from NIST test vector 2 + uint8_t nonce_1[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; + uint8_t aad_1[1] = {}; + uint8_t key_1[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, + 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x2, + 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2}; + uint8_t plaintext_1[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; + uint8_t ciphertext_1[] = {0x51, 0xE9, 0xA8, 0xCB, 0x23, 0xCA, 0x25, 0x12, + 0xC8, 0x25, 0x6A, 0xFF, 0xF8, 0xE7, 0x2D, 0x68, + 0x1A, 0xCA, 0x19, 0xA1, 0x14, 0x8A, 0xC1, 0x15, + 0xE8, 0x3D, 0xF4, 0x88, 0x8C, 0xC0, 0xD, 0x11}; + vec = {nonce_1, aad_1, key_1, plaintext_1, ciphertext_1, 12, 0, 44, 16, 32}; + gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); + + // Derived from NIST test vector 3 + uint8_t nonce_2[] = {0xCA, 0xFE, 0xBA, 0xBE, 0xFA, 0xCE, + 0xDB, 0xAD, 0xDE, 0xCA, 0xF8, 0x88}; + uint8_t aad_2[1] = {}; + uint8_t key_2[] = {0xFE, 0xFF, 0xE9, 0x92, 0x86, 0x65, 0x73, 0x1C, 0x6D, + 0x6A, 0x8F, 0x94, 0x67, 0x30, 0x83, 0x8, 0xFF, 0xFE, + 0xE8, 0x93, 0x87, 0x64, 0x72, 0x1D, 0x6C, 0x6B, 0x8E, + 0x95, 0x66, 0x31, 0x82, 0x9, 0xFC, 0xFD, 0xEB, 0x90, + 0x84, 0x67, 0x71, 0x1E, 0x6F, 0x68, 0x8D, 0x96}; + uint8_t plaintext_2[] = { + 0xD9, 0x31, 0x32, 0x25, 0xF8, 0x84, 0x6, 0xE5, 0xA5, 0x59, 0x9, + 0xC5, 0xAF, 0xF5, 0x26, 0x9A, 0x86, 0xA7, 0xA9, 0x53, 0x15, 0x34, + 0xF7, 0xDA, 0x2E, 0x4C, 0x30, 0x3D, 0x8A, 0x31, 0x8A, 0x72, 0x1C, + 0x3C, 0xC, 0x95, 0x95, 0x68, 0x9, 0x53, 0x2F, 0xCF, 0xE, 0x24, + 0x49, 0xA6, 0xB5, 0x25, 0xB1, 0x6A, 0xED, 0xF5, 0xAA, 0xD, 0xE6, + 0x57, 0xBA, 0x63, 0x7B, 0x39, 0x1A, 0xAF, 0xD2, 0x55}; + uint8_t ciphertext_2[] = { + 0x10, 0x18, 0xED, 0x5A, 0x14, 0x2, 0xA8, 0x65, 0x16, 0xD6, 0x57, 0x6D, + 0x70, 0xB2, 0xFF, 0xCC, 0xCA, 0x26, 0x1B, 0x94, 0xDF, 0x88, 0xB5, 0x8F, + 0x53, 0xB6, 0x4D, 0xFB, 0xA4, 0x35, 0xD1, 0x8B, 0x2F, 0x6E, 0x3B, 0x78, + 0x69, 0xF9, 0x35, 0x3D, 0x4A, 0xC8, 0xCF, 0x9, 0xAF, 0xB1, 0x66, 0x3D, + 0xAA, 0x7B, 0x40, 0x17, 0xE6, 0xFC, 0x2C, 0x17, 0x7C, 0xC, 0x8, 0x7C, + 0xD, 0xF1, 0x16, 0x21, 0x29, 0x95, 0x22, 0x13, 0xCE, 0xE1, 0xBC, 0x6E, + 0x9C, 0x84, 0x95, 0xDD, 0x70, 0x5E, 0x1F, 0x3D}; + vec = {nonce_2, aad_2, key_2, plaintext_2, ciphertext_2, 12, 0, 44, 64, 80}; + gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); + + // Derived from NIST test vector 4 + uint8_t nonce_3[] = {0xCA, 0xFE, 0xBA, 0xBE, 0xFA, 0xCE, + 0xDB, 0xAD, 0xDE, 0xCA, 0xF8, 0x88}; + uint8_t aad_3[] = {0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, + 0xEF, 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, + 0xBE, 0xEF, 0xAB, 0xAD, 0xDA, 0xD2}; + uint8_t key_3[] = {0xFE, 0xFF, 0xE9, 0x92, 0x86, 0x65, 0x73, 0x1C, 0x6D, + 0x6A, 0x8F, 0x94, 0x67, 0x30, 0x83, 0x8, 0xFF, 0xFE, + 0xE8, 0x93, 0x87, 0x64, 0x72, 0x1D, 0x6C, 0x6B, 0x8E, + 0x95, 0x66, 0x31, 0x82, 0x9, 0xFC, 0xFD, 0xEB, 0x90, + 0x84, 0x67, 0x71, 0x1E, 0x6F, 0x68, 0x8D, 0x96}; + uint8_t plaintext_3[] = { + 0xD9, 0x31, 0x32, 0x25, 0xF8, 0x84, 0x6, 0xE5, 0xA5, 0x59, 0x9, 0xC5, + 0xAF, 0xF5, 0x26, 0x9A, 0x86, 0xA7, 0xA9, 0x53, 0x15, 0x34, 0xF7, 0xDA, + 0x2E, 0x4C, 0x30, 0x3D, 0x8A, 0x31, 0x8A, 0x72, 0x1C, 0x3C, 0xC, 0x95, + 0x95, 0x68, 0x9, 0x53, 0x2F, 0xCF, 0xE, 0x24, 0x49, 0xA6, 0xB5, 0x25, + 0xB1, 0x6A, 0xED, 0xF5, 0xAA, 0xD, 0xE6, 0x57, 0xBA, 0x63, 0x7B, 0x39}; + uint8_t ciphertext_3[] = { + 0x10, 0x18, 0xED, 0x5A, 0x14, 0x2, 0xA8, 0x65, 0x16, 0xD6, 0x57, + 0x6D, 0x70, 0xB2, 0xFF, 0xCC, 0xCA, 0x26, 0x1B, 0x94, 0xDF, 0x88, + 0xB5, 0x8F, 0x53, 0xB6, 0x4D, 0xFB, 0xA4, 0x35, 0xD1, 0x8B, 0x2F, + 0x6E, 0x3B, 0x78, 0x69, 0xF9, 0x35, 0x3D, 0x4A, 0xC8, 0xCF, 0x9, + 0xAF, 0xB1, 0x66, 0x3D, 0xAA, 0x7B, 0x40, 0x17, 0xE6, 0xFC, 0x2C, + 0x17, 0x7C, 0xC, 0x8, 0x7C, 0x47, 0x64, 0x56, 0x5D, 0x7, 0x7E, + 0x91, 0x24, 0x0, 0x1D, 0xDB, 0x27, 0xFC, 0x8, 0x48, 0xC5}; + vec = {nonce_3, aad_3, key_3, plaintext_3, ciphertext_3, 12, 20, 44, 60, 76}; + gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); + + // Derived from adapted NIST test vector 4 for KDF counter boundary (flip + // nonce bit 15) + uint8_t nonce_4[] = {0xCA, 0x7E, 0xBA, 0xBE, 0xFA, 0xCE, + 0xDB, 0xAD, 0xDE, 0xCA, 0xF8, 0x88}; + uint8_t aad_4[] = {0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, + 0xEF, 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, + 0xBE, 0xEF, 0xAB, 0xAD, 0xDA, 0xD2}; + uint8_t key_4[] = {0xFE, 0xFF, 0xE9, 0x92, 0x86, 0x65, 0x73, 0x1C, 0x6D, + 0x6A, 0x8F, 0x94, 0x67, 0x30, 0x83, 0x8, 0xFF, 0xFE, + 0xE8, 0x93, 0x87, 0x64, 0x72, 0x1D, 0x6C, 0x6B, 0x8E, + 0x95, 0x66, 0x31, 0x82, 0x9, 0xFC, 0xFD, 0xEB, 0x90, + 0x84, 0x67, 0x71, 0x1E, 0x6F, 0x68, 0x8D, 0x96}; + uint8_t plaintext_4[] = { + 0xD9, 0x31, 0x32, 0x25, 0xF8, 0x84, 0x6, 0xE5, 0xA5, 0x59, 0x9, 0xC5, + 0xAF, 0xF5, 0x26, 0x9A, 0x86, 0xA7, 0xA9, 0x53, 0x15, 0x34, 0xF7, 0xDA, + 0x2E, 0x4C, 0x30, 0x3D, 0x8A, 0x31, 0x8A, 0x72, 0x1C, 0x3C, 0xC, 0x95, + 0x95, 0x68, 0x9, 0x53, 0x2F, 0xCF, 0xE, 0x24, 0x49, 0xA6, 0xB5, 0x25, + 0xB1, 0x6A, 0xED, 0xF5, 0xAA, 0xD, 0xE6, 0x57, 0xBA, 0x63, 0x7B, 0x39}; + uint8_t ciphertext_4[] = { + 0xE6, 0x50, 0xD3, 0xC0, 0xFB, 0x87, 0x93, 0x27, 0xF2, 0xD0, 0x32, + 0x87, 0xFA, 0x93, 0xCD, 0x7, 0x34, 0x2B, 0x13, 0x62, 0x15, 0xAD, + 0xBC, 0xA0, 0xC, 0x3B, 0xD5, 0x9, 0x9E, 0xC4, 0x18, 0x32, 0xB1, + 0xD1, 0x8E, 0x4, 0x23, 0xED, 0x26, 0xBB, 0x12, 0xC6, 0xCD, 0x9, + 0xDE, 0xBB, 0x29, 0x23, 0xA, 0x94, 0xC0, 0xCE, 0xE1, 0x59, 0x3, + 0x65, 0x6F, 0x85, 0xED, 0xB6, 0xFC, 0x50, 0x9B, 0x1B, 0x28, 0x21, + 0x63, 0x82, 0x17, 0x2E, 0xCB, 0xCC, 0x31, 0xE1, 0xE9, 0xB1}; + vec = {nonce_4, aad_4, key_4, plaintext_4, ciphertext_4, 12, 20, 44, 60, 76}; + gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); + + // Derived from adapted NIST test vector 4 for KDF counter boundary (flip + // nonce bit 16) + uint8_t nonce_5[] = {0xCA, 0xFE, 0xBB, 0xBE, 0xFA, 0xCE, + 0xDB, 0xAD, 0xDE, 0xCA, 0xF8, 0x88}; + uint8_t aad_5[] = {0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, + 0xEF, 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, + 0xBE, 0xEF, 0xAB, 0xAD, 0xDA, 0xD2}; + uint8_t key_5[] = {0xFE, 0xFF, 0xE9, 0x92, 0x86, 0x65, 0x73, 0x1C, 0x6D, + 0x6A, 0x8F, 0x94, 0x67, 0x30, 0x83, 0x8, 0xFF, 0xFE, + 0xE8, 0x93, 0x87, 0x64, 0x72, 0x1D, 0x6C, 0x6B, 0x8E, + 0x95, 0x66, 0x31, 0x82, 0x9, 0xFC, 0xFD, 0xEB, 0x90, + 0x84, 0x67, 0x71, 0x1E, 0x6F, 0x68, 0x8D, 0x96}; + uint8_t plaintext_5[] = { + 0xD9, 0x31, 0x32, 0x25, 0xF8, 0x84, 0x6, 0xE5, 0xA5, 0x59, 0x9, 0xC5, + 0xAF, 0xF5, 0x26, 0x9A, 0x86, 0xA7, 0xA9, 0x53, 0x15, 0x34, 0xF7, 0xDA, + 0x2E, 0x4C, 0x30, 0x3D, 0x8A, 0x31, 0x8A, 0x72, 0x1C, 0x3C, 0xC, 0x95, + 0x95, 0x68, 0x9, 0x53, 0x2F, 0xCF, 0xE, 0x24, 0x49, 0xA6, 0xB5, 0x25, + 0xB1, 0x6A, 0xED, 0xF5, 0xAA, 0xD, 0xE6, 0x57, 0xBA, 0x63, 0x7B, 0x39}; + uint8_t ciphertext_5[] = { + 0xC0, 0x12, 0x1E, 0x6C, 0x95, 0x4D, 0x7, 0x67, 0xF9, 0x66, 0x30, + 0xC3, 0x34, 0x50, 0x99, 0x97, 0x91, 0xB2, 0xDA, 0x2A, 0xD0, 0x5C, + 0x41, 0x90, 0x16, 0x9C, 0xCA, 0xD9, 0xAC, 0x86, 0xFF, 0x1C, 0x72, + 0x1E, 0x3D, 0x82, 0xF2, 0xAD, 0x22, 0xAB, 0x46, 0x3B, 0xAB, 0x4A, + 0x7, 0x54, 0xB7, 0xDD, 0x68, 0xCA, 0x4D, 0xE7, 0xEA, 0x25, 0x31, + 0xB6, 0x25, 0xED, 0xA0, 0x1F, 0x89, 0x31, 0x2B, 0x2A, 0xB9, 0x57, + 0xD5, 0xC7, 0xF8, 0x56, 0x8D, 0xD9, 0x5F, 0xCD, 0xCD, 0x1F}; + vec = {nonce_5, aad_5, key_5, plaintext_5, ciphertext_5, 12, 20, 44, 60, 76}; + gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); + + // Derived from adapted NIST test vector 4 for KDF counter boundary (flip + // nonce bit 63) + uint8_t nonce_6[] = {0xCA, 0xFE, 0xBA, 0xBE, 0xFA, 0xCE, + 0xDB, 0x2D, 0xDE, 0xCA, 0xF8, 0x88}; + uint8_t aad_6[] = {0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, + 0xEF, 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, + 0xBE, 0xEF, 0xAB, 0xAD, 0xDA, 0xD2}; + uint8_t key_6[] = {0xFE, 0xFF, 0xE9, 0x92, 0x86, 0x65, 0x73, 0x1C, 0x6D, + 0x6A, 0x8F, 0x94, 0x67, 0x30, 0x83, 0x8, 0xFF, 0xFE, + 0xE8, 0x93, 0x87, 0x64, 0x72, 0x1D, 0x6C, 0x6B, 0x8E, + 0x95, 0x66, 0x31, 0x82, 0x9, 0xFC, 0xFD, 0xEB, 0x90, + 0x84, 0x67, 0x71, 0x1E, 0x6F, 0x68, 0x8D, 0x96}; + uint8_t plaintext_6[] = { + 0xD9, 0x31, 0x32, 0x25, 0xF8, 0x84, 0x6, 0xE5, 0xA5, 0x59, 0x9, 0xC5, + 0xAF, 0xF5, 0x26, 0x9A, 0x86, 0xA7, 0xA9, 0x53, 0x15, 0x34, 0xF7, 0xDA, + 0x2E, 0x4C, 0x30, 0x3D, 0x8A, 0x31, 0x8A, 0x72, 0x1C, 0x3C, 0xC, 0x95, + 0x95, 0x68, 0x9, 0x53, 0x2F, 0xCF, 0xE, 0x24, 0x49, 0xA6, 0xB5, 0x25, + 0xB1, 0x6A, 0xED, 0xF5, 0xAA, 0xD, 0xE6, 0x57, 0xBA, 0x63, 0x7B, 0x39}; + uint8_t ciphertext_6[] = { + 0x8A, 0xF3, 0x7E, 0xA5, 0x68, 0x4A, 0x4D, 0x81, 0xD4, 0xFD, 0x81, + 0x72, 0x61, 0xFD, 0x97, 0x43, 0x9, 0x9E, 0x7E, 0x6A, 0x2, 0x5E, + 0xAA, 0xCF, 0x8E, 0x54, 0xB1, 0x24, 0xFB, 0x57, 0x43, 0x14, 0x9E, + 0x5, 0xCB, 0x89, 0xF4, 0xA4, 0x94, 0x67, 0xFE, 0x2E, 0x5E, 0x59, + 0x65, 0xF2, 0x9A, 0x19, 0xF9, 0x94, 0x16, 0xB0, 0x1, 0x6B, 0x54, + 0x58, 0x5D, 0x12, 0x55, 0x37, 0x83, 0xBA, 0x59, 0xE9, 0xF7, 0x82, + 0xE8, 0x2E, 0x9, 0x7C, 0x33, 0x6B, 0xF7, 0x98, 0x9F, 0x8}; + vec = {nonce_6, aad_6, key_6, plaintext_6, ciphertext_6, 12, 20, 44, 60, 76}; + gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); + + // Derived from adapted NIST test vector 4 for KDF counter boundary (flip + // nonce bit 64) + uint8_t nonce_7[] = {0xCA, 0xFE, 0xBA, 0xBE, 0xFA, 0xCE, + 0xDB, 0xAD, 0xDF, 0xCA, 0xF8, 0x88}; + uint8_t aad_7[] = {0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, + 0xEF, 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, + 0xBE, 0xEF, 0xAB, 0xAD, 0xDA, 0xD2}; + uint8_t key_7[] = {0xFE, 0xFF, 0xE9, 0x92, 0x86, 0x65, 0x73, 0x1C, 0x6D, + 0x6A, 0x8F, 0x94, 0x67, 0x30, 0x83, 0x8, 0xFF, 0xFE, + 0xE8, 0x93, 0x87, 0x64, 0x72, 0x1D, 0x6C, 0x6B, 0x8E, + 0x95, 0x66, 0x31, 0x82, 0x9, 0xFC, 0xFD, 0xEB, 0x90, + 0x84, 0x67, 0x71, 0x1E, 0x6F, 0x68, 0x8D, 0x96}; + uint8_t plaintext_7[] = { + 0xD9, 0x31, 0x32, 0x25, 0xF8, 0x84, 0x6, 0xE5, 0xA5, 0x59, 0x9, 0xC5, + 0xAF, 0xF5, 0x26, 0x9A, 0x86, 0xA7, 0xA9, 0x53, 0x15, 0x34, 0xF7, 0xDA, + 0x2E, 0x4C, 0x30, 0x3D, 0x8A, 0x31, 0x8A, 0x72, 0x1C, 0x3C, 0xC, 0x95, + 0x95, 0x68, 0x9, 0x53, 0x2F, 0xCF, 0xE, 0x24, 0x49, 0xA6, 0xB5, 0x25, + 0xB1, 0x6A, 0xED, 0xF5, 0xAA, 0xD, 0xE6, 0x57, 0xBA, 0x63, 0x7B, 0x39}; + uint8_t ciphertext_7[] = { + 0xFB, 0xD5, 0x28, 0x44, 0x8D, 0x3, 0x46, 0xBF, 0xA8, 0x78, 0x63, + 0x48, 0x64, 0xD4, 0x7, 0xA3, 0x5A, 0x3, 0x9D, 0xE9, 0xDB, 0x2F, + 0x1F, 0xEB, 0x8E, 0x96, 0x5B, 0x3A, 0xE9, 0x35, 0x6C, 0xE6, 0x28, + 0x94, 0x41, 0xD7, 0x7F, 0x8F, 0xD, 0xF2, 0x94, 0x89, 0x1F, 0x37, + 0xEA, 0x43, 0x8B, 0x22, 0x3E, 0x3B, 0xF2, 0xBD, 0xC5, 0x3D, 0x4C, + 0x5A, 0x74, 0xFB, 0x68, 0xB, 0xB3, 0x12, 0xA8, 0xDE, 0xC6, 0xF7, + 0x25, 0x2C, 0xBC, 0xD7, 0xF5, 0x79, 0x97, 0x50, 0xAD, 0x78}; + vec = {nonce_7, aad_7, key_7, plaintext_7, ciphertext_7, 12, 20, 44, 60, 76}; + gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); +} + +static void gsec_test_do_vector_tests_rekey_ieee() { + // IEEE vectors from: + // http://www.ieee802.org/1/files/public/docs2011/bn-randall-test-vectors-0511-v1.pdf + // + // Key expanded by setting expandedKey = (key||(key ^ {0x01, .., 0x01})||key ^ + // {0x02,..,0x02}))[0:44]. + + gsec_aead_test_vector vec; + + // Derived from IEEE 2.1.1 54-byte auth + uint8_t nonce_8[] = {0x12, 0x15, 0x35, 0x24, 0xC0, 0x89, + 0x5E, 0x81, 0xB2, 0xC2, 0x84, 0x65}; + uint8_t aad_8[] = {0xD6, 0x9, 0xB1, 0xF0, 0x56, 0x63, 0x7A, 0xD, 0x46, 0xDF, + 0x99, 0x8D, 0x88, 0xE5, 0x22, 0x2A, 0xB2, 0xC2, 0x84, 0x65, + 0x12, 0x15, 0x35, 0x24, 0xC0, 0x89, 0x5E, 0x81, 0x8, 0x0, + 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, + 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, + 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x0, 0x1}; + uint8_t key_8[] = {0xAD, 0x7A, 0x2B, 0xD0, 0x3E, 0xAC, 0x83, 0x5A, 0x6F, + 0x62, 0xF, 0xDC, 0xB5, 0x6, 0xB3, 0x45, 0xAC, 0x7B, + 0x2A, 0xD1, 0x3F, 0xAD, 0x82, 0x5B, 0x6E, 0x63, 0xE, + 0xDD, 0xB4, 0x7, 0xB2, 0x44, 0xAF, 0x78, 0x29, 0xD2, + 0x3C, 0xAE, 0x81, 0x58, 0x6D, 0x60, 0xD, 0xDE}; + uint8_t plaintext_8[1] = {}; + uint8_t ciphertext_8[] = {0x3E, 0xA0, 0xB5, 0x84, 0xF3, 0xC8, 0x5E, 0x93, + 0xF9, 0x32, 0xE, 0xA5, 0x91, 0x69, 0x9E, 0xFB}; + vec = {nonce_8, aad_8, key_8, plaintext_8, ciphertext_8, 12, 70, 44, 0, 16}; + gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); + + // Derived from IEEE 2.1.2 54-byte auth + uint8_t nonce_9[] = {0x12, 0x15, 0x35, 0x24, 0xC0, 0x89, + 0x5E, 0x81, 0xB2, 0xC2, 0x84, 0x65}; + uint8_t aad_9[] = {0xD6, 0x9, 0xB1, 0xF0, 0x56, 0x63, 0x7A, 0xD, 0x46, 0xDF, + 0x99, 0x8D, 0x88, 0xE5, 0x22, 0x2A, 0xB2, 0xC2, 0x84, 0x65, + 0x12, 0x15, 0x35, 0x24, 0xC0, 0x89, 0x5E, 0x81, 0x8, 0x0, + 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, + 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, + 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x0, 0x1}; + uint8_t key_9[] = {0xE3, 0xC0, 0x8A, 0x8F, 0x6, 0xC6, 0xE3, 0xAD, 0x95, + 0xA7, 0x5, 0x57, 0xB2, 0x3F, 0x75, 0x48, 0x3C, 0xE3, + 0x30, 0x21, 0xA9, 0xC7, 0x2B, 0x70, 0x25, 0x66, 0x62, + 0x4, 0xC6, 0x9C, 0xB, 0x72, 0xE1, 0xC2, 0x88, 0x8D, + 0x4, 0xC4, 0xE1, 0xAF, 0x97, 0xA5, 0x7, 0x55}; + uint8_t plaintext_9[1] = {}; + uint8_t ciphertext_9[] = {0x29, 0x4E, 0x2, 0x8B, 0xF1, 0xFE, 0x6F, 0x14, + 0xC4, 0xE8, 0xF7, 0x30, 0x5C, 0x93, 0x3E, 0xB5}; + vec = {nonce_9, aad_9, key_9, plaintext_9, ciphertext_9, 12, 70, 44, 0, 16}; + gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); + + // Derived from IEEE 2.2.1 60-byte crypt + uint8_t nonce_10[] = {0x12, 0x15, 0x35, 0x24, 0xC0, 0x89, + 0x5E, 0x81, 0xB2, 0xC2, 0x84, 0x65}; + uint8_t aad_10[] = {0xD6, 0x9, 0xB1, 0xF0, 0x56, 0x63, 0x7A, + 0xD, 0x46, 0xDF, 0x99, 0x8D, 0x88, 0xE5, + 0x2E, 0x0, 0xB2, 0xC2, 0x84, 0x65, 0x12, + 0x15, 0x35, 0x24, 0xC0, 0x89, 0x5E, 0x81}; + uint8_t key_10[] = {0xAD, 0x7A, 0x2B, 0xD0, 0x3E, 0xAC, 0x83, 0x5A, 0x6F, + 0x62, 0xF, 0xDC, 0xB5, 0x6, 0xB3, 0x45, 0xAC, 0x7B, + 0x2A, 0xD1, 0x3F, 0xAD, 0x82, 0x5B, 0x6E, 0x63, 0xE, + 0xDD, 0xB4, 0x7, 0xB2, 0x44, 0xAF, 0x78, 0x29, 0xD2, + 0x3C, 0xAE, 0x81, 0x58, 0x6D, 0x60, 0xD, 0xDE}; + uint8_t plaintext_10[] = { + 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, + 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, + 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, + 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x0, 0x2}; + uint8_t ciphertext_10[] = { + 0xDB, 0x3D, 0x25, 0x71, 0x9C, 0x6B, 0xA, 0x3C, 0xA6, 0x14, 0x5C, + 0x15, 0x9D, 0x5C, 0x6E, 0xD9, 0xAF, 0xF9, 0xC6, 0xE0, 0xB7, 0x9F, + 0x17, 0x1, 0x9E, 0xA9, 0x23, 0xB8, 0x66, 0x5D, 0xDF, 0x52, 0x13, + 0x7A, 0xD6, 0x11, 0xF0, 0xD1, 0xBF, 0x41, 0x7A, 0x7C, 0xA8, 0x5E, + 0x45, 0xAF, 0xE1, 0x6, 0xFF, 0x9C, 0x75, 0x69, 0xD3, 0x35, 0xD0, + 0x86, 0xAE, 0x6C, 0x3, 0xF0, 0x9, 0x87, 0xCC, 0xD6}; + vec = {nonce_10, aad_10, key_10, plaintext_10, ciphertext_10, + 12, 28, 44, 48, 64}; + gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); + + // Derived from IEEE 2.2.2 60-byte crypt + uint8_t nonce_11[] = {0x12, 0x15, 0x35, 0x24, 0xC0, 0x89, + 0x5E, 0x81, 0xB2, 0xC2, 0x84, 0x65}; + uint8_t aad_11[] = {0xD6, 0x9, 0xB1, 0xF0, 0x56, 0x63, 0x7A, + 0xD, 0x46, 0xDF, 0x99, 0x8D, 0x88, 0xE5, + 0x2E, 0x0, 0xB2, 0xC2, 0x84, 0x65, 0x12, + 0x15, 0x35, 0x24, 0xC0, 0x89, 0x5E, 0x81}; + uint8_t key_11[] = {0xE3, 0xC0, 0x8A, 0x8F, 0x6, 0xC6, 0xE3, 0xAD, 0x95, + 0xA7, 0x5, 0x57, 0xB2, 0x3F, 0x75, 0x48, 0x3C, 0xE3, + 0x30, 0x21, 0xA9, 0xC7, 0x2B, 0x70, 0x25, 0x66, 0x62, + 0x4, 0xC6, 0x9C, 0xB, 0x72, 0xE1, 0xC2, 0x88, 0x8D, + 0x4, 0xC4, 0xE1, 0xAF, 0x97, 0xA5, 0x7, 0x55}; + uint8_t plaintext_11[] = { + 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, + 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, + 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, + 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x0, 0x2}; + uint8_t ciphertext_11[] = { + 0x16, 0x41, 0xF2, 0x8E, 0xC1, 0x3A, 0xFC, 0xC8, 0xF7, 0x90, 0x33, + 0x89, 0x78, 0x72, 0x1, 0x5, 0x16, 0x44, 0x91, 0x49, 0x33, 0xE9, + 0x20, 0x2B, 0xB9, 0xD0, 0x6A, 0xA0, 0x20, 0xC2, 0xA6, 0x7E, 0xF5, + 0x1D, 0xFE, 0x7B, 0xC0, 0xA, 0x85, 0x6C, 0x55, 0xB8, 0xF8, 0x13, + 0x3E, 0x77, 0xF6, 0x59, 0x13, 0x25, 0x2, 0xBA, 0xD6, 0x3F, 0x57, + 0x13, 0xD5, 0x7D, 0xC, 0x11, 0xE0, 0xF8, 0x71, 0xED}; + vec = {nonce_11, aad_11, key_11, plaintext_11, ciphertext_11, + 12, 28, 44, 48, 64}; + gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); + + // Derived from IEEE 2.3.1 60-byte auth + uint8_t nonce_12[] = {0xF0, 0x76, 0x1E, 0x8D, 0xCD, 0x3D, + 0x0, 0x1, 0x76, 0xD4, 0x57, 0xED}; + uint8_t aad_12[] = { + 0xE2, 0x1, 0x6, 0xD7, 0xCD, 0xD, 0xF0, 0x76, 0x1E, 0x8D, 0xCD, 0x3D, + 0x88, 0xE5, 0x40, 0x0, 0x76, 0xD4, 0x57, 0xED, 0x8, 0x0, 0xF, 0x10, + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, + 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, + 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x0, 0x3}; + uint8_t key_12[] = {0x7, 0x1B, 0x11, 0x3B, 0xC, 0xA7, 0x43, 0xFE, 0xCC, + 0xCF, 0x3D, 0x5, 0x1F, 0x73, 0x73, 0x82, 0x6, 0x1A, + 0x10, 0x3A, 0xD, 0xA6, 0x42, 0xFF, 0xCD, 0xCE, 0x3C, + 0x4, 0x1E, 0x72, 0x72, 0x83, 0x5, 0x19, 0x13, 0x39, + 0xE, 0xA5, 0x41, 0xFC, 0xCE, 0xCD, 0x3F, 0x7}; + uint8_t plaintext_12[1] = {}; + uint8_t ciphertext_12[] = {0x58, 0x83, 0x7A, 0x10, 0x56, 0x2B, 0xF, 0x1F, + 0x8E, 0xDB, 0xE5, 0x8C, 0xA5, 0x58, 0x11, 0xD3}; + vec = {nonce_12, aad_12, key_12, plaintext_12, ciphertext_12, 12, 68, + 44, 0, 16}; + gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); + + // Derived from IEEE 2.3.2 60-byte auth + uint8_t nonce_13[] = {0xF0, 0x76, 0x1E, 0x8D, 0xCD, 0x3D, + 0x0, 0x1, 0x76, 0xD4, 0x57, 0xED}; + uint8_t aad_13[] = { + 0xE2, 0x1, 0x6, 0xD7, 0xCD, 0xD, 0xF0, 0x76, 0x1E, 0x8D, 0xCD, 0x3D, + 0x88, 0xE5, 0x40, 0x0, 0x76, 0xD4, 0x57, 0xED, 0x8, 0x0, 0xF, 0x10, + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, + 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, + 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x0, 0x3}; + uint8_t key_13[] = {0x69, 0x1D, 0x3E, 0xE9, 0x9, 0xD7, 0xF5, 0x41, 0x67, + 0xFD, 0x1C, 0xA0, 0xB5, 0xD7, 0x69, 0x8, 0x1F, 0x2B, + 0xDE, 0x1A, 0xEE, 0x65, 0x5F, 0xDB, 0xAB, 0x80, 0xBD, + 0x52, 0x95, 0xAE, 0x6B, 0xE7, 0x6B, 0x1F, 0x3C, 0xEB, + 0xB, 0xD5, 0xF7, 0x43, 0x65, 0xFF, 0x1E, 0xA2}; + uint8_t plaintext_13[1] = {}; + uint8_t ciphertext_13[] = {0xC2, 0x72, 0x2F, 0xF6, 0xCA, 0x29, 0xA2, 0x57, + 0x71, 0x8A, 0x52, 0x9D, 0x1F, 0xC, 0x6A, 0x3B}; + vec = {nonce_13, aad_13, key_13, plaintext_13, ciphertext_13, 12, 68, + 44, 0, 16}; + gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); + + // Derived from IEEE 2.4.1 54-byte crypt + uint8_t nonce_14[] = {0xF0, 0x76, 0x1E, 0x8D, 0xCD, 0x3D, + 0x0, 0x1, 0x76, 0xD4, 0x57, 0xED}; + uint8_t aad_14[] = {0xE2, 0x1, 0x6, 0xD7, 0xCD, 0xD, 0xF0, + 0x76, 0x1E, 0x8D, 0xCD, 0x3D, 0x88, 0xE5, + 0x4C, 0x2A, 0x76, 0xD4, 0x57, 0xED}; + uint8_t key_14[] = {0x7, 0x1B, 0x11, 0x3B, 0xC, 0xA7, 0x43, 0xFE, 0xCC, + 0xCF, 0x3D, 0x5, 0x1F, 0x73, 0x73, 0x82, 0x6, 0x1A, + 0x10, 0x3A, 0xD, 0xA6, 0x42, 0xFF, 0xCD, 0xCE, 0x3C, + 0x4, 0x1E, 0x72, 0x72, 0x83, 0x5, 0x19, 0x13, 0x39, + 0xE, 0xA5, 0x41, 0xFC, 0xCE, 0xCD, 0x3F, 0x7}; + uint8_t plaintext_14[] = { + 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, + 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, + 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x0, 0x4}; + uint8_t ciphertext_14[] = { + 0xFD, 0x96, 0xB7, 0x15, 0xB9, 0x3A, 0x13, 0x34, 0x6A, 0xF5, 0x1E, 0x8A, + 0xCD, 0xF7, 0x92, 0xCD, 0xC7, 0xB2, 0x68, 0x6F, 0x85, 0x74, 0xC7, 0xE, + 0x6B, 0xC, 0xBF, 0x16, 0x29, 0x1D, 0xED, 0x42, 0x7A, 0xD7, 0x3F, 0xEC, + 0x48, 0xCD, 0x29, 0x8E, 0x5, 0x28, 0xA1, 0xF4, 0xC6, 0x44, 0xA9, 0x49, + 0xFC, 0x31, 0xDC, 0x92, 0x79, 0x70, 0x6D, 0xDB, 0xA3, 0x3F}; + vec = {nonce_14, aad_14, key_14, plaintext_14, ciphertext_14, + 12, 20, 44, 42, 58}; + gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); + + // Derived from IEEE 2.4.2 54-byte crypt + uint8_t nonce_15[] = {0xF0, 0x76, 0x1E, 0x8D, 0xCD, 0x3D, + 0x0, 0x1, 0x76, 0xD4, 0x57, 0xED}; + uint8_t aad_15[] = {0xE2, 0x1, 0x6, 0xD7, 0xCD, 0xD, 0xF0, + 0x76, 0x1E, 0x8D, 0xCD, 0x3D, 0x88, 0xE5, + 0x4C, 0x2A, 0x76, 0xD4, 0x57, 0xED}; + uint8_t key_15[] = {0x69, 0x1D, 0x3E, 0xE9, 0x9, 0xD7, 0xF5, 0x41, 0x67, + 0xFD, 0x1C, 0xA0, 0xB5, 0xD7, 0x69, 0x8, 0x1F, 0x2B, + 0xDE, 0x1A, 0xEE, 0x65, 0x5F, 0xDB, 0xAB, 0x80, 0xBD, + 0x52, 0x95, 0xAE, 0x6B, 0xE7, 0x6B, 0x1F, 0x3C, 0xEB, + 0xB, 0xD5, 0xF7, 0x43, 0x65, 0xFF, 0x1E, 0xA2}; + uint8_t plaintext_15[] = { + 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, + 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, + 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x0, 0x4}; + uint8_t ciphertext_15[] = { + 0xB6, 0x8F, 0x63, 0x0, 0xC2, 0xE9, 0xAE, 0x83, 0x3B, 0xDC, 0x7, 0xE, + 0x24, 0x2, 0x1A, 0x34, 0x77, 0x11, 0x8E, 0x78, 0xCC, 0xF8, 0x4E, 0x11, + 0xA4, 0x85, 0xD8, 0x61, 0x47, 0x6C, 0x30, 0xF, 0x17, 0x53, 0x53, 0xD5, + 0xCD, 0xF9, 0x20, 0x8, 0xA4, 0xF8, 0x78, 0xE6, 0xCC, 0x35, 0x77, 0x76, + 0x80, 0x85, 0xC5, 0xA, 0xE, 0x98, 0xFD, 0xA6, 0xCB, 0xB8}; + vec = {nonce_15, aad_15, key_15, plaintext_15, ciphertext_15, + 12, 20, 44, 42, 58}; + gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); + + // Derived from IEEE 2.5.1 65-byte auth + uint8_t nonce_16[] = {0x7C, 0xFD, 0xE9, 0xF9, 0xE3, 0x37, + 0x24, 0xC6, 0x89, 0x32, 0xD6, 0x12}; + uint8_t aad_16[] = { + 0x84, 0xC5, 0xD5, 0x13, 0xD2, 0xAA, 0xF6, 0xE5, 0xBB, 0xD2, 0x72, 0x77, + 0x88, 0xE5, 0x23, 0x0, 0x89, 0x32, 0xD6, 0x12, 0x7C, 0xFD, 0xE9, 0xF9, + 0xE3, 0x37, 0x24, 0xC6, 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, + 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, + 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x0, 0x5}; + uint8_t key_16[] = {0x1, 0x3F, 0xE0, 0xB, 0x5F, 0x11, 0xBE, 0x7F, 0x86, + 0x6D, 0xC, 0xBB, 0xC5, 0x5A, 0x7A, 0x90, 0x0, 0x3E, + 0xE1, 0xA, 0x5E, 0x10, 0xBF, 0x7E, 0x87, 0x6C, 0xD, + 0xBA, 0xC4, 0x5B, 0x7B, 0x91, 0x3, 0x3D, 0xE2, 0x9, + 0x5D, 0x13, 0xBC, 0x7D, 0x84, 0x6F, 0xE, 0xB9}; + uint8_t plaintext_16[1] = {}; + uint8_t ciphertext_16[] = {0xCC, 0xA2, 0xE, 0xEC, 0xDA, 0x62, 0x83, 0xF0, + 0x9B, 0xB3, 0x54, 0x3D, 0xD9, 0x9E, 0xDB, 0x9B}; + vec = {nonce_16, aad_16, key_16, plaintext_16, ciphertext_16, 12, 81, + 44, 0, 16}; + gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); + + // Derived from IEEE 2.5.2 65-byte auth + uint8_t nonce_17[] = {0x7C, 0xFD, 0xE9, 0xF9, 0xE3, 0x37, + 0x24, 0xC6, 0x89, 0x32, 0xD6, 0x12}; + uint8_t aad_17[] = { + 0x84, 0xC5, 0xD5, 0x13, 0xD2, 0xAA, 0xF6, 0xE5, 0xBB, 0xD2, 0x72, 0x77, + 0x88, 0xE5, 0x23, 0x0, 0x89, 0x32, 0xD6, 0x12, 0x7C, 0xFD, 0xE9, 0xF9, + 0xE3, 0x37, 0x24, 0xC6, 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, + 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, + 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x0, 0x5}; + uint8_t key_17[] = {0x83, 0xC0, 0x93, 0xB5, 0x8D, 0xE7, 0xFF, 0xE1, 0xC0, + 0xDA, 0x92, 0x6A, 0xC4, 0x3F, 0xB3, 0x60, 0x9A, 0xC1, + 0xC8, 0xF, 0xEE, 0x1B, 0x62, 0x44, 0x97, 0xEF, 0x94, + 0x2E, 0x2F, 0x79, 0xA8, 0x23, 0x81, 0xC2, 0x91, 0xB7, + 0x8F, 0xE5, 0xFD, 0xE3, 0xC2, 0xD8, 0x90, 0x68}; + uint8_t plaintext_17[1] = {}; + uint8_t ciphertext_17[] = {0xB2, 0x32, 0xCC, 0x1D, 0xA5, 0x11, 0x7B, 0xF1, + 0x50, 0x3, 0x73, 0x4F, 0xA5, 0x99, 0xD2, 0x71}; + vec = {nonce_17, aad_17, key_17, plaintext_17, ciphertext_17, 12, 81, + 44, 0, 16}; + gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); + + // Derived from IEEE 2.6.1 61-byte crypt + uint8_t nonce_18[] = {0x7C, 0xFD, 0xE9, 0xF9, 0xE3, 0x37, + 0x24, 0xC6, 0x89, 0x32, 0xD6, 0x12}; + uint8_t aad_18[] = {0x84, 0xC5, 0xD5, 0x13, 0xD2, 0xAA, 0xF6, + 0xE5, 0xBB, 0xD2, 0x72, 0x77, 0x88, 0xE5, + 0x2F, 0x0, 0x89, 0x32, 0xD6, 0x12, 0x7C, + 0xFD, 0xE9, 0xF9, 0xE3, 0x37, 0x24, 0xC6}; + uint8_t key_18[] = {0x1, 0x3F, 0xE0, 0xB, 0x5F, 0x11, 0xBE, 0x7F, 0x86, + 0x6D, 0xC, 0xBB, 0xC5, 0x5A, 0x7A, 0x90, 0x0, 0x3E, + 0xE1, 0xA, 0x5E, 0x10, 0xBF, 0x7E, 0x87, 0x6C, 0xD, + 0xBA, 0xC4, 0x5B, 0x7B, 0x91, 0x3, 0x3D, 0xE2, 0x9, + 0x5D, 0x13, 0xBC, 0x7D, 0x84, 0x6F, 0xE, 0xB9}; + uint8_t plaintext_18[] = { + 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, + 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, + 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, + 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x0, 0x6}; + uint8_t ciphertext_18[] = { + 0xFF, 0x19, 0x10, 0xD3, 0x5A, 0xD7, 0xE5, 0x65, 0x78, 0x90, 0xC7, + 0xC5, 0x60, 0x14, 0x6F, 0xD0, 0x38, 0x70, 0x7F, 0x20, 0x4B, 0x66, + 0xED, 0xBC, 0x3D, 0x16, 0x1F, 0x8A, 0xCE, 0x24, 0x4B, 0x98, 0x59, + 0x21, 0x2, 0x3C, 0x43, 0x6E, 0x3A, 0x1C, 0x35, 0x32, 0xEC, 0xD5, + 0xD0, 0x9A, 0x5, 0x6D, 0x70, 0xBE, 0x58, 0x3F, 0xD, 0x10, 0x82, + 0x9D, 0x93, 0x87, 0xD0, 0x7D, 0x33, 0xD8, 0x72, 0xE4, 0x90}; + vec = {nonce_18, aad_18, key_18, plaintext_18, ciphertext_18, + 12, 28, 44, 49, 65}; + gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); + + // Derived from IEEE 2.6.2 61-byte crypt + uint8_t nonce_19[] = {0x7C, 0xFD, 0xE9, 0xF9, 0xE3, 0x37, + 0x24, 0xC6, 0x89, 0x32, 0xD6, 0x12}; + uint8_t aad_19[] = {0x84, 0xC5, 0xD5, 0x13, 0xD2, 0xAA, 0xF6, + 0xE5, 0xBB, 0xD2, 0x72, 0x77, 0x88, 0xE5, + 0x2F, 0x0, 0x89, 0x32, 0xD6, 0x12, 0x7C, + 0xFD, 0xE9, 0xF9, 0xE3, 0x37, 0x24, 0xC6}; + uint8_t key_19[] = {0x83, 0xC0, 0x93, 0xB5, 0x8D, 0xE7, 0xFF, 0xE1, 0xC0, + 0xDA, 0x92, 0x6A, 0xC4, 0x3F, 0xB3, 0x60, 0x9A, 0xC1, + 0xC8, 0xF, 0xEE, 0x1B, 0x62, 0x44, 0x97, 0xEF, 0x94, + 0x2E, 0x2F, 0x79, 0xA8, 0x23, 0x81, 0xC2, 0x91, 0xB7, + 0x8F, 0xE5, 0xFD, 0xE3, 0xC2, 0xD8, 0x90, 0x68}; + uint8_t plaintext_19[] = { + 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, + 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, + 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, + 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x0, 0x6}; + uint8_t ciphertext_19[] = { + 0xD, 0xB4, 0xCF, 0x95, 0x6B, 0x5F, 0x97, 0xEC, 0xA4, 0xEA, 0xB8, + 0x2A, 0x69, 0x55, 0x30, 0x7F, 0x9A, 0xE0, 0x2A, 0x32, 0xDD, 0x7D, + 0x93, 0xF8, 0x3D, 0x66, 0xAD, 0x4, 0xE1, 0xCF, 0xDC, 0x51, 0x82, + 0xAD, 0x12, 0xAB, 0xDE, 0xA5, 0xBB, 0xB6, 0x19, 0xA1, 0xBD, 0x5F, + 0xB9, 0xA5, 0x73, 0x59, 0xF, 0xBA, 0x90, 0x8E, 0x9C, 0x7A, 0x46, + 0xC1, 0xF7, 0xBA, 0x9, 0x5, 0xD1, 0xB5, 0x5F, 0xFD, 0xA4}; + vec = {nonce_19, aad_19, key_19, plaintext_19, ciphertext_19, + 12, 28, 44, 49, 65}; + gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); + + // Derived from IEEE 2.7.1 79-byte crypt + uint8_t nonce_20[] = {0x7A, 0xE8, 0xE2, 0xCA, 0x4E, 0xC5, + 0x0, 0x1, 0x2E, 0x58, 0x49, 0x5C}; + uint8_t aad_20[] = { + 0x68, 0xF2, 0xE7, 0x76, 0x96, 0xCE, 0x7A, 0xE8, 0xE2, 0xCA, 0x4E, + 0xC5, 0x88, 0xE5, 0x41, 0x0, 0x2E, 0x58, 0x49, 0x5C, 0x8, 0x0, + 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, + 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, + 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, + 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, + 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x0, 0x7}; + uint8_t key_20[] = {0x88, 0xEE, 0x8, 0x7F, 0xD9, 0x5D, 0xA9, 0xFB, 0xF6, + 0x72, 0x5A, 0xA9, 0xD7, 0x57, 0xB0, 0xCD, 0x89, 0xEF, + 0x9, 0x7E, 0xD8, 0x5C, 0xA8, 0xFA, 0xF7, 0x73, 0x5B, + 0xA8, 0xD6, 0x56, 0xB1, 0xCC, 0x8A, 0xEC, 0xA, 0x7D, + 0xDB, 0x5F, 0xAB, 0xF9, 0xF4, 0x70, 0x58, 0xAB}; + uint8_t plaintext_20[1] = {}; + uint8_t ciphertext_20[] = {0x81, 0x3F, 0xE, 0x63, 0xF, 0x96, 0xFB, 0x2D, + 0x3, 0xF, 0x58, 0xD8, 0x3F, 0x5C, 0xDF, 0xD0}; + vec = {nonce_20, aad_20, key_20, plaintext_20, ciphertext_20, 12, 87, + 44, 0, 16}; + gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); + + // Derived from IEEE 2.7.2 79-byte crypt + uint8_t nonce_21[] = {0x7A, 0xE8, 0xE2, 0xCA, 0x4E, 0xC5, + 0x0, 0x1, 0x2E, 0x58, 0x49, 0x5C}; + uint8_t aad_21[] = { + 0x68, 0xF2, 0xE7, 0x76, 0x96, 0xCE, 0x7A, 0xE8, 0xE2, 0xCA, 0x4E, + 0xC5, 0x88, 0xE5, 0x41, 0x0, 0x2E, 0x58, 0x49, 0x5C, 0x8, 0x0, + 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, + 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, + 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, + 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, + 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x0, 0x7}; + uint8_t key_21[] = {0x4C, 0x97, 0x3D, 0xBC, 0x73, 0x64, 0x62, 0x16, 0x74, + 0xF8, 0xB5, 0xB8, 0x9E, 0x5C, 0x15, 0x51, 0x1F, 0xCE, + 0xD9, 0x21, 0x64, 0x90, 0xFB, 0x1C, 0x1A, 0x2C, 0xAA, + 0xF, 0xFE, 0x4, 0x7, 0xE5, 0x4E, 0x95, 0x3F, 0xBE, + 0x71, 0x66, 0x60, 0x14, 0x76, 0xFA, 0xB7, 0xBA}; + uint8_t plaintext_21[1] = {}; + uint8_t ciphertext_21[] = {0x77, 0xE5, 0xA4, 0x4C, 0x21, 0xEB, 0x7, 0x18, + 0x8A, 0xAC, 0xBD, 0x74, 0xD1, 0x98, 0xE, 0x97}; + vec = {nonce_21, aad_21, key_21, plaintext_21, ciphertext_21, 12, 87, + 44, 0, 16}; + gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); + + // Derived from IEEE 2.8.1 61-byte crypt + uint8_t nonce_22[] = {0x7A, 0xE8, 0xE2, 0xCA, 0x4E, 0xC5, + 0x0, 0x1, 0x2E, 0x58, 0x49, 0x5C}; + uint8_t aad_22[] = {0x68, 0xF2, 0xE7, 0x76, 0x96, 0xCE, 0x7A, + 0xE8, 0xE2, 0xCA, 0x4E, 0xC5, 0x88, 0xE5, + 0x4D, 0x0, 0x2E, 0x58, 0x49, 0x5C}; + uint8_t key_22[] = {0x88, 0xEE, 0x8, 0x7F, 0xD9, 0x5D, 0xA9, 0xFB, 0xF6, + 0x72, 0x5A, 0xA9, 0xD7, 0x57, 0xB0, 0xCD, 0x89, 0xEF, + 0x9, 0x7E, 0xD8, 0x5C, 0xA8, 0xFA, 0xF7, 0x73, 0x5B, + 0xA8, 0xD6, 0x56, 0xB1, 0xCC, 0x8A, 0xEC, 0xA, 0x7D, + 0xDB, 0x5F, 0xAB, 0xF9, 0xF4, 0x70, 0x58, 0xAB}; + uint8_t plaintext_22[] = { + 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, + 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, + 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, + 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, + 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x0, 0x8}; + uint8_t ciphertext_22[] = { + 0x95, 0x8E, 0xC3, 0xF6, 0xD6, 0xA, 0xFE, 0xDA, 0x99, 0xEF, 0xD8, 0x88, + 0xF1, 0x75, 0xE5, 0xFC, 0xD4, 0xC8, 0x7B, 0x9B, 0xCC, 0x5C, 0x2F, 0x54, + 0x26, 0x25, 0x3A, 0x8B, 0x50, 0x62, 0x96, 0xC8, 0xC4, 0x33, 0x9, 0xAB, + 0x2A, 0xDB, 0x59, 0x39, 0x46, 0x25, 0x41, 0xD9, 0x5E, 0x80, 0x81, 0x1E, + 0x4, 0xE7, 0x6, 0xB1, 0x49, 0x8F, 0x2C, 0x40, 0x7C, 0x7F, 0xB2, 0x34, + 0xF8, 0xCC, 0x1, 0xA6, 0x47, 0x55, 0xE, 0xE6, 0xB5, 0x57, 0xB3, 0x5A, + 0x7E, 0x39, 0x45, 0x38, 0x18, 0x21, 0xF4}; + vec = {nonce_22, aad_22, key_22, plaintext_22, ciphertext_22, + 12, 20, 44, 63, 79}; + gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); + + // Derived from IEEE 2.8.2 61-byte crypt + uint8_t nonce_23[] = {0x7A, 0xE8, 0xE2, 0xCA, 0x4E, 0xC5, + 0x0, 0x1, 0x2E, 0x58, 0x49, 0x5C}; + uint8_t aad_23[] = {0x68, 0xF2, 0xE7, 0x76, 0x96, 0xCE, 0x7A, + 0xE8, 0xE2, 0xCA, 0x4E, 0xC5, 0x88, 0xE5, + 0x4D, 0x0, 0x2E, 0x58, 0x49, 0x5C}; + uint8_t key_23[] = {0x4C, 0x97, 0x3D, 0xBC, 0x73, 0x64, 0x62, 0x16, 0x74, + 0xF8, 0xB5, 0xB8, 0x9E, 0x5C, 0x15, 0x51, 0x1F, 0xCE, + 0xD9, 0x21, 0x64, 0x90, 0xFB, 0x1C, 0x1A, 0x2C, 0xAA, + 0xF, 0xFE, 0x4, 0x7, 0xE5, 0x4E, 0x95, 0x3F, 0xBE, + 0x71, 0x66, 0x60, 0x14, 0x76, 0xFA, 0xB7, 0xBA}; + uint8_t plaintext_23[] = { + 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, + 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, + 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, + 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, + 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x0, 0x8}; + uint8_t ciphertext_23[] = { + 0xB4, 0x4D, 0x7, 0x20, 0x11, 0xCD, 0x36, 0xD2, 0x72, 0xA9, 0xB7, 0xA9, + 0x8D, 0xB9, 0xAA, 0x90, 0xCB, 0xC5, 0xC6, 0x7B, 0x93, 0xDD, 0xCE, 0x67, + 0xC8, 0x54, 0x50, 0x32, 0x14, 0xE2, 0xE8, 0x96, 0xEC, 0x7E, 0x9D, 0xB6, + 0x49, 0xED, 0x4B, 0xCF, 0x6F, 0x85, 0xA, 0xAC, 0x2, 0x23, 0xD0, 0xCF, + 0x92, 0xC8, 0x3D, 0xB8, 0x7, 0x95, 0xC3, 0xA1, 0x7E, 0xCC, 0x12, 0x48, + 0xBB, 0x0, 0x59, 0x17, 0x12, 0xB1, 0xAE, 0x71, 0xE2, 0x68, 0x16, 0x41, + 0x96, 0x25, 0x21, 0x62, 0x81, 0xB, 0x0}; + vec = {nonce_23, aad_23, key_23, plaintext_23, ciphertext_23, + 12, 20, 44, 63, 79}; + gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true); +} + +static void gsec_test_do_vector_tests_nist() { + /** + * From: + * http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/ + * gcm-revised-spec.pdf + */ + + /* Test vector 1 */ + gsec_aead_test_vector* test_vector_1; + const uint8_t test_vector_1_key[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00}; + const uint8_t test_vector_1_nonce[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + const uint8_t test_vector_1_aad[1] = {}; + const uint8_t test_vector_1_plaintext[1] = {}; + const uint8_t test_vector_1_ciphertext_and_tag[] = { + 0x58, 0xe2, 0xfc, 0xce, 0xfa, 0x7e, 0x30, 0x61, + 0x36, 0x7f, 0x1d, 0x57, 0xa4, 0xe7, 0x45, 0x5a}; + gsec_aead_malloc_test_vector( + &test_vector_1, test_vector_1_key, + sizeof(test_vector_1_key) / sizeof(uint8_t), test_vector_1_nonce, + sizeof(test_vector_1_nonce) / sizeof(uint8_t), test_vector_1_aad, 0, + test_vector_1_plaintext, 0, test_vector_1_ciphertext_and_tag, + sizeof(test_vector_1_ciphertext_and_tag) / sizeof(uint8_t)); + gsec_test_verify_crypter_on_test_vector(test_vector_1); + gsec_aead_free_test_vector(test_vector_1); + + /* Test vector 2 */ + gsec_aead_test_vector* test_vector_2; + const uint8_t test_vector_2_key[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00}; + const uint8_t test_vector_2_nonce[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + const uint8_t test_vector_2_aad[1] = {}; + const uint8_t test_vector_2_plaintext[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00}; + const uint8_t test_vector_2_ciphertext_and_tag[] = { + 0x03, 0x88, 0xda, 0xce, 0x60, 0xb6, 0xa3, 0x92, 0xf3, 0x28, 0xc2, + 0xb9, 0x71, 0xb2, 0xfe, 0x78, 0xab, 0x6e, 0x47, 0xd4, 0x2c, 0xec, + 0x13, 0xbd, 0xf5, 0x3a, 0x67, 0xb2, 0x12, 0x57, 0xbd, 0xdf}; + gsec_aead_malloc_test_vector( + &test_vector_2, test_vector_2_key, + sizeof(test_vector_2_key) / sizeof(uint8_t), test_vector_2_nonce, + sizeof(test_vector_2_nonce) / sizeof(uint8_t), test_vector_2_aad, 0, + test_vector_2_plaintext, + sizeof(test_vector_2_plaintext) / sizeof(uint8_t), + test_vector_2_ciphertext_and_tag, + sizeof(test_vector_2_ciphertext_and_tag) / sizeof(uint8_t)); + gsec_test_verify_crypter_on_test_vector(test_vector_2); + gsec_aead_free_test_vector(test_vector_2); + + /* Test vector 3 */ + gsec_aead_test_vector* test_vector_3; + const uint8_t test_vector_3_key[] = {0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, + 0x73, 0x1c, 0x6d, 0x6a, 0x8f, 0x94, + 0x67, 0x30, 0x83, 0x08}; + const uint8_t test_vector_3_nonce[] = {0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, + 0xdb, 0xad, 0xde, 0xca, 0xf8, 0x88}; + const uint8_t test_vector_3_aad[1] = {}; + const uint8_t test_vector_3_plaintext[] = { + 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, 0xa5, 0x59, 0x09, + 0xc5, 0xaf, 0xf5, 0x26, 0x9a, 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, + 0xf7, 0xda, 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, 0x1c, + 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, 0x2f, 0xcf, 0x0e, 0x24, + 0x49, 0xa6, 0xb5, 0x25, 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, + 0x57, 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55}; + const uint8_t test_vector_3_ciphertext_and_tag[] = { + 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24, 0x4b, 0x72, 0x21, 0xb7, + 0x84, 0xd0, 0xd4, 0x9c, 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0, + 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e, 0x21, 0xd5, 0x14, 0xb2, + 0x54, 0x66, 0x93, 0x1c, 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05, + 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97, 0x3d, 0x58, 0xe0, 0x91, + 0x47, 0x3f, 0x59, 0x85, 0x4d, 0x5c, 0x2a, 0xf3, 0x27, 0xcd, 0x64, 0xa6, + 0x2c, 0xf3, 0x5a, 0xbd, 0x2b, 0xa6, 0xfa, 0xb4}; + gsec_aead_malloc_test_vector( + &test_vector_3, test_vector_3_key, + sizeof(test_vector_3_key) / sizeof(uint8_t), test_vector_3_nonce, + sizeof(test_vector_3_nonce) / sizeof(uint8_t), test_vector_3_aad, 0, + test_vector_3_plaintext, + sizeof(test_vector_3_plaintext) / sizeof(uint8_t), + test_vector_3_ciphertext_and_tag, + sizeof(test_vector_3_ciphertext_and_tag) / sizeof(uint8_t)); + gsec_test_verify_crypter_on_test_vector(test_vector_3); + gsec_aead_free_test_vector(test_vector_3); + + /* Test vector 4 */ + gsec_aead_test_vector* test_vector_4; + const uint8_t test_vector_4_key[] = {0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, + 0x73, 0x1c, 0x6d, 0x6a, 0x8f, 0x94, + 0x67, 0x30, 0x83, 0x08}; + const uint8_t test_vector_4_nonce[] = {0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, + 0xdb, 0xad, 0xde, 0xca, 0xf8, 0x88}; + const uint8_t test_vector_4_aad[] = {0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, + 0xef, 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, + 0xbe, 0xef, 0xab, 0xad, 0xda, 0xd2}; + const uint8_t test_vector_4_plaintext[] = { + 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, 0xa5, 0x59, 0x09, 0xc5, + 0xaf, 0xf5, 0x26, 0x9a, 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, + 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, 0x1c, 0x3c, 0x0c, 0x95, + 0x95, 0x68, 0x09, 0x53, 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, + 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, 0xba, 0x63, 0x7b, 0x39}; + const uint8_t test_vector_4_ciphertext_and_tag[] = { + 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24, 0x4b, 0x72, 0x21, + 0xb7, 0x84, 0xd0, 0xd4, 0x9c, 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, + 0xa4, 0xe0, 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e, 0x21, + 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c, 0x7d, 0x8f, 0x6a, 0x5a, + 0xac, 0x84, 0xaa, 0x05, 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, + 0x97, 0x3d, 0x58, 0xe0, 0x91, 0x5b, 0xc9, 0x4f, 0xbc, 0x32, 0x21, + 0xa5, 0xdb, 0x94, 0xfa, 0xe9, 0x5a, 0xe7, 0x12, 0x1a, 0x47}; + gsec_aead_malloc_test_vector( + &test_vector_4, test_vector_4_key, + sizeof(test_vector_4_key) / sizeof(uint8_t), test_vector_4_nonce, + sizeof(test_vector_4_nonce) / sizeof(uint8_t), test_vector_4_aad, + sizeof(test_vector_4_aad) / sizeof(uint8_t), test_vector_4_plaintext, + sizeof(test_vector_4_plaintext) / sizeof(uint8_t), + test_vector_4_ciphertext_and_tag, + sizeof(test_vector_4_ciphertext_and_tag) / sizeof(uint8_t)); + gsec_test_verify_crypter_on_test_vector(test_vector_4); + gsec_aead_free_test_vector(test_vector_4); +} + +static void gsec_test_do_vector_tests_ieee() { + /** + * From: + * http://www.ieee802.org/1/files/public/docs2011/ + * bn-randall-test-vectors-0511-v1.pdf + */ + + /* 2.1.1 54-byte auth */ + gsec_aead_test_vector* test_vector_5; + const uint8_t test_vector_5_key[] = {0xad, 0x7a, 0x2b, 0xd0, 0x3e, 0xac, + 0x83, 0x5a, 0x6f, 0x62, 0x0f, 0xdc, + 0xb5, 0x06, 0xb3, 0x45}; + const uint8_t test_vector_5_nonce[] = {0x12, 0x15, 0x35, 0x24, 0xc0, 0x89, + 0x5e, 0x81, 0xb2, 0xc2, 0x84, 0x65}; + const uint8_t test_vector_5_aad[] = { + 0xd6, 0x09, 0xb1, 0xf0, 0x56, 0x63, 0x7a, 0x0d, 0x46, 0xdf, 0x99, 0x8d, + 0x88, 0xe5, 0x22, 0x2a, 0xb2, 0xc2, 0x84, 0x65, 0x12, 0x15, 0x35, 0x24, + 0xc0, 0x89, 0x5e, 0x81, 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, + 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, + 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x00, 0x01}; + const uint8_t test_vector_5_plaintext[1] = {}; + const uint8_t test_vector_5_ciphertext_and_tag[] = { + 0xf0, 0x94, 0x78, 0xa9, 0xb0, 0x90, 0x07, 0xd0, + 0x6f, 0x46, 0xe9, 0xb6, 0xa1, 0xda, 0x25, 0xdd}; + gsec_aead_malloc_test_vector( + &test_vector_5, test_vector_5_key, + sizeof(test_vector_5_key) / sizeof(uint8_t), test_vector_5_nonce, + sizeof(test_vector_5_nonce) / sizeof(uint8_t), test_vector_5_aad, + sizeof(test_vector_5_aad) / sizeof(uint8_t), test_vector_5_plaintext, 0, + test_vector_5_ciphertext_and_tag, + sizeof(test_vector_5_ciphertext_and_tag) / sizeof(uint8_t)); + gsec_test_verify_crypter_on_test_vector(test_vector_5); + gsec_aead_free_test_vector(test_vector_5); + + /* 2.1.2 54-byte auth */ + gsec_aead_test_vector* test_vector_6; + const uint8_t test_vector_6_key[] = { + 0xe3, 0xc0, 0x8a, 0x8f, 0x06, 0xc6, 0xe3, 0xad, 0x95, 0xa7, 0x05, + 0x57, 0xb2, 0x3f, 0x75, 0x48, 0x3c, 0xe3, 0x30, 0x21, 0xa9, 0xc7, + 0x2b, 0x70, 0x25, 0x66, 0x62, 0x04, 0xc6, 0x9c, 0x0b, 0x72}; + + const uint8_t test_vector_6_nonce[] = {0x12, 0x15, 0x35, 0x24, 0xc0, 0x89, + 0x5e, 0x81, 0xb2, 0xc2, 0x84, 0x65}; + const uint8_t test_vector_6_aad[] = { + 0xd6, 0x09, 0xb1, 0xf0, 0x56, 0x63, 0x7a, 0x0d, 0x46, 0xdf, 0x99, 0x8d, + 0x88, 0xe5, 0x22, 0x2a, 0xb2, 0xc2, 0x84, 0x65, 0x12, 0x15, 0x35, 0x24, + 0xc0, 0x89, 0x5e, 0x81, 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, + 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, + 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x00, 0x01}; + const uint8_t test_vector_6_plaintext[1] = {}; + const uint8_t test_vector_6_ciphertext_and_tag[] = { + 0x2f, 0x0b, 0xc5, 0xaf, 0x40, 0x9e, 0x06, 0xd6, + 0x09, 0xea, 0x8b, 0x7d, 0x0f, 0xa5, 0xea, 0x50}; + gsec_aead_malloc_test_vector( + &test_vector_6, test_vector_6_key, + sizeof(test_vector_6_key) / sizeof(uint8_t), test_vector_6_nonce, + sizeof(test_vector_6_nonce) / sizeof(uint8_t), test_vector_6_aad, + sizeof(test_vector_6_aad) / sizeof(uint8_t), test_vector_6_plaintext, 0, + test_vector_6_ciphertext_and_tag, + sizeof(test_vector_6_ciphertext_and_tag) / sizeof(uint8_t)); + gsec_test_verify_crypter_on_test_vector(test_vector_6); + gsec_aead_free_test_vector(test_vector_6); + + /* 2.2.1 60-byte crypt */ + gsec_aead_test_vector* test_vector_7; + const uint8_t test_vector_7_key[] = {0xad, 0x7a, 0x2b, 0xd0, 0x3e, 0xac, + 0x83, 0x5a, 0x6f, 0x62, 0x0f, 0xdc, + 0xb5, 0x06, 0xb3, 0x45}; + + const uint8_t test_vector_7_nonce[] = {0x12, 0x15, 0x35, 0x24, 0xc0, 0x89, + 0x5e, 0x81, 0xb2, 0xc2, 0x84, 0x65}; + const uint8_t test_vector_7_aad[] = { + 0xd6, 0x09, 0xb1, 0xf0, 0x56, 0x63, 0x7a, 0x0d, 0x46, 0xdf, + 0x99, 0x8d, 0x88, 0xe5, 0x2e, 0x00, 0xb2, 0xc2, 0x84, 0x65, + 0x12, 0x15, 0x35, 0x24, 0xc0, 0x89, 0x5e, 0x81}; + const uint8_t test_vector_7_plaintext[] = { + 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, + 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, + 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, + 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x00, 0x02}; + const uint8_t test_vector_7_ciphertext_and_tag[] = { + 0x70, 0x1a, 0xfa, 0x1c, 0xc0, 0x39, 0xc0, 0xd7, 0x65, 0x12, 0x8a, + 0x66, 0x5d, 0xab, 0x69, 0x24, 0x38, 0x99, 0xbf, 0x73, 0x18, 0xcc, + 0xdc, 0x81, 0xc9, 0x93, 0x1d, 0xa1, 0x7f, 0xbe, 0x8e, 0xdd, 0x7d, + 0x17, 0xcb, 0x8b, 0x4c, 0x26, 0xfc, 0x81, 0xe3, 0x28, 0x4f, 0x2b, + 0x7f, 0xba, 0x71, 0x3d, 0x4f, 0x8d, 0x55, 0xe7, 0xd3, 0xf0, 0x6f, + 0xd5, 0xa1, 0x3c, 0x0c, 0x29, 0xb9, 0xd5, 0xb8, 0x80}; + gsec_aead_malloc_test_vector( + &test_vector_7, test_vector_7_key, + sizeof(test_vector_7_key) / sizeof(uint8_t), test_vector_7_nonce, + sizeof(test_vector_7_nonce) / sizeof(uint8_t), test_vector_7_aad, + sizeof(test_vector_7_aad) / sizeof(uint8_t), test_vector_7_plaintext, + sizeof(test_vector_7_plaintext) / sizeof(uint8_t), + test_vector_7_ciphertext_and_tag, + sizeof(test_vector_7_ciphertext_and_tag) / sizeof(uint8_t)); + gsec_test_verify_crypter_on_test_vector(test_vector_7); + gsec_aead_free_test_vector(test_vector_7); + + /* 2.2.2 60-byte crypt */ + gsec_aead_test_vector* test_vector_8; + const uint8_t test_vector_8_key[] = { + 0xe3, 0xc0, 0x8a, 0x8f, 0x06, 0xc6, 0xe3, 0xad, 0x95, 0xa7, 0x05, + 0x57, 0xb2, 0x3f, 0x75, 0x48, 0x3c, 0xe3, 0x30, 0x21, 0xa9, 0xc7, + 0x2b, 0x70, 0x25, 0x66, 0x62, 0x04, 0xc6, 0x9c, 0x0b, 0x72}; + const uint8_t test_vector_8_nonce[] = {0x12, 0x15, 0x35, 0x24, 0xc0, 0x89, + 0x5e, 0x81, 0xb2, 0xc2, 0x84, 0x65}; + const uint8_t test_vector_8_aad[] = { + 0xd6, 0x09, 0xb1, 0xf0, 0x56, 0x63, 0x7a, 0x0d, 0x46, 0xdf, + 0x99, 0x8d, 0x88, 0xe5, 0x2e, 0x00, 0xb2, 0xc2, 0x84, 0x65, + 0x12, 0x15, 0x35, 0x24, 0xc0, 0x89, 0x5e, 0x81}; + const uint8_t test_vector_8_plaintext[] = { + 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, + 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, + 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, + 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x00, 0x02}; + const uint8_t test_vector_8_ciphertext_and_tag[] = { + 0xe2, 0x00, 0x6e, 0xb4, 0x2f, 0x52, 0x77, 0x02, 0x2d, 0x9b, 0x19, + 0x92, 0x5b, 0xc4, 0x19, 0xd7, 0xa5, 0x92, 0x66, 0x6c, 0x92, 0x5f, + 0xe2, 0xef, 0x71, 0x8e, 0xb4, 0xe3, 0x08, 0xef, 0xea, 0xa7, 0xc5, + 0x27, 0x3b, 0x39, 0x41, 0x18, 0x86, 0x0a, 0x5b, 0xe2, 0xa9, 0x7f, + 0x56, 0xab, 0x78, 0x36, 0x5c, 0xa5, 0x97, 0xcd, 0xbb, 0x3e, 0xdb, + 0x8d, 0x1a, 0x11, 0x51, 0xea, 0x0a, 0xf7, 0xb4, 0x36}; + gsec_aead_malloc_test_vector( + &test_vector_8, test_vector_8_key, + sizeof(test_vector_8_key) / sizeof(uint8_t), test_vector_8_nonce, + sizeof(test_vector_8_nonce) / sizeof(uint8_t), test_vector_8_aad, + sizeof(test_vector_8_aad) / sizeof(uint8_t), test_vector_8_plaintext, + sizeof(test_vector_8_plaintext) / sizeof(uint8_t), + test_vector_8_ciphertext_and_tag, + sizeof(test_vector_8_ciphertext_and_tag) / sizeof(uint8_t)); + gsec_test_verify_crypter_on_test_vector(test_vector_8); + gsec_aead_free_test_vector(test_vector_8); + + /* 2.3.1 60-byte auth */ + gsec_aead_test_vector* test_vector_9; + const uint8_t test_vector_9_key[] = {0x07, 0x1b, 0x11, 0x3b, 0x0c, 0xa7, + 0x43, 0xfe, 0xcc, 0xcf, 0x3d, 0x05, + 0x1f, 0x73, 0x73, 0x82}; + const uint8_t test_vector_9_nonce[] = {0xf0, 0x76, 0x1e, 0x8d, 0xcd, 0x3d, + 0x00, 0x01, 0x76, 0xd4, 0x57, 0xed}; + const uint8_t test_vector_9_aad[] = { + 0xe2, 0x01, 0x06, 0xd7, 0xcd, 0x0d, 0xf0, 0x76, 0x1e, 0x8d, 0xcd, 0x3d, + 0x88, 0xe5, 0x40, 0x00, 0x76, 0xd4, 0x57, 0xed, 0x08, 0x00, 0x0f, 0x10, + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, + 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, + 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x00, 0x03}; + const uint8_t test_vector_9_plaintext[1] = {}; + const uint8_t test_vector_9_ciphertext_and_tag[] = { + 0x0c, 0x01, 0x7b, 0xc7, 0x3b, 0x22, 0x7d, 0xfc, + 0xc9, 0xba, 0xfa, 0x1c, 0x41, 0xac, 0xc3, 0x53}; + gsec_aead_malloc_test_vector( + &test_vector_9, test_vector_9_key, + sizeof(test_vector_9_key) / sizeof(uint8_t), test_vector_9_nonce, + sizeof(test_vector_9_nonce) / sizeof(uint8_t), test_vector_9_aad, + sizeof(test_vector_9_aad) / sizeof(uint8_t), test_vector_9_plaintext, 0, + test_vector_9_ciphertext_and_tag, + sizeof(test_vector_9_ciphertext_and_tag) / sizeof(uint8_t)); + gsec_test_verify_crypter_on_test_vector(test_vector_9); + gsec_aead_free_test_vector(test_vector_9); + + /* 2.3.2 60-byte auth */ + gsec_aead_test_vector* test_vector_10; + const uint8_t test_vector_10_key[] = { + 0x69, 0x1d, 0x3e, 0xe9, 0x09, 0xd7, 0xf5, 0x41, 0x67, 0xfd, 0x1c, + 0xa0, 0xb5, 0xd7, 0x69, 0x08, 0x1f, 0x2b, 0xde, 0x1a, 0xee, 0x65, + 0x5f, 0xdb, 0xab, 0x80, 0xbd, 0x52, 0x95, 0xae, 0x6b, 0xe7}; + const uint8_t test_vector_10_nonce[] = {0xf0, 0x76, 0x1e, 0x8d, 0xcd, 0x3d, + 0x00, 0x01, 0x76, 0xd4, 0x57, 0xed}; + const uint8_t test_vector_10_aad[] = { + 0xe2, 0x01, 0x06, 0xd7, 0xcd, 0x0d, 0xf0, 0x76, 0x1e, 0x8d, 0xcd, 0x3d, + 0x88, 0xe5, 0x40, 0x00, 0x76, 0xd4, 0x57, 0xed, 0x08, 0x00, 0x0f, 0x10, + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, + 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, + 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x00, 0x03}; + const uint8_t test_vector_10_plaintext[1] = {}; + const uint8_t test_vector_10_ciphertext_and_tag[] = { + 0x35, 0x21, 0x7c, 0x77, 0x4b, 0xbc, 0x31, 0xb6, + 0x31, 0x66, 0xbc, 0xf9, 0xd4, 0xab, 0xed, 0x07}; + gsec_aead_malloc_test_vector( + &test_vector_10, test_vector_10_key, + sizeof(test_vector_10_key) / sizeof(uint8_t), test_vector_10_nonce, + sizeof(test_vector_10_nonce) / sizeof(uint8_t), test_vector_10_aad, + sizeof(test_vector_10_aad) / sizeof(uint8_t), test_vector_10_plaintext, 0, + test_vector_10_ciphertext_and_tag, + sizeof(test_vector_10_ciphertext_and_tag) / sizeof(uint8_t)); + gsec_test_verify_crypter_on_test_vector(test_vector_10); + gsec_aead_free_test_vector(test_vector_10); + + /* 2.4.1 54-byte crypt */ + gsec_aead_test_vector* test_vector_11; + const uint8_t test_vector_11_key[] = {0x07, 0x1b, 0x11, 0x3b, 0x0c, 0xa7, + 0x43, 0xfe, 0xcc, 0xcf, 0x3d, 0x05, + 0x1f, 0x73, 0x73, 0x82}; + const uint8_t test_vector_11_nonce[] = {0xf0, 0x76, 0x1e, 0x8d, 0xcd, 0x3d, + 0x00, 0x01, 0x76, 0xd4, 0x57, 0xed}; + const uint8_t test_vector_11_aad[] = { + 0xe2, 0x01, 0x06, 0xd7, 0xcd, 0x0d, 0xf0, 0x76, 0x1e, 0x8d, + 0xcd, 0x3d, 0x88, 0xe5, 0x4c, 0x2a, 0x76, 0xd4, 0x57, 0xed}; + const uint8_t test_vector_11_plaintext[] = { + 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, + 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, + 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x00, 0x04}; + const uint8_t test_vector_11_ciphertext_and_tag[] = { + 0x13, 0xb4, 0xc7, 0x2b, 0x38, 0x9d, 0xc5, 0x01, 0x8e, 0x72, 0xa1, 0x71, + 0xdd, 0x85, 0xa5, 0xd3, 0x75, 0x22, 0x74, 0xd3, 0xa0, 0x19, 0xfb, 0xca, + 0xed, 0x09, 0xa4, 0x25, 0xcd, 0x9b, 0x2e, 0x1c, 0x9b, 0x72, 0xee, 0xe7, + 0xc9, 0xde, 0x7d, 0x52, 0xb3, 0xf3, 0xd6, 0xa5, 0x28, 0x4f, 0x4a, 0x6d, + 0x3f, 0xe2, 0x2a, 0x5d, 0x6c, 0x2b, 0x96, 0x04, 0x94, 0xc3}; + gsec_aead_malloc_test_vector( + &test_vector_11, test_vector_11_key, + sizeof(test_vector_11_key) / sizeof(uint8_t), test_vector_11_nonce, + sizeof(test_vector_11_nonce) / sizeof(uint8_t), test_vector_11_aad, + sizeof(test_vector_11_aad) / sizeof(uint8_t), test_vector_11_plaintext, + sizeof(test_vector_11_plaintext) / sizeof(uint8_t), + test_vector_11_ciphertext_and_tag, + sizeof(test_vector_11_ciphertext_and_tag) / sizeof(uint8_t)); + gsec_test_verify_crypter_on_test_vector(test_vector_11); + gsec_aead_free_test_vector(test_vector_11); + + /* 2.4.2 54-byte crypt */ + gsec_aead_test_vector* test_vector_12; + const uint8_t test_vector_12_key[] = { + 0x69, 0x1d, 0x3e, 0xe9, 0x09, 0xd7, 0xf5, 0x41, 0x67, 0xfd, 0x1c, + 0xa0, 0xb5, 0xd7, 0x69, 0x08, 0x1f, 0x2b, 0xde, 0x1a, 0xee, 0x65, + 0x5f, 0xdb, 0xab, 0x80, 0xbd, 0x52, 0x95, 0xae, 0x6b, 0xe7}; + const uint8_t test_vector_12_nonce[] = {0xf0, 0x76, 0x1e, 0x8d, 0xcd, 0x3d, + 0x00, 0x01, 0x76, 0xd4, 0x57, 0xed}; + const uint8_t test_vector_12_aad[] = { + 0xe2, 0x01, 0x06, 0xd7, 0xcd, 0x0d, 0xf0, 0x76, 0x1e, 0x8d, + 0xcd, 0x3d, 0x88, 0xe5, 0x4c, 0x2a, 0x76, 0xd4, 0x57, 0xed}; + const uint8_t test_vector_12_plaintext[] = { + 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, + 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, + 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x00, 0x04}; + const uint8_t test_vector_12_ciphertext_and_tag[] = { + 0xc1, 0x62, 0x3f, 0x55, 0x73, 0x0c, 0x93, 0x53, 0x30, 0x97, 0xad, 0xda, + 0xd2, 0x56, 0x64, 0x96, 0x61, 0x25, 0x35, 0x2b, 0x43, 0xad, 0xac, 0xbd, + 0x61, 0xc5, 0xef, 0x3a, 0xc9, 0x0b, 0x5b, 0xee, 0x92, 0x9c, 0xe4, 0x63, + 0x0e, 0xa7, 0x9f, 0x6c, 0xe5, 0x19, 0x12, 0xaf, 0x39, 0xc2, 0xd1, 0xfd, + 0xc2, 0x05, 0x1f, 0x8b, 0x7b, 0x3c, 0x9d, 0x39, 0x7e, 0xf2}; + gsec_aead_malloc_test_vector( + &test_vector_12, test_vector_12_key, + sizeof(test_vector_12_key) / sizeof(uint8_t), test_vector_12_nonce, + sizeof(test_vector_12_nonce) / sizeof(uint8_t), test_vector_12_aad, + sizeof(test_vector_12_aad) / sizeof(uint8_t), test_vector_12_plaintext, + sizeof(test_vector_12_plaintext) / sizeof(uint8_t), + test_vector_12_ciphertext_and_tag, + sizeof(test_vector_12_ciphertext_and_tag) / sizeof(uint8_t)); + gsec_test_verify_crypter_on_test_vector(test_vector_12); + gsec_aead_free_test_vector(test_vector_12); + + /* 2.5.1 65-byte auth */ + gsec_aead_test_vector* test_vector_13; + const uint8_t test_vector_13_key[] = {0x01, 0x3f, 0xe0, 0x0b, 0x5f, 0x11, + 0xbe, 0x7f, 0x86, 0x6d, 0x0c, 0xbb, + 0xc5, 0x5a, 0x7a, 0x90}; + const uint8_t test_vector_13_nonce[] = {0x7c, 0xfd, 0xe9, 0xf9, 0xe3, 0x37, + 0x24, 0xc6, 0x89, 0x32, 0xd6, 0x12}; + const uint8_t test_vector_13_aad[] = { + 0x84, 0xc5, 0xd5, 0x13, 0xd2, 0xaa, 0xf6, 0xe5, 0xbb, 0xd2, 0x72, 0x77, + 0x88, 0xe5, 0x23, 0x00, 0x89, 0x32, 0xd6, 0x12, 0x7c, 0xfd, 0xe9, 0xf9, + 0xe3, 0x37, 0x24, 0xc6, 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, + 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, + 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, + 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x00, 0x05}; + const uint8_t test_vector_13_plaintext[1] = {}; + const uint8_t test_vector_13_ciphertext_and_tag[] = { + 0x21, 0x78, 0x67, 0xe5, 0x0c, 0x2d, 0xad, 0x74, + 0xc2, 0x8c, 0x3b, 0x50, 0xab, 0xdf, 0x69, 0x5a}; + gsec_aead_malloc_test_vector( + &test_vector_13, test_vector_13_key, + sizeof(test_vector_13_key) / sizeof(uint8_t), test_vector_13_nonce, + sizeof(test_vector_13_nonce) / sizeof(uint8_t), test_vector_13_aad, + sizeof(test_vector_13_aad) / sizeof(uint8_t), test_vector_13_plaintext, 0, + test_vector_13_ciphertext_and_tag, + sizeof(test_vector_13_ciphertext_and_tag) / sizeof(uint8_t)); + gsec_test_verify_crypter_on_test_vector(test_vector_13); + gsec_aead_free_test_vector(test_vector_13); + + /* 2.5.2 65-byte auth */ + gsec_aead_test_vector* test_vector_14; + const uint8_t test_vector_14_key[] = { + 0x83, 0xc0, 0x93, 0xb5, 0x8d, 0xe7, 0xff, 0xe1, 0xc0, 0xda, 0x92, + 0x6a, 0xc4, 0x3f, 0xb3, 0x60, 0x9a, 0xc1, 0xc8, 0x0f, 0xee, 0x1b, + 0x62, 0x44, 0x97, 0xef, 0x94, 0x2e, 0x2f, 0x79, 0xa8, 0x23}; + const uint8_t test_vector_14_nonce[] = {0x7c, 0xfd, 0xe9, 0xf9, 0xe3, 0x37, + 0x24, 0xc6, 0x89, 0x32, 0xd6, 0x12}; + const uint8_t test_vector_14_aad[] = { + 0x84, 0xc5, 0xd5, 0x13, 0xd2, 0xaa, 0xf6, 0xe5, 0xbb, 0xd2, 0x72, 0x77, + 0x88, 0xe5, 0x23, 0x00, 0x89, 0x32, 0xd6, 0x12, 0x7c, 0xfd, 0xe9, 0xf9, + 0xe3, 0x37, 0x24, 0xc6, 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, + 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, + 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, + 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x00, 0x05}; + const uint8_t test_vector_14_plaintext[1] = {}; + const uint8_t test_vector_14_ciphertext_and_tag[] = { + 0x6e, 0xe1, 0x60, 0xe8, 0xfa, 0xec, 0xa4, 0xb3, + 0x6c, 0x86, 0xb2, 0x34, 0x92, 0x0c, 0xa9, 0x75}; + gsec_aead_malloc_test_vector( + &test_vector_14, test_vector_14_key, + sizeof(test_vector_14_key) / sizeof(uint8_t), test_vector_14_nonce, + sizeof(test_vector_14_nonce) / sizeof(uint8_t), test_vector_14_aad, + sizeof(test_vector_14_aad) / sizeof(uint8_t), test_vector_14_plaintext, 0, + test_vector_14_ciphertext_and_tag, + sizeof(test_vector_14_ciphertext_and_tag) / sizeof(uint8_t)); + gsec_test_verify_crypter_on_test_vector(test_vector_14); + gsec_aead_free_test_vector(test_vector_14); + + /* 2.6.1 61-byte crypt */ + gsec_aead_test_vector* test_vector_15; + const uint8_t test_vector_15_key[] = {0x01, 0x3f, 0xe0, 0x0b, 0x5f, 0x11, + 0xbe, 0x7f, 0x86, 0x6d, 0x0c, 0xbb, + 0xc5, 0x5a, 0x7a, 0x90}; + const uint8_t test_vector_15_nonce[] = {0x7c, 0xfd, 0xe9, 0xf9, 0xe3, 0x37, + 0x24, 0xc6, 0x89, 0x32, 0xd6, 0x12}; + const uint8_t test_vector_15_aad[] = { + 0x84, 0xc5, 0xd5, 0x13, 0xd2, 0xaa, 0xf6, 0xe5, 0xbb, 0xd2, + 0x72, 0x77, 0x88, 0xe5, 0x2f, 0x00, 0x89, 0x32, 0xd6, 0x12, + 0x7c, 0xfd, 0xe9, 0xf9, 0xe3, 0x37, 0x24, 0xc6}; + const uint8_t test_vector_15_plaintext[] = { + 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, + 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, + 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, + 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x00, 0x06}; + const uint8_t test_vector_15_ciphertext_and_tag[] = { + 0x3a, 0x4d, 0xe6, 0xfa, 0x32, 0x19, 0x10, 0x14, 0xdb, 0xb3, 0x03, + 0xd9, 0x2e, 0xe3, 0xa9, 0xe8, 0xa1, 0xb5, 0x99, 0xc1, 0x4d, 0x22, + 0xfb, 0x08, 0x00, 0x96, 0xe1, 0x38, 0x11, 0x81, 0x6a, 0x3c, 0x9c, + 0x9b, 0xcf, 0x7c, 0x1b, 0x9b, 0x96, 0xda, 0x80, 0x92, 0x04, 0xe2, + 0x9d, 0x0e, 0x2a, 0x76, 0x42, 0xbf, 0xd3, 0x10, 0xa4, 0x83, 0x7c, + 0x81, 0x6c, 0xcf, 0xa5, 0xac, 0x23, 0xab, 0x00, 0x39, 0x88}; + gsec_aead_malloc_test_vector( + &test_vector_15, test_vector_15_key, + sizeof(test_vector_15_key) / sizeof(uint8_t), test_vector_15_nonce, + sizeof(test_vector_15_nonce) / sizeof(uint8_t), test_vector_15_aad, + sizeof(test_vector_15_aad) / sizeof(uint8_t), test_vector_15_plaintext, + sizeof(test_vector_15_plaintext) / sizeof(uint8_t), + test_vector_15_ciphertext_and_tag, + sizeof(test_vector_15_ciphertext_and_tag) / sizeof(uint8_t)); + gsec_test_verify_crypter_on_test_vector(test_vector_15); + gsec_aead_free_test_vector(test_vector_15); + + /* 2.6.2 61-byte crypt */ + gsec_aead_test_vector* test_vector_16; + const uint8_t test_vector_16_key[] = { + 0x83, 0xc0, 0x93, 0xb5, 0x8d, 0xe7, 0xff, 0xe1, 0xc0, 0xda, 0x92, + 0x6a, 0xc4, 0x3f, 0xb3, 0x60, 0x9a, 0xc1, 0xc8, 0x0f, 0xee, 0x1b, + 0x62, 0x44, 0x97, 0xef, 0x94, 0x2e, 0x2f, 0x79, 0xa8, 0x23}; + const uint8_t test_vector_16_nonce[] = {0x7c, 0xfd, 0xe9, 0xf9, 0xe3, 0x37, + 0x24, 0xc6, 0x89, 0x32, 0xd6, 0x12}; + const uint8_t test_vector_16_aad[] = { + 0x84, 0xc5, 0xd5, 0x13, 0xd2, 0xaa, 0xf6, 0xe5, 0xbb, 0xd2, + 0x72, 0x77, 0x88, 0xe5, 0x2f, 0x00, 0x89, 0x32, 0xd6, 0x12, + 0x7c, 0xfd, 0xe9, 0xf9, 0xe3, 0x37, 0x24, 0xc6}; + const uint8_t test_vector_16_plaintext[] = { + 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, + 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, + 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, + 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x00, 0x06}; + const uint8_t test_vector_16_ciphertext_and_tag[] = { + 0x11, 0x02, 0x22, 0xff, 0x80, 0x50, 0xcb, 0xec, 0xe6, 0x6a, 0x81, + 0x3a, 0xd0, 0x9a, 0x73, 0xed, 0x7a, 0x9a, 0x08, 0x9c, 0x10, 0x6b, + 0x95, 0x93, 0x89, 0x16, 0x8e, 0xd6, 0xe8, 0x69, 0x8e, 0xa9, 0x02, + 0xeb, 0x12, 0x77, 0xdb, 0xec, 0x2e, 0x68, 0xe4, 0x73, 0x15, 0x5a, + 0x15, 0xa7, 0xda, 0xee, 0xd4, 0xa1, 0x0f, 0x4e, 0x05, 0x13, 0x9c, + 0x23, 0xdf, 0x00, 0xb3, 0xaa, 0xdc, 0x71, 0xf0, 0x59, 0x6a}; + gsec_aead_malloc_test_vector( + &test_vector_16, test_vector_16_key, + sizeof(test_vector_16_key) / sizeof(uint8_t), test_vector_16_nonce, + sizeof(test_vector_16_nonce) / sizeof(uint8_t), test_vector_16_aad, + sizeof(test_vector_16_aad) / sizeof(uint8_t), test_vector_16_plaintext, + sizeof(test_vector_16_plaintext) / sizeof(uint8_t), + test_vector_16_ciphertext_and_tag, + sizeof(test_vector_16_ciphertext_and_tag) / sizeof(uint8_t)); + gsec_test_verify_crypter_on_test_vector(test_vector_16); + gsec_aead_free_test_vector(test_vector_16); + + /* 2.7.1 79-byte crypt */ + gsec_aead_test_vector* test_vector_17; + const uint8_t test_vector_17_key[] = {0x88, 0xee, 0x08, 0x7f, 0xd9, 0x5d, + 0xa9, 0xfb, 0xf6, 0x72, 0x5a, 0xa9, + 0xd7, 0x57, 0xb0, 0xcd}; + const uint8_t test_vector_17_nonce[] = {0x7a, 0xe8, 0xe2, 0xca, 0x4e, 0xc5, + 0x00, 0x01, 0x2e, 0x58, 0x49, 0x5c}; + const uint8_t test_vector_17_aad[] = { + 0x68, 0xf2, 0xe7, 0x76, 0x96, 0xce, 0x7a, 0xe8, 0xe2, 0xca, 0x4e, + 0xc5, 0x88, 0xe5, 0x41, 0x00, 0x2e, 0x58, 0x49, 0x5c, 0x08, 0x00, + 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, + 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, + 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, + 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, + 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x00, 0x07}; + const uint8_t test_vector_17_plaintext[1] = {}; + const uint8_t test_vector_17_ciphertext_and_tag[] = { + 0x07, 0x92, 0x2b, 0x8e, 0xbc, 0xf1, 0x0b, 0xb2, + 0x29, 0x75, 0x88, 0xca, 0x4c, 0x61, 0x45, 0x23}; + gsec_aead_malloc_test_vector( + &test_vector_17, test_vector_17_key, + sizeof(test_vector_17_key) / sizeof(uint8_t), test_vector_17_nonce, + sizeof(test_vector_17_nonce) / sizeof(uint8_t), test_vector_17_aad, + sizeof(test_vector_17_aad) / sizeof(uint8_t), test_vector_17_plaintext, 0, + test_vector_17_ciphertext_and_tag, + sizeof(test_vector_17_ciphertext_and_tag) / sizeof(uint8_t)); + gsec_test_verify_crypter_on_test_vector(test_vector_17); + gsec_aead_free_test_vector(test_vector_17); + + /* 2.7.2 79-byte crypt */ + gsec_aead_test_vector* test_vector_18; + const uint8_t test_vector_18_key[] = { + 0x4c, 0x97, 0x3d, 0xbc, 0x73, 0x64, 0x62, 0x16, 0x74, 0xf8, 0xb5, + 0xb8, 0x9e, 0x5c, 0x15, 0x51, 0x1f, 0xce, 0xd9, 0x21, 0x64, 0x90, + 0xfb, 0x1c, 0x1a, 0x2c, 0xaa, 0x0f, 0xfe, 0x04, 0x07, 0xe5}; + const uint8_t test_vector_18_nonce[] = {0x7a, 0xe8, 0xe2, 0xca, 0x4e, 0xc5, + 0x00, 0x01, 0x2e, 0x58, 0x49, 0x5c}; + const uint8_t test_vector_18_aad[] = { + 0x68, 0xf2, 0xe7, 0x76, 0x96, 0xce, 0x7a, 0xe8, 0xe2, 0xca, 0x4e, + 0xc5, 0x88, 0xe5, 0x41, 0x00, 0x2e, 0x58, 0x49, 0x5c, 0x08, 0x00, + 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, + 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, + 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, + 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, + 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x00, 0x07}; + const uint8_t test_vector_18_plaintext[1] = {}; + const uint8_t test_vector_18_ciphertext_and_tag[] = { + 0x00, 0xbd, 0xa1, 0xb7, 0xe8, 0x76, 0x08, 0xbc, + 0xbf, 0x47, 0x0f, 0x12, 0x15, 0x7f, 0x4c, 0x07}; + gsec_aead_malloc_test_vector( + &test_vector_18, test_vector_18_key, + sizeof(test_vector_18_key) / sizeof(uint8_t), test_vector_18_nonce, + sizeof(test_vector_18_nonce) / sizeof(uint8_t), test_vector_18_aad, + sizeof(test_vector_18_aad) / sizeof(uint8_t), test_vector_18_plaintext, 0, + test_vector_18_ciphertext_and_tag, + sizeof(test_vector_18_ciphertext_and_tag) / sizeof(uint8_t)); + gsec_test_verify_crypter_on_test_vector(test_vector_18); + gsec_aead_free_test_vector(test_vector_18); + + /* 2.8.1 61-byte crypt */ + gsec_aead_test_vector* test_vector_19; + const uint8_t test_vector_19_key[] = {0x88, 0xee, 0x08, 0x7f, 0xd9, 0x5d, + 0xa9, 0xfb, 0xf6, 0x72, 0x5a, 0xa9, + 0xd7, 0x57, 0xb0, 0xcd}; + const uint8_t test_vector_19_nonce[] = {0x7a, 0xe8, 0xe2, 0xca, 0x4e, 0xc5, + 0x00, 0x01, 0x2e, 0x58, 0x49, 0x5c}; + const uint8_t test_vector_19_aad[] = { + 0x68, 0xf2, 0xe7, 0x76, 0x96, 0xce, 0x7a, 0xe8, 0xe2, 0xca, + 0x4e, 0xc5, 0x88, 0xe5, 0x4d, 0x00, 0x2e, 0x58, 0x49, 0x5c}; + const uint8_t test_vector_19_plaintext[] = { + 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, + 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, + 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, + 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, + 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x00, 0x08}; + const uint8_t test_vector_19_ciphertext_and_tag[] = { + 0xc3, 0x1f, 0x53, 0xd9, 0x9e, 0x56, 0x87, 0xf7, 0x36, 0x51, 0x19, 0xb8, + 0x32, 0xd2, 0xaa, 0xe7, 0x07, 0x41, 0xd5, 0x93, 0xf1, 0xf9, 0xe2, 0xab, + 0x34, 0x55, 0x77, 0x9b, 0x07, 0x8e, 0xb8, 0xfe, 0xac, 0xdf, 0xec, 0x1f, + 0x8e, 0x3e, 0x52, 0x77, 0xf8, 0x18, 0x0b, 0x43, 0x36, 0x1f, 0x65, 0x12, + 0xad, 0xb1, 0x6d, 0x2e, 0x38, 0x54, 0x8a, 0x2c, 0x71, 0x9d, 0xba, 0x72, + 0x28, 0xd8, 0x40, 0x88, 0xf8, 0x75, 0x7a, 0xdb, 0x8a, 0xa7, 0x88, 0xd8, + 0xf6, 0x5a, 0xd6, 0x68, 0xbe, 0x70, 0xe7}; + gsec_aead_malloc_test_vector( + &test_vector_19, test_vector_19_key, + sizeof(test_vector_19_key) / sizeof(uint8_t), test_vector_19_nonce, + sizeof(test_vector_19_nonce) / sizeof(uint8_t), test_vector_19_aad, + sizeof(test_vector_19_aad) / sizeof(uint8_t), test_vector_19_plaintext, + sizeof(test_vector_19_plaintext) / sizeof(uint8_t), + test_vector_19_ciphertext_and_tag, + sizeof(test_vector_19_ciphertext_and_tag) / sizeof(uint8_t)); + gsec_test_verify_crypter_on_test_vector(test_vector_19); + gsec_aead_free_test_vector(test_vector_19); + + /* 2.8.2 61-byte crypt */ + gsec_aead_test_vector* test_vector_20; + const uint8_t test_vector_20_key[] = { + 0x4c, 0x97, 0x3d, 0xbc, 0x73, 0x64, 0x62, 0x16, 0x74, 0xf8, 0xb5, + 0xb8, 0x9e, 0x5c, 0x15, 0x51, 0x1f, 0xce, 0xd9, 0x21, 0x64, 0x90, + 0xfb, 0x1c, 0x1a, 0x2c, 0xaa, 0x0f, 0xfe, 0x04, 0x07, 0xe5}; + const uint8_t test_vector_20_nonce[] = {0x7a, 0xe8, 0xe2, 0xca, 0x4e, 0xc5, + 0x00, 0x01, 0x2e, 0x58, 0x49, 0x5c}; + const uint8_t test_vector_20_aad[] = { + 0x68, 0xf2, 0xe7, 0x76, 0x96, 0xce, 0x7a, 0xe8, 0xe2, 0xca, + 0x4e, 0xc5, 0x88, 0xe5, 0x4d, 0x00, 0x2e, 0x58, 0x49, 0x5c}; + const uint8_t test_vector_20_plaintext[] = { + 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, + 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, + 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, + 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, + 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x00, 0x08}; + const uint8_t test_vector_20_ciphertext_and_tag[] = { + 0xba, 0x8a, 0xe3, 0x1b, 0xc5, 0x06, 0x48, 0x6d, 0x68, 0x73, 0xe4, 0xfc, + 0xe4, 0x60, 0xe7, 0xdc, 0x57, 0x59, 0x1f, 0xf0, 0x06, 0x11, 0xf3, 0x1c, + 0x38, 0x34, 0xfe, 0x1c, 0x04, 0xad, 0x80, 0xb6, 0x68, 0x03, 0xaf, 0xcf, + 0x5b, 0x27, 0xe6, 0x33, 0x3f, 0xa6, 0x7c, 0x99, 0xda, 0x47, 0xc2, 0xf0, + 0xce, 0xd6, 0x8d, 0x53, 0x1b, 0xd7, 0x41, 0xa9, 0x43, 0xcf, 0xf7, 0xa6, + 0x71, 0x3b, 0xd0, 0x26, 0x11, 0xcd, 0x7d, 0xaa, 0x01, 0xd6, 0x1c, 0x5c, + 0x88, 0x6d, 0xc1, 0xa8, 0x17, 0x01, 0x07}; + gsec_aead_malloc_test_vector( + &test_vector_20, test_vector_20_key, + sizeof(test_vector_20_key) / sizeof(uint8_t), test_vector_20_nonce, + sizeof(test_vector_20_nonce) / sizeof(uint8_t), test_vector_20_aad, + sizeof(test_vector_20_aad) / sizeof(uint8_t), test_vector_20_plaintext, + sizeof(test_vector_20_plaintext) / sizeof(uint8_t), + test_vector_20_ciphertext_and_tag, + sizeof(test_vector_20_ciphertext_and_tag) / sizeof(uint8_t)); + gsec_test_verify_crypter_on_test_vector(test_vector_20); + gsec_aead_free_test_vector(test_vector_20); +} + +int main(int argc, char** argv) { + grpc_init(); + gsec_test_do_generic_crypter_tests(); + gsec_test_do_vector_tests_nist(); + gsec_test_do_vector_tests_ieee(); + gsec_test_do_vector_tests_rekey_nist(); + gsec_test_do_vector_tests_rekey_ieee(); + grpc_shutdown(); + return 0; +} diff --git a/test/core/tsi/alts/crypt/gsec_test_util.cc b/test/core/tsi/alts/crypt/gsec_test_util.cc new file mode 100644 index 0000000000..c682fb8e4d --- /dev/null +++ b/test/core/tsi/alts/crypt/gsec_test_util.cc @@ -0,0 +1,89 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "test/core/tsi/alts/crypt/gsec_test_util.h" + +#include + +#include + +void gsec_test_random_bytes(uint8_t* bytes, size_t length) { + srand(time(nullptr)); + size_t ind; + for (ind = 0; ind < length; ind++) { + bytes[ind] = static_cast(rand() % 255 + 1); + } +} + +void gsec_test_random_array(uint8_t** bytes, size_t length) { + if (bytes != nullptr) { + *bytes = static_cast(gpr_malloc(length)); + gsec_test_random_bytes(*bytes, length); + } else { + fprintf(stderr, "bytes buffer is nullptr in gsec_test_random_array()."); + abort(); + } +} + +uint32_t gsec_test_bias_random_uint32(uint32_t max_length) { + uint32_t value; + gsec_test_random_bytes((uint8_t*)(&value), sizeof(value)); + return value % max_length; +} + +void gsec_test_copy(const uint8_t* src, uint8_t** des, size_t source_len) { + if (src != nullptr && des != nullptr) { + *des = static_cast(gpr_malloc(source_len)); + memcpy(*des, src, source_len); + } else { + fprintf(stderr, "Either src or des buffer is nullptr in gsec_test_copy()."); + abort(); + } +} + +void gsec_test_copy_and_alter_random_byte(const uint8_t* src, uint8_t** des, + size_t source_len) { + if (src != nullptr && des != nullptr) { + *des = static_cast(gpr_malloc(source_len)); + memcpy(*des, src, source_len); + uint32_t offset; + offset = gsec_test_bias_random_uint32(static_cast(source_len)); + (*(*des + offset))++; + } else { + fprintf(stderr, + "Either src or des is nullptr in " + "gsec_test_copy_and_alter_random_byte()."); + abort(); + } +} + +int gsec_test_expect_compare_code_and_substr(grpc_status_code status1, + grpc_status_code status2, + const char* msg1, + const char* msg2) { + int failure = 1; + if (status1 != status2) { + fprintf(stderr, "Status %d does not equal %d.\n", status1, status2); + failure = 0; + } + if (strstr(msg1, msg2) == nullptr) { + fprintf(stderr, "Status message <%s> does not contain <%s>.\n", msg1, msg2); + failure = 0; + } + return failure; +} diff --git a/test/core/tsi/alts/crypt/gsec_test_util.h b/test/core/tsi/alts/crypt/gsec_test_util.h new file mode 100644 index 0000000000..1bd780000f --- /dev/null +++ b/test/core/tsi/alts/crypt/gsec_test_util.h @@ -0,0 +1,89 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_TEST_CORE_TSI_ALTS_CRYPT_GSEC_TEST_UTIL_H_ +#define GRPC_TEST_CORE_TSI_ALTS_CRYPT_GSEC_TEST_UTIL_H_ + +#include +#include +#include +#include + +#include + +/** + * This method returns random bytes of certain length. + * + * - bytes: buffer to hold random bytes. + * - length: length of buffer to be populated. + */ +void gsec_test_random_bytes(uint8_t* bytes, size_t length); + +/** + * This method returns an array of random bytes. + * + * - bytes: array to hold random bytes. + * - length: length of array to be populated. + */ +void gsec_test_random_array(uint8_t** bytes, size_t length); + +/** + * This method returns a uint32 that's not quite uniformly random, but good + * enough for tests. + * + * - max_length: a max value the returned random number can choose. + */ +uint32_t gsec_test_bias_random_uint32(uint32_t max_length); + +/** + * This method copies data from a source to a destination buffer. + * + * - src: a source buffer. + * - des: a destination buffer. + * - length: the length of source buffer to be copied from its beginning. + */ +void gsec_test_copy(const uint8_t* src, uint8_t** des, size_t length); + +/** + * This method copies data from a source to a destination buffer, and flips one + * byte in the destination buffer randomly. + * + * - src: a source buffer. + * - des: a destination buffer. + * - length: the length of source buffer to be copied from its beginning. + */ +void gsec_test_copy_and_alter_random_byte(const uint8_t* src, uint8_t** des, + size_t source_len); + +/** + * This method compares two grpc_status_code values, and verifies if one string + * is a substring of the other. + * + * - status1: the first grpc_status_code to be compared. + * - status2: the second grpc_status_code to be compared. + * - msg1: a string to be scanned. + * - msg2: a small string to be searched within msg1. + * + * If both checks succeed, the method returns 1 and otherwise, it returns 0. + */ +int gsec_test_expect_compare_code_and_substr(grpc_status_code status1, + grpc_status_code status2, + const char* msg1, + const char* msg2); + +#endif // GRPC_TEST_CORE_TSI_ALTS_CRYPT_GSEC_TEST_UTIL_H_ */ diff --git a/test/core/tsi/alts/frame_protector/BUILD b/test/core/tsi/alts/frame_protector/BUILD new file mode 100644 index 0000000000..94c2ab3747 --- /dev/null +++ b/test/core/tsi/alts/frame_protector/BUILD @@ -0,0 +1,71 @@ +# Copyright 2018 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_package") + +licenses(["notice"]) # Apache v2 + +grpc_package(name = "frame_protector") + +grpc_cc_test( + name = "alts_counter_test", + srcs = ["alts_counter_test.cc"], + language = "C++", + deps = [ + "//:alts_frame_protector", + "//:gpr", + "//:grpc", + "//test/core/tsi/alts/crypt:alts_crypt_test_util", + ], +) + +grpc_cc_test( + name = "alts_crypter_test", + srcs = ["alts_crypter_test.cc"], + language = "C++", + deps = [ + "//:alts_frame_protector", + "//:gpr", + "//:grpc", + "//test/core/tsi/alts/crypt:alts_crypt_test_util", + ], +) + +grpc_cc_test( + name = "alts_frame_protector_test", + srcs = ["alts_frame_protector_test.cc"], + language = "C++", + deps = [ + "//:alts_frame_protector", + "//:gpr", + "//:grpc", + "//:tsi", + "//:tsi_interface", + "//test/core/tsi/alts/crypt:alts_crypt_test_util", + "//test/core/tsi:transport_security_test_lib", + ], +) + +grpc_cc_test( + name = "frame_handler_test", + srcs = ["frame_handler_test.cc"], + language = "C++", + deps = [ + "//:alts_frame_protector", + "//:gpr", + "//:gpr_base", + "//:grpc", + "//test/core/tsi/alts/crypt:alts_crypt_test_util", + ], +) diff --git a/test/core/tsi/alts/frame_protector/alts_counter_test.cc b/test/core/tsi/alts/frame_protector/alts_counter_test.cc new file mode 100644 index 0000000000..49ff82108b --- /dev/null +++ b/test/core/tsi/alts/frame_protector/alts_counter_test.cc @@ -0,0 +1,180 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include + +#include "src/core/tsi/alts/frame_protector/alts_counter.h" +#include "test/core/tsi/alts/crypt/gsec_test_util.h" + +const size_t kSmallCounterSize = 4; +const size_t kSmallOverflowSize = 1; +const size_t kGcmCounterSize = 12; +const size_t kGcmOverflowSize = 5; + +static bool do_bytes_represent_client(alts_counter* ctr, unsigned char* counter, + size_t size) { + return (ctr->counter[size - 1] & 0x80) == 0x80; +} + +static void alts_counter_test_input_sanity_check(size_t counter_size, + size_t overflow_size) { + alts_counter* ctr = nullptr; + char* error_details = nullptr; + + /* Input sanity check on alts_counter_create(). */ + /* Invalid counter size. */ + grpc_status_code status = + alts_counter_create(true, 0, overflow_size, &ctr, &error_details); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_details, + "counter_size is invalid.")); + gpr_free(error_details); + + /* Invalid overflow size. */ + status = alts_counter_create(true, counter_size, 0, &ctr, &error_details); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_details, + "overflow_size is invalid.")); + gpr_free(error_details); + + /* alts_counter is nullptr. */ + status = alts_counter_create(true, counter_size, overflow_size, nullptr, + &error_details); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_details, + "crypter_counter is nullptr.")); + gpr_free(error_details); + + status = alts_counter_create(true, counter_size, overflow_size, &ctr, + &error_details); + GPR_ASSERT(status == GRPC_STATUS_OK); + + /* Input sanity check on alts_counter_increment(). */ + /* crypter_counter is nullptr. */ + bool is_overflow = false; + status = alts_counter_increment(nullptr, &is_overflow, &error_details); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_details, + "crypter_counter is nullptr.")); + gpr_free(error_details); + /* is_overflow is nullptr. */ + status = alts_counter_increment(ctr, nullptr, &error_details); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_details, + "is_overflow is nullptr.")); + gpr_free(error_details); + alts_counter_destroy(ctr); +} + +static void alts_counter_test_overflow_full_range(bool is_client, + size_t counter_size, + size_t overflow_size) { + alts_counter* ctr = nullptr; + char* error_details = nullptr; + grpc_status_code status = alts_counter_create( + is_client, counter_size, overflow_size, &ctr, &error_details); + GPR_ASSERT(status == GRPC_STATUS_OK); + unsigned char* expected = + static_cast(gpr_zalloc(counter_size)); + if (is_client) { + expected[counter_size - 1] = 0x80; + } + /* Do a single iteration to ensure the counter is initialized as expected. */ + GPR_ASSERT(do_bytes_represent_client(ctr, alts_counter_get_counter(ctr), + counter_size) == is_client); + GPR_ASSERT(memcmp(alts_counter_get_counter(ctr), expected, counter_size) == + 0); + bool is_overflow = false; + GPR_ASSERT(alts_counter_increment(ctr, &is_overflow, &error_details) == + GRPC_STATUS_OK); + GPR_ASSERT(!is_overflow); + /** + * The counter can return 2^{overflow_size * 8} counters. The + * high-order bit is fixed to the client/server. The last call will yield a + * useable counter, but overflow the counter object. + */ + int iterations = 1 << (overflow_size * 8); + int ind = 1; + for (ind = 1; ind < iterations - 1; ind++) { + GPR_ASSERT(do_bytes_represent_client(ctr, alts_counter_get_counter(ctr), + counter_size) == is_client); + GPR_ASSERT(alts_counter_increment(ctr, &is_overflow, &error_details) == + GRPC_STATUS_OK); + GPR_ASSERT(!is_overflow); + } + GPR_ASSERT(do_bytes_represent_client(ctr, alts_counter_get_counter(ctr), + counter_size) == is_client); + GPR_ASSERT(alts_counter_increment(ctr, &is_overflow, &error_details) == + GRPC_STATUS_FAILED_PRECONDITION); + GPR_ASSERT(is_overflow); + gpr_free(expected); + alts_counter_destroy(ctr); +} + +/* Set the counter manually and make sure it overflows as expected. */ +static void alts_counter_test_overflow_single_increment(bool is_client, + size_t counter_size, + size_t overflow_size) { + alts_counter* ctr = nullptr; + char* error_details = nullptr; + grpc_status_code status = alts_counter_create( + is_client, counter_size, overflow_size, &ctr, &error_details); + GPR_ASSERT(status == GRPC_STATUS_OK); + unsigned char* expected = + static_cast(gpr_zalloc(counter_size)); + memset(expected, 0xFF, overflow_size); + expected[0] = 0xFE; + + if (is_client) { + expected[counter_size - 1] = 0x80; + } + memcpy(ctr->counter, expected, counter_size); + GPR_ASSERT(do_bytes_represent_client(ctr, alts_counter_get_counter(ctr), + counter_size) == is_client); + GPR_ASSERT(memcmp(expected, alts_counter_get_counter(ctr), counter_size) == + 0); + bool is_overflow = false; + GPR_ASSERT(alts_counter_increment(ctr, &is_overflow, &error_details) == + GRPC_STATUS_OK); + GPR_ASSERT(!is_overflow); + GPR_ASSERT(do_bytes_represent_client(ctr, alts_counter_get_counter(ctr), + counter_size) == is_client); + expected[0] = static_cast(expected[0] + 1); + GPR_ASSERT(memcmp(expected, alts_counter_get_counter(ctr), counter_size) == + 0); + GPR_ASSERT(alts_counter_increment(ctr, &is_overflow, &error_details) == + GRPC_STATUS_FAILED_PRECONDITION); + GPR_ASSERT(is_overflow); + gpr_free(expected); + alts_counter_destroy(ctr); +} + +int main(int argc, char** argv) { + alts_counter_test_input_sanity_check(kGcmCounterSize, kGcmOverflowSize); + alts_counter_test_overflow_full_range(true, kSmallCounterSize, + kSmallOverflowSize); + alts_counter_test_overflow_full_range(false, kSmallCounterSize, + kSmallOverflowSize); + alts_counter_test_overflow_single_increment(true, kGcmCounterSize, + kGcmOverflowSize); + alts_counter_test_overflow_single_increment(false, kGcmCounterSize, + kGcmOverflowSize); + + return 0; +} diff --git a/test/core/tsi/alts/frame_protector/alts_crypter_test.cc b/test/core/tsi/alts/frame_protector/alts_crypter_test.cc new file mode 100644 index 0000000000..0ad616bcd6 --- /dev/null +++ b/test/core/tsi/alts/frame_protector/alts_crypter_test.cc @@ -0,0 +1,493 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include + +#include +#include + +#include "src/core/tsi/alts/frame_protector/alts_crypter.h" +#include "test/core/tsi/alts/crypt/gsec_test_util.h" + +static void alts_crypter_test_random_seal_unseal(alts_crypter* server_seal, + alts_crypter* server_unseal, + alts_crypter* client_seal, + alts_crypter* client_unseal) { + size_t data_size = gsec_test_bias_random_uint32(1024) + 1; + size_t num_overhead_bytes = alts_crypter_num_overhead_bytes(server_seal); + size_t protected_data_size = data_size + num_overhead_bytes; + uint8_t* data_buffer = static_cast(gpr_malloc(protected_data_size)); + gsec_test_random_bytes(data_buffer, data_size); + uint8_t* duplicate_buffer = nullptr; + gsec_test_copy(data_buffer, &duplicate_buffer, data_size); + + /* Client seal and server unseal */ + size_t size = data_size; + grpc_status_code status = alts_crypter_process_in_place( + client_seal, data_buffer, protected_data_size, size, &size, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(size == protected_data_size); + status = alts_crypter_process_in_place( + server_unseal, data_buffer, protected_data_size, size, &size, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(memcmp(data_buffer, duplicate_buffer, data_size) == 0); + GPR_ASSERT(size == data_size); + /* Server seal and client unseal */ + status = alts_crypter_process_in_place( + server_seal, data_buffer, protected_data_size, size, &size, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(size == protected_data_size); + status = alts_crypter_process_in_place( + client_unseal, data_buffer, protected_data_size, size, &size, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(memcmp(data_buffer, duplicate_buffer, data_size) == 0); + GPR_ASSERT(size == data_size); + gpr_free(data_buffer); + gpr_free(duplicate_buffer); +} + +static void alts_crypter_test_multiple_random_seal_unseal( + alts_crypter* server_seal, alts_crypter* server_unseal, + alts_crypter* client_seal, alts_crypter* client_unseal) { + size_t data_size = gsec_test_bias_random_uint32(1024) + 1; + size_t num_overhead_bytes = alts_crypter_num_overhead_bytes(server_seal); + size_t protected_data_size = data_size + num_overhead_bytes; + + uint8_t* data_buffer1 = + static_cast(gpr_malloc(protected_data_size)); + uint8_t* data_buffer2 = + static_cast(gpr_malloc(protected_data_size)); + uint8_t* duplicate_buffer1 = nullptr; + uint8_t* duplicate_buffer2 = nullptr; + gsec_test_random_bytes(data_buffer1, data_size); + gsec_test_random_bytes(data_buffer2, data_size); + gsec_test_copy(data_buffer1, &duplicate_buffer1, data_size); + gsec_test_copy(data_buffer2, &duplicate_buffer2, data_size); + + /* Client seal and server unseal */ + size_t size1 = data_size, size2 = data_size; + grpc_status_code status = alts_crypter_process_in_place( + client_seal, data_buffer1, protected_data_size, size1, &size1, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(size1 == protected_data_size); + status = alts_crypter_process_in_place( + client_seal, data_buffer2, protected_data_size, size2, &size2, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(size2 == protected_data_size); + status = alts_crypter_process_in_place( + server_unseal, data_buffer1, protected_data_size, size1, &size1, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(memcmp(data_buffer1, duplicate_buffer1, data_size) == 0); + GPR_ASSERT(size1 == data_size); + status = alts_crypter_process_in_place( + server_unseal, data_buffer2, protected_data_size, size2, &size2, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(memcmp(data_buffer2, duplicate_buffer2, data_size) == 0); + GPR_ASSERT(size2 == data_size); + + /* Server seal and client unseal */ + status = alts_crypter_process_in_place( + server_seal, data_buffer1, protected_data_size, size1, &size1, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(size1 == protected_data_size); + status = alts_crypter_process_in_place( + server_seal, data_buffer2, protected_data_size, size2, &size2, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(size2 == protected_data_size); + status = alts_crypter_process_in_place( + client_unseal, data_buffer1, protected_data_size, size1, &size1, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(memcmp(data_buffer1, duplicate_buffer1, data_size) == 0); + GPR_ASSERT(size1 == data_size); + status = alts_crypter_process_in_place( + client_unseal, data_buffer2, protected_data_size, size2, &size2, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(memcmp(data_buffer2, duplicate_buffer2, data_size) == 0); + GPR_ASSERT(size2 == data_size); + + gpr_free(data_buffer1); + gpr_free(data_buffer2); + gpr_free(duplicate_buffer1); + gpr_free(duplicate_buffer2); +} + +static void alts_crypter_test_corrupted_unseal(alts_crypter* server_seal, + alts_crypter* server_unseal, + alts_crypter* client_seal, + alts_crypter* client_unseal) { + size_t data_size = gsec_test_bias_random_uint32(1024) + 1; + size_t num_overhead_bytes = alts_crypter_num_overhead_bytes(server_seal); + size_t protected_data_size = data_size + num_overhead_bytes; + auto* data_buffer = static_cast(gpr_malloc(protected_data_size)); + auto* zero_buffer = static_cast(gpr_zalloc(data_size)); + + /* Corrupt a random byte in protected data. */ + size_t size = data_size; + gsec_test_random_bytes(data_buffer, data_size); + grpc_status_code status = alts_crypter_process_in_place( + client_seal, data_buffer, protected_data_size, size, &size, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(size == protected_data_size); + uint8_t* corrupted_data_buffer; + char* error_message = nullptr; + gsec_test_copy_and_alter_random_byte(data_buffer, &corrupted_data_buffer, + protected_data_size); + status = alts_crypter_process_in_place(server_unseal, corrupted_data_buffer, + protected_data_size, size, &size, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_FAILED_PRECONDITION, error_message, + "Checking tag failed")); + GPR_ASSERT(memcmp(corrupted_data_buffer, zero_buffer, data_size) == 0); + gpr_free(corrupted_data_buffer); + gpr_free(error_message); + + /* Corrupt the beginning of protected data. */ + size = data_size; + gsec_test_random_bytes(data_buffer, data_size); + status = alts_crypter_process_in_place( + client_seal, data_buffer, protected_data_size, size, &size, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(size == protected_data_size); + gsec_test_copy(data_buffer, &corrupted_data_buffer, protected_data_size); + (*corrupted_data_buffer)++; + status = alts_crypter_process_in_place(server_unseal, corrupted_data_buffer, + protected_data_size, size, &size, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_FAILED_PRECONDITION, error_message, + "Checking tag failed")); + GPR_ASSERT(memcmp(corrupted_data_buffer, zero_buffer, data_size) == 0); + gpr_free(corrupted_data_buffer); + gpr_free(error_message); + + /* Corrupt the end of protected data. */ + size = data_size; + gsec_test_random_bytes(data_buffer, data_size); + status = alts_crypter_process_in_place( + client_seal, data_buffer, protected_data_size, size, &size, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(size == protected_data_size); + gsec_test_copy(data_buffer, &corrupted_data_buffer, protected_data_size); + (*(corrupted_data_buffer + protected_data_size - 1))++; + status = alts_crypter_process_in_place(server_unseal, corrupted_data_buffer, + protected_data_size, size, &size, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_FAILED_PRECONDITION, error_message, + "Checking tag failed")); + GPR_ASSERT(memcmp(corrupted_data_buffer, zero_buffer, data_size) == 0); + gpr_free(corrupted_data_buffer); + gpr_free(error_message); + + gpr_free(data_buffer); + gpr_free(zero_buffer); +} + +static void alts_crypter_test_unsync_seal_unseal(alts_crypter* server_seal, + alts_crypter* server_unseal, + alts_crypter* client_seal, + alts_crypter* client_unseal) { + size_t data_size = gsec_test_bias_random_uint32(1024) + 1; + size_t num_overhead_bytes = alts_crypter_num_overhead_bytes(server_seal); + size_t protected_data_size = data_size + num_overhead_bytes; + auto* data_buffer = static_cast(gpr_malloc(protected_data_size)); + auto* zero_buffer = static_cast(gpr_zalloc(data_size)); + + /* Perform two seals at client, one unseal at server. */ + size_t size = data_size; + gsec_test_random_bytes(data_buffer, data_size); + grpc_status_code status = alts_crypter_process_in_place( + client_seal, data_buffer, protected_data_size, size, &size, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(size == protected_data_size); + + size = data_size; + gsec_test_random_bytes(data_buffer, data_size); + status = alts_crypter_process_in_place( + client_seal, data_buffer, protected_data_size, size, &size, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(size == protected_data_size); + + char* error_message = nullptr; + status = alts_crypter_process_in_place(server_unseal, data_buffer, + protected_data_size, size, &size, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_FAILED_PRECONDITION, error_message, + "Checking tag failed")); + GPR_ASSERT(memcmp(data_buffer, zero_buffer, data_size) == 0); + gpr_free(error_message); + + /* Perform two seals at server, one unseal at client. */ + size = data_size; + gsec_test_random_bytes(data_buffer, data_size); + status = alts_crypter_process_in_place( + server_seal, data_buffer, protected_data_size, size, &size, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(size == protected_data_size); + + size = data_size; + gsec_test_random_bytes(data_buffer, data_size); + status = alts_crypter_process_in_place( + server_seal, data_buffer, protected_data_size, size, &size, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(size == protected_data_size); + + status = alts_crypter_process_in_place(client_unseal, data_buffer, + protected_data_size, size, &size, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_FAILED_PRECONDITION, error_message, + "Checking tag failed")); + GPR_ASSERT(memcmp(data_buffer, zero_buffer, data_size) == 0); + gpr_free(error_message); + gpr_free(data_buffer); + gpr_free(zero_buffer); +} + +static void alts_crypter_test_input_sanity_check(alts_crypter* crypter_seal, + alts_crypter* crypter_unseal) { + size_t data_size = gsec_test_bias_random_uint32(1024) + 1; + size_t num_overhead_bytes = alts_crypter_num_overhead_bytes(crypter_seal); + size_t protected_data_size = data_size + num_overhead_bytes; + auto* data_buffer = static_cast(gpr_malloc(protected_data_size)); + gsec_test_random_bytes(data_buffer, data_size); + char* error_message = nullptr; + size_t size = data_size; + + /* Crypter is nullptr. */ + grpc_status_code status = alts_crypter_process_in_place( + nullptr, data_buffer, protected_data_size, size, &size, &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "crypter or crypter->vtable has not been initialized properly.")); + gpr_free(error_message); + + /* Seal data is nullptr. */ + size = data_size; + status = alts_crypter_process_in_place( + crypter_seal, nullptr, protected_data_size, size, &size, &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, "data is nullptr.")); + gpr_free(error_message); + + /* Seal data size is 0. */ + size = 0; + status = alts_crypter_process_in_place(crypter_seal, data_buffer, + protected_data_size, size, &size, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "data_size is zero.")); + gpr_free(error_message); + + /* Seal data buffer has a size smaller than the required. */ + size = data_size; + status = alts_crypter_process_in_place(crypter_seal, data_buffer, + protected_data_size - 1, size, &size, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "data_allocated_size is smaller than sum of data_size and " + "num_overhead_bytes.")); + gpr_free(error_message); + + /* Unseal data is nullptr. */ + size = data_size; + status = alts_crypter_process_in_place(crypter_unseal, nullptr, + protected_data_size, size, &size, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, "data is nullptr.")); + gpr_free(error_message); + + /* Unseal data size is 0. */ + size = 0; + status = alts_crypter_process_in_place(crypter_unseal, data_buffer, + protected_data_size, size, &size, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "data_size is smaller than num_overhead_bytes.")); + gpr_free(error_message); + + /* Unseal data size is smaller than number of overhead bytes. */ + size = num_overhead_bytes - 1; + status = alts_crypter_process_in_place(crypter_unseal, data_buffer, + protected_data_size, size, &size, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "data_size is smaller than num_overhead_bytes.")); + gpr_free(error_message); + gpr_free(data_buffer); +} + +static void create_random_alts_seal_crypter( + alts_crypter** server_seal, alts_crypter** server_unseal, + alts_crypter** client_seal, alts_crypter** client_unseal, + gsec_aead_crypter** server_crypter_seal, + gsec_aead_crypter** server_crypter_unseal, + gsec_aead_crypter** client_crypter_seal, + gsec_aead_crypter** client_crypter_unseal, bool rekey) { + size_t key_length = rekey ? kAes128GcmRekeyKeyLength : kAes128GcmKeyLength; + uint8_t* key; + gsec_test_random_array(&key, key_length); + gsec_aes_gcm_aead_crypter_create(key, key_length, kAesGcmNonceLength, + kAesGcmTagLength, rekey, server_crypter_seal, + nullptr); + gsec_aes_gcm_aead_crypter_create(key, key_length, kAesGcmNonceLength, + kAesGcmTagLength, rekey, + server_crypter_unseal, nullptr); + gsec_aes_gcm_aead_crypter_create(key, key_length, kAesGcmNonceLength, + kAesGcmTagLength, rekey, client_crypter_seal, + nullptr); + gsec_aes_gcm_aead_crypter_create(key, key_length, kAesGcmNonceLength, + kAesGcmTagLength, rekey, + client_crypter_unseal, nullptr); + + size_t overflow_size = rekey ? 8 : 5; + alts_seal_crypter_create(*client_crypter_seal, /*is_client=*/true, + overflow_size, client_seal, nullptr); + alts_unseal_crypter_create(*client_crypter_unseal, /*is_client=*/true, + overflow_size, client_unseal, nullptr); + alts_seal_crypter_create(*server_crypter_seal, /*is_client=*/false, + overflow_size, server_seal, nullptr); + alts_unseal_crypter_create(*server_crypter_unseal, /*is_client=*/false, + overflow_size, server_unseal, nullptr); + gpr_free(key); +} + +static void destroy_random_alts_seal_crypter(alts_crypter* server_seal, + alts_crypter* server_unseal, + alts_crypter* client_seal, + alts_crypter* client_unseal) { + alts_crypter_destroy(server_seal); + alts_crypter_destroy(server_unseal); + alts_crypter_destroy(client_seal); + alts_crypter_destroy(client_unseal); +} + +static void alts_crypter_do_generic_tests() { + alts_crypter *server_seal = nullptr, *server_unseal = nullptr, + *client_seal = nullptr, *client_unseal = nullptr; + gsec_aead_crypter *server_crypter_seal = nullptr, + *server_crypter_unseal = nullptr, + *client_crypter_seal = nullptr, + *client_crypter_unseal = nullptr; + /* Random seal and unseal tests */ + create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal, + &client_unseal, &server_crypter_seal, + &server_crypter_unseal, &client_crypter_seal, + &client_crypter_unseal, /*rekey=*/false); + alts_crypter_test_random_seal_unseal(server_seal, server_unseal, client_seal, + client_unseal); + destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal, + client_unseal); + + create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal, + &client_unseal, &server_crypter_seal, + &server_crypter_unseal, &client_crypter_seal, + &client_crypter_unseal, /*rekey=*/true); + alts_crypter_test_random_seal_unseal(server_seal, server_unseal, client_seal, + client_unseal); + destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal, + client_unseal); + + /* Multiple random seal and unseal tests */ + create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal, + &client_unseal, &server_crypter_seal, + &server_crypter_unseal, &client_crypter_seal, + &client_crypter_unseal, /*rekey=*/false); + alts_crypter_test_multiple_random_seal_unseal(server_seal, server_unseal, + client_seal, client_unseal); + destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal, + client_unseal); + + create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal, + &client_unseal, &server_crypter_seal, + &server_crypter_unseal, &client_crypter_seal, + &client_crypter_unseal, /*rekey=*/true); + alts_crypter_test_multiple_random_seal_unseal(server_seal, server_unseal, + client_seal, client_unseal); + destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal, + client_unseal); + + /* Corrupted unseal tests */ + create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal, + &client_unseal, &server_crypter_seal, + &server_crypter_unseal, &client_crypter_seal, + &client_crypter_unseal, /*rekey=*/false); + alts_crypter_test_corrupted_unseal(server_seal, server_unseal, client_seal, + client_unseal); + destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal, + client_unseal); + + create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal, + &client_unseal, &server_crypter_seal, + &server_crypter_unseal, &client_crypter_seal, + &client_crypter_unseal, /*rekey=*/true); + alts_crypter_test_corrupted_unseal(server_seal, server_unseal, client_seal, + client_unseal); + destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal, + client_unseal); + + /* Unsync seal and unseal tests */ + create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal, + &client_unseal, &server_crypter_seal, + &server_crypter_unseal, &client_crypter_seal, + &client_crypter_unseal, /*rekey=*/false); + alts_crypter_test_unsync_seal_unseal(server_seal, server_unseal, client_seal, + client_unseal); + destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal, + client_unseal); + + create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal, + &client_unseal, &server_crypter_seal, + &server_crypter_unseal, &client_crypter_seal, + &client_crypter_unseal, /*rekey=*/true); + alts_crypter_test_unsync_seal_unseal(server_seal, server_unseal, client_seal, + client_unseal); + destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal, + client_unseal); + + /* Input sanity check tests */ + create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal, + &client_unseal, &server_crypter_seal, + &server_crypter_unseal, &client_crypter_seal, + &client_crypter_unseal, /*rekey=*/false); + alts_crypter_test_input_sanity_check(server_seal, server_unseal); + destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal, + client_unseal); + + create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal, + &client_unseal, &server_crypter_seal, + &server_crypter_unseal, &client_crypter_seal, + &client_crypter_unseal, /*rekey=*/true); + alts_crypter_test_input_sanity_check(server_seal, server_unseal); + destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal, + client_unseal); +} + +int main(int argc, char** argv) { + alts_crypter_do_generic_tests(); + return 0; +} diff --git a/test/core/tsi/alts/frame_protector/alts_frame_protector_test.cc b/test/core/tsi/alts/frame_protector/alts_frame_protector_test.cc new file mode 100644 index 0000000000..2bd4958763 --- /dev/null +++ b/test/core/tsi/alts/frame_protector/alts_frame_protector_test.cc @@ -0,0 +1,394 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include + +#include + +#include "src/core/tsi/alts/crypt/gsec.h" +#include "src/core/tsi/alts/frame_protector/alts_frame_protector.h" +#include "src/core/tsi/transport_security_interface.h" +#include "test/core/tsi/alts/crypt/gsec_test_util.h" +#include "test/core/tsi/transport_security_test_lib.h" + +const size_t kChannelSize = 32768; + +static void alts_test_do_round_trip_check_frames( + tsi_test_frame_protector_fixture* fixture, const uint8_t* key, + const size_t key_size, bool rekey, const uint8_t* client_message, + const size_t client_message_size, const uint8_t* client_expected_frames, + const size_t client_frame_size, const uint8_t* server_message, + const size_t server_message_size, const uint8_t* server_expected_frames, + const size_t server_frame_size) { + GPR_ASSERT(fixture != nullptr); + GPR_ASSERT(fixture->config != nullptr); + tsi_frame_protector* client_frame_protector = nullptr; + tsi_frame_protector* server_frame_protector = nullptr; + tsi_test_frame_protector_config* config = fixture->config; + tsi_test_channel* channel = fixture->channel; + /* Create a client frame protector. */ + size_t client_max_output_protected_frame_size = + config->client_max_output_protected_frame_size; + GPR_ASSERT( + alts_create_frame_protector(key, key_size, /*is_client=*/true, rekey, + client_max_output_protected_frame_size == 0 + ? nullptr + : &client_max_output_protected_frame_size, + &client_frame_protector) == TSI_OK); + /* Create a server frame protector. */ + size_t server_max_output_protected_frame_size = + config->server_max_output_protected_frame_size; + GPR_ASSERT( + alts_create_frame_protector(key, key_size, /*is_client=*/false, rekey, + server_max_output_protected_frame_size == 0 + ? nullptr + : &server_max_output_protected_frame_size, + &server_frame_protector) == TSI_OK); + tsi_test_frame_protector_fixture_init(fixture, client_frame_protector, + server_frame_protector); + /* Client sends a message to server. */ + uint8_t* saved_client_message = config->client_message; + config->client_message = const_cast(client_message); + config->client_message_size = client_message_size; + tsi_test_frame_protector_send_message_to_peer(config, channel, + client_frame_protector, + /*is_client=*/true); + /* Verify if the generated frame is the same as the expected. */ + GPR_ASSERT(channel->bytes_written_to_server_channel == client_frame_size); + GPR_ASSERT(memcmp(client_expected_frames, channel->server_channel, + client_frame_size) == 0); + unsigned char* server_received_message = + static_cast(gpr_malloc(kChannelSize)); + size_t server_received_message_size = 0; + tsi_test_frame_protector_receive_message_from_peer( + config, channel, server_frame_protector, server_received_message, + &server_received_message_size, /*is_client=*/false); + GPR_ASSERT(config->client_message_size == server_received_message_size); + GPR_ASSERT(memcmp(config->client_message, server_received_message, + server_received_message_size) == 0); + /* Server sends a message to client. */ + uint8_t* saved_server_message = config->server_message; + config->server_message = const_cast(server_message); + config->server_message_size = server_message_size; + tsi_test_frame_protector_send_message_to_peer(config, channel, + server_frame_protector, + /*is_client=*/false); + /* Verify if the generated frame is the same as the expected. */ + GPR_ASSERT(channel->bytes_written_to_client_channel == server_frame_size); + GPR_ASSERT(memcmp(server_expected_frames, channel->client_channel, + server_frame_size) == 0); + unsigned char* client_received_message = + static_cast(gpr_malloc(kChannelSize)); + size_t client_received_message_size = 0; + tsi_test_frame_protector_receive_message_from_peer( + config, channel, client_frame_protector, client_received_message, + &client_received_message_size, + /*is_client=*/true); + GPR_ASSERT(config->server_message_size == client_received_message_size); + GPR_ASSERT(memcmp(config->server_message, client_received_message, + client_received_message_size) == 0); + config->client_message = saved_client_message; + config->server_message = saved_server_message; + /* Destroy server and client frame protectors. */ + gpr_free(server_received_message); + gpr_free(client_received_message); +} + +static void alts_test_do_round_trip_vector_tests() { + const uint8_t key[] = {0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, + 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08}; + const char small_message[] = {'C', 'h', 'a', 'p', 'i', ' ', + 'C', 'h', 'a', 'p', 'o'}; + const uint8_t large_message[] = { + 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, 0xa5, 0x59, 0x09, 0xc5, + 0xaf, 0xf5, 0x26, 0x9a, 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, + 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, 0x1c, 0x3c, 0x0c, 0x95, + 0x95, 0x68, 0x09, 0x53, 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, + 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, 0xba, 0x63, 0x7b, 0x39, + 0x1a, 0xaf, 0xd2, 0x55, 0xd6, 0x09, 0xb1, 0xf0, 0x56, 0x63, 0x7a, 0x0d, + 0x46, 0xdf, 0x99, 0x8d, 0x88, 0xe5, 0x22, 0x2a, 0xb2, 0xc2, 0x84, 0x65, + 0x12, 0x15, 0x35, 0x24, 0xc0, 0x89, 0x5e, 0x81, 0x08, 0x06, 0x0f, 0x10, + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, + 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30}; + const size_t small_message_size = sizeof(small_message) / sizeof(uint8_t); + const size_t large_message_size = sizeof(large_message) / sizeof(uint8_t); + /* Test small client message and large server message. */ + const uint8_t client_expected_frame1[] = { + 0x1f, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x09, 0xd8, 0xd5, 0x92, + 0x4d, 0x50, 0x32, 0xb7, 0x1f, 0xb8, 0xf2, 0xbb, 0x43, 0xc7, 0xe2, 0x94, + 0x3d, 0x3e, 0x9a, 0x78, 0x76, 0xaa, 0x0a, 0x6b, 0xfa, 0x98, 0x3a}; + const uint8_t server_expected_frame1[] = { + 0x94, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xa9, 0x4b, 0xf8, 0xc8, + 0xe7, 0x8f, 0x1a, 0x26, 0x37, 0x44, 0xa2, 0x5c, 0x55, 0x94, 0x30, 0x4e, + 0x3e, 0x16, 0xe7, 0x9e, 0x96, 0xe8, 0x1b, 0xc0, 0xdd, 0x52, 0x30, 0x06, + 0xc2, 0x72, 0x9a, 0xa1, 0x0b, 0xdb, 0xdc, 0x19, 0x8c, 0x93, 0x5e, 0x84, + 0x1f, 0x4b, 0x97, 0x26, 0xf0, 0x73, 0x85, 0x59, 0x00, 0x95, 0xc1, 0xc5, + 0x22, 0x2f, 0x70, 0x85, 0x68, 0x2c, 0x4f, 0xfe, 0x30, 0x26, 0x91, 0xde, + 0x62, 0x55, 0x1d, 0x35, 0x01, 0x96, 0x1c, 0xe7, 0xa2, 0x8b, 0x14, 0x8a, + 0x5e, 0x1b, 0x4a, 0x3b, 0x4f, 0x65, 0x0f, 0xca, 0x79, 0x10, 0xb4, 0xdd, + 0xf7, 0xa4, 0x8b, 0x64, 0x2f, 0x00, 0x39, 0x60, 0x03, 0xfc, 0xe1, 0x8b, + 0x5c, 0x19, 0xba, 0xcc, 0x46, 0xba, 0x88, 0xdd, 0x40, 0x42, 0x27, 0x4f, + 0xe4, 0x1a, 0x6a, 0x31, 0x6c, 0x1c, 0xb0, 0xb6, 0x5c, 0x3e, 0xca, 0x84, + 0x9b, 0x5f, 0x04, 0x84, 0x11, 0xa9, 0xf8, 0x39, 0xe7, 0xe7, 0xc5, 0xc4, + 0x33, 0x9f, 0x63, 0x21, 0x9a, 0x7c, 0x9c, 0x64}; + const size_t client_frame_size1 = + sizeof(client_expected_frame1) / sizeof(uint8_t); + const size_t server_frame_size1 = + sizeof(server_expected_frame1) / sizeof(uint8_t); + tsi_test_frame_protector_fixture* fixture = + tsi_test_frame_protector_fixture_create(); + alts_test_do_round_trip_check_frames( + fixture, key, kAes128GcmKeyLength, /*rekey=*/false, + reinterpret_cast(small_message), small_message_size, + client_expected_frame1, client_frame_size1, large_message, + large_message_size, server_expected_frame1, server_frame_size1); + tsi_test_frame_protector_fixture_destroy(fixture); + /** + * Test large client message, small server message, and small + * message_buffer_allocated_size. + */ + const uint8_t client_expected_frame2[] = { + 0x94, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x93, 0x81, 0x86, 0xc7, + 0xdc, 0xf4, 0x77, 0x3a, 0xdb, 0x91, 0x94, 0x61, 0xba, 0xed, 0xd5, 0x37, + 0x47, 0x53, 0x0c, 0xe1, 0xbf, 0x59, 0x23, 0x20, 0xde, 0x8b, 0x25, 0x13, + 0x72, 0xe7, 0x8a, 0x4f, 0x32, 0x61, 0xc6, 0xda, 0xc3, 0xe9, 0xff, 0x31, + 0x33, 0x53, 0x4a, 0xf8, 0xc9, 0x98, 0xe4, 0x19, 0x71, 0x9c, 0x5e, 0x72, + 0xc7, 0x35, 0x97, 0x78, 0x30, 0xf2, 0xc4, 0xd1, 0x53, 0xd5, 0x6e, 0x8f, + 0x4f, 0xd9, 0x28, 0x5a, 0xfd, 0x22, 0x57, 0x7f, 0x95, 0xb4, 0x8a, 0x5e, + 0x7c, 0x47, 0xa8, 0xcf, 0x64, 0x3d, 0x83, 0xa5, 0xcf, 0xc3, 0xfe, 0x54, + 0xc2, 0x6a, 0x40, 0xc4, 0xfb, 0x8e, 0x07, 0x77, 0x70, 0x8f, 0x99, 0x94, + 0xb1, 0xd5, 0xa7, 0xf9, 0x0d, 0xc7, 0x11, 0xc5, 0x6f, 0x4a, 0x4f, 0x56, + 0xd5, 0xe2, 0x9c, 0xbb, 0x95, 0x7a, 0xd0, 0x9f, 0x30, 0x54, 0xca, 0x6d, + 0x5c, 0x8e, 0x83, 0xa0, 0x04, 0x5e, 0xd0, 0x22, 0x8c, 0x2a, 0x7f, 0xdb, + 0xfe, 0xb3, 0x2e, 0xae, 0x22, 0xe6, 0xf4, 0xb7}; + const uint8_t server_expected_frame2[] = { + 0x1f, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x33, 0x12, 0xab, 0x9d, + 0x76, 0x2b, 0x5f, 0xab, 0xf3, 0x6d, 0xc4, 0xaa, 0xe5, 0x1e, 0x63, 0xc1, + 0x7b, 0x7b, 0x10, 0xd5, 0x63, 0x0f, 0x29, 0xad, 0x17, 0x33, 0x73}; + const size_t client_frame_size2 = + sizeof(client_expected_frame2) / sizeof(uint8_t); + const size_t server_frame_size2 = + sizeof(server_expected_frame2) / sizeof(uint8_t); + fixture = tsi_test_frame_protector_fixture_create(); + alts_test_do_round_trip_check_frames( + fixture, key, kAes128GcmKeyLength, /*rekey=*/false, large_message, + large_message_size, client_expected_frame2, client_frame_size2, + reinterpret_cast(small_message), small_message_size, + server_expected_frame2, server_frame_size2); + tsi_test_frame_protector_fixture_destroy(fixture); + /** + * Test large client message, small server message, and small + * protected_buffer_size. + */ + const uint8_t client_expected_frame3[] = { + 0x94, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x93, 0x81, 0x86, 0xc7, + 0xdc, 0xf4, 0x77, 0x3a, 0xdb, 0x91, 0x94, 0x61, 0xba, 0xed, 0xd5, 0x37, + 0x47, 0x53, 0x0c, 0xe1, 0xbf, 0x59, 0x23, 0x20, 0xde, 0x8b, 0x25, 0x13, + 0x72, 0xe7, 0x8a, 0x4f, 0x32, 0x61, 0xc6, 0xda, 0xc3, 0xe9, 0xff, 0x31, + 0x33, 0x53, 0x4a, 0xf8, 0xc9, 0x98, 0xe4, 0x19, 0x71, 0x9c, 0x5e, 0x72, + 0xc7, 0x35, 0x97, 0x78, 0x30, 0xf2, 0xc4, 0xd1, 0x53, 0xd5, 0x6e, 0x8f, + 0x4f, 0xd9, 0x28, 0x5a, 0xfd, 0x22, 0x57, 0x7f, 0x95, 0xb4, 0x8a, 0x5e, + 0x7c, 0x47, 0xa8, 0xcf, 0x64, 0x3d, 0x83, 0xa5, 0xcf, 0xc3, 0xfe, 0x54, + 0xc2, 0x6a, 0x40, 0xc4, 0xfb, 0x8e, 0x07, 0x77, 0x70, 0x8f, 0x99, 0x94, + 0xb1, 0xd5, 0xa7, 0xf9, 0x0d, 0xc7, 0x11, 0xc5, 0x6f, 0x4a, 0x4f, 0x56, + 0xd5, 0xe2, 0x9c, 0xbb, 0x95, 0x7a, 0xd0, 0x9f, 0x30, 0x54, 0xca, 0x6d, + 0x5c, 0x8e, 0x83, 0xa0, 0x04, 0x5e, 0xd0, 0x22, 0x8c, 0x2a, 0x7f, 0xdb, + 0xfe, 0xb3, 0x2e, 0xae, 0x22, 0xe6, 0xf4, 0xb7}; + const uint8_t server_expected_frame3[] = { + 0x1f, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x33, 0x12, 0xab, 0x9d, + 0x76, 0x2b, 0x5f, 0xab, 0xf3, 0x6d, 0xc4, 0xaa, 0xe5, 0x1e, 0x63, 0xc1, + 0x7b, 0x7b, 0x10, 0xd5, 0x63, 0x0f, 0x29, 0xad, 0x17, 0x33, 0x73}; + const size_t client_frame_size3 = + sizeof(client_expected_frame3) / sizeof(uint8_t); + const size_t server_frame_size3 = + sizeof(server_expected_frame3) / sizeof(uint8_t); + fixture = tsi_test_frame_protector_fixture_create(); + alts_test_do_round_trip_check_frames( + fixture, key, kAes128GcmKeyLength, /*rekey=*/false, large_message, + large_message_size, client_expected_frame3, client_frame_size3, + reinterpret_cast(small_message), small_message_size, + server_expected_frame3, server_frame_size3); + tsi_test_frame_protector_fixture_destroy(fixture); + /** + * Test large client message, small server message, and small + * read_buffer_allocated_size. + */ + const uint8_t client_expected_frame4[] = { + 0x94, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x93, 0x81, 0x86, 0xc7, + 0xdc, 0xf4, 0x77, 0x3a, 0xdb, 0x91, 0x94, 0x61, 0xba, 0xed, 0xd5, 0x37, + 0x47, 0x53, 0x0c, 0xe1, 0xbf, 0x59, 0x23, 0x20, 0xde, 0x8b, 0x25, 0x13, + 0x72, 0xe7, 0x8a, 0x4f, 0x32, 0x61, 0xc6, 0xda, 0xc3, 0xe9, 0xff, 0x31, + 0x33, 0x53, 0x4a, 0xf8, 0xc9, 0x98, 0xe4, 0x19, 0x71, 0x9c, 0x5e, 0x72, + 0xc7, 0x35, 0x97, 0x78, 0x30, 0xf2, 0xc4, 0xd1, 0x53, 0xd5, 0x6e, 0x8f, + 0x4f, 0xd9, 0x28, 0x5a, 0xfd, 0x22, 0x57, 0x7f, 0x95, 0xb4, 0x8a, 0x5e, + 0x7c, 0x47, 0xa8, 0xcf, 0x64, 0x3d, 0x83, 0xa5, 0xcf, 0xc3, 0xfe, 0x54, + 0xc2, 0x6a, 0x40, 0xc4, 0xfb, 0x8e, 0x07, 0x77, 0x70, 0x8f, 0x99, 0x94, + 0xb1, 0xd5, 0xa7, 0xf9, 0x0d, 0xc7, 0x11, 0xc5, 0x6f, 0x4a, 0x4f, 0x56, + 0xd5, 0xe2, 0x9c, 0xbb, 0x95, 0x7a, 0xd0, 0x9f, 0x30, 0x54, 0xca, 0x6d, + 0x5c, 0x8e, 0x83, 0xa0, 0x04, 0x5e, 0xd0, 0x22, 0x8c, 0x2a, 0x7f, 0xdb, + 0xfe, 0xb3, 0x2e, 0xae, 0x22, 0xe6, 0xf4, 0xb7}; + const uint8_t server_expected_frame4[] = { + 0x1f, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x33, 0x12, 0xab, 0x9d, + 0x76, 0x2b, 0x5f, 0xab, 0xf3, 0x6d, 0xc4, 0xaa, 0xe5, 0x1e, 0x63, 0xc1, + 0x7b, 0x7b, 0x10, 0xd5, 0x63, 0x0f, 0x29, 0xad, 0x17, 0x33, 0x73}; + const size_t client_frame_size4 = + sizeof(client_expected_frame4) / sizeof(uint8_t); + const size_t server_frame_size4 = + sizeof(server_expected_frame4) / sizeof(uint8_t); + fixture = tsi_test_frame_protector_fixture_create(); + alts_test_do_round_trip_check_frames( + fixture, key, kAes128GcmKeyLength, /*rekey=*/false, large_message, + large_message_size, client_expected_frame4, client_frame_size4, + reinterpret_cast(small_message), small_message_size, + server_expected_frame4, server_frame_size4); + tsi_test_frame_protector_fixture_destroy(fixture); + /** + * Test large client message, small server message, and small + * client_max_output_protected_frame_size. + */ + const uint8_t client_expected_frame5[] = { + 0x94, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x93, 0x81, 0x86, 0xc7, + 0xdc, 0xf4, 0x77, 0x3a, 0xdb, 0x91, 0x94, 0x61, 0xba, 0xed, 0xd5, 0x37, + 0x47, 0x53, 0x0c, 0xe1, 0xbf, 0x59, 0x23, 0x20, 0xde, 0x8b, 0x25, 0x13, + 0x72, 0xe7, 0x8a, 0x4f, 0x32, 0x61, 0xc6, 0xda, 0xc3, 0xe9, 0xff, 0x31, + 0x33, 0x53, 0x4a, 0xf8, 0xc9, 0x98, 0xe4, 0x19, 0x71, 0x9c, 0x5e, 0x72, + 0xc7, 0x35, 0x97, 0x78, 0x30, 0xf2, 0xc4, 0xd1, 0x53, 0xd5, 0x6e, 0x8f, + 0x4f, 0xd9, 0x28, 0x5a, 0xfd, 0x22, 0x57, 0x7f, 0x95, 0xb4, 0x8a, 0x5e, + 0x7c, 0x47, 0xa8, 0xcf, 0x64, 0x3d, 0x83, 0xa5, 0xcf, 0xc3, 0xfe, 0x54, + 0xc2, 0x6a, 0x40, 0xc4, 0xfb, 0x8e, 0x07, 0x77, 0x70, 0x8f, 0x99, 0x94, + 0xb1, 0xd5, 0xa7, 0xf9, 0x0d, 0xc7, 0x11, 0xc5, 0x6f, 0x4a, 0x4f, 0x56, + 0xd5, 0xe2, 0x9c, 0xbb, 0x95, 0x7a, 0xd0, 0x9f, 0x30, 0x54, 0xca, 0x6d, + 0x5c, 0x8e, 0x83, 0xa0, 0x04, 0x5e, 0xd0, 0x22, 0x8c, 0x2a, 0x7f, 0xdb, + 0xfe, 0xb3, 0x2e, 0xae, 0x22, 0xe6, 0xf4, 0xb7}; + const uint8_t server_expected_frame5[] = { + 0x1f, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x33, 0x12, 0xab, 0x9d, + 0x76, 0x2b, 0x5f, 0xab, 0xf3, 0x6d, 0xc4, 0xaa, 0xe5, 0x1e, 0x63, 0xc1, + 0x7b, 0x7b, 0x10, 0xd5, 0x63, 0x0f, 0x29, 0xad, 0x17, 0x33, 0x73}; + const size_t client_frame_size5 = + sizeof(client_expected_frame5) / sizeof(uint8_t); + const size_t server_frame_size5 = + sizeof(server_expected_frame5) / sizeof(uint8_t); + fixture = tsi_test_frame_protector_fixture_create(); + alts_test_do_round_trip_check_frames( + fixture, key, kAes128GcmKeyLength, /*rekey=*/false, large_message, + large_message_size, client_expected_frame5, client_frame_size5, + reinterpret_cast(small_message), small_message_size, + server_expected_frame5, server_frame_size5); + tsi_test_frame_protector_fixture_destroy(fixture); + /** + * Test small client message, large server message, and small + * server_max_output_protected_frame_size. + */ + const uint8_t client_expected_frame6[] = { + 0x1f, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x09, 0xd8, 0xd5, 0x92, + 0x4d, 0x50, 0x32, 0xb7, 0x1f, 0xb8, 0xf2, 0xbb, 0x43, 0xc7, 0xe2, 0x94, + 0x3d, 0x3e, 0x9a, 0x78, 0x76, 0xaa, 0x0a, 0x6b, 0xfa, 0x98, 0x3a}; + const uint8_t server_expected_frame6[] = { + 0x94, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0xa9, 0x4b, 0xf8, 0xc8, + 0xe7, 0x8f, 0x1a, 0x26, 0x37, 0x44, 0xa2, 0x5c, 0x55, 0x94, 0x30, 0x4e, + 0x3e, 0x16, 0xe7, 0x9e, 0x96, 0xe8, 0x1b, 0xc0, 0xdd, 0x52, 0x30, 0x06, + 0xc2, 0x72, 0x9a, 0xa1, 0x0b, 0xdb, 0xdc, 0x19, 0x8c, 0x93, 0x5e, 0x84, + 0x1f, 0x4b, 0x97, 0x26, 0xf0, 0x73, 0x85, 0x59, 0x00, 0x95, 0xc1, 0xc5, + 0x22, 0x2f, 0x70, 0x85, 0x68, 0x2c, 0x4f, 0xfe, 0x30, 0x26, 0x91, 0xde, + 0x62, 0x55, 0x1d, 0x35, 0x01, 0x96, 0x1c, 0xe7, 0xa2, 0x8b, 0x14, 0x8a, + 0x5e, 0x1b, 0x4a, 0x3b, 0x4f, 0x65, 0x0f, 0xca, 0x79, 0x10, 0xb4, 0xdd, + 0xf7, 0xa4, 0x8b, 0x64, 0x2f, 0x00, 0x39, 0x60, 0x03, 0xfc, 0xe1, 0x8b, + 0x5c, 0x19, 0xba, 0xcc, 0x46, 0xba, 0x88, 0xdd, 0x40, 0x42, 0x27, 0x4f, + 0xe4, 0x1a, 0x6a, 0x31, 0x6c, 0x1c, 0xb0, 0xb6, 0x5c, 0x3e, 0xca, 0x84, + 0x9b, 0x5f, 0x04, 0x84, 0x11, 0xa9, 0xf8, 0x39, 0xe7, 0xe7, 0xc5, 0xc4, + 0x33, 0x9f, 0x63, 0x21, 0x9a, 0x7c, 0x9c, 0x64}; + const size_t client_frame_size6 = + sizeof(client_expected_frame6) / sizeof(uint8_t); + const size_t server_frame_size6 = + sizeof(server_expected_frame6) / sizeof(uint8_t); + fixture = tsi_test_frame_protector_fixture_create(); + alts_test_do_round_trip_check_frames( + fixture, key, kAes128GcmKeyLength, /*rekey=*/false, + reinterpret_cast(small_message), small_message_size, + client_expected_frame6, client_frame_size6, large_message, + large_message_size, server_expected_frame6, server_frame_size6); + tsi_test_frame_protector_fixture_destroy(fixture); +} + +static void alts_test_do_round_trip(tsi_test_frame_protector_fixture* fixture, + bool rekey) { + GPR_ASSERT(fixture != nullptr); + GPR_ASSERT(fixture->config != nullptr); + tsi_frame_protector* client_frame_protector = nullptr; + tsi_frame_protector* server_frame_protector = nullptr; + tsi_test_frame_protector_config* config = fixture->config; + /* Create a key to be used by both client and server. */ + uint8_t* key = nullptr; + size_t key_length = rekey ? kAes128GcmRekeyKeyLength : kAes128GcmKeyLength; + gsec_test_random_array(&key, key_length); + /* Create a client frame protector. */ + size_t client_max_output_protected_frame_size = + config->client_max_output_protected_frame_size; + GPR_ASSERT( + alts_create_frame_protector(key, key_length, /*is_client=*/true, rekey, + client_max_output_protected_frame_size == 0 + ? nullptr + : &client_max_output_protected_frame_size, + &client_frame_protector) == TSI_OK); + /* Create a server frame protector. */ + size_t server_max_output_protected_frame_size = + config->server_max_output_protected_frame_size; + GPR_ASSERT( + alts_create_frame_protector(key, key_length, /*is_client=*/false, rekey, + server_max_output_protected_frame_size == 0 + ? nullptr + : &server_max_output_protected_frame_size, + &server_frame_protector) == TSI_OK); + tsi_test_frame_protector_fixture_init(fixture, client_frame_protector, + server_frame_protector); + tsi_test_frame_protector_do_round_trip_no_handshake(fixture); + gpr_free(key); +} + +/* Run all combinations of different arguments of test config. */ +static void alts_test_do_round_trip_all(bool rekey) { + unsigned int* bit_array = static_cast( + gpr_malloc(sizeof(unsigned int) * TSI_TEST_NUM_OF_ARGUMENTS)); + unsigned int mask = 1U << (TSI_TEST_NUM_OF_ARGUMENTS - 1); + unsigned int val = 0, ind = 0; + for (val = 0; val < TSI_TEST_NUM_OF_COMBINATIONS; val++) { + unsigned int v = val; + for (ind = 0; ind < TSI_TEST_NUM_OF_ARGUMENTS; ind++) { + bit_array[ind] = (v & mask) ? 1 : 0; + v <<= 1; + } + tsi_test_frame_protector_fixture* fixture = + tsi_test_frame_protector_fixture_create(); + tsi_test_frame_protector_config_destroy(fixture->config); + fixture->config = tsi_test_frame_protector_config_create( + bit_array[0], bit_array[1], bit_array[2], bit_array[3], bit_array[4], + bit_array[5], bit_array[6]); + alts_test_do_round_trip(fixture, rekey); + tsi_test_frame_protector_fixture_destroy(fixture); + } + gpr_free(bit_array); +} + +int main(int argc, char** argv) { + alts_test_do_round_trip_vector_tests(); + alts_test_do_round_trip_all(/*rekey=*/false); + alts_test_do_round_trip_all(/*rekey=*/true); + return 0; +} diff --git a/test/core/tsi/alts/frame_protector/frame_handler_test.cc b/test/core/tsi/alts/frame_protector/frame_handler_test.cc new file mode 100644 index 0000000000..6434ea1d31 --- /dev/null +++ b/test/core/tsi/alts/frame_protector/frame_handler_test.cc @@ -0,0 +1,244 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include + +#include +#include + +#include "src/core/lib/gpr/useful.h" +#include "src/core/tsi/alts/frame_protector/frame_handler.h" +#include "test/core/tsi/alts/crypt/gsec_test_util.h" + +const size_t kFrameHandlerTestBufferSize = 1024; + +typedef struct frame_handler { + alts_frame_writer* writer; + alts_frame_reader* reader; + unsigned char* buffer; + size_t buffer_size; +} frame_handler; + +static size_t frame_length(size_t payload_length) { + return payload_length + kFrameHeaderSize; +} + +static frame_handler* create_frame_handler() { + frame_handler* handler = + static_cast(gpr_malloc(sizeof(frame_handler))); + handler->writer = alts_create_frame_writer(); + handler->reader = alts_create_frame_reader(); + handler->buffer = nullptr; + handler->buffer_size = 0; + return handler; +} + +static void destroy_frame_handler(frame_handler* handler) { + if (handler != nullptr) { + alts_destroy_frame_reader(handler->reader); + alts_destroy_frame_writer(handler->writer); + if (handler->buffer != nullptr) gpr_free(handler->buffer); + gpr_free(handler); + } +} + +static void frame(frame_handler* handler, unsigned char* payload, + size_t payload_length, size_t write_length) { + handler->buffer_size = frame_length(payload_length); + handler->buffer = + static_cast(gpr_malloc(handler->buffer_size)); + GPR_ASSERT(alts_reset_frame_writer(handler->writer, payload, payload_length)); + size_t offset = 0; + while (offset < handler->buffer_size && + !alts_is_frame_writer_done(handler->writer)) { + size_t bytes_written = GPR_MIN(write_length, handler->buffer_size - offset); + GPR_ASSERT(alts_write_frame_bytes(handler->writer, handler->buffer + offset, + &bytes_written)); + offset += bytes_written; + } + GPR_ASSERT(alts_is_frame_writer_done(handler->writer)); + GPR_ASSERT(handler->buffer_size == offset); +} + +static size_t deframe(frame_handler* handler, unsigned char* bytes, + size_t read_length) { + GPR_ASSERT(alts_reset_frame_reader(handler->reader, bytes)); + size_t offset = 0; + while (offset < handler->buffer_size && + !alts_is_frame_reader_done(handler->reader)) { + size_t bytes_read = GPR_MIN(read_length, handler->buffer_size - offset); + GPR_ASSERT(alts_read_frame_bytes(handler->reader, handler->buffer + offset, + &bytes_read)); + offset += bytes_read; + } + GPR_ASSERT(alts_is_frame_reader_done(handler->reader)); + GPR_ASSERT(handler->buffer_size == offset); + return offset - handler->reader->header_bytes_read; +} + +static void frame_n_deframe(frame_handler* handler, unsigned char* payload, + size_t payload_length, size_t write_length, + size_t read_length) { + frame(handler, payload, payload_length, write_length); + unsigned char* bytes = + static_cast(gpr_malloc(kFrameHandlerTestBufferSize)); + size_t deframed_payload_length = deframe(handler, bytes, read_length); + GPR_ASSERT(payload_length == deframed_payload_length); + GPR_ASSERT(memcmp(payload, bytes, payload_length) == 0); + gpr_free(bytes); +} + +static void frame_handler_test_frame_deframe() { + unsigned char payload[] = "hello world"; + size_t payload_length = strlen((char*)payload) + 1; + frame_handler* handler = create_frame_handler(); + frame_n_deframe(handler, payload, payload_length, + frame_length(payload_length), frame_length(payload_length)); + destroy_frame_handler(handler); +} + +static void frame_handler_test_small_buffer() { + unsigned char payload[] = "hello world"; + size_t payload_length = strlen(reinterpret_cast(payload)) + 1; + frame_handler* handler = create_frame_handler(); + frame_n_deframe(handler, payload, payload_length, 1, 1); + destroy_frame_handler(handler); +} + +static void frame_handler_test_null_input_stream() { + frame_handler* handler = create_frame_handler(); + GPR_ASSERT(!alts_reset_frame_writer(handler->writer, nullptr, 0)); + destroy_frame_handler(handler); +} + +static void frame_handler_test_bad_input_length() { + unsigned char payload[] = "hello world"; + frame_handler* handler = create_frame_handler(); + GPR_ASSERT(!alts_reset_frame_writer(handler->writer, payload, SIZE_MAX)); + destroy_frame_handler(handler); +} + +static void frame_handler_test_null_writer_byte_length() { + unsigned char payload[] = "hello world"; + size_t payload_length = strlen(reinterpret_cast(payload)) + 1; + frame_handler* handler = create_frame_handler(); + GPR_ASSERT(alts_reset_frame_writer(handler->writer, payload, payload_length)); + GPR_ASSERT( + !alts_write_frame_bytes(handler->writer, handler->buffer, nullptr)); + destroy_frame_handler(handler); +} + +static void frame_handler_test_null_writer_bytes() { + unsigned char payload[] = "hello world"; + size_t payload_length = strlen(reinterpret_cast(payload)) + 1; + frame_handler* handler = create_frame_handler(); + GPR_ASSERT(alts_reset_frame_writer(handler->writer, payload, payload_length)); + GPR_ASSERT( + !alts_write_frame_bytes(handler->writer, nullptr, &payload_length)); + destroy_frame_handler(handler); +} + +static void frame_handler_test_bad_frame_length() { + unsigned char payload[] = "hello world"; + size_t payload_length = strlen(reinterpret_cast(payload)) + 1; + frame_handler* handler = create_frame_handler(); + frame(handler, payload, payload_length, payload_length); + memset(handler->buffer, 0x00, kFrameLengthFieldSize); + unsigned char* bytes = + static_cast(gpr_malloc(kFrameHandlerTestBufferSize)); + GPR_ASSERT(alts_reset_frame_reader(handler->reader, bytes)); + size_t bytes_read = handler->buffer_size; + GPR_ASSERT( + !alts_read_frame_bytes(handler->reader, handler->buffer, &bytes_read)); + GPR_ASSERT(alts_is_frame_reader_done(handler->reader)); + GPR_ASSERT(bytes_read == 0); + gpr_free(bytes); + destroy_frame_handler(handler); +} + +static void frame_handler_test_unsupported_message_type() { + unsigned char payload[] = "hello world"; + size_t payload_length = strlen(reinterpret_cast(payload)) + 1; + frame_handler* handler = create_frame_handler(); + frame(handler, payload, payload_length, payload_length); + memset(handler->buffer + kFrameLengthFieldSize, 0x00, + kFrameMessageTypeFieldSize); + unsigned char* bytes = + static_cast(gpr_malloc(kFrameHandlerTestBufferSize)); + GPR_ASSERT(alts_reset_frame_reader(handler->reader, bytes)); + size_t bytes_read = handler->buffer_size; + GPR_ASSERT( + !alts_read_frame_bytes(handler->reader, handler->buffer, &bytes_read)); + GPR_ASSERT(alts_is_frame_reader_done(handler->reader)); + GPR_ASSERT(bytes_read == 0); + gpr_free(bytes); + destroy_frame_handler(handler); +} + +static void frame_handler_test_null_output_stream() { + unsigned char payload[] = "hello world"; + size_t payload_length = strlen(reinterpret_cast(payload)) + 1; + frame_handler* handler = create_frame_handler(); + frame(handler, payload, payload_length, payload_length); + GPR_ASSERT(!alts_reset_frame_reader(handler->reader, nullptr)); + destroy_frame_handler(handler); +} + +static void frame_handler_test_null_reader_byte_length() { + unsigned char payload[] = "hello world"; + size_t payload_length = strlen(reinterpret_cast(payload)) + 1; + frame_handler* handler = create_frame_handler(); + frame(handler, payload, payload_length, payload_length); + unsigned char* bytes = + static_cast(gpr_malloc(kFrameHandlerTestBufferSize)); + GPR_ASSERT(alts_reset_frame_reader(handler->reader, bytes)); + GPR_ASSERT(!alts_read_frame_bytes(handler->reader, handler->buffer, nullptr)); + gpr_free(bytes); + destroy_frame_handler(handler); +} + +static void frame_handler_test_null_reader_bytes() { + unsigned char payload[] = "hello world"; + size_t payload_length = strlen(reinterpret_cast(payload)) + 1; + frame_handler* handler = create_frame_handler(); + frame(handler, payload, payload_length, payload_length); + unsigned char* bytes = + static_cast(gpr_malloc(kFrameHandlerTestBufferSize)); + GPR_ASSERT(alts_reset_frame_reader(handler->reader, bytes)); + size_t bytes_read = handler->buffer_size; + GPR_ASSERT(!alts_read_frame_bytes(handler->reader, nullptr, &bytes_read)); + gpr_free(bytes); + destroy_frame_handler(handler); +} + +int main(int argc, char** argv) { + frame_handler_test_frame_deframe(); + frame_handler_test_small_buffer(); + frame_handler_test_null_input_stream(); + frame_handler_test_bad_input_length(); + frame_handler_test_null_writer_byte_length(); + frame_handler_test_null_writer_bytes(); + frame_handler_test_bad_frame_length(); + frame_handler_test_unsupported_message_type(); + frame_handler_test_null_output_stream(); + frame_handler_test_null_reader_byte_length(); + frame_handler_test_null_reader_bytes(); + return 0; +} diff --git a/test/core/tsi/alts/handshaker/BUILD b/test/core/tsi/alts/handshaker/BUILD new file mode 100644 index 0000000000..fc2c395bdf --- /dev/null +++ b/test/core/tsi/alts/handshaker/BUILD @@ -0,0 +1,86 @@ +# Copyright 2018 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_package") + +licenses(["notice"]) # Apache v2 + +grpc_package(name = "handshaker") + +grpc_cc_library( + name = "alts_handshaker_service_api_test_lib", + srcs = ["alts_handshaker_service_api_test_lib.cc"], + hdrs = ["alts_handshaker_service_api_test_lib.h"], + deps = [ + "//:alts_util", + "//:grpc", + ], +) + +grpc_cc_test( + name = "alts_handshaker_client_test", + srcs = ["alts_handshaker_client_test.cc"], + language = "C++", + deps = [ + ":alts_handshaker_service_api_test_lib", + "//:tsi", + "//:tsi_interface", + "//:grpc", + ], +) + +grpc_cc_test( + name = "alts_handshaker_service_api_test", + srcs = ["alts_handshaker_service_api_test.cc"], + language = "C++", + deps = [ + ":alts_handshaker_service_api_test_lib", + "//:grpc", + ], +) + +grpc_cc_test( + name = "alts_tsi_handshaker_test", + srcs = ["alts_tsi_handshaker_test.cc"], + language = "C++", + deps = [ + ":alts_handshaker_service_api_test_lib", + "//:gpr", + "//:gpr_base", + "//:grpc", + "//:tsi", + ], +) + +grpc_cc_test( + name = "alts_tsi_utils_test", + srcs = ["alts_tsi_utils_test.cc"], + language = "C++", + deps = [ + ":alts_handshaker_service_api_test_lib", + "//:grpc", + "//:tsi", + ], +) + +grpc_cc_test( + name = "transport_security_common_api_test", + srcs = ["transport_security_common_api_test.cc"], + language = "C++", + deps = [ + "//:alts_util", + "//:grpc", + ], +) + diff --git a/test/core/tsi/alts/handshaker/alts_handshaker_client_test.cc b/test/core/tsi/alts/handshaker/alts_handshaker_client_test.cc new file mode 100644 index 0000000000..7072be6e3a --- /dev/null +++ b/test/core/tsi/alts/handshaker/alts_handshaker_client_test.cc @@ -0,0 +1,412 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/tsi/alts/handshaker/alts_handshaker_client.h" +#include "src/core/tsi/alts/handshaker/alts_tsi_event.h" +#include "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h" +#include "src/core/tsi/transport_security.h" +#include "src/core/tsi/transport_security_interface.h" +#include "test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h" + +#define ALTS_HANDSHAKER_CLIENT_TEST_OUT_FRAME "Hello Google" +#define ALTS_HANDSHAKER_CLIENT_TEST_HANDSHAKER_SERVICE_URL "lame" +#define ALTS_HANDSHAKER_CLIENT_TEST_TARGET_NAME "bigtable.google.api.com" +#define ALTS_HANDSHAKER_CLIENT_TEST_TARGET_SERVICE_ACCOUNT1 "A@google.com" +#define ALTS_HANDSHAKER_CLIENT_TEST_TARGET_SERVICE_ACCOUNT2 "B@google.com" + +const size_t kHandshakerClientOpNum = 4; +const size_t kMaxRpcVersionMajor = 3; +const size_t kMaxRpcVersionMinor = 2; +const size_t kMinRpcVersionMajor = 2; +const size_t kMinRpcVersionMinor = 1; + +using grpc_core::internal::alts_handshaker_client_set_grpc_caller_for_testing; + +typedef struct alts_handshaker_client_test_config { + grpc_channel* channel; + grpc_completion_queue* cq; + alts_handshaker_client* client; + grpc_slice out_frame; +} alts_handshaker_client_test_config; + +static alts_tsi_event* alts_tsi_event_create_for_testing(bool is_client) { + alts_tsi_event* e = static_cast(gpr_zalloc(sizeof(*e))); + grpc_metadata_array_init(&e->initial_metadata); + grpc_metadata_array_init(&e->trailing_metadata); + e->options = is_client ? grpc_alts_credentials_client_options_create() + : grpc_alts_credentials_server_options_create(); + if (is_client) { + grpc_alts_credentials_client_options_add_target_service_account( + reinterpret_cast(e->options), + ALTS_HANDSHAKER_CLIENT_TEST_TARGET_SERVICE_ACCOUNT1); + grpc_alts_credentials_client_options_add_target_service_account( + reinterpret_cast(e->options), + ALTS_HANDSHAKER_CLIENT_TEST_TARGET_SERVICE_ACCOUNT2); + } + grpc_gcp_rpc_protocol_versions* versions = &e->options->rpc_versions; + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_max( + versions, kMaxRpcVersionMajor, kMaxRpcVersionMinor)); + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_min( + versions, kMinRpcVersionMajor, kMinRpcVersionMinor)); + e->target_name = + grpc_slice_from_static_string(ALTS_HANDSHAKER_CLIENT_TEST_TARGET_NAME); + return e; +} + +static void validate_rpc_protocol_versions( + grpc_gcp_rpc_protocol_versions* versions) { + GPR_ASSERT(versions != nullptr); + GPR_ASSERT(versions->max_rpc_version.major == kMaxRpcVersionMajor); + GPR_ASSERT(versions->max_rpc_version.minor == kMaxRpcVersionMinor); + GPR_ASSERT(versions->min_rpc_version.major == kMinRpcVersionMajor); + GPR_ASSERT(versions->min_rpc_version.minor == kMinRpcVersionMinor); +} + +static void validate_target_identities( + const repeated_field* target_identity_head) { + grpc_gcp_identity* target_identity1 = static_cast( + const_cast(target_identity_head->next->data)); + grpc_gcp_identity* target_identity2 = static_cast( + const_cast(target_identity_head->data)); + grpc_slice* service_account1 = + static_cast(target_identity1->service_account.arg); + grpc_slice* service_account2 = + static_cast(target_identity2->service_account.arg); + GPR_ASSERT(memcmp(GRPC_SLICE_START_PTR(*service_account1), + ALTS_HANDSHAKER_CLIENT_TEST_TARGET_SERVICE_ACCOUNT1, + GRPC_SLICE_LENGTH(*service_account1)) == 0); + GPR_ASSERT(strlen(ALTS_HANDSHAKER_CLIENT_TEST_TARGET_SERVICE_ACCOUNT1) == + GRPC_SLICE_LENGTH(*service_account1)); + GPR_ASSERT(memcmp(GRPC_SLICE_START_PTR(*service_account2), + ALTS_HANDSHAKER_CLIENT_TEST_TARGET_SERVICE_ACCOUNT2, + GRPC_SLICE_LENGTH(*service_account2)) == 0); + GPR_ASSERT(strlen(ALTS_HANDSHAKER_CLIENT_TEST_TARGET_SERVICE_ACCOUNT2) == + GRPC_SLICE_LENGTH(*service_account2)); +} + +/** + * Validate if grpc operation data is correctly populated with the fields of + * ALTS TSI event. + */ +static bool validate_op(alts_tsi_event* event, const grpc_op* op, size_t nops, + bool is_start) { + GPR_ASSERT(event != nullptr && op != nullptr && nops != 0); + bool ok = true; + grpc_op* start_op = const_cast(op); + if (is_start) { + ok &= (op->op == GRPC_OP_SEND_INITIAL_METADATA); + ok &= (op->data.send_initial_metadata.count == 0); + op++; + GPR_ASSERT((size_t)(op - start_op) <= kHandshakerClientOpNum); + + ok &= (op->op == GRPC_OP_RECV_INITIAL_METADATA); + ok &= (op->data.recv_initial_metadata.recv_initial_metadata == + &event->initial_metadata); + op++; + GPR_ASSERT((size_t)(op - start_op) <= kHandshakerClientOpNum); + } + ok &= (op->op == GRPC_OP_SEND_MESSAGE); + ok &= (op->data.send_message.send_message == event->send_buffer); + op++; + GPR_ASSERT((size_t)(op - start_op) <= kHandshakerClientOpNum); + + ok &= (op->op == GRPC_OP_RECV_MESSAGE); + ok &= (op->data.recv_message.recv_message == &event->recv_buffer); + op++; + GPR_ASSERT((size_t)(op - start_op) <= kHandshakerClientOpNum); + + return ok; +} + +static grpc_gcp_handshaker_req* deserialize_handshaker_req( + grpc_gcp_handshaker_req_type type, grpc_byte_buffer* buffer) { + GPR_ASSERT(buffer != nullptr); + grpc_gcp_handshaker_req* req = grpc_gcp_handshaker_decoded_req_create(type); + grpc_byte_buffer_reader bbr; + GPR_ASSERT(grpc_byte_buffer_reader_init(&bbr, buffer)); + grpc_slice slice = grpc_byte_buffer_reader_readall(&bbr); + GPR_ASSERT(grpc_gcp_handshaker_req_decode(slice, req)); + grpc_slice_unref(slice); + grpc_byte_buffer_reader_destroy(&bbr); + return req; +} + +/** + * A mock grpc_caller used to check if client_start, server_start, and next + * operations correctly handle invalid arguments. It should not be called. + */ +static grpc_call_error check_must_not_be_called(grpc_call* call, + const grpc_op* ops, size_t nops, + void* tag) { + GPR_ASSERT(0); +} + +/** + * A mock grpc_caller used to check correct execution of client_start operation. + * It checks if the client_start handshaker request is populated with correct + * handshake_security_protocol, application_protocol, and record_protocol, and + * op is correctly populated. + */ +static grpc_call_error check_client_start_success(grpc_call* call, + const grpc_op* op, + size_t nops, void* tag) { + alts_tsi_event* event = static_cast(tag); + grpc_gcp_handshaker_req* req = + deserialize_handshaker_req(CLIENT_START_REQ, event->send_buffer); + GPR_ASSERT(req->client_start.handshake_security_protocol == + grpc_gcp_HandshakeProtocol_ALTS); + const void* data = (static_cast( + req->client_start.application_protocols.arg)) + ->data; + GPR_ASSERT(data != nullptr); + grpc_slice* application_protocol = (grpc_slice*)data; + data = (static_cast(req->client_start.record_protocols.arg)) + ->data; + grpc_slice* record_protocol = (grpc_slice*)data; + GPR_ASSERT(memcmp(GRPC_SLICE_START_PTR(*application_protocol), + ALTS_APPLICATION_PROTOCOL, + GRPC_SLICE_LENGTH(*application_protocol)) == 0); + GPR_ASSERT(memcmp(GRPC_SLICE_START_PTR(*record_protocol), + ALTS_RECORD_PROTOCOL, + GRPC_SLICE_LENGTH(*record_protocol)) == 0); + validate_rpc_protocol_versions(&req->client_start.rpc_versions); + validate_target_identities( + static_cast(req->client_start.target_identities.arg)); + grpc_slice* target_name = + static_cast(req->client_start.target_name.arg); + GPR_ASSERT(memcmp(GRPC_SLICE_START_PTR(*target_name), + ALTS_HANDSHAKER_CLIENT_TEST_TARGET_NAME, + GRPC_SLICE_LENGTH(*target_name)) == 0); + GPR_ASSERT(GRPC_SLICE_LENGTH(*target_name) == + strlen(ALTS_HANDSHAKER_CLIENT_TEST_TARGET_NAME)); + GPR_ASSERT(validate_op(event, op, nops, true /* is_start */)); + grpc_gcp_handshaker_req_destroy(req); + return GRPC_CALL_OK; +} + +/** + * A mock grpc_caller used to check correct execution of server_start operation. + * It checks if the server_start handshaker request is populated with correct + * handshake_security_protocol, application_protocol, and record_protocol, and + * op is correctly populated. + */ +static grpc_call_error check_server_start_success(grpc_call* call, + const grpc_op* op, + size_t nops, void* tag) { + alts_tsi_event* event = static_cast(tag); + grpc_gcp_handshaker_req* req = + deserialize_handshaker_req(SERVER_START_REQ, event->send_buffer); + const void* data = (static_cast( + req->server_start.application_protocols.arg)) + ->data; + GPR_ASSERT(data != nullptr); + grpc_slice* application_protocol = (grpc_slice*)data; + GPR_ASSERT(memcmp(GRPC_SLICE_START_PTR(*application_protocol), + ALTS_APPLICATION_PROTOCOL, + GRPC_SLICE_LENGTH(*application_protocol)) == 0); + GPR_ASSERT(req->server_start.handshake_parameters_count == 1); + GPR_ASSERT(req->server_start.handshake_parameters[0].key == + grpc_gcp_HandshakeProtocol_ALTS); + data = (static_cast(req->server_start.handshake_parameters[0] + .value.record_protocols.arg)) + ->data; + GPR_ASSERT(data != nullptr); + grpc_slice* record_protocol = (grpc_slice*)data; + GPR_ASSERT(memcmp(GRPC_SLICE_START_PTR(*record_protocol), + ALTS_RECORD_PROTOCOL, + GRPC_SLICE_LENGTH(*record_protocol)) == 0); + validate_rpc_protocol_versions(&req->server_start.rpc_versions); + GPR_ASSERT(validate_op(event, op, nops, true /* is_start */)); + grpc_gcp_handshaker_req_destroy(req); + return GRPC_CALL_OK; +} + +/** + * A mock grpc_caller used to check correct execution of next operation. It + * checks if the next handshaker request is populated with correct information, + * and op is correctly populated. + */ +static grpc_call_error check_next_success(grpc_call* call, const grpc_op* op, + size_t nops, void* tag) { + alts_tsi_event* event = static_cast(tag); + grpc_gcp_handshaker_req* req = + deserialize_handshaker_req(NEXT_REQ, event->send_buffer); + grpc_slice* in_bytes = static_cast(req->next.in_bytes.arg); + GPR_ASSERT(in_bytes != nullptr); + GPR_ASSERT(memcmp(GRPC_SLICE_START_PTR(*in_bytes), + ALTS_HANDSHAKER_CLIENT_TEST_OUT_FRAME, + GRPC_SLICE_LENGTH(*in_bytes)) == 0); + GPR_ASSERT(validate_op(event, op, nops, false /* is_start */)); + grpc_gcp_handshaker_req_destroy(req); + return GRPC_CALL_OK; +} +/** + * A mock grpc_caller used to check if client_start, server_start, and next + * operations correctly handle the situation when the grpc call made to the + * handshaker service fails. + */ +static grpc_call_error check_grpc_call_failure(grpc_call* call, + const grpc_op* op, size_t nops, + void* tag) { + return GRPC_CALL_ERROR; +} + +static alts_handshaker_client_test_config* create_config() { + alts_handshaker_client_test_config* config = + static_cast( + gpr_zalloc(sizeof(*config))); + config->channel = grpc_insecure_channel_create( + ALTS_HANDSHAKER_CLIENT_TEST_HANDSHAKER_SERVICE_URL, nullptr, nullptr); + config->cq = grpc_completion_queue_create_for_next(nullptr); + config->client = alts_grpc_handshaker_client_create( + config->channel, config->cq, + ALTS_HANDSHAKER_CLIENT_TEST_HANDSHAKER_SERVICE_URL); + GPR_ASSERT(config->client != nullptr); + config->out_frame = + grpc_slice_from_static_string(ALTS_HANDSHAKER_CLIENT_TEST_OUT_FRAME); + return config; +} + +static void destroy_config(alts_handshaker_client_test_config* config) { + if (config == nullptr) { + return; + } + grpc_completion_queue_destroy(config->cq); + grpc_channel_destroy(config->channel); + alts_handshaker_client_destroy(config->client); + grpc_slice_unref(config->out_frame); + gpr_free(config); +} + +static void schedule_request_invalid_arg_test() { + /* Initialization. */ + alts_handshaker_client_test_config* config = create_config(); + alts_tsi_event* event = nullptr; + + /* Tests. */ + alts_handshaker_client_set_grpc_caller_for_testing(config->client, + check_must_not_be_called); + event = alts_tsi_event_create_for_testing(true /* is_client */); + /* Check client_start. */ + GPR_ASSERT(alts_handshaker_client_start_client(nullptr, event) == + TSI_INVALID_ARGUMENT); + GPR_ASSERT(alts_handshaker_client_start_client(config->client, nullptr) == + TSI_INVALID_ARGUMENT); + + /* Check server_start. */ + GPR_ASSERT(alts_handshaker_client_start_server( + config->client, event, nullptr) == TSI_INVALID_ARGUMENT); + GPR_ASSERT(alts_handshaker_client_start_server(config->client, nullptr, + &config->out_frame) == + TSI_INVALID_ARGUMENT); + GPR_ASSERT(alts_handshaker_client_start_server( + nullptr, event, &config->out_frame) == TSI_INVALID_ARGUMENT); + + /* Check next. */ + GPR_ASSERT(alts_handshaker_client_next(config->client, event, nullptr) == + TSI_INVALID_ARGUMENT); + GPR_ASSERT(alts_handshaker_client_next(config->client, nullptr, + &config->out_frame) == + TSI_INVALID_ARGUMENT); + GPR_ASSERT(alts_handshaker_client_next(nullptr, event, &config->out_frame) == + TSI_INVALID_ARGUMENT); + + /* Cleanup. */ + alts_tsi_event_destroy(event); + destroy_config(config); +} + +static void schedule_request_success_test() { + /* Initialization. */ + alts_handshaker_client_test_config* config = create_config(); + alts_tsi_event* event = nullptr; + + /* Check client_start success. */ + alts_handshaker_client_set_grpc_caller_for_testing( + config->client, check_client_start_success); + event = alts_tsi_event_create_for_testing(true /* is_client. */); + GPR_ASSERT(alts_handshaker_client_start_client(config->client, event) == + TSI_OK); + alts_tsi_event_destroy(event); + + /* Check server_start success. */ + alts_handshaker_client_set_grpc_caller_for_testing( + config->client, check_server_start_success); + event = alts_tsi_event_create_for_testing(false /* is_client. */); + GPR_ASSERT(alts_handshaker_client_start_server(config->client, event, + &config->out_frame) == TSI_OK); + alts_tsi_event_destroy(event); + + /* Check next success. */ + alts_handshaker_client_set_grpc_caller_for_testing(config->client, + check_next_success); + event = alts_tsi_event_create_for_testing(true /* is_client. */); + GPR_ASSERT(alts_handshaker_client_next(config->client, event, + &config->out_frame) == TSI_OK); + alts_tsi_event_destroy(event); + + /* Cleanup. */ + destroy_config(config); +} + +static void schedule_request_grpc_call_failure_test() { + /* Initialization. */ + alts_handshaker_client_test_config* config = create_config(); + alts_tsi_event* event = nullptr; + + /* Check client_start failure. */ + alts_handshaker_client_set_grpc_caller_for_testing(config->client, + check_grpc_call_failure); + event = alts_tsi_event_create_for_testing(true /* is_client. */); + GPR_ASSERT(alts_handshaker_client_start_client(config->client, event) == + TSI_INTERNAL_ERROR); + alts_tsi_event_destroy(event); + + /* Check server_start failure. */ + event = alts_tsi_event_create_for_testing(false /* is_client. */); + GPR_ASSERT(alts_handshaker_client_start_server(config->client, event, + &config->out_frame) == + TSI_INTERNAL_ERROR); + alts_tsi_event_destroy(event); + + /* Check next failure. */ + event = alts_tsi_event_create_for_testing(true /* is_cleint. */); + GPR_ASSERT( + alts_handshaker_client_next(config->client, event, &config->out_frame) == + TSI_INTERNAL_ERROR); + alts_tsi_event_destroy(event); + + /* Cleanup. */ + destroy_config(config); +} + +int main(int argc, char** argv) { + /* Initialization. */ + grpc_init(); + + /* Tests. */ + schedule_request_invalid_arg_test(); + schedule_request_success_test(); + schedule_request_grpc_call_failure_test(); + + /* Cleanup. */ + grpc_shutdown(); + return 0; +} diff --git a/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test.cc b/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test.cc new file mode 100644 index 0000000000..3506264f52 --- /dev/null +++ b/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test.cc @@ -0,0 +1,149 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include + +#include "test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h" + +int main(int argc, char** argv) { + const char in_bytes[] = "HELLO GOOGLE!"; + const char out_frames[] = "HELLO WORLD!"; + const char key_data[] = "THIS IS KEY DATA."; + const char details[] = "DETAILS NEED TO BE POPULATED"; + const uint32_t max_rpc_version_major = 3; + const uint32_t max_rpc_version_minor = 2; + const uint32_t min_rpc_version_major = 2; + const uint32_t min_rpc_version_minor = 1; + + /* handshaker_req_next. */ + grpc_gcp_handshaker_req* req = grpc_gcp_handshaker_req_create(NEXT_REQ); + grpc_gcp_handshaker_req* decoded_req = + grpc_gcp_handshaker_decoded_req_create(NEXT_REQ); + GPR_ASSERT( + grpc_gcp_handshaker_req_set_in_bytes(req, in_bytes, strlen(in_bytes))); + grpc_slice encoded_req; + GPR_ASSERT(grpc_gcp_handshaker_req_encode(req, &encoded_req)); + GPR_ASSERT(grpc_gcp_handshaker_req_decode(encoded_req, decoded_req)); + GPR_ASSERT(grpc_gcp_handshaker_req_equals(req, decoded_req)); + grpc_gcp_handshaker_req_destroy(req); + grpc_gcp_handshaker_req_destroy(decoded_req); + grpc_slice_unref(encoded_req); + + /* handshaker_req_client_start. */ + req = grpc_gcp_handshaker_req_create(CLIENT_START_REQ); + decoded_req = grpc_gcp_handshaker_decoded_req_create(CLIENT_START_REQ); + GPR_ASSERT(grpc_gcp_handshaker_req_set_handshake_protocol( + req, grpc_gcp_HandshakeProtocol_TLS)); + GPR_ASSERT(grpc_gcp_handshaker_req_set_local_identity_hostname( + req, "www.google.com")); + GPR_ASSERT(grpc_gcp_handshaker_req_set_local_endpoint( + req, "2001:db8::8:800:200C:417a", 9876, grpc_gcp_NetworkProtocol_TCP)); + GPR_ASSERT(grpc_gcp_handshaker_req_set_remote_endpoint( + req, "2001:db8::bac5::fed0:84a2", 1234, grpc_gcp_NetworkProtocol_TCP)); + GPR_ASSERT(grpc_gcp_handshaker_req_add_application_protocol(req, "grpc")); + GPR_ASSERT(grpc_gcp_handshaker_req_add_application_protocol(req, "http2")); + GPR_ASSERT( + grpc_gcp_handshaker_req_add_record_protocol(req, "ALTSRP_GCM_AES256")); + GPR_ASSERT( + grpc_gcp_handshaker_req_add_record_protocol(req, "ALTSRP_GCM_AES384")); + GPR_ASSERT(grpc_gcp_handshaker_req_add_target_identity_service_account( + req, "foo@google.com")); + GPR_ASSERT(grpc_gcp_handshaker_req_set_target_name( + req, "google.example.library.service")); + GPR_ASSERT(grpc_gcp_handshaker_req_set_rpc_versions( + req, max_rpc_version_major, max_rpc_version_minor, min_rpc_version_major, + min_rpc_version_minor)); + GPR_ASSERT(grpc_gcp_handshaker_req_encode(req, &encoded_req)); + GPR_ASSERT(grpc_gcp_handshaker_req_decode(encoded_req, decoded_req)); + GPR_ASSERT(grpc_gcp_handshaker_req_equals(req, decoded_req)); + grpc_gcp_handshaker_req_destroy(req); + grpc_gcp_handshaker_req_destroy(decoded_req); + grpc_slice_unref(encoded_req); + + /* handshaker_req_server_start. */ + req = grpc_gcp_handshaker_req_create(SERVER_START_REQ); + decoded_req = grpc_gcp_handshaker_decoded_req_create(SERVER_START_REQ); + GPR_ASSERT(grpc_gcp_handshaker_req_add_application_protocol(req, "grpc")); + GPR_ASSERT(grpc_gcp_handshaker_req_add_application_protocol(req, "http2")); + GPR_ASSERT(grpc_gcp_handshaker_req_set_local_endpoint( + req, "2001:db8::8:800:200C:417a", 9876, grpc_gcp_NetworkProtocol_TCP)); + GPR_ASSERT(grpc_gcp_handshaker_req_set_remote_endpoint( + req, "2001:db8::bac5::fed0:84a2", 1234, grpc_gcp_NetworkProtocol_UDP)); + GPR_ASSERT( + grpc_gcp_handshaker_req_set_in_bytes(req, in_bytes, strlen(in_bytes))); + GPR_ASSERT(grpc_gcp_handshaker_req_param_add_record_protocol( + req, grpc_gcp_HandshakeProtocol_TLS, "ALTSRP_GCM_AES128")); + GPR_ASSERT(grpc_gcp_handshaker_req_param_add_local_identity_service_account( + req, grpc_gcp_HandshakeProtocol_TLS, "foo@google.com")); + GPR_ASSERT(grpc_gcp_handshaker_req_param_add_local_identity_hostname( + req, grpc_gcp_HandshakeProtocol_TLS, "yihuaz0.mtv.corp.google.com")); + GPR_ASSERT(grpc_gcp_handshaker_req_param_add_record_protocol( + req, grpc_gcp_HandshakeProtocol_ALTS, "ALTSRP_GCM_AES128")); + GPR_ASSERT(grpc_gcp_handshaker_req_param_add_local_identity_hostname( + req, grpc_gcp_HandshakeProtocol_ALTS, "www.amazon.com")); + GPR_ASSERT(grpc_gcp_handshaker_req_set_rpc_versions( + req, max_rpc_version_major, max_rpc_version_minor, min_rpc_version_major, + min_rpc_version_minor)); + + GPR_ASSERT(grpc_gcp_handshaker_req_encode(req, &encoded_req)); + GPR_ASSERT(grpc_gcp_handshaker_req_decode(encoded_req, decoded_req)); + GPR_ASSERT(grpc_gcp_handshaker_req_equals(req, decoded_req)); + grpc_gcp_handshaker_req_destroy(req); + grpc_gcp_handshaker_req_destroy(decoded_req); + grpc_slice_unref(encoded_req); + + /* handshaker_resp. */ + grpc_gcp_handshaker_resp* resp = grpc_gcp_handshaker_resp_create(); + grpc_gcp_handshaker_resp* decoded_resp = grpc_gcp_handshaker_resp_create(); + GPR_ASSERT(grpc_gcp_handshaker_resp_set_out_frames(resp, out_frames, + strlen(out_frames))); + GPR_ASSERT(grpc_gcp_handshaker_resp_set_bytes_consumed(resp, 1024)); + GPR_ASSERT(grpc_gcp_handshaker_resp_set_application_protocol(resp, "http")); + GPR_ASSERT( + grpc_gcp_handshaker_resp_set_record_protocol(resp, "ALTSRP_GCM_AES128")); + GPR_ASSERT( + grpc_gcp_handshaker_resp_set_key_data(resp, key_data, strlen(key_data))); + GPR_ASSERT(grpc_gcp_handshaker_resp_set_local_identity_hostname( + resp, "www.faceboook.com")); + GPR_ASSERT(grpc_gcp_handshaker_resp_set_peer_identity_hostname( + resp, "www.amazon.com")); + GPR_ASSERT(grpc_gcp_handshaker_resp_set_channel_open( + resp, false /* channel_open */)); + GPR_ASSERT(grpc_gcp_handshaker_resp_set_code(resp, 1023)); + GPR_ASSERT(grpc_gcp_handshaker_resp_set_details(resp, details)); + GPR_ASSERT(grpc_gcp_handshaker_resp_set_peer_rpc_versions( + resp, max_rpc_version_major, max_rpc_version_minor, min_rpc_version_major, + min_rpc_version_minor)); + grpc_slice encoded_resp; + GPR_ASSERT(grpc_gcp_handshaker_resp_encode(resp, &encoded_resp)); + GPR_ASSERT(grpc_gcp_handshaker_resp_decode(encoded_resp, decoded_resp)); + GPR_ASSERT(grpc_gcp_handshaker_resp_equals(resp, decoded_resp)); + grpc_gcp_handshaker_resp_destroy(resp); + grpc_gcp_handshaker_resp_destroy(decoded_resp); + grpc_slice_unref(encoded_resp); + /* Test invalid arguments. */ + GPR_ASSERT(!grpc_gcp_handshaker_req_set_in_bytes(nullptr, in_bytes, + strlen(in_bytes))); + GPR_ASSERT(!grpc_gcp_handshaker_req_param_add_record_protocol( + req, grpc_gcp_HandshakeProtocol_TLS, nullptr)); + GPR_ASSERT(!grpc_gcp_handshaker_req_param_add_local_identity_service_account( + nullptr, grpc_gcp_HandshakeProtocol_TLS, nullptr)); + GPR_ASSERT(!grpc_gcp_handshaker_resp_set_record_protocol(nullptr, nullptr)); +} diff --git a/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc b/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc new file mode 100644 index 0000000000..ecca04defa --- /dev/null +++ b/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc @@ -0,0 +1,642 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h" + +const size_t kHandshakeProtocolNum = 3; + +grpc_gcp_handshaker_req* grpc_gcp_handshaker_decoded_req_create( + grpc_gcp_handshaker_req_type type) { + grpc_gcp_handshaker_req* req = + static_cast(gpr_zalloc(sizeof(*req))); + switch (type) { + case CLIENT_START_REQ: + req->has_client_start = true; + req->client_start.target_identities.funcs.decode = + decode_repeated_identity_cb; + req->client_start.application_protocols.funcs.decode = + decode_repeated_string_cb; + req->client_start.record_protocols.funcs.decode = + decode_repeated_string_cb; + req->client_start.local_identity.hostname.funcs.decode = + decode_string_or_bytes_cb; + req->client_start.local_identity.service_account.funcs.decode = + decode_string_or_bytes_cb; + req->client_start.local_endpoint.ip_address.funcs.decode = + decode_string_or_bytes_cb; + req->client_start.remote_endpoint.ip_address.funcs.decode = + decode_string_or_bytes_cb; + req->client_start.target_name.funcs.decode = decode_string_or_bytes_cb; + break; + case SERVER_START_REQ: + req->has_server_start = true; + req->server_start.application_protocols.funcs.decode = + &decode_repeated_string_cb; + for (size_t i = 0; i < kHandshakeProtocolNum; i++) { + req->server_start.handshake_parameters[i] + .value.local_identities.funcs.decode = &decode_repeated_identity_cb; + req->server_start.handshake_parameters[i] + .value.record_protocols.funcs.decode = &decode_repeated_string_cb; + } + req->server_start.in_bytes.funcs.decode = decode_string_or_bytes_cb; + req->server_start.local_endpoint.ip_address.funcs.decode = + decode_string_or_bytes_cb; + req->server_start.remote_endpoint.ip_address.funcs.decode = + decode_string_or_bytes_cb; + break; + case NEXT_REQ: + req->has_next = true; + break; + } + return req; +} + +bool grpc_gcp_handshaker_resp_set_application_protocol( + grpc_gcp_handshaker_resp* resp, const char* application_protocol) { + if (resp == nullptr || application_protocol == nullptr) { + gpr_log(GPR_ERROR, + "Invalid nullptr arguments to " + "handshaker_resp_set_application_protocol()."); + return false; + } + resp->has_result = true; + grpc_slice* slice = + create_slice(application_protocol, strlen(application_protocol)); + resp->result.application_protocol.arg = slice; + resp->result.application_protocol.funcs.encode = encode_string_or_bytes_cb; + return true; +} + +bool grpc_gcp_handshaker_resp_set_record_protocol( + grpc_gcp_handshaker_resp* resp, const char* record_protocol) { + if (resp == nullptr || record_protocol == nullptr) { + gpr_log(GPR_ERROR, + "Invalid nullptr arguments to " + "handshaker_resp_set_record_protocol()."); + return false; + } + resp->has_result = true; + grpc_slice* slice = create_slice(record_protocol, strlen(record_protocol)); + resp->result.record_protocol.arg = slice; + resp->result.record_protocol.funcs.encode = encode_string_or_bytes_cb; + return true; +} + +bool grpc_gcp_handshaker_resp_set_key_data(grpc_gcp_handshaker_resp* resp, + const char* key_data, size_t size) { + if (resp == nullptr || key_data == nullptr) { + gpr_log(GPR_ERROR, + "Invalid nullptr arguments to handshaker_resp_set_key_data()."); + return false; + } + resp->has_result = true; + grpc_slice* slice = create_slice(key_data, size); + resp->result.key_data.arg = slice; + resp->result.key_data.funcs.encode = encode_string_or_bytes_cb; + return true; +} + +static void set_identity_hostname(grpc_gcp_identity* identity, + const char* hostname) { + grpc_slice* slice = create_slice(hostname, strlen(hostname)); + identity->hostname.arg = slice; + identity->hostname.funcs.encode = encode_string_or_bytes_cb; +} + +static void set_identity_service_account(grpc_gcp_identity* identity, + const char* service_account) { + grpc_slice* slice = create_slice(service_account, strlen(service_account)); + identity->service_account.arg = slice; + identity->service_account.funcs.encode = encode_string_or_bytes_cb; +} + +bool grpc_gcp_handshaker_resp_set_local_identity_hostname( + grpc_gcp_handshaker_resp* resp, const char* hostname) { + if (resp == nullptr || hostname == nullptr) { + gpr_log(GPR_ERROR, + "Invalid nullptr arguments to " + "grpc_gcp_handshaker_resp_set_local_identity_hostname()."); + return false; + } + resp->has_result = true; + resp->result.has_local_identity = true; + set_identity_hostname(&resp->result.local_identity, hostname); + return true; +} + +bool grpc_gcp_handshaker_resp_set_local_identity_service_account( + grpc_gcp_handshaker_resp* resp, const char* service_account) { + if (resp == nullptr || service_account == nullptr) { + gpr_log(GPR_ERROR, + "Invalid nullptr arguments to " + "grpc_gcp_handshaker_resp_set_local_identity_service_account()."); + return false; + } + resp->has_result = true; + resp->result.has_local_identity = true; + set_identity_service_account(&resp->result.local_identity, service_account); + return true; +} + +bool grpc_gcp_handshaker_resp_set_peer_identity_hostname( + grpc_gcp_handshaker_resp* resp, const char* hostname) { + if (resp == nullptr || hostname == nullptr) { + gpr_log(GPR_ERROR, + "Invalid nullptr arguments to " + "grpc_gcp_handshaker_resp_set_peer_identity_hostname()."); + return false; + } + resp->has_result = true; + resp->result.has_peer_identity = true; + set_identity_hostname(&resp->result.peer_identity, hostname); + return true; +} + +bool grpc_gcp_handshaker_resp_set_peer_identity_service_account( + grpc_gcp_handshaker_resp* resp, const char* service_account) { + if (resp == nullptr || service_account == nullptr) { + gpr_log(GPR_ERROR, + "Invalid nullptr arguments to " + "grpc_gcp_handshaker_resp_set_peer_identity_service_account()."); + return false; + } + resp->has_result = true; + resp->result.has_peer_identity = true; + set_identity_service_account(&resp->result.peer_identity, service_account); + return true; +} + +bool grpc_gcp_handshaker_resp_set_channel_open(grpc_gcp_handshaker_resp* resp, + bool keep_channel_open) { + if (resp == nullptr) { + gpr_log(GPR_ERROR, + "Invalid nullptr argument to " + "grpc_gcp_handshaker_resp_set_channel_open()."); + return false; + } + resp->has_result = true; + resp->result.has_keep_channel_open = true; + resp->result.keep_channel_open = keep_channel_open; + return true; +} + +bool grpc_gcp_handshaker_resp_set_code(grpc_gcp_handshaker_resp* resp, + uint32_t code) { + if (resp == nullptr) { + gpr_log(GPR_ERROR, + "Invalid nullptr argument to grpc_gcp_handshaker_resp_set_code()."); + return false; + } + resp->has_status = true; + resp->status.has_code = true; + resp->status.code = code; + return true; +} + +bool grpc_gcp_handshaker_resp_set_details(grpc_gcp_handshaker_resp* resp, + const char* details) { + if (resp == nullptr || details == nullptr) { + gpr_log( + GPR_ERROR, + "Invalid nullptr arguments to grpc_gcp_handshaker_resp_set_details()."); + return false; + } + resp->has_status = true; + grpc_slice* slice = create_slice(details, strlen(details)); + resp->status.details.arg = slice; + resp->status.details.funcs.encode = encode_string_or_bytes_cb; + return true; +} + +bool grpc_gcp_handshaker_resp_set_out_frames(grpc_gcp_handshaker_resp* resp, + const char* out_frames, + size_t size) { + if (resp == nullptr || out_frames == nullptr) { + gpr_log(GPR_ERROR, + "Invalid nullptr arguments to " + "grpc_gcp_handshaker_resp_set_out_frames()."); + return false; + } + grpc_slice* slice = create_slice(out_frames, size); + resp->out_frames.arg = slice; + resp->out_frames.funcs.encode = encode_string_or_bytes_cb; + return true; +} + +bool grpc_gcp_handshaker_resp_set_bytes_consumed(grpc_gcp_handshaker_resp* resp, + int32_t bytes_consumed) { + if (resp == nullptr) { + gpr_log(GPR_ERROR, + "Invalid nullptr argument to " + "grpc_gcp_handshaker_resp_set_bytes_consumed()."); + return false; + } + resp->has_bytes_consumed = true; + resp->bytes_consumed = bytes_consumed; + return true; +} + +bool grpc_gcp_handshaker_resp_set_peer_rpc_versions( + grpc_gcp_handshaker_resp* resp, uint32_t max_major, uint32_t max_minor, + uint32_t min_major, uint32_t min_minor) { + if (resp == nullptr) { + gpr_log(GPR_ERROR, + "Invalid nullptr argument to " + "grpc_gcp_handshaker_resp_set_peer_rpc_versions()."); + return false; + } + resp->has_result = true; + resp->result.has_peer_rpc_versions = true; + grpc_gcp_rpc_protocol_versions* versions = &resp->result.peer_rpc_versions; + versions->has_max_rpc_version = true; + versions->has_min_rpc_version = true; + versions->max_rpc_version.has_major = true; + versions->max_rpc_version.has_minor = true; + versions->min_rpc_version.has_major = true; + versions->min_rpc_version.has_minor = true; + versions->max_rpc_version.major = max_major; + versions->max_rpc_version.minor = max_minor; + versions->min_rpc_version.major = min_major; + versions->min_rpc_version.minor = min_minor; + return true; +} + +bool grpc_gcp_handshaker_resp_encode(grpc_gcp_handshaker_resp* resp, + grpc_slice* slice) { + if (resp == nullptr || slice == nullptr) { + gpr_log(GPR_ERROR, + "Invalid nullptr arguments to grpc_gcp_handshaker_resp_encode()."); + return false; + } + pb_ostream_t size_stream; + memset(&size_stream, 0, sizeof(pb_ostream_t)); + if (!pb_encode(&size_stream, grpc_gcp_HandshakerResp_fields, resp)) { + gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&size_stream)); + return false; + } + size_t encoded_length = size_stream.bytes_written; + *slice = grpc_slice_malloc(encoded_length); + pb_ostream_t output_stream = + pb_ostream_from_buffer(GRPC_SLICE_START_PTR(*slice), encoded_length); + if (!pb_encode(&output_stream, grpc_gcp_HandshakerResp_fields, resp)) { + gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&size_stream)); + return false; + } + return true; +} + +bool grpc_gcp_handshaker_req_decode(grpc_slice slice, + grpc_gcp_handshaker_req* req) { + if (req == nullptr) { + gpr_log(GPR_ERROR, + "Invalid nullptr argument to grpc_gcp_handshaker_req_decode()."); + return false; + } + pb_istream_t stream = pb_istream_from_buffer(GRPC_SLICE_START_PTR(slice), + GRPC_SLICE_LENGTH(slice)); + req->next.in_bytes.funcs.decode = decode_string_or_bytes_cb; + if (!pb_decode(&stream, grpc_gcp_HandshakerReq_fields, req)) { + gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&stream)); + return false; + } + return true; +} + +/* Check equality of a pair of grpc_slice fields. */ +static bool slice_equals(grpc_slice* l_slice, grpc_slice* r_slice) { + if (l_slice == nullptr && r_slice == nullptr) { + return true; + } + if (l_slice != nullptr && r_slice != nullptr) { + return grpc_slice_eq(*l_slice, *r_slice); + } + return false; +} + +/* Check equality of a pair of grpc_gcp_identity fields. */ +static bool handshaker_identity_equals(const grpc_gcp_identity* l_id, + const grpc_gcp_identity* r_id) { + if (!((l_id->hostname.arg != nullptr) != (r_id->hostname.arg != nullptr))) { + if (l_id->hostname.arg != nullptr) { + return slice_equals(static_cast(l_id->hostname.arg), + static_cast(r_id->hostname.arg)); + } + } else { + return false; + } + if (!((l_id->service_account.arg != nullptr) != + (r_id->service_account.arg != nullptr))) { + if (l_id->service_account.arg != nullptr) { + return slice_equals(static_cast(l_id->service_account.arg), + static_cast(r_id->service_account.arg)); + } + } else { + return false; + } + return true; +} + +static bool handshaker_rpc_versions_equals( + const grpc_gcp_rpc_protocol_versions* l_version, + const grpc_gcp_rpc_protocol_versions* r_version) { + bool result = true; + result &= + (l_version->max_rpc_version.major == r_version->max_rpc_version.major); + result &= + (l_version->max_rpc_version.minor == r_version->max_rpc_version.minor); + result &= + (l_version->min_rpc_version.major == r_version->min_rpc_version.major); + result &= + (l_version->min_rpc_version.minor == r_version->min_rpc_version.minor); + return result; +} + +/* Check equality of a pair of grpc_gcp_endpoint fields. */ +static bool handshaker_endpoint_equals(const grpc_gcp_endpoint* l_end, + const grpc_gcp_endpoint* r_end) { + bool result = true; + result &= (l_end->port == r_end->port); + result &= (l_end->protocol == r_end->protocol); + if (!((l_end->ip_address.arg != nullptr) != + (r_end->ip_address.arg != nullptr))) { + if (l_end->ip_address.arg != nullptr) { + result &= slice_equals(static_cast(l_end->ip_address.arg), + static_cast(r_end->ip_address.arg)); + } + } else { + return false; + } + return result; +} +/** + * Check if a specific repeated field (i.e., target) is contained in a repeated + * field list (i.e., head). + */ +static bool repeated_field_list_contains_identity( + const repeated_field* head, const repeated_field* target) { + repeated_field* field = const_cast(head); + while (field != nullptr) { + if (handshaker_identity_equals( + static_cast(field->data), + static_cast(target->data))) { + return true; + } + field = field->next; + } + return false; +} + +static bool repeated_field_list_contains_string(const repeated_field* head, + const repeated_field* target) { + repeated_field* field = const_cast(head); + while (field != nullptr) { + if (slice_equals((grpc_slice*)field->data, (grpc_slice*)target->data)) { + return true; + } + field = field->next; + } + return false; +} + +/* Return a length of repeated field list. */ +static size_t repeated_field_list_get_length(const repeated_field* head) { + repeated_field* field = const_cast(head); + size_t len = 0; + while (field != nullptr) { + len++; + field = field->next; + } + return len; +} + +/** + * Check if a pair of repeated field lists contain the same set of repeated + * fields. + */ +static bool repeated_field_list_equals_identity(const repeated_field* l_head, + const repeated_field* r_head) { + if (repeated_field_list_get_length(l_head) != + repeated_field_list_get_length(r_head)) { + return false; + } + repeated_field* field = const_cast(l_head); + repeated_field* head = const_cast(r_head); + while (field != nullptr) { + if (!repeated_field_list_contains_identity(head, field)) { + return false; + } + field = field->next; + } + return true; +} + +static bool repeated_field_list_equals_string(const repeated_field* l_head, + const repeated_field* r_head) { + if (repeated_field_list_get_length(l_head) != + repeated_field_list_get_length(r_head)) { + return false; + } + repeated_field* field = const_cast(l_head); + repeated_field* head = const_cast(r_head); + while (field != nullptr) { + if (!repeated_field_list_contains_string(head, field)) { + return false; + } + field = field->next; + } + return true; +} + +/* Check equality of a pair of ALTS client_start handshake requests. */ +bool grpc_gcp_handshaker_client_start_req_equals( + grpc_gcp_start_client_handshake_req* l_req, + grpc_gcp_start_client_handshake_req* r_req) { + bool result = true; + /* Compare handshake_security_protocol. */ + result &= + l_req->handshake_security_protocol == r_req->handshake_security_protocol; + /* Compare application_protocols, record_protocols, and target_identities. */ + result &= repeated_field_list_equals_string( + static_cast(l_req->application_protocols.arg), + static_cast(r_req->application_protocols.arg)); + result &= repeated_field_list_equals_string( + static_cast(l_req->record_protocols.arg), + static_cast(r_req->record_protocols.arg)); + result &= repeated_field_list_equals_identity( + static_cast(l_req->target_identities.arg), + static_cast(r_req->target_identities.arg)); + if ((l_req->has_local_identity ^ r_req->has_local_identity) | + (l_req->has_local_endpoint ^ r_req->has_local_endpoint) | + ((l_req->has_remote_endpoint ^ r_req->has_remote_endpoint)) | + (l_req->has_rpc_versions ^ r_req->has_rpc_versions)) { + return false; + } + /* Compare local_identity, local_endpoint, and remote_endpoint. */ + if (l_req->has_local_identity) { + result &= handshaker_identity_equals(&l_req->local_identity, + &r_req->local_identity); + } + if (l_req->has_local_endpoint) { + result &= handshaker_endpoint_equals(&l_req->local_endpoint, + &r_req->local_endpoint); + } + if (l_req->has_remote_endpoint) { + result &= handshaker_endpoint_equals(&l_req->remote_endpoint, + &r_req->remote_endpoint); + } + if (l_req->has_rpc_versions) { + result &= handshaker_rpc_versions_equals(&l_req->rpc_versions, + &r_req->rpc_versions); + } + return result; +} + +/* Check equality of a pair of ALTS server_start handshake requests. */ +bool grpc_gcp_handshaker_server_start_req_equals( + grpc_gcp_start_server_handshake_req* l_req, + grpc_gcp_start_server_handshake_req* r_req) { + bool result = true; + /* Compare application_protocols. */ + result &= repeated_field_list_equals_string( + static_cast(l_req->application_protocols.arg), + static_cast(r_req->application_protocols.arg)); + /* Compare handshake_parameters. */ + size_t i = 0, j = 0; + result &= + (l_req->handshake_parameters_count == r_req->handshake_parameters_count); + for (i = 0; i < l_req->handshake_parameters_count; i++) { + bool found = false; + for (j = 0; j < r_req->handshake_parameters_count; j++) { + if (l_req->handshake_parameters[i].key == + r_req->handshake_parameters[j].key) { + found = true; + result &= repeated_field_list_equals_string( + static_cast( + l_req->handshake_parameters[i].value.record_protocols.arg), + static_cast( + r_req->handshake_parameters[j].value.record_protocols.arg)); + result &= repeated_field_list_equals_identity( + static_cast( + l_req->handshake_parameters[i].value.local_identities.arg), + static_cast( + r_req->handshake_parameters[j].value.local_identities.arg)); + } + } + if (!found) { + return false; + } + } + /* Compare in_bytes, local_endpoint, remote_endpoint. */ + result &= slice_equals(static_cast(l_req->in_bytes.arg), + static_cast(r_req->in_bytes.arg)); + if ((l_req->has_local_endpoint ^ r_req->has_local_endpoint) | + (l_req->has_remote_endpoint ^ r_req->has_remote_endpoint) | + (l_req->has_rpc_versions ^ r_req->has_rpc_versions)) + return false; + if (l_req->has_local_endpoint) { + result &= handshaker_endpoint_equals(&l_req->local_endpoint, + &r_req->local_endpoint); + } + if (l_req->has_remote_endpoint) { + result &= handshaker_endpoint_equals(&l_req->remote_endpoint, + &r_req->remote_endpoint); + } + if (l_req->has_rpc_versions) { + result &= handshaker_rpc_versions_equals(&l_req->rpc_versions, + &r_req->rpc_versions); + } + return result; +} + +/* Check equality of a pair of ALTS handshake requests. */ +bool grpc_gcp_handshaker_req_equals(grpc_gcp_handshaker_req* l_req, + grpc_gcp_handshaker_req* r_req) { + if (l_req->has_next && r_req->has_next) { + return slice_equals(static_cast(l_req->next.in_bytes.arg), + static_cast(r_req->next.in_bytes.arg)); + } else if (l_req->has_client_start && r_req->has_client_start) { + return grpc_gcp_handshaker_client_start_req_equals(&l_req->client_start, + &r_req->client_start); + } else if (l_req->has_server_start && r_req->has_server_start) { + return grpc_gcp_handshaker_server_start_req_equals(&l_req->server_start, + &r_req->server_start); + } + return false; +} + +/* Check equality of a pair of ALTS handshake results. */ +bool grpc_gcp_handshaker_resp_result_equals( + grpc_gcp_handshaker_result* l_result, + grpc_gcp_handshaker_result* r_result) { + bool result = true; + /* Compare application_protocol, record_protocol, and key_data. */ + result &= slice_equals( + static_cast(l_result->application_protocol.arg), + static_cast(r_result->application_protocol.arg)); + result &= + slice_equals(static_cast(l_result->record_protocol.arg), + static_cast(r_result->record_protocol.arg)); + result &= slice_equals(static_cast(l_result->key_data.arg), + static_cast(r_result->key_data.arg)); + /* Compare local_identity, peer_identity, and keep_channel_open. */ + if ((l_result->has_local_identity ^ r_result->has_local_identity) | + (l_result->has_peer_identity ^ r_result->has_peer_identity) | + (l_result->has_peer_rpc_versions ^ r_result->has_peer_rpc_versions)) { + return false; + } + if (l_result->has_local_identity) { + result &= handshaker_identity_equals(&l_result->local_identity, + &r_result->local_identity); + } + if (l_result->has_peer_identity) { + result &= handshaker_identity_equals(&l_result->peer_identity, + &r_result->peer_identity); + } + if (l_result->has_peer_rpc_versions) { + result &= handshaker_rpc_versions_equals(&l_result->peer_rpc_versions, + &r_result->peer_rpc_versions); + } + result &= (l_result->keep_channel_open == r_result->keep_channel_open); + return result; +} + +/* Check equality of a pair of ALTS handshake responses. */ +bool grpc_gcp_handshaker_resp_equals(grpc_gcp_handshaker_resp* l_resp, + grpc_gcp_handshaker_resp* r_resp) { + bool result = true; + /* Compare out_frames and bytes_consumed. */ + result &= slice_equals(static_cast(l_resp->out_frames.arg), + static_cast(r_resp->out_frames.arg)); + result &= (l_resp->bytes_consumed == r_resp->bytes_consumed); + /* Compare result and status. */ + if ((l_resp->has_result ^ r_resp->has_result) | + (l_resp->has_status ^ r_resp->has_status)) { + return false; + } + if (l_resp->has_result) { + result &= grpc_gcp_handshaker_resp_result_equals(&l_resp->result, + &r_resp->result); + } + if (l_resp->has_status) { + result &= (l_resp->status.code == r_resp->status.code); + result &= + slice_equals(static_cast(l_resp->status.details.arg), + static_cast(r_resp->status.details.arg)); + } + return result; +} diff --git a/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h b/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h new file mode 100644 index 0000000000..2fcbb4ea99 --- /dev/null +++ b/test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h @@ -0,0 +1,143 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_TEST_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_SERVICE_API_TEST_LIB_H +#define GRPC_TEST_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_SERVICE_API_TEST_LIB_H + +#include "src/core/tsi/alts/handshaker/alts_handshaker_service_api.h" +#include "src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h" +#include "src/core/tsi/alts/handshaker/transport_security_common_api.h" + +/** + * The first part of this file contains function signatures for de-serializing + * ALTS handshake requests and setting/serializing ALTS handshake responses, + * which simulate the behaviour of grpc server that runs ALTS handshaker + * service. + */ + +/** + * This method creates a ALTS handshaker request that is used to hold + * de-serialized result. + */ +grpc_gcp_handshaker_req* grpc_gcp_handshaker_decoded_req_create( + grpc_gcp_handshaker_req_type type); + +/* This method de-serializes a ALTS handshaker request. */ +bool grpc_gcp_handshaker_req_decode(grpc_slice slice, + grpc_gcp_handshaker_req* req); + +/* This method serializes a ALTS handshaker response. */ +bool grpc_gcp_handshaker_resp_encode(grpc_gcp_handshaker_resp* resp, + grpc_slice* slice); + +/* This method sets application protocol of ALTS handshaker response. */ +bool grpc_gcp_handshaker_resp_set_application_protocol( + grpc_gcp_handshaker_resp* resp, const char* application_protocol); + +/* This method sets record protocol of ALTS handshaker response. */ +bool grpc_gcp_handshaker_resp_set_record_protocol( + grpc_gcp_handshaker_resp* resp, const char* record_protocol); + +/* This method sets key_data of ALTS handshaker response. */ +bool grpc_gcp_handshaker_resp_set_key_data(grpc_gcp_handshaker_resp* resp, + const char* key_data, size_t size); + +/* This method sets local identity's hostname for ALTS handshaker response. */ +bool grpc_gcp_handshaker_resp_set_local_identity_hostname( + grpc_gcp_handshaker_resp* resp, const char* hostname); + +/** + * This method sets local identity's service account for ALTS handshaker + * response. + */ +bool grpc_gcp_handshaker_resp_set_local_identity_service_account( + grpc_gcp_handshaker_resp* resp, const char* service_account); + +/* This method sets peer identity's hostname for ALTS handshaker response. */ +bool grpc_gcp_handshaker_resp_set_peer_identity_hostname( + grpc_gcp_handshaker_resp* resp, const char* hostname); + +/** + * This method sets peer identity's service account for ALTS handshaker + * response. + */ +bool grpc_gcp_handshaker_resp_set_peer_identity_service_account( + grpc_gcp_handshaker_resp* resp, const char* service_account); + +/* This method sets keep_channel_open for ALTS handshaker response. */ +bool grpc_gcp_handshaker_resp_set_channel_open(grpc_gcp_handshaker_resp* resp, + bool keep_channel_open); + +/* This method sets code for ALTS handshaker response. */ +bool grpc_gcp_handshaker_resp_set_code(grpc_gcp_handshaker_resp* resp, + uint32_t code); + +/* This method sets details for ALTS handshaker response. */ +bool grpc_gcp_handshaker_resp_set_details(grpc_gcp_handshaker_resp* resp, + const char* details); + +/* This method sets out_frames for ALTS handshaker response. */ +bool grpc_gcp_handshaker_resp_set_out_frames(grpc_gcp_handshaker_resp* resp, + const char* out_frames, + size_t size); + +/* This method sets peer_rpc_versions for ALTS handshaker response. */ +bool grpc_gcp_handshaker_resp_set_peer_rpc_versions( + grpc_gcp_handshaker_resp* resp, uint32_t max_major, uint32_t max_minor, + uint32_t min_major, uint32_t min_minor); + +/* This method sets bytes_consumed for ALTS handshaker response. */ +bool grpc_gcp_handshaker_resp_set_bytes_consumed(grpc_gcp_handshaker_resp* resp, + int32_t bytes_consumed); + +/* This method serializes ALTS handshaker response. */ +bool grpc_gcp_handshaker_resp_encode(grpc_gcp_handshaker_resp* resp, + grpc_slice* slice); + +/* This method de-serializes ALTS handshaker request. */ +bool grpc_gcp_handshaker_req_decode(grpc_slice slice, + grpc_gcp_handshaker_req* req); + +/** + * The second part contains function signatures for checking equality of a pair + * of ALTS handshake requests/responses. + */ + +/* This method checks equality of two client_start handshaker requests. */ +bool grpc_gcp_handshaker_client_start_req_equals( + grpc_gcp_start_client_handshake_req* l_req, + grpc_gcp_start_client_handshake_req* r_req); + +/* This method checks equality of two server_start handshaker requests. */ +bool grpc_gcp_handshaker_server_start_req_equals( + grpc_gcp_start_server_handshake_req* l_req, + grpc_gcp_start_server_handshake_req* r_req); + +/* This method checks equality of two ALTS handshaker requests. */ +bool grpc_gcp_handshaker_req_equals(grpc_gcp_handshaker_req* l_req, + grpc_gcp_handshaker_req* r_req); + +/* This method checks equality of two handshaker response results. */ +bool grpc_gcp_handshaker_resp_result_equals( + grpc_gcp_handshaker_result* l_result, grpc_gcp_handshaker_result* r_result); + +/* This method checks equality of two ALTS handshaker responses. */ +bool grpc_gcp_handshaker_resp_equals(grpc_gcp_handshaker_resp* l_resp, + grpc_gcp_handshaker_resp* r_resp); + +#endif // GRPC_TEST_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_SERVICE_API_TEST_LIB_H diff --git a/test/core/tsi/alts/handshaker/alts_tsi_handshaker_test.cc b/test/core/tsi/alts/handshaker/alts_tsi_handshaker_test.cc new file mode 100644 index 0000000000..95724f84f4 --- /dev/null +++ b/test/core/tsi/alts/handshaker/alts_tsi_handshaker_test.cc @@ -0,0 +1,682 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include + +#include +#include + +#include "src/core/lib/gprpp/thd.h" +#include "src/core/tsi/alts/handshaker/alts_handshaker_client.h" +#include "src/core/tsi/alts/handshaker/alts_tsi_event.h" +#include "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h" +#include "src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h" +#include "test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h" + +#define ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES "Hello World" +#define ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME "Hello Google" +#define ALTS_TSI_HANDSHAKER_TEST_CONSUMED_BYTES "Hello " +#define ALTS_TSI_HANDSHAKER_TEST_REMAIN_BYTES "Google" +#define ALTS_TSI_HANDSHAKER_TEST_PEER_IDENTITY "chapi@service.google.com" +#define ALTS_TSI_HANDSHAKER_TEST_KEY_DATA \ + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKL" +#define ALTS_TSI_HANDSHAKER_TEST_BUFFER_SIZE 100 +#define ALTS_TSI_HANDSHAKER_TEST_SLEEP_TIME_IN_SECONDS 2 +#define ALTS_TSI_HANDSHAKER_TEST_MAX_RPC_VERSION_MAJOR 3 +#define ALTS_TSI_HANDSHAKER_TEST_MAX_RPC_VERSION_MINOR 2 +#define ALTS_TSI_HANDSHAKER_TEST_MIN_RPC_VERSION_MAJOR 2 +#define ALTS_TSI_HANDSHAKER_TEST_MIN_RPC_VERSION_MINOR 1 + +using grpc_core::internal:: + alts_tsi_handshaker_get_has_sent_start_message_for_testing; +using grpc_core::internal::alts_tsi_handshaker_get_is_client_for_testing; +using grpc_core::internal::alts_tsi_handshaker_get_recv_bytes_for_testing; +using grpc_core::internal::alts_tsi_handshaker_set_client_for_testing; +using grpc_core::internal::alts_tsi_handshaker_set_recv_bytes_for_testing; + +/* ALTS mock notification. */ +typedef struct notification { + gpr_cv cv; + gpr_mu mu; + bool notified; +} notification; + +/* ALTS mock handshaker client. */ +typedef struct alts_mock_handshaker_client { + alts_handshaker_client base; + bool used_for_success_test; +} alts_mock_handshaker_client; + +/* Type of ALTS handshaker response. */ +typedef enum { + INVALID, + FAILED, + CLIENT_START, + SERVER_START, + CLIENT_NEXT, + SERVER_NEXT, +} alts_handshaker_response_type; + +static alts_tsi_event* client_start_event; +static alts_tsi_event* client_next_event; +static alts_tsi_event* server_start_event; +static alts_tsi_event* server_next_event; +static notification caller_to_tsi_notification; +static notification tsi_to_caller_notification; + +static void notification_init(notification* n) { + gpr_mu_init(&n->mu); + gpr_cv_init(&n->cv); + n->notified = false; +} + +static void notification_destroy(notification* n) { + gpr_mu_destroy(&n->mu); + gpr_cv_destroy(&n->cv); +} + +static void signal(notification* n) { + gpr_mu_lock(&n->mu); + n->notified = true; + gpr_cv_signal(&n->cv); + gpr_mu_unlock(&n->mu); +} + +static void wait(notification* n) { + gpr_mu_lock(&n->mu); + while (!n->notified) { + gpr_cv_wait(&n->cv, &n->mu, gpr_inf_future(GPR_CLOCK_REALTIME)); + } + n->notified = false; + gpr_mu_unlock(&n->mu); +} + +/** + * This method mocks ALTS handshaker service to generate handshaker response + * for a specific request. + */ +static grpc_byte_buffer* generate_handshaker_response( + alts_handshaker_response_type type) { + grpc_gcp_handshaker_resp* resp = grpc_gcp_handshaker_resp_create(); + GPR_ASSERT(grpc_gcp_handshaker_resp_set_code(resp, 0)); + switch (type) { + case INVALID: + break; + case CLIENT_START: + case SERVER_START: + GPR_ASSERT(grpc_gcp_handshaker_resp_set_out_frames( + resp, ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME, + strlen(ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME))); + break; + case CLIENT_NEXT: + GPR_ASSERT(grpc_gcp_handshaker_resp_set_out_frames( + resp, ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME, + strlen(ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME))); + GPR_ASSERT(grpc_gcp_handshaker_resp_set_peer_identity_service_account( + resp, ALTS_TSI_HANDSHAKER_TEST_PEER_IDENTITY)); + GPR_ASSERT(grpc_gcp_handshaker_resp_set_bytes_consumed( + resp, strlen(ALTS_TSI_HANDSHAKER_TEST_CONSUMED_BYTES))); + GPR_ASSERT(grpc_gcp_handshaker_resp_set_key_data( + resp, ALTS_TSI_HANDSHAKER_TEST_KEY_DATA, + strlen(ALTS_TSI_HANDSHAKER_TEST_KEY_DATA))); + GPR_ASSERT(grpc_gcp_handshaker_resp_set_peer_rpc_versions( + resp, ALTS_TSI_HANDSHAKER_TEST_MAX_RPC_VERSION_MAJOR, + ALTS_TSI_HANDSHAKER_TEST_MAX_RPC_VERSION_MINOR, + ALTS_TSI_HANDSHAKER_TEST_MIN_RPC_VERSION_MAJOR, + ALTS_TSI_HANDSHAKER_TEST_MIN_RPC_VERSION_MINOR)); + break; + case SERVER_NEXT: + GPR_ASSERT(grpc_gcp_handshaker_resp_set_peer_identity_service_account( + resp, ALTS_TSI_HANDSHAKER_TEST_PEER_IDENTITY)); + GPR_ASSERT(grpc_gcp_handshaker_resp_set_bytes_consumed( + resp, strlen(ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME))); + GPR_ASSERT(grpc_gcp_handshaker_resp_set_key_data( + resp, ALTS_TSI_HANDSHAKER_TEST_KEY_DATA, + strlen(ALTS_TSI_HANDSHAKER_TEST_KEY_DATA))); + GPR_ASSERT(grpc_gcp_handshaker_resp_set_peer_rpc_versions( + resp, ALTS_TSI_HANDSHAKER_TEST_MAX_RPC_VERSION_MAJOR, + ALTS_TSI_HANDSHAKER_TEST_MAX_RPC_VERSION_MINOR, + ALTS_TSI_HANDSHAKER_TEST_MIN_RPC_VERSION_MAJOR, + ALTS_TSI_HANDSHAKER_TEST_MIN_RPC_VERSION_MINOR)); + break; + case FAILED: + GPR_ASSERT( + grpc_gcp_handshaker_resp_set_code(resp, 3 /* INVALID ARGUMENT */)); + break; + } + grpc_slice slice; + GPR_ASSERT(grpc_gcp_handshaker_resp_encode(resp, &slice)); + if (type == INVALID) { + grpc_slice bad_slice = + grpc_slice_split_head(&slice, GRPC_SLICE_LENGTH(slice) - 1); + grpc_slice_unref(slice); + slice = grpc_slice_ref(bad_slice); + grpc_slice_unref(bad_slice); + } + grpc_byte_buffer* buffer = + grpc_raw_byte_buffer_create(&slice, 1 /* number of slices */); + grpc_slice_unref(slice); + grpc_gcp_handshaker_resp_destroy(resp); + return buffer; +} + +static void check_must_not_be_called(tsi_result status, void* user_data, + const unsigned char* bytes_to_send, + size_t bytes_to_send_size, + tsi_handshaker_result* result) { + GPR_ASSERT(0); +} + +static void on_client_start_success_cb(tsi_result status, void* user_data, + const unsigned char* bytes_to_send, + size_t bytes_to_send_size, + tsi_handshaker_result* result) { + GPR_ASSERT(status == TSI_OK); + GPR_ASSERT(user_data == nullptr); + GPR_ASSERT(bytes_to_send_size == strlen(ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME)); + GPR_ASSERT(memcmp(bytes_to_send, ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME, + bytes_to_send_size) == 0); + GPR_ASSERT(result == nullptr); + /* Validate peer identity. */ + tsi_peer peer; + GPR_ASSERT(tsi_handshaker_result_extract_peer(result, &peer) == + TSI_INVALID_ARGUMENT); + /* Validate frame protector. */ + tsi_frame_protector* protector = nullptr; + GPR_ASSERT(tsi_handshaker_result_create_frame_protector( + result, nullptr, &protector) == TSI_INVALID_ARGUMENT); + /* Validate unused bytes. */ + const unsigned char* unused_bytes = nullptr; + size_t unused_bytes_size = 0; + GPR_ASSERT(tsi_handshaker_result_get_unused_bytes(result, &unused_bytes, + &unused_bytes_size) == + TSI_INVALID_ARGUMENT); + signal(&tsi_to_caller_notification); +} + +static void on_server_start_success_cb(tsi_result status, void* user_data, + const unsigned char* bytes_to_send, + size_t bytes_to_send_size, + tsi_handshaker_result* result) { + GPR_ASSERT(status == TSI_OK); + GPR_ASSERT(user_data == nullptr); + GPR_ASSERT(bytes_to_send_size == strlen(ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME)); + GPR_ASSERT(memcmp(bytes_to_send, ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME, + bytes_to_send_size) == 0); + GPR_ASSERT(result == nullptr); + /* Validate peer identity. */ + tsi_peer peer; + GPR_ASSERT(tsi_handshaker_result_extract_peer(result, &peer) == + TSI_INVALID_ARGUMENT); + /* Validate frame protector. */ + tsi_frame_protector* protector = nullptr; + GPR_ASSERT(tsi_handshaker_result_create_frame_protector( + result, nullptr, &protector) == TSI_INVALID_ARGUMENT); + /* Validate unused bytes. */ + const unsigned char* unused_bytes = nullptr; + size_t unused_bytes_size = 0; + GPR_ASSERT(tsi_handshaker_result_get_unused_bytes(result, &unused_bytes, + &unused_bytes_size) == + TSI_INVALID_ARGUMENT); + signal(&tsi_to_caller_notification); +} + +static void on_client_next_success_cb(tsi_result status, void* user_data, + const unsigned char* bytes_to_send, + size_t bytes_to_send_size, + tsi_handshaker_result* result) { + GPR_ASSERT(status == TSI_OK); + GPR_ASSERT(user_data == nullptr); + GPR_ASSERT(bytes_to_send_size == strlen(ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME)); + GPR_ASSERT(memcmp(bytes_to_send, ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME, + bytes_to_send_size) == 0); + GPR_ASSERT(result != nullptr); + /* Validate peer identity. */ + tsi_peer peer; + GPR_ASSERT(tsi_handshaker_result_extract_peer(result, &peer) == TSI_OK); + GPR_ASSERT(peer.property_count == kTsiAltsNumOfPeerProperties); + GPR_ASSERT(memcmp(TSI_ALTS_CERTIFICATE_TYPE, peer.properties[0].value.data, + peer.properties[0].value.length) == 0); + GPR_ASSERT(memcmp(ALTS_TSI_HANDSHAKER_TEST_PEER_IDENTITY, + peer.properties[1].value.data, + peer.properties[1].value.length) == 0); + tsi_peer_destruct(&peer); + /* Validate unused bytes. */ + const unsigned char* bytes = nullptr; + size_t bytes_size = 0; + GPR_ASSERT(tsi_handshaker_result_get_unused_bytes(result, &bytes, + &bytes_size) == TSI_OK); + GPR_ASSERT(bytes_size == strlen(ALTS_TSI_HANDSHAKER_TEST_REMAIN_BYTES)); + GPR_ASSERT(memcmp(bytes, ALTS_TSI_HANDSHAKER_TEST_REMAIN_BYTES, bytes_size) == + 0); + /* Validate frame protector. */ + tsi_frame_protector* protector = nullptr; + GPR_ASSERT(tsi_handshaker_result_create_frame_protector( + result, nullptr, &protector) == TSI_OK); + GPR_ASSERT(protector != nullptr); + tsi_frame_protector_destroy(protector); + tsi_handshaker_result_destroy(result); + signal(&tsi_to_caller_notification); +} + +static void on_server_next_success_cb(tsi_result status, void* user_data, + const unsigned char* bytes_to_send, + size_t bytes_to_send_size, + tsi_handshaker_result* result) { + GPR_ASSERT(status == TSI_OK); + GPR_ASSERT(user_data == nullptr); + GPR_ASSERT(bytes_to_send_size == 0); + GPR_ASSERT(bytes_to_send == nullptr); + GPR_ASSERT(result != nullptr); + /* Validate peer identity. */ + tsi_peer peer; + GPR_ASSERT(tsi_handshaker_result_extract_peer(result, &peer) == TSI_OK); + GPR_ASSERT(peer.property_count == kTsiAltsNumOfPeerProperties); + GPR_ASSERT(memcmp(TSI_ALTS_CERTIFICATE_TYPE, peer.properties[0].value.data, + peer.properties[0].value.length) == 0); + GPR_ASSERT(memcmp(ALTS_TSI_HANDSHAKER_TEST_PEER_IDENTITY, + peer.properties[1].value.data, + peer.properties[1].value.length) == 0); + tsi_peer_destruct(&peer); + /* Validate unused bytes. */ + const unsigned char* bytes = nullptr; + size_t bytes_size = 0; + GPR_ASSERT(tsi_handshaker_result_get_unused_bytes(result, &bytes, + &bytes_size) == TSI_OK); + GPR_ASSERT(bytes_size == 0); + GPR_ASSERT(bytes == nullptr); + /* Validate frame protector. */ + tsi_frame_protector* protector = nullptr; + GPR_ASSERT(tsi_handshaker_result_create_frame_protector( + result, nullptr, &protector) == TSI_OK); + GPR_ASSERT(protector != nullptr); + tsi_frame_protector_destroy(protector); + tsi_handshaker_result_destroy(result); + signal(&tsi_to_caller_notification); +} + +static tsi_result mock_client_start(alts_handshaker_client* self, + alts_tsi_event* event) { + alts_mock_handshaker_client* client = + reinterpret_cast(self); + if (!client->used_for_success_test) { + alts_tsi_event_destroy(event); + return TSI_INTERNAL_ERROR; + } + GPR_ASSERT(event->cb == on_client_start_success_cb); + GPR_ASSERT(event->user_data == nullptr); + GPR_ASSERT(!alts_tsi_handshaker_get_has_sent_start_message_for_testing( + event->handshaker)); + /* Populate handshaker response for client_start request. */ + event->recv_buffer = generate_handshaker_response(CLIENT_START); + client_start_event = event; + signal(&caller_to_tsi_notification); + return TSI_OK; +} + +static tsi_result mock_server_start(alts_handshaker_client* self, + alts_tsi_event* event, + grpc_slice* bytes_received) { + alts_mock_handshaker_client* client = + reinterpret_cast(self); + if (!client->used_for_success_test) { + alts_tsi_event_destroy(event); + return TSI_INTERNAL_ERROR; + } + GPR_ASSERT(event->cb == on_server_start_success_cb); + GPR_ASSERT(event->user_data == nullptr); + grpc_slice slice = grpc_empty_slice(); + GPR_ASSERT(grpc_slice_cmp(*bytes_received, slice) == 0); + GPR_ASSERT(!alts_tsi_handshaker_get_has_sent_start_message_for_testing( + event->handshaker)); + /* Populate handshaker response for server_start request. */ + event->recv_buffer = generate_handshaker_response(SERVER_START); + server_start_event = event; + grpc_slice_unref(slice); + signal(&caller_to_tsi_notification); + return TSI_OK; +} + +static tsi_result mock_next(alts_handshaker_client* self, alts_tsi_event* event, + grpc_slice* bytes_received) { + alts_mock_handshaker_client* client = + reinterpret_cast(self); + if (!client->used_for_success_test) { + alts_tsi_event_destroy(event); + return TSI_INTERNAL_ERROR; + } + bool is_client = + alts_tsi_handshaker_get_is_client_for_testing(event->handshaker); + if (is_client) { + GPR_ASSERT(event->cb == on_client_next_success_cb); + } else { + GPR_ASSERT(event->cb == on_server_next_success_cb); + } + GPR_ASSERT(event->user_data == nullptr); + GPR_ASSERT(bytes_received != nullptr); + GPR_ASSERT(memcmp(GRPC_SLICE_START_PTR(*bytes_received), + ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES, + GRPC_SLICE_LENGTH(*bytes_received)) == 0); + GPR_ASSERT(grpc_slice_cmp(alts_tsi_handshaker_get_recv_bytes_for_testing( + event->handshaker), + *bytes_received) == 0); + GPR_ASSERT(alts_tsi_handshaker_get_has_sent_start_message_for_testing( + event->handshaker)); + /* Populate handshaker response for next request. */ + grpc_slice out_frame = + grpc_slice_from_static_string(ALTS_TSI_HANDSHAKER_TEST_OUT_FRAME); + if (is_client) { + event->recv_buffer = generate_handshaker_response(CLIENT_NEXT); + } else { + event->recv_buffer = generate_handshaker_response(SERVER_NEXT); + } + alts_tsi_handshaker_set_recv_bytes_for_testing(event->handshaker, &out_frame); + if (is_client) { + client_next_event = event; + } else { + server_next_event = event; + } + signal(&caller_to_tsi_notification); + grpc_slice_unref(out_frame); + return TSI_OK; +} + +static void mock_destruct(alts_handshaker_client* client) {} + +static const alts_handshaker_client_vtable vtable = { + mock_client_start, mock_server_start, mock_next, mock_destruct}; + +static alts_handshaker_client* alts_mock_handshaker_client_create( + bool used_for_success_test) { + alts_mock_handshaker_client* client = + static_cast(gpr_zalloc(sizeof(*client))); + client->base.vtable = &vtable; + client->used_for_success_test = used_for_success_test; + return &client->base; +} + +static tsi_handshaker* create_test_handshaker(bool used_for_success_test, + bool is_client) { + tsi_handshaker* handshaker = nullptr; + alts_handshaker_client* client = + alts_mock_handshaker_client_create(used_for_success_test); + grpc_alts_credentials_options* options = + grpc_alts_credentials_client_options_create(); + alts_tsi_handshaker_create(options, "target_name", "lame", is_client, + &handshaker); + alts_tsi_handshaker* alts_handshaker = + reinterpret_cast(handshaker); + alts_tsi_handshaker_set_client_for_testing(alts_handshaker, client); + grpc_alts_credentials_options_destroy(options); + return handshaker; +} + +static void check_handshaker_next_invalid_input() { + /* Initialization. */ + tsi_handshaker* handshaker = create_test_handshaker(true, true); + /* Check nullptr handshaker. */ + GPR_ASSERT(tsi_handshaker_next(nullptr, nullptr, 0, nullptr, nullptr, nullptr, + check_must_not_be_called, + nullptr) == TSI_INVALID_ARGUMENT); + /* Check nullptr callback. */ + GPR_ASSERT(tsi_handshaker_next(handshaker, nullptr, 0, nullptr, nullptr, + nullptr, nullptr, + nullptr) == TSI_INVALID_ARGUMENT); + /* Cleanup. */ + tsi_handshaker_destroy(handshaker); +} + +static void check_handshaker_next_success() { + /** + * Create handshakers for which internal mock client is going to do + * correctness check. + */ + tsi_handshaker* client_handshaker = create_test_handshaker( + true /* used_for_success_test */, true /* is_client */); + tsi_handshaker* server_handshaker = create_test_handshaker( + true /* used_for_success_test */, false /* is_client */); + /* Client start. */ + GPR_ASSERT(tsi_handshaker_next(client_handshaker, nullptr, 0, nullptr, + nullptr, nullptr, on_client_start_success_cb, + nullptr) == TSI_ASYNC); + wait(&tsi_to_caller_notification); + /* Client next. */ + GPR_ASSERT(tsi_handshaker_next( + client_handshaker, + (const unsigned char*)ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES, + strlen(ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES), nullptr, nullptr, + nullptr, on_client_next_success_cb, nullptr) == TSI_ASYNC); + wait(&tsi_to_caller_notification); + /* Server start. */ + GPR_ASSERT(tsi_handshaker_next(server_handshaker, nullptr, 0, nullptr, + nullptr, nullptr, on_server_start_success_cb, + nullptr) == TSI_ASYNC); + wait(&tsi_to_caller_notification); + /* Server next. */ + GPR_ASSERT(tsi_handshaker_next( + server_handshaker, + (const unsigned char*)ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES, + strlen(ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES), nullptr, nullptr, + nullptr, on_server_next_success_cb, nullptr) == TSI_ASYNC); + wait(&tsi_to_caller_notification); + /* Cleanup. */ + tsi_handshaker_destroy(server_handshaker); + tsi_handshaker_destroy(client_handshaker); +} + +static void check_handshaker_next_failure() { + /** + * Create handshakers for which internal mock client is always going to fail. + */ + tsi_handshaker* client_handshaker = create_test_handshaker( + false /* used_for_success_test */, true /* is_client */); + tsi_handshaker* server_handshaker = create_test_handshaker( + false /* used_for_success_test */, false /* is_client */); + /* Client start. */ + GPR_ASSERT(tsi_handshaker_next(client_handshaker, nullptr, 0, nullptr, + nullptr, nullptr, check_must_not_be_called, + nullptr) == TSI_INTERNAL_ERROR); + /* Server start. */ + GPR_ASSERT(tsi_handshaker_next(server_handshaker, nullptr, 0, nullptr, + nullptr, nullptr, check_must_not_be_called, + nullptr) == TSI_INTERNAL_ERROR); + /* Server next. */ + GPR_ASSERT(tsi_handshaker_next( + server_handshaker, + (const unsigned char*)ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES, + strlen(ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES), nullptr, nullptr, + nullptr, check_must_not_be_called, + nullptr) == TSI_INTERNAL_ERROR); + /* Client next. */ + GPR_ASSERT(tsi_handshaker_next( + client_handshaker, + (const unsigned char*)ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES, + strlen(ALTS_TSI_HANDSHAKER_TEST_RECV_BYTES), nullptr, nullptr, + nullptr, check_must_not_be_called, + nullptr) == TSI_INTERNAL_ERROR); + /* Cleanup. */ + tsi_handshaker_destroy(server_handshaker); + tsi_handshaker_destroy(client_handshaker); +} + +static void on_invalid_input_cb(tsi_result status, void* user_data, + const unsigned char* bytes_to_send, + size_t bytes_to_send_size, + tsi_handshaker_result* result) { + GPR_ASSERT(status == TSI_INTERNAL_ERROR); + GPR_ASSERT(user_data == nullptr); + GPR_ASSERT(bytes_to_send == nullptr); + GPR_ASSERT(bytes_to_send_size == 0); + GPR_ASSERT(result == nullptr); +} + +static void on_failed_grpc_call_cb(tsi_result status, void* user_data, + const unsigned char* bytes_to_send, + size_t bytes_to_send_size, + tsi_handshaker_result* result) { + GPR_ASSERT(status == TSI_INTERNAL_ERROR); + GPR_ASSERT(user_data == nullptr); + GPR_ASSERT(bytes_to_send == nullptr); + GPR_ASSERT(bytes_to_send_size == 0); + GPR_ASSERT(result == nullptr); +} + +static void check_handle_response_invalid_input() { + /** + * Create a handshaker at the client side, for which internal mock client is + * always going to fail. + */ + tsi_handshaker* handshaker = create_test_handshaker( + false /* used_for_success_test */, true /* is_client */); + alts_tsi_handshaker* alts_handshaker = + reinterpret_cast(handshaker); + grpc_byte_buffer recv_buffer; + /* Check nullptr handshaker. */ + alts_tsi_handshaker_handle_response(nullptr, &recv_buffer, GRPC_STATUS_OK, + nullptr, on_invalid_input_cb, nullptr, + true); + /* Check nullptr recv_bytes. */ + alts_tsi_handshaker_handle_response(alts_handshaker, nullptr, GRPC_STATUS_OK, + nullptr, on_invalid_input_cb, nullptr, + true); + /* Check failed grpc call made to handshaker service. */ + alts_tsi_handshaker_handle_response(alts_handshaker, &recv_buffer, + GRPC_STATUS_UNKNOWN, nullptr, + on_failed_grpc_call_cb, nullptr, true); + + alts_tsi_handshaker_handle_response(alts_handshaker, &recv_buffer, + GRPC_STATUS_OK, nullptr, + on_failed_grpc_call_cb, nullptr, false); + + /* Cleanup. */ + tsi_handshaker_destroy(handshaker); +} + +static void on_invalid_resp_cb(tsi_result status, void* user_data, + const unsigned char* bytes_to_send, + size_t bytes_to_send_size, + tsi_handshaker_result* result) { + GPR_ASSERT(status == TSI_DATA_CORRUPTED); + GPR_ASSERT(user_data == nullptr); + GPR_ASSERT(bytes_to_send == nullptr); + GPR_ASSERT(bytes_to_send_size == 0); + GPR_ASSERT(result == nullptr); +} + +static void check_handle_response_invalid_resp() { + /** + * Create a handshaker at the client side, for which internal mock client is + * always going to fail. + */ + tsi_handshaker* handshaker = create_test_handshaker( + false /* used_for_success_test */, true /* is_client */); + alts_tsi_handshaker* alts_handshaker = + reinterpret_cast(handshaker); + /* Tests. */ + grpc_byte_buffer* recv_buffer = generate_handshaker_response(INVALID); + alts_tsi_handshaker_handle_response(alts_handshaker, recv_buffer, + GRPC_STATUS_OK, nullptr, + on_invalid_resp_cb, nullptr, true); + /* Cleanup. */ + grpc_byte_buffer_destroy(recv_buffer); + tsi_handshaker_destroy(handshaker); +} + +static void check_handle_response_success(void* unused) { + /* Client start. */ + wait(&caller_to_tsi_notification); + alts_tsi_event_dispatch_to_handshaker(client_start_event, true /* is_ok */); + alts_tsi_event_destroy(client_start_event); + /* Client next. */ + wait(&caller_to_tsi_notification); + alts_tsi_event_dispatch_to_handshaker(client_next_event, true /* is_ok */); + alts_tsi_event_destroy(client_next_event); + /* Server start. */ + wait(&caller_to_tsi_notification); + alts_tsi_event_dispatch_to_handshaker(server_start_event, true /* is_ok */); + alts_tsi_event_destroy(server_start_event); + /* Server next. */ + wait(&caller_to_tsi_notification); + alts_tsi_event_dispatch_to_handshaker(server_next_event, true /* is_ok */); + alts_tsi_event_destroy(server_next_event); +} + +static void on_failed_resp_cb(tsi_result status, void* user_data, + const unsigned char* bytes_to_send, + size_t bytes_to_send_size, + tsi_handshaker_result* result) { + GPR_ASSERT(status == TSI_INVALID_ARGUMENT); + GPR_ASSERT(user_data == nullptr); + GPR_ASSERT(bytes_to_send == nullptr); + GPR_ASSERT(bytes_to_send_size == 0); + GPR_ASSERT(result == nullptr); +} + +static void check_handle_response_failure() { + /** + * Create a handshaker at the client side, for which internal mock client is + * always going to fail. + */ + tsi_handshaker* handshaker = create_test_handshaker( + false /* used_for_success_test */, true /* is_client */); + alts_tsi_handshaker* alts_handshaker = + reinterpret_cast(handshaker); + /* Tests. */ + grpc_byte_buffer* recv_buffer = generate_handshaker_response(FAILED); + alts_tsi_handshaker_handle_response(alts_handshaker, recv_buffer, + GRPC_STATUS_OK, nullptr, + on_failed_resp_cb, nullptr, true); + grpc_byte_buffer_destroy(recv_buffer); + /* Cleanup. */ + tsi_handshaker_destroy(handshaker); +} + +void check_handshaker_success() { + /* Initialization. */ + notification_init(&caller_to_tsi_notification); + notification_init(&tsi_to_caller_notification); + client_start_event = nullptr; + client_next_event = nullptr; + server_start_event = nullptr; + server_next_event = nullptr; + /* Tests. */ + grpc_core::Thread thd("alts_tsi_handshaker_test", + &check_handle_response_success, nullptr); + thd.Start(); + check_handshaker_next_success(); + thd.Join(); + /* Cleanup. */ + notification_destroy(&caller_to_tsi_notification); + notification_destroy(&tsi_to_caller_notification); +} + +int main(int argc, char** argv) { + /* Initialization. */ + grpc_init(); + /* Tests. */ + check_handshaker_success(); + check_handshaker_next_invalid_input(); + check_handshaker_next_failure(); + check_handle_response_invalid_input(); + check_handle_response_invalid_resp(); + check_handle_response_failure(); + /* Cleanup. */ + grpc_shutdown(); + return 0; +} diff --git a/test/core/tsi/alts/handshaker/alts_tsi_utils_test.cc b/test/core/tsi/alts/handshaker/alts_tsi_utils_test.cc new file mode 100644 index 0000000000..98c5d23641 --- /dev/null +++ b/test/core/tsi/alts/handshaker/alts_tsi_utils_test.cc @@ -0,0 +1,73 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "src/core/tsi/alts/handshaker/alts_tsi_utils.h" +#include "test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h" + +#define ALTS_TSI_UTILS_TEST_OUT_FRAME "Hello Google" + +static void convert_to_tsi_result_test() { + GPR_ASSERT(alts_tsi_utils_convert_to_tsi_result(GRPC_STATUS_OK) == TSI_OK); + GPR_ASSERT(alts_tsi_utils_convert_to_tsi_result(GRPC_STATUS_UNKNOWN) == + TSI_UNKNOWN_ERROR); + GPR_ASSERT(alts_tsi_utils_convert_to_tsi_result( + GRPC_STATUS_INVALID_ARGUMENT) == TSI_INVALID_ARGUMENT); + GPR_ASSERT(alts_tsi_utils_convert_to_tsi_result(GRPC_STATUS_OUT_OF_RANGE) == + TSI_UNKNOWN_ERROR); + GPR_ASSERT(alts_tsi_utils_convert_to_tsi_result(GRPC_STATUS_INTERNAL) == + TSI_INTERNAL_ERROR); + GPR_ASSERT(alts_tsi_utils_convert_to_tsi_result(GRPC_STATUS_NOT_FOUND) == + TSI_NOT_FOUND); +} + +static void deserialize_response_test() { + grpc_gcp_handshaker_resp* resp = grpc_gcp_handshaker_resp_create(); + GPR_ASSERT(grpc_gcp_handshaker_resp_set_out_frames( + resp, ALTS_TSI_UTILS_TEST_OUT_FRAME, + strlen(ALTS_TSI_UTILS_TEST_OUT_FRAME))); + grpc_slice slice; + GPR_ASSERT(grpc_gcp_handshaker_resp_encode(resp, &slice)); + + /* Valid serialization. */ + grpc_byte_buffer* buffer = + grpc_raw_byte_buffer_create(&slice, 1 /* number of slices */); + grpc_gcp_handshaker_resp* decoded_resp = + alts_tsi_utils_deserialize_response(buffer); + GPR_ASSERT(grpc_gcp_handshaker_resp_equals(resp, decoded_resp)); + grpc_byte_buffer_destroy(buffer); + + /* Invalid serializaiton. */ + grpc_slice bad_slice = + grpc_slice_split_head(&slice, GRPC_SLICE_LENGTH(slice) - 1); + buffer = grpc_raw_byte_buffer_create(&bad_slice, 1 /* number of slices */); + GPR_ASSERT(alts_tsi_utils_deserialize_response(buffer) == nullptr); + + /* Clean up. */ + grpc_slice_unref(slice); + grpc_slice_unref(bad_slice); + grpc_byte_buffer_destroy(buffer); + grpc_gcp_handshaker_resp_destroy(resp); + grpc_gcp_handshaker_resp_destroy(decoded_resp); +} + +int main(int argc, char** argv) { + /* Tests. */ + deserialize_response_test(); + convert_to_tsi_result_test(); + return 0; +} diff --git a/test/core/tsi/alts/handshaker/transport_security_common_api_test.cc b/test/core/tsi/alts/handshaker/transport_security_common_api_test.cc new file mode 100644 index 0000000000..6ff1357c27 --- /dev/null +++ b/test/core/tsi/alts/handshaker/transport_security_common_api_test.cc @@ -0,0 +1,196 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include + +#include "src/core/tsi/alts/handshaker/transport_security_common_api.h" + +const size_t kMaxRpcVersionMajor = 3; +const size_t kMaxRpcVersionMinor = 2; +const size_t kMinRpcVersionMajor = 2; +const size_t kMinRpcVersionMinor = 1; + +static bool grpc_gcp_rpc_protocol_versions_equal( + grpc_gcp_rpc_protocol_versions* l_versions, + grpc_gcp_rpc_protocol_versions* r_versions) { + GPR_ASSERT(l_versions != nullptr && r_versions != nullptr); + if ((l_versions->has_max_rpc_version ^ r_versions->has_max_rpc_version) | + (l_versions->has_min_rpc_version ^ r_versions->has_min_rpc_version)) { + return false; + } + if (l_versions->has_max_rpc_version) { + if ((l_versions->max_rpc_version.major != + r_versions->max_rpc_version.major) || + (l_versions->max_rpc_version.minor != + r_versions->max_rpc_version.minor)) { + return false; + } + } + if (l_versions->has_min_rpc_version) { + if ((l_versions->min_rpc_version.major != + r_versions->min_rpc_version.major) || + (l_versions->min_rpc_version.minor != + r_versions->min_rpc_version.minor)) { + return false; + } + } + return true; +} + +static void test_success() { + grpc_gcp_rpc_protocol_versions version; + grpc_gcp_rpc_protocol_versions decoded_version; + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_max( + &version, kMaxRpcVersionMajor, kMaxRpcVersionMinor)); + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_min( + &version, kMinRpcVersionMajor, kMinRpcVersionMinor)); + /* Serializes to raw bytes. */ + size_t encoded_length = + grpc_gcp_rpc_protocol_versions_encode_length(&version); + uint8_t* encoded_bytes = static_cast(gpr_malloc(encoded_length)); + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_encode_to_raw_bytes( + &version, encoded_bytes, encoded_length)); + grpc_slice encoded_slice; + /* Serializes to grpc slice. */ + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_encode(&version, &encoded_slice)); + /* Checks serialized raw bytes and serialized grpc slice have same content. */ + GPR_ASSERT(encoded_length == GRPC_SLICE_LENGTH(encoded_slice)); + GPR_ASSERT(memcmp(encoded_bytes, GRPC_SLICE_START_PTR(encoded_slice), + encoded_length) == 0); + /* Deserializes and compares with the original version. */ + GPR_ASSERT( + grpc_gcp_rpc_protocol_versions_decode(encoded_slice, &decoded_version)); + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_equal(&version, &decoded_version)); + grpc_slice_unref(encoded_slice); + gpr_free(encoded_bytes); +} + +static void test_failure() { + grpc_gcp_rpc_protocol_versions version, decoded_version; + grpc_slice encoded_slice; + /* Test for invalid arguments. */ + GPR_ASSERT(!grpc_gcp_rpc_protocol_versions_set_max( + nullptr, kMaxRpcVersionMajor, kMaxRpcVersionMinor)); + GPR_ASSERT(!grpc_gcp_rpc_protocol_versions_set_min( + nullptr, kMinRpcVersionMajor, kMinRpcVersionMinor)); + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_encode_length(nullptr) == 0); + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_max( + &version, kMaxRpcVersionMajor, kMaxRpcVersionMinor)); + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_min( + &version, kMinRpcVersionMajor, kMinRpcVersionMinor)); + size_t encoded_length = + grpc_gcp_rpc_protocol_versions_encode_length(&version); + uint8_t* encoded_bytes = static_cast(gpr_malloc(encoded_length)); + GPR_ASSERT(!grpc_gcp_rpc_protocol_versions_encode_to_raw_bytes( + nullptr, encoded_bytes, encoded_length)); + GPR_ASSERT(!grpc_gcp_rpc_protocol_versions_encode_to_raw_bytes( + &version, nullptr, encoded_length)); + GPR_ASSERT(!grpc_gcp_rpc_protocol_versions_encode_to_raw_bytes( + &version, encoded_bytes, 0)); + GPR_ASSERT(!grpc_gcp_rpc_protocol_versions_encode(nullptr, &encoded_slice)); + GPR_ASSERT(!grpc_gcp_rpc_protocol_versions_encode(&version, nullptr)); + GPR_ASSERT(!grpc_gcp_rpc_protocol_versions_decode(encoded_slice, nullptr)); + /* Test for nanopb decode. */ + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_encode(&version, &encoded_slice)); + grpc_slice bad_slice = grpc_slice_split_head( + &encoded_slice, GRPC_SLICE_LENGTH(encoded_slice) - 1); + grpc_slice_unref(encoded_slice); + GPR_ASSERT( + !grpc_gcp_rpc_protocol_versions_decode(bad_slice, &decoded_version)); + grpc_slice_unref(bad_slice); + gpr_free(encoded_bytes); +} + +static void test_copy() { + grpc_gcp_rpc_protocol_versions src; + grpc_gcp_rpc_protocol_versions des; + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_max(&src, kMaxRpcVersionMajor, + kMaxRpcVersionMinor)); + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_min(&src, kMinRpcVersionMajor, + kMinRpcVersionMinor)); + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_copy(&src, &des)); + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_equal(&src, &des)); +} + +static void test_check_success() { + grpc_gcp_rpc_protocol_versions v1; + grpc_gcp_rpc_protocol_versions v2; + grpc_gcp_rpc_protocol_versions_version highest_common_version; + /* test equality. */ + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_max(&v1, kMaxRpcVersionMajor, + kMaxRpcVersionMinor)); + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_min(&v1, kMaxRpcVersionMajor, + kMaxRpcVersionMinor)); + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_max(&v2, kMaxRpcVersionMajor, + kMaxRpcVersionMinor)); + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_min(&v2, kMaxRpcVersionMajor, + kMaxRpcVersionMinor)); + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_check( + (const grpc_gcp_rpc_protocol_versions*)&v1, + (const grpc_gcp_rpc_protocol_versions*)&v2, + &highest_common_version) == 1); + GPR_ASSERT(grpc_core::internal::grpc_gcp_rpc_protocol_version_compare( + &highest_common_version, &v1.max_rpc_version) == 0); + + /* test inequality. */ + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_max(&v1, kMaxRpcVersionMajor, + kMaxRpcVersionMinor)); + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_min(&v1, kMinRpcVersionMinor, + kMinRpcVersionMinor)); + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_max(&v2, kMaxRpcVersionMajor, + kMinRpcVersionMinor)); + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_min(&v2, kMinRpcVersionMajor, + kMaxRpcVersionMinor)); + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_check( + (const grpc_gcp_rpc_protocol_versions*)&v1, + (const grpc_gcp_rpc_protocol_versions*)&v2, + &highest_common_version) == 1); + GPR_ASSERT(grpc_core::internal::grpc_gcp_rpc_protocol_version_compare( + &highest_common_version, &v2.max_rpc_version) == 0); +} + +static void test_check_failure() { + grpc_gcp_rpc_protocol_versions v1; + grpc_gcp_rpc_protocol_versions v2; + grpc_gcp_rpc_protocol_versions_version highest_common_version; + + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_max(&v1, kMinRpcVersionMajor, + kMinRpcVersionMinor)); + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_min(&v1, kMinRpcVersionMajor, + kMinRpcVersionMinor)); + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_max(&v2, kMaxRpcVersionMajor, + kMaxRpcVersionMinor)); + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_min(&v2, kMaxRpcVersionMajor, + kMaxRpcVersionMinor)); + GPR_ASSERT(grpc_gcp_rpc_protocol_versions_check( + (const grpc_gcp_rpc_protocol_versions*)&v1, + (const grpc_gcp_rpc_protocol_versions*)&v2, + &highest_common_version) == 0); +} + +int main(int argc, char** argv) { + /* Run tests. */ + test_success(); + test_failure(); + test_copy(); + test_check_success(); + test_check_failure(); + return 0; +} diff --git a/test/core/tsi/alts/zero_copy_frame_protector/BUILD b/test/core/tsi/alts/zero_copy_frame_protector/BUILD new file mode 100644 index 0000000000..4c6fb91a76 --- /dev/null +++ b/test/core/tsi/alts/zero_copy_frame_protector/BUILD @@ -0,0 +1,57 @@ +# Copyright 2018 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_package") + +licenses(["notice"]) # Apache v2 + +grpc_package(name = "zero_copy_frame_protector") + +grpc_cc_test( + name = "alts_grpc_record_protocol_test", + srcs = ["alts_grpc_record_protocol_test.cc"], + language = "C++", + deps = [ + "//:alts_frame_protector", + "//:gpr", + "//:grpc", + "//:grpc_base_c", + "//test/core/tsi/alts/crypt:alts_crypt_test_util", + ], +) + +grpc_cc_test( + name = "alts_iovec_record_protocol_test", + srcs = ["alts_iovec_record_protocol_test.cc"], + language = "C++", + deps = [ + "//:alts_frame_protector", + "//:gpr", + "//:grpc", + "//test/core/tsi/alts/crypt:alts_crypt_test_util", + ], +) + +grpc_cc_test( + name = "alts_zero_copy_grpc_protector_test", + srcs = ["alts_zero_copy_grpc_protector_test.cc"], + language = "C++", + deps = [ + "//:alts_frame_protector", + "//:gpr", + "//:grpc", + "//:grpc_base_c", + "//test/core/tsi/alts/crypt:alts_crypt_test_util", + ], +) diff --git a/test/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_test.cc b/test/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_test.cc new file mode 100644 index 0000000000..fbbea71cb7 --- /dev/null +++ b/test/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_test.cc @@ -0,0 +1,449 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include + +#include "src/core/lib/slice/slice_internal.h" +#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h" +#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h" +#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h" +#include "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h" +#include "test/core/tsi/alts/crypt/gsec_test_util.h" + +constexpr size_t kMaxSliceLength = 256; +constexpr size_t kMaxSlices = 10; +constexpr size_t kSealRepeatTimes = 5; +constexpr size_t kTagLength = 16; + +/* Test fixtures for each test cases. */ +struct alts_grpc_record_protocol_test_fixture { + alts_grpc_record_protocol* client_protect; + alts_grpc_record_protocol* client_unprotect; + alts_grpc_record_protocol* server_protect; + alts_grpc_record_protocol* server_unprotect; +}; + +/* Test input variables for protect/unprotect operations. */ +struct alts_grpc_record_protocol_test_var { + size_t header_length; + size_t tag_length; + grpc_slice_buffer original_sb; + grpc_slice_buffer duplicate_sb; + grpc_slice_buffer protected_sb; + grpc_slice_buffer unprotected_sb; +}; + +/* --- Test utility functions. --- */ + +static void create_random_slice_buffer(grpc_slice_buffer* sb) { + GPR_ASSERT(sb != nullptr); + size_t slice_count = gsec_test_bias_random_uint32(kMaxSlices) + 1; + for (size_t i = 0; i < slice_count; i++) { + size_t slice_length = gsec_test_bias_random_uint32(kMaxSliceLength) + 1; + grpc_slice slice = GRPC_SLICE_MALLOC(slice_length); + gsec_test_random_bytes(GRPC_SLICE_START_PTR(slice), slice_length); + grpc_slice_buffer_add(sb, slice); + } +} + +static uint8_t* pointer_to_nth_byte(grpc_slice_buffer* sb, size_t index) { + GPR_ASSERT(sb != nullptr); + GPR_ASSERT(index < sb->length); + for (size_t i = 0; i < sb->count; i++) { + if (index < GRPC_SLICE_LENGTH(sb->slices[i])) { + return GRPC_SLICE_START_PTR(sb->slices[i]) + index; + } else { + index -= GRPC_SLICE_LENGTH(sb->slices[i]); + } + } + return nullptr; +} + +/* Checks if two slice buffer contents are the same. It is not super efficient, + * but OK for testing. */ +static bool are_slice_buffers_equal(grpc_slice_buffer* first, + grpc_slice_buffer* second) { + GPR_ASSERT(first != nullptr); + GPR_ASSERT(second != nullptr); + if (first->length != second->length) { + return false; + } + for (size_t i = 0; i < first->length; i++) { + uint8_t* first_ptr = pointer_to_nth_byte(first, i); + uint8_t* second_ptr = pointer_to_nth_byte(second, i); + GPR_ASSERT(first_ptr != nullptr); + GPR_ASSERT(second_ptr != nullptr); + if ((*first_ptr) != (*second_ptr)) { + return false; + } + } + return true; +} + +static void alter_random_byte(grpc_slice_buffer* sb) { + GPR_ASSERT(sb != nullptr); + if (sb->length == 0) { + return; + } + uint32_t offset = + gsec_test_bias_random_uint32(static_cast(sb->length)); + uint8_t* ptr = pointer_to_nth_byte(sb, offset); + (*ptr)++; +} + +static alts_grpc_record_protocol_test_fixture* +test_fixture_integrity_only_create(bool rekey) { + alts_grpc_record_protocol_test_fixture* fixture = + static_cast( + gpr_zalloc(sizeof(alts_grpc_record_protocol_test_fixture))); + size_t key_length = rekey ? kAes128GcmRekeyKeyLength : kAes128GcmKeyLength; + uint8_t* key; + gsec_test_random_array(&key, key_length); + gsec_aead_crypter* crypter = nullptr; + + /* Create client record protocol for protect. */ + GPR_ASSERT(gsec_aes_gcm_aead_crypter_create( + key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey, + &crypter, nullptr) == GRPC_STATUS_OK); + GPR_ASSERT(alts_grpc_integrity_only_record_protocol_create( + crypter, 8, /*is_client=*/true, /*is_protect=*/true, + &fixture->client_protect) == TSI_OK); + /* Create client record protocol for unprotect. */ + GPR_ASSERT(gsec_aes_gcm_aead_crypter_create( + key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey, + &crypter, nullptr) == GRPC_STATUS_OK); + GPR_ASSERT(alts_grpc_integrity_only_record_protocol_create( + crypter, 8, /*is_client=*/true, /*is_protect=*/false, + &fixture->client_unprotect) == TSI_OK); + /* Create server record protocol for protect. */ + GPR_ASSERT(gsec_aes_gcm_aead_crypter_create( + key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey, + &crypter, nullptr) == GRPC_STATUS_OK); + GPR_ASSERT(alts_grpc_integrity_only_record_protocol_create( + crypter, 8, /*is_client=*/false, /*is_protect=*/true, + &fixture->server_protect) == TSI_OK); + /* Create server record protocol for unprotect. */ + GPR_ASSERT(gsec_aes_gcm_aead_crypter_create( + key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey, + &crypter, nullptr) == GRPC_STATUS_OK); + GPR_ASSERT(alts_grpc_integrity_only_record_protocol_create( + crypter, 8, /*is_client=*/false, /*is_protect=*/false, + &fixture->server_unprotect) == TSI_OK); + + gpr_free(key); + return fixture; +} + +static alts_grpc_record_protocol_test_fixture* +test_fixture_integrity_only_no_rekey_create() { + return test_fixture_integrity_only_create(false); +} + +static alts_grpc_record_protocol_test_fixture* +test_fixture_integrity_only_rekey_create() { + return test_fixture_integrity_only_create(true); +} + +static alts_grpc_record_protocol_test_fixture* +test_fixture_privacy_integrity_create(bool rekey) { + alts_grpc_record_protocol_test_fixture* fixture = + static_cast( + gpr_zalloc(sizeof(alts_grpc_record_protocol_test_fixture))); + size_t key_length = rekey ? kAes128GcmRekeyKeyLength : kAes128GcmKeyLength; + uint8_t* key; + gsec_test_random_array(&key, key_length); + gsec_aead_crypter* crypter = nullptr; + + /* Create client record protocol for protect. */ + GPR_ASSERT(gsec_aes_gcm_aead_crypter_create( + key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey, + &crypter, nullptr) == GRPC_STATUS_OK); + GPR_ASSERT(alts_grpc_privacy_integrity_record_protocol_create( + crypter, 8, /*is_client=*/true, /*is_protect=*/true, + &fixture->client_protect) == TSI_OK); + /* Create client record protocol for unprotect. */ + GPR_ASSERT(gsec_aes_gcm_aead_crypter_create( + key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey, + &crypter, nullptr) == GRPC_STATUS_OK); + GPR_ASSERT(alts_grpc_privacy_integrity_record_protocol_create( + crypter, 8, /*is_client=*/true, /*is_protect=*/false, + &fixture->client_unprotect) == TSI_OK); + /* Create server record protocol for protect. */ + GPR_ASSERT(gsec_aes_gcm_aead_crypter_create( + key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey, + &crypter, nullptr) == GRPC_STATUS_OK); + GPR_ASSERT(alts_grpc_privacy_integrity_record_protocol_create( + crypter, 8, /*is_client=*/false, /*is_protect=*/true, + &fixture->server_protect) == TSI_OK); + /* Create server record protocol for unprotect. */ + GPR_ASSERT(gsec_aes_gcm_aead_crypter_create( + key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey, + &crypter, nullptr) == GRPC_STATUS_OK); + GPR_ASSERT(alts_grpc_privacy_integrity_record_protocol_create( + crypter, 8, /*is_client=*/false, /*is_protect=*/false, + &fixture->server_unprotect) == TSI_OK); + + gpr_free(key); + return fixture; +} + +static alts_grpc_record_protocol_test_fixture* +test_fixture_privacy_integrity_no_rekey_create() { + return test_fixture_privacy_integrity_create(false); +} + +static alts_grpc_record_protocol_test_fixture* +test_fixture_privacy_integrity_rekey_create() { + return test_fixture_privacy_integrity_create(true); +} + +static void alts_grpc_record_protocol_test_fixture_destroy( + alts_grpc_record_protocol_test_fixture* fixture) { + if (fixture == nullptr) { + return; + } + grpc_core::ExecCtx exec_ctx; + alts_grpc_record_protocol_destroy(fixture->client_protect); + alts_grpc_record_protocol_destroy(fixture->client_unprotect); + alts_grpc_record_protocol_destroy(fixture->server_protect); + alts_grpc_record_protocol_destroy(fixture->server_unprotect); + grpc_core::ExecCtx::Get()->Flush(); + gpr_free(fixture); +} + +static alts_grpc_record_protocol_test_var* +alts_grpc_record_protocol_test_var_create() { + alts_grpc_record_protocol_test_var* var = + static_cast( + gpr_zalloc(sizeof(alts_grpc_record_protocol_test_var))); + var->header_length = alts_iovec_record_protocol_get_header_length(); + var->tag_length = kTagLength; + /* Initialized slice buffers. */ + grpc_slice_buffer_init(&var->original_sb); + grpc_slice_buffer_init(&var->duplicate_sb); + grpc_slice_buffer_init(&var->protected_sb); + grpc_slice_buffer_init(&var->unprotected_sb); + /* Randomly sets content of original_sb, and copies into duplicate_sb. */ + create_random_slice_buffer(&var->original_sb); + for (size_t i = 0; i < var->original_sb.count; i++) { + grpc_slice_buffer_add(&var->duplicate_sb, + grpc_slice_ref(var->original_sb.slices[i])); + } + return var; +} + +static void alts_grpc_record_protocol_test_var_destroy( + alts_grpc_record_protocol_test_var* var) { + if (var == nullptr) { + return; + } + grpc_slice_buffer_destroy_internal(&var->original_sb); + grpc_slice_buffer_destroy_internal(&var->duplicate_sb); + grpc_slice_buffer_destroy_internal(&var->protected_sb); + grpc_slice_buffer_destroy_internal(&var->unprotected_sb); + gpr_free(var); +} + +/* --- alts grpc record protocol tests. --- */ + +static void random_seal_unseal(alts_grpc_record_protocol* sender, + alts_grpc_record_protocol* receiver) { + grpc_core::ExecCtx exec_ctx; + for (size_t i = 0; i < kSealRepeatTimes; i++) { + alts_grpc_record_protocol_test_var* var = + alts_grpc_record_protocol_test_var_create(); + /* Seals and then unseals. */ + size_t data_length = var->original_sb.length; + tsi_result status = alts_grpc_record_protocol_protect( + sender, &var->original_sb, &var->protected_sb); + GPR_ASSERT(status == TSI_OK); + GPR_ASSERT(var->protected_sb.length == + data_length + var->header_length + var->tag_length); + status = alts_grpc_record_protocol_unprotect(receiver, &var->protected_sb, + &var->unprotected_sb); + GPR_ASSERT(status == TSI_OK); + GPR_ASSERT( + are_slice_buffers_equal(&var->unprotected_sb, &var->duplicate_sb)); + alts_grpc_record_protocol_test_var_destroy(var); + } + grpc_core::ExecCtx::Get()->Flush(); +} + +static void empty_seal_unseal(alts_grpc_record_protocol* sender, + alts_grpc_record_protocol* receiver) { + grpc_core::ExecCtx exec_ctx; + for (size_t i = 0; i < kSealRepeatTimes; i++) { + alts_grpc_record_protocol_test_var* var = + alts_grpc_record_protocol_test_var_create(); + /* Seals and then unseals empty payload. */ + grpc_slice_buffer_reset_and_unref_internal(&var->original_sb); + grpc_slice_buffer_reset_and_unref_internal(&var->duplicate_sb); + tsi_result status = alts_grpc_record_protocol_protect( + sender, &var->original_sb, &var->protected_sb); + GPR_ASSERT(status == TSI_OK); + GPR_ASSERT(var->protected_sb.length == + var->header_length + var->tag_length); + status = alts_grpc_record_protocol_unprotect(receiver, &var->protected_sb, + &var->unprotected_sb); + GPR_ASSERT(status == TSI_OK); + GPR_ASSERT( + are_slice_buffers_equal(&var->unprotected_sb, &var->duplicate_sb)); + alts_grpc_record_protocol_test_var_destroy(var); + } + grpc_core::ExecCtx::Get()->Flush(); +} + +static void unsync_seal_unseal(alts_grpc_record_protocol* sender, + alts_grpc_record_protocol* receiver) { + grpc_core::ExecCtx exec_ctx; + tsi_result status; + alts_grpc_record_protocol_test_var* var = + alts_grpc_record_protocol_test_var_create(); + /* Seals once. */ + status = alts_grpc_record_protocol_protect(sender, &var->original_sb, + &var->protected_sb); + GPR_ASSERT(status == TSI_OK); + grpc_slice_buffer_reset_and_unref_internal(&var->protected_sb); + /* Seals again. */ + status = alts_grpc_record_protocol_protect(sender, &var->duplicate_sb, + &var->protected_sb); + GPR_ASSERT(status == TSI_OK); + /* Unseals the second frame. */ + status = alts_grpc_record_protocol_unprotect(receiver, &var->protected_sb, + &var->unprotected_sb); + GPR_ASSERT(status == TSI_INTERNAL_ERROR); + alts_grpc_record_protocol_test_var_destroy(var); + grpc_core::ExecCtx::Get()->Flush(); +} + +static void corrupted_data(alts_grpc_record_protocol* sender, + alts_grpc_record_protocol* receiver) { + grpc_core::ExecCtx exec_ctx; + tsi_result status; + alts_grpc_record_protocol_test_var* var = + alts_grpc_record_protocol_test_var_create(); + /* Seals once. */ + status = alts_grpc_record_protocol_protect(sender, &var->original_sb, + &var->protected_sb); + GPR_ASSERT(status == TSI_OK); + /* Corrupts one byte in protected_sb and tries to unprotect. */ + alter_random_byte(&var->protected_sb); + status = alts_grpc_record_protocol_unprotect(receiver, &var->protected_sb, + &var->unprotected_sb); + GPR_ASSERT(status == TSI_INTERNAL_ERROR); + alts_grpc_record_protocol_test_var_destroy(var); + grpc_core::ExecCtx::Get()->Flush(); +} + +static void input_check(alts_grpc_record_protocol* rp) { + grpc_core::ExecCtx exec_ctx; + tsi_result status; + alts_grpc_record_protocol_test_var* var = + alts_grpc_record_protocol_test_var_create(); + /* Protects with nullptr input. */ + status = alts_grpc_record_protocol_protect(rp, nullptr, &var->protected_sb); + GPR_ASSERT(status == TSI_INVALID_ARGUMENT); + status = alts_grpc_record_protocol_protect(rp, &var->original_sb, nullptr); + GPR_ASSERT(status == TSI_INVALID_ARGUMENT); + /* Unprotects with nullptr input. */ + status = alts_grpc_record_protocol_protect(rp, &var->original_sb, + &var->protected_sb); + GPR_ASSERT(status == TSI_OK); + status = + alts_grpc_record_protocol_unprotect(rp, nullptr, &var->unprotected_sb); + GPR_ASSERT(status == TSI_INVALID_ARGUMENT); + status = alts_grpc_record_protocol_unprotect(rp, &var->protected_sb, nullptr); + GPR_ASSERT(status == TSI_INVALID_ARGUMENT); + /* Unprotects on a temporary slice buffer which length is smaller than header + * length plus tag length. */ + grpc_slice_buffer temp_sb; + grpc_slice_buffer_init(&temp_sb); + grpc_slice_buffer_move_first( + &var->protected_sb, var->header_length + var->tag_length - 1, &temp_sb); + status = + alts_grpc_record_protocol_unprotect(rp, &temp_sb, &var->unprotected_sb); + GPR_ASSERT(status == TSI_INVALID_ARGUMENT); + grpc_slice_buffer_destroy_internal(&temp_sb); + alts_grpc_record_protocol_test_var_destroy(var); + grpc_core::ExecCtx::Get()->Flush(); +} + +/* --- Test cases. --- */ + +static void alts_grpc_record_protocol_random_seal_unseal_tests( + alts_grpc_record_protocol_test_fixture* fixture) { + random_seal_unseal(fixture->client_protect, fixture->server_unprotect); + random_seal_unseal(fixture->server_protect, fixture->client_unprotect); +} + +static void alts_grpc_record_protocol_empty_seal_unseal_tests( + alts_grpc_record_protocol_test_fixture* fixture) { + empty_seal_unseal(fixture->client_protect, fixture->server_unprotect); + empty_seal_unseal(fixture->server_protect, fixture->client_unprotect); +} + +static void alts_grpc_record_protocol_unsync_seal_unseal_tests( + alts_grpc_record_protocol_test_fixture* fixture) { + unsync_seal_unseal(fixture->client_protect, fixture->server_unprotect); + unsync_seal_unseal(fixture->server_protect, fixture->client_unprotect); +} + +static void alts_grpc_record_protocol_corrupted_data_tests( + alts_grpc_record_protocol_test_fixture* fixture) { + corrupted_data(fixture->client_protect, fixture->server_unprotect); + corrupted_data(fixture->server_protect, fixture->client_unprotect); +} + +static void alts_grpc_record_protocol_input_check_tests( + alts_grpc_record_protocol_test_fixture* fixture) { + input_check(fixture->client_protect); +} + +static void alts_grpc_record_protocol_tests( + alts_grpc_record_protocol_test_fixture* (*fixture_create)()) { + auto* fixture_1 = fixture_create(); + alts_grpc_record_protocol_random_seal_unseal_tests(fixture_1); + alts_grpc_record_protocol_test_fixture_destroy(fixture_1); + + auto* fixture_2 = fixture_create(); + alts_grpc_record_protocol_empty_seal_unseal_tests(fixture_2); + alts_grpc_record_protocol_test_fixture_destroy(fixture_2); + + auto* fixture_3 = fixture_create(); + alts_grpc_record_protocol_unsync_seal_unseal_tests(fixture_3); + alts_grpc_record_protocol_test_fixture_destroy(fixture_3); + + auto* fixture_4 = fixture_create(); + alts_grpc_record_protocol_corrupted_data_tests(fixture_4); + alts_grpc_record_protocol_test_fixture_destroy(fixture_4); + + auto* fixture_5 = fixture_create(); + alts_grpc_record_protocol_input_check_tests(fixture_5); + alts_grpc_record_protocol_test_fixture_destroy(fixture_5); +} + +int main(int argc, char** argv) { + alts_grpc_record_protocol_tests(&test_fixture_integrity_only_no_rekey_create); + alts_grpc_record_protocol_tests(&test_fixture_integrity_only_rekey_create); + alts_grpc_record_protocol_tests( + &test_fixture_privacy_integrity_no_rekey_create); + alts_grpc_record_protocol_tests(&test_fixture_privacy_integrity_rekey_create); + + return 0; +} diff --git a/test/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol_test.cc b/test/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol_test.cc new file mode 100644 index 0000000000..db1934bbae --- /dev/null +++ b/test/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol_test.cc @@ -0,0 +1,928 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include + +#include "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h" +#include "test/core/tsi/alts/crypt/gsec_test_util.h" + +constexpr size_t kMaxDataSize = 1024; +constexpr size_t kMaxSlices = 10; +constexpr size_t kSealRepeatTimes = 5; +constexpr size_t kTagLength = 16; + +/* Test fixtures for each test cases. */ +struct alts_iovec_record_protocol_test_fixture { + alts_iovec_record_protocol* client_protect; + alts_iovec_record_protocol* client_unprotect; + alts_iovec_record_protocol* server_protect; + alts_iovec_record_protocol* server_unprotect; +}; + +/* Test variables for protect/unprotect operations. */ +struct alts_iovec_record_protocol_test_var { + uint8_t* header_buf; + size_t header_length; + iovec_t header_iovec; + uint8_t* tag_buf; + size_t tag_length; + iovec_t tag_iovec; + uint8_t* data_buf; + uint8_t* dup_buf; + size_t data_length; + iovec_t* data_iovec; + size_t data_iovec_length; + uint8_t* protected_buf; + iovec_t protected_iovec; + iovec_t unprotected_iovec; +}; + +/* --- Test utility functions. --- */ + +static void randomly_slice(uint8_t* input, size_t input_length, + iovec_t** output, size_t* output_length) { + if (input_length == 0) { + *output = nullptr; + *output_length = 0; + return; + } + *output_length = gsec_test_bias_random_uint32(kMaxSlices) + 1; + *output = static_cast(gpr_malloc(*output_length * sizeof(iovec_t))); + for (size_t i = 0; i < *output_length - 1; i++) { + size_t slice_length = + gsec_test_bias_random_uint32(static_cast(input_length)); + iovec_t slice = {input, slice_length}; + (*output)[i] = slice; + input += slice_length; + input_length -= slice_length; + } + iovec_t slice = {input, input_length}; + (*output)[*output_length - 1] = slice; +} + +static size_t alter_random_byte(uint8_t* buf, size_t buf_length) { + GPR_ASSERT(buf != nullptr); + uint32_t offset = + gsec_test_bias_random_uint32(static_cast(buf_length)); + (*(buf + offset))++; + return offset; +} + +static void revert_back_alter(uint8_t* buf, size_t offset) { + GPR_ASSERT(buf != nullptr); + (*(buf + offset))--; +} + +static alts_iovec_record_protocol_test_fixture* +alts_iovec_record_protocol_test_fixture_create(bool rekey, + bool integrity_only) { + alts_iovec_record_protocol_test_fixture* fixture = + static_cast( + gpr_malloc(sizeof(alts_iovec_record_protocol_test_fixture))); + size_t overflow_size = 8; + size_t key_length = rekey ? kAes128GcmRekeyKeyLength : kAes128GcmKeyLength; + uint8_t* key; + gsec_test_random_array(&key, key_length); + gsec_aead_crypter* crypter = nullptr; + /* Create client record protocol for protect. */ + GPR_ASSERT(gsec_aes_gcm_aead_crypter_create( + key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey, + &crypter, nullptr) == GRPC_STATUS_OK); + GPR_ASSERT(alts_iovec_record_protocol_create( + crypter, overflow_size, /*is_client=*/true, integrity_only, + /*is_protect=*/true, &fixture->client_protect, + nullptr) == GRPC_STATUS_OK); + /* Create client record protocol for unprotect. */ + GPR_ASSERT(gsec_aes_gcm_aead_crypter_create( + key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey, + &crypter, nullptr) == GRPC_STATUS_OK); + GPR_ASSERT(alts_iovec_record_protocol_create( + crypter, overflow_size, /*is_client=*/true, integrity_only, + /*is_protect=*/false, &fixture->client_unprotect, + nullptr) == GRPC_STATUS_OK); + /* Create server record protocol for protect. */ + GPR_ASSERT(gsec_aes_gcm_aead_crypter_create( + key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey, + &crypter, nullptr) == GRPC_STATUS_OK); + GPR_ASSERT(alts_iovec_record_protocol_create( + crypter, overflow_size, /*is_client=*/false, integrity_only, + /*is_protect=*/true, &fixture->server_protect, + nullptr) == GRPC_STATUS_OK); + /* Create server record protocol for unprotect. */ + GPR_ASSERT(gsec_aes_gcm_aead_crypter_create( + key, key_length, kAesGcmNonceLength, kAesGcmTagLength, rekey, + &crypter, nullptr) == GRPC_STATUS_OK); + GPR_ASSERT(alts_iovec_record_protocol_create( + crypter, overflow_size, /*is_client=*/false, integrity_only, + /*is_protect=*/false, &fixture->server_unprotect, + nullptr) == GRPC_STATUS_OK); + + gpr_free(key); + return fixture; +} + +static void alts_iovec_record_protocol_test_fixture_destroy( + alts_iovec_record_protocol_test_fixture* fixture) { + if (fixture == nullptr) { + return; + } + alts_iovec_record_protocol_destroy(fixture->client_protect); + alts_iovec_record_protocol_destroy(fixture->client_unprotect); + alts_iovec_record_protocol_destroy(fixture->server_protect); + alts_iovec_record_protocol_destroy(fixture->server_unprotect); + gpr_free(fixture); +} + +static alts_iovec_record_protocol_test_var* +alts_iovec_record_protocol_test_var_create() { + auto* var = static_cast( + gpr_zalloc(sizeof(alts_iovec_record_protocol_test_var))); + /* Sets header buffer. */ + var->header_length = alts_iovec_record_protocol_get_header_length(); + var->header_buf = static_cast(gpr_malloc(var->header_length)); + var->header_iovec.iov_base = var->header_buf; + var->header_iovec.iov_len = var->header_length; + /* Sets tag buffer. */ + var->tag_length = kTagLength; + var->tag_buf = static_cast(gpr_malloc(var->tag_length)); + var->tag_iovec.iov_base = var->tag_buf; + var->tag_iovec.iov_len = var->tag_length; + /* Randomly sets data buffer and duplicates to dup_buf. */ + var->data_length = gsec_test_bias_random_uint32(kMaxDataSize) + 1; + var->data_buf = static_cast(gpr_malloc(var->data_length)); + gsec_test_random_bytes(var->data_buf, var->data_length); + gsec_test_copy(var->data_buf, &var->dup_buf, var->data_length); + var->data_iovec = nullptr; + var->data_iovec_length = 0; + randomly_slice(var->data_buf, var->data_length, &var->data_iovec, + &var->data_iovec_length); + /* Sets protected iovec. */ + size_t protected_buf_length = + var->header_length + var->data_length + var->tag_length; + var->protected_buf = static_cast(gpr_malloc(protected_buf_length)); + var->protected_iovec.iov_base = var->protected_buf; + var->protected_iovec.iov_len = protected_buf_length; + /* Unprotected iovec points to data_buf. */ + var->unprotected_iovec.iov_base = var->data_buf; + var->unprotected_iovec.iov_len = var->data_length; + return var; +} + +static void alts_iovec_record_protocol_test_var_destroy( + alts_iovec_record_protocol_test_var* var) { + if (var == nullptr) { + return; + } + gpr_free(var->header_buf); + gpr_free(var->tag_buf); + gpr_free(var->data_buf); + gpr_free(var->dup_buf); + gpr_free(var->data_iovec); + gpr_free(var->protected_buf); + gpr_free(var); +} + +/* --- Integrity-only protect/unprotect tests. --- */ + +static void integrity_only_random_seal_unseal( + alts_iovec_record_protocol* sender, alts_iovec_record_protocol* receiver) { + for (size_t i = 0; i < kSealRepeatTimes; i++) { + alts_iovec_record_protocol_test_var* var = + alts_iovec_record_protocol_test_var_create(); + /* Seals and then unseals. */ + grpc_status_code status = alts_iovec_record_protocol_integrity_only_protect( + sender, var->data_iovec, var->data_iovec_length, var->header_iovec, + var->tag_iovec, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + gpr_free(var->data_iovec); + /* Randomly slices data buffer again. */ + randomly_slice(var->data_buf, var->data_length, &var->data_iovec, + &var->data_iovec_length); + status = alts_iovec_record_protocol_integrity_only_unprotect( + receiver, var->data_iovec, var->data_iovec_length, var->header_iovec, + var->tag_iovec, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + /* Makes sure data buffer has not been modified during + * seal/unseal. */ + GPR_ASSERT(memcmp(var->data_buf, var->dup_buf, var->data_length) == 0); + alts_iovec_record_protocol_test_var_destroy(var); + } +} + +static void integrity_only_empty_seal_unseal( + alts_iovec_record_protocol* sender, alts_iovec_record_protocol* receiver) { + for (size_t i = 0; i < kSealRepeatTimes; i++) { + alts_iovec_record_protocol_test_var* var = + alts_iovec_record_protocol_test_var_create(); + /* Seals and then unseals empty payload. */ + grpc_status_code status = alts_iovec_record_protocol_integrity_only_protect( + sender, nullptr, 0, var->header_iovec, var->tag_iovec, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + status = alts_iovec_record_protocol_integrity_only_unprotect( + receiver, nullptr, 0, var->header_iovec, var->tag_iovec, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + alts_iovec_record_protocol_test_var_destroy(var); + } +} + +static void integrity_only_unsync_seal_unseal( + alts_iovec_record_protocol* sender, alts_iovec_record_protocol* receiver) { + /* Seals once. */ + alts_iovec_record_protocol_test_var* var = + alts_iovec_record_protocol_test_var_create(); + grpc_status_code status = alts_iovec_record_protocol_integrity_only_protect( + sender, var->data_iovec, var->data_iovec_length, var->header_iovec, + var->tag_iovec, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + alts_iovec_record_protocol_test_var_destroy(var); + /* Seals again. */ + var = alts_iovec_record_protocol_test_var_create(); + status = alts_iovec_record_protocol_integrity_only_protect( + sender, var->data_iovec, var->data_iovec_length, var->header_iovec, + var->tag_iovec, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + /* Unseals the second frame. */ + char* error_message = nullptr; + status = alts_iovec_record_protocol_integrity_only_unprotect( + receiver, var->data_iovec, var->data_iovec_length, var->header_iovec, + var->tag_iovec, &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INTERNAL, error_message, + "Frame tag verification failed.")); + gpr_free(error_message); + alts_iovec_record_protocol_test_var_destroy(var); +} + +static void integrity_only_corrupted_data( + alts_iovec_record_protocol* sender, alts_iovec_record_protocol* receiver) { + /* Seals the data first. */ + alts_iovec_record_protocol_test_var* var = + alts_iovec_record_protocol_test_var_create(); + grpc_status_code status = alts_iovec_record_protocol_integrity_only_protect( + sender, var->data_iovec, var->data_iovec_length, var->header_iovec, + var->tag_iovec, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + /* Alter frame length field. */ + char* error_message = nullptr; + size_t offset = + alter_random_byte(var->header_buf, kZeroCopyFrameLengthFieldSize); + status = alts_iovec_record_protocol_integrity_only_unprotect( + receiver, var->data_iovec, var->data_iovec_length, var->header_iovec, + var->tag_iovec, &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INTERNAL, error_message, "Bad frame length.")); + gpr_free(error_message); + revert_back_alter(var->header_buf, offset); + /* Alter message type field. */ + offset = alter_random_byte(var->header_buf + kZeroCopyFrameLengthFieldSize, + kZeroCopyFrameMessageTypeFieldSize); + status = alts_iovec_record_protocol_integrity_only_unprotect( + receiver, var->data_iovec, var->data_iovec_length, var->header_iovec, + var->tag_iovec, &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INTERNAL, error_message, + "Unsupported message type.")); + gpr_free(error_message); + revert_back_alter(var->header_buf + kZeroCopyFrameLengthFieldSize, offset); + /* Alter data. */ + offset = alter_random_byte(var->data_buf, var->data_length); + status = alts_iovec_record_protocol_integrity_only_unprotect( + receiver, var->data_iovec, var->data_iovec_length, var->header_iovec, + var->tag_iovec, &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INTERNAL, error_message, + "Frame tag verification failed.")); + gpr_free(error_message); + revert_back_alter(var->data_buf, offset); + /* Alter tag. */ + offset = alter_random_byte(var->tag_buf, var->tag_length); + status = alts_iovec_record_protocol_integrity_only_unprotect( + receiver, var->data_iovec, var->data_iovec_length, var->header_iovec, + var->tag_iovec, &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INTERNAL, error_message, + "Frame tag verification failed.")); + gpr_free(error_message); + revert_back_alter(var->tag_buf, offset); + /* Reverted protected data should be verified correctly. */ + status = alts_iovec_record_protocol_integrity_only_unprotect( + receiver, var->data_iovec, var->data_iovec_length, var->header_iovec, + var->tag_iovec, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(memcmp(var->data_buf, var->dup_buf, var->data_length) == 0); + alts_iovec_record_protocol_test_var_destroy(var); +} + +static void integrity_only_protect_input_check(alts_iovec_record_protocol* rp) { + alts_iovec_record_protocol_test_var* var = + alts_iovec_record_protocol_test_var_create(); + char* error_message = nullptr; + /* Header buffer is nullptr. */ + iovec_t header_iovec = {nullptr, var->header_length}; + grpc_status_code status = alts_iovec_record_protocol_integrity_only_protect( + rp, var->data_iovec, var->data_iovec_length, header_iovec, var->tag_iovec, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "Header is nullptr.")); + gpr_free(error_message); + /* Header buffer length is 0. */ + header_iovec.iov_base = var->header_buf; + header_iovec.iov_len = 0; + status = alts_iovec_record_protocol_integrity_only_protect( + rp, var->data_iovec, var->data_iovec_length, header_iovec, var->tag_iovec, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "Header length is incorrect.")); + gpr_free(error_message); + /* Tag buffer is nullptr. */ + iovec_t tag_iovec = {nullptr, var->tag_length}; + status = alts_iovec_record_protocol_integrity_only_protect( + rp, var->data_iovec, var->data_iovec_length, var->header_iovec, tag_iovec, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, "Tag is nullptr.")); + gpr_free(error_message); + /* Tag buffer length is 0. */ + tag_iovec.iov_base = var->tag_buf; + tag_iovec.iov_len = 0; + status = alts_iovec_record_protocol_integrity_only_protect( + rp, var->data_iovec, var->data_iovec_length, var->header_iovec, tag_iovec, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "Tag length is incorrect.")); + gpr_free(error_message); + alts_iovec_record_protocol_test_var_destroy(var); +} + +static void integrity_only_unprotect_input_check( + alts_iovec_record_protocol* rp) { + alts_iovec_record_protocol_test_var* var = + alts_iovec_record_protocol_test_var_create(); + char* error_message = nullptr; + /* Header buffer is nullptr. */ + iovec_t header_iovec = {nullptr, var->header_length}; + grpc_status_code status = alts_iovec_record_protocol_integrity_only_unprotect( + rp, var->data_iovec, var->data_iovec_length, header_iovec, var->tag_iovec, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "Header is nullptr.")); + gpr_free(error_message); + /* Header buffer length is 0. */ + header_iovec.iov_base = var->header_buf; + header_iovec.iov_len = 0; + status = alts_iovec_record_protocol_integrity_only_unprotect( + rp, var->data_iovec, var->data_iovec_length, header_iovec, var->tag_iovec, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "Header length is incorrect.")); + gpr_free(error_message); + /* Tag buffer is nullptr. */ + iovec_t tag_iovec = {nullptr, var->tag_length}; + status = alts_iovec_record_protocol_integrity_only_unprotect( + rp, var->data_iovec, var->data_iovec_length, var->header_iovec, tag_iovec, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, "Tag is nullptr.")); + gpr_free(error_message); + /* Tag buffer length is 0. */ + tag_iovec.iov_base = var->tag_buf; + tag_iovec.iov_len = 0; + status = alts_iovec_record_protocol_integrity_only_unprotect( + rp, var->data_iovec, var->data_iovec_length, var->header_iovec, tag_iovec, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "Tag length is incorrect.")); + gpr_free(error_message); + alts_iovec_record_protocol_test_var_destroy(var); +} + +/* --- Privacy-integrity protect/unprotect tests. --- */ + +static void privacy_integrity_random_seal_unseal( + alts_iovec_record_protocol* sender, alts_iovec_record_protocol* receiver) { + for (size_t i = 0; i < kSealRepeatTimes; i++) { + alts_iovec_record_protocol_test_var* var = + alts_iovec_record_protocol_test_var_create(); + /* Seals and then unseals. */ + grpc_status_code status = + alts_iovec_record_protocol_privacy_integrity_protect( + sender, var->data_iovec, var->data_iovec_length, + var->protected_iovec, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + iovec_t header_iovec = {var->protected_buf, var->header_length}; + gpr_free(var->data_iovec); + /* Randomly slices protected buffer, excluding the header. */ + randomly_slice(var->protected_buf + var->header_length, + var->data_length + var->tag_length, &var->data_iovec, + &var->data_iovec_length); + status = alts_iovec_record_protocol_privacy_integrity_unprotect( + receiver, header_iovec, var->data_iovec, var->data_iovec_length, + var->unprotected_iovec, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + /* Makes sure unprotected data are the same as the original. */ + GPR_ASSERT(memcmp(var->data_buf, var->dup_buf, var->data_length) == 0); + alts_iovec_record_protocol_test_var_destroy(var); + } +} + +static void privacy_integrity_empty_seal_unseal( + alts_iovec_record_protocol* sender, alts_iovec_record_protocol* receiver) { + alts_iovec_record_protocol_test_var* var = + alts_iovec_record_protocol_test_var_create(); + size_t empty_payload_frame_size = var->header_length + var->tag_length; + auto* protected_buf = + static_cast(gpr_malloc(empty_payload_frame_size)); + for (size_t i = 0; i < kSealRepeatTimes; i++) { + iovec_t protected_iovec = {protected_buf, empty_payload_frame_size}; + iovec_t unprotected_iovec = {nullptr, 0}; + iovec_t data_iovec = {protected_buf + var->header_length, var->tag_length}; + /* Seals and then unseals empty payload. */ + grpc_status_code status = + alts_iovec_record_protocol_privacy_integrity_protect( + sender, nullptr, 0, protected_iovec, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + iovec_t header_iovec = {protected_buf, var->header_length}; + status = alts_iovec_record_protocol_privacy_integrity_unprotect( + receiver, header_iovec, &data_iovec, 1, unprotected_iovec, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + } + gpr_free(protected_buf); + alts_iovec_record_protocol_test_var_destroy(var); +} + +static void privacy_integrity_unsync_seal_unseal( + alts_iovec_record_protocol* sender, alts_iovec_record_protocol* receiver) { + /* Seals once. */ + alts_iovec_record_protocol_test_var* var = + alts_iovec_record_protocol_test_var_create(); + grpc_status_code status = + alts_iovec_record_protocol_privacy_integrity_protect( + sender, var->data_iovec, var->data_iovec_length, var->protected_iovec, + nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + alts_iovec_record_protocol_test_var_destroy(var); + /* Seals again. */ + var = alts_iovec_record_protocol_test_var_create(); + status = alts_iovec_record_protocol_privacy_integrity_protect( + sender, var->data_iovec, var->data_iovec_length, var->protected_iovec, + nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + /* Unseals the second frame. */ + char* error_message = nullptr; + iovec_t header_iovec = {var->protected_buf, var->header_length}; + iovec_t protected_iovec = {var->protected_buf + var->header_length, + var->data_length + var->tag_length}; + status = alts_iovec_record_protocol_privacy_integrity_unprotect( + receiver, header_iovec, &protected_iovec, 1, var->unprotected_iovec, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INTERNAL, error_message, "Frame decryption failed.")); + gpr_free(error_message); + alts_iovec_record_protocol_test_var_destroy(var); +} + +static void privacy_integrity_corrupted_data( + alts_iovec_record_protocol* sender, alts_iovec_record_protocol* receiver) { + /* Seals the data first. */ + alts_iovec_record_protocol_test_var* var = + alts_iovec_record_protocol_test_var_create(); + grpc_status_code status = + alts_iovec_record_protocol_privacy_integrity_protect( + sender, var->data_iovec, var->data_iovec_length, var->protected_iovec, + nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + char* error_message = nullptr; + uint8_t* header_buf = var->protected_buf; + size_t header_length = var->header_length; + iovec_t header_iovec = {header_buf, header_length}; + /* The following protected_buf and protected_length excludes header. */ + uint8_t* protected_buf = var->protected_buf + var->header_length; + size_t protected_length = var->data_length + var->tag_length; + iovec_t protected_iovec = {protected_buf, protected_length}; + /* Alter frame length field. */ + size_t offset = alter_random_byte(header_buf, kZeroCopyFrameLengthFieldSize); + status = alts_iovec_record_protocol_privacy_integrity_unprotect( + receiver, header_iovec, &protected_iovec, 1, var->unprotected_iovec, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INTERNAL, error_message, "Bad frame length.")); + gpr_free(error_message); + revert_back_alter(header_buf, offset); + /* Alter message type field. */ + offset = alter_random_byte(header_buf + kZeroCopyFrameLengthFieldSize, + kZeroCopyFrameMessageTypeFieldSize); + status = alts_iovec_record_protocol_privacy_integrity_unprotect( + receiver, header_iovec, &protected_iovec, 1, var->unprotected_iovec, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INTERNAL, error_message, + "Unsupported message type.")); + gpr_free(error_message); + revert_back_alter(header_buf + kZeroCopyFrameLengthFieldSize, offset); + /* Alter protected data. */ + offset = alter_random_byte(protected_buf, protected_length); + status = alts_iovec_record_protocol_privacy_integrity_unprotect( + receiver, header_iovec, &protected_iovec, 1, var->unprotected_iovec, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INTERNAL, error_message, "Frame decryption failed.")); + gpr_free(error_message); + revert_back_alter(protected_buf, offset); + /* Reverted protected data should be verified correctly. */ + status = alts_iovec_record_protocol_privacy_integrity_unprotect( + receiver, header_iovec, &protected_iovec, 1, var->unprotected_iovec, + nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(memcmp(var->data_buf, var->dup_buf, var->data_length) == 0); + alts_iovec_record_protocol_test_var_destroy(var); +} + +static void privacy_integrity_protect_input_check( + alts_iovec_record_protocol* rp) { + alts_iovec_record_protocol_test_var* var = + alts_iovec_record_protocol_test_var_create(); + char* error_message = nullptr; + /* Protected output buffer is nullptr. */ + iovec_t protected_iovec = {nullptr, var->protected_iovec.iov_len}; + grpc_status_code status = + alts_iovec_record_protocol_privacy_integrity_protect( + rp, var->data_iovec, var->data_iovec_length, protected_iovec, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "Protected frame is nullptr.")); + gpr_free(error_message); + /* Protected output buffer length incorrect. */ + protected_iovec.iov_base = var->protected_buf; + protected_iovec.iov_len = var->header_length + var->data_length; + status = alts_iovec_record_protocol_privacy_integrity_protect( + rp, var->data_iovec, var->data_iovec_length, protected_iovec, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "Protected frame size is incorrect.")); + gpr_free(error_message); + alts_iovec_record_protocol_test_var_destroy(var); +} + +static void privacy_integrity_unprotect_input_check( + alts_iovec_record_protocol* rp) { + alts_iovec_record_protocol_test_var* var = + alts_iovec_record_protocol_test_var_create(); + char* error_message = nullptr; + /* Header buffer is nullptr. */ + iovec_t header_iovec = {var->protected_buf, var->header_length}; + iovec_t protected_iovec = {var->protected_buf + var->header_length, + var->data_length + var->tag_length}; + header_iovec.iov_base = nullptr; + grpc_status_code status = + alts_iovec_record_protocol_privacy_integrity_unprotect( + rp, header_iovec, &protected_iovec, 1, var->unprotected_iovec, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "Header is nullptr.")); + gpr_free(error_message); + header_iovec.iov_base = var->protected_buf; + /* Header buffer length is 0. */ + header_iovec.iov_len = 0; + status = alts_iovec_record_protocol_privacy_integrity_unprotect( + rp, header_iovec, &protected_iovec, 1, var->unprotected_iovec, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "Header length is incorrect.")); + gpr_free(error_message); + header_iovec.iov_len = var->header_length; + /* Unprotected output buffer length is incorrect. */ + iovec_t unprotected_iovec = {var->data_buf, var->data_length - 1}; + status = alts_iovec_record_protocol_privacy_integrity_unprotect( + rp, header_iovec, &protected_iovec, 1, unprotected_iovec, &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INVALID_ARGUMENT, error_message, + "Unprotected data size is incorrect.")); + gpr_free(error_message); + alts_iovec_record_protocol_test_var_destroy(var); +} + +/* --- Integrity-only and privacy-integrity mixed. --- */ + +static void record_protocol_wrong_mode( + alts_iovec_record_protocol* integrity_only_protect_rp, + alts_iovec_record_protocol* integrity_only_unprotect_rp, + alts_iovec_record_protocol* privacy_integrity_protect_rp, + alts_iovec_record_protocol* privacy_integrity_unprotect_rp) { + alts_iovec_record_protocol_test_var* var = + alts_iovec_record_protocol_test_var_create(); + grpc_status_code status; + char* error_message = nullptr; + /* Call integrity-only protect on privacy-integrity record protocol. */ + status = alts_iovec_record_protocol_integrity_only_protect( + privacy_integrity_protect_rp, var->data_iovec, var->data_iovec_length, + var->header_iovec, var->tag_iovec, &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_FAILED_PRECONDITION, error_message, + "Integrity-only operations are not allowed for this object.")); + gpr_free(error_message); + /* Call integrity-only unprotect on privacy-integrity record protocol. */ + status = alts_iovec_record_protocol_integrity_only_unprotect( + privacy_integrity_unprotect_rp, var->data_iovec, var->data_iovec_length, + var->header_iovec, var->tag_iovec, &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_FAILED_PRECONDITION, error_message, + "Integrity-only operations are not allowed for this object.")); + gpr_free(error_message); + /* Call privacy-integrity protect on integrity-only record protocol. */ + status = alts_iovec_record_protocol_privacy_integrity_protect( + integrity_only_protect_rp, var->data_iovec, var->data_iovec_length, + var->protected_iovec, &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_FAILED_PRECONDITION, error_message, + "Privacy-integrity operations are not allowed for this object.")); + gpr_free(error_message); + /* Call privacy-integrity unprotect on integrity-only record protocol. */ + status = alts_iovec_record_protocol_privacy_integrity_unprotect( + integrity_only_unprotect_rp, var->header_iovec, var->data_iovec, + var->data_iovec_length, var->unprotected_iovec, &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_FAILED_PRECONDITION, error_message, + "Privacy-integrity operations are not allowed for this object.")); + gpr_free(error_message); + alts_iovec_record_protocol_test_var_destroy(var); +} + +static void integrity_seal_privacy_unseal( + alts_iovec_record_protocol* integrity_only_sender, + alts_iovec_record_protocol* privacy_integrity_receiver) { + alts_iovec_record_protocol_test_var* var = + alts_iovec_record_protocol_test_var_create(); + grpc_status_code status; + char* error_message = nullptr; + /* Seals with integrity-only protect. */ + status = alts_iovec_record_protocol_integrity_only_protect( + integrity_only_sender, var->data_iovec, var->data_iovec_length, + var->header_iovec, var->tag_iovec, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + /* Unseal with privacy-integrity unprotect. */ + memcpy(var->protected_buf, var->data_buf, var->data_length); + memcpy(var->protected_buf + var->data_length, var->tag_buf, var->tag_length); + iovec_t protected_iovec = {var->protected_buf, + var->data_length + var->tag_length}; + status = alts_iovec_record_protocol_privacy_integrity_unprotect( + privacy_integrity_receiver, var->header_iovec, &protected_iovec, 1, + var->unprotected_iovec, &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INTERNAL, error_message, "Frame decryption failed.")); + gpr_free(error_message); + alts_iovec_record_protocol_test_var_destroy(var); +} + +static void privacy_seal_integrity_unseal( + alts_iovec_record_protocol* privacy_integrity_sender, + alts_iovec_record_protocol* integrity_only_receiver) { + alts_iovec_record_protocol_test_var* var = + alts_iovec_record_protocol_test_var_create(); + grpc_status_code status; + char* error_message = nullptr; + /* Seals with privacy-integrity protect. */ + status = alts_iovec_record_protocol_privacy_integrity_protect( + privacy_integrity_sender, var->data_iovec, var->data_iovec_length, + var->protected_iovec, nullptr); + GPR_ASSERT(status == GRPC_STATUS_OK); + /* Unseal with integrity-only unprotect. */ + iovec_t header_iovec = {var->protected_buf, var->header_length}; + iovec_t data_iovec = {var->protected_buf + var->header_length, + var->data_length}; + iovec_t tag_iovec = { + var->protected_buf + var->header_length + var->data_length, + var->tag_length}; + status = alts_iovec_record_protocol_integrity_only_unprotect( + integrity_only_receiver, &data_iovec, 1, header_iovec, tag_iovec, + &error_message); + GPR_ASSERT(gsec_test_expect_compare_code_and_substr( + status, GRPC_STATUS_INTERNAL, error_message, + "Frame tag verification failed.")); + gpr_free(error_message); + alts_iovec_record_protocol_test_var_destroy(var); +} + +/* --- Test cases. --- */ + +static void alts_iovec_record_protocol_random_seal_unseal_tests() { + alts_iovec_record_protocol_test_fixture* fixture = + alts_iovec_record_protocol_test_fixture_create( + /*rekey=*/false, /*integrity_only=*/true); + integrity_only_random_seal_unseal(fixture->client_protect, + fixture->server_unprotect); + integrity_only_random_seal_unseal(fixture->server_protect, + fixture->client_unprotect); + alts_iovec_record_protocol_test_fixture_destroy(fixture); + + fixture = alts_iovec_record_protocol_test_fixture_create( + /*rekey=*/true, /*integrity_only=*/true); + integrity_only_random_seal_unseal(fixture->client_protect, + fixture->server_unprotect); + integrity_only_random_seal_unseal(fixture->server_protect, + fixture->client_unprotect); + alts_iovec_record_protocol_test_fixture_destroy(fixture); + + fixture = alts_iovec_record_protocol_test_fixture_create( + /*rekey=*/false, /*integrity_only=*/false); + privacy_integrity_random_seal_unseal(fixture->client_protect, + fixture->server_unprotect); + privacy_integrity_random_seal_unseal(fixture->server_protect, + fixture->client_unprotect); + alts_iovec_record_protocol_test_fixture_destroy(fixture); + + fixture = alts_iovec_record_protocol_test_fixture_create( + /*rekey=*/true, /*integrity_only=*/false); + privacy_integrity_random_seal_unseal(fixture->client_protect, + fixture->server_unprotect); + privacy_integrity_random_seal_unseal(fixture->server_protect, + fixture->client_unprotect); + alts_iovec_record_protocol_test_fixture_destroy(fixture); +} + +static void alts_iovec_record_protocol_empty_seal_unseal_tests() { + alts_iovec_record_protocol_test_fixture* fixture = + alts_iovec_record_protocol_test_fixture_create( + /*rekey=*/false, /*integrity_only=*/true); + integrity_only_empty_seal_unseal(fixture->client_protect, + fixture->server_unprotect); + integrity_only_empty_seal_unseal(fixture->server_protect, + fixture->client_unprotect); + alts_iovec_record_protocol_test_fixture_destroy(fixture); + + fixture = alts_iovec_record_protocol_test_fixture_create( + /*rekey=*/true, /*integrity_only=*/true); + integrity_only_empty_seal_unseal(fixture->client_protect, + fixture->server_unprotect); + integrity_only_empty_seal_unseal(fixture->server_protect, + fixture->client_unprotect); + alts_iovec_record_protocol_test_fixture_destroy(fixture); + + fixture = alts_iovec_record_protocol_test_fixture_create( + /*rekey=*/false, /*integrity_only=*/false); + privacy_integrity_empty_seal_unseal(fixture->client_protect, + fixture->server_unprotect); + privacy_integrity_empty_seal_unseal(fixture->server_protect, + fixture->client_unprotect); + alts_iovec_record_protocol_test_fixture_destroy(fixture); + + fixture = alts_iovec_record_protocol_test_fixture_create( + /*rekey=*/true, /*integrity_only=*/false); + privacy_integrity_empty_seal_unseal(fixture->client_protect, + fixture->server_unprotect); + privacy_integrity_empty_seal_unseal(fixture->server_protect, + fixture->client_unprotect); + alts_iovec_record_protocol_test_fixture_destroy(fixture); +} + +static void alts_iovec_record_protocol_unsync_seal_unseal_tests() { + alts_iovec_record_protocol_test_fixture* fixture = + alts_iovec_record_protocol_test_fixture_create( + /*rekey=*/false, /*integrity_only=*/true); + integrity_only_unsync_seal_unseal(fixture->client_protect, + fixture->server_unprotect); + integrity_only_unsync_seal_unseal(fixture->server_protect, + fixture->client_unprotect); + alts_iovec_record_protocol_test_fixture_destroy(fixture); + + fixture = alts_iovec_record_protocol_test_fixture_create( + /*rekey=*/true, /*integrity_only=*/true); + integrity_only_unsync_seal_unseal(fixture->client_protect, + fixture->server_unprotect); + integrity_only_unsync_seal_unseal(fixture->server_protect, + fixture->client_unprotect); + alts_iovec_record_protocol_test_fixture_destroy(fixture); + + fixture = alts_iovec_record_protocol_test_fixture_create( + /*rekey=*/false, /*integrity_only=*/false); + privacy_integrity_unsync_seal_unseal(fixture->client_protect, + fixture->server_unprotect); + privacy_integrity_unsync_seal_unseal(fixture->server_protect, + fixture->client_unprotect); + alts_iovec_record_protocol_test_fixture_destroy(fixture); + + fixture = alts_iovec_record_protocol_test_fixture_create( + /*rekey=*/true, /*integrity_only=*/false); + privacy_integrity_unsync_seal_unseal(fixture->client_protect, + fixture->server_unprotect); + privacy_integrity_unsync_seal_unseal(fixture->server_protect, + fixture->client_unprotect); + alts_iovec_record_protocol_test_fixture_destroy(fixture); +} + +static void alts_iovec_record_protocol_corrupted_data_tests() { + alts_iovec_record_protocol_test_fixture* fixture = + alts_iovec_record_protocol_test_fixture_create( + /*rekey=*/false, /*integrity_only=*/true); + integrity_only_corrupted_data(fixture->client_protect, + fixture->server_unprotect); + integrity_only_corrupted_data(fixture->server_protect, + fixture->client_unprotect); + alts_iovec_record_protocol_test_fixture_destroy(fixture); + + fixture = alts_iovec_record_protocol_test_fixture_create( + /*rekey=*/true, /*integrity_only=*/true); + integrity_only_corrupted_data(fixture->client_protect, + fixture->server_unprotect); + integrity_only_corrupted_data(fixture->server_protect, + fixture->client_unprotect); + alts_iovec_record_protocol_test_fixture_destroy(fixture); + + fixture = alts_iovec_record_protocol_test_fixture_create( + /*rekey=*/false, /*integrity_only=*/false); + privacy_integrity_corrupted_data(fixture->client_protect, + fixture->server_unprotect); + privacy_integrity_corrupted_data(fixture->server_protect, + fixture->client_unprotect); + alts_iovec_record_protocol_test_fixture_destroy(fixture); + + fixture = alts_iovec_record_protocol_test_fixture_create( + /*rekey=*/true, /*integrity_only=*/false); + privacy_integrity_corrupted_data(fixture->client_protect, + fixture->server_unprotect); + privacy_integrity_corrupted_data(fixture->server_protect, + fixture->client_unprotect); + alts_iovec_record_protocol_test_fixture_destroy(fixture); +} + +static void alts_iovec_record_protocol_input_check_tests() { + alts_iovec_record_protocol_test_fixture* fixture = + alts_iovec_record_protocol_test_fixture_create( + /*rekey=*/false, /*integrity_only=*/true); + integrity_only_protect_input_check(fixture->client_protect); + integrity_only_unprotect_input_check(fixture->client_unprotect); + alts_iovec_record_protocol_test_fixture_destroy(fixture); + + fixture = alts_iovec_record_protocol_test_fixture_create( + /*rekey=*/true, /*integrity_only=*/true); + integrity_only_protect_input_check(fixture->client_protect); + integrity_only_unprotect_input_check(fixture->client_unprotect); + alts_iovec_record_protocol_test_fixture_destroy(fixture); + + fixture = alts_iovec_record_protocol_test_fixture_create( + /*rekey=*/false, /*integrity_only=*/false); + privacy_integrity_protect_input_check(fixture->client_protect); + privacy_integrity_unprotect_input_check(fixture->client_unprotect); + alts_iovec_record_protocol_test_fixture_destroy(fixture); + + fixture = alts_iovec_record_protocol_test_fixture_create( + /*rekey=*/true, /*integrity_only=*/false); + privacy_integrity_protect_input_check(fixture->client_protect); + privacy_integrity_unprotect_input_check(fixture->client_unprotect); + alts_iovec_record_protocol_test_fixture_destroy(fixture); +} + +static void alts_iovec_record_protocol_mix_operations_tests() { + alts_iovec_record_protocol_test_fixture* fixture_1 = + alts_iovec_record_protocol_test_fixture_create( + /*rekey=*/false, /*integrity_only=*/true); + alts_iovec_record_protocol_test_fixture* fixture_2 = + alts_iovec_record_protocol_test_fixture_create( + /*rekey=*/false, /*integrity_only=*/false); + + record_protocol_wrong_mode( + fixture_1->client_protect, fixture_1->client_unprotect, + fixture_2->client_protect, fixture_2->client_unprotect); + integrity_seal_privacy_unseal(fixture_1->client_protect, + fixture_2->server_unprotect); + privacy_seal_integrity_unseal(fixture_2->client_protect, + fixture_1->server_unprotect); + + alts_iovec_record_protocol_test_fixture_destroy(fixture_1); + alts_iovec_record_protocol_test_fixture_destroy(fixture_2); +} + +int main(int argc, char** argv) { + alts_iovec_record_protocol_random_seal_unseal_tests(); + alts_iovec_record_protocol_empty_seal_unseal_tests(); + alts_iovec_record_protocol_unsync_seal_unseal_tests(); + alts_iovec_record_protocol_corrupted_data_tests(); + alts_iovec_record_protocol_input_check_tests(); + alts_iovec_record_protocol_mix_operations_tests(); + return 0; +} diff --git a/test/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector_test.cc b/test/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector_test.cc new file mode 100644 index 0000000000..2388be95cd --- /dev/null +++ b/test/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector_test.cc @@ -0,0 +1,289 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include + +#include "src/core/lib/slice/slice_internal.h" +#include "src/core/tsi/alts/crypt/gsec.h" +#include "src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h" +#include "src/core/tsi/transport_security_grpc.h" +#include "test/core/tsi/alts/crypt/gsec_test_util.h" + +/* TODO: tests zero_copy_grpc_protector under TSI test library, which + * has more comprehensive tests. */ + +constexpr size_t kSealRepeatTimes = 50; +constexpr size_t kSmallBufferSize = 16; +constexpr size_t kLargeBufferSize = 16384; +constexpr size_t kChannelMaxSize = 2048; +constexpr size_t kChannelMinSize = 128; + +/* Test fixtures for each test cases. */ +struct alts_zero_copy_grpc_protector_test_fixture { + tsi_zero_copy_grpc_protector* client; + tsi_zero_copy_grpc_protector* server; +}; + +/* Test input variables for protect/unprotect operations. */ +struct alts_zero_copy_grpc_protector_test_var { + grpc_slice_buffer original_sb; + grpc_slice_buffer duplicate_sb; + grpc_slice_buffer staging_sb; + grpc_slice_buffer protected_sb; + grpc_slice_buffer unprotected_sb; +}; + +/* --- Test utility functions. --- */ + +static void create_random_slice_buffer(grpc_slice_buffer* sb, + grpc_slice_buffer* dup_sb, + size_t length) { + GPR_ASSERT(sb != nullptr); + GPR_ASSERT(dup_sb != nullptr); + GPR_ASSERT(length > 0); + grpc_slice slice = GRPC_SLICE_MALLOC(length); + gsec_test_random_bytes(GRPC_SLICE_START_PTR(slice), length); + grpc_slice_buffer_add(sb, grpc_slice_ref(slice)); + grpc_slice_buffer_add(dup_sb, slice); +} + +static uint8_t* pointer_to_nth_byte(grpc_slice_buffer* sb, size_t index) { + GPR_ASSERT(sb != nullptr); + GPR_ASSERT(index < sb->length); + for (size_t i = 0; i < sb->count; i++) { + if (index < GRPC_SLICE_LENGTH(sb->slices[i])) { + return GRPC_SLICE_START_PTR(sb->slices[i]) + index; + } else { + index -= GRPC_SLICE_LENGTH(sb->slices[i]); + } + } + return nullptr; +} + +/* Checks if two slice buffer contents are the same. It is not super efficient, + * but OK for testing. */ +static bool are_slice_buffers_equal(grpc_slice_buffer* first, + grpc_slice_buffer* second) { + GPR_ASSERT(first != nullptr); + GPR_ASSERT(second != nullptr); + if (first->length != second->length) { + return false; + } + for (size_t i = 0; i < first->length; i++) { + uint8_t* first_ptr = pointer_to_nth_byte(first, i); + uint8_t* second_ptr = pointer_to_nth_byte(second, i); + GPR_ASSERT(first_ptr != nullptr && second_ptr != nullptr); + if ((*first_ptr) != (*second_ptr)) { + return false; + } + } + return true; +} + +static alts_zero_copy_grpc_protector_test_fixture* +alts_zero_copy_grpc_protector_test_fixture_create(bool rekey, + bool integrity_only) { + alts_zero_copy_grpc_protector_test_fixture* fixture = + static_cast( + gpr_zalloc(sizeof(alts_zero_copy_grpc_protector_test_fixture))); + grpc_core::ExecCtx exec_ctx; + size_t key_length = rekey ? kAes128GcmRekeyKeyLength : kAes128GcmKeyLength; + uint8_t* key; + size_t max_protected_frame_size = 1024; + gsec_test_random_array(&key, key_length); + GPR_ASSERT(alts_zero_copy_grpc_protector_create( + key, key_length, rekey, /*is_client=*/true, integrity_only, + &max_protected_frame_size, &fixture->client) == TSI_OK); + GPR_ASSERT(alts_zero_copy_grpc_protector_create( + key, key_length, rekey, /*is_client=*/false, integrity_only, + &max_protected_frame_size, &fixture->server) == TSI_OK); + gpr_free(key); + grpc_core::ExecCtx::Get()->Flush(); + return fixture; +} + +static void alts_zero_copy_grpc_protector_test_fixture_destroy( + alts_zero_copy_grpc_protector_test_fixture* fixture) { + if (fixture == nullptr) { + return; + } + grpc_core::ExecCtx exec_ctx; + tsi_zero_copy_grpc_protector_destroy(fixture->client); + tsi_zero_copy_grpc_protector_destroy(fixture->server); + grpc_core::ExecCtx::Get()->Flush(); + gpr_free(fixture); +} + +static alts_zero_copy_grpc_protector_test_var* +alts_zero_copy_grpc_protector_test_var_create() { + alts_zero_copy_grpc_protector_test_var* var = + static_cast( + gpr_zalloc(sizeof(alts_zero_copy_grpc_protector_test_var))); + grpc_slice_buffer_init(&var->original_sb); + grpc_slice_buffer_init(&var->duplicate_sb); + grpc_slice_buffer_init(&var->staging_sb); + grpc_slice_buffer_init(&var->protected_sb); + grpc_slice_buffer_init(&var->unprotected_sb); + return var; +} + +static void alts_zero_copy_grpc_protector_test_var_destroy( + alts_zero_copy_grpc_protector_test_var* var) { + if (var == nullptr) { + return; + } + grpc_slice_buffer_destroy_internal(&var->original_sb); + grpc_slice_buffer_destroy_internal(&var->duplicate_sb); + grpc_slice_buffer_destroy_internal(&var->staging_sb); + grpc_slice_buffer_destroy_internal(&var->protected_sb); + grpc_slice_buffer_destroy_internal(&var->unprotected_sb); + gpr_free(var); +} + +/* --- ALTS zero-copy protector tests. --- */ + +static void seal_unseal_small_buffer(tsi_zero_copy_grpc_protector* sender, + tsi_zero_copy_grpc_protector* receiver) { + grpc_core::ExecCtx exec_ctx; + for (size_t i = 0; i < kSealRepeatTimes; i++) { + alts_zero_copy_grpc_protector_test_var* var = + alts_zero_copy_grpc_protector_test_var_create(); + /* Creates a random small slice buffer and calls protect(). */ + create_random_slice_buffer(&var->original_sb, &var->duplicate_sb, + kSmallBufferSize); + GPR_ASSERT(tsi_zero_copy_grpc_protector_protect( + sender, &var->original_sb, &var->protected_sb) == TSI_OK); + /* Splits protected slice buffer into two: first one is staging_sb, and + * second one is is protected_sb. */ + uint32_t staging_sb_size = + gsec_test_bias_random_uint32( + static_cast(var->protected_sb.length - 1)) + + 1; + grpc_slice_buffer_move_first(&var->protected_sb, staging_sb_size, + &var->staging_sb); + /* Unprotects one by one. */ + GPR_ASSERT(tsi_zero_copy_grpc_protector_unprotect( + receiver, &var->staging_sb, &var->unprotected_sb) == TSI_OK); + GPR_ASSERT(var->unprotected_sb.length == 0); + GPR_ASSERT(tsi_zero_copy_grpc_protector_unprotect( + receiver, &var->protected_sb, &var->unprotected_sb) == + TSI_OK); + GPR_ASSERT( + are_slice_buffers_equal(&var->unprotected_sb, &var->duplicate_sb)); + alts_zero_copy_grpc_protector_test_var_destroy(var); + } + grpc_core::ExecCtx::Get()->Flush(); +} + +static void seal_unseal_large_buffer(tsi_zero_copy_grpc_protector* sender, + tsi_zero_copy_grpc_protector* receiver) { + grpc_core::ExecCtx exec_ctx; + for (size_t i = 0; i < kSealRepeatTimes; i++) { + alts_zero_copy_grpc_protector_test_var* var = + alts_zero_copy_grpc_protector_test_var_create(); + /* Creates a random large slice buffer and calls protect(). */ + create_random_slice_buffer(&var->original_sb, &var->duplicate_sb, + kLargeBufferSize); + GPR_ASSERT(tsi_zero_copy_grpc_protector_protect( + sender, &var->original_sb, &var->protected_sb) == TSI_OK); + /* Splits protected slice buffer into multiple pieces. Receiver unprotects + * each slice buffer one by one. */ + uint32_t channel_size = gsec_test_bias_random_uint32(static_cast( + kChannelMaxSize + 1 - kChannelMinSize)) + + static_cast(kChannelMinSize); + while (var->protected_sb.length > channel_size) { + grpc_slice_buffer_reset_and_unref_internal(&var->staging_sb); + grpc_slice_buffer_move_first(&var->protected_sb, channel_size, + &var->staging_sb); + GPR_ASSERT(tsi_zero_copy_grpc_protector_unprotect( + receiver, &var->staging_sb, &var->unprotected_sb) == + TSI_OK); + } + GPR_ASSERT(tsi_zero_copy_grpc_protector_unprotect( + receiver, &var->protected_sb, &var->unprotected_sb) == + TSI_OK); + GPR_ASSERT( + are_slice_buffers_equal(&var->unprotected_sb, &var->duplicate_sb)); + alts_zero_copy_grpc_protector_test_var_destroy(var); + } + grpc_core::ExecCtx::Get()->Flush(); +} + +/* --- Test cases. --- */ + +static void alts_zero_copy_protector_seal_unseal_small_buffer_tests() { + alts_zero_copy_grpc_protector_test_fixture* fixture = + alts_zero_copy_grpc_protector_test_fixture_create( + /*rekey=*/false, /*integrity_only=*/true); + seal_unseal_small_buffer(fixture->client, fixture->server); + seal_unseal_small_buffer(fixture->server, fixture->client); + alts_zero_copy_grpc_protector_test_fixture_destroy(fixture); + + fixture = alts_zero_copy_grpc_protector_test_fixture_create( + /*rekey=*/false, /*integrity_only=*/false); + seal_unseal_small_buffer(fixture->client, fixture->server); + seal_unseal_small_buffer(fixture->server, fixture->client); + alts_zero_copy_grpc_protector_test_fixture_destroy(fixture); + + fixture = alts_zero_copy_grpc_protector_test_fixture_create( + /*rekey=*/true, /*integrity_only=*/true); + seal_unseal_small_buffer(fixture->client, fixture->server); + seal_unseal_small_buffer(fixture->server, fixture->client); + alts_zero_copy_grpc_protector_test_fixture_destroy(fixture); + + fixture = alts_zero_copy_grpc_protector_test_fixture_create( + /*rekey=*/true, /*integrity_only=*/false); + seal_unseal_small_buffer(fixture->client, fixture->server); + seal_unseal_small_buffer(fixture->server, fixture->client); + alts_zero_copy_grpc_protector_test_fixture_destroy(fixture); +} + +static void alts_zero_copy_protector_seal_unseal_large_buffer_tests() { + alts_zero_copy_grpc_protector_test_fixture* fixture = + alts_zero_copy_grpc_protector_test_fixture_create( + /*rekey=*/false, /*integrity_only=*/true); + seal_unseal_large_buffer(fixture->client, fixture->server); + seal_unseal_large_buffer(fixture->server, fixture->client); + alts_zero_copy_grpc_protector_test_fixture_destroy(fixture); + + fixture = alts_zero_copy_grpc_protector_test_fixture_create( + /*rekey=*/false, /*integrity_only=*/false); + seal_unseal_large_buffer(fixture->client, fixture->server); + seal_unseal_large_buffer(fixture->server, fixture->client); + alts_zero_copy_grpc_protector_test_fixture_destroy(fixture); + + fixture = alts_zero_copy_grpc_protector_test_fixture_create( + /*rekey=*/true, /*integrity_only=*/true); + seal_unseal_large_buffer(fixture->client, fixture->server); + seal_unseal_large_buffer(fixture->server, fixture->client); + alts_zero_copy_grpc_protector_test_fixture_destroy(fixture); + + fixture = alts_zero_copy_grpc_protector_test_fixture_create( + /*rekey=*/true, /*integrity_only=*/false); + seal_unseal_large_buffer(fixture->client, fixture->server); + seal_unseal_large_buffer(fixture->server, fixture->client); + alts_zero_copy_grpc_protector_test_fixture_destroy(fixture); +} + +int main(int argc, char** argv) { + alts_zero_copy_protector_seal_unseal_small_buffer_tests(); + alts_zero_copy_protector_seal_unseal_large_buffer_tests(); + return 0; +} diff --git a/test/core/tsi/fake_transport_security_test.cc b/test/core/tsi/fake_transport_security_test.cc index bec81ed42f..5e6671965d 100644 --- a/test/core/tsi/fake_transport_security_test.cc +++ b/test/core/tsi/fake_transport_security_test.cc @@ -107,7 +107,7 @@ void fake_tsi_test_do_round_trip_for_all_configs() { tsi_test_frame_protector_config_destroy(fake_fixture->base.config); fake_fixture->base.config = tsi_test_frame_protector_config_create( bit_array[0], bit_array[1], bit_array[2], bit_array[3], bit_array[4], - bit_array[5], bit_array[6], bit_array[7]); + bit_array[5], bit_array[6]); tsi_test_do_round_trip(&fake_fixture->base); tsi_test_fixture_destroy(fixture); } diff --git a/test/core/tsi/ssl_transport_security_test.cc b/test/core/tsi/ssl_transport_security_test.cc index 8f255a3d35..d9eb7470d5 100644 --- a/test/core/tsi/ssl_transport_security_test.cc +++ b/test/core/tsi/ssl_transport_security_test.cc @@ -528,7 +528,7 @@ void ssl_tsi_test_do_round_trip_for_all_configs() { tsi_test_frame_protector_config_destroy(ssl_fixture->base.config); ssl_fixture->base.config = tsi_test_frame_protector_config_create( bit_array[0], bit_array[1], bit_array[2], bit_array[3], bit_array[4], - bit_array[5], bit_array[6], bit_array[7]); + bit_array[5], bit_array[6]); tsi_test_do_round_trip(&ssl_fixture->base); tsi_test_fixture_destroy(fixture); } diff --git a/test/core/tsi/transport_security_test_lib.cc b/test/core/tsi/transport_security_test_lib.cc index 8ea83f7088..26349dbfca 100644 --- a/test/core/tsi/transport_security_test_lib.cc +++ b/test/core/tsi/transport_security_test_lib.cc @@ -110,27 +110,29 @@ static void check_handshake_results(tsi_test_fixture* fixture) { fixture->vtable->check_handshaker_peers(fixture); /* Check unused bytes. */ if (fixture->test_unused_bytes) { + tsi_test_channel* channel = fixture->channel; if (fixture->server_result != nullptr && fixture->client_result != nullptr) { check_unused_bytes(fixture); } - fixture->bytes_written_to_server_channel = 0; - fixture->bytes_written_to_client_channel = 0; - fixture->bytes_read_from_client_channel = 0; - fixture->bytes_read_from_server_channel = 0; + channel->bytes_written_to_server_channel = 0; + channel->bytes_written_to_client_channel = 0; + channel->bytes_read_from_client_channel = 0; + channel->bytes_read_from_server_channel = 0; } } -static void send_bytes_to_peer(tsi_test_fixture* fixture, +static void send_bytes_to_peer(tsi_test_channel* test_channel, const unsigned char* buf, size_t buf_size, bool is_client) { - GPR_ASSERT(fixture != nullptr); + GPR_ASSERT(test_channel != nullptr); GPR_ASSERT(buf != nullptr); uint8_t* channel = - is_client ? fixture->server_channel : fixture->client_channel; + is_client ? test_channel->server_channel : test_channel->client_channel; GPR_ASSERT(channel != nullptr); - size_t* bytes_written = is_client ? &fixture->bytes_written_to_server_channel - : &fixture->bytes_written_to_client_channel; + size_t* bytes_written = is_client + ? &test_channel->bytes_written_to_server_channel + : &test_channel->bytes_written_to_client_channel; GPR_ASSERT(bytes_written != nullptr); GPR_ASSERT(*bytes_written + buf_size <= TSI_TEST_DEFAULT_CHANNEL_SIZE); /* Write data to channel. */ @@ -145,7 +147,8 @@ static void maybe_append_unused_bytes(handshaker_args* args) { if (fixture->test_unused_bytes && !args->appended_unused_bytes) { args->appended_unused_bytes = true; send_bytes_to_peer( - fixture, reinterpret_cast(TSI_TEST_UNUSED_BYTES), + fixture->channel, + reinterpret_cast(TSI_TEST_UNUSED_BYTES), strlen(TSI_TEST_UNUSED_BYTES), args->is_client); if (fixture->client_result != nullptr && fixture->server_result == nullptr) { @@ -154,19 +157,21 @@ static void maybe_append_unused_bytes(handshaker_args* args) { } } -static void receive_bytes_from_peer(tsi_test_fixture* fixture, +static void receive_bytes_from_peer(tsi_test_channel* test_channel, unsigned char** buf, size_t* buf_size, bool is_client) { - GPR_ASSERT(fixture != nullptr); + GPR_ASSERT(test_channel != nullptr); GPR_ASSERT(*buf != nullptr); GPR_ASSERT(buf_size != nullptr); uint8_t* channel = - is_client ? fixture->client_channel : fixture->server_channel; + is_client ? test_channel->client_channel : test_channel->server_channel; GPR_ASSERT(channel != nullptr); - size_t* bytes_read = is_client ? &fixture->bytes_read_from_client_channel - : &fixture->bytes_read_from_server_channel; - size_t* bytes_written = is_client ? &fixture->bytes_written_to_client_channel - : &fixture->bytes_written_to_server_channel; + size_t* bytes_read = is_client + ? &test_channel->bytes_read_from_client_channel + : &test_channel->bytes_read_from_server_channel; + size_t* bytes_written = is_client + ? &test_channel->bytes_written_to_client_channel + : &test_channel->bytes_written_to_server_channel; GPR_ASSERT(bytes_read != nullptr); GPR_ASSERT(bytes_written != nullptr); size_t to_read = *buf_size < *bytes_written - *bytes_read @@ -178,14 +183,13 @@ static void receive_bytes_from_peer(tsi_test_fixture* fixture, *bytes_read += to_read; } -static void send_message_to_peer(tsi_test_fixture* fixture, - tsi_frame_protector* protector, - bool is_client) { +void tsi_test_frame_protector_send_message_to_peer( + tsi_test_frame_protector_config* config, tsi_test_channel* channel, + tsi_frame_protector* protector, bool is_client) { /* Initialization. */ - GPR_ASSERT(fixture != nullptr); - GPR_ASSERT(fixture->config != nullptr); + GPR_ASSERT(config != nullptr); + GPR_ASSERT(channel != nullptr); GPR_ASSERT(protector != nullptr); - tsi_test_frame_protector_config* config = fixture->config; unsigned char* protected_buffer = static_cast(gpr_zalloc(config->protected_buffer_size)); size_t message_size = @@ -205,7 +209,7 @@ static void send_message_to_peer(tsi_test_fixture* fixture, &protected_buffer_size_to_send); GPR_ASSERT(result == TSI_OK); /* Send protected data to peer. */ - send_bytes_to_peer(fixture, protected_buffer, protected_buffer_size_to_send, + send_bytes_to_peer(channel, protected_buffer, protected_buffer_size_to_send, is_client); message_bytes += processed_message_size; message_size -= processed_message_size; @@ -218,7 +222,7 @@ static void send_message_to_peer(tsi_test_fixture* fixture, protector, protected_buffer, &protected_buffer_size_to_send, &still_pending_size); GPR_ASSERT(result == TSI_OK); - send_bytes_to_peer(fixture, protected_buffer, + send_bytes_to_peer(channel, protected_buffer, protected_buffer_size_to_send, is_client); } while (still_pending_size > 0 && result == TSI_OK); GPR_ASSERT(result == TSI_OK); @@ -228,17 +232,16 @@ static void send_message_to_peer(tsi_test_fixture* fixture, gpr_free(protected_buffer); } -static void receive_message_from_peer(tsi_test_fixture* fixture, - tsi_frame_protector* protector, - unsigned char* message, - size_t* bytes_received, bool is_client) { +void tsi_test_frame_protector_receive_message_from_peer( + tsi_test_frame_protector_config* config, tsi_test_channel* channel, + tsi_frame_protector* protector, unsigned char* message, + size_t* bytes_received, bool is_client) { /* Initialization. */ - GPR_ASSERT(fixture != nullptr); + GPR_ASSERT(config != nullptr); + GPR_ASSERT(channel != nullptr); GPR_ASSERT(protector != nullptr); GPR_ASSERT(message != nullptr); GPR_ASSERT(bytes_received != nullptr); - GPR_ASSERT(fixture->config != nullptr); - tsi_test_frame_protector_config* config = fixture->config; size_t read_offset = 0; size_t message_offset = 0; size_t read_from_peer_size = 0; @@ -253,7 +256,7 @@ static void receive_message_from_peer(tsi_test_fixture* fixture, /* Receive data from peer. */ if (read_from_peer_size == 0) { read_from_peer_size = config->read_buffer_allocated_size; - receive_bytes_from_peer(fixture, &read_buffer, &read_from_peer_size, + receive_bytes_from_peer(channel, &read_buffer, &read_from_peer_size, is_client); read_offset = 0; } @@ -314,7 +317,7 @@ grpc_error* on_handshake_next_done(tsi_result result, void* user_data, } /* Send data to peer, if needed. */ if (bytes_to_send_size > 0) { - send_bytes_to_peer(args->fixture, bytes_to_send, bytes_to_send_size, + send_bytes_to_peer(fixture->channel, bytes_to_send, bytes_to_send_size, args->is_client); args->transferred_data = true; } @@ -361,8 +364,8 @@ static void do_handshaker_next(handshaker_args* args) { /* Receive data from peer, if available. */ do { size_t buf_size = args->handshake_buffer_size; - receive_bytes_from_peer(args->fixture, &args->handshake_buffer, &buf_size, - args->is_client); + receive_bytes_from_peer(fixture->channel, &args->handshake_buffer, + &buf_size, args->is_client); if (buf_size > 0) { args->transferred_data = true; } @@ -411,6 +414,50 @@ void tsi_test_do_handshake(tsi_test_fixture* fixture) { handshaker_args_destroy(server_args); } +static void tsi_test_do_ping_pong(tsi_test_frame_protector_config* config, + tsi_test_channel* channel, + tsi_frame_protector* client_frame_protector, + tsi_frame_protector* server_frame_protector) { + GPR_ASSERT(config != nullptr); + GPR_ASSERT(channel != nullptr); + GPR_ASSERT(client_frame_protector != nullptr); + GPR_ASSERT(server_frame_protector != nullptr); + /* Client sends a message to server. */ + tsi_test_frame_protector_send_message_to_peer( + config, channel, client_frame_protector, true /* is_client */); + unsigned char* server_received_message = + static_cast(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE)); + size_t server_received_message_size = 0; + tsi_test_frame_protector_receive_message_from_peer( + config, channel, server_frame_protector, server_received_message, + &server_received_message_size, false /* is_client */); + GPR_ASSERT(config->client_message_size == server_received_message_size); + GPR_ASSERT(memcmp(config->client_message, server_received_message, + server_received_message_size) == 0); + /* Server sends a message to client. */ + tsi_test_frame_protector_send_message_to_peer( + config, channel, server_frame_protector, false /* is_client */); + unsigned char* client_received_message = + static_cast(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE)); + size_t client_received_message_size = 0; + tsi_test_frame_protector_receive_message_from_peer( + config, channel, client_frame_protector, client_received_message, + &client_received_message_size, true /* is_client */); + GPR_ASSERT(config->server_message_size == client_received_message_size); + GPR_ASSERT(memcmp(config->server_message, client_received_message, + client_received_message_size) == 0); + gpr_free(server_received_message); + gpr_free(client_received_message); +} + +void tsi_test_frame_protector_do_round_trip_no_handshake( + tsi_test_frame_protector_fixture* fixture) { + GPR_ASSERT(fixture != nullptr); + tsi_test_do_ping_pong(fixture->config, fixture->channel, + fixture->client_frame_protector, + fixture->server_frame_protector); +} + void tsi_test_do_round_trip(tsi_test_fixture* fixture) { /* Initialization. */ GPR_ASSERT(fixture != nullptr); @@ -437,33 +484,11 @@ void tsi_test_do_round_trip(tsi_test_fixture* fixture) { ? nullptr : &server_max_output_protected_frame_size, &server_frame_protector) == TSI_OK); - /* Client sends a message to server. */ - send_message_to_peer(fixture, client_frame_protector, true /* is_client */); - unsigned char* server_received_message = - static_cast(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE)); - size_t server_received_message_size = 0; - receive_message_from_peer( - fixture, server_frame_protector, server_received_message, - &server_received_message_size, false /* is_client */); - GPR_ASSERT(config->client_message_size == server_received_message_size); - GPR_ASSERT(memcmp(config->client_message, server_received_message, - server_received_message_size) == 0); - /* Server sends a message to client. */ - send_message_to_peer(fixture, server_frame_protector, false /* is_client */); - unsigned char* client_received_message = - static_cast(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE)); - size_t client_received_message_size = 0; - receive_message_from_peer( - fixture, client_frame_protector, client_received_message, - &client_received_message_size, true /* is_client */); - GPR_ASSERT(config->server_message_size == client_received_message_size); - GPR_ASSERT(memcmp(config->server_message, client_received_message, - client_received_message_size) == 0); + tsi_test_do_ping_pong(config, fixture->channel, client_frame_protector, + server_frame_protector); /* Destroy server and client frame protectors. */ tsi_frame_protector_destroy(client_frame_protector); tsi_frame_protector_destroy(server_frame_protector); - gpr_free(server_received_message); - gpr_free(client_received_message); } static unsigned char* generate_random_message(size_t size) { @@ -483,8 +508,7 @@ tsi_test_frame_protector_config* tsi_test_frame_protector_config_create( bool use_default_protected_buffer_size, bool use_default_client_message, bool use_default_server_message, bool use_default_client_max_output_protected_frame_size, - bool use_default_server_max_output_protected_frame_size, - bool use_default_handshake_buffer_size) { + bool use_default_server_max_output_protected_frame_size) { tsi_test_frame_protector_config* config = static_cast( gpr_zalloc(sizeof(*config))); @@ -552,24 +576,42 @@ void tsi_test_frame_protector_config_set_buffer_size( void tsi_test_frame_protector_config_destroy( tsi_test_frame_protector_config* config) { - GPR_ASSERT(config != nullptr); + if (config == nullptr) { + return; + } gpr_free(config->client_message); gpr_free(config->server_message); gpr_free(config); } +static tsi_test_channel* tsi_test_channel_create() { + tsi_test_channel* channel = + static_cast(gpr_zalloc(sizeof(*channel))); + channel->client_channel = + static_cast(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE)); + channel->server_channel = + static_cast(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE)); + channel->bytes_written_to_client_channel = 0; + channel->bytes_written_to_server_channel = 0; + channel->bytes_read_from_client_channel = 0; + channel->bytes_read_from_server_channel = 0; + return channel; +} + +static void tsi_test_channel_destroy(tsi_test_channel* channel) { + if (channel == nullptr) { + return; + } + gpr_free(channel->client_channel); + gpr_free(channel->server_channel); + gpr_free(channel); +} + void tsi_test_fixture_init(tsi_test_fixture* fixture) { fixture->config = tsi_test_frame_protector_config_create( - true, true, true, true, true, true, true, true); + true, true, true, true, true, true, true); fixture->handshake_buffer_size = TSI_TEST_DEFAULT_BUFFER_SIZE; - fixture->client_channel = - static_cast(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE)); - fixture->server_channel = - static_cast(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE)); - fixture->bytes_written_to_client_channel = 0; - fixture->bytes_written_to_server_channel = 0; - fixture->bytes_read_from_client_channel = 0; - fixture->bytes_read_from_server_channel = 0; + fixture->channel = tsi_test_channel_create(); fixture->test_unused_bytes = true; fixture->has_client_finished_first = false; gpr_mu_init(&fixture->mu); @@ -578,14 +620,15 @@ void tsi_test_fixture_init(tsi_test_fixture* fixture) { } void tsi_test_fixture_destroy(tsi_test_fixture* fixture) { - GPR_ASSERT(fixture != nullptr); + if (fixture == nullptr) { + return; + } tsi_test_frame_protector_config_destroy(fixture->config); tsi_handshaker_destroy(fixture->client_handshaker); tsi_handshaker_destroy(fixture->server_handshaker); tsi_handshaker_result_destroy(fixture->client_result); tsi_handshaker_result_destroy(fixture->server_result); - gpr_free(fixture->client_channel); - gpr_free(fixture->server_channel); + tsi_test_channel_destroy(fixture->channel); GPR_ASSERT(fixture->vtable != nullptr); GPR_ASSERT(fixture->vtable->destruct != nullptr); fixture->vtable->destruct(fixture); @@ -593,3 +636,34 @@ void tsi_test_fixture_destroy(tsi_test_fixture* fixture) { gpr_cv_destroy(&fixture->cv); gpr_free(fixture); } + +tsi_test_frame_protector_fixture* tsi_test_frame_protector_fixture_create() { + tsi_test_frame_protector_fixture* fixture = + static_cast( + gpr_zalloc(sizeof(*fixture))); + fixture->config = tsi_test_frame_protector_config_create( + true, true, true, true, true, true, true); + fixture->channel = tsi_test_channel_create(); + return fixture; +} + +void tsi_test_frame_protector_fixture_init( + tsi_test_frame_protector_fixture* fixture, + tsi_frame_protector* client_frame_protector, + tsi_frame_protector* server_frame_protector) { + GPR_ASSERT(fixture != nullptr); + fixture->client_frame_protector = client_frame_protector; + fixture->server_frame_protector = server_frame_protector; +} + +void tsi_test_frame_protector_fixture_destroy( + tsi_test_frame_protector_fixture* fixture) { + if (fixture == nullptr) { + return; + } + tsi_test_frame_protector_config_destroy(fixture->config); + tsi_test_channel_destroy(fixture->channel); + tsi_frame_protector_destroy(fixture->client_frame_protector); + tsi_frame_protector_destroy(fixture->server_frame_protector); + gpr_free(fixture); +} diff --git a/test/core/tsi/transport_security_test_lib.h b/test/core/tsi/transport_security_test_lib.h index 9b07448cc5..b6a431f5a0 100644 --- a/test/core/tsi/transport_security_test_lib.h +++ b/test/core/tsi/transport_security_test_lib.h @@ -35,8 +35,8 @@ #define TSI_TEST_DEFAULT_CHANNEL_SIZE 32768 #define TSI_TEST_BIG_MESSAGE_SIZE 17000 #define TSI_TEST_SMALL_MESSAGE_SIZE 10 -#define TSI_TEST_NUM_OF_ARGUMENTS 8 -#define TSI_TEST_NUM_OF_COMBINATIONS 256 +#define TSI_TEST_NUM_OF_ARGUMENTS 7 +#define TSI_TEST_NUM_OF_COMBINATIONS 128 #define TSI_TEST_UNUSED_BYTES "HELLO GOOGLE" /* --- tsi_test_fixture object --- @@ -46,12 +46,22 @@ protect/unprotect operations with respect to TSI implementations. */ typedef struct tsi_test_fixture tsi_test_fixture; -/* --- tsi_test_frame_protector_config object --- +/* --- tsi_test_frame_protector_fixture object --- + The object wraps all necessary information used to test correctness of TSI + frame protector implementations. */ +typedef struct tsi_test_frame_protector_fixture + tsi_test_frame_protector_fixture; +/* --- tsi_test_frame_protector_config object --- This object is used to configure different parameters of TSI frame protector APIs. */ typedef struct tsi_test_frame_protector_config tsi_test_frame_protector_config; +/* --- tsi_test_channel object --- + This object represents simulated channels between the client and server + from/to which they could read/write the exchanged information. */ +typedef struct tsi_test_channel tsi_test_channel; + /* V-table for tsi_test_fixture operations that are implemented differently in different TSI implementations. */ typedef struct tsi_test_fixture_vtable { @@ -73,17 +83,8 @@ struct tsi_test_fixture { tsi_handshaker_result* server_result; /* size of buffer used to store data received from the peer. */ size_t handshake_buffer_size; - /* simulated channels between client and server. If the server (client) - wants to send data to the client (server), he will write data to - client_channel (server_channel), which will be read by client (server). */ - uint8_t* client_channel; - uint8_t* server_channel; - /* size of data written to the client/server channel. */ - size_t bytes_written_to_client_channel; - size_t bytes_written_to_server_channel; - /* size of data read from the client/server channel */ - size_t bytes_read_from_client_channel; - size_t bytes_read_from_server_channel; + /* tsi_test_channel instance. */ + tsi_test_channel* channel; /* tsi_test_frame_protector_config instance */ tsi_test_frame_protector_config* config; /* a flag indicating if client has finished TSI handshake first (i.e., before @@ -106,6 +107,30 @@ struct tsi_test_fixture { bool notified; }; +struct tsi_test_frame_protector_fixture { + /* client/server TSI frame protectors whose ownership are transferred. */ + tsi_frame_protector* client_frame_protector; + tsi_frame_protector* server_frame_protector; + /* tsi_test_channel instance. */ + tsi_test_channel* channel; + /* tsi_test_frame_protector_config instance */ + tsi_test_frame_protector_config* config; +}; + +struct tsi_test_channel { + /* simulated channels between client and server. If the server (client) + wants to send data to the client (server), he will write data to + client_channel (server_channel), which will be read by client (server). */ + uint8_t* client_channel; + uint8_t* server_channel; + /* size of data written to the client/server channel. */ + size_t bytes_written_to_client_channel; + size_t bytes_written_to_server_channel; + /* size of data read from the client/server channel */ + size_t bytes_read_from_client_channel; + size_t bytes_read_from_server_channel; +}; + struct tsi_test_frame_protector_config { /* size of buffer used to store protected frames to be unprotected. */ size_t read_buffer_allocated_size; @@ -135,8 +160,7 @@ tsi_test_frame_protector_config* tsi_test_frame_protector_config_create( bool use_default_protected_buffer_size, bool use_default_client_message, bool use_default_server_message, bool use_default_client_max_output_protected_frame_size, - bool use_default_server_max_output_protected_frame_size, - bool use_default_handshake_buffer_size); + bool use_default_server_max_output_protected_frame_size); /* This method sets different buffer and frame sizes of a tsi_test_frame_protector_config instance with user provided values. */ @@ -160,6 +184,35 @@ void tsi_test_fixture_init(tsi_test_fixture* fixture); this function. */ void tsi_test_fixture_destroy(tsi_test_fixture* fixture); +/* This method creates a tsi_test_frame_protector_fixture instance. */ +tsi_test_frame_protector_fixture* tsi_test_frame_protector_fixture_create(); + +/* This method initializes members of tsi_test_frame_protector_fixture instance. + Note that the struct instance should be allocated before making + this call. */ +void tsi_test_frame_protector_fixture_init( + tsi_test_frame_protector_fixture* fixture, + tsi_frame_protector* client_frame_protector, + tsi_frame_protector* server_frame_protector); + +/* This method destroys a tsi_test_frame_protector_fixture instance. Note that + the fixture intance must be dynamically allocated and will be freed by this + function. */ +void tsi_test_frame_protector_fixture_destroy( + tsi_test_frame_protector_fixture* fixture); + +/* This method performs a protect opeation on raw data and sends the result to + peer. */ +void tsi_test_frame_protector_send_message_to_peer( + tsi_test_frame_protector_config* config, tsi_test_channel* channel, + tsi_frame_protector* protector, bool is_client); + +/* This method receives message from peer and unprotects it. */ +void tsi_test_frame_protector_receive_message_from_peer( + tsi_test_frame_protector_config* config, tsi_test_channel* channel, + tsi_frame_protector* protector, unsigned char* message, + size_t* bytes_received, bool is_client); + /* This method performs a full TSI handshake between a client and a server. Note that the test library will implement the new TSI handshaker API to perform handshakes. */ @@ -171,4 +224,8 @@ void tsi_test_do_handshake(tsi_test_fixture* fixture); the client and server switching its role. */ void tsi_test_do_round_trip(tsi_test_fixture* fixture); +/* This method performs the above round trip test without doing handshakes. */ +void tsi_test_frame_protector_do_round_trip_no_handshake( + tsi_test_frame_protector_fixture* fixture); + #endif // GRPC_TEST_CORE_TSI_TRANSPORT_SECURITY_TEST_LIB_H_ diff --git a/third_party/nanopb/pb.h b/third_party/nanopb/pb.h index 4576f79abc..62dca73f4f 100644 --- a/third_party/nanopb/pb.h +++ b/third_party/nanopb/pb.h @@ -25,7 +25,7 @@ /* #define PB_FIELD_16BIT 1 */ /* Add support for tag numbers > 65536 and fields larger than 65536 bytes. */ -/* #define PB_FIELD_32BIT 1 */ +/* #define PB_FIELD_32BIT 1 */ /* Disable support for error messages in order to save some code space. */ /* #define PB_NO_ERRMSG 1 */ diff --git a/tools/codegen/core/gen_nano_proto.sh b/tools/codegen/core/gen_nano_proto.sh index 4246840173..6ce15178bd 100755 --- a/tools/codegen/core/gen_nano_proto.sh +++ b/tools/codegen/core/gen_nano_proto.sh @@ -43,9 +43,9 @@ if [[ ! -f "$INPUT_PROTO" ]]; then echo "Input proto file '$INPUT_PROTO' doesn't exist." exit 2 fi + if [[ ! -f "${EXPECTED_OPTIONS_FILE_PATH}" ]]; then - echo "Expected nanopb options file '${EXPECTED_OPTIONS_FILE_PATH}' missing" - exit 3 + echo "Input proto file may need .options file to be correctly compiled." fi if [[ "${OUTPUT_DIR:0:1}" != '/' ]]; then @@ -81,6 +81,11 @@ readonly PROTO_BASENAME=$(basename $INPUT_PROTO .proto) sed -i "s:$PROTO_BASENAME.pb.h:${GRPC_OUTPUT_DIR}/$PROTO_BASENAME.pb.h:g" \ "$OUTPUT_DIR/$PROTO_BASENAME.pb.c" +if [ $PROTO_BASENAME == "handshaker" ] || [ $PROTO_BASENAME == "altscontext" ]; then + sed -i "s:transport_security_common.pb.h:${GRPC_OUTPUT_DIR}/transport_security_common.pb.h:g" \ + "$OUTPUT_DIR/$PROTO_BASENAME.pb.h" +fi + # Fix up the include guards such that they pass the check_include_guards.py # test. Assumes that the generated files are being placed in gRPC src dir. readonly INCLUDE_GUARD_BASE=`echo $GRPC_OUTPUT_DIR | tr [a-z/] [A-Z_] | sed s:^.*SRC_::` diff --git a/tools/distrib/check_copyright.py b/tools/distrib/check_copyright.py index 6e1a303fb0..e7893a1fd5 100755 --- a/tools/distrib/check_copyright.py +++ b/tools/distrib/check_copyright.py @@ -77,6 +77,12 @@ _EXEMPT = frozenset(( 'examples/python/route_guide/route_guide_pb2_grpc.py', 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h', 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c', + 'src/core/tsi/alts/handshaker/altscontext.pb.h', + 'src/core/tsi/alts/handshaker/altscontext.pb.c', + 'src/core/tsi/alts/handshaker/handshaker.pb.h', + 'src/core/tsi/alts/handshaker/handshaker.pb.c', + 'src/core/tsi/alts/handshaker/transport_security_common.pb.h', + 'src/core/tsi/alts/handshaker/transport_security_common.pb.c', 'src/cpp/server/health/health.pb.h', 'src/cpp/server/health/health.pb.c', diff --git a/tools/distrib/check_include_guards.py b/tools/distrib/check_include_guards.py index 05d34c2b28..b356a74d2d 100755 --- a/tools/distrib/check_include_guards.py +++ b/tools/distrib/check_include_guards.py @@ -157,6 +157,9 @@ args = argp.parse_args() KNOWN_BAD = set([ 'src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h', + 'src/core/tsi/alts/handshaker/altscontext.pb.h', + 'src/core/tsi/alts/handshaker/handshaker.pb.h', + 'src/core/tsi/alts/handshaker/transport_security_common.pb.h', 'include/grpc++/ext/reflection.grpc.pb.h', 'include/grpc++/ext/reflection.pb.h', ]) diff --git a/tools/distrib/check_nanopb_output.sh b/tools/distrib/check_nanopb_output.sh index a30b73f689..8b5823b938 100755 --- a/tools/distrib/check_nanopb_output.sh +++ b/tools/distrib/check_nanopb_output.sh @@ -15,6 +15,7 @@ set -ex +readonly NANOPB_ALTS_TMP_OUTPUT="$(mktemp -d)" readonly NANOPB_TMP_OUTPUT="$(mktemp -d)" readonly PROTOBUF_INSTALL_PREFIX="$(mktemp -d)" @@ -55,3 +56,29 @@ if ! diff -r "$NANOPB_TMP_OUTPUT" src/core/ext/filters/client_channel/lb_policy/ echo "Outputs differ: $NANOPB_TMP_OUTPUT vs $LOAD_BALANCER_GRPC_OUTPUT_PATH" exit 2 fi + +# +# Checks for handshaker.proto and transport_security_common.proto +# +readonly HANDSHAKER_GRPC_OUTPUT_PATH='src/core/tsi/alts/handshaker' +# nanopb-compile the proto to a temp location +./tools/codegen/core/gen_nano_proto.sh \ + src/core/tsi/alts/handshaker/proto/handshaker.proto \ + "$NANOPB_ALTS_TMP_OUTPUT" \ + "$HANDSHAKER_GRPC_OUTPUT_PATH" +./tools/codegen/core/gen_nano_proto.sh \ + src/core/tsi/alts/handshaker/proto/transport_security_common.proto \ + "$NANOPB_ALTS_TMP_OUTPUT" \ + "$HANDSHAKER_GRPC_OUTPUT_PATH" +./tools/codegen/core/gen_nano_proto.sh \ + src/core/tsi/alts/handshaker/proto/altscontext.proto \ + "$NANOPB_ALTS_TMP_OUTPUT" \ + "$HANDSHAKER_GRPC_OUTPUT_PATH" + +# compare outputs to checked compiled code +for NANOPB_OUTPUT_FILE in $NANOPB_ALTS_TMP_OUTPUT/*.pb.*; do + if ! diff "$NANOPB_OUTPUT_FILE" "src/core/tsi/alts/handshaker/$(basename $NANOPB_OUTPUT_FILE)"; then + echo "Outputs differ: $NANOPB_ALTS_TMP_OUTPUT vs $HANDSHAKER_GRPC_OUTPUT_PATH" + exit 2 + fi +done diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 57f9147f44..e7e9e04979 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -1284,6 +1284,17 @@ src/core/lib/profiling/stap_timers.cc \ src/core/lib/profiling/timers.h \ src/core/lib/security/context/security_context.cc \ src/core/lib/security/context/security_context.h \ +src/core/lib/security/credentials/alts/alts_credentials.cc \ +src/core/lib/security/credentials/alts/alts_credentials.h \ +src/core/lib/security/credentials/alts/check_gcp_environment.cc \ +src/core/lib/security/credentials/alts/check_gcp_environment.h \ +src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc \ +src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc \ +src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc \ +src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc \ +src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc \ +src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h \ +src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc \ src/core/lib/security/credentials/composite/composite_credentials.cc \ src/core/lib/security/credentials/composite/composite_credentials.h \ src/core/lib/security/credentials/credentials.cc \ @@ -1308,6 +1319,8 @@ src/core/lib/security/credentials/plugin/plugin_credentials.cc \ src/core/lib/security/credentials/plugin/plugin_credentials.h \ src/core/lib/security/credentials/ssl/ssl_credentials.cc \ src/core/lib/security/credentials/ssl/ssl_credentials.h \ +src/core/lib/security/security_connector/alts_security_connector.cc \ +src/core/lib/security/security_connector/alts_security_connector.h \ src/core/lib/security/security_connector/security_connector.cc \ src/core/lib/security/security_connector/security_connector.h \ src/core/lib/security/transport/auth_filters.h \ @@ -1401,6 +1414,53 @@ src/core/lib/transport/transport_impl.h \ src/core/lib/transport/transport_op_string.cc \ src/core/plugin_registry/grpc_plugin_registry.cc \ src/core/tsi/README.md \ +src/core/tsi/alts/crypt/aes_gcm.cc \ +src/core/tsi/alts/crypt/gsec.cc \ +src/core/tsi/alts/crypt/gsec.h \ +src/core/tsi/alts/frame_protector/alts_counter.cc \ +src/core/tsi/alts/frame_protector/alts_counter.h \ +src/core/tsi/alts/frame_protector/alts_crypter.cc \ +src/core/tsi/alts/frame_protector/alts_crypter.h \ +src/core/tsi/alts/frame_protector/alts_frame_protector.cc \ +src/core/tsi/alts/frame_protector/alts_frame_protector.h \ +src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc \ +src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h \ +src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc \ +src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc \ +src/core/tsi/alts/frame_protector/frame_handler.cc \ +src/core/tsi/alts/frame_protector/frame_handler.h \ +src/core/tsi/alts/handshaker/alts_handshaker_client.cc \ +src/core/tsi/alts/handshaker/alts_handshaker_client.h \ +src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc \ +src/core/tsi/alts/handshaker/alts_handshaker_service_api.h \ +src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc \ +src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h \ +src/core/tsi/alts/handshaker/alts_tsi_event.cc \ +src/core/tsi/alts/handshaker/alts_tsi_event.h \ +src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc \ +src/core/tsi/alts/handshaker/alts_tsi_handshaker.h \ +src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h \ +src/core/tsi/alts/handshaker/alts_tsi_utils.cc \ +src/core/tsi/alts/handshaker/alts_tsi_utils.h \ +src/core/tsi/alts/handshaker/altscontext.pb.c \ +src/core/tsi/alts/handshaker/altscontext.pb.h \ +src/core/tsi/alts/handshaker/handshaker.pb.c \ +src/core/tsi/alts/handshaker/handshaker.pb.h \ +src/core/tsi/alts/handshaker/transport_security_common.pb.c \ +src/core/tsi/alts/handshaker/transport_security_common.pb.h \ +src/core/tsi/alts/handshaker/transport_security_common_api.cc \ +src/core/tsi/alts/handshaker/transport_security_common_api.h \ +src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc \ +src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h \ +src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc \ +src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h \ +src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h \ +src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc \ +src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h \ +src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc \ +src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h \ +src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc \ +src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h \ src/core/tsi/alts_transport_security.cc \ src/core/tsi/alts_transport_security.h \ src/core/tsi/fake_transport_security.cc \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index abccbd4466..f5a9eb828e 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -2415,6 +2415,215 @@ "third_party": false, "type": "target" }, + { + "deps": [ + "alts_test_util", + "gpr", + "grpc" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "alts_counter_test", + "src": [ + "test/core/tsi/alts/frame_protector/alts_counter_test.cc" + ], + "third_party": false, + "type": "target" + }, + { + "deps": [ + "alts_test_util", + "gpr", + "gpr_test_util", + "grpc" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "alts_crypt_test", + "src": [ + "test/core/tsi/alts/crypt/aes_gcm_test.cc" + ], + "third_party": false, + "type": "target" + }, + { + "deps": [ + "alts_test_util", + "gpr", + "grpc" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "alts_crypter_test", + "src": [ + "test/core/tsi/alts/frame_protector/alts_crypter_test.cc" + ], + "third_party": false, + "type": "target" + }, + { + "deps": [ + "alts_test_util", + "gpr", + "grpc" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "alts_frame_handler_test", + "src": [ + "test/core/tsi/alts/frame_protector/frame_handler_test.cc" + ], + "third_party": false, + "type": "target" + }, + { + "deps": [ + "alts_test_util", + "gpr", + "grpc", + "transport_security_test_lib" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "alts_frame_protector_test", + "src": [ + "test/core/tsi/alts/frame_protector/alts_frame_protector_test.cc" + ], + "third_party": false, + "type": "target" + }, + { + "deps": [ + "alts_test_util", + "gpr", + "grpc" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "alts_grpc_record_protocol_test", + "src": [ + "test/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_test.cc" + ], + "third_party": false, + "type": "target" + }, + { + "deps": [ + "alts_test_util", + "gpr", + "grpc" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "alts_handshaker_client_test", + "src": [ + "test/core/tsi/alts/handshaker/alts_handshaker_client_test.cc" + ], + "third_party": false, + "type": "target" + }, + { + "deps": [ + "alts_test_util", + "gpr", + "grpc" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "alts_handshaker_service_api_test", + "src": [ + "test/core/tsi/alts/handshaker/alts_handshaker_service_api_test.cc" + ], + "third_party": false, + "type": "target" + }, + { + "deps": [ + "alts_test_util", + "gpr", + "grpc" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "alts_iovec_record_protocol_test", + "src": [ + "test/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol_test.cc" + ], + "third_party": false, + "type": "target" + }, + { + "deps": [ + "gpr", + "grpc" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "alts_security_connector_test", + "src": [ + "test/core/security/alts_security_connector_test.cc" + ], + "third_party": false, + "type": "target" + }, + { + "deps": [ + "alts_test_util", + "gpr", + "grpc" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "alts_tsi_handshaker_test", + "src": [ + "test/core/tsi/alts/handshaker/alts_tsi_handshaker_test.cc" + ], + "third_party": false, + "type": "target" + }, + { + "deps": [ + "alts_test_util", + "gpr", + "grpc" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "alts_tsi_utils_test", + "src": [ + "test/core/tsi/alts/handshaker/alts_tsi_utils_test.cc" + ], + "third_party": false, + "type": "target" + }, + { + "deps": [ + "alts_test_util", + "gpr", + "grpc" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "alts_zero_copy_grpc_protector_test", + "src": [ + "test/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector_test.cc" + ], + "third_party": false, + "type": "target" + }, { "deps": [ "gpr", @@ -2825,6 +3034,36 @@ "third_party": false, "type": "target" }, + { + "deps": [ + "gpr", + "grpc" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "check_gcp_environment_linux_test", + "src": [ + "test/core/security/check_gcp_environment_linux_test.cc" + ], + "third_party": false, + "type": "target" + }, + { + "deps": [ + "gpr", + "grpc" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "check_gcp_environment_windows_test", + "src": [ + "test/core/security/check_gcp_environment_windows_test.cc" + ], + "third_party": false, + "type": "target" + }, { "deps": [ "gpr", @@ -3210,6 +3449,21 @@ "third_party": false, "type": "target" }, + { + "deps": [ + "gpr", + "grpc" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "grpc_alts_credentials_options_test", + "src": [ + "test/core/security/grpc_alts_credentials_options_test.cc" + ], + "third_party": false, + "type": "target" + }, { "deps": [ "gpr", @@ -4371,6 +4625,22 @@ "third_party": false, "type": "target" }, + { + "deps": [ + "alts_test_util", + "gpr", + "grpc" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "transport_security_common_api_test", + "src": [ + "test/core/tsi/alts/handshaker/transport_security_common_api_test.cc" + ], + "third_party": false, + "type": "target" + }, { "deps": [ "gpr", @@ -6303,6 +6573,26 @@ "third_party": false, "type": "target" }, + { + "deps": [ + "grpc" + ], + "headers": [ + "test/core/tsi/alts/crypt/gsec_test_util.h", + "test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h" + ], + "is_filegroup": false, + "language": "c", + "name": "alts_test_util", + "src": [ + "test/core/tsi/alts/crypt/gsec_test_util.cc", + "test/core/tsi/alts/crypt/gsec_test_util.h", + "test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc", + "test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.h" + ], + "third_party": false, + "type": "lib" + }, { "deps": [ "gpr_base" @@ -8314,6 +8604,138 @@ "third_party": false, "type": "lib" }, + { + "deps": [ + "nanopb" + ], + "headers": [ + "src/core/tsi/alts/handshaker/altscontext.pb.h", + "src/core/tsi/alts/handshaker/handshaker.pb.h", + "src/core/tsi/alts/handshaker/transport_security_common.pb.h" + ], + "is_filegroup": true, + "language": "c", + "name": "alts_proto", + "src": [ + "src/core/tsi/alts/handshaker/altscontext.pb.c", + "src/core/tsi/alts/handshaker/altscontext.pb.h", + "src/core/tsi/alts/handshaker/handshaker.pb.c", + "src/core/tsi/alts/handshaker/handshaker.pb.h", + "src/core/tsi/alts/handshaker/transport_security_common.pb.c", + "src/core/tsi/alts/handshaker/transport_security_common.pb.h" + ], + "third_party": false, + "type": "filegroup" + }, + { + "deps": [ + "alts_util", + "gpr", + "grpc_base", + "grpc_transport_chttp2_client_insecure", + "tsi", + "tsi_interface" + ], + "headers": [ + "src/core/tsi/alts/crypt/gsec.h", + "src/core/tsi/alts/frame_protector/alts_counter.h", + "src/core/tsi/alts/frame_protector/alts_crypter.h", + "src/core/tsi/alts/frame_protector/alts_frame_protector.h", + "src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h", + "src/core/tsi/alts/frame_protector/frame_handler.h", + "src/core/tsi/alts/handshaker/alts_handshaker_client.h", + "src/core/tsi/alts/handshaker/alts_tsi_event.h", + "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h", + "src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h", + "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h", + "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h", + "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h", + "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h", + "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h", + "src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h" + ], + "is_filegroup": true, + "language": "c", + "name": "alts_tsi", + "src": [ + "src/core/tsi/alts/crypt/aes_gcm.cc", + "src/core/tsi/alts/crypt/gsec.cc", + "src/core/tsi/alts/crypt/gsec.h", + "src/core/tsi/alts/frame_protector/alts_counter.cc", + "src/core/tsi/alts/frame_protector/alts_counter.h", + "src/core/tsi/alts/frame_protector/alts_crypter.cc", + "src/core/tsi/alts/frame_protector/alts_crypter.h", + "src/core/tsi/alts/frame_protector/alts_frame_protector.cc", + "src/core/tsi/alts/frame_protector/alts_frame_protector.h", + "src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc", + "src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h", + "src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc", + "src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc", + "src/core/tsi/alts/frame_protector/frame_handler.cc", + "src/core/tsi/alts/frame_protector/frame_handler.h", + "src/core/tsi/alts/handshaker/alts_handshaker_client.cc", + "src/core/tsi/alts/handshaker/alts_handshaker_client.h", + "src/core/tsi/alts/handshaker/alts_tsi_event.cc", + "src/core/tsi/alts/handshaker/alts_tsi_event.h", + "src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc", + "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h", + "src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h", + "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc", + "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h", + "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc", + "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h", + "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h", + "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc", + "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h", + "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc", + "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h", + "src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc", + "src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h" + ], + "third_party": false, + "type": "filegroup" + }, + { + "deps": [ + "alts_proto", + "gpr", + "grpc_base", + "nanopb", + "tsi_interface" + ], + "headers": [ + "src/core/lib/security/credentials/alts/check_gcp_environment.h", + "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h", + "src/core/tsi/alts/handshaker/alts_handshaker_service_api.h", + "src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h", + "src/core/tsi/alts/handshaker/alts_tsi_utils.h", + "src/core/tsi/alts/handshaker/transport_security_common_api.h" + ], + "is_filegroup": true, + "language": "c", + "name": "alts_util", + "src": [ + "src/core/lib/security/credentials/alts/check_gcp_environment.cc", + "src/core/lib/security/credentials/alts/check_gcp_environment.h", + "src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc", + "src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc", + "src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc", + "src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc", + "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc", + "src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h", + "src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc", + "src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc", + "src/core/tsi/alts/handshaker/alts_handshaker_service_api.h", + "src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc", + "src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h", + "src/core/tsi/alts/handshaker/alts_tsi_utils.cc", + "src/core/tsi/alts/handshaker/alts_tsi_utils.h", + "src/core/tsi/alts/handshaker/transport_security_common_api.cc", + "src/core/tsi/alts/handshaker/transport_security_common_api.h" + ], + "third_party": false, + "type": "filegroup" + }, { "deps": [ "gpr", @@ -9398,6 +9820,7 @@ }, { "deps": [ + "alts_tsi", "gpr", "grpc_base", "grpc_transport_chttp2_alpn", @@ -9406,6 +9829,7 @@ "headers": [ "include/grpc/grpc_security.h", "src/core/lib/security/context/security_context.h", + "src/core/lib/security/credentials/alts/alts_credentials.h", "src/core/lib/security/credentials/composite/composite_credentials.h", "src/core/lib/security/credentials/credentials.h", "src/core/lib/security/credentials/fake/fake_credentials.h", @@ -9417,6 +9841,7 @@ "src/core/lib/security/credentials/oauth2/oauth2_credentials.h", "src/core/lib/security/credentials/plugin/plugin_credentials.h", "src/core/lib/security/credentials/ssl/ssl_credentials.h", + "src/core/lib/security/security_connector/alts_security_connector.h", "src/core/lib/security/security_connector/security_connector.h", "src/core/lib/security/transport/auth_filters.h", "src/core/lib/security/transport/secure_endpoint.h", @@ -9433,6 +9858,8 @@ "src/core/lib/http/httpcli_security_connector.cc", "src/core/lib/security/context/security_context.cc", "src/core/lib/security/context/security_context.h", + "src/core/lib/security/credentials/alts/alts_credentials.cc", + "src/core/lib/security/credentials/alts/alts_credentials.h", "src/core/lib/security/credentials/composite/composite_credentials.cc", "src/core/lib/security/credentials/composite/composite_credentials.h", "src/core/lib/security/credentials/credentials.cc", @@ -9457,6 +9884,8 @@ "src/core/lib/security/credentials/plugin/plugin_credentials.h", "src/core/lib/security/credentials/ssl/ssl_credentials.cc", "src/core/lib/security/credentials/ssl/ssl_credentials.h", + "src/core/lib/security/security_connector/alts_security_connector.cc", + "src/core/lib/security/security_connector/alts_security_connector.h", "src/core/lib/security/security_connector/security_connector.cc", "src/core/lib/security/security_connector/security_connector.h", "src/core/lib/security/transport/auth_filters.h", diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index d35f396994..1406c4ac7e 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -2863,6 +2863,318 @@ ], "uses_polling": true }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": false, + "language": "c++", + "name": "alts_counter_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": false, + "language": "c++", + "name": "alts_crypt_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": false, + "language": "c++", + "name": "alts_crypter_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": false, + "language": "c++", + "name": "alts_frame_handler_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": false, + "language": "c++", + "name": "alts_frame_protector_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": false, + "language": "c++", + "name": "alts_grpc_record_protocol_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": false, + "language": "c++", + "name": "alts_handshaker_client_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": false, + "language": "c++", + "name": "alts_handshaker_service_api_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": false, + "language": "c++", + "name": "alts_iovec_record_protocol_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": false, + "language": "c++", + "name": "alts_security_connector_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": false, + "language": "c++", + "name": "alts_tsi_handshaker_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": false, + "language": "c++", + "name": "alts_tsi_utils_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": false, + "language": "c++", + "name": "alts_zero_copy_grpc_protector_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, { "args": [], "benchmark": false, @@ -3337,6 +3649,54 @@ ], "uses_polling": false }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": false, + "language": "c++", + "name": "check_gcp_environment_linux_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": false, + "language": "c++", + "name": "check_gcp_environment_windows_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, { "args": [], "benchmark": false, @@ -3769,6 +4129,30 @@ ], "uses_polling": false }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": false, + "language": "c++", + "name": "grpc_alts_credentials_options_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, { "args": [], "benchmark": false, @@ -4672,6 +5056,30 @@ ], "uses_polling": true }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": false, + "language": "c++", + "name": "transport_security_common_api_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, { "args": [], "benchmark": false, -- cgit v1.2.3 From c7c0d69d8b411f1c5102bfd186aa2f6992c2e59c Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Sat, 10 Mar 2018 17:27:15 -0800 Subject: Secure channels: use the right authority --- BUILD | 18 +-- CMakeLists.txt | 34 +---- Makefile | 42 +------ build.yaml | 13 +- config.m4 | 1 + config.w32 | 1 + gRPC-C++.podspec | 2 + gRPC-Core.podspec | 3 + grpc.gemspec | 2 + grpc.gyp | 4 + package.xml | 2 + .../client_channel/client_channel_plugin.cc | 4 +- .../client_channel/lb_policy/grpclb/grpclb.cc | 11 +- .../chttp2/client/insecure/channel_create.cc | 36 +++++- .../chttp2/client/secure/secure_channel_create.cc | 25 +++- src/core/lib/channel/client_authority_filter.cc | 117 ++++++++++++++++++ src/core/lib/channel/client_authority_filter.h | 34 +++++ .../security/credentials/ssl/ssl_credentials.cc | 2 +- .../security_connector/security_connector.cc | 10 +- src/core/lib/surface/channel.cc | 80 ++++++------ src/core/lib/surface/init.cc | 8 ++ src/python/grpcio/grpc_core_dependencies.py | 1 + test/core/channel/minimal_stack_is_minimal_test.cc | 26 ++-- test/core/end2end/tests/default_host.cc | 9 +- test/core/surface/BUILD | 12 -- test/core/surface/invalid_channel_args_test.cc | 137 --------------------- tools/doxygen/Doxyfile.c++.internal | 1 + tools/doxygen/Doxyfile.core.internal | 2 + tools/run_tests/generated/sources_and_headers.json | 20 +-- tools/run_tests/generated/tests.json | 24 ---- 30 files changed, 331 insertions(+), 350 deletions(-) create mode 100644 src/core/lib/channel/client_authority_filter.cc create mode 100644 src/core/lib/channel/client_authority_filter.h delete mode 100644 test/core/surface/invalid_channel_args_test.cc (limited to 'gRPC-C++.podspec') diff --git a/BUILD b/BUILD index 9c99f95fcd..49f45f8218 100644 --- a/BUILD +++ b/BUILD @@ -676,6 +676,7 @@ grpc_cc_library( "src/core/lib/channel/channel_args.cc", "src/core/lib/channel/channel_stack.cc", "src/core/lib/channel/channel_stack_builder.cc", + "src/core/lib/channel/client_authority_filter.cc", "src/core/lib/channel/connected_channel.cc", "src/core/lib/channel/handshaker.cc", "src/core/lib/channel/handshaker_factory.cc", @@ -811,6 +812,7 @@ grpc_cc_library( "src/core/lib/channel/channel_args.h", "src/core/lib/channel/channel_stack.h", "src/core/lib/channel/channel_stack_builder.h", + "src/core/lib/channel/client_authority_filter.h", "src/core/lib/channel/connected_channel.h", "src/core/lib/channel/context.h", "src/core/lib/channel/handshaker.h", @@ -1313,6 +1315,7 @@ grpc_cc_library( srcs = [ "src/core/lib/http/httpcli_security_connector.cc", "src/core/lib/security/context/security_context.cc", + "src/core/lib/security/credentials/alts/alts_credentials.cc", "src/core/lib/security/credentials/composite/composite_credentials.cc", "src/core/lib/security/credentials/credentials.cc", "src/core/lib/security/credentials/credentials_metadata.cc", @@ -1326,7 +1329,6 @@ grpc_cc_library( "src/core/lib/security/credentials/oauth2/oauth2_credentials.cc", "src/core/lib/security/credentials/plugin/plugin_credentials.cc", "src/core/lib/security/credentials/ssl/ssl_credentials.cc", - "src/core/lib/security/credentials/alts/alts_credentials.cc", "src/core/lib/security/security_connector/alts_security_connector.cc", "src/core/lib/security/security_connector/security_connector.cc", "src/core/lib/security/transport/client_auth_filter.cc", @@ -1340,6 +1342,7 @@ grpc_cc_library( ], hdrs = [ "src/core/lib/security/context/security_context.h", + "src/core/lib/security/credentials/alts/alts_credentials.h", "src/core/lib/security/credentials/composite/composite_credentials.h", "src/core/lib/security/credentials/credentials.h", "src/core/lib/security/credentials/fake/fake_credentials.h", @@ -1351,7 +1354,6 @@ grpc_cc_library( "src/core/lib/security/credentials/oauth2/oauth2_credentials.h", "src/core/lib/security/credentials/plugin/plugin_credentials.h", "src/core/lib/security/credentials/ssl/ssl_credentials.h", - "src/core/lib/security/credentials/alts/alts_credentials.h", "src/core/lib/security/security_connector/alts_security_connector.h", "src/core/lib/security/security_connector/security_connector.h", "src/core/lib/security/transport/auth_filters.h", @@ -1614,8 +1616,8 @@ grpc_cc_library( "src/core/tsi/alts/frame_protector/frame_handler.h", "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h", "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h", - "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h", "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h", + "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h", "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h", "src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h", "src/core/tsi/transport_security_grpc.h", @@ -1675,31 +1677,31 @@ grpc_cc_library( ], language = "c++", deps = [ - "alts_proto", - "gpr", - "grpc_base", + "alts_proto", + "gpr", + "grpc_base", ], ) grpc_cc_library( name = "tsi", srcs = [ - "src/core/tsi/alts_transport_security.cc", "src/core/tsi/alts/handshaker/alts_handshaker_client.cc", "src/core/tsi/alts/handshaker/alts_tsi_event.cc", "src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc", "src/core/tsi/alts/handshaker/alts_tsi_utils.cc", + "src/core/tsi/alts_transport_security.cc", "src/core/tsi/fake_transport_security.cc", "src/core/tsi/ssl_transport_security.cc", "src/core/tsi/transport_security_grpc.cc", ], hdrs = [ - "src/core/tsi/alts_transport_security.h", "src/core/tsi/alts/handshaker/alts_handshaker_client.h", "src/core/tsi/alts/handshaker/alts_tsi_event.h", "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h", "src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h", "src/core/tsi/alts/handshaker/alts_tsi_utils.h", + "src/core/tsi/alts_transport_security.h", "src/core/tsi/fake_transport_security.h", "src/core/tsi/ssl_transport_security.h", "src/core/tsi/ssl_types.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index 5dfbdcb85a..d3e84c7751 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -289,7 +289,6 @@ add_dependencies(buildtests_c grpc_completion_queue_test) add_dependencies(buildtests_c grpc_completion_queue_threading_test) add_dependencies(buildtests_c grpc_credentials_test) add_dependencies(buildtests_c grpc_fetch_oauth2) -add_dependencies(buildtests_c grpc_invalid_channel_args_test) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) add_dependencies(buildtests_c grpc_json_token_test) endif() @@ -856,6 +855,7 @@ add_library(grpc src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc + src/core/lib/channel/client_authority_filter.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc @@ -1231,6 +1231,7 @@ add_library(grpc_cronet src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc + src/core/lib/channel/client_authority_filter.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc @@ -1597,6 +1598,7 @@ add_library(grpc_test_util src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc + src/core/lib/channel/client_authority_filter.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc @@ -1886,6 +1888,7 @@ add_library(grpc_test_util_unsecure src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc + src/core/lib/channel/client_authority_filter.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc @@ -2155,6 +2158,7 @@ add_library(grpc_unsecure src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc + src/core/lib/channel/client_authority_filter.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc @@ -2958,6 +2962,7 @@ add_library(grpc++_cronet src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc + src/core/lib/channel/client_authority_filter.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc @@ -6811,33 +6816,6 @@ target_link_libraries(grpc_fetch_oauth2 gpr ) -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) - -add_executable(grpc_invalid_channel_args_test - test/core/surface/invalid_channel_args_test.cc -) - - -target_include_directories(grpc_invalid_channel_args_test - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${_gRPC_SSL_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} - PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} - PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} - PRIVATE ${_gRPC_CARES_INCLUDE_DIR} - PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} -) - -target_link_libraries(grpc_invalid_channel_args_test - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_test_util - grpc - gpr_test_util - gpr -) - endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) diff --git a/Makefile b/Makefile index a298fafd6b..02e1215459 100644 --- a/Makefile +++ b/Makefile @@ -1013,7 +1013,6 @@ grpc_completion_queue_threading_test: $(BINDIR)/$(CONFIG)/grpc_completion_queue_ grpc_create_jwt: $(BINDIR)/$(CONFIG)/grpc_create_jwt grpc_credentials_test: $(BINDIR)/$(CONFIG)/grpc_credentials_test grpc_fetch_oauth2: $(BINDIR)/$(CONFIG)/grpc_fetch_oauth2 -grpc_invalid_channel_args_test: $(BINDIR)/$(CONFIG)/grpc_invalid_channel_args_test grpc_json_token_test: $(BINDIR)/$(CONFIG)/grpc_json_token_test grpc_jwt_verifier_test: $(BINDIR)/$(CONFIG)/grpc_jwt_verifier_test grpc_print_google_default_creds_token: $(BINDIR)/$(CONFIG)/grpc_print_google_default_creds_token @@ -1448,7 +1447,6 @@ buildtests_c: privatelibs_c \ $(BINDIR)/$(CONFIG)/grpc_completion_queue_threading_test \ $(BINDIR)/$(CONFIG)/grpc_credentials_test \ $(BINDIR)/$(CONFIG)/grpc_fetch_oauth2 \ - $(BINDIR)/$(CONFIG)/grpc_invalid_channel_args_test \ $(BINDIR)/$(CONFIG)/grpc_json_token_test \ $(BINDIR)/$(CONFIG)/grpc_jwt_verifier_test \ $(BINDIR)/$(CONFIG)/grpc_security_connector_test \ @@ -1977,8 +1975,6 @@ test_c: buildtests_c $(Q) $(BINDIR)/$(CONFIG)/grpc_completion_queue_threading_test || ( echo test grpc_completion_queue_threading_test failed ; exit 1 ) $(E) "[RUN] Testing grpc_credentials_test" $(Q) $(BINDIR)/$(CONFIG)/grpc_credentials_test || ( echo test grpc_credentials_test failed ; exit 1 ) - $(E) "[RUN] Testing grpc_invalid_channel_args_test" - $(Q) $(BINDIR)/$(CONFIG)/grpc_invalid_channel_args_test || ( echo test grpc_invalid_channel_args_test failed ; exit 1 ) $(E) "[RUN] Testing grpc_json_token_test" $(Q) $(BINDIR)/$(CONFIG)/grpc_json_token_test || ( echo test grpc_json_token_test failed ; exit 1 ) $(E) "[RUN] Testing grpc_jwt_verifier_test" @@ -3164,6 +3160,7 @@ LIBGRPC_SRC = \ src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ + src/core/lib/channel/client_authority_filter.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ @@ -3541,6 +3538,7 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ + src/core/lib/channel/client_authority_filter.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ @@ -3908,6 +3906,7 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ + src/core/lib/channel/client_authority_filter.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ @@ -4190,6 +4189,7 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ + src/core/lib/channel/client_authority_filter.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ @@ -4439,6 +4439,7 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ + src/core/lib/channel/client_authority_filter.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ @@ -5241,6 +5242,7 @@ LIBGRPC++_CRONET_SRC = \ src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ + src/core/lib/channel/client_authority_filter.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ @@ -11798,38 +11800,6 @@ endif endif -GRPC_INVALID_CHANNEL_ARGS_TEST_SRC = \ - test/core/surface/invalid_channel_args_test.cc \ - -GRPC_INVALID_CHANNEL_ARGS_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(GRPC_INVALID_CHANNEL_ARGS_TEST_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/grpc_invalid_channel_args_test: openssl_dep_error - -else - - - -$(BINDIR)/$(CONFIG)/grpc_invalid_channel_args_test: $(GRPC_INVALID_CHANNEL_ARGS_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LD) $(LDFLAGS) $(GRPC_INVALID_CHANNEL_ARGS_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/grpc_invalid_channel_args_test - -endif - -$(OBJDIR)/$(CONFIG)/test/core/surface/invalid_channel_args_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_grpc_invalid_channel_args_test: $(GRPC_INVALID_CHANNEL_ARGS_TEST_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(GRPC_INVALID_CHANNEL_ARGS_TEST_OBJS:.o=.dep) -endif -endif - - GRPC_JSON_TOKEN_TEST_SRC = \ test/core/security/json_token_test.cc \ diff --git a/build.yaml b/build.yaml index e2bb8bfa9f..eab2897706 100644 --- a/build.yaml +++ b/build.yaml @@ -232,6 +232,7 @@ filegroups: - src/core/lib/channel/channel_args.cc - src/core/lib/channel/channel_stack.cc - src/core/lib/channel/channel_stack_builder.cc + - src/core/lib/channel/client_authority_filter.cc - src/core/lib/channel/connected_channel.cc - src/core/lib/channel/handshaker.cc - src/core/lib/channel/handshaker_factory.cc @@ -388,6 +389,7 @@ filegroups: - src/core/lib/channel/channel_args.h - src/core/lib/channel/channel_stack.h - src/core/lib/channel/channel_stack_builder.h + - src/core/lib/channel/client_authority_filter.h - src/core/lib/channel/connected_channel.h - src/core/lib/channel/context.h - src/core/lib/channel/handshaker.h @@ -2576,17 +2578,6 @@ targets: - grpc - gpr_test_util - gpr -- name: grpc_invalid_channel_args_test - build: test - language: c - src: - - test/core/surface/invalid_channel_args_test.cc - deps: - - grpc_test_util - - grpc - - gpr_test_util - - gpr - uses_polling: false - name: grpc_json_token_test build: test language: c diff --git a/config.m4 b/config.m4 index 7270051b0b..3b061e565e 100644 --- a/config.m4 +++ b/config.m4 @@ -84,6 +84,7 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ + src/core/lib/channel/client_authority_filter.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ diff --git a/config.w32 b/config.w32 index d73acc1118..1b89419c57 100644 --- a/config.w32 +++ b/config.w32 @@ -61,6 +61,7 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\channel\\channel_args.cc " + "src\\core\\lib\\channel\\channel_stack.cc " + "src\\core\\lib\\channel\\channel_stack_builder.cc " + + "src\\core\\lib\\channel\\client_authority_filter.cc " + "src\\core\\lib\\channel\\connected_channel.cc " + "src\\core\\lib\\channel\\handshaker.cc " + "src\\core\\lib\\channel\\handshaker_factory.cc " + diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 65a5dc66b4..6334ac433d 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -343,6 +343,7 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.h', 'src/core/lib/channel/channel_stack.h', 'src/core/lib/channel/channel_stack_builder.h', + 'src/core/lib/channel/client_authority_filter.h', 'src/core/lib/channel/connected_channel.h', 'src/core/lib/channel/context.h', 'src/core/lib/channel/handshaker.h', @@ -522,6 +523,7 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.h', 'src/core/lib/channel/channel_stack.h', 'src/core/lib/channel/channel_stack_builder.h', + 'src/core/lib/channel/client_authority_filter.h', 'src/core/lib/channel/connected_channel.h', 'src/core/lib/channel/context.h', 'src/core/lib/channel/handshaker.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 7f61719cb1..5827b397ff 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -354,6 +354,7 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.h', 'src/core/lib/channel/channel_stack.h', 'src/core/lib/channel/channel_stack_builder.h', + 'src/core/lib/channel/client_authority_filter.h', 'src/core/lib/channel/connected_channel.h', 'src/core/lib/channel/context.h', 'src/core/lib/channel/handshaker.h', @@ -498,6 +499,7 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', + 'src/core/lib/channel/client_authority_filter.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', @@ -908,6 +910,7 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.h', 'src/core/lib/channel/channel_stack.h', 'src/core/lib/channel/channel_stack_builder.h', + 'src/core/lib/channel/client_authority_filter.h', 'src/core/lib/channel/connected_channel.h', 'src/core/lib/channel/context.h', 'src/core/lib/channel/handshaker.h', diff --git a/grpc.gemspec b/grpc.gemspec index 89a3812376..06520c1f95 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -284,6 +284,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/channel/channel_args.h ) s.files += %w( src/core/lib/channel/channel_stack.h ) s.files += %w( src/core/lib/channel/channel_stack_builder.h ) + s.files += %w( src/core/lib/channel/client_authority_filter.h ) s.files += %w( src/core/lib/channel/connected_channel.h ) s.files += %w( src/core/lib/channel/context.h ) s.files += %w( src/core/lib/channel/handshaker.h ) @@ -428,6 +429,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/channel/channel_args.cc ) s.files += %w( src/core/lib/channel/channel_stack.cc ) s.files += %w( src/core/lib/channel/channel_stack_builder.cc ) + s.files += %w( src/core/lib/channel/client_authority_filter.cc ) s.files += %w( src/core/lib/channel/connected_channel.cc ) s.files += %w( src/core/lib/channel/handshaker.cc ) s.files += %w( src/core/lib/channel/handshaker_factory.cc ) diff --git a/grpc.gyp b/grpc.gyp index 0b60efe978..a398e4f460 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -236,6 +236,7 @@ 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', + 'src/core/lib/channel/client_authority_filter.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', @@ -568,6 +569,7 @@ 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', + 'src/core/lib/channel/client_authority_filter.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', @@ -785,6 +787,7 @@ 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', + 'src/core/lib/channel/client_authority_filter.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', @@ -981,6 +984,7 @@ 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', + 'src/core/lib/channel/client_authority_filter.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', diff --git a/package.xml b/package.xml index fc7ba68e8b..0abcb89738 100644 --- a/package.xml +++ b/package.xml @@ -291,6 +291,7 @@ + @@ -435,6 +436,7 @@ + diff --git a/src/core/ext/filters/client_channel/client_channel_plugin.cc b/src/core/ext/filters/client_channel/client_channel_plugin.cc index 3c3a97532f..ed3ebd2696 100644 --- a/src/core/ext/filters/client_channel/client_channel_plugin.cc +++ b/src/core/ext/filters/client_channel/client_channel_plugin.cc @@ -39,6 +39,8 @@ static bool append_filter(grpc_channel_stack_builder* builder, void* arg) { builder, static_cast(arg), nullptr, nullptr); } +// Only used for direct channels, as they don't create subchannels, which is +// where default authority is handled for regular channels. static bool set_default_host_if_unset(grpc_channel_stack_builder* builder, void* unused) { const grpc_channel_args* args = @@ -69,7 +71,7 @@ void grpc_client_channel_init(void) { grpc_proxy_mapper_registry_init(); grpc_register_http_proxy_mapper(); grpc_subchannel_index_init(); - grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL, INT_MIN, + grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MIN, set_default_host_if_unset, nullptr); grpc_channel_init_register_stage( GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, append_filter, diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc index cb39e4224e..49918e11b7 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc @@ -504,9 +504,7 @@ GrpcLb::BalancerCallState::BalancerCallState( // the polling entities from client_channel. GPR_ASSERT(grpclb_policy()->server_name_ != nullptr); GPR_ASSERT(grpclb_policy()->server_name_[0] != '\0'); - grpc_slice host = - grpc_slice_from_copied_string(grpclb_policy()->server_name_); - grpc_millis deadline = + const grpc_millis deadline = grpclb_policy()->lb_call_timeout_ms_ == 0 ? GRPC_MILLIS_INF_FUTURE : ExecCtx::Get()->Now() + grpclb_policy()->lb_call_timeout_ms_; @@ -514,8 +512,7 @@ GrpcLb::BalancerCallState::BalancerCallState( grpclb_policy()->lb_channel_, nullptr, GRPC_PROPAGATE_DEFAULTS, grpclb_policy_->interested_parties(), GRPC_MDSTR_SLASH_GRPC_DOT_LB_DOT_V1_DOT_LOADBALANCER_SLASH_BALANCELOAD, - &host, deadline, nullptr); - grpc_slice_unref_internal(host); + nullptr, deadline, nullptr); // Init the LB call request payload. grpc_grpclb_request* request = grpc_grpclb_request_create(grpclb_policy()->server_name_); @@ -982,6 +979,10 @@ grpc_channel_args* BuildBalancerChannelArgs( // with the one from the grpclb policy, used to propagate updates to // the LB channel. GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR, + // The LB channel should use the authority indicated by the target + // authority table (see \a grpc_lb_policy_grpclb_modify_lb_channel_args), + // as opposed to the authority from the parent channel. + GRPC_ARG_DEFAULT_AUTHORITY, }; // Channel args to add. const grpc_arg args_to_add[] = { diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc index 60800365b8..8424cc5bc6 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc @@ -38,11 +38,41 @@ static void client_channel_factory_ref( static void client_channel_factory_unref( grpc_client_channel_factory* cc_factory) {} +static grpc_channel_args* add_default_authority_if_not_present( + const grpc_channel_args* args) { + const bool has_default_authority = + grpc_channel_args_find(args, GRPC_ARG_DEFAULT_AUTHORITY) != nullptr; + grpc_arg new_args[1]; + size_t num_new_args = 0; + grpc_core::UniquePtr default_authority; + if (!has_default_authority) { + const grpc_arg* server_uri_arg = + grpc_channel_args_find(args, GRPC_ARG_SERVER_URI); + const char* server_uri_str = grpc_channel_arg_get_string(server_uri_arg); + GPR_ASSERT(server_uri_str != nullptr); + default_authority = + grpc_core::ResolverRegistry::GetDefaultAuthority(server_uri_str); + GPR_ASSERT(default_authority != nullptr); + new_args[num_new_args++] = grpc_channel_arg_string_create( + const_cast(GRPC_ARG_DEFAULT_AUTHORITY), default_authority.get()); + } + return grpc_channel_args_copy_and_add(args, new_args, num_new_args); +} + static grpc_subchannel* client_channel_factory_create_subchannel( grpc_client_channel_factory* cc_factory, const grpc_subchannel_args* args) { + grpc_subchannel_args* final_sc_args = + static_cast(gpr_malloc(sizeof(*final_sc_args))); + memcpy(final_sc_args, args, sizeof(*args)); + final_sc_args->args = add_default_authority_if_not_present(args->args); + grpc_connector* connector = grpc_chttp2_connector_create(); - grpc_subchannel* s = grpc_subchannel_create(connector, args); + grpc_subchannel* s = grpc_subchannel_create(connector, final_sc_args); grpc_connector_unref(connector); + + grpc_channel_args_destroy( + const_cast(final_sc_args->args)); + gpr_free(final_sc_args); return s; } @@ -56,8 +86,8 @@ static grpc_channel* client_channel_factory_create_channel( // Add channel arg containing the server URI. grpc_core::UniquePtr canonical_target = grpc_core::ResolverRegistry::AddDefaultPrefixIfNeeded(target); - grpc_arg arg = grpc_channel_arg_string_create((char*)GRPC_ARG_SERVER_URI, - canonical_target.get()); + grpc_arg arg = grpc_channel_arg_string_create( + const_cast(GRPC_ARG_SERVER_URI), canonical_target.get()); const char* to_remove[] = {GRPC_ARG_SERVER_URI}; grpc_channel_args* new_args = grpc_channel_args_copy_and_add_and_remove(args, to_remove, 1, &arg, 1); diff --git a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc index a82009ff69..5ce73a95d7 100644 --- a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +++ b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc @@ -71,9 +71,6 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args( grpc_uri* server_uri = grpc_uri_parse(server_uri_str, true /* supress errors */); GPR_ASSERT(server_uri != nullptr); - const char* server_uri_path; - server_uri_path = - server_uri->path[0] == '/' ? server_uri->path + 1 : server_uri->path; const grpc_core::TargetAuthorityTable* target_authority_table = grpc_core::FindTargetAuthorityTableInArgs(args->args); grpc_core::UniquePtr authority; @@ -98,33 +95,49 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args( // authority table was present or because the target was not present // in the table), fall back to using the original server URI. if (authority == nullptr) { - authority.reset(gpr_strdup(server_uri_path)); + authority = + grpc_core::ResolverRegistry::GetDefaultAuthority(server_uri_str); } + grpc_arg args_to_add[2]; + size_t num_args_to_add = 0; + if (grpc_channel_args_find(args->args, GRPC_ARG_DEFAULT_AUTHORITY) == + nullptr) { + // If the channel args don't already contain GRPC_ARG_DEFAULT_AUTHORITY, add + // the arg, setting it to the value just obtained. + args_to_add[num_args_to_add++] = grpc_channel_arg_string_create( + const_cast(GRPC_ARG_DEFAULT_AUTHORITY), authority.get()); + } + grpc_channel_args* args_with_authority = + grpc_channel_args_copy_and_add(args->args, args_to_add, num_args_to_add); grpc_uri_destroy(server_uri); grpc_channel_security_connector* subchannel_security_connector = nullptr; // Create the security connector using the credentials and target name. grpc_channel_args* new_args_from_connector = nullptr; const grpc_security_status security_status = grpc_channel_credentials_create_security_connector( - channel_credentials, authority.get(), args->args, + channel_credentials, authority.get(), args_with_authority, &subchannel_security_connector, &new_args_from_connector); if (security_status != GRPC_SECURITY_OK) { gpr_log(GPR_ERROR, "Failed to create secure subchannel for secure name '%s'", authority.get()); + grpc_channel_args_destroy(args_with_authority); return nullptr; } grpc_arg new_security_connector_arg = grpc_security_connector_to_arg(&subchannel_security_connector->base); grpc_channel_args* new_args = grpc_channel_args_copy_and_add( - new_args_from_connector != nullptr ? new_args_from_connector : args->args, + new_args_from_connector != nullptr ? new_args_from_connector + : args_with_authority, &new_security_connector_arg, 1); + GRPC_SECURITY_CONNECTOR_UNREF(&subchannel_security_connector->base, "lb_channel_create"); if (new_args_from_connector != nullptr) { grpc_channel_args_destroy(new_args_from_connector); } + grpc_channel_args_destroy(args_with_authority); grpc_subchannel_args* final_sc_args = static_cast(gpr_malloc(sizeof(*final_sc_args))); memcpy(final_sc_args, args, sizeof(*args)); diff --git a/src/core/lib/channel/client_authority_filter.cc b/src/core/lib/channel/client_authority_filter.cc new file mode 100644 index 0000000000..57c5d29a93 --- /dev/null +++ b/src/core/lib/channel/client_authority_filter.cc @@ -0,0 +1,117 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include +#include + +#include +#include +#include + +#include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/channel/client_authority_filter.h" +#include "src/core/lib/gpr/string.h" +#include "src/core/lib/slice/slice_internal.h" +#include "src/core/lib/slice/slice_string_helpers.h" +#include "src/core/lib/surface/call.h" +#include "src/core/lib/surface/channel_init.h" +#include "src/core/lib/surface/channel_stack_type.h" +#include "src/core/lib/transport/static_metadata.h" + +namespace { + +struct call_data { + grpc_linked_mdelem authority_storage; + grpc_call_combiner* call_combiner; +}; + +struct channel_data { + grpc_slice default_authority; +}; + +void authority_start_transport_stream_op_batch( + grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { + channel_data* chand = static_cast(elem->channel_data); + call_data* calld = static_cast(elem->call_data); + // Handle send_initial_metadata. + auto* initial_metadata = + batch->payload->send_initial_metadata.send_initial_metadata; + // If the initial metadata doesn't already contain :authority, add it. + if (batch->send_initial_metadata && + initial_metadata->idx.named.authority == nullptr) { + grpc_error* error = grpc_metadata_batch_add_head( + initial_metadata, &calld->authority_storage, + grpc_mdelem_from_slices(GRPC_MDSTR_AUTHORITY, + grpc_slice_ref(chand->default_authority))); + if (error != GRPC_ERROR_NONE) { + grpc_transport_stream_op_batch_finish_with_failure(batch, error, + calld->call_combiner); + return; + } + } + // Pass control down the stack. + grpc_call_next_op(elem, batch); +} + +/* Constructor for call_data */ +grpc_error* init_call_elem(grpc_call_element* elem, + const grpc_call_element_args* args) { + call_data* calld = static_cast(elem->call_data); + calld->call_combiner = args->call_combiner; + return GRPC_ERROR_NONE; +} + +/* Destructor for call_data */ +void destroy_call_elem(grpc_call_element* elem, + const grpc_call_final_info* final_info, + grpc_closure* ignored) {} + +/* Constructor for channel_data */ +grpc_error* init_channel_elem(grpc_channel_element* elem, + grpc_channel_element_args* args) { + channel_data* chand = static_cast(elem->channel_data); + const grpc_arg* default_authority_arg = + grpc_channel_args_find(args->channel_args, GRPC_ARG_DEFAULT_AUTHORITY); + GPR_ASSERT(default_authority_arg != nullptr); + chand->default_authority = grpc_slice_from_copied_string( + grpc_channel_arg_get_string(default_authority_arg)); + GPR_ASSERT(!args->is_last); + return GRPC_ERROR_NONE; +} + +/* Destructor for channel data */ +void destroy_channel_elem(grpc_channel_element* elem) { + channel_data* chand = static_cast(elem->channel_data); + grpc_slice_unref(chand->default_authority); +} +} // namespace + +const grpc_channel_filter grpc_client_authority_filter = { + authority_start_transport_stream_op_batch, + grpc_channel_next_op, + sizeof(call_data), + init_call_elem, + grpc_call_stack_ignore_set_pollset_or_pollset_set, + destroy_call_elem, + sizeof(channel_data), + init_channel_elem, + destroy_channel_elem, + grpc_channel_next_get_info, + "authority"}; diff --git a/src/core/lib/channel/client_authority_filter.h b/src/core/lib/channel/client_authority_filter.h new file mode 100644 index 0000000000..ba996dc823 --- /dev/null +++ b/src/core/lib/channel/client_authority_filter.h @@ -0,0 +1,34 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_LIB_CHANNEL_CLIENT_AUTHORITY_FILTER_H +#define GRPC_CORE_LIB_CHANNEL_CLIENT_AUTHORITY_FILTER_H + +#include + +#include + +#include "src/core/lib/channel/channel_stack.h" + +/// Filter responsible for setting the authority header, if not already set. It +/// uses the value of the GRPC_ARG_DEFAULT_AUTHORITY channel arg if the initial +/// metadata doesn't already contain an authority value. + +extern const grpc_channel_filter grpc_client_authority_filter; + +#endif /* GRPC_CORE_LIB_CHANNEL_CLIENT_AUTHORITY_FILTER_H */ diff --git a/src/core/lib/security/credentials/ssl/ssl_credentials.cc b/src/core/lib/security/credentials/ssl/ssl_credentials.cc index 252b25bc0a..295f13c3b7 100644 --- a/src/core/lib/security/credentials/ssl/ssl_credentials.cc +++ b/src/core/lib/security/credentials/ssl/ssl_credentials.cc @@ -58,7 +58,7 @@ static grpc_security_status ssl_create_security_connector( const char* overridden_target_name = nullptr; for (size_t i = 0; args && i < args->num_args; i++) { grpc_arg* arg = &args->args[i]; - if (strcmp(arg->key, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG) == 0 && + if (strcmp(arg->key, GRPC_ARG_DEFAULT_AUTHORITY) == 0 && arg->type == GRPC_ARG_STRING) { overridden_target_name = arg->value.string; break; diff --git a/src/core/lib/security/security_connector/security_connector.cc b/src/core/lib/security/security_connector/security_connector.cc index 3cc151bec7..7b90b19075 100644 --- a/src/core/lib/security/security_connector/security_connector.cc +++ b/src/core/lib/security/security_connector/security_connector.cc @@ -465,12 +465,10 @@ static bool fake_channel_check_call_host(grpc_channel_security_connector* sc, grpc_error** error) { grpc_fake_channel_security_connector* c = reinterpret_cast(sc); - if (c->is_lb_channel) { - // TODO(dgq): verify that the host (ie, authority header) matches that of - // the LB, as opposed to that of the backends. - } else { - // TODO(dgq): verify that the host (ie, authority header) matches that of - // the backend, not the LB's. + if (c->is_lb_channel && strcmp(host, c->target) != 0) { + gpr_log(GPR_ERROR, "Authority (host) '%s' != Target '%s' for an LB call", + host, c->target); + abort(); } return true; } diff --git a/src/core/lib/surface/channel.cc b/src/core/lib/surface/channel.cc index 03353d6beb..48bc69509f 100644 --- a/src/core/lib/surface/channel.cc +++ b/src/core/lib/surface/channel.cc @@ -32,6 +32,7 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/debug/stats.h" #include "src/core/lib/gpr/string.h" +#include "src/core/lib/gprpp/memory.h" #include "src/core/lib/iomgr/iomgr.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/surface/api_trace.h" @@ -55,7 +56,6 @@ typedef struct registered_call { struct grpc_channel { int is_client; grpc_compression_options compression_options; - grpc_mdelem default_authority; gpr_atm call_size_estimate; @@ -108,40 +108,8 @@ grpc_channel* grpc_channel_create_with_builder( grpc_compression_options_init(&channel->compression_options); for (size_t i = 0; i < args->num_args; i++) { - if (0 == strcmp(args->args[i].key, GRPC_ARG_DEFAULT_AUTHORITY)) { - if (args->args[i].type != GRPC_ARG_STRING) { - gpr_log(GPR_ERROR, "%s ignored: it must be a string", - GRPC_ARG_DEFAULT_AUTHORITY); - } else { - if (!GRPC_MDISNULL(channel->default_authority)) { - /* setting this takes precedence over anything else */ - GRPC_MDELEM_UNREF(channel->default_authority); - } - channel->default_authority = grpc_mdelem_from_slices( - GRPC_MDSTR_AUTHORITY, - grpc_slice_intern( - grpc_slice_from_static_string(args->args[i].value.string))); - } - } else if (0 == - strcmp(args->args[i].key, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG)) { - if (args->args[i].type != GRPC_ARG_STRING) { - gpr_log(GPR_ERROR, "%s ignored: it must be a string", - GRPC_SSL_TARGET_NAME_OVERRIDE_ARG); - } else { - if (!GRPC_MDISNULL(channel->default_authority)) { - /* other ways of setting this (notably ssl) take precedence */ - gpr_log(GPR_ERROR, - "%s ignored: default host already set some other way", - GRPC_SSL_TARGET_NAME_OVERRIDE_ARG); - } else { - channel->default_authority = grpc_mdelem_from_slices( - GRPC_MDSTR_AUTHORITY, - grpc_slice_intern( - grpc_slice_from_static_string(args->args[i].value.string))); - } - } - } else if (0 == strcmp(args->args[i].key, - GRPC_COMPRESSION_CHANNEL_DEFAULT_LEVEL)) { + if (0 == + strcmp(args->args[i].key, GRPC_COMPRESSION_CHANNEL_DEFAULT_LEVEL)) { channel->compression_options.default_level.is_set = true; channel->compression_options.default_level.level = static_cast(grpc_channel_arg_get_integer( @@ -169,12 +137,49 @@ done: return channel; } +static grpc_core::UniquePtr get_default_authority( + const char* target, const grpc_channel_args* input_args, + grpc_channel_stack_type channel_stack_type) { + bool has_default_authority = false; + char* ssl_override = nullptr; + grpc_core::UniquePtr default_authority; + const size_t num_args = input_args != nullptr ? input_args->num_args : 0; + for (size_t i = 0; i < num_args; ++i) { + if (0 == strcmp(input_args->args[i].key, GRPC_ARG_DEFAULT_AUTHORITY)) { + has_default_authority = true; + } else if (0 == strcmp(input_args->args[i].key, + GRPC_SSL_TARGET_NAME_OVERRIDE_ARG)) { + ssl_override = input_args->args[i].value.string; + } + } + if (!has_default_authority && ssl_override != nullptr) { + default_authority.reset(gpr_strdup(ssl_override)); + } + return default_authority; +} + +static grpc_channel_args* build_channel_args( + const grpc_channel_args* input_args, char* default_authority) { + grpc_arg new_args[1]; + size_t num_new_args = 0; + if (default_authority != nullptr) { + new_args[num_new_args++] = grpc_channel_arg_string_create( + const_cast(GRPC_ARG_DEFAULT_AUTHORITY), default_authority); + } + return grpc_channel_args_copy_and_add(input_args, new_args, num_new_args); +} + grpc_channel* grpc_channel_create(const char* target, const grpc_channel_args* input_args, grpc_channel_stack_type channel_stack_type, grpc_transport* optional_transport) { grpc_channel_stack_builder* builder = grpc_channel_stack_builder_create(); - grpc_channel_stack_builder_set_channel_arguments(builder, input_args); + const grpc_core::UniquePtr default_authority = + get_default_authority(target, input_args, channel_stack_type); + grpc_channel_args* args = + build_channel_args(input_args, default_authority.get()); + grpc_channel_stack_builder_set_channel_arguments(builder, args); + grpc_channel_args_destroy(args); grpc_channel_stack_builder_set_target(builder, target); grpc_channel_stack_builder_set_transport(builder, optional_transport); if (!grpc_channel_init_create_stack(builder, channel_stack_type)) { @@ -246,8 +251,6 @@ static grpc_call* grpc_channel_create_call_internal( send_metadata[num_metadata++] = path_mdelem; if (!GRPC_MDISNULL(authority_mdelem)) { send_metadata[num_metadata++] = authority_mdelem; - } else if (!GRPC_MDISNULL(channel->default_authority)) { - send_metadata[num_metadata++] = GRPC_MDELEM_REF(channel->default_authority); } grpc_call_create_args args; @@ -377,7 +380,6 @@ static void destroy_channel(void* arg, grpc_error* error) { GRPC_MDELEM_UNREF(rc->authority); gpr_free(rc); } - GRPC_MDELEM_UNREF(channel->default_authority); gpr_mu_destroy(&channel->registered_call_mu); gpr_free(channel->target); gpr_free(channel); diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc index ac9f9e6066..10c65ce09f 100644 --- a/src/core/lib/surface/init.cc +++ b/src/core/lib/surface/init.cc @@ -27,6 +27,7 @@ #include #include #include "src/core/lib/channel/channel_stack.h" +#include "src/core/lib/channel/client_authority_filter.h" #include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/channel/handshaker_registry.h" #include "src/core/lib/debug/stats.h" @@ -83,6 +84,13 @@ static bool prepend_filter(grpc_channel_stack_builder* builder, void* arg) { } static void register_builtin_channel_init() { + grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, INT_MAX, + prepend_filter, + (void*)(&grpc_client_authority_filter)); + grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, + prepend_filter, + (void*)(&grpc_client_authority_filter)); + grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, grpc_add_connected_filter, nullptr); diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 994443c651..7bd1adf8fe 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -60,6 +60,7 @@ CORE_SOURCE_FILES = [ 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', + 'src/core/lib/channel/client_authority_filter.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', diff --git a/test/core/channel/minimal_stack_is_minimal_test.cc b/test/core/channel/minimal_stack_is_minimal_test.cc index f02c8180f2..e5953acedc 100644 --- a/test/core/channel/minimal_stack_is_minimal_test.cc +++ b/test/core/channel/minimal_stack_is_minimal_test.cc @@ -66,35 +66,37 @@ int main(int argc, char** argv) { minimal_stack_arg.key = const_cast(GRPC_ARG_MINIMAL_STACK); minimal_stack_arg.value.integer = 1; grpc_channel_args minimal_stack_args = {1, &minimal_stack_arg}; - errors += CHECK_STACK("unknown", &minimal_stack_args, - GRPC_CLIENT_DIRECT_CHANNEL, "connected", NULL); + errors += + CHECK_STACK("unknown", &minimal_stack_args, GRPC_CLIENT_DIRECT_CHANNEL, + "authority", "connected", NULL); errors += CHECK_STACK("unknown", &minimal_stack_args, GRPC_CLIENT_SUBCHANNEL, - "connected", NULL); + "authority", "connected", NULL); errors += CHECK_STACK("unknown", &minimal_stack_args, GRPC_SERVER_CHANNEL, "server", "connected", NULL); errors += CHECK_STACK("chttp2", &minimal_stack_args, GRPC_CLIENT_DIRECT_CHANNEL, - "http-client", "connected", NULL); + "authority", "http-client", "connected", NULL); errors += CHECK_STACK("chttp2", &minimal_stack_args, GRPC_CLIENT_SUBCHANNEL, - "http-client", "connected", NULL); + "authority", "http-client", "connected", NULL); errors += CHECK_STACK("chttp2", &minimal_stack_args, GRPC_SERVER_CHANNEL, "server", "http-server", "connected", NULL); errors += CHECK_STACK(nullptr, &minimal_stack_args, GRPC_CLIENT_CHANNEL, "client-channel", NULL); // tests with a default stack - errors += CHECK_STACK("unknown", nullptr, GRPC_CLIENT_DIRECT_CHANNEL, - "message_size", "deadline", "connected", NULL); - errors += CHECK_STACK("unknown", nullptr, GRPC_CLIENT_SUBCHANNEL, + errors += + CHECK_STACK("unknown", nullptr, GRPC_CLIENT_DIRECT_CHANNEL, "authority", + "message_size", "deadline", "connected", NULL); + errors += CHECK_STACK("unknown", nullptr, GRPC_CLIENT_SUBCHANNEL, "authority", "message_size", "connected", NULL); errors += CHECK_STACK("unknown", nullptr, GRPC_SERVER_CHANNEL, "server", "message_size", "deadline", "connected", NULL); errors += CHECK_STACK("chttp2", nullptr, GRPC_CLIENT_DIRECT_CHANNEL, - "message_size", "deadline", "http-client", + "authority", "message_size", "deadline", "http-client", "message_compress", "connected", NULL); - errors += - CHECK_STACK("chttp2", nullptr, GRPC_CLIENT_SUBCHANNEL, "message_size", - "http-client", "message_compress", "connected", NULL); + errors += CHECK_STACK("chttp2", nullptr, GRPC_CLIENT_SUBCHANNEL, "authority", + "message_size", "http-client", "message_compress", + "connected", NULL); errors += CHECK_STACK("chttp2", nullptr, GRPC_SERVER_CHANNEL, "server", "message_size", "deadline", "http-server", "message_compress", "connected", NULL); diff --git a/test/core/end2end/tests/default_host.cc b/test/core/end2end/tests/default_host.cc index 3191f76688..cda716a259 100644 --- a/test/core/end2end/tests/default_host.cc +++ b/test/core/end2end/tests/default_host.cc @@ -191,7 +191,9 @@ static void simple_request_body(grpc_end2end_test_fixture f) { GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); - GPR_ASSERT(grpc_slice_buf_start_eq(call_details.host, "localhost", 9)); + char* target = grpc_channel_get_target(f.client); + GPR_ASSERT(grpc_slice_buf_start_eq(call_details.host, target, 9)); + gpr_free(target); GPR_ASSERT(was_cancelled == 1); grpc_slice_unref(details); @@ -216,10 +218,9 @@ static void test_invoke_simple_request(grpc_end2end_test_config config) { } void default_host(grpc_end2end_test_config config) { - if ((config.feature_mask & FEATURE_MASK_SUPPORTS_HOSTNAME_VERIFICATION) == 0) - return; - if ((config.feature_mask & FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION) == 0) + if ((config.feature_mask & FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS) != 0) { return; + } test_invoke_simple_request(config); } diff --git a/test/core/surface/BUILD b/test/core/surface/BUILD index e848dded13..77df1cc989 100644 --- a/test/core/surface/BUILD +++ b/test/core/surface/BUILD @@ -90,18 +90,6 @@ grpc_cc_test( ], ) -grpc_cc_test( - name = "grpc_invalid_channel_args_test", - srcs = ["invalid_channel_args_test.cc"], - language = "C++", - deps = [ - "//:gpr", - "//:grpc", - "//test/core/util:gpr_test_util", - "//test/core/util:grpc_test_util", - ], -) - grpc_cc_test( name = "lame_client_test", srcs = ["lame_client_test.cc"], diff --git a/test/core/surface/invalid_channel_args_test.cc b/test/core/surface/invalid_channel_args_test.cc deleted file mode 100644 index 7c5f1f0352..0000000000 --- a/test/core/surface/invalid_channel_args_test.cc +++ /dev/null @@ -1,137 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include - -#include -#include -#include -#include "test/core/util/test_config.h" - -static char* g_last_log_error_message = nullptr; -static const char* g_file_name = "channel.cc"; - -static int ends_with(const char* src, const char* suffix) { - size_t src_len = strlen(src); - size_t suffix_len = strlen(suffix); - if (src_len < suffix_len) { - return 0; - } - return strcmp(src + src_len - suffix_len, suffix) == 0; -} - -static void log_error_sink(gpr_log_func_args* args) { - if (args->severity == GPR_LOG_SEVERITY_ERROR && - ends_with(args->file, g_file_name)) { - g_last_log_error_message = gpr_strdup(args->message); - } -} - -static void verify_last_error(const char* message) { - if (message == nullptr) { - GPR_ASSERT(g_last_log_error_message == nullptr); - return; - } - GPR_ASSERT(strcmp(message, g_last_log_error_message) == 0); - gpr_free(g_last_log_error_message); - g_last_log_error_message = nullptr; -} - -static char* compose_error_string(const char* key, const char* message) { - char* ret; - gpr_asprintf(&ret, "%s%s", key, message); - return ret; -} - -static void one_test(grpc_channel_args* args, char* expected_error_message) { - grpc_channel* chan = - grpc_insecure_channel_create("nonexistant:54321", args, nullptr); - verify_last_error(expected_error_message); - gpr_free(expected_error_message); - grpc_channel_destroy(chan); -} - -static void test_no_error_message(void) { one_test(nullptr, nullptr); } - -static void test_default_authority_type(void) { - grpc_arg client_arg; - grpc_channel_args client_args; - char* expected_error_message; - - client_arg.type = GRPC_ARG_INTEGER; - client_arg.key = const_cast(GRPC_ARG_DEFAULT_AUTHORITY); - client_arg.value.integer = 0; - - client_args.num_args = 1; - client_args.args = &client_arg; - expected_error_message = compose_error_string( - GRPC_ARG_DEFAULT_AUTHORITY, " ignored: it must be a string"); - one_test(&client_args, expected_error_message); -} - -static void test_ssl_name_override_type(void) { - grpc_arg client_arg; - grpc_channel_args client_args; - char* expected_error_message; - - client_arg.type = GRPC_ARG_INTEGER; - client_arg.key = const_cast(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG); - client_arg.value.integer = 0; - - client_args.num_args = 1; - client_args.args = &client_arg; - expected_error_message = compose_error_string( - GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, " ignored: it must be a string"); - one_test(&client_args, expected_error_message); -} - -static void test_ssl_name_override_failed(void) { - grpc_arg client_arg[2]; - grpc_channel_args client_args; - char* expected_error_message; - - client_arg[0].type = GRPC_ARG_STRING; - client_arg[0].key = const_cast(GRPC_ARG_DEFAULT_AUTHORITY); - client_arg[0].value.string = const_cast("default"); - client_arg[1].type = GRPC_ARG_STRING; - client_arg[1].key = const_cast(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG); - client_arg[1].value.string = const_cast("ssl"); - - client_args.num_args = 2; - client_args.args = client_arg; - expected_error_message = - compose_error_string(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, - " ignored: default host already set some other way"); - one_test(&client_args, expected_error_message); -} - -int main(int argc, char** argv) { - grpc_test_init(argc, argv); - grpc_init(); - gpr_set_log_function(log_error_sink); - - test_no_error_message(); - test_default_authority_type(); - test_ssl_name_override_type(); - test_ssl_name_override_failed(); - - grpc_shutdown(); - - return 0; -} diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index ff5abc679d..f1fb7d29fc 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -1007,6 +1007,7 @@ src/core/lib/backoff/backoff.h \ src/core/lib/channel/channel_args.h \ src/core/lib/channel/channel_stack.h \ src/core/lib/channel/channel_stack_builder.h \ +src/core/lib/channel/client_authority_filter.h \ src/core/lib/channel/connected_channel.h \ src/core/lib/channel/context.h \ src/core/lib/channel/handshaker.h \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index e7e9e04979..1f19bac169 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -1034,6 +1034,8 @@ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack.h \ src/core/lib/channel/channel_stack_builder.cc \ src/core/lib/channel/channel_stack_builder.h \ +src/core/lib/channel/client_authority_filter.cc \ +src/core/lib/channel/client_authority_filter.h \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/connected_channel.h \ src/core/lib/channel/context.h \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index f5a9eb828e..fa34d963aa 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -1000,23 +1000,6 @@ "third_party": false, "type": "target" }, - { - "deps": [ - "gpr", - "gpr_test_util", - "grpc", - "grpc_test_util" - ], - "headers": [], - "is_filegroup": false, - "language": "c", - "name": "grpc_invalid_channel_args_test", - "src": [ - "test/core/surface/invalid_channel_args_test.cc" - ], - "third_party": false, - "type": "target" - }, { "deps": [ "gpr", @@ -9005,6 +8988,7 @@ "src/core/lib/channel/channel_args.cc", "src/core/lib/channel/channel_stack.cc", "src/core/lib/channel/channel_stack_builder.cc", + "src/core/lib/channel/client_authority_filter.cc", "src/core/lib/channel/connected_channel.cc", "src/core/lib/channel/handshaker.cc", "src/core/lib/channel/handshaker_factory.cc", @@ -9162,6 +9146,7 @@ "src/core/lib/channel/channel_args.h", "src/core/lib/channel/channel_stack.h", "src/core/lib/channel/channel_stack_builder.h", + "src/core/lib/channel/client_authority_filter.h", "src/core/lib/channel/connected_channel.h", "src/core/lib/channel/context.h", "src/core/lib/channel/handshaker.h", @@ -9306,6 +9291,7 @@ "src/core/lib/channel/channel_args.h", "src/core/lib/channel/channel_stack.h", "src/core/lib/channel/channel_stack_builder.h", + "src/core/lib/channel/client_authority_filter.h", "src/core/lib/channel/connected_channel.h", "src/core/lib/channel/context.h", "src/core/lib/channel/handshaker.h", diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 1406c4ac7e..db2776ba75 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -1297,30 +1297,6 @@ ], "uses_polling": true }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": false, - "language": "c", - "name": "grpc_invalid_channel_args_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": false - }, { "args": [], "benchmark": false, -- cgit v1.2.3 From 539f5068bd14e3d07b58309b657222919e94aba5 Mon Sep 17 00:00:00 2001 From: kpayson64 Date: Mon, 12 Mar 2018 19:16:30 -0700 Subject: Abstract libuv implementation Structures the libuv implementation to allow for a plugable BSD style socket implementation to allow for other IO Managers --- BUILD | 31 +- CMakeLists.txt | 114 +- MANIFEST.md | 4 - Makefile | 114 +- build.yaml | 31 +- config.m4 | 19 +- config.w32 | 19 +- gRPC-C++.podspec | 24 +- gRPC-Core.podspec | 43 +- grpc.gemspec | 31 +- grpc.gyp | 76 +- include/grpc/impl/codegen/slice.h | 2 +- package.xml | 31 +- .../client_channel/lb_policy/grpclb/grpclb.cc | 15 +- .../ext/filters/client_channel/parse_address.cc | 26 +- .../resolver/dns/c_ares/dns_resolver_ares.cc | 24 +- .../chttp2/server/insecure/server_chttp2.cc | 1 - src/core/lib/iomgr/endpoint.cc | 2 + src/core/lib/iomgr/endpoint_pair_windows.cc | 9 +- src/core/lib/iomgr/ev_posix.cc | 52 +- src/core/lib/iomgr/exec_ctx.h | 7 +- src/core/lib/iomgr/iomgr.cc | 1 + src/core/lib/iomgr/iomgr_custom.cc | 63 ++ src/core/lib/iomgr/iomgr_custom.h | 47 + src/core/lib/iomgr/iomgr_internal.cc | 43 + src/core/lib/iomgr/iomgr_internal.h | 12 + src/core/lib/iomgr/iomgr_posix.cc | 31 +- src/core/lib/iomgr/iomgr_uv.cc | 35 +- src/core/lib/iomgr/iomgr_uv.h | 39 - src/core/lib/iomgr/iomgr_windows.cc | 30 +- src/core/lib/iomgr/pollset.cc | 56 + src/core/lib/iomgr/pollset.h | 18 + src/core/lib/iomgr/pollset_custom.cc | 106 ++ src/core/lib/iomgr/pollset_custom.h | 35 + src/core/lib/iomgr/pollset_set.cc | 55 + src/core/lib/iomgr/pollset_set.h | 11 + src/core/lib/iomgr/pollset_set_custom.cc | 48 + src/core/lib/iomgr/pollset_set_custom.h | 26 + src/core/lib/iomgr/pollset_set_uv.cc | 45 - src/core/lib/iomgr/pollset_set_windows.cc | 25 +- src/core/lib/iomgr/pollset_uv.cc | 145 +-- src/core/lib/iomgr/pollset_uv.h | 9 +- src/core/lib/iomgr/pollset_windows.cc | 28 +- src/core/lib/iomgr/port.h | 27 +- src/core/lib/iomgr/resolve_address.cc | 50 + src/core/lib/iomgr/resolve_address.h | 29 +- src/core/lib/iomgr/resolve_address_custom.cc | 187 ++++ src/core/lib/iomgr/resolve_address_custom.h | 43 + src/core/lib/iomgr/resolve_address_posix.cc | 28 +- src/core/lib/iomgr/resolve_address_uv.cc | 286 ----- src/core/lib/iomgr/resolve_address_windows.cc | 28 +- src/core/lib/iomgr/resource_quota.h | 4 - src/core/lib/iomgr/sockaddr.h | 14 +- src/core/lib/iomgr/sockaddr_custom.h | 54 + src/core/lib/iomgr/sockaddr_posix.h | 24 + src/core/lib/iomgr/sockaddr_utils.cc | 156 +-- src/core/lib/iomgr/sockaddr_utils.h | 2 + src/core/lib/iomgr/sockaddr_windows.h | 19 + src/core/lib/iomgr/socket_utils.h | 9 + src/core/lib/iomgr/socket_utils_common_posix.cc | 18 +- src/core/lib/iomgr/socket_utils_linux.cc | 3 +- src/core/lib/iomgr/socket_utils_posix.cc | 2 +- src/core/lib/iomgr/socket_utils_uv.cc | 17 +- src/core/lib/iomgr/socket_utils_windows.cc | 8 + src/core/lib/iomgr/tcp_client.cc | 36 + src/core/lib/iomgr/tcp_client.h | 11 + src/core/lib/iomgr/tcp_client_custom.cc | 151 +++ src/core/lib/iomgr/tcp_client_posix.cc | 30 +- src/core/lib/iomgr/tcp_client_uv.cc | 177 ---- src/core/lib/iomgr/tcp_client_windows.cc | 31 +- src/core/lib/iomgr/tcp_custom.cc | 365 +++++++ src/core/lib/iomgr/tcp_custom.h | 83 ++ src/core/lib/iomgr/tcp_posix.cc | 2 +- src/core/lib/iomgr/tcp_server.cc | 73 ++ src/core/lib/iomgr/tcp_server.h | 22 + src/core/lib/iomgr/tcp_server_custom.cc | 479 +++++++++ src/core/lib/iomgr/tcp_server_posix.cc | 49 +- .../lib/iomgr/tcp_server_utils_posix_common.cc | 5 +- .../lib/iomgr/tcp_server_utils_posix_ifaddrs.cc | 8 +- src/core/lib/iomgr/tcp_server_uv.cc | 473 --------- src/core/lib/iomgr/tcp_server_windows.cc | 62 +- src/core/lib/iomgr/tcp_uv.cc | 627 ++++++----- src/core/lib/iomgr/tcp_uv.h | 53 - src/core/lib/iomgr/tcp_windows.cc | 2 +- src/core/lib/iomgr/timer.cc | 45 + src/core/lib/iomgr/timer.h | 48 +- src/core/lib/iomgr/timer_custom.cc | 93 ++ src/core/lib/iomgr/timer_custom.h | 43 + src/core/lib/iomgr/timer_generic.cc | 20 +- src/core/lib/iomgr/timer_heap.cc | 4 - src/core/lib/iomgr/timer_uv.cc | 62 +- src/core/lib/iomgr/timer_uv.h | 34 - src/core/lib/iomgr/udp_server.cc | 15 +- src/core/lib/iomgr/unix_sockets_posix.cc | 12 +- src/python/grpcio/grpc_core_dependencies.py | 19 +- test/core/client_channel/parse_address_test.cc | 27 +- .../resolvers/dns_resolver_connectivity_test.cc | 5 +- .../resolvers/dns_resolver_cooldown_test.cc | 33 +- test/core/end2end/fixtures/http_proxy_fixture.cc | 6 +- test/core/end2end/fuzzers/api_fuzzer.cc | 15 +- test/core/end2end/goaway_server_test.cc | 46 +- test/core/end2end/tests/request_with_flags.cc | 8 +- test/core/iomgr/sockaddr_utils_test.cc | 46 +- test/core/iomgr/timer_heap_test.cc | 9 - test/core/iomgr/timer_list_test.cc | 11 +- test/core/iomgr/wakeup_fd_cv_test.cc | 2 +- test/core/surface/concurrent_connectivity_test.cc | 5 +- test/core/util/test_tcp_server.cc | 9 +- test/cpp/end2end/client_lb_end2end_test.cc | 19 +- tools/doxygen/Doxyfile.c++.internal | 12 +- tools/doxygen/Doxyfile.core.internal | 31 +- tools/run_tests/generated/sources_and_headers.json | 43 +- tools/run_tests/run_tests.py | 2 +- vsprojects/vcxproj/grpc++/grpc++.vcxproj | 646 ++++++++++++ vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters | 1096 ++++++++++++++++++++ .../grpc++_unsecure/grpc++_unsecure.vcxproj | 630 +++++++++++ .../grpc++_unsecure.vcxproj.filters | 1063 +++++++++++++++++++ vsprojects/vcxproj/grpc/grpc.vcxproj | 46 +- vsprojects/vcxproj/grpc/grpc.vcxproj.filters | 79 +- .../vcxproj/grpc_test_util/grpc_test_util.vcxproj | 38 +- .../grpc_test_util/grpc_test_util.vcxproj.filters | 50 +- .../grpc_test_util_unsecure.vcxproj | 649 ++++++++++++ .../grpc_test_util_unsecure.vcxproj.filters | 946 +++++++++++++++++ .../vcxproj/grpc_unsecure/grpc_unsecure.vcxproj | 44 +- .../grpc_unsecure/grpc_unsecure.vcxproj.filters | 64 +- 125 files changed, 9071 insertions(+), 2334 deletions(-) create mode 100644 src/core/lib/iomgr/iomgr_custom.cc create mode 100644 src/core/lib/iomgr/iomgr_custom.h create mode 100644 src/core/lib/iomgr/iomgr_internal.cc delete mode 100644 src/core/lib/iomgr/iomgr_uv.h create mode 100644 src/core/lib/iomgr/pollset.cc create mode 100644 src/core/lib/iomgr/pollset_custom.cc create mode 100644 src/core/lib/iomgr/pollset_custom.h create mode 100644 src/core/lib/iomgr/pollset_set.cc create mode 100644 src/core/lib/iomgr/pollset_set_custom.cc create mode 100644 src/core/lib/iomgr/pollset_set_custom.h delete mode 100644 src/core/lib/iomgr/pollset_set_uv.cc create mode 100644 src/core/lib/iomgr/resolve_address.cc create mode 100644 src/core/lib/iomgr/resolve_address_custom.cc create mode 100644 src/core/lib/iomgr/resolve_address_custom.h delete mode 100644 src/core/lib/iomgr/resolve_address_uv.cc create mode 100644 src/core/lib/iomgr/sockaddr_custom.h create mode 100644 src/core/lib/iomgr/tcp_client.cc create mode 100644 src/core/lib/iomgr/tcp_client_custom.cc delete mode 100644 src/core/lib/iomgr/tcp_client_uv.cc create mode 100644 src/core/lib/iomgr/tcp_custom.cc create mode 100644 src/core/lib/iomgr/tcp_custom.h create mode 100644 src/core/lib/iomgr/tcp_server.cc create mode 100644 src/core/lib/iomgr/tcp_server_custom.cc delete mode 100644 src/core/lib/iomgr/tcp_server_uv.cc delete mode 100644 src/core/lib/iomgr/tcp_uv.h create mode 100644 src/core/lib/iomgr/timer.cc create mode 100644 src/core/lib/iomgr/timer_custom.cc create mode 100644 src/core/lib/iomgr/timer_custom.h delete mode 100644 src/core/lib/iomgr/timer_uv.h create mode 100644 vsprojects/vcxproj/grpc++/grpc++.vcxproj create mode 100644 vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters create mode 100644 vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj create mode 100644 vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters create mode 100644 vsprojects/vcxproj/grpc_test_util_unsecure/grpc_test_util_unsecure.vcxproj create mode 100644 vsprojects/vcxproj/grpc_test_util_unsecure/grpc_test_util_unsecure.vcxproj.filters (limited to 'gRPC-C++.podspec') diff --git a/BUILD b/BUILD index bfda84e0f4..6c18ad94d7 100644 --- a/BUILD +++ b/BUILD @@ -713,20 +713,25 @@ grpc_cc_library( "src/core/lib/iomgr/gethostname_sysconf.cc", "src/core/lib/iomgr/iocp_windows.cc", "src/core/lib/iomgr/iomgr.cc", + "src/core/lib/iomgr/iomgr_custom.cc", + "src/core/lib/iomgr/iomgr_internal.cc", "src/core/lib/iomgr/iomgr_posix.cc", - "src/core/lib/iomgr/iomgr_uv.cc", "src/core/lib/iomgr/iomgr_windows.cc", "src/core/lib/iomgr/is_epollexclusive_available.cc", "src/core/lib/iomgr/load_file.cc", "src/core/lib/iomgr/lockfree_event.cc", "src/core/lib/iomgr/network_status_tracker.cc", "src/core/lib/iomgr/polling_entity.cc", - "src/core/lib/iomgr/pollset_set_uv.cc", + "src/core/lib/iomgr/pollset.cc", + "src/core/lib/iomgr/pollset_custom.cc", + "src/core/lib/iomgr/pollset_set.cc", + "src/core/lib/iomgr/pollset_set_custom.cc", "src/core/lib/iomgr/pollset_set_windows.cc", "src/core/lib/iomgr/pollset_uv.cc", "src/core/lib/iomgr/pollset_windows.cc", + "src/core/lib/iomgr/resolve_address.cc", + "src/core/lib/iomgr/resolve_address_custom.cc", "src/core/lib/iomgr/resolve_address_posix.cc", - "src/core/lib/iomgr/resolve_address_uv.cc", "src/core/lib/iomgr/resolve_address_windows.cc", "src/core/lib/iomgr/resource_quota.cc", "src/core/lib/iomgr/sockaddr_utils.cc", @@ -735,22 +740,26 @@ grpc_cc_library( "src/core/lib/iomgr/socket_utils_common_posix.cc", "src/core/lib/iomgr/socket_utils_linux.cc", "src/core/lib/iomgr/socket_utils_posix.cc", - "src/core/lib/iomgr/socket_utils_uv.cc", "src/core/lib/iomgr/socket_utils_windows.cc", "src/core/lib/iomgr/socket_windows.cc", + "src/core/lib/iomgr/tcp_client.cc", + "src/core/lib/iomgr/tcp_client_custom.cc", "src/core/lib/iomgr/tcp_client_posix.cc", - "src/core/lib/iomgr/tcp_client_uv.cc", "src/core/lib/iomgr/tcp_client_windows.cc", + "src/core/lib/iomgr/tcp_custom.cc", "src/core/lib/iomgr/tcp_posix.cc", + "src/core/lib/iomgr/tcp_server.cc", + "src/core/lib/iomgr/tcp_server_custom.cc", "src/core/lib/iomgr/tcp_server_posix.cc", "src/core/lib/iomgr/tcp_server_utils_posix_common.cc", "src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc", "src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc", - "src/core/lib/iomgr/tcp_server_uv.cc", "src/core/lib/iomgr/tcp_server_windows.cc", "src/core/lib/iomgr/tcp_uv.cc", "src/core/lib/iomgr/tcp_windows.cc", "src/core/lib/iomgr/time_averaged_stats.cc", + "src/core/lib/iomgr/timer.cc", + "src/core/lib/iomgr/timer_custom.cc", "src/core/lib/iomgr/timer_generic.cc", "src/core/lib/iomgr/timer_heap.cc", "src/core/lib/iomgr/timer_manager.cc", @@ -845,9 +854,9 @@ grpc_cc_library( "src/core/lib/iomgr/gethostname.h", "src/core/lib/iomgr/iocp_windows.h", "src/core/lib/iomgr/iomgr.h", + "src/core/lib/iomgr/iomgr_custom.h", "src/core/lib/iomgr/iomgr_internal.h", "src/core/lib/iomgr/iomgr_posix.h", - "src/core/lib/iomgr/iomgr_uv.h", "src/core/lib/iomgr/is_epollexclusive_available.h", "src/core/lib/iomgr/load_file.h", "src/core/lib/iomgr/lockfree_event.h", @@ -855,14 +864,18 @@ grpc_cc_library( "src/core/lib/iomgr/network_status_tracker.h", "src/core/lib/iomgr/polling_entity.h", "src/core/lib/iomgr/pollset.h", + "src/core/lib/iomgr/pollset_custom.h", "src/core/lib/iomgr/pollset_set.h", + "src/core/lib/iomgr/pollset_set_custom.h", "src/core/lib/iomgr/pollset_set_windows.h", "src/core/lib/iomgr/pollset_uv.h", "src/core/lib/iomgr/pollset_windows.h", "src/core/lib/iomgr/port.h", "src/core/lib/iomgr/resolve_address.h", + "src/core/lib/iomgr/resolve_address_custom.h", "src/core/lib/iomgr/resource_quota.h", "src/core/lib/iomgr/sockaddr.h", + "src/core/lib/iomgr/sockaddr_custom.h", "src/core/lib/iomgr/sockaddr_posix.h", "src/core/lib/iomgr/sockaddr_utils.h", "src/core/lib/iomgr/sockaddr_windows.h", @@ -874,17 +887,17 @@ grpc_cc_library( "src/core/lib/iomgr/sys_epoll_wrapper.h", "src/core/lib/iomgr/tcp_client.h", "src/core/lib/iomgr/tcp_client_posix.h", + "src/core/lib/iomgr/tcp_custom.h", "src/core/lib/iomgr/tcp_posix.h", "src/core/lib/iomgr/tcp_server.h", "src/core/lib/iomgr/tcp_server_utils_posix.h", - "src/core/lib/iomgr/tcp_uv.h", "src/core/lib/iomgr/tcp_windows.h", "src/core/lib/iomgr/time_averaged_stats.h", "src/core/lib/iomgr/timer.h", + "src/core/lib/iomgr/timer_custom.h", "src/core/lib/iomgr/timer_generic.h", "src/core/lib/iomgr/timer_heap.h", "src/core/lib/iomgr/timer_manager.h", - "src/core/lib/iomgr/timer_uv.h", "src/core/lib/iomgr/udp_server.h", "src/core/lib/iomgr/unix_sockets_posix.h", "src/core/lib/iomgr/wakeup_fd_cv.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index e0724d10aa..3e58593fb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -893,6 +893,8 @@ add_library(grpc src/core/lib/iomgr/gethostname_sysconf.cc src/core/lib/iomgr/iocp_windows.cc src/core/lib/iomgr/iomgr.cc + src/core/lib/iomgr/iomgr_custom.cc + src/core/lib/iomgr/iomgr_internal.cc src/core/lib/iomgr/iomgr_posix.cc src/core/lib/iomgr/iomgr_uv.cc src/core/lib/iomgr/iomgr_windows.cc @@ -901,12 +903,16 @@ add_library(grpc src/core/lib/iomgr/lockfree_event.cc src/core/lib/iomgr/network_status_tracker.cc src/core/lib/iomgr/polling_entity.cc - src/core/lib/iomgr/pollset_set_uv.cc + src/core/lib/iomgr/pollset.cc + src/core/lib/iomgr/pollset_custom.cc + src/core/lib/iomgr/pollset_set.cc + src/core/lib/iomgr/pollset_set_custom.cc src/core/lib/iomgr/pollset_set_windows.cc src/core/lib/iomgr/pollset_uv.cc src/core/lib/iomgr/pollset_windows.cc + src/core/lib/iomgr/resolve_address.cc + src/core/lib/iomgr/resolve_address_custom.cc src/core/lib/iomgr/resolve_address_posix.cc - src/core/lib/iomgr/resolve_address_uv.cc src/core/lib/iomgr/resolve_address_windows.cc src/core/lib/iomgr/resource_quota.cc src/core/lib/iomgr/sockaddr_utils.cc @@ -918,19 +924,24 @@ add_library(grpc src/core/lib/iomgr/socket_utils_uv.cc src/core/lib/iomgr/socket_utils_windows.cc src/core/lib/iomgr/socket_windows.cc + src/core/lib/iomgr/tcp_client.cc + src/core/lib/iomgr/tcp_client_custom.cc src/core/lib/iomgr/tcp_client_posix.cc - src/core/lib/iomgr/tcp_client_uv.cc src/core/lib/iomgr/tcp_client_windows.cc + src/core/lib/iomgr/tcp_custom.cc src/core/lib/iomgr/tcp_posix.cc + src/core/lib/iomgr/tcp_server.cc + src/core/lib/iomgr/tcp_server_custom.cc src/core/lib/iomgr/tcp_server_posix.cc src/core/lib/iomgr/tcp_server_utils_posix_common.cc src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc - src/core/lib/iomgr/tcp_server_uv.cc src/core/lib/iomgr/tcp_server_windows.cc src/core/lib/iomgr/tcp_uv.cc src/core/lib/iomgr/tcp_windows.cc src/core/lib/iomgr/time_averaged_stats.cc + src/core/lib/iomgr/timer.cc + src/core/lib/iomgr/timer_custom.cc src/core/lib/iomgr/timer_generic.cc src/core/lib/iomgr/timer_heap.cc src/core/lib/iomgr/timer_manager.cc @@ -1268,6 +1279,8 @@ add_library(grpc_cronet src/core/lib/iomgr/gethostname_sysconf.cc src/core/lib/iomgr/iocp_windows.cc src/core/lib/iomgr/iomgr.cc + src/core/lib/iomgr/iomgr_custom.cc + src/core/lib/iomgr/iomgr_internal.cc src/core/lib/iomgr/iomgr_posix.cc src/core/lib/iomgr/iomgr_uv.cc src/core/lib/iomgr/iomgr_windows.cc @@ -1276,12 +1289,16 @@ add_library(grpc_cronet src/core/lib/iomgr/lockfree_event.cc src/core/lib/iomgr/network_status_tracker.cc src/core/lib/iomgr/polling_entity.cc - src/core/lib/iomgr/pollset_set_uv.cc + src/core/lib/iomgr/pollset.cc + src/core/lib/iomgr/pollset_custom.cc + src/core/lib/iomgr/pollset_set.cc + src/core/lib/iomgr/pollset_set_custom.cc src/core/lib/iomgr/pollset_set_windows.cc src/core/lib/iomgr/pollset_uv.cc src/core/lib/iomgr/pollset_windows.cc + src/core/lib/iomgr/resolve_address.cc + src/core/lib/iomgr/resolve_address_custom.cc src/core/lib/iomgr/resolve_address_posix.cc - src/core/lib/iomgr/resolve_address_uv.cc src/core/lib/iomgr/resolve_address_windows.cc src/core/lib/iomgr/resource_quota.cc src/core/lib/iomgr/sockaddr_utils.cc @@ -1293,19 +1310,24 @@ add_library(grpc_cronet src/core/lib/iomgr/socket_utils_uv.cc src/core/lib/iomgr/socket_utils_windows.cc src/core/lib/iomgr/socket_windows.cc + src/core/lib/iomgr/tcp_client.cc + src/core/lib/iomgr/tcp_client_custom.cc src/core/lib/iomgr/tcp_client_posix.cc - src/core/lib/iomgr/tcp_client_uv.cc src/core/lib/iomgr/tcp_client_windows.cc + src/core/lib/iomgr/tcp_custom.cc src/core/lib/iomgr/tcp_posix.cc + src/core/lib/iomgr/tcp_server.cc + src/core/lib/iomgr/tcp_server_custom.cc src/core/lib/iomgr/tcp_server_posix.cc src/core/lib/iomgr/tcp_server_utils_posix_common.cc src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc - src/core/lib/iomgr/tcp_server_uv.cc src/core/lib/iomgr/tcp_server_windows.cc src/core/lib/iomgr/tcp_uv.cc src/core/lib/iomgr/tcp_windows.cc src/core/lib/iomgr/time_averaged_stats.cc + src/core/lib/iomgr/timer.cc + src/core/lib/iomgr/timer_custom.cc src/core/lib/iomgr/timer_generic.cc src/core/lib/iomgr/timer_heap.cc src/core/lib/iomgr/timer_manager.cc @@ -1634,6 +1656,8 @@ add_library(grpc_test_util src/core/lib/iomgr/gethostname_sysconf.cc src/core/lib/iomgr/iocp_windows.cc src/core/lib/iomgr/iomgr.cc + src/core/lib/iomgr/iomgr_custom.cc + src/core/lib/iomgr/iomgr_internal.cc src/core/lib/iomgr/iomgr_posix.cc src/core/lib/iomgr/iomgr_uv.cc src/core/lib/iomgr/iomgr_windows.cc @@ -1642,12 +1666,16 @@ add_library(grpc_test_util src/core/lib/iomgr/lockfree_event.cc src/core/lib/iomgr/network_status_tracker.cc src/core/lib/iomgr/polling_entity.cc - src/core/lib/iomgr/pollset_set_uv.cc + src/core/lib/iomgr/pollset.cc + src/core/lib/iomgr/pollset_custom.cc + src/core/lib/iomgr/pollset_set.cc + src/core/lib/iomgr/pollset_set_custom.cc src/core/lib/iomgr/pollset_set_windows.cc src/core/lib/iomgr/pollset_uv.cc src/core/lib/iomgr/pollset_windows.cc + src/core/lib/iomgr/resolve_address.cc + src/core/lib/iomgr/resolve_address_custom.cc src/core/lib/iomgr/resolve_address_posix.cc - src/core/lib/iomgr/resolve_address_uv.cc src/core/lib/iomgr/resolve_address_windows.cc src/core/lib/iomgr/resource_quota.cc src/core/lib/iomgr/sockaddr_utils.cc @@ -1659,19 +1687,24 @@ add_library(grpc_test_util src/core/lib/iomgr/socket_utils_uv.cc src/core/lib/iomgr/socket_utils_windows.cc src/core/lib/iomgr/socket_windows.cc + src/core/lib/iomgr/tcp_client.cc + src/core/lib/iomgr/tcp_client_custom.cc src/core/lib/iomgr/tcp_client_posix.cc - src/core/lib/iomgr/tcp_client_uv.cc src/core/lib/iomgr/tcp_client_windows.cc + src/core/lib/iomgr/tcp_custom.cc src/core/lib/iomgr/tcp_posix.cc + src/core/lib/iomgr/tcp_server.cc + src/core/lib/iomgr/tcp_server_custom.cc src/core/lib/iomgr/tcp_server_posix.cc src/core/lib/iomgr/tcp_server_utils_posix_common.cc src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc - src/core/lib/iomgr/tcp_server_uv.cc src/core/lib/iomgr/tcp_server_windows.cc src/core/lib/iomgr/tcp_uv.cc src/core/lib/iomgr/tcp_windows.cc src/core/lib/iomgr/time_averaged_stats.cc + src/core/lib/iomgr/timer.cc + src/core/lib/iomgr/timer_custom.cc src/core/lib/iomgr/timer_generic.cc src/core/lib/iomgr/timer_heap.cc src/core/lib/iomgr/timer_manager.cc @@ -1923,6 +1956,8 @@ add_library(grpc_test_util_unsecure src/core/lib/iomgr/gethostname_sysconf.cc src/core/lib/iomgr/iocp_windows.cc src/core/lib/iomgr/iomgr.cc + src/core/lib/iomgr/iomgr_custom.cc + src/core/lib/iomgr/iomgr_internal.cc src/core/lib/iomgr/iomgr_posix.cc src/core/lib/iomgr/iomgr_uv.cc src/core/lib/iomgr/iomgr_windows.cc @@ -1931,12 +1966,16 @@ add_library(grpc_test_util_unsecure src/core/lib/iomgr/lockfree_event.cc src/core/lib/iomgr/network_status_tracker.cc src/core/lib/iomgr/polling_entity.cc - src/core/lib/iomgr/pollset_set_uv.cc + src/core/lib/iomgr/pollset.cc + src/core/lib/iomgr/pollset_custom.cc + src/core/lib/iomgr/pollset_set.cc + src/core/lib/iomgr/pollset_set_custom.cc src/core/lib/iomgr/pollset_set_windows.cc src/core/lib/iomgr/pollset_uv.cc src/core/lib/iomgr/pollset_windows.cc + src/core/lib/iomgr/resolve_address.cc + src/core/lib/iomgr/resolve_address_custom.cc src/core/lib/iomgr/resolve_address_posix.cc - src/core/lib/iomgr/resolve_address_uv.cc src/core/lib/iomgr/resolve_address_windows.cc src/core/lib/iomgr/resource_quota.cc src/core/lib/iomgr/sockaddr_utils.cc @@ -1948,19 +1987,24 @@ add_library(grpc_test_util_unsecure src/core/lib/iomgr/socket_utils_uv.cc src/core/lib/iomgr/socket_utils_windows.cc src/core/lib/iomgr/socket_windows.cc + src/core/lib/iomgr/tcp_client.cc + src/core/lib/iomgr/tcp_client_custom.cc src/core/lib/iomgr/tcp_client_posix.cc - src/core/lib/iomgr/tcp_client_uv.cc src/core/lib/iomgr/tcp_client_windows.cc + src/core/lib/iomgr/tcp_custom.cc src/core/lib/iomgr/tcp_posix.cc + src/core/lib/iomgr/tcp_server.cc + src/core/lib/iomgr/tcp_server_custom.cc src/core/lib/iomgr/tcp_server_posix.cc src/core/lib/iomgr/tcp_server_utils_posix_common.cc src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc - src/core/lib/iomgr/tcp_server_uv.cc src/core/lib/iomgr/tcp_server_windows.cc src/core/lib/iomgr/tcp_uv.cc src/core/lib/iomgr/tcp_windows.cc src/core/lib/iomgr/time_averaged_stats.cc + src/core/lib/iomgr/timer.cc + src/core/lib/iomgr/timer_custom.cc src/core/lib/iomgr/timer_generic.cc src/core/lib/iomgr/timer_heap.cc src/core/lib/iomgr/timer_manager.cc @@ -2192,6 +2236,8 @@ add_library(grpc_unsecure src/core/lib/iomgr/gethostname_sysconf.cc src/core/lib/iomgr/iocp_windows.cc src/core/lib/iomgr/iomgr.cc + src/core/lib/iomgr/iomgr_custom.cc + src/core/lib/iomgr/iomgr_internal.cc src/core/lib/iomgr/iomgr_posix.cc src/core/lib/iomgr/iomgr_uv.cc src/core/lib/iomgr/iomgr_windows.cc @@ -2200,12 +2246,16 @@ add_library(grpc_unsecure src/core/lib/iomgr/lockfree_event.cc src/core/lib/iomgr/network_status_tracker.cc src/core/lib/iomgr/polling_entity.cc - src/core/lib/iomgr/pollset_set_uv.cc + src/core/lib/iomgr/pollset.cc + src/core/lib/iomgr/pollset_custom.cc + src/core/lib/iomgr/pollset_set.cc + src/core/lib/iomgr/pollset_set_custom.cc src/core/lib/iomgr/pollset_set_windows.cc src/core/lib/iomgr/pollset_uv.cc src/core/lib/iomgr/pollset_windows.cc + src/core/lib/iomgr/resolve_address.cc + src/core/lib/iomgr/resolve_address_custom.cc src/core/lib/iomgr/resolve_address_posix.cc - src/core/lib/iomgr/resolve_address_uv.cc src/core/lib/iomgr/resolve_address_windows.cc src/core/lib/iomgr/resource_quota.cc src/core/lib/iomgr/sockaddr_utils.cc @@ -2217,19 +2267,24 @@ add_library(grpc_unsecure src/core/lib/iomgr/socket_utils_uv.cc src/core/lib/iomgr/socket_utils_windows.cc src/core/lib/iomgr/socket_windows.cc + src/core/lib/iomgr/tcp_client.cc + src/core/lib/iomgr/tcp_client_custom.cc src/core/lib/iomgr/tcp_client_posix.cc - src/core/lib/iomgr/tcp_client_uv.cc src/core/lib/iomgr/tcp_client_windows.cc + src/core/lib/iomgr/tcp_custom.cc src/core/lib/iomgr/tcp_posix.cc + src/core/lib/iomgr/tcp_server.cc + src/core/lib/iomgr/tcp_server_custom.cc src/core/lib/iomgr/tcp_server_posix.cc src/core/lib/iomgr/tcp_server_utils_posix_common.cc src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc - src/core/lib/iomgr/tcp_server_uv.cc src/core/lib/iomgr/tcp_server_windows.cc src/core/lib/iomgr/tcp_uv.cc src/core/lib/iomgr/tcp_windows.cc src/core/lib/iomgr/time_averaged_stats.cc + src/core/lib/iomgr/timer.cc + src/core/lib/iomgr/timer_custom.cc src/core/lib/iomgr/timer_generic.cc src/core/lib/iomgr/timer_heap.cc src/core/lib/iomgr/timer_manager.cc @@ -2995,6 +3050,8 @@ add_library(grpc++_cronet src/core/lib/iomgr/gethostname_sysconf.cc src/core/lib/iomgr/iocp_windows.cc src/core/lib/iomgr/iomgr.cc + src/core/lib/iomgr/iomgr_custom.cc + src/core/lib/iomgr/iomgr_internal.cc src/core/lib/iomgr/iomgr_posix.cc src/core/lib/iomgr/iomgr_uv.cc src/core/lib/iomgr/iomgr_windows.cc @@ -3003,12 +3060,16 @@ add_library(grpc++_cronet src/core/lib/iomgr/lockfree_event.cc src/core/lib/iomgr/network_status_tracker.cc src/core/lib/iomgr/polling_entity.cc - src/core/lib/iomgr/pollset_set_uv.cc + src/core/lib/iomgr/pollset.cc + src/core/lib/iomgr/pollset_custom.cc + src/core/lib/iomgr/pollset_set.cc + src/core/lib/iomgr/pollset_set_custom.cc src/core/lib/iomgr/pollset_set_windows.cc src/core/lib/iomgr/pollset_uv.cc src/core/lib/iomgr/pollset_windows.cc + src/core/lib/iomgr/resolve_address.cc + src/core/lib/iomgr/resolve_address_custom.cc src/core/lib/iomgr/resolve_address_posix.cc - src/core/lib/iomgr/resolve_address_uv.cc src/core/lib/iomgr/resolve_address_windows.cc src/core/lib/iomgr/resource_quota.cc src/core/lib/iomgr/sockaddr_utils.cc @@ -3020,19 +3081,24 @@ add_library(grpc++_cronet src/core/lib/iomgr/socket_utils_uv.cc src/core/lib/iomgr/socket_utils_windows.cc src/core/lib/iomgr/socket_windows.cc + src/core/lib/iomgr/tcp_client.cc + src/core/lib/iomgr/tcp_client_custom.cc src/core/lib/iomgr/tcp_client_posix.cc - src/core/lib/iomgr/tcp_client_uv.cc src/core/lib/iomgr/tcp_client_windows.cc + src/core/lib/iomgr/tcp_custom.cc src/core/lib/iomgr/tcp_posix.cc + src/core/lib/iomgr/tcp_server.cc + src/core/lib/iomgr/tcp_server_custom.cc src/core/lib/iomgr/tcp_server_posix.cc src/core/lib/iomgr/tcp_server_utils_posix_common.cc src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc - src/core/lib/iomgr/tcp_server_uv.cc src/core/lib/iomgr/tcp_server_windows.cc src/core/lib/iomgr/tcp_uv.cc src/core/lib/iomgr/tcp_windows.cc src/core/lib/iomgr/time_averaged_stats.cc + src/core/lib/iomgr/timer.cc + src/core/lib/iomgr/timer_custom.cc src/core/lib/iomgr/timer_generic.cc src/core/lib/iomgr/timer_heap.cc src/core/lib/iomgr/timer_manager.cc diff --git a/MANIFEST.md b/MANIFEST.md index a0e79e8532..9581e1c993 100644 --- a/MANIFEST.md +++ b/MANIFEST.md @@ -3,10 +3,6 @@ ## Bazel * [grpc.bzl](grpc.bzl) -## Node -* [binding.gyp](binding.gyp) -* [package.json](package.json) - ## Objective-C * [gRPC.podspec](gRPC.podspec) diff --git a/Makefile b/Makefile index 8341fba094..625248ea30 100644 --- a/Makefile +++ b/Makefile @@ -3202,6 +3202,8 @@ LIBGRPC_SRC = \ src/core/lib/iomgr/gethostname_sysconf.cc \ src/core/lib/iomgr/iocp_windows.cc \ src/core/lib/iomgr/iomgr.cc \ + src/core/lib/iomgr/iomgr_custom.cc \ + src/core/lib/iomgr/iomgr_internal.cc \ src/core/lib/iomgr/iomgr_posix.cc \ src/core/lib/iomgr/iomgr_uv.cc \ src/core/lib/iomgr/iomgr_windows.cc \ @@ -3210,12 +3212,16 @@ LIBGRPC_SRC = \ src/core/lib/iomgr/lockfree_event.cc \ src/core/lib/iomgr/network_status_tracker.cc \ src/core/lib/iomgr/polling_entity.cc \ - src/core/lib/iomgr/pollset_set_uv.cc \ + src/core/lib/iomgr/pollset.cc \ + src/core/lib/iomgr/pollset_custom.cc \ + src/core/lib/iomgr/pollset_set.cc \ + src/core/lib/iomgr/pollset_set_custom.cc \ src/core/lib/iomgr/pollset_set_windows.cc \ src/core/lib/iomgr/pollset_uv.cc \ src/core/lib/iomgr/pollset_windows.cc \ + src/core/lib/iomgr/resolve_address.cc \ + src/core/lib/iomgr/resolve_address_custom.cc \ src/core/lib/iomgr/resolve_address_posix.cc \ - src/core/lib/iomgr/resolve_address_uv.cc \ src/core/lib/iomgr/resolve_address_windows.cc \ src/core/lib/iomgr/resource_quota.cc \ src/core/lib/iomgr/sockaddr_utils.cc \ @@ -3227,19 +3233,24 @@ LIBGRPC_SRC = \ src/core/lib/iomgr/socket_utils_uv.cc \ src/core/lib/iomgr/socket_utils_windows.cc \ src/core/lib/iomgr/socket_windows.cc \ + src/core/lib/iomgr/tcp_client.cc \ + src/core/lib/iomgr/tcp_client_custom.cc \ src/core/lib/iomgr/tcp_client_posix.cc \ - src/core/lib/iomgr/tcp_client_uv.cc \ src/core/lib/iomgr/tcp_client_windows.cc \ + src/core/lib/iomgr/tcp_custom.cc \ src/core/lib/iomgr/tcp_posix.cc \ + src/core/lib/iomgr/tcp_server.cc \ + src/core/lib/iomgr/tcp_server_custom.cc \ src/core/lib/iomgr/tcp_server_posix.cc \ src/core/lib/iomgr/tcp_server_utils_posix_common.cc \ src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc \ src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc \ - src/core/lib/iomgr/tcp_server_uv.cc \ src/core/lib/iomgr/tcp_server_windows.cc \ src/core/lib/iomgr/tcp_uv.cc \ src/core/lib/iomgr/tcp_windows.cc \ src/core/lib/iomgr/time_averaged_stats.cc \ + src/core/lib/iomgr/timer.cc \ + src/core/lib/iomgr/timer_custom.cc \ src/core/lib/iomgr/timer_generic.cc \ src/core/lib/iomgr/timer_heap.cc \ src/core/lib/iomgr/timer_manager.cc \ @@ -3579,6 +3590,8 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/iomgr/gethostname_sysconf.cc \ src/core/lib/iomgr/iocp_windows.cc \ src/core/lib/iomgr/iomgr.cc \ + src/core/lib/iomgr/iomgr_custom.cc \ + src/core/lib/iomgr/iomgr_internal.cc \ src/core/lib/iomgr/iomgr_posix.cc \ src/core/lib/iomgr/iomgr_uv.cc \ src/core/lib/iomgr/iomgr_windows.cc \ @@ -3587,12 +3600,16 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/iomgr/lockfree_event.cc \ src/core/lib/iomgr/network_status_tracker.cc \ src/core/lib/iomgr/polling_entity.cc \ - src/core/lib/iomgr/pollset_set_uv.cc \ + src/core/lib/iomgr/pollset.cc \ + src/core/lib/iomgr/pollset_custom.cc \ + src/core/lib/iomgr/pollset_set.cc \ + src/core/lib/iomgr/pollset_set_custom.cc \ src/core/lib/iomgr/pollset_set_windows.cc \ src/core/lib/iomgr/pollset_uv.cc \ src/core/lib/iomgr/pollset_windows.cc \ + src/core/lib/iomgr/resolve_address.cc \ + src/core/lib/iomgr/resolve_address_custom.cc \ src/core/lib/iomgr/resolve_address_posix.cc \ - src/core/lib/iomgr/resolve_address_uv.cc \ src/core/lib/iomgr/resolve_address_windows.cc \ src/core/lib/iomgr/resource_quota.cc \ src/core/lib/iomgr/sockaddr_utils.cc \ @@ -3604,19 +3621,24 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/iomgr/socket_utils_uv.cc \ src/core/lib/iomgr/socket_utils_windows.cc \ src/core/lib/iomgr/socket_windows.cc \ + src/core/lib/iomgr/tcp_client.cc \ + src/core/lib/iomgr/tcp_client_custom.cc \ src/core/lib/iomgr/tcp_client_posix.cc \ - src/core/lib/iomgr/tcp_client_uv.cc \ src/core/lib/iomgr/tcp_client_windows.cc \ + src/core/lib/iomgr/tcp_custom.cc \ src/core/lib/iomgr/tcp_posix.cc \ + src/core/lib/iomgr/tcp_server.cc \ + src/core/lib/iomgr/tcp_server_custom.cc \ src/core/lib/iomgr/tcp_server_posix.cc \ src/core/lib/iomgr/tcp_server_utils_posix_common.cc \ src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc \ src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc \ - src/core/lib/iomgr/tcp_server_uv.cc \ src/core/lib/iomgr/tcp_server_windows.cc \ src/core/lib/iomgr/tcp_uv.cc \ src/core/lib/iomgr/tcp_windows.cc \ src/core/lib/iomgr/time_averaged_stats.cc \ + src/core/lib/iomgr/timer.cc \ + src/core/lib/iomgr/timer_custom.cc \ src/core/lib/iomgr/timer_generic.cc \ src/core/lib/iomgr/timer_heap.cc \ src/core/lib/iomgr/timer_manager.cc \ @@ -3946,6 +3968,8 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/iomgr/gethostname_sysconf.cc \ src/core/lib/iomgr/iocp_windows.cc \ src/core/lib/iomgr/iomgr.cc \ + src/core/lib/iomgr/iomgr_custom.cc \ + src/core/lib/iomgr/iomgr_internal.cc \ src/core/lib/iomgr/iomgr_posix.cc \ src/core/lib/iomgr/iomgr_uv.cc \ src/core/lib/iomgr/iomgr_windows.cc \ @@ -3954,12 +3978,16 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/iomgr/lockfree_event.cc \ src/core/lib/iomgr/network_status_tracker.cc \ src/core/lib/iomgr/polling_entity.cc \ - src/core/lib/iomgr/pollset_set_uv.cc \ + src/core/lib/iomgr/pollset.cc \ + src/core/lib/iomgr/pollset_custom.cc \ + src/core/lib/iomgr/pollset_set.cc \ + src/core/lib/iomgr/pollset_set_custom.cc \ src/core/lib/iomgr/pollset_set_windows.cc \ src/core/lib/iomgr/pollset_uv.cc \ src/core/lib/iomgr/pollset_windows.cc \ + src/core/lib/iomgr/resolve_address.cc \ + src/core/lib/iomgr/resolve_address_custom.cc \ src/core/lib/iomgr/resolve_address_posix.cc \ - src/core/lib/iomgr/resolve_address_uv.cc \ src/core/lib/iomgr/resolve_address_windows.cc \ src/core/lib/iomgr/resource_quota.cc \ src/core/lib/iomgr/sockaddr_utils.cc \ @@ -3971,19 +3999,24 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/iomgr/socket_utils_uv.cc \ src/core/lib/iomgr/socket_utils_windows.cc \ src/core/lib/iomgr/socket_windows.cc \ + src/core/lib/iomgr/tcp_client.cc \ + src/core/lib/iomgr/tcp_client_custom.cc \ src/core/lib/iomgr/tcp_client_posix.cc \ - src/core/lib/iomgr/tcp_client_uv.cc \ src/core/lib/iomgr/tcp_client_windows.cc \ + src/core/lib/iomgr/tcp_custom.cc \ src/core/lib/iomgr/tcp_posix.cc \ + src/core/lib/iomgr/tcp_server.cc \ + src/core/lib/iomgr/tcp_server_custom.cc \ src/core/lib/iomgr/tcp_server_posix.cc \ src/core/lib/iomgr/tcp_server_utils_posix_common.cc \ src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc \ src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc \ - src/core/lib/iomgr/tcp_server_uv.cc \ src/core/lib/iomgr/tcp_server_windows.cc \ src/core/lib/iomgr/tcp_uv.cc \ src/core/lib/iomgr/tcp_windows.cc \ src/core/lib/iomgr/time_averaged_stats.cc \ + src/core/lib/iomgr/timer.cc \ + src/core/lib/iomgr/timer_custom.cc \ src/core/lib/iomgr/timer_generic.cc \ src/core/lib/iomgr/timer_heap.cc \ src/core/lib/iomgr/timer_manager.cc \ @@ -4228,6 +4261,8 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ src/core/lib/iomgr/gethostname_sysconf.cc \ src/core/lib/iomgr/iocp_windows.cc \ src/core/lib/iomgr/iomgr.cc \ + src/core/lib/iomgr/iomgr_custom.cc \ + src/core/lib/iomgr/iomgr_internal.cc \ src/core/lib/iomgr/iomgr_posix.cc \ src/core/lib/iomgr/iomgr_uv.cc \ src/core/lib/iomgr/iomgr_windows.cc \ @@ -4236,12 +4271,16 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ src/core/lib/iomgr/lockfree_event.cc \ src/core/lib/iomgr/network_status_tracker.cc \ src/core/lib/iomgr/polling_entity.cc \ - src/core/lib/iomgr/pollset_set_uv.cc \ + src/core/lib/iomgr/pollset.cc \ + src/core/lib/iomgr/pollset_custom.cc \ + src/core/lib/iomgr/pollset_set.cc \ + src/core/lib/iomgr/pollset_set_custom.cc \ src/core/lib/iomgr/pollset_set_windows.cc \ src/core/lib/iomgr/pollset_uv.cc \ src/core/lib/iomgr/pollset_windows.cc \ + src/core/lib/iomgr/resolve_address.cc \ + src/core/lib/iomgr/resolve_address_custom.cc \ src/core/lib/iomgr/resolve_address_posix.cc \ - src/core/lib/iomgr/resolve_address_uv.cc \ src/core/lib/iomgr/resolve_address_windows.cc \ src/core/lib/iomgr/resource_quota.cc \ src/core/lib/iomgr/sockaddr_utils.cc \ @@ -4253,19 +4292,24 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ src/core/lib/iomgr/socket_utils_uv.cc \ src/core/lib/iomgr/socket_utils_windows.cc \ src/core/lib/iomgr/socket_windows.cc \ + src/core/lib/iomgr/tcp_client.cc \ + src/core/lib/iomgr/tcp_client_custom.cc \ src/core/lib/iomgr/tcp_client_posix.cc \ - src/core/lib/iomgr/tcp_client_uv.cc \ src/core/lib/iomgr/tcp_client_windows.cc \ + src/core/lib/iomgr/tcp_custom.cc \ src/core/lib/iomgr/tcp_posix.cc \ + src/core/lib/iomgr/tcp_server.cc \ + src/core/lib/iomgr/tcp_server_custom.cc \ src/core/lib/iomgr/tcp_server_posix.cc \ src/core/lib/iomgr/tcp_server_utils_posix_common.cc \ src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc \ src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc \ - src/core/lib/iomgr/tcp_server_uv.cc \ src/core/lib/iomgr/tcp_server_windows.cc \ src/core/lib/iomgr/tcp_uv.cc \ src/core/lib/iomgr/tcp_windows.cc \ src/core/lib/iomgr/time_averaged_stats.cc \ + src/core/lib/iomgr/timer.cc \ + src/core/lib/iomgr/timer_custom.cc \ src/core/lib/iomgr/timer_generic.cc \ src/core/lib/iomgr/timer_heap.cc \ src/core/lib/iomgr/timer_manager.cc \ @@ -4477,6 +4521,8 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/iomgr/gethostname_sysconf.cc \ src/core/lib/iomgr/iocp_windows.cc \ src/core/lib/iomgr/iomgr.cc \ + src/core/lib/iomgr/iomgr_custom.cc \ + src/core/lib/iomgr/iomgr_internal.cc \ src/core/lib/iomgr/iomgr_posix.cc \ src/core/lib/iomgr/iomgr_uv.cc \ src/core/lib/iomgr/iomgr_windows.cc \ @@ -4485,12 +4531,16 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/iomgr/lockfree_event.cc \ src/core/lib/iomgr/network_status_tracker.cc \ src/core/lib/iomgr/polling_entity.cc \ - src/core/lib/iomgr/pollset_set_uv.cc \ + src/core/lib/iomgr/pollset.cc \ + src/core/lib/iomgr/pollset_custom.cc \ + src/core/lib/iomgr/pollset_set.cc \ + src/core/lib/iomgr/pollset_set_custom.cc \ src/core/lib/iomgr/pollset_set_windows.cc \ src/core/lib/iomgr/pollset_uv.cc \ src/core/lib/iomgr/pollset_windows.cc \ + src/core/lib/iomgr/resolve_address.cc \ + src/core/lib/iomgr/resolve_address_custom.cc \ src/core/lib/iomgr/resolve_address_posix.cc \ - src/core/lib/iomgr/resolve_address_uv.cc \ src/core/lib/iomgr/resolve_address_windows.cc \ src/core/lib/iomgr/resource_quota.cc \ src/core/lib/iomgr/sockaddr_utils.cc \ @@ -4502,19 +4552,24 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/iomgr/socket_utils_uv.cc \ src/core/lib/iomgr/socket_utils_windows.cc \ src/core/lib/iomgr/socket_windows.cc \ + src/core/lib/iomgr/tcp_client.cc \ + src/core/lib/iomgr/tcp_client_custom.cc \ src/core/lib/iomgr/tcp_client_posix.cc \ - src/core/lib/iomgr/tcp_client_uv.cc \ src/core/lib/iomgr/tcp_client_windows.cc \ + src/core/lib/iomgr/tcp_custom.cc \ src/core/lib/iomgr/tcp_posix.cc \ + src/core/lib/iomgr/tcp_server.cc \ + src/core/lib/iomgr/tcp_server_custom.cc \ src/core/lib/iomgr/tcp_server_posix.cc \ src/core/lib/iomgr/tcp_server_utils_posix_common.cc \ src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc \ src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc \ - src/core/lib/iomgr/tcp_server_uv.cc \ src/core/lib/iomgr/tcp_server_windows.cc \ src/core/lib/iomgr/tcp_uv.cc \ src/core/lib/iomgr/tcp_windows.cc \ src/core/lib/iomgr/time_averaged_stats.cc \ + src/core/lib/iomgr/timer.cc \ + src/core/lib/iomgr/timer_custom.cc \ src/core/lib/iomgr/timer_generic.cc \ src/core/lib/iomgr/timer_heap.cc \ src/core/lib/iomgr/timer_manager.cc \ @@ -5279,6 +5334,8 @@ LIBGRPC++_CRONET_SRC = \ src/core/lib/iomgr/gethostname_sysconf.cc \ src/core/lib/iomgr/iocp_windows.cc \ src/core/lib/iomgr/iomgr.cc \ + src/core/lib/iomgr/iomgr_custom.cc \ + src/core/lib/iomgr/iomgr_internal.cc \ src/core/lib/iomgr/iomgr_posix.cc \ src/core/lib/iomgr/iomgr_uv.cc \ src/core/lib/iomgr/iomgr_windows.cc \ @@ -5287,12 +5344,16 @@ LIBGRPC++_CRONET_SRC = \ src/core/lib/iomgr/lockfree_event.cc \ src/core/lib/iomgr/network_status_tracker.cc \ src/core/lib/iomgr/polling_entity.cc \ - src/core/lib/iomgr/pollset_set_uv.cc \ + src/core/lib/iomgr/pollset.cc \ + src/core/lib/iomgr/pollset_custom.cc \ + src/core/lib/iomgr/pollset_set.cc \ + src/core/lib/iomgr/pollset_set_custom.cc \ src/core/lib/iomgr/pollset_set_windows.cc \ src/core/lib/iomgr/pollset_uv.cc \ src/core/lib/iomgr/pollset_windows.cc \ + src/core/lib/iomgr/resolve_address.cc \ + src/core/lib/iomgr/resolve_address_custom.cc \ src/core/lib/iomgr/resolve_address_posix.cc \ - src/core/lib/iomgr/resolve_address_uv.cc \ src/core/lib/iomgr/resolve_address_windows.cc \ src/core/lib/iomgr/resource_quota.cc \ src/core/lib/iomgr/sockaddr_utils.cc \ @@ -5304,19 +5365,24 @@ LIBGRPC++_CRONET_SRC = \ src/core/lib/iomgr/socket_utils_uv.cc \ src/core/lib/iomgr/socket_utils_windows.cc \ src/core/lib/iomgr/socket_windows.cc \ + src/core/lib/iomgr/tcp_client.cc \ + src/core/lib/iomgr/tcp_client_custom.cc \ src/core/lib/iomgr/tcp_client_posix.cc \ - src/core/lib/iomgr/tcp_client_uv.cc \ src/core/lib/iomgr/tcp_client_windows.cc \ + src/core/lib/iomgr/tcp_custom.cc \ src/core/lib/iomgr/tcp_posix.cc \ + src/core/lib/iomgr/tcp_server.cc \ + src/core/lib/iomgr/tcp_server_custom.cc \ src/core/lib/iomgr/tcp_server_posix.cc \ src/core/lib/iomgr/tcp_server_utils_posix_common.cc \ src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc \ src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc \ - src/core/lib/iomgr/tcp_server_uv.cc \ src/core/lib/iomgr/tcp_server_windows.cc \ src/core/lib/iomgr/tcp_uv.cc \ src/core/lib/iomgr/tcp_windows.cc \ src/core/lib/iomgr/time_averaged_stats.cc \ + src/core/lib/iomgr/timer.cc \ + src/core/lib/iomgr/timer_custom.cc \ src/core/lib/iomgr/timer_generic.cc \ src/core/lib/iomgr/timer_heap.cc \ src/core/lib/iomgr/timer_manager.cc \ diff --git a/build.yaml b/build.yaml index 3bb85a88c9..02a1e6186e 100644 --- a/build.yaml +++ b/build.yaml @@ -269,6 +269,8 @@ filegroups: - src/core/lib/iomgr/gethostname_sysconf.cc - src/core/lib/iomgr/iocp_windows.cc - src/core/lib/iomgr/iomgr.cc + - src/core/lib/iomgr/iomgr_custom.cc + - src/core/lib/iomgr/iomgr_internal.cc - src/core/lib/iomgr/iomgr_posix.cc - src/core/lib/iomgr/iomgr_uv.cc - src/core/lib/iomgr/iomgr_windows.cc @@ -277,12 +279,16 @@ filegroups: - src/core/lib/iomgr/lockfree_event.cc - src/core/lib/iomgr/network_status_tracker.cc - src/core/lib/iomgr/polling_entity.cc - - src/core/lib/iomgr/pollset_set_uv.cc + - src/core/lib/iomgr/pollset.cc + - src/core/lib/iomgr/pollset_custom.cc + - src/core/lib/iomgr/pollset_set.cc + - src/core/lib/iomgr/pollset_set_custom.cc - src/core/lib/iomgr/pollset_set_windows.cc - src/core/lib/iomgr/pollset_uv.cc - src/core/lib/iomgr/pollset_windows.cc + - src/core/lib/iomgr/resolve_address.cc + - src/core/lib/iomgr/resolve_address_custom.cc - src/core/lib/iomgr/resolve_address_posix.cc - - src/core/lib/iomgr/resolve_address_uv.cc - src/core/lib/iomgr/resolve_address_windows.cc - src/core/lib/iomgr/resource_quota.cc - src/core/lib/iomgr/sockaddr_utils.cc @@ -294,19 +300,24 @@ filegroups: - src/core/lib/iomgr/socket_utils_uv.cc - src/core/lib/iomgr/socket_utils_windows.cc - src/core/lib/iomgr/socket_windows.cc + - src/core/lib/iomgr/tcp_client.cc + - src/core/lib/iomgr/tcp_client_custom.cc - src/core/lib/iomgr/tcp_client_posix.cc - - src/core/lib/iomgr/tcp_client_uv.cc - src/core/lib/iomgr/tcp_client_windows.cc + - src/core/lib/iomgr/tcp_custom.cc - src/core/lib/iomgr/tcp_posix.cc + - src/core/lib/iomgr/tcp_server.cc + - src/core/lib/iomgr/tcp_server_custom.cc - src/core/lib/iomgr/tcp_server_posix.cc - src/core/lib/iomgr/tcp_server_utils_posix_common.cc - src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc - src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc - - src/core/lib/iomgr/tcp_server_uv.cc - src/core/lib/iomgr/tcp_server_windows.cc - src/core/lib/iomgr/tcp_uv.cc - src/core/lib/iomgr/tcp_windows.cc - src/core/lib/iomgr/time_averaged_stats.cc + - src/core/lib/iomgr/timer.cc + - src/core/lib/iomgr/timer_custom.cc - src/core/lib/iomgr/timer_generic.cc - src/core/lib/iomgr/timer_heap.cc - src/core/lib/iomgr/timer_manager.cc @@ -427,9 +438,9 @@ filegroups: - src/core/lib/iomgr/gethostname.h - src/core/lib/iomgr/iocp_windows.h - src/core/lib/iomgr/iomgr.h + - src/core/lib/iomgr/iomgr_custom.h - src/core/lib/iomgr/iomgr_internal.h - src/core/lib/iomgr/iomgr_posix.h - - src/core/lib/iomgr/iomgr_uv.h - src/core/lib/iomgr/is_epollexclusive_available.h - src/core/lib/iomgr/load_file.h - src/core/lib/iomgr/lockfree_event.h @@ -437,14 +448,17 @@ filegroups: - src/core/lib/iomgr/network_status_tracker.h - src/core/lib/iomgr/polling_entity.h - src/core/lib/iomgr/pollset.h + - src/core/lib/iomgr/pollset_custom.h - src/core/lib/iomgr/pollset_set.h + - src/core/lib/iomgr/pollset_set_custom.h - src/core/lib/iomgr/pollset_set_windows.h - - src/core/lib/iomgr/pollset_uv.h - src/core/lib/iomgr/pollset_windows.h - src/core/lib/iomgr/port.h - src/core/lib/iomgr/resolve_address.h + - src/core/lib/iomgr/resolve_address_custom.h - src/core/lib/iomgr/resource_quota.h - src/core/lib/iomgr/sockaddr.h + - src/core/lib/iomgr/sockaddr_custom.h - src/core/lib/iomgr/sockaddr_posix.h - src/core/lib/iomgr/sockaddr_utils.h - src/core/lib/iomgr/sockaddr_windows.h @@ -456,17 +470,16 @@ filegroups: - src/core/lib/iomgr/sys_epoll_wrapper.h - src/core/lib/iomgr/tcp_client.h - src/core/lib/iomgr/tcp_client_posix.h + - src/core/lib/iomgr/tcp_custom.h - src/core/lib/iomgr/tcp_posix.h - src/core/lib/iomgr/tcp_server.h - src/core/lib/iomgr/tcp_server_utils_posix.h - - src/core/lib/iomgr/tcp_uv.h - src/core/lib/iomgr/tcp_windows.h - src/core/lib/iomgr/time_averaged_stats.h - src/core/lib/iomgr/timer.h - - src/core/lib/iomgr/timer_generic.h + - src/core/lib/iomgr/timer_custom.h - src/core/lib/iomgr/timer_heap.h - src/core/lib/iomgr/timer_manager.h - - src/core/lib/iomgr/timer_uv.h - src/core/lib/iomgr/udp_server.h - src/core/lib/iomgr/unix_sockets_posix.h - src/core/lib/iomgr/wakeup_fd_cv.h diff --git a/config.m4 b/config.m4 index 7270051b0b..2f17d0c4b7 100644 --- a/config.m4 +++ b/config.m4 @@ -121,6 +121,8 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/iomgr/gethostname_sysconf.cc \ src/core/lib/iomgr/iocp_windows.cc \ src/core/lib/iomgr/iomgr.cc \ + src/core/lib/iomgr/iomgr_custom.cc \ + src/core/lib/iomgr/iomgr_internal.cc \ src/core/lib/iomgr/iomgr_posix.cc \ src/core/lib/iomgr/iomgr_uv.cc \ src/core/lib/iomgr/iomgr_windows.cc \ @@ -129,12 +131,16 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/iomgr/lockfree_event.cc \ src/core/lib/iomgr/network_status_tracker.cc \ src/core/lib/iomgr/polling_entity.cc \ - src/core/lib/iomgr/pollset_set_uv.cc \ + src/core/lib/iomgr/pollset.cc \ + src/core/lib/iomgr/pollset_custom.cc \ + src/core/lib/iomgr/pollset_set.cc \ + src/core/lib/iomgr/pollset_set_custom.cc \ src/core/lib/iomgr/pollset_set_windows.cc \ src/core/lib/iomgr/pollset_uv.cc \ src/core/lib/iomgr/pollset_windows.cc \ + src/core/lib/iomgr/resolve_address.cc \ + src/core/lib/iomgr/resolve_address_custom.cc \ src/core/lib/iomgr/resolve_address_posix.cc \ - src/core/lib/iomgr/resolve_address_uv.cc \ src/core/lib/iomgr/resolve_address_windows.cc \ src/core/lib/iomgr/resource_quota.cc \ src/core/lib/iomgr/sockaddr_utils.cc \ @@ -146,19 +152,24 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/iomgr/socket_utils_uv.cc \ src/core/lib/iomgr/socket_utils_windows.cc \ src/core/lib/iomgr/socket_windows.cc \ + src/core/lib/iomgr/tcp_client.cc \ + src/core/lib/iomgr/tcp_client_custom.cc \ src/core/lib/iomgr/tcp_client_posix.cc \ - src/core/lib/iomgr/tcp_client_uv.cc \ src/core/lib/iomgr/tcp_client_windows.cc \ + src/core/lib/iomgr/tcp_custom.cc \ src/core/lib/iomgr/tcp_posix.cc \ + src/core/lib/iomgr/tcp_server.cc \ + src/core/lib/iomgr/tcp_server_custom.cc \ src/core/lib/iomgr/tcp_server_posix.cc \ src/core/lib/iomgr/tcp_server_utils_posix_common.cc \ src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc \ src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc \ - src/core/lib/iomgr/tcp_server_uv.cc \ src/core/lib/iomgr/tcp_server_windows.cc \ src/core/lib/iomgr/tcp_uv.cc \ src/core/lib/iomgr/tcp_windows.cc \ src/core/lib/iomgr/time_averaged_stats.cc \ + src/core/lib/iomgr/timer.cc \ + src/core/lib/iomgr/timer_custom.cc \ src/core/lib/iomgr/timer_generic.cc \ src/core/lib/iomgr/timer_heap.cc \ src/core/lib/iomgr/timer_manager.cc \ diff --git a/config.w32 b/config.w32 index d73acc1118..78f2fe079d 100644 --- a/config.w32 +++ b/config.w32 @@ -98,6 +98,8 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\iomgr\\gethostname_sysconf.cc " + "src\\core\\lib\\iomgr\\iocp_windows.cc " + "src\\core\\lib\\iomgr\\iomgr.cc " + + "src\\core\\lib\\iomgr\\iomgr_custom.cc " + + "src\\core\\lib\\iomgr\\iomgr_internal.cc " + "src\\core\\lib\\iomgr\\iomgr_posix.cc " + "src\\core\\lib\\iomgr\\iomgr_uv.cc " + "src\\core\\lib\\iomgr\\iomgr_windows.cc " + @@ -106,12 +108,16 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\iomgr\\lockfree_event.cc " + "src\\core\\lib\\iomgr\\network_status_tracker.cc " + "src\\core\\lib\\iomgr\\polling_entity.cc " + - "src\\core\\lib\\iomgr\\pollset_set_uv.cc " + + "src\\core\\lib\\iomgr\\pollset.cc " + + "src\\core\\lib\\iomgr\\pollset_custom.cc " + + "src\\core\\lib\\iomgr\\pollset_set.cc " + + "src\\core\\lib\\iomgr\\pollset_set_custom.cc " + "src\\core\\lib\\iomgr\\pollset_set_windows.cc " + "src\\core\\lib\\iomgr\\pollset_uv.cc " + "src\\core\\lib\\iomgr\\pollset_windows.cc " + + "src\\core\\lib\\iomgr\\resolve_address.cc " + + "src\\core\\lib\\iomgr\\resolve_address_custom.cc " + "src\\core\\lib\\iomgr\\resolve_address_posix.cc " + - "src\\core\\lib\\iomgr\\resolve_address_uv.cc " + "src\\core\\lib\\iomgr\\resolve_address_windows.cc " + "src\\core\\lib\\iomgr\\resource_quota.cc " + "src\\core\\lib\\iomgr\\sockaddr_utils.cc " + @@ -123,19 +129,24 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\iomgr\\socket_utils_uv.cc " + "src\\core\\lib\\iomgr\\socket_utils_windows.cc " + "src\\core\\lib\\iomgr\\socket_windows.cc " + + "src\\core\\lib\\iomgr\\tcp_client.cc " + + "src\\core\\lib\\iomgr\\tcp_client_custom.cc " + "src\\core\\lib\\iomgr\\tcp_client_posix.cc " + - "src\\core\\lib\\iomgr\\tcp_client_uv.cc " + "src\\core\\lib\\iomgr\\tcp_client_windows.cc " + + "src\\core\\lib\\iomgr\\tcp_custom.cc " + "src\\core\\lib\\iomgr\\tcp_posix.cc " + + "src\\core\\lib\\iomgr\\tcp_server.cc " + + "src\\core\\lib\\iomgr\\tcp_server_custom.cc " + "src\\core\\lib\\iomgr\\tcp_server_posix.cc " + "src\\core\\lib\\iomgr\\tcp_server_utils_posix_common.cc " + "src\\core\\lib\\iomgr\\tcp_server_utils_posix_ifaddrs.cc " + "src\\core\\lib\\iomgr\\tcp_server_utils_posix_noifaddrs.cc " + - "src\\core\\lib\\iomgr\\tcp_server_uv.cc " + "src\\core\\lib\\iomgr\\tcp_server_windows.cc " + "src\\core\\lib\\iomgr\\tcp_uv.cc " + "src\\core\\lib\\iomgr\\tcp_windows.cc " + "src\\core\\lib\\iomgr\\time_averaged_stats.cc " + + "src\\core\\lib\\iomgr\\timer.cc " + + "src\\core\\lib\\iomgr\\timer_custom.cc " + "src\\core\\lib\\iomgr\\timer_generic.cc " + "src\\core\\lib\\iomgr\\timer_heap.cc " + "src\\core\\lib\\iomgr\\timer_manager.cc " + diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 65a5dc66b4..e1282611b0 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -382,9 +382,9 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/gethostname.h', 'src/core/lib/iomgr/iocp_windows.h', 'src/core/lib/iomgr/iomgr.h', + 'src/core/lib/iomgr/iomgr_custom.h', 'src/core/lib/iomgr/iomgr_internal.h', 'src/core/lib/iomgr/iomgr_posix.h', - 'src/core/lib/iomgr/iomgr_uv.h', 'src/core/lib/iomgr/is_epollexclusive_available.h', 'src/core/lib/iomgr/load_file.h', 'src/core/lib/iomgr/lockfree_event.h', @@ -392,14 +392,17 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/network_status_tracker.h', 'src/core/lib/iomgr/polling_entity.h', 'src/core/lib/iomgr/pollset.h', + 'src/core/lib/iomgr/pollset_custom.h', 'src/core/lib/iomgr/pollset_set.h', + 'src/core/lib/iomgr/pollset_set_custom.h', 'src/core/lib/iomgr/pollset_set_windows.h', - 'src/core/lib/iomgr/pollset_uv.h', 'src/core/lib/iomgr/pollset_windows.h', 'src/core/lib/iomgr/port.h', 'src/core/lib/iomgr/resolve_address.h', + 'src/core/lib/iomgr/resolve_address_custom.h', 'src/core/lib/iomgr/resource_quota.h', 'src/core/lib/iomgr/sockaddr.h', + 'src/core/lib/iomgr/sockaddr_custom.h', 'src/core/lib/iomgr/sockaddr_posix.h', 'src/core/lib/iomgr/sockaddr_utils.h', 'src/core/lib/iomgr/sockaddr_windows.h', @@ -411,17 +414,16 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/sys_epoll_wrapper.h', 'src/core/lib/iomgr/tcp_client.h', 'src/core/lib/iomgr/tcp_client_posix.h', + 'src/core/lib/iomgr/tcp_custom.h', 'src/core/lib/iomgr/tcp_posix.h', 'src/core/lib/iomgr/tcp_server.h', 'src/core/lib/iomgr/tcp_server_utils_posix.h', - 'src/core/lib/iomgr/tcp_uv.h', 'src/core/lib/iomgr/tcp_windows.h', 'src/core/lib/iomgr/time_averaged_stats.h', 'src/core/lib/iomgr/timer.h', - 'src/core/lib/iomgr/timer_generic.h', + 'src/core/lib/iomgr/timer_custom.h', 'src/core/lib/iomgr/timer_heap.h', 'src/core/lib/iomgr/timer_manager.h', - 'src/core/lib/iomgr/timer_uv.h', 'src/core/lib/iomgr/udp_server.h', 'src/core/lib/iomgr/unix_sockets_posix.h', 'src/core/lib/iomgr/wakeup_fd_cv.h', @@ -561,9 +563,9 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/gethostname.h', 'src/core/lib/iomgr/iocp_windows.h', 'src/core/lib/iomgr/iomgr.h', + 'src/core/lib/iomgr/iomgr_custom.h', 'src/core/lib/iomgr/iomgr_internal.h', 'src/core/lib/iomgr/iomgr_posix.h', - 'src/core/lib/iomgr/iomgr_uv.h', 'src/core/lib/iomgr/is_epollexclusive_available.h', 'src/core/lib/iomgr/load_file.h', 'src/core/lib/iomgr/lockfree_event.h', @@ -571,14 +573,17 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/network_status_tracker.h', 'src/core/lib/iomgr/polling_entity.h', 'src/core/lib/iomgr/pollset.h', + 'src/core/lib/iomgr/pollset_custom.h', 'src/core/lib/iomgr/pollset_set.h', + 'src/core/lib/iomgr/pollset_set_custom.h', 'src/core/lib/iomgr/pollset_set_windows.h', - 'src/core/lib/iomgr/pollset_uv.h', 'src/core/lib/iomgr/pollset_windows.h', 'src/core/lib/iomgr/port.h', 'src/core/lib/iomgr/resolve_address.h', + 'src/core/lib/iomgr/resolve_address_custom.h', 'src/core/lib/iomgr/resource_quota.h', 'src/core/lib/iomgr/sockaddr.h', + 'src/core/lib/iomgr/sockaddr_custom.h', 'src/core/lib/iomgr/sockaddr_posix.h', 'src/core/lib/iomgr/sockaddr_utils.h', 'src/core/lib/iomgr/sockaddr_windows.h', @@ -590,17 +595,16 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/sys_epoll_wrapper.h', 'src/core/lib/iomgr/tcp_client.h', 'src/core/lib/iomgr/tcp_client_posix.h', + 'src/core/lib/iomgr/tcp_custom.h', 'src/core/lib/iomgr/tcp_posix.h', 'src/core/lib/iomgr/tcp_server.h', 'src/core/lib/iomgr/tcp_server_utils_posix.h', - 'src/core/lib/iomgr/tcp_uv.h', 'src/core/lib/iomgr/tcp_windows.h', 'src/core/lib/iomgr/time_averaged_stats.h', 'src/core/lib/iomgr/timer.h', - 'src/core/lib/iomgr/timer_generic.h', + 'src/core/lib/iomgr/timer_custom.h', 'src/core/lib/iomgr/timer_heap.h', 'src/core/lib/iomgr/timer_manager.h', - 'src/core/lib/iomgr/timer_uv.h', 'src/core/lib/iomgr/udp_server.h', 'src/core/lib/iomgr/unix_sockets_posix.h', 'src/core/lib/iomgr/wakeup_fd_cv.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 72020d2d10..39433ff819 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -393,9 +393,9 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/gethostname.h', 'src/core/lib/iomgr/iocp_windows.h', 'src/core/lib/iomgr/iomgr.h', + 'src/core/lib/iomgr/iomgr_custom.h', 'src/core/lib/iomgr/iomgr_internal.h', 'src/core/lib/iomgr/iomgr_posix.h', - 'src/core/lib/iomgr/iomgr_uv.h', 'src/core/lib/iomgr/is_epollexclusive_available.h', 'src/core/lib/iomgr/load_file.h', 'src/core/lib/iomgr/lockfree_event.h', @@ -403,14 +403,17 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/network_status_tracker.h', 'src/core/lib/iomgr/polling_entity.h', 'src/core/lib/iomgr/pollset.h', + 'src/core/lib/iomgr/pollset_custom.h', 'src/core/lib/iomgr/pollset_set.h', + 'src/core/lib/iomgr/pollset_set_custom.h', 'src/core/lib/iomgr/pollset_set_windows.h', - 'src/core/lib/iomgr/pollset_uv.h', 'src/core/lib/iomgr/pollset_windows.h', 'src/core/lib/iomgr/port.h', 'src/core/lib/iomgr/resolve_address.h', + 'src/core/lib/iomgr/resolve_address_custom.h', 'src/core/lib/iomgr/resource_quota.h', 'src/core/lib/iomgr/sockaddr.h', + 'src/core/lib/iomgr/sockaddr_custom.h', 'src/core/lib/iomgr/sockaddr_posix.h', 'src/core/lib/iomgr/sockaddr_utils.h', 'src/core/lib/iomgr/sockaddr_windows.h', @@ -422,17 +425,16 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/sys_epoll_wrapper.h', 'src/core/lib/iomgr/tcp_client.h', 'src/core/lib/iomgr/tcp_client_posix.h', + 'src/core/lib/iomgr/tcp_custom.h', 'src/core/lib/iomgr/tcp_posix.h', 'src/core/lib/iomgr/tcp_server.h', 'src/core/lib/iomgr/tcp_server_utils_posix.h', - 'src/core/lib/iomgr/tcp_uv.h', 'src/core/lib/iomgr/tcp_windows.h', 'src/core/lib/iomgr/time_averaged_stats.h', 'src/core/lib/iomgr/timer.h', - 'src/core/lib/iomgr/timer_generic.h', + 'src/core/lib/iomgr/timer_custom.h', 'src/core/lib/iomgr/timer_heap.h', 'src/core/lib/iomgr/timer_manager.h', - 'src/core/lib/iomgr/timer_uv.h', 'src/core/lib/iomgr/udp_server.h', 'src/core/lib/iomgr/unix_sockets_posix.h', 'src/core/lib/iomgr/wakeup_fd_cv.h', @@ -535,6 +537,8 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/gethostname_sysconf.cc', 'src/core/lib/iomgr/iocp_windows.cc', 'src/core/lib/iomgr/iomgr.cc', + 'src/core/lib/iomgr/iomgr_custom.cc', + 'src/core/lib/iomgr/iomgr_internal.cc', 'src/core/lib/iomgr/iomgr_posix.cc', 'src/core/lib/iomgr/iomgr_uv.cc', 'src/core/lib/iomgr/iomgr_windows.cc', @@ -543,12 +547,16 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/lockfree_event.cc', 'src/core/lib/iomgr/network_status_tracker.cc', 'src/core/lib/iomgr/polling_entity.cc', - 'src/core/lib/iomgr/pollset_set_uv.cc', + 'src/core/lib/iomgr/pollset.cc', + 'src/core/lib/iomgr/pollset_custom.cc', + 'src/core/lib/iomgr/pollset_set.cc', + 'src/core/lib/iomgr/pollset_set_custom.cc', 'src/core/lib/iomgr/pollset_set_windows.cc', 'src/core/lib/iomgr/pollset_uv.cc', 'src/core/lib/iomgr/pollset_windows.cc', + 'src/core/lib/iomgr/resolve_address.cc', + 'src/core/lib/iomgr/resolve_address_custom.cc', 'src/core/lib/iomgr/resolve_address_posix.cc', - 'src/core/lib/iomgr/resolve_address_uv.cc', 'src/core/lib/iomgr/resolve_address_windows.cc', 'src/core/lib/iomgr/resource_quota.cc', 'src/core/lib/iomgr/sockaddr_utils.cc', @@ -560,19 +568,24 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/socket_utils_uv.cc', 'src/core/lib/iomgr/socket_utils_windows.cc', 'src/core/lib/iomgr/socket_windows.cc', + 'src/core/lib/iomgr/tcp_client.cc', + 'src/core/lib/iomgr/tcp_client_custom.cc', 'src/core/lib/iomgr/tcp_client_posix.cc', - 'src/core/lib/iomgr/tcp_client_uv.cc', 'src/core/lib/iomgr/tcp_client_windows.cc', + 'src/core/lib/iomgr/tcp_custom.cc', 'src/core/lib/iomgr/tcp_posix.cc', + 'src/core/lib/iomgr/tcp_server.cc', + 'src/core/lib/iomgr/tcp_server_custom.cc', 'src/core/lib/iomgr/tcp_server_posix.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_common.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc', - 'src/core/lib/iomgr/tcp_server_uv.cc', 'src/core/lib/iomgr/tcp_server_windows.cc', 'src/core/lib/iomgr/tcp_uv.cc', 'src/core/lib/iomgr/tcp_windows.cc', 'src/core/lib/iomgr/time_averaged_stats.cc', + 'src/core/lib/iomgr/timer.cc', + 'src/core/lib/iomgr/timer_custom.cc', 'src/core/lib/iomgr/timer_generic.cc', 'src/core/lib/iomgr/timer_heap.cc', 'src/core/lib/iomgr/timer_manager.cc', @@ -947,9 +960,9 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/gethostname.h', 'src/core/lib/iomgr/iocp_windows.h', 'src/core/lib/iomgr/iomgr.h', + 'src/core/lib/iomgr/iomgr_custom.h', 'src/core/lib/iomgr/iomgr_internal.h', 'src/core/lib/iomgr/iomgr_posix.h', - 'src/core/lib/iomgr/iomgr_uv.h', 'src/core/lib/iomgr/is_epollexclusive_available.h', 'src/core/lib/iomgr/load_file.h', 'src/core/lib/iomgr/lockfree_event.h', @@ -957,14 +970,17 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/network_status_tracker.h', 'src/core/lib/iomgr/polling_entity.h', 'src/core/lib/iomgr/pollset.h', + 'src/core/lib/iomgr/pollset_custom.h', 'src/core/lib/iomgr/pollset_set.h', + 'src/core/lib/iomgr/pollset_set_custom.h', 'src/core/lib/iomgr/pollset_set_windows.h', - 'src/core/lib/iomgr/pollset_uv.h', 'src/core/lib/iomgr/pollset_windows.h', 'src/core/lib/iomgr/port.h', 'src/core/lib/iomgr/resolve_address.h', + 'src/core/lib/iomgr/resolve_address_custom.h', 'src/core/lib/iomgr/resource_quota.h', 'src/core/lib/iomgr/sockaddr.h', + 'src/core/lib/iomgr/sockaddr_custom.h', 'src/core/lib/iomgr/sockaddr_posix.h', 'src/core/lib/iomgr/sockaddr_utils.h', 'src/core/lib/iomgr/sockaddr_windows.h', @@ -976,17 +992,16 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/sys_epoll_wrapper.h', 'src/core/lib/iomgr/tcp_client.h', 'src/core/lib/iomgr/tcp_client_posix.h', + 'src/core/lib/iomgr/tcp_custom.h', 'src/core/lib/iomgr/tcp_posix.h', 'src/core/lib/iomgr/tcp_server.h', 'src/core/lib/iomgr/tcp_server_utils_posix.h', - 'src/core/lib/iomgr/tcp_uv.h', 'src/core/lib/iomgr/tcp_windows.h', 'src/core/lib/iomgr/time_averaged_stats.h', 'src/core/lib/iomgr/timer.h', - 'src/core/lib/iomgr/timer_generic.h', + 'src/core/lib/iomgr/timer_custom.h', 'src/core/lib/iomgr/timer_heap.h', 'src/core/lib/iomgr/timer_manager.h', - 'src/core/lib/iomgr/timer_uv.h', 'src/core/lib/iomgr/udp_server.h', 'src/core/lib/iomgr/unix_sockets_posix.h', 'src/core/lib/iomgr/wakeup_fd_cv.h', diff --git a/grpc.gemspec b/grpc.gemspec index 89a3812376..3a57829943 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -323,9 +323,9 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/iomgr/gethostname.h ) s.files += %w( src/core/lib/iomgr/iocp_windows.h ) s.files += %w( src/core/lib/iomgr/iomgr.h ) + s.files += %w( src/core/lib/iomgr/iomgr_custom.h ) s.files += %w( src/core/lib/iomgr/iomgr_internal.h ) s.files += %w( src/core/lib/iomgr/iomgr_posix.h ) - s.files += %w( src/core/lib/iomgr/iomgr_uv.h ) s.files += %w( src/core/lib/iomgr/is_epollexclusive_available.h ) s.files += %w( src/core/lib/iomgr/load_file.h ) s.files += %w( src/core/lib/iomgr/lockfree_event.h ) @@ -333,14 +333,17 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/iomgr/network_status_tracker.h ) s.files += %w( src/core/lib/iomgr/polling_entity.h ) s.files += %w( src/core/lib/iomgr/pollset.h ) + s.files += %w( src/core/lib/iomgr/pollset_custom.h ) s.files += %w( src/core/lib/iomgr/pollset_set.h ) + s.files += %w( src/core/lib/iomgr/pollset_set_custom.h ) s.files += %w( src/core/lib/iomgr/pollset_set_windows.h ) - s.files += %w( src/core/lib/iomgr/pollset_uv.h ) s.files += %w( src/core/lib/iomgr/pollset_windows.h ) s.files += %w( src/core/lib/iomgr/port.h ) s.files += %w( src/core/lib/iomgr/resolve_address.h ) + s.files += %w( src/core/lib/iomgr/resolve_address_custom.h ) s.files += %w( src/core/lib/iomgr/resource_quota.h ) s.files += %w( src/core/lib/iomgr/sockaddr.h ) + s.files += %w( src/core/lib/iomgr/sockaddr_custom.h ) s.files += %w( src/core/lib/iomgr/sockaddr_posix.h ) s.files += %w( src/core/lib/iomgr/sockaddr_utils.h ) s.files += %w( src/core/lib/iomgr/sockaddr_windows.h ) @@ -352,17 +355,16 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/iomgr/sys_epoll_wrapper.h ) s.files += %w( src/core/lib/iomgr/tcp_client.h ) s.files += %w( src/core/lib/iomgr/tcp_client_posix.h ) + s.files += %w( src/core/lib/iomgr/tcp_custom.h ) s.files += %w( src/core/lib/iomgr/tcp_posix.h ) s.files += %w( src/core/lib/iomgr/tcp_server.h ) s.files += %w( src/core/lib/iomgr/tcp_server_utils_posix.h ) - s.files += %w( src/core/lib/iomgr/tcp_uv.h ) s.files += %w( src/core/lib/iomgr/tcp_windows.h ) s.files += %w( src/core/lib/iomgr/time_averaged_stats.h ) s.files += %w( src/core/lib/iomgr/timer.h ) - s.files += %w( src/core/lib/iomgr/timer_generic.h ) + s.files += %w( src/core/lib/iomgr/timer_custom.h ) s.files += %w( src/core/lib/iomgr/timer_heap.h ) s.files += %w( src/core/lib/iomgr/timer_manager.h ) - s.files += %w( src/core/lib/iomgr/timer_uv.h ) s.files += %w( src/core/lib/iomgr/udp_server.h ) s.files += %w( src/core/lib/iomgr/unix_sockets_posix.h ) s.files += %w( src/core/lib/iomgr/wakeup_fd_cv.h ) @@ -465,6 +467,8 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/iomgr/gethostname_sysconf.cc ) s.files += %w( src/core/lib/iomgr/iocp_windows.cc ) s.files += %w( src/core/lib/iomgr/iomgr.cc ) + s.files += %w( src/core/lib/iomgr/iomgr_custom.cc ) + s.files += %w( src/core/lib/iomgr/iomgr_internal.cc ) s.files += %w( src/core/lib/iomgr/iomgr_posix.cc ) s.files += %w( src/core/lib/iomgr/iomgr_uv.cc ) s.files += %w( src/core/lib/iomgr/iomgr_windows.cc ) @@ -473,12 +477,16 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/iomgr/lockfree_event.cc ) s.files += %w( src/core/lib/iomgr/network_status_tracker.cc ) s.files += %w( src/core/lib/iomgr/polling_entity.cc ) - s.files += %w( src/core/lib/iomgr/pollset_set_uv.cc ) + s.files += %w( src/core/lib/iomgr/pollset.cc ) + s.files += %w( src/core/lib/iomgr/pollset_custom.cc ) + s.files += %w( src/core/lib/iomgr/pollset_set.cc ) + s.files += %w( src/core/lib/iomgr/pollset_set_custom.cc ) s.files += %w( src/core/lib/iomgr/pollset_set_windows.cc ) s.files += %w( src/core/lib/iomgr/pollset_uv.cc ) s.files += %w( src/core/lib/iomgr/pollset_windows.cc ) + s.files += %w( src/core/lib/iomgr/resolve_address.cc ) + s.files += %w( src/core/lib/iomgr/resolve_address_custom.cc ) s.files += %w( src/core/lib/iomgr/resolve_address_posix.cc ) - s.files += %w( src/core/lib/iomgr/resolve_address_uv.cc ) s.files += %w( src/core/lib/iomgr/resolve_address_windows.cc ) s.files += %w( src/core/lib/iomgr/resource_quota.cc ) s.files += %w( src/core/lib/iomgr/sockaddr_utils.cc ) @@ -490,19 +498,24 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/iomgr/socket_utils_uv.cc ) s.files += %w( src/core/lib/iomgr/socket_utils_windows.cc ) s.files += %w( src/core/lib/iomgr/socket_windows.cc ) + s.files += %w( src/core/lib/iomgr/tcp_client.cc ) + s.files += %w( src/core/lib/iomgr/tcp_client_custom.cc ) s.files += %w( src/core/lib/iomgr/tcp_client_posix.cc ) - s.files += %w( src/core/lib/iomgr/tcp_client_uv.cc ) s.files += %w( src/core/lib/iomgr/tcp_client_windows.cc ) + s.files += %w( src/core/lib/iomgr/tcp_custom.cc ) s.files += %w( src/core/lib/iomgr/tcp_posix.cc ) + s.files += %w( src/core/lib/iomgr/tcp_server.cc ) + s.files += %w( src/core/lib/iomgr/tcp_server_custom.cc ) s.files += %w( src/core/lib/iomgr/tcp_server_posix.cc ) s.files += %w( src/core/lib/iomgr/tcp_server_utils_posix_common.cc ) s.files += %w( src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc ) s.files += %w( src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc ) - s.files += %w( src/core/lib/iomgr/tcp_server_uv.cc ) s.files += %w( src/core/lib/iomgr/tcp_server_windows.cc ) s.files += %w( src/core/lib/iomgr/tcp_uv.cc ) s.files += %w( src/core/lib/iomgr/tcp_windows.cc ) s.files += %w( src/core/lib/iomgr/time_averaged_stats.cc ) + s.files += %w( src/core/lib/iomgr/timer.cc ) + s.files += %w( src/core/lib/iomgr/timer_custom.cc ) s.files += %w( src/core/lib/iomgr/timer_generic.cc ) s.files += %w( src/core/lib/iomgr/timer_heap.cc ) s.files += %w( src/core/lib/iomgr/timer_manager.cc ) diff --git a/grpc.gyp b/grpc.gyp index c5401f32b3..403d32831b 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -274,6 +274,8 @@ 'src/core/lib/iomgr/gethostname_sysconf.cc', 'src/core/lib/iomgr/iocp_windows.cc', 'src/core/lib/iomgr/iomgr.cc', + 'src/core/lib/iomgr/iomgr_custom.cc', + 'src/core/lib/iomgr/iomgr_internal.cc', 'src/core/lib/iomgr/iomgr_posix.cc', 'src/core/lib/iomgr/iomgr_uv.cc', 'src/core/lib/iomgr/iomgr_windows.cc', @@ -282,12 +284,16 @@ 'src/core/lib/iomgr/lockfree_event.cc', 'src/core/lib/iomgr/network_status_tracker.cc', 'src/core/lib/iomgr/polling_entity.cc', - 'src/core/lib/iomgr/pollset_set_uv.cc', + 'src/core/lib/iomgr/pollset.cc', + 'src/core/lib/iomgr/pollset_custom.cc', + 'src/core/lib/iomgr/pollset_set.cc', + 'src/core/lib/iomgr/pollset_set_custom.cc', 'src/core/lib/iomgr/pollset_set_windows.cc', 'src/core/lib/iomgr/pollset_uv.cc', 'src/core/lib/iomgr/pollset_windows.cc', + 'src/core/lib/iomgr/resolve_address.cc', + 'src/core/lib/iomgr/resolve_address_custom.cc', 'src/core/lib/iomgr/resolve_address_posix.cc', - 'src/core/lib/iomgr/resolve_address_uv.cc', 'src/core/lib/iomgr/resolve_address_windows.cc', 'src/core/lib/iomgr/resource_quota.cc', 'src/core/lib/iomgr/sockaddr_utils.cc', @@ -299,19 +305,24 @@ 'src/core/lib/iomgr/socket_utils_uv.cc', 'src/core/lib/iomgr/socket_utils_windows.cc', 'src/core/lib/iomgr/socket_windows.cc', + 'src/core/lib/iomgr/tcp_client.cc', + 'src/core/lib/iomgr/tcp_client_custom.cc', 'src/core/lib/iomgr/tcp_client_posix.cc', - 'src/core/lib/iomgr/tcp_client_uv.cc', 'src/core/lib/iomgr/tcp_client_windows.cc', + 'src/core/lib/iomgr/tcp_custom.cc', 'src/core/lib/iomgr/tcp_posix.cc', + 'src/core/lib/iomgr/tcp_server.cc', + 'src/core/lib/iomgr/tcp_server_custom.cc', 'src/core/lib/iomgr/tcp_server_posix.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_common.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc', - 'src/core/lib/iomgr/tcp_server_uv.cc', 'src/core/lib/iomgr/tcp_server_windows.cc', 'src/core/lib/iomgr/tcp_uv.cc', 'src/core/lib/iomgr/tcp_windows.cc', 'src/core/lib/iomgr/time_averaged_stats.cc', + 'src/core/lib/iomgr/timer.cc', + 'src/core/lib/iomgr/timer_custom.cc', 'src/core/lib/iomgr/timer_generic.cc', 'src/core/lib/iomgr/timer_heap.cc', 'src/core/lib/iomgr/timer_manager.cc', @@ -606,6 +617,8 @@ 'src/core/lib/iomgr/gethostname_sysconf.cc', 'src/core/lib/iomgr/iocp_windows.cc', 'src/core/lib/iomgr/iomgr.cc', + 'src/core/lib/iomgr/iomgr_custom.cc', + 'src/core/lib/iomgr/iomgr_internal.cc', 'src/core/lib/iomgr/iomgr_posix.cc', 'src/core/lib/iomgr/iomgr_uv.cc', 'src/core/lib/iomgr/iomgr_windows.cc', @@ -614,12 +627,16 @@ 'src/core/lib/iomgr/lockfree_event.cc', 'src/core/lib/iomgr/network_status_tracker.cc', 'src/core/lib/iomgr/polling_entity.cc', - 'src/core/lib/iomgr/pollset_set_uv.cc', + 'src/core/lib/iomgr/pollset.cc', + 'src/core/lib/iomgr/pollset_custom.cc', + 'src/core/lib/iomgr/pollset_set.cc', + 'src/core/lib/iomgr/pollset_set_custom.cc', 'src/core/lib/iomgr/pollset_set_windows.cc', 'src/core/lib/iomgr/pollset_uv.cc', 'src/core/lib/iomgr/pollset_windows.cc', + 'src/core/lib/iomgr/resolve_address.cc', + 'src/core/lib/iomgr/resolve_address_custom.cc', 'src/core/lib/iomgr/resolve_address_posix.cc', - 'src/core/lib/iomgr/resolve_address_uv.cc', 'src/core/lib/iomgr/resolve_address_windows.cc', 'src/core/lib/iomgr/resource_quota.cc', 'src/core/lib/iomgr/sockaddr_utils.cc', @@ -631,19 +648,24 @@ 'src/core/lib/iomgr/socket_utils_uv.cc', 'src/core/lib/iomgr/socket_utils_windows.cc', 'src/core/lib/iomgr/socket_windows.cc', + 'src/core/lib/iomgr/tcp_client.cc', + 'src/core/lib/iomgr/tcp_client_custom.cc', 'src/core/lib/iomgr/tcp_client_posix.cc', - 'src/core/lib/iomgr/tcp_client_uv.cc', 'src/core/lib/iomgr/tcp_client_windows.cc', + 'src/core/lib/iomgr/tcp_custom.cc', 'src/core/lib/iomgr/tcp_posix.cc', + 'src/core/lib/iomgr/tcp_server.cc', + 'src/core/lib/iomgr/tcp_server_custom.cc', 'src/core/lib/iomgr/tcp_server_posix.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_common.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc', - 'src/core/lib/iomgr/tcp_server_uv.cc', 'src/core/lib/iomgr/tcp_server_windows.cc', 'src/core/lib/iomgr/tcp_uv.cc', 'src/core/lib/iomgr/tcp_windows.cc', 'src/core/lib/iomgr/time_averaged_stats.cc', + 'src/core/lib/iomgr/timer.cc', + 'src/core/lib/iomgr/timer_custom.cc', 'src/core/lib/iomgr/timer_generic.cc', 'src/core/lib/iomgr/timer_heap.cc', 'src/core/lib/iomgr/timer_manager.cc', @@ -823,6 +845,8 @@ 'src/core/lib/iomgr/gethostname_sysconf.cc', 'src/core/lib/iomgr/iocp_windows.cc', 'src/core/lib/iomgr/iomgr.cc', + 'src/core/lib/iomgr/iomgr_custom.cc', + 'src/core/lib/iomgr/iomgr_internal.cc', 'src/core/lib/iomgr/iomgr_posix.cc', 'src/core/lib/iomgr/iomgr_uv.cc', 'src/core/lib/iomgr/iomgr_windows.cc', @@ -831,12 +855,16 @@ 'src/core/lib/iomgr/lockfree_event.cc', 'src/core/lib/iomgr/network_status_tracker.cc', 'src/core/lib/iomgr/polling_entity.cc', - 'src/core/lib/iomgr/pollset_set_uv.cc', + 'src/core/lib/iomgr/pollset.cc', + 'src/core/lib/iomgr/pollset_custom.cc', + 'src/core/lib/iomgr/pollset_set.cc', + 'src/core/lib/iomgr/pollset_set_custom.cc', 'src/core/lib/iomgr/pollset_set_windows.cc', 'src/core/lib/iomgr/pollset_uv.cc', 'src/core/lib/iomgr/pollset_windows.cc', + 'src/core/lib/iomgr/resolve_address.cc', + 'src/core/lib/iomgr/resolve_address_custom.cc', 'src/core/lib/iomgr/resolve_address_posix.cc', - 'src/core/lib/iomgr/resolve_address_uv.cc', 'src/core/lib/iomgr/resolve_address_windows.cc', 'src/core/lib/iomgr/resource_quota.cc', 'src/core/lib/iomgr/sockaddr_utils.cc', @@ -848,19 +876,24 @@ 'src/core/lib/iomgr/socket_utils_uv.cc', 'src/core/lib/iomgr/socket_utils_windows.cc', 'src/core/lib/iomgr/socket_windows.cc', + 'src/core/lib/iomgr/tcp_client.cc', + 'src/core/lib/iomgr/tcp_client_custom.cc', 'src/core/lib/iomgr/tcp_client_posix.cc', - 'src/core/lib/iomgr/tcp_client_uv.cc', 'src/core/lib/iomgr/tcp_client_windows.cc', + 'src/core/lib/iomgr/tcp_custom.cc', 'src/core/lib/iomgr/tcp_posix.cc', + 'src/core/lib/iomgr/tcp_server.cc', + 'src/core/lib/iomgr/tcp_server_custom.cc', 'src/core/lib/iomgr/tcp_server_posix.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_common.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc', - 'src/core/lib/iomgr/tcp_server_uv.cc', 'src/core/lib/iomgr/tcp_server_windows.cc', 'src/core/lib/iomgr/tcp_uv.cc', 'src/core/lib/iomgr/tcp_windows.cc', 'src/core/lib/iomgr/time_averaged_stats.cc', + 'src/core/lib/iomgr/timer.cc', + 'src/core/lib/iomgr/timer_custom.cc', 'src/core/lib/iomgr/timer_generic.cc', 'src/core/lib/iomgr/timer_heap.cc', 'src/core/lib/iomgr/timer_manager.cc', @@ -1019,6 +1052,8 @@ 'src/core/lib/iomgr/gethostname_sysconf.cc', 'src/core/lib/iomgr/iocp_windows.cc', 'src/core/lib/iomgr/iomgr.cc', + 'src/core/lib/iomgr/iomgr_custom.cc', + 'src/core/lib/iomgr/iomgr_internal.cc', 'src/core/lib/iomgr/iomgr_posix.cc', 'src/core/lib/iomgr/iomgr_uv.cc', 'src/core/lib/iomgr/iomgr_windows.cc', @@ -1027,12 +1062,16 @@ 'src/core/lib/iomgr/lockfree_event.cc', 'src/core/lib/iomgr/network_status_tracker.cc', 'src/core/lib/iomgr/polling_entity.cc', - 'src/core/lib/iomgr/pollset_set_uv.cc', + 'src/core/lib/iomgr/pollset.cc', + 'src/core/lib/iomgr/pollset_custom.cc', + 'src/core/lib/iomgr/pollset_set.cc', + 'src/core/lib/iomgr/pollset_set_custom.cc', 'src/core/lib/iomgr/pollset_set_windows.cc', 'src/core/lib/iomgr/pollset_uv.cc', 'src/core/lib/iomgr/pollset_windows.cc', + 'src/core/lib/iomgr/resolve_address.cc', + 'src/core/lib/iomgr/resolve_address_custom.cc', 'src/core/lib/iomgr/resolve_address_posix.cc', - 'src/core/lib/iomgr/resolve_address_uv.cc', 'src/core/lib/iomgr/resolve_address_windows.cc', 'src/core/lib/iomgr/resource_quota.cc', 'src/core/lib/iomgr/sockaddr_utils.cc', @@ -1044,19 +1083,24 @@ 'src/core/lib/iomgr/socket_utils_uv.cc', 'src/core/lib/iomgr/socket_utils_windows.cc', 'src/core/lib/iomgr/socket_windows.cc', + 'src/core/lib/iomgr/tcp_client.cc', + 'src/core/lib/iomgr/tcp_client_custom.cc', 'src/core/lib/iomgr/tcp_client_posix.cc', - 'src/core/lib/iomgr/tcp_client_uv.cc', 'src/core/lib/iomgr/tcp_client_windows.cc', + 'src/core/lib/iomgr/tcp_custom.cc', 'src/core/lib/iomgr/tcp_posix.cc', + 'src/core/lib/iomgr/tcp_server.cc', + 'src/core/lib/iomgr/tcp_server_custom.cc', 'src/core/lib/iomgr/tcp_server_posix.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_common.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc', - 'src/core/lib/iomgr/tcp_server_uv.cc', 'src/core/lib/iomgr/tcp_server_windows.cc', 'src/core/lib/iomgr/tcp_uv.cc', 'src/core/lib/iomgr/tcp_windows.cc', 'src/core/lib/iomgr/time_averaged_stats.cc', + 'src/core/lib/iomgr/timer.cc', + 'src/core/lib/iomgr/timer_custom.cc', 'src/core/lib/iomgr/timer_generic.cc', 'src/core/lib/iomgr/timer_heap.cc', 'src/core/lib/iomgr/timer_manager.cc', diff --git a/include/grpc/impl/codegen/slice.h b/include/grpc/impl/codegen/slice.h index a3cd1f1bbe..90dbfd3b1f 100644 --- a/include/grpc/impl/codegen/slice.h +++ b/include/grpc/impl/codegen/slice.h @@ -95,7 +95,7 @@ struct grpc_slice { /** Represents an expandable array of slices, to be interpreted as a single item. */ -typedef struct { +typedef struct grpc_slice_buffer { /** This is for internal use only. External users (i.e any code outside grpc * core) MUST NOT use this field */ grpc_slice* base_slices; diff --git a/package.xml b/package.xml index fc7ba68e8b..8f0dc55dbf 100644 --- a/package.xml +++ b/package.xml @@ -330,9 +330,9 @@ + - @@ -340,14 +340,17 @@ + + - + + @@ -359,17 +362,16 @@ + - - + - @@ -472,6 +474,8 @@ + + @@ -480,12 +484,16 @@ - + + + + + + - @@ -497,19 +505,24 @@ + + - + + + - + + diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc index cb39e4224e..47e1deef12 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc @@ -61,6 +61,7 @@ #include #include "src/core/lib/iomgr/sockaddr.h" +#include "src/core/lib/iomgr/socket_utils.h" #include #include @@ -417,20 +418,20 @@ void ParseServer(const grpc_grpclb_server* server, grpc_resolved_address* addr) { memset(addr, 0, sizeof(*addr)); if (server->drop) return; - const uint16_t netorder_port = htons((uint16_t)server->port); + const uint16_t netorder_port = grpc_htons((uint16_t)server->port); /* the addresses are given in binary format (a in(6)_addr struct) in * server->ip_address.bytes. */ const grpc_grpclb_ip_address* ip = &server->ip_address; if (ip->size == 4) { - addr->len = sizeof(struct sockaddr_in); - struct sockaddr_in* addr4 = (struct sockaddr_in*)&addr->addr; - addr4->sin_family = AF_INET; + addr->len = sizeof(grpc_sockaddr_in); + grpc_sockaddr_in* addr4 = reinterpret_cast(&addr->addr); + addr4->sin_family = GRPC_AF_INET; memcpy(&addr4->sin_addr, ip->bytes, ip->size); addr4->sin_port = netorder_port; } else if (ip->size == 16) { - addr->len = sizeof(struct sockaddr_in6); - struct sockaddr_in6* addr6 = (struct sockaddr_in6*)&addr->addr; - addr6->sin6_family = AF_INET6; + addr->len = sizeof(grpc_sockaddr_in6); + grpc_sockaddr_in6* addr6 = (grpc_sockaddr_in6*)&addr->addr; + addr6->sin6_family = GRPC_AF_INET6; memcpy(&addr6->sin6_addr, ip->bytes, ip->size); addr6->sin6_port = netorder_port; } diff --git a/src/core/ext/filters/client_channel/parse_address.cc b/src/core/ext/filters/client_channel/parse_address.cc index e78dc99e0b..92ea259cf0 100644 --- a/src/core/ext/filters/client_channel/parse_address.cc +++ b/src/core/ext/filters/client_channel/parse_address.cc @@ -20,6 +20,7 @@ #include "src/core/ext/filters/client_channel/parse_address.h" #include "src/core/lib/iomgr/sockaddr.h" +#include "src/core/lib/iomgr/socket_utils.h" #include #include @@ -71,10 +72,10 @@ bool grpc_parse_ipv4_hostport(const char* hostport, grpc_resolved_address* addr, if (!gpr_split_host_port(hostport, &host, &port)) return false; // Parse IP address. memset(addr, 0, sizeof(*addr)); - addr->len = sizeof(struct sockaddr_in); - struct sockaddr_in* in = reinterpret_cast(addr->addr); - in->sin_family = AF_INET; - if (inet_pton(AF_INET, host, &in->sin_addr) == 0) { + addr->len = sizeof(grpc_sockaddr_in); + grpc_sockaddr_in* in = reinterpret_cast(addr->addr); + in->sin_family = GRPC_AF_INET; + if (grpc_inet_pton(GRPC_AF_INET, host, &in->sin_addr) == 0) { if (log_errors) gpr_log(GPR_ERROR, "invalid ipv4 address: '%s'", host); goto done; } @@ -88,7 +89,7 @@ bool grpc_parse_ipv4_hostport(const char* hostport, grpc_resolved_address* addr, if (log_errors) gpr_log(GPR_ERROR, "invalid ipv4 port: '%s'", port); goto done; } - in->sin_port = htons(static_cast(port_num)); + in->sin_port = grpc_htons(static_cast(port_num)); success = true; done: gpr_free(host); @@ -117,19 +118,20 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr, if (!gpr_split_host_port(hostport, &host, &port)) return false; // Parse IP address. memset(addr, 0, sizeof(*addr)); - addr->len = sizeof(struct sockaddr_in6); - struct sockaddr_in6* in6 = reinterpret_cast(addr->addr); - in6->sin6_family = AF_INET6; + addr->len = sizeof(grpc_sockaddr_in6); + grpc_sockaddr_in6* in6 = reinterpret_cast(addr->addr); + in6->sin6_family = GRPC_AF_INET6; // Handle the RFC6874 syntax for IPv6 zone identifiers. char* host_end = static_cast(gpr_memrchr(host, '%', strlen(host))); if (host_end != nullptr) { GPR_ASSERT(host_end >= host); - char host_without_scope[INET6_ADDRSTRLEN]; + char host_without_scope[GRPC_INET6_ADDRSTRLEN]; size_t host_without_scope_len = static_cast(host_end - host); uint32_t sin6_scope_id = 0; strncpy(host_without_scope, host, host_without_scope_len); host_without_scope[host_without_scope_len] = '\0'; - if (inet_pton(AF_INET6, host_without_scope, &in6->sin6_addr) == 0) { + if (grpc_inet_pton(GRPC_AF_INET6, host_without_scope, &in6->sin6_addr) == + 0) { gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host_without_scope); goto done; } @@ -142,7 +144,7 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr, // Handle "sin6_scope_id" being type "u_long". See grpc issue #10027. in6->sin6_scope_id = sin6_scope_id; } else { - if (inet_pton(AF_INET6, host, &in6->sin6_addr) == 0) { + if (grpc_inet_pton(GRPC_AF_INET6, host, &in6->sin6_addr) == 0) { gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host); goto done; } @@ -157,7 +159,7 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr, if (log_errors) gpr_log(GPR_ERROR, "invalid ipv6 port: '%s'", port); goto done; } - in6->sin6_port = htons(static_cast(port_num)); + in6->sin6_port = grpc_htons(static_cast(port_num)); success = true; done: gpr_free(host); diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc index aa93e5d8de..a895afa784 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc @@ -440,6 +440,27 @@ class AresDnsResolverFactory : public ResolverFactory { } // namespace grpc_core +extern grpc_address_resolver_vtable* grpc_resolve_address_impl; +static grpc_address_resolver_vtable* default_resolver; + +static void resolve_address_ares(const char* addr, const char* default_port, + grpc_pollset_set* interested_parties, + grpc_closure* on_done, + grpc_resolved_addresses** addrs) { + grpc_resolve_address_ares(addr, default_port, interested_parties, on_done, + addrs); +} + +static grpc_error* blocking_resolve_address_ares( + const char* name, const char* default_port, + grpc_resolved_addresses** addresses) { + return default_resolver->blocking_resolve_address(name, default_port, + addresses); +} + +static grpc_address_resolver_vtable ares_resolver = { + resolve_address_ares, blocking_resolve_address_ares}; + void grpc_resolver_dns_ares_init() { char* resolver_env = gpr_getenv("GRPC_DNS_RESOLVER"); /* TODO(zyc): Turn on c-ares based resolver by default after the address @@ -450,7 +471,8 @@ void grpc_resolver_dns_ares_init() { GRPC_LOG_IF_ERROR("ares_library_init() failed", error); return; } - grpc_resolve_address = grpc_resolve_address_ares; + default_resolver = grpc_resolve_address_impl; + grpc_set_resolver_impl(&ares_resolver); grpc_core::ResolverRegistry::Builder::RegisterResolverFactory( grpc_core::UniquePtr( grpc_core::New())); diff --git a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc index 822236dd2d..99f18cdf39 100644 --- a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc +++ b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc @@ -41,6 +41,5 @@ int grpc_server_add_insecure_http2_port(grpc_server* server, const char* addr) { GRPC_ERROR_UNREF(err); } - return port_num; } diff --git a/src/core/lib/iomgr/endpoint.cc b/src/core/lib/iomgr/endpoint.cc index e22c21e4bd..92e7930111 100644 --- a/src/core/lib/iomgr/endpoint.cc +++ b/src/core/lib/iomgr/endpoint.cc @@ -20,6 +20,8 @@ #include "src/core/lib/iomgr/endpoint.h" +grpc_core::TraceFlag grpc_tcp_trace(false, "tcp"); + void grpc_endpoint_read(grpc_endpoint* ep, grpc_slice_buffer* slices, grpc_closure* cb) { ep->vtable->read(ep, slices, cb); diff --git a/src/core/lib/iomgr/endpoint_pair_windows.cc b/src/core/lib/iomgr/endpoint_pair_windows.cc index 416c9d88a1..177331d681 100644 --- a/src/core/lib/iomgr/endpoint_pair_windows.cc +++ b/src/core/lib/iomgr/endpoint_pair_windows.cc @@ -22,6 +22,7 @@ #ifdef GRPC_WINSOCK_SOCKET #include "src/core/lib/iomgr/endpoint_pair.h" +#include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/iomgr/sockaddr_utils.h" #include @@ -46,19 +47,19 @@ static void create_sockets(SOCKET sv[2]) { memset(&addr, 0, sizeof(addr)); addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); addr.sin_family = AF_INET; - GPR_ASSERT(bind(lst_sock, (struct sockaddr*)&addr, sizeof(addr)) != + GPR_ASSERT(bind(lst_sock, (grpc_sockaddr*)&addr, sizeof(addr)) != SOCKET_ERROR); GPR_ASSERT(listen(lst_sock, SOMAXCONN) != SOCKET_ERROR); - GPR_ASSERT(getsockname(lst_sock, (struct sockaddr*)&addr, &addr_len) != + GPR_ASSERT(getsockname(lst_sock, (grpc_sockaddr*)&addr, &addr_len) != SOCKET_ERROR); cli_sock = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED); GPR_ASSERT(cli_sock != INVALID_SOCKET); - GPR_ASSERT(WSAConnect(cli_sock, (struct sockaddr*)&addr, addr_len, NULL, NULL, + GPR_ASSERT(WSAConnect(cli_sock, (grpc_sockaddr*)&addr, addr_len, NULL, NULL, NULL, NULL) == 0); - svr_sock = accept(lst_sock, (struct sockaddr*)&addr, &addr_len); + svr_sock = accept(lst_sock, (grpc_sockaddr*)&addr, &addr_len); GPR_ASSERT(svr_sock != INVALID_SOCKET); closesocket(lst_sock); diff --git a/src/core/lib/iomgr/ev_posix.cc b/src/core/lib/iomgr/ev_posix.cc index 39ce459f1e..8b80070265 100644 --- a/src/core/lib/iomgr/ev_posix.cc +++ b/src/core/lib/iomgr/ev_posix.cc @@ -224,26 +224,26 @@ void grpc_fd_notify_on_write(grpc_fd* fd, grpc_closure* closure) { g_event_engine->fd_notify_on_write(fd, closure); } -size_t grpc_pollset_size(void) { return g_event_engine->pollset_size; } +static size_t pollset_size(void) { return g_event_engine->pollset_size; } -void grpc_pollset_init(grpc_pollset* pollset, gpr_mu** mu) { +static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { GRPC_POLLING_API_TRACE("pollset_init(%p)", pollset); g_event_engine->pollset_init(pollset, mu); } -void grpc_pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { +static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { GRPC_POLLING_API_TRACE("pollset_shutdown(%p)", pollset); g_event_engine->pollset_shutdown(pollset, closure); } -void grpc_pollset_destroy(grpc_pollset* pollset) { +static void pollset_destroy(grpc_pollset* pollset) { GRPC_POLLING_API_TRACE("pollset_destroy(%p)", pollset); g_event_engine->pollset_destroy(pollset); } -grpc_error* grpc_pollset_work(grpc_pollset* pollset, - grpc_pollset_worker** worker, - grpc_millis deadline) { +static grpc_error* pollset_work(grpc_pollset* pollset, + grpc_pollset_worker** worker, + grpc_millis deadline) { GRPC_POLLING_API_TRACE("pollset_work(%p, %" PRIdPTR ") begin", pollset, deadline); grpc_error* err = g_event_engine->pollset_work(pollset, worker, deadline); @@ -252,8 +252,8 @@ grpc_error* grpc_pollset_work(grpc_pollset* pollset, return err; } -grpc_error* grpc_pollset_kick(grpc_pollset* pollset, - grpc_pollset_worker* specific_worker) { +static grpc_error* pollset_kick(grpc_pollset* pollset, + grpc_pollset_worker* specific_worker) { GRPC_POLLING_API_TRACE("pollset_kick(%p, %p)", pollset, specific_worker); return g_event_engine->pollset_kick(pollset, specific_worker); } @@ -264,43 +264,57 @@ void grpc_pollset_add_fd(grpc_pollset* pollset, struct grpc_fd* fd) { g_event_engine->pollset_add_fd(pollset, fd); } -grpc_pollset_set* grpc_pollset_set_create(void) { +void pollset_global_init() {} +void pollset_global_shutdown() {} + +grpc_pollset_vtable grpc_posix_pollset_vtable = { + pollset_global_init, pollset_global_shutdown, + pollset_init, pollset_shutdown, + pollset_destroy, pollset_work, + pollset_kick, pollset_size}; + +static grpc_pollset_set* pollset_set_create(void) { grpc_pollset_set* pss = g_event_engine->pollset_set_create(); GRPC_POLLING_API_TRACE("pollset_set_create(%p)", pss); return pss; } -void grpc_pollset_set_destroy(grpc_pollset_set* pollset_set) { +static void pollset_set_destroy(grpc_pollset_set* pollset_set) { GRPC_POLLING_API_TRACE("pollset_set_destroy(%p)", pollset_set); g_event_engine->pollset_set_destroy(pollset_set); } -void grpc_pollset_set_add_pollset(grpc_pollset_set* pollset_set, - grpc_pollset* pollset) { +static void pollset_set_add_pollset(grpc_pollset_set* pollset_set, + grpc_pollset* pollset) { GRPC_POLLING_API_TRACE("pollset_set_add_pollset(%p, %p)", pollset_set, pollset); g_event_engine->pollset_set_add_pollset(pollset_set, pollset); } -void grpc_pollset_set_del_pollset(grpc_pollset_set* pollset_set, - grpc_pollset* pollset) { +static void pollset_set_del_pollset(grpc_pollset_set* pollset_set, + grpc_pollset* pollset) { GRPC_POLLING_API_TRACE("pollset_set_del_pollset(%p, %p)", pollset_set, pollset); g_event_engine->pollset_set_del_pollset(pollset_set, pollset); } -void grpc_pollset_set_add_pollset_set(grpc_pollset_set* bag, - grpc_pollset_set* item) { +static void pollset_set_add_pollset_set(grpc_pollset_set* bag, + grpc_pollset_set* item) { GRPC_POLLING_API_TRACE("pollset_set_add_pollset_set(%p, %p)", bag, item); g_event_engine->pollset_set_add_pollset_set(bag, item); } -void grpc_pollset_set_del_pollset_set(grpc_pollset_set* bag, - grpc_pollset_set* item) { +static void pollset_set_del_pollset_set(grpc_pollset_set* bag, + grpc_pollset_set* item) { GRPC_POLLING_API_TRACE("pollset_set_del_pollset_set(%p, %p)", bag, item); g_event_engine->pollset_set_del_pollset_set(bag, item); } +grpc_pollset_set_vtable grpc_posix_pollset_set_vtable = { + pollset_set_create, pollset_set_destroy, + pollset_set_add_pollset, pollset_set_del_pollset, + pollset_set_add_pollset_set, pollset_set_del_pollset_set}; + void grpc_pollset_set_add_fd(grpc_pollset_set* pollset_set, grpc_fd* fd) { GRPC_POLLING_API_TRACE("pollset_set_add_fd(%p, %d)", pollset_set, grpc_fd_wrapped_fd(fd)); diff --git a/src/core/lib/iomgr/exec_ctx.h b/src/core/lib/iomgr/exec_ctx.h index de97164f02..e4edcf67f4 100644 --- a/src/core/lib/iomgr/exec_ctx.h +++ b/src/core/lib/iomgr/exec_ctx.h @@ -171,6 +171,10 @@ on outside context */ return reinterpret_cast(gpr_tls_get(&exec_ctx_)); } + static void Set(ExecCtx* exec_ctx) { + gpr_tls_set(&exec_ctx_, reinterpret_cast(exec_ctx)); + } + protected: /** Check if ready to finish */ virtual bool CheckReadyToFinish() { return false; } @@ -180,9 +184,6 @@ on outside context */ private: /** Set exec_ctx_ to exec_ctx */ - void Set(ExecCtx* exec_ctx) { - gpr_tls_set(&exec_ctx_, reinterpret_cast(exec_ctx)); - } grpc_closure_list closure_list_ = GRPC_CLOSURE_LIST_INIT; CombinerData combiner_data_ = {nullptr, nullptr}; diff --git a/src/core/lib/iomgr/iomgr.cc b/src/core/lib/iomgr/iomgr.cc index 3c2b83a549..468814eaee 100644 --- a/src/core/lib/iomgr/iomgr.cc +++ b/src/core/lib/iomgr/iomgr.cc @@ -47,6 +47,7 @@ static grpc_iomgr_object g_root_object; void grpc_iomgr_init() { grpc_core::ExecCtx exec_ctx; + grpc_determine_iomgr_platform(); g_shutdown = 0; gpr_mu_init(&g_mu); gpr_cv_init(&g_rcv); diff --git a/src/core/lib/iomgr/iomgr_custom.cc b/src/core/lib/iomgr/iomgr_custom.cc new file mode 100644 index 0000000000..d34c8e7cd1 --- /dev/null +++ b/src/core/lib/iomgr/iomgr_custom.cc @@ -0,0 +1,63 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/lib/iomgr/port.h" + +#include + +#include "src/core/lib/iomgr/exec_ctx.h" +#include "src/core/lib/iomgr/executor.h" +#include "src/core/lib/iomgr/iomgr_custom.h" +#include "src/core/lib/iomgr/iomgr_internal.h" +#include "src/core/lib/iomgr/pollset_custom.h" +#include "src/core/lib/iomgr/pollset_set_custom.h" +#include "src/core/lib/iomgr/resolve_address_custom.h" + +gpr_thd_id g_init_thread; + +static void iomgr_platform_init(void) { + grpc_core::ExecCtx exec_ctx; + grpc_executor_set_threading(false); + g_init_thread = gpr_thd_currentid(); + grpc_pollset_global_init(); +} +static void iomgr_platform_flush(void) {} +static void iomgr_platform_shutdown(void) { grpc_pollset_global_shutdown(); } + +static grpc_iomgr_platform_vtable vtable = { + iomgr_platform_init, iomgr_platform_flush, iomgr_platform_shutdown}; + +void grpc_custom_iomgr_init(grpc_socket_vtable* socket, + grpc_custom_resolver_vtable* resolver, + grpc_custom_timer_vtable* timer, + grpc_custom_poller_vtable* poller) { + grpc_custom_endpoint_init(socket); + grpc_custom_timer_init(timer); + grpc_custom_pollset_init(poller); + grpc_custom_pollset_set_init(); + grpc_custom_resolver_init(resolver); + grpc_set_iomgr_platform_vtable(&vtable); +} + +#ifdef GRPC_CUSTOM_SOCKET +grpc_iomgr_platform_vtable* grpc_default_iomgr_platform_vtable() { + return &vtable; +} +#endif diff --git a/src/core/lib/iomgr/iomgr_custom.h b/src/core/lib/iomgr/iomgr_custom.h new file mode 100644 index 0000000000..ceb6c65db2 --- /dev/null +++ b/src/core/lib/iomgr/iomgr_custom.h @@ -0,0 +1,47 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_LIB_IOMGR_IOMGR_CUSTOM_H +#define GRPC_CORE_LIB_IOMGR_IOMGR_CUSTOM_H + +#include + +#include "src/core/lib/iomgr/pollset_custom.h" +#include "src/core/lib/iomgr/resolve_address_custom.h" +#include "src/core/lib/iomgr/tcp_custom.h" +#include "src/core/lib/iomgr/timer_custom.h" + +#include + +/* The thread ID of the thread on which grpc was initialized. Used to verify + * that all calls into the custom iomgr are made on that same thread */ +extern gpr_thd_id g_init_thread; + +#ifdef GRPC_CUSTOM_IOMGR_THREAD_CHECK +#define GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD() \ + GPR_ASSERT(gpr_thd_currentid() == g_init_thread) +#else +#define GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD() +#endif /* GRPC_UV_THREAD_CHECK */ + +void grpc_custom_iomgr_init(grpc_socket_vtable* socket, + grpc_custom_resolver_vtable* resolver, + grpc_custom_timer_vtable* timer, + grpc_custom_poller_vtable* poller); + +#endif /* GRPC_CORE_LIB_IOMGR_IOMGR_CUSTOM_H */ diff --git a/src/core/lib/iomgr/iomgr_internal.cc b/src/core/lib/iomgr/iomgr_internal.cc new file mode 100644 index 0000000000..32dbabb79d --- /dev/null +++ b/src/core/lib/iomgr/iomgr_internal.cc @@ -0,0 +1,43 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include + +#include "src/core/lib/iomgr/iomgr_internal.h" +#include "src/core/lib/iomgr/timer.h" +#include "src/core/lib/iomgr/timer_manager.h" + +static grpc_iomgr_platform_vtable* iomgr_platform_vtable = nullptr; + +void grpc_set_iomgr_platform_vtable(grpc_iomgr_platform_vtable* vtable) { + iomgr_platform_vtable = vtable; +} + +void grpc_determine_iomgr_platform() { + if (iomgr_platform_vtable == nullptr) { + grpc_set_default_iomgr_platform(); + } +} + +void grpc_iomgr_platform_init() { iomgr_platform_vtable->init(); } + +void grpc_iomgr_platform_flush() { iomgr_platform_vtable->flush(); } + +void grpc_iomgr_platform_shutdown() { iomgr_platform_vtable->shutdown(); } diff --git a/src/core/lib/iomgr/iomgr_internal.h b/src/core/lib/iomgr/iomgr_internal.h index 644219fb4d..b011d9c7b1 100644 --- a/src/core/lib/iomgr/iomgr_internal.h +++ b/src/core/lib/iomgr/iomgr_internal.h @@ -31,9 +31,21 @@ typedef struct grpc_iomgr_object { struct grpc_iomgr_object* prev; } grpc_iomgr_object; +typedef struct grpc_iomgr_platform_vtable { + void (*init)(void); + void (*flush)(void); + void (*shutdown)(void); +} grpc_iomgr_platform_vtable; + void grpc_iomgr_register_object(grpc_iomgr_object* obj, const char* name); void grpc_iomgr_unregister_object(grpc_iomgr_object* obj); +void grpc_determine_iomgr_platform(); + +void grpc_set_iomgr_platform_vtable(grpc_iomgr_platform_vtable* vtable); + +void grpc_set_default_iomgr_platform(); + void grpc_iomgr_platform_init(void); /** flush any globally queued work from iomgr */ void grpc_iomgr_platform_flush(void); diff --git a/src/core/lib/iomgr/iomgr_posix.cc b/src/core/lib/iomgr/iomgr_posix.cc index 35b8adf01e..66c9cb7ff7 100644 --- a/src/core/lib/iomgr/iomgr_posix.cc +++ b/src/core/lib/iomgr/iomgr_posix.cc @@ -24,19 +24,44 @@ #include "src/core/lib/debug/trace.h" #include "src/core/lib/iomgr/ev_posix.h" +#include "src/core/lib/iomgr/iomgr_internal.h" #include "src/core/lib/iomgr/iomgr_posix.h" +#include "src/core/lib/iomgr/resolve_address.h" +#include "src/core/lib/iomgr/tcp_client.h" #include "src/core/lib/iomgr/tcp_posix.h" +#include "src/core/lib/iomgr/tcp_server.h" +#include "src/core/lib/iomgr/timer.h" -void grpc_iomgr_platform_init(void) { +extern grpc_tcp_server_vtable grpc_posix_tcp_server_vtable; +extern grpc_tcp_client_vtable grpc_posix_tcp_client_vtable; +extern grpc_timer_vtable grpc_generic_timer_vtable; +extern grpc_pollset_vtable grpc_posix_pollset_vtable; +extern grpc_pollset_set_vtable grpc_posix_pollset_set_vtable; +extern grpc_address_resolver_vtable grpc_posix_resolver_vtable; + +static void iomgr_platform_init(void) { grpc_wakeup_fd_global_init(); grpc_event_engine_init(); } -void grpc_iomgr_platform_flush(void) {} +static void iomgr_platform_flush(void) {} -void grpc_iomgr_platform_shutdown(void) { +static void iomgr_platform_shutdown(void) { grpc_event_engine_shutdown(); grpc_wakeup_fd_global_destroy(); } +static grpc_iomgr_platform_vtable vtable = { + iomgr_platform_init, iomgr_platform_flush, iomgr_platform_shutdown}; + +void grpc_set_default_iomgr_platform() { + grpc_set_tcp_client_impl(&grpc_posix_tcp_client_vtable); + grpc_set_tcp_server_impl(&grpc_posix_tcp_server_vtable); + grpc_set_timer_impl(&grpc_generic_timer_vtable); + grpc_set_pollset_vtable(&grpc_posix_pollset_vtable); + grpc_set_pollset_set_vtable(&grpc_posix_pollset_set_vtable); + grpc_set_resolver_impl(&grpc_posix_resolver_vtable); + grpc_set_iomgr_platform_vtable(&vtable); +} + #endif /* GRPC_POSIX_SOCKET */ diff --git a/src/core/lib/iomgr/iomgr_uv.cc b/src/core/lib/iomgr/iomgr_uv.cc index c11c37ca20..4a984446db 100644 --- a/src/core/lib/iomgr/iomgr_uv.cc +++ b/src/core/lib/iomgr/iomgr_uv.cc @@ -1,6 +1,6 @@ /* * - * Copyright 2016 gRPC authors. + * Copyright 2018 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,26 +20,21 @@ #include "src/core/lib/iomgr/port.h" -#ifdef GRPC_UV +#if defined(GRPC_CUSTOM_SOCKET) && defined(GRPC_UV) -#include +#include "src/core/lib/iomgr/iomgr_custom.h" +#include "src/core/lib/iomgr/iomgr_internal.h" +#include "src/core/lib/iomgr/pollset_custom.h" +#include "src/core/lib/iomgr/tcp_custom.h" +#include "src/core/lib/iomgr/timer_custom.h" -#include "src/core/lib/debug/trace.h" -#include "src/core/lib/iomgr/executor.h" -#include "src/core/lib/iomgr/iomgr_uv.h" -#include "src/core/lib/iomgr/pollset_uv.h" -#include "src/core/lib/iomgr/tcp_uv.h" +extern grpc_socket_vtable grpc_uv_socket_vtable; +extern grpc_custom_resolver_vtable uv_resolver_vtable; +extern grpc_custom_timer_vtable uv_timer_vtable; +extern grpc_custom_poller_vtable uv_pollset_vtable; -gpr_thd_id g_init_thread; - -void grpc_iomgr_platform_init(void) { - grpc_core::ExecCtx exec_ctx; - grpc_pollset_global_init(); - - grpc_executor_set_threading(false); - g_init_thread = gpr_thd_currentid(); +void grpc_set_default_iomgr_platform() { + grpc_custom_iomgr_init(&grpc_uv_socket_vtable, &uv_resolver_vtable, + &uv_timer_vtable, &uv_pollset_vtable); } -void grpc_iomgr_platform_flush(void) {} -void grpc_iomgr_platform_shutdown(void) { grpc_pollset_global_shutdown(); } - -#endif /* GRPC_UV */ +#endif diff --git a/src/core/lib/iomgr/iomgr_uv.h b/src/core/lib/iomgr/iomgr_uv.h deleted file mode 100644 index 4d62f00ad6..0000000000 --- a/src/core/lib/iomgr/iomgr_uv.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_LIB_IOMGR_IOMGR_UV_H -#define GRPC_CORE_LIB_IOMGR_IOMGR_UV_H - -#include - -#include "src/core/lib/iomgr/iomgr_internal.h" - -#include - -/* The thread ID of the thread on which grpc was initialized. Used to verify - * that all calls into libuv are made on that same thread */ -extern gpr_thd_id g_init_thread; - -#ifdef GRPC_UV_THREAD_CHECK -#define GRPC_UV_ASSERT_SAME_THREAD() \ - GPR_ASSERT(gpr_thd_currentid() == g_init_thread) -#else -#define GRPC_UV_ASSERT_SAME_THREAD() -#endif /* GRPC_UV_THREAD_CHECK */ - -#endif /* GRPC_CORE_LIB_IOMGR_IOMGR_UV_H */ diff --git a/src/core/lib/iomgr/iomgr_windows.cc b/src/core/lib/iomgr/iomgr_windows.cc index 8c4888ca97..cdef89cbf0 100644 --- a/src/core/lib/iomgr/iomgr_windows.cc +++ b/src/core/lib/iomgr/iomgr_windows.cc @@ -29,7 +29,18 @@ #include "src/core/lib/iomgr/iocp_windows.h" #include "src/core/lib/iomgr/iomgr.h" #include "src/core/lib/iomgr/pollset_windows.h" +#include "src/core/lib/iomgr/resolve_address.h" #include "src/core/lib/iomgr/socket_windows.h" +#include "src/core/lib/iomgr/tcp_client.h" +#include "src/core/lib/iomgr/tcp_server.h" +#include "src/core/lib/iomgr/timer.h" + +extern grpc_tcp_server_vtable grpc_windows_tcp_server_vtable; +extern grpc_tcp_client_vtable grpc_windows_tcp_client_vtable; +extern grpc_timer_vtable grpc_generic_timer_vtable; +extern grpc_pollset_vtable grpc_windows_pollset_vtable; +extern grpc_pollset_set_vtable grpc_windows_pollset_set_vtable; +extern grpc_address_resolver_vtable grpc_windows_resolver_vtable; /* Windows' io manager is going to be fully designed using IO completion ports. All of what we're doing here is basically make sure that @@ -46,18 +57,31 @@ static void winsock_shutdown(void) { GPR_ASSERT(status == 0); } -void grpc_iomgr_platform_init(void) { +static void iomgr_platform_init(void) { winsock_init(); grpc_iocp_init(); grpc_pollset_global_init(); } -void grpc_iomgr_platform_flush(void) { grpc_iocp_flush(); } +static void iomgr_platform_flush(void) { grpc_iocp_flush(); } -void grpc_iomgr_platform_shutdown(void) { +static void iomgr_platform_shutdown(void) { grpc_pollset_global_shutdown(); grpc_iocp_shutdown(); winsock_shutdown(); } +static grpc_iomgr_platform_vtable vtable = { + iomgr_platform_init, iomgr_platform_flush, iomgr_platform_shutdown}; + +void grpc_set_default_iomgr_platform() { + grpc_set_tcp_client_impl(&grpc_windows_tcp_client_vtable); + grpc_set_tcp_server_impl(&grpc_windows_tcp_server_vtable); + grpc_set_timer_impl(&grpc_generic_timer_vtable); + grpc_set_pollset_vtable(&grpc_windows_pollset_vtable); + grpc_set_pollset_set_vtable(&grpc_windows_pollset_set_vtable); + grpc_set_resolver_impl(&grpc_windows_resolver_vtable); + grpc_set_iomgr_platform_vtable(&vtable); +} + #endif /* GRPC_WINSOCK_SOCKET */ diff --git a/src/core/lib/iomgr/pollset.cc b/src/core/lib/iomgr/pollset.cc new file mode 100644 index 0000000000..ebfef1dbc7 --- /dev/null +++ b/src/core/lib/iomgr/pollset.cc @@ -0,0 +1,56 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/lib/iomgr/pollset.h" + +grpc_pollset_vtable* grpc_pollset_impl; + +void grpc_set_pollset_vtable(grpc_pollset_vtable* vtable) { + grpc_pollset_impl = vtable; +} + +void grpc_pollset_global_init() { grpc_pollset_impl->global_init(); } + +void grpc_pollset_global_shutdown() { grpc_pollset_impl->global_shutdown(); } + +void grpc_pollset_init(grpc_pollset* pollset, gpr_mu** mu) { + grpc_pollset_impl->init(pollset, mu); +} + +void grpc_pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { + grpc_pollset_impl->shutdown(pollset, closure); +} + +void grpc_pollset_destroy(grpc_pollset* pollset) { + grpc_pollset_impl->destroy(pollset); +} + +grpc_error* grpc_pollset_work(grpc_pollset* pollset, + grpc_pollset_worker** worker, + grpc_millis deadline) { + return grpc_pollset_impl->work(pollset, worker, deadline); +} + +grpc_error* grpc_pollset_kick(grpc_pollset* pollset, + grpc_pollset_worker* specific_worker) { + return grpc_pollset_impl->kick(pollset, specific_worker); +} + +size_t grpc_pollset_size(void) { return grpc_pollset_impl->pollset_size(); } diff --git a/src/core/lib/iomgr/pollset.h b/src/core/lib/iomgr/pollset.h index 9cc3e4c7fa..28472b360d 100644 --- a/src/core/lib/iomgr/pollset.h +++ b/src/core/lib/iomgr/pollset.h @@ -38,6 +38,24 @@ extern grpc_core::DebugOnlyTraceFlag grpc_trace_fd_refcount; typedef struct grpc_pollset grpc_pollset; typedef struct grpc_pollset_worker grpc_pollset_worker; +typedef struct grpc_pollset_vtable { + void (*global_init)(void); + void (*global_shutdown)(void); + void (*init)(grpc_pollset* pollset, gpr_mu** mu); + void (*shutdown)(grpc_pollset* pollset, grpc_closure* closure); + void (*destroy)(grpc_pollset* pollset); + grpc_error* (*work)(grpc_pollset* pollset, grpc_pollset_worker** worker, + grpc_millis deadline); + grpc_error* (*kick)(grpc_pollset* pollset, + grpc_pollset_worker* specific_worker); + size_t (*pollset_size)(void); +} grpc_pollset_vtable; + +void grpc_set_pollset_vtable(grpc_pollset_vtable* vtable); + +void grpc_pollset_global_init(void); +void grpc_pollset_global_shutdown(void); + size_t grpc_pollset_size(void); /* Initialize a pollset: assumes *pollset contains all zeros */ void grpc_pollset_init(grpc_pollset* pollset, gpr_mu** mu); diff --git a/src/core/lib/iomgr/pollset_custom.cc b/src/core/lib/iomgr/pollset_custom.cc new file mode 100644 index 0000000000..04bd104055 --- /dev/null +++ b/src/core/lib/iomgr/pollset_custom.cc @@ -0,0 +1,106 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/lib/iomgr/port.h" + +#include +#include + +#include +#include +#include + +#include "src/core/lib/iomgr/closure.h" +#include "src/core/lib/iomgr/iomgr_custom.h" +#include "src/core/lib/iomgr/pollset.h" +#include "src/core/lib/iomgr/pollset_custom.h" +#include "src/core/lib/iomgr/timer.h" + +#include "src/core/lib/debug/trace.h" + +static grpc_custom_poller_vtable* poller_vtable; + +struct grpc_pollset { + gpr_mu mu; +}; + +static size_t pollset_size() { return sizeof(grpc_pollset); } + +static void pollset_global_init() { poller_vtable->init(); } + +static void pollset_global_shutdown() { poller_vtable->shutdown(); } + +static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + gpr_mu_init(&pollset->mu); + *mu = &pollset->mu; +} + +static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_NONE); +} + +static void pollset_destroy(grpc_pollset* pollset) { + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + gpr_mu_destroy(&pollset->mu); +} + +static grpc_error* pollset_work(grpc_pollset* pollset, + grpc_pollset_worker** worker_hdl, + grpc_millis deadline) { + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + gpr_mu_unlock(&pollset->mu); + grpc_millis now = grpc_core::ExecCtx::Get()->Now(); + size_t timeout = 0; + if (deadline > now) { + timeout = deadline - now; + } + // We yield here because the poll() call might yield + // control back to the application + grpc_core::ExecCtx* curr = grpc_core::ExecCtx::Get(); + grpc_core::ExecCtx::Set(nullptr); + poller_vtable->poll(timeout); + grpc_core::ExecCtx::Set(curr); + grpc_core::ExecCtx::Get()->InvalidateNow(); + if (grpc_core::ExecCtx::Get()->HasWork()) { + grpc_core::ExecCtx::Get()->Flush(); + } + gpr_mu_lock(&pollset->mu); + return GRPC_ERROR_NONE; +} + +static grpc_error* pollset_kick(grpc_pollset* pollset, + grpc_pollset_worker* specific_worker) { + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + poller_vtable->kick(); + return GRPC_ERROR_NONE; +} + +grpc_pollset_vtable custom_pollset_vtable = { + pollset_global_init, pollset_global_shutdown, + pollset_init, pollset_shutdown, + pollset_destroy, pollset_work, + pollset_kick, pollset_size}; + +void grpc_custom_pollset_init(grpc_custom_poller_vtable* vtable) { + poller_vtable = vtable; + grpc_set_pollset_vtable(&custom_pollset_vtable); +} diff --git a/src/core/lib/iomgr/pollset_custom.h b/src/core/lib/iomgr/pollset_custom.h new file mode 100644 index 0000000000..9e2027f7f4 --- /dev/null +++ b/src/core/lib/iomgr/pollset_custom.h @@ -0,0 +1,35 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_LIB_IOMGR_POLLSET_CUSTOM_H +#define GRPC_CORE_LIB_IOMGR_POLLSET_CUSTOM_H + +#include + +#include + +typedef struct grpc_custom_poller_vtable { + void (*init)(); + void (*poll)(size_t timeout_ms); + void (*kick)(); + void (*shutdown)(); +} grpc_custom_poller_vtable; + +void grpc_custom_pollset_init(grpc_custom_poller_vtable* vtable); + +#endif /* GRPC_CORE_LIB_IOMGR_POLLSET_CUSTOM_H */ diff --git a/src/core/lib/iomgr/pollset_set.cc b/src/core/lib/iomgr/pollset_set.cc new file mode 100644 index 0000000000..42a647a737 --- /dev/null +++ b/src/core/lib/iomgr/pollset_set.cc @@ -0,0 +1,55 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/lib/iomgr/pollset_set.h" + +grpc_pollset_set_vtable* grpc_pollset_set_impl; + +void grpc_set_pollset_set_vtable(grpc_pollset_set_vtable* vtable) { + grpc_pollset_set_impl = vtable; +} + +grpc_pollset_set* grpc_pollset_set_create() { + return grpc_pollset_set_impl->create(); +} + +void grpc_pollset_set_destroy(grpc_pollset_set* pollset_set) { + grpc_pollset_set_impl->destroy(pollset_set); +} + +void grpc_pollset_set_add_pollset(grpc_pollset_set* pollset_set, + grpc_pollset* pollset) { + grpc_pollset_set_impl->add_pollset(pollset_set, pollset); +} + +void grpc_pollset_set_del_pollset(grpc_pollset_set* pollset_set, + grpc_pollset* pollset) { + grpc_pollset_set_impl->del_pollset(pollset_set, pollset); +} + +void grpc_pollset_set_add_pollset_set(grpc_pollset_set* bag, + grpc_pollset_set* item) { + grpc_pollset_set_impl->add_pollset_set(bag, item); +} + +void grpc_pollset_set_del_pollset_set(grpc_pollset_set* bag, + grpc_pollset_set* item) { + grpc_pollset_set_impl->del_pollset_set(bag, item); +} diff --git a/src/core/lib/iomgr/pollset_set.h b/src/core/lib/iomgr/pollset_set.h index 18f30aa94e..d3355b8ff8 100644 --- a/src/core/lib/iomgr/pollset_set.h +++ b/src/core/lib/iomgr/pollset_set.h @@ -30,6 +30,17 @@ typedef struct grpc_pollset_set grpc_pollset_set; +typedef struct grpc_pollset_set_vtable { + grpc_pollset_set* (*create)(void); + void (*destroy)(grpc_pollset_set* pollset_set); + void (*add_pollset)(grpc_pollset_set* pollset_set, grpc_pollset* pollset); + void (*del_pollset)(grpc_pollset_set* pollset_set, grpc_pollset* pollset); + void (*add_pollset_set)(grpc_pollset_set* bag, grpc_pollset_set* item); + void (*del_pollset_set)(grpc_pollset_set* bag, grpc_pollset_set* item); +} grpc_pollset_set_vtable; + +void grpc_set_pollset_set_vtable(grpc_pollset_set_vtable* vtable); + grpc_pollset_set* grpc_pollset_set_create(void); void grpc_pollset_set_destroy(grpc_pollset_set* pollset_set); void grpc_pollset_set_add_pollset(grpc_pollset_set* pollset_set, diff --git a/src/core/lib/iomgr/pollset_set_custom.cc b/src/core/lib/iomgr/pollset_set_custom.cc new file mode 100644 index 0000000000..b1ee66020d --- /dev/null +++ b/src/core/lib/iomgr/pollset_set_custom.cc @@ -0,0 +1,48 @@ +/* + * + * Copyright 2016 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/lib/iomgr/port.h" + +#include "src/core/lib/iomgr/pollset_set.h" + +grpc_pollset_set* pollset_set_create(void) { + return (grpc_pollset_set*)((intptr_t)0xdeafbeef); +} + +void pollset_set_destroy(grpc_pollset_set* pollset_set) {} + +void pollset_set_add_pollset(grpc_pollset_set* pollset_set, + grpc_pollset* pollset) {} + +void pollset_set_del_pollset(grpc_pollset_set* pollset_set, + grpc_pollset* pollset) {} + +void pollset_set_add_pollset_set(grpc_pollset_set* bag, + grpc_pollset_set* item) {} + +void pollset_set_del_pollset_set(grpc_pollset_set* bag, + grpc_pollset_set* item) {} + +static grpc_pollset_set_vtable vtable = { + pollset_set_create, pollset_set_destroy, + pollset_set_add_pollset, pollset_set_del_pollset, + pollset_set_add_pollset_set, pollset_set_del_pollset_set}; + +void grpc_custom_pollset_set_init() { grpc_set_pollset_set_vtable(&vtable); } diff --git a/src/core/lib/iomgr/pollset_set_custom.h b/src/core/lib/iomgr/pollset_set_custom.h new file mode 100644 index 0000000000..80e19a1fef --- /dev/null +++ b/src/core/lib/iomgr/pollset_set_custom.h @@ -0,0 +1,26 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_LIB_IOMGR_POLLSET_SET_CUSTOM_H +#define GRPC_CORE_LIB_IOMGR_POLLSET_SET_CUSTOM_H + +#include + +void grpc_custom_pollset_set_init(); + +#endif /* GRPC_CORE_LIB_IOMGR_POLLSET_SET_CUSTOM_H */ diff --git a/src/core/lib/iomgr/pollset_set_uv.cc b/src/core/lib/iomgr/pollset_set_uv.cc deleted file mode 100644 index 50814c1f0a..0000000000 --- a/src/core/lib/iomgr/pollset_set_uv.cc +++ /dev/null @@ -1,45 +0,0 @@ -/* - * - * Copyright 2016 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/lib/iomgr/port.h" - -#ifdef GRPC_UV - -#include "src/core/lib/iomgr/pollset_set.h" - -grpc_pollset_set* grpc_pollset_set_create(void) { - return (grpc_pollset_set*)((intptr_t)0xdeafbeef); -} - -void grpc_pollset_set_destroy(grpc_pollset_set* pollset_set) {} - -void grpc_pollset_set_add_pollset(grpc_pollset_set* pollset_set, - grpc_pollset* pollset) {} - -void grpc_pollset_set_del_pollset(grpc_pollset_set* pollset_set, - grpc_pollset* pollset) {} - -void grpc_pollset_set_add_pollset_set(grpc_pollset_set* bag, - grpc_pollset_set* item) {} - -void grpc_pollset_set_del_pollset_set(grpc_pollset_set* bag, - grpc_pollset_set* item) {} - -#endif /* GRPC_UV */ diff --git a/src/core/lib/iomgr/pollset_set_windows.cc b/src/core/lib/iomgr/pollset_set_windows.cc index ff3f6a944e..bb9e7f5d28 100644 --- a/src/core/lib/iomgr/pollset_set_windows.cc +++ b/src/core/lib/iomgr/pollset_set_windows.cc @@ -25,22 +25,27 @@ #include "src/core/lib/iomgr/pollset_set_windows.h" -grpc_pollset_set* grpc_pollset_set_create(void) { +static grpc_pollset_set* pollset_set_create(void) { return (grpc_pollset_set*)((intptr_t)0xdeafbeef); } -void grpc_pollset_set_destroy(grpc_pollset_set* pollset_set) {} +static void pollset_set_destroy(grpc_pollset_set* pollset_set) {} -void grpc_pollset_set_add_pollset(grpc_pollset_set* pollset_set, - grpc_pollset* pollset) {} +static void pollset_set_add_pollset(grpc_pollset_set* pollset_set, + grpc_pollset* pollset) {} -void grpc_pollset_set_del_pollset(grpc_pollset_set* pollset_set, - grpc_pollset* pollset) {} +static void pollset_set_del_pollset(grpc_pollset_set* pollset_set, + grpc_pollset* pollset) {} -void grpc_pollset_set_add_pollset_set(grpc_pollset_set* bag, - grpc_pollset_set* item) {} +static void pollset_set_add_pollset_set(grpc_pollset_set* bag, + grpc_pollset_set* item) {} -void grpc_pollset_set_del_pollset_set(grpc_pollset_set* bag, - grpc_pollset_set* item) {} +static void pollset_set_del_pollset_set(grpc_pollset_set* bag, + grpc_pollset_set* item) {} + +grpc_pollset_set_vtable grpc_windows_pollset_set_vtable = { + pollset_set_create, pollset_set_destroy, + pollset_set_add_pollset, pollset_set_del_pollset, + pollset_set_add_pollset_set, pollset_set_del_pollset_set}; #endif /* GRPC_WINSOCK_SOCKET */ diff --git a/src/core/lib/iomgr/pollset_uv.cc b/src/core/lib/iomgr/pollset_uv.cc index c6a2f43bf1..bade6eae6c 100644 --- a/src/core/lib/iomgr/pollset_uv.cc +++ b/src/core/lib/iomgr/pollset_uv.cc @@ -22,137 +22,72 @@ #ifdef GRPC_UV -#include - -#include - #include #include -#include - -#include "src/core/lib/iomgr/iomgr_uv.h" -#include "src/core/lib/iomgr/pollset.h" -#include "src/core/lib/iomgr/pollset_uv.h" +#include "src/core/lib/iomgr/pollset_custom.h" -#include "src/core/lib/debug/trace.h" - -grpc_core::DebugOnlyTraceFlag grpc_trace_fd_refcount(false, "fd_refcount"); - -struct grpc_pollset { - uv_timer_t* timer; - int shutting_down; -}; +#include /* Indicates that grpc_pollset_work should run an iteration of the UV loop before running callbacks. This defaults to 1, and should be disabled if grpc_pollset_work will be called within the callstack of uv_run */ -int grpc_pollset_work_run_loop; - -gpr_mu grpc_polling_mu; +int grpc_pollset_work_run_loop = 1; -/* This is used solely to kick the uv loop, by setting a callback to be run - immediately in the next loop iteration. - Note: In the future, if there is a bug that involves missing wakeups in the - future, try adding a uv_async_t to kick the loop differently */ -uv_timer_t* dummy_uv_handle; +static bool g_kicked = false; -size_t grpc_pollset_size() { return sizeof(grpc_pollset); } +typedef struct uv_poller_handle { + uv_timer_t poll_timer; + uv_timer_t kick_timer; + int refs; +} uv_poller_handle; -void dummy_timer_cb(uv_timer_t* handle) {} +static uv_poller_handle* g_handle; -void dummy_handle_close_cb(uv_handle_t* handle) { gpr_free(handle); } - -void grpc_pollset_global_init(void) { - gpr_mu_init(&grpc_polling_mu); - dummy_uv_handle = (uv_timer_t*)gpr_malloc(sizeof(uv_timer_t)); - uv_timer_init(uv_default_loop(), dummy_uv_handle); - grpc_pollset_work_run_loop = 1; -} - -void grpc_pollset_global_shutdown(void) { - GRPC_UV_ASSERT_SAME_THREAD(); - gpr_mu_destroy(&grpc_polling_mu); - uv_close((uv_handle_t*)dummy_uv_handle, dummy_handle_close_cb); +static void init() { + g_handle = (uv_poller_handle*)gpr_malloc(sizeof(uv_poller_handle)); + g_handle->refs = 2; + uv_timer_init(uv_default_loop(), &g_handle->poll_timer); + uv_timer_init(uv_default_loop(), &g_handle->kick_timer); } -static void timer_run_cb(uv_timer_t* timer) {} +static void empty_timer_cb(uv_timer_t* handle) {} -static void timer_close_cb(uv_handle_t* handle) { - handle->data = (void*)1; - gpr_free(handle); -} +static void kick_timer_cb(uv_timer_t* handle) { g_kicked = false; } -void grpc_pollset_init(grpc_pollset* pollset, gpr_mu** mu) { - GRPC_UV_ASSERT_SAME_THREAD(); - *mu = &grpc_polling_mu; - pollset->timer = (uv_timer_t*)gpr_malloc(sizeof(uv_timer_t)); - uv_timer_init(uv_default_loop(), pollset->timer); - pollset->shutting_down = 0; +static void run_loop(size_t timeout) { + if (grpc_pollset_work_run_loop) { + if (timeout == 0) { + uv_run(uv_default_loop(), UV_RUN_NOWAIT); + } else { + uv_timer_start(&g_handle->poll_timer, empty_timer_cb, timeout, 0); + uv_run(uv_default_loop(), UV_RUN_ONCE); + uv_timer_stop(&g_handle->poll_timer); + } + } } -void grpc_pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { - GPR_ASSERT(!pollset->shutting_down); - GRPC_UV_ASSERT_SAME_THREAD(); - pollset->shutting_down = 1; - if (grpc_pollset_work_run_loop) { - // Drain any pending UV callbacks without blocking - uv_run(uv_default_loop(), UV_RUN_NOWAIT); - } else { - // kick the loop once - uv_timer_start(dummy_uv_handle, dummy_timer_cb, 0, 0); +static void kick() { + if (!g_kicked) { + g_kicked = true; + uv_timer_start(&g_handle->kick_timer, kick_timer_cb, 0, 0); } - GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_NONE); } -void grpc_pollset_destroy(grpc_pollset* pollset) { - GRPC_UV_ASSERT_SAME_THREAD(); - uv_close((uv_handle_t*)pollset->timer, timer_close_cb); - // timer.data is a boolean indicating that the timer has finished closing - pollset->timer->data = (void*)0; - if (grpc_pollset_work_run_loop) { - while (!pollset->timer->data) { - uv_run(uv_default_loop(), UV_RUN_NOWAIT); - } +static void close_timer_cb(uv_handle_t* handle) { + g_handle->refs--; + if (g_handle->refs == 0) { + gpr_free(g_handle); } } -grpc_error* grpc_pollset_work(grpc_pollset* pollset, - grpc_pollset_worker** worker_hdl, - grpc_millis deadline) { - uint64_t timeout; - GRPC_UV_ASSERT_SAME_THREAD(); - gpr_mu_unlock(&grpc_polling_mu); +static void shutdown() { + uv_close((uv_handle_t*)&g_handle->poll_timer, close_timer_cb); + uv_close((uv_handle_t*)&g_handle->kick_timer, close_timer_cb); if (grpc_pollset_work_run_loop) { - grpc_millis now = grpc_core::ExecCtx::Get()->Now(); - if (deadline >= now) { - timeout = deadline - now; - } else { - timeout = 0; - } - /* We special-case timeout=0 so that we don't bother with the timer when - the loop won't block anyway */ - if (timeout > 0) { - uv_timer_start(pollset->timer, timer_run_cb, timeout, 0); - /* Run until there is some I/O activity or the timer triggers. It doesn't - matter which happens */ - uv_run(uv_default_loop(), UV_RUN_ONCE); - uv_timer_stop(pollset->timer); - } else { - uv_run(uv_default_loop(), UV_RUN_NOWAIT); - } - } - if (!grpc_closure_list_empty(*grpc_core::ExecCtx::Get()->closure_list())) { - grpc_core::ExecCtx::Get()->Flush(); + GPR_ASSERT(uv_run(uv_default_loop(), UV_RUN_DEFAULT) == 0); } - gpr_mu_lock(&grpc_polling_mu); - return GRPC_ERROR_NONE; } -grpc_error* grpc_pollset_kick(grpc_pollset* pollset, - grpc_pollset_worker* specific_worker) { - GRPC_UV_ASSERT_SAME_THREAD(); - uv_timer_start(dummy_uv_handle, dummy_timer_cb, 0, 0); - return GRPC_ERROR_NONE; -} +grpc_custom_poller_vtable uv_pollset_vtable = {init, run_loop, kick, shutdown}; #endif /* GRPC_UV */ diff --git a/src/core/lib/iomgr/pollset_uv.h b/src/core/lib/iomgr/pollset_uv.h index 566c110ca6..de82bcc1d3 100644 --- a/src/core/lib/iomgr/pollset_uv.h +++ b/src/core/lib/iomgr/pollset_uv.h @@ -21,7 +21,12 @@ extern int grpc_pollset_work_run_loop; -void grpc_pollset_global_init(void); -void grpc_pollset_global_shutdown(void); +typedef struct grpc_custom_poller_vtable { + void (*init)(void); + void (*run_loop)(int blocking); +} grpc_custom_poller_vtable; + +void grpc_custom_pollset_global_init(grpc_custom_poller_vtable* vtable); +void grpc_custom_pollset_global_shutdown(void); #endif /* GRPC_CORE_LIB_IOMGR_POLLSET_UV_H */ diff --git a/src/core/lib/iomgr/pollset_windows.cc b/src/core/lib/iomgr/pollset_windows.cc index c1b83ddc14..e9a808d8ad 100644 --- a/src/core/lib/iomgr/pollset_windows.cc +++ b/src/core/lib/iomgr/pollset_windows.cc @@ -38,7 +38,7 @@ gpr_mu grpc_polling_mu; static grpc_pollset_worker* g_active_poller; static grpc_pollset_worker g_global_root_worker; -void grpc_pollset_global_init(void) { +static void pollset_global_init(void) { gpr_mu_init(&grpc_polling_mu); g_active_poller = NULL; g_global_root_worker.links[GRPC_POLLSET_WORKER_LINK_GLOBAL].next = @@ -46,7 +46,7 @@ void grpc_pollset_global_init(void) { &g_global_root_worker; } -void grpc_pollset_global_shutdown(void) { gpr_mu_destroy(&grpc_polling_mu); } +static void pollset_global_shutdown(void) { gpr_mu_destroy(&grpc_polling_mu); } static void remove_worker(grpc_pollset_worker* worker, grpc_pollset_worker_link_type type) { @@ -80,21 +80,21 @@ static void push_front_worker(grpc_pollset_worker* root, worker->links[type].next->links[type].prev = worker; } -size_t grpc_pollset_size(void) { return sizeof(grpc_pollset); } +static size_t pollset_size(void) { return sizeof(grpc_pollset); } /* There isn't really any such thing as a pollset under Windows, due to the nature of the IO completion ports. We're still going to provide a minimal set of features for the sake of the rest of grpc. But grpc_pollset_work won't actually do any polling, and return as quickly as possible. */ -void grpc_pollset_init(grpc_pollset* pollset, gpr_mu** mu) { +static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { *mu = &grpc_polling_mu; pollset->root_worker.links[GRPC_POLLSET_WORKER_LINK_POLLSET].next = pollset->root_worker.links[GRPC_POLLSET_WORKER_LINK_POLLSET].prev = &pollset->root_worker; } -void grpc_pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { +static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { pollset->shutting_down = 1; grpc_pollset_kick(pollset, GRPC_POLLSET_KICK_BROADCAST); if (!pollset->is_iocp_worker) { @@ -104,11 +104,11 @@ void grpc_pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { } } -void grpc_pollset_destroy(grpc_pollset* pollset) {} +static void pollset_destroy(grpc_pollset* pollset) {} -grpc_error* grpc_pollset_work(grpc_pollset* pollset, - grpc_pollset_worker** worker_hdl, - grpc_millis deadline) { +static grpc_error* pollset_work(grpc_pollset* pollset, + grpc_pollset_worker** worker_hdl, + grpc_millis deadline) { grpc_pollset_worker worker; if (worker_hdl) *worker_hdl = &worker; @@ -182,8 +182,8 @@ done: return GRPC_ERROR_NONE; } -grpc_error* grpc_pollset_kick(grpc_pollset* p, - grpc_pollset_worker* specific_worker) { +static grpc_error* pollset_kick(grpc_pollset* p, + grpc_pollset_worker* specific_worker) { if (specific_worker != NULL) { if (specific_worker == GRPC_POLLSET_KICK_BROADCAST) { for (specific_worker = @@ -220,4 +220,10 @@ grpc_error* grpc_pollset_kick(grpc_pollset* p, return GRPC_ERROR_NONE; } +grpc_pollset_vtable grpc_windows_pollset_vtable = { + pollset_global_init, pollset_global_shutdown, + pollset_init, pollset_shutdown, + pollset_destroy, pollset_work, + pollset_kick, pollset_size}; + #endif /* GRPC_WINSOCK_SOCKET */ diff --git a/src/core/lib/iomgr/port.h b/src/core/lib/iomgr/port.h index 25090898ed..c1dcc52618 100644 --- a/src/core/lib/iomgr/port.h +++ b/src/core/lib/iomgr/port.h @@ -21,8 +21,11 @@ #ifndef GRPC_CORE_LIB_IOMGR_PORT_H #define GRPC_CORE_LIB_IOMGR_PORT_H -#if defined(GRPC_UV) -// Do nothing +#ifdef GRPC_UV +#define GRPC_CUSTOM_SOCKET +#endif +#if defined(GRPC_CUSTOM_SOCKET) +// Do Nothing #elif defined(GPR_MANYLINUX1) #define GRPC_HAVE_ARPA_NAMESER 1 #define GRPC_HAVE_IFADDRS 1 @@ -33,13 +36,10 @@ #define GRPC_POSIX_FORK 1 #define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1 #define GRPC_POSIX_SOCKET 1 -#define GRPC_POSIX_SOCKETADDR 1 #define GRPC_POSIX_SOCKETUTILS 1 #define GRPC_POSIX_WAKEUP_FD 1 -#define GRPC_TIMER_USE_GENERIC 1 #define GRPC_LINUX_EPOLL 1 #elif defined(GPR_WINDOWS) -#define GRPC_TIMER_USE_GENERIC 1 #define GRPC_WINSOCK_SOCKET 1 #define GRPC_WINDOWS_SOCKETUTILS 1 #elif defined(GPR_ANDROID) @@ -49,10 +49,8 @@ #define GRPC_HAVE_UNIX_SOCKET 1 #define GRPC_LINUX_EVENTFD 1 #define GRPC_POSIX_SOCKET 1 -#define GRPC_POSIX_SOCKETADDR 1 #define GRPC_POSIX_SOCKETUTILS 1 #define GRPC_POSIX_WAKEUP_FD 1 -#define GRPC_TIMER_USE_GENERIC 1 #elif defined(GPR_LINUX) #define GRPC_HAVE_ARPA_NAMESER 1 #define GRPC_HAVE_IFADDRS 1 @@ -64,9 +62,7 @@ #define GRPC_POSIX_FORK 1 #define GRPC_POSIX_HOST_NAME_MAX 1 #define GRPC_POSIX_SOCKET 1 -#define GRPC_POSIX_SOCKETADDR 1 #define GRPC_POSIX_WAKEUP_FD 1 -#define GRPC_TIMER_USE_GENERIC 1 #ifdef __GLIBC_PREREQ #if __GLIBC_PREREQ(2, 4) #define GRPC_LINUX_EPOLL 1 @@ -100,11 +96,9 @@ #define GRPC_POSIX_FORK 1 #define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1 #define GRPC_POSIX_SOCKET 1 -#define GRPC_POSIX_SOCKETADDR 1 #define GRPC_POSIX_SOCKETUTILS 1 #define GRPC_POSIX_SYSCONF 1 #define GRPC_POSIX_WAKEUP_FD 1 -#define GRPC_TIMER_USE_GENERIC 1 #elif defined(GPR_FREEBSD) #define GRPC_HAVE_ARPA_NAMESER 1 #define GRPC_HAVE_IFADDRS 1 @@ -114,36 +108,31 @@ #define GRPC_POSIX_FORK 1 #define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1 #define GRPC_POSIX_SOCKET 1 -#define GRPC_POSIX_SOCKETADDR 1 #define GRPC_POSIX_SOCKETUTILS 1 #define GRPC_POSIX_WAKEUP_FD 1 -#define GRPC_TIMER_USE_GENERIC 1 #elif defined(GPR_OPENBSD) #define GRPC_HAVE_IFADDRS 1 #define GRPC_HAVE_IPV6_RECVPKTINFO 1 #define GRPC_HAVE_UNIX_SOCKET 1 #define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1 #define GRPC_POSIX_SOCKET 1 -#define GRPC_POSIX_SOCKETADDR 1 #define GRPC_POSIX_SOCKETUTILS 1 #define GRPC_POSIX_WAKEUP_FD 1 -#define GRPC_TIMER_USE_GENERIC 1 #elif defined(GPR_NACL) #define GRPC_HAVE_ARPA_NAMESER 1 #define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1 #define GRPC_POSIX_SOCKET 1 -#define GRPC_POSIX_SOCKETADDR 1 #define GRPC_POSIX_SOCKETUTILS 1 #define GRPC_POSIX_WAKEUP_FD 1 -#define GRPC_TIMER_USE_GENERIC 1 #elif !defined(GPR_NO_AUTODETECT_PLATFORM) #error "Platform not recognized" #endif #if defined(GRPC_POSIX_SOCKET) + defined(GRPC_WINSOCK_SOCKET) + \ - defined(GRPC_CUSTOM_SOCKET) + defined(GRPC_UV) != \ + defined(GRPC_CUSTOM_SOCKET) != \ 1 -#error Must define exactly one of GRPC_POSIX_SOCKET, GRPC_WINSOCK_SOCKET, GPR_CUSTOM_SOCKET +#error \ + "Must define exactly one of GRPC_POSIX_SOCKET, GRPC_WINSOCK_SOCKET, GRPC_CUSTOM_SOCKET" #endif #if defined(GRPC_POSIX_HOST_NAME_MAX) && defined(GRPC_POSIX_SYSCONF) diff --git a/src/core/lib/iomgr/resolve_address.cc b/src/core/lib/iomgr/resolve_address.cc new file mode 100644 index 0000000000..f2a4676369 --- /dev/null +++ b/src/core/lib/iomgr/resolve_address.cc @@ -0,0 +1,50 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include +#include "src/core/lib/iomgr/resolve_address.h" + +grpc_address_resolver_vtable* grpc_resolve_address_impl; + +void grpc_set_resolver_impl(grpc_address_resolver_vtable* vtable) { + grpc_resolve_address_impl = vtable; +} + +void grpc_resolve_address(const char* addr, const char* default_port, + grpc_pollset_set* interested_parties, + grpc_closure* on_done, + grpc_resolved_addresses** addresses) { + grpc_resolve_address_impl->resolve_address( + addr, default_port, interested_parties, on_done, addresses); +} + +void grpc_resolved_addresses_destroy(grpc_resolved_addresses* addrs) { + if (addrs != nullptr) { + gpr_free(addrs->addrs); + } + gpr_free(addrs); +} + +grpc_error* grpc_blocking_resolve_address(const char* name, + const char* default_port, + grpc_resolved_addresses** addresses) { + return grpc_resolve_address_impl->blocking_resolve_address(name, default_port, + addresses); +} diff --git a/src/core/lib/iomgr/resolve_address.h b/src/core/lib/iomgr/resolve_address.h index 10a7822654..7da5caaa8e 100644 --- a/src/core/lib/iomgr/resolve_address.h +++ b/src/core/lib/iomgr/resolve_address.h @@ -37,20 +37,33 @@ typedef struct { grpc_resolved_address* addrs; } grpc_resolved_addresses; +typedef struct grpc_address_resolver_vtable { + void (*resolve_address)(const char* addr, const char* default_port, + grpc_pollset_set* interested_parties, + grpc_closure* on_done, + grpc_resolved_addresses** addresses); + grpc_error* (*blocking_resolve_address)(const char* name, + const char* default_port, + grpc_resolved_addresses** addresses); +} grpc_address_resolver_vtable; + +void grpc_set_resolver_impl(grpc_address_resolver_vtable* vtable); + /* Asynchronously resolve addr. Use default_port if a port isn't designated in addr, otherwise use the port in addr. */ /* TODO(ctiller): add a timeout here */ -extern void (*grpc_resolve_address)(const char* addr, const char* default_port, - grpc_pollset_set* interested_parties, - grpc_closure* on_done, - grpc_resolved_addresses** addresses); +void grpc_resolve_address(const char* addr, const char* default_port, + grpc_pollset_set* interested_parties, + grpc_closure* on_done, + grpc_resolved_addresses** addresses); + /* Destroy resolved addresses */ void grpc_resolved_addresses_destroy(grpc_resolved_addresses* addresses); -/* Resolve addr in a blocking fashion. Returns NULL on failure. On success, +/* Resolve addr in a blocking fashion. On success, result must be freed with grpc_resolved_addresses_destroy. */ -extern grpc_error* (*grpc_blocking_resolve_address)( - const char* name, const char* default_port, - grpc_resolved_addresses** addresses); +grpc_error* grpc_blocking_resolve_address(const char* name, + const char* default_port, + grpc_resolved_addresses** addresses); #endif /* GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_H */ diff --git a/src/core/lib/iomgr/resolve_address_custom.cc b/src/core/lib/iomgr/resolve_address_custom.cc new file mode 100644 index 0000000000..9cf7817f66 --- /dev/null +++ b/src/core/lib/iomgr/resolve_address_custom.cc @@ -0,0 +1,187 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/lib/iomgr/port.h" + +#include +#include + +#include +#include "src/core/lib/gpr/host_port.h" +#include "src/core/lib/gpr/string.h" +#include "src/core/lib/gpr/useful.h" + +#include "src/core/lib/iomgr/iomgr_custom.h" +#include "src/core/lib/iomgr/resolve_address_custom.h" +#include "src/core/lib/iomgr/sockaddr_utils.h" + +#include + +typedef struct grpc_custom_resolver { + grpc_closure* on_done; + grpc_resolved_addresses** addresses; + char* host; + char* port; +} grpc_custom_resolver; + +static grpc_custom_resolver_vtable* resolve_address_vtable = nullptr; + +static int retry_named_port_failure(grpc_custom_resolver* r, + grpc_resolved_addresses** res) { + // This loop is copied from resolve_address_posix.c + const char* svc[][2] = {{"http", "80"}, {"https", "443"}}; + for (size_t i = 0; i < GPR_ARRAY_SIZE(svc); i++) { + if (strcmp(r->port, svc[i][0]) == 0) { + gpr_free(r->port); + r->port = gpr_strdup(svc[i][1]); + if (res) { + grpc_error* error = + resolve_address_vtable->resolve(r->host, r->port, res); + if (error != GRPC_ERROR_NONE) { + GRPC_ERROR_UNREF(error); + return 0; + } + } else { + resolve_address_vtable->resolve_async(r, r->host, r->port); + } + return 1; + } + } + return 0; +} + +void grpc_custom_resolve_callback(grpc_custom_resolver* r, + grpc_resolved_addresses* result, + grpc_error* error) { + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + grpc_core::ExecCtx exec_ctx; + if (error == GRPC_ERROR_NONE) { + *r->addresses = result; + } else if (retry_named_port_failure(r, nullptr)) { + return; + } + if (r->on_done) { + GRPC_CLOSURE_SCHED(r->on_done, error); + } + gpr_free(r->host); + gpr_free(r->port); + gpr_free(r); +} + +static grpc_error* try_split_host_port(const char* name, + const char* default_port, char** host, + char** port) { + /* parse name, splitting it into host and port parts */ + grpc_error* error; + gpr_split_host_port(name, host, port); + if (*host == nullptr) { + char* msg; + gpr_asprintf(&msg, "unparseable host:port: '%s'", name); + error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); + gpr_free(msg); + return error; + } + if (*port == nullptr) { + // TODO(murgatroid99): add tests for this case + if (default_port == nullptr) { + char* msg; + gpr_asprintf(&msg, "no port in name '%s'", name); + error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); + gpr_free(msg); + return error; + } + *port = gpr_strdup(default_port); + } + return GRPC_ERROR_NONE; +} + +static grpc_error* blocking_resolve_address_impl( + const char* name, const char* default_port, + grpc_resolved_addresses** addresses) { + char* host; + char* port; + grpc_error* err; + + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + + err = try_split_host_port(name, default_port, &host, &port); + if (err != GRPC_ERROR_NONE) { + gpr_free(host); + gpr_free(port); + return err; + } + + /* Call getaddrinfo */ + grpc_custom_resolver resolver; + resolver.host = host; + resolver.port = port; + + grpc_resolved_addresses* addrs; + grpc_core::ExecCtx* curr = grpc_core::ExecCtx::Get(); + grpc_core::ExecCtx::Set(nullptr); + err = resolve_address_vtable->resolve(host, port, &addrs); + if (err != GRPC_ERROR_NONE) { + if (retry_named_port_failure(&resolver, &addrs)) { + GRPC_ERROR_UNREF(err); + err = GRPC_ERROR_NONE; + } + } + grpc_core::ExecCtx::Set(curr); + if (err == GRPC_ERROR_NONE) { + *addresses = addrs; + } + gpr_free(resolver.host); + gpr_free(resolver.port); + return err; +} + +static void resolve_address_impl(const char* name, const char* default_port, + grpc_pollset_set* interested_parties, + grpc_closure* on_done, + grpc_resolved_addresses** addrs) { + grpc_custom_resolver* r = nullptr; + char* host = nullptr; + char* port = nullptr; + grpc_error* err; + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + err = try_split_host_port(name, default_port, &host, &port); + if (err != GRPC_ERROR_NONE) { + GRPC_CLOSURE_SCHED(on_done, err); + gpr_free(host); + gpr_free(port); + return; + } + r = (grpc_custom_resolver*)gpr_malloc(sizeof(grpc_custom_resolver)); + r->on_done = on_done; + r->addresses = addrs; + r->host = host; + r->port = port; + + /* Call getaddrinfo */ + resolve_address_vtable->resolve_async(r, r->host, r->port); +} + +static grpc_address_resolver_vtable custom_resolver_vtable = { + resolve_address_impl, blocking_resolve_address_impl}; + +void grpc_custom_resolver_init(grpc_custom_resolver_vtable* impl) { + resolve_address_vtable = impl; + grpc_set_resolver_impl(&custom_resolver_vtable); +} diff --git a/src/core/lib/iomgr/resolve_address_custom.h b/src/core/lib/iomgr/resolve_address_custom.h new file mode 100644 index 0000000000..e0c6714087 --- /dev/null +++ b/src/core/lib/iomgr/resolve_address_custom.h @@ -0,0 +1,43 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_CUSTOM_H +#define GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_CUSTOM_H + +#include + +#include "src/core/lib/iomgr/port.h" + +#include "src/core/lib/iomgr/resolve_address.h" +#include "src/core/lib/iomgr/sockaddr.h" + +typedef struct grpc_custom_resolver grpc_custom_resolver; + +typedef struct grpc_custom_resolver_vtable { + grpc_error* (*resolve)(char* host, char* port, grpc_resolved_addresses** res); + void (*resolve_async)(grpc_custom_resolver* resolver, char* host, char* port); +} grpc_custom_resolver_vtable; + +void grpc_custom_resolve_callback(grpc_custom_resolver* resolver, + grpc_resolved_addresses* result, + grpc_error* error); + +/* Internal APIs */ +void grpc_custom_resolver_init(grpc_custom_resolver_vtable* impl); + +#endif /* GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_CUSTOM_H */ diff --git a/src/core/lib/iomgr/resolve_address_posix.cc b/src/core/lib/iomgr/resolve_address_posix.cc index 2f68dbe214..a82075542f 100644 --- a/src/core/lib/iomgr/resolve_address_posix.cc +++ b/src/core/lib/iomgr/resolve_address_posix.cc @@ -42,7 +42,7 @@ #include "src/core/lib/iomgr/iomgr_internal.h" #include "src/core/lib/iomgr/unix_sockets_posix.h" -static grpc_error* blocking_resolve_address_impl( +static grpc_error* posix_blocking_resolve_address( const char* name, const char* default_port, grpc_resolved_addresses** addresses) { grpc_core::ExecCtx exec_ctx; @@ -141,10 +141,6 @@ done: return err; } -grpc_error* (*grpc_blocking_resolve_address)( - const char* name, const char* default_port, - grpc_resolved_addresses** addresses) = blocking_resolve_address_impl; - typedef struct { char* name; char* default_port; @@ -165,17 +161,10 @@ static void do_request_thread(void* rp, grpc_error* error) { gpr_free(r); } -void grpc_resolved_addresses_destroy(grpc_resolved_addresses* addrs) { - if (addrs != nullptr) { - gpr_free(addrs->addrs); - } - gpr_free(addrs); -} - -static void resolve_address_impl(const char* name, const char* default_port, - grpc_pollset_set* interested_parties, - grpc_closure* on_done, - grpc_resolved_addresses** addrs) { +static void posix_resolve_address(const char* name, const char* default_port, + grpc_pollset_set* interested_parties, + grpc_closure* on_done, + grpc_resolved_addresses** addrs) { request* r = static_cast(gpr_malloc(sizeof(request))); GRPC_CLOSURE_INIT(&r->request_closure, do_request_thread, r, grpc_executor_scheduler(GRPC_EXECUTOR_SHORT)); @@ -186,9 +175,6 @@ static void resolve_address_impl(const char* name, const char* default_port, GRPC_CLOSURE_SCHED(&r->request_closure, GRPC_ERROR_NONE); } -void (*grpc_resolve_address)( - const char* name, const char* default_port, - grpc_pollset_set* interested_parties, grpc_closure* on_done, - grpc_resolved_addresses** addrs) = resolve_address_impl; - +grpc_address_resolver_vtable grpc_posix_resolver_vtable = { + posix_resolve_address, posix_blocking_resolve_address}; #endif diff --git a/src/core/lib/iomgr/resolve_address_uv.cc b/src/core/lib/iomgr/resolve_address_uv.cc deleted file mode 100644 index 4d8ea596f3..0000000000 --- a/src/core/lib/iomgr/resolve_address_uv.cc +++ /dev/null @@ -1,286 +0,0 @@ -/* - * - * Copyright 2016 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/lib/iomgr/port.h" -#ifdef GRPC_UV - -#include - -#include -#include -#include - -#include "src/core/lib/gpr/host_port.h" -#include "src/core/lib/gpr/useful.h" -#include "src/core/lib/iomgr/closure.h" -#include "src/core/lib/iomgr/error.h" -#include "src/core/lib/iomgr/exec_ctx.h" -#include "src/core/lib/iomgr/iomgr_uv.h" -#include "src/core/lib/iomgr/resolve_address.h" -#include "src/core/lib/iomgr/sockaddr.h" -#include "src/core/lib/iomgr/sockaddr_utils.h" - -#include - -typedef struct request { - grpc_closure* on_done; - grpc_resolved_addresses** addresses; - struct addrinfo* hints; - char* host; - char* port; -} request; - -static int retry_named_port_failure(int status, request* r, - uv_getaddrinfo_cb getaddrinfo_cb) { - if (status != 0) { - // This loop is copied from resolve_address_posix.c - const char* svc[][2] = {{"http", "80"}, {"https", "443"}}; - for (size_t i = 0; i < GPR_ARRAY_SIZE(svc); i++) { - if (strcmp(r->port, svc[i][0]) == 0) { - int retry_status; - uv_getaddrinfo_t* req = - (uv_getaddrinfo_t*)gpr_malloc(sizeof(uv_getaddrinfo_t)); - req->data = r; - r->port = gpr_strdup(svc[i][1]); - retry_status = uv_getaddrinfo(uv_default_loop(), req, getaddrinfo_cb, - r->host, r->port, r->hints); - if (retry_status < 0 || getaddrinfo_cb == NULL) { - // The callback will not be called - gpr_free(req); - } - return retry_status; - } - } - } - /* If this function calls uv_getaddrinfo, it will return that function's - return value. That function only returns numbers <=0, so we can safely - return 1 to indicate that we never retried */ - return 1; -} - -static grpc_error* handle_addrinfo_result(int status, struct addrinfo* result, - grpc_resolved_addresses** addresses) { - struct addrinfo* resp; - size_t i; - if (status != 0) { - grpc_error* error; - *addresses = NULL; - error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("getaddrinfo failed"); - error = - grpc_error_set_str(error, GRPC_ERROR_STR_OS_ERROR, - grpc_slice_from_static_string(uv_strerror(status))); - return error; - } - (*addresses) = - (grpc_resolved_addresses*)gpr_malloc(sizeof(grpc_resolved_addresses)); - (*addresses)->naddrs = 0; - for (resp = result; resp != NULL; resp = resp->ai_next) { - (*addresses)->naddrs++; - } - (*addresses)->addrs = (grpc_resolved_address*)gpr_malloc( - sizeof(grpc_resolved_address) * (*addresses)->naddrs); - i = 0; - for (resp = result; resp != NULL; resp = resp->ai_next) { - memcpy(&(*addresses)->addrs[i].addr, resp->ai_addr, resp->ai_addrlen); - (*addresses)->addrs[i].len = resp->ai_addrlen; - i++; - } - - { - for (i = 0; i < (*addresses)->naddrs; i++) { - char* buf; - grpc_sockaddr_to_string(&buf, &(*addresses)->addrs[i], 0); - gpr_free(buf); - } - } - return GRPC_ERROR_NONE; -} - -static void getaddrinfo_callback(uv_getaddrinfo_t* req, int status, - struct addrinfo* res) { - request* r = (request*)req->data; - grpc_core::ExecCtx exec_ctx; - grpc_error* error; - int retry_status; - char* port = r->port; - - gpr_free(req); - retry_status = retry_named_port_failure(status, r, getaddrinfo_callback); - if (retry_status == 0) { - /* The request is being retried. It is using its own port string, so we free - * the original one */ - gpr_free(port); - return; - } - /* Either no retry was attempted, or the retry failed. Either way, the - original error probably has more interesting information */ - error = handle_addrinfo_result(status, res, r->addresses); - GRPC_CLOSURE_SCHED(r->on_done, error); - - gpr_free(r->hints); - gpr_free(r->host); - gpr_free(r->port); - gpr_free(r); - uv_freeaddrinfo(res); -} - -static grpc_error* try_split_host_port(const char* name, - const char* default_port, char** host, - char** port) { - /* parse name, splitting it into host and port parts */ - grpc_error* error; - gpr_split_host_port(name, host, port); - if (*host == NULL) { - char* msg; - gpr_asprintf(&msg, "unparseable host:port: '%s'", name); - error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); - gpr_free(msg); - return error; - } - if (*port == NULL) { - // TODO(murgatroid99): add tests for this case - if (default_port == NULL) { - char* msg; - gpr_asprintf(&msg, "no port in name '%s'", name); - error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); - gpr_free(msg); - return error; - } - *port = gpr_strdup(default_port); - } - return GRPC_ERROR_NONE; -} - -static grpc_error* blocking_resolve_address_impl( - const char* name, const char* default_port, - grpc_resolved_addresses** addresses) { - char* host; - char* port; - struct addrinfo hints; - uv_getaddrinfo_t req; - int s; - grpc_error* err; - int retry_status; - request r; - - GRPC_UV_ASSERT_SAME_THREAD(); - - req.addrinfo = NULL; - - err = try_split_host_port(name, default_port, &host, &port); - if (err != GRPC_ERROR_NONE) { - goto done; - } - - /* Call getaddrinfo */ - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_UNSPEC; /* ipv4 or ipv6 */ - hints.ai_socktype = SOCK_STREAM; /* stream socket */ - hints.ai_flags = AI_PASSIVE; /* for wildcard IP address */ - - s = uv_getaddrinfo(uv_default_loop(), &req, NULL, host, port, &hints); - r.addresses = addresses; - r.hints = &hints; - r.host = host; - r.port = port; - retry_status = retry_named_port_failure(s, &r, NULL); - if (retry_status <= 0) { - s = retry_status; - } - err = handle_addrinfo_result(s, req.addrinfo, addresses); - -done: - gpr_free(host); - gpr_free(port); - if (req.addrinfo) { - uv_freeaddrinfo(req.addrinfo); - } - return err; -} - -grpc_error* (*grpc_blocking_resolve_address)( - const char* name, const char* default_port, - grpc_resolved_addresses** addresses) = blocking_resolve_address_impl; - -void grpc_resolved_addresses_destroy(grpc_resolved_addresses* addrs) { - if (addrs != NULL) { - gpr_free(addrs->addrs); - } - gpr_free(addrs); -} - -static void resolve_address_impl(const char* name, const char* default_port, - grpc_pollset_set* interested_parties, - grpc_closure* on_done, - grpc_resolved_addresses** addrs) { - uv_getaddrinfo_t* req = NULL; - request* r = NULL; - struct addrinfo* hints = NULL; - char* host = NULL; - char* port = NULL; - grpc_error* err; - int s; - GRPC_UV_ASSERT_SAME_THREAD(); - err = try_split_host_port(name, default_port, &host, &port); - if (err != GRPC_ERROR_NONE) { - GRPC_CLOSURE_SCHED(on_done, err); - gpr_free(host); - gpr_free(port); - return; - } - r = (request*)gpr_malloc(sizeof(request)); - r->on_done = on_done; - r->addresses = addrs; - r->host = host; - r->port = port; - req = (uv_getaddrinfo_t*)gpr_malloc(sizeof(uv_getaddrinfo_t)); - req->data = r; - - /* Call getaddrinfo */ - hints = (addrinfo*)gpr_malloc(sizeof(struct addrinfo)); - memset(hints, 0, sizeof(struct addrinfo)); - hints->ai_family = AF_UNSPEC; /* ipv4 or ipv6 */ - hints->ai_socktype = SOCK_STREAM; /* stream socket */ - hints->ai_flags = AI_PASSIVE; /* for wildcard IP address */ - r->hints = hints; - - s = uv_getaddrinfo(uv_default_loop(), req, getaddrinfo_callback, host, port, - hints); - - if (s != 0) { - *addrs = NULL; - err = GRPC_ERROR_CREATE_FROM_STATIC_STRING("getaddrinfo failed"); - err = grpc_error_set_str(err, GRPC_ERROR_STR_OS_ERROR, - grpc_slice_from_static_string(uv_strerror(s))); - GRPC_CLOSURE_SCHED(on_done, err); - gpr_free(r); - gpr_free(req); - gpr_free(hints); - gpr_free(host); - gpr_free(port); - } -} - -void (*grpc_resolve_address)( - const char* name, const char* default_port, - grpc_pollset_set* interested_parties, grpc_closure* on_done, - grpc_resolved_addresses** addrs) = resolve_address_impl; - -#endif /* GRPC_UV */ diff --git a/src/core/lib/iomgr/resolve_address_windows.cc b/src/core/lib/iomgr/resolve_address_windows.cc index 7a62c88720..71c92615ad 100644 --- a/src/core/lib/iomgr/resolve_address_windows.cc +++ b/src/core/lib/iomgr/resolve_address_windows.cc @@ -51,7 +51,7 @@ typedef struct { grpc_resolved_addresses** addresses; } request; -static grpc_error* blocking_resolve_address_impl( +static grpc_error* windows_blocking_resolve_address( const char* name, const char* default_port, grpc_resolved_addresses** addresses) { grpc_core::ExecCtx exec_ctx; @@ -130,10 +130,6 @@ done: return error; } -grpc_error* (*grpc_blocking_resolve_address)( - const char* name, const char* default_port, - grpc_resolved_addresses** addresses) = blocking_resolve_address_impl; - /* Callback to be passed to grpc_executor to asynch-ify * grpc_blocking_resolve_address */ static void do_request_thread(void* rp, grpc_error* error) { @@ -150,17 +146,10 @@ static void do_request_thread(void* rp, grpc_error* error) { gpr_free(r); } -void grpc_resolved_addresses_destroy(grpc_resolved_addresses* addrs) { - if (addrs != NULL) { - gpr_free(addrs->addrs); - } - gpr_free(addrs); -} - -static void resolve_address_impl(const char* name, const char* default_port, - grpc_pollset_set* interested_parties, - grpc_closure* on_done, - grpc_resolved_addresses** addresses) { +static void windows_resolve_address(const char* name, const char* default_port, + grpc_pollset_set* interested_parties, + grpc_closure* on_done, + grpc_resolved_addresses** addresses) { request* r = (request*)gpr_malloc(sizeof(request)); GRPC_CLOSURE_INIT(&r->request_closure, do_request_thread, r, grpc_executor_scheduler(GRPC_EXECUTOR_SHORT)); @@ -171,9 +160,6 @@ static void resolve_address_impl(const char* name, const char* default_port, GRPC_CLOSURE_SCHED(&r->request_closure, GRPC_ERROR_NONE); } -void (*grpc_resolve_address)( - const char* name, const char* default_port, - grpc_pollset_set* interested_parties, grpc_closure* on_done, - grpc_resolved_addresses** addresses) = resolve_address_impl; - +grpc_address_resolver_vtable grpc_windows_resolver_vtable = { + windows_resolve_address, windows_blocking_resolve_address}; #endif diff --git a/src/core/lib/iomgr/resource_quota.h b/src/core/lib/iomgr/resource_quota.h index 4e1c651278..89e8a39118 100644 --- a/src/core/lib/iomgr/resource_quota.h +++ b/src/core/lib/iomgr/resource_quota.h @@ -139,8 +139,4 @@ void grpc_resource_user_alloc_slices( grpc_resource_user_slice_allocator* slice_allocator, size_t length, size_t count, grpc_slice_buffer* dest); -/* Allocate one slice of length \a size synchronously. */ -grpc_slice grpc_resource_user_slice_malloc(grpc_resource_user* resource_user, - size_t size); - #endif /* GRPC_CORE_LIB_IOMGR_RESOURCE_QUOTA_H */ diff --git a/src/core/lib/iomgr/sockaddr.h b/src/core/lib/iomgr/sockaddr.h index 3b30da8a7d..5edf735cd1 100644 --- a/src/core/lib/iomgr/sockaddr.h +++ b/src/core/lib/iomgr/sockaddr.h @@ -25,18 +25,8 @@ #include -#include "src/core/lib/iomgr/port.h" - -#ifdef GRPC_UV -#include -#endif - -#ifdef GPR_WINDOWS -#include "src/core/lib/iomgr/sockaddr_windows.h" -#endif - -#ifdef GRPC_POSIX_SOCKETADDR +#include "src/core/lib/iomgr/sockaddr_custom.h" #include "src/core/lib/iomgr/sockaddr_posix.h" -#endif +#include "src/core/lib/iomgr/sockaddr_windows.h" #endif /* GRPC_CORE_LIB_IOMGR_SOCKADDR_H */ diff --git a/src/core/lib/iomgr/sockaddr_custom.h b/src/core/lib/iomgr/sockaddr_custom.h new file mode 100644 index 0000000000..d85cc504d3 --- /dev/null +++ b/src/core/lib/iomgr/sockaddr_custom.h @@ -0,0 +1,54 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_LIB_IOMGR_SOCKADDR_CUSTOM_H +#define GRPC_CORE_LIB_IOMGR_SOCKADDR_CUSTOM_H + +#include + +#include +#include "src/core/lib/iomgr/port.h" + +#ifdef GRPC_UV + +#include + +// TODO(kpayson) It would be nice to abstract this so we don't +// depend on anything uv specific +typedef struct sockaddr grpc_sockaddr; +typedef struct sockaddr_in grpc_sockaddr_in; +typedef struct in_addr grpc_in_addr; +typedef struct sockaddr_in6 grpc_sockaddr_in6; +typedef struct in6_addr grpc_in6_addr; + +#define GRPC_INET_ADDRSTRLEN INET_ADDRSTRLEN +#define GRPC_INET6_ADDRSTRLEN INET6_ADDRSTRLEN + +#define GRPC_SOCK_STREAM SOCK_STREAM +#define GRPC_SOCK_DGRAM SOCK_DGRAM + +#define GRPC_AF_UNSPEC AF_UNSPEC +#define GRPC_AF_UNIX AF_UNIX +#define GRPC_AF_INET AF_INET +#define GRPC_AF_INET6 AF_INET6 + +#define GRPC_AI_PASSIVE AI_PASSIVE + +#endif // GRPC_UV + +#endif /* GRPC_CORE_LIB_IOMGR_SOCKADDR_CUSTOM_H */ diff --git a/src/core/lib/iomgr/sockaddr_posix.h b/src/core/lib/iomgr/sockaddr_posix.h index 83981e0aa5..5b18bbc465 100644 --- a/src/core/lib/iomgr/sockaddr_posix.h +++ b/src/core/lib/iomgr/sockaddr_posix.h @@ -21,6 +21,9 @@ #include +#include "src/core/lib/iomgr/port.h" + +#ifdef GRPC_POSIX_SOCKET #include #include #include @@ -28,4 +31,25 @@ #include #include +typedef struct sockaddr grpc_sockaddr; +typedef struct sockaddr_in grpc_sockaddr_in; +typedef struct in_addr grpc_in_addr; +typedef struct sockaddr_in6 grpc_sockaddr_in6; +typedef struct in6_addr grpc_in6_addr; + +#define GRPC_INET_ADDRSTRLEN INET_ADDRSTRLEN +#define GRPC_INET6_ADDRSTRLEN INET6_ADDRSTRLEN + +#define GRPC_SOCK_STREAM SOCK_STREAM +#define GRPC_SOCK_DGRAM SOCK_DGRAM + +#define GRPC_AF_UNSPEC AF_UNSPEC +#define GRPC_AF_UNIX AF_UNIX +#define GRPC_AF_INET AF_INET +#define GRPC_AF_INET6 AF_INET6 + +#define GRPC_AI_PASSIVE AI_PASSIVE + +#endif + #endif /* GRPC_CORE_LIB_IOMGR_SOCKADDR_POSIX_H */ diff --git a/src/core/lib/iomgr/sockaddr_utils.cc b/src/core/lib/iomgr/sockaddr_utils.cc index 88f9b2ffd9..bc3550a679 100644 --- a/src/core/lib/iomgr/sockaddr_utils.cc +++ b/src/core/lib/iomgr/sockaddr_utils.cc @@ -40,25 +40,25 @@ static const uint8_t kV4MappedPrefix[] = {0, 0, 0, 0, 0, 0, int grpc_sockaddr_is_v4mapped(const grpc_resolved_address* resolved_addr, grpc_resolved_address* resolved_addr4_out) { GPR_ASSERT(resolved_addr != resolved_addr4_out); - const struct sockaddr* addr = - reinterpret_cast(resolved_addr->addr); - struct sockaddr_in* addr4_out = + const grpc_sockaddr* addr = + reinterpret_cast(resolved_addr->addr); + grpc_sockaddr_in* addr4_out = resolved_addr4_out == nullptr ? nullptr - : reinterpret_cast(resolved_addr4_out->addr); - if (addr->sa_family == AF_INET6) { - const struct sockaddr_in6* addr6 = - reinterpret_cast(addr); + : reinterpret_cast(resolved_addr4_out->addr); + if (addr->sa_family == GRPC_AF_INET6) { + const grpc_sockaddr_in6* addr6 = + reinterpret_cast(addr); if (memcmp(addr6->sin6_addr.s6_addr, kV4MappedPrefix, sizeof(kV4MappedPrefix)) == 0) { if (resolved_addr4_out != nullptr) { /* Normalize ::ffff:0.0.0.0/96 to IPv4. */ memset(resolved_addr4_out, 0, sizeof(*resolved_addr4_out)); - addr4_out->sin_family = AF_INET; + addr4_out->sin_family = GRPC_AF_INET; /* s6_addr32 would be nice, but it's non-standard. */ memcpy(&addr4_out->sin_addr, &addr6->sin6_addr.s6_addr[12], 4); addr4_out->sin_port = addr6->sin6_port; - resolved_addr4_out->len = sizeof(struct sockaddr_in); + resolved_addr4_out->len = sizeof(grpc_sockaddr_in); } return 1; } @@ -69,19 +69,19 @@ int grpc_sockaddr_is_v4mapped(const grpc_resolved_address* resolved_addr, int grpc_sockaddr_to_v4mapped(const grpc_resolved_address* resolved_addr, grpc_resolved_address* resolved_addr6_out) { GPR_ASSERT(resolved_addr != resolved_addr6_out); - const struct sockaddr* addr = - reinterpret_cast(resolved_addr->addr); - struct sockaddr_in6* addr6_out = - reinterpret_cast(resolved_addr6_out->addr); - if (addr->sa_family == AF_INET) { - const struct sockaddr_in* addr4 = - reinterpret_cast(addr); + const grpc_sockaddr* addr = + reinterpret_cast(resolved_addr->addr); + grpc_sockaddr_in6* addr6_out = + reinterpret_cast(resolved_addr6_out->addr); + if (addr->sa_family == GRPC_AF_INET) { + const grpc_sockaddr_in* addr4 = + reinterpret_cast(addr); memset(resolved_addr6_out, 0, sizeof(*resolved_addr6_out)); - addr6_out->sin6_family = AF_INET6; + addr6_out->sin6_family = GRPC_AF_INET6; memcpy(&addr6_out->sin6_addr.s6_addr[0], kV4MappedPrefix, 12); memcpy(&addr6_out->sin6_addr.s6_addr[12], &addr4->sin_addr, 4); addr6_out->sin6_port = addr4->sin_port; - resolved_addr6_out->len = sizeof(struct sockaddr_in6); + resolved_addr6_out->len = sizeof(grpc_sockaddr_in6); return 1; } return 0; @@ -89,32 +89,32 @@ int grpc_sockaddr_to_v4mapped(const grpc_resolved_address* resolved_addr, int grpc_sockaddr_is_wildcard(const grpc_resolved_address* resolved_addr, int* port_out) { - const struct sockaddr* addr; + const grpc_sockaddr* addr; grpc_resolved_address addr4_normalized; if (grpc_sockaddr_is_v4mapped(resolved_addr, &addr4_normalized)) { resolved_addr = &addr4_normalized; } - addr = reinterpret_cast(resolved_addr->addr); - if (addr->sa_family == AF_INET) { + addr = reinterpret_cast(resolved_addr->addr); + if (addr->sa_family == GRPC_AF_INET) { /* Check for 0.0.0.0 */ - const struct sockaddr_in* addr4 = - reinterpret_cast(addr); + const grpc_sockaddr_in* addr4 = + reinterpret_cast(addr); if (addr4->sin_addr.s_addr != 0) { return 0; } - *port_out = ntohs(addr4->sin_port); + *port_out = grpc_ntohs(addr4->sin_port); return 1; - } else if (addr->sa_family == AF_INET6) { + } else if (addr->sa_family == GRPC_AF_INET6) { /* Check for :: */ - const struct sockaddr_in6* addr6 = - reinterpret_cast(addr); + const grpc_sockaddr_in6* addr6 = + reinterpret_cast(addr); int i; for (i = 0; i < 16; i++) { if (addr6->sin6_addr.s6_addr[i] != 0) { return 0; } } - *port_out = ntohs(addr6->sin6_port); + *port_out = grpc_ntohs(addr6->sin6_port); return 1; } else { return 0; @@ -129,33 +129,33 @@ void grpc_sockaddr_make_wildcards(int port, grpc_resolved_address* wild4_out, void grpc_sockaddr_make_wildcard4(int port, grpc_resolved_address* resolved_wild_out) { - struct sockaddr_in* wild_out = - reinterpret_cast(resolved_wild_out->addr); + grpc_sockaddr_in* wild_out = + reinterpret_cast(resolved_wild_out->addr); GPR_ASSERT(port >= 0 && port < 65536); memset(resolved_wild_out, 0, sizeof(*resolved_wild_out)); - wild_out->sin_family = AF_INET; - wild_out->sin_port = htons(static_cast(port)); - resolved_wild_out->len = sizeof(struct sockaddr_in); + wild_out->sin_family = GRPC_AF_INET; + wild_out->sin_port = grpc_htons(static_cast(port)); + resolved_wild_out->len = sizeof(grpc_sockaddr_in); } void grpc_sockaddr_make_wildcard6(int port, grpc_resolved_address* resolved_wild_out) { - struct sockaddr_in6* wild_out = - reinterpret_cast(resolved_wild_out->addr); + grpc_sockaddr_in6* wild_out = + reinterpret_cast(resolved_wild_out->addr); GPR_ASSERT(port >= 0 && port < 65536); memset(resolved_wild_out, 0, sizeof(*resolved_wild_out)); - wild_out->sin6_family = AF_INET6; - wild_out->sin6_port = htons(static_cast(port)); - resolved_wild_out->len = sizeof(struct sockaddr_in6); + wild_out->sin6_family = GRPC_AF_INET6; + wild_out->sin6_port = grpc_htons(static_cast(port)); + resolved_wild_out->len = sizeof(grpc_sockaddr_in6); } int grpc_sockaddr_to_string(char** out, const grpc_resolved_address* resolved_addr, int normalize) { - const struct sockaddr* addr; + const grpc_sockaddr* addr; const int save_errno = errno; grpc_resolved_address addr_normalized; - char ntop_buf[INET6_ADDRSTRLEN]; + char ntop_buf[GRPC_INET6_ADDRSTRLEN]; const void* ip = nullptr; int port = 0; uint32_t sin6_scope_id = 0; @@ -165,17 +165,17 @@ int grpc_sockaddr_to_string(char** out, if (normalize && grpc_sockaddr_is_v4mapped(resolved_addr, &addr_normalized)) { resolved_addr = &addr_normalized; } - addr = reinterpret_cast(resolved_addr->addr); - if (addr->sa_family == AF_INET) { - const struct sockaddr_in* addr4 = - reinterpret_cast(addr); + addr = reinterpret_cast(resolved_addr->addr); + if (addr->sa_family == GRPC_AF_INET) { + const grpc_sockaddr_in* addr4 = + reinterpret_cast(addr); ip = &addr4->sin_addr; - port = ntohs(addr4->sin_port); - } else if (addr->sa_family == AF_INET6) { - const struct sockaddr_in6* addr6 = - reinterpret_cast(addr); + port = grpc_ntohs(addr4->sin_port); + } else if (addr->sa_family == GRPC_AF_INET6) { + const grpc_sockaddr_in6* addr6 = + reinterpret_cast(addr); ip = &addr6->sin6_addr; - port = ntohs(addr6->sin6_port); + port = grpc_ntohs(addr6->sin6_port); sin6_scope_id = addr6->sin6_scope_id; } if (ip != nullptr && grpc_inet_ntop(addr->sa_family, ip, ntop_buf, @@ -197,6 +197,22 @@ int grpc_sockaddr_to_string(char** out, return ret; } +void grpc_string_to_sockaddr(grpc_resolved_address* out, char* addr, int port) { + grpc_sockaddr_in6* addr6 = (grpc_sockaddr_in6*)out->addr; + grpc_sockaddr_in* addr4 = (grpc_sockaddr_in*)out->addr; + + if (grpc_inet_pton(GRPC_AF_INET6, addr, &addr6->sin6_addr) == 1) { + addr6->sin6_family = GRPC_AF_INET6; + out->len = sizeof(grpc_sockaddr_in6); + } else if (grpc_inet_pton(GRPC_AF_INET, addr, &addr4->sin_addr) == 1) { + addr4->sin_family = GRPC_AF_INET; + out->len = sizeof(grpc_sockaddr_in); + } else { + GPR_ASSERT(0); + } + grpc_sockaddr_set_port(out, port); +} + char* grpc_sockaddr_to_uri(const grpc_resolved_address* resolved_addr) { grpc_resolved_address addr_normalized; if (grpc_sockaddr_is_v4mapped(resolved_addr, &addr_normalized)) { @@ -219,33 +235,33 @@ char* grpc_sockaddr_to_uri(const grpc_resolved_address* resolved_addr) { const char* grpc_sockaddr_get_uri_scheme( const grpc_resolved_address* resolved_addr) { - const struct sockaddr* addr = - reinterpret_cast(resolved_addr->addr); + const grpc_sockaddr* addr = + reinterpret_cast(resolved_addr->addr); switch (addr->sa_family) { - case AF_INET: + case GRPC_AF_INET: return "ipv4"; - case AF_INET6: + case GRPC_AF_INET6: return "ipv6"; - case AF_UNIX: + case GRPC_AF_UNIX: return "unix"; } return nullptr; } int grpc_sockaddr_get_family(const grpc_resolved_address* resolved_addr) { - const struct sockaddr* addr = - reinterpret_cast(resolved_addr->addr); + const grpc_sockaddr* addr = + reinterpret_cast(resolved_addr->addr); return addr->sa_family; } int grpc_sockaddr_get_port(const grpc_resolved_address* resolved_addr) { - const struct sockaddr* addr = - reinterpret_cast(resolved_addr->addr); + const grpc_sockaddr* addr = + reinterpret_cast(resolved_addr->addr); switch (addr->sa_family) { - case AF_INET: - return ntohs(((struct sockaddr_in*)addr)->sin_port); - case AF_INET6: - return ntohs(((struct sockaddr_in6*)addr)->sin6_port); + case GRPC_AF_INET: + return grpc_ntohs(((grpc_sockaddr_in*)addr)->sin_port); + case GRPC_AF_INET6: + return grpc_ntohs(((grpc_sockaddr_in6*)addr)->sin6_port); default: if (grpc_is_unix_socket(resolved_addr)) { return 1; @@ -258,18 +274,18 @@ int grpc_sockaddr_get_port(const grpc_resolved_address* resolved_addr) { int grpc_sockaddr_set_port(const grpc_resolved_address* resolved_addr, int port) { - const struct sockaddr* addr = - reinterpret_cast(resolved_addr->addr); + const grpc_sockaddr* addr = + reinterpret_cast(resolved_addr->addr); switch (addr->sa_family) { - case AF_INET: + case GRPC_AF_INET: GPR_ASSERT(port >= 0 && port < 65536); - ((struct sockaddr_in*)addr)->sin_port = - htons(static_cast(port)); + ((grpc_sockaddr_in*)addr)->sin_port = + grpc_htons(static_cast(port)); return 1; - case AF_INET6: + case GRPC_AF_INET6: GPR_ASSERT(port >= 0 && port < 65536); - ((struct sockaddr_in6*)addr)->sin6_port = - htons(static_cast(port)); + ((grpc_sockaddr_in6*)addr)->sin6_port = + grpc_htons(static_cast(port)); return 1; default: gpr_log(GPR_ERROR, "Unknown socket family %d in grpc_sockaddr_set_port", diff --git a/src/core/lib/iomgr/sockaddr_utils.h b/src/core/lib/iomgr/sockaddr_utils.h index ace54a2a80..a4e90a73ab 100644 --- a/src/core/lib/iomgr/sockaddr_utils.h +++ b/src/core/lib/iomgr/sockaddr_utils.h @@ -71,6 +71,8 @@ int grpc_sockaddr_set_port(const grpc_resolved_address* addr, int port); int grpc_sockaddr_to_string(char** out, const grpc_resolved_address* addr, int normalize); +void grpc_string_to_sockaddr(grpc_resolved_address* out, char* addr, int port); + /* Returns the URI string corresponding to \a addr */ char* grpc_sockaddr_to_uri(const grpc_resolved_address* addr); diff --git a/src/core/lib/iomgr/sockaddr_windows.h b/src/core/lib/iomgr/sockaddr_windows.h index 3a4fcc9e8a..4d637251a1 100644 --- a/src/core/lib/iomgr/sockaddr_windows.h +++ b/src/core/lib/iomgr/sockaddr_windows.h @@ -31,6 +31,25 @@ // must be included after the above #include +typedef struct sockaddr grpc_sockaddr; +typedef struct sockaddr_in grpc_sockaddr_in; +typedef struct in_addr grpc_in_addr; +typedef struct sockaddr_in6 grpc_sockaddr_in6; +typedef struct in6_addr grpc_in6_addr; + +#define GRPC_INET_ADDRSTRLEN INET_ADDRSTRLEN +#define GRPC_INET6_ADDRSTRLEN INET6_ADDRSTRLEN + +#define GRPC_SOCK_STREAM SOCK_STREAM +#define GRPC_SOCK_DGRAM SOCK_DGRAM + +#define GRPC_AF_UNSPEC AF_UNSPEC +#define GRPC_AF_UNIX AF_UNIX +#define GRPC_AF_INET AF_INET +#define GRPC_AF_INET6 AF_INET6 + +#define GRPC_AI_PASSIVE AI_PASSIVE + #endif #endif /* GRPC_CORE_LIB_IOMGR_SOCKADDR_WINDOWS_H */ diff --git a/src/core/lib/iomgr/socket_utils.h b/src/core/lib/iomgr/socket_utils.h index e96eb97a7e..cf1a7be648 100644 --- a/src/core/lib/iomgr/socket_utils.h +++ b/src/core/lib/iomgr/socket_utils.h @@ -23,6 +23,15 @@ #include +/* A wrapper for htons on POSIX and Windows */ +uint16_t grpc_htons(uint16_t hostshort); + +/* A wrapper for ntohs on POSIX and WINDOWS */ +uint16_t grpc_ntohs(uint16_t netshort); + +/* A wrapper for inet_pton on POSIX and WINDOWS */ +int grpc_inet_pton(int af, const char* src, void* dst); + /* A wrapper for inet_ntop on POSIX systems and InetNtop on Windows systems */ const char* grpc_inet_ntop(int af, const void* src, char* dst, size_t size); diff --git a/src/core/lib/iomgr/socket_utils_common_posix.cc b/src/core/lib/iomgr/socket_utils_common_posix.cc index 4fb6c7ad63..c52e237fa8 100644 --- a/src/core/lib/iomgr/socket_utils_common_posix.cc +++ b/src/core/lib/iomgr/socket_utils_common_posix.cc @@ -43,6 +43,7 @@ #include "src/core/lib/gpr/host_port.h" #include "src/core/lib/gpr/string.h" +#include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/iomgr/sockaddr_utils.h" /* set a socket to non blocking mode */ @@ -215,12 +216,11 @@ static void probe_ipv6_once(void) { if (fd < 0) { gpr_log(GPR_INFO, "Disabling AF_INET6 sockets because socket() failed."); } else { - struct sockaddr_in6 addr; + grpc_sockaddr_in6 addr; memset(&addr, 0, sizeof(addr)); addr.sin6_family = AF_INET6; addr.sin6_addr.s6_addr[15] = 1; /* [::1]:0 */ - if (bind(fd, reinterpret_cast(&addr), sizeof(addr)) == - 0) { + if (bind(fd, reinterpret_cast(&addr), sizeof(addr)) == 0) { g_ipv6_loopback_available = 1; } else { gpr_log(GPR_INFO, @@ -280,8 +280,8 @@ static int create_socket(grpc_socket_factory* factory, int domain, int type, grpc_error* grpc_create_dualstack_socket_using_factory( grpc_socket_factory* factory, const grpc_resolved_address* resolved_addr, int type, int protocol, grpc_dualstack_mode* dsmode, int* newfd) { - const struct sockaddr* addr = - reinterpret_cast(resolved_addr->addr); + const grpc_sockaddr* addr = + reinterpret_cast(resolved_addr->addr); int family = addr->sa_family; if (family == AF_INET6) { if (grpc_ipv6_loopback_available()) { @@ -311,6 +311,14 @@ grpc_error* grpc_create_dualstack_socket_using_factory( return error_for_fd(*newfd, resolved_addr); } +uint16_t grpc_htons(uint16_t hostshort) { return htons(hostshort); } + +uint16_t grpc_ntohs(uint16_t netshort) { return ntohs(netshort); } + +int grpc_inet_pton(int af, const char* src, void* dst) { + return inet_pton(af, src, dst); +} + const char* grpc_inet_ntop(int af, const void* src, char* dst, size_t size) { GPR_ASSERT(size <= (socklen_t)-1); return inet_ntop(af, src, dst, static_cast(size)); diff --git a/src/core/lib/iomgr/socket_utils_linux.cc b/src/core/lib/iomgr/socket_utils_linux.cc index deb7c55267..1364cd35f6 100644 --- a/src/core/lib/iomgr/socket_utils_linux.cc +++ b/src/core/lib/iomgr/socket_utils_linux.cc @@ -37,8 +37,7 @@ int grpc_accept4(int sockfd, grpc_resolved_address* resolved_addr, int nonblock, GPR_ASSERT(resolved_addr->len <= (socklen_t)-1); flags |= nonblock ? SOCK_NONBLOCK : 0; flags |= cloexec ? SOCK_CLOEXEC : 0; - return accept4(sockfd, - reinterpret_cast(resolved_addr->addr), + return accept4(sockfd, reinterpret_cast(resolved_addr->addr), reinterpret_cast(&resolved_addr->len), flags); } diff --git a/src/core/lib/iomgr/socket_utils_posix.cc b/src/core/lib/iomgr/socket_utils_posix.cc index c856f641e3..d5d00af976 100644 --- a/src/core/lib/iomgr/socket_utils_posix.cc +++ b/src/core/lib/iomgr/socket_utils_posix.cc @@ -36,7 +36,7 @@ int grpc_accept4(int sockfd, grpc_resolved_address* resolved_addr, int nonblock, int fd, flags; GPR_ASSERT(sizeof(socklen_t) <= sizeof(size_t)); GPR_ASSERT(resolved_addr->len <= (socklen_t)-1); - fd = accept(sockfd, (struct sockaddr*)resolved_addr->addr, + fd = accept(sockfd, (grpc_sockaddr*)resolved_addr->addr, (socklen_t*)&resolved_addr->len); if (fd >= 0) { if (nonblock) { diff --git a/src/core/lib/iomgr/socket_utils_uv.cc b/src/core/lib/iomgr/socket_utils_uv.cc index 3f650eef66..8538abc7e4 100644 --- a/src/core/lib/iomgr/socket_utils_uv.cc +++ b/src/core/lib/iomgr/socket_utils_uv.cc @@ -22,15 +22,24 @@ #ifdef GRPC_UV -#include - +#include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/iomgr/socket_utils.h" #include +#include + +uint16_t grpc_htons(uint16_t hostshort) { return htons(hostshort); } + +uint16_t grpc_ntohs(uint16_t netshort) { return ntohs(netshort); } + +int grpc_inet_pton(int af, const char* src, void* dst) { + return inet_pton(af, src, dst); +} + const char* grpc_inet_ntop(int af, const void* src, char* dst, size_t size) { - uv_inet_ntop(af, src, dst, size); - return dst; + /* Windows InetNtopA wants a mutable ip pointer */ + return inet_ntop(af, src, dst, (socklen_t)size); } #endif /* GRPC_UV */ diff --git a/src/core/lib/iomgr/socket_utils_windows.cc b/src/core/lib/iomgr/socket_utils_windows.cc index 5fc3b7617e..3e7b5b812d 100644 --- a/src/core/lib/iomgr/socket_utils_windows.cc +++ b/src/core/lib/iomgr/socket_utils_windows.cc @@ -27,6 +27,14 @@ #include +uint16_t grpc_htons(uint16_t hostshort) { return htons(hostshort); } + +uint16_t grpc_ntohs(uint16_t netshort) { return ntohs(netshort); } + +int grpc_inet_pton(int af, const char* src, void* dst) { + return inet_pton(af, src, dst); +} + const char* grpc_inet_ntop(int af, const void* src, char* dst, size_t size) { /* Windows InetNtopA wants a mutable ip pointer */ return InetNtopA(af, (void*)src, dst, size); diff --git a/src/core/lib/iomgr/tcp_client.cc b/src/core/lib/iomgr/tcp_client.cc new file mode 100644 index 0000000000..6c0ba40781 --- /dev/null +++ b/src/core/lib/iomgr/tcp_client.cc @@ -0,0 +1,36 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/lib/iomgr/tcp_client.h" + +grpc_tcp_client_vtable* grpc_tcp_client_impl; + +void grpc_tcp_client_connect(grpc_closure* closure, grpc_endpoint** ep, + grpc_pollset_set* interested_parties, + const grpc_channel_args* channel_args, + const grpc_resolved_address* addr, + grpc_millis deadline) { + grpc_tcp_client_impl->connect(closure, ep, interested_parties, channel_args, + addr, deadline); +} + +void grpc_set_tcp_client_impl(grpc_tcp_client_vtable* impl) { + grpc_tcp_client_impl = impl; +} diff --git a/src/core/lib/iomgr/tcp_client.h b/src/core/lib/iomgr/tcp_client.h index a6b99e63c2..d209eeb8c2 100644 --- a/src/core/lib/iomgr/tcp_client.h +++ b/src/core/lib/iomgr/tcp_client.h @@ -27,6 +27,13 @@ #include "src/core/lib/iomgr/pollset_set.h" #include "src/core/lib/iomgr/resolve_address.h" +typedef struct grpc_tcp_client_vtable { + void (*connect)(grpc_closure* on_connect, grpc_endpoint** endpoint, + grpc_pollset_set* interested_parties, + const grpc_channel_args* channel_args, + const grpc_resolved_address* addr, grpc_millis deadline); +} grpc_tcp_client_vtable; + /* Asynchronously connect to an address (specified as (addr, len)), and call cb with arg and the completed connection when done (or call cb with arg and NULL on failure). @@ -38,4 +45,8 @@ void grpc_tcp_client_connect(grpc_closure* on_connect, grpc_endpoint** endpoint, const grpc_resolved_address* addr, grpc_millis deadline); +void grpc_tcp_client_global_init(); + +void grpc_set_tcp_client_impl(grpc_tcp_client_vtable* impl); + #endif /* GRPC_CORE_LIB_IOMGR_TCP_CLIENT_H */ diff --git a/src/core/lib/iomgr/tcp_client_custom.cc b/src/core/lib/iomgr/tcp_client_custom.cc new file mode 100644 index 0000000000..55632a55a1 --- /dev/null +++ b/src/core/lib/iomgr/tcp_client_custom.cc @@ -0,0 +1,151 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/lib/iomgr/port.h" + +#include + +#include +#include + +#include "src/core/lib/iomgr/error.h" +#include "src/core/lib/iomgr/iomgr_custom.h" +#include "src/core/lib/iomgr/sockaddr_utils.h" +#include "src/core/lib/iomgr/tcp_client.h" +#include "src/core/lib/iomgr/tcp_custom.h" +#include "src/core/lib/iomgr/timer.h" + +extern grpc_core::TraceFlag grpc_tcp_trace; +extern grpc_socket_vtable* grpc_custom_socket_vtable; + +struct grpc_custom_tcp_connect { + grpc_custom_socket* socket; + grpc_timer alarm; + grpc_closure on_alarm; + grpc_closure* closure; + grpc_endpoint** endpoint; + int refs; + char* addr_name; + grpc_resource_quota* resource_quota; +}; + +static void custom_tcp_connect_cleanup(grpc_custom_tcp_connect* connect) { + grpc_custom_socket* socket = connect->socket; + grpc_resource_quota_unref_internal(connect->resource_quota); + gpr_free(connect->addr_name); + gpr_free(connect); + socket->refs--; + if (socket->refs == 0) { + grpc_custom_socket_vtable->destroy(socket); + gpr_free(socket); + } +} + +static void custom_close_callback(grpc_custom_socket* socket) {} + +static void on_alarm(void* acp, grpc_error* error) { + int done; + grpc_custom_socket* socket = (grpc_custom_socket*)acp; + grpc_custom_tcp_connect* connect = socket->connector; + if (grpc_tcp_trace.enabled()) { + const char* str = grpc_error_string(error); + gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: on_alarm: error=%s", + connect->addr_name, str); + } + if (error == GRPC_ERROR_NONE) { + /* error == NONE implies that the timer ran out, and wasn't cancelled. If + it was cancelled, then the handler that cancelled it also should close + the handle, if applicable */ + grpc_custom_socket_vtable->close(socket, custom_close_callback); + } + done = (--connect->refs == 0); + if (done) { + custom_tcp_connect_cleanup(connect); + } +} + +static void custom_connect_callback(grpc_custom_socket* socket, + grpc_error* error) { + grpc_core::ExecCtx exec_ctx; + grpc_custom_tcp_connect* connect = socket->connector; + int done; + grpc_closure* closure = connect->closure; + grpc_timer_cancel(&connect->alarm); + if (error == GRPC_ERROR_NONE) { + *connect->endpoint = custom_tcp_endpoint_create( + socket, connect->resource_quota, connect->addr_name); + } + done = (--connect->refs == 0); + if (done) { + grpc_core::ExecCtx::Get()->Flush(); + custom_tcp_connect_cleanup(connect); + } + GRPC_CLOSURE_SCHED(closure, error); +} + +static void tcp_connect(grpc_closure* closure, grpc_endpoint** ep, + grpc_pollset_set* interested_parties, + const grpc_channel_args* channel_args, + const grpc_resolved_address* resolved_addr, + grpc_millis deadline) { + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + (void)channel_args; + (void)interested_parties; + grpc_custom_tcp_connect* connect; + grpc_resource_quota* resource_quota = grpc_resource_quota_create(nullptr); + if (channel_args != nullptr) { + for (size_t i = 0; i < channel_args->num_args; i++) { + if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) { + grpc_resource_quota_unref_internal(resource_quota); + resource_quota = grpc_resource_quota_ref_internal( + (grpc_resource_quota*)channel_args->args[i].value.pointer.p); + } + } + } + grpc_custom_socket* socket = + (grpc_custom_socket*)gpr_malloc(sizeof(grpc_custom_socket)); + socket->refs = 2; + grpc_custom_socket_vtable->init(socket, GRPC_AF_UNSPEC); + connect = + (grpc_custom_tcp_connect*)gpr_malloc(sizeof(grpc_custom_tcp_connect)); + connect->closure = closure; + connect->endpoint = ep; + connect->addr_name = grpc_sockaddr_to_uri(resolved_addr); + connect->resource_quota = resource_quota; + connect->socket = socket; + socket->connector = connect; + socket->endpoint = nullptr; + socket->listener = nullptr; + connect->refs = 2; + + if (grpc_tcp_trace.enabled()) { + gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %p %s: asynchronously connecting", + socket, connect->addr_name); + } + + grpc_custom_socket_vtable->connect( + socket, (const grpc_sockaddr*)resolved_addr->addr, resolved_addr->len, + custom_connect_callback); + GRPC_CLOSURE_INIT(&connect->on_alarm, on_alarm, socket, + grpc_schedule_on_exec_ctx); + grpc_timer_init(&connect->alarm, deadline, &connect->on_alarm); +} + +grpc_tcp_client_vtable custom_tcp_client_vtable = {tcp_connect}; diff --git a/src/core/lib/iomgr/tcp_client_posix.cc b/src/core/lib/iomgr/tcp_client_posix.cc index 3fe2989c6b..c21fb40ab1 100644 --- a/src/core/lib/iomgr/tcp_client_posix.cc +++ b/src/core/lib/iomgr/tcp_client_posix.cc @@ -38,6 +38,7 @@ #include "src/core/lib/gpr/string.h" #include "src/core/lib/iomgr/ev_posix.h" #include "src/core/lib/iomgr/iomgr_posix.h" +#include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/iomgr/socket_mutator.h" #include "src/core/lib/iomgr/socket_utils_posix.h" @@ -293,7 +294,7 @@ void grpc_tcp_client_create_from_prepared_fd( async_connect* ac; do { GPR_ASSERT(addr->len < ~(socklen_t)0); - err = connect(fd, reinterpret_cast(addr->addr), + err = connect(fd, reinterpret_cast(addr->addr), static_cast(addr->len)); } while (err < 0 && errno == EINTR); if (err >= 0) { @@ -336,11 +337,11 @@ void grpc_tcp_client_create_from_prepared_fd( gpr_mu_unlock(&ac->mu); } -static void tcp_client_connect_impl(grpc_closure* closure, grpc_endpoint** ep, - grpc_pollset_set* interested_parties, - const grpc_channel_args* channel_args, - const grpc_resolved_address* addr, - grpc_millis deadline) { +static void tcp_connect(grpc_closure* closure, grpc_endpoint** ep, + grpc_pollset_set* interested_parties, + const grpc_channel_args* channel_args, + const grpc_resolved_address* addr, + grpc_millis deadline) { grpc_resolved_address mapped_addr; grpc_fd* fdobj = nullptr; grpc_error* error; @@ -355,20 +356,5 @@ static void tcp_client_connect_impl(grpc_closure* closure, grpc_endpoint** ep, ep); } -// overridden by api_fuzzer.c -void (*grpc_tcp_client_connect_impl)( - grpc_closure* closure, grpc_endpoint** ep, - grpc_pollset_set* interested_parties, const grpc_channel_args* channel_args, - const grpc_resolved_address* addr, - grpc_millis deadline) = tcp_client_connect_impl; - -void grpc_tcp_client_connect(grpc_closure* closure, grpc_endpoint** ep, - grpc_pollset_set* interested_parties, - const grpc_channel_args* channel_args, - const grpc_resolved_address* addr, - grpc_millis deadline) { - grpc_tcp_client_connect_impl(closure, ep, interested_parties, channel_args, - addr, deadline); -} - +grpc_tcp_client_vtable grpc_posix_tcp_client_vtable = {tcp_connect}; #endif diff --git a/src/core/lib/iomgr/tcp_client_uv.cc b/src/core/lib/iomgr/tcp_client_uv.cc deleted file mode 100644 index d29d6c8f41..0000000000 --- a/src/core/lib/iomgr/tcp_client_uv.cc +++ /dev/null @@ -1,177 +0,0 @@ -/* - * - * Copyright 2016 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/lib/iomgr/port.h" - -#ifdef GRPC_UV - -#include - -#include -#include - -#include "src/core/lib/iomgr/error.h" -#include "src/core/lib/iomgr/iomgr_uv.h" -#include "src/core/lib/iomgr/sockaddr_utils.h" -#include "src/core/lib/iomgr/tcp_client.h" -#include "src/core/lib/iomgr/tcp_uv.h" -#include "src/core/lib/iomgr/timer.h" - -extern grpc_core::TraceFlag grpc_tcp_trace; - -typedef struct grpc_uv_tcp_connect { - uv_connect_t connect_req; - grpc_timer alarm; - grpc_closure on_alarm; - uv_tcp_t* tcp_handle; - grpc_closure* closure; - grpc_endpoint** endpoint; - int refs; - char* addr_name; - grpc_resource_quota* resource_quota; -} grpc_uv_tcp_connect; - -static void uv_tcp_connect_cleanup(grpc_uv_tcp_connect* connect) { - grpc_resource_quota_unref_internal(connect->resource_quota); - gpr_free(connect->addr_name); - gpr_free(connect); -} - -static void tcp_close_callback(uv_handle_t* handle) { gpr_free(handle); } - -static void uv_tc_on_alarm(void* acp, grpc_error* error) { - int done; - grpc_uv_tcp_connect* connect = (grpc_uv_tcp_connect*)acp; - if (grpc_tcp_trace.enabled()) { - const char* str = grpc_error_string(error); - gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: on_alarm: error=%s", - connect->addr_name, str); - } - if (error == GRPC_ERROR_NONE) { - /* error == NONE implies that the timer ran out, and wasn't cancelled. If - it was cancelled, then the handler that cancelled it also should close - the handle, if applicable */ - uv_close((uv_handle_t*)connect->tcp_handle, tcp_close_callback); - } - done = (--connect->refs == 0); - if (done) { - uv_tcp_connect_cleanup(connect); - } -} - -static void uv_tc_on_connect(uv_connect_t* req, int status) { - grpc_uv_tcp_connect* connect = (grpc_uv_tcp_connect*)req->data; - grpc_core::ExecCtx exec_ctx; - grpc_error* error = GRPC_ERROR_NONE; - int done; - grpc_closure* closure = connect->closure; - grpc_timer_cancel(&connect->alarm); - if (status == 0) { - *connect->endpoint = grpc_tcp_create( - connect->tcp_handle, connect->resource_quota, connect->addr_name); - } else { - error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "Failed to connect to remote host"); - error = grpc_error_set_int(error, GRPC_ERROR_INT_ERRNO, -status); - error = - grpc_error_set_str(error, GRPC_ERROR_STR_OS_ERROR, - grpc_slice_from_static_string(uv_strerror(status))); - if (status == UV_ECANCELED) { - error = - grpc_error_set_str(error, GRPC_ERROR_STR_OS_ERROR, - grpc_slice_from_static_string("Timeout occurred")); - // This should only happen if the handle is already closed - } else { - error = grpc_error_set_str( - error, GRPC_ERROR_STR_OS_ERROR, - grpc_slice_from_static_string(uv_strerror(status))); - uv_close((uv_handle_t*)connect->tcp_handle, tcp_close_callback); - } - } - done = (--connect->refs == 0); - if (done) { - grpc_core::ExecCtx::Get()->Flush(); - uv_tcp_connect_cleanup(connect); - } - GRPC_CLOSURE_SCHED(closure, error); -} - -static void tcp_client_connect_impl(grpc_closure* closure, grpc_endpoint** ep, - grpc_pollset_set* interested_parties, - const grpc_channel_args* channel_args, - const grpc_resolved_address* resolved_addr, - grpc_millis deadline) { - grpc_uv_tcp_connect* connect; - grpc_resource_quota* resource_quota = grpc_resource_quota_create(NULL); - (void)channel_args; - (void)interested_parties; - - GRPC_UV_ASSERT_SAME_THREAD(); - - if (channel_args != NULL) { - for (size_t i = 0; i < channel_args->num_args; i++) { - if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) { - grpc_resource_quota_unref_internal(resource_quota); - resource_quota = grpc_resource_quota_ref_internal( - (grpc_resource_quota*)channel_args->args[i].value.pointer.p); - } - } - } - - connect = (grpc_uv_tcp_connect*)gpr_zalloc(sizeof(grpc_uv_tcp_connect)); - connect->closure = closure; - connect->endpoint = ep; - connect->tcp_handle = (uv_tcp_t*)gpr_malloc(sizeof(uv_tcp_t)); - connect->addr_name = grpc_sockaddr_to_uri(resolved_addr); - connect->resource_quota = resource_quota; - uv_tcp_init(uv_default_loop(), connect->tcp_handle); - connect->connect_req.data = connect; - connect->refs = 2; // One for the connect operation, one for the timer. - - if (grpc_tcp_trace.enabled()) { - gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: asynchronously connecting", - connect->addr_name); - } - - // TODO(murgatroid99): figure out what the return value here means - uv_tcp_connect(&connect->connect_req, connect->tcp_handle, - (const struct sockaddr*)resolved_addr->addr, uv_tc_on_connect); - GRPC_CLOSURE_INIT(&connect->on_alarm, uv_tc_on_alarm, connect, - grpc_schedule_on_exec_ctx); - grpc_timer_init(&connect->alarm, deadline, &connect->on_alarm); -} - -// overridden by api_fuzzer.c -void (*grpc_tcp_client_connect_impl)( - grpc_closure* closure, grpc_endpoint** ep, - grpc_pollset_set* interested_parties, const grpc_channel_args* channel_args, - const grpc_resolved_address* addr, - grpc_millis deadline) = tcp_client_connect_impl; - -void grpc_tcp_client_connect(grpc_closure* closure, grpc_endpoint** ep, - grpc_pollset_set* interested_parties, - const grpc_channel_args* channel_args, - const grpc_resolved_address* addr, - grpc_millis deadline) { - grpc_tcp_client_connect_impl(closure, ep, interested_parties, channel_args, - addr, deadline); -} - -#endif /* GRPC_UV */ diff --git a/src/core/lib/iomgr/tcp_client_windows.cc b/src/core/lib/iomgr/tcp_client_windows.cc index 70c2495350..e5b5502597 100644 --- a/src/core/lib/iomgr/tcp_client_windows.cc +++ b/src/core/lib/iomgr/tcp_client_windows.cc @@ -122,12 +122,11 @@ static void on_connect(void* acp, grpc_error* error) { /* Tries to issue one async connection, then schedules both an IOCP notification request for the connection, and one timeout alert. */ -static void tcp_client_connect_impl(grpc_closure* on_done, - grpc_endpoint** endpoint, - grpc_pollset_set* interested_parties, - const grpc_channel_args* channel_args, - const grpc_resolved_address* addr, - grpc_millis deadline) { +static void tcp_connect(grpc_closure* on_done, grpc_endpoint** endpoint, + grpc_pollset_set* interested_parties, + const grpc_channel_args* channel_args, + const grpc_resolved_address* addr, + grpc_millis deadline) { SOCKET sock = INVALID_SOCKET; BOOL success; int status; @@ -175,7 +174,7 @@ static void tcp_client_connect_impl(grpc_closure* on_done, grpc_sockaddr_make_wildcard6(0, &local_address); status = - bind(sock, (struct sockaddr*)&local_address.addr, (int)local_address.len); + bind(sock, (grpc_sockaddr*)&local_address.addr, (int)local_address.len); if (status != 0) { error = GRPC_WSA_ERROR(WSAGetLastError(), "bind"); goto failure; @@ -183,7 +182,7 @@ static void tcp_client_connect_impl(grpc_closure* on_done, socket = grpc_winsocket_create(sock, "client"); info = &socket->write_info; - success = ConnectEx(sock, (struct sockaddr*)&addr->addr, (int)addr->len, NULL, + success = ConnectEx(sock, (grpc_sockaddr*)&addr->addr, (int)addr->len, NULL, 0, NULL, &info->overlapped); /* It wouldn't be unusual to get a success immediately. But we'll still get @@ -227,20 +226,6 @@ failure: GRPC_CLOSURE_SCHED(on_done, final_error); } -// overridden by api_fuzzer.c -void (*grpc_tcp_client_connect_impl)( - grpc_closure* closure, grpc_endpoint** ep, - grpc_pollset_set* interested_parties, const grpc_channel_args* channel_args, - const grpc_resolved_address* addr, - grpc_millis deadline) = tcp_client_connect_impl; - -void grpc_tcp_client_connect(grpc_closure* closure, grpc_endpoint** ep, - grpc_pollset_set* interested_parties, - const grpc_channel_args* channel_args, - const grpc_resolved_address* addr, - grpc_millis deadline) { - grpc_tcp_client_connect_impl(closure, ep, interested_parties, channel_args, - addr, deadline); -} +grpc_tcp_client_vtable grpc_windows_tcp_client_vtable = {tcp_connect}; #endif /* GRPC_WINSOCK_SOCKET */ diff --git a/src/core/lib/iomgr/tcp_custom.cc b/src/core/lib/iomgr/tcp_custom.cc new file mode 100644 index 0000000000..2b1fc93028 --- /dev/null +++ b/src/core/lib/iomgr/tcp_custom.cc @@ -0,0 +1,365 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/lib/iomgr/port.h" + +#include +#include + +#include + +#include +#include +#include + +#include "src/core/lib/iomgr/error.h" +#include "src/core/lib/iomgr/iomgr_custom.h" +#include "src/core/lib/iomgr/network_status_tracker.h" +#include "src/core/lib/iomgr/resource_quota.h" +#include "src/core/lib/iomgr/tcp_client.h" +#include "src/core/lib/iomgr/tcp_custom.h" +#include "src/core/lib/iomgr/tcp_server.h" +#include "src/core/lib/slice/slice_internal.h" +#include "src/core/lib/slice/slice_string_helpers.h" + +#define GRPC_TCP_DEFAULT_READ_SLICE_SIZE 8192 + +extern grpc_core::TraceFlag grpc_tcp_trace; + +grpc_socket_vtable* grpc_custom_socket_vtable = nullptr; +extern grpc_tcp_server_vtable custom_tcp_server_vtable; +extern grpc_tcp_client_vtable custom_tcp_client_vtable; + +void grpc_custom_endpoint_init(grpc_socket_vtable* impl) { + grpc_custom_socket_vtable = impl; + grpc_set_tcp_client_impl(&custom_tcp_client_vtable); + grpc_set_tcp_server_impl(&custom_tcp_server_vtable); +} + +typedef struct { + grpc_endpoint base; + gpr_refcount refcount; + grpc_custom_socket* socket; + + grpc_closure* read_cb; + grpc_closure* write_cb; + + grpc_slice_buffer* read_slices; + grpc_slice_buffer* write_slices; + + grpc_resource_user* resource_user; + grpc_resource_user_slice_allocator slice_allocator; + + bool shutting_down; + + char* peer_string; +} custom_tcp_endpoint; + +static void tcp_free(grpc_custom_socket* s) { + custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)s->endpoint; + grpc_resource_user_unref(tcp->resource_user); + gpr_free(tcp->peer_string); + gpr_free(tcp); + s->refs--; + if (s->refs == 0) { + grpc_custom_socket_vtable->destroy(s); + gpr_free(s); + } +} + +#ifndef NDEBUG +#define TCP_UNREF(tcp, reason) tcp_unref((tcp), (reason), __FILE__, __LINE__) +#define TCP_REF(tcp, reason) tcp_ref((tcp), (reason), __FILE__, __LINE__) +static void tcp_unref(custom_tcp_endpoint* tcp, const char* reason, + const char* file, int line) { + if (grpc_tcp_trace.enabled()) { + gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count); + gpr_log(file, line, GPR_LOG_SEVERITY_ERROR, + "TCP unref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp->socket, reason, + val, val - 1); + } + if (gpr_unref(&tcp->refcount)) { + tcp_free(tcp->socket); + } +} + +static void tcp_ref(custom_tcp_endpoint* tcp, const char* reason, + const char* file, int line) { + if (grpc_tcp_trace.enabled()) { + gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count); + gpr_log(file, line, GPR_LOG_SEVERITY_ERROR, + "TCP ref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp->socket, reason, + val, val + 1); + } + gpr_ref(&tcp->refcount); +} +#else +#define TCP_UNREF(tcp, reason) tcp_unref((tcp)) +#define TCP_REF(tcp, reason) tcp_ref((tcp)) +static void tcp_unref(custom_tcp_endpoint* tcp) { + if (gpr_unref(&tcp->refcount)) { + tcp_free(tcp->socket); + } +} + +static void tcp_ref(custom_tcp_endpoint* tcp) { gpr_ref(&tcp->refcount); } +#endif + +static void call_read_cb(custom_tcp_endpoint* tcp, grpc_error* error) { + grpc_closure* cb = tcp->read_cb; + if (grpc_tcp_trace.enabled()) { + gpr_log(GPR_DEBUG, "TCP:%p call_cb %p %p:%p", tcp->socket, cb, cb->cb, + cb->cb_arg); + size_t i; + const char* str = grpc_error_string(error); + gpr_log(GPR_DEBUG, "read: error=%s", str); + + for (i = 0; i < tcp->read_slices->count; i++) { + char* dump = grpc_dump_slice(tcp->read_slices->slices[i], + GPR_DUMP_HEX | GPR_DUMP_ASCII); + gpr_log(GPR_DEBUG, "READ %p (peer=%s): %s", tcp, tcp->peer_string, dump); + gpr_free(dump); + } + } + TCP_UNREF(tcp, "read"); + tcp->read_slices = nullptr; + tcp->read_cb = nullptr; + GRPC_CLOSURE_RUN(cb, error); +} + +static void custom_read_callback(grpc_custom_socket* socket, size_t nread, + grpc_error* error) { + grpc_core::ExecCtx exec_ctx; + grpc_slice_buffer garbage; + custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)socket->endpoint; + if (error == GRPC_ERROR_NONE && nread == 0) { + error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("EOF"); + } + if (error == GRPC_ERROR_NONE) { + // Successful read + if ((size_t)nread < tcp->read_slices->length) { + /* TODO(murgatroid99): Instead of discarding the unused part of the read + * buffer, reuse it as the next read buffer. */ + grpc_slice_buffer_init(&garbage); + grpc_slice_buffer_trim_end( + tcp->read_slices, tcp->read_slices->length - (size_t)nread, &garbage); + grpc_slice_buffer_reset_and_unref_internal(&garbage); + } + } else { + grpc_slice_buffer_reset_and_unref_internal(tcp->read_slices); + } + call_read_cb(tcp, error); +} + +static void tcp_read_allocation_done(void* tcpp, grpc_error* error) { + custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)tcpp; + if (grpc_tcp_trace.enabled()) { + gpr_log(GPR_DEBUG, "TCP:%p read_allocation_done: %s", tcp->socket, + grpc_error_string(error)); + } + if (error == GRPC_ERROR_NONE) { + /* Before calling read, we allocate a buffer with exactly one slice + * to tcp->read_slices and wait for the callback indicating that the + * allocation was successful. So slices[0] should always exist here */ + char* buffer = (char*)GRPC_SLICE_START_PTR(tcp->read_slices->slices[0]); + size_t len = GRPC_SLICE_LENGTH(tcp->read_slices->slices[0]); + grpc_custom_socket_vtable->read(tcp->socket, buffer, len, + custom_read_callback); + } else { + grpc_slice_buffer_reset_and_unref_internal(tcp->read_slices); + call_read_cb(tcp, GRPC_ERROR_REF(error)); + } + if (grpc_tcp_trace.enabled()) { + const char* str = grpc_error_string(error); + gpr_log(GPR_DEBUG, "Initiating read on %p: error=%s", tcp->socket, str); + } +} + +static void endpoint_read(grpc_endpoint* ep, grpc_slice_buffer* read_slices, + grpc_closure* cb) { + custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)ep; + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + GPR_ASSERT(tcp->read_cb == nullptr); + tcp->read_cb = cb; + tcp->read_slices = read_slices; + grpc_slice_buffer_reset_and_unref_internal(read_slices); + TCP_REF(tcp, "read"); + grpc_resource_user_alloc_slices(&tcp->slice_allocator, + GRPC_TCP_DEFAULT_READ_SLICE_SIZE, 1, + tcp->read_slices); +} + +static void custom_write_callback(grpc_custom_socket* socket, + grpc_error* error) { + grpc_core::ExecCtx exec_ctx; + custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)socket->endpoint; + grpc_closure* cb = tcp->write_cb; + tcp->write_cb = nullptr; + if (grpc_tcp_trace.enabled()) { + const char* str = grpc_error_string(error); + gpr_log(GPR_DEBUG, "write complete on %p: error=%s", tcp->socket, str); + } + TCP_UNREF(tcp, "write"); + GRPC_CLOSURE_SCHED(cb, error); +} + +static void endpoint_write(grpc_endpoint* ep, grpc_slice_buffer* write_slices, + grpc_closure* cb) { + custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)ep; + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + + if (grpc_tcp_trace.enabled()) { + size_t j; + + for (j = 0; j < write_slices->count; j++) { + char* data = grpc_dump_slice(write_slices->slices[j], + GPR_DUMP_HEX | GPR_DUMP_ASCII); + gpr_log(GPR_DEBUG, "WRITE %p (peer=%s): %s", tcp->socket, + tcp->peer_string, data); + gpr_free(data); + } + } + + if (tcp->shutting_down) { + GRPC_CLOSURE_SCHED(cb, GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "TCP socket is shutting down")); + return; + } + + GPR_ASSERT(tcp->write_cb == nullptr); + tcp->write_slices = write_slices; + GPR_ASSERT(tcp->write_slices->count <= UINT_MAX); + if (tcp->write_slices->count == 0) { + // No slices means we don't have to do anything, + // and libuv doesn't like empty writes + GRPC_CLOSURE_SCHED(cb, GRPC_ERROR_NONE); + return; + } + tcp->write_cb = cb; + TCP_REF(tcp, "write"); + grpc_custom_socket_vtable->write(tcp->socket, tcp->write_slices, + custom_write_callback); +} + +static void endpoint_add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset) { + // No-op. We're ignoring pollsets currently + (void)ep; + (void)pollset; +} + +static void endpoint_add_to_pollset_set(grpc_endpoint* ep, + grpc_pollset_set* pollset) { + // No-op. We're ignoring pollsets currently + (void)ep; + (void)pollset; +} + +static void endpoint_delete_from_pollset_set(grpc_endpoint* ep, + grpc_pollset_set* pollset) { + // No-op. We're ignoring pollsets currently + (void)ep; + (void)pollset; +} + +static void endpoint_shutdown(grpc_endpoint* ep, grpc_error* why) { + custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)ep; + if (!tcp->shutting_down) { + if (grpc_tcp_trace.enabled()) { + const char* str = grpc_error_string(why); + gpr_log(GPR_DEBUG, "TCP %p shutdown why=%s", tcp->socket, str); + } + tcp->shutting_down = true; + // GRPC_CLOSURE_SCHED(tcp->read_cb, GRPC_ERROR_REF(why)); + // GRPC_CLOSURE_SCHED(tcp->write_cb, GRPC_ERROR_REF(why)); + // tcp->read_cb = nullptr; + // tcp->write_cb = nullptr; + grpc_resource_user_shutdown(tcp->resource_user); + grpc_custom_socket_vtable->shutdown(tcp->socket); + } + GRPC_ERROR_UNREF(why); +} + +static void custom_close_callback(grpc_custom_socket* socket) { + socket->refs--; + if (socket->refs == 0) { + grpc_custom_socket_vtable->destroy(socket); + gpr_free(socket); + } else if (socket->endpoint) { + grpc_core::ExecCtx exec_ctx; + custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)socket->endpoint; + TCP_UNREF(tcp, "destroy"); + } +} + +static void endpoint_destroy(grpc_endpoint* ep) { + grpc_network_status_unregister_endpoint(ep); + custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)ep; + grpc_custom_socket_vtable->close(tcp->socket, custom_close_callback); +} + +static char* endpoint_get_peer(grpc_endpoint* ep) { + custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)ep; + return gpr_strdup(tcp->peer_string); +} + +static grpc_resource_user* endpoint_get_resource_user(grpc_endpoint* ep) { + custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)ep; + return tcp->resource_user; +} + +static int endpoint_get_fd(grpc_endpoint* ep) { return -1; } + +static grpc_endpoint_vtable vtable = {endpoint_read, + endpoint_write, + endpoint_add_to_pollset, + endpoint_add_to_pollset_set, + endpoint_delete_from_pollset_set, + endpoint_shutdown, + endpoint_destroy, + endpoint_get_resource_user, + endpoint_get_peer, + endpoint_get_fd}; + +grpc_endpoint* custom_tcp_endpoint_create(grpc_custom_socket* socket, + grpc_resource_quota* resource_quota, + char* peer_string) { + custom_tcp_endpoint* tcp = + (custom_tcp_endpoint*)gpr_malloc(sizeof(custom_tcp_endpoint)); + grpc_core::ExecCtx exec_ctx; + + if (grpc_tcp_trace.enabled()) { + gpr_log(GPR_DEBUG, "Creating TCP endpoint %p", socket); + } + memset(tcp, 0, sizeof(custom_tcp_endpoint)); + socket->refs++; + socket->endpoint = (grpc_endpoint*)tcp; + tcp->socket = socket; + tcp->base.vtable = &vtable; + gpr_ref_init(&tcp->refcount, 1); + tcp->peer_string = gpr_strdup(peer_string); + tcp->shutting_down = false; + tcp->resource_user = grpc_resource_user_create(resource_quota, peer_string); + grpc_resource_user_slice_allocator_init( + &tcp->slice_allocator, tcp->resource_user, tcp_read_allocation_done, tcp); + /* Tell network status tracking code about the new endpoint */ + grpc_network_status_register_endpoint(&tcp->base); + + return &tcp->base; +} diff --git a/src/core/lib/iomgr/tcp_custom.h b/src/core/lib/iomgr/tcp_custom.h new file mode 100644 index 0000000000..22caa149f8 --- /dev/null +++ b/src/core/lib/iomgr/tcp_custom.h @@ -0,0 +1,83 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_LIB_IOMGR_TCP_CUSTOM_H +#define GRPC_CORE_LIB_IOMGR_TCP_CUSTOM_H + +#include + +#include "src/core/lib/iomgr/endpoint.h" +#include "src/core/lib/iomgr/sockaddr.h" + +typedef struct grpc_tcp_listener grpc_tcp_listener; +typedef struct grpc_custom_tcp_connect grpc_custom_tcp_connect; + +typedef struct grpc_custom_socket { + // Implementation defined + void* impl; + grpc_endpoint* endpoint; + grpc_tcp_listener* listener; + grpc_custom_tcp_connect* connector; + int refs; +} grpc_custom_socket; + +typedef void (*grpc_custom_connect_callback)(grpc_custom_socket* socket, + grpc_error* error); +typedef void (*grpc_custom_write_callback)(grpc_custom_socket* socket, + grpc_error* error); +typedef void (*grpc_custom_read_callback)(grpc_custom_socket* socket, + size_t nread, grpc_error* error); +typedef void (*grpc_custom_accept_callback)(grpc_custom_socket* socket, + grpc_custom_socket* client, + grpc_error* error); +typedef void (*grpc_custom_close_callback)(grpc_custom_socket* socket); + +typedef struct grpc_socket_vtable { + grpc_error* (*init)(grpc_custom_socket* socket, int domain); + void (*connect)(grpc_custom_socket* socket, const grpc_sockaddr* addr, + size_t len, grpc_custom_connect_callback cb); + void (*destroy)(grpc_custom_socket* socket); + void (*shutdown)(grpc_custom_socket* socket); + void (*close)(grpc_custom_socket* socket, grpc_custom_close_callback cb); + void (*write)(grpc_custom_socket* socket, grpc_slice_buffer* slices, + grpc_custom_write_callback cb); + void (*read)(grpc_custom_socket* socket, char* buffer, size_t length, + grpc_custom_read_callback cb); + grpc_error* (*getpeername)(grpc_custom_socket* socket, + const grpc_sockaddr* addr, int* len); + grpc_error* (*getsockname)(grpc_custom_socket* socket, + const grpc_sockaddr* addr, int* len); + grpc_error* (*setsockopt)(grpc_custom_socket* socket, int level, int optname, + const void* optval, uint32_t optlen); + grpc_error* (*bind)(grpc_custom_socket* socket, const grpc_sockaddr* addr, + size_t len, int flags); + grpc_error* (*listen)(grpc_custom_socket* socket); + void (*accept)(grpc_custom_socket* socket, grpc_custom_socket* client, + grpc_custom_accept_callback cb); +} grpc_socket_vtable; + +/* Internal APIs */ +void grpc_custom_endpoint_init(grpc_socket_vtable* impl); + +void grpc_custom_close_server_callback(grpc_tcp_listener* listener); + +grpc_endpoint* custom_tcp_endpoint_create(grpc_custom_socket* socket, + grpc_resource_quota* resource_quota, + char* peer_string); + +#endif /* GRPC_CORE_LIB_IOMGR_TCP_CUSTOM_H */ diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc index ca0046b83b..205af22531 100644 --- a/src/core/lib/iomgr/tcp_posix.cc +++ b/src/core/lib/iomgr/tcp_posix.cc @@ -63,7 +63,7 @@ typedef GRPC_MSG_IOVLEN_TYPE msg_iovlen_type; typedef size_t msg_iovlen_type; #endif -grpc_core::TraceFlag grpc_tcp_trace(false, "tcp"); +extern grpc_core::TraceFlag grpc_tcp_trace; namespace { struct grpc_tcp { diff --git a/src/core/lib/iomgr/tcp_server.cc b/src/core/lib/iomgr/tcp_server.cc new file mode 100644 index 0000000000..ea745f266b --- /dev/null +++ b/src/core/lib/iomgr/tcp_server.cc @@ -0,0 +1,73 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/lib/iomgr/tcp_server.h" + +grpc_tcp_server_vtable* grpc_tcp_server_impl; + +grpc_error* grpc_tcp_server_create(grpc_closure* shutdown_complete, + const grpc_channel_args* args, + grpc_tcp_server** server) { + return grpc_tcp_server_impl->create(shutdown_complete, args, server); +} + +void grpc_tcp_server_start(grpc_tcp_server* server, grpc_pollset** pollsets, + size_t pollset_count, + grpc_tcp_server_cb on_accept_cb, void* cb_arg) { + grpc_tcp_server_impl->start(server, pollsets, pollset_count, on_accept_cb, + cb_arg); +} + +grpc_error* grpc_tcp_server_add_port(grpc_tcp_server* s, + const grpc_resolved_address* addr, + int* out_port) { + return grpc_tcp_server_impl->add_port(s, addr, out_port); +} + +unsigned grpc_tcp_server_port_fd_count(grpc_tcp_server* s, + unsigned port_index) { + return grpc_tcp_server_impl->port_fd_count(s, port_index); +} + +int grpc_tcp_server_port_fd(grpc_tcp_server* s, unsigned port_index, + unsigned fd_index) { + return grpc_tcp_server_impl->port_fd(s, port_index, fd_index); +} + +grpc_tcp_server* grpc_tcp_server_ref(grpc_tcp_server* s) { + return grpc_tcp_server_impl->ref(s); +} + +void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server* s, + grpc_closure* shutdown_starting) { + grpc_tcp_server_impl->shutdown_starting_add(s, shutdown_starting); +} + +void grpc_tcp_server_unref(grpc_tcp_server* s) { + grpc_tcp_server_impl->unref(s); +} + +void grpc_tcp_server_shutdown_listeners(grpc_tcp_server* s) { + grpc_tcp_server_impl->shutdown_listeners(s); +} + +void grpc_set_tcp_server_impl(grpc_tcp_server_vtable* impl) { + grpc_tcp_server_impl = impl; +} diff --git a/src/core/lib/iomgr/tcp_server.h b/src/core/lib/iomgr/tcp_server.h index 965d97407f..8fcbb2f680 100644 --- a/src/core/lib/iomgr/tcp_server.h +++ b/src/core/lib/iomgr/tcp_server.h @@ -45,6 +45,24 @@ typedef void (*grpc_tcp_server_cb)(void* arg, grpc_endpoint* ep, grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor); +typedef struct grpc_tcp_server_vtable { + grpc_error* (*create)(grpc_closure* shutdown_complete, + const grpc_channel_args* args, + grpc_tcp_server** server); + void (*start)(grpc_tcp_server* server, grpc_pollset** pollsets, + size_t pollset_count, grpc_tcp_server_cb on_accept_cb, + void* cb_arg); + grpc_error* (*add_port)(grpc_tcp_server* s, const grpc_resolved_address* addr, + int* out_port); + unsigned (*port_fd_count)(grpc_tcp_server* s, unsigned port_index); + int (*port_fd)(grpc_tcp_server* s, unsigned port_index, unsigned fd_index); + grpc_tcp_server* (*ref)(grpc_tcp_server* s); + void (*shutdown_starting_add)(grpc_tcp_server* s, + grpc_closure* shutdown_starting); + void (*unref)(grpc_tcp_server* s); + void (*shutdown_listeners)(grpc_tcp_server* s); +} grpc_tcp_server_vtable; + /* Create a server, initially not bound to any ports. The caller owns one ref. If shutdown_complete is not NULL, it will be used by grpc_tcp_server_unref() when the ref count reaches zero. */ @@ -97,4 +115,8 @@ void grpc_tcp_server_unref(grpc_tcp_server* s); /* Shutdown the fds of listeners. */ void grpc_tcp_server_shutdown_listeners(grpc_tcp_server* s); +void grpc_tcp_server_global_init(); + +void grpc_set_tcp_server_impl(grpc_tcp_server_vtable* impl); + #endif /* GRPC_CORE_LIB_IOMGR_TCP_SERVER_H */ diff --git a/src/core/lib/iomgr/tcp_server_custom.cc b/src/core/lib/iomgr/tcp_server_custom.cc new file mode 100644 index 0000000000..be92e61b62 --- /dev/null +++ b/src/core/lib/iomgr/tcp_server_custom.cc @@ -0,0 +1,479 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/lib/iomgr/port.h" + +#include +#include + +#include +#include + +#include "src/core/lib/iomgr/error.h" +#include "src/core/lib/iomgr/exec_ctx.h" +#include "src/core/lib/iomgr/iomgr_custom.h" +#include "src/core/lib/iomgr/sockaddr.h" +#include "src/core/lib/iomgr/sockaddr_utils.h" +#include "src/core/lib/iomgr/tcp_custom.h" +#include "src/core/lib/iomgr/tcp_server.h" + +extern grpc_core::TraceFlag grpc_tcp_trace; + +extern grpc_socket_vtable* grpc_custom_socket_vtable; + +/* one listening port */ +struct grpc_tcp_listener { + grpc_tcp_server* server; + unsigned port_index; + int port; + + grpc_custom_socket* socket; + + /* linked list */ + struct grpc_tcp_listener* next; + + bool closed; +}; + +struct grpc_tcp_server { + gpr_refcount refs; + + /* Called whenever accept() succeeds on a server port. */ + grpc_tcp_server_cb on_accept_cb; + void* on_accept_cb_arg; + + int open_ports; + + /* linked list of server ports */ + grpc_tcp_listener* head; + grpc_tcp_listener* tail; + + /* List of closures passed to shutdown_starting_add(). */ + grpc_closure_list shutdown_starting; + + /* shutdown callback */ + grpc_closure* shutdown_complete; + + bool shutdown; + + grpc_resource_quota* resource_quota; +}; + +static grpc_error* tcp_server_create(grpc_closure* shutdown_complete, + const grpc_channel_args* args, + grpc_tcp_server** server) { + grpc_tcp_server* s = (grpc_tcp_server*)gpr_malloc(sizeof(grpc_tcp_server)); + s->resource_quota = grpc_resource_quota_create(nullptr); + for (size_t i = 0; i < (args == nullptr ? 0 : args->num_args); i++) { + if (0 == strcmp(GRPC_ARG_RESOURCE_QUOTA, args->args[i].key)) { + if (args->args[i].type == GRPC_ARG_POINTER) { + grpc_resource_quota_unref_internal(s->resource_quota); + s->resource_quota = grpc_resource_quota_ref_internal( + (grpc_resource_quota*)args->args[i].value.pointer.p); + } else { + grpc_resource_quota_unref_internal(s->resource_quota); + gpr_free(s); + return GRPC_ERROR_CREATE_FROM_STATIC_STRING( + GRPC_ARG_RESOURCE_QUOTA " must be a pointer to a buffer pool"); + } + } + } + gpr_ref_init(&s->refs, 1); + s->on_accept_cb = nullptr; + s->on_accept_cb_arg = nullptr; + s->open_ports = 0; + s->head = nullptr; + s->tail = nullptr; + s->shutdown_starting.head = nullptr; + s->shutdown_starting.tail = nullptr; + s->shutdown_complete = shutdown_complete; + s->shutdown = false; + *server = s; + return GRPC_ERROR_NONE; +} + +static grpc_tcp_server* tcp_server_ref(grpc_tcp_server* s) { + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + gpr_ref(&s->refs); + return s; +} + +static void tcp_server_shutdown_starting_add(grpc_tcp_server* s, + grpc_closure* shutdown_starting) { + grpc_closure_list_append(&s->shutdown_starting, shutdown_starting, + GRPC_ERROR_NONE); +} + +static void finish_shutdown(grpc_tcp_server* s) { + GPR_ASSERT(s->shutdown); + if (s->shutdown_complete != nullptr) { + GRPC_CLOSURE_SCHED(s->shutdown_complete, GRPC_ERROR_NONE); + } + + while (s->head) { + grpc_tcp_listener* sp = s->head; + s->head = sp->next; + sp->next = nullptr; + gpr_free(sp); + } + grpc_resource_quota_unref_internal(s->resource_quota); + gpr_free(s); +} + +static void custom_close_callback(grpc_custom_socket* socket) { + grpc_tcp_listener* sp = socket->listener; + if (sp) { + grpc_core::ExecCtx exec_ctx; + sp->server->open_ports--; + if (sp->server->open_ports == 0 && sp->server->shutdown) { + finish_shutdown(sp->server); + } + } + socket->refs--; + if (socket->refs == 0) { + grpc_custom_socket_vtable->destroy(socket); + gpr_free(socket); + } +} + +void grpc_custom_close_server_callback(grpc_tcp_listener* sp) { + if (sp) { + grpc_core::ExecCtx exec_ctx; + sp->server->open_ports--; + if (sp->server->open_ports == 0 && sp->server->shutdown) { + finish_shutdown(sp->server); + } + } +} + +static void close_listener(grpc_tcp_listener* sp) { + grpc_custom_socket* socket = sp->socket; + if (!sp->closed) { + sp->closed = true; + grpc_custom_socket_vtable->close(socket, custom_close_callback); + } +} + +static void tcp_server_destroy(grpc_tcp_server* s) { + int immediately_done = 0; + grpc_tcp_listener* sp; + + GPR_ASSERT(!s->shutdown); + s->shutdown = true; + + if (s->open_ports == 0) { + immediately_done = 1; + } + for (sp = s->head; sp; sp = sp->next) { + close_listener(sp); + } + + if (immediately_done) { + finish_shutdown(s); + } +} + +static void tcp_server_unref(grpc_tcp_server* s) { + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + if (gpr_unref(&s->refs)) { + /* Complete shutdown_starting work before destroying. */ + grpc_core::ExecCtx exec_ctx; + GRPC_CLOSURE_LIST_SCHED(&s->shutdown_starting); + grpc_core::ExecCtx::Get()->Flush(); + tcp_server_destroy(s); + } +} + +static void finish_accept(grpc_tcp_listener* sp, grpc_custom_socket* socket) { + grpc_tcp_server_acceptor* acceptor = + (grpc_tcp_server_acceptor*)gpr_malloc(sizeof(*acceptor)); + grpc_endpoint* ep = nullptr; + grpc_resolved_address peer_name; + char* peer_name_string; + grpc_error* err; + + peer_name_string = nullptr; + memset(&peer_name, 0, sizeof(grpc_resolved_address)); + peer_name.len = GRPC_MAX_SOCKADDR_SIZE; + err = grpc_custom_socket_vtable->getpeername( + socket, (grpc_sockaddr*)&peer_name.addr, (int*)&peer_name.len); + if (err == GRPC_ERROR_NONE) { + peer_name_string = grpc_sockaddr_to_uri(&peer_name); + } else { + GRPC_LOG_IF_ERROR("getpeername error", err); + GRPC_ERROR_UNREF(err); + } + if (grpc_tcp_trace.enabled()) { + if (peer_name_string) { + gpr_log(GPR_DEBUG, "SERVER_CONNECT: %p accepted connection: %s", + sp->server, peer_name_string); + } else { + gpr_log(GPR_DEBUG, "SERVER_CONNECT: %p accepted connection", sp->server); + } + } + ep = custom_tcp_endpoint_create(socket, sp->server->resource_quota, + peer_name_string); + acceptor->from_server = sp->server; + acceptor->port_index = sp->port_index; + acceptor->fd_index = 0; + sp->server->on_accept_cb(sp->server->on_accept_cb_arg, ep, nullptr, acceptor); + gpr_free(peer_name_string); +} + +static void custom_accept_callback(grpc_custom_socket* socket, + grpc_custom_socket* client, + grpc_error* error); + +static void custom_accept_callback(grpc_custom_socket* socket, + grpc_custom_socket* client, + grpc_error* error) { + grpc_core::ExecCtx exec_ctx; + grpc_tcp_listener* sp = socket->listener; + if (error != GRPC_ERROR_NONE) { + if (!sp->closed) { + gpr_log(GPR_ERROR, "Accept failed: %s", grpc_error_string(error)); + } + gpr_free(client); + GRPC_ERROR_UNREF(error); + return; + } + finish_accept(sp, client); + if (!sp->closed) { + grpc_custom_socket* new_socket = + (grpc_custom_socket*)gpr_malloc(sizeof(grpc_custom_socket)); + new_socket->endpoint = nullptr; + new_socket->listener = nullptr; + new_socket->connector = nullptr; + new_socket->refs = 1; + grpc_custom_socket_vtable->accept(sp->socket, new_socket, + custom_accept_callback); + } +} + +static grpc_error* add_socket_to_server(grpc_tcp_server* s, + grpc_custom_socket* socket, + const grpc_resolved_address* addr, + unsigned port_index, + grpc_tcp_listener** listener) { + grpc_tcp_listener* sp = nullptr; + int port = -1; + grpc_error* error; + grpc_resolved_address sockname_temp; + + // The last argument to uv_tcp_bind is flags + error = grpc_custom_socket_vtable->bind(socket, (grpc_sockaddr*)addr->addr, + addr->len, 0); + if (error != GRPC_ERROR_NONE) { + return error; + } + + error = grpc_custom_socket_vtable->listen(socket); + if (error != GRPC_ERROR_NONE) { + return error; + } + + sockname_temp.len = GRPC_MAX_SOCKADDR_SIZE; + error = grpc_custom_socket_vtable->getsockname( + socket, (grpc_sockaddr*)&sockname_temp.addr, (int*)&sockname_temp.len); + if (error != GRPC_ERROR_NONE) { + return error; + } + + port = grpc_sockaddr_get_port(&sockname_temp); + + GPR_ASSERT(port >= 0); + GPR_ASSERT(!s->on_accept_cb && "must add ports before starting server"); + sp = (grpc_tcp_listener*)gpr_zalloc(sizeof(grpc_tcp_listener)); + sp->next = nullptr; + if (s->head == nullptr) { + s->head = sp; + } else { + s->tail->next = sp; + } + s->tail = sp; + sp->server = s; + sp->socket = socket; + sp->port = port; + sp->port_index = port_index; + sp->closed = false; + s->open_ports++; + *listener = sp; + + return GRPC_ERROR_NONE; +} + +static grpc_error* tcp_server_add_port(grpc_tcp_server* s, + const grpc_resolved_address* addr, + int* port) { + // This function is mostly copied from tcp_server_windows.c + grpc_tcp_listener* sp = nullptr; + grpc_custom_socket* socket; + grpc_resolved_address addr6_v4mapped; + grpc_resolved_address wildcard; + grpc_resolved_address* allocated_addr = nullptr; + grpc_resolved_address sockname_temp; + unsigned port_index = 0; + grpc_error* error = GRPC_ERROR_NONE; + int family; + + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + + if (s->tail != nullptr) { + port_index = s->tail->port_index + 1; + } + + /* Check if this is a wildcard port, and if so, try to keep the port the same + as some previously created listener. */ + if (grpc_sockaddr_get_port(addr) == 0) { + for (sp = s->head; sp; sp = sp->next) { + socket = sp->socket; + sockname_temp.len = GRPC_MAX_SOCKADDR_SIZE; + if (nullptr == grpc_custom_socket_vtable->getsockname( + socket, (grpc_sockaddr*)&sockname_temp.addr, + (int*)&sockname_temp.len)) { + *port = grpc_sockaddr_get_port(&sockname_temp); + if (*port > 0) { + allocated_addr = + (grpc_resolved_address*)gpr_malloc(sizeof(grpc_resolved_address)); + memcpy(allocated_addr, addr, sizeof(grpc_resolved_address)); + grpc_sockaddr_set_port(allocated_addr, *port); + addr = allocated_addr; + break; + } + } + } + } + + if (grpc_sockaddr_to_v4mapped(addr, &addr6_v4mapped)) { + addr = &addr6_v4mapped; + } + + /* Treat :: or 0.0.0.0 as a family-agnostic wildcard. */ + if (grpc_sockaddr_is_wildcard(addr, port)) { + grpc_sockaddr_make_wildcard6(*port, &wildcard); + + addr = &wildcard; + } + + if (grpc_tcp_trace.enabled()) { + char* port_string; + grpc_sockaddr_to_string(&port_string, addr, 0); + const char* str = grpc_error_string(error); + if (port_string) { + gpr_log(GPR_DEBUG, "SERVER %p add_port %s error=%s", s, port_string, str); + gpr_free(port_string); + } else { + gpr_log(GPR_DEBUG, "SERVER %p add_port error=%s", s, str); + } + } + + family = grpc_sockaddr_get_family(addr); + socket = (grpc_custom_socket*)gpr_malloc(sizeof(grpc_custom_socket)); + socket->refs = 1; + socket->endpoint = nullptr; + socket->listener = nullptr; + socket->connector = nullptr; + grpc_custom_socket_vtable->init(socket, family); + + if (error == GRPC_ERROR_NONE) { +#if defined(GPR_LINUX) && defined(SO_REUSEPORT) + if (family == AF_INET || family == AF_INET6) { + int enable = 1; + grpc_custom_socket_vtable->setsockopt(socket, SOL_SOCKET, SO_REUSEPORT, + &enable, sizeof(enable)); + } +#endif /* GPR_LINUX && SO_REUSEPORT */ + error = add_socket_to_server(s, socket, addr, port_index, &sp); + } + gpr_free(allocated_addr); + + if (error != GRPC_ERROR_NONE) { + grpc_error* error_out = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( + "Failed to add port to server", &error, 1); + GRPC_ERROR_UNREF(error); + error = error_out; + *port = -1; + } else { + GPR_ASSERT(sp != nullptr); + *port = sp->port; + } + socket->listener = sp; + return error; +} + +static void tcp_server_start(grpc_tcp_server* server, grpc_pollset** pollsets, + size_t pollset_count, + grpc_tcp_server_cb on_accept_cb, void* cb_arg) { + grpc_tcp_listener* sp; + (void)pollsets; + (void)pollset_count; + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + if (grpc_tcp_trace.enabled()) { + gpr_log(GPR_DEBUG, "SERVER_START %p", server); + } + GPR_ASSERT(on_accept_cb); + GPR_ASSERT(!server->on_accept_cb); + server->on_accept_cb = on_accept_cb; + server->on_accept_cb_arg = cb_arg; + for (sp = server->head; sp; sp = sp->next) { + grpc_custom_socket* new_socket = + (grpc_custom_socket*)gpr_malloc(sizeof(grpc_custom_socket)); + new_socket->endpoint = nullptr; + new_socket->listener = nullptr; + new_socket->connector = nullptr; + new_socket->refs = 1; + grpc_custom_socket_vtable->accept(sp->socket, new_socket, + custom_accept_callback); + } +} + +static unsigned tcp_server_port_fd_count(grpc_tcp_server* s, + unsigned port_index) { + return 0; +} + +static int tcp_server_port_fd(grpc_tcp_server* s, unsigned port_index, + unsigned fd_index) { + return -1; +} + +static void tcp_server_shutdown_listeners(grpc_tcp_server* s) { + for (grpc_tcp_listener* sp = s->head; sp; sp = sp->next) { + if (!sp->closed) { + sp->closed = true; + grpc_custom_socket_vtable->close(sp->socket, custom_close_callback); + } + } +} + +grpc_tcp_server_vtable custom_tcp_server_vtable = { + tcp_server_create, + tcp_server_start, + tcp_server_add_port, + tcp_server_port_fd_count, + tcp_server_port_fd, + tcp_server_ref, + tcp_server_shutdown_starting_add, + tcp_server_unref, + tcp_server_shutdown_listeners}; + +#ifdef GRPC_UV_TEST +grpc_tcp_server_vtable* default_tcp_server_vtable = &custom_tcp_server_vtable; +#endif diff --git a/src/core/lib/iomgr/tcp_server_posix.cc b/src/core/lib/iomgr/tcp_server_posix.cc index a609c09ea7..aba5d6cdb0 100644 --- a/src/core/lib/iomgr/tcp_server_posix.cc +++ b/src/core/lib/iomgr/tcp_server_posix.cc @@ -69,9 +69,9 @@ static void init(void) { #endif } -grpc_error* grpc_tcp_server_create(grpc_closure* shutdown_complete, - const grpc_channel_args* args, - grpc_tcp_server** server) { +static grpc_error* tcp_server_create(grpc_closure* shutdown_complete, + const grpc_channel_args* args, + grpc_tcp_server** server) { gpr_once_init(&check_init, init); grpc_tcp_server* s = @@ -392,9 +392,9 @@ static grpc_error* clone_port(grpc_tcp_listener* listener, unsigned count) { return GRPC_ERROR_NONE; } -grpc_error* grpc_tcp_server_add_port(grpc_tcp_server* s, - const grpc_resolved_address* addr, - int* out_port) { +static grpc_error* tcp_server_add_port(grpc_tcp_server* s, + const grpc_resolved_address* addr, + int* out_port) { grpc_tcp_listener* sp; grpc_resolved_address sockname_temp; grpc_resolved_address addr6_v4mapped; @@ -415,7 +415,7 @@ grpc_error* grpc_tcp_server_add_port(grpc_tcp_server* s, sockname_temp.len = sizeof(struct sockaddr_storage); if (0 == getsockname(sp->fd, - reinterpret_cast(&sockname_temp.addr), + reinterpret_cast(&sockname_temp.addr), reinterpret_cast(&sockname_temp.len))) { int used_port = grpc_sockaddr_get_port(&sockname_temp); if (used_port > 0) { @@ -458,8 +458,7 @@ static grpc_tcp_listener* get_port_index(grpc_tcp_server* s, return nullptr; } -unsigned grpc_tcp_server_port_fd_count(grpc_tcp_server* s, - unsigned port_index) { +unsigned tcp_server_port_fd_count(grpc_tcp_server* s, unsigned port_index) { unsigned num_fds = 0; gpr_mu_lock(&s->mu); grpc_tcp_listener* sp = get_port_index(s, port_index); @@ -470,8 +469,8 @@ unsigned grpc_tcp_server_port_fd_count(grpc_tcp_server* s, return num_fds; } -int grpc_tcp_server_port_fd(grpc_tcp_server* s, unsigned port_index, - unsigned fd_index) { +static int tcp_server_port_fd(grpc_tcp_server* s, unsigned port_index, + unsigned fd_index) { gpr_mu_lock(&s->mu); grpc_tcp_listener* sp = get_port_index(s, port_index); for (; sp; sp = sp->sibling, --fd_index) { @@ -484,10 +483,10 @@ int grpc_tcp_server_port_fd(grpc_tcp_server* s, unsigned port_index, return -1; } -void grpc_tcp_server_start(grpc_tcp_server* s, grpc_pollset** pollsets, - size_t pollset_count, - grpc_tcp_server_cb on_accept_cb, - void* on_accept_cb_arg) { +static void tcp_server_start(grpc_tcp_server* s, grpc_pollset** pollsets, + size_t pollset_count, + grpc_tcp_server_cb on_accept_cb, + void* on_accept_cb_arg) { size_t i; grpc_tcp_listener* sp; GPR_ASSERT(on_accept_cb); @@ -526,20 +525,20 @@ void grpc_tcp_server_start(grpc_tcp_server* s, grpc_pollset** pollsets, gpr_mu_unlock(&s->mu); } -grpc_tcp_server* grpc_tcp_server_ref(grpc_tcp_server* s) { +grpc_tcp_server* tcp_server_ref(grpc_tcp_server* s) { gpr_ref_non_zero(&s->refs); return s; } -void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server* s, - grpc_closure* shutdown_starting) { +static void tcp_server_shutdown_starting_add(grpc_tcp_server* s, + grpc_closure* shutdown_starting) { gpr_mu_lock(&s->mu); grpc_closure_list_append(&s->shutdown_starting, shutdown_starting, GRPC_ERROR_NONE); gpr_mu_unlock(&s->mu); } -void grpc_tcp_server_unref(grpc_tcp_server* s) { +static void tcp_server_unref(grpc_tcp_server* s) { if (gpr_unref(&s->refs)) { grpc_tcp_server_shutdown_listeners(s); gpr_mu_lock(&s->mu); @@ -549,7 +548,7 @@ void grpc_tcp_server_unref(grpc_tcp_server* s) { } } -void grpc_tcp_server_shutdown_listeners(grpc_tcp_server* s) { +static void tcp_server_shutdown_listeners(grpc_tcp_server* s) { gpr_mu_lock(&s->mu); s->shutdown_listeners = true; /* shutdown all fd's */ @@ -563,4 +562,14 @@ void grpc_tcp_server_shutdown_listeners(grpc_tcp_server* s) { gpr_mu_unlock(&s->mu); } +grpc_tcp_server_vtable grpc_posix_tcp_server_vtable = { + tcp_server_create, + tcp_server_start, + tcp_server_add_port, + tcp_server_port_fd_count, + tcp_server_port_fd, + tcp_server_ref, + tcp_server_shutdown_starting_add, + tcp_server_unref, + tcp_server_shutdown_listeners}; #endif diff --git a/src/core/lib/iomgr/tcp_server_utils_posix_common.cc b/src/core/lib/iomgr/tcp_server_utils_posix_common.cc index 846f9cccb7..76d3d62940 100644 --- a/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +++ b/src/core/lib/iomgr/tcp_server_utils_posix_common.cc @@ -171,8 +171,7 @@ grpc_error* grpc_tcp_server_prepare_socket(int fd, if (err != GRPC_ERROR_NONE) goto error; GPR_ASSERT(addr->len < ~(socklen_t)0); - if (bind(fd, - reinterpret_cast(const_cast(addr->addr)), + if (bind(fd, reinterpret_cast(const_cast(addr->addr)), static_cast(addr->len)) < 0) { err = GRPC_OS_ERROR(errno, "bind"); goto error; @@ -185,7 +184,7 @@ grpc_error* grpc_tcp_server_prepare_socket(int fd, sockname_temp.len = sizeof(struct sockaddr_storage); - if (getsockname(fd, reinterpret_cast(sockname_temp.addr), + if (getsockname(fd, reinterpret_cast(sockname_temp.addr), reinterpret_cast(&sockname_temp.len)) < 0) { err = GRPC_OS_ERROR(errno, "getsockname"); goto error; diff --git a/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc b/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc index 308ff0f8a6..29ff9ecda1 100644 --- a/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +++ b/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc @@ -68,13 +68,13 @@ static grpc_error* get_unused_port(int* port) { if (dsmode == GRPC_DSMODE_IPV4) { grpc_sockaddr_make_wildcard4(0, &wild); } - if (bind(fd, reinterpret_cast(wild.addr), + if (bind(fd, reinterpret_cast(wild.addr), static_cast(wild.len)) != 0) { err = GRPC_OS_ERROR(errno, "bind"); close(fd); return err; } - if (getsockname(fd, reinterpret_cast(wild.addr), + if (getsockname(fd, reinterpret_cast(wild.addr), reinterpret_cast(&wild.len)) != 0) { err = GRPC_OS_ERROR(errno, "getsockname"); close(fd); @@ -119,9 +119,9 @@ grpc_error* grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s, if (ifa_it->ifa_addr == nullptr) { continue; } else if (ifa_it->ifa_addr->sa_family == AF_INET) { - addr.len = sizeof(struct sockaddr_in); + addr.len = sizeof(grpc_sockaddr_in); } else if (ifa_it->ifa_addr->sa_family == AF_INET6) { - addr.len = sizeof(struct sockaddr_in6); + addr.len = sizeof(grpc_sockaddr_in6); } else { continue; } diff --git a/src/core/lib/iomgr/tcp_server_uv.cc b/src/core/lib/iomgr/tcp_server_uv.cc deleted file mode 100644 index aa423766c7..0000000000 --- a/src/core/lib/iomgr/tcp_server_uv.cc +++ /dev/null @@ -1,473 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/lib/iomgr/port.h" - -#ifdef GRPC_UV - -#include -#include - -#include -#include - -#include "src/core/lib/iomgr/error.h" -#include "src/core/lib/iomgr/exec_ctx.h" -#include "src/core/lib/iomgr/iomgr_uv.h" -#include "src/core/lib/iomgr/sockaddr.h" -#include "src/core/lib/iomgr/sockaddr_utils.h" -#include "src/core/lib/iomgr/tcp_server.h" -#include "src/core/lib/iomgr/tcp_uv.h" - -/* one listening port */ -typedef struct grpc_tcp_listener grpc_tcp_listener; -struct grpc_tcp_listener { - uv_tcp_t* handle; - grpc_tcp_server* server; - unsigned port_index; - int port; - /* linked list */ - struct grpc_tcp_listener* next; - - bool closed; - - bool has_pending_connection; -}; - -struct grpc_tcp_server { - gpr_refcount refs; - - /* Called whenever accept() succeeds on a server port. */ - grpc_tcp_server_cb on_accept_cb; - void* on_accept_cb_arg; - - int open_ports; - - /* linked list of server ports */ - grpc_tcp_listener* head; - grpc_tcp_listener* tail; - - /* List of closures passed to shutdown_starting_add(). */ - grpc_closure_list shutdown_starting; - - /* shutdown callback */ - grpc_closure* shutdown_complete; - - bool shutdown; - - grpc_resource_quota* resource_quota; -}; - -grpc_error* grpc_tcp_server_create(grpc_closure* shutdown_complete, - const grpc_channel_args* args, - grpc_tcp_server** server) { - grpc_tcp_server* s = (grpc_tcp_server*)gpr_malloc(sizeof(grpc_tcp_server)); - s->resource_quota = grpc_resource_quota_create(NULL); - for (size_t i = 0; i < (args == NULL ? 0 : args->num_args); i++) { - if (0 == strcmp(GRPC_ARG_RESOURCE_QUOTA, args->args[i].key)) { - if (args->args[i].type == GRPC_ARG_POINTER) { - grpc_resource_quota_unref_internal(s->resource_quota); - s->resource_quota = grpc_resource_quota_ref_internal( - (grpc_resource_quota*)args->args[i].value.pointer.p); - } else { - grpc_resource_quota_unref_internal(s->resource_quota); - gpr_free(s); - return GRPC_ERROR_CREATE_FROM_STATIC_STRING( - GRPC_ARG_RESOURCE_QUOTA " must be a pointer to a buffer pool"); - } - } - } - gpr_ref_init(&s->refs, 1); - s->on_accept_cb = NULL; - s->on_accept_cb_arg = NULL; - s->open_ports = 0; - s->head = NULL; - s->tail = NULL; - s->shutdown_starting.head = NULL; - s->shutdown_starting.tail = NULL; - s->shutdown_complete = shutdown_complete; - s->shutdown = false; - *server = s; - return GRPC_ERROR_NONE; -} - -grpc_tcp_server* grpc_tcp_server_ref(grpc_tcp_server* s) { - GRPC_UV_ASSERT_SAME_THREAD(); - gpr_ref(&s->refs); - return s; -} - -void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server* s, - grpc_closure* shutdown_starting) { - grpc_closure_list_append(&s->shutdown_starting, shutdown_starting, - GRPC_ERROR_NONE); -} - -static void finish_shutdown(grpc_tcp_server* s) { - GPR_ASSERT(s->shutdown); - if (s->shutdown_complete != NULL) { - GRPC_CLOSURE_SCHED(s->shutdown_complete, GRPC_ERROR_NONE); - } - - while (s->head) { - grpc_tcp_listener* sp = s->head; - s->head = sp->next; - sp->next = NULL; - gpr_free(sp->handle); - gpr_free(sp); - } - grpc_resource_quota_unref_internal(s->resource_quota); - gpr_free(s); -} - -static void handle_close_callback(uv_handle_t* handle) { - grpc_tcp_listener* sp = (grpc_tcp_listener*)handle->data; - grpc_core::ExecCtx exec_ctx; - sp->server->open_ports--; - if (sp->server->open_ports == 0 && sp->server->shutdown) { - finish_shutdown(sp->server); - } -} - -static void close_listener(grpc_tcp_listener* sp) { - if (!sp->closed) { - sp->closed = true; - uv_close((uv_handle_t*)sp->handle, handle_close_callback); - } -} - -static void tcp_server_destroy(grpc_tcp_server* s) { - int immediately_done = 0; - grpc_tcp_listener* sp; - - GPR_ASSERT(!s->shutdown); - s->shutdown = true; - - if (s->open_ports == 0) { - immediately_done = 1; - } - for (sp = s->head; sp; sp = sp->next) { - close_listener(sp); - } - - if (immediately_done) { - finish_shutdown(s); - } -} - -void grpc_tcp_server_unref(grpc_tcp_server* s) { - GRPC_UV_ASSERT_SAME_THREAD(); - if (gpr_unref(&s->refs)) { - /* Complete shutdown_starting work before destroying. */ - grpc_core::ExecCtx exec_ctx; - GRPC_CLOSURE_LIST_SCHED(&s->shutdown_starting); - grpc_core::ExecCtx::Get()->Flush(); - tcp_server_destroy(s); - } -} - -static void finish_accept(grpc_tcp_listener* sp) { - grpc_tcp_server_acceptor* acceptor = - (grpc_tcp_server_acceptor*)gpr_malloc(sizeof(*acceptor)); - uv_tcp_t* client = NULL; - grpc_endpoint* ep = NULL; - grpc_resolved_address peer_name; - char* peer_name_string; - int err; - uv_tcp_t* server = sp->handle; - - client = (uv_tcp_t*)gpr_malloc(sizeof(uv_tcp_t)); - uv_tcp_init(uv_default_loop(), client); - // UV documentation says this is guaranteed to succeed - uv_accept((uv_stream_t*)server, (uv_stream_t*)client); - peer_name_string = NULL; - memset(&peer_name, 0, sizeof(grpc_resolved_address)); - peer_name.len = sizeof(struct sockaddr_storage); - err = uv_tcp_getpeername(client, (struct sockaddr*)&peer_name.addr, - (int*)&peer_name.len); - if (err == 0) { - peer_name_string = grpc_sockaddr_to_uri(&peer_name); - } else { - gpr_log(GPR_INFO, "uv_tcp_getpeername error: %s", uv_strerror(err)); - } - if (grpc_tcp_trace.enabled()) { - if (peer_name_string) { - gpr_log(GPR_DEBUG, "SERVER_CONNECT: %p accepted connection: %s", - sp->server, peer_name_string); - } else { - gpr_log(GPR_DEBUG, "SERVER_CONNECT: %p accepted connection", sp->server); - } - } - ep = grpc_tcp_create(client, sp->server->resource_quota, peer_name_string); - acceptor->from_server = sp->server; - acceptor->port_index = sp->port_index; - acceptor->fd_index = 0; - sp->server->on_accept_cb(sp->server->on_accept_cb_arg, ep, NULL, acceptor); - gpr_free(peer_name_string); -} - -static void on_connect(uv_stream_t* server, int status) { - grpc_tcp_listener* sp = (grpc_tcp_listener*)server->data; - grpc_core::ExecCtx exec_ctx; - - if (status < 0) { - switch (status) { - case UV_EINTR: - case UV_EAGAIN: - return; - default: - close_listener(sp); - return; - } - } - - GPR_ASSERT(!sp->has_pending_connection); - - if (grpc_tcp_trace.enabled()) { - gpr_log(GPR_DEBUG, "SERVER_CONNECT: %p incoming connection", sp->server); - } - - // Create acceptor. - if (sp->server->on_accept_cb) { - finish_accept(sp); - } else { - sp->has_pending_connection = true; - } -} - -static grpc_error* add_addr_to_server(grpc_tcp_server* s, - const grpc_resolved_address* addr, - unsigned port_index, - grpc_tcp_listener** listener) { - grpc_tcp_listener* sp = NULL; - int port = -1; - int status; - grpc_error* error; - grpc_resolved_address sockname_temp; - uv_tcp_t* handle = (uv_tcp_t*)gpr_malloc(sizeof(uv_tcp_t)); - int family = grpc_sockaddr_get_family(addr); - - status = uv_tcp_init_ex(uv_default_loop(), handle, (unsigned int)family); -#if defined(GPR_LINUX) && defined(SO_REUSEPORT) - if (family == AF_INET || family == AF_INET6) { - int fd; - uv_fileno((uv_handle_t*)handle, &fd); - int enable = 1; - setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &enable, sizeof(enable)); - } -#endif /* GPR_LINUX && SO_REUSEPORT */ - - if (status != 0) { - error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "Failed to initialize UV tcp handle"); - error = - grpc_error_set_str(error, GRPC_ERROR_STR_OS_ERROR, - grpc_slice_from_static_string(uv_strerror(status))); - return error; - } - - // The last argument to uv_tcp_bind is flags - status = uv_tcp_bind(handle, (struct sockaddr*)addr->addr, 0); - if (status != 0) { - error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to bind to port"); - error = - grpc_error_set_str(error, GRPC_ERROR_STR_OS_ERROR, - grpc_slice_from_static_string(uv_strerror(status))); - return error; - } - - status = uv_listen((uv_stream_t*)handle, SOMAXCONN, on_connect); - if (status != 0) { - error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to listen to port"); - error = - grpc_error_set_str(error, GRPC_ERROR_STR_OS_ERROR, - grpc_slice_from_static_string(uv_strerror(status))); - return error; - } - - sockname_temp.len = (int)sizeof(struct sockaddr_storage); - status = uv_tcp_getsockname(handle, (struct sockaddr*)&sockname_temp.addr, - (int*)&sockname_temp.len); - if (status != 0) { - error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("getsockname failed"); - error = - grpc_error_set_str(error, GRPC_ERROR_STR_OS_ERROR, - grpc_slice_from_static_string(uv_strerror(status))); - return error; - } - - port = grpc_sockaddr_get_port(&sockname_temp); - - GPR_ASSERT(port >= 0); - GPR_ASSERT(!s->on_accept_cb && "must add ports before starting server"); - sp = (grpc_tcp_listener*)gpr_zalloc(sizeof(grpc_tcp_listener)); - sp->next = NULL; - if (s->head == NULL) { - s->head = sp; - } else { - s->tail->next = sp; - } - s->tail = sp; - sp->server = s; - sp->handle = handle; - sp->port = port; - sp->port_index = port_index; - sp->closed = false; - handle->data = sp; - s->open_ports++; - GPR_ASSERT(sp->handle); - *listener = sp; - - return GRPC_ERROR_NONE; -} - -static grpc_error* add_wildcard_addrs_to_server(grpc_tcp_server* s, - unsigned port_index, - int requested_port, - grpc_tcp_listener** listener) { - grpc_resolved_address wild4; - grpc_resolved_address wild6; - grpc_tcp_listener* sp = nullptr; - grpc_tcp_listener* sp2 = nullptr; - grpc_error* v6_err = GRPC_ERROR_NONE; - grpc_error* v4_err = GRPC_ERROR_NONE; - - grpc_sockaddr_make_wildcards(requested_port, &wild4, &wild6); - /* Try listening on IPv6 first. */ - if ((v6_err = add_addr_to_server(s, &wild6, port_index, &sp)) == - GRPC_ERROR_NONE) { - *listener = sp; - return GRPC_ERROR_NONE; - } - - if ((v4_err = add_addr_to_server(s, &wild4, port_index, &sp2)) == - GRPC_ERROR_NONE) { - *listener = sp2; - return GRPC_ERROR_NONE; - } - - grpc_error* root_err = GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "Failed to add any wildcard listeners"); - root_err = grpc_error_add_child(root_err, v6_err); - root_err = grpc_error_add_child(root_err, v4_err); - return root_err; -} - -grpc_error* grpc_tcp_server_add_port(grpc_tcp_server* s, - const grpc_resolved_address* addr, - int* port) { - // This function is mostly copied from tcp_server_windows.c - grpc_tcp_listener* sp = NULL; - grpc_resolved_address addr6_v4mapped; - grpc_resolved_address* allocated_addr = NULL; - grpc_resolved_address sockname_temp; - unsigned port_index = 0; - grpc_error* error = GRPC_ERROR_NONE; - - GRPC_UV_ASSERT_SAME_THREAD(); - - if (s->tail != NULL) { - port_index = s->tail->port_index + 1; - } - - /* Check if this is a wildcard port, and if so, try to keep the port the same - as some previously created listener. */ - if (grpc_sockaddr_get_port(addr) == 0) { - for (sp = s->head; sp; sp = sp->next) { - sockname_temp.len = sizeof(struct sockaddr_storage); - if (0 == uv_tcp_getsockname(sp->handle, - (struct sockaddr*)&sockname_temp.addr, - (int*)&sockname_temp.len)) { - *port = grpc_sockaddr_get_port(&sockname_temp); - if (*port > 0) { - allocated_addr = - (grpc_resolved_address*)gpr_malloc(sizeof(grpc_resolved_address)); - memcpy(allocated_addr, addr, sizeof(grpc_resolved_address)); - grpc_sockaddr_set_port(allocated_addr, *port); - addr = allocated_addr; - break; - } - } - } - } - - /* Treat :: or 0.0.0.0 as a family-agnostic wildcard. */ - if (grpc_sockaddr_is_wildcard(addr, port)) { - error = add_wildcard_addrs_to_server(s, port_index, *port, &sp); - } else { - if (grpc_sockaddr_to_v4mapped(addr, &addr6_v4mapped)) { - addr = &addr6_v4mapped; - } - - error = add_addr_to_server(s, addr, port_index, &sp); - } - - gpr_free(allocated_addr); - - if (grpc_tcp_trace.enabled()) { - char* port_string; - grpc_sockaddr_to_string(&port_string, addr, 0); - const char* str = grpc_error_string(error); - if (port_string) { - gpr_log(GPR_DEBUG, "SERVER %p add_port %s error=%s", s, port_string, str); - gpr_free(port_string); - } else { - gpr_log(GPR_DEBUG, "SERVER %p add_port error=%s", s, str); - } - } - - if (error != GRPC_ERROR_NONE) { - grpc_error* error_out = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( - "Failed to add port to server", &error, 1); - GRPC_ERROR_UNREF(error); - error = error_out; - *port = -1; - } else { - GPR_ASSERT(sp != NULL); - *port = sp->port; - } - return error; -} - -void grpc_tcp_server_start(grpc_tcp_server* server, grpc_pollset** pollsets, - size_t pollset_count, - grpc_tcp_server_cb on_accept_cb, void* cb_arg) { - grpc_tcp_listener* sp; - (void)pollsets; - (void)pollset_count; - GRPC_UV_ASSERT_SAME_THREAD(); - if (grpc_tcp_trace.enabled()) { - gpr_log(GPR_DEBUG, "SERVER_START %p", server); - } - GPR_ASSERT(on_accept_cb); - GPR_ASSERT(!server->on_accept_cb); - server->on_accept_cb = on_accept_cb; - server->on_accept_cb_arg = cb_arg; - for (sp = server->head; sp; sp = sp->next) { - if (sp->has_pending_connection) { - finish_accept(sp); - sp->has_pending_connection = false; - } - } -} - -void grpc_tcp_server_shutdown_listeners(grpc_tcp_server* s) {} - -#endif /* GRPC_UV */ diff --git a/src/core/lib/iomgr/tcp_server_windows.cc b/src/core/lib/iomgr/tcp_server_windows.cc index 6d19c1c4d7..77f3811dca 100644 --- a/src/core/lib/iomgr/tcp_server_windows.cc +++ b/src/core/lib/iomgr/tcp_server_windows.cc @@ -50,7 +50,7 @@ typedef struct grpc_tcp_listener grpc_tcp_listener; struct grpc_tcp_listener { /* This seemingly magic number comes from AcceptEx's documentation. each address buffer needs to have at least 16 more bytes at their end. */ - uint8_t addresses[(sizeof(struct sockaddr_in6) + 16) * 2]; + uint8_t addresses[(sizeof(grpc_sockaddr_in6) + 16) * 2]; /* This will hold the socket for the next accept. */ SOCKET new_socket; /* The listener winsocket. */ @@ -96,9 +96,9 @@ struct grpc_tcp_server { /* Public function. Allocates the proper data structures to hold a grpc_tcp_server. */ -grpc_error* grpc_tcp_server_create(grpc_closure* shutdown_complete, - const grpc_channel_args* args, - grpc_tcp_server** server) { +static grpc_error* tcp_server_create(grpc_closure* shutdown_complete, + const grpc_channel_args* args, + grpc_tcp_server** server) { grpc_tcp_server* s = (grpc_tcp_server*)gpr_malloc(sizeof(grpc_tcp_server)); s->channel_args = grpc_channel_args_copy(args); gpr_ref_init(&s->refs, 1); @@ -142,13 +142,13 @@ static void finish_shutdown_locked(grpc_tcp_server* s) { GRPC_ERROR_NONE); } -grpc_tcp_server* grpc_tcp_server_ref(grpc_tcp_server* s) { +static grpc_tcp_server* tcp_server_ref(grpc_tcp_server* s) { gpr_ref_non_zero(&s->refs); return s; } -void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server* s, - grpc_closure* shutdown_starting) { +static void tcp_server_shutdown_starting_add(grpc_tcp_server* s, + grpc_closure* shutdown_starting) { gpr_mu_lock(&s->mu); grpc_closure_list_append(&s->shutdown_starting, shutdown_starting, GRPC_ERROR_NONE); @@ -172,7 +172,7 @@ static void tcp_server_destroy(grpc_tcp_server* s) { gpr_mu_unlock(&s->mu); } -void grpc_tcp_server_unref(grpc_tcp_server* s) { +static void tcp_server_unref(grpc_tcp_server* s) { if (gpr_unref(&s->refs)) { grpc_tcp_server_shutdown_listeners(s); gpr_mu_lock(&s->mu); @@ -195,7 +195,7 @@ static grpc_error* prepare_socket(SOCKET sock, goto failure; } - if (bind(sock, (const struct sockaddr*)addr->addr, (int)addr->len) == + if (bind(sock, (const grpc_sockaddr*)addr->addr, (int)addr->len) == SOCKET_ERROR) { error = GRPC_WSA_ERROR(WSAGetLastError(), "bind"); goto failure; @@ -207,7 +207,7 @@ static grpc_error* prepare_socket(SOCKET sock, } sockname_temp_len = sizeof(struct sockaddr_storage); - if (getsockname(sock, (struct sockaddr*)sockname_temp.addr, + if (getsockname(sock, (grpc_sockaddr*)sockname_temp.addr, &sockname_temp_len) == SOCKET_ERROR) { error = GRPC_WSA_ERROR(WSAGetLastError(), "getsockname"); goto failure; @@ -245,7 +245,7 @@ static void decrement_active_ports_and_notify_locked(grpc_tcp_listener* sp) { static grpc_error* start_accept_locked(grpc_tcp_listener* port) { SOCKET sock = INVALID_SOCKET; BOOL success; - DWORD addrlen = sizeof(struct sockaddr_in6) + 16; + DWORD addrlen = sizeof(grpc_sockaddr_in6) + 16; DWORD bytes_received = 0; grpc_error* error = GRPC_ERROR_NONE; @@ -343,7 +343,7 @@ static void on_accept(void* arg, grpc_error* error) { gpr_free(utf8_message); } int peer_name_len = (int)peer_name.len; - err = getpeername(sock, (struct sockaddr*)peer_name.addr, &peer_name_len); + err = getpeername(sock, (grpc_sockaddr*)peer_name.addr, &peer_name_len); peer_name.len = (size_t)peer_name_len; if (!err) { peer_name_string = grpc_sockaddr_to_uri(&peer_name); @@ -442,9 +442,9 @@ static grpc_error* add_socket_to_server(grpc_tcp_server* s, SOCKET sock, return GRPC_ERROR_NONE; } -grpc_error* grpc_tcp_server_add_port(grpc_tcp_server* s, - const grpc_resolved_address* addr, - int* port) { +static grpc_error* tcp_server_add_port(grpc_tcp_server* s, + const grpc_resolved_address* addr, + int* port) { grpc_tcp_listener* sp = NULL; SOCKET sock; grpc_resolved_address addr6_v4mapped; @@ -464,7 +464,7 @@ grpc_error* grpc_tcp_server_add_port(grpc_tcp_server* s, for (sp = s->head; sp; sp = sp->next) { int sockname_temp_len = sizeof(struct sockaddr_storage); if (0 == getsockname(sp->socket->socket, - (struct sockaddr*)sockname_temp.addr, + (grpc_sockaddr*)sockname_temp.addr, &sockname_temp_len)) { sockname_temp.len = (size_t)sockname_temp_len; *port = grpc_sockaddr_get_port(&sockname_temp); @@ -516,10 +516,10 @@ done: return error; } -void grpc_tcp_server_start(grpc_tcp_server* s, grpc_pollset** pollset, - size_t pollset_count, - grpc_tcp_server_cb on_accept_cb, - void* on_accept_cb_arg) { +static void tcp_server_start(grpc_tcp_server* s, grpc_pollset** pollset, + size_t pollset_count, + grpc_tcp_server_cb on_accept_cb, + void* on_accept_cb_arg) { grpc_tcp_listener* sp; GPR_ASSERT(on_accept_cb); gpr_mu_lock(&s->mu); @@ -534,6 +534,26 @@ void grpc_tcp_server_start(grpc_tcp_server* s, grpc_pollset** pollset, gpr_mu_unlock(&s->mu); } -void grpc_tcp_server_shutdown_listeners(grpc_tcp_server* s) {} +static unsigned tcp_server_port_fd_count(grpc_tcp_server* s, + unsigned port_index) { + return 0; +} + +static int tcp_server_port_fd(grpc_tcp_server* s, unsigned port_index, + unsigned fd_index) { + return -1; +} +static void tcp_server_shutdown_listeners(grpc_tcp_server* s) {} + +grpc_tcp_server_vtable grpc_windows_tcp_server_vtable = { + tcp_server_create, + tcp_server_start, + tcp_server_add_port, + tcp_server_port_fd_count, + tcp_server_port_fd, + tcp_server_ref, + tcp_server_shutdown_starting_add, + tcp_server_unref, + tcp_server_shutdown_listeners}; #endif /* GRPC_WINSOCK_SOCKET */ diff --git a/src/core/lib/iomgr/tcp_uv.cc b/src/core/lib/iomgr/tcp_uv.cc index 6db3217d6e..5e3166926b 100644 --- a/src/core/lib/iomgr/tcp_uv.cc +++ b/src/core/lib/iomgr/tcp_uv.cc @@ -21,7 +21,6 @@ #include "src/core/lib/iomgr/port.h" #ifdef GRPC_UV - #include #include @@ -33,393 +32,393 @@ #include "src/core/lib/gpr/string.h" #include "src/core/lib/iomgr/error.h" -#include "src/core/lib/iomgr/iomgr_uv.h" +#include "src/core/lib/iomgr/iomgr_custom.h" #include "src/core/lib/iomgr/network_status_tracker.h" +#include "src/core/lib/iomgr/resolve_address_custom.h" #include "src/core/lib/iomgr/resource_quota.h" -#include "src/core/lib/iomgr/tcp_uv.h" +#include "src/core/lib/iomgr/tcp_custom.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_string_helpers.h" -grpc_core::TraceFlag grpc_tcp_trace(false, "tcp"); +#include -typedef struct { - grpc_endpoint base; - gpr_refcount refcount; +#define IGNORE_CONST(addr) ((grpc_sockaddr*)(uintptr_t)(addr)) +typedef struct uv_socket_t { + uv_connect_t connect_req; uv_write_t write_req; uv_shutdown_t shutdown_req; - uv_tcp_t* handle; - - grpc_closure* read_cb; - grpc_closure* write_cb; - - grpc_slice_buffer* read_slices; - grpc_slice_buffer* write_slices; uv_buf_t* write_buffers; - grpc_resource_user* resource_user; - grpc_resource_user_slice_allocator slice_allocator; - - bool shutting_down; + char* read_buf; + size_t read_len; - char* peer_string; - grpc_pollset* pollset; -} grpc_tcp; + bool pending_connection; + grpc_custom_socket* accept_socket; + grpc_error* accept_error; -static grpc_error* tcp_annotate_error(grpc_error* src_error, grpc_tcp* tcp) { - return grpc_error_set_str( - grpc_error_set_int( - src_error, - /* All tcp errors are marked with UNAVAILABLE so that application may - * choose to retry. */ - GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE), - GRPC_ERROR_STR_TARGET_ADDRESS, - grpc_slice_from_copied_string(tcp->peer_string)); -} + grpc_custom_connect_callback connect_cb; + grpc_custom_write_callback write_cb; + grpc_custom_read_callback read_cb; + grpc_custom_accept_callback accept_cb; + grpc_custom_close_callback close_cb; -static void tcp_free(grpc_tcp* tcp) { - grpc_resource_user_unref(tcp->resource_user); - gpr_free(tcp->handle); - gpr_free(tcp->peer_string); - gpr_free(tcp); -} - -#ifndef NDEBUG -#define TCP_UNREF(tcp, reason) tcp_unref((tcp), (reason), __FILE__, __LINE__) -#define TCP_REF(tcp, reason) tcp_ref((tcp), (reason), __FILE__, __LINE__) -static void tcp_unref(grpc_tcp* tcp, const char* reason, const char* file, - int line) { - if (grpc_tcp_trace.enabled()) { - gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count); - gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, - "TCP unref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, reason, val, - val - 1); - } - if (gpr_unref(&tcp->refcount)) { - tcp_free(tcp); - } -} +} uv_socket_t; -static void tcp_ref(grpc_tcp* tcp, const char* reason, const char* file, - int line) { - if (grpc_tcp_trace.enabled()) { - gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count); - gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, - "TCP ref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, reason, val, - val + 1); - } - gpr_ref(&tcp->refcount); -} -#else -#define TCP_UNREF(tcp, reason) tcp_unref((tcp)) -#define TCP_REF(tcp, reason) tcp_ref((tcp)) -static void tcp_unref(grpc_tcp* tcp) { - if (gpr_unref(&tcp->refcount)) { - tcp_free(tcp); +static grpc_error* tcp_error_create(const char* desc, int status) { + if (status == 0) { + return GRPC_ERROR_NONE; } + grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(desc); + /* All tcp errors are marked with UNAVAILABLE so that application may + * choose to retry. */ + error = grpc_error_set_int(error, GRPC_ERROR_INT_GRPC_STATUS, + GRPC_STATUS_UNAVAILABLE); + return grpc_error_set_str(error, GRPC_ERROR_STR_OS_ERROR, + grpc_slice_from_static_string(uv_strerror(status))); } -static void tcp_ref(grpc_tcp* tcp) { gpr_ref(&tcp->refcount); } -#endif - -static void uv_close_callback(uv_handle_t* handle) { - grpc_core::ExecCtx exec_ctx; - grpc_tcp* tcp = (grpc_tcp*)handle->data; - TCP_UNREF(tcp, "destroy"); +static void uv_socket_destroy(grpc_custom_socket* socket) { + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + gpr_free(uv_socket->handle); + gpr_free(uv_socket); } static void alloc_uv_buf(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { - grpc_core::ExecCtx exec_ctx; - grpc_tcp* tcp = (grpc_tcp*)handle->data; + uv_socket_t* uv_socket = + (uv_socket_t*)((grpc_custom_socket*)handle->data)->impl; (void)suggested_size; - /* Before calling uv_read_start, we allocate a buffer with exactly one slice - * to tcp->read_slices and wait for the callback indicating that the - * allocation was successful. So slices[0] should always exist here */ - buf->base = (char*)GRPC_SLICE_START_PTR(tcp->read_slices->slices[0]); - buf->len = GRPC_SLICE_LENGTH(tcp->read_slices->slices[0]); -} - -static void call_read_cb(grpc_tcp* tcp, grpc_error* error) { - grpc_closure* cb = tcp->read_cb; - if (grpc_tcp_trace.enabled()) { - gpr_log(GPR_DEBUG, "TCP:%p call_cb %p %p:%p", tcp, cb, cb->cb, cb->cb_arg); - size_t i; - const char* str = grpc_error_string(error); - gpr_log(GPR_DEBUG, "read: error=%s", str); - - for (i = 0; i < tcp->read_slices->count; i++) { - char* dump = grpc_dump_slice(tcp->read_slices->slices[i], - GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_DEBUG, "READ %p (peer=%s): %s", tcp, tcp->peer_string, dump); - gpr_free(dump); - } - } - tcp->read_slices = NULL; - tcp->read_cb = NULL; - GRPC_CLOSURE_RUN(cb, error); + buf->base = uv_socket->read_buf; + buf->len = uv_socket->read_len; } -static void read_callback(uv_stream_t* stream, ssize_t nread, - const uv_buf_t* buf) { - grpc_error* error; - grpc_core::ExecCtx exec_ctx; - grpc_tcp* tcp = (grpc_tcp*)stream->data; - grpc_slice_buffer garbage; +static void uv_read_callback(uv_stream_t* stream, ssize_t nread, + const uv_buf_t* buf) { + grpc_error* error = GRPC_ERROR_NONE; if (nread == 0) { // Nothing happened. Wait for the next callback return; } - TCP_UNREF(tcp, "read"); // TODO(murgatroid99): figure out what the return value here means uv_read_stop(stream); if (nread == UV_EOF) { - error = - tcp_annotate_error(GRPC_ERROR_CREATE_FROM_STATIC_STRING("EOF"), tcp); - grpc_slice_buffer_reset_and_unref_internal(tcp->read_slices); - } else if (nread > 0) { - // Successful read - error = GRPC_ERROR_NONE; - if ((size_t)nread < tcp->read_slices->length) { - /* TODO(murgatroid99): Instead of discarding the unused part of the read - * buffer, reuse it as the next read buffer. */ - grpc_slice_buffer_init(&garbage); - grpc_slice_buffer_trim_end( - tcp->read_slices, tcp->read_slices->length - (size_t)nread, &garbage); - grpc_slice_buffer_reset_and_unref_internal(&garbage); - } - } else { - // nread < 0: Error - error = tcp_annotate_error( - GRPC_ERROR_CREATE_FROM_STATIC_STRING("TCP Read failed"), tcp); - grpc_slice_buffer_reset_and_unref_internal(tcp->read_slices); + error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("EOF"); + } else if (nread < 0) { + error = tcp_error_create("TCP Read failed", nread); } - call_read_cb(tcp, error); + grpc_custom_socket* socket = (grpc_custom_socket*)stream->data; + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + uv_socket->read_cb(socket, (size_t)nread, error); } -static void tcp_read_allocation_done(void* tcpp, grpc_error* error) { - int status; - grpc_tcp* tcp = (grpc_tcp*)tcpp; - if (grpc_tcp_trace.enabled()) { - gpr_log(GPR_DEBUG, "TCP:%p read_allocation_done: %s", tcp, - grpc_error_string(error)); - } - if (error == GRPC_ERROR_NONE) { - status = - uv_read_start((uv_stream_t*)tcp->handle, alloc_uv_buf, read_callback); - if (status != 0) { - error = tcp_annotate_error( - GRPC_ERROR_CREATE_FROM_STATIC_STRING("TCP Read failed at start"), - tcp); - error = grpc_error_set_str( - error, GRPC_ERROR_STR_OS_ERROR, - grpc_slice_from_static_string(uv_strerror(status))); - } - } - if (error != GRPC_ERROR_NONE) { - grpc_slice_buffer_reset_and_unref_internal(tcp->read_slices); - call_read_cb(tcp, GRPC_ERROR_REF(error)); - TCP_UNREF(tcp, "read"); +static void uv_close_callback(uv_handle_t* handle) { + grpc_custom_socket* socket = (grpc_custom_socket*)handle->data; + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + if (uv_socket->accept_socket) { + uv_socket->accept_cb(socket, uv_socket->accept_socket, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("socket closed")); } - if (grpc_tcp_trace.enabled()) { - const char* str = grpc_error_string(error); - gpr_log(GPR_DEBUG, "Initiating read on %p: error=%s", tcp, str); + uv_socket->close_cb(socket); +} + +static void uv_socket_read(grpc_custom_socket* socket, char* buffer, + size_t length, grpc_custom_read_callback read_cb) { + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + int status; + grpc_error* error; + uv_socket->read_cb = read_cb; + uv_socket->read_buf = buffer; + uv_socket->read_len = length; + // TODO(murgatroid99): figure out what the return value here means + status = + uv_read_start((uv_stream_t*)uv_socket->handle, (uv_alloc_cb)alloc_uv_buf, + (uv_read_cb)uv_read_callback); + if (status != 0) { + error = tcp_error_create("TCP Read failed at start", status); + uv_socket->read_cb(socket, 0, error); } } -static void uv_endpoint_read(grpc_endpoint* ep, grpc_slice_buffer* read_slices, - grpc_closure* cb) { - grpc_tcp* tcp = (grpc_tcp*)ep; - GRPC_UV_ASSERT_SAME_THREAD(); - GPR_ASSERT(tcp->read_cb == NULL); - tcp->read_cb = cb; - tcp->read_slices = read_slices; - grpc_slice_buffer_reset_and_unref_internal(read_slices); - TCP_REF(tcp, "read"); - grpc_resource_user_alloc_slices(&tcp->slice_allocator, - GRPC_TCP_DEFAULT_READ_SLICE_SIZE, 1, - tcp->read_slices); +static void uv_write_callback(uv_write_t* req, int status) { + grpc_custom_socket* socket = (grpc_custom_socket*)req->data; + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + gpr_free(uv_socket->write_buffers); + uv_socket->write_cb(socket, tcp_error_create("TCP Write failed", status)); } -static void write_callback(uv_write_t* req, int status) { - grpc_tcp* tcp = (grpc_tcp*)req->data; - grpc_error* error; - grpc_core::ExecCtx exec_ctx; - grpc_closure* cb = tcp->write_cb; - tcp->write_cb = NULL; - TCP_UNREF(tcp, "write"); - if (status == 0) { - error = GRPC_ERROR_NONE; - } else { - error = tcp_annotate_error( - GRPC_ERROR_CREATE_FROM_STATIC_STRING("TCP Write failed"), tcp); - } - if (grpc_tcp_trace.enabled()) { - const char* str = grpc_error_string(error); - gpr_log(GPR_DEBUG, "write complete on %p: error=%s", tcp, str); +void uv_socket_write(grpc_custom_socket* socket, + grpc_slice_buffer* write_slices, + grpc_custom_write_callback write_cb) { + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + uv_socket->write_cb = write_cb; + uv_buf_t* uv_buffers; + uv_write_t* write_req; + + uv_buffers = (uv_buf_t*)gpr_malloc(sizeof(uv_buf_t) * write_slices->count); + for (size_t i = 0; i < write_slices->count; i++) { + uv_buffers[i].base = (char*)GRPC_SLICE_START_PTR(write_slices->slices[i]); + uv_buffers[i].len = GRPC_SLICE_LENGTH(write_slices->slices[i]); } - gpr_free(tcp->write_buffers); - GRPC_CLOSURE_SCHED(cb, error); + + uv_socket->write_buffers = uv_buffers; + write_req = &uv_socket->write_req; + write_req->data = socket; + // TODO(murgatroid99): figure out what the return value here means + uv_write(write_req, (uv_stream_t*)uv_socket->handle, uv_buffers, + write_slices->count, uv_write_callback); } -static void uv_endpoint_write(grpc_endpoint* ep, - grpc_slice_buffer* write_slices, - grpc_closure* cb) { - grpc_tcp* tcp = (grpc_tcp*)ep; - uv_buf_t* buffers; - unsigned int buffer_count; - unsigned int i; - grpc_slice* slice; - uv_write_t* write_req; - GRPC_UV_ASSERT_SAME_THREAD(); +static void shutdown_callback(uv_shutdown_t* req, int status) {} - if (grpc_tcp_trace.enabled()) { - size_t j; +static void uv_socket_shutdown(grpc_custom_socket* socket) { + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + uv_shutdown_t* req = &uv_socket->shutdown_req; + uv_shutdown(req, (uv_stream_t*)uv_socket->handle, shutdown_callback); +} - for (j = 0; j < write_slices->count; j++) { - char* data = grpc_dump_slice(write_slices->slices[j], - GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_DEBUG, "WRITE %p (peer=%s): %s", tcp, tcp->peer_string, data); - gpr_free(data); - } +static void uv_socket_close(grpc_custom_socket* socket, + grpc_custom_close_callback close_cb) { + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + uv_socket->close_cb = close_cb; + uv_close((uv_handle_t*)uv_socket->handle, uv_close_callback); +} + +static grpc_error* uv_socket_init_helper(uv_socket_t* uv_socket, int domain) { + uv_tcp_t* tcp = (uv_tcp_t*)gpr_malloc(sizeof(uv_tcp_t)); + uv_socket->handle = tcp; + int status = uv_tcp_init_ex(uv_default_loop(), tcp, (unsigned int)domain); + if (status != 0) { + return tcp_error_create("Failed to initialize UV tcp handle", status); } + uv_socket->write_buffers = nullptr; + uv_socket->read_len = 0; + uv_tcp_nodelay(uv_socket->handle, 1); + uv_socket->pending_connection = false; + uv_socket->accept_socket = nullptr; + uv_socket->accept_error = GRPC_ERROR_NONE; + return GRPC_ERROR_NONE; +} - if (tcp->shutting_down) { - GRPC_CLOSURE_SCHED(cb, - tcp_annotate_error(GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "TCP socket is shutting down"), - tcp)); - return; +static grpc_error* uv_socket_init(grpc_custom_socket* socket, int domain) { + uv_socket_t* uv_socket = (uv_socket_t*)gpr_malloc(sizeof(uv_socket_t)); + grpc_error* error = uv_socket_init_helper(uv_socket, domain); + if (error != GRPC_ERROR_NONE) { + return error; } + uv_socket->handle->data = socket; + socket->impl = uv_socket; + return GRPC_ERROR_NONE; +} + +static grpc_error* uv_socket_getpeername(grpc_custom_socket* socket, + const grpc_sockaddr* addr, + int* addr_len) { + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + int err = uv_tcp_getpeername(uv_socket->handle, + (struct sockaddr*)IGNORE_CONST(addr), addr_len); + return tcp_error_create("getpeername failed", err); +} + +static grpc_error* uv_socket_getsockname(grpc_custom_socket* socket, + const grpc_sockaddr* addr, + int* addr_len) { + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + int err = uv_tcp_getsockname(uv_socket->handle, + (struct sockaddr*)IGNORE_CONST(addr), addr_len); + return tcp_error_create("getsockname failed", err); +} - GPR_ASSERT(tcp->write_cb == NULL); - tcp->write_slices = write_slices; - GPR_ASSERT(tcp->write_slices->count <= UINT_MAX); - if (tcp->write_slices->count == 0) { - // No slices means we don't have to do anything, - // and libuv doesn't like empty writes - GRPC_CLOSURE_SCHED(cb, GRPC_ERROR_NONE); +static void accept_new_connection(grpc_custom_socket* socket) { + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + if (!uv_socket->pending_connection || !uv_socket->accept_socket) { return; } + grpc_custom_socket* new_socket = uv_socket->accept_socket; + grpc_error* error = uv_socket->accept_error; + uv_socket->accept_socket = nullptr; + uv_socket->accept_error = GRPC_ERROR_NONE; + uv_socket->pending_connection = false; + if (uv_socket->accept_error != GRPC_ERROR_NONE) { + uv_stream_t dummy_handle; + uv_accept((uv_stream_t*)uv_socket->handle, &dummy_handle); + uv_socket->accept_cb(socket, new_socket, error); + } else { + uv_socket_t* uv_new_socket = (uv_socket_t*)gpr_malloc(sizeof(uv_socket_t)); + uv_socket_init_helper(uv_new_socket, AF_UNSPEC); + // UV documentation says this is guaranteed to succeed + GPR_ASSERT(uv_accept((uv_stream_t*)uv_socket->handle, + (uv_stream_t*)uv_new_socket->handle) == 0); + new_socket->impl = uv_new_socket; + uv_new_socket->handle->data = new_socket; + uv_socket->accept_cb(socket, new_socket, error); + } +} - tcp->write_cb = cb; - buffer_count = (unsigned int)tcp->write_slices->count; - buffers = (uv_buf_t*)gpr_malloc(sizeof(uv_buf_t) * buffer_count); - for (i = 0; i < buffer_count; i++) { - slice = &tcp->write_slices->slices[i]; - buffers[i].base = (char*)GRPC_SLICE_START_PTR(*slice); - buffers[i].len = GRPC_SLICE_LENGTH(*slice); +static void uv_on_connect(uv_stream_t* server, int status) { + grpc_custom_socket* socket = (grpc_custom_socket*)server->data; + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + GPR_ASSERT(!uv_socket->pending_connection); + uv_socket->pending_connection = true; + if (status < 0) { + switch (status) { + case UV_EINTR: + case UV_EAGAIN: + return; + default: + uv_socket->accept_error = tcp_error_create("accept failed", status); + } } - tcp->write_buffers = buffers; - write_req = &tcp->write_req; - write_req->data = tcp; - TCP_REF(tcp, "write"); - // TODO(murgatroid99): figure out what the return value here means - uv_write(write_req, (uv_stream_t*)tcp->handle, buffers, buffer_count, - write_callback); + accept_new_connection(socket); } -static void uv_add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset) { - // No-op. We're ignoring pollsets currently - (void)ep; - (void)pollset; - grpc_tcp* tcp = (grpc_tcp*)ep; - tcp->pollset = pollset; +void uv_socket_accept(grpc_custom_socket* socket, + grpc_custom_socket* new_socket, + grpc_custom_accept_callback accept_cb) { + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + uv_socket->accept_cb = accept_cb; + GPR_ASSERT(uv_socket->accept_socket == nullptr); + uv_socket->accept_socket = new_socket; + accept_new_connection(socket); } -static void uv_add_to_pollset_set(grpc_endpoint* ep, - grpc_pollset_set* pollset) { - // No-op. We're ignoring pollsets currently - (void)ep; - (void)pollset; +static grpc_error* uv_socket_bind(grpc_custom_socket* socket, + const grpc_sockaddr* addr, size_t len, + int flags) { + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + int status = + uv_tcp_bind((uv_tcp_t*)uv_socket->handle, (struct sockaddr*)addr, 0); + return tcp_error_create("Failed to bind to port", status); } -static void uv_delete_from_pollset_set(grpc_endpoint* ep, - grpc_pollset_set* pollset) { - // No-op. We're ignoring pollsets currently - (void)ep; - (void)pollset; +static grpc_error* uv_socket_listen(grpc_custom_socket* socket) { + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + int status = + uv_listen((uv_stream_t*)uv_socket->handle, SOMAXCONN, uv_on_connect); + return tcp_error_create("Failed to listen to port", status); } -static void shutdown_callback(uv_shutdown_t* req, int status) {} +static grpc_error* uv_socket_setsockopt(grpc_custom_socket* socket, int level, + int option_name, const void* optval, + socklen_t option_len) { + int fd; + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + uv_fileno((uv_handle_t*)uv_socket->handle, &fd); + // TODO Handle error here. Also, does this work on windows?? + setsockopt(fd, level, option_name, &optval, (socklen_t)option_len); + return GRPC_ERROR_NONE; +} -static void uv_endpoint_shutdown(grpc_endpoint* ep, grpc_error* why) { - grpc_tcp* tcp = (grpc_tcp*)ep; - if (!tcp->shutting_down) { - if (grpc_tcp_trace.enabled()) { - const char* str = grpc_error_string(why); - gpr_log(GPR_DEBUG, "TCP %p shutdown why=%s", tcp->handle, str); - } - tcp->shutting_down = true; - uv_shutdown_t* req = &tcp->shutdown_req; - uv_shutdown(req, (uv_stream_t*)tcp->handle, shutdown_callback); - grpc_resource_user_shutdown(tcp->resource_user); +static void uv_tc_on_connect(uv_connect_t* req, int status) { + grpc_custom_socket* socket = (grpc_custom_socket*)req->data; + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + grpc_error* error; + if (status == UV_ECANCELED) { + // This should only happen if the handle is already closed + error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Timeout occurred"); + } else { + error = tcp_error_create("Failed to connect to remote host", status); } - GRPC_ERROR_UNREF(why); + uv_socket->connect_cb(socket, error); } -static void uv_destroy(grpc_endpoint* ep) { - grpc_network_status_unregister_endpoint(ep); - grpc_tcp* tcp = (grpc_tcp*)ep; - uv_close((uv_handle_t*)tcp->handle, uv_close_callback); +static void uv_socket_connect(grpc_custom_socket* socket, + const grpc_sockaddr* addr, size_t len, + grpc_custom_connect_callback connect_cb) { + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + uv_socket->connect_cb = connect_cb; + uv_socket->connect_req.data = socket; + int status = uv_tcp_connect(&uv_socket->connect_req, uv_socket->handle, + (struct sockaddr*)addr, uv_tc_on_connect); + if (status != 0) { + // The callback will not be called + uv_socket->connect_cb(socket, tcp_error_create("connect failed", status)); + } +} + +static grpc_resolved_addresses* handle_addrinfo_result( + struct addrinfo* result) { + struct addrinfo* resp; + struct addrinfo* prev; + size_t i; + grpc_resolved_addresses* addresses = + (grpc_resolved_addresses*)gpr_malloc(sizeof(grpc_resolved_addresses)); + addresses->naddrs = 0; + for (resp = result; resp != nullptr; resp = resp->ai_next) { + addresses->naddrs++; + } + addresses->addrs = (grpc_resolved_address*)gpr_malloc( + sizeof(grpc_resolved_address) * addresses->naddrs); + i = 0; + resp = result; + while (resp != nullptr) { + memcpy(&addresses->addrs[i].addr, resp->ai_addr, resp->ai_addrlen); + addresses->addrs[i].len = resp->ai_addrlen; + i++; + prev = resp; + resp = resp->ai_next; + gpr_free(prev); + } + return addresses; } -static char* uv_get_peer(grpc_endpoint* ep) { - grpc_tcp* tcp = (grpc_tcp*)ep; - return gpr_strdup(tcp->peer_string); +static void uv_resolve_callback(uv_getaddrinfo_t* req, int status, + struct addrinfo* res) { + grpc_custom_resolver* r = (grpc_custom_resolver*)req->data; + gpr_free(req); + grpc_resolved_addresses* result = nullptr; + if (status == 0) { + result = handle_addrinfo_result(res); + } + grpc_custom_resolve_callback(r, result, + tcp_error_create("getaddrinfo failed", status)); } -static grpc_resource_user* uv_get_resource_user(grpc_endpoint* ep) { - grpc_tcp* tcp = (grpc_tcp*)ep; - return tcp->resource_user; +static grpc_error* uv_resolve(char* host, char* port, + grpc_resolved_addresses** result) { + int status; + uv_getaddrinfo_t req; + struct addrinfo hints; + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = AF_UNSPEC; /* ipv4 or ipv6 */ + hints.ai_socktype = SOCK_STREAM; /* stream socket */ + hints.ai_flags = AI_PASSIVE; /* for wildcard IP address */ + status = uv_getaddrinfo(uv_default_loop(), &req, NULL, host, port, &hints); + if (status != 0) { + *result = nullptr; + } else { + *result = handle_addrinfo_result(req.addrinfo); + } + return tcp_error_create("getaddrinfo failed", status); } -static int uv_get_fd(grpc_endpoint* ep) { return -1; } - -static grpc_endpoint_vtable vtable = {uv_endpoint_read, - uv_endpoint_write, - uv_add_to_pollset, - uv_add_to_pollset_set, - uv_delete_from_pollset_set, - uv_endpoint_shutdown, - uv_destroy, - uv_get_resource_user, - uv_get_peer, - uv_get_fd}; - -grpc_endpoint* grpc_tcp_create(uv_tcp_t* handle, - grpc_resource_quota* resource_quota, - char* peer_string) { - grpc_tcp* tcp = (grpc_tcp*)gpr_malloc(sizeof(grpc_tcp)); - grpc_core::ExecCtx exec_ctx; - - if (grpc_tcp_trace.enabled()) { - gpr_log(GPR_DEBUG, "Creating TCP endpoint %p", tcp); +static void uv_resolve_async(grpc_custom_resolver* r, char* host, char* port) { + int status; + uv_getaddrinfo_t* req = + (uv_getaddrinfo_t*)gpr_malloc(sizeof(uv_getaddrinfo_t)); + req->data = r; + struct addrinfo hints; + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = GRPC_AF_UNSPEC; /* ipv4 or ipv6 */ + hints.ai_socktype = GRPC_SOCK_STREAM; /* stream socket */ + hints.ai_flags = GRPC_AI_PASSIVE; /* for wildcard IP address */ + status = uv_getaddrinfo(uv_default_loop(), req, uv_resolve_callback, host, + port, &hints); + if (status != 0) { + gpr_free(req); + grpc_error* error = tcp_error_create("getaddrinfo failed", status); + grpc_custom_resolve_callback(r, NULL, error); } +} - /* Disable Nagle's Algorithm */ - uv_tcp_nodelay(handle, 1); - - memset(tcp, 0, sizeof(grpc_tcp)); - tcp->base.vtable = &vtable; - tcp->handle = handle; - handle->data = tcp; - gpr_ref_init(&tcp->refcount, 1); - tcp->peer_string = gpr_strdup(peer_string); - tcp->shutting_down = false; - tcp->read_slices = NULL; - tcp->resource_user = grpc_resource_user_create(resource_quota, peer_string); - grpc_resource_user_slice_allocator_init( - &tcp->slice_allocator, tcp->resource_user, tcp_read_allocation_done, tcp); - /* Tell network status tracking code about the new endpoint */ - grpc_network_status_register_endpoint(&tcp->base); - -#ifndef GRPC_UV_TCP_HOLD_LOOP - uv_unref((uv_handle_t*)handle); -#endif +grpc_custom_resolver_vtable uv_resolver_vtable = {uv_resolve, uv_resolve_async}; - return &tcp->base; -} +grpc_socket_vtable grpc_uv_socket_vtable = { + uv_socket_init, uv_socket_connect, uv_socket_destroy, + uv_socket_shutdown, uv_socket_close, uv_socket_write, + uv_socket_read, uv_socket_getpeername, uv_socket_getsockname, + uv_socket_setsockopt, uv_socket_bind, uv_socket_listen, + uv_socket_accept}; -#endif /* GRPC_UV */ +#endif diff --git a/src/core/lib/iomgr/tcp_uv.h b/src/core/lib/iomgr/tcp_uv.h deleted file mode 100644 index 6b1a6f77c2..0000000000 --- a/src/core/lib/iomgr/tcp_uv.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * - * Copyright 2016 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_LIB_IOMGR_TCP_UV_H -#define GRPC_CORE_LIB_IOMGR_TCP_UV_H -/* - Low level TCP "bottom half" implementation, for use by transports built on - top of a TCP connection. - - Note that this file does not (yet) include APIs for creating the socket in - the first place. - - All calls passing slice transfer ownership of a slice refcount unless - otherwise specified. -*/ - -#include - -#include "src/core/lib/debug/trace.h" -#include "src/core/lib/iomgr/endpoint.h" - -#include "src/core/lib/iomgr/port.h" - -#ifdef GRPC_UV - -#include - -extern grpc_core::TraceFlag grpc_tcp_trace; - -#define GRPC_TCP_DEFAULT_READ_SLICE_SIZE 8192 - -grpc_endpoint* grpc_tcp_create(uv_tcp_t* handle, - grpc_resource_quota* resource_quota, - char* peer_string); - -#endif /* GRPC_UV */ - -#endif /* GRPC_CORE_LIB_IOMGR_TCP_UV_H */ diff --git a/src/core/lib/iomgr/tcp_windows.cc b/src/core/lib/iomgr/tcp_windows.cc index aab8edc888..04e6f11eee 100644 --- a/src/core/lib/iomgr/tcp_windows.cc +++ b/src/core/lib/iomgr/tcp_windows.cc @@ -51,7 +51,7 @@ #define GRPC_FIONBIO FIONBIO #endif -grpc_core::TraceFlag grpc_tcp_trace(false, "tcp"); +extern grpc_core::TraceFlag grpc_tcp_trace; static grpc_error* set_non_block(SOCKET sock) { int status; diff --git a/src/core/lib/iomgr/timer.cc b/src/core/lib/iomgr/timer.cc new file mode 100644 index 0000000000..e647cdefa0 --- /dev/null +++ b/src/core/lib/iomgr/timer.cc @@ -0,0 +1,45 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/lib/iomgr/timer.h" +#include "src/core/lib/iomgr/timer_manager.h" + +grpc_timer_vtable* grpc_timer_impl; + +void grpc_set_timer_impl(grpc_timer_vtable* vtable) { + grpc_timer_impl = vtable; +} + +void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, + grpc_closure* closure) { + grpc_timer_impl->init(timer, deadline, closure); +} + +void grpc_timer_cancel(grpc_timer* timer) { grpc_timer_impl->cancel(timer); } + +grpc_timer_check_result grpc_timer_check(grpc_millis* next) { + return grpc_timer_impl->check(next); +} + +void grpc_timer_list_init() { grpc_timer_impl->list_init(); } + +void grpc_timer_list_shutdown() { grpc_timer_impl->list_shutdown(); } + +void grpc_timer_consume_kick() { grpc_timer_impl->consume_kick(); } diff --git a/src/core/lib/iomgr/timer.h b/src/core/lib/iomgr/timer.h index 67f1b1b3f9..5ff10d3aee 100644 --- a/src/core/lib/iomgr/timer.h +++ b/src/core/lib/iomgr/timer.h @@ -23,17 +23,41 @@ #include "src/core/lib/iomgr/port.h" -#ifdef GRPC_UV -#include "src/core/lib/iomgr/timer_uv.h" -#else -#include "src/core/lib/iomgr/timer_generic.h" -#endif /* GRPC_UV */ - #include #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/iomgr.h" -typedef struct grpc_timer grpc_timer; +typedef struct grpc_timer { + gpr_atm deadline; + uint32_t heap_index; /* INVALID_HEAP_INDEX if not in heap */ + bool pending; + struct grpc_timer* next; + struct grpc_timer* prev; + grpc_closure* closure; +#ifndef NDEBUG + struct grpc_timer* hash_table_next; +#endif + + // Optional field used by custom timers + void* custom_timer; +} grpc_timer; + +typedef enum { + GRPC_TIMERS_NOT_CHECKED, + GRPC_TIMERS_CHECKED_AND_EMPTY, + GRPC_TIMERS_FIRED, +} grpc_timer_check_result; + +typedef struct grpc_timer_vtable { + void (*init)(grpc_timer* timer, grpc_millis, grpc_closure* closure); + void (*cancel)(grpc_timer* timer); + + /* Internal API */ + grpc_timer_check_result (*check)(grpc_millis* next); + void (*list_init)(); + void (*list_shutdown)(void); + void (*consume_kick)(void); +} grpc_timer_vtable; /* Initialize *timer. When expired or canceled, closure will be called with error set to indicate if it expired (GRPC_ERROR_NONE) or was canceled @@ -78,12 +102,6 @@ void grpc_timer_cancel(grpc_timer* timer); /* iomgr internal api for dealing with timers */ -typedef enum { - GRPC_TIMERS_NOT_CHECKED, - GRPC_TIMERS_CHECKED_AND_EMPTY, - GRPC_TIMERS_FIRED, -} grpc_timer_check_result; - /* Check for timers to be run, and run them. Return true if timer callbacks were executed. If next is non-null, TRY to update *next with the next running timer @@ -99,7 +117,9 @@ void grpc_timer_list_shutdown(); void grpc_timer_consume_kick(void); /* the following must be implemented by each iomgr implementation */ - void grpc_kick_poller(void); +/* Sets the timer implementation */ +void grpc_set_timer_impl(grpc_timer_vtable* vtable); + #endif /* GRPC_CORE_LIB_IOMGR_TIMER_H */ diff --git a/src/core/lib/iomgr/timer_custom.cc b/src/core/lib/iomgr/timer_custom.cc new file mode 100644 index 0000000000..71d825ff9f --- /dev/null +++ b/src/core/lib/iomgr/timer_custom.cc @@ -0,0 +1,93 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/lib/iomgr/port.h" + +#include +#include + +#include "src/core/lib/debug/trace.h" +#include "src/core/lib/iomgr/iomgr_custom.h" +#include "src/core/lib/iomgr/timer.h" +#include "src/core/lib/iomgr/timer_custom.h" + +static grpc_custom_timer_vtable* custom_timer_impl; + +void grpc_custom_timer_callback(grpc_custom_timer* t, grpc_error* error) { + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + grpc_core::ExecCtx exec_ctx; + grpc_timer* timer = t->original; + GPR_ASSERT(timer->pending); + timer->pending = 0; + GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_NONE); + custom_timer_impl->stop(t); + gpr_free(t); +} + +static void timer_init(grpc_timer* timer, grpc_millis deadline, + grpc_closure* closure) { + uint64_t timeout; + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + grpc_millis now = grpc_core::ExecCtx::Get()->Now(); + if (deadline <= grpc_core::ExecCtx::Get()->Now()) { + GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_NONE); + timer->pending = false; + return; + } else { + timeout = deadline - now; + } + timer->pending = true; + timer->closure = closure; + grpc_custom_timer* timer_wrapper = + (grpc_custom_timer*)gpr_malloc(sizeof(grpc_custom_timer)); + timer_wrapper->timeout_ms = timeout; + timer->custom_timer = (void*)timer_wrapper; + timer_wrapper->original = timer; + custom_timer_impl->start(timer_wrapper); +} + +static void timer_cancel(grpc_timer* timer) { + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + grpc_custom_timer* tw = (grpc_custom_timer*)timer->custom_timer; + if (timer->pending) { + timer->pending = 0; + GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_CANCELLED); + custom_timer_impl->stop(tw); + gpr_free(tw); + } +} + +static grpc_timer_check_result timer_check(grpc_millis* next) { + return GRPC_TIMERS_NOT_CHECKED; +} + +static void timer_list_init() {} +static void timer_list_shutdown() {} + +static void timer_consume_kick(void) {} + +static grpc_timer_vtable custom_timer_vtable = { + timer_init, timer_cancel, timer_check, + timer_list_init, timer_list_shutdown, timer_consume_kick}; + +void grpc_custom_timer_init(grpc_custom_timer_vtable* impl) { + custom_timer_impl = impl; + grpc_set_timer_impl(&custom_timer_vtable); +} diff --git a/src/core/lib/iomgr/timer_custom.h b/src/core/lib/iomgr/timer_custom.h new file mode 100644 index 0000000000..bfea8bafa6 --- /dev/null +++ b/src/core/lib/iomgr/timer_custom.h @@ -0,0 +1,43 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_LIB_IOMGR_TIMER_CUSTOM_H +#define GRPC_CORE_LIB_IOMGR_TIMER_CUSTOM_H + +#include + +#include "src/core/lib/iomgr/timer.h" + +typedef struct grpc_custom_timer { + // Implementation defined + void* timer; + uint64_t timeout_ms; + + grpc_timer* original; +} grpc_custom_timer; + +typedef struct grpc_custom_timer_vtable { + void (*start)(grpc_custom_timer* t); + void (*stop)(grpc_custom_timer* t); +} grpc_custom_timer_vtable; + +void grpc_custom_timer_init(grpc_custom_timer_vtable* impl); + +void grpc_custom_timer_callback(grpc_custom_timer* t, grpc_error* error); + +#endif /* GRPC_CORE_LIB_IOMGR_TIMER_CUSTOM_H */ diff --git a/src/core/lib/iomgr/timer_generic.cc b/src/core/lib/iomgr/timer_generic.cc index 52a571f425..93e654b7fa 100644 --- a/src/core/lib/iomgr/timer_generic.cc +++ b/src/core/lib/iomgr/timer_generic.cc @@ -22,8 +22,6 @@ #include -#ifdef GRPC_TIMER_USE_GENERIC - #include "src/core/lib/iomgr/timer.h" #include @@ -238,7 +236,7 @@ static gpr_atm compute_min_deadline(timer_shard* shard) { : grpc_timer_heap_top(&shard->heap)->deadline; } -void grpc_timer_list_init() { +static void timer_list_init() { uint32_t i; g_num_shards = GPR_MIN(1, 2 * gpr_cpu_num_cores()); @@ -270,7 +268,7 @@ void grpc_timer_list_init() { INIT_TIMER_HASH_TABLE(); } -void grpc_timer_list_shutdown() { +static void timer_list_shutdown() { size_t i; run_some_expired_timers( GPR_ATM_MAX, nullptr, @@ -326,8 +324,8 @@ static void note_deadline_change(timer_shard* shard) { void grpc_timer_init_unset(grpc_timer* timer) { timer->pending = false; } -void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, - grpc_closure* closure) { +static void timer_init(grpc_timer* timer, grpc_millis deadline, + grpc_closure* closure) { int is_first_timer = 0; timer_shard* shard = &g_shards[GPR_HASH_POINTER(timer, g_num_shards)]; timer->closure = closure; @@ -412,12 +410,12 @@ void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, } } -void grpc_timer_consume_kick(void) { +static void timer_consume_kick(void) { /* force re-evaluation of last seeen min */ gpr_tls_set(&g_last_seen_min_timer, 0); } -void grpc_timer_cancel(grpc_timer* timer) { +static void timer_cancel(grpc_timer* timer) { if (!g_shared_mutables.initialized) { /* must have already been cancelled, also the shard mutex is invalid */ return; @@ -604,7 +602,7 @@ static grpc_timer_check_result run_some_expired_timers(gpr_atm now, return result; } -grpc_timer_check_result grpc_timer_check(grpc_millis* next) { +static grpc_timer_check_result timer_check(grpc_millis* next) { // prelude grpc_millis now = grpc_core::ExecCtx::Get()->Now(); @@ -660,4 +658,6 @@ grpc_timer_check_result grpc_timer_check(grpc_millis* next) { return r; } -#endif /* GRPC_TIMER_USE_GENERIC */ +grpc_timer_vtable grpc_generic_timer_vtable = { + timer_init, timer_cancel, timer_check, + timer_list_init, timer_list_shutdown, timer_consume_kick}; diff --git a/src/core/lib/iomgr/timer_heap.cc b/src/core/lib/iomgr/timer_heap.cc index e5b5abfc97..0c17d607eb 100644 --- a/src/core/lib/iomgr/timer_heap.cc +++ b/src/core/lib/iomgr/timer_heap.cc @@ -20,8 +20,6 @@ #include "src/core/lib/iomgr/port.h" -#ifdef GRPC_TIMER_USE_GENERIC - #include "src/core/lib/iomgr/timer_heap.h" #include @@ -135,5 +133,3 @@ grpc_timer* grpc_timer_heap_top(grpc_timer_heap* heap) { void grpc_timer_heap_pop(grpc_timer_heap* heap) { grpc_timer_heap_remove(heap, grpc_timer_heap_top(heap)); } - -#endif /* GRPC_TIMER_USE_GENERIC */ diff --git a/src/core/lib/iomgr/timer_uv.cc b/src/core/lib/iomgr/timer_uv.cc index 6f28f553c5..dadeb960b2 100644 --- a/src/core/lib/iomgr/timer_uv.cc +++ b/src/core/lib/iomgr/timer_uv.cc @@ -20,20 +20,18 @@ #include "src/core/lib/iomgr/port.h" -#if GRPC_UV +#ifdef GRPC_UV #include #include #include "src/core/lib/debug/trace.h" -#include "src/core/lib/iomgr/iomgr_uv.h" +#include "src/core/lib/iomgr/iomgr_custom.h" #include "src/core/lib/iomgr/timer.h" +#include "src/core/lib/iomgr/timer_custom.h" #include -grpc_core::TraceFlag grpc_timer_trace(false, "timer"); -grpc_core::TraceFlag grpc_timer_check_trace(false, "timer_check"); - static void timer_close_callback(uv_handle_t* handle) { gpr_free(handle); } static void stop_uv_timer(uv_timer_t* handle) { @@ -43,57 +41,23 @@ static void stop_uv_timer(uv_timer_t* handle) { } void run_expired_timer(uv_timer_t* handle) { - grpc_timer* timer = (grpc_timer*)handle->data; - grpc_core::ExecCtx exec_ctx; - GRPC_UV_ASSERT_SAME_THREAD(); - GPR_ASSERT(timer->pending); - timer->pending = 0; - GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_NONE); - stop_uv_timer(handle); + grpc_custom_timer* timer_wrapper = (grpc_custom_timer*)handle->data; + grpc_custom_timer_callback(timer_wrapper, GRPC_ERROR_NONE); } -void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, - grpc_closure* closure) { - uint64_t timeout; +static void timer_start(grpc_custom_timer* t) { uv_timer_t* uv_timer; - GRPC_UV_ASSERT_SAME_THREAD(); - timer->closure = closure; - if (deadline <= grpc_core::ExecCtx::Get()->Now()) { - timer->pending = 0; - GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_NONE); - return; - } - timer->pending = 1; - timeout = (uint64_t)(deadline - grpc_core::ExecCtx::Get()->Now()); uv_timer = (uv_timer_t*)gpr_malloc(sizeof(uv_timer_t)); uv_timer_init(uv_default_loop(), uv_timer); - uv_timer->data = timer; - timer->uv_timer = uv_timer; - uv_timer_start(uv_timer, run_expired_timer, timeout, 0); - /* We assume that gRPC timers are only used alongside other active gRPC - objects, and that there will therefore always be something else keeping - the uv loop alive whenever there is a timer */ - uv_unref((uv_handle_t*)uv_timer); + uv_timer->data = t; + t->timer = (void*)uv_timer; + uv_timer_start(uv_timer, run_expired_timer, t->timeout_ms, 0); } -void grpc_timer_init_unset(grpc_timer* timer) { timer->pending = 0; } - -void grpc_timer_cancel(grpc_timer* timer) { - GRPC_UV_ASSERT_SAME_THREAD(); - if (timer->pending) { - timer->pending = 0; - GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_CANCELLED); - stop_uv_timer((uv_timer_t*)timer->uv_timer); - } +static void timer_stop(grpc_custom_timer* t) { + stop_uv_timer((uv_timer_t*)t->timer); } -grpc_timer_check_result grpc_timer_check(grpc_millis* next) { - return GRPC_TIMERS_NOT_CHECKED; -} - -void grpc_timer_list_init() {} -void grpc_timer_list_shutdown() {} - -void grpc_timer_consume_kick(void) {} +grpc_custom_timer_vtable uv_timer_vtable = {timer_start, timer_stop}; -#endif /* GRPC_UV */ +#endif diff --git a/src/core/lib/iomgr/timer_uv.h b/src/core/lib/iomgr/timer_uv.h deleted file mode 100644 index 093b2d085d..0000000000 --- a/src/core/lib/iomgr/timer_uv.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * - * Copyright 2016 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_LIB_IOMGR_TIMER_UV_H -#define GRPC_CORE_LIB_IOMGR_TIMER_UV_H - -#include - -#include "src/core/lib/iomgr/exec_ctx.h" - -struct grpc_timer { - grpc_closure* closure; - /* This is actually a uv_timer_t*, but we want to keep platform-specific - types out of headers */ - void* uv_timer; - int pending; -}; - -#endif /* GRPC_CORE_LIB_IOMGR_TIMER_UV_H */ diff --git a/src/core/lib/iomgr/udp_server.cc b/src/core/lib/iomgr/udp_server.cc index e739a5df93..15a242abe2 100644 --- a/src/core/lib/iomgr/udp_server.cc +++ b/src/core/lib/iomgr/udp_server.cc @@ -345,7 +345,7 @@ static int bind_socket(grpc_socket_factory* socket_factory, int sockfd, return (socket_factory != nullptr) ? grpc_socket_factory_bind(socket_factory, sockfd, addr) : bind(sockfd, - reinterpret_cast( + reinterpret_cast( const_cast(addr->addr)), static_cast(addr->len)); } @@ -355,8 +355,8 @@ static int prepare_socket(grpc_socket_factory* socket_factory, int fd, const grpc_resolved_address* addr, int rcv_buf_size, int snd_buf_size) { grpc_resolved_address sockname_temp; - struct sockaddr* addr_ptr = - reinterpret_cast(const_cast(addr->addr)); + grpc_sockaddr* addr_ptr = + reinterpret_cast(const_cast(addr->addr)); if (fd < 0) { goto error; @@ -392,7 +392,7 @@ static int prepare_socket(grpc_socket_factory* socket_factory, int fd, sockname_temp.len = sizeof(struct sockaddr_storage); - if (getsockname(fd, reinterpret_cast(sockname_temp.addr), + if (getsockname(fd, reinterpret_cast(sockname_temp.addr), reinterpret_cast(&sockname_temp.len)) < 0) { goto error; } @@ -576,10 +576,9 @@ int grpc_udp_server_add_port(grpc_udp_server* s, if (grpc_sockaddr_get_port(addr) == 0) { for (size_t i = 0; i < s->listeners.size(); ++i) { sockname_temp.len = sizeof(struct sockaddr_storage); - if (0 == - getsockname(s->listeners[i].fd(), - reinterpret_cast(sockname_temp.addr), - reinterpret_cast(&sockname_temp.len))) { + if (0 == getsockname(s->listeners[i].fd(), + reinterpret_cast(sockname_temp.addr), + reinterpret_cast(&sockname_temp.len))) { port = grpc_sockaddr_get_port(&sockname_temp); if (port > 0) { allocated_addr = static_cast( diff --git a/src/core/lib/iomgr/unix_sockets_posix.cc b/src/core/lib/iomgr/unix_sockets_posix.cc index 8d252fd331..5d09b4a9b1 100644 --- a/src/core/lib/iomgr/unix_sockets_posix.cc +++ b/src/core/lib/iomgr/unix_sockets_posix.cc @@ -66,15 +66,15 @@ grpc_error* grpc_resolve_unix_domain_address(const char* name, } int grpc_is_unix_socket(const grpc_resolved_address* resolved_addr) { - const struct sockaddr* addr = - reinterpret_cast(resolved_addr->addr); + const grpc_sockaddr* addr = + reinterpret_cast(resolved_addr->addr); return addr->sa_family == AF_UNIX; } void grpc_unlink_if_unix_domain_socket( const grpc_resolved_address* resolved_addr) { - const struct sockaddr* addr = - reinterpret_cast(resolved_addr->addr); + const grpc_sockaddr* addr = + reinterpret_cast(resolved_addr->addr); if (addr->sa_family != AF_UNIX) { return; } @@ -89,8 +89,8 @@ void grpc_unlink_if_unix_domain_socket( char* grpc_sockaddr_to_uri_unix_if_possible( const grpc_resolved_address* resolved_addr) { - const struct sockaddr* addr = - reinterpret_cast(resolved_addr->addr); + const grpc_sockaddr* addr = + reinterpret_cast(resolved_addr->addr); if (addr->sa_family != AF_UNIX) { return nullptr; } diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 994443c651..d96cbec292 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -97,6 +97,8 @@ CORE_SOURCE_FILES = [ 'src/core/lib/iomgr/gethostname_sysconf.cc', 'src/core/lib/iomgr/iocp_windows.cc', 'src/core/lib/iomgr/iomgr.cc', + 'src/core/lib/iomgr/iomgr_custom.cc', + 'src/core/lib/iomgr/iomgr_internal.cc', 'src/core/lib/iomgr/iomgr_posix.cc', 'src/core/lib/iomgr/iomgr_uv.cc', 'src/core/lib/iomgr/iomgr_windows.cc', @@ -105,12 +107,16 @@ CORE_SOURCE_FILES = [ 'src/core/lib/iomgr/lockfree_event.cc', 'src/core/lib/iomgr/network_status_tracker.cc', 'src/core/lib/iomgr/polling_entity.cc', - 'src/core/lib/iomgr/pollset_set_uv.cc', + 'src/core/lib/iomgr/pollset.cc', + 'src/core/lib/iomgr/pollset_custom.cc', + 'src/core/lib/iomgr/pollset_set.cc', + 'src/core/lib/iomgr/pollset_set_custom.cc', 'src/core/lib/iomgr/pollset_set_windows.cc', 'src/core/lib/iomgr/pollset_uv.cc', 'src/core/lib/iomgr/pollset_windows.cc', + 'src/core/lib/iomgr/resolve_address.cc', + 'src/core/lib/iomgr/resolve_address_custom.cc', 'src/core/lib/iomgr/resolve_address_posix.cc', - 'src/core/lib/iomgr/resolve_address_uv.cc', 'src/core/lib/iomgr/resolve_address_windows.cc', 'src/core/lib/iomgr/resource_quota.cc', 'src/core/lib/iomgr/sockaddr_utils.cc', @@ -122,19 +128,24 @@ CORE_SOURCE_FILES = [ 'src/core/lib/iomgr/socket_utils_uv.cc', 'src/core/lib/iomgr/socket_utils_windows.cc', 'src/core/lib/iomgr/socket_windows.cc', + 'src/core/lib/iomgr/tcp_client.cc', + 'src/core/lib/iomgr/tcp_client_custom.cc', 'src/core/lib/iomgr/tcp_client_posix.cc', - 'src/core/lib/iomgr/tcp_client_uv.cc', 'src/core/lib/iomgr/tcp_client_windows.cc', + 'src/core/lib/iomgr/tcp_custom.cc', 'src/core/lib/iomgr/tcp_posix.cc', + 'src/core/lib/iomgr/tcp_server.cc', + 'src/core/lib/iomgr/tcp_server_custom.cc', 'src/core/lib/iomgr/tcp_server_posix.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_common.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc', - 'src/core/lib/iomgr/tcp_server_uv.cc', 'src/core/lib/iomgr/tcp_server_windows.cc', 'src/core/lib/iomgr/tcp_uv.cc', 'src/core/lib/iomgr/tcp_windows.cc', 'src/core/lib/iomgr/time_averaged_stats.cc', + 'src/core/lib/iomgr/timer.cc', + 'src/core/lib/iomgr/timer_custom.cc', 'src/core/lib/iomgr/timer_generic.cc', 'src/core/lib/iomgr/timer_heap.cc', 'src/core/lib/iomgr/timer_manager.cc', diff --git a/test/core/client_channel/parse_address_test.cc b/test/core/client_channel/parse_address_test.cc index 373ed76cbe..ae157fbb8b 100644 --- a/test/core/client_channel/parse_address_test.cc +++ b/test/core/client_channel/parse_address_test.cc @@ -18,6 +18,7 @@ #include "src/core/ext/filters/client_channel/parse_address.h" #include "src/core/lib/iomgr/sockaddr.h" +#include "src/core/lib/iomgr/socket_utils.h" #include #ifdef GRPC_HAVE_UNIX_SOCKET @@ -58,16 +59,15 @@ static void test_grpc_parse_ipv4(const char* uri_text, const char* host, grpc_core::ExecCtx exec_ctx; grpc_uri* uri = grpc_uri_parse(uri_text, 0); grpc_resolved_address addr; - char ntop_buf[INET_ADDRSTRLEN]; + char ntop_buf[GRPC_INET_ADDRSTRLEN]; GPR_ASSERT(1 == grpc_parse_ipv4(uri, &addr)); - struct sockaddr_in* addr_in = - reinterpret_cast(addr.addr); - GPR_ASSERT(AF_INET == addr_in->sin_family); - GPR_ASSERT(nullptr != grpc_inet_ntop(AF_INET, &addr_in->sin_addr, ntop_buf, - sizeof(ntop_buf))); + grpc_sockaddr_in* addr_in = reinterpret_cast(addr.addr); + GPR_ASSERT(GRPC_AF_INET == addr_in->sin_family); + GPR_ASSERT(nullptr != grpc_inet_ntop(GRPC_AF_INET, &addr_in->sin_addr, + ntop_buf, sizeof(ntop_buf))); GPR_ASSERT(0 == strcmp(ntop_buf, host)); - GPR_ASSERT(ntohs(addr_in->sin_port) == port); + GPR_ASSERT(grpc_ntohs(addr_in->sin_port) == port); grpc_uri_destroy(uri); } @@ -77,16 +77,15 @@ static void test_grpc_parse_ipv6(const char* uri_text, const char* host, grpc_core::ExecCtx exec_ctx; grpc_uri* uri = grpc_uri_parse(uri_text, 0); grpc_resolved_address addr; - char ntop_buf[INET6_ADDRSTRLEN]; + char ntop_buf[GRPC_INET6_ADDRSTRLEN]; GPR_ASSERT(1 == grpc_parse_ipv6(uri, &addr)); - struct sockaddr_in6* addr_in6 = - reinterpret_cast(addr.addr); - GPR_ASSERT(AF_INET6 == addr_in6->sin6_family); - GPR_ASSERT(nullptr != grpc_inet_ntop(AF_INET6, &addr_in6->sin6_addr, ntop_buf, - sizeof(ntop_buf))); + grpc_sockaddr_in6* addr_in6 = reinterpret_cast(addr.addr); + GPR_ASSERT(GRPC_AF_INET6 == addr_in6->sin6_family); + GPR_ASSERT(nullptr != grpc_inet_ntop(GRPC_AF_INET6, &addr_in6->sin6_addr, + ntop_buf, sizeof(ntop_buf))); GPR_ASSERT(0 == strcmp(ntop_buf, host)); - GPR_ASSERT(ntohs(addr_in6->sin6_port) == port); + GPR_ASSERT(grpc_ntohs(addr_in6->sin6_port) == port); GPR_ASSERT(addr_in6->sin6_scope_id == scope_id); grpc_uri_destroy(uri); diff --git a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc index 966fb1d14b..e34aa2e676 100644 --- a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc +++ b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc @@ -57,6 +57,9 @@ static void my_resolve_address(const char* addr, const char* default_port, GRPC_CLOSURE_SCHED(on_done, error); } +static grpc_address_resolver_vtable test_resolver = {my_resolve_address, + nullptr}; + static grpc_ares_request* my_dns_lookup_ares( const char* dns_server, const char* addr, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, @@ -143,7 +146,7 @@ int main(int argc, char** argv) { grpc_init(); gpr_mu_init(&g_mu); g_combiner = grpc_combiner_create(); - grpc_resolve_address = my_resolve_address; + grpc_set_resolver_impl(&test_resolver); grpc_dns_lookup_ares = my_dns_lookup_ares; grpc_channel_args* result = (grpc_channel_args*)1; diff --git a/test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc b/test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc index 9402a605b3..01c61a9f18 100644 --- a/test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc +++ b/test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc @@ -28,12 +28,10 @@ #include "src/core/lib/iomgr/sockaddr_utils.h" #include "test/core/util/test_config.h" -static grpc_combiner* g_combiner; +extern grpc_address_resolver_vtable* grpc_resolve_address_impl; +static grpc_address_resolver_vtable* default_resolve_address; -static void (*g_default_grpc_resolve_address)( - const char* name, const char* default_port, - grpc_pollset_set* interested_parties, grpc_closure* on_done, - grpc_resolved_addresses** addrs); +static grpc_combiner* g_combiner; grpc_ares_request* (*g_default_dns_lookup_ares)( const char* dns_server, const char* name, const char* default_port, @@ -52,18 +50,28 @@ struct iomgr_args { grpc_pollset_set* pollset_set; } g_iomgr_args; -// Wrapper around g_default_grpc_resolve_address in order to count the number of +// Wrapper around default resolve_address in order to count the number of // times we incur in a system-level name resolution. static void test_resolve_address_impl(const char* name, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addrs) { - g_default_grpc_resolve_address(name, default_port, g_iomgr_args.pollset_set, - on_done, addrs); + default_resolve_address->resolve_address( + name, default_port, g_iomgr_args.pollset_set, on_done, addrs); ++g_resolution_count; } +static grpc_error* test_blocking_resolve_address_impl( + const char* name, const char* default_port, + grpc_resolved_addresses** addresses) { + return default_resolve_address->blocking_resolve_address(name, default_port, + addresses); +} + +static grpc_address_resolver_vtable test_resolver = { + test_resolve_address_impl, test_blocking_resolve_address_impl}; + grpc_ares_request* test_dns_lookup_ares( const char* dns_server, const char* name, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, @@ -285,11 +293,14 @@ int main(int argc, char** argv) { g_combiner = grpc_combiner_create(); - const bool using_cares = (grpc_resolve_address == grpc_resolve_address_ares); - g_default_grpc_resolve_address = grpc_resolve_address; + bool using_cares = false; +#if GRPC_ARES == 1 + using_cares = true; +#endif g_default_dns_lookup_ares = grpc_dns_lookup_ares; grpc_dns_lookup_ares = test_dns_lookup_ares; - grpc_resolve_address = test_resolve_address_impl; + default_resolve_address = grpc_resolve_address_impl; + grpc_set_resolver_impl(&test_resolver); test_cooldown(using_cares); diff --git a/test/core/end2end/fixtures/http_proxy_fixture.cc b/test/core/end2end/fixtures/http_proxy_fixture.cc index 58353376f3..f02fa9d998 100644 --- a/test/core/end2end/fixtures/http_proxy_fixture.cc +++ b/test/core/end2end/fixtures/http_proxy_fixture.cc @@ -535,10 +535,10 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( GPR_ASSERT(error == GRPC_ERROR_NONE); // Bind to port. grpc_resolved_address resolved_addr; - struct sockaddr_in* addr = - reinterpret_cast(resolved_addr.addr); + grpc_sockaddr_in* addr = + reinterpret_cast(resolved_addr.addr); memset(&resolved_addr, 0, sizeof(resolved_addr)); - addr->sin_family = AF_INET; + addr->sin_family = GRPC_AF_INET; grpc_sockaddr_set_port(&resolved_addr, proxy_port); int port; error = grpc_tcp_server_add_port(proxy->server, &resolved_addr, &port); diff --git a/test/core/end2end/fuzzers/api_fuzzer.cc b/test/core/end2end/fuzzers/api_fuzzer.cc index b6347fb1db..9ace7d04aa 100644 --- a/test/core/end2end/fuzzers/api_fuzzer.cc +++ b/test/core/end2end/fuzzers/api_fuzzer.cc @@ -426,6 +426,9 @@ void my_resolve_address(const char* addr, const char* default_port, GRPC_CLOSURE_CREATE(finish_resolve, r, grpc_schedule_on_exec_ctx)); } +static grpc_address_resolver_vtable fuzzer_resolver = {my_resolve_address, + nullptr}; + grpc_ares_request* my_dns_lookup_ares(const char* dns_server, const char* addr, const char* default_port, grpc_pollset_set* interested_parties, @@ -447,12 +450,6 @@ grpc_ares_request* my_dns_lookup_ares(const char* dns_server, const char* addr, //////////////////////////////////////////////////////////////////////////////// // client connection -// defined in tcp_client_posix.c -extern void (*grpc_tcp_client_connect_impl)( - grpc_closure* closure, grpc_endpoint** ep, - grpc_pollset_set* interested_parties, const grpc_channel_args* channel_args, - const grpc_resolved_address* addr, grpc_millis deadline); - static void sched_connect(grpc_closure* closure, grpc_endpoint** ep, gpr_timespec deadline); @@ -513,6 +510,8 @@ static void my_tcp_client_connect(grpc_closure* closure, grpc_endpoint** ep, grpc_millis_to_timespec(deadline, GPR_CLOCK_MONOTONIC)); } +grpc_tcp_client_vtable fuzz_tcp_client_vtable = {my_tcp_client_connect}; + //////////////////////////////////////////////////////////////////////////////// // test driver @@ -753,7 +752,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (squelch && grpc_trace_fuzzer == nullptr) gpr_set_log_function(dont_log); gpr_free(grpc_trace_fuzzer); input_stream inp = {data, data + size}; - grpc_tcp_client_connect_impl = my_tcp_client_connect; + grpc_set_tcp_client_impl(&fuzz_tcp_client_vtable); gpr_now_impl = now_impl; grpc_init(); grpc_timer_manager_set_threading(false); @@ -761,7 +760,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_core::ExecCtx exec_ctx; grpc_executor_set_threading(false); } - grpc_resolve_address = my_resolve_address; + grpc_set_resolver_impl(&fuzzer_resolver); grpc_dns_lookup_ares = my_dns_lookup_ares; GPR_ASSERT(g_channel == nullptr); diff --git a/test/core/end2end/goaway_server_test.cc b/test/core/end2end/goaway_server_test.cc index 09f0301c44..8ff14e2b85 100644 --- a/test/core/end2end/goaway_server_test.cc +++ b/test/core/end2end/goaway_server_test.cc @@ -21,6 +21,7 @@ including windows.h on Windows, uv.h must be included before other system headers. Therefore, sockaddr.h must always be included first */ #include "src/core/lib/iomgr/sockaddr.h" +#include "src/core/lib/iomgr/socket_utils.h" #include #include @@ -35,14 +36,13 @@ #include "test/core/util/port.h" #include "test/core/util/test_config.h" +extern grpc_address_resolver_vtable* grpc_resolve_address_impl; +static grpc_address_resolver_vtable* default_resolver; + static void* tag(intptr_t i) { return (void*)i; } static gpr_mu g_mu; static int g_resolve_port = -1; -static void (*iomgr_resolve_address)(const char* addr, const char* default_port, - grpc_pollset_set* interested_parties, - grpc_closure* on_done, - grpc_resolved_addresses** addresses); static grpc_ares_request* (*iomgr_dns_lookup_ares)( const char* dns_server, const char* addr, const char* default_port, @@ -61,8 +61,8 @@ static void my_resolve_address(const char* addr, const char* default_port, grpc_closure* on_done, grpc_resolved_addresses** addrs) { if (0 != strcmp(addr, "test")) { - iomgr_resolve_address(addr, default_port, interested_parties, on_done, - addrs); + default_resolver->resolve_address(addr, default_port, interested_parties, + on_done, addrs); return; } @@ -77,17 +77,27 @@ static void my_resolve_address(const char* addr, const char* default_port, (*addrs)->addrs = static_cast( gpr_malloc(sizeof(*(*addrs)->addrs))); memset((*addrs)->addrs, 0, sizeof(*(*addrs)->addrs)); - struct sockaddr_in* sa = - reinterpret_cast((*addrs)->addrs[0].addr); - sa->sin_family = AF_INET; - sa->sin_addr.s_addr = htonl(0x7f000001); - sa->sin_port = htons(static_cast(g_resolve_port)); + grpc_sockaddr_in* sa = + reinterpret_cast((*addrs)->addrs[0].addr); + sa->sin_family = GRPC_AF_INET; + sa->sin_addr.s_addr = 0x100007f; + sa->sin_port = grpc_htons(static_cast(g_resolve_port)); (*addrs)->addrs[0].len = sizeof(*sa); gpr_mu_unlock(&g_mu); } GRPC_CLOSURE_SCHED(on_done, error); } +static grpc_error* my_blocking_resolve_address( + const char* name, const char* default_port, + grpc_resolved_addresses** addresses) { + return default_resolver->blocking_resolve_address(name, default_port, + addresses); +} + +static grpc_address_resolver_vtable test_resolver = { + my_resolve_address, my_blocking_resolve_address}; + static grpc_ares_request* my_dns_lookup_ares( const char* dns_server, const char* addr, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, @@ -106,11 +116,11 @@ static grpc_ares_request* my_dns_lookup_ares( error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Forced Failure"); } else { *lb_addrs = grpc_lb_addresses_create(1, nullptr); - struct sockaddr_in* sa = static_cast( - gpr_zalloc(sizeof(struct sockaddr_in))); - sa->sin_family = AF_INET; - sa->sin_addr.s_addr = htonl(0x7f000001); - sa->sin_port = htons(static_cast(g_resolve_port)); + grpc_sockaddr_in* sa = + static_cast(gpr_zalloc(sizeof(grpc_sockaddr_in))); + sa->sin_family = GRPC_AF_INET; + sa->sin_addr.s_addr = 0x100007f; + sa->sin_port = grpc_htons(static_cast(g_resolve_port)); grpc_lb_addresses_set_address(*lb_addrs, 0, sa, sizeof(*sa), false, nullptr, nullptr); gpr_free(sa); @@ -130,9 +140,9 @@ int main(int argc, char** argv) { gpr_mu_init(&g_mu); grpc_init(); - iomgr_resolve_address = grpc_resolve_address; + default_resolver = grpc_resolve_address_impl; + grpc_set_resolver_impl(&test_resolver); iomgr_dns_lookup_ares = grpc_dns_lookup_ares; - grpc_resolve_address = my_resolve_address; grpc_dns_lookup_ares = my_dns_lookup_ares; int was_cancelled1; diff --git a/test/core/end2end/tests/request_with_flags.cc b/test/core/end2end/tests/request_with_flags.cc index 4a54318d0f..c52482470e 100644 --- a/test/core/end2end/tests/request_with_flags.cc +++ b/test/core/end2end/tests/request_with_flags.cc @@ -48,14 +48,12 @@ static gpr_timespec n_seconds_from_now(int n) { return grpc_timeout_seconds_to_deadline(n); } -static gpr_timespec five_seconds_from_now(void) { - return n_seconds_from_now(5); -} +static gpr_timespec one_second_from_now(void) { return n_seconds_from_now(1); } static void drain_cq(grpc_completion_queue* cq) { grpc_event ev; do { - ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr); + ev = grpc_completion_queue_next(cq, one_second_from_now(), nullptr); } while (ev.type != GRPC_QUEUE_SHUTDOWN); } @@ -109,7 +107,7 @@ static void test_invoke_request_with_flags( grpc_slice details; grpc_call_error expectation; - gpr_timespec deadline = five_seconds_from_now(); + gpr_timespec deadline = one_second_from_now(); c = grpc_channel_create_call( f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq, grpc_slice_from_static_string("/foo"), diff --git a/test/core/iomgr/sockaddr_utils_test.cc b/test/core/iomgr/sockaddr_utils_test.cc index 32d2a384bd..aa9ece3081 100644 --- a/test/core/iomgr/sockaddr_utils_test.cc +++ b/test/core/iomgr/sockaddr_utils_test.cc @@ -22,6 +22,7 @@ headers. Therefore, sockaddr.h must always be included first */ #include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/iomgr/sockaddr.h" +#include "src/core/lib/iomgr/socket_utils.h" #include #include @@ -33,34 +34,33 @@ static grpc_resolved_address make_addr4(const uint8_t* data, size_t data_len) { grpc_resolved_address resolved_addr4; - struct sockaddr_in* addr4 = - reinterpret_cast(resolved_addr4.addr); + grpc_sockaddr_in* addr4 = + reinterpret_cast(resolved_addr4.addr); memset(&resolved_addr4, 0, sizeof(resolved_addr4)); - addr4->sin_family = AF_INET; + addr4->sin_family = GRPC_AF_INET; GPR_ASSERT(data_len == sizeof(addr4->sin_addr.s_addr)); memcpy(&addr4->sin_addr.s_addr, data, data_len); - addr4->sin_port = htons(12345); - resolved_addr4.len = sizeof(struct sockaddr_in); + addr4->sin_port = grpc_htons(12345); + resolved_addr4.len = sizeof(grpc_sockaddr_in); return resolved_addr4; } static grpc_resolved_address make_addr6(const uint8_t* data, size_t data_len) { grpc_resolved_address resolved_addr6; - struct sockaddr_in6* addr6 = - reinterpret_cast(resolved_addr6.addr); + grpc_sockaddr_in6* addr6 = + reinterpret_cast(resolved_addr6.addr); memset(&resolved_addr6, 0, sizeof(resolved_addr6)); - addr6->sin6_family = AF_INET6; + addr6->sin6_family = GRPC_AF_INET6; GPR_ASSERT(data_len == sizeof(addr6->sin6_addr.s6_addr)); memcpy(&addr6->sin6_addr.s6_addr, data, data_len); - addr6->sin6_port = htons(12345); - resolved_addr6.len = sizeof(struct sockaddr_in6); + addr6->sin6_port = grpc_htons(12345); + resolved_addr6.len = sizeof(grpc_sockaddr_in6); return resolved_addr6; } static void set_addr6_scope_id(grpc_resolved_address* addr, uint32_t scope_id) { - struct sockaddr_in6* addr6 = - reinterpret_cast(addr->addr); - GPR_ASSERT(addr6->sin6_family == AF_INET6); + grpc_sockaddr_in6* addr6 = reinterpret_cast(addr->addr); + GPR_ASSERT(addr6->sin6_family == GRPC_AF_INET6); addr6->sin6_scope_id = scope_id; } @@ -131,9 +131,9 @@ static void test_sockaddr_is_wildcard(void) { grpc_resolved_address wild6; grpc_resolved_address wild_mapped; grpc_resolved_address dummy; - struct sockaddr_in* wild4_addr; - struct sockaddr_in6* wild6_addr; - struct sockaddr_in6* wild_mapped_addr; + grpc_sockaddr_in* wild4_addr; + grpc_sockaddr_in6* wild6_addr; + grpc_sockaddr_in6* wild_mapped_addr; int port; gpr_log(GPR_INFO, "%s", "test_sockaddr_is_wildcard"); @@ -146,7 +146,7 @@ static void test_sockaddr_is_wildcard(void) { port = -1; GPR_ASSERT(grpc_sockaddr_is_wildcard(&wild4, &port)); GPR_ASSERT(port == 555); - wild4_addr = reinterpret_cast(&wild4.addr); + wild4_addr = reinterpret_cast(&wild4.addr); memset(&wild4_addr->sin_addr.s_addr, 0xbd, 1); GPR_ASSERT(!grpc_sockaddr_is_wildcard(&wild4, &port)); @@ -154,7 +154,7 @@ static void test_sockaddr_is_wildcard(void) { port = -1; GPR_ASSERT(grpc_sockaddr_is_wildcard(&wild6, &port)); GPR_ASSERT(port == 555); - wild6_addr = reinterpret_cast(&wild6.addr); + wild6_addr = reinterpret_cast(&wild6.addr); memset(&wild6_addr->sin6_addr.s6_addr, 0xbd, 1); GPR_ASSERT(!grpc_sockaddr_is_wildcard(&wild6, &port)); @@ -162,7 +162,7 @@ static void test_sockaddr_is_wildcard(void) { port = -1; GPR_ASSERT(grpc_sockaddr_is_wildcard(&wild_mapped, &port)); GPR_ASSERT(port == 555); - wild_mapped_addr = reinterpret_cast(&wild_mapped.addr); + wild_mapped_addr = reinterpret_cast(&wild_mapped.addr); memset(&wild_mapped_addr->sin6_addr.s6_addr, 0xbd, 1); GPR_ASSERT(!grpc_sockaddr_is_wildcard(&wild_mapped, &port)); @@ -200,7 +200,7 @@ static void test_sockaddr_to_string(void) { grpc_resolved_address input4; grpc_resolved_address input6; grpc_resolved_address dummy; - struct sockaddr* dummy_addr; + grpc_sockaddr* dummy_addr; gpr_log(GPR_INFO, "%s", "test_sockaddr_to_string"); @@ -237,7 +237,7 @@ static void test_sockaddr_to_string(void) { expect_sockaddr_uri("ipv6:[::fffe:c000:263]:12345", &input6); memset(&dummy, 0, sizeof(dummy)); - dummy_addr = reinterpret_cast(dummy.addr); + dummy_addr = reinterpret_cast(dummy.addr); dummy_addr->sa_family = 123; expect_sockaddr_str("(sockaddr family=123)", &dummy, 0); expect_sockaddr_str("(sockaddr family=123)", &dummy, 1); @@ -248,7 +248,7 @@ static void test_sockaddr_set_get_port(void) { grpc_resolved_address input4; grpc_resolved_address input6; grpc_resolved_address dummy; - struct sockaddr* dummy_addr; + grpc_sockaddr* dummy_addr; gpr_log(GPR_DEBUG, "test_sockaddr_set_get_port"); @@ -263,7 +263,7 @@ static void test_sockaddr_set_get_port(void) { GPR_ASSERT(grpc_sockaddr_get_port(&input6) == 54321); memset(&dummy, 0, sizeof(dummy)); - dummy_addr = reinterpret_cast(dummy.addr); + dummy_addr = reinterpret_cast(dummy.addr); dummy_addr->sa_family = 123; GPR_ASSERT(grpc_sockaddr_get_port(&dummy) == 0); GPR_ASSERT(grpc_sockaddr_set_port(&dummy, 1234) == 0); diff --git a/test/core/iomgr/timer_heap_test.cc b/test/core/iomgr/timer_heap_test.cc index 08f5d632e3..ebe5e32f3a 100644 --- a/test/core/iomgr/timer_heap_test.cc +++ b/test/core/iomgr/timer_heap_test.cc @@ -18,9 +18,6 @@ #include "src/core/lib/iomgr/port.h" -// This test only works with the generic timer implementation -#ifdef GRPC_TIMER_USE_GENERIC - #include "src/core/lib/iomgr/timer_heap.h" #include @@ -299,9 +296,3 @@ int main(int argc, char** argv) { return 0; } - -#else /* GRPC_TIMER_USE_GENERIC */ - -int main(int argc, char** argv) { return 1; } - -#endif /* GRPC_TIMER_USE_GENERIC */ diff --git a/test/core/iomgr/timer_list_test.cc b/test/core/iomgr/timer_list_test.cc index deb8c4d87e..b1d919b292 100644 --- a/test/core/iomgr/timer_list_test.cc +++ b/test/core/iomgr/timer_list_test.cc @@ -19,8 +19,9 @@ #include "src/core/lib/iomgr/port.h" // This test only works with the generic timer implementation -#ifdef GRPC_TIMER_USE_GENERIC +#ifndef GRPC_CUSTOM_SOCKET +#include "src/core/lib/iomgr/iomgr_internal.h" #include "src/core/lib/iomgr/timer.h" #include @@ -153,15 +154,19 @@ void destruction_test(void) { int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_core::ExecCtx::GlobalInit(); + grpc_core::ExecCtx exec_ctx; + grpc_determine_iomgr_platform(); + grpc_iomgr_platform_init(); gpr_set_log_verbosity(GPR_LOG_SEVERITY_DEBUG); add_test(); destruction_test(); + grpc_iomgr_platform_shutdown(); grpc_core::ExecCtx::GlobalShutdown(); return 0; } -#else /* GRPC_TIMER_USE_GENERIC */ +#else /* GRPC_CUSTOM_SOCKET */ int main(int argc, char** argv) { return 1; } -#endif /* GRPC_TIMER_USE_GENERIC */ +#endif /* GRPC_CUSTOM_SOCKET */ diff --git a/test/core/iomgr/wakeup_fd_cv_test.cc b/test/core/iomgr/wakeup_fd_cv_test.cc index 9bd7c6e47e..f297a569d2 100644 --- a/test/core/iomgr/wakeup_fd_cv_test.cc +++ b/test/core/iomgr/wakeup_fd_cv_test.cc @@ -225,7 +225,7 @@ int main(int argc, char** argv) { grpc_poll_function = &mock_poll; gpr_mu_init(&poll_mu); gpr_cv_init(&poll_cv); - + grpc_determine_iomgr_platform(); grpc_iomgr_platform_init(); test_many_fds(); grpc_iomgr_platform_shutdown(); diff --git a/test/core/surface/concurrent_connectivity_test.cc b/test/core/surface/concurrent_connectivity_test.cc index c1298b6636..fbc5ec4c54 100644 --- a/test/core/surface/concurrent_connectivity_test.cc +++ b/test/core/surface/concurrent_connectivity_test.cc @@ -124,14 +124,13 @@ void bad_server_thread(void* vargs) { grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; - struct sockaddr_storage* addr = - reinterpret_cast(resolved_addr.addr); + grpc_sockaddr* addr = reinterpret_cast(resolved_addr.addr); int port; grpc_tcp_server* s; grpc_error* error = grpc_tcp_server_create(nullptr, nullptr, &s); GPR_ASSERT(error == GRPC_ERROR_NONE); memset(&resolved_addr, 0, sizeof(resolved_addr)); - addr->ss_family = AF_INET; + addr->sa_family = GRPC_AF_INET; error = grpc_tcp_server_add_port(s, &resolved_addr, &port); GPR_ASSERT(GRPC_LOG_IF_ERROR("grpc_tcp_server_add_port", error)); GPR_ASSERT(port > 0); diff --git a/test/core/util/test_tcp_server.cc b/test/core/util/test_tcp_server.cc index cb2bc701fa..610a9918ce 100644 --- a/test/core/util/test_tcp_server.cc +++ b/test/core/util/test_tcp_server.cc @@ -17,6 +17,7 @@ */ #include "src/core/lib/iomgr/sockaddr.h" +#include "src/core/lib/iomgr/socket_utils.h" #include "test/core/util/test_tcp_server.h" @@ -54,13 +55,13 @@ void test_tcp_server_init(test_tcp_server* server, void test_tcp_server_start(test_tcp_server* server, int port) { grpc_resolved_address resolved_addr; - struct sockaddr_in* addr = - reinterpret_cast(resolved_addr.addr); + grpc_sockaddr_in* addr = + reinterpret_cast(resolved_addr.addr); int port_added; grpc_core::ExecCtx exec_ctx; - addr->sin_family = AF_INET; - addr->sin_port = htons(static_cast(port)); + addr->sin_family = GRPC_AF_INET; + addr->sin_port = grpc_htons(static_cast(port)); memset(&addr->sin_addr, 0, sizeof(addr->sin_addr)); grpc_error* error = grpc_tcp_server_create(&server->shutdown_complete, diff --git a/test/cpp/end2end/client_lb_end2end_test.cc b/test/cpp/end2end/client_lb_end2end_test.cc index 455eaceb59..a39e443cf0 100644 --- a/test/cpp/end2end/client_lb_end2end_test.cc +++ b/test/cpp/end2end/client_lb_end2end_test.cc @@ -40,6 +40,7 @@ #include "src/core/lib/gpr/env.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" +#include "src/core/lib/iomgr/tcp_client.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "test/core/util/port.h" @@ -52,13 +53,10 @@ using grpc::testing::EchoRequest; using grpc::testing::EchoResponse; using std::chrono::system_clock; -// defined in tcp_client_posix.c -extern void (*grpc_tcp_client_connect_impl)( - grpc_closure* closure, grpc_endpoint** ep, - grpc_pollset_set* interested_parties, const grpc_channel_args* channel_args, - const grpc_resolved_address* addr, grpc_millis deadline); +// defined in tcp_client.cc +extern grpc_tcp_client_vtable* grpc_tcp_client_impl; -const auto original_tcp_connect_fn = grpc_tcp_client_connect_impl; +static grpc_tcp_client_vtable* default_client_impl; namespace grpc { namespace testing { @@ -75,10 +73,12 @@ void tcp_client_connect_with_delay(grpc_closure* closure, grpc_endpoint** ep, if (delay_ms > 0) { gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(delay_ms)); } - original_tcp_connect_fn(closure, ep, interested_parties, channel_args, addr, - deadline + delay_ms); + default_client_impl->connect(closure, ep, interested_parties, channel_args, + addr, deadline + delay_ms); } +grpc_tcp_client_vtable delayed_connect = {tcp_client_connect_with_delay}; + // Subclass of TestServiceImpl that increments a request counter for // every call to the Echo RPC. class MyTestServiceImpl : public TestServiceImpl { @@ -384,7 +384,8 @@ TEST_F(ClientLbEnd2endTest, PickFirstBackOffMinReconnect) { // Make connection delay a 10% longer than it's willing to in order to make // sure we are hitting the codepath that waits for the min reconnect backoff. gpr_atm_rel_store(&g_connection_delay_ms, kMinReconnectBackOffMs * 1.10); - grpc_tcp_client_connect_impl = tcp_client_connect_with_delay; + default_client_impl = grpc_tcp_client_impl; + grpc_set_tcp_client_impl(&delayed_connect); const gpr_timespec t0 = gpr_now(GPR_CLOCK_MONOTONIC); channel->WaitForConnected( grpc_timeout_milliseconds_to_deadline(kMinReconnectBackOffMs * 2)); diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index ff5abc679d..c822d9b3cd 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -1070,9 +1070,9 @@ src/core/lib/iomgr/executor.h \ src/core/lib/iomgr/gethostname.h \ src/core/lib/iomgr/iocp_windows.h \ src/core/lib/iomgr/iomgr.h \ +src/core/lib/iomgr/iomgr_custom.h \ src/core/lib/iomgr/iomgr_internal.h \ src/core/lib/iomgr/iomgr_posix.h \ -src/core/lib/iomgr/iomgr_uv.h \ src/core/lib/iomgr/is_epollexclusive_available.h \ src/core/lib/iomgr/load_file.h \ src/core/lib/iomgr/lockfree_event.h \ @@ -1080,14 +1080,17 @@ src/core/lib/iomgr/nameser.h \ src/core/lib/iomgr/network_status_tracker.h \ src/core/lib/iomgr/polling_entity.h \ src/core/lib/iomgr/pollset.h \ +src/core/lib/iomgr/pollset_custom.h \ src/core/lib/iomgr/pollset_set.h \ +src/core/lib/iomgr/pollset_set_custom.h \ src/core/lib/iomgr/pollset_set_windows.h \ -src/core/lib/iomgr/pollset_uv.h \ src/core/lib/iomgr/pollset_windows.h \ src/core/lib/iomgr/port.h \ src/core/lib/iomgr/resolve_address.h \ +src/core/lib/iomgr/resolve_address_custom.h \ src/core/lib/iomgr/resource_quota.h \ src/core/lib/iomgr/sockaddr.h \ +src/core/lib/iomgr/sockaddr_custom.h \ src/core/lib/iomgr/sockaddr_posix.h \ src/core/lib/iomgr/sockaddr_utils.h \ src/core/lib/iomgr/sockaddr_windows.h \ @@ -1099,17 +1102,16 @@ src/core/lib/iomgr/socket_windows.h \ src/core/lib/iomgr/sys_epoll_wrapper.h \ src/core/lib/iomgr/tcp_client.h \ src/core/lib/iomgr/tcp_client_posix.h \ +src/core/lib/iomgr/tcp_custom.h \ src/core/lib/iomgr/tcp_posix.h \ src/core/lib/iomgr/tcp_server.h \ src/core/lib/iomgr/tcp_server_utils_posix.h \ -src/core/lib/iomgr/tcp_uv.h \ src/core/lib/iomgr/tcp_windows.h \ src/core/lib/iomgr/time_averaged_stats.h \ src/core/lib/iomgr/timer.h \ -src/core/lib/iomgr/timer_generic.h \ +src/core/lib/iomgr/timer_custom.h \ src/core/lib/iomgr/timer_heap.h \ src/core/lib/iomgr/timer_manager.h \ -src/core/lib/iomgr/timer_uv.h \ src/core/lib/iomgr/udp_server.h \ src/core/lib/iomgr/unix_sockets_posix.h \ src/core/lib/iomgr/wakeup_fd_cv.h \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index e7e9e04979..212e1d53dd 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -1176,11 +1176,13 @@ src/core/lib/iomgr/iocp_windows.cc \ src/core/lib/iomgr/iocp_windows.h \ src/core/lib/iomgr/iomgr.cc \ src/core/lib/iomgr/iomgr.h \ +src/core/lib/iomgr/iomgr_custom.cc \ +src/core/lib/iomgr/iomgr_custom.h \ +src/core/lib/iomgr/iomgr_internal.cc \ src/core/lib/iomgr/iomgr_internal.h \ src/core/lib/iomgr/iomgr_posix.cc \ src/core/lib/iomgr/iomgr_posix.h \ src/core/lib/iomgr/iomgr_uv.cc \ -src/core/lib/iomgr/iomgr_uv.h \ src/core/lib/iomgr/iomgr_windows.cc \ src/core/lib/iomgr/is_epollexclusive_available.cc \ src/core/lib/iomgr/is_epollexclusive_available.h \ @@ -1193,23 +1195,30 @@ src/core/lib/iomgr/network_status_tracker.cc \ src/core/lib/iomgr/network_status_tracker.h \ src/core/lib/iomgr/polling_entity.cc \ src/core/lib/iomgr/polling_entity.h \ +src/core/lib/iomgr/pollset.cc \ src/core/lib/iomgr/pollset.h \ +src/core/lib/iomgr/pollset_custom.cc \ +src/core/lib/iomgr/pollset_custom.h \ +src/core/lib/iomgr/pollset_set.cc \ src/core/lib/iomgr/pollset_set.h \ -src/core/lib/iomgr/pollset_set_uv.cc \ +src/core/lib/iomgr/pollset_set_custom.cc \ +src/core/lib/iomgr/pollset_set_custom.h \ src/core/lib/iomgr/pollset_set_windows.cc \ src/core/lib/iomgr/pollset_set_windows.h \ src/core/lib/iomgr/pollset_uv.cc \ -src/core/lib/iomgr/pollset_uv.h \ src/core/lib/iomgr/pollset_windows.cc \ src/core/lib/iomgr/pollset_windows.h \ src/core/lib/iomgr/port.h \ +src/core/lib/iomgr/resolve_address.cc \ src/core/lib/iomgr/resolve_address.h \ +src/core/lib/iomgr/resolve_address_custom.cc \ +src/core/lib/iomgr/resolve_address_custom.h \ src/core/lib/iomgr/resolve_address_posix.cc \ -src/core/lib/iomgr/resolve_address_uv.cc \ src/core/lib/iomgr/resolve_address_windows.cc \ src/core/lib/iomgr/resource_quota.cc \ src/core/lib/iomgr/resource_quota.h \ src/core/lib/iomgr/sockaddr.h \ +src/core/lib/iomgr/sockaddr_custom.h \ src/core/lib/iomgr/sockaddr_posix.h \ src/core/lib/iomgr/sockaddr_utils.cc \ src/core/lib/iomgr/sockaddr_utils.h \ @@ -1228,36 +1237,40 @@ src/core/lib/iomgr/socket_utils_windows.cc \ src/core/lib/iomgr/socket_windows.cc \ src/core/lib/iomgr/socket_windows.h \ src/core/lib/iomgr/sys_epoll_wrapper.h \ +src/core/lib/iomgr/tcp_client.cc \ src/core/lib/iomgr/tcp_client.h \ +src/core/lib/iomgr/tcp_client_custom.cc \ src/core/lib/iomgr/tcp_client_posix.cc \ src/core/lib/iomgr/tcp_client_posix.h \ -src/core/lib/iomgr/tcp_client_uv.cc \ src/core/lib/iomgr/tcp_client_windows.cc \ +src/core/lib/iomgr/tcp_custom.cc \ +src/core/lib/iomgr/tcp_custom.h \ src/core/lib/iomgr/tcp_posix.cc \ src/core/lib/iomgr/tcp_posix.h \ +src/core/lib/iomgr/tcp_server.cc \ src/core/lib/iomgr/tcp_server.h \ +src/core/lib/iomgr/tcp_server_custom.cc \ src/core/lib/iomgr/tcp_server_posix.cc \ src/core/lib/iomgr/tcp_server_utils_posix.h \ src/core/lib/iomgr/tcp_server_utils_posix_common.cc \ src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc \ src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc \ -src/core/lib/iomgr/tcp_server_uv.cc \ src/core/lib/iomgr/tcp_server_windows.cc \ src/core/lib/iomgr/tcp_uv.cc \ -src/core/lib/iomgr/tcp_uv.h \ src/core/lib/iomgr/tcp_windows.cc \ src/core/lib/iomgr/tcp_windows.h \ src/core/lib/iomgr/time_averaged_stats.cc \ src/core/lib/iomgr/time_averaged_stats.h \ +src/core/lib/iomgr/timer.cc \ src/core/lib/iomgr/timer.h \ +src/core/lib/iomgr/timer_custom.cc \ +src/core/lib/iomgr/timer_custom.h \ src/core/lib/iomgr/timer_generic.cc \ -src/core/lib/iomgr/timer_generic.h \ src/core/lib/iomgr/timer_heap.cc \ src/core/lib/iomgr/timer_heap.h \ src/core/lib/iomgr/timer_manager.cc \ src/core/lib/iomgr/timer_manager.h \ src/core/lib/iomgr/timer_uv.cc \ -src/core/lib/iomgr/timer_uv.h \ src/core/lib/iomgr/udp_server.cc \ src/core/lib/iomgr/udp_server.h \ src/core/lib/iomgr/unix_sockets_posix.cc \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index fb1a4fe0f0..d754c5d6fc 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -9042,6 +9042,8 @@ "src/core/lib/iomgr/gethostname_sysconf.cc", "src/core/lib/iomgr/iocp_windows.cc", "src/core/lib/iomgr/iomgr.cc", + "src/core/lib/iomgr/iomgr_custom.cc", + "src/core/lib/iomgr/iomgr_internal.cc", "src/core/lib/iomgr/iomgr_posix.cc", "src/core/lib/iomgr/iomgr_uv.cc", "src/core/lib/iomgr/iomgr_windows.cc", @@ -9050,12 +9052,16 @@ "src/core/lib/iomgr/lockfree_event.cc", "src/core/lib/iomgr/network_status_tracker.cc", "src/core/lib/iomgr/polling_entity.cc", - "src/core/lib/iomgr/pollset_set_uv.cc", + "src/core/lib/iomgr/pollset.cc", + "src/core/lib/iomgr/pollset_custom.cc", + "src/core/lib/iomgr/pollset_set.cc", + "src/core/lib/iomgr/pollset_set_custom.cc", "src/core/lib/iomgr/pollset_set_windows.cc", "src/core/lib/iomgr/pollset_uv.cc", "src/core/lib/iomgr/pollset_windows.cc", + "src/core/lib/iomgr/resolve_address.cc", + "src/core/lib/iomgr/resolve_address_custom.cc", "src/core/lib/iomgr/resolve_address_posix.cc", - "src/core/lib/iomgr/resolve_address_uv.cc", "src/core/lib/iomgr/resolve_address_windows.cc", "src/core/lib/iomgr/resource_quota.cc", "src/core/lib/iomgr/sockaddr_utils.cc", @@ -9067,19 +9073,24 @@ "src/core/lib/iomgr/socket_utils_uv.cc", "src/core/lib/iomgr/socket_utils_windows.cc", "src/core/lib/iomgr/socket_windows.cc", + "src/core/lib/iomgr/tcp_client.cc", + "src/core/lib/iomgr/tcp_client_custom.cc", "src/core/lib/iomgr/tcp_client_posix.cc", - "src/core/lib/iomgr/tcp_client_uv.cc", "src/core/lib/iomgr/tcp_client_windows.cc", + "src/core/lib/iomgr/tcp_custom.cc", "src/core/lib/iomgr/tcp_posix.cc", + "src/core/lib/iomgr/tcp_server.cc", + "src/core/lib/iomgr/tcp_server_custom.cc", "src/core/lib/iomgr/tcp_server_posix.cc", "src/core/lib/iomgr/tcp_server_utils_posix_common.cc", "src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc", "src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc", - "src/core/lib/iomgr/tcp_server_uv.cc", "src/core/lib/iomgr/tcp_server_windows.cc", "src/core/lib/iomgr/tcp_uv.cc", "src/core/lib/iomgr/tcp_windows.cc", "src/core/lib/iomgr/time_averaged_stats.cc", + "src/core/lib/iomgr/timer.cc", + "src/core/lib/iomgr/timer_custom.cc", "src/core/lib/iomgr/timer_generic.cc", "src/core/lib/iomgr/timer_heap.cc", "src/core/lib/iomgr/timer_manager.cc", @@ -9201,9 +9212,9 @@ "src/core/lib/iomgr/gethostname.h", "src/core/lib/iomgr/iocp_windows.h", "src/core/lib/iomgr/iomgr.h", + "src/core/lib/iomgr/iomgr_custom.h", "src/core/lib/iomgr/iomgr_internal.h", "src/core/lib/iomgr/iomgr_posix.h", - "src/core/lib/iomgr/iomgr_uv.h", "src/core/lib/iomgr/is_epollexclusive_available.h", "src/core/lib/iomgr/load_file.h", "src/core/lib/iomgr/lockfree_event.h", @@ -9211,14 +9222,17 @@ "src/core/lib/iomgr/network_status_tracker.h", "src/core/lib/iomgr/polling_entity.h", "src/core/lib/iomgr/pollset.h", + "src/core/lib/iomgr/pollset_custom.h", "src/core/lib/iomgr/pollset_set.h", + "src/core/lib/iomgr/pollset_set_custom.h", "src/core/lib/iomgr/pollset_set_windows.h", - "src/core/lib/iomgr/pollset_uv.h", "src/core/lib/iomgr/pollset_windows.h", "src/core/lib/iomgr/port.h", "src/core/lib/iomgr/resolve_address.h", + "src/core/lib/iomgr/resolve_address_custom.h", "src/core/lib/iomgr/resource_quota.h", "src/core/lib/iomgr/sockaddr.h", + "src/core/lib/iomgr/sockaddr_custom.h", "src/core/lib/iomgr/sockaddr_posix.h", "src/core/lib/iomgr/sockaddr_utils.h", "src/core/lib/iomgr/sockaddr_windows.h", @@ -9230,17 +9244,16 @@ "src/core/lib/iomgr/sys_epoll_wrapper.h", "src/core/lib/iomgr/tcp_client.h", "src/core/lib/iomgr/tcp_client_posix.h", + "src/core/lib/iomgr/tcp_custom.h", "src/core/lib/iomgr/tcp_posix.h", "src/core/lib/iomgr/tcp_server.h", "src/core/lib/iomgr/tcp_server_utils_posix.h", - "src/core/lib/iomgr/tcp_uv.h", "src/core/lib/iomgr/tcp_windows.h", "src/core/lib/iomgr/time_averaged_stats.h", "src/core/lib/iomgr/timer.h", - "src/core/lib/iomgr/timer_generic.h", + "src/core/lib/iomgr/timer_custom.h", "src/core/lib/iomgr/timer_heap.h", "src/core/lib/iomgr/timer_manager.h", - "src/core/lib/iomgr/timer_uv.h", "src/core/lib/iomgr/udp_server.h", "src/core/lib/iomgr/unix_sockets_posix.h", "src/core/lib/iomgr/wakeup_fd_cv.h", @@ -9345,9 +9358,9 @@ "src/core/lib/iomgr/gethostname.h", "src/core/lib/iomgr/iocp_windows.h", "src/core/lib/iomgr/iomgr.h", + "src/core/lib/iomgr/iomgr_custom.h", "src/core/lib/iomgr/iomgr_internal.h", "src/core/lib/iomgr/iomgr_posix.h", - "src/core/lib/iomgr/iomgr_uv.h", "src/core/lib/iomgr/is_epollexclusive_available.h", "src/core/lib/iomgr/load_file.h", "src/core/lib/iomgr/lockfree_event.h", @@ -9355,14 +9368,17 @@ "src/core/lib/iomgr/network_status_tracker.h", "src/core/lib/iomgr/polling_entity.h", "src/core/lib/iomgr/pollset.h", + "src/core/lib/iomgr/pollset_custom.h", "src/core/lib/iomgr/pollset_set.h", + "src/core/lib/iomgr/pollset_set_custom.h", "src/core/lib/iomgr/pollset_set_windows.h", - "src/core/lib/iomgr/pollset_uv.h", "src/core/lib/iomgr/pollset_windows.h", "src/core/lib/iomgr/port.h", "src/core/lib/iomgr/resolve_address.h", + "src/core/lib/iomgr/resolve_address_custom.h", "src/core/lib/iomgr/resource_quota.h", "src/core/lib/iomgr/sockaddr.h", + "src/core/lib/iomgr/sockaddr_custom.h", "src/core/lib/iomgr/sockaddr_posix.h", "src/core/lib/iomgr/sockaddr_utils.h", "src/core/lib/iomgr/sockaddr_windows.h", @@ -9374,17 +9390,16 @@ "src/core/lib/iomgr/sys_epoll_wrapper.h", "src/core/lib/iomgr/tcp_client.h", "src/core/lib/iomgr/tcp_client_posix.h", + "src/core/lib/iomgr/tcp_custom.h", "src/core/lib/iomgr/tcp_posix.h", "src/core/lib/iomgr/tcp_server.h", "src/core/lib/iomgr/tcp_server_utils_posix.h", - "src/core/lib/iomgr/tcp_uv.h", "src/core/lib/iomgr/tcp_windows.h", "src/core/lib/iomgr/time_averaged_stats.h", "src/core/lib/iomgr/timer.h", - "src/core/lib/iomgr/timer_generic.h", + "src/core/lib/iomgr/timer_custom.h", "src/core/lib/iomgr/timer_heap.h", "src/core/lib/iomgr/timer_manager.h", - "src/core/lib/iomgr/timer_uv.h", "src/core/lib/iomgr/udp_server.h", "src/core/lib/iomgr/unix_sockets_posix.h", "src/core/lib/iomgr/wakeup_fd_cv.h", diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index b751bf9714..85c7f5c4dc 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -281,7 +281,7 @@ class CLanguage(object): self._docker_distro, self._make_options = self._compiler_options( self.args.use_docker, self.args.compiler) if args.iomgr_platform == "uv": - cflags = '-DGRPC_UV -DGRPC_UV_THREAD_CHECK' + cflags = '-DGRPC_UV -DGRPC_CUSTOM_IOMGR_THREAD_CHECK ' try: cflags += subprocess.check_output( ['pkg-config', '--cflags', 'libuv']).strip() + ' ' diff --git a/vsprojects/vcxproj/grpc++/grpc++.vcxproj b/vsprojects/vcxproj/grpc++/grpc++.vcxproj new file mode 100644 index 0000000000..8f357d35e9 --- /dev/null +++ b/vsprojects/vcxproj/grpc++/grpc++.vcxproj @@ -0,0 +1,646 @@ + + + + + Debug-DLL + Win32 + + + Debug-DLL + x64 + + + Release-DLL + Win32 + + + Release-DLL + x64 + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {C187A093-A0FE-489D-A40A-6E33DE0F9FEB} + true + $(SolutionDir)IntDir\$(MSBuildProjectName)\ + + + + v100 + + + v110 + + + v120 + + + v140 + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + + + + + + + + + + grpc++ + + + grpc++ + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + true + None + false + + + Windows + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + true + None + false + + + Windows + true + false + true + true + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + true + None + false + + + Windows + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + true + None + false + + + Windows + true + false + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {29D16885-7228-4C31-81ED-5F9187C7F2A9} + + + {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + diff --git a/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters b/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters new file mode 100644 index 0000000000..c5c1eba593 --- /dev/null +++ b/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters @@ -0,0 +1,1096 @@ + + + + + src\cpp\client + + + src\cpp\client + + + src\cpp\common + + + src\cpp\common + + + src\cpp\common + + + src\cpp\common + + + src\cpp\server + + + src\cpp\server + + + src\cpp\client + + + src\cpp\client + + + src\cpp\client + + + src\cpp\client + + + src\cpp\client + + + src\cpp\client + + + src\cpp\client + + + src\cpp\common + + + src\cpp\common + + + src\cpp\common + + + src\cpp\common + + + src\cpp\common + + + src\cpp\common + + + src\cpp\common + + + src\cpp\server + + + src\cpp\server + + + src\cpp\server + + + src\cpp\server + + + src\cpp\server\health + + + src\cpp\server\health + + + src\cpp\server\health + + + src\cpp\server\health + + + src\cpp\server + + + src\cpp\server + + + src\cpp\server + + + src\cpp\server + + + src\cpp\server + + + src\cpp\thread_manager + + + src\cpp\util + + + src\cpp\util + + + src\cpp\util + + + src\cpp\util + + + src\cpp\util + + + src\cpp\codegen + + + + + include\grpc++ + + + include\grpc++ + + + include\grpc++ + + + include\grpc++ + + + include\grpc++ + + + include\grpc++ + + + include\grpc++\ext + + + include\grpc++\generic + + + include\grpc++\generic + + + include\grpc++ + + + include\grpc++ + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl\codegen + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++ + + + include\grpc++\security + + + include\grpc++\security + + + include\grpc++\security + + + include\grpc++\security + + + include\grpc++ + + + include\grpc++ + + + include\grpc++ + + + include\grpc++ + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc\support + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen\security + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + + + include\grpc++\impl\codegen + + + src\cpp\client + + + src\cpp\common + + + src\cpp\server + + + src\cpp\client + + + src\cpp\common + + + src\cpp\server + + + src\cpp\server\health + + + src\cpp\server\health + + + src\cpp\server + + + src\cpp\thread_manager + + + src\core\lib\profiling + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\compression + + + src\core\lib\compression + + + src\core\lib\compression + + + src\core\lib\http + + + src\core\lib\http + + + src\core\lib\http + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\json + + + src\core\lib\json + + + src\core\lib\json + + + src\core\lib\json + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\debug + + + src\core\ext\transport\inproc + + + third_party\nanopb + + + third_party\nanopb + + + third_party\nanopb + + + third_party\nanopb + + + + + + {82445414-24cd-8198-1fe1-4267c3f3df00} + + + {16946104-53ac-ac76-68b9-f9ec77ea6fae} + + + {784a0281-f547-aeb0-9f55-b26b7de9c769} + + + {25501d8e-5fae-2fe4-14a6-d69a07acefdd} + + + {51dae921-3aa2-1976-2ee4-c5615de1af54} + + + {0da8cd95-314f-da1b-5ce7-7791a5be1f1a} + + + {a3e7f28b-a7c7-7364-d402-edb1bfa414a4} + + + {20cbcf00-994a-300a-5184-bda96c6f45e4} + + + {a80eb32b-1be9-1187-5f40-30d92accecc8} + + + {a5c10dae-f715-2a30-1066-d22f8bc94cb2} + + + {48c3b0ae-c00f-fa20-6965-b73da65d71cb} + + + {dc8bfccd-341f-26f0-8ee4-47dde62a6dd1} + + + {5ec10a44-9a09-9220-cf3b-b18ce6e4f70f} + + + {328ff211-2886-406e-56f9-18ba1686f363} + + + {d02f1155-7e7e-3736-3c69-dc9146dc523d} + + + {96d09c4a-59f9-3486-6c2f-cbf695b285d8} + + + {202b1172-189f-afc4-f16c-4ca12677b480} + + + {635a93a8-e23a-a664-c9cb-0963736dd9ce} + + + {80567a8f-622f-a3ce-c12d-aebb63984b07} + + + {e769265c-8abd-cd64-2cc2-a52da484fe7b} + + + {701b2d46-11c6-3640-b189-45287f00bee3} + + + {ada68fd5-8e51-98cb-71a7-baf7989d8ffa} + + + {e770844e-61d4-555e-59be-81288e21a35f} + + + {04dfa1c8-7ffe-4f06-4a7c-37441dc75764} + + + {a5d5bddf-6f19-b655-a03a-f30ff5c253a5} + + + {836e78ab-aaae-9dce-dd1e-06f03c436a13} + + + {afe126ba-52c9-1daa-d174-8ee8aade08c2} + + + {83b45914-6f97-b4ad-f2d0-cc56a10ea1bb} + + + {fb2276d7-5a11-f1d9-82c3-e7c7f1155523} + + + {4bd7971a-68f7-0d5a-f502-6dea3099caaa} + + + {2420a905-e4f1-a5aa-a364-6a112878a39e} + + + {7febf32a-d7a6-76fa-9e17-f189f591c062} + + + {3c3e27f4-d3d9-3c42-5204-08b5e839f2de} + + + {2336e396-7e0b-8bf9-3b09-adc6ad1f0e5b} + + + {321b0980-74ad-e8ca-f23b-deffa5d6bb8f} + + + {5bc9ef4e-78c1-159e-4e4e-30ddfce3e140} + + + {23f9df56-8604-52a0-e6a2-f01b8e68d0e7} + + + {f842537a-2bf1-1ec3-b495-7d62c64a1c06} + + + {0cfc99f5-c633-356e-6810-754c93b15658} + + + {abc9bbec-57f7-141f-8616-e2d3aa8b2e6d} + + + + diff --git a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj new file mode 100644 index 0000000000..3d8bf82b6a --- /dev/null +++ b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj @@ -0,0 +1,630 @@ + + + + + Debug-DLL + Win32 + + + Debug-DLL + x64 + + + Release-DLL + Win32 + + + Release-DLL + x64 + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {6EE56155-DF7C-4F6E-BFC4-F6F776BEB211} + true + $(SolutionDir)IntDir\$(MSBuildProjectName)\ + + + + v100 + + + v110 + + + v120 + + + v140 + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + + + + + + + + + + grpc++_unsecure + + + grpc++_unsecure + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + true + None + false + + + Windows + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + true + None + false + + + Windows + true + false + true + true + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + true + None + false + + + Windows + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + true + None + false + + + Windows + true + false + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} + + + {46CEDFFF-9692-456A-AA24-38B5D6BCF4C5} + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + diff --git a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters new file mode 100644 index 0000000000..2c4230f4fe --- /dev/null +++ b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters @@ -0,0 +1,1063 @@ + + + + + src\cpp\client + + + src\cpp\common + + + src\cpp\server + + + src\cpp\client + + + src\cpp\client + + + src\cpp\client + + + src\cpp\client + + + src\cpp\client + + + src\cpp\client + + + src\cpp\client + + + src\cpp\common + + + src\cpp\common + + + src\cpp\common + + + src\cpp\common + + + src\cpp\common + + + src\cpp\common + + + src\cpp\common + + + src\cpp\server + + + src\cpp\server + + + src\cpp\server + + + src\cpp\server + + + src\cpp\server\health + + + src\cpp\server\health + + + src\cpp\server\health + + + src\cpp\server\health + + + src\cpp\server + + + src\cpp\server + + + src\cpp\server + + + src\cpp\server + + + src\cpp\server + + + src\cpp\thread_manager + + + src\cpp\util + + + src\cpp\util + + + src\cpp\util + + + src\cpp\util + + + src\cpp\util + + + src\cpp\codegen + + + + + include\grpc++ + + + include\grpc++ + + + include\grpc++ + + + include\grpc++ + + + include\grpc++ + + + include\grpc++ + + + include\grpc++\ext + + + include\grpc++\generic + + + include\grpc++\generic + + + include\grpc++ + + + include\grpc++ + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl\codegen + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++ + + + include\grpc++\security + + + include\grpc++\security + + + include\grpc++\security + + + include\grpc++\security + + + include\grpc++ + + + include\grpc++ + + + include\grpc++ + + + include\grpc++ + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc\support + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen\security + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + + + src\cpp\client + + + src\cpp\common + + + src\cpp\server + + + src\cpp\server\health + + + src\cpp\server\health + + + src\cpp\server + + + src\cpp\thread_manager + + + src\core\lib\profiling + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\compression + + + src\core\lib\compression + + + src\core\lib\compression + + + src\core\lib\http + + + src\core\lib\http + + + src\core\lib\http + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\json + + + src\core\lib\json + + + src\core\lib\json + + + src\core\lib\json + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\debug + + + src\core\ext\transport\inproc + + + third_party\nanopb + + + third_party\nanopb + + + third_party\nanopb + + + third_party\nanopb + + + + + + {5c4eb19f-d511-e8fd-e1d6-c377cdc7d3b1} + + + {f3dd91a8-058b-becf-9e41-eb42c7bc6e55} + + + {eceb50c0-bb49-3812-b6bd-b0af6df81da7} + + + {e6643be2-2b2f-953d-ab14-27d89c835c8a} + + + {83717d3c-57d9-2bfa-ed9c-2b08f86da12b} + + + {dadc0002-f2ac-451b-a9b8-33b8de10b5fc} + + + {ccc364e2-3f28-8bfc-c26e-800dd6f9a9af} + + + {87cae06e-f40c-8fb6-73d6-26c7482ed9da} + + + {64bf60ff-9192-bb59-dcc8-8a0021e1d016} + + + {0ebf8008-80b9-d6da-e1dc-854bf1ec2195} + + + {c1049250-64f6-f900-d2e5-1718e148f1f0} + + + {adf6b8e3-4a4b-cb35-bb3d-568af97b58d1} + + + {9d6d36f2-26e7-a66b-c19d-a958b80878d6} + + + {cce6a85d-1111-3834-6825-31e170d93cff} + + + {595f2ea0-aafb-87e5-c938-db3ff0b0c69a} + + + {52eca76b-9502-3d96-9064-6415226a860f} + + + {8e70201f-3b54-d3cb-8b30-ebe0d96a9b2a} + + + {ecf09c42-c470-1883-35d7-442453ea8370} + + + {cf8fd5d8-ff54-331d-2d20-36d6cae0e14b} + + + {7e0225af-000b-4873-1c16-caffffbfd084} + + + {0bbdbf56-83ad-bb4b-c4e2-a6d38c342179} + + + {3875f7d7-ff11-c91d-0f98-810260cb554b} + + + {4bd405b9-af65-f0a6-d67a-433f75900668} + + + {f4b146e4-8fba-83a6-1cc1-1262ebb785e8} + + + {b83c8e70-e491-f6f9-a08c-85f632bb61d2} + + + {c3b582f8-079a-5936-7694-54cd75a7e61e} + + + {0d6d88e2-8549-5118-8b78-06e8283dadcb} + + + {a5139298-498a-41d4-59fd-c38d8f0380c1} + + + {1d59dcef-3358-d0ab-fa42-64da74065785} + + + {ba865739-5dd9-6731-6772-48c25d45134f} + + + {1e5fd68c-bd87-e803-42b0-75a7fa19b91d} + + + {ff72923a-6499-8d2a-e0fb-6d574b85d77e} + + + {18e9c249-37f0-7f2c-f026-502d48ed8c92} + + + {ed8e4daa-825f-fbe5-2a45-846ad9165d3d} + + + {8a54a279-d14b-4237-0df3-1ffe1ef5a7af} + + + {a003cb5c-7249-106c-8ee5-de5e11a6692c} + + + {e5b55f25-d99f-b8e5-9981-7da7fa7ba628} + + + {fb5d9a64-20ca-5119-ed38-04a3cf94923d} + + + {e911fd76-1313-5d02-3983-cdd0bafe1c6a} + + + {1ff41e28-caf4-c4b9-0170-53d36c7dac29} + + + + diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj b/vsprojects/vcxproj/grpc/grpc.vcxproj index fbb9fde753..73cb0c243a 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj @@ -334,9 +334,9 @@ + - @@ -362,6 +362,7 @@ + @@ -369,10 +370,9 @@ - + - @@ -595,9 +595,11 @@ - + + + - + @@ -611,7 +613,13 @@ - + + + + + + + @@ -619,9 +627,11 @@ - + - + + + @@ -645,14 +655,22 @@ - + - + + + + + + + + + @@ -661,8 +679,6 @@ - - @@ -671,6 +687,10 @@ + + + + @@ -885,6 +905,8 @@ + + diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters index 5332066df6..043671cd14 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters @@ -106,10 +106,13 @@ src\core\lib\iomgr - + + src\core\lib\iomgr + + src\core\lib\iomgr - + src\core\lib\iomgr @@ -130,7 +133,16 @@ src\core\lib\iomgr - + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + src\core\lib\iomgr @@ -142,10 +154,13 @@ src\core\lib\iomgr - + src\core\lib\iomgr - + + src\core\lib\iomgr + + src\core\lib\iomgr @@ -181,18 +196,30 @@ src\core\lib\iomgr - + src\core\lib\iomgr - + + src\core\lib\iomgr + + src\core\lib\iomgr src\core\lib\iomgr + + src\core\lib\iomgr + src\core\lib\iomgr + + src\core\lib\iomgr + + + src\core\lib\iomgr + src\core\lib\iomgr @@ -205,9 +232,6 @@ src\core\lib\iomgr - - src\core\lib\iomgr - src\core\lib\iomgr @@ -220,6 +244,12 @@ src\core\lib\iomgr + + src\core\lib\iomgr + + + src\core\lib\iomgr + src\core\lib\iomgr @@ -541,6 +571,9 @@ src\core\lib\surface + + src\python\grpcio\grpc\_cython + src\core\tsi @@ -965,13 +998,13 @@ src\core\lib\iomgr - + src\core\lib\iomgr - + src\core\lib\iomgr - + src\core\lib\iomgr @@ -1049,6 +1082,9 @@ src\core\lib\iomgr + + src\core\lib\iomgr + src\core\lib\iomgr @@ -1070,7 +1106,7 @@ src\core\lib\iomgr - + src\core\lib\iomgr @@ -1079,9 +1115,6 @@ src\core\lib\iomgr - - src\core\lib\iomgr - src\core\lib\iomgr @@ -1748,6 +1781,18 @@ {0b0f9ab1-efa4-7f03-e446-6fb9b5227e84} + + {50d054e3-a413-b871-9049-e8612ef56281} + + + {92bc7bec-9183-0f2b-47d9-31f68a980f1e} + + + {a75d942e-8d7a-306e-372f-0c6260f439d4} + + + {89423fb6-ab96-95e8-d197-239e91b777ca} + {aaab30a4-2a15-732e-c141-3fbc0f0f5a7a} diff --git a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj index 3fd0fb5f9f..cd7bbe2081 100644 --- a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj +++ b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj @@ -420,9 +420,11 @@ - + + + - + @@ -436,7 +438,13 @@ - + + + + + + + @@ -444,9 +452,11 @@ - + - + + + @@ -470,14 +480,22 @@ - + + + - + + + + + + + @@ -486,8 +504,6 @@ - - @@ -496,6 +512,10 @@ + + + + diff --git a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters index d51623834f..6fd8b127e1 100644 --- a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters @@ -163,10 +163,13 @@ src\core\lib\iomgr - + + src\core\lib\iomgr + + src\core\lib\iomgr - + src\core\lib\iomgr @@ -187,7 +190,16 @@ src\core\lib\iomgr - + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + src\core\lib\iomgr @@ -199,10 +211,13 @@ src\core\lib\iomgr - + src\core\lib\iomgr - + + src\core\lib\iomgr + + src\core\lib\iomgr @@ -238,18 +253,30 @@ src\core\lib\iomgr - + src\core\lib\iomgr - + + src\core\lib\iomgr + + src\core\lib\iomgr src\core\lib\iomgr + + src\core\lib\iomgr + src\core\lib\iomgr + + src\core\lib\iomgr + + + src\core\lib\iomgr + src\core\lib\iomgr @@ -262,9 +289,6 @@ src\core\lib\iomgr - - src\core\lib\iomgr - src\core\lib\iomgr @@ -277,6 +301,12 @@ src\core\lib\iomgr + + src\core\lib\iomgr + + + src\core\lib\iomgr + src\core\lib\iomgr diff --git a/vsprojects/vcxproj/grpc_test_util_unsecure/grpc_test_util_unsecure.vcxproj b/vsprojects/vcxproj/grpc_test_util_unsecure/grpc_test_util_unsecure.vcxproj new file mode 100644 index 0000000000..972828fa31 --- /dev/null +++ b/vsprojects/vcxproj/grpc_test_util_unsecure/grpc_test_util_unsecure.vcxproj @@ -0,0 +1,649 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {0A7E7F92-FDEA-40F1-A9EC-3BA484F98BBF} + true + $(SolutionDir)IntDir\$(MSBuildProjectName)\ + + + + v100 + + + v110 + + + v120 + + + v140 + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + + + + + + + + + + grpc_test_util_unsecure + + + grpc_test_util_unsecure + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + true + None + false + + + Windows + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + true + None + false + + + Windows + true + false + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} + + + {EAB0A629-17A9-44DB-B5FF-E91A721FE037} + + + {46CEDFFF-9692-456A-AA24-38B5D6BCF4C5} + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + diff --git a/vsprojects/vcxproj/grpc_test_util_unsecure/grpc_test_util_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc_test_util_unsecure/grpc_test_util_unsecure.vcxproj.filters new file mode 100644 index 0000000000..b92079c7a0 --- /dev/null +++ b/vsprojects/vcxproj/grpc_test_util_unsecure/grpc_test_util_unsecure.vcxproj.filters @@ -0,0 +1,946 @@ + + + + + src\core\ext\filters\client_channel\resolver\fake + + + test\core\end2end + + + test\core\end2end\fixtures + + + test\core\end2end\fixtures + + + test\core\iomgr + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\compression + + + src\core\lib\compression + + + src\core\lib\compression + + + src\core\lib\http + + + src\core\lib\http + + + src\core\lib\http + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\json + + + src\core\lib\json + + + src\core\lib\json + + + src\core\lib\json + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\debug + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\deadline + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\alpn + + + src\core\ext\filters\http\client + + + src\core\ext\filters\http + + + src\core\ext\filters\http\message_compress + + + src\core\ext\filters\http\server + + + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + + + src\core\ext\filters\client_channel\resolver\fake + + + test\core\end2end + + + test\core\end2end\fixtures + + + test\core\end2end\fixtures + + + test\core\iomgr + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\deadline + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\alpn + + + src\core\ext\filters\http\client + + + src\core\ext\filters\http\message_compress + + + src\core\ext\filters\http\server + + + + + + {9793fab6-15ae-1f61-712d-c3d673654d72} + + + {c2447106-a6bf-6b88-9ad0-a42b7ac1573c} + + + {dba70812-267b-656c-9f8c-636338d3f5c0} + + + {b9e2ddac-f042-3042-ba4b-79ba4445e68c} + + + {65483377-42fd-137e-3847-00dfd4675db3} + + + {51a516dc-93e3-4dd5-d114-2d06f5df4ad7} + + + {a927155d-bcf6-0dd8-6d63-be48bcaf617f} + + + {df16e935-149b-79bf-ecb3-dc3a6b628082} + + + {0fb7c1f0-5e3a-d1df-4c9d-96a677a7f3ee} + + + {f47477d5-cb4e-e726-04dd-182151e81c71} + + + {2d280bd0-f4ee-d1f2-4d70-174147ac0dbc} + + + {6820a68f-2aa3-8b45-ddea-294656d531f6} + + + {b7df4d88-fa6b-6bd3-579e-b5f086ba6299} + + + {37d93a32-6a75-3b9e-35a4-c47f0a2d274a} + + + {a4bd6a23-c8e1-4e35-f9eb-6434a86f38f0} + + + {2dd536f5-341a-771f-4853-a95522e59224} + + + {fb32254e-a807-768a-3686-4e87f3bf1e8e} + + + {87c61e56-5090-5e1a-22af-02e3c8bf4a2a} + + + {e50ce1d1-6b17-dad2-9ef3-46f68d4bee1b} + + + {67007111-23fe-296f-1808-91f2b96a31aa} + + + {e3d002a7-9318-1ac5-4259-e177f58ccc9a} + + + {ac14fd16-a4af-6b22-4226-2d7dabf25409} + + + {24268e45-f6c3-6024-b49a-d01bb9c12d96} + + + {0be401bd-3e26-dead-fdf4-2ce27a1ac3a3} + + + {ac2f12e3-ac77-f0a7-d15d-92899e61ed25} + + + {9015222c-df04-298f-3f2c-d19babffc180} + + + {c3ff117a-aae9-dedd-2f5a-888f0383cbb8} + + + {588ffbfc-2f94-a99f-85b0-4c47ec9f8d13} + + + {732318c6-bb34-9a99-611b-9928db3d4e2a} + + + {2c0ca4a1-38df-329d-eeba-5c5b61dc81a5} + + + {037c7645-1698-cf2d-4163-525240323101} + + + {85f90d4a-70b4-1b30-8cef-4eadb2a3a04b} + + + {6387fc42-48d5-0134-a9d4-4477151722bf} + + + {204e56b4-4315-b3bd-4a71-7e1c3ebef3ce} + + + {53745d42-f5b1-2381-6b64-146f1234e513} + + + {31b30beb-baf0-3979-2a54-560a16814cf9} + + + + diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj index 08c1e78e8f..0575d47622 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj @@ -324,9 +324,9 @@ + - @@ -352,6 +352,7 @@ + @@ -359,10 +360,9 @@ - + - @@ -561,9 +561,11 @@ - + + + - + @@ -577,7 +579,13 @@ - + + + + + + + @@ -585,9 +593,11 @@ - + - + + + @@ -611,14 +621,22 @@ - + + + - + + + + + + + @@ -627,8 +645,6 @@ - - @@ -637,6 +653,10 @@ + + + + diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters index d9a5914e65..4c25674b1e 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters @@ -109,10 +109,13 @@ src\core\lib\iomgr - + src\core\lib\iomgr - + + src\core\lib\iomgr + + src\core\lib\iomgr @@ -133,7 +136,16 @@ src\core\lib\iomgr - + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + src\core\lib\iomgr @@ -145,10 +157,13 @@ src\core\lib\iomgr - + src\core\lib\iomgr - + + src\core\lib\iomgr + + src\core\lib\iomgr @@ -184,18 +199,30 @@ src\core\lib\iomgr - + src\core\lib\iomgr - + + src\core\lib\iomgr + + src\core\lib\iomgr src\core\lib\iomgr + + src\core\lib\iomgr + src\core\lib\iomgr + + src\core\lib\iomgr + + + src\core\lib\iomgr + src\core\lib\iomgr @@ -208,9 +235,6 @@ src\core\lib\iomgr - - src\core\lib\iomgr - src\core\lib\iomgr @@ -223,6 +247,12 @@ src\core\lib\iomgr + + src\core\lib\iomgr + + + src\core\lib\iomgr + src\core\lib\iomgr @@ -872,13 +902,13 @@ src\core\lib\iomgr - + src\core\lib\iomgr - + src\core\lib\iomgr - + src\core\lib\iomgr @@ -956,6 +986,9 @@ src\core\lib\iomgr + + src\core\lib\iomgr + src\core\lib\iomgr @@ -977,7 +1010,7 @@ src\core\lib\iomgr - + src\core\lib\iomgr @@ -986,9 +1019,6 @@ src\core\lib\iomgr - - src\core\lib\iomgr - src\core\lib\iomgr -- cgit v1.2.3 From aa843f2bfc83b588a645d5edc9300b0e1d353f93 Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Tue, 13 Mar 2018 08:36:16 -0700 Subject: Testing making the authority filter a plugin, for cronet --- BUILD | 16 +++++++++++++++ CMakeLists.txt | 8 ++------ build.yaml | 12 +++++++++-- config.m4 | 2 +- config.w32 | 2 +- gRPC-C++.podspec | 3 +-- gRPC-Core.podspec | 6 +++--- grpc.gemspec | 4 ++-- grpc.gyp | 6 ++---- package.xml | 4 ++-- src/core/lib/channel/client_authority_filter.cc | 18 +++++++++++++++++ src/core/lib/surface/init.cc | 7 ------- src/core/lib/surface/init_secure.cc | 4 ++-- src/core/plugin_registry/grpc_plugin_registry.cc | 4 ++++ .../grpc_unsecure_plugin_registry.cc | 4 ++++ src/python/grpcio/grpc_core_dependencies.py | 2 +- tools/doxygen/Doxyfile.c++.internal | 1 - tools/run_tests/generated/sources_and_headers.json | 23 +++++++++++++++++++--- 18 files changed, 89 insertions(+), 37 deletions(-) (limited to 'gRPC-C++.podspec') diff --git a/BUILD b/BUILD index 49f45f8218..75aebb2462 100644 --- a/BUILD +++ b/BUILD @@ -966,6 +966,7 @@ grpc_cc_library( # standard plugins "census", "grpc_deadline_filter", + "grpc_client_authority_filter", "grpc_lb_policy_pick_first", "grpc_lb_policy_round_robin", "grpc_server_load_reporting", @@ -1036,6 +1037,7 @@ grpc_cc_library( deps = [ "gpr_base", "grpc_base", + "grpc_client_authority_filter", "grpc_deadline_filter", "inlined_vector", "orphanable", @@ -1072,6 +1074,20 @@ grpc_cc_library( ], ) +grpc_cc_library( + name = "grpc_client_authority_filter", + srcs = [ + "src/core/lib/channel/client_authority_filter.cc", + ], + hdrs = [ + "src/core/lib/channel/client_authority_filter.h", + ], + language = "c++", + deps = [ + "grpc_base", + ], +) + grpc_cc_library( name = "grpc_message_size_filter", srcs = [ diff --git a/CMakeLists.txt b/CMakeLists.txt index d3e84c7751..1657f1ae7e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -855,7 +855,6 @@ add_library(grpc src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc - src/core/lib/channel/client_authority_filter.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc @@ -1133,6 +1132,7 @@ add_library(grpc src/core/ext/census/grpc_context.cc src/core/ext/filters/max_age/max_age_filter.cc src/core/ext/filters/message_size/message_size_filter.cc + src/core/lib/channel/client_authority_filter.cc src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc src/core/ext/filters/workarounds/workaround_utils.cc src/core/plugin_registry/grpc_plugin_registry.cc @@ -1231,7 +1231,6 @@ add_library(grpc_cronet src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc - src/core/lib/channel/client_authority_filter.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc @@ -1598,7 +1597,6 @@ add_library(grpc_test_util src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc - src/core/lib/channel/client_authority_filter.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc @@ -1888,7 +1886,6 @@ add_library(grpc_test_util_unsecure src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc - src/core/lib/channel/client_authority_filter.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc @@ -2158,7 +2155,6 @@ add_library(grpc_unsecure src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc - src/core/lib/channel/client_authority_filter.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc @@ -2371,6 +2367,7 @@ add_library(grpc_unsecure src/core/ext/census/grpc_context.cc src/core/ext/filters/max_age/max_age_filter.cc src/core/ext/filters/message_size/message_size_filter.cc + src/core/lib/channel/client_authority_filter.cc src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc src/core/ext/filters/workarounds/workaround_utils.cc src/core/plugin_registry/grpc_unsecure_plugin_registry.cc @@ -2962,7 +2959,6 @@ add_library(grpc++_cronet src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc - src/core/lib/channel/client_authority_filter.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc diff --git a/build.yaml b/build.yaml index eab2897706..20581ae00e 100644 --- a/build.yaml +++ b/build.yaml @@ -232,7 +232,6 @@ filegroups: - src/core/lib/channel/channel_args.cc - src/core/lib/channel/channel_stack.cc - src/core/lib/channel/channel_stack_builder.cc - - src/core/lib/channel/client_authority_filter.cc - src/core/lib/channel/connected_channel.cc - src/core/lib/channel/handshaker.cc - src/core/lib/channel/handshaker_factory.cc @@ -389,7 +388,6 @@ filegroups: - src/core/lib/channel/channel_args.h - src/core/lib/channel/channel_stack.h - src/core/lib/channel/channel_stack_builder.h - - src/core/lib/channel/client_authority_filter.h - src/core/lib/channel/connected_channel.h - src/core/lib/channel/context.h - src/core/lib/channel/handshaker.h @@ -517,6 +515,14 @@ filegroups: uses: - grpc_codegen - grpc_trace_headers +- name: grpc_client_authority_filter + headers: + - src/core/lib/channel/client_authority_filter.h + src: + - src/core/lib/channel/client_authority_filter.cc + plugin: grpc_client_authority_filter + uses: + - grpc_base - name: grpc_client_channel headers: - src/core/ext/filters/client_channel/backup_poller.h @@ -1354,6 +1360,7 @@ libs: - grpc_max_age_filter - grpc_message_size_filter - grpc_deadline_filter + - grpc_client_authority_filter - grpc_workaround_cronet_compression_filter - grpc_server_backward_compatibility generate_plugin_registry: true @@ -1456,6 +1463,7 @@ libs: - grpc_max_age_filter - grpc_message_size_filter - grpc_deadline_filter + - grpc_client_authority_filter - grpc_workaround_cronet_compression_filter - grpc_server_backward_compatibility generate_plugin_registry: true diff --git a/config.m4 b/config.m4 index 3b061e565e..9b48890d4c 100644 --- a/config.m4 +++ b/config.m4 @@ -84,7 +84,6 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ - src/core/lib/channel/client_authority_filter.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ @@ -362,6 +361,7 @@ if test "$PHP_GRPC" != "no"; then src/core/ext/census/grpc_context.cc \ src/core/ext/filters/max_age/max_age_filter.cc \ src/core/ext/filters/message_size/message_size_filter.cc \ + src/core/lib/channel/client_authority_filter.cc \ src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc \ src/core/ext/filters/workarounds/workaround_utils.cc \ src/core/plugin_registry/grpc_plugin_registry.cc \ diff --git a/config.w32 b/config.w32 index 1b89419c57..b6b417e3de 100644 --- a/config.w32 +++ b/config.w32 @@ -61,7 +61,6 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\channel\\channel_args.cc " + "src\\core\\lib\\channel\\channel_stack.cc " + "src\\core\\lib\\channel\\channel_stack_builder.cc " + - "src\\core\\lib\\channel\\client_authority_filter.cc " + "src\\core\\lib\\channel\\connected_channel.cc " + "src\\core\\lib\\channel\\handshaker.cc " + "src\\core\\lib\\channel\\handshaker_factory.cc " + @@ -339,6 +338,7 @@ if (PHP_GRPC != "no") { "src\\core\\ext\\census\\grpc_context.cc " + "src\\core\\ext\\filters\\max_age\\max_age_filter.cc " + "src\\core\\ext\\filters\\message_size\\message_size_filter.cc " + + "src\\core\\lib\\channel\\client_authority_filter.cc " + "src\\core\\ext\\filters\\workarounds\\workaround_cronet_compression_filter.cc " + "src\\core\\ext\\filters\\workarounds\\workaround_utils.cc " + "src\\core\\plugin_registry\\grpc_plugin_registry.cc " + diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 6334ac433d..5e8ae3f9a6 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -343,7 +343,6 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.h', 'src/core/lib/channel/channel_stack.h', 'src/core/lib/channel/channel_stack_builder.h', - 'src/core/lib/channel/client_authority_filter.h', 'src/core/lib/channel/connected_channel.h', 'src/core/lib/channel/context.h', 'src/core/lib/channel/handshaker.h', @@ -480,6 +479,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/load_reporting/server_load_reporting_plugin.h', 'src/core/ext/filters/max_age/max_age_filter.h', 'src/core/ext/filters/message_size/message_size_filter.h', + 'src/core/lib/channel/client_authority_filter.h', 'src/core/ext/filters/workarounds/workaround_cronet_compression_filter.h', 'src/core/ext/filters/workarounds/workaround_utils.h' @@ -523,7 +523,6 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.h', 'src/core/lib/channel/channel_stack.h', 'src/core/lib/channel/channel_stack_builder.h', - 'src/core/lib/channel/client_authority_filter.h', 'src/core/lib/channel/connected_channel.h', 'src/core/lib/channel/context.h', 'src/core/lib/channel/handshaker.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 5827b397ff..242bc49bd3 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -354,7 +354,6 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.h', 'src/core/lib/channel/channel_stack.h', 'src/core/lib/channel/channel_stack_builder.h', - 'src/core/lib/channel/client_authority_filter.h', 'src/core/lib/channel/connected_channel.h', 'src/core/lib/channel/context.h', 'src/core/lib/channel/handshaker.h', @@ -491,6 +490,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/load_reporting/server_load_reporting_plugin.h', 'src/core/ext/filters/max_age/max_age_filter.h', 'src/core/ext/filters/message_size/message_size_filter.h', + 'src/core/lib/channel/client_authority_filter.h', 'src/core/ext/filters/workarounds/workaround_cronet_compression_filter.h', 'src/core/ext/filters/workarounds/workaround_utils.h', 'src/core/lib/surface/init.cc', @@ -499,7 +499,6 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', - 'src/core/lib/channel/client_authority_filter.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', @@ -774,6 +773,7 @@ Pod::Spec.new do |s| 'src/core/ext/census/grpc_context.cc', 'src/core/ext/filters/max_age/max_age_filter.cc', 'src/core/ext/filters/message_size/message_size_filter.cc', + 'src/core/lib/channel/client_authority_filter.cc', 'src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc', 'src/core/ext/filters/workarounds/workaround_utils.cc', 'src/core/plugin_registry/grpc_plugin_registry.cc' @@ -910,7 +910,6 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.h', 'src/core/lib/channel/channel_stack.h', 'src/core/lib/channel/channel_stack_builder.h', - 'src/core/lib/channel/client_authority_filter.h', 'src/core/lib/channel/connected_channel.h', 'src/core/lib/channel/context.h', 'src/core/lib/channel/handshaker.h', @@ -1047,6 +1046,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/load_reporting/server_load_reporting_plugin.h', 'src/core/ext/filters/max_age/max_age_filter.h', 'src/core/ext/filters/message_size/message_size_filter.h', + 'src/core/lib/channel/client_authority_filter.h', 'src/core/ext/filters/workarounds/workaround_cronet_compression_filter.h', 'src/core/ext/filters/workarounds/workaround_utils.h' end diff --git a/grpc.gemspec b/grpc.gemspec index 06520c1f95..33ca745e69 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -284,7 +284,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/channel/channel_args.h ) s.files += %w( src/core/lib/channel/channel_stack.h ) s.files += %w( src/core/lib/channel/channel_stack_builder.h ) - s.files += %w( src/core/lib/channel/client_authority_filter.h ) s.files += %w( src/core/lib/channel/connected_channel.h ) s.files += %w( src/core/lib/channel/context.h ) s.files += %w( src/core/lib/channel/handshaker.h ) @@ -421,6 +420,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/load_reporting/server_load_reporting_plugin.h ) s.files += %w( src/core/ext/filters/max_age/max_age_filter.h ) s.files += %w( src/core/ext/filters/message_size/message_size_filter.h ) + s.files += %w( src/core/lib/channel/client_authority_filter.h ) s.files += %w( src/core/ext/filters/workarounds/workaround_cronet_compression_filter.h ) s.files += %w( src/core/ext/filters/workarounds/workaround_utils.h ) s.files += %w( src/core/lib/surface/init.cc ) @@ -429,7 +429,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/channel/channel_args.cc ) s.files += %w( src/core/lib/channel/channel_stack.cc ) s.files += %w( src/core/lib/channel/channel_stack_builder.cc ) - s.files += %w( src/core/lib/channel/client_authority_filter.cc ) s.files += %w( src/core/lib/channel/connected_channel.cc ) s.files += %w( src/core/lib/channel/handshaker.cc ) s.files += %w( src/core/lib/channel/handshaker_factory.cc ) @@ -707,6 +706,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/census/grpc_context.cc ) s.files += %w( src/core/ext/filters/max_age/max_age_filter.cc ) s.files += %w( src/core/ext/filters/message_size/message_size_filter.cc ) + s.files += %w( src/core/lib/channel/client_authority_filter.cc ) s.files += %w( src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc ) s.files += %w( src/core/ext/filters/workarounds/workaround_utils.cc ) s.files += %w( src/core/plugin_registry/grpc_plugin_registry.cc ) diff --git a/grpc.gyp b/grpc.gyp index a398e4f460..04421bad57 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -236,7 +236,6 @@ 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', - 'src/core/lib/channel/client_authority_filter.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', @@ -514,6 +513,7 @@ 'src/core/ext/census/grpc_context.cc', 'src/core/ext/filters/max_age/max_age_filter.cc', 'src/core/ext/filters/message_size/message_size_filter.cc', + 'src/core/lib/channel/client_authority_filter.cc', 'src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc', 'src/core/ext/filters/workarounds/workaround_utils.cc', 'src/core/plugin_registry/grpc_plugin_registry.cc', @@ -569,7 +569,6 @@ 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', - 'src/core/lib/channel/client_authority_filter.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', @@ -787,7 +786,6 @@ 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', - 'src/core/lib/channel/client_authority_filter.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', @@ -984,7 +982,6 @@ 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', - 'src/core/lib/channel/client_authority_filter.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', @@ -1197,6 +1194,7 @@ 'src/core/ext/census/grpc_context.cc', 'src/core/ext/filters/max_age/max_age_filter.cc', 'src/core/ext/filters/message_size/message_size_filter.cc', + 'src/core/lib/channel/client_authority_filter.cc', 'src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc', 'src/core/ext/filters/workarounds/workaround_utils.cc', 'src/core/plugin_registry/grpc_unsecure_plugin_registry.cc', diff --git a/package.xml b/package.xml index 0abcb89738..a8a3c4f356 100644 --- a/package.xml +++ b/package.xml @@ -291,7 +291,6 @@ - @@ -428,6 +427,7 @@ + @@ -436,7 +436,6 @@ - @@ -714,6 +713,7 @@ + diff --git a/src/core/lib/channel/client_authority_filter.cc b/src/core/lib/channel/client_authority_filter.cc index f684684be1..bf37f52e9c 100644 --- a/src/core/lib/channel/client_authority_filter.cc +++ b/src/core/lib/channel/client_authority_filter.cc @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -115,3 +116,20 @@ const grpc_channel_filter grpc_client_authority_filter = { destroy_channel_elem, grpc_channel_next_get_info, "authority"}; + +static bool add_client_authority_filter(grpc_channel_stack_builder* builder, + void* arg) { + return grpc_channel_stack_builder_prepend_filter( + builder, static_cast(arg), nullptr, nullptr); +} + +void grpc_client_authority_filter_init(void) { + grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, INT_MAX, + add_client_authority_filter, + (void*)&grpc_client_authority_filter); + grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, + add_client_authority_filter, + (void*)&grpc_client_authority_filter); +} + +void grpc_client_authority_filter_shutdown(void) {} diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc index 10c65ce09f..2d29c7d95f 100644 --- a/src/core/lib/surface/init.cc +++ b/src/core/lib/surface/init.cc @@ -84,13 +84,6 @@ static bool prepend_filter(grpc_channel_stack_builder* builder, void* arg) { } static void register_builtin_channel_init() { - grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, INT_MAX, - prepend_filter, - (void*)(&grpc_client_authority_filter)); - grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, - prepend_filter, - (void*)(&grpc_client_authority_filter)); - grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, grpc_add_connected_filter, nullptr); diff --git a/src/core/lib/surface/init_secure.cc b/src/core/lib/surface/init_secure.cc index 78e983e0cd..9700f43a55 100644 --- a/src/core/lib/surface/init_secure.cc +++ b/src/core/lib/surface/init_secure.cc @@ -67,9 +67,9 @@ static bool maybe_prepend_server_auth_filter( } void grpc_register_security_filters(void) { - grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, INT_MAX, + grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, INT_MAX - 1, maybe_prepend_client_auth_filter, nullptr); - grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, + grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX - 1, maybe_prepend_client_auth_filter, nullptr); grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX, maybe_prepend_server_auth_filter, nullptr); diff --git a/src/core/plugin_registry/grpc_plugin_registry.cc b/src/core/plugin_registry/grpc_plugin_registry.cc index 6f11e6bb5b..e371310fa1 100644 --- a/src/core/plugin_registry/grpc_plugin_registry.cc +++ b/src/core/plugin_registry/grpc_plugin_registry.cc @@ -52,6 +52,8 @@ void grpc_max_age_filter_init(void); void grpc_max_age_filter_shutdown(void); void grpc_message_size_filter_init(void); void grpc_message_size_filter_shutdown(void); +void grpc_client_authority_filter_init(void); +void grpc_client_authority_filter_shutdown(void); void grpc_workaround_cronet_compression_filter_init(void); void grpc_workaround_cronet_compression_filter_shutdown(void); @@ -88,6 +90,8 @@ void grpc_register_built_in_plugins(void) { grpc_max_age_filter_shutdown); grpc_register_plugin(grpc_message_size_filter_init, grpc_message_size_filter_shutdown); + grpc_register_plugin(grpc_client_authority_filter_init, + grpc_client_authority_filter_shutdown); grpc_register_plugin(grpc_workaround_cronet_compression_filter_init, grpc_workaround_cronet_compression_filter_shutdown); } diff --git a/src/core/plugin_registry/grpc_unsecure_plugin_registry.cc b/src/core/plugin_registry/grpc_unsecure_plugin_registry.cc index b08c5ce3ae..283db5b4f4 100644 --- a/src/core/plugin_registry/grpc_unsecure_plugin_registry.cc +++ b/src/core/plugin_registry/grpc_unsecure_plugin_registry.cc @@ -50,6 +50,8 @@ void grpc_max_age_filter_init(void); void grpc_max_age_filter_shutdown(void); void grpc_message_size_filter_init(void); void grpc_message_size_filter_shutdown(void); +void grpc_client_authority_filter_init(void); +void grpc_client_authority_filter_shutdown(void); void grpc_workaround_cronet_compression_filter_init(void); void grpc_workaround_cronet_compression_filter_shutdown(void); @@ -84,6 +86,8 @@ void grpc_register_built_in_plugins(void) { grpc_max_age_filter_shutdown); grpc_register_plugin(grpc_message_size_filter_init, grpc_message_size_filter_shutdown); + grpc_register_plugin(grpc_client_authority_filter_init, + grpc_client_authority_filter_shutdown); grpc_register_plugin(grpc_workaround_cronet_compression_filter_init, grpc_workaround_cronet_compression_filter_shutdown); } diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 7bd1adf8fe..bb426b070f 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -60,7 +60,6 @@ CORE_SOURCE_FILES = [ 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', - 'src/core/lib/channel/client_authority_filter.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', @@ -338,6 +337,7 @@ CORE_SOURCE_FILES = [ 'src/core/ext/census/grpc_context.cc', 'src/core/ext/filters/max_age/max_age_filter.cc', 'src/core/ext/filters/message_size/message_size_filter.cc', + 'src/core/lib/channel/client_authority_filter.cc', 'src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc', 'src/core/ext/filters/workarounds/workaround_utils.cc', 'src/core/plugin_registry/grpc_plugin_registry.cc', diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index f1fb7d29fc..ff5abc679d 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -1007,7 +1007,6 @@ src/core/lib/backoff/backoff.h \ src/core/lib/channel/channel_args.h \ src/core/lib/channel/channel_stack.h \ src/core/lib/channel/channel_stack_builder.h \ -src/core/lib/channel/client_authority_filter.h \ src/core/lib/channel/connected_channel.h \ src/core/lib/channel/context.h \ src/core/lib/channel/handshaker.h \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index fa34d963aa..07edd14b04 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -6610,6 +6610,7 @@ "census", "gpr", "grpc_base", + "grpc_client_authority_filter", "grpc_deadline_filter", "grpc_lb_policy_grpclb_secure", "grpc_lb_policy_pick_first", @@ -6717,6 +6718,7 @@ "census", "gpr", "grpc_base", + "grpc_client_authority_filter", "grpc_deadline_filter", "grpc_lb_policy_grpclb", "grpc_lb_policy_pick_first", @@ -8988,7 +8990,6 @@ "src/core/lib/channel/channel_args.cc", "src/core/lib/channel/channel_stack.cc", "src/core/lib/channel/channel_stack_builder.cc", - "src/core/lib/channel/client_authority_filter.cc", "src/core/lib/channel/connected_channel.cc", "src/core/lib/channel/handshaker.cc", "src/core/lib/channel/handshaker_factory.cc", @@ -9146,7 +9147,6 @@ "src/core/lib/channel/channel_args.h", "src/core/lib/channel/channel_stack.h", "src/core/lib/channel/channel_stack_builder.h", - "src/core/lib/channel/client_authority_filter.h", "src/core/lib/channel/connected_channel.h", "src/core/lib/channel/context.h", "src/core/lib/channel/handshaker.h", @@ -9291,7 +9291,6 @@ "src/core/lib/channel/channel_args.h", "src/core/lib/channel/channel_stack.h", "src/core/lib/channel/channel_stack_builder.h", - "src/core/lib/channel/client_authority_filter.h", "src/core/lib/channel/connected_channel.h", "src/core/lib/channel/context.h", "src/core/lib/channel/handshaker.h", @@ -9418,6 +9417,24 @@ "third_party": false, "type": "filegroup" }, + { + "deps": [ + "gpr", + "grpc_base" + ], + "headers": [ + "src/core/lib/channel/client_authority_filter.h" + ], + "is_filegroup": true, + "language": "c", + "name": "grpc_client_authority_filter", + "src": [ + "src/core/lib/channel/client_authority_filter.cc", + "src/core/lib/channel/client_authority_filter.h" + ], + "third_party": false, + "type": "filegroup" + }, { "deps": [ "gpr", -- cgit v1.2.3 From 961353ab6d1b48da74e307f805f45509c4a7de7f Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Thu, 15 Mar 2018 16:11:05 -0700 Subject: moved filter to ext --- BUILD | 6 +- CMakeLists.txt | 4 +- Makefile | 4 +- build.yaml | 4 +- config.m4 | 2 +- config.w32 | 2 +- gRPC-C++.podspec | 2 +- gRPC-Core.podspec | 6 +- grpc.gemspec | 4 +- grpc.gyp | 4 +- package.xml | 4 +- .../ext/filters/http/client_authority_filter.cc | 135 +++++++++++++++++++++ .../ext/filters/http/client_authority_filter.h | 34 ++++++ src/core/lib/channel/client_authority_filter.cc | 135 --------------------- src/core/lib/channel/client_authority_filter.h | 34 ------ src/core/lib/surface/init.cc | 1 - src/python/grpcio/grpc_core_dependencies.py | 2 +- tools/doxygen/Doxyfile.core.internal | 4 +- tools/run_tests/generated/sources_and_headers.json | 6 +- 19 files changed, 195 insertions(+), 198 deletions(-) create mode 100644 src/core/ext/filters/http/client_authority_filter.cc create mode 100644 src/core/ext/filters/http/client_authority_filter.h delete mode 100644 src/core/lib/channel/client_authority_filter.cc delete mode 100644 src/core/lib/channel/client_authority_filter.h (limited to 'gRPC-C++.podspec') diff --git a/BUILD b/BUILD index 75aebb2462..8a4349eb81 100644 --- a/BUILD +++ b/BUILD @@ -676,7 +676,6 @@ grpc_cc_library( "src/core/lib/channel/channel_args.cc", "src/core/lib/channel/channel_stack.cc", "src/core/lib/channel/channel_stack_builder.cc", - "src/core/lib/channel/client_authority_filter.cc", "src/core/lib/channel/connected_channel.cc", "src/core/lib/channel/handshaker.cc", "src/core/lib/channel/handshaker_factory.cc", @@ -812,7 +811,6 @@ grpc_cc_library( "src/core/lib/channel/channel_args.h", "src/core/lib/channel/channel_stack.h", "src/core/lib/channel/channel_stack_builder.h", - "src/core/lib/channel/client_authority_filter.h", "src/core/lib/channel/connected_channel.h", "src/core/lib/channel/context.h", "src/core/lib/channel/handshaker.h", @@ -1077,10 +1075,10 @@ grpc_cc_library( grpc_cc_library( name = "grpc_client_authority_filter", srcs = [ - "src/core/lib/channel/client_authority_filter.cc", + "src/core/ext/filters/http/client_authority_filter.cc", ], hdrs = [ - "src/core/lib/channel/client_authority_filter.h", + "src/core/ext/filters/http/client_authority_filter.h", ], language = "c++", deps = [ diff --git a/CMakeLists.txt b/CMakeLists.txt index 1657f1ae7e..836b36a7eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1132,7 +1132,7 @@ add_library(grpc src/core/ext/census/grpc_context.cc src/core/ext/filters/max_age/max_age_filter.cc src/core/ext/filters/message_size/message_size_filter.cc - src/core/lib/channel/client_authority_filter.cc + src/core/ext/filters/http/client_authority_filter.cc src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc src/core/ext/filters/workarounds/workaround_utils.cc src/core/plugin_registry/grpc_plugin_registry.cc @@ -2367,7 +2367,7 @@ add_library(grpc_unsecure src/core/ext/census/grpc_context.cc src/core/ext/filters/max_age/max_age_filter.cc src/core/ext/filters/message_size/message_size_filter.cc - src/core/lib/channel/client_authority_filter.cc + src/core/ext/filters/http/client_authority_filter.cc src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc src/core/ext/filters/workarounds/workaround_utils.cc src/core/plugin_registry/grpc_unsecure_plugin_registry.cc diff --git a/Makefile b/Makefile index 93b3588de2..df30405d8b 100644 --- a/Makefile +++ b/Makefile @@ -3437,7 +3437,7 @@ LIBGRPC_SRC = \ src/core/ext/census/grpc_context.cc \ src/core/ext/filters/max_age/max_age_filter.cc \ src/core/ext/filters/message_size/message_size_filter.cc \ - src/core/lib/channel/client_authority_filter.cc \ + src/core/ext/filters/http/client_authority_filter.cc \ src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc \ src/core/ext/filters/workarounds/workaround_utils.cc \ src/core/plugin_registry/grpc_plugin_registry.cc \ @@ -4648,7 +4648,7 @@ LIBGRPC_UNSECURE_SRC = \ src/core/ext/census/grpc_context.cc \ src/core/ext/filters/max_age/max_age_filter.cc \ src/core/ext/filters/message_size/message_size_filter.cc \ - src/core/lib/channel/client_authority_filter.cc \ + src/core/ext/filters/http/client_authority_filter.cc \ src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc \ src/core/ext/filters/workarounds/workaround_utils.cc \ src/core/plugin_registry/grpc_unsecure_plugin_registry.cc \ diff --git a/build.yaml b/build.yaml index 20581ae00e..7a2d5cf884 100644 --- a/build.yaml +++ b/build.yaml @@ -517,9 +517,9 @@ filegroups: - grpc_trace_headers - name: grpc_client_authority_filter headers: - - src/core/lib/channel/client_authority_filter.h + - src/core/ext/filters/http/client_authority_filter.h src: - - src/core/lib/channel/client_authority_filter.cc + - src/core/ext/filters/http/client_authority_filter.cc plugin: grpc_client_authority_filter uses: - grpc_base diff --git a/config.m4 b/config.m4 index 9b48890d4c..756108ba3a 100644 --- a/config.m4 +++ b/config.m4 @@ -361,7 +361,7 @@ if test "$PHP_GRPC" != "no"; then src/core/ext/census/grpc_context.cc \ src/core/ext/filters/max_age/max_age_filter.cc \ src/core/ext/filters/message_size/message_size_filter.cc \ - src/core/lib/channel/client_authority_filter.cc \ + src/core/ext/filters/http/client_authority_filter.cc \ src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc \ src/core/ext/filters/workarounds/workaround_utils.cc \ src/core/plugin_registry/grpc_plugin_registry.cc \ diff --git a/config.w32 b/config.w32 index b6b417e3de..755dd08007 100644 --- a/config.w32 +++ b/config.w32 @@ -338,7 +338,7 @@ if (PHP_GRPC != "no") { "src\\core\\ext\\census\\grpc_context.cc " + "src\\core\\ext\\filters\\max_age\\max_age_filter.cc " + "src\\core\\ext\\filters\\message_size\\message_size_filter.cc " + - "src\\core\\lib\\channel\\client_authority_filter.cc " + + "src\\core\\ext\\filters\\http\\client_authority_filter.cc " + "src\\core\\ext\\filters\\workarounds\\workaround_cronet_compression_filter.cc " + "src\\core\\ext\\filters\\workarounds\\workaround_utils.cc " + "src\\core\\plugin_registry\\grpc_plugin_registry.cc " + diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 5e8ae3f9a6..ae68984e65 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -479,7 +479,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/load_reporting/server_load_reporting_plugin.h', 'src/core/ext/filters/max_age/max_age_filter.h', 'src/core/ext/filters/message_size/message_size_filter.h', - 'src/core/lib/channel/client_authority_filter.h', + 'src/core/ext/filters/http/client_authority_filter.h', 'src/core/ext/filters/workarounds/workaround_cronet_compression_filter.h', 'src/core/ext/filters/workarounds/workaround_utils.h' diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 242bc49bd3..e469a99b67 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -490,7 +490,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/load_reporting/server_load_reporting_plugin.h', 'src/core/ext/filters/max_age/max_age_filter.h', 'src/core/ext/filters/message_size/message_size_filter.h', - 'src/core/lib/channel/client_authority_filter.h', + 'src/core/ext/filters/http/client_authority_filter.h', 'src/core/ext/filters/workarounds/workaround_cronet_compression_filter.h', 'src/core/ext/filters/workarounds/workaround_utils.h', 'src/core/lib/surface/init.cc', @@ -773,7 +773,7 @@ Pod::Spec.new do |s| 'src/core/ext/census/grpc_context.cc', 'src/core/ext/filters/max_age/max_age_filter.cc', 'src/core/ext/filters/message_size/message_size_filter.cc', - 'src/core/lib/channel/client_authority_filter.cc', + 'src/core/ext/filters/http/client_authority_filter.cc', 'src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc', 'src/core/ext/filters/workarounds/workaround_utils.cc', 'src/core/plugin_registry/grpc_plugin_registry.cc' @@ -1046,7 +1046,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/load_reporting/server_load_reporting_plugin.h', 'src/core/ext/filters/max_age/max_age_filter.h', 'src/core/ext/filters/message_size/message_size_filter.h', - 'src/core/lib/channel/client_authority_filter.h', + 'src/core/ext/filters/http/client_authority_filter.h', 'src/core/ext/filters/workarounds/workaround_cronet_compression_filter.h', 'src/core/ext/filters/workarounds/workaround_utils.h' end diff --git a/grpc.gemspec b/grpc.gemspec index 33ca745e69..c797b28d54 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -420,7 +420,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/load_reporting/server_load_reporting_plugin.h ) s.files += %w( src/core/ext/filters/max_age/max_age_filter.h ) s.files += %w( src/core/ext/filters/message_size/message_size_filter.h ) - s.files += %w( src/core/lib/channel/client_authority_filter.h ) + s.files += %w( src/core/ext/filters/http/client_authority_filter.h ) s.files += %w( src/core/ext/filters/workarounds/workaround_cronet_compression_filter.h ) s.files += %w( src/core/ext/filters/workarounds/workaround_utils.h ) s.files += %w( src/core/lib/surface/init.cc ) @@ -706,7 +706,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/census/grpc_context.cc ) s.files += %w( src/core/ext/filters/max_age/max_age_filter.cc ) s.files += %w( src/core/ext/filters/message_size/message_size_filter.cc ) - s.files += %w( src/core/lib/channel/client_authority_filter.cc ) + s.files += %w( src/core/ext/filters/http/client_authority_filter.cc ) s.files += %w( src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc ) s.files += %w( src/core/ext/filters/workarounds/workaround_utils.cc ) s.files += %w( src/core/plugin_registry/grpc_plugin_registry.cc ) diff --git a/grpc.gyp b/grpc.gyp index 04421bad57..9448183e69 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -513,7 +513,7 @@ 'src/core/ext/census/grpc_context.cc', 'src/core/ext/filters/max_age/max_age_filter.cc', 'src/core/ext/filters/message_size/message_size_filter.cc', - 'src/core/lib/channel/client_authority_filter.cc', + 'src/core/ext/filters/http/client_authority_filter.cc', 'src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc', 'src/core/ext/filters/workarounds/workaround_utils.cc', 'src/core/plugin_registry/grpc_plugin_registry.cc', @@ -1194,7 +1194,7 @@ 'src/core/ext/census/grpc_context.cc', 'src/core/ext/filters/max_age/max_age_filter.cc', 'src/core/ext/filters/message_size/message_size_filter.cc', - 'src/core/lib/channel/client_authority_filter.cc', + 'src/core/ext/filters/http/client_authority_filter.cc', 'src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc', 'src/core/ext/filters/workarounds/workaround_utils.cc', 'src/core/plugin_registry/grpc_unsecure_plugin_registry.cc', diff --git a/package.xml b/package.xml index a8a3c4f356..79eeffbb0c 100644 --- a/package.xml +++ b/package.xml @@ -427,7 +427,7 @@ - + @@ -713,7 +713,7 @@ - + diff --git a/src/core/ext/filters/http/client_authority_filter.cc b/src/core/ext/filters/http/client_authority_filter.cc new file mode 100644 index 0000000000..5294cfdcc5 --- /dev/null +++ b/src/core/ext/filters/http/client_authority_filter.cc @@ -0,0 +1,135 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include +#include +#include + +#include +#include +#include + +#include "src/core/ext/filters/http/client_authority_filter.h" +#include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/gpr/string.h" +#include "src/core/lib/slice/slice_internal.h" +#include "src/core/lib/slice/slice_string_helpers.h" +#include "src/core/lib/surface/call.h" +#include "src/core/lib/surface/channel_init.h" +#include "src/core/lib/surface/channel_stack_type.h" +#include "src/core/lib/transport/static_metadata.h" + +namespace { + +struct call_data { + grpc_linked_mdelem authority_storage; + grpc_call_combiner* call_combiner; +}; + +struct channel_data { + grpc_slice default_authority; +}; + +void authority_start_transport_stream_op_batch( + grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { + channel_data* chand = static_cast(elem->channel_data); + call_data* calld = static_cast(elem->call_data); + // Handle send_initial_metadata. + auto* initial_metadata = + batch->payload->send_initial_metadata.send_initial_metadata; + // If the initial metadata doesn't already contain :authority, add it. + if (batch->send_initial_metadata && + initial_metadata->idx.named.authority == nullptr) { + grpc_error* error = grpc_metadata_batch_add_head( + initial_metadata, &calld->authority_storage, + grpc_mdelem_from_slices(GRPC_MDSTR_AUTHORITY, + grpc_slice_ref(chand->default_authority))); + if (error != GRPC_ERROR_NONE) { + grpc_transport_stream_op_batch_finish_with_failure(batch, error, + calld->call_combiner); + return; + } + } + // Pass control down the stack. + grpc_call_next_op(elem, batch); +} + +/* Constructor for call_data */ +grpc_error* init_call_elem(grpc_call_element* elem, + const grpc_call_element_args* args) { + call_data* calld = static_cast(elem->call_data); + calld->call_combiner = args->call_combiner; + return GRPC_ERROR_NONE; +} + +/* Destructor for call_data */ +void destroy_call_elem(grpc_call_element* elem, + const grpc_call_final_info* final_info, + grpc_closure* ignored) {} + +/* Constructor for channel_data */ +grpc_error* init_channel_elem(grpc_channel_element* elem, + grpc_channel_element_args* args) { + channel_data* chand = static_cast(elem->channel_data); + const grpc_arg* default_authority_arg = + grpc_channel_args_find(args->channel_args, GRPC_ARG_DEFAULT_AUTHORITY); + GPR_ASSERT(default_authority_arg != nullptr); + chand->default_authority = grpc_slice_from_copied_string( + grpc_channel_arg_get_string(default_authority_arg)); + GPR_ASSERT(!args->is_last); + return GRPC_ERROR_NONE; +} + +/* Destructor for channel data */ +void destroy_channel_elem(grpc_channel_element* elem) { + channel_data* chand = static_cast(elem->channel_data); + grpc_slice_unref(chand->default_authority); +} +} // namespace + +const grpc_channel_filter grpc_client_authority_filter = { + authority_start_transport_stream_op_batch, + grpc_channel_next_op, + sizeof(call_data), + init_call_elem, + grpc_call_stack_ignore_set_pollset_or_pollset_set, + destroy_call_elem, + sizeof(channel_data), + init_channel_elem, + destroy_channel_elem, + grpc_channel_next_get_info, + "authority"}; + +static bool add_client_authority_filter(grpc_channel_stack_builder* builder, + void* arg) { + return grpc_channel_stack_builder_prepend_filter( + builder, static_cast(arg), nullptr, nullptr); +} + +void grpc_client_authority_filter_init(void) { + grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, INT_MAX, + add_client_authority_filter, + (void*)&grpc_client_authority_filter); + grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, + add_client_authority_filter, + (void*)&grpc_client_authority_filter); +} + +void grpc_client_authority_filter_shutdown(void) {} diff --git a/src/core/ext/filters/http/client_authority_filter.h b/src/core/ext/filters/http/client_authority_filter.h new file mode 100644 index 0000000000..5824e91ff2 --- /dev/null +++ b/src/core/ext/filters/http/client_authority_filter.h @@ -0,0 +1,34 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_EXT_FILTERS_HTTP_CLIENT_AUTHORITY_FILTER_H +#define GRPC_CORE_EXT_FILTERS_HTTP_CLIENT_AUTHORITY_FILTER_H + +#include + +#include + +#include "src/core/lib/channel/channel_stack.h" + +/// Filter responsible for setting the authority header, if not already set. It +/// uses the value of the GRPC_ARG_DEFAULT_AUTHORITY channel arg if the initial +/// metadata doesn't already contain an authority value. + +extern const grpc_channel_filter grpc_client_authority_filter; + +#endif /* GRPC_CORE_EXT_FILTERS_HTTP_CLIENT_AUTHORITY_FILTER_H */ diff --git a/src/core/lib/channel/client_authority_filter.cc b/src/core/lib/channel/client_authority_filter.cc deleted file mode 100644 index bf37f52e9c..0000000000 --- a/src/core/lib/channel/client_authority_filter.cc +++ /dev/null @@ -1,135 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include -#include -#include - -#include -#include -#include - -#include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/channel/client_authority_filter.h" -#include "src/core/lib/gpr/string.h" -#include "src/core/lib/slice/slice_internal.h" -#include "src/core/lib/slice/slice_string_helpers.h" -#include "src/core/lib/surface/call.h" -#include "src/core/lib/surface/channel_init.h" -#include "src/core/lib/surface/channel_stack_type.h" -#include "src/core/lib/transport/static_metadata.h" - -namespace { - -struct call_data { - grpc_linked_mdelem authority_storage; - grpc_call_combiner* call_combiner; -}; - -struct channel_data { - grpc_slice default_authority; -}; - -void authority_start_transport_stream_op_batch( - grpc_call_element* elem, grpc_transport_stream_op_batch* batch) { - channel_data* chand = static_cast(elem->channel_data); - call_data* calld = static_cast(elem->call_data); - // Handle send_initial_metadata. - auto* initial_metadata = - batch->payload->send_initial_metadata.send_initial_metadata; - // If the initial metadata doesn't already contain :authority, add it. - if (batch->send_initial_metadata && - initial_metadata->idx.named.authority == nullptr) { - grpc_error* error = grpc_metadata_batch_add_head( - initial_metadata, &calld->authority_storage, - grpc_mdelem_from_slices(GRPC_MDSTR_AUTHORITY, - grpc_slice_ref(chand->default_authority))); - if (error != GRPC_ERROR_NONE) { - grpc_transport_stream_op_batch_finish_with_failure(batch, error, - calld->call_combiner); - return; - } - } - // Pass control down the stack. - grpc_call_next_op(elem, batch); -} - -/* Constructor for call_data */ -grpc_error* init_call_elem(grpc_call_element* elem, - const grpc_call_element_args* args) { - call_data* calld = static_cast(elem->call_data); - calld->call_combiner = args->call_combiner; - return GRPC_ERROR_NONE; -} - -/* Destructor for call_data */ -void destroy_call_elem(grpc_call_element* elem, - const grpc_call_final_info* final_info, - grpc_closure* ignored) {} - -/* Constructor for channel_data */ -grpc_error* init_channel_elem(grpc_channel_element* elem, - grpc_channel_element_args* args) { - channel_data* chand = static_cast(elem->channel_data); - const grpc_arg* default_authority_arg = - grpc_channel_args_find(args->channel_args, GRPC_ARG_DEFAULT_AUTHORITY); - GPR_ASSERT(default_authority_arg != nullptr); - chand->default_authority = grpc_slice_from_copied_string( - grpc_channel_arg_get_string(default_authority_arg)); - GPR_ASSERT(!args->is_last); - return GRPC_ERROR_NONE; -} - -/* Destructor for channel data */ -void destroy_channel_elem(grpc_channel_element* elem) { - channel_data* chand = static_cast(elem->channel_data); - grpc_slice_unref(chand->default_authority); -} -} // namespace - -const grpc_channel_filter grpc_client_authority_filter = { - authority_start_transport_stream_op_batch, - grpc_channel_next_op, - sizeof(call_data), - init_call_elem, - grpc_call_stack_ignore_set_pollset_or_pollset_set, - destroy_call_elem, - sizeof(channel_data), - init_channel_elem, - destroy_channel_elem, - grpc_channel_next_get_info, - "authority"}; - -static bool add_client_authority_filter(grpc_channel_stack_builder* builder, - void* arg) { - return grpc_channel_stack_builder_prepend_filter( - builder, static_cast(arg), nullptr, nullptr); -} - -void grpc_client_authority_filter_init(void) { - grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, INT_MAX, - add_client_authority_filter, - (void*)&grpc_client_authority_filter); - grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, - add_client_authority_filter, - (void*)&grpc_client_authority_filter); -} - -void grpc_client_authority_filter_shutdown(void) {} diff --git a/src/core/lib/channel/client_authority_filter.h b/src/core/lib/channel/client_authority_filter.h deleted file mode 100644 index c101c359d2..0000000000 --- a/src/core/lib/channel/client_authority_filter.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_LIB_CHANNEL_CLIENT_AUTHORITY_FILTER_H -#define GRPC_CORE_LIB_CHANNEL_CLIENT_AUTHORITY_FILTER_H - -#include - -#include - -#include "src/core/lib/channel/channel_stack.h" - -/// Filter responsible for setting the authority header, if not already set. It -/// uses the value of the GRPC_ARG_DEFAULT_AUTHORITY channel arg if the initial -/// metadata doesn't already contain an authority value. - -extern const grpc_channel_filter grpc_client_authority_filter; - -#endif /* GRPC_CORE_LIB_CHANNEL_CLIENT_AUTHORITY_FILTER_H */ diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc index 2d29c7d95f..ac9f9e6066 100644 --- a/src/core/lib/surface/init.cc +++ b/src/core/lib/surface/init.cc @@ -27,7 +27,6 @@ #include #include #include "src/core/lib/channel/channel_stack.h" -#include "src/core/lib/channel/client_authority_filter.h" #include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/channel/handshaker_registry.h" #include "src/core/lib/debug/stats.h" diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index bb426b070f..5c9107cf2a 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -337,7 +337,7 @@ CORE_SOURCE_FILES = [ 'src/core/ext/census/grpc_context.cc', 'src/core/ext/filters/max_age/max_age_filter.cc', 'src/core/ext/filters/message_size/message_size_filter.cc', - 'src/core/lib/channel/client_authority_filter.cc', + 'src/core/ext/filters/http/client_authority_filter.cc', 'src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc', 'src/core/ext/filters/workarounds/workaround_utils.cc', 'src/core/plugin_registry/grpc_plugin_registry.cc', diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 1f19bac169..68e808675e 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -941,6 +941,8 @@ src/core/ext/filters/deadline/deadline_filter.cc \ src/core/ext/filters/deadline/deadline_filter.h \ src/core/ext/filters/http/client/http_client_filter.cc \ src/core/ext/filters/http/client/http_client_filter.h \ +src/core/ext/filters/http/client_authority_filter.cc \ +src/core/ext/filters/http/client_authority_filter.h \ src/core/ext/filters/http/http_filters_plugin.cc \ src/core/ext/filters/http/message_compress/message_compress_filter.cc \ src/core/ext/filters/http/message_compress/message_compress_filter.h \ @@ -1034,8 +1036,6 @@ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack.h \ src/core/lib/channel/channel_stack_builder.cc \ src/core/lib/channel/channel_stack_builder.h \ -src/core/lib/channel/client_authority_filter.cc \ -src/core/lib/channel/client_authority_filter.h \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/connected_channel.h \ src/core/lib/channel/context.h \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 07edd14b04..e5a0d9a247 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -9423,14 +9423,14 @@ "grpc_base" ], "headers": [ - "src/core/lib/channel/client_authority_filter.h" + "src/core/ext/filters/http/client_authority_filter.h" ], "is_filegroup": true, "language": "c", "name": "grpc_client_authority_filter", "src": [ - "src/core/lib/channel/client_authority_filter.cc", - "src/core/lib/channel/client_authority_filter.h" + "src/core/ext/filters/http/client_authority_filter.cc", + "src/core/ext/filters/http/client_authority_filter.h" ], "third_party": false, "type": "filegroup" -- cgit v1.2.3 From f2bea3725f8218777268decfd37c7b543f839d9f Mon Sep 17 00:00:00 2001 From: Noah Eisen Date: Mon, 19 Mar 2018 12:05:18 -0700 Subject: Revert "Channel Tracing Implementation; Part 1" --- BUILD | 8 +- CMakeLists.txt | 80 +--- Makefile | 114 +----- build.yaml | 35 +- config.m4 | 4 +- config.w32 | 4 +- gRPC-C++.podspec | 7 +- gRPC-Core.podspec | 12 +- grpc.def | 2 - grpc.gemspec | 8 +- grpc.gyp | 18 +- include/grpc/grpc.h | 8 - include/grpc/impl/codegen/grpc_types.h | 4 - package.xml | 8 +- .../ext/filters/client_channel/client_channel.cc | 2 +- .../ext/filters/client_channel/method_params.cc | 2 +- .../ext/filters/client_channel/method_params.h | 2 +- src/core/ext/filters/client_channel/status_util.cc | 100 +++++ src/core/ext/filters/client_channel/status_util.h | 58 +++ src/core/ext/filters/client_channel/subchannel.cc | 1 - src/core/lib/channel/channel_trace.cc | 238 ----------- src/core/lib/channel/channel_trace.h | 133 ------ src/core/lib/channel/channel_trace_registry.cc | 80 ---- src/core/lib/channel/channel_trace_registry.h | 43 -- src/core/lib/channel/status_util.cc | 100 ----- src/core/lib/channel/status_util.h | 58 --- src/core/lib/json/json.cc | 36 -- src/core/lib/json/json.h | 21 +- src/core/lib/surface/channel.cc | 33 +- src/core/lib/surface/init.cc | 3 - src/proto/grpc/channelz/BUILD | 26 -- src/proto/grpc/channelz/channelz.proto | 456 --------------------- src/python/grpcio/grpc_core_dependencies.py | 4 +- src/ruby/ext/grpc/rb_grpc_imports.generated.c | 4 - src/ruby/ext/grpc/rb_grpc_imports.generated.h | 6 - test/core/channel/BUILD | 29 -- test/core/channel/channel_trace_test.cc | 240 ----------- test/core/channel/status_util_test.cc | 49 --- test/core/client_channel/BUILD | 12 + test/core/client_channel/status_util_test.cc | 49 +++ test/core/surface/public_headers_must_be_c89.c | 2 - test/cpp/util/BUILD | 18 - test/cpp/util/channel_trace_proto_helper.cc | 56 --- test/cpp/util/channel_trace_proto_helper.h | 30 -- tools/doxygen/Doxyfile.c++.internal | 3 - tools/doxygen/Doxyfile.core.internal | 8 +- tools/run_tests/generated/sources_and_headers.json | 55 +-- tools/run_tests/generated/tests.json | 24 -- 48 files changed, 273 insertions(+), 2020 deletions(-) create mode 100644 src/core/ext/filters/client_channel/status_util.cc create mode 100644 src/core/ext/filters/client_channel/status_util.h delete mode 100644 src/core/lib/channel/channel_trace.cc delete mode 100644 src/core/lib/channel/channel_trace.h delete mode 100644 src/core/lib/channel/channel_trace_registry.cc delete mode 100644 src/core/lib/channel/channel_trace_registry.h delete mode 100644 src/core/lib/channel/status_util.cc delete mode 100644 src/core/lib/channel/status_util.h delete mode 100644 src/proto/grpc/channelz/BUILD delete mode 100644 src/proto/grpc/channelz/channelz.proto delete mode 100644 test/core/channel/channel_trace_test.cc delete mode 100644 test/core/channel/status_util_test.cc create mode 100644 test/core/client_channel/status_util_test.cc delete mode 100644 test/cpp/util/channel_trace_proto_helper.cc delete mode 100644 test/cpp/util/channel_trace_proto_helper.h (limited to 'gRPC-C++.podspec') diff --git a/BUILD b/BUILD index d59d2ad63f..6c18ad94d7 100644 --- a/BUILD +++ b/BUILD @@ -676,9 +676,6 @@ grpc_cc_library( "src/core/lib/channel/channel_args.cc", "src/core/lib/channel/channel_stack.cc", "src/core/lib/channel/channel_stack_builder.cc", - "src/core/lib/channel/channel_trace.cc", - "src/core/lib/channel/channel_trace_registry.cc", - "src/core/lib/channel/status_util.cc", "src/core/lib/channel/connected_channel.cc", "src/core/lib/channel/handshaker.cc", "src/core/lib/channel/handshaker_factory.cc", @@ -823,9 +820,6 @@ grpc_cc_library( "src/core/lib/channel/channel_args.h", "src/core/lib/channel/channel_stack.h", "src/core/lib/channel/channel_stack_builder.h", - "src/core/lib/channel/channel_trace.h", - "src/core/lib/channel/channel_trace_registry.h", - "src/core/lib/channel/status_util.h", "src/core/lib/channel/connected_channel.h", "src/core/lib/channel/context.h", "src/core/lib/channel/handshaker.h", @@ -1022,6 +1016,7 @@ grpc_cc_library( "src/core/ext/filters/client_channel/resolver.cc", "src/core/ext/filters/client_channel/resolver_registry.cc", "src/core/ext/filters/client_channel/retry_throttle.cc", + "src/core/ext/filters/client_channel/status_util.cc", "src/core/ext/filters/client_channel/subchannel.cc", "src/core/ext/filters/client_channel/subchannel_index.cc", "src/core/ext/filters/client_channel/uri_parser.cc", @@ -1044,6 +1039,7 @@ grpc_cc_library( "src/core/ext/filters/client_channel/resolver_factory.h", "src/core/ext/filters/client_channel/resolver_registry.h", "src/core/ext/filters/client_channel/retry_throttle.h", + "src/core/ext/filters/client_channel/status_util.h", "src/core/ext/filters/client_channel/subchannel.h", "src/core/ext/filters/client_channel/subchannel_index.h", "src/core/ext/filters/client_channel/uri_parser.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index 56dcb4671b..77e84a0df8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -532,7 +532,6 @@ endif() add_dependencies(buildtests_cxx byte_stream_test) add_dependencies(buildtests_cxx channel_arguments_test) add_dependencies(buildtests_cxx channel_filter_test) -add_dependencies(buildtests_cxx channel_trace_test) add_dependencies(buildtests_cxx check_gcp_environment_linux_test) add_dependencies(buildtests_cxx check_gcp_environment_windows_test) add_dependencies(buildtests_cxx chttp2_settings_timeout_test) @@ -856,13 +855,10 @@ add_library(grpc src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc - src/core/lib/channel/channel_trace.cc - src/core/lib/channel/channel_trace_registry.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc src/core/lib/channel/handshaker_registry.cc - src/core/lib/channel/status_util.cc src/core/lib/compression/compression.cc src/core/lib/compression/compression_internal.cc src/core/lib/compression/message_compress.cc @@ -1111,6 +1107,7 @@ add_library(grpc src/core/ext/filters/client_channel/resolver.cc src/core/ext/filters/client_channel/resolver_registry.cc src/core/ext/filters/client_channel/retry_throttle.cc + src/core/ext/filters/client_channel/status_util.cc src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc @@ -1244,13 +1241,10 @@ add_library(grpc_cronet src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc - src/core/lib/channel/channel_trace.cc - src/core/lib/channel/channel_trace_registry.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc src/core/lib/channel/handshaker_registry.cc - src/core/lib/channel/status_util.cc src/core/lib/compression/compression.cc src/core/lib/compression/compression_internal.cc src/core/lib/compression/message_compress.cc @@ -1437,6 +1431,7 @@ add_library(grpc_cronet src/core/ext/filters/client_channel/resolver.cc src/core/ext/filters/client_channel/resolver_registry.cc src/core/ext/filters/client_channel/retry_throttle.cc + src/core/ext/filters/client_channel/status_util.cc src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc @@ -1623,13 +1618,10 @@ add_library(grpc_test_util src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc - src/core/lib/channel/channel_trace.cc - src/core/lib/channel/channel_trace_registry.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc src/core/lib/channel/handshaker_registry.cc - src/core/lib/channel/status_util.cc src/core/lib/compression/compression.cc src/core/lib/compression/compression_internal.cc src/core/lib/compression/message_compress.cc @@ -1785,6 +1777,7 @@ add_library(grpc_test_util src/core/ext/filters/client_channel/resolver.cc src/core/ext/filters/client_channel/resolver_registry.cc src/core/ext/filters/client_channel/retry_throttle.cc + src/core/ext/filters/client_channel/status_util.cc src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc @@ -1925,13 +1918,10 @@ add_library(grpc_test_util_unsecure src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc - src/core/lib/channel/channel_trace.cc - src/core/lib/channel/channel_trace_registry.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc src/core/lib/channel/handshaker_registry.cc - src/core/lib/channel/status_util.cc src/core/lib/compression/compression.cc src/core/lib/compression/compression_internal.cc src/core/lib/compression/message_compress.cc @@ -2087,6 +2077,7 @@ add_library(grpc_test_util_unsecure src/core/ext/filters/client_channel/resolver.cc src/core/ext/filters/client_channel/resolver_registry.cc src/core/ext/filters/client_channel/retry_throttle.cc + src/core/ext/filters/client_channel/status_util.cc src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc @@ -2207,13 +2198,10 @@ add_library(grpc_unsecure src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc - src/core/lib/channel/channel_trace.cc - src/core/lib/channel/channel_trace_registry.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc src/core/lib/channel/handshaker_registry.cc - src/core/lib/channel/status_util.cc src/core/lib/compression/compression.cc src/core/lib/compression/compression_internal.cc src/core/lib/compression/message_compress.cc @@ -2402,6 +2390,7 @@ add_library(grpc_unsecure src/core/ext/filters/client_channel/resolver.cc src/core/ext/filters/client_channel/resolver_registry.cc src/core/ext/filters/client_channel/retry_throttle.cc + src/core/ext/filters/client_channel/status_util.cc src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc @@ -3023,13 +3012,10 @@ add_library(grpc++_cronet src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc - src/core/lib/channel/channel_trace.cc - src/core/lib/channel/channel_trace_registry.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc src/core/lib/channel/handshaker_registry.cc - src/core/lib/channel/status_util.cc src/core/lib/compression/compression.cc src/core/lib/compression/compression_internal.cc src/core/lib/compression/message_compress.cc @@ -3190,6 +3176,7 @@ add_library(grpc++_cronet src/core/ext/filters/client_channel/resolver.cc src/core/ext/filters/client_channel/resolver_registry.cc src/core/ext/filters/client_channel/retry_throttle.cc + src/core/ext/filters/client_channel/status_util.cc src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc @@ -3694,10 +3681,6 @@ if (gRPC_BUILD_TESTS) if (gRPC_BUILD_CODEGEN) add_library(grpc++_test_util - ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/channelz/channelz.pb.cc - ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/channelz/channelz.grpc.pb.cc - ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/channelz/channelz.pb.h - ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/channelz/channelz.grpc.pb.h ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/health/v1/health.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/health/v1/health.grpc.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/health/v1/health.pb.h @@ -3717,7 +3700,6 @@ add_library(grpc++_test_util ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h test/cpp/end2end/test_service_impl.cc test/cpp/util/byte_buffer_proto_helper.cc - test/cpp/util/channel_trace_proto_helper.cc test/cpp/util/create_test_channel.cc test/cpp/util/string_ref_helper.cc test/cpp/util/subprocess.cc @@ -3736,9 +3718,6 @@ if(WIN32 AND MSVC) endif() endif() -protobuf_generate_grpc_cpp( - src/proto/grpc/channelz/channelz.proto -) protobuf_generate_grpc_cpp( src/proto/grpc/health/v1/health.proto ) @@ -10149,51 +10128,6 @@ target_link_libraries(channel_filter_test endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -add_executable(channel_trace_test - test/core/channel/channel_trace_test.cc - ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/channelz/channelz.pb.cc - ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/channelz/channelz.grpc.pb.cc - ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/channelz/channelz.pb.h - ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/channelz/channelz.grpc.pb.h - third_party/googletest/googletest/src/gtest-all.cc - third_party/googletest/googlemock/src/gmock-all.cc -) - -protobuf_generate_grpc_cpp( - src/proto/grpc/channelz/channelz.proto -) - -target_include_directories(channel_trace_test - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${_gRPC_SSL_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} - PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} - PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} - PRIVATE ${_gRPC_CARES_INCLUDE_DIR} - PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} - PRIVATE third_party/googletest/googletest/include - PRIVATE third_party/googletest/googletest - PRIVATE third_party/googletest/googlemock/include - PRIVATE third_party/googletest/googlemock - PRIVATE ${_gRPC_PROTO_GENS_DIR} -) - -target_link_libraries(channel_trace_test - ${_gRPC_PROTOBUF_LIBRARIES} - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_test_util - grpc++_test_util - grpc++ - grpc - gpr_test_util - gpr - ${_gRPC_GFLAGS_LIBRARIES} -) - -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) - add_executable(check_gcp_environment_linux_test test/core/security/check_gcp_environment_linux_test.cc third_party/googletest/googletest/src/gtest-all.cc @@ -13139,7 +13073,7 @@ endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) add_executable(status_util_test - test/core/channel/status_util_test.cc + test/core/client_channel/status_util_test.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) diff --git a/Makefile b/Makefile index 50889716bd..3fa0f6617b 100644 --- a/Makefile +++ b/Makefile @@ -1129,7 +1129,6 @@ bm_pollset: $(BINDIR)/$(CONFIG)/bm_pollset byte_stream_test: $(BINDIR)/$(CONFIG)/byte_stream_test channel_arguments_test: $(BINDIR)/$(CONFIG)/channel_arguments_test channel_filter_test: $(BINDIR)/$(CONFIG)/channel_filter_test -channel_trace_test: $(BINDIR)/$(CONFIG)/channel_trace_test check_gcp_environment_linux_test: $(BINDIR)/$(CONFIG)/check_gcp_environment_linux_test check_gcp_environment_windows_test: $(BINDIR)/$(CONFIG)/check_gcp_environment_windows_test chttp2_settings_timeout_test: $(BINDIR)/$(CONFIG)/chttp2_settings_timeout_test @@ -1615,7 +1614,6 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/byte_stream_test \ $(BINDIR)/$(CONFIG)/channel_arguments_test \ $(BINDIR)/$(CONFIG)/channel_filter_test \ - $(BINDIR)/$(CONFIG)/channel_trace_test \ $(BINDIR)/$(CONFIG)/check_gcp_environment_linux_test \ $(BINDIR)/$(CONFIG)/check_gcp_environment_windows_test \ $(BINDIR)/$(CONFIG)/chttp2_settings_timeout_test \ @@ -1782,7 +1780,6 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/byte_stream_test \ $(BINDIR)/$(CONFIG)/channel_arguments_test \ $(BINDIR)/$(CONFIG)/channel_filter_test \ - $(BINDIR)/$(CONFIG)/channel_trace_test \ $(BINDIR)/$(CONFIG)/check_gcp_environment_linux_test \ $(BINDIR)/$(CONFIG)/check_gcp_environment_windows_test \ $(BINDIR)/$(CONFIG)/chttp2_settings_timeout_test \ @@ -2208,8 +2205,6 @@ test_cxx: buildtests_cxx $(Q) $(BINDIR)/$(CONFIG)/channel_arguments_test || ( echo test channel_arguments_test failed ; exit 1 ) $(E) "[RUN] Testing channel_filter_test" $(Q) $(BINDIR)/$(CONFIG)/channel_filter_test || ( echo test channel_filter_test failed ; exit 1 ) - $(E) "[RUN] Testing channel_trace_test" - $(Q) $(BINDIR)/$(CONFIG)/channel_trace_test || ( echo test channel_trace_test failed ; exit 1 ) $(E) "[RUN] Testing check_gcp_environment_linux_test" $(Q) $(BINDIR)/$(CONFIG)/check_gcp_environment_linux_test || ( echo test check_gcp_environment_linux_test failed ; exit 1 ) $(E) "[RUN] Testing check_gcp_environment_windows_test" @@ -2448,22 +2443,6 @@ $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc: $(Q) mkdir -p $(@D) $(Q) echo "$(GRPCXX_UNSECURE_PC_FILE)" | tr , '\n' >$@ -ifeq ($(NO_PROTOC),true) -$(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc: protoc_dep_error -$(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc: protoc_dep_error -else - -$(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc: src/proto/grpc/channelz/channelz.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) - $(E) "[PROTOC] Generating protobuf CC file from $<" - $(Q) mkdir -p `dirname $@` - $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --cpp_out=$(GENDIR) $< - -$(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc: src/proto/grpc/channelz/channelz.proto $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(PROTOBUF_DEP) $(PROTOC_PLUGINS) - $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<" - $(Q) mkdir -p `dirname $@` - $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(PROTOC_PLUGINS_DIR)/grpc_cpp_plugin$(EXECUTABLE_SUFFIX) $< -endif - ifeq ($(NO_PROTOC),true) $(GENDIR)/src/proto/grpc/core/stats.pb.cc: protoc_dep_error $(GENDIR)/src/proto/grpc/core/stats.grpc.pb.cc: protoc_dep_error @@ -3181,13 +3160,10 @@ LIBGRPC_SRC = \ src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ - src/core/lib/channel/channel_trace.cc \ - src/core/lib/channel/channel_trace_registry.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ - src/core/lib/channel/status_util.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ @@ -3436,6 +3412,7 @@ LIBGRPC_SRC = \ src/core/ext/filters/client_channel/resolver.cc \ src/core/ext/filters/client_channel/resolver_registry.cc \ src/core/ext/filters/client_channel/retry_throttle.cc \ + src/core/ext/filters/client_channel/status_util.cc \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ @@ -3571,13 +3548,10 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ - src/core/lib/channel/channel_trace.cc \ - src/core/lib/channel/channel_trace_registry.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ - src/core/lib/channel/status_util.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ @@ -3764,6 +3738,7 @@ LIBGRPC_CRONET_SRC = \ src/core/ext/filters/client_channel/resolver.cc \ src/core/ext/filters/client_channel/resolver_registry.cc \ src/core/ext/filters/client_channel/retry_throttle.cc \ + src/core/ext/filters/client_channel/status_util.cc \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ @@ -3951,13 +3926,10 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ - src/core/lib/channel/channel_trace.cc \ - src/core/lib/channel/channel_trace_registry.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ - src/core/lib/channel/status_util.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ @@ -4113,6 +4085,7 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/ext/filters/client_channel/resolver.cc \ src/core/ext/filters/client_channel/resolver_registry.cc \ src/core/ext/filters/client_channel/retry_throttle.cc \ + src/core/ext/filters/client_channel/status_util.cc \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ @@ -4246,13 +4219,10 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ - src/core/lib/channel/channel_trace.cc \ - src/core/lib/channel/channel_trace_registry.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ - src/core/lib/channel/status_util.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ @@ -4408,6 +4378,7 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ src/core/ext/filters/client_channel/resolver.cc \ src/core/ext/filters/client_channel/resolver_registry.cc \ src/core/ext/filters/client_channel/retry_throttle.cc \ + src/core/ext/filters/client_channel/status_util.cc \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ @@ -4508,13 +4479,10 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ - src/core/lib/channel/channel_trace.cc \ - src/core/lib/channel/channel_trace_registry.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ - src/core/lib/channel/status_util.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ @@ -4703,6 +4671,7 @@ LIBGRPC_UNSECURE_SRC = \ src/core/ext/filters/client_channel/resolver.cc \ src/core/ext/filters/client_channel/resolver_registry.cc \ src/core/ext/filters/client_channel/retry_throttle.cc \ + src/core/ext/filters/client_channel/status_util.cc \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ @@ -5323,13 +5292,10 @@ LIBGRPC++_CRONET_SRC = \ src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ - src/core/lib/channel/channel_trace.cc \ - src/core/lib/channel/channel_trace_registry.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ - src/core/lib/channel/status_util.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ @@ -5490,6 +5456,7 @@ LIBGRPC++_CRONET_SRC = \ src/core/ext/filters/client_channel/resolver.cc \ src/core/ext/filters/client_channel/resolver_registry.cc \ src/core/ext/filters/client_channel/retry_throttle.cc \ + src/core/ext/filters/client_channel/status_util.cc \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ @@ -6017,14 +5984,12 @@ endif LIBGRPC++_TEST_UTIL_SRC = \ - $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc \ $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc \ $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc \ $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc \ $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc \ test/cpp/end2end/test_service_impl.cc \ test/cpp/util/byte_buffer_proto_helper.cc \ - test/cpp/util/channel_trace_proto_helper.cc \ test/cpp/util/create_test_channel.cc \ test/cpp/util/string_ref_helper.cc \ test/cpp/util/subprocess.cc \ @@ -6160,14 +6125,13 @@ ifneq ($(NO_DEPS),true) -include $(LIBGRPC++_TEST_UTIL_OBJS:.o=.dep) endif endif -$(OBJDIR)/$(CONFIG)/test/cpp/end2end/test_service_impl.o: $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc -$(OBJDIR)/$(CONFIG)/test/cpp/util/byte_buffer_proto_helper.o: $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc -$(OBJDIR)/$(CONFIG)/test/cpp/util/channel_trace_proto_helper.o: $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc -$(OBJDIR)/$(CONFIG)/test/cpp/util/create_test_channel.o: $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc -$(OBJDIR)/$(CONFIG)/test/cpp/util/string_ref_helper.o: $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc -$(OBJDIR)/$(CONFIG)/test/cpp/util/subprocess.o: $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc -$(OBJDIR)/$(CONFIG)/test/cpp/util/test_credentials_provider.o: $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc -$(OBJDIR)/$(CONFIG)/src/cpp/codegen/codegen_init.o: $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc +$(OBJDIR)/$(CONFIG)/test/cpp/end2end/test_service_impl.o: $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc +$(OBJDIR)/$(CONFIG)/test/cpp/util/byte_buffer_proto_helper.o: $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc +$(OBJDIR)/$(CONFIG)/test/cpp/util/create_test_channel.o: $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc +$(OBJDIR)/$(CONFIG)/test/cpp/util/string_ref_helper.o: $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc +$(OBJDIR)/$(CONFIG)/test/cpp/util/subprocess.o: $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc +$(OBJDIR)/$(CONFIG)/test/cpp/util/test_credentials_provider.o: $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc +$(OBJDIR)/$(CONFIG)/src/cpp/codegen/codegen_init.o: $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc LIBGRPC++_TEST_UTIL_UNSECURE_SRC = \ @@ -16025,53 +15989,6 @@ endif endif -CHANNEL_TRACE_TEST_SRC = \ - test/core/channel/channel_trace_test.cc \ - $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc \ - -CHANNEL_TRACE_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(CHANNEL_TRACE_TEST_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/channel_trace_test: openssl_dep_error - -else - - - - -ifeq ($(NO_PROTOBUF),true) - -# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. - -$(BINDIR)/$(CONFIG)/channel_trace_test: protobuf_dep_error - -else - -$(BINDIR)/$(CONFIG)/channel_trace_test: $(PROTOBUF_DEP) $(CHANNEL_TRACE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(CHANNEL_TRACE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/channel_trace_test - -endif - -endif - -$(OBJDIR)/$(CONFIG)/test/core/channel/channel_trace_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - -$(OBJDIR)/$(CONFIG)/src/proto/grpc/channelz/channelz.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_channel_trace_test: $(CHANNEL_TRACE_TEST_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(CHANNEL_TRACE_TEST_OBJS:.o=.dep) -endif -endif -$(OBJDIR)/$(CONFIG)/test/core/channel/channel_trace_test.o: $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc - - CHECK_GCP_ENVIRONMENT_LINUX_TEST_SRC = \ test/core/security/check_gcp_environment_linux_test.cc \ @@ -19194,7 +19111,7 @@ endif STATUS_UTIL_TEST_SRC = \ - test/core/channel/status_util_test.cc \ + test/core/client_channel/status_util_test.cc \ STATUS_UTIL_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(STATUS_UTIL_TEST_SRC)))) ifeq ($(NO_SECURE),true) @@ -19225,7 +19142,7 @@ endif endif -$(OBJDIR)/$(CONFIG)/test/core/channel/status_util_test.o: $(LIBDIR)/$(CONFIG)/libgrpc.a +$(OBJDIR)/$(CONFIG)/test/core/client_channel/status_util_test.o: $(LIBDIR)/$(CONFIG)/libgrpc.a deps_status_util_test: $(STATUS_UTIL_TEST_OBJS:.o=.dep) @@ -23637,7 +23554,6 @@ test/cpp/qps/server_async.cc: $(OPENSSL_DEP) test/cpp/qps/server_sync.cc: $(OPENSSL_DEP) test/cpp/qps/usage_timer.cc: $(OPENSSL_DEP) test/cpp/util/byte_buffer_proto_helper.cc: $(OPENSSL_DEP) -test/cpp/util/channel_trace_proto_helper.cc: $(OPENSSL_DEP) test/cpp/util/cli_call.cc: $(OPENSSL_DEP) test/cpp/util/cli_credentials.cc: $(OPENSSL_DEP) test/cpp/util/create_test_channel.cc: $(OPENSSL_DEP) diff --git a/build.yaml b/build.yaml index 0dd3d36d8c..a4875df9e5 100644 --- a/build.yaml +++ b/build.yaml @@ -232,13 +232,10 @@ filegroups: - src/core/lib/channel/channel_args.cc - src/core/lib/channel/channel_stack.cc - src/core/lib/channel/channel_stack_builder.cc - - src/core/lib/channel/channel_trace.cc - - src/core/lib/channel/channel_trace_registry.cc - src/core/lib/channel/connected_channel.cc - src/core/lib/channel/handshaker.cc - src/core/lib/channel/handshaker_factory.cc - src/core/lib/channel/handshaker_registry.cc - - src/core/lib/channel/status_util.cc - src/core/lib/compression/compression.cc - src/core/lib/compression/compression_internal.cc - src/core/lib/compression/message_compress.cc @@ -402,14 +399,11 @@ filegroups: - src/core/lib/channel/channel_args.h - src/core/lib/channel/channel_stack.h - src/core/lib/channel/channel_stack_builder.h - - src/core/lib/channel/channel_trace.h - - src/core/lib/channel/channel_trace_registry.h - src/core/lib/channel/connected_channel.h - src/core/lib/channel/context.h - src/core/lib/channel/handshaker.h - src/core/lib/channel/handshaker_factory.h - src/core/lib/channel/handshaker_registry.h - - src/core/lib/channel/status_util.h - src/core/lib/compression/algorithm_metadata.h - src/core/lib/compression/compression_internal.h - src/core/lib/compression/message_compress.h @@ -553,6 +547,7 @@ filegroups: - src/core/ext/filters/client_channel/resolver_factory.h - src/core/ext/filters/client_channel/resolver_registry.h - src/core/ext/filters/client_channel/retry_throttle.h + - src/core/ext/filters/client_channel/status_util.h - src/core/ext/filters/client_channel/subchannel.h - src/core/ext/filters/client_channel/subchannel_index.h - src/core/ext/filters/client_channel/uri_parser.h @@ -575,6 +570,7 @@ filegroups: - src/core/ext/filters/client_channel/resolver.cc - src/core/ext/filters/client_channel/resolver_registry.cc - src/core/ext/filters/client_channel/retry_throttle.cc + - src/core/ext/filters/client_channel/status_util.cc - src/core/ext/filters/client_channel/subchannel.cc - src/core/ext/filters/client_channel/subchannel_index.cc - src/core/ext/filters/client_channel/uri_parser.cc @@ -1070,10 +1066,6 @@ filegroups: secure: true uses: - grpc_trace -- name: grpc++_channelz_proto - language: c++ - src: - - src/proto/grpc/channelz/channelz.proto - name: grpc++_codegen_base language: c++ public_headers: @@ -1622,20 +1614,17 @@ libs: headers: - test/cpp/end2end/test_service_impl.h - test/cpp/util/byte_buffer_proto_helper.h - - test/cpp/util/channel_trace_proto_helper.h - test/cpp/util/create_test_channel.h - test/cpp/util/string_ref_helper.h - test/cpp/util/subprocess.h - test/cpp/util/test_credentials_provider.h src: - - src/proto/grpc/channelz/channelz.proto - src/proto/grpc/health/v1/health.proto - src/proto/grpc/testing/echo_messages.proto - src/proto/grpc/testing/echo.proto - src/proto/grpc/testing/duplicate/echo_duplicate.proto - test/cpp/end2end/test_service_impl.cc - test/cpp/util/byte_buffer_proto_helper.cc - - test/cpp/util/channel_trace_proto_helper.cc - test/cpp/util/create_test_channel.cc - test/cpp/util/string_ref_helper.cc - test/cpp/util/subprocess.cc @@ -4118,24 +4107,6 @@ targets: - grpc - gpr uses_polling: false -- name: channel_trace_test - gtest: true - build: test - language: c++ - src: - - test/core/channel/channel_trace_test.cc - deps: - - grpc_test_util - - grpc++_test_util - - grpc++ - - grpc - - gpr_test_util - - gpr - filegroups: - - grpc++_channelz_proto - uses: - - grpc++_test - uses_polling: false - name: check_gcp_environment_linux_test build: test language: c++ @@ -5157,7 +5128,7 @@ targets: build: test language: c++ src: - - test/core/channel/status_util_test.cc + - test/core/client_channel/status_util_test.cc deps: - grpc uses_polling: false diff --git a/config.m4 b/config.m4 index 3a81f9d7f9..2f17d0c4b7 100644 --- a/config.m4 +++ b/config.m4 @@ -84,13 +84,10 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ - src/core/lib/channel/channel_trace.cc \ - src/core/lib/channel/channel_trace_registry.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ - src/core/lib/channel/status_util.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ @@ -339,6 +336,7 @@ if test "$PHP_GRPC" != "no"; then src/core/ext/filters/client_channel/resolver.cc \ src/core/ext/filters/client_channel/resolver_registry.cc \ src/core/ext/filters/client_channel/retry_throttle.cc \ + src/core/ext/filters/client_channel/status_util.cc \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ diff --git a/config.w32 b/config.w32 index 76be896e44..78f2fe079d 100644 --- a/config.w32 +++ b/config.w32 @@ -61,13 +61,10 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\channel\\channel_args.cc " + "src\\core\\lib\\channel\\channel_stack.cc " + "src\\core\\lib\\channel\\channel_stack_builder.cc " + - "src\\core\\lib\\channel\\channel_trace.cc " + - "src\\core\\lib\\channel\\channel_trace_registry.cc " + "src\\core\\lib\\channel\\connected_channel.cc " + "src\\core\\lib\\channel\\handshaker.cc " + "src\\core\\lib\\channel\\handshaker_factory.cc " + "src\\core\\lib\\channel\\handshaker_registry.cc " + - "src\\core\\lib\\channel\\status_util.cc " + "src\\core\\lib\\compression\\compression.cc " + "src\\core\\lib\\compression\\compression_internal.cc " + "src\\core\\lib\\compression\\message_compress.cc " + @@ -316,6 +313,7 @@ if (PHP_GRPC != "no") { "src\\core\\ext\\filters\\client_channel\\resolver.cc " + "src\\core\\ext\\filters\\client_channel\\resolver_registry.cc " + "src\\core\\ext\\filters\\client_channel\\retry_throttle.cc " + + "src\\core\\ext\\filters\\client_channel\\status_util.cc " + "src\\core\\ext\\filters\\client_channel\\subchannel.cc " + "src\\core\\ext\\filters\\client_channel\\subchannel_index.cc " + "src\\core\\ext\\filters\\client_channel\\uri_parser.cc " + diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index f42bd4f81c..e1282611b0 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -326,6 +326,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/resolver_factory.h', 'src/core/ext/filters/client_channel/resolver_registry.h', 'src/core/ext/filters/client_channel/retry_throttle.h', + 'src/core/ext/filters/client_channel/status_util.h', 'src/core/ext/filters/client_channel/subchannel.h', 'src/core/ext/filters/client_channel/subchannel_index.h', 'src/core/ext/filters/client_channel/uri_parser.h', @@ -342,14 +343,11 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.h', 'src/core/lib/channel/channel_stack.h', 'src/core/lib/channel/channel_stack_builder.h', - 'src/core/lib/channel/channel_trace.h', - 'src/core/lib/channel/channel_trace_registry.h', 'src/core/lib/channel/connected_channel.h', 'src/core/lib/channel/context.h', 'src/core/lib/channel/handshaker.h', 'src/core/lib/channel/handshaker_factory.h', 'src/core/lib/channel/handshaker_registry.h', - 'src/core/lib/channel/status_util.h', 'src/core/lib/compression/algorithm_metadata.h', 'src/core/lib/compression/compression_internal.h', 'src/core/lib/compression/message_compress.h', @@ -526,14 +524,11 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.h', 'src/core/lib/channel/channel_stack.h', 'src/core/lib/channel/channel_stack_builder.h', - 'src/core/lib/channel/channel_trace.h', - 'src/core/lib/channel/channel_trace_registry.h', 'src/core/lib/channel/connected_channel.h', 'src/core/lib/channel/context.h', 'src/core/lib/channel/handshaker.h', 'src/core/lib/channel/handshaker_factory.h', 'src/core/lib/channel/handshaker_registry.h', - 'src/core/lib/channel/status_util.h', 'src/core/lib/compression/algorithm_metadata.h', 'src/core/lib/compression/compression_internal.h', 'src/core/lib/compression/message_compress.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 634bff2f06..39433ff819 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -337,6 +337,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/resolver_factory.h', 'src/core/ext/filters/client_channel/resolver_registry.h', 'src/core/ext/filters/client_channel/retry_throttle.h', + 'src/core/ext/filters/client_channel/status_util.h', 'src/core/ext/filters/client_channel/subchannel.h', 'src/core/ext/filters/client_channel/subchannel_index.h', 'src/core/ext/filters/client_channel/uri_parser.h', @@ -353,14 +354,11 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.h', 'src/core/lib/channel/channel_stack.h', 'src/core/lib/channel/channel_stack_builder.h', - 'src/core/lib/channel/channel_trace.h', - 'src/core/lib/channel/channel_trace_registry.h', 'src/core/lib/channel/connected_channel.h', 'src/core/lib/channel/context.h', 'src/core/lib/channel/handshaker.h', 'src/core/lib/channel/handshaker_factory.h', 'src/core/lib/channel/handshaker_registry.h', - 'src/core/lib/channel/status_util.h', 'src/core/lib/compression/algorithm_metadata.h', 'src/core/lib/compression/compression_internal.h', 'src/core/lib/compression/message_compress.h', @@ -502,13 +500,10 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', - 'src/core/lib/channel/channel_trace.cc', - 'src/core/lib/channel/channel_trace_registry.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', 'src/core/lib/channel/handshaker_registry.cc', - 'src/core/lib/channel/status_util.cc', 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/compression_internal.cc', 'src/core/lib/compression/message_compress.cc', @@ -754,6 +749,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/resolver.cc', 'src/core/ext/filters/client_channel/resolver_registry.cc', 'src/core/ext/filters/client_channel/retry_throttle.cc', + 'src/core/ext/filters/client_channel/status_util.cc', 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', @@ -908,6 +904,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/resolver_factory.h', 'src/core/ext/filters/client_channel/resolver_registry.h', 'src/core/ext/filters/client_channel/retry_throttle.h', + 'src/core/ext/filters/client_channel/status_util.h', 'src/core/ext/filters/client_channel/subchannel.h', 'src/core/ext/filters/client_channel/subchannel_index.h', 'src/core/ext/filters/client_channel/uri_parser.h', @@ -924,14 +921,11 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.h', 'src/core/lib/channel/channel_stack.h', 'src/core/lib/channel/channel_stack_builder.h', - 'src/core/lib/channel/channel_trace.h', - 'src/core/lib/channel/channel_trace_registry.h', 'src/core/lib/channel/connected_channel.h', 'src/core/lib/channel/context.h', 'src/core/lib/channel/handshaker.h', 'src/core/lib/channel/handshaker_factory.h', 'src/core/lib/channel/handshaker_registry.h', - 'src/core/lib/channel/status_util.h', 'src/core/lib/compression/algorithm_metadata.h', 'src/core/lib/compression/compression_internal.h', 'src/core/lib/compression/message_compress.h', diff --git a/grpc.def b/grpc.def index 5ff3a1efe8..2bafebbbd4 100644 --- a/grpc.def +++ b/grpc.def @@ -45,8 +45,6 @@ EXPORTS grpc_insecure_channel_create grpc_lame_client_channel_create grpc_channel_destroy - grpc_channel_get_trace - grpc_channel_get_uuid grpc_call_cancel grpc_call_cancel_with_status grpc_call_ref diff --git a/grpc.gemspec b/grpc.gemspec index 3b07dd6433..3a57829943 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -267,6 +267,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/client_channel/resolver_factory.h ) s.files += %w( src/core/ext/filters/client_channel/resolver_registry.h ) s.files += %w( src/core/ext/filters/client_channel/retry_throttle.h ) + s.files += %w( src/core/ext/filters/client_channel/status_util.h ) s.files += %w( src/core/ext/filters/client_channel/subchannel.h ) s.files += %w( src/core/ext/filters/client_channel/subchannel_index.h ) s.files += %w( src/core/ext/filters/client_channel/uri_parser.h ) @@ -283,14 +284,11 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/channel/channel_args.h ) s.files += %w( src/core/lib/channel/channel_stack.h ) s.files += %w( src/core/lib/channel/channel_stack_builder.h ) - s.files += %w( src/core/lib/channel/channel_trace.h ) - s.files += %w( src/core/lib/channel/channel_trace_registry.h ) s.files += %w( src/core/lib/channel/connected_channel.h ) s.files += %w( src/core/lib/channel/context.h ) s.files += %w( src/core/lib/channel/handshaker.h ) s.files += %w( src/core/lib/channel/handshaker_factory.h ) s.files += %w( src/core/lib/channel/handshaker_registry.h ) - s.files += %w( src/core/lib/channel/status_util.h ) s.files += %w( src/core/lib/compression/algorithm_metadata.h ) s.files += %w( src/core/lib/compression/compression_internal.h ) s.files += %w( src/core/lib/compression/message_compress.h ) @@ -432,13 +430,10 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/channel/channel_args.cc ) s.files += %w( src/core/lib/channel/channel_stack.cc ) s.files += %w( src/core/lib/channel/channel_stack_builder.cc ) - s.files += %w( src/core/lib/channel/channel_trace.cc ) - s.files += %w( src/core/lib/channel/channel_trace_registry.cc ) s.files += %w( src/core/lib/channel/connected_channel.cc ) s.files += %w( src/core/lib/channel/handshaker.cc ) s.files += %w( src/core/lib/channel/handshaker_factory.cc ) s.files += %w( src/core/lib/channel/handshaker_registry.cc ) - s.files += %w( src/core/lib/channel/status_util.cc ) s.files += %w( src/core/lib/compression/compression.cc ) s.files += %w( src/core/lib/compression/compression_internal.cc ) s.files += %w( src/core/lib/compression/message_compress.cc ) @@ -687,6 +682,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/client_channel/resolver.cc ) s.files += %w( src/core/ext/filters/client_channel/resolver_registry.cc ) s.files += %w( src/core/ext/filters/client_channel/retry_throttle.cc ) + s.files += %w( src/core/ext/filters/client_channel/status_util.cc ) s.files += %w( src/core/ext/filters/client_channel/subchannel.cc ) s.files += %w( src/core/ext/filters/client_channel/subchannel_index.cc ) s.files += %w( src/core/ext/filters/client_channel/uri_parser.cc ) diff --git a/grpc.gyp b/grpc.gyp index fc9a45d307..403d32831b 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -237,13 +237,10 @@ 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', - 'src/core/lib/channel/channel_trace.cc', - 'src/core/lib/channel/channel_trace_registry.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', 'src/core/lib/channel/handshaker_registry.cc', - 'src/core/lib/channel/status_util.cc', 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/compression_internal.cc', 'src/core/lib/compression/message_compress.cc', @@ -492,6 +489,7 @@ 'src/core/ext/filters/client_channel/resolver.cc', 'src/core/ext/filters/client_channel/resolver_registry.cc', 'src/core/ext/filters/client_channel/retry_throttle.cc', + 'src/core/ext/filters/client_channel/status_util.cc', 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', @@ -582,13 +580,10 @@ 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', - 'src/core/lib/channel/channel_trace.cc', - 'src/core/lib/channel/channel_trace_registry.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', 'src/core/lib/channel/handshaker_registry.cc', - 'src/core/lib/channel/status_util.cc', 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/compression_internal.cc', 'src/core/lib/compression/message_compress.cc', @@ -744,6 +739,7 @@ 'src/core/ext/filters/client_channel/resolver.cc', 'src/core/ext/filters/client_channel/resolver_registry.cc', 'src/core/ext/filters/client_channel/retry_throttle.cc', + 'src/core/ext/filters/client_channel/status_util.cc', 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', @@ -812,13 +808,10 @@ 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', - 'src/core/lib/channel/channel_trace.cc', - 'src/core/lib/channel/channel_trace_registry.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', 'src/core/lib/channel/handshaker_registry.cc', - 'src/core/lib/channel/status_util.cc', 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/compression_internal.cc', 'src/core/lib/compression/message_compress.cc', @@ -974,6 +967,7 @@ 'src/core/ext/filters/client_channel/resolver.cc', 'src/core/ext/filters/client_channel/resolver_registry.cc', 'src/core/ext/filters/client_channel/retry_throttle.cc', + 'src/core/ext/filters/client_channel/status_util.cc', 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', @@ -1021,13 +1015,10 @@ 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', - 'src/core/lib/channel/channel_trace.cc', - 'src/core/lib/channel/channel_trace_registry.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', 'src/core/lib/channel/handshaker_registry.cc', - 'src/core/lib/channel/status_util.cc', 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/compression_internal.cc', 'src/core/lib/compression/message_compress.cc', @@ -1216,6 +1207,7 @@ 'src/core/ext/filters/client_channel/resolver.cc', 'src/core/ext/filters/client_channel/resolver_registry.cc', 'src/core/ext/filters/client_channel/retry_throttle.cc', + 'src/core/ext/filters/client_channel/status_util.cc', 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', @@ -1396,14 +1388,12 @@ 'grpc', ], 'sources': [ - 'src/proto/grpc/channelz/channelz.proto', 'src/proto/grpc/health/v1/health.proto', 'src/proto/grpc/testing/echo_messages.proto', 'src/proto/grpc/testing/echo.proto', 'src/proto/grpc/testing/duplicate/echo_duplicate.proto', 'test/cpp/end2end/test_service_impl.cc', 'test/cpp/util/byte_buffer_proto_helper.cc', - 'test/cpp/util/channel_trace_proto_helper.cc', 'test/cpp/util/create_test_channel.cc', 'test/cpp/util/string_ref_helper.cc', 'test/cpp/util/subprocess.cc', diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index dd8a5d7d5f..c129a66949 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -286,14 +286,6 @@ GRPCAPI grpc_channel* grpc_lame_client_channel_create( /** Close and destroy a grpc channel */ GRPCAPI void grpc_channel_destroy(grpc_channel* channel); -/** Returns the JSON formatted channel trace for this channel. The caller - owns the returned string and is responsible for freeing it. */ -GRPCAPI char* grpc_channel_get_trace(grpc_channel* channel); - -/** Returns the channel uuid, which can be used to look up its trace at a - later time. */ -GRPCAPI intptr_t grpc_channel_get_uuid(grpc_channel* channel); - /** Error handling for grpc_call Most grpc_call functions return a grpc_error. If the error is not GRPC_OK then the operation failed due to some unsatisfied precondition. diff --git a/include/grpc/impl/codegen/grpc_types.h b/include/grpc/impl/codegen/grpc_types.h index b671ad653e..dcce2e7f9a 100644 --- a/include/grpc/impl/codegen/grpc_types.h +++ b/include/grpc/impl/codegen/grpc_types.h @@ -281,10 +281,6 @@ typedef struct { #define GRPC_ARG_SOCKET_MUTATOR "grpc.socket_mutator" /** The grpc_socket_factory instance to create and bind sockets. A pointer. */ #define GRPC_ARG_SOCKET_FACTORY "grpc.socket_factory" -/** The maximum number of trace events to keep in the tracer for each channel or - * subchannel. The default is 10. If set to 0, channel tracing is disabled. */ -#define GRPC_ARG_MAX_CHANNEL_TRACE_EVENTS_PER_NODE \ - "grpc.max_channel_trace_events_per_node" /** If non-zero, Cronet transport will coalesce packets to fewer frames * when possible. */ #define GRPC_ARG_USE_CRONET_PACKET_COALESCING \ diff --git a/package.xml b/package.xml index 0b3fc3a9a0..8f0dc55dbf 100644 --- a/package.xml +++ b/package.xml @@ -274,6 +274,7 @@ + @@ -290,14 +291,11 @@ - - - @@ -439,13 +437,10 @@ - - - @@ -694,6 +689,7 @@ + diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index bf3911e5ee..bbc5160bec 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -38,12 +38,12 @@ #include "src/core/ext/filters/client_channel/proxy_mapper_registry.h" #include "src/core/ext/filters/client_channel/resolver_registry.h" #include "src/core/ext/filters/client_channel/retry_throttle.h" +#include "src/core/ext/filters/client_channel/status_util.h" #include "src/core/ext/filters/client_channel/subchannel.h" #include "src/core/ext/filters/deadline/deadline_filter.h" #include "src/core/lib/backoff/backoff.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/connected_channel.h" -#include "src/core/lib/channel/status_util.h" #include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/inlined_vector.h" #include "src/core/lib/gprpp/manual_constructor.h" diff --git a/src/core/ext/filters/client_channel/method_params.cc b/src/core/ext/filters/client_channel/method_params.cc index 1f116bb67d..374b87e170 100644 --- a/src/core/ext/filters/client_channel/method_params.cc +++ b/src/core/ext/filters/client_channel/method_params.cc @@ -26,7 +26,7 @@ #include #include "src/core/ext/filters/client_channel/method_params.h" -#include "src/core/lib/channel/status_util.h" +#include "src/core/ext/filters/client_channel/status_util.h" #include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/memory.h" diff --git a/src/core/ext/filters/client_channel/method_params.h b/src/core/ext/filters/client_channel/method_params.h index 099924edf3..48ece29867 100644 --- a/src/core/ext/filters/client_channel/method_params.h +++ b/src/core/ext/filters/client_channel/method_params.h @@ -21,7 +21,7 @@ #include -#include "src/core/lib/channel/status_util.h" +#include "src/core/ext/filters/client_channel/status_util.h" #include "src/core/lib/gprpp/ref_counted.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/iomgr/exec_ctx.h" // for grpc_millis diff --git a/src/core/ext/filters/client_channel/status_util.cc b/src/core/ext/filters/client_channel/status_util.cc new file mode 100644 index 0000000000..11f732ab44 --- /dev/null +++ b/src/core/ext/filters/client_channel/status_util.cc @@ -0,0 +1,100 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/ext/filters/client_channel/status_util.h" + +#include "src/core/lib/gpr/useful.h" + +typedef struct { + const char* str; + grpc_status_code status; +} status_string_entry; + +static const status_string_entry g_status_string_entries[] = { + {"OK", GRPC_STATUS_OK}, + {"CANCELLED", GRPC_STATUS_CANCELLED}, + {"UNKNOWN", GRPC_STATUS_UNKNOWN}, + {"INVALID_ARGUMENT", GRPC_STATUS_INVALID_ARGUMENT}, + {"DEADLINE_EXCEEDED", GRPC_STATUS_DEADLINE_EXCEEDED}, + {"NOT_FOUND", GRPC_STATUS_NOT_FOUND}, + {"ALREADY_EXISTS", GRPC_STATUS_ALREADY_EXISTS}, + {"PERMISSION_DENIED", GRPC_STATUS_PERMISSION_DENIED}, + {"UNAUTHENTICATED", GRPC_STATUS_UNAUTHENTICATED}, + {"RESOURCE_EXHAUSTED", GRPC_STATUS_RESOURCE_EXHAUSTED}, + {"FAILED_PRECONDITION", GRPC_STATUS_FAILED_PRECONDITION}, + {"ABORTED", GRPC_STATUS_ABORTED}, + {"OUT_OF_RANGE", GRPC_STATUS_OUT_OF_RANGE}, + {"UNIMPLEMENTED", GRPC_STATUS_UNIMPLEMENTED}, + {"INTERNAL", GRPC_STATUS_INTERNAL}, + {"UNAVAILABLE", GRPC_STATUS_UNAVAILABLE}, + {"DATA_LOSS", GRPC_STATUS_DATA_LOSS}, +}; + +bool grpc_status_code_from_string(const char* status_str, + grpc_status_code* status) { + for (size_t i = 0; i < GPR_ARRAY_SIZE(g_status_string_entries); ++i) { + if (strcmp(status_str, g_status_string_entries[i].str) == 0) { + *status = g_status_string_entries[i].status; + return true; + } + } + return false; +} + +const char* grpc_status_code_to_string(grpc_status_code status) { + switch (status) { + case GRPC_STATUS_OK: + return "OK"; + case GRPC_STATUS_CANCELLED: + return "CANCELLED"; + case GRPC_STATUS_UNKNOWN: + return "UNKNOWN"; + case GRPC_STATUS_INVALID_ARGUMENT: + return "INVALID_ARGUMENT"; + case GRPC_STATUS_DEADLINE_EXCEEDED: + return "DEADLINE_EXCEEDED"; + case GRPC_STATUS_NOT_FOUND: + return "NOT_FOUND"; + case GRPC_STATUS_ALREADY_EXISTS: + return "ALREADY_EXISTS"; + case GRPC_STATUS_PERMISSION_DENIED: + return "PERMISSION_DENIED"; + case GRPC_STATUS_UNAUTHENTICATED: + return "UNAUTHENTICATED"; + case GRPC_STATUS_RESOURCE_EXHAUSTED: + return "RESOURCE_EXHAUSTED"; + case GRPC_STATUS_FAILED_PRECONDITION: + return "FAILED_PRECONDITION"; + case GRPC_STATUS_ABORTED: + return "ABORTED"; + case GRPC_STATUS_OUT_OF_RANGE: + return "OUT_OF_RANGE"; + case GRPC_STATUS_UNIMPLEMENTED: + return "UNIMPLEMENTED"; + case GRPC_STATUS_INTERNAL: + return "INTERNAL"; + case GRPC_STATUS_UNAVAILABLE: + return "UNAVAILABLE"; + case GRPC_STATUS_DATA_LOSS: + return "DATA_LOSS"; + default: + return "UNKNOWN"; + } +} diff --git a/src/core/ext/filters/client_channel/status_util.h b/src/core/ext/filters/client_channel/status_util.h new file mode 100644 index 0000000000..e018709730 --- /dev/null +++ b/src/core/ext/filters/client_channel/status_util.h @@ -0,0 +1,58 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_STATUS_UTIL_H +#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_STATUS_UTIL_H + +#include + +#include + +#include +#include + +/// If \a status_str is a valid status string, sets \a status to the +/// corresponding status value and returns true. +bool grpc_status_code_from_string(const char* status_str, + grpc_status_code* status); + +/// Returns the string form of \a status, or "UNKNOWN" if invalid. +const char* grpc_status_code_to_string(grpc_status_code status); + +namespace grpc_core { +namespace internal { + +/// A set of grpc_status_code values. +class StatusCodeSet { + public: + bool Empty() const { return status_code_mask_ == 0; } + + void Add(grpc_status_code status) { status_code_mask_ |= (1 << status); } + + bool Contains(grpc_status_code status) const { + return status_code_mask_ & (1 << status); + } + + private: + int status_code_mask_ = 0; // A bitfield of status codes in the set. +}; + +} // namespace internal +} // namespace grpc_core + +#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_STATUS_UTIL_H */ diff --git a/src/core/ext/filters/client_channel/subchannel.cc b/src/core/ext/filters/client_channel/subchannel.cc index d7815fb7e1..cae7cc35e3 100644 --- a/src/core/ext/filters/client_channel/subchannel.cc +++ b/src/core/ext/filters/client_channel/subchannel.cc @@ -40,7 +40,6 @@ #include "src/core/lib/debug/stats.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/manual_constructor.h" -#include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/iomgr/timer.h" #include "src/core/lib/profiling/timers.h" diff --git a/src/core/lib/channel/channel_trace.cc b/src/core/lib/channel/channel_trace.cc deleted file mode 100644 index 67d5fd364b..0000000000 --- a/src/core/lib/channel/channel_trace.cc +++ /dev/null @@ -1,238 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/lib/channel/channel_trace.h" - -#include -#include -#include -#include -#include -#include - -#include "src/core/lib/channel/channel_trace_registry.h" -#include "src/core/lib/channel/status_util.h" -#include "src/core/lib/gpr/string.h" -#include "src/core/lib/gpr/useful.h" -#include "src/core/lib/gprpp/memory.h" -#include "src/core/lib/iomgr/error.h" -#include "src/core/lib/slice/slice_internal.h" -#include "src/core/lib/surface/channel.h" -#include "src/core/lib/transport/connectivity_state.h" -#include "src/core/lib/transport/error_utils.h" - -namespace grpc_core { - -ChannelTrace::TraceEvent::TraceEvent( - Severity severity, grpc_slice data, - RefCountedPtr referenced_tracer, ReferencedType type) - : severity_(severity), - data_(data), - timestamp_(grpc_millis_to_timespec(grpc_core::ExecCtx::Get()->Now(), - GPR_CLOCK_REALTIME)), - next_(nullptr), - referenced_tracer_(std::move(referenced_tracer)), - referenced_type_(type) {} - -ChannelTrace::TraceEvent::TraceEvent(Severity severity, grpc_slice data) - : severity_(severity), - data_(data), - timestamp_(grpc_millis_to_timespec(grpc_core::ExecCtx::Get()->Now(), - GPR_CLOCK_REALTIME)), - next_(nullptr) {} - -ChannelTrace::TraceEvent::~TraceEvent() { grpc_slice_unref_internal(data_); } - -ChannelTrace::ChannelTrace(size_t max_events) - : channel_uuid_(-1), - num_events_logged_(0), - list_size_(0), - max_list_size_(max_events), - head_trace_(nullptr), - tail_trace_(nullptr) { - if (max_list_size_ == 0) return; // tracing is disabled if max_events == 0 - gpr_mu_init(&tracer_mu_); - channel_uuid_ = grpc_channel_trace_registry_register_channel_trace(this); - time_created_ = grpc_millis_to_timespec(grpc_core::ExecCtx::Get()->Now(), - GPR_CLOCK_REALTIME); -} - -ChannelTrace::~ChannelTrace() { - if (max_list_size_ == 0) return; // tracing is disabled if max_events == 0 - TraceEvent* it = head_trace_; - while (it != nullptr) { - TraceEvent* to_free = it; - it = it->next(); - Delete(to_free); - } - grpc_channel_trace_registry_unregister_channel_trace(channel_uuid_); - gpr_mu_destroy(&tracer_mu_); -} - -intptr_t ChannelTrace::GetUuid() const { return channel_uuid_; } - -void ChannelTrace::AddTraceEventHelper(TraceEvent* new_trace_event) { - ++num_events_logged_; - // first event case - if (head_trace_ == nullptr) { - head_trace_ = tail_trace_ = new_trace_event; - } - // regular event add case - else { - tail_trace_->set_next(new_trace_event); - tail_trace_ = tail_trace_->next(); - } - ++list_size_; - // maybe garbage collect the end - if (list_size_ > max_list_size_) { - TraceEvent* to_free = head_trace_; - head_trace_ = head_trace_->next(); - Delete(to_free); - --list_size_; - } -} - -void ChannelTrace::AddTraceEvent(Severity severity, grpc_slice data) { - if (max_list_size_ == 0) return; // tracing is disabled if max_events == 0 - AddTraceEventHelper(New(severity, data)); -} - -void ChannelTrace::AddTraceEventReferencingChannel( - Severity severity, grpc_slice data, - RefCountedPtr referenced_tracer) { - if (max_list_size_ == 0) return; // tracing is disabled if max_events == 0 - // create and fill up the new event - AddTraceEventHelper( - New(severity, data, std::move(referenced_tracer), Channel)); -} - -void ChannelTrace::AddTraceEventReferencingSubchannel( - Severity severity, grpc_slice data, - RefCountedPtr referenced_tracer) { - if (max_list_size_ == 0) return; // tracing is disabled if max_events == 0 - // create and fill up the new event - AddTraceEventHelper(New( - severity, data, std::move(referenced_tracer), Subchannel)); -} - -namespace { - -// returns an allocated string that represents tm according to RFC-3339, and, -// more specifically, follows: -// https://developers.google.com/protocol-buffers/docs/proto3#json -// -// "Uses RFC 3339, where generated output will always be Z-normalized and uses -// 0, 3, 6 or 9 fractional digits." -char* fmt_time(gpr_timespec tm) { - char time_buffer[35]; - char ns_buffer[11]; // '.' + 9 digits of precision - struct tm* tm_info = localtime((const time_t*)&tm.tv_sec); - strftime(time_buffer, sizeof(time_buffer), "%Y-%m-%dT%H:%M:%S", tm_info); - snprintf(ns_buffer, 11, ".%09d", tm.tv_nsec); - // This loop trims off trailing zeros by inserting a null character that the - // right point. We iterate in chunks of three because we want 0, 3, 6, or 9 - // fractional digits. - for (int i = 7; i >= 1; i -= 3) { - if (ns_buffer[i] == '0' && ns_buffer[i + 1] == '0' && - ns_buffer[i + 2] == '0') { - ns_buffer[i] = '\0'; - // Edge case in which all fractional digits were 0. - if (i == 1) { - ns_buffer[0] = '\0'; - } - } else { - break; - } - } - char* full_time_str; - gpr_asprintf(&full_time_str, "%s%sZ", time_buffer, ns_buffer); - return full_time_str; -} - -const char* severity_string(ChannelTrace::Severity severity) { - switch (severity) { - case ChannelTrace::Severity::Info: - return "CT_INFO"; - case ChannelTrace::Severity::Warning: - return "CT_WARNING"; - case ChannelTrace::Severity::Error: - return "CT_ERROR"; - default: - GPR_UNREACHABLE_CODE(return "CT_UNKNOWN"); - } -} - -} // anonymous namespace - -void ChannelTrace::TraceEvent::RenderTraceEvent(grpc_json* json) const { - grpc_json* json_iterator = nullptr; - json_iterator = grpc_json_create_child(json_iterator, json, "description", - grpc_slice_to_c_string(data_), - GRPC_JSON_STRING, true); - json_iterator = grpc_json_create_child(json_iterator, json, "severity", - severity_string(severity_), - GRPC_JSON_STRING, false); - json_iterator = - grpc_json_create_child(json_iterator, json, "timestamp", - fmt_time(timestamp_), GRPC_JSON_STRING, true); - if (referenced_tracer_ != nullptr) { - char* uuid_str; - gpr_asprintf(&uuid_str, "%" PRIdPTR, referenced_tracer_->channel_uuid_); - grpc_json* child_ref = grpc_json_create_child( - json_iterator, json, - (referenced_type_ == Channel) ? "channelRef" : "subchannelRef", nullptr, - GRPC_JSON_OBJECT, false); - json_iterator = grpc_json_create_child( - nullptr, child_ref, - (referenced_type_ == Channel) ? "channelId" : "subchannelId", uuid_str, - GRPC_JSON_STRING, true); - json_iterator = child_ref; - } -} - -char* ChannelTrace::RenderTrace() const { - if (!max_list_size_) - return nullptr; // tracing is disabled if max_events == 0 - grpc_json* json = grpc_json_create(GRPC_JSON_OBJECT); - char* num_events_logged_str; - gpr_asprintf(&num_events_logged_str, "%" PRId64, num_events_logged_); - grpc_json* json_iterator = nullptr; - json_iterator = - grpc_json_create_child(json_iterator, json, "numEventsLogged", - num_events_logged_str, GRPC_JSON_STRING, true); - json_iterator = - grpc_json_create_child(json_iterator, json, "creationTime", - fmt_time(time_created_), GRPC_JSON_STRING, true); - grpc_json* events = grpc_json_create_child(json_iterator, json, "events", - nullptr, GRPC_JSON_ARRAY, false); - json_iterator = nullptr; - TraceEvent* it = head_trace_; - while (it != nullptr) { - json_iterator = grpc_json_create_child(json_iterator, events, nullptr, - nullptr, GRPC_JSON_OBJECT, false); - it->RenderTraceEvent(json_iterator); - it = it->next(); - } - char* json_str = grpc_json_dump_to_string(json, 0); - grpc_json_destroy(json); - return json_str; -} - -} // namespace grpc_core diff --git a/src/core/lib/channel/channel_trace.h b/src/core/lib/channel/channel_trace.h deleted file mode 100644 index 1df1e585f2..0000000000 --- a/src/core/lib/channel/channel_trace.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_LIB_CHANNEL_CHANNEL_TRACE_H -#define GRPC_CORE_LIB_CHANNEL_CHANNEL_TRACE_H - -#include - -#include -#include "src/core/lib/gprpp/ref_counted.h" -#include "src/core/lib/gprpp/ref_counted_ptr.h" -#include "src/core/lib/iomgr/error.h" -#include "src/core/lib/json/json.h" - -namespace grpc_core { - -// Object used to hold live data for a channel. This data is exposed via the -// channelz service: -// https://github.com/grpc/proposal/blob/master/A14-channelz.md -class ChannelTrace : public RefCounted { - public: - ChannelTrace(size_t max_events); - ~ChannelTrace(); - - // returns the tracer's uuid - intptr_t GetUuid() const; - - enum Severity { - Unset = 0, // never to be used - Info, // we start at 1 to avoid using proto default values - Warning, - Error - }; - - // Adds a new trace event to the tracing object - // - // TODO(ncteisen): as this call is used more and more throughout the gRPC - // stack, determine if it makes more sense to accept a char* instead of a - // slice. - void AddTraceEvent(Severity severity, grpc_slice data); - - // Adds a new trace event to the tracing object. This trace event refers to a - // an event on a child of the channel. For example, if this channel has - // created a new subchannel, then it would record that with a TraceEvent - // referencing the new subchannel. - // - // TODO(ncteisen): Once channelz is implemented, the events should reference - // the overall channelz object, not just the ChannelTrace object. - // TODO(ncteisen): as this call is used more and more throughout the gRPC - // stack, determine if it makes more sense to accept a char* instead of a - // slice. - void AddTraceEventReferencingChannel( - Severity severity, grpc_slice data, - RefCountedPtr referenced_tracer); - void AddTraceEventReferencingSubchannel( - Severity severity, grpc_slice data, - RefCountedPtr referenced_tracer); - - // Returns the tracing data rendered as a grpc json string. - // The string is owned by the caller and must be freed. - char* RenderTrace() const; - - private: - // Types of objects that can be references by trace events. - enum ReferencedType { Channel, Subchannel }; - // Private class to encapsulate all the data and bookkeeping needed for a - // a trace event. - class TraceEvent { - public: - // Constructor for a TraceEvent that references a different channel. - // TODO(ncteisen): once channelz is implemented, this should reference the - // overall channelz object, not just the ChannelTrace object - TraceEvent(Severity severity, grpc_slice data, - RefCountedPtr referenced_tracer, - ReferencedType type); - - // Constructor for a TraceEvent that does not reverence a different - // channel. - TraceEvent(Severity severity, grpc_slice data); - - ~TraceEvent(); - - // Renders the data inside of this TraceEvent into a json object. This is - // used by the ChannelTrace, when it is rendering itself. - void RenderTraceEvent(grpc_json* json) const; - - // set and get for the next_ pointer. - TraceEvent* next() const { return next_; } - void set_next(TraceEvent* next) { next_ = next; } - - private: - Severity severity_; - grpc_slice data_; - gpr_timespec timestamp_; - TraceEvent* next_; - // the tracer object for the (sub)channel that this trace event refers to. - RefCountedPtr referenced_tracer_; - // the type that the referenced tracer points to. Unused if this trace - // does not point to any channel or subchannel - ReferencedType referenced_type_; - }; // TraceEvent - - // Internal helper to add and link in a trace event - void AddTraceEventHelper(TraceEvent* new_trace_event); - - gpr_mu tracer_mu_; - intptr_t channel_uuid_; - uint64_t num_events_logged_; - size_t list_size_; - size_t max_list_size_; - TraceEvent* head_trace_; - TraceEvent* tail_trace_; - gpr_timespec time_created_; -}; - -} // namespace grpc_core - -#endif /* GRPC_CORE_LIB_CHANNEL_CHANNEL_TRACE_H */ diff --git a/src/core/lib/channel/channel_trace_registry.cc b/src/core/lib/channel/channel_trace_registry.cc deleted file mode 100644 index 6c82431467..0000000000 --- a/src/core/lib/channel/channel_trace_registry.cc +++ /dev/null @@ -1,80 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/lib/avl/avl.h" -#include "src/core/lib/channel/channel_trace.h" -#include "src/core/lib/channel/channel_trace_registry.h" -#include "src/core/lib/gpr/useful.h" - -#include -#include - -// file global lock and avl. -static gpr_mu g_mu; -static grpc_avl g_avl; -static gpr_atm g_uuid = 0; - -// avl vtable for uuid (intptr_t) -> ChannelTrace -// this table is only looking, it does not own anything. -static void destroy_intptr(void* not_used, void* user_data) {} -static void* copy_intptr(void* key, void* user_data) { return key; } -static long compare_intptr(void* key1, void* key2, void* user_data) { - return GPR_ICMP(key1, key2); -} - -static void destroy_channel_trace(void* trace, void* user_data) {} -static void* copy_channel_trace(void* trace, void* user_data) { return trace; } -static const grpc_avl_vtable avl_vtable = { - destroy_intptr, copy_intptr, compare_intptr, destroy_channel_trace, - copy_channel_trace}; - -void grpc_channel_trace_registry_init() { - gpr_mu_init(&g_mu); - g_avl = grpc_avl_create(&avl_vtable); -} - -void grpc_channel_trace_registry_shutdown() { - grpc_avl_unref(g_avl, nullptr); - gpr_mu_destroy(&g_mu); -} - -intptr_t grpc_channel_trace_registry_register_channel_trace( - grpc_core::ChannelTrace* channel_trace) { - intptr_t prior = gpr_atm_no_barrier_fetch_add(&g_uuid, 1); - gpr_mu_lock(&g_mu); - g_avl = grpc_avl_add(g_avl, (void*)prior, channel_trace, nullptr); - gpr_mu_unlock(&g_mu); - return prior; -} - -void grpc_channel_trace_registry_unregister_channel_trace(intptr_t uuid) { - gpr_mu_lock(&g_mu); - g_avl = grpc_avl_remove(g_avl, (void*)uuid, nullptr); - gpr_mu_unlock(&g_mu); -} - -grpc_core::ChannelTrace* grpc_channel_trace_registry_get_channel_trace( - intptr_t uuid) { - gpr_mu_lock(&g_mu); - grpc_core::ChannelTrace* ret = static_cast( - grpc_avl_get(g_avl, (void*)uuid, nullptr)); - gpr_mu_unlock(&g_mu); - return ret; -} diff --git a/src/core/lib/channel/channel_trace_registry.h b/src/core/lib/channel/channel_trace_registry.h deleted file mode 100644 index 391ecba7de..0000000000 --- a/src/core/lib/channel/channel_trace_registry.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_LIB_CHANNEL_CHANNEL_TRACE_REGISTRY_H -#define GRPC_CORE_LIB_CHANNEL_CHANNEL_TRACE_REGISTRY_H - -#include - -#include "src/core/lib/channel/channel_trace.h" - -#include - -// TODO(ncteisen): convert this file to C++ - -void grpc_channel_trace_registry_init(); -void grpc_channel_trace_registry_shutdown(); - -// globally registers a ChannelTrace. Returns its unique uuid -intptr_t grpc_channel_trace_registry_register_channel_trace( - grpc_core::ChannelTrace* channel_trace); -// globally unregisters the ChannelTrace that is associated to uuid. -void grpc_channel_trace_registry_unregister_channel_trace(intptr_t uuid); -// if object with uuid has previously been registered, returns the ChannelTrace -// associated with that uuid. Else returns nullptr. -grpc_core::ChannelTrace* grpc_channel_trace_registry_get_channel_trace( - intptr_t uuid); - -#endif /* GRPC_CORE_LIB_CHANNEL_CHANNEL_TRACE_REGISTRY_H */ diff --git a/src/core/lib/channel/status_util.cc b/src/core/lib/channel/status_util.cc deleted file mode 100644 index 563db40846..0000000000 --- a/src/core/lib/channel/status_util.cc +++ /dev/null @@ -1,100 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/lib/channel/status_util.h" - -#include "src/core/lib/gpr/useful.h" - -typedef struct { - const char* str; - grpc_status_code status; -} status_string_entry; - -static const status_string_entry g_status_string_entries[] = { - {"OK", GRPC_STATUS_OK}, - {"CANCELLED", GRPC_STATUS_CANCELLED}, - {"UNKNOWN", GRPC_STATUS_UNKNOWN}, - {"INVALID_ARGUMENT", GRPC_STATUS_INVALID_ARGUMENT}, - {"DEADLINE_EXCEEDED", GRPC_STATUS_DEADLINE_EXCEEDED}, - {"NOT_FOUND", GRPC_STATUS_NOT_FOUND}, - {"ALREADY_EXISTS", GRPC_STATUS_ALREADY_EXISTS}, - {"PERMISSION_DENIED", GRPC_STATUS_PERMISSION_DENIED}, - {"UNAUTHENTICATED", GRPC_STATUS_UNAUTHENTICATED}, - {"RESOURCE_EXHAUSTED", GRPC_STATUS_RESOURCE_EXHAUSTED}, - {"FAILED_PRECONDITION", GRPC_STATUS_FAILED_PRECONDITION}, - {"ABORTED", GRPC_STATUS_ABORTED}, - {"OUT_OF_RANGE", GRPC_STATUS_OUT_OF_RANGE}, - {"UNIMPLEMENTED", GRPC_STATUS_UNIMPLEMENTED}, - {"INTERNAL", GRPC_STATUS_INTERNAL}, - {"UNAVAILABLE", GRPC_STATUS_UNAVAILABLE}, - {"DATA_LOSS", GRPC_STATUS_DATA_LOSS}, -}; - -bool grpc_status_code_from_string(const char* status_str, - grpc_status_code* status) { - for (size_t i = 0; i < GPR_ARRAY_SIZE(g_status_string_entries); ++i) { - if (strcmp(status_str, g_status_string_entries[i].str) == 0) { - *status = g_status_string_entries[i].status; - return true; - } - } - return false; -} - -const char* grpc_status_code_to_string(grpc_status_code status) { - switch (status) { - case GRPC_STATUS_OK: - return "OK"; - case GRPC_STATUS_CANCELLED: - return "CANCELLED"; - case GRPC_STATUS_UNKNOWN: - return "UNKNOWN"; - case GRPC_STATUS_INVALID_ARGUMENT: - return "INVALID_ARGUMENT"; - case GRPC_STATUS_DEADLINE_EXCEEDED: - return "DEADLINE_EXCEEDED"; - case GRPC_STATUS_NOT_FOUND: - return "NOT_FOUND"; - case GRPC_STATUS_ALREADY_EXISTS: - return "ALREADY_EXISTS"; - case GRPC_STATUS_PERMISSION_DENIED: - return "PERMISSION_DENIED"; - case GRPC_STATUS_UNAUTHENTICATED: - return "UNAUTHENTICATED"; - case GRPC_STATUS_RESOURCE_EXHAUSTED: - return "RESOURCE_EXHAUSTED"; - case GRPC_STATUS_FAILED_PRECONDITION: - return "FAILED_PRECONDITION"; - case GRPC_STATUS_ABORTED: - return "ABORTED"; - case GRPC_STATUS_OUT_OF_RANGE: - return "OUT_OF_RANGE"; - case GRPC_STATUS_UNIMPLEMENTED: - return "UNIMPLEMENTED"; - case GRPC_STATUS_INTERNAL: - return "INTERNAL"; - case GRPC_STATUS_UNAVAILABLE: - return "UNAVAILABLE"; - case GRPC_STATUS_DATA_LOSS: - return "DATA_LOSS"; - default: - return "UNKNOWN"; - } -} diff --git a/src/core/lib/channel/status_util.h b/src/core/lib/channel/status_util.h deleted file mode 100644 index 5409de6b3c..0000000000 --- a/src/core/lib/channel/status_util.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_LIB_CHANNEL_STATUS_UTIL_H -#define GRPC_CORE_LIB_CHANNEL_STATUS_UTIL_H - -#include - -#include - -#include -#include - -/// If \a status_str is a valid status string, sets \a status to the -/// corresponding status value and returns true. -bool grpc_status_code_from_string(const char* status_str, - grpc_status_code* status); - -/// Returns the string form of \a status, or "UNKNOWN" if invalid. -const char* grpc_status_code_to_string(grpc_status_code status); - -namespace grpc_core { -namespace internal { - -/// A set of grpc_status_code values. -class StatusCodeSet { - public: - bool Empty() const { return status_code_mask_ == 0; } - - void Add(grpc_status_code status) { status_code_mask_ |= (1 << status); } - - bool Contains(grpc_status_code status) const { - return status_code_mask_ & (1 << status); - } - - private: - int status_code_mask_ = 0; // A bitfield of status codes in the set. -}; - -} // namespace internal -} // namespace grpc_core - -#endif /* GRPC_CORE_LIB_CHANNEL_STATUS_UTIL_H */ diff --git a/src/core/lib/json/json.cc b/src/core/lib/json/json.cc index 816241bbf0..2141db4c5b 100644 --- a/src/core/lib/json/json.cc +++ b/src/core/lib/json/json.cc @@ -21,7 +21,6 @@ #include #include -#include #include "src/core/lib/json/json.h" @@ -47,40 +46,5 @@ void grpc_json_destroy(grpc_json* json) { json->parent->child = json->next; } - if (json->owns_value) { - gpr_free((void*)json->value); - } - gpr_free(json); } - -grpc_json* grpc_json_link_child(grpc_json* parent, grpc_json* child, - grpc_json* sibling) { - // first child case. - if (parent->child == nullptr) { - GPR_ASSERT(sibling == nullptr); - parent->child = child; - return child; - } - if (sibling == nullptr) { - sibling = parent->child; - } - // always find the right most sibling. - while (sibling->next != nullptr) { - sibling = sibling->next; - } - sibling->next = child; - return child; -} - -grpc_json* grpc_json_create_child(grpc_json* sibling, grpc_json* parent, - const char* key, const char* value, - grpc_json_type type, bool owns_value) { - grpc_json* child = grpc_json_create(type); - grpc_json_link_child(parent, child, sibling); - child->owns_value = owns_value; - child->parent = parent; - child->value = value; - child->key = key; - return child; -} diff --git a/src/core/lib/json/json.h b/src/core/lib/json/json.h index f93b43048b..3a62ef9cfb 100644 --- a/src/core/lib/json/json.h +++ b/src/core/lib/json/json.h @@ -21,7 +21,6 @@ #include -#include #include #include "src/core/lib/json/json_common.h" @@ -38,9 +37,6 @@ typedef struct grpc_json { grpc_json_type type; const char* key; const char* value; - - /* if set, destructor will free value */ - bool owns_value; } grpc_json; /* The next two functions are going to parse the input string, and @@ -71,24 +67,9 @@ char* grpc_json_dump_to_string(grpc_json* json, int indent); /* Use these to create or delete a grpc_json object. * Deletion is recursive. We will not attempt to free any of the strings - * in any of the objects of that tree, unless the boolean, owns_value, - * is true. + * in any of the objects of that tree. */ grpc_json* grpc_json_create(grpc_json_type type); void grpc_json_destroy(grpc_json* json); -/* Links the child json object into the parent's json tree. If the parent - * already has children, then passing in the most recently added child as the - * sibling parameter is an optimization. For if sibling is NULL, this function - * will manually traverse the tree in order to find the right most sibling. - */ -grpc_json* grpc_json_link_child(grpc_json* parent, grpc_json* child, - grpc_json* sibling); - -/* Creates a child json object into the parent's json tree then links it in - * as described above. */ -grpc_json* grpc_json_create_child(grpc_json* sibling, grpc_json* parent, - const char* key, const char* value, - grpc_json_type type, bool owns_value); - #endif /* GRPC_CORE_LIB_JSON_JSON_H */ diff --git a/src/core/lib/surface/channel.cc b/src/core/lib/surface/channel.cc index cecc15b2df..03353d6beb 100644 --- a/src/core/lib/surface/channel.cc +++ b/src/core/lib/surface/channel.cc @@ -21,7 +21,6 @@ #include "src/core/lib/surface/channel.h" #include -#include #include #include @@ -31,12 +30,8 @@ #include #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/channel/channel_trace.h" #include "src/core/lib/debug/stats.h" #include "src/core/lib/gpr/string.h" -#include "src/core/lib/gprpp/manual_constructor.h" -#include "src/core/lib/gprpp/memory.h" -#include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/iomgr/iomgr.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/surface/api_trace.h" @@ -67,8 +62,6 @@ struct grpc_channel { gpr_mu registered_call_mu; registered_call* registered_calls; - grpc_core::RefCountedPtr tracer; - char* target; }; @@ -100,14 +93,12 @@ grpc_channel* grpc_channel_create_with_builder( grpc_error_string(error)); GRPC_ERROR_UNREF(error); gpr_free(target); - grpc_channel_args_destroy(args); - return channel; + goto done; } memset(channel, 0, sizeof(*channel)); channel->target = target; channel->is_client = grpc_channel_stack_type_is_client(channel_stack_type); - size_t channel_tracer_max_nodes = 0; // default to off gpr_mu_init(&channel->registered_call_mu); channel->registered_calls = nullptr; @@ -170,33 +161,14 @@ grpc_channel* grpc_channel_create_with_builder( channel->compression_options.enabled_algorithms_bitset = static_cast(args->args[i].value.integer) | 0x1; /* always support no compression */ - } else if (0 == strcmp(args->args[i].key, - GRPC_ARG_MAX_CHANNEL_TRACE_EVENTS_PER_NODE)) { - GPR_ASSERT(channel_tracer_max_nodes == 0); - // max_nodes defaults to 0 (which is off), clamped between 0 and INT_MAX - const grpc_integer_options options = {0, 0, INT_MAX}; - channel_tracer_max_nodes = - (size_t)grpc_channel_arg_get_integer(&args->args[i], options); } } +done: grpc_channel_args_destroy(args); - channel->tracer = grpc_core::MakeRefCounted( - channel_tracer_max_nodes); - channel->tracer->AddTraceEvent( - grpc_core::ChannelTrace::Severity::Info, - grpc_slice_from_static_string("Channel created")); return channel; } -char* grpc_channel_get_trace(grpc_channel* channel) { - return channel->tracer->RenderTrace(); -} - -intptr_t grpc_channel_get_uuid(grpc_channel* channel) { - return channel->tracer->GetUuid(); -} - grpc_channel* grpc_channel_create(const char* target, const grpc_channel_args* input_args, grpc_channel_stack_type channel_stack_type, @@ -405,7 +377,6 @@ static void destroy_channel(void* arg, grpc_error* error) { GRPC_MDELEM_UNREF(rc->authority); gpr_free(rc); } - channel->tracer.reset(); GRPC_MDELEM_UNREF(channel->default_authority); gpr_mu_destroy(&channel->registered_call_mu); gpr_free(channel->target); diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc index bd436d6857..ac9f9e6066 100644 --- a/src/core/lib/surface/init.cc +++ b/src/core/lib/surface/init.cc @@ -27,7 +27,6 @@ #include #include #include "src/core/lib/channel/channel_stack.h" -#include "src/core/lib/channel/channel_trace_registry.h" #include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/channel/handshaker_registry.h" #include "src/core/lib/debug/stats.h" @@ -129,7 +128,6 @@ void grpc_init(void) { grpc_slice_intern_init(); grpc_mdctx_global_init(); grpc_channel_init_init(); - grpc_channel_trace_registry_init(); grpc_security_pre_init(); grpc_core::ExecCtx::GlobalInit(); grpc_iomgr_init(); @@ -178,7 +176,6 @@ void grpc_shutdown(void) { grpc_mdctx_global_shutdown(); grpc_handshaker_factory_registry_shutdown(); grpc_slice_intern_shutdown(); - grpc_channel_trace_registry_shutdown(); grpc_stats_shutdown(); } grpc_core::ExecCtx::GlobalShutdown(); diff --git a/src/proto/grpc/channelz/BUILD b/src/proto/grpc/channelz/BUILD deleted file mode 100644 index bdb03d5e2d..0000000000 --- a/src/proto/grpc/channelz/BUILD +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright 2018 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -licenses(["notice"]) # Apache v2 - -load("//bazel:grpc_build_system.bzl", "grpc_proto_library", "grpc_package") - -grpc_package(name = "channelz", visibility = "public") - -grpc_proto_library( - name = "channelz_proto", - srcs = ["channelz.proto"], - has_services = True, - well_known_protos = True, -) diff --git a/src/proto/grpc/channelz/channelz.proto b/src/proto/grpc/channelz/channelz.proto deleted file mode 100644 index 14db66a654..0000000000 --- a/src/proto/grpc/channelz/channelz.proto +++ /dev/null @@ -1,456 +0,0 @@ -// Copyright 2018 gRPC authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -syntax = "proto3"; - -package grpc.channelz; - -import "google/protobuf/any.proto"; -import "google/protobuf/duration.proto"; -import "google/protobuf/timestamp.proto"; -import "google/protobuf/wrappers.proto"; - -// See go/grpc-channelz. - -// Channel is a logical grouping of channels, subchannels, and sockets. -message Channel { - // The identifier for this channel. - ChannelRef ref = 1; - // Data specific to this channel. - ChannelData data = 2; - // At most one of 'channel_ref+subchannel_ref' and 'socket' is set. - - // There are no ordering guarantees on the order of channel refs. - // There may not be cycles in the ref graph. - // A channel ref may be present in more than one channel or subchannel. - repeated ChannelRef channel_ref = 3; - - // At most one of 'channel_ref+subchannel_ref' and 'socket' is set. - // There are no ordering guarantees on the order of subchannel refs. - // There may not be cycles in the ref graph. - // A sub channel ref may be present in more than one channel or subchannel. - repeated SubchannelRef subchannel_ref = 4; - - // There are no ordering guarantees on the order of sockets. - repeated SocketRef socket = 5; -} - -// Subchannel is a logical grouping of channels, subchannels, and sockets. -// A subchannel is load balanced over by it's ancestor -message Subchannel { - // The identifier for this channel. - SubchannelRef ref = 1; - // Data specific to this channel. - ChannelData data = 2; - // At most one of 'channel_ref+subchannel_ref' and 'socket' is set. - - // There are no ordering guarantees on the order of channel refs. - // There may not be cycles in the ref graph. - // A channel ref may be present in more than one channel or subchannel. - repeated ChannelRef channel_ref = 3; - - // At most one of 'channel_ref+subchannel_ref' and 'socket' is set. - // There are no ordering guarantees on the order of subchannel refs. - // There may not be cycles in the ref graph. - // A sub channel ref may be present in more than one channel or subchannel. - repeated SubchannelRef subchannel_ref = 4; - - // There are no ordering guarantees on the order of sockets. - repeated SocketRef socket = 5; -} - -// These come from the specified states in this document: -// https://github.com/grpc/grpc/blob/master/doc/connectivity-semantics-and-api.md -message ChannelConnectivityState { - enum State { - UNKNOWN = 0; - IDLE = 1; - CONNECTING = 2; - READY = 3; - TRANSIENT_FAILURE = 4; - SHUTDOWN = 5; - } - State state = 1; -} - -message ChannelData { - - ChannelConnectivityState state = 1; - - // The target this channel originally tried to connect to. May be absent - string target = 2; - - ChannelTrace trace = 3; - - // The number of calls started on the channel - int64 calls_started = 4; - // The number of calls that have completed with an OK status - int64 calls_succeeded = 5; - // The number of calls that have a completed with a non-OK status - int64 calls_failed = 6; - - // The last time a call was started on the channel. - google.protobuf.Timestamp last_call_started_timestamp = 7; -} - -// A trace event is an interesting thing that happened to a channel or -// subchannel, such as creation, address resolution, subchannel creation, etc. -message ChannelTraceEvent { - // High level description of the event. - string description = 1; - // The supported severity levels of trace events. - enum Severity { - CT_UNKNOWN = 0; - CT_INFO = 1; - CT_WARNING = 2; - CT_ERROR = 3; - } - // the severity of the trace event - Severity severity = 2; - // When this event occurred. - google.protobuf.Timestamp timestamp = 3; - // ref of referenced channel or subchannel. - // Optional, only present if this event refers to a child object. For example, - // this field would be filled if this trace event was for a subchannel being - // created. - oneof child_ref { - ChannelRef channel_ref = 4; - SubchannelRef subchannel_ref = 5; - } -} - -message ChannelTrace { - // Number of events ever logged in this tracing object. This can differ from - // events.size() because events can be overwritten or garbage collected by - // implementations. - int64 num_events_logged = 1; - // Time that this channel was created. - google.protobuf.Timestamp creation_time = 2; - // List of events that have occurred on this channel. - repeated ChannelTraceEvent events = 3; -} - -message ChannelRef { - // The globally unique id for this channel. Must be a positive number. - int64 channel_id = 1; - // An optional name associated with the channel. - string name = 2; - // Intentionally don't use field numbers from other refs. - reserved 3, 4, 5, 6; -} - -message SubchannelRef { - // The globally unique id for this subchannel. Must be a positive number. - int64 subchannel_id = 7; - // An optional name associated with the subchannel. - string name = 8; - // Intentionally don't use field numbers from other refs. - reserved 1, 2, 3, 4, 5, 6; -} - -message SocketRef { - int64 socket_id = 3; - // An optional name associated with the socket. - string name = 4; - // Intentionally don't use field numbers from other refs. - reserved 1, 2, 5, 6, 7, 8; -} - -message ServerRef { - // A globally unique identifier for this server. Must be a positive number. - int64 server_id = 5; - // An optional name associated with the server. - string name = 6; - // Intentionally don't use field numbers from other refs. - reserved 1, 2, 3, 4, 7, 8; -} - -message Server { - ServerRef ref = 1; - ServerData data = 2; - - // The sockets that the server is listening on. There are no ordering - // guarantees. - repeated SocketRef listen_socket = 3; -} - -message ServerData { - ChannelTrace trace = 1; - - // The number of incoming calls started on the server - int64 calls_started = 2; - // The number of incoming calls that have completed with an OK status - int64 calls_succeeded = 3; - // The number of incoming calls that have a completed with a non-OK status - int64 calls_failed = 4; - - // The last time a call was started on the server. - google.protobuf.Timestamp last_call_started_timestamp = 5; -} - -// Information about an actual connection. Pronounced "sock-ay". -message Socket { - SocketRef ref = 1; - - SocketData data = 2; - // The locally bound address. - Address local = 3; - // The remote bound address. May be absent. - Address remote = 4; - Security security = 5; - - // Optional, represents the name of the remote endpoint, if different than - // the original target name. - string remote_name = 6; -} - -message SocketData { - // The number of streams that have been started. - int64 streams_started = 1; - // The number of streams that have ended successfully with the EoS bit set for - // both end points - int64 streams_succeeded = 2; - // The number of incoming streams that have a completed with a non-OK status - int64 streams_failed = 3; - - // The number of messages successfully sent on this socket. - int64 messages_sent = 4; - int64 messages_received = 5; - - // The number of keep alives sent. This is typically implemented with HTTP/2 - // ping messages. - int64 keep_alives_sent = 6; - - // The last time a stream was created by this endpoint. Usually unset for - // servers. - google.protobuf.Timestamp last_local_stream_created_timestamp = 7; - // The last time a stream was created by the remote endpoint. Usually unset - // for clients. - google.protobuf.Timestamp last_remote_stream_created_timestamp = 8; - - // The last time a message was sent by this endpoint. - google.protobuf.Timestamp last_message_sent_timestamp = 9; - // The last time a message was received by this endpoint. - google.protobuf.Timestamp last_message_received_timestamp = 10; - - // The amount of window, granted to the local endpoint by the remote endpoint. - // This may be slightly out of date due to network latency. This does NOT - // include stream level or TCP level flow control info. - google.protobuf.Int64Value local_flow_control_window = 11; - - // The amount of window, granted to the remote endpoint by the local endpoint. - // This may be slightly out of date due to network latency. This does NOT - // include stream level or TCP level flow control info. - google.protobuf.Int64Value remote_flow_control_window = 12; - - repeated SocketOption option = 13; -} - -message Address { - message TcpIpAddress { - // Either the IPv4 or IPv6 address in bytes. Will either be 4 bytes or 16 - // bytes in length. - bytes ip_address = 1; - // 0-64k, or -1 if not appropriate. - int32 port = 2; - } - // A Unix Domain Socket address. - message UdsAddress { - string filename = 1; - } - // An address type not included above. - message OtherAddress { - // The human readable version of the value. - string name = 1; - // The actual address message. - google.protobuf.Any value = 2; - } - - oneof address { - TcpIpAddress tcpip_address = 1; - UdsAddress uds_address = 2; - OtherAddress other_address = 3; - } -} - -message Security { - message Tls { - // The key exchange used. e.g. X25519 - string key_exchange = 1; - // The cipher used. e.g. AES_128_GCM. - string cipher = 2; - // the certificate used by this endpoint. - bytes local_certificate = 3; - // the certificate used by the remote endpoint. - bytes remote_certificate = 4; - } - message OtherSecurity { - // The human readable version of the value. - string name = 1; - // The actual security details message. - google.protobuf.Any value = 2; - } - oneof model { - Tls tls = 1; - OtherSecurity other = 2; - } -} - -message SocketOption { - string name = 1; - // The human readable value of this socket option. At least one of value or - // additional will be set. - string value = 2; - // Additional data associated with the socket option. At least one of value - // or additional will be set. - google.protobuf.Any additional = 3; -} - -// For use with SocketOption's additional field. This is primarily used for -// SO_RCVTIMEO and SO_SNDTIMEO -message SocketOptionTimeout { - google.protobuf.Duration duration = 1; -} - -message SocketOptionLinger { - bool active = 1; - google.protobuf.Duration duration = 2; -} - -// Tcp info for SOL_TCP, TCP_INFO -message SocketOptionTcpInfo { - uint32 tcpi_state = 1; - - uint32 tcpi_ca_state = 2; - uint32 tcpi_retransmits = 3; - uint32 tcpi_probes = 4; - uint32 tcpi_backoff = 5; - uint32 tcpi_options = 6; - uint32 tcpi_snd_wscale = 7; - uint32 tcpi_rcv_wscale = 8; - - uint32 tcpi_rto = 9; - uint32 tcpi_ato = 10; - uint32 tcpi_snd_mss = 11; - uint32 tcpi_rcv_mss = 12; - - uint32 tcpi_unacked = 13; - uint32 tcpi_sacked = 14; - uint32 tcpi_lost = 15; - uint32 tcpi_retrans = 16; - uint32 tcpi_fackets = 17; - - uint32 tcpi_last_data_sent = 18; - uint32 tcpi_last_ack_sent = 19; - uint32 tcpi_last_data_recv = 20; - uint32 tcpi_last_ack_recv = 21; - - uint32 tcpi_pmtu = 22; - uint32 tcpi_rcv_ssthresh = 23; - uint32 tcpi_rtt = 24; - uint32 tcpi_rttvar = 25; - uint32 tcpi_snd_ssthresh = 26; - uint32 tcpi_snd_cwnd = 27; - uint32 tcpi_advmss = 28; - uint32 tcpi_reordering = 29; -} - -service Channelz { - // Gets all root channels (e.g. channels the application has directly - // created). This does not include subchannels nor non-top level channels. - rpc GetTopChannels(GetTopChannelsRequest) returns (GetTopChannelsResponse); - // Gets all servers that exist in the process. - rpc GetServers(GetServersRequest) returns (GetServersResponse); - // Gets all server sockets that exist in the process. - rpc GetServerSockets(GetServerSocketsRequest) returns (GetServerSocketsResponse); - // Returns a single Channel, or else a NOT_FOUND code. - rpc GetChannel(GetChannelRequest) returns (GetChannelResponse); - // Returns a single Subchannel, or else a NOT_FOUND code. - rpc GetSubchannel(GetSubchannelRequest) returns (GetSubchannelResponse); - // Returns a single Socket or else a NOT_FOUND code. - rpc GetSocket(GetSocketRequest) returns (GetSocketResponse); -} - -message GetServersRequest { - // start_server_id indicates that only servers at or above this id should be - // included in the results. - int64 start_server_id = 1; -} - -message GetServersResponse { - // list of servers that the connection detail service knows about. Sorted in - // ascending server_id order. - repeated Server server = 1; - // If set, indicates that the list of servers is the final list. Requesting - // more servers will only return more if they are created after this RPC - // completes. - bool end = 2; -} - -message GetServerSocketsRequest { - int64 server_id = 1; - // start_socket_id indicates that only sockets at or above this id should be - // included in the results. - int64 start_socket_id = 2; -} - -message GetServerSocketsResponse { - // list of socket refs that the connection detail service knows about. Sorted in - // ascending socket_id order. - repeated SocketRef socket_ref = 1; - // If set, indicates that the list of sockets is the final list. Requesting - // more sockets will only return more if they are created after this RPC - // completes. - bool end = 2; -} - -message GetTopChannelsRequest { - // start_channel_id indicates that only channels at or above this id should be - // included in the results. - int64 start_channel_id = 1; -} - -message GetTopChannelsResponse { - // list of channels that the connection detail service knows about. Sorted in - // ascending channel_id order. - repeated Channel channel = 1; - // If set, indicates that the list of channels is the final list. Requesting - // more channels can only return more if they are created after this RPC - // completes. - bool end = 2; -} - -message GetChannelRequest { - int64 channel_id = 1; -} - -message GetChannelResponse { - Channel channel = 1; -} - -message GetSubchannelRequest { - int64 subchannel_id = 1; -} - -message GetSubchannelResponse { - Subchannel subchannel = 1; -} - -message GetSocketRequest { - int64 socket_id = 1; -} - -message GetSocketResponse { - Socket socket = 1; -} diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 9807300527..d96cbec292 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -60,13 +60,10 @@ CORE_SOURCE_FILES = [ 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', - 'src/core/lib/channel/channel_trace.cc', - 'src/core/lib/channel/channel_trace_registry.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', 'src/core/lib/channel/handshaker_registry.cc', - 'src/core/lib/channel/status_util.cc', 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/compression_internal.cc', 'src/core/lib/compression/message_compress.cc', @@ -315,6 +312,7 @@ CORE_SOURCE_FILES = [ 'src/core/ext/filters/client_channel/resolver.cc', 'src/core/ext/filters/client_channel/resolver_registry.cc', 'src/core/ext/filters/client_channel/retry_throttle.cc', + 'src/core/ext/filters/client_channel/status_util.cc', 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.c b/src/ruby/ext/grpc/rb_grpc_imports.generated.c index 1c042739a8..c045480ff4 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.c +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.c @@ -68,8 +68,6 @@ grpc_channel_get_info_type grpc_channel_get_info_import; grpc_insecure_channel_create_type grpc_insecure_channel_create_import; grpc_lame_client_channel_create_type grpc_lame_client_channel_create_import; grpc_channel_destroy_type grpc_channel_destroy_import; -grpc_channel_get_trace_type grpc_channel_get_trace_import; -grpc_channel_get_uuid_type grpc_channel_get_uuid_import; grpc_call_cancel_type grpc_call_cancel_import; grpc_call_cancel_with_status_type grpc_call_cancel_with_status_import; grpc_call_ref_type grpc_call_ref_import; @@ -306,8 +304,6 @@ void grpc_rb_load_imports(HMODULE library) { grpc_insecure_channel_create_import = (grpc_insecure_channel_create_type) GetProcAddress(library, "grpc_insecure_channel_create"); grpc_lame_client_channel_create_import = (grpc_lame_client_channel_create_type) GetProcAddress(library, "grpc_lame_client_channel_create"); grpc_channel_destroy_import = (grpc_channel_destroy_type) GetProcAddress(library, "grpc_channel_destroy"); - grpc_channel_get_trace_import = (grpc_channel_get_trace_type) GetProcAddress(library, "grpc_channel_get_trace"); - grpc_channel_get_uuid_import = (grpc_channel_get_uuid_type) GetProcAddress(library, "grpc_channel_get_uuid"); grpc_call_cancel_import = (grpc_call_cancel_type) GetProcAddress(library, "grpc_call_cancel"); grpc_call_cancel_with_status_import = (grpc_call_cancel_with_status_type) GetProcAddress(library, "grpc_call_cancel_with_status"); grpc_call_ref_import = (grpc_call_ref_type) GetProcAddress(library, "grpc_call_ref"); diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.h b/src/ruby/ext/grpc/rb_grpc_imports.generated.h index 9a09321364..4f07452c68 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.h +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.h @@ -179,12 +179,6 @@ extern grpc_lame_client_channel_create_type grpc_lame_client_channel_create_impo typedef void(*grpc_channel_destroy_type)(grpc_channel* channel); extern grpc_channel_destroy_type grpc_channel_destroy_import; #define grpc_channel_destroy grpc_channel_destroy_import -typedef char*(*grpc_channel_get_trace_type)(grpc_channel* channel); -extern grpc_channel_get_trace_type grpc_channel_get_trace_import; -#define grpc_channel_get_trace grpc_channel_get_trace_import -typedef intptr_t(*grpc_channel_get_uuid_type)(grpc_channel* channel); -extern grpc_channel_get_uuid_type grpc_channel_get_uuid_import; -#define grpc_channel_get_uuid grpc_channel_get_uuid_import typedef grpc_call_error(*grpc_call_cancel_type)(grpc_call* call, void* reserved); extern grpc_call_cancel_type grpc_call_cancel_import; #define grpc_call_cancel grpc_call_cancel_import diff --git a/test/core/channel/BUILD b/test/core/channel/BUILD index 6bf4fcdbb8..c5dfd8ef37 100644 --- a/test/core/channel/BUILD +++ b/test/core/channel/BUILD @@ -65,32 +65,3 @@ grpc_cc_test( "//test/core/util:grpc_test_util", ], ) - -grpc_cc_test( - name = "channel_trace_test", - srcs = ["channel_trace_test.cc"], - language = "C++", - deps = [ - "//:gpr", - "//:grpc", - "//:grpc++", - "//test/core/util:gpr_test_util", - "//test/core/util:grpc_test_util", - "//test/cpp/util:channel_trace_proto_helper", - ], - external_deps = [ - "gtest", - ], -) - -grpc_cc_test( - name = "status_util_test", - srcs = ["status_util_test.cc"], - language = "C++", - deps = [ - "//:grpc", - ], - external_deps = [ - "gtest", - ], -) diff --git a/test/core/channel/channel_trace_test.cc b/test/core/channel/channel_trace_test.cc deleted file mode 100644 index 3c73e33612..0000000000 --- a/test/core/channel/channel_trace_test.cc +++ /dev/null @@ -1,240 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include - -#include - -#include -#include - -#include "src/core/lib/channel/channel_trace.h" -#include "src/core/lib/channel/channel_trace_registry.h" -#include "src/core/lib/gpr/useful.h" -#include "src/core/lib/iomgr/exec_ctx.h" -#include "src/core/lib/json/json.h" - -#include "test/core/util/test_config.h" -#include "test/cpp/util/channel_trace_proto_helper.h" - -// remove me -#include -#include -#include - -namespace grpc_core { -namespace testing { -namespace { - -grpc_json* GetJsonChild(grpc_json* parent, const char* key) { - EXPECT_NE(parent, nullptr); - for (grpc_json* child = parent->child; child != nullptr; - child = child->next) { - if (child->key != nullptr && strcmp(child->key, key) == 0) return child; - } - return nullptr; -} - -void ValidateJsonArraySize(grpc_json* json, const char* key, - size_t expected_size) { - grpc_json* arr = GetJsonChild(json, key); - ASSERT_NE(arr, nullptr); - ASSERT_EQ(arr->type, GRPC_JSON_ARRAY); - size_t count = 0; - for (grpc_json* child = arr->child; child != nullptr; child = child->next) { - ++count; - } - ASSERT_EQ(count, expected_size); -} - -void ValidateChannelTraceData(grpc_json* json, - size_t num_events_logged_expected, - size_t actual_num_events_expected) { - ASSERT_NE(json, nullptr); - grpc_json* num_events_logged_json = GetJsonChild(json, "numEventsLogged"); - ASSERT_NE(num_events_logged_json, nullptr); - grpc_json* start_time = GetJsonChild(json, "creationTime"); - ASSERT_NE(start_time, nullptr); - size_t num_events_logged = - (size_t)strtol(num_events_logged_json->value, nullptr, 0); - ASSERT_EQ(num_events_logged, num_events_logged_expected); - ValidateJsonArraySize(json, "events", actual_num_events_expected); -} - -void AddSimpleTrace(RefCountedPtr tracer) { - tracer->AddTraceEvent(ChannelTrace::Severity::Info, - grpc_slice_from_static_string("simple trace")); -} - -// checks for the existence of all the required members of the tracer. -void ValidateChannelTrace(RefCountedPtr tracer, - size_t expected_num_event_logged, size_t max_nodes) { - if (!max_nodes) return; - char* json_str = tracer->RenderTrace(); - grpc::testing::ValidateChannelTraceProtoJsonTranslation(json_str); - grpc_json* json = grpc_json_parse_string(json_str); - ValidateChannelTraceData(json, expected_num_event_logged, - GPR_MIN(expected_num_event_logged, max_nodes)); - grpc_json_destroy(json); - gpr_free(json_str); -} - -void ValidateTraceDataMatchedUuidLookup(RefCountedPtr tracer) { - intptr_t uuid = tracer->GetUuid(); - if (uuid == -1) return; // Doesn't make sense to lookup if tracing disabled - char* tracer_json_str = tracer->RenderTrace(); - ChannelTrace* uuid_lookup = - grpc_channel_trace_registry_get_channel_trace(uuid); - char* uuid_lookup_json_str = uuid_lookup->RenderTrace(); - EXPECT_EQ(strcmp(tracer_json_str, uuid_lookup_json_str), 0); - gpr_free(tracer_json_str); - gpr_free(uuid_lookup_json_str); -} - -} // anonymous namespace - -class ChannelTracerTest : public ::testing::TestWithParam {}; - -// Tests basic ChannelTrace functionality like construction, adding trace, and -// lookups by uuid. -TEST_P(ChannelTracerTest, BasicTest) { - grpc_core::ExecCtx exec_ctx; - RefCountedPtr tracer = MakeRefCounted(GetParam()); - AddSimpleTrace(tracer); - AddSimpleTrace(tracer); - ValidateTraceDataMatchedUuidLookup(tracer); - tracer->AddTraceEvent(ChannelTrace::Severity::Info, - grpc_slice_from_static_string("trace three")); - tracer->AddTraceEvent(ChannelTrace::Severity::Error, - grpc_slice_from_static_string("trace four error")); - ValidateChannelTrace(tracer, 4, GetParam()); - AddSimpleTrace(tracer); - AddSimpleTrace(tracer); - ValidateChannelTrace(tracer, 6, GetParam()); - AddSimpleTrace(tracer); - AddSimpleTrace(tracer); - AddSimpleTrace(tracer); - AddSimpleTrace(tracer); - ValidateChannelTrace(tracer, 10, GetParam()); - ValidateTraceDataMatchedUuidLookup(tracer); - tracer.reset(nullptr); -} - -// Tests more complex functionality, like a parent channel tracking -// subchannles. This exercises the ref/unref patterns since the parent tracer -// and this function will both hold refs to the subchannel. -TEST_P(ChannelTracerTest, ComplexTest) { - grpc_core::ExecCtx exec_ctx; - RefCountedPtr tracer = MakeRefCounted(GetParam()); - AddSimpleTrace(tracer); - AddSimpleTrace(tracer); - RefCountedPtr sc1 = MakeRefCounted(GetParam()); - tracer->AddTraceEventReferencingSubchannel( - ChannelTrace::Severity::Info, - grpc_slice_from_static_string("subchannel one created"), sc1); - ValidateChannelTrace(tracer, 3, GetParam()); - AddSimpleTrace(sc1); - AddSimpleTrace(sc1); - AddSimpleTrace(sc1); - ValidateChannelTrace(sc1, 3, GetParam()); - AddSimpleTrace(sc1); - AddSimpleTrace(sc1); - AddSimpleTrace(sc1); - ValidateChannelTrace(sc1, 6, GetParam()); - AddSimpleTrace(tracer); - AddSimpleTrace(tracer); - ValidateChannelTrace(tracer, 5, GetParam()); - ValidateTraceDataMatchedUuidLookup(tracer); - RefCountedPtr sc2 = MakeRefCounted(GetParam()); - tracer->AddTraceEventReferencingChannel( - ChannelTrace::Severity::Info, - grpc_slice_from_static_string("LB channel two created"), sc2); - tracer->AddTraceEventReferencingSubchannel( - ChannelTrace::Severity::Warning, - grpc_slice_from_static_string("subchannel one inactive"), sc1); - ValidateChannelTrace(tracer, 7, GetParam()); - AddSimpleTrace(tracer); - AddSimpleTrace(tracer); - AddSimpleTrace(tracer); - AddSimpleTrace(tracer); - AddSimpleTrace(tracer); - AddSimpleTrace(tracer); - ValidateTraceDataMatchedUuidLookup(tracer); - tracer.reset(nullptr); - sc1.reset(nullptr); - sc2.reset(nullptr); -} - -// Test a case in which the parent channel has subchannels and the subchannels -// have connections. Ensures that everything lives as long as it should then -// gets deleted. -TEST_P(ChannelTracerTest, TestNesting) { - grpc_core::ExecCtx exec_ctx; - RefCountedPtr tracer = MakeRefCounted(GetParam()); - AddSimpleTrace(tracer); - AddSimpleTrace(tracer); - ValidateChannelTrace(tracer, 2, GetParam()); - RefCountedPtr sc1 = MakeRefCounted(GetParam()); - tracer->AddTraceEventReferencingChannel( - ChannelTrace::Severity::Info, - grpc_slice_from_static_string("subchannel one created"), sc1); - ValidateChannelTrace(tracer, 3, GetParam()); - AddSimpleTrace(sc1); - RefCountedPtr conn1 = MakeRefCounted(GetParam()); - // nesting one level deeper. - sc1->AddTraceEventReferencingSubchannel( - ChannelTrace::Severity::Info, - grpc_slice_from_static_string("connection one created"), conn1); - ValidateChannelTrace(tracer, 3, GetParam()); - AddSimpleTrace(conn1); - AddSimpleTrace(tracer); - AddSimpleTrace(tracer); - ValidateChannelTrace(tracer, 5, GetParam()); - ValidateChannelTrace(conn1, 1, GetParam()); - RefCountedPtr sc2 = MakeRefCounted(GetParam()); - tracer->AddTraceEventReferencingSubchannel( - ChannelTrace::Severity::Info, - grpc_slice_from_static_string("subchannel two created"), sc2); - // this trace should not get added to the parents children since it is already - // present in the tracer. - tracer->AddTraceEventReferencingChannel( - ChannelTrace::Severity::Warning, - grpc_slice_from_static_string("subchannel one inactive"), sc1); - AddSimpleTrace(tracer); - ValidateChannelTrace(tracer, 8, GetParam()); - tracer.reset(nullptr); - sc1.reset(nullptr); - sc2.reset(nullptr); - conn1.reset(nullptr); -} - -INSTANTIATE_TEST_CASE_P(ChannelTracerTestSweep, ChannelTracerTest, - ::testing::Values(0, 1, 2, 6, 10, 15)); - -} // namespace testing -} // namespace grpc_core - -int main(int argc, char** argv) { - grpc_test_init(argc, argv); - grpc_init(); - ::testing::InitGoogleTest(&argc, argv); - int ret = RUN_ALL_TESTS(); - grpc_shutdown(); - return ret; -} diff --git a/test/core/channel/status_util_test.cc b/test/core/channel/status_util_test.cc deleted file mode 100644 index 1d64bf1995..0000000000 --- a/test/core/channel/status_util_test.cc +++ /dev/null @@ -1,49 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "src/core/lib/channel/status_util.h" - -#include - -namespace grpc_core { -namespace internal { -namespace { - -TEST(StatusCodeSet, Basic) { - StatusCodeSet set; - EXPECT_TRUE(set.Empty()); - EXPECT_FALSE(set.Contains(GRPC_STATUS_OK)); - EXPECT_FALSE(set.Contains(GRPC_STATUS_UNAVAILABLE)); - set.Add(GRPC_STATUS_OK); - EXPECT_FALSE(set.Empty()); - EXPECT_TRUE(set.Contains(GRPC_STATUS_OK)); - EXPECT_FALSE(set.Contains(GRPC_STATUS_UNAVAILABLE)); - set.Add(GRPC_STATUS_UNAVAILABLE); - EXPECT_FALSE(set.Empty()); - EXPECT_TRUE(set.Contains(GRPC_STATUS_OK)); - EXPECT_TRUE(set.Contains(GRPC_STATUS_UNAVAILABLE)); -} - -} // namespace -} // namespace internal -} // namespace grpc_core - -int main(int argc, char** argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/test/core/client_channel/BUILD b/test/core/client_channel/BUILD index 5148dc5f74..d430b722df 100644 --- a/test/core/client_channel/BUILD +++ b/test/core/client_channel/BUILD @@ -53,3 +53,15 @@ grpc_cc_test( "//test/core/util:grpc_test_util", ], ) + +grpc_cc_test( + name = "status_util_test", + srcs = ["status_util_test.cc"], + language = "C++", + deps = [ + "//:grpc", + ], + external_deps = [ + "gtest", + ], +) diff --git a/test/core/client_channel/status_util_test.cc b/test/core/client_channel/status_util_test.cc new file mode 100644 index 0000000000..f944990ad2 --- /dev/null +++ b/test/core/client_channel/status_util_test.cc @@ -0,0 +1,49 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "src/core/ext/filters/client_channel/status_util.h" + +#include + +namespace grpc_core { +namespace internal { +namespace { + +TEST(StatusCodeSet, Basic) { + StatusCodeSet set; + EXPECT_TRUE(set.Empty()); + EXPECT_FALSE(set.Contains(GRPC_STATUS_OK)); + EXPECT_FALSE(set.Contains(GRPC_STATUS_UNAVAILABLE)); + set.Add(GRPC_STATUS_OK); + EXPECT_FALSE(set.Empty()); + EXPECT_TRUE(set.Contains(GRPC_STATUS_OK)); + EXPECT_FALSE(set.Contains(GRPC_STATUS_UNAVAILABLE)); + set.Add(GRPC_STATUS_UNAVAILABLE); + EXPECT_FALSE(set.Empty()); + EXPECT_TRUE(set.Contains(GRPC_STATUS_OK)); + EXPECT_TRUE(set.Contains(GRPC_STATUS_UNAVAILABLE)); +} + +} // namespace +} // namespace internal +} // namespace grpc_core + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test/core/surface/public_headers_must_be_c89.c b/test/core/surface/public_headers_must_be_c89.c index d858603e47..bd4dc0b60e 100644 --- a/test/core/surface/public_headers_must_be_c89.c +++ b/test/core/surface/public_headers_must_be_c89.c @@ -106,8 +106,6 @@ int main(int argc, char **argv) { printf("%lx", (unsigned long) grpc_insecure_channel_create); printf("%lx", (unsigned long) grpc_lame_client_channel_create); printf("%lx", (unsigned long) grpc_channel_destroy); - printf("%lx", (unsigned long) grpc_channel_get_trace); - printf("%lx", (unsigned long) grpc_channel_get_uuid); printf("%lx", (unsigned long) grpc_call_cancel); printf("%lx", (unsigned long) grpc_call_cancel_with_status); printf("%lx", (unsigned long) grpc_call_ref); diff --git a/test/cpp/util/BUILD b/test/cpp/util/BUILD index 4ac8572072..4f84c73820 100644 --- a/test/cpp/util/BUILD +++ b/test/cpp/util/BUILD @@ -84,24 +84,6 @@ grpc_cc_library( ], ) -grpc_cc_library( - name = "channel_trace_proto_helper", - srcs = [ - "channel_trace_proto_helper.cc", - ], - hdrs = [ - "channel_trace_proto_helper.h", - ], - deps = [ - "//:grpc++", - "//src/proto/grpc/channelz:channelz_proto", - ], - external_deps = [ - "gtest", - "protobuf", - ], -) - grpc_cc_library( name = "test_util_unsecure", srcs = GRPCXX_TESTUTIL_SRCS, diff --git a/test/cpp/util/channel_trace_proto_helper.cc b/test/cpp/util/channel_trace_proto_helper.cc deleted file mode 100644 index fbc9f1501c..0000000000 --- a/test/cpp/util/channel_trace_proto_helper.cc +++ /dev/null @@ -1,56 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "test/cpp/util/channel_trace_proto_helper.h" - -#include -#include - -#include -#include -#include - -#include "src/proto/grpc/channelz/channelz.pb.h" - -namespace grpc { -namespace testing { - -void ValidateChannelTraceProtoJsonTranslation(char* tracer_json_c_str) { - std::string tracer_json_str(tracer_json_c_str); - grpc::channelz::ChannelTrace channel_trace; - google::protobuf::util::JsonParseOptions parse_options; - // If the following line is failing, then uncomment the last line of the - // comment, and uncomment the lines that print the two strings. You can - // then compare the output, and determine what fields are missing. - // - // options.ignore_unknown_fields = true; - ASSERT_EQ(google::protobuf::util::JsonStringToMessage( - tracer_json_str, &channel_trace, parse_options), - google::protobuf::util::Status::OK); - std::string proto_json_str; - ASSERT_EQ(google::protobuf::util::MessageToJsonString(channel_trace, - &proto_json_str), - google::protobuf::util::Status::OK); - // uncomment these to compare the the json strings. - // gpr_log(GPR_ERROR, "tracer json: %s", tracer_json_str.c_str()); - // gpr_log(GPR_ERROR, "proto json: %s", proto_json_str.c_str()); - ASSERT_EQ(tracer_json_str, proto_json_str); -} - -} // namespace testing -} // namespace grpc diff --git a/test/cpp/util/channel_trace_proto_helper.h b/test/cpp/util/channel_trace_proto_helper.h deleted file mode 100644 index d7043d9f06..0000000000 --- a/test/cpp/util/channel_trace_proto_helper.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_TEST_CPP_UTIL_CHANNEL_TRACE_PROTO_HELPER_H -#define GRPC_TEST_CPP_UTIL_CHANNEL_TRACE_PROTO_HELPER_H - -namespace grpc { -namespace testing { - -void ValidateChannelTraceProtoJsonTranslation(char* tracer_json_c_str); - -} // namespace testing -} // namespace grpc - -#endif // GRPC_TEST_CPP_UTIL_CHANNEL_TRACE_PROTO_HELPER_H diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index 52a16d6e98..c822d9b3cd 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -1007,14 +1007,11 @@ src/core/lib/backoff/backoff.h \ src/core/lib/channel/channel_args.h \ src/core/lib/channel/channel_stack.h \ src/core/lib/channel/channel_stack_builder.h \ -src/core/lib/channel/channel_trace.h \ -src/core/lib/channel/channel_trace_registry.h \ src/core/lib/channel/connected_channel.h \ src/core/lib/channel/context.h \ src/core/lib/channel/handshaker.h \ src/core/lib/channel/handshaker_factory.h \ src/core/lib/channel/handshaker_registry.h \ -src/core/lib/channel/status_util.h \ src/core/lib/compression/algorithm_metadata.h \ src/core/lib/compression/compression_internal.h \ src/core/lib/compression/message_compress.h \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 2757114b34..212e1d53dd 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -929,6 +929,8 @@ src/core/ext/filters/client_channel/resolver_registry.cc \ src/core/ext/filters/client_channel/resolver_registry.h \ src/core/ext/filters/client_channel/retry_throttle.cc \ src/core/ext/filters/client_channel/retry_throttle.h \ +src/core/ext/filters/client_channel/status_util.cc \ +src/core/ext/filters/client_channel/status_util.h \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel.h \ src/core/ext/filters/client_channel/subchannel_index.cc \ @@ -1032,10 +1034,6 @@ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack.h \ src/core/lib/channel/channel_stack_builder.cc \ src/core/lib/channel/channel_stack_builder.h \ -src/core/lib/channel/channel_trace.cc \ -src/core/lib/channel/channel_trace.h \ -src/core/lib/channel/channel_trace_registry.cc \ -src/core/lib/channel/channel_trace_registry.h \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/connected_channel.h \ src/core/lib/channel/context.h \ @@ -1045,8 +1043,6 @@ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_factory.h \ src/core/lib/channel/handshaker_registry.cc \ src/core/lib/channel/handshaker_registry.h \ -src/core/lib/channel/status_util.cc \ -src/core/lib/channel/status_util.h \ src/core/lib/compression/algorithm_metadata.h \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 08dc3fa9ea..f80cd9f2b5 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -3034,27 +3034,6 @@ "third_party": false, "type": "target" }, - { - "deps": [ - "gpr", - "gpr_test_util", - "grpc", - "grpc++", - "grpc++_channelz_proto", - "grpc++_test", - "grpc++_test_util", - "grpc_test_util" - ], - "headers": [], - "is_filegroup": false, - "language": "c++", - "name": "channel_trace_test", - "src": [ - "test/core/channel/channel_trace_test.cc" - ], - "third_party": false, - "type": "target" - }, { "deps": [ "gpr", @@ -4503,7 +4482,7 @@ "language": "c++", "name": "status_util_test", "src": [ - "test/core/channel/status_util_test.cc" + "test/core/client_channel/status_util_test.cc" ], "third_party": false, "type": "target" @@ -6980,9 +6959,6 @@ "grpc_test_util" ], "headers": [ - "src/proto/grpc/channelz/channelz.grpc.pb.h", - "src/proto/grpc/channelz/channelz.pb.h", - "src/proto/grpc/channelz/channelz_mock.grpc.pb.h", "src/proto/grpc/health/v1/health.grpc.pb.h", "src/proto/grpc/health/v1/health.pb.h", "src/proto/grpc/health/v1/health_mock.grpc.pb.h", @@ -6997,7 +6973,6 @@ "src/proto/grpc/testing/echo_mock.grpc.pb.h", "test/cpp/end2end/test_service_impl.h", "test/cpp/util/byte_buffer_proto_helper.h", - "test/cpp/util/channel_trace_proto_helper.h", "test/cpp/util/create_test_channel.h", "test/cpp/util/string_ref_helper.h", "test/cpp/util/subprocess.h", @@ -7011,8 +6986,6 @@ "test/cpp/end2end/test_service_impl.h", "test/cpp/util/byte_buffer_proto_helper.cc", "test/cpp/util/byte_buffer_proto_helper.h", - "test/cpp/util/channel_trace_proto_helper.cc", - "test/cpp/util/channel_trace_proto_helper.h", "test/cpp/util/create_test_channel.cc", "test/cpp/util/create_test_channel.h", "test/cpp/util/string_ref_helper.cc", @@ -9014,13 +8987,10 @@ "src/core/lib/channel/channel_args.cc", "src/core/lib/channel/channel_stack.cc", "src/core/lib/channel/channel_stack_builder.cc", - "src/core/lib/channel/channel_trace.cc", - "src/core/lib/channel/channel_trace_registry.cc", "src/core/lib/channel/connected_channel.cc", "src/core/lib/channel/handshaker.cc", "src/core/lib/channel/handshaker_factory.cc", "src/core/lib/channel/handshaker_registry.cc", - "src/core/lib/channel/status_util.cc", "src/core/lib/compression/compression.cc", "src/core/lib/compression/compression_internal.cc", "src/core/lib/compression/message_compress.cc", @@ -9185,14 +9155,11 @@ "src/core/lib/channel/channel_args.h", "src/core/lib/channel/channel_stack.h", "src/core/lib/channel/channel_stack_builder.h", - "src/core/lib/channel/channel_trace.h", - "src/core/lib/channel/channel_trace_registry.h", "src/core/lib/channel/connected_channel.h", "src/core/lib/channel/context.h", "src/core/lib/channel/handshaker.h", "src/core/lib/channel/handshaker_factory.h", "src/core/lib/channel/handshaker_registry.h", - "src/core/lib/channel/status_util.h", "src/core/lib/compression/algorithm_metadata.h", "src/core/lib/compression/compression_internal.h", "src/core/lib/compression/message_compress.h", @@ -9334,14 +9301,11 @@ "src/core/lib/channel/channel_args.h", "src/core/lib/channel/channel_stack.h", "src/core/lib/channel/channel_stack_builder.h", - "src/core/lib/channel/channel_trace.h", - "src/core/lib/channel/channel_trace_registry.h", "src/core/lib/channel/connected_channel.h", "src/core/lib/channel/context.h", "src/core/lib/channel/handshaker.h", "src/core/lib/channel/handshaker_factory.h", "src/core/lib/channel/handshaker_registry.h", - "src/core/lib/channel/status_util.h", "src/core/lib/compression/algorithm_metadata.h", "src/core/lib/compression/compression_internal.h", "src/core/lib/compression/message_compress.h", @@ -9489,6 +9453,7 @@ "src/core/ext/filters/client_channel/resolver_factory.h", "src/core/ext/filters/client_channel/resolver_registry.h", "src/core/ext/filters/client_channel/retry_throttle.h", + "src/core/ext/filters/client_channel/status_util.h", "src/core/ext/filters/client_channel/subchannel.h", "src/core/ext/filters/client_channel/subchannel_index.h", "src/core/ext/filters/client_channel/uri_parser.h" @@ -9532,6 +9497,8 @@ "src/core/ext/filters/client_channel/resolver_registry.h", "src/core/ext/filters/client_channel/retry_throttle.cc", "src/core/ext/filters/client_channel/retry_throttle.h", + "src/core/ext/filters/client_channel/status_util.cc", + "src/core/ext/filters/client_channel/status_util.h", "src/core/ext/filters/client_channel/subchannel.cc", "src/core/ext/filters/client_channel/subchannel.h", "src/core/ext/filters/client_channel/subchannel_index.cc", @@ -10470,20 +10437,6 @@ "third_party": false, "type": "filegroup" }, - { - "deps": [], - "headers": [ - "src/proto/grpc/channelz/channelz.grpc.pb.h", - "src/proto/grpc/channelz/channelz.pb.h", - "src/proto/grpc/channelz/channelz_mock.grpc.pb.h" - ], - "is_filegroup": true, - "language": "c++", - "name": "grpc++_channelz_proto", - "src": [], - "third_party": false, - "type": "filegroup" - }, { "deps": [ "grpc_codegen" diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 8a99792108..3d6b6caa2a 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -3649,30 +3649,6 @@ ], "uses_polling": false }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": true, - "language": "c++", - "name": "channel_trace_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": false - }, { "args": [], "benchmark": false, -- cgit v1.2.3 From 3b42f83068618d5888b870874937a185803a2db1 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Mon, 19 Mar 2018 13:22:35 -0700 Subject: Revert "Revert "Channel Tracing Implementation; Part 1"" This reverts commit f2bea3725f8218777268decfd37c7b543f839d9f. --- BUILD | 8 +- CMakeLists.txt | 80 +++- Makefile | 114 +++++- build.yaml | 35 +- config.m4 | 4 +- config.w32 | 4 +- gRPC-C++.podspec | 7 +- gRPC-Core.podspec | 12 +- grpc.def | 2 + grpc.gemspec | 8 +- grpc.gyp | 18 +- include/grpc/grpc.h | 8 + include/grpc/impl/codegen/grpc_types.h | 4 + package.xml | 8 +- .../ext/filters/client_channel/client_channel.cc | 2 +- .../ext/filters/client_channel/method_params.cc | 2 +- .../ext/filters/client_channel/method_params.h | 2 +- src/core/ext/filters/client_channel/status_util.cc | 100 ----- src/core/ext/filters/client_channel/status_util.h | 58 --- src/core/ext/filters/client_channel/subchannel.cc | 1 + src/core/lib/channel/channel_trace.cc | 238 +++++++++++ src/core/lib/channel/channel_trace.h | 133 ++++++ src/core/lib/channel/channel_trace_registry.cc | 80 ++++ src/core/lib/channel/channel_trace_registry.h | 43 ++ src/core/lib/channel/status_util.cc | 100 +++++ src/core/lib/channel/status_util.h | 58 +++ src/core/lib/json/json.cc | 36 ++ src/core/lib/json/json.h | 21 +- src/core/lib/surface/channel.cc | 33 +- src/core/lib/surface/init.cc | 3 + src/proto/grpc/channelz/BUILD | 26 ++ src/proto/grpc/channelz/channelz.proto | 456 +++++++++++++++++++++ src/python/grpcio/grpc_core_dependencies.py | 4 +- src/ruby/ext/grpc/rb_grpc_imports.generated.c | 4 + src/ruby/ext/grpc/rb_grpc_imports.generated.h | 6 + test/core/channel/BUILD | 29 ++ test/core/channel/channel_trace_test.cc | 240 +++++++++++ test/core/channel/status_util_test.cc | 49 +++ test/core/client_channel/BUILD | 12 - test/core/client_channel/status_util_test.cc | 49 --- test/core/surface/public_headers_must_be_c89.c | 2 + test/cpp/util/BUILD | 18 + test/cpp/util/channel_trace_proto_helper.cc | 56 +++ test/cpp/util/channel_trace_proto_helper.h | 30 ++ tools/doxygen/Doxyfile.c++.internal | 3 + tools/doxygen/Doxyfile.core.internal | 8 +- tools/run_tests/generated/sources_and_headers.json | 55 ++- tools/run_tests/generated/tests.json | 24 ++ 48 files changed, 2020 insertions(+), 273 deletions(-) delete mode 100644 src/core/ext/filters/client_channel/status_util.cc delete mode 100644 src/core/ext/filters/client_channel/status_util.h create mode 100644 src/core/lib/channel/channel_trace.cc create mode 100644 src/core/lib/channel/channel_trace.h create mode 100644 src/core/lib/channel/channel_trace_registry.cc create mode 100644 src/core/lib/channel/channel_trace_registry.h create mode 100644 src/core/lib/channel/status_util.cc create mode 100644 src/core/lib/channel/status_util.h create mode 100644 src/proto/grpc/channelz/BUILD create mode 100644 src/proto/grpc/channelz/channelz.proto create mode 100644 test/core/channel/channel_trace_test.cc create mode 100644 test/core/channel/status_util_test.cc delete mode 100644 test/core/client_channel/status_util_test.cc create mode 100644 test/cpp/util/channel_trace_proto_helper.cc create mode 100644 test/cpp/util/channel_trace_proto_helper.h (limited to 'gRPC-C++.podspec') diff --git a/BUILD b/BUILD index 6c18ad94d7..d59d2ad63f 100644 --- a/BUILD +++ b/BUILD @@ -676,6 +676,9 @@ grpc_cc_library( "src/core/lib/channel/channel_args.cc", "src/core/lib/channel/channel_stack.cc", "src/core/lib/channel/channel_stack_builder.cc", + "src/core/lib/channel/channel_trace.cc", + "src/core/lib/channel/channel_trace_registry.cc", + "src/core/lib/channel/status_util.cc", "src/core/lib/channel/connected_channel.cc", "src/core/lib/channel/handshaker.cc", "src/core/lib/channel/handshaker_factory.cc", @@ -820,6 +823,9 @@ grpc_cc_library( "src/core/lib/channel/channel_args.h", "src/core/lib/channel/channel_stack.h", "src/core/lib/channel/channel_stack_builder.h", + "src/core/lib/channel/channel_trace.h", + "src/core/lib/channel/channel_trace_registry.h", + "src/core/lib/channel/status_util.h", "src/core/lib/channel/connected_channel.h", "src/core/lib/channel/context.h", "src/core/lib/channel/handshaker.h", @@ -1016,7 +1022,6 @@ grpc_cc_library( "src/core/ext/filters/client_channel/resolver.cc", "src/core/ext/filters/client_channel/resolver_registry.cc", "src/core/ext/filters/client_channel/retry_throttle.cc", - "src/core/ext/filters/client_channel/status_util.cc", "src/core/ext/filters/client_channel/subchannel.cc", "src/core/ext/filters/client_channel/subchannel_index.cc", "src/core/ext/filters/client_channel/uri_parser.cc", @@ -1039,7 +1044,6 @@ grpc_cc_library( "src/core/ext/filters/client_channel/resolver_factory.h", "src/core/ext/filters/client_channel/resolver_registry.h", "src/core/ext/filters/client_channel/retry_throttle.h", - "src/core/ext/filters/client_channel/status_util.h", "src/core/ext/filters/client_channel/subchannel.h", "src/core/ext/filters/client_channel/subchannel_index.h", "src/core/ext/filters/client_channel/uri_parser.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index 77e84a0df8..56dcb4671b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -532,6 +532,7 @@ endif() add_dependencies(buildtests_cxx byte_stream_test) add_dependencies(buildtests_cxx channel_arguments_test) add_dependencies(buildtests_cxx channel_filter_test) +add_dependencies(buildtests_cxx channel_trace_test) add_dependencies(buildtests_cxx check_gcp_environment_linux_test) add_dependencies(buildtests_cxx check_gcp_environment_windows_test) add_dependencies(buildtests_cxx chttp2_settings_timeout_test) @@ -855,10 +856,13 @@ add_library(grpc src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc + src/core/lib/channel/channel_trace.cc + src/core/lib/channel/channel_trace_registry.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc src/core/lib/channel/handshaker_registry.cc + src/core/lib/channel/status_util.cc src/core/lib/compression/compression.cc src/core/lib/compression/compression_internal.cc src/core/lib/compression/message_compress.cc @@ -1107,7 +1111,6 @@ add_library(grpc src/core/ext/filters/client_channel/resolver.cc src/core/ext/filters/client_channel/resolver_registry.cc src/core/ext/filters/client_channel/retry_throttle.cc - src/core/ext/filters/client_channel/status_util.cc src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc @@ -1241,10 +1244,13 @@ add_library(grpc_cronet src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc + src/core/lib/channel/channel_trace.cc + src/core/lib/channel/channel_trace_registry.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc src/core/lib/channel/handshaker_registry.cc + src/core/lib/channel/status_util.cc src/core/lib/compression/compression.cc src/core/lib/compression/compression_internal.cc src/core/lib/compression/message_compress.cc @@ -1431,7 +1437,6 @@ add_library(grpc_cronet src/core/ext/filters/client_channel/resolver.cc src/core/ext/filters/client_channel/resolver_registry.cc src/core/ext/filters/client_channel/retry_throttle.cc - src/core/ext/filters/client_channel/status_util.cc src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc @@ -1618,10 +1623,13 @@ add_library(grpc_test_util src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc + src/core/lib/channel/channel_trace.cc + src/core/lib/channel/channel_trace_registry.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc src/core/lib/channel/handshaker_registry.cc + src/core/lib/channel/status_util.cc src/core/lib/compression/compression.cc src/core/lib/compression/compression_internal.cc src/core/lib/compression/message_compress.cc @@ -1777,7 +1785,6 @@ add_library(grpc_test_util src/core/ext/filters/client_channel/resolver.cc src/core/ext/filters/client_channel/resolver_registry.cc src/core/ext/filters/client_channel/retry_throttle.cc - src/core/ext/filters/client_channel/status_util.cc src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc @@ -1918,10 +1925,13 @@ add_library(grpc_test_util_unsecure src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc + src/core/lib/channel/channel_trace.cc + src/core/lib/channel/channel_trace_registry.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc src/core/lib/channel/handshaker_registry.cc + src/core/lib/channel/status_util.cc src/core/lib/compression/compression.cc src/core/lib/compression/compression_internal.cc src/core/lib/compression/message_compress.cc @@ -2077,7 +2087,6 @@ add_library(grpc_test_util_unsecure src/core/ext/filters/client_channel/resolver.cc src/core/ext/filters/client_channel/resolver_registry.cc src/core/ext/filters/client_channel/retry_throttle.cc - src/core/ext/filters/client_channel/status_util.cc src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc @@ -2198,10 +2207,13 @@ add_library(grpc_unsecure src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc + src/core/lib/channel/channel_trace.cc + src/core/lib/channel/channel_trace_registry.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc src/core/lib/channel/handshaker_registry.cc + src/core/lib/channel/status_util.cc src/core/lib/compression/compression.cc src/core/lib/compression/compression_internal.cc src/core/lib/compression/message_compress.cc @@ -2390,7 +2402,6 @@ add_library(grpc_unsecure src/core/ext/filters/client_channel/resolver.cc src/core/ext/filters/client_channel/resolver_registry.cc src/core/ext/filters/client_channel/retry_throttle.cc - src/core/ext/filters/client_channel/status_util.cc src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc @@ -3012,10 +3023,13 @@ add_library(grpc++_cronet src/core/lib/channel/channel_args.cc src/core/lib/channel/channel_stack.cc src/core/lib/channel/channel_stack_builder.cc + src/core/lib/channel/channel_trace.cc + src/core/lib/channel/channel_trace_registry.cc src/core/lib/channel/connected_channel.cc src/core/lib/channel/handshaker.cc src/core/lib/channel/handshaker_factory.cc src/core/lib/channel/handshaker_registry.cc + src/core/lib/channel/status_util.cc src/core/lib/compression/compression.cc src/core/lib/compression/compression_internal.cc src/core/lib/compression/message_compress.cc @@ -3176,7 +3190,6 @@ add_library(grpc++_cronet src/core/ext/filters/client_channel/resolver.cc src/core/ext/filters/client_channel/resolver_registry.cc src/core/ext/filters/client_channel/retry_throttle.cc - src/core/ext/filters/client_channel/status_util.cc src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc @@ -3681,6 +3694,10 @@ if (gRPC_BUILD_TESTS) if (gRPC_BUILD_CODEGEN) add_library(grpc++_test_util + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/channelz/channelz.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/channelz/channelz.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/channelz/channelz.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/channelz/channelz.grpc.pb.h ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/health/v1/health.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/health/v1/health.grpc.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/health/v1/health.pb.h @@ -3700,6 +3717,7 @@ add_library(grpc++_test_util ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h test/cpp/end2end/test_service_impl.cc test/cpp/util/byte_buffer_proto_helper.cc + test/cpp/util/channel_trace_proto_helper.cc test/cpp/util/create_test_channel.cc test/cpp/util/string_ref_helper.cc test/cpp/util/subprocess.cc @@ -3718,6 +3736,9 @@ if(WIN32 AND MSVC) endif() endif() +protobuf_generate_grpc_cpp( + src/proto/grpc/channelz/channelz.proto +) protobuf_generate_grpc_cpp( src/proto/grpc/health/v1/health.proto ) @@ -10128,6 +10149,51 @@ target_link_libraries(channel_filter_test endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +add_executable(channel_trace_test + test/core/channel/channel_trace_test.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/channelz/channelz.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/channelz/channelz.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/channelz/channelz.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/channelz/channelz.grpc.pb.h + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + +protobuf_generate_grpc_cpp( + src/proto/grpc/channelz/channelz.proto +) + +target_include_directories(channel_trace_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${_gRPC_SSL_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} + PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} + PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} + PRIVATE ${_gRPC_CARES_INCLUDE_DIR} + PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} + PRIVATE third_party/googletest/googletest/include + PRIVATE third_party/googletest/googletest + PRIVATE third_party/googletest/googlemock/include + PRIVATE third_party/googletest/googlemock + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(channel_trace_test + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc_test_util + grpc++_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + add_executable(check_gcp_environment_linux_test test/core/security/check_gcp_environment_linux_test.cc third_party/googletest/googletest/src/gtest-all.cc @@ -13073,7 +13139,7 @@ endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) add_executable(status_util_test - test/core/client_channel/status_util_test.cc + test/core/channel/status_util_test.cc third_party/googletest/googletest/src/gtest-all.cc third_party/googletest/googlemock/src/gmock-all.cc ) diff --git a/Makefile b/Makefile index 3fa0f6617b..50889716bd 100644 --- a/Makefile +++ b/Makefile @@ -1129,6 +1129,7 @@ bm_pollset: $(BINDIR)/$(CONFIG)/bm_pollset byte_stream_test: $(BINDIR)/$(CONFIG)/byte_stream_test channel_arguments_test: $(BINDIR)/$(CONFIG)/channel_arguments_test channel_filter_test: $(BINDIR)/$(CONFIG)/channel_filter_test +channel_trace_test: $(BINDIR)/$(CONFIG)/channel_trace_test check_gcp_environment_linux_test: $(BINDIR)/$(CONFIG)/check_gcp_environment_linux_test check_gcp_environment_windows_test: $(BINDIR)/$(CONFIG)/check_gcp_environment_windows_test chttp2_settings_timeout_test: $(BINDIR)/$(CONFIG)/chttp2_settings_timeout_test @@ -1614,6 +1615,7 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/byte_stream_test \ $(BINDIR)/$(CONFIG)/channel_arguments_test \ $(BINDIR)/$(CONFIG)/channel_filter_test \ + $(BINDIR)/$(CONFIG)/channel_trace_test \ $(BINDIR)/$(CONFIG)/check_gcp_environment_linux_test \ $(BINDIR)/$(CONFIG)/check_gcp_environment_windows_test \ $(BINDIR)/$(CONFIG)/chttp2_settings_timeout_test \ @@ -1780,6 +1782,7 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/byte_stream_test \ $(BINDIR)/$(CONFIG)/channel_arguments_test \ $(BINDIR)/$(CONFIG)/channel_filter_test \ + $(BINDIR)/$(CONFIG)/channel_trace_test \ $(BINDIR)/$(CONFIG)/check_gcp_environment_linux_test \ $(BINDIR)/$(CONFIG)/check_gcp_environment_windows_test \ $(BINDIR)/$(CONFIG)/chttp2_settings_timeout_test \ @@ -2205,6 +2208,8 @@ test_cxx: buildtests_cxx $(Q) $(BINDIR)/$(CONFIG)/channel_arguments_test || ( echo test channel_arguments_test failed ; exit 1 ) $(E) "[RUN] Testing channel_filter_test" $(Q) $(BINDIR)/$(CONFIG)/channel_filter_test || ( echo test channel_filter_test failed ; exit 1 ) + $(E) "[RUN] Testing channel_trace_test" + $(Q) $(BINDIR)/$(CONFIG)/channel_trace_test || ( echo test channel_trace_test failed ; exit 1 ) $(E) "[RUN] Testing check_gcp_environment_linux_test" $(Q) $(BINDIR)/$(CONFIG)/check_gcp_environment_linux_test || ( echo test check_gcp_environment_linux_test failed ; exit 1 ) $(E) "[RUN] Testing check_gcp_environment_windows_test" @@ -2443,6 +2448,22 @@ $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc: $(Q) mkdir -p $(@D) $(Q) echo "$(GRPCXX_UNSECURE_PC_FILE)" | tr , '\n' >$@ +ifeq ($(NO_PROTOC),true) +$(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc: protoc_dep_error +$(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc: protoc_dep_error +else + +$(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc: src/proto/grpc/channelz/channelz.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) + $(E) "[PROTOC] Generating protobuf CC file from $<" + $(Q) mkdir -p `dirname $@` + $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --cpp_out=$(GENDIR) $< + +$(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc: src/proto/grpc/channelz/channelz.proto $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(PROTOBUF_DEP) $(PROTOC_PLUGINS) + $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<" + $(Q) mkdir -p `dirname $@` + $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(PROTOC_PLUGINS_DIR)/grpc_cpp_plugin$(EXECUTABLE_SUFFIX) $< +endif + ifeq ($(NO_PROTOC),true) $(GENDIR)/src/proto/grpc/core/stats.pb.cc: protoc_dep_error $(GENDIR)/src/proto/grpc/core/stats.grpc.pb.cc: protoc_dep_error @@ -3160,10 +3181,13 @@ LIBGRPC_SRC = \ src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ + src/core/lib/channel/channel_trace.cc \ + src/core/lib/channel/channel_trace_registry.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ + src/core/lib/channel/status_util.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ @@ -3412,7 +3436,6 @@ LIBGRPC_SRC = \ src/core/ext/filters/client_channel/resolver.cc \ src/core/ext/filters/client_channel/resolver_registry.cc \ src/core/ext/filters/client_channel/retry_throttle.cc \ - src/core/ext/filters/client_channel/status_util.cc \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ @@ -3548,10 +3571,13 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ + src/core/lib/channel/channel_trace.cc \ + src/core/lib/channel/channel_trace_registry.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ + src/core/lib/channel/status_util.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ @@ -3738,7 +3764,6 @@ LIBGRPC_CRONET_SRC = \ src/core/ext/filters/client_channel/resolver.cc \ src/core/ext/filters/client_channel/resolver_registry.cc \ src/core/ext/filters/client_channel/retry_throttle.cc \ - src/core/ext/filters/client_channel/status_util.cc \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ @@ -3926,10 +3951,13 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ + src/core/lib/channel/channel_trace.cc \ + src/core/lib/channel/channel_trace_registry.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ + src/core/lib/channel/status_util.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ @@ -4085,7 +4113,6 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/ext/filters/client_channel/resolver.cc \ src/core/ext/filters/client_channel/resolver_registry.cc \ src/core/ext/filters/client_channel/retry_throttle.cc \ - src/core/ext/filters/client_channel/status_util.cc \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ @@ -4219,10 +4246,13 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ + src/core/lib/channel/channel_trace.cc \ + src/core/lib/channel/channel_trace_registry.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ + src/core/lib/channel/status_util.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ @@ -4378,7 +4408,6 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ src/core/ext/filters/client_channel/resolver.cc \ src/core/ext/filters/client_channel/resolver_registry.cc \ src/core/ext/filters/client_channel/retry_throttle.cc \ - src/core/ext/filters/client_channel/status_util.cc \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ @@ -4479,10 +4508,13 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ + src/core/lib/channel/channel_trace.cc \ + src/core/lib/channel/channel_trace_registry.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ + src/core/lib/channel/status_util.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ @@ -4671,7 +4703,6 @@ LIBGRPC_UNSECURE_SRC = \ src/core/ext/filters/client_channel/resolver.cc \ src/core/ext/filters/client_channel/resolver_registry.cc \ src/core/ext/filters/client_channel/retry_throttle.cc \ - src/core/ext/filters/client_channel/status_util.cc \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ @@ -5292,10 +5323,13 @@ LIBGRPC++_CRONET_SRC = \ src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ + src/core/lib/channel/channel_trace.cc \ + src/core/lib/channel/channel_trace_registry.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ + src/core/lib/channel/status_util.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ @@ -5456,7 +5490,6 @@ LIBGRPC++_CRONET_SRC = \ src/core/ext/filters/client_channel/resolver.cc \ src/core/ext/filters/client_channel/resolver_registry.cc \ src/core/ext/filters/client_channel/retry_throttle.cc \ - src/core/ext/filters/client_channel/status_util.cc \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ @@ -5984,12 +6017,14 @@ endif LIBGRPC++_TEST_UTIL_SRC = \ + $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc \ $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc \ $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc \ $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc \ $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc \ test/cpp/end2end/test_service_impl.cc \ test/cpp/util/byte_buffer_proto_helper.cc \ + test/cpp/util/channel_trace_proto_helper.cc \ test/cpp/util/create_test_channel.cc \ test/cpp/util/string_ref_helper.cc \ test/cpp/util/subprocess.cc \ @@ -6125,13 +6160,14 @@ ifneq ($(NO_DEPS),true) -include $(LIBGRPC++_TEST_UTIL_OBJS:.o=.dep) endif endif -$(OBJDIR)/$(CONFIG)/test/cpp/end2end/test_service_impl.o: $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc -$(OBJDIR)/$(CONFIG)/test/cpp/util/byte_buffer_proto_helper.o: $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc -$(OBJDIR)/$(CONFIG)/test/cpp/util/create_test_channel.o: $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc -$(OBJDIR)/$(CONFIG)/test/cpp/util/string_ref_helper.o: $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc -$(OBJDIR)/$(CONFIG)/test/cpp/util/subprocess.o: $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc -$(OBJDIR)/$(CONFIG)/test/cpp/util/test_credentials_provider.o: $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc -$(OBJDIR)/$(CONFIG)/src/cpp/codegen/codegen_init.o: $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc +$(OBJDIR)/$(CONFIG)/test/cpp/end2end/test_service_impl.o: $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc +$(OBJDIR)/$(CONFIG)/test/cpp/util/byte_buffer_proto_helper.o: $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc +$(OBJDIR)/$(CONFIG)/test/cpp/util/channel_trace_proto_helper.o: $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc +$(OBJDIR)/$(CONFIG)/test/cpp/util/create_test_channel.o: $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc +$(OBJDIR)/$(CONFIG)/test/cpp/util/string_ref_helper.o: $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc +$(OBJDIR)/$(CONFIG)/test/cpp/util/subprocess.o: $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc +$(OBJDIR)/$(CONFIG)/test/cpp/util/test_credentials_provider.o: $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc +$(OBJDIR)/$(CONFIG)/src/cpp/codegen/codegen_init.o: $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc LIBGRPC++_TEST_UTIL_UNSECURE_SRC = \ @@ -15989,6 +16025,53 @@ endif endif +CHANNEL_TRACE_TEST_SRC = \ + test/core/channel/channel_trace_test.cc \ + $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc \ + +CHANNEL_TRACE_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(CHANNEL_TRACE_TEST_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/channel_trace_test: openssl_dep_error + +else + + + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/channel_trace_test: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/channel_trace_test: $(PROTOBUF_DEP) $(CHANNEL_TRACE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(CHANNEL_TRACE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/channel_trace_test + +endif + +endif + +$(OBJDIR)/$(CONFIG)/test/core/channel/channel_trace_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + +$(OBJDIR)/$(CONFIG)/src/proto/grpc/channelz/channelz.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_channel_trace_test: $(CHANNEL_TRACE_TEST_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(CHANNEL_TRACE_TEST_OBJS:.o=.dep) +endif +endif +$(OBJDIR)/$(CONFIG)/test/core/channel/channel_trace_test.o: $(GENDIR)/src/proto/grpc/channelz/channelz.pb.cc $(GENDIR)/src/proto/grpc/channelz/channelz.grpc.pb.cc + + CHECK_GCP_ENVIRONMENT_LINUX_TEST_SRC = \ test/core/security/check_gcp_environment_linux_test.cc \ @@ -19111,7 +19194,7 @@ endif STATUS_UTIL_TEST_SRC = \ - test/core/client_channel/status_util_test.cc \ + test/core/channel/status_util_test.cc \ STATUS_UTIL_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(STATUS_UTIL_TEST_SRC)))) ifeq ($(NO_SECURE),true) @@ -19142,7 +19225,7 @@ endif endif -$(OBJDIR)/$(CONFIG)/test/core/client_channel/status_util_test.o: $(LIBDIR)/$(CONFIG)/libgrpc.a +$(OBJDIR)/$(CONFIG)/test/core/channel/status_util_test.o: $(LIBDIR)/$(CONFIG)/libgrpc.a deps_status_util_test: $(STATUS_UTIL_TEST_OBJS:.o=.dep) @@ -23554,6 +23637,7 @@ test/cpp/qps/server_async.cc: $(OPENSSL_DEP) test/cpp/qps/server_sync.cc: $(OPENSSL_DEP) test/cpp/qps/usage_timer.cc: $(OPENSSL_DEP) test/cpp/util/byte_buffer_proto_helper.cc: $(OPENSSL_DEP) +test/cpp/util/channel_trace_proto_helper.cc: $(OPENSSL_DEP) test/cpp/util/cli_call.cc: $(OPENSSL_DEP) test/cpp/util/cli_credentials.cc: $(OPENSSL_DEP) test/cpp/util/create_test_channel.cc: $(OPENSSL_DEP) diff --git a/build.yaml b/build.yaml index a4875df9e5..0dd3d36d8c 100644 --- a/build.yaml +++ b/build.yaml @@ -232,10 +232,13 @@ filegroups: - src/core/lib/channel/channel_args.cc - src/core/lib/channel/channel_stack.cc - src/core/lib/channel/channel_stack_builder.cc + - src/core/lib/channel/channel_trace.cc + - src/core/lib/channel/channel_trace_registry.cc - src/core/lib/channel/connected_channel.cc - src/core/lib/channel/handshaker.cc - src/core/lib/channel/handshaker_factory.cc - src/core/lib/channel/handshaker_registry.cc + - src/core/lib/channel/status_util.cc - src/core/lib/compression/compression.cc - src/core/lib/compression/compression_internal.cc - src/core/lib/compression/message_compress.cc @@ -399,11 +402,14 @@ filegroups: - src/core/lib/channel/channel_args.h - src/core/lib/channel/channel_stack.h - src/core/lib/channel/channel_stack_builder.h + - src/core/lib/channel/channel_trace.h + - src/core/lib/channel/channel_trace_registry.h - src/core/lib/channel/connected_channel.h - src/core/lib/channel/context.h - src/core/lib/channel/handshaker.h - src/core/lib/channel/handshaker_factory.h - src/core/lib/channel/handshaker_registry.h + - src/core/lib/channel/status_util.h - src/core/lib/compression/algorithm_metadata.h - src/core/lib/compression/compression_internal.h - src/core/lib/compression/message_compress.h @@ -547,7 +553,6 @@ filegroups: - src/core/ext/filters/client_channel/resolver_factory.h - src/core/ext/filters/client_channel/resolver_registry.h - src/core/ext/filters/client_channel/retry_throttle.h - - src/core/ext/filters/client_channel/status_util.h - src/core/ext/filters/client_channel/subchannel.h - src/core/ext/filters/client_channel/subchannel_index.h - src/core/ext/filters/client_channel/uri_parser.h @@ -570,7 +575,6 @@ filegroups: - src/core/ext/filters/client_channel/resolver.cc - src/core/ext/filters/client_channel/resolver_registry.cc - src/core/ext/filters/client_channel/retry_throttle.cc - - src/core/ext/filters/client_channel/status_util.cc - src/core/ext/filters/client_channel/subchannel.cc - src/core/ext/filters/client_channel/subchannel_index.cc - src/core/ext/filters/client_channel/uri_parser.cc @@ -1066,6 +1070,10 @@ filegroups: secure: true uses: - grpc_trace +- name: grpc++_channelz_proto + language: c++ + src: + - src/proto/grpc/channelz/channelz.proto - name: grpc++_codegen_base language: c++ public_headers: @@ -1614,17 +1622,20 @@ libs: headers: - test/cpp/end2end/test_service_impl.h - test/cpp/util/byte_buffer_proto_helper.h + - test/cpp/util/channel_trace_proto_helper.h - test/cpp/util/create_test_channel.h - test/cpp/util/string_ref_helper.h - test/cpp/util/subprocess.h - test/cpp/util/test_credentials_provider.h src: + - src/proto/grpc/channelz/channelz.proto - src/proto/grpc/health/v1/health.proto - src/proto/grpc/testing/echo_messages.proto - src/proto/grpc/testing/echo.proto - src/proto/grpc/testing/duplicate/echo_duplicate.proto - test/cpp/end2end/test_service_impl.cc - test/cpp/util/byte_buffer_proto_helper.cc + - test/cpp/util/channel_trace_proto_helper.cc - test/cpp/util/create_test_channel.cc - test/cpp/util/string_ref_helper.cc - test/cpp/util/subprocess.cc @@ -4107,6 +4118,24 @@ targets: - grpc - gpr uses_polling: false +- name: channel_trace_test + gtest: true + build: test + language: c++ + src: + - test/core/channel/channel_trace_test.cc + deps: + - grpc_test_util + - grpc++_test_util + - grpc++ + - grpc + - gpr_test_util + - gpr + filegroups: + - grpc++_channelz_proto + uses: + - grpc++_test + uses_polling: false - name: check_gcp_environment_linux_test build: test language: c++ @@ -5128,7 +5157,7 @@ targets: build: test language: c++ src: - - test/core/client_channel/status_util_test.cc + - test/core/channel/status_util_test.cc deps: - grpc uses_polling: false diff --git a/config.m4 b/config.m4 index 2f17d0c4b7..3a81f9d7f9 100644 --- a/config.m4 +++ b/config.m4 @@ -84,10 +84,13 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/channel/channel_args.cc \ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack_builder.cc \ + src/core/lib/channel/channel_trace.cc \ + src/core/lib/channel/channel_trace_registry.cc \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/handshaker.cc \ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_registry.cc \ + src/core/lib/channel/status_util.cc \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ src/core/lib/compression/message_compress.cc \ @@ -336,7 +339,6 @@ if test "$PHP_GRPC" != "no"; then src/core/ext/filters/client_channel/resolver.cc \ src/core/ext/filters/client_channel/resolver_registry.cc \ src/core/ext/filters/client_channel/retry_throttle.cc \ - src/core/ext/filters/client_channel/status_util.cc \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ diff --git a/config.w32 b/config.w32 index 78f2fe079d..76be896e44 100644 --- a/config.w32 +++ b/config.w32 @@ -61,10 +61,13 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\channel\\channel_args.cc " + "src\\core\\lib\\channel\\channel_stack.cc " + "src\\core\\lib\\channel\\channel_stack_builder.cc " + + "src\\core\\lib\\channel\\channel_trace.cc " + + "src\\core\\lib\\channel\\channel_trace_registry.cc " + "src\\core\\lib\\channel\\connected_channel.cc " + "src\\core\\lib\\channel\\handshaker.cc " + "src\\core\\lib\\channel\\handshaker_factory.cc " + "src\\core\\lib\\channel\\handshaker_registry.cc " + + "src\\core\\lib\\channel\\status_util.cc " + "src\\core\\lib\\compression\\compression.cc " + "src\\core\\lib\\compression\\compression_internal.cc " + "src\\core\\lib\\compression\\message_compress.cc " + @@ -313,7 +316,6 @@ if (PHP_GRPC != "no") { "src\\core\\ext\\filters\\client_channel\\resolver.cc " + "src\\core\\ext\\filters\\client_channel\\resolver_registry.cc " + "src\\core\\ext\\filters\\client_channel\\retry_throttle.cc " + - "src\\core\\ext\\filters\\client_channel\\status_util.cc " + "src\\core\\ext\\filters\\client_channel\\subchannel.cc " + "src\\core\\ext\\filters\\client_channel\\subchannel_index.cc " + "src\\core\\ext\\filters\\client_channel\\uri_parser.cc " + diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index e1282611b0..f42bd4f81c 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -326,7 +326,6 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/resolver_factory.h', 'src/core/ext/filters/client_channel/resolver_registry.h', 'src/core/ext/filters/client_channel/retry_throttle.h', - 'src/core/ext/filters/client_channel/status_util.h', 'src/core/ext/filters/client_channel/subchannel.h', 'src/core/ext/filters/client_channel/subchannel_index.h', 'src/core/ext/filters/client_channel/uri_parser.h', @@ -343,11 +342,14 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.h', 'src/core/lib/channel/channel_stack.h', 'src/core/lib/channel/channel_stack_builder.h', + 'src/core/lib/channel/channel_trace.h', + 'src/core/lib/channel/channel_trace_registry.h', 'src/core/lib/channel/connected_channel.h', 'src/core/lib/channel/context.h', 'src/core/lib/channel/handshaker.h', 'src/core/lib/channel/handshaker_factory.h', 'src/core/lib/channel/handshaker_registry.h', + 'src/core/lib/channel/status_util.h', 'src/core/lib/compression/algorithm_metadata.h', 'src/core/lib/compression/compression_internal.h', 'src/core/lib/compression/message_compress.h', @@ -524,11 +526,14 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.h', 'src/core/lib/channel/channel_stack.h', 'src/core/lib/channel/channel_stack_builder.h', + 'src/core/lib/channel/channel_trace.h', + 'src/core/lib/channel/channel_trace_registry.h', 'src/core/lib/channel/connected_channel.h', 'src/core/lib/channel/context.h', 'src/core/lib/channel/handshaker.h', 'src/core/lib/channel/handshaker_factory.h', 'src/core/lib/channel/handshaker_registry.h', + 'src/core/lib/channel/status_util.h', 'src/core/lib/compression/algorithm_metadata.h', 'src/core/lib/compression/compression_internal.h', 'src/core/lib/compression/message_compress.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 39433ff819..634bff2f06 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -337,7 +337,6 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/resolver_factory.h', 'src/core/ext/filters/client_channel/resolver_registry.h', 'src/core/ext/filters/client_channel/retry_throttle.h', - 'src/core/ext/filters/client_channel/status_util.h', 'src/core/ext/filters/client_channel/subchannel.h', 'src/core/ext/filters/client_channel/subchannel_index.h', 'src/core/ext/filters/client_channel/uri_parser.h', @@ -354,11 +353,14 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.h', 'src/core/lib/channel/channel_stack.h', 'src/core/lib/channel/channel_stack_builder.h', + 'src/core/lib/channel/channel_trace.h', + 'src/core/lib/channel/channel_trace_registry.h', 'src/core/lib/channel/connected_channel.h', 'src/core/lib/channel/context.h', 'src/core/lib/channel/handshaker.h', 'src/core/lib/channel/handshaker_factory.h', 'src/core/lib/channel/handshaker_registry.h', + 'src/core/lib/channel/status_util.h', 'src/core/lib/compression/algorithm_metadata.h', 'src/core/lib/compression/compression_internal.h', 'src/core/lib/compression/message_compress.h', @@ -500,10 +502,13 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', + 'src/core/lib/channel/channel_trace.cc', + 'src/core/lib/channel/channel_trace_registry.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', 'src/core/lib/channel/handshaker_registry.cc', + 'src/core/lib/channel/status_util.cc', 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/compression_internal.cc', 'src/core/lib/compression/message_compress.cc', @@ -749,7 +754,6 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/resolver.cc', 'src/core/ext/filters/client_channel/resolver_registry.cc', 'src/core/ext/filters/client_channel/retry_throttle.cc', - 'src/core/ext/filters/client_channel/status_util.cc', 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', @@ -904,7 +908,6 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/resolver_factory.h', 'src/core/ext/filters/client_channel/resolver_registry.h', 'src/core/ext/filters/client_channel/retry_throttle.h', - 'src/core/ext/filters/client_channel/status_util.h', 'src/core/ext/filters/client_channel/subchannel.h', 'src/core/ext/filters/client_channel/subchannel_index.h', 'src/core/ext/filters/client_channel/uri_parser.h', @@ -921,11 +924,14 @@ Pod::Spec.new do |s| 'src/core/lib/channel/channel_args.h', 'src/core/lib/channel/channel_stack.h', 'src/core/lib/channel/channel_stack_builder.h', + 'src/core/lib/channel/channel_trace.h', + 'src/core/lib/channel/channel_trace_registry.h', 'src/core/lib/channel/connected_channel.h', 'src/core/lib/channel/context.h', 'src/core/lib/channel/handshaker.h', 'src/core/lib/channel/handshaker_factory.h', 'src/core/lib/channel/handshaker_registry.h', + 'src/core/lib/channel/status_util.h', 'src/core/lib/compression/algorithm_metadata.h', 'src/core/lib/compression/compression_internal.h', 'src/core/lib/compression/message_compress.h', diff --git a/grpc.def b/grpc.def index 2bafebbbd4..5ff3a1efe8 100644 --- a/grpc.def +++ b/grpc.def @@ -45,6 +45,8 @@ EXPORTS grpc_insecure_channel_create grpc_lame_client_channel_create grpc_channel_destroy + grpc_channel_get_trace + grpc_channel_get_uuid grpc_call_cancel grpc_call_cancel_with_status grpc_call_ref diff --git a/grpc.gemspec b/grpc.gemspec index 3a57829943..3b07dd6433 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -267,7 +267,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/client_channel/resolver_factory.h ) s.files += %w( src/core/ext/filters/client_channel/resolver_registry.h ) s.files += %w( src/core/ext/filters/client_channel/retry_throttle.h ) - s.files += %w( src/core/ext/filters/client_channel/status_util.h ) s.files += %w( src/core/ext/filters/client_channel/subchannel.h ) s.files += %w( src/core/ext/filters/client_channel/subchannel_index.h ) s.files += %w( src/core/ext/filters/client_channel/uri_parser.h ) @@ -284,11 +283,14 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/channel/channel_args.h ) s.files += %w( src/core/lib/channel/channel_stack.h ) s.files += %w( src/core/lib/channel/channel_stack_builder.h ) + s.files += %w( src/core/lib/channel/channel_trace.h ) + s.files += %w( src/core/lib/channel/channel_trace_registry.h ) s.files += %w( src/core/lib/channel/connected_channel.h ) s.files += %w( src/core/lib/channel/context.h ) s.files += %w( src/core/lib/channel/handshaker.h ) s.files += %w( src/core/lib/channel/handshaker_factory.h ) s.files += %w( src/core/lib/channel/handshaker_registry.h ) + s.files += %w( src/core/lib/channel/status_util.h ) s.files += %w( src/core/lib/compression/algorithm_metadata.h ) s.files += %w( src/core/lib/compression/compression_internal.h ) s.files += %w( src/core/lib/compression/message_compress.h ) @@ -430,10 +432,13 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/channel/channel_args.cc ) s.files += %w( src/core/lib/channel/channel_stack.cc ) s.files += %w( src/core/lib/channel/channel_stack_builder.cc ) + s.files += %w( src/core/lib/channel/channel_trace.cc ) + s.files += %w( src/core/lib/channel/channel_trace_registry.cc ) s.files += %w( src/core/lib/channel/connected_channel.cc ) s.files += %w( src/core/lib/channel/handshaker.cc ) s.files += %w( src/core/lib/channel/handshaker_factory.cc ) s.files += %w( src/core/lib/channel/handshaker_registry.cc ) + s.files += %w( src/core/lib/channel/status_util.cc ) s.files += %w( src/core/lib/compression/compression.cc ) s.files += %w( src/core/lib/compression/compression_internal.cc ) s.files += %w( src/core/lib/compression/message_compress.cc ) @@ -682,7 +687,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/client_channel/resolver.cc ) s.files += %w( src/core/ext/filters/client_channel/resolver_registry.cc ) s.files += %w( src/core/ext/filters/client_channel/retry_throttle.cc ) - s.files += %w( src/core/ext/filters/client_channel/status_util.cc ) s.files += %w( src/core/ext/filters/client_channel/subchannel.cc ) s.files += %w( src/core/ext/filters/client_channel/subchannel_index.cc ) s.files += %w( src/core/ext/filters/client_channel/uri_parser.cc ) diff --git a/grpc.gyp b/grpc.gyp index 403d32831b..fc9a45d307 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -237,10 +237,13 @@ 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', + 'src/core/lib/channel/channel_trace.cc', + 'src/core/lib/channel/channel_trace_registry.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', 'src/core/lib/channel/handshaker_registry.cc', + 'src/core/lib/channel/status_util.cc', 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/compression_internal.cc', 'src/core/lib/compression/message_compress.cc', @@ -489,7 +492,6 @@ 'src/core/ext/filters/client_channel/resolver.cc', 'src/core/ext/filters/client_channel/resolver_registry.cc', 'src/core/ext/filters/client_channel/retry_throttle.cc', - 'src/core/ext/filters/client_channel/status_util.cc', 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', @@ -580,10 +582,13 @@ 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', + 'src/core/lib/channel/channel_trace.cc', + 'src/core/lib/channel/channel_trace_registry.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', 'src/core/lib/channel/handshaker_registry.cc', + 'src/core/lib/channel/status_util.cc', 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/compression_internal.cc', 'src/core/lib/compression/message_compress.cc', @@ -739,7 +744,6 @@ 'src/core/ext/filters/client_channel/resolver.cc', 'src/core/ext/filters/client_channel/resolver_registry.cc', 'src/core/ext/filters/client_channel/retry_throttle.cc', - 'src/core/ext/filters/client_channel/status_util.cc', 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', @@ -808,10 +812,13 @@ 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', + 'src/core/lib/channel/channel_trace.cc', + 'src/core/lib/channel/channel_trace_registry.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', 'src/core/lib/channel/handshaker_registry.cc', + 'src/core/lib/channel/status_util.cc', 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/compression_internal.cc', 'src/core/lib/compression/message_compress.cc', @@ -967,7 +974,6 @@ 'src/core/ext/filters/client_channel/resolver.cc', 'src/core/ext/filters/client_channel/resolver_registry.cc', 'src/core/ext/filters/client_channel/retry_throttle.cc', - 'src/core/ext/filters/client_channel/status_util.cc', 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', @@ -1015,10 +1021,13 @@ 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', + 'src/core/lib/channel/channel_trace.cc', + 'src/core/lib/channel/channel_trace_registry.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', 'src/core/lib/channel/handshaker_registry.cc', + 'src/core/lib/channel/status_util.cc', 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/compression_internal.cc', 'src/core/lib/compression/message_compress.cc', @@ -1207,7 +1216,6 @@ 'src/core/ext/filters/client_channel/resolver.cc', 'src/core/ext/filters/client_channel/resolver_registry.cc', 'src/core/ext/filters/client_channel/retry_throttle.cc', - 'src/core/ext/filters/client_channel/status_util.cc', 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', @@ -1388,12 +1396,14 @@ 'grpc', ], 'sources': [ + 'src/proto/grpc/channelz/channelz.proto', 'src/proto/grpc/health/v1/health.proto', 'src/proto/grpc/testing/echo_messages.proto', 'src/proto/grpc/testing/echo.proto', 'src/proto/grpc/testing/duplicate/echo_duplicate.proto', 'test/cpp/end2end/test_service_impl.cc', 'test/cpp/util/byte_buffer_proto_helper.cc', + 'test/cpp/util/channel_trace_proto_helper.cc', 'test/cpp/util/create_test_channel.cc', 'test/cpp/util/string_ref_helper.cc', 'test/cpp/util/subprocess.cc', diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index c129a66949..dd8a5d7d5f 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -286,6 +286,14 @@ GRPCAPI grpc_channel* grpc_lame_client_channel_create( /** Close and destroy a grpc channel */ GRPCAPI void grpc_channel_destroy(grpc_channel* channel); +/** Returns the JSON formatted channel trace for this channel. The caller + owns the returned string and is responsible for freeing it. */ +GRPCAPI char* grpc_channel_get_trace(grpc_channel* channel); + +/** Returns the channel uuid, which can be used to look up its trace at a + later time. */ +GRPCAPI intptr_t grpc_channel_get_uuid(grpc_channel* channel); + /** Error handling for grpc_call Most grpc_call functions return a grpc_error. If the error is not GRPC_OK then the operation failed due to some unsatisfied precondition. diff --git a/include/grpc/impl/codegen/grpc_types.h b/include/grpc/impl/codegen/grpc_types.h index dcce2e7f9a..b671ad653e 100644 --- a/include/grpc/impl/codegen/grpc_types.h +++ b/include/grpc/impl/codegen/grpc_types.h @@ -281,6 +281,10 @@ typedef struct { #define GRPC_ARG_SOCKET_MUTATOR "grpc.socket_mutator" /** The grpc_socket_factory instance to create and bind sockets. A pointer. */ #define GRPC_ARG_SOCKET_FACTORY "grpc.socket_factory" +/** The maximum number of trace events to keep in the tracer for each channel or + * subchannel. The default is 10. If set to 0, channel tracing is disabled. */ +#define GRPC_ARG_MAX_CHANNEL_TRACE_EVENTS_PER_NODE \ + "grpc.max_channel_trace_events_per_node" /** If non-zero, Cronet transport will coalesce packets to fewer frames * when possible. */ #define GRPC_ARG_USE_CRONET_PACKET_COALESCING \ diff --git a/package.xml b/package.xml index 8f0dc55dbf..0b3fc3a9a0 100644 --- a/package.xml +++ b/package.xml @@ -274,7 +274,6 @@ - @@ -291,11 +290,14 @@ + + + @@ -437,10 +439,13 @@ + + + @@ -689,7 +694,6 @@ - diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index bbc5160bec..bf3911e5ee 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -38,12 +38,12 @@ #include "src/core/ext/filters/client_channel/proxy_mapper_registry.h" #include "src/core/ext/filters/client_channel/resolver_registry.h" #include "src/core/ext/filters/client_channel/retry_throttle.h" -#include "src/core/ext/filters/client_channel/status_util.h" #include "src/core/ext/filters/client_channel/subchannel.h" #include "src/core/ext/filters/deadline/deadline_filter.h" #include "src/core/lib/backoff/backoff.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/connected_channel.h" +#include "src/core/lib/channel/status_util.h" #include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/inlined_vector.h" #include "src/core/lib/gprpp/manual_constructor.h" diff --git a/src/core/ext/filters/client_channel/method_params.cc b/src/core/ext/filters/client_channel/method_params.cc index 374b87e170..1f116bb67d 100644 --- a/src/core/ext/filters/client_channel/method_params.cc +++ b/src/core/ext/filters/client_channel/method_params.cc @@ -26,7 +26,7 @@ #include #include "src/core/ext/filters/client_channel/method_params.h" -#include "src/core/ext/filters/client_channel/status_util.h" +#include "src/core/lib/channel/status_util.h" #include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/memory.h" diff --git a/src/core/ext/filters/client_channel/method_params.h b/src/core/ext/filters/client_channel/method_params.h index 48ece29867..099924edf3 100644 --- a/src/core/ext/filters/client_channel/method_params.h +++ b/src/core/ext/filters/client_channel/method_params.h @@ -21,7 +21,7 @@ #include -#include "src/core/ext/filters/client_channel/status_util.h" +#include "src/core/lib/channel/status_util.h" #include "src/core/lib/gprpp/ref_counted.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/iomgr/exec_ctx.h" // for grpc_millis diff --git a/src/core/ext/filters/client_channel/status_util.cc b/src/core/ext/filters/client_channel/status_util.cc deleted file mode 100644 index 11f732ab44..0000000000 --- a/src/core/ext/filters/client_channel/status_util.cc +++ /dev/null @@ -1,100 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/ext/filters/client_channel/status_util.h" - -#include "src/core/lib/gpr/useful.h" - -typedef struct { - const char* str; - grpc_status_code status; -} status_string_entry; - -static const status_string_entry g_status_string_entries[] = { - {"OK", GRPC_STATUS_OK}, - {"CANCELLED", GRPC_STATUS_CANCELLED}, - {"UNKNOWN", GRPC_STATUS_UNKNOWN}, - {"INVALID_ARGUMENT", GRPC_STATUS_INVALID_ARGUMENT}, - {"DEADLINE_EXCEEDED", GRPC_STATUS_DEADLINE_EXCEEDED}, - {"NOT_FOUND", GRPC_STATUS_NOT_FOUND}, - {"ALREADY_EXISTS", GRPC_STATUS_ALREADY_EXISTS}, - {"PERMISSION_DENIED", GRPC_STATUS_PERMISSION_DENIED}, - {"UNAUTHENTICATED", GRPC_STATUS_UNAUTHENTICATED}, - {"RESOURCE_EXHAUSTED", GRPC_STATUS_RESOURCE_EXHAUSTED}, - {"FAILED_PRECONDITION", GRPC_STATUS_FAILED_PRECONDITION}, - {"ABORTED", GRPC_STATUS_ABORTED}, - {"OUT_OF_RANGE", GRPC_STATUS_OUT_OF_RANGE}, - {"UNIMPLEMENTED", GRPC_STATUS_UNIMPLEMENTED}, - {"INTERNAL", GRPC_STATUS_INTERNAL}, - {"UNAVAILABLE", GRPC_STATUS_UNAVAILABLE}, - {"DATA_LOSS", GRPC_STATUS_DATA_LOSS}, -}; - -bool grpc_status_code_from_string(const char* status_str, - grpc_status_code* status) { - for (size_t i = 0; i < GPR_ARRAY_SIZE(g_status_string_entries); ++i) { - if (strcmp(status_str, g_status_string_entries[i].str) == 0) { - *status = g_status_string_entries[i].status; - return true; - } - } - return false; -} - -const char* grpc_status_code_to_string(grpc_status_code status) { - switch (status) { - case GRPC_STATUS_OK: - return "OK"; - case GRPC_STATUS_CANCELLED: - return "CANCELLED"; - case GRPC_STATUS_UNKNOWN: - return "UNKNOWN"; - case GRPC_STATUS_INVALID_ARGUMENT: - return "INVALID_ARGUMENT"; - case GRPC_STATUS_DEADLINE_EXCEEDED: - return "DEADLINE_EXCEEDED"; - case GRPC_STATUS_NOT_FOUND: - return "NOT_FOUND"; - case GRPC_STATUS_ALREADY_EXISTS: - return "ALREADY_EXISTS"; - case GRPC_STATUS_PERMISSION_DENIED: - return "PERMISSION_DENIED"; - case GRPC_STATUS_UNAUTHENTICATED: - return "UNAUTHENTICATED"; - case GRPC_STATUS_RESOURCE_EXHAUSTED: - return "RESOURCE_EXHAUSTED"; - case GRPC_STATUS_FAILED_PRECONDITION: - return "FAILED_PRECONDITION"; - case GRPC_STATUS_ABORTED: - return "ABORTED"; - case GRPC_STATUS_OUT_OF_RANGE: - return "OUT_OF_RANGE"; - case GRPC_STATUS_UNIMPLEMENTED: - return "UNIMPLEMENTED"; - case GRPC_STATUS_INTERNAL: - return "INTERNAL"; - case GRPC_STATUS_UNAVAILABLE: - return "UNAVAILABLE"; - case GRPC_STATUS_DATA_LOSS: - return "DATA_LOSS"; - default: - return "UNKNOWN"; - } -} diff --git a/src/core/ext/filters/client_channel/status_util.h b/src/core/ext/filters/client_channel/status_util.h deleted file mode 100644 index e018709730..0000000000 --- a/src/core/ext/filters/client_channel/status_util.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_STATUS_UTIL_H -#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_STATUS_UTIL_H - -#include - -#include - -#include -#include - -/// If \a status_str is a valid status string, sets \a status to the -/// corresponding status value and returns true. -bool grpc_status_code_from_string(const char* status_str, - grpc_status_code* status); - -/// Returns the string form of \a status, or "UNKNOWN" if invalid. -const char* grpc_status_code_to_string(grpc_status_code status); - -namespace grpc_core { -namespace internal { - -/// A set of grpc_status_code values. -class StatusCodeSet { - public: - bool Empty() const { return status_code_mask_ == 0; } - - void Add(grpc_status_code status) { status_code_mask_ |= (1 << status); } - - bool Contains(grpc_status_code status) const { - return status_code_mask_ & (1 << status); - } - - private: - int status_code_mask_ = 0; // A bitfield of status codes in the set. -}; - -} // namespace internal -} // namespace grpc_core - -#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_STATUS_UTIL_H */ diff --git a/src/core/ext/filters/client_channel/subchannel.cc b/src/core/ext/filters/client_channel/subchannel.cc index cae7cc35e3..d7815fb7e1 100644 --- a/src/core/ext/filters/client_channel/subchannel.cc +++ b/src/core/ext/filters/client_channel/subchannel.cc @@ -40,6 +40,7 @@ #include "src/core/lib/debug/stats.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/manual_constructor.h" +#include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/iomgr/timer.h" #include "src/core/lib/profiling/timers.h" diff --git a/src/core/lib/channel/channel_trace.cc b/src/core/lib/channel/channel_trace.cc new file mode 100644 index 0000000000..67d5fd364b --- /dev/null +++ b/src/core/lib/channel/channel_trace.cc @@ -0,0 +1,238 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/lib/channel/channel_trace.h" + +#include +#include +#include +#include +#include +#include + +#include "src/core/lib/channel/channel_trace_registry.h" +#include "src/core/lib/channel/status_util.h" +#include "src/core/lib/gpr/string.h" +#include "src/core/lib/gpr/useful.h" +#include "src/core/lib/gprpp/memory.h" +#include "src/core/lib/iomgr/error.h" +#include "src/core/lib/slice/slice_internal.h" +#include "src/core/lib/surface/channel.h" +#include "src/core/lib/transport/connectivity_state.h" +#include "src/core/lib/transport/error_utils.h" + +namespace grpc_core { + +ChannelTrace::TraceEvent::TraceEvent( + Severity severity, grpc_slice data, + RefCountedPtr referenced_tracer, ReferencedType type) + : severity_(severity), + data_(data), + timestamp_(grpc_millis_to_timespec(grpc_core::ExecCtx::Get()->Now(), + GPR_CLOCK_REALTIME)), + next_(nullptr), + referenced_tracer_(std::move(referenced_tracer)), + referenced_type_(type) {} + +ChannelTrace::TraceEvent::TraceEvent(Severity severity, grpc_slice data) + : severity_(severity), + data_(data), + timestamp_(grpc_millis_to_timespec(grpc_core::ExecCtx::Get()->Now(), + GPR_CLOCK_REALTIME)), + next_(nullptr) {} + +ChannelTrace::TraceEvent::~TraceEvent() { grpc_slice_unref_internal(data_); } + +ChannelTrace::ChannelTrace(size_t max_events) + : channel_uuid_(-1), + num_events_logged_(0), + list_size_(0), + max_list_size_(max_events), + head_trace_(nullptr), + tail_trace_(nullptr) { + if (max_list_size_ == 0) return; // tracing is disabled if max_events == 0 + gpr_mu_init(&tracer_mu_); + channel_uuid_ = grpc_channel_trace_registry_register_channel_trace(this); + time_created_ = grpc_millis_to_timespec(grpc_core::ExecCtx::Get()->Now(), + GPR_CLOCK_REALTIME); +} + +ChannelTrace::~ChannelTrace() { + if (max_list_size_ == 0) return; // tracing is disabled if max_events == 0 + TraceEvent* it = head_trace_; + while (it != nullptr) { + TraceEvent* to_free = it; + it = it->next(); + Delete(to_free); + } + grpc_channel_trace_registry_unregister_channel_trace(channel_uuid_); + gpr_mu_destroy(&tracer_mu_); +} + +intptr_t ChannelTrace::GetUuid() const { return channel_uuid_; } + +void ChannelTrace::AddTraceEventHelper(TraceEvent* new_trace_event) { + ++num_events_logged_; + // first event case + if (head_trace_ == nullptr) { + head_trace_ = tail_trace_ = new_trace_event; + } + // regular event add case + else { + tail_trace_->set_next(new_trace_event); + tail_trace_ = tail_trace_->next(); + } + ++list_size_; + // maybe garbage collect the end + if (list_size_ > max_list_size_) { + TraceEvent* to_free = head_trace_; + head_trace_ = head_trace_->next(); + Delete(to_free); + --list_size_; + } +} + +void ChannelTrace::AddTraceEvent(Severity severity, grpc_slice data) { + if (max_list_size_ == 0) return; // tracing is disabled if max_events == 0 + AddTraceEventHelper(New(severity, data)); +} + +void ChannelTrace::AddTraceEventReferencingChannel( + Severity severity, grpc_slice data, + RefCountedPtr referenced_tracer) { + if (max_list_size_ == 0) return; // tracing is disabled if max_events == 0 + // create and fill up the new event + AddTraceEventHelper( + New(severity, data, std::move(referenced_tracer), Channel)); +} + +void ChannelTrace::AddTraceEventReferencingSubchannel( + Severity severity, grpc_slice data, + RefCountedPtr referenced_tracer) { + if (max_list_size_ == 0) return; // tracing is disabled if max_events == 0 + // create and fill up the new event + AddTraceEventHelper(New( + severity, data, std::move(referenced_tracer), Subchannel)); +} + +namespace { + +// returns an allocated string that represents tm according to RFC-3339, and, +// more specifically, follows: +// https://developers.google.com/protocol-buffers/docs/proto3#json +// +// "Uses RFC 3339, where generated output will always be Z-normalized and uses +// 0, 3, 6 or 9 fractional digits." +char* fmt_time(gpr_timespec tm) { + char time_buffer[35]; + char ns_buffer[11]; // '.' + 9 digits of precision + struct tm* tm_info = localtime((const time_t*)&tm.tv_sec); + strftime(time_buffer, sizeof(time_buffer), "%Y-%m-%dT%H:%M:%S", tm_info); + snprintf(ns_buffer, 11, ".%09d", tm.tv_nsec); + // This loop trims off trailing zeros by inserting a null character that the + // right point. We iterate in chunks of three because we want 0, 3, 6, or 9 + // fractional digits. + for (int i = 7; i >= 1; i -= 3) { + if (ns_buffer[i] == '0' && ns_buffer[i + 1] == '0' && + ns_buffer[i + 2] == '0') { + ns_buffer[i] = '\0'; + // Edge case in which all fractional digits were 0. + if (i == 1) { + ns_buffer[0] = '\0'; + } + } else { + break; + } + } + char* full_time_str; + gpr_asprintf(&full_time_str, "%s%sZ", time_buffer, ns_buffer); + return full_time_str; +} + +const char* severity_string(ChannelTrace::Severity severity) { + switch (severity) { + case ChannelTrace::Severity::Info: + return "CT_INFO"; + case ChannelTrace::Severity::Warning: + return "CT_WARNING"; + case ChannelTrace::Severity::Error: + return "CT_ERROR"; + default: + GPR_UNREACHABLE_CODE(return "CT_UNKNOWN"); + } +} + +} // anonymous namespace + +void ChannelTrace::TraceEvent::RenderTraceEvent(grpc_json* json) const { + grpc_json* json_iterator = nullptr; + json_iterator = grpc_json_create_child(json_iterator, json, "description", + grpc_slice_to_c_string(data_), + GRPC_JSON_STRING, true); + json_iterator = grpc_json_create_child(json_iterator, json, "severity", + severity_string(severity_), + GRPC_JSON_STRING, false); + json_iterator = + grpc_json_create_child(json_iterator, json, "timestamp", + fmt_time(timestamp_), GRPC_JSON_STRING, true); + if (referenced_tracer_ != nullptr) { + char* uuid_str; + gpr_asprintf(&uuid_str, "%" PRIdPTR, referenced_tracer_->channel_uuid_); + grpc_json* child_ref = grpc_json_create_child( + json_iterator, json, + (referenced_type_ == Channel) ? "channelRef" : "subchannelRef", nullptr, + GRPC_JSON_OBJECT, false); + json_iterator = grpc_json_create_child( + nullptr, child_ref, + (referenced_type_ == Channel) ? "channelId" : "subchannelId", uuid_str, + GRPC_JSON_STRING, true); + json_iterator = child_ref; + } +} + +char* ChannelTrace::RenderTrace() const { + if (!max_list_size_) + return nullptr; // tracing is disabled if max_events == 0 + grpc_json* json = grpc_json_create(GRPC_JSON_OBJECT); + char* num_events_logged_str; + gpr_asprintf(&num_events_logged_str, "%" PRId64, num_events_logged_); + grpc_json* json_iterator = nullptr; + json_iterator = + grpc_json_create_child(json_iterator, json, "numEventsLogged", + num_events_logged_str, GRPC_JSON_STRING, true); + json_iterator = + grpc_json_create_child(json_iterator, json, "creationTime", + fmt_time(time_created_), GRPC_JSON_STRING, true); + grpc_json* events = grpc_json_create_child(json_iterator, json, "events", + nullptr, GRPC_JSON_ARRAY, false); + json_iterator = nullptr; + TraceEvent* it = head_trace_; + while (it != nullptr) { + json_iterator = grpc_json_create_child(json_iterator, events, nullptr, + nullptr, GRPC_JSON_OBJECT, false); + it->RenderTraceEvent(json_iterator); + it = it->next(); + } + char* json_str = grpc_json_dump_to_string(json, 0); + grpc_json_destroy(json); + return json_str; +} + +} // namespace grpc_core diff --git a/src/core/lib/channel/channel_trace.h b/src/core/lib/channel/channel_trace.h new file mode 100644 index 0000000000..1df1e585f2 --- /dev/null +++ b/src/core/lib/channel/channel_trace.h @@ -0,0 +1,133 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_LIB_CHANNEL_CHANNEL_TRACE_H +#define GRPC_CORE_LIB_CHANNEL_CHANNEL_TRACE_H + +#include + +#include +#include "src/core/lib/gprpp/ref_counted.h" +#include "src/core/lib/gprpp/ref_counted_ptr.h" +#include "src/core/lib/iomgr/error.h" +#include "src/core/lib/json/json.h" + +namespace grpc_core { + +// Object used to hold live data for a channel. This data is exposed via the +// channelz service: +// https://github.com/grpc/proposal/blob/master/A14-channelz.md +class ChannelTrace : public RefCounted { + public: + ChannelTrace(size_t max_events); + ~ChannelTrace(); + + // returns the tracer's uuid + intptr_t GetUuid() const; + + enum Severity { + Unset = 0, // never to be used + Info, // we start at 1 to avoid using proto default values + Warning, + Error + }; + + // Adds a new trace event to the tracing object + // + // TODO(ncteisen): as this call is used more and more throughout the gRPC + // stack, determine if it makes more sense to accept a char* instead of a + // slice. + void AddTraceEvent(Severity severity, grpc_slice data); + + // Adds a new trace event to the tracing object. This trace event refers to a + // an event on a child of the channel. For example, if this channel has + // created a new subchannel, then it would record that with a TraceEvent + // referencing the new subchannel. + // + // TODO(ncteisen): Once channelz is implemented, the events should reference + // the overall channelz object, not just the ChannelTrace object. + // TODO(ncteisen): as this call is used more and more throughout the gRPC + // stack, determine if it makes more sense to accept a char* instead of a + // slice. + void AddTraceEventReferencingChannel( + Severity severity, grpc_slice data, + RefCountedPtr referenced_tracer); + void AddTraceEventReferencingSubchannel( + Severity severity, grpc_slice data, + RefCountedPtr referenced_tracer); + + // Returns the tracing data rendered as a grpc json string. + // The string is owned by the caller and must be freed. + char* RenderTrace() const; + + private: + // Types of objects that can be references by trace events. + enum ReferencedType { Channel, Subchannel }; + // Private class to encapsulate all the data and bookkeeping needed for a + // a trace event. + class TraceEvent { + public: + // Constructor for a TraceEvent that references a different channel. + // TODO(ncteisen): once channelz is implemented, this should reference the + // overall channelz object, not just the ChannelTrace object + TraceEvent(Severity severity, grpc_slice data, + RefCountedPtr referenced_tracer, + ReferencedType type); + + // Constructor for a TraceEvent that does not reverence a different + // channel. + TraceEvent(Severity severity, grpc_slice data); + + ~TraceEvent(); + + // Renders the data inside of this TraceEvent into a json object. This is + // used by the ChannelTrace, when it is rendering itself. + void RenderTraceEvent(grpc_json* json) const; + + // set and get for the next_ pointer. + TraceEvent* next() const { return next_; } + void set_next(TraceEvent* next) { next_ = next; } + + private: + Severity severity_; + grpc_slice data_; + gpr_timespec timestamp_; + TraceEvent* next_; + // the tracer object for the (sub)channel that this trace event refers to. + RefCountedPtr referenced_tracer_; + // the type that the referenced tracer points to. Unused if this trace + // does not point to any channel or subchannel + ReferencedType referenced_type_; + }; // TraceEvent + + // Internal helper to add and link in a trace event + void AddTraceEventHelper(TraceEvent* new_trace_event); + + gpr_mu tracer_mu_; + intptr_t channel_uuid_; + uint64_t num_events_logged_; + size_t list_size_; + size_t max_list_size_; + TraceEvent* head_trace_; + TraceEvent* tail_trace_; + gpr_timespec time_created_; +}; + +} // namespace grpc_core + +#endif /* GRPC_CORE_LIB_CHANNEL_CHANNEL_TRACE_H */ diff --git a/src/core/lib/channel/channel_trace_registry.cc b/src/core/lib/channel/channel_trace_registry.cc new file mode 100644 index 0000000000..6c82431467 --- /dev/null +++ b/src/core/lib/channel/channel_trace_registry.cc @@ -0,0 +1,80 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/lib/avl/avl.h" +#include "src/core/lib/channel/channel_trace.h" +#include "src/core/lib/channel/channel_trace_registry.h" +#include "src/core/lib/gpr/useful.h" + +#include +#include + +// file global lock and avl. +static gpr_mu g_mu; +static grpc_avl g_avl; +static gpr_atm g_uuid = 0; + +// avl vtable for uuid (intptr_t) -> ChannelTrace +// this table is only looking, it does not own anything. +static void destroy_intptr(void* not_used, void* user_data) {} +static void* copy_intptr(void* key, void* user_data) { return key; } +static long compare_intptr(void* key1, void* key2, void* user_data) { + return GPR_ICMP(key1, key2); +} + +static void destroy_channel_trace(void* trace, void* user_data) {} +static void* copy_channel_trace(void* trace, void* user_data) { return trace; } +static const grpc_avl_vtable avl_vtable = { + destroy_intptr, copy_intptr, compare_intptr, destroy_channel_trace, + copy_channel_trace}; + +void grpc_channel_trace_registry_init() { + gpr_mu_init(&g_mu); + g_avl = grpc_avl_create(&avl_vtable); +} + +void grpc_channel_trace_registry_shutdown() { + grpc_avl_unref(g_avl, nullptr); + gpr_mu_destroy(&g_mu); +} + +intptr_t grpc_channel_trace_registry_register_channel_trace( + grpc_core::ChannelTrace* channel_trace) { + intptr_t prior = gpr_atm_no_barrier_fetch_add(&g_uuid, 1); + gpr_mu_lock(&g_mu); + g_avl = grpc_avl_add(g_avl, (void*)prior, channel_trace, nullptr); + gpr_mu_unlock(&g_mu); + return prior; +} + +void grpc_channel_trace_registry_unregister_channel_trace(intptr_t uuid) { + gpr_mu_lock(&g_mu); + g_avl = grpc_avl_remove(g_avl, (void*)uuid, nullptr); + gpr_mu_unlock(&g_mu); +} + +grpc_core::ChannelTrace* grpc_channel_trace_registry_get_channel_trace( + intptr_t uuid) { + gpr_mu_lock(&g_mu); + grpc_core::ChannelTrace* ret = static_cast( + grpc_avl_get(g_avl, (void*)uuid, nullptr)); + gpr_mu_unlock(&g_mu); + return ret; +} diff --git a/src/core/lib/channel/channel_trace_registry.h b/src/core/lib/channel/channel_trace_registry.h new file mode 100644 index 0000000000..391ecba7de --- /dev/null +++ b/src/core/lib/channel/channel_trace_registry.h @@ -0,0 +1,43 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_LIB_CHANNEL_CHANNEL_TRACE_REGISTRY_H +#define GRPC_CORE_LIB_CHANNEL_CHANNEL_TRACE_REGISTRY_H + +#include + +#include "src/core/lib/channel/channel_trace.h" + +#include + +// TODO(ncteisen): convert this file to C++ + +void grpc_channel_trace_registry_init(); +void grpc_channel_trace_registry_shutdown(); + +// globally registers a ChannelTrace. Returns its unique uuid +intptr_t grpc_channel_trace_registry_register_channel_trace( + grpc_core::ChannelTrace* channel_trace); +// globally unregisters the ChannelTrace that is associated to uuid. +void grpc_channel_trace_registry_unregister_channel_trace(intptr_t uuid); +// if object with uuid has previously been registered, returns the ChannelTrace +// associated with that uuid. Else returns nullptr. +grpc_core::ChannelTrace* grpc_channel_trace_registry_get_channel_trace( + intptr_t uuid); + +#endif /* GRPC_CORE_LIB_CHANNEL_CHANNEL_TRACE_REGISTRY_H */ diff --git a/src/core/lib/channel/status_util.cc b/src/core/lib/channel/status_util.cc new file mode 100644 index 0000000000..563db40846 --- /dev/null +++ b/src/core/lib/channel/status_util.cc @@ -0,0 +1,100 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/lib/channel/status_util.h" + +#include "src/core/lib/gpr/useful.h" + +typedef struct { + const char* str; + grpc_status_code status; +} status_string_entry; + +static const status_string_entry g_status_string_entries[] = { + {"OK", GRPC_STATUS_OK}, + {"CANCELLED", GRPC_STATUS_CANCELLED}, + {"UNKNOWN", GRPC_STATUS_UNKNOWN}, + {"INVALID_ARGUMENT", GRPC_STATUS_INVALID_ARGUMENT}, + {"DEADLINE_EXCEEDED", GRPC_STATUS_DEADLINE_EXCEEDED}, + {"NOT_FOUND", GRPC_STATUS_NOT_FOUND}, + {"ALREADY_EXISTS", GRPC_STATUS_ALREADY_EXISTS}, + {"PERMISSION_DENIED", GRPC_STATUS_PERMISSION_DENIED}, + {"UNAUTHENTICATED", GRPC_STATUS_UNAUTHENTICATED}, + {"RESOURCE_EXHAUSTED", GRPC_STATUS_RESOURCE_EXHAUSTED}, + {"FAILED_PRECONDITION", GRPC_STATUS_FAILED_PRECONDITION}, + {"ABORTED", GRPC_STATUS_ABORTED}, + {"OUT_OF_RANGE", GRPC_STATUS_OUT_OF_RANGE}, + {"UNIMPLEMENTED", GRPC_STATUS_UNIMPLEMENTED}, + {"INTERNAL", GRPC_STATUS_INTERNAL}, + {"UNAVAILABLE", GRPC_STATUS_UNAVAILABLE}, + {"DATA_LOSS", GRPC_STATUS_DATA_LOSS}, +}; + +bool grpc_status_code_from_string(const char* status_str, + grpc_status_code* status) { + for (size_t i = 0; i < GPR_ARRAY_SIZE(g_status_string_entries); ++i) { + if (strcmp(status_str, g_status_string_entries[i].str) == 0) { + *status = g_status_string_entries[i].status; + return true; + } + } + return false; +} + +const char* grpc_status_code_to_string(grpc_status_code status) { + switch (status) { + case GRPC_STATUS_OK: + return "OK"; + case GRPC_STATUS_CANCELLED: + return "CANCELLED"; + case GRPC_STATUS_UNKNOWN: + return "UNKNOWN"; + case GRPC_STATUS_INVALID_ARGUMENT: + return "INVALID_ARGUMENT"; + case GRPC_STATUS_DEADLINE_EXCEEDED: + return "DEADLINE_EXCEEDED"; + case GRPC_STATUS_NOT_FOUND: + return "NOT_FOUND"; + case GRPC_STATUS_ALREADY_EXISTS: + return "ALREADY_EXISTS"; + case GRPC_STATUS_PERMISSION_DENIED: + return "PERMISSION_DENIED"; + case GRPC_STATUS_UNAUTHENTICATED: + return "UNAUTHENTICATED"; + case GRPC_STATUS_RESOURCE_EXHAUSTED: + return "RESOURCE_EXHAUSTED"; + case GRPC_STATUS_FAILED_PRECONDITION: + return "FAILED_PRECONDITION"; + case GRPC_STATUS_ABORTED: + return "ABORTED"; + case GRPC_STATUS_OUT_OF_RANGE: + return "OUT_OF_RANGE"; + case GRPC_STATUS_UNIMPLEMENTED: + return "UNIMPLEMENTED"; + case GRPC_STATUS_INTERNAL: + return "INTERNAL"; + case GRPC_STATUS_UNAVAILABLE: + return "UNAVAILABLE"; + case GRPC_STATUS_DATA_LOSS: + return "DATA_LOSS"; + default: + return "UNKNOWN"; + } +} diff --git a/src/core/lib/channel/status_util.h b/src/core/lib/channel/status_util.h new file mode 100644 index 0000000000..5409de6b3c --- /dev/null +++ b/src/core/lib/channel/status_util.h @@ -0,0 +1,58 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_LIB_CHANNEL_STATUS_UTIL_H +#define GRPC_CORE_LIB_CHANNEL_STATUS_UTIL_H + +#include + +#include + +#include +#include + +/// If \a status_str is a valid status string, sets \a status to the +/// corresponding status value and returns true. +bool grpc_status_code_from_string(const char* status_str, + grpc_status_code* status); + +/// Returns the string form of \a status, or "UNKNOWN" if invalid. +const char* grpc_status_code_to_string(grpc_status_code status); + +namespace grpc_core { +namespace internal { + +/// A set of grpc_status_code values. +class StatusCodeSet { + public: + bool Empty() const { return status_code_mask_ == 0; } + + void Add(grpc_status_code status) { status_code_mask_ |= (1 << status); } + + bool Contains(grpc_status_code status) const { + return status_code_mask_ & (1 << status); + } + + private: + int status_code_mask_ = 0; // A bitfield of status codes in the set. +}; + +} // namespace internal +} // namespace grpc_core + +#endif /* GRPC_CORE_LIB_CHANNEL_STATUS_UTIL_H */ diff --git a/src/core/lib/json/json.cc b/src/core/lib/json/json.cc index 2141db4c5b..816241bbf0 100644 --- a/src/core/lib/json/json.cc +++ b/src/core/lib/json/json.cc @@ -21,6 +21,7 @@ #include #include +#include #include "src/core/lib/json/json.h" @@ -46,5 +47,40 @@ void grpc_json_destroy(grpc_json* json) { json->parent->child = json->next; } + if (json->owns_value) { + gpr_free((void*)json->value); + } + gpr_free(json); } + +grpc_json* grpc_json_link_child(grpc_json* parent, grpc_json* child, + grpc_json* sibling) { + // first child case. + if (parent->child == nullptr) { + GPR_ASSERT(sibling == nullptr); + parent->child = child; + return child; + } + if (sibling == nullptr) { + sibling = parent->child; + } + // always find the right most sibling. + while (sibling->next != nullptr) { + sibling = sibling->next; + } + sibling->next = child; + return child; +} + +grpc_json* grpc_json_create_child(grpc_json* sibling, grpc_json* parent, + const char* key, const char* value, + grpc_json_type type, bool owns_value) { + grpc_json* child = grpc_json_create(type); + grpc_json_link_child(parent, child, sibling); + child->owns_value = owns_value; + child->parent = parent; + child->value = value; + child->key = key; + return child; +} diff --git a/src/core/lib/json/json.h b/src/core/lib/json/json.h index 3a62ef9cfb..f93b43048b 100644 --- a/src/core/lib/json/json.h +++ b/src/core/lib/json/json.h @@ -21,6 +21,7 @@ #include +#include #include #include "src/core/lib/json/json_common.h" @@ -37,6 +38,9 @@ typedef struct grpc_json { grpc_json_type type; const char* key; const char* value; + + /* if set, destructor will free value */ + bool owns_value; } grpc_json; /* The next two functions are going to parse the input string, and @@ -67,9 +71,24 @@ char* grpc_json_dump_to_string(grpc_json* json, int indent); /* Use these to create or delete a grpc_json object. * Deletion is recursive. We will not attempt to free any of the strings - * in any of the objects of that tree. + * in any of the objects of that tree, unless the boolean, owns_value, + * is true. */ grpc_json* grpc_json_create(grpc_json_type type); void grpc_json_destroy(grpc_json* json); +/* Links the child json object into the parent's json tree. If the parent + * already has children, then passing in the most recently added child as the + * sibling parameter is an optimization. For if sibling is NULL, this function + * will manually traverse the tree in order to find the right most sibling. + */ +grpc_json* grpc_json_link_child(grpc_json* parent, grpc_json* child, + grpc_json* sibling); + +/* Creates a child json object into the parent's json tree then links it in + * as described above. */ +grpc_json* grpc_json_create_child(grpc_json* sibling, grpc_json* parent, + const char* key, const char* value, + grpc_json_type type, bool owns_value); + #endif /* GRPC_CORE_LIB_JSON_JSON_H */ diff --git a/src/core/lib/surface/channel.cc b/src/core/lib/surface/channel.cc index 03353d6beb..cecc15b2df 100644 --- a/src/core/lib/surface/channel.cc +++ b/src/core/lib/surface/channel.cc @@ -21,6 +21,7 @@ #include "src/core/lib/surface/channel.h" #include +#include #include #include @@ -30,8 +31,12 @@ #include #include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/channel/channel_trace.h" #include "src/core/lib/debug/stats.h" #include "src/core/lib/gpr/string.h" +#include "src/core/lib/gprpp/manual_constructor.h" +#include "src/core/lib/gprpp/memory.h" +#include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/iomgr/iomgr.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/surface/api_trace.h" @@ -62,6 +67,8 @@ struct grpc_channel { gpr_mu registered_call_mu; registered_call* registered_calls; + grpc_core::RefCountedPtr tracer; + char* target; }; @@ -93,12 +100,14 @@ grpc_channel* grpc_channel_create_with_builder( grpc_error_string(error)); GRPC_ERROR_UNREF(error); gpr_free(target); - goto done; + grpc_channel_args_destroy(args); + return channel; } memset(channel, 0, sizeof(*channel)); channel->target = target; channel->is_client = grpc_channel_stack_type_is_client(channel_stack_type); + size_t channel_tracer_max_nodes = 0; // default to off gpr_mu_init(&channel->registered_call_mu); channel->registered_calls = nullptr; @@ -161,14 +170,33 @@ grpc_channel* grpc_channel_create_with_builder( channel->compression_options.enabled_algorithms_bitset = static_cast(args->args[i].value.integer) | 0x1; /* always support no compression */ + } else if (0 == strcmp(args->args[i].key, + GRPC_ARG_MAX_CHANNEL_TRACE_EVENTS_PER_NODE)) { + GPR_ASSERT(channel_tracer_max_nodes == 0); + // max_nodes defaults to 0 (which is off), clamped between 0 and INT_MAX + const grpc_integer_options options = {0, 0, INT_MAX}; + channel_tracer_max_nodes = + (size_t)grpc_channel_arg_get_integer(&args->args[i], options); } } -done: grpc_channel_args_destroy(args); + channel->tracer = grpc_core::MakeRefCounted( + channel_tracer_max_nodes); + channel->tracer->AddTraceEvent( + grpc_core::ChannelTrace::Severity::Info, + grpc_slice_from_static_string("Channel created")); return channel; } +char* grpc_channel_get_trace(grpc_channel* channel) { + return channel->tracer->RenderTrace(); +} + +intptr_t grpc_channel_get_uuid(grpc_channel* channel) { + return channel->tracer->GetUuid(); +} + grpc_channel* grpc_channel_create(const char* target, const grpc_channel_args* input_args, grpc_channel_stack_type channel_stack_type, @@ -377,6 +405,7 @@ static void destroy_channel(void* arg, grpc_error* error) { GRPC_MDELEM_UNREF(rc->authority); gpr_free(rc); } + channel->tracer.reset(); GRPC_MDELEM_UNREF(channel->default_authority); gpr_mu_destroy(&channel->registered_call_mu); gpr_free(channel->target); diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc index ac9f9e6066..bd436d6857 100644 --- a/src/core/lib/surface/init.cc +++ b/src/core/lib/surface/init.cc @@ -27,6 +27,7 @@ #include #include #include "src/core/lib/channel/channel_stack.h" +#include "src/core/lib/channel/channel_trace_registry.h" #include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/channel/handshaker_registry.h" #include "src/core/lib/debug/stats.h" @@ -128,6 +129,7 @@ void grpc_init(void) { grpc_slice_intern_init(); grpc_mdctx_global_init(); grpc_channel_init_init(); + grpc_channel_trace_registry_init(); grpc_security_pre_init(); grpc_core::ExecCtx::GlobalInit(); grpc_iomgr_init(); @@ -176,6 +178,7 @@ void grpc_shutdown(void) { grpc_mdctx_global_shutdown(); grpc_handshaker_factory_registry_shutdown(); grpc_slice_intern_shutdown(); + grpc_channel_trace_registry_shutdown(); grpc_stats_shutdown(); } grpc_core::ExecCtx::GlobalShutdown(); diff --git a/src/proto/grpc/channelz/BUILD b/src/proto/grpc/channelz/BUILD new file mode 100644 index 0000000000..bdb03d5e2d --- /dev/null +++ b/src/proto/grpc/channelz/BUILD @@ -0,0 +1,26 @@ +# Copyright 2018 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +licenses(["notice"]) # Apache v2 + +load("//bazel:grpc_build_system.bzl", "grpc_proto_library", "grpc_package") + +grpc_package(name = "channelz", visibility = "public") + +grpc_proto_library( + name = "channelz_proto", + srcs = ["channelz.proto"], + has_services = True, + well_known_protos = True, +) diff --git a/src/proto/grpc/channelz/channelz.proto b/src/proto/grpc/channelz/channelz.proto new file mode 100644 index 0000000000..14db66a654 --- /dev/null +++ b/src/proto/grpc/channelz/channelz.proto @@ -0,0 +1,456 @@ +// Copyright 2018 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package grpc.channelz; + +import "google/protobuf/any.proto"; +import "google/protobuf/duration.proto"; +import "google/protobuf/timestamp.proto"; +import "google/protobuf/wrappers.proto"; + +// See go/grpc-channelz. + +// Channel is a logical grouping of channels, subchannels, and sockets. +message Channel { + // The identifier for this channel. + ChannelRef ref = 1; + // Data specific to this channel. + ChannelData data = 2; + // At most one of 'channel_ref+subchannel_ref' and 'socket' is set. + + // There are no ordering guarantees on the order of channel refs. + // There may not be cycles in the ref graph. + // A channel ref may be present in more than one channel or subchannel. + repeated ChannelRef channel_ref = 3; + + // At most one of 'channel_ref+subchannel_ref' and 'socket' is set. + // There are no ordering guarantees on the order of subchannel refs. + // There may not be cycles in the ref graph. + // A sub channel ref may be present in more than one channel or subchannel. + repeated SubchannelRef subchannel_ref = 4; + + // There are no ordering guarantees on the order of sockets. + repeated SocketRef socket = 5; +} + +// Subchannel is a logical grouping of channels, subchannels, and sockets. +// A subchannel is load balanced over by it's ancestor +message Subchannel { + // The identifier for this channel. + SubchannelRef ref = 1; + // Data specific to this channel. + ChannelData data = 2; + // At most one of 'channel_ref+subchannel_ref' and 'socket' is set. + + // There are no ordering guarantees on the order of channel refs. + // There may not be cycles in the ref graph. + // A channel ref may be present in more than one channel or subchannel. + repeated ChannelRef channel_ref = 3; + + // At most one of 'channel_ref+subchannel_ref' and 'socket' is set. + // There are no ordering guarantees on the order of subchannel refs. + // There may not be cycles in the ref graph. + // A sub channel ref may be present in more than one channel or subchannel. + repeated SubchannelRef subchannel_ref = 4; + + // There are no ordering guarantees on the order of sockets. + repeated SocketRef socket = 5; +} + +// These come from the specified states in this document: +// https://github.com/grpc/grpc/blob/master/doc/connectivity-semantics-and-api.md +message ChannelConnectivityState { + enum State { + UNKNOWN = 0; + IDLE = 1; + CONNECTING = 2; + READY = 3; + TRANSIENT_FAILURE = 4; + SHUTDOWN = 5; + } + State state = 1; +} + +message ChannelData { + + ChannelConnectivityState state = 1; + + // The target this channel originally tried to connect to. May be absent + string target = 2; + + ChannelTrace trace = 3; + + // The number of calls started on the channel + int64 calls_started = 4; + // The number of calls that have completed with an OK status + int64 calls_succeeded = 5; + // The number of calls that have a completed with a non-OK status + int64 calls_failed = 6; + + // The last time a call was started on the channel. + google.protobuf.Timestamp last_call_started_timestamp = 7; +} + +// A trace event is an interesting thing that happened to a channel or +// subchannel, such as creation, address resolution, subchannel creation, etc. +message ChannelTraceEvent { + // High level description of the event. + string description = 1; + // The supported severity levels of trace events. + enum Severity { + CT_UNKNOWN = 0; + CT_INFO = 1; + CT_WARNING = 2; + CT_ERROR = 3; + } + // the severity of the trace event + Severity severity = 2; + // When this event occurred. + google.protobuf.Timestamp timestamp = 3; + // ref of referenced channel or subchannel. + // Optional, only present if this event refers to a child object. For example, + // this field would be filled if this trace event was for a subchannel being + // created. + oneof child_ref { + ChannelRef channel_ref = 4; + SubchannelRef subchannel_ref = 5; + } +} + +message ChannelTrace { + // Number of events ever logged in this tracing object. This can differ from + // events.size() because events can be overwritten or garbage collected by + // implementations. + int64 num_events_logged = 1; + // Time that this channel was created. + google.protobuf.Timestamp creation_time = 2; + // List of events that have occurred on this channel. + repeated ChannelTraceEvent events = 3; +} + +message ChannelRef { + // The globally unique id for this channel. Must be a positive number. + int64 channel_id = 1; + // An optional name associated with the channel. + string name = 2; + // Intentionally don't use field numbers from other refs. + reserved 3, 4, 5, 6; +} + +message SubchannelRef { + // The globally unique id for this subchannel. Must be a positive number. + int64 subchannel_id = 7; + // An optional name associated with the subchannel. + string name = 8; + // Intentionally don't use field numbers from other refs. + reserved 1, 2, 3, 4, 5, 6; +} + +message SocketRef { + int64 socket_id = 3; + // An optional name associated with the socket. + string name = 4; + // Intentionally don't use field numbers from other refs. + reserved 1, 2, 5, 6, 7, 8; +} + +message ServerRef { + // A globally unique identifier for this server. Must be a positive number. + int64 server_id = 5; + // An optional name associated with the server. + string name = 6; + // Intentionally don't use field numbers from other refs. + reserved 1, 2, 3, 4, 7, 8; +} + +message Server { + ServerRef ref = 1; + ServerData data = 2; + + // The sockets that the server is listening on. There are no ordering + // guarantees. + repeated SocketRef listen_socket = 3; +} + +message ServerData { + ChannelTrace trace = 1; + + // The number of incoming calls started on the server + int64 calls_started = 2; + // The number of incoming calls that have completed with an OK status + int64 calls_succeeded = 3; + // The number of incoming calls that have a completed with a non-OK status + int64 calls_failed = 4; + + // The last time a call was started on the server. + google.protobuf.Timestamp last_call_started_timestamp = 5; +} + +// Information about an actual connection. Pronounced "sock-ay". +message Socket { + SocketRef ref = 1; + + SocketData data = 2; + // The locally bound address. + Address local = 3; + // The remote bound address. May be absent. + Address remote = 4; + Security security = 5; + + // Optional, represents the name of the remote endpoint, if different than + // the original target name. + string remote_name = 6; +} + +message SocketData { + // The number of streams that have been started. + int64 streams_started = 1; + // The number of streams that have ended successfully with the EoS bit set for + // both end points + int64 streams_succeeded = 2; + // The number of incoming streams that have a completed with a non-OK status + int64 streams_failed = 3; + + // The number of messages successfully sent on this socket. + int64 messages_sent = 4; + int64 messages_received = 5; + + // The number of keep alives sent. This is typically implemented with HTTP/2 + // ping messages. + int64 keep_alives_sent = 6; + + // The last time a stream was created by this endpoint. Usually unset for + // servers. + google.protobuf.Timestamp last_local_stream_created_timestamp = 7; + // The last time a stream was created by the remote endpoint. Usually unset + // for clients. + google.protobuf.Timestamp last_remote_stream_created_timestamp = 8; + + // The last time a message was sent by this endpoint. + google.protobuf.Timestamp last_message_sent_timestamp = 9; + // The last time a message was received by this endpoint. + google.protobuf.Timestamp last_message_received_timestamp = 10; + + // The amount of window, granted to the local endpoint by the remote endpoint. + // This may be slightly out of date due to network latency. This does NOT + // include stream level or TCP level flow control info. + google.protobuf.Int64Value local_flow_control_window = 11; + + // The amount of window, granted to the remote endpoint by the local endpoint. + // This may be slightly out of date due to network latency. This does NOT + // include stream level or TCP level flow control info. + google.protobuf.Int64Value remote_flow_control_window = 12; + + repeated SocketOption option = 13; +} + +message Address { + message TcpIpAddress { + // Either the IPv4 or IPv6 address in bytes. Will either be 4 bytes or 16 + // bytes in length. + bytes ip_address = 1; + // 0-64k, or -1 if not appropriate. + int32 port = 2; + } + // A Unix Domain Socket address. + message UdsAddress { + string filename = 1; + } + // An address type not included above. + message OtherAddress { + // The human readable version of the value. + string name = 1; + // The actual address message. + google.protobuf.Any value = 2; + } + + oneof address { + TcpIpAddress tcpip_address = 1; + UdsAddress uds_address = 2; + OtherAddress other_address = 3; + } +} + +message Security { + message Tls { + // The key exchange used. e.g. X25519 + string key_exchange = 1; + // The cipher used. e.g. AES_128_GCM. + string cipher = 2; + // the certificate used by this endpoint. + bytes local_certificate = 3; + // the certificate used by the remote endpoint. + bytes remote_certificate = 4; + } + message OtherSecurity { + // The human readable version of the value. + string name = 1; + // The actual security details message. + google.protobuf.Any value = 2; + } + oneof model { + Tls tls = 1; + OtherSecurity other = 2; + } +} + +message SocketOption { + string name = 1; + // The human readable value of this socket option. At least one of value or + // additional will be set. + string value = 2; + // Additional data associated with the socket option. At least one of value + // or additional will be set. + google.protobuf.Any additional = 3; +} + +// For use with SocketOption's additional field. This is primarily used for +// SO_RCVTIMEO and SO_SNDTIMEO +message SocketOptionTimeout { + google.protobuf.Duration duration = 1; +} + +message SocketOptionLinger { + bool active = 1; + google.protobuf.Duration duration = 2; +} + +// Tcp info for SOL_TCP, TCP_INFO +message SocketOptionTcpInfo { + uint32 tcpi_state = 1; + + uint32 tcpi_ca_state = 2; + uint32 tcpi_retransmits = 3; + uint32 tcpi_probes = 4; + uint32 tcpi_backoff = 5; + uint32 tcpi_options = 6; + uint32 tcpi_snd_wscale = 7; + uint32 tcpi_rcv_wscale = 8; + + uint32 tcpi_rto = 9; + uint32 tcpi_ato = 10; + uint32 tcpi_snd_mss = 11; + uint32 tcpi_rcv_mss = 12; + + uint32 tcpi_unacked = 13; + uint32 tcpi_sacked = 14; + uint32 tcpi_lost = 15; + uint32 tcpi_retrans = 16; + uint32 tcpi_fackets = 17; + + uint32 tcpi_last_data_sent = 18; + uint32 tcpi_last_ack_sent = 19; + uint32 tcpi_last_data_recv = 20; + uint32 tcpi_last_ack_recv = 21; + + uint32 tcpi_pmtu = 22; + uint32 tcpi_rcv_ssthresh = 23; + uint32 tcpi_rtt = 24; + uint32 tcpi_rttvar = 25; + uint32 tcpi_snd_ssthresh = 26; + uint32 tcpi_snd_cwnd = 27; + uint32 tcpi_advmss = 28; + uint32 tcpi_reordering = 29; +} + +service Channelz { + // Gets all root channels (e.g. channels the application has directly + // created). This does not include subchannels nor non-top level channels. + rpc GetTopChannels(GetTopChannelsRequest) returns (GetTopChannelsResponse); + // Gets all servers that exist in the process. + rpc GetServers(GetServersRequest) returns (GetServersResponse); + // Gets all server sockets that exist in the process. + rpc GetServerSockets(GetServerSocketsRequest) returns (GetServerSocketsResponse); + // Returns a single Channel, or else a NOT_FOUND code. + rpc GetChannel(GetChannelRequest) returns (GetChannelResponse); + // Returns a single Subchannel, or else a NOT_FOUND code. + rpc GetSubchannel(GetSubchannelRequest) returns (GetSubchannelResponse); + // Returns a single Socket or else a NOT_FOUND code. + rpc GetSocket(GetSocketRequest) returns (GetSocketResponse); +} + +message GetServersRequest { + // start_server_id indicates that only servers at or above this id should be + // included in the results. + int64 start_server_id = 1; +} + +message GetServersResponse { + // list of servers that the connection detail service knows about. Sorted in + // ascending server_id order. + repeated Server server = 1; + // If set, indicates that the list of servers is the final list. Requesting + // more servers will only return more if they are created after this RPC + // completes. + bool end = 2; +} + +message GetServerSocketsRequest { + int64 server_id = 1; + // start_socket_id indicates that only sockets at or above this id should be + // included in the results. + int64 start_socket_id = 2; +} + +message GetServerSocketsResponse { + // list of socket refs that the connection detail service knows about. Sorted in + // ascending socket_id order. + repeated SocketRef socket_ref = 1; + // If set, indicates that the list of sockets is the final list. Requesting + // more sockets will only return more if they are created after this RPC + // completes. + bool end = 2; +} + +message GetTopChannelsRequest { + // start_channel_id indicates that only channels at or above this id should be + // included in the results. + int64 start_channel_id = 1; +} + +message GetTopChannelsResponse { + // list of channels that the connection detail service knows about. Sorted in + // ascending channel_id order. + repeated Channel channel = 1; + // If set, indicates that the list of channels is the final list. Requesting + // more channels can only return more if they are created after this RPC + // completes. + bool end = 2; +} + +message GetChannelRequest { + int64 channel_id = 1; +} + +message GetChannelResponse { + Channel channel = 1; +} + +message GetSubchannelRequest { + int64 subchannel_id = 1; +} + +message GetSubchannelResponse { + Subchannel subchannel = 1; +} + +message GetSocketRequest { + int64 socket_id = 1; +} + +message GetSocketResponse { + Socket socket = 1; +} diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index d96cbec292..9807300527 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -60,10 +60,13 @@ CORE_SOURCE_FILES = [ 'src/core/lib/channel/channel_args.cc', 'src/core/lib/channel/channel_stack.cc', 'src/core/lib/channel/channel_stack_builder.cc', + 'src/core/lib/channel/channel_trace.cc', + 'src/core/lib/channel/channel_trace_registry.cc', 'src/core/lib/channel/connected_channel.cc', 'src/core/lib/channel/handshaker.cc', 'src/core/lib/channel/handshaker_factory.cc', 'src/core/lib/channel/handshaker_registry.cc', + 'src/core/lib/channel/status_util.cc', 'src/core/lib/compression/compression.cc', 'src/core/lib/compression/compression_internal.cc', 'src/core/lib/compression/message_compress.cc', @@ -312,7 +315,6 @@ CORE_SOURCE_FILES = [ 'src/core/ext/filters/client_channel/resolver.cc', 'src/core/ext/filters/client_channel/resolver_registry.cc', 'src/core/ext/filters/client_channel/retry_throttle.cc', - 'src/core/ext/filters/client_channel/status_util.cc', 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.c b/src/ruby/ext/grpc/rb_grpc_imports.generated.c index c045480ff4..1c042739a8 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.c +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.c @@ -68,6 +68,8 @@ grpc_channel_get_info_type grpc_channel_get_info_import; grpc_insecure_channel_create_type grpc_insecure_channel_create_import; grpc_lame_client_channel_create_type grpc_lame_client_channel_create_import; grpc_channel_destroy_type grpc_channel_destroy_import; +grpc_channel_get_trace_type grpc_channel_get_trace_import; +grpc_channel_get_uuid_type grpc_channel_get_uuid_import; grpc_call_cancel_type grpc_call_cancel_import; grpc_call_cancel_with_status_type grpc_call_cancel_with_status_import; grpc_call_ref_type grpc_call_ref_import; @@ -304,6 +306,8 @@ void grpc_rb_load_imports(HMODULE library) { grpc_insecure_channel_create_import = (grpc_insecure_channel_create_type) GetProcAddress(library, "grpc_insecure_channel_create"); grpc_lame_client_channel_create_import = (grpc_lame_client_channel_create_type) GetProcAddress(library, "grpc_lame_client_channel_create"); grpc_channel_destroy_import = (grpc_channel_destroy_type) GetProcAddress(library, "grpc_channel_destroy"); + grpc_channel_get_trace_import = (grpc_channel_get_trace_type) GetProcAddress(library, "grpc_channel_get_trace"); + grpc_channel_get_uuid_import = (grpc_channel_get_uuid_type) GetProcAddress(library, "grpc_channel_get_uuid"); grpc_call_cancel_import = (grpc_call_cancel_type) GetProcAddress(library, "grpc_call_cancel"); grpc_call_cancel_with_status_import = (grpc_call_cancel_with_status_type) GetProcAddress(library, "grpc_call_cancel_with_status"); grpc_call_ref_import = (grpc_call_ref_type) GetProcAddress(library, "grpc_call_ref"); diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.h b/src/ruby/ext/grpc/rb_grpc_imports.generated.h index 4f07452c68..9a09321364 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.h +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.h @@ -179,6 +179,12 @@ extern grpc_lame_client_channel_create_type grpc_lame_client_channel_create_impo typedef void(*grpc_channel_destroy_type)(grpc_channel* channel); extern grpc_channel_destroy_type grpc_channel_destroy_import; #define grpc_channel_destroy grpc_channel_destroy_import +typedef char*(*grpc_channel_get_trace_type)(grpc_channel* channel); +extern grpc_channel_get_trace_type grpc_channel_get_trace_import; +#define grpc_channel_get_trace grpc_channel_get_trace_import +typedef intptr_t(*grpc_channel_get_uuid_type)(grpc_channel* channel); +extern grpc_channel_get_uuid_type grpc_channel_get_uuid_import; +#define grpc_channel_get_uuid grpc_channel_get_uuid_import typedef grpc_call_error(*grpc_call_cancel_type)(grpc_call* call, void* reserved); extern grpc_call_cancel_type grpc_call_cancel_import; #define grpc_call_cancel grpc_call_cancel_import diff --git a/test/core/channel/BUILD b/test/core/channel/BUILD index c5dfd8ef37..6bf4fcdbb8 100644 --- a/test/core/channel/BUILD +++ b/test/core/channel/BUILD @@ -65,3 +65,32 @@ grpc_cc_test( "//test/core/util:grpc_test_util", ], ) + +grpc_cc_test( + name = "channel_trace_test", + srcs = ["channel_trace_test.cc"], + language = "C++", + deps = [ + "//:gpr", + "//:grpc", + "//:grpc++", + "//test/core/util:gpr_test_util", + "//test/core/util:grpc_test_util", + "//test/cpp/util:channel_trace_proto_helper", + ], + external_deps = [ + "gtest", + ], +) + +grpc_cc_test( + name = "status_util_test", + srcs = ["status_util_test.cc"], + language = "C++", + deps = [ + "//:grpc", + ], + external_deps = [ + "gtest", + ], +) diff --git a/test/core/channel/channel_trace_test.cc b/test/core/channel/channel_trace_test.cc new file mode 100644 index 0000000000..3c73e33612 --- /dev/null +++ b/test/core/channel/channel_trace_test.cc @@ -0,0 +1,240 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include + +#include + +#include +#include + +#include "src/core/lib/channel/channel_trace.h" +#include "src/core/lib/channel/channel_trace_registry.h" +#include "src/core/lib/gpr/useful.h" +#include "src/core/lib/iomgr/exec_ctx.h" +#include "src/core/lib/json/json.h" + +#include "test/core/util/test_config.h" +#include "test/cpp/util/channel_trace_proto_helper.h" + +// remove me +#include +#include +#include + +namespace grpc_core { +namespace testing { +namespace { + +grpc_json* GetJsonChild(grpc_json* parent, const char* key) { + EXPECT_NE(parent, nullptr); + for (grpc_json* child = parent->child; child != nullptr; + child = child->next) { + if (child->key != nullptr && strcmp(child->key, key) == 0) return child; + } + return nullptr; +} + +void ValidateJsonArraySize(grpc_json* json, const char* key, + size_t expected_size) { + grpc_json* arr = GetJsonChild(json, key); + ASSERT_NE(arr, nullptr); + ASSERT_EQ(arr->type, GRPC_JSON_ARRAY); + size_t count = 0; + for (grpc_json* child = arr->child; child != nullptr; child = child->next) { + ++count; + } + ASSERT_EQ(count, expected_size); +} + +void ValidateChannelTraceData(grpc_json* json, + size_t num_events_logged_expected, + size_t actual_num_events_expected) { + ASSERT_NE(json, nullptr); + grpc_json* num_events_logged_json = GetJsonChild(json, "numEventsLogged"); + ASSERT_NE(num_events_logged_json, nullptr); + grpc_json* start_time = GetJsonChild(json, "creationTime"); + ASSERT_NE(start_time, nullptr); + size_t num_events_logged = + (size_t)strtol(num_events_logged_json->value, nullptr, 0); + ASSERT_EQ(num_events_logged, num_events_logged_expected); + ValidateJsonArraySize(json, "events", actual_num_events_expected); +} + +void AddSimpleTrace(RefCountedPtr tracer) { + tracer->AddTraceEvent(ChannelTrace::Severity::Info, + grpc_slice_from_static_string("simple trace")); +} + +// checks for the existence of all the required members of the tracer. +void ValidateChannelTrace(RefCountedPtr tracer, + size_t expected_num_event_logged, size_t max_nodes) { + if (!max_nodes) return; + char* json_str = tracer->RenderTrace(); + grpc::testing::ValidateChannelTraceProtoJsonTranslation(json_str); + grpc_json* json = grpc_json_parse_string(json_str); + ValidateChannelTraceData(json, expected_num_event_logged, + GPR_MIN(expected_num_event_logged, max_nodes)); + grpc_json_destroy(json); + gpr_free(json_str); +} + +void ValidateTraceDataMatchedUuidLookup(RefCountedPtr tracer) { + intptr_t uuid = tracer->GetUuid(); + if (uuid == -1) return; // Doesn't make sense to lookup if tracing disabled + char* tracer_json_str = tracer->RenderTrace(); + ChannelTrace* uuid_lookup = + grpc_channel_trace_registry_get_channel_trace(uuid); + char* uuid_lookup_json_str = uuid_lookup->RenderTrace(); + EXPECT_EQ(strcmp(tracer_json_str, uuid_lookup_json_str), 0); + gpr_free(tracer_json_str); + gpr_free(uuid_lookup_json_str); +} + +} // anonymous namespace + +class ChannelTracerTest : public ::testing::TestWithParam {}; + +// Tests basic ChannelTrace functionality like construction, adding trace, and +// lookups by uuid. +TEST_P(ChannelTracerTest, BasicTest) { + grpc_core::ExecCtx exec_ctx; + RefCountedPtr tracer = MakeRefCounted(GetParam()); + AddSimpleTrace(tracer); + AddSimpleTrace(tracer); + ValidateTraceDataMatchedUuidLookup(tracer); + tracer->AddTraceEvent(ChannelTrace::Severity::Info, + grpc_slice_from_static_string("trace three")); + tracer->AddTraceEvent(ChannelTrace::Severity::Error, + grpc_slice_from_static_string("trace four error")); + ValidateChannelTrace(tracer, 4, GetParam()); + AddSimpleTrace(tracer); + AddSimpleTrace(tracer); + ValidateChannelTrace(tracer, 6, GetParam()); + AddSimpleTrace(tracer); + AddSimpleTrace(tracer); + AddSimpleTrace(tracer); + AddSimpleTrace(tracer); + ValidateChannelTrace(tracer, 10, GetParam()); + ValidateTraceDataMatchedUuidLookup(tracer); + tracer.reset(nullptr); +} + +// Tests more complex functionality, like a parent channel tracking +// subchannles. This exercises the ref/unref patterns since the parent tracer +// and this function will both hold refs to the subchannel. +TEST_P(ChannelTracerTest, ComplexTest) { + grpc_core::ExecCtx exec_ctx; + RefCountedPtr tracer = MakeRefCounted(GetParam()); + AddSimpleTrace(tracer); + AddSimpleTrace(tracer); + RefCountedPtr sc1 = MakeRefCounted(GetParam()); + tracer->AddTraceEventReferencingSubchannel( + ChannelTrace::Severity::Info, + grpc_slice_from_static_string("subchannel one created"), sc1); + ValidateChannelTrace(tracer, 3, GetParam()); + AddSimpleTrace(sc1); + AddSimpleTrace(sc1); + AddSimpleTrace(sc1); + ValidateChannelTrace(sc1, 3, GetParam()); + AddSimpleTrace(sc1); + AddSimpleTrace(sc1); + AddSimpleTrace(sc1); + ValidateChannelTrace(sc1, 6, GetParam()); + AddSimpleTrace(tracer); + AddSimpleTrace(tracer); + ValidateChannelTrace(tracer, 5, GetParam()); + ValidateTraceDataMatchedUuidLookup(tracer); + RefCountedPtr sc2 = MakeRefCounted(GetParam()); + tracer->AddTraceEventReferencingChannel( + ChannelTrace::Severity::Info, + grpc_slice_from_static_string("LB channel two created"), sc2); + tracer->AddTraceEventReferencingSubchannel( + ChannelTrace::Severity::Warning, + grpc_slice_from_static_string("subchannel one inactive"), sc1); + ValidateChannelTrace(tracer, 7, GetParam()); + AddSimpleTrace(tracer); + AddSimpleTrace(tracer); + AddSimpleTrace(tracer); + AddSimpleTrace(tracer); + AddSimpleTrace(tracer); + AddSimpleTrace(tracer); + ValidateTraceDataMatchedUuidLookup(tracer); + tracer.reset(nullptr); + sc1.reset(nullptr); + sc2.reset(nullptr); +} + +// Test a case in which the parent channel has subchannels and the subchannels +// have connections. Ensures that everything lives as long as it should then +// gets deleted. +TEST_P(ChannelTracerTest, TestNesting) { + grpc_core::ExecCtx exec_ctx; + RefCountedPtr tracer = MakeRefCounted(GetParam()); + AddSimpleTrace(tracer); + AddSimpleTrace(tracer); + ValidateChannelTrace(tracer, 2, GetParam()); + RefCountedPtr sc1 = MakeRefCounted(GetParam()); + tracer->AddTraceEventReferencingChannel( + ChannelTrace::Severity::Info, + grpc_slice_from_static_string("subchannel one created"), sc1); + ValidateChannelTrace(tracer, 3, GetParam()); + AddSimpleTrace(sc1); + RefCountedPtr conn1 = MakeRefCounted(GetParam()); + // nesting one level deeper. + sc1->AddTraceEventReferencingSubchannel( + ChannelTrace::Severity::Info, + grpc_slice_from_static_string("connection one created"), conn1); + ValidateChannelTrace(tracer, 3, GetParam()); + AddSimpleTrace(conn1); + AddSimpleTrace(tracer); + AddSimpleTrace(tracer); + ValidateChannelTrace(tracer, 5, GetParam()); + ValidateChannelTrace(conn1, 1, GetParam()); + RefCountedPtr sc2 = MakeRefCounted(GetParam()); + tracer->AddTraceEventReferencingSubchannel( + ChannelTrace::Severity::Info, + grpc_slice_from_static_string("subchannel two created"), sc2); + // this trace should not get added to the parents children since it is already + // present in the tracer. + tracer->AddTraceEventReferencingChannel( + ChannelTrace::Severity::Warning, + grpc_slice_from_static_string("subchannel one inactive"), sc1); + AddSimpleTrace(tracer); + ValidateChannelTrace(tracer, 8, GetParam()); + tracer.reset(nullptr); + sc1.reset(nullptr); + sc2.reset(nullptr); + conn1.reset(nullptr); +} + +INSTANTIATE_TEST_CASE_P(ChannelTracerTestSweep, ChannelTracerTest, + ::testing::Values(0, 1, 2, 6, 10, 15)); + +} // namespace testing +} // namespace grpc_core + +int main(int argc, char** argv) { + grpc_test_init(argc, argv); + grpc_init(); + ::testing::InitGoogleTest(&argc, argv); + int ret = RUN_ALL_TESTS(); + grpc_shutdown(); + return ret; +} diff --git a/test/core/channel/status_util_test.cc b/test/core/channel/status_util_test.cc new file mode 100644 index 0000000000..1d64bf1995 --- /dev/null +++ b/test/core/channel/status_util_test.cc @@ -0,0 +1,49 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "src/core/lib/channel/status_util.h" + +#include + +namespace grpc_core { +namespace internal { +namespace { + +TEST(StatusCodeSet, Basic) { + StatusCodeSet set; + EXPECT_TRUE(set.Empty()); + EXPECT_FALSE(set.Contains(GRPC_STATUS_OK)); + EXPECT_FALSE(set.Contains(GRPC_STATUS_UNAVAILABLE)); + set.Add(GRPC_STATUS_OK); + EXPECT_FALSE(set.Empty()); + EXPECT_TRUE(set.Contains(GRPC_STATUS_OK)); + EXPECT_FALSE(set.Contains(GRPC_STATUS_UNAVAILABLE)); + set.Add(GRPC_STATUS_UNAVAILABLE); + EXPECT_FALSE(set.Empty()); + EXPECT_TRUE(set.Contains(GRPC_STATUS_OK)); + EXPECT_TRUE(set.Contains(GRPC_STATUS_UNAVAILABLE)); +} + +} // namespace +} // namespace internal +} // namespace grpc_core + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test/core/client_channel/BUILD b/test/core/client_channel/BUILD index d430b722df..5148dc5f74 100644 --- a/test/core/client_channel/BUILD +++ b/test/core/client_channel/BUILD @@ -53,15 +53,3 @@ grpc_cc_test( "//test/core/util:grpc_test_util", ], ) - -grpc_cc_test( - name = "status_util_test", - srcs = ["status_util_test.cc"], - language = "C++", - deps = [ - "//:grpc", - ], - external_deps = [ - "gtest", - ], -) diff --git a/test/core/client_channel/status_util_test.cc b/test/core/client_channel/status_util_test.cc deleted file mode 100644 index f944990ad2..0000000000 --- a/test/core/client_channel/status_util_test.cc +++ /dev/null @@ -1,49 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "src/core/ext/filters/client_channel/status_util.h" - -#include - -namespace grpc_core { -namespace internal { -namespace { - -TEST(StatusCodeSet, Basic) { - StatusCodeSet set; - EXPECT_TRUE(set.Empty()); - EXPECT_FALSE(set.Contains(GRPC_STATUS_OK)); - EXPECT_FALSE(set.Contains(GRPC_STATUS_UNAVAILABLE)); - set.Add(GRPC_STATUS_OK); - EXPECT_FALSE(set.Empty()); - EXPECT_TRUE(set.Contains(GRPC_STATUS_OK)); - EXPECT_FALSE(set.Contains(GRPC_STATUS_UNAVAILABLE)); - set.Add(GRPC_STATUS_UNAVAILABLE); - EXPECT_FALSE(set.Empty()); - EXPECT_TRUE(set.Contains(GRPC_STATUS_OK)); - EXPECT_TRUE(set.Contains(GRPC_STATUS_UNAVAILABLE)); -} - -} // namespace -} // namespace internal -} // namespace grpc_core - -int main(int argc, char** argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/test/core/surface/public_headers_must_be_c89.c b/test/core/surface/public_headers_must_be_c89.c index bd4dc0b60e..d858603e47 100644 --- a/test/core/surface/public_headers_must_be_c89.c +++ b/test/core/surface/public_headers_must_be_c89.c @@ -106,6 +106,8 @@ int main(int argc, char **argv) { printf("%lx", (unsigned long) grpc_insecure_channel_create); printf("%lx", (unsigned long) grpc_lame_client_channel_create); printf("%lx", (unsigned long) grpc_channel_destroy); + printf("%lx", (unsigned long) grpc_channel_get_trace); + printf("%lx", (unsigned long) grpc_channel_get_uuid); printf("%lx", (unsigned long) grpc_call_cancel); printf("%lx", (unsigned long) grpc_call_cancel_with_status); printf("%lx", (unsigned long) grpc_call_ref); diff --git a/test/cpp/util/BUILD b/test/cpp/util/BUILD index 4f84c73820..4ac8572072 100644 --- a/test/cpp/util/BUILD +++ b/test/cpp/util/BUILD @@ -84,6 +84,24 @@ grpc_cc_library( ], ) +grpc_cc_library( + name = "channel_trace_proto_helper", + srcs = [ + "channel_trace_proto_helper.cc", + ], + hdrs = [ + "channel_trace_proto_helper.h", + ], + deps = [ + "//:grpc++", + "//src/proto/grpc/channelz:channelz_proto", + ], + external_deps = [ + "gtest", + "protobuf", + ], +) + grpc_cc_library( name = "test_util_unsecure", srcs = GRPCXX_TESTUTIL_SRCS, diff --git a/test/cpp/util/channel_trace_proto_helper.cc b/test/cpp/util/channel_trace_proto_helper.cc new file mode 100644 index 0000000000..fbc9f1501c --- /dev/null +++ b/test/cpp/util/channel_trace_proto_helper.cc @@ -0,0 +1,56 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "test/cpp/util/channel_trace_proto_helper.h" + +#include +#include + +#include +#include +#include + +#include "src/proto/grpc/channelz/channelz.pb.h" + +namespace grpc { +namespace testing { + +void ValidateChannelTraceProtoJsonTranslation(char* tracer_json_c_str) { + std::string tracer_json_str(tracer_json_c_str); + grpc::channelz::ChannelTrace channel_trace; + google::protobuf::util::JsonParseOptions parse_options; + // If the following line is failing, then uncomment the last line of the + // comment, and uncomment the lines that print the two strings. You can + // then compare the output, and determine what fields are missing. + // + // options.ignore_unknown_fields = true; + ASSERT_EQ(google::protobuf::util::JsonStringToMessage( + tracer_json_str, &channel_trace, parse_options), + google::protobuf::util::Status::OK); + std::string proto_json_str; + ASSERT_EQ(google::protobuf::util::MessageToJsonString(channel_trace, + &proto_json_str), + google::protobuf::util::Status::OK); + // uncomment these to compare the the json strings. + // gpr_log(GPR_ERROR, "tracer json: %s", tracer_json_str.c_str()); + // gpr_log(GPR_ERROR, "proto json: %s", proto_json_str.c_str()); + ASSERT_EQ(tracer_json_str, proto_json_str); +} + +} // namespace testing +} // namespace grpc diff --git a/test/cpp/util/channel_trace_proto_helper.h b/test/cpp/util/channel_trace_proto_helper.h new file mode 100644 index 0000000000..d7043d9f06 --- /dev/null +++ b/test/cpp/util/channel_trace_proto_helper.h @@ -0,0 +1,30 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_TEST_CPP_UTIL_CHANNEL_TRACE_PROTO_HELPER_H +#define GRPC_TEST_CPP_UTIL_CHANNEL_TRACE_PROTO_HELPER_H + +namespace grpc { +namespace testing { + +void ValidateChannelTraceProtoJsonTranslation(char* tracer_json_c_str); + +} // namespace testing +} // namespace grpc + +#endif // GRPC_TEST_CPP_UTIL_CHANNEL_TRACE_PROTO_HELPER_H diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index c822d9b3cd..52a16d6e98 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -1007,11 +1007,14 @@ src/core/lib/backoff/backoff.h \ src/core/lib/channel/channel_args.h \ src/core/lib/channel/channel_stack.h \ src/core/lib/channel/channel_stack_builder.h \ +src/core/lib/channel/channel_trace.h \ +src/core/lib/channel/channel_trace_registry.h \ src/core/lib/channel/connected_channel.h \ src/core/lib/channel/context.h \ src/core/lib/channel/handshaker.h \ src/core/lib/channel/handshaker_factory.h \ src/core/lib/channel/handshaker_registry.h \ +src/core/lib/channel/status_util.h \ src/core/lib/compression/algorithm_metadata.h \ src/core/lib/compression/compression_internal.h \ src/core/lib/compression/message_compress.h \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 212e1d53dd..2757114b34 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -929,8 +929,6 @@ src/core/ext/filters/client_channel/resolver_registry.cc \ src/core/ext/filters/client_channel/resolver_registry.h \ src/core/ext/filters/client_channel/retry_throttle.cc \ src/core/ext/filters/client_channel/retry_throttle.h \ -src/core/ext/filters/client_channel/status_util.cc \ -src/core/ext/filters/client_channel/status_util.h \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel.h \ src/core/ext/filters/client_channel/subchannel_index.cc \ @@ -1034,6 +1032,10 @@ src/core/lib/channel/channel_stack.cc \ src/core/lib/channel/channel_stack.h \ src/core/lib/channel/channel_stack_builder.cc \ src/core/lib/channel/channel_stack_builder.h \ +src/core/lib/channel/channel_trace.cc \ +src/core/lib/channel/channel_trace.h \ +src/core/lib/channel/channel_trace_registry.cc \ +src/core/lib/channel/channel_trace_registry.h \ src/core/lib/channel/connected_channel.cc \ src/core/lib/channel/connected_channel.h \ src/core/lib/channel/context.h \ @@ -1043,6 +1045,8 @@ src/core/lib/channel/handshaker_factory.cc \ src/core/lib/channel/handshaker_factory.h \ src/core/lib/channel/handshaker_registry.cc \ src/core/lib/channel/handshaker_registry.h \ +src/core/lib/channel/status_util.cc \ +src/core/lib/channel/status_util.h \ src/core/lib/compression/algorithm_metadata.h \ src/core/lib/compression/compression.cc \ src/core/lib/compression/compression_internal.cc \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index f80cd9f2b5..08dc3fa9ea 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -3034,6 +3034,27 @@ "third_party": false, "type": "target" }, + { + "deps": [ + "gpr", + "gpr_test_util", + "grpc", + "grpc++", + "grpc++_channelz_proto", + "grpc++_test", + "grpc++_test_util", + "grpc_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "channel_trace_test", + "src": [ + "test/core/channel/channel_trace_test.cc" + ], + "third_party": false, + "type": "target" + }, { "deps": [ "gpr", @@ -4482,7 +4503,7 @@ "language": "c++", "name": "status_util_test", "src": [ - "test/core/client_channel/status_util_test.cc" + "test/core/channel/status_util_test.cc" ], "third_party": false, "type": "target" @@ -6959,6 +6980,9 @@ "grpc_test_util" ], "headers": [ + "src/proto/grpc/channelz/channelz.grpc.pb.h", + "src/proto/grpc/channelz/channelz.pb.h", + "src/proto/grpc/channelz/channelz_mock.grpc.pb.h", "src/proto/grpc/health/v1/health.grpc.pb.h", "src/proto/grpc/health/v1/health.pb.h", "src/proto/grpc/health/v1/health_mock.grpc.pb.h", @@ -6973,6 +6997,7 @@ "src/proto/grpc/testing/echo_mock.grpc.pb.h", "test/cpp/end2end/test_service_impl.h", "test/cpp/util/byte_buffer_proto_helper.h", + "test/cpp/util/channel_trace_proto_helper.h", "test/cpp/util/create_test_channel.h", "test/cpp/util/string_ref_helper.h", "test/cpp/util/subprocess.h", @@ -6986,6 +7011,8 @@ "test/cpp/end2end/test_service_impl.h", "test/cpp/util/byte_buffer_proto_helper.cc", "test/cpp/util/byte_buffer_proto_helper.h", + "test/cpp/util/channel_trace_proto_helper.cc", + "test/cpp/util/channel_trace_proto_helper.h", "test/cpp/util/create_test_channel.cc", "test/cpp/util/create_test_channel.h", "test/cpp/util/string_ref_helper.cc", @@ -8987,10 +9014,13 @@ "src/core/lib/channel/channel_args.cc", "src/core/lib/channel/channel_stack.cc", "src/core/lib/channel/channel_stack_builder.cc", + "src/core/lib/channel/channel_trace.cc", + "src/core/lib/channel/channel_trace_registry.cc", "src/core/lib/channel/connected_channel.cc", "src/core/lib/channel/handshaker.cc", "src/core/lib/channel/handshaker_factory.cc", "src/core/lib/channel/handshaker_registry.cc", + "src/core/lib/channel/status_util.cc", "src/core/lib/compression/compression.cc", "src/core/lib/compression/compression_internal.cc", "src/core/lib/compression/message_compress.cc", @@ -9155,11 +9185,14 @@ "src/core/lib/channel/channel_args.h", "src/core/lib/channel/channel_stack.h", "src/core/lib/channel/channel_stack_builder.h", + "src/core/lib/channel/channel_trace.h", + "src/core/lib/channel/channel_trace_registry.h", "src/core/lib/channel/connected_channel.h", "src/core/lib/channel/context.h", "src/core/lib/channel/handshaker.h", "src/core/lib/channel/handshaker_factory.h", "src/core/lib/channel/handshaker_registry.h", + "src/core/lib/channel/status_util.h", "src/core/lib/compression/algorithm_metadata.h", "src/core/lib/compression/compression_internal.h", "src/core/lib/compression/message_compress.h", @@ -9301,11 +9334,14 @@ "src/core/lib/channel/channel_args.h", "src/core/lib/channel/channel_stack.h", "src/core/lib/channel/channel_stack_builder.h", + "src/core/lib/channel/channel_trace.h", + "src/core/lib/channel/channel_trace_registry.h", "src/core/lib/channel/connected_channel.h", "src/core/lib/channel/context.h", "src/core/lib/channel/handshaker.h", "src/core/lib/channel/handshaker_factory.h", "src/core/lib/channel/handshaker_registry.h", + "src/core/lib/channel/status_util.h", "src/core/lib/compression/algorithm_metadata.h", "src/core/lib/compression/compression_internal.h", "src/core/lib/compression/message_compress.h", @@ -9453,7 +9489,6 @@ "src/core/ext/filters/client_channel/resolver_factory.h", "src/core/ext/filters/client_channel/resolver_registry.h", "src/core/ext/filters/client_channel/retry_throttle.h", - "src/core/ext/filters/client_channel/status_util.h", "src/core/ext/filters/client_channel/subchannel.h", "src/core/ext/filters/client_channel/subchannel_index.h", "src/core/ext/filters/client_channel/uri_parser.h" @@ -9497,8 +9532,6 @@ "src/core/ext/filters/client_channel/resolver_registry.h", "src/core/ext/filters/client_channel/retry_throttle.cc", "src/core/ext/filters/client_channel/retry_throttle.h", - "src/core/ext/filters/client_channel/status_util.cc", - "src/core/ext/filters/client_channel/status_util.h", "src/core/ext/filters/client_channel/subchannel.cc", "src/core/ext/filters/client_channel/subchannel.h", "src/core/ext/filters/client_channel/subchannel_index.cc", @@ -10437,6 +10470,20 @@ "third_party": false, "type": "filegroup" }, + { + "deps": [], + "headers": [ + "src/proto/grpc/channelz/channelz.grpc.pb.h", + "src/proto/grpc/channelz/channelz.pb.h", + "src/proto/grpc/channelz/channelz_mock.grpc.pb.h" + ], + "is_filegroup": true, + "language": "c++", + "name": "grpc++_channelz_proto", + "src": [], + "third_party": false, + "type": "filegroup" + }, { "deps": [ "grpc_codegen" diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 3d6b6caa2a..8a99792108 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -3649,6 +3649,30 @@ ], "uses_polling": false }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": true, + "language": "c++", + "name": "channel_trace_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": false + }, { "args": [], "benchmark": false, -- cgit v1.2.3 From 99d0cee31bdbc29c63170dfb2100c10da3a6eba7 Mon Sep 17 00:00:00 2001 From: Ruslan Nigmatullin Date: Tue, 20 Mar 2018 09:18:29 -0700 Subject: regenerate projects --- CMakeLists.txt | 44 +++++++++++++++++ Makefile | 57 ++++++++++++++++++++++ config.m4 | 4 ++ config.w32 | 5 ++ gRPC-C++.podspec | 2 + gRPC-Core.podspec | 7 +++ grpc.def | 3 ++ grpc.gemspec | 5 ++ grpc.gyp | 3 ++ package.xml | 5 ++ src/python/grpcio/grpc_core_dependencies.py | 3 ++ src/ruby/ext/grpc/rb_grpc_imports.generated.c | 6 +++ src/ruby/ext/grpc/rb_grpc_imports.generated.h | 9 ++++ test/core/surface/public_headers_must_be_c89.c | 3 ++ tools/doxygen/Doxyfile.core.internal | 5 ++ tools/run_tests/generated/sources_and_headers.json | 29 +++++++++++ tools/run_tests/generated/tests.json | 24 +++++++++ 17 files changed, 214 insertions(+) (limited to 'gRPC-C++.podspec') diff --git a/CMakeLists.txt b/CMakeLists.txt index 77e84a0df8..c9333f5220 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -561,6 +561,7 @@ add_dependencies(buildtests_cxx grpc_tool_test) add_dependencies(buildtests_cxx grpclb_api_test) add_dependencies(buildtests_cxx grpclb_end2end_test) add_dependencies(buildtests_cxx h2_ssl_cert_test) +add_dependencies(buildtests_cxx h2_ssl_session_reuse_test) add_dependencies(buildtests_cxx health_service_end2end_test) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) add_dependencies(buildtests_cxx http2_client) @@ -1114,6 +1115,9 @@ add_library(grpc src/core/ext/filters/deadline/deadline_filter.cc src/core/tsi/alts_transport_security.cc src/core/tsi/fake_transport_security.cc + src/core/tsi/ssl/session_cache/ssl_session_boringssl.cc + src/core/tsi/ssl/session_cache/ssl_session_cache.cc + src/core/tsi/ssl/session_cache/ssl_session_openssl.cc src/core/tsi/ssl_transport_security.cc src/core/tsi/transport_security_grpc.cc src/core/ext/transport/chttp2/server/chttp2_server.cc @@ -1503,6 +1507,9 @@ add_library(grpc_cronet src/core/ext/transport/chttp2/client/chttp2_connector.cc src/core/tsi/alts_transport_security.cc src/core/tsi/fake_transport_security.cc + src/core/tsi/ssl/session_cache/ssl_session_boringssl.cc + src/core/tsi/ssl/session_cache/ssl_session_cache.cc + src/core/tsi/ssl/session_cache/ssl_session_openssl.cc src/core/tsi/ssl_transport_security.cc src/core/tsi/transport_security_grpc.cc src/core/ext/filters/load_reporting/server_load_reporting_filter.cc @@ -11493,6 +11500,43 @@ target_link_libraries(h2_ssl_cert_test endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +add_executable(h2_ssl_session_reuse_test + test/core/end2end/h2_ssl_session_reuse_test.cc + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + + +target_include_directories(h2_ssl_session_reuse_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${_gRPC_SSL_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} + PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} + PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} + PRIVATE ${_gRPC_CARES_INCLUDE_DIR} + PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} + PRIVATE third_party/googletest/googletest/include + PRIVATE third_party/googletest/googletest + PRIVATE third_party/googletest/googlemock/include + PRIVATE third_party/googletest/googlemock + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(h2_ssl_session_reuse_test + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + add_executable(health_service_end2end_test test/cpp/end2end/health_service_end2end_test.cc third_party/googletest/googletest/src/gtest-all.cc diff --git a/Makefile b/Makefile index 3fa0f6617b..e477e672b5 100644 --- a/Makefile +++ b/Makefile @@ -1163,6 +1163,7 @@ grpc_tool_test: $(BINDIR)/$(CONFIG)/grpc_tool_test grpclb_api_test: $(BINDIR)/$(CONFIG)/grpclb_api_test grpclb_end2end_test: $(BINDIR)/$(CONFIG)/grpclb_end2end_test h2_ssl_cert_test: $(BINDIR)/$(CONFIG)/h2_ssl_cert_test +h2_ssl_session_reuse_test: $(BINDIR)/$(CONFIG)/h2_ssl_session_reuse_test health_service_end2end_test: $(BINDIR)/$(CONFIG)/health_service_end2end_test http2_client: $(BINDIR)/$(CONFIG)/http2_client hybrid_end2end_test: $(BINDIR)/$(CONFIG)/hybrid_end2end_test @@ -1641,6 +1642,7 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/grpclb_api_test \ $(BINDIR)/$(CONFIG)/grpclb_end2end_test \ $(BINDIR)/$(CONFIG)/h2_ssl_cert_test \ + $(BINDIR)/$(CONFIG)/h2_ssl_session_reuse_test \ $(BINDIR)/$(CONFIG)/health_service_end2end_test \ $(BINDIR)/$(CONFIG)/http2_client \ $(BINDIR)/$(CONFIG)/hybrid_end2end_test \ @@ -1807,6 +1809,7 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/grpclb_api_test \ $(BINDIR)/$(CONFIG)/grpclb_end2end_test \ $(BINDIR)/$(CONFIG)/h2_ssl_cert_test \ + $(BINDIR)/$(CONFIG)/h2_ssl_session_reuse_test \ $(BINDIR)/$(CONFIG)/health_service_end2end_test \ $(BINDIR)/$(CONFIG)/http2_client \ $(BINDIR)/$(CONFIG)/hybrid_end2end_test \ @@ -2255,6 +2258,8 @@ test_cxx: buildtests_cxx $(Q) $(BINDIR)/$(CONFIG)/grpclb_end2end_test || ( echo test grpclb_end2end_test failed ; exit 1 ) $(E) "[RUN] Testing h2_ssl_cert_test" $(Q) $(BINDIR)/$(CONFIG)/h2_ssl_cert_test || ( echo test h2_ssl_cert_test failed ; exit 1 ) + $(E) "[RUN] Testing h2_ssl_session_reuse_test" + $(Q) $(BINDIR)/$(CONFIG)/h2_ssl_session_reuse_test || ( echo test h2_ssl_session_reuse_test failed ; exit 1 ) $(E) "[RUN] Testing health_service_end2end_test" $(Q) $(BINDIR)/$(CONFIG)/health_service_end2end_test || ( echo test health_service_end2end_test failed ; exit 1 ) $(E) "[RUN] Testing inlined_vector_test" @@ -3419,6 +3424,9 @@ LIBGRPC_SRC = \ src/core/ext/filters/deadline/deadline_filter.cc \ src/core/tsi/alts_transport_security.cc \ src/core/tsi/fake_transport_security.cc \ + src/core/tsi/ssl/session_cache/ssl_session_boringssl.cc \ + src/core/tsi/ssl/session_cache/ssl_session_cache.cc \ + src/core/tsi/ssl/session_cache/ssl_session_openssl.cc \ src/core/tsi/ssl_transport_security.cc \ src/core/tsi/transport_security_grpc.cc \ src/core/ext/transport/chttp2/server/chttp2_server.cc \ @@ -3810,6 +3818,9 @@ LIBGRPC_CRONET_SRC = \ src/core/ext/transport/chttp2/client/chttp2_connector.cc \ src/core/tsi/alts_transport_security.cc \ src/core/tsi/fake_transport_security.cc \ + src/core/tsi/ssl/session_cache/ssl_session_boringssl.cc \ + src/core/tsi/ssl/session_cache/ssl_session_cache.cc \ + src/core/tsi/ssl/session_cache/ssl_session_openssl.cc \ src/core/tsi/ssl_transport_security.cc \ src/core/tsi/transport_security_grpc.cc \ src/core/ext/filters/load_reporting/server_load_reporting_filter.cc \ @@ -17430,6 +17441,49 @@ endif endif +H2_SSL_SESSION_REUSE_TEST_SRC = \ + test/core/end2end/h2_ssl_session_reuse_test.cc \ + +H2_SSL_SESSION_REUSE_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(H2_SSL_SESSION_REUSE_TEST_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/h2_ssl_session_reuse_test: openssl_dep_error + +else + + + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/h2_ssl_session_reuse_test: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/h2_ssl_session_reuse_test: $(PROTOBUF_DEP) $(H2_SSL_SESSION_REUSE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(H2_SSL_SESSION_REUSE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/h2_ssl_session_reuse_test + +endif + +endif + +$(OBJDIR)/$(CONFIG)/test/core/end2end/h2_ssl_session_reuse_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_h2_ssl_session_reuse_test: $(H2_SSL_SESSION_REUSE_TEST_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(H2_SSL_SESSION_REUSE_TEST_OBJS:.o=.dep) +endif +endif + + HEALTH_SERVICE_END2END_TEST_SRC = \ test/cpp/end2end/health_service_end2end_test.cc \ @@ -23505,6 +23559,9 @@ src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc: $(OPE src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc: $(OPENSSL_DEP) src/core/tsi/alts_transport_security.cc: $(OPENSSL_DEP) src/core/tsi/fake_transport_security.cc: $(OPENSSL_DEP) +src/core/tsi/ssl/session_cache/ssl_session_boringssl.cc: $(OPENSSL_DEP) +src/core/tsi/ssl/session_cache/ssl_session_cache.cc: $(OPENSSL_DEP) +src/core/tsi/ssl/session_cache/ssl_session_openssl.cc: $(OPENSSL_DEP) src/core/tsi/ssl_transport_security.cc: $(OPENSSL_DEP) src/core/tsi/transport_security.cc: $(OPENSSL_DEP) src/core/tsi/transport_security_adapter.cc: $(OPENSSL_DEP) diff --git a/config.m4 b/config.m4 index 2f17d0c4b7..9b7b6bbc1b 100644 --- a/config.m4 +++ b/config.m4 @@ -343,6 +343,9 @@ if test "$PHP_GRPC" != "no"; then src/core/ext/filters/deadline/deadline_filter.cc \ src/core/tsi/alts_transport_security.cc \ src/core/tsi/fake_transport_security.cc \ + src/core/tsi/ssl/session_cache/ssl_session_boringssl.cc \ + src/core/tsi/ssl/session_cache/ssl_session_cache.cc \ + src/core/tsi/ssl/session_cache/ssl_session_openssl.cc \ src/core/tsi/ssl_transport_security.cc \ src/core/tsi/transport_security_grpc.cc \ src/core/ext/transport/chttp2/server/chttp2_server.cc \ @@ -700,6 +703,7 @@ if test "$PHP_GRPC" != "no"; then PHP_ADD_BUILD_DIR($ext_builddir/src/core/tsi/alts/frame_protector) PHP_ADD_BUILD_DIR($ext_builddir/src/core/tsi/alts/handshaker) PHP_ADD_BUILD_DIR($ext_builddir/src/core/tsi/alts/zero_copy_frame_protector) + PHP_ADD_BUILD_DIR($ext_builddir/src/core/tsi/ssl/session_cache) PHP_ADD_BUILD_DIR($ext_builddir/third_party/boringssl/crypto) PHP_ADD_BUILD_DIR($ext_builddir/third_party/boringssl/crypto/asn1) PHP_ADD_BUILD_DIR($ext_builddir/third_party/boringssl/crypto/base64) diff --git a/config.w32 b/config.w32 index 78f2fe079d..85c5a5f3fe 100644 --- a/config.w32 +++ b/config.w32 @@ -320,6 +320,9 @@ if (PHP_GRPC != "no") { "src\\core\\ext\\filters\\deadline\\deadline_filter.cc " + "src\\core\\tsi\\alts_transport_security.cc " + "src\\core\\tsi\\fake_transport_security.cc " + + "src\\core\\tsi\\ssl\\session_cache\\ssl_session_boringssl.cc " + + "src\\core\\tsi\\ssl\\session_cache\\ssl_session_cache.cc " + + "src\\core\\tsi\\ssl\\session_cache\\ssl_session_openssl.cc " + "src\\core\\tsi\\ssl_transport_security.cc " + "src\\core\\tsi\\transport_security_grpc.cc " + "src\\core\\ext\\transport\\chttp2\\server\\chttp2_server.cc " + @@ -714,6 +717,8 @@ if (PHP_GRPC != "no") { FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\tsi\\alts\\frame_protector"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\tsi\\alts\\handshaker"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\tsi\\alts\\zero_copy_frame_protector"); + FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\tsi\\ssl"); + FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\tsi\\ssl\\session_cache"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\php"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\php\\ext"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\php\\ext\\grpc"); diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index e1282611b0..6dd67f5134 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -333,6 +333,8 @@ Pod::Spec.new do |s| 'src/core/ext/filters/deadline/deadline_filter.h', 'src/core/tsi/alts_transport_security.h', 'src/core/tsi/fake_transport_security.h', + 'src/core/tsi/ssl/session_cache/ssl_session.h', + 'src/core/tsi/ssl/session_cache/ssl_session_cache.h', 'src/core/tsi/ssl_transport_security.h', 'src/core/tsi/ssl_types.h', 'src/core/tsi/transport_security_grpc.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 39433ff819..1159835341 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -344,6 +344,8 @@ Pod::Spec.new do |s| 'src/core/ext/filters/deadline/deadline_filter.h', 'src/core/tsi/alts_transport_security.h', 'src/core/tsi/fake_transport_security.h', + 'src/core/tsi/ssl/session_cache/ssl_session.h', + 'src/core/tsi/ssl/session_cache/ssl_session_cache.h', 'src/core/tsi/ssl_transport_security.h', 'src/core/tsi/ssl_types.h', 'src/core/tsi/transport_security_grpc.h', @@ -756,6 +758,9 @@ Pod::Spec.new do |s| 'src/core/ext/filters/deadline/deadline_filter.cc', 'src/core/tsi/alts_transport_security.cc', 'src/core/tsi/fake_transport_security.cc', + 'src/core/tsi/ssl/session_cache/ssl_session_boringssl.cc', + 'src/core/tsi/ssl/session_cache/ssl_session_cache.cc', + 'src/core/tsi/ssl/session_cache/ssl_session_openssl.cc', 'src/core/tsi/ssl_transport_security.cc', 'src/core/tsi/transport_security_grpc.cc', 'src/core/ext/transport/chttp2/server/chttp2_server.cc', @@ -911,6 +916,8 @@ Pod::Spec.new do |s| 'src/core/ext/filters/deadline/deadline_filter.h', 'src/core/tsi/alts_transport_security.h', 'src/core/tsi/fake_transport_security.h', + 'src/core/tsi/ssl/session_cache/ssl_session.h', + 'src/core/tsi/ssl/session_cache/ssl_session_cache.h', 'src/core/tsi/ssl_transport_security.h', 'src/core/tsi/ssl_types.h', 'src/core/tsi/transport_security_grpc.h', diff --git a/grpc.def b/grpc.def index 2bafebbbd4..cc19005e68 100644 --- a/grpc.def +++ b/grpc.def @@ -83,6 +83,9 @@ EXPORTS grpc_auth_context_add_property grpc_auth_context_add_cstring_property grpc_auth_context_set_peer_identity_property_name + grpc_ssl_session_cache_create_lru + grpc_ssl_session_cache_destroy + grpc_ssl_session_cache_create_channel_arg grpc_channel_credentials_release grpc_google_default_credentials_create grpc_set_ssl_roots_override_callback diff --git a/grpc.gemspec b/grpc.gemspec index 3a57829943..e1106bc9a1 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -274,6 +274,8 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/deadline/deadline_filter.h ) s.files += %w( src/core/tsi/alts_transport_security.h ) s.files += %w( src/core/tsi/fake_transport_security.h ) + s.files += %w( src/core/tsi/ssl/session_cache/ssl_session.h ) + s.files += %w( src/core/tsi/ssl/session_cache/ssl_session_cache.h ) s.files += %w( src/core/tsi/ssl_transport_security.h ) s.files += %w( src/core/tsi/ssl_types.h ) s.files += %w( src/core/tsi/transport_security_grpc.h ) @@ -689,6 +691,9 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/deadline/deadline_filter.cc ) s.files += %w( src/core/tsi/alts_transport_security.cc ) s.files += %w( src/core/tsi/fake_transport_security.cc ) + s.files += %w( src/core/tsi/ssl/session_cache/ssl_session_boringssl.cc ) + s.files += %w( src/core/tsi/ssl/session_cache/ssl_session_cache.cc ) + s.files += %w( src/core/tsi/ssl/session_cache/ssl_session_openssl.cc ) s.files += %w( src/core/tsi/ssl_transport_security.cc ) s.files += %w( src/core/tsi/transport_security_grpc.cc ) s.files += %w( src/core/ext/transport/chttp2/server/chttp2_server.cc ) diff --git a/grpc.gyp b/grpc.gyp index 403d32831b..1bdebe0019 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -496,6 +496,9 @@ 'src/core/ext/filters/deadline/deadline_filter.cc', 'src/core/tsi/alts_transport_security.cc', 'src/core/tsi/fake_transport_security.cc', + 'src/core/tsi/ssl/session_cache/ssl_session_boringssl.cc', + 'src/core/tsi/ssl/session_cache/ssl_session_cache.cc', + 'src/core/tsi/ssl/session_cache/ssl_session_openssl.cc', 'src/core/tsi/ssl_transport_security.cc', 'src/core/tsi/transport_security_grpc.cc', 'src/core/ext/transport/chttp2/server/chttp2_server.cc', diff --git a/package.xml b/package.xml index 8f0dc55dbf..2a38df8406 100644 --- a/package.xml +++ b/package.xml @@ -281,6 +281,8 @@ + + @@ -696,6 +698,9 @@ + + + diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index d96cbec292..62e54a388a 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -319,6 +319,9 @@ CORE_SOURCE_FILES = [ 'src/core/ext/filters/deadline/deadline_filter.cc', 'src/core/tsi/alts_transport_security.cc', 'src/core/tsi/fake_transport_security.cc', + 'src/core/tsi/ssl/session_cache/ssl_session_boringssl.cc', + 'src/core/tsi/ssl/session_cache/ssl_session_cache.cc', + 'src/core/tsi/ssl/session_cache/ssl_session_openssl.cc', 'src/core/tsi/ssl_transport_security.cc', 'src/core/tsi/transport_security_grpc.cc', 'src/core/ext/transport/chttp2/server/chttp2_server.cc', diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.c b/src/ruby/ext/grpc/rb_grpc_imports.generated.c index c045480ff4..7009bd80f6 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.c +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.c @@ -106,6 +106,9 @@ grpc_auth_context_release_type grpc_auth_context_release_import; grpc_auth_context_add_property_type grpc_auth_context_add_property_import; grpc_auth_context_add_cstring_property_type grpc_auth_context_add_cstring_property_import; grpc_auth_context_set_peer_identity_property_name_type grpc_auth_context_set_peer_identity_property_name_import; +grpc_ssl_session_cache_create_lru_type grpc_ssl_session_cache_create_lru_import; +grpc_ssl_session_cache_destroy_type grpc_ssl_session_cache_destroy_import; +grpc_ssl_session_cache_create_channel_arg_type grpc_ssl_session_cache_create_channel_arg_import; grpc_channel_credentials_release_type grpc_channel_credentials_release_import; grpc_google_default_credentials_create_type grpc_google_default_credentials_create_import; grpc_set_ssl_roots_override_callback_type grpc_set_ssl_roots_override_callback_import; @@ -342,6 +345,9 @@ void grpc_rb_load_imports(HMODULE library) { grpc_auth_context_add_property_import = (grpc_auth_context_add_property_type) GetProcAddress(library, "grpc_auth_context_add_property"); grpc_auth_context_add_cstring_property_import = (grpc_auth_context_add_cstring_property_type) GetProcAddress(library, "grpc_auth_context_add_cstring_property"); grpc_auth_context_set_peer_identity_property_name_import = (grpc_auth_context_set_peer_identity_property_name_type) GetProcAddress(library, "grpc_auth_context_set_peer_identity_property_name"); + grpc_ssl_session_cache_create_lru_import = (grpc_ssl_session_cache_create_lru_type) GetProcAddress(library, "grpc_ssl_session_cache_create_lru"); + grpc_ssl_session_cache_destroy_import = (grpc_ssl_session_cache_destroy_type) GetProcAddress(library, "grpc_ssl_session_cache_destroy"); + grpc_ssl_session_cache_create_channel_arg_import = (grpc_ssl_session_cache_create_channel_arg_type) GetProcAddress(library, "grpc_ssl_session_cache_create_channel_arg"); grpc_channel_credentials_release_import = (grpc_channel_credentials_release_type) GetProcAddress(library, "grpc_channel_credentials_release"); grpc_google_default_credentials_create_import = (grpc_google_default_credentials_create_type) GetProcAddress(library, "grpc_google_default_credentials_create"); grpc_set_ssl_roots_override_callback_import = (grpc_set_ssl_roots_override_callback_type) GetProcAddress(library, "grpc_set_ssl_roots_override_callback"); diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.h b/src/ruby/ext/grpc/rb_grpc_imports.generated.h index 4f07452c68..244976c9c5 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.h +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.h @@ -293,6 +293,15 @@ extern grpc_auth_context_add_cstring_property_type grpc_auth_context_add_cstring typedef int(*grpc_auth_context_set_peer_identity_property_name_type)(grpc_auth_context* ctx, const char* name); extern grpc_auth_context_set_peer_identity_property_name_type grpc_auth_context_set_peer_identity_property_name_import; #define grpc_auth_context_set_peer_identity_property_name grpc_auth_context_set_peer_identity_property_name_import +typedef grpc_ssl_session_cache*(*grpc_ssl_session_cache_create_lru_type)(size_t capacity); +extern grpc_ssl_session_cache_create_lru_type grpc_ssl_session_cache_create_lru_import; +#define grpc_ssl_session_cache_create_lru grpc_ssl_session_cache_create_lru_import +typedef void(*grpc_ssl_session_cache_destroy_type)(grpc_ssl_session_cache* cache); +extern grpc_ssl_session_cache_destroy_type grpc_ssl_session_cache_destroy_import; +#define grpc_ssl_session_cache_destroy grpc_ssl_session_cache_destroy_import +typedef grpc_arg(*grpc_ssl_session_cache_create_channel_arg_type)(grpc_ssl_session_cache* cache); +extern grpc_ssl_session_cache_create_channel_arg_type grpc_ssl_session_cache_create_channel_arg_import; +#define grpc_ssl_session_cache_create_channel_arg grpc_ssl_session_cache_create_channel_arg_import typedef void(*grpc_channel_credentials_release_type)(grpc_channel_credentials* creds); extern grpc_channel_credentials_release_type grpc_channel_credentials_release_import; #define grpc_channel_credentials_release grpc_channel_credentials_release_import diff --git a/test/core/surface/public_headers_must_be_c89.c b/test/core/surface/public_headers_must_be_c89.c index bd4dc0b60e..38a7d7e709 100644 --- a/test/core/surface/public_headers_must_be_c89.c +++ b/test/core/surface/public_headers_must_be_c89.c @@ -141,6 +141,9 @@ int main(int argc, char **argv) { printf("%lx", (unsigned long) grpc_auth_context_add_property); printf("%lx", (unsigned long) grpc_auth_context_add_cstring_property); printf("%lx", (unsigned long) grpc_auth_context_set_peer_identity_property_name); + printf("%lx", (unsigned long) grpc_ssl_session_cache_create_lru); + printf("%lx", (unsigned long) grpc_ssl_session_cache_destroy); + printf("%lx", (unsigned long) grpc_ssl_session_cache_create_channel_arg); printf("%lx", (unsigned long) grpc_channel_credentials_release); printf("%lx", (unsigned long) grpc_google_default_credentials_create); printf("%lx", (unsigned long) grpc_set_ssl_roots_override_callback); diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 212e1d53dd..af0c875b99 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -1478,6 +1478,11 @@ src/core/tsi/alts_transport_security.cc \ src/core/tsi/alts_transport_security.h \ src/core/tsi/fake_transport_security.cc \ src/core/tsi/fake_transport_security.h \ +src/core/tsi/ssl/session_cache/ssl_session.h \ +src/core/tsi/ssl/session_cache/ssl_session_boringssl.cc \ +src/core/tsi/ssl/session_cache/ssl_session_cache.cc \ +src/core/tsi/ssl/session_cache/ssl_session_cache.h \ +src/core/tsi/ssl/session_cache/ssl_session_openssl.cc \ src/core/tsi/ssl_transport_security.cc \ src/core/tsi/ssl_transport_security.h \ src/core/tsi/ssl_types.h \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index f80cd9f2b5..1b11fd13cc 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -3677,6 +3677,28 @@ "third_party": false, "type": "target" }, + { + "deps": [ + "gpr", + "gpr_test_util", + "grpc", + "grpc++", + "grpc++_test", + "grpc_test_util" + ], + "headers": [ + "test/core/end2end/end2end_tests.h" + ], + "is_filegroup": false, + "language": "c++", + "name": "h2_ssl_session_reuse_test", + "src": [ + "test/core/end2end/end2end_tests.h", + "test/core/end2end/h2_ssl_session_reuse_test.cc" + ], + "third_party": false, + "type": "target" + }, { "deps": [ "gpr", @@ -10393,6 +10415,8 @@ "headers": [ "src/core/tsi/alts_transport_security.h", "src/core/tsi/fake_transport_security.h", + "src/core/tsi/ssl/session_cache/ssl_session.h", + "src/core/tsi/ssl/session_cache/ssl_session_cache.h", "src/core/tsi/ssl_transport_security.h", "src/core/tsi/ssl_types.h", "src/core/tsi/transport_security_grpc.h" @@ -10405,6 +10429,11 @@ "src/core/tsi/alts_transport_security.h", "src/core/tsi/fake_transport_security.cc", "src/core/tsi/fake_transport_security.h", + "src/core/tsi/ssl/session_cache/ssl_session.h", + "src/core/tsi/ssl/session_cache/ssl_session_boringssl.cc", + "src/core/tsi/ssl/session_cache/ssl_session_cache.cc", + "src/core/tsi/ssl/session_cache/ssl_session_cache.h", + "src/core/tsi/ssl/session_cache/ssl_session_openssl.cc", "src/core/tsi/ssl_transport_security.cc", "src/core/tsi/ssl_transport_security.h", "src/core/tsi/ssl_types.h", diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 3d6b6caa2a..11f2b9a0dd 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -4249,6 +4249,30 @@ ], "uses_polling": true }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": true, + "language": "c++", + "name": "h2_ssl_session_reuse_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, { "args": [], "benchmark": false, -- cgit v1.2.3 From fa460dcf1d6d2c711be7a88caa93a06310efc4a6 Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Fri, 23 Mar 2018 14:51:41 -0700 Subject: Factor out grpc_add_default_authority_if_not_present --- BUILD | 6 ++-- CMakeLists.txt | 6 ++++ Makefile | 6 ++++ build.yaml | 2 ++ config.m4 | 1 + config.w32 | 1 + gRPC-C++.podspec | 1 + gRPC-Core.podspec | 6 ++++ grpc.gemspec | 2 ++ grpc.gyp | 4 +++ package.xml | 2 ++ src/core/ext/filters/client_channel/authority.cc | 42 ++++++++++++++++++++++ src/core/ext/filters/client_channel/authority.h | 36 +++++++++++++++++++ .../chttp2/client/insecure/channel_create.cc | 24 ++----------- src/python/grpcio/grpc_core_dependencies.py | 1 + tools/doxygen/Doxyfile.core.internal | 2 ++ tools/run_tests/generated/sources_and_headers.json | 3 ++ 17 files changed, 121 insertions(+), 24 deletions(-) create mode 100644 src/core/ext/filters/client_channel/authority.cc create mode 100644 src/core/ext/filters/client_channel/authority.h (limited to 'gRPC-C++.podspec') diff --git a/BUILD b/BUILD index a511896038..b56e6e4719 100644 --- a/BUILD +++ b/BUILD @@ -682,11 +682,11 @@ grpc_cc_library( "src/core/lib/channel/channel_stack_builder.cc", "src/core/lib/channel/channel_trace.cc", "src/core/lib/channel/channel_trace_registry.cc", - "src/core/lib/channel/status_util.cc", "src/core/lib/channel/connected_channel.cc", "src/core/lib/channel/handshaker.cc", "src/core/lib/channel/handshaker_factory.cc", "src/core/lib/channel/handshaker_registry.cc", + "src/core/lib/channel/status_util.cc", "src/core/lib/compression/compression.cc", "src/core/lib/compression/compression_internal.cc", "src/core/lib/compression/message_compress.cc", @@ -829,12 +829,12 @@ grpc_cc_library( "src/core/lib/channel/channel_stack_builder.h", "src/core/lib/channel/channel_trace.h", "src/core/lib/channel/channel_trace_registry.h", - "src/core/lib/channel/status_util.h", "src/core/lib/channel/connected_channel.h", "src/core/lib/channel/context.h", "src/core/lib/channel/handshaker.h", "src/core/lib/channel/handshaker_factory.h", "src/core/lib/channel/handshaker_registry.h", + "src/core/lib/channel/status_util.h", "src/core/lib/compression/algorithm_metadata.h", "src/core/lib/compression/compression_internal.h", "src/core/lib/compression/message_compress.h", @@ -1009,6 +1009,7 @@ grpc_cc_library( grpc_cc_library( name = "grpc_client_channel", srcs = [ + "src/core/ext/filters/client_channel/authority.cc", "src/core/ext/filters/client_channel/backup_poller.cc", "src/core/ext/filters/client_channel/channel_connectivity.cc", "src/core/ext/filters/client_channel/client_channel.cc", @@ -1032,6 +1033,7 @@ grpc_cc_library( "src/core/ext/filters/client_channel/uri_parser.cc", ], hdrs = [ + "src/core/ext/filters/client_channel/authority.h", "src/core/ext/filters/client_channel/backup_poller.h", "src/core/ext/filters/client_channel/client_channel.h", "src/core/ext/filters/client_channel/client_channel_factory.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d4467beea..977cb64a14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1093,6 +1093,7 @@ add_library(grpc src/core/ext/transport/chttp2/client/insecure/channel_create.cc src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc src/core/ext/transport/chttp2/client/chttp2_connector.cc + src/core/ext/filters/client_channel/authority.cc src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc src/core/ext/filters/client_channel/client_channel.cc @@ -1427,6 +1428,7 @@ add_library(grpc_cronet src/core/ext/filters/http/http_filters_plugin.cc src/core/ext/filters/http/message_compress/message_compress_filter.cc src/core/ext/filters/http/server/http_server_filter.cc + src/core/ext/filters/client_channel/authority.cc src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc src/core/ext/filters/client_channel/client_channel.cc @@ -1788,6 +1790,7 @@ add_library(grpc_test_util src/core/lib/transport/transport.cc src/core/lib/transport/transport_op_string.cc src/core/lib/debug/trace.cc + src/core/ext/filters/client_channel/authority.cc src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc src/core/ext/filters/client_channel/client_channel.cc @@ -2090,6 +2093,7 @@ add_library(grpc_test_util_unsecure src/core/lib/transport/transport.cc src/core/lib/transport/transport_op_string.cc src/core/lib/debug/trace.cc + src/core/ext/filters/client_channel/authority.cc src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc src/core/ext/filters/client_channel/client_channel.cc @@ -2405,6 +2409,7 @@ add_library(grpc_unsecure src/core/ext/transport/chttp2/client/insecure/channel_create.cc src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc src/core/ext/transport/chttp2/client/chttp2_connector.cc + src/core/ext/filters/client_channel/authority.cc src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc src/core/ext/filters/client_channel/client_channel.cc @@ -3194,6 +3199,7 @@ add_library(grpc++_cronet src/core/ext/filters/http/http_filters_plugin.cc src/core/ext/filters/http/message_compress/message_compress_filter.cc src/core/ext/filters/http/server/http_server_filter.cc + src/core/ext/filters/client_channel/authority.cc src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc src/core/ext/filters/client_channel/client_channel.cc diff --git a/Makefile b/Makefile index 20992b6a65..e62c94b651 100644 --- a/Makefile +++ b/Makefile @@ -3419,6 +3419,7 @@ LIBGRPC_SRC = \ src/core/ext/transport/chttp2/client/insecure/channel_create.cc \ src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \ src/core/ext/transport/chttp2/client/chttp2_connector.cc \ + src/core/ext/filters/client_channel/authority.cc \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ src/core/ext/filters/client_channel/client_channel.cc \ @@ -3755,6 +3756,7 @@ LIBGRPC_CRONET_SRC = \ src/core/ext/filters/http/http_filters_plugin.cc \ src/core/ext/filters/http/message_compress/message_compress_filter.cc \ src/core/ext/filters/http/server/http_server_filter.cc \ + src/core/ext/filters/client_channel/authority.cc \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ src/core/ext/filters/client_channel/client_channel.cc \ @@ -4117,6 +4119,7 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/transport/transport.cc \ src/core/lib/transport/transport_op_string.cc \ src/core/lib/debug/trace.cc \ + src/core/ext/filters/client_channel/authority.cc \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ src/core/ext/filters/client_channel/client_channel.cc \ @@ -4412,6 +4415,7 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ src/core/lib/transport/transport.cc \ src/core/lib/transport/transport_op_string.cc \ src/core/lib/debug/trace.cc \ + src/core/ext/filters/client_channel/authority.cc \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ src/core/ext/filters/client_channel/client_channel.cc \ @@ -4707,6 +4711,7 @@ LIBGRPC_UNSECURE_SRC = \ src/core/ext/transport/chttp2/client/insecure/channel_create.cc \ src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \ src/core/ext/transport/chttp2/client/chttp2_connector.cc \ + src/core/ext/filters/client_channel/authority.cc \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ src/core/ext/filters/client_channel/client_channel.cc \ @@ -5495,6 +5500,7 @@ LIBGRPC++_CRONET_SRC = \ src/core/ext/filters/http/http_filters_plugin.cc \ src/core/ext/filters/http/message_compress/message_compress_filter.cc \ src/core/ext/filters/http/server/http_server_filter.cc \ + src/core/ext/filters/client_channel/authority.cc \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ src/core/ext/filters/client_channel/client_channel.cc \ diff --git a/build.yaml b/build.yaml index b24eb854ae..46785a1a3f 100644 --- a/build.yaml +++ b/build.yaml @@ -544,6 +544,7 @@ filegroups: - grpc_base - name: grpc_client_channel headers: + - src/core/ext/filters/client_channel/authority.h - src/core/ext/filters/client_channel/backup_poller.h - src/core/ext/filters/client_channel/client_channel.h - src/core/ext/filters/client_channel/client_channel_factory.h @@ -565,6 +566,7 @@ filegroups: - src/core/ext/filters/client_channel/subchannel_index.h - src/core/ext/filters/client_channel/uri_parser.h src: + - src/core/ext/filters/client_channel/authority.cc - src/core/ext/filters/client_channel/backup_poller.cc - src/core/ext/filters/client_channel/channel_connectivity.cc - src/core/ext/filters/client_channel/client_channel.cc diff --git a/config.m4 b/config.m4 index a402e0f767..630fda6d68 100644 --- a/config.m4 +++ b/config.m4 @@ -321,6 +321,7 @@ if test "$PHP_GRPC" != "no"; then src/core/ext/transport/chttp2/client/insecure/channel_create.cc \ src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \ src/core/ext/transport/chttp2/client/chttp2_connector.cc \ + src/core/ext/filters/client_channel/authority.cc \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ src/core/ext/filters/client_channel/client_channel.cc \ diff --git a/config.w32 b/config.w32 index ba908b5e46..3623f2070e 100644 --- a/config.w32 +++ b/config.w32 @@ -298,6 +298,7 @@ if (PHP_GRPC != "no") { "src\\core\\ext\\transport\\chttp2\\client\\insecure\\channel_create.cc " + "src\\core\\ext\\transport\\chttp2\\client\\insecure\\channel_create_posix.cc " + "src\\core\\ext\\transport\\chttp2\\client\\chttp2_connector.cc " + + "src\\core\\ext\\filters\\client_channel\\authority.cc " + "src\\core\\ext\\filters\\client_channel\\backup_poller.cc " + "src\\core\\ext\\filters\\client_channel\\channel_connectivity.cc " + "src\\core\\ext\\filters\\client_channel\\client_channel.cc " + diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 2501377127..403674d1ee 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -309,6 +309,7 @@ Pod::Spec.new do |s| 'src/core/tsi/transport_security_adapter.h', 'src/core/tsi/transport_security_interface.h', 'src/core/ext/transport/chttp2/client/chttp2_connector.h', + 'src/core/ext/filters/client_channel/authority.h', 'src/core/ext/filters/client_channel/backup_poller.h', 'src/core/ext/filters/client_channel/client_channel.h', 'src/core/ext/filters/client_channel/client_channel_factory.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 137903249b..f9f9b77261 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -319,6 +319,7 @@ Pod::Spec.new do |s| 'src/core/tsi/transport_security_adapter.h', 'src/core/tsi/transport_security_interface.h', 'src/core/ext/transport/chttp2/client/chttp2_connector.h', + 'src/core/ext/filters/client_channel/authority.h', 'src/core/ext/filters/client_channel/backup_poller.h', 'src/core/ext/filters/client_channel/client_channel.h', 'src/core/ext/filters/client_channel/client_channel_factory.h', @@ -738,6 +739,7 @@ Pod::Spec.new do |s| 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', + 'src/core/ext/filters/client_channel/authority.cc', 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', 'src/core/ext/filters/client_channel/client_channel.cc', @@ -897,6 +899,7 @@ Pod::Spec.new do |s| 'src/core/tsi/transport_security_adapter.h', 'src/core/tsi/transport_security_interface.h', 'src/core/ext/transport/chttp2/client/chttp2_connector.h', + 'src/core/ext/filters/client_channel/authority.h', 'src/core/ext/filters/client_channel/backup_poller.h', 'src/core/ext/filters/client_channel/client_channel.h', 'src/core/ext/filters/client_channel/client_channel_factory.h', @@ -1380,6 +1383,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/http/client/http_client_filter.h', 'src/core/ext/filters/http/message_compress/message_compress_filter.h', 'src/core/ext/filters/http/server/http_server_filter.h', + 'src/core/ext/filters/client_channel/authority.h', 'src/core/ext/filters/client_channel/backup_poller.h', 'src/core/ext/filters/client_channel/client_channel.h', 'src/core/ext/filters/client_channel/client_channel_factory.h', @@ -1646,6 +1650,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/http/http_filters_plugin.cc', 'src/core/ext/filters/http/message_compress/message_compress_filter.cc', 'src/core/ext/filters/http/server/http_server_filter.cc', + 'src/core/ext/filters/client_channel/authority.cc', 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', 'src/core/ext/filters/client_channel/client_channel.cc', @@ -1930,6 +1935,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/http/client/http_client_filter.h', 'src/core/ext/filters/http/message_compress/message_compress_filter.h', 'src/core/ext/filters/http/server/http_server_filter.h', + 'src/core/ext/filters/client_channel/authority.h', 'src/core/ext/filters/client_channel/backup_poller.h', 'src/core/ext/filters/client_channel/client_channel.h', 'src/core/ext/filters/client_channel/client_channel_factory.h', diff --git a/grpc.gemspec b/grpc.gemspec index 1c0cfe35c5..dfb0fbb0ad 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -250,6 +250,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/tsi/transport_security_adapter.h ) s.files += %w( src/core/tsi/transport_security_interface.h ) s.files += %w( src/core/ext/transport/chttp2/client/chttp2_connector.h ) + s.files += %w( src/core/ext/filters/client_channel/authority.h ) s.files += %w( src/core/ext/filters/client_channel/backup_poller.h ) s.files += %w( src/core/ext/filters/client_channel/client_channel.h ) s.files += %w( src/core/ext/filters/client_channel/client_channel_factory.h ) @@ -672,6 +673,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/transport/chttp2/client/insecure/channel_create.cc ) s.files += %w( src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc ) s.files += %w( src/core/ext/transport/chttp2/client/chttp2_connector.cc ) + s.files += %w( src/core/ext/filters/client_channel/authority.cc ) s.files += %w( src/core/ext/filters/client_channel/backup_poller.cc ) s.files += %w( src/core/ext/filters/client_channel/channel_connectivity.cc ) s.files += %w( src/core/ext/filters/client_channel/client_channel.cc ) diff --git a/grpc.gyp b/grpc.gyp index 424641641e..7235e33849 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -474,6 +474,7 @@ 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', + 'src/core/ext/filters/client_channel/authority.cc', 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', 'src/core/ext/filters/client_channel/client_channel.cc', @@ -730,6 +731,7 @@ 'src/core/lib/transport/transport.cc', 'src/core/lib/transport/transport_op_string.cc', 'src/core/lib/debug/trace.cc', + 'src/core/ext/filters/client_channel/authority.cc', 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', 'src/core/ext/filters/client_channel/client_channel.cc', @@ -960,6 +962,7 @@ 'src/core/lib/transport/transport.cc', 'src/core/lib/transport/transport_op_string.cc', 'src/core/lib/debug/trace.cc', + 'src/core/ext/filters/client_channel/authority.cc', 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', 'src/core/ext/filters/client_channel/client_channel.cc', @@ -1202,6 +1205,7 @@ 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', + 'src/core/ext/filters/client_channel/authority.cc', 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', 'src/core/ext/filters/client_channel/client_channel.cc', diff --git a/package.xml b/package.xml index a8e4667c86..5bb146db8a 100644 --- a/package.xml +++ b/package.xml @@ -257,6 +257,7 @@ + @@ -679,6 +680,7 @@ + diff --git a/src/core/ext/filters/client_channel/authority.cc b/src/core/ext/filters/client_channel/authority.cc new file mode 100644 index 0000000000..46a9f39aed --- /dev/null +++ b/src/core/ext/filters/client_channel/authority.cc @@ -0,0 +1,42 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/ext/filters/client_channel/authority.h" + +grpc_channel_args* grpc_add_default_authority_if_not_present( + const grpc_channel_args* args) { + const bool has_default_authority = + grpc_channel_args_find(args, GRPC_ARG_DEFAULT_AUTHORITY) != nullptr; + grpc_arg new_args[1]; + size_t num_new_args = 0; + grpc_core::UniquePtr default_authority; + if (!has_default_authority) { + const grpc_arg* server_uri_arg = + grpc_channel_args_find(args, GRPC_ARG_SERVER_URI); + const char* server_uri_str = grpc_channel_arg_get_string(server_uri_arg); + GPR_ASSERT(server_uri_str != nullptr); + default_authority = + grpc_core::ResolverRegistry::GetDefaultAuthority(server_uri_str); + GPR_ASSERT(default_authority != nullptr); + new_args[num_new_args++] = grpc_channel_arg_string_create( + const_cast(GRPC_ARG_DEFAULT_AUTHORITY), default_authority.get()); + } + return grpc_channel_args_copy_and_add(args, new_args, num_new_args); +} diff --git a/src/core/ext/filters/client_channel/authority.h b/src/core/ext/filters/client_channel/authority.h new file mode 100644 index 0000000000..0923e9d56c --- /dev/null +++ b/src/core/ext/filters/client_channel/authority.h @@ -0,0 +1,36 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_AUTHORITY_H +#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_AUTHORITY_H + +#include + +#include + +#include "src/core/ext/filters/client_channel/client_channel.h" +#include "src/core/ext/filters/client_channel/resolver_registry.h" +#include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/gprpp/memory.h" + +/// Returns a copy of \a args with the default authority channel arg set if it +/// wasn't already present. +grpc_channel_args* grpc_add_default_authority_if_not_present( + const grpc_channel_args* args); + +#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_AUTHORITY_H */ diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc index 9fb87c2164..5b08b6cd36 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc @@ -25,6 +25,7 @@ #include #include +#include "src/core/ext/filters/client_channel/authority.h" #include "src/core/ext/filters/client_channel/client_channel.h" #include "src/core/ext/filters/client_channel/resolver_registry.h" #include "src/core/ext/transport/chttp2/client/chttp2_connector.h" @@ -38,33 +39,12 @@ static void client_channel_factory_ref( static void client_channel_factory_unref( grpc_client_channel_factory* cc_factory) {} -static grpc_channel_args* add_default_authority_if_not_present( - const grpc_channel_args* args) { - const bool has_default_authority = - grpc_channel_args_find(args, GRPC_ARG_DEFAULT_AUTHORITY) != nullptr; - grpc_arg new_args[1]; - size_t num_new_args = 0; - grpc_core::UniquePtr default_authority; - if (!has_default_authority) { - const grpc_arg* server_uri_arg = - grpc_channel_args_find(args, GRPC_ARG_SERVER_URI); - const char* server_uri_str = grpc_channel_arg_get_string(server_uri_arg); - GPR_ASSERT(server_uri_str != nullptr); - default_authority = - grpc_core::ResolverRegistry::GetDefaultAuthority(server_uri_str); - GPR_ASSERT(default_authority != nullptr); - new_args[num_new_args++] = grpc_channel_arg_string_create( - const_cast(GRPC_ARG_DEFAULT_AUTHORITY), default_authority.get()); - } - return grpc_channel_args_copy_and_add(args, new_args, num_new_args); -} - static grpc_subchannel* client_channel_factory_create_subchannel( grpc_client_channel_factory* cc_factory, const grpc_subchannel_args* args) { grpc_subchannel_args* final_sc_args = static_cast(gpr_malloc(sizeof(*final_sc_args))); memcpy(final_sc_args, args, sizeof(*args)); - final_sc_args->args = add_default_authority_if_not_present(args->args); + final_sc_args->args = grpc_add_default_authority_if_not_present(args->args); grpc_connector* connector = grpc_chttp2_connector_create(); grpc_subchannel* s = grpc_subchannel_create(connector, final_sc_args); grpc_connector_unref(connector); diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index b3b114ef7c..2ec9e07e95 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -297,6 +297,7 @@ CORE_SOURCE_FILES = [ 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', + 'src/core/ext/filters/client_channel/authority.cc', 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', 'src/core/ext/filters/client_channel/client_channel.cc', diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 859efd29d1..92b97c4c82 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -866,6 +866,8 @@ src/core/README.md \ src/core/ext/README.md \ src/core/ext/census/grpc_context.cc \ src/core/ext/filters/client_channel/README.md \ +src/core/ext/filters/client_channel/authority.cc \ +src/core/ext/filters/client_channel/authority.h \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/backup_poller.h \ src/core/ext/filters/client_channel/channel_connectivity.cc \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 965487fbd6..b46a2b7f9a 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -9501,6 +9501,7 @@ "grpc_deadline_filter" ], "headers": [ + "src/core/ext/filters/client_channel/authority.h", "src/core/ext/filters/client_channel/backup_poller.h", "src/core/ext/filters/client_channel/client_channel.h", "src/core/ext/filters/client_channel/client_channel_factory.h", @@ -9526,6 +9527,8 @@ "language": "c", "name": "grpc_client_channel", "src": [ + "src/core/ext/filters/client_channel/authority.cc", + "src/core/ext/filters/client_channel/authority.h", "src/core/ext/filters/client_channel/backup_poller.cc", "src/core/ext/filters/client_channel/backup_poller.h", "src/core/ext/filters/client_channel/channel_connectivity.cc", -- cgit v1.2.3 From e44efe099de238a8f5ddc613baad2d3b4fd9438d Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Mon, 26 Mar 2018 16:23:07 -0700 Subject: rest of pr comments --- CMakeLists.txt | 12 +++---- Makefile | 12 +++---- build.yaml | 4 +-- config.m4 | 2 +- config.w32 | 2 +- gRPC-C++.podspec | 2 +- gRPC-Core.podspec | 12 +++---- grpc.gemspec | 4 +-- grpc.gyp | 8 ++--- package.xml | 4 +-- src/core/ext/filters/client_channel/authority.cc | 42 ---------------------- src/core/ext/filters/client_channel/authority.h | 8 ++--- src/core/ext/transport/chttp2/client/authority.cc | 42 ++++++++++++++++++++++ src/core/ext/transport/chttp2/client/authority.h | 36 +++++++++++++++++++ .../chttp2/client/insecure/channel_create.cc | 2 +- src/python/grpcio/grpc_core_dependencies.py | 2 +- tools/doxygen/Doxyfile.core.internal | 4 +-- tools/run_tests/generated/sources_and_headers.json | 10 +++--- 18 files changed, 122 insertions(+), 86 deletions(-) delete mode 100644 src/core/ext/filters/client_channel/authority.cc create mode 100644 src/core/ext/transport/chttp2/client/authority.cc create mode 100644 src/core/ext/transport/chttp2/client/authority.h (limited to 'gRPC-C++.podspec') diff --git a/CMakeLists.txt b/CMakeLists.txt index 92bc643cb4..1b5848b667 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1093,7 +1093,6 @@ add_library(grpc src/core/ext/transport/chttp2/client/insecure/channel_create.cc src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc src/core/ext/transport/chttp2/client/chttp2_connector.cc - src/core/ext/filters/client_channel/authority.cc src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc src/core/ext/filters/client_channel/client_channel.cc @@ -1115,6 +1114,7 @@ add_library(grpc src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc + src/core/ext/transport/chttp2/client/authority.cc src/core/ext/filters/deadline/deadline_filter.cc src/core/tsi/alts_transport_security.cc src/core/tsi/fake_transport_security.cc @@ -1428,7 +1428,6 @@ add_library(grpc_cronet src/core/ext/filters/http/http_filters_plugin.cc src/core/ext/filters/http/message_compress/message_compress_filter.cc src/core/ext/filters/http/server/http_server_filter.cc - src/core/ext/filters/client_channel/authority.cc src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc src/core/ext/filters/client_channel/client_channel.cc @@ -1450,6 +1449,7 @@ add_library(grpc_cronet src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc + src/core/ext/transport/chttp2/client/authority.cc src/core/lib/http/httpcli_security_connector.cc src/core/lib/security/context/security_context.cc src/core/lib/security/credentials/alts/alts_credentials.cc @@ -1790,7 +1790,6 @@ add_library(grpc_test_util src/core/lib/transport/transport.cc src/core/lib/transport/transport_op_string.cc src/core/lib/debug/trace.cc - src/core/ext/filters/client_channel/authority.cc src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc src/core/ext/filters/client_channel/client_channel.cc @@ -1812,6 +1811,7 @@ add_library(grpc_test_util src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc + src/core/ext/transport/chttp2/client/authority.cc src/core/ext/filters/deadline/deadline_filter.cc src/core/ext/transport/chttp2/transport/bin_decoder.cc src/core/ext/transport/chttp2/transport/bin_encoder.cc @@ -2093,7 +2093,6 @@ add_library(grpc_test_util_unsecure src/core/lib/transport/transport.cc src/core/lib/transport/transport_op_string.cc src/core/lib/debug/trace.cc - src/core/ext/filters/client_channel/authority.cc src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc src/core/ext/filters/client_channel/client_channel.cc @@ -2115,6 +2114,7 @@ add_library(grpc_test_util_unsecure src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc + src/core/ext/transport/chttp2/client/authority.cc src/core/ext/filters/deadline/deadline_filter.cc src/core/ext/transport/chttp2/transport/bin_decoder.cc src/core/ext/transport/chttp2/transport/bin_encoder.cc @@ -2409,7 +2409,6 @@ add_library(grpc_unsecure src/core/ext/transport/chttp2/client/insecure/channel_create.cc src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc src/core/ext/transport/chttp2/client/chttp2_connector.cc - src/core/ext/filters/client_channel/authority.cc src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc src/core/ext/filters/client_channel/client_channel.cc @@ -2431,6 +2430,7 @@ add_library(grpc_unsecure src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc + src/core/ext/transport/chttp2/client/authority.cc src/core/ext/filters/deadline/deadline_filter.cc src/core/ext/transport/inproc/inproc_plugin.cc src/core/ext/transport/inproc/inproc_transport.cc @@ -3199,7 +3199,6 @@ add_library(grpc++_cronet src/core/ext/filters/http/http_filters_plugin.cc src/core/ext/filters/http/message_compress/message_compress_filter.cc src/core/ext/filters/http/server/http_server_filter.cc - src/core/ext/filters/client_channel/authority.cc src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc src/core/ext/filters/client_channel/client_channel.cc @@ -3221,6 +3220,7 @@ add_library(grpc++_cronet src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc + src/core/ext/transport/chttp2/client/authority.cc src/core/ext/filters/deadline/deadline_filter.cc src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc diff --git a/Makefile b/Makefile index 49f892b6a4..f213f6de2e 100644 --- a/Makefile +++ b/Makefile @@ -3419,7 +3419,6 @@ LIBGRPC_SRC = \ src/core/ext/transport/chttp2/client/insecure/channel_create.cc \ src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \ src/core/ext/transport/chttp2/client/chttp2_connector.cc \ - src/core/ext/filters/client_channel/authority.cc \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ src/core/ext/filters/client_channel/client_channel.cc \ @@ -3441,6 +3440,7 @@ LIBGRPC_SRC = \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ + src/core/ext/transport/chttp2/client/authority.cc \ src/core/ext/filters/deadline/deadline_filter.cc \ src/core/tsi/alts_transport_security.cc \ src/core/tsi/fake_transport_security.cc \ @@ -3756,7 +3756,6 @@ LIBGRPC_CRONET_SRC = \ src/core/ext/filters/http/http_filters_plugin.cc \ src/core/ext/filters/http/message_compress/message_compress_filter.cc \ src/core/ext/filters/http/server/http_server_filter.cc \ - src/core/ext/filters/client_channel/authority.cc \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ src/core/ext/filters/client_channel/client_channel.cc \ @@ -3778,6 +3777,7 @@ LIBGRPC_CRONET_SRC = \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ + src/core/ext/transport/chttp2/client/authority.cc \ src/core/lib/http/httpcli_security_connector.cc \ src/core/lib/security/context/security_context.cc \ src/core/lib/security/credentials/alts/alts_credentials.cc \ @@ -4119,7 +4119,6 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/transport/transport.cc \ src/core/lib/transport/transport_op_string.cc \ src/core/lib/debug/trace.cc \ - src/core/ext/filters/client_channel/authority.cc \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ src/core/ext/filters/client_channel/client_channel.cc \ @@ -4141,6 +4140,7 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ + src/core/ext/transport/chttp2/client/authority.cc \ src/core/ext/filters/deadline/deadline_filter.cc \ src/core/ext/transport/chttp2/transport/bin_decoder.cc \ src/core/ext/transport/chttp2/transport/bin_encoder.cc \ @@ -4415,7 +4415,6 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ src/core/lib/transport/transport.cc \ src/core/lib/transport/transport_op_string.cc \ src/core/lib/debug/trace.cc \ - src/core/ext/filters/client_channel/authority.cc \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ src/core/ext/filters/client_channel/client_channel.cc \ @@ -4437,6 +4436,7 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ + src/core/ext/transport/chttp2/client/authority.cc \ src/core/ext/filters/deadline/deadline_filter.cc \ src/core/ext/transport/chttp2/transport/bin_decoder.cc \ src/core/ext/transport/chttp2/transport/bin_encoder.cc \ @@ -4711,7 +4711,6 @@ LIBGRPC_UNSECURE_SRC = \ src/core/ext/transport/chttp2/client/insecure/channel_create.cc \ src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \ src/core/ext/transport/chttp2/client/chttp2_connector.cc \ - src/core/ext/filters/client_channel/authority.cc \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ src/core/ext/filters/client_channel/client_channel.cc \ @@ -4733,6 +4732,7 @@ LIBGRPC_UNSECURE_SRC = \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ + src/core/ext/transport/chttp2/client/authority.cc \ src/core/ext/filters/deadline/deadline_filter.cc \ src/core/ext/transport/inproc/inproc_plugin.cc \ src/core/ext/transport/inproc/inproc_transport.cc \ @@ -5500,7 +5500,6 @@ LIBGRPC++_CRONET_SRC = \ src/core/ext/filters/http/http_filters_plugin.cc \ src/core/ext/filters/http/message_compress/message_compress_filter.cc \ src/core/ext/filters/http/server/http_server_filter.cc \ - src/core/ext/filters/client_channel/authority.cc \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ src/core/ext/filters/client_channel/client_channel.cc \ @@ -5522,6 +5521,7 @@ LIBGRPC++_CRONET_SRC = \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ + src/core/ext/transport/chttp2/client/authority.cc \ src/core/ext/filters/deadline/deadline_filter.cc \ src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc \ src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc \ diff --git a/build.yaml b/build.yaml index 46785a1a3f..6550ab87b2 100644 --- a/build.yaml +++ b/build.yaml @@ -544,7 +544,6 @@ filegroups: - grpc_base - name: grpc_client_channel headers: - - src/core/ext/filters/client_channel/authority.h - src/core/ext/filters/client_channel/backup_poller.h - src/core/ext/filters/client_channel/client_channel.h - src/core/ext/filters/client_channel/client_channel_factory.h @@ -565,8 +564,8 @@ filegroups: - src/core/ext/filters/client_channel/subchannel.h - src/core/ext/filters/client_channel/subchannel_index.h - src/core/ext/filters/client_channel/uri_parser.h + - src/core/ext/transport/chttp2/client/authority.h src: - - src/core/ext/filters/client_channel/authority.cc - src/core/ext/filters/client_channel/backup_poller.cc - src/core/ext/filters/client_channel/channel_connectivity.cc - src/core/ext/filters/client_channel/client_channel.cc @@ -588,6 +587,7 @@ filegroups: - src/core/ext/filters/client_channel/subchannel.cc - src/core/ext/filters/client_channel/subchannel_index.cc - src/core/ext/filters/client_channel/uri_parser.cc + - src/core/ext/transport/chttp2/client/authority.cc plugin: grpc_client_channel uses: - grpc_base diff --git a/config.m4 b/config.m4 index 630fda6d68..5d39c14e6a 100644 --- a/config.m4 +++ b/config.m4 @@ -321,7 +321,6 @@ if test "$PHP_GRPC" != "no"; then src/core/ext/transport/chttp2/client/insecure/channel_create.cc \ src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \ src/core/ext/transport/chttp2/client/chttp2_connector.cc \ - src/core/ext/filters/client_channel/authority.cc \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ src/core/ext/filters/client_channel/client_channel.cc \ @@ -343,6 +342,7 @@ if test "$PHP_GRPC" != "no"; then src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ + src/core/ext/transport/chttp2/client/authority.cc \ src/core/ext/filters/deadline/deadline_filter.cc \ src/core/tsi/alts_transport_security.cc \ src/core/tsi/fake_transport_security.cc \ diff --git a/config.w32 b/config.w32 index 3623f2070e..208059b38a 100644 --- a/config.w32 +++ b/config.w32 @@ -298,7 +298,6 @@ if (PHP_GRPC != "no") { "src\\core\\ext\\transport\\chttp2\\client\\insecure\\channel_create.cc " + "src\\core\\ext\\transport\\chttp2\\client\\insecure\\channel_create_posix.cc " + "src\\core\\ext\\transport\\chttp2\\client\\chttp2_connector.cc " + - "src\\core\\ext\\filters\\client_channel\\authority.cc " + "src\\core\\ext\\filters\\client_channel\\backup_poller.cc " + "src\\core\\ext\\filters\\client_channel\\channel_connectivity.cc " + "src\\core\\ext\\filters\\client_channel\\client_channel.cc " + @@ -320,6 +319,7 @@ if (PHP_GRPC != "no") { "src\\core\\ext\\filters\\client_channel\\subchannel.cc " + "src\\core\\ext\\filters\\client_channel\\subchannel_index.cc " + "src\\core\\ext\\filters\\client_channel\\uri_parser.cc " + + "src\\core\\ext\\transport\\chttp2\\client\\authority.cc " + "src\\core\\ext\\filters\\deadline\\deadline_filter.cc " + "src\\core\\tsi\\alts_transport_security.cc " + "src\\core\\tsi\\fake_transport_security.cc " + diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 403674d1ee..7b3e65c793 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -309,7 +309,6 @@ Pod::Spec.new do |s| 'src/core/tsi/transport_security_adapter.h', 'src/core/tsi/transport_security_interface.h', 'src/core/ext/transport/chttp2/client/chttp2_connector.h', - 'src/core/ext/filters/client_channel/authority.h', 'src/core/ext/filters/client_channel/backup_poller.h', 'src/core/ext/filters/client_channel/client_channel.h', 'src/core/ext/filters/client_channel/client_channel_factory.h', @@ -330,6 +329,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/subchannel.h', 'src/core/ext/filters/client_channel/subchannel_index.h', 'src/core/ext/filters/client_channel/uri_parser.h', + 'src/core/ext/transport/chttp2/client/authority.h', 'src/core/ext/filters/deadline/deadline_filter.h', 'src/core/tsi/alts_transport_security.h', 'src/core/tsi/fake_transport_security.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index e7cb395446..3b4f108844 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -319,7 +319,6 @@ Pod::Spec.new do |s| 'src/core/tsi/transport_security_adapter.h', 'src/core/tsi/transport_security_interface.h', 'src/core/ext/transport/chttp2/client/chttp2_connector.h', - 'src/core/ext/filters/client_channel/authority.h', 'src/core/ext/filters/client_channel/backup_poller.h', 'src/core/ext/filters/client_channel/client_channel.h', 'src/core/ext/filters/client_channel/client_channel_factory.h', @@ -340,6 +339,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/subchannel.h', 'src/core/ext/filters/client_channel/subchannel_index.h', 'src/core/ext/filters/client_channel/uri_parser.h', + 'src/core/ext/transport/chttp2/client/authority.h', 'src/core/ext/filters/deadline/deadline_filter.h', 'src/core/tsi/alts_transport_security.h', 'src/core/tsi/fake_transport_security.h', @@ -739,7 +739,6 @@ Pod::Spec.new do |s| 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', - 'src/core/ext/filters/client_channel/authority.cc', 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', 'src/core/ext/filters/client_channel/client_channel.cc', @@ -761,6 +760,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', + 'src/core/ext/transport/chttp2/client/authority.cc', 'src/core/ext/filters/deadline/deadline_filter.cc', 'src/core/tsi/alts_transport_security.cc', 'src/core/tsi/fake_transport_security.cc', @@ -899,7 +899,6 @@ Pod::Spec.new do |s| 'src/core/tsi/transport_security_adapter.h', 'src/core/tsi/transport_security_interface.h', 'src/core/ext/transport/chttp2/client/chttp2_connector.h', - 'src/core/ext/filters/client_channel/authority.h', 'src/core/ext/filters/client_channel/backup_poller.h', 'src/core/ext/filters/client_channel/client_channel.h', 'src/core/ext/filters/client_channel/client_channel_factory.h', @@ -920,6 +919,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/subchannel.h', 'src/core/ext/filters/client_channel/subchannel_index.h', 'src/core/ext/filters/client_channel/uri_parser.h', + 'src/core/ext/transport/chttp2/client/authority.h', 'src/core/ext/filters/deadline/deadline_filter.h', 'src/core/tsi/alts_transport_security.h', 'src/core/tsi/fake_transport_security.h', @@ -1383,7 +1383,6 @@ Pod::Spec.new do |s| 'src/core/ext/filters/http/client/http_client_filter.h', 'src/core/ext/filters/http/message_compress/message_compress_filter.h', 'src/core/ext/filters/http/server/http_server_filter.h', - 'src/core/ext/filters/client_channel/authority.h', 'src/core/ext/filters/client_channel/backup_poller.h', 'src/core/ext/filters/client_channel/client_channel.h', 'src/core/ext/filters/client_channel/client_channel_factory.h', @@ -1404,6 +1403,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/subchannel.h', 'src/core/ext/filters/client_channel/subchannel_index.h', 'src/core/ext/filters/client_channel/uri_parser.h', + 'src/core/ext/transport/chttp2/client/authority.h', 'src/core/lib/security/context/security_context.h', 'src/core/lib/security/credentials/alts/alts_credentials.h', 'src/core/lib/security/credentials/composite/composite_credentials.h', @@ -1650,7 +1650,6 @@ Pod::Spec.new do |s| 'src/core/ext/filters/http/http_filters_plugin.cc', 'src/core/ext/filters/http/message_compress/message_compress_filter.cc', 'src/core/ext/filters/http/server/http_server_filter.cc', - 'src/core/ext/filters/client_channel/authority.cc', 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', 'src/core/ext/filters/client_channel/client_channel.cc', @@ -1672,6 +1671,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', + 'src/core/ext/transport/chttp2/client/authority.cc', 'src/core/lib/http/httpcli_security_connector.cc', 'src/core/lib/security/context/security_context.cc', 'src/core/lib/security/credentials/alts/alts_credentials.cc', @@ -1935,7 +1935,6 @@ Pod::Spec.new do |s| 'src/core/ext/filters/http/client/http_client_filter.h', 'src/core/ext/filters/http/message_compress/message_compress_filter.h', 'src/core/ext/filters/http/server/http_server_filter.h', - 'src/core/ext/filters/client_channel/authority.h', 'src/core/ext/filters/client_channel/backup_poller.h', 'src/core/ext/filters/client_channel/client_channel.h', 'src/core/ext/filters/client_channel/client_channel_factory.h', @@ -1956,6 +1955,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/subchannel.h', 'src/core/ext/filters/client_channel/subchannel_index.h', 'src/core/ext/filters/client_channel/uri_parser.h', + 'src/core/ext/transport/chttp2/client/authority.h', 'src/core/lib/security/context/security_context.h', 'src/core/lib/security/credentials/alts/alts_credentials.h', 'src/core/lib/security/credentials/composite/composite_credentials.h', diff --git a/grpc.gemspec b/grpc.gemspec index dfb0fbb0ad..d5d052d35c 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -250,7 +250,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/tsi/transport_security_adapter.h ) s.files += %w( src/core/tsi/transport_security_interface.h ) s.files += %w( src/core/ext/transport/chttp2/client/chttp2_connector.h ) - s.files += %w( src/core/ext/filters/client_channel/authority.h ) s.files += %w( src/core/ext/filters/client_channel/backup_poller.h ) s.files += %w( src/core/ext/filters/client_channel/client_channel.h ) s.files += %w( src/core/ext/filters/client_channel/client_channel_factory.h ) @@ -271,6 +270,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/client_channel/subchannel.h ) s.files += %w( src/core/ext/filters/client_channel/subchannel_index.h ) s.files += %w( src/core/ext/filters/client_channel/uri_parser.h ) + s.files += %w( src/core/ext/transport/chttp2/client/authority.h ) s.files += %w( src/core/ext/filters/deadline/deadline_filter.h ) s.files += %w( src/core/tsi/alts_transport_security.h ) s.files += %w( src/core/tsi/fake_transport_security.h ) @@ -673,7 +673,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/transport/chttp2/client/insecure/channel_create.cc ) s.files += %w( src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc ) s.files += %w( src/core/ext/transport/chttp2/client/chttp2_connector.cc ) - s.files += %w( src/core/ext/filters/client_channel/authority.cc ) s.files += %w( src/core/ext/filters/client_channel/backup_poller.cc ) s.files += %w( src/core/ext/filters/client_channel/channel_connectivity.cc ) s.files += %w( src/core/ext/filters/client_channel/client_channel.cc ) @@ -695,6 +694,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/client_channel/subchannel.cc ) s.files += %w( src/core/ext/filters/client_channel/subchannel_index.cc ) s.files += %w( src/core/ext/filters/client_channel/uri_parser.cc ) + s.files += %w( src/core/ext/transport/chttp2/client/authority.cc ) s.files += %w( src/core/ext/filters/deadline/deadline_filter.cc ) s.files += %w( src/core/tsi/alts_transport_security.cc ) s.files += %w( src/core/tsi/fake_transport_security.cc ) diff --git a/grpc.gyp b/grpc.gyp index 9587bbfc44..9e1c91012b 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -474,7 +474,6 @@ 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', - 'src/core/ext/filters/client_channel/authority.cc', 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', 'src/core/ext/filters/client_channel/client_channel.cc', @@ -496,6 +495,7 @@ 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', + 'src/core/ext/transport/chttp2/client/authority.cc', 'src/core/ext/filters/deadline/deadline_filter.cc', 'src/core/tsi/alts_transport_security.cc', 'src/core/tsi/fake_transport_security.cc', @@ -731,7 +731,6 @@ 'src/core/lib/transport/transport.cc', 'src/core/lib/transport/transport_op_string.cc', 'src/core/lib/debug/trace.cc', - 'src/core/ext/filters/client_channel/authority.cc', 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', 'src/core/ext/filters/client_channel/client_channel.cc', @@ -753,6 +752,7 @@ 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', + 'src/core/ext/transport/chttp2/client/authority.cc', 'src/core/ext/filters/deadline/deadline_filter.cc', 'src/core/ext/transport/chttp2/transport/bin_decoder.cc', 'src/core/ext/transport/chttp2/transport/bin_encoder.cc', @@ -962,7 +962,6 @@ 'src/core/lib/transport/transport.cc', 'src/core/lib/transport/transport_op_string.cc', 'src/core/lib/debug/trace.cc', - 'src/core/ext/filters/client_channel/authority.cc', 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', 'src/core/ext/filters/client_channel/client_channel.cc', @@ -984,6 +983,7 @@ 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', + 'src/core/ext/transport/chttp2/client/authority.cc', 'src/core/ext/filters/deadline/deadline_filter.cc', 'src/core/ext/transport/chttp2/transport/bin_decoder.cc', 'src/core/ext/transport/chttp2/transport/bin_encoder.cc', @@ -1205,7 +1205,6 @@ 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', - 'src/core/ext/filters/client_channel/authority.cc', 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', 'src/core/ext/filters/client_channel/client_channel.cc', @@ -1227,6 +1226,7 @@ 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', + 'src/core/ext/transport/chttp2/client/authority.cc', 'src/core/ext/filters/deadline/deadline_filter.cc', 'src/core/ext/transport/inproc/inproc_plugin.cc', 'src/core/ext/transport/inproc/inproc_transport.cc', diff --git a/package.xml b/package.xml index 5bb146db8a..f616e56d51 100644 --- a/package.xml +++ b/package.xml @@ -257,7 +257,6 @@ - @@ -278,6 +277,7 @@ + @@ -680,7 +680,6 @@ - @@ -702,6 +701,7 @@ + diff --git a/src/core/ext/filters/client_channel/authority.cc b/src/core/ext/filters/client_channel/authority.cc deleted file mode 100644 index 46a9f39aed..0000000000 --- a/src/core/ext/filters/client_channel/authority.cc +++ /dev/null @@ -1,42 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/ext/filters/client_channel/authority.h" - -grpc_channel_args* grpc_add_default_authority_if_not_present( - const grpc_channel_args* args) { - const bool has_default_authority = - grpc_channel_args_find(args, GRPC_ARG_DEFAULT_AUTHORITY) != nullptr; - grpc_arg new_args[1]; - size_t num_new_args = 0; - grpc_core::UniquePtr default_authority; - if (!has_default_authority) { - const grpc_arg* server_uri_arg = - grpc_channel_args_find(args, GRPC_ARG_SERVER_URI); - const char* server_uri_str = grpc_channel_arg_get_string(server_uri_arg); - GPR_ASSERT(server_uri_str != nullptr); - default_authority = - grpc_core::ResolverRegistry::GetDefaultAuthority(server_uri_str); - GPR_ASSERT(default_authority != nullptr); - new_args[num_new_args++] = grpc_channel_arg_string_create( - const_cast(GRPC_ARG_DEFAULT_AUTHORITY), default_authority.get()); - } - return grpc_channel_args_copy_and_add(args, new_args, num_new_args); -} diff --git a/src/core/ext/filters/client_channel/authority.h b/src/core/ext/filters/client_channel/authority.h index 0923e9d56c..642584ef56 100644 --- a/src/core/ext/filters/client_channel/authority.h +++ b/src/core/ext/filters/client_channel/authority.h @@ -16,8 +16,8 @@ * */ -#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_AUTHORITY_H -#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_AUTHORITY_H +#ifndef GRPC_CORE_EXT_TRANSPORT_CHTTP2_CLIENT_AUTHORITY_H +#define GRPC_CORE_EXT_TRANSPORT_CHTTP2_CLIENT_AUTHORITY_H #include @@ -30,7 +30,7 @@ /// Returns a copy of \a args with the default authority channel arg set if it /// wasn't already present. -grpc_channel_args* grpc_add_default_authority_if_not_present( +grpc_channel_args* grpc_default_authority_add_if_not_present( const grpc_channel_args* args); -#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_AUTHORITY_H */ +#endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_CLIENT_AUTHORITY_H */ diff --git a/src/core/ext/transport/chttp2/client/authority.cc b/src/core/ext/transport/chttp2/client/authority.cc new file mode 100644 index 0000000000..bad3153b01 --- /dev/null +++ b/src/core/ext/transport/chttp2/client/authority.cc @@ -0,0 +1,42 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "src/core/ext/transport/chttp2/client/authority.h" + +grpc_channel_args* grpc_default_authority_add_if_not_present( + const grpc_channel_args* args) { + const bool has_default_authority = + grpc_channel_args_find(args, GRPC_ARG_DEFAULT_AUTHORITY) != nullptr; + grpc_arg new_args[1]; + size_t num_new_args = 0; + grpc_core::UniquePtr default_authority; + if (!has_default_authority) { + const grpc_arg* server_uri_arg = + grpc_channel_args_find(args, GRPC_ARG_SERVER_URI); + const char* server_uri_str = grpc_channel_arg_get_string(server_uri_arg); + GPR_ASSERT(server_uri_str != nullptr); + default_authority = + grpc_core::ResolverRegistry::GetDefaultAuthority(server_uri_str); + GPR_ASSERT(default_authority != nullptr); + new_args[num_new_args++] = grpc_channel_arg_string_create( + const_cast(GRPC_ARG_DEFAULT_AUTHORITY), default_authority.get()); + } + return grpc_channel_args_copy_and_add(args, new_args, num_new_args); +} diff --git a/src/core/ext/transport/chttp2/client/authority.h b/src/core/ext/transport/chttp2/client/authority.h new file mode 100644 index 0000000000..fa08bd7073 --- /dev/null +++ b/src/core/ext/transport/chttp2/client/authority.h @@ -0,0 +1,36 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_AUTHORITY_H +#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_AUTHORITY_H + +#include + +#include + +#include "src/core/ext/filters/client_channel/client_channel.h" +#include "src/core/ext/filters/client_channel/resolver_registry.h" +#include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/gprpp/memory.h" + +/// Returns a copy of \a args with the default authority channel arg set if it +/// wasn't already present. +grpc_channel_args* grpc_default_authority_add_if_not_present( + const grpc_channel_args* args); + +#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_AUTHORITY_H */ diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc index 5b08b6cd36..baac4fb9b2 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc @@ -44,7 +44,7 @@ static grpc_subchannel* client_channel_factory_create_subchannel( grpc_subchannel_args* final_sc_args = static_cast(gpr_malloc(sizeof(*final_sc_args))); memcpy(final_sc_args, args, sizeof(*args)); - final_sc_args->args = grpc_add_default_authority_if_not_present(args->args); + final_sc_args->args = grpc_default_authority_add_if_not_present(args->args); grpc_connector* connector = grpc_chttp2_connector_create(); grpc_subchannel* s = grpc_subchannel_create(connector, final_sc_args); grpc_connector_unref(connector); diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 2ec9e07e95..8d35849411 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -297,7 +297,6 @@ CORE_SOURCE_FILES = [ 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', - 'src/core/ext/filters/client_channel/authority.cc', 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', 'src/core/ext/filters/client_channel/client_channel.cc', @@ -319,6 +318,7 @@ CORE_SOURCE_FILES = [ 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', + 'src/core/ext/transport/chttp2/client/authority.cc', 'src/core/ext/filters/deadline/deadline_filter.cc', 'src/core/tsi/alts_transport_security.cc', 'src/core/tsi/fake_transport_security.cc', diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 92b97c4c82..b5869a6231 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -866,8 +866,6 @@ src/core/README.md \ src/core/ext/README.md \ src/core/ext/census/grpc_context.cc \ src/core/ext/filters/client_channel/README.md \ -src/core/ext/filters/client_channel/authority.cc \ -src/core/ext/filters/client_channel/authority.h \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/backup_poller.h \ src/core/ext/filters/client_channel/channel_connectivity.cc \ @@ -964,6 +962,8 @@ src/core/ext/transport/README.md \ src/core/ext/transport/chttp2/README.md \ src/core/ext/transport/chttp2/alpn/alpn.cc \ src/core/ext/transport/chttp2/alpn/alpn.h \ +src/core/ext/transport/chttp2/client/authority.cc \ +src/core/ext/transport/chttp2/client/authority.h \ src/core/ext/transport/chttp2/client/chttp2_connector.cc \ src/core/ext/transport/chttp2/client/chttp2_connector.h \ src/core/ext/transport/chttp2/client/insecure/README.md \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 92e9f939b7..4a3a9edf26 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -9503,7 +9503,6 @@ "grpc_deadline_filter" ], "headers": [ - "src/core/ext/filters/client_channel/authority.h", "src/core/ext/filters/client_channel/backup_poller.h", "src/core/ext/filters/client_channel/client_channel.h", "src/core/ext/filters/client_channel/client_channel_factory.h", @@ -9523,14 +9522,13 @@ "src/core/ext/filters/client_channel/retry_throttle.h", "src/core/ext/filters/client_channel/subchannel.h", "src/core/ext/filters/client_channel/subchannel_index.h", - "src/core/ext/filters/client_channel/uri_parser.h" + "src/core/ext/filters/client_channel/uri_parser.h", + "src/core/ext/transport/chttp2/client/authority.h" ], "is_filegroup": true, "language": "c", "name": "grpc_client_channel", "src": [ - "src/core/ext/filters/client_channel/authority.cc", - "src/core/ext/filters/client_channel/authority.h", "src/core/ext/filters/client_channel/backup_poller.cc", "src/core/ext/filters/client_channel/backup_poller.h", "src/core/ext/filters/client_channel/channel_connectivity.cc", @@ -9571,7 +9569,9 @@ "src/core/ext/filters/client_channel/subchannel_index.cc", "src/core/ext/filters/client_channel/subchannel_index.h", "src/core/ext/filters/client_channel/uri_parser.cc", - "src/core/ext/filters/client_channel/uri_parser.h" + "src/core/ext/filters/client_channel/uri_parser.h", + "src/core/ext/transport/chttp2/client/authority.cc", + "src/core/ext/transport/chttp2/client/authority.h" ], "third_party": false, "type": "filegroup" -- cgit v1.2.3 From 49f625f232bc859cbb59a0de37bbd1d66b8b8ec7 Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Tue, 27 Mar 2018 11:23:49 -0700 Subject: more comments --- BUILD | 2 ++ CMakeLists.txt | 10 +++--- Makefile | 10 +++--- build.yaml | 4 +-- config.m4 | 2 +- config.w32 | 2 +- gRPC-C++.podspec | 2 +- gRPC-Core.podspec | 12 ++++---- grpc.gemspec | 4 +-- grpc.gyp | 6 ++-- include/grpc/impl/codegen/grpc_types.h | 10 ------ package.xml | 4 +-- src/core/ext/filters/client_channel/authority.h | 36 ---------------------- .../security_connector/security_connector.cc | 2 +- src/python/grpcio/grpc_core_dependencies.py | 2 +- test/core/end2end/tests/call_host_override.cc | 2 +- tools/run_tests/generated/sources_and_headers.json | 10 +++--- 17 files changed, 35 insertions(+), 85 deletions(-) delete mode 100644 src/core/ext/filters/client_channel/authority.h (limited to 'gRPC-C++.podspec') diff --git a/BUILD b/BUILD index b56e6e4719..7900b8d23d 100644 --- a/BUILD +++ b/BUILD @@ -1485,9 +1485,11 @@ grpc_cc_library( grpc_cc_library( name = "grpc_transport_chttp2_client_connector", srcs = [ + "src/core/ext/transport/chttp2/client/authority.cc", "src/core/ext/transport/chttp2/client/chttp2_connector.cc", ], hdrs = [ + "src/core/ext/transport/chttp2/client/authority.h", "src/core/ext/transport/chttp2/client/chttp2_connector.h", ], language = "c++", diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b5848b667..a50017dc00 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1092,6 +1092,7 @@ add_library(grpc src/core/tsi/transport_security_adapter.cc src/core/ext/transport/chttp2/client/insecure/channel_create.cc src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc + src/core/ext/transport/chttp2/client/authority.cc src/core/ext/transport/chttp2/client/chttp2_connector.cc src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc @@ -1114,7 +1115,6 @@ add_library(grpc src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc - src/core/ext/transport/chttp2/client/authority.cc src/core/ext/filters/deadline/deadline_filter.cc src/core/tsi/alts_transport_security.cc src/core/tsi/fake_transport_security.cc @@ -1449,7 +1449,6 @@ add_library(grpc_cronet src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc - src/core/ext/transport/chttp2/client/authority.cc src/core/lib/http/httpcli_security_connector.cc src/core/lib/security/context/security_context.cc src/core/lib/security/credentials/alts/alts_credentials.cc @@ -1514,6 +1513,7 @@ add_library(grpc_cronet src/core/tsi/transport_security_adapter.cc src/core/ext/transport/chttp2/client/insecure/channel_create.cc src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc + src/core/ext/transport/chttp2/client/authority.cc src/core/ext/transport/chttp2/client/chttp2_connector.cc src/core/tsi/alts_transport_security.cc src/core/tsi/fake_transport_security.cc @@ -1811,7 +1811,6 @@ add_library(grpc_test_util src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc - src/core/ext/transport/chttp2/client/authority.cc src/core/ext/filters/deadline/deadline_filter.cc src/core/ext/transport/chttp2/transport/bin_decoder.cc src/core/ext/transport/chttp2/transport/bin_encoder.cc @@ -2114,7 +2113,6 @@ add_library(grpc_test_util_unsecure src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc - src/core/ext/transport/chttp2/client/authority.cc src/core/ext/filters/deadline/deadline_filter.cc src/core/ext/transport/chttp2/transport/bin_decoder.cc src/core/ext/transport/chttp2/transport/bin_encoder.cc @@ -2408,6 +2406,7 @@ add_library(grpc_unsecure src/core/ext/transport/chttp2/server/chttp2_server.cc src/core/ext/transport/chttp2/client/insecure/channel_create.cc src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc + src/core/ext/transport/chttp2/client/authority.cc src/core/ext/transport/chttp2/client/chttp2_connector.cc src/core/ext/filters/client_channel/backup_poller.cc src/core/ext/filters/client_channel/channel_connectivity.cc @@ -2430,7 +2429,6 @@ add_library(grpc_unsecure src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc - src/core/ext/transport/chttp2/client/authority.cc src/core/ext/filters/deadline/deadline_filter.cc src/core/ext/transport/inproc/inproc_plugin.cc src/core/ext/transport/inproc/inproc_transport.cc @@ -3022,6 +3020,7 @@ add_library(grpc++_cronet src/cpp/codegen/codegen_init.cc src/core/ext/transport/chttp2/client/insecure/channel_create.cc src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc + src/core/ext/transport/chttp2/client/authority.cc src/core/ext/transport/chttp2/client/chttp2_connector.cc src/core/ext/transport/chttp2/transport/bin_decoder.cc src/core/ext/transport/chttp2/transport/bin_encoder.cc @@ -3220,7 +3219,6 @@ add_library(grpc++_cronet src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel_index.cc src/core/ext/filters/client_channel/uri_parser.cc - src/core/ext/transport/chttp2/client/authority.cc src/core/ext/filters/deadline/deadline_filter.cc src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc diff --git a/Makefile b/Makefile index f213f6de2e..af01e2380f 100644 --- a/Makefile +++ b/Makefile @@ -3418,6 +3418,7 @@ LIBGRPC_SRC = \ src/core/tsi/transport_security_adapter.cc \ src/core/ext/transport/chttp2/client/insecure/channel_create.cc \ src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \ + src/core/ext/transport/chttp2/client/authority.cc \ src/core/ext/transport/chttp2/client/chttp2_connector.cc \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ @@ -3440,7 +3441,6 @@ LIBGRPC_SRC = \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ - src/core/ext/transport/chttp2/client/authority.cc \ src/core/ext/filters/deadline/deadline_filter.cc \ src/core/tsi/alts_transport_security.cc \ src/core/tsi/fake_transport_security.cc \ @@ -3777,7 +3777,6 @@ LIBGRPC_CRONET_SRC = \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ - src/core/ext/transport/chttp2/client/authority.cc \ src/core/lib/http/httpcli_security_connector.cc \ src/core/lib/security/context/security_context.cc \ src/core/lib/security/credentials/alts/alts_credentials.cc \ @@ -3842,6 +3841,7 @@ LIBGRPC_CRONET_SRC = \ src/core/tsi/transport_security_adapter.cc \ src/core/ext/transport/chttp2/client/insecure/channel_create.cc \ src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \ + src/core/ext/transport/chttp2/client/authority.cc \ src/core/ext/transport/chttp2/client/chttp2_connector.cc \ src/core/tsi/alts_transport_security.cc \ src/core/tsi/fake_transport_security.cc \ @@ -4140,7 +4140,6 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ - src/core/ext/transport/chttp2/client/authority.cc \ src/core/ext/filters/deadline/deadline_filter.cc \ src/core/ext/transport/chttp2/transport/bin_decoder.cc \ src/core/ext/transport/chttp2/transport/bin_encoder.cc \ @@ -4436,7 +4435,6 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ - src/core/ext/transport/chttp2/client/authority.cc \ src/core/ext/filters/deadline/deadline_filter.cc \ src/core/ext/transport/chttp2/transport/bin_decoder.cc \ src/core/ext/transport/chttp2/transport/bin_encoder.cc \ @@ -4710,6 +4708,7 @@ LIBGRPC_UNSECURE_SRC = \ src/core/ext/transport/chttp2/server/chttp2_server.cc \ src/core/ext/transport/chttp2/client/insecure/channel_create.cc \ src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \ + src/core/ext/transport/chttp2/client/authority.cc \ src/core/ext/transport/chttp2/client/chttp2_connector.cc \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ @@ -4732,7 +4731,6 @@ LIBGRPC_UNSECURE_SRC = \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ - src/core/ext/transport/chttp2/client/authority.cc \ src/core/ext/filters/deadline/deadline_filter.cc \ src/core/ext/transport/inproc/inproc_plugin.cc \ src/core/ext/transport/inproc/inproc_transport.cc \ @@ -5323,6 +5321,7 @@ LIBGRPC++_CRONET_SRC = \ src/cpp/codegen/codegen_init.cc \ src/core/ext/transport/chttp2/client/insecure/channel_create.cc \ src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \ + src/core/ext/transport/chttp2/client/authority.cc \ src/core/ext/transport/chttp2/client/chttp2_connector.cc \ src/core/ext/transport/chttp2/transport/bin_decoder.cc \ src/core/ext/transport/chttp2/transport/bin_encoder.cc \ @@ -5521,7 +5520,6 @@ LIBGRPC++_CRONET_SRC = \ src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ - src/core/ext/transport/chttp2/client/authority.cc \ src/core/ext/filters/deadline/deadline_filter.cc \ src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc \ src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc \ diff --git a/build.yaml b/build.yaml index 6550ab87b2..1bdca1065f 100644 --- a/build.yaml +++ b/build.yaml @@ -564,7 +564,6 @@ filegroups: - src/core/ext/filters/client_channel/subchannel.h - src/core/ext/filters/client_channel/subchannel_index.h - src/core/ext/filters/client_channel/uri_parser.h - - src/core/ext/transport/chttp2/client/authority.h src: - src/core/ext/filters/client_channel/backup_poller.cc - src/core/ext/filters/client_channel/channel_connectivity.cc @@ -587,7 +586,6 @@ filegroups: - src/core/ext/filters/client_channel/subchannel.cc - src/core/ext/filters/client_channel/subchannel_index.cc - src/core/ext/filters/client_channel/uri_parser.cc - - src/core/ext/transport/chttp2/client/authority.cc plugin: grpc_client_channel uses: - grpc_base @@ -939,8 +937,10 @@ filegroups: - gpr - name: grpc_transport_chttp2_client_connector headers: + - src/core/ext/transport/chttp2/client/authority.h - src/core/ext/transport/chttp2/client/chttp2_connector.h src: + - src/core/ext/transport/chttp2/client/authority.cc - src/core/ext/transport/chttp2/client/chttp2_connector.cc uses: - grpc_transport_chttp2 diff --git a/config.m4 b/config.m4 index 5d39c14e6a..f1abdd8df4 100644 --- a/config.m4 +++ b/config.m4 @@ -320,6 +320,7 @@ if test "$PHP_GRPC" != "no"; then src/core/tsi/transport_security_adapter.cc \ src/core/ext/transport/chttp2/client/insecure/channel_create.cc \ src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \ + src/core/ext/transport/chttp2/client/authority.cc \ src/core/ext/transport/chttp2/client/chttp2_connector.cc \ src/core/ext/filters/client_channel/backup_poller.cc \ src/core/ext/filters/client_channel/channel_connectivity.cc \ @@ -342,7 +343,6 @@ if test "$PHP_GRPC" != "no"; then src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel_index.cc \ src/core/ext/filters/client_channel/uri_parser.cc \ - src/core/ext/transport/chttp2/client/authority.cc \ src/core/ext/filters/deadline/deadline_filter.cc \ src/core/tsi/alts_transport_security.cc \ src/core/tsi/fake_transport_security.cc \ diff --git a/config.w32 b/config.w32 index 208059b38a..efabab48a6 100644 --- a/config.w32 +++ b/config.w32 @@ -297,6 +297,7 @@ if (PHP_GRPC != "no") { "src\\core\\tsi\\transport_security_adapter.cc " + "src\\core\\ext\\transport\\chttp2\\client\\insecure\\channel_create.cc " + "src\\core\\ext\\transport\\chttp2\\client\\insecure\\channel_create_posix.cc " + + "src\\core\\ext\\transport\\chttp2\\client\\authority.cc " + "src\\core\\ext\\transport\\chttp2\\client\\chttp2_connector.cc " + "src\\core\\ext\\filters\\client_channel\\backup_poller.cc " + "src\\core\\ext\\filters\\client_channel\\channel_connectivity.cc " + @@ -319,7 +320,6 @@ if (PHP_GRPC != "no") { "src\\core\\ext\\filters\\client_channel\\subchannel.cc " + "src\\core\\ext\\filters\\client_channel\\subchannel_index.cc " + "src\\core\\ext\\filters\\client_channel\\uri_parser.cc " + - "src\\core\\ext\\transport\\chttp2\\client\\authority.cc " + "src\\core\\ext\\filters\\deadline\\deadline_filter.cc " + "src\\core\\tsi\\alts_transport_security.cc " + "src\\core\\tsi\\fake_transport_security.cc " + diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 7b3e65c793..9d4d15a9a1 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -308,6 +308,7 @@ Pod::Spec.new do |s| 'src/core/tsi/transport_security.h', 'src/core/tsi/transport_security_adapter.h', 'src/core/tsi/transport_security_interface.h', + 'src/core/ext/transport/chttp2/client/authority.h', 'src/core/ext/transport/chttp2/client/chttp2_connector.h', 'src/core/ext/filters/client_channel/backup_poller.h', 'src/core/ext/filters/client_channel/client_channel.h', @@ -329,7 +330,6 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/subchannel.h', 'src/core/ext/filters/client_channel/subchannel_index.h', 'src/core/ext/filters/client_channel/uri_parser.h', - 'src/core/ext/transport/chttp2/client/authority.h', 'src/core/ext/filters/deadline/deadline_filter.h', 'src/core/tsi/alts_transport_security.h', 'src/core/tsi/fake_transport_security.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 3b4f108844..a4bf934100 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -318,6 +318,7 @@ Pod::Spec.new do |s| 'src/core/tsi/transport_security.h', 'src/core/tsi/transport_security_adapter.h', 'src/core/tsi/transport_security_interface.h', + 'src/core/ext/transport/chttp2/client/authority.h', 'src/core/ext/transport/chttp2/client/chttp2_connector.h', 'src/core/ext/filters/client_channel/backup_poller.h', 'src/core/ext/filters/client_channel/client_channel.h', @@ -339,7 +340,6 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/subchannel.h', 'src/core/ext/filters/client_channel/subchannel_index.h', 'src/core/ext/filters/client_channel/uri_parser.h', - 'src/core/ext/transport/chttp2/client/authority.h', 'src/core/ext/filters/deadline/deadline_filter.h', 'src/core/tsi/alts_transport_security.h', 'src/core/tsi/fake_transport_security.h', @@ -738,6 +738,7 @@ Pod::Spec.new do |s| 'src/core/tsi/transport_security_adapter.cc', 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', + 'src/core/ext/transport/chttp2/client/authority.cc', 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', @@ -760,7 +761,6 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', - 'src/core/ext/transport/chttp2/client/authority.cc', 'src/core/ext/filters/deadline/deadline_filter.cc', 'src/core/tsi/alts_transport_security.cc', 'src/core/tsi/fake_transport_security.cc', @@ -898,6 +898,7 @@ Pod::Spec.new do |s| 'src/core/tsi/transport_security.h', 'src/core/tsi/transport_security_adapter.h', 'src/core/tsi/transport_security_interface.h', + 'src/core/ext/transport/chttp2/client/authority.h', 'src/core/ext/transport/chttp2/client/chttp2_connector.h', 'src/core/ext/filters/client_channel/backup_poller.h', 'src/core/ext/filters/client_channel/client_channel.h', @@ -919,7 +920,6 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/subchannel.h', 'src/core/ext/filters/client_channel/subchannel_index.h', 'src/core/ext/filters/client_channel/uri_parser.h', - 'src/core/ext/transport/chttp2/client/authority.h', 'src/core/ext/filters/deadline/deadline_filter.h', 'src/core/tsi/alts_transport_security.h', 'src/core/tsi/fake_transport_security.h', @@ -1403,7 +1403,6 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/subchannel.h', 'src/core/ext/filters/client_channel/subchannel_index.h', 'src/core/ext/filters/client_channel/uri_parser.h', - 'src/core/ext/transport/chttp2/client/authority.h', 'src/core/lib/security/context/security_context.h', 'src/core/lib/security/credentials/alts/alts_credentials.h', 'src/core/lib/security/credentials/composite/composite_credentials.h', @@ -1457,6 +1456,7 @@ Pod::Spec.new do |s| 'src/core/tsi/transport_security.h', 'src/core/tsi/transport_security_adapter.h', 'src/core/tsi/transport_security_interface.h', + 'src/core/ext/transport/chttp2/client/authority.h', 'src/core/ext/transport/chttp2/client/chttp2_connector.h', 'src/core/tsi/alts_transport_security.h', 'src/core/tsi/fake_transport_security.h', @@ -1671,7 +1671,6 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', - 'src/core/ext/transport/chttp2/client/authority.cc', 'src/core/lib/http/httpcli_security_connector.cc', 'src/core/lib/security/context/security_context.cc', 'src/core/lib/security/credentials/alts/alts_credentials.cc', @@ -1736,6 +1735,7 @@ Pod::Spec.new do |s| 'src/core/tsi/transport_security_adapter.cc', 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', + 'src/core/ext/transport/chttp2/client/authority.cc', 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', 'src/core/tsi/alts_transport_security.cc', 'src/core/tsi/fake_transport_security.cc', @@ -1955,7 +1955,6 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/subchannel.h', 'src/core/ext/filters/client_channel/subchannel_index.h', 'src/core/ext/filters/client_channel/uri_parser.h', - 'src/core/ext/transport/chttp2/client/authority.h', 'src/core/lib/security/context/security_context.h', 'src/core/lib/security/credentials/alts/alts_credentials.h', 'src/core/lib/security/credentials/composite/composite_credentials.h', @@ -2009,6 +2008,7 @@ Pod::Spec.new do |s| 'src/core/tsi/transport_security.h', 'src/core/tsi/transport_security_adapter.h', 'src/core/tsi/transport_security_interface.h', + 'src/core/ext/transport/chttp2/client/authority.h', 'src/core/ext/transport/chttp2/client/chttp2_connector.h', 'src/core/tsi/alts_transport_security.h', 'src/core/tsi/fake_transport_security.h', diff --git a/grpc.gemspec b/grpc.gemspec index d5d052d35c..ec8a7ffb77 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -249,6 +249,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/tsi/transport_security.h ) s.files += %w( src/core/tsi/transport_security_adapter.h ) s.files += %w( src/core/tsi/transport_security_interface.h ) + s.files += %w( src/core/ext/transport/chttp2/client/authority.h ) s.files += %w( src/core/ext/transport/chttp2/client/chttp2_connector.h ) s.files += %w( src/core/ext/filters/client_channel/backup_poller.h ) s.files += %w( src/core/ext/filters/client_channel/client_channel.h ) @@ -270,7 +271,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/client_channel/subchannel.h ) s.files += %w( src/core/ext/filters/client_channel/subchannel_index.h ) s.files += %w( src/core/ext/filters/client_channel/uri_parser.h ) - s.files += %w( src/core/ext/transport/chttp2/client/authority.h ) s.files += %w( src/core/ext/filters/deadline/deadline_filter.h ) s.files += %w( src/core/tsi/alts_transport_security.h ) s.files += %w( src/core/tsi/fake_transport_security.h ) @@ -672,6 +672,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/tsi/transport_security_adapter.cc ) s.files += %w( src/core/ext/transport/chttp2/client/insecure/channel_create.cc ) s.files += %w( src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc ) + s.files += %w( src/core/ext/transport/chttp2/client/authority.cc ) s.files += %w( src/core/ext/transport/chttp2/client/chttp2_connector.cc ) s.files += %w( src/core/ext/filters/client_channel/backup_poller.cc ) s.files += %w( src/core/ext/filters/client_channel/channel_connectivity.cc ) @@ -694,7 +695,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/client_channel/subchannel.cc ) s.files += %w( src/core/ext/filters/client_channel/subchannel_index.cc ) s.files += %w( src/core/ext/filters/client_channel/uri_parser.cc ) - s.files += %w( src/core/ext/transport/chttp2/client/authority.cc ) s.files += %w( src/core/ext/filters/deadline/deadline_filter.cc ) s.files += %w( src/core/tsi/alts_transport_security.cc ) s.files += %w( src/core/tsi/fake_transport_security.cc ) diff --git a/grpc.gyp b/grpc.gyp index 9e1c91012b..5e112fafec 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -473,6 +473,7 @@ 'src/core/tsi/transport_security_adapter.cc', 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', + 'src/core/ext/transport/chttp2/client/authority.cc', 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', @@ -495,7 +496,6 @@ 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', - 'src/core/ext/transport/chttp2/client/authority.cc', 'src/core/ext/filters/deadline/deadline_filter.cc', 'src/core/tsi/alts_transport_security.cc', 'src/core/tsi/fake_transport_security.cc', @@ -752,7 +752,6 @@ 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', - 'src/core/ext/transport/chttp2/client/authority.cc', 'src/core/ext/filters/deadline/deadline_filter.cc', 'src/core/ext/transport/chttp2/transport/bin_decoder.cc', 'src/core/ext/transport/chttp2/transport/bin_encoder.cc', @@ -983,7 +982,6 @@ 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', - 'src/core/ext/transport/chttp2/client/authority.cc', 'src/core/ext/filters/deadline/deadline_filter.cc', 'src/core/ext/transport/chttp2/transport/bin_decoder.cc', 'src/core/ext/transport/chttp2/transport/bin_encoder.cc', @@ -1204,6 +1202,7 @@ 'src/core/ext/transport/chttp2/server/chttp2_server.cc', 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', + 'src/core/ext/transport/chttp2/client/authority.cc', 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', @@ -1226,7 +1225,6 @@ 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', - 'src/core/ext/transport/chttp2/client/authority.cc', 'src/core/ext/filters/deadline/deadline_filter.cc', 'src/core/ext/transport/inproc/inproc_plugin.cc', 'src/core/ext/transport/inproc/inproc_transport.cc', diff --git a/include/grpc/impl/codegen/grpc_types.h b/include/grpc/impl/codegen/grpc_types.h index 51f641054f..03aaa9fae4 100644 --- a/include/grpc/impl/codegen/grpc_types.h +++ b/include/grpc/impl/codegen/grpc_types.h @@ -258,16 +258,6 @@ typedef struct { secure channel is an SSL channel). If this parameter is specified and the underlying is not an SSL channel, it will just be ignored. */ #define GRPC_SSL_TARGET_NAME_OVERRIDE_ARG "grpc.ssl_target_name_override" -/** This *should* be used for testing only. - The caller of the secure_channel_create functions may override the target - name used for fake security host name checking using this channel argument - which is of type \a GRPC_ARG_STRING. If this argument is not specified, the - name used for fake security host name checking will be the target parameter - (assuming that the secure channel is a fake security channel). If this - parameter is specified and the underlying is not a fake security channel, it - will just be ignored. */ -#define GRPC_FAKE_SECURITY_TARGET_NAME_OVERRIDE_ARG \ - "grpc.fake_security_target_name_override" /** If non-zero, a pointer to a session cache (a pointer of type grpc_ssl_session_cache*). (use grpc_ssl_session_cache_arg_vtable() to fetch an appropriate pointer arg vtable) */ diff --git a/package.xml b/package.xml index f616e56d51..d8b9b2cbbb 100644 --- a/package.xml +++ b/package.xml @@ -256,6 +256,7 @@ + @@ -277,7 +278,6 @@ - @@ -679,6 +679,7 @@ + @@ -701,7 +702,6 @@ - diff --git a/src/core/ext/filters/client_channel/authority.h b/src/core/ext/filters/client_channel/authority.h deleted file mode 100644 index 642584ef56..0000000000 --- a/src/core/ext/filters/client_channel/authority.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_EXT_TRANSPORT_CHTTP2_CLIENT_AUTHORITY_H -#define GRPC_CORE_EXT_TRANSPORT_CHTTP2_CLIENT_AUTHORITY_H - -#include - -#include - -#include "src/core/ext/filters/client_channel/client_channel.h" -#include "src/core/ext/filters/client_channel/resolver_registry.h" -#include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gprpp/memory.h" - -/// Returns a copy of \a args with the default authority channel arg set if it -/// wasn't already present. -grpc_channel_args* grpc_default_authority_add_if_not_present( - const grpc_channel_args* args); - -#endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_CLIENT_AUTHORITY_H */ diff --git a/src/core/lib/security/security_connector/security_connector.cc b/src/core/lib/security/security_connector/security_connector.cc index 0066d3f09f..980c9e9248 100644 --- a/src/core/lib/security/security_connector/security_connector.cc +++ b/src/core/lib/security/security_connector/security_connector.cc @@ -550,7 +550,7 @@ grpc_channel_security_connector* grpc_fake_channel_security_connector_create( c->expected_targets = gpr_strdup(expected_targets); c->is_lb_channel = grpc_core::FindTargetAuthorityTableInArgs(args) != nullptr; const grpc_arg* target_name_override_arg = - grpc_channel_args_find(args, GRPC_FAKE_SECURITY_TARGET_NAME_OVERRIDE_ARG); + grpc_channel_args_find(args, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG); if (target_name_override_arg != nullptr) { c->target_name_override = gpr_strdup(grpc_channel_arg_get_string(target_name_override_arg)); diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 8d35849411..ebc0a6c41a 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -296,6 +296,7 @@ CORE_SOURCE_FILES = [ 'src/core/tsi/transport_security_adapter.cc', 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', + 'src/core/ext/transport/chttp2/client/authority.cc', 'src/core/ext/transport/chttp2/client/chttp2_connector.cc', 'src/core/ext/filters/client_channel/backup_poller.cc', 'src/core/ext/filters/client_channel/channel_connectivity.cc', @@ -318,7 +319,6 @@ CORE_SOURCE_FILES = [ 'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel_index.cc', 'src/core/ext/filters/client_channel/uri_parser.cc', - 'src/core/ext/transport/chttp2/client/authority.cc', 'src/core/ext/filters/deadline/deadline_filter.cc', 'src/core/tsi/alts_transport_security.cc', 'src/core/tsi/fake_transport_security.cc', diff --git a/test/core/end2end/tests/call_host_override.cc b/test/core/end2end/tests/call_host_override.cc index ab920be31a..251dc6d045 100644 --- a/test/core/end2end/tests/call_host_override.cc +++ b/test/core/end2end/tests/call_host_override.cc @@ -42,7 +42,7 @@ static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, f = config.create_fixture(client_args, server_args); grpc_arg fake_security_name_override = { GRPC_ARG_STRING, - const_cast(GRPC_FAKE_SECURITY_TARGET_NAME_OVERRIDE_ARG), + const_cast(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG), {const_cast("foo.test.google.fr:1234")}}; grpc_channel_args* new_client_args = grpc_channel_args_copy_and_add( client_args, &fake_security_name_override, 1); diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 4a3a9edf26..7c26a20b9f 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -9522,8 +9522,7 @@ "src/core/ext/filters/client_channel/retry_throttle.h", "src/core/ext/filters/client_channel/subchannel.h", "src/core/ext/filters/client_channel/subchannel_index.h", - "src/core/ext/filters/client_channel/uri_parser.h", - "src/core/ext/transport/chttp2/client/authority.h" + "src/core/ext/filters/client_channel/uri_parser.h" ], "is_filegroup": true, "language": "c", @@ -9569,9 +9568,7 @@ "src/core/ext/filters/client_channel/subchannel_index.cc", "src/core/ext/filters/client_channel/subchannel_index.h", "src/core/ext/filters/client_channel/uri_parser.cc", - "src/core/ext/filters/client_channel/uri_parser.h", - "src/core/ext/transport/chttp2/client/authority.cc", - "src/core/ext/transport/chttp2/client/authority.h" + "src/core/ext/filters/client_channel/uri_parser.h" ], "third_party": false, "type": "filegroup" @@ -10220,12 +10217,15 @@ "grpc_transport_chttp2" ], "headers": [ + "src/core/ext/transport/chttp2/client/authority.h", "src/core/ext/transport/chttp2/client/chttp2_connector.h" ], "is_filegroup": true, "language": "c", "name": "grpc_transport_chttp2_client_connector", "src": [ + "src/core/ext/transport/chttp2/client/authority.cc", + "src/core/ext/transport/chttp2/client/authority.h", "src/core/ext/transport/chttp2/client/chttp2_connector.cc", "src/core/ext/transport/chttp2/client/chttp2_connector.h" ], -- cgit v1.2.3 From 90cfc8ed5727680e1f67f3789285d1d04b390548 Mon Sep 17 00:00:00 2001 From: Mehrdad Afshari Date: Wed, 4 Apr 2018 14:04:11 -0700 Subject: Regenerate projects --- CMakeLists.txt | 2 +- Makefile | 4 ++-- gRPC-C++.podspec | 4 ++-- gRPC-Core.podspec | 2 +- gRPC-ProtoRPC.podspec | 2 +- gRPC-RxLibrary.podspec | 2 +- gRPC.podspec | 2 +- package.xml | 4 ++-- src/core/lib/surface/version.cc | 2 +- src/cpp/common/version_cc.cc | 2 +- src/csharp/Grpc.Core/Version.csproj.include | 2 +- src/csharp/Grpc.Core/VersionInfo.cs | 4 ++-- src/csharp/build_packages_dotnetcli.bat | 2 +- src/csharp/build_packages_dotnetcli.sh | 4 ++-- src/objective-c/!ProtoCompiler-gRPCPlugin.podspec | 2 +- src/objective-c/GRPCClient/private/version.h | 2 +- src/objective-c/tests/version.h | 2 +- src/php/composer.json | 2 +- src/php/ext/grpc/version.h | 2 +- src/python/grpcio/grpc/_grpcio_metadata.py | 2 +- src/python/grpcio/grpc_version.py | 2 +- src/python/grpcio_health_checking/grpc_version.py | 2 +- src/python/grpcio_reflection/grpc_version.py | 2 +- src/python/grpcio_testing/grpc_version.py | 2 +- src/python/grpcio_tests/grpc_version.py | 2 +- src/ruby/lib/grpc/version.rb | 2 +- src/ruby/tools/version.rb | 2 +- tools/distrib/python/grpcio_tools/grpc_version.py | 2 +- tools/doxygen/Doxyfile.c++ | 2 +- tools/doxygen/Doxyfile.c++.internal | 2 +- 30 files changed, 35 insertions(+), 35 deletions(-) (limited to 'gRPC-C++.podspec') diff --git a/CMakeLists.txt b/CMakeLists.txt index 4fd9826e99..d94422f741 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ cmake_minimum_required(VERSION 2.8) set(PACKAGE_NAME "grpc") -set(PACKAGE_VERSION "1.11.0-dev") +set(PACKAGE_VERSION "1.12.0-dev") set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") set(PACKAGE_TARNAME "${PACKAGE_NAME}-${PACKAGE_VERSION}") set(PACKAGE_BUGREPORT "https://github.com/grpc/grpc/issues/") diff --git a/Makefile b/Makefile index 64195ee6ff..77ef1b3cbc 100644 --- a/Makefile +++ b/Makefile @@ -421,8 +421,8 @@ Q = @ endif CORE_VERSION = 6.0.0-dev -CPP_VERSION = 1.11.0-dev -CSHARP_VERSION = 1.11.0-dev +CPP_VERSION = 1.12.0-dev +CSHARP_VERSION = 1.12.0-dev CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES)) CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS) diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 9d4d15a9a1..c5a4e50cd3 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -23,7 +23,7 @@ Pod::Spec.new do |s| s.name = 'gRPC-C++' # TODO (mxyan): use version that match gRPC version when pod is stabilized - # version = '1.11.0-dev' + # version = '1.12.0-dev' version = '0.0.2' s.version = version s.summary = 'gRPC C++ library' @@ -31,7 +31,7 @@ Pod::Spec.new do |s| s.license = 'Apache License, Version 2.0' s.authors = { 'The gRPC contributors' => 'grpc-packages@google.com' } - grpc_version = '1.11.0-dev' + grpc_version = '1.12.0-dev' s.source = { :git => 'https://github.com/grpc/grpc.git', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 0eadbb5147..bd192b43ca 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -22,7 +22,7 @@ Pod::Spec.new do |s| s.name = 'gRPC-Core' - version = '1.11.0-dev' + version = '1.12.0-dev' s.version = version s.summary = 'Core cross-platform gRPC library, written in C' s.homepage = 'https://grpc.io' diff --git a/gRPC-ProtoRPC.podspec b/gRPC-ProtoRPC.podspec index 149687e5b4..e98dee4a3c 100644 --- a/gRPC-ProtoRPC.podspec +++ b/gRPC-ProtoRPC.podspec @@ -21,7 +21,7 @@ Pod::Spec.new do |s| s.name = 'gRPC-ProtoRPC' - version = '1.11.0-dev' + version = '1.12.0-dev' s.version = version s.summary = 'RPC library for Protocol Buffers, based on gRPC' s.homepage = 'https://grpc.io' diff --git a/gRPC-RxLibrary.podspec b/gRPC-RxLibrary.podspec index 2497174417..3bba14b695 100644 --- a/gRPC-RxLibrary.podspec +++ b/gRPC-RxLibrary.podspec @@ -21,7 +21,7 @@ Pod::Spec.new do |s| s.name = 'gRPC-RxLibrary' - version = '1.11.0-dev' + version = '1.12.0-dev' s.version = version s.summary = 'Reactive Extensions library for iOS/OSX.' s.homepage = 'https://grpc.io' diff --git a/gRPC.podspec b/gRPC.podspec index 68e06b5536..bf73ffd22e 100644 --- a/gRPC.podspec +++ b/gRPC.podspec @@ -20,7 +20,7 @@ Pod::Spec.new do |s| s.name = 'gRPC' - version = '1.11.0-dev' + version = '1.12.0-dev' s.version = version s.summary = 'gRPC client library for iOS/OSX' s.homepage = 'https://grpc.io' diff --git a/package.xml b/package.xml index fd43006836..0777ee0050 100644 --- a/package.xml +++ b/package.xml @@ -13,8 +13,8 @@ 2018-01-19 - 1.11.0dev - 1.11.0dev + 1.12.0dev + 1.12.0dev beta diff --git a/src/core/lib/surface/version.cc b/src/core/lib/surface/version.cc index be196a78bc..a712e10037 100644 --- a/src/core/lib/surface/version.cc +++ b/src/core/lib/surface/version.cc @@ -25,4 +25,4 @@ const char* grpc_version_string(void) { return "6.0.0-dev"; } -const char* grpc_g_stands_for(void) { return "gorgeous"; } +const char* grpc_g_stands_for(void) { return "glorious"; } diff --git a/src/cpp/common/version_cc.cc b/src/cpp/common/version_cc.cc index fb1723c816..d669ea21a9 100644 --- a/src/cpp/common/version_cc.cc +++ b/src/cpp/common/version_cc.cc @@ -22,5 +22,5 @@ #include namespace grpc { -grpc::string Version() { return "1.11.0-dev"; } +grpc::string Version() { return "1.12.0-dev"; } } // namespace grpc diff --git a/src/csharp/Grpc.Core/Version.csproj.include b/src/csharp/Grpc.Core/Version.csproj.include index 9b55f2469a..f7a7a5cbe9 100755 --- a/src/csharp/Grpc.Core/Version.csproj.include +++ b/src/csharp/Grpc.Core/Version.csproj.include @@ -1,7 +1,7 @@ - 1.11.0-dev + 1.12.0-dev 3.3.0 diff --git a/src/csharp/Grpc.Core/VersionInfo.cs b/src/csharp/Grpc.Core/VersionInfo.cs index 2902aee8d9..06a0396c34 100644 --- a/src/csharp/Grpc.Core/VersionInfo.cs +++ b/src/csharp/Grpc.Core/VersionInfo.cs @@ -33,11 +33,11 @@ namespace Grpc.Core /// /// Current AssemblyFileVersion of gRPC C# assemblies /// - public const string CurrentAssemblyFileVersion = "1.11.0.0"; + public const string CurrentAssemblyFileVersion = "1.12.0.0"; /// /// Current version of gRPC C# /// - public const string CurrentVersion = "1.11.0-dev"; + public const string CurrentVersion = "1.12.0-dev"; } } diff --git a/src/csharp/build_packages_dotnetcli.bat b/src/csharp/build_packages_dotnetcli.bat index 76391738ff..0d65748697 100755 --- a/src/csharp/build_packages_dotnetcli.bat +++ b/src/csharp/build_packages_dotnetcli.bat @@ -13,7 +13,7 @@ @rem limitations under the License. @rem Current package versions -set VERSION=1.11.0-dev +set VERSION=1.12.0-dev @rem Adjust the location of nuget.exe set NUGET=C:\nuget\nuget.exe diff --git a/src/csharp/build_packages_dotnetcli.sh b/src/csharp/build_packages_dotnetcli.sh index 1b73614b91..66aba36089 100755 --- a/src/csharp/build_packages_dotnetcli.sh +++ b/src/csharp/build_packages_dotnetcli.sh @@ -45,7 +45,7 @@ dotnet pack --configuration Release Grpc.Auth --output ../../../artifacts dotnet pack --configuration Release Grpc.HealthCheck --output ../../../artifacts dotnet pack --configuration Release Grpc.Reflection --output ../../../artifacts -nuget pack Grpc.nuspec -Version "1.11.0-dev" -OutputDirectory ../../artifacts -nuget pack Grpc.Tools.nuspec -Version "1.11.0-dev" -OutputDirectory ../../artifacts +nuget pack Grpc.nuspec -Version "1.12.0-dev" -OutputDirectory ../../artifacts +nuget pack Grpc.Tools.nuspec -Version "1.12.0-dev" -OutputDirectory ../../artifacts (cd ../../artifacts && zip csharp_nugets_dotnetcli.zip *.nupkg) diff --git a/src/objective-c/!ProtoCompiler-gRPCPlugin.podspec b/src/objective-c/!ProtoCompiler-gRPCPlugin.podspec index 954beed8e1..f06312bea9 100644 --- a/src/objective-c/!ProtoCompiler-gRPCPlugin.podspec +++ b/src/objective-c/!ProtoCompiler-gRPCPlugin.podspec @@ -42,7 +42,7 @@ Pod::Spec.new do |s| # exclamation mark ensures that other "regular" pods will be able to find it as it'll be installed # before them. s.name = '!ProtoCompiler-gRPCPlugin' - v = '1.11.0-dev' + v = '1.12.0-dev' s.version = v s.summary = 'The gRPC ProtoC plugin generates Objective-C files from .proto services.' s.description = <<-DESC diff --git a/src/objective-c/GRPCClient/private/version.h b/src/objective-c/GRPCClient/private/version.h index 405c2fff9f..a99eb289c3 100644 --- a/src/objective-c/GRPCClient/private/version.h +++ b/src/objective-c/GRPCClient/private/version.h @@ -23,4 +23,4 @@ // `tools/buildgen/generate_projects.sh`. -#define GRPC_OBJC_VERSION_STRING @"1.11.0-dev" +#define GRPC_OBJC_VERSION_STRING @"1.12.0-dev" diff --git a/src/objective-c/tests/version.h b/src/objective-c/tests/version.h index 6f6cd25007..15fe1a59f3 100644 --- a/src/objective-c/tests/version.h +++ b/src/objective-c/tests/version.h @@ -23,5 +23,5 @@ // `tools/buildgen/generate_projects.sh`. -#define GRPC_OBJC_VERSION_STRING @"1.11.0-dev" +#define GRPC_OBJC_VERSION_STRING @"1.12.0-dev" #define GRPC_C_VERSION_STRING @"6.0.0-dev" diff --git a/src/php/composer.json b/src/php/composer.json index dbf0cc35fd..57d911db79 100644 --- a/src/php/composer.json +++ b/src/php/composer.json @@ -2,7 +2,7 @@ "name": "grpc/grpc-dev", "description": "gRPC library for PHP - for Developement use only", "license": "Apache-2.0", - "version": "1.11.0", + "version": "1.12.0", "require": { "php": ">=5.5.0", "google/protobuf": "^v3.3.0" diff --git a/src/php/ext/grpc/version.h b/src/php/ext/grpc/version.h index dd2a701ada..37df2768bf 100644 --- a/src/php/ext/grpc/version.h +++ b/src/php/ext/grpc/version.h @@ -20,6 +20,6 @@ #ifndef VERSION_H #define VERSION_H -#define PHP_GRPC_VERSION "1.11.0dev" +#define PHP_GRPC_VERSION "1.12.0dev" #endif /* VERSION_H */ diff --git a/src/python/grpcio/grpc/_grpcio_metadata.py b/src/python/grpcio/grpc/_grpcio_metadata.py index 4a69d859fc..cb5da72f1f 100644 --- a/src/python/grpcio/grpc/_grpcio_metadata.py +++ b/src/python/grpcio/grpc/_grpcio_metadata.py @@ -14,4 +14,4 @@ # AUTO-GENERATED FROM `$REPO_ROOT/templates/src/python/grpcio/grpc/_grpcio_metadata.py.template`!!! -__version__ = """1.11.0.dev0""" +__version__ = """1.12.0.dev0""" diff --git a/src/python/grpcio/grpc_version.py b/src/python/grpcio/grpc_version.py index 32e82493f3..de5a780abd 100644 --- a/src/python/grpcio/grpc_version.py +++ b/src/python/grpcio/grpc_version.py @@ -14,4 +14,4 @@ # AUTO-GENERATED FROM `$REPO_ROOT/templates/src/python/grpcio/grpc_version.py.template`!!! -VERSION = '1.11.0.dev0' +VERSION = '1.12.0.dev0' diff --git a/src/python/grpcio_health_checking/grpc_version.py b/src/python/grpcio_health_checking/grpc_version.py index ad4c85cc12..afcd316e5c 100644 --- a/src/python/grpcio_health_checking/grpc_version.py +++ b/src/python/grpcio_health_checking/grpc_version.py @@ -14,4 +14,4 @@ # AUTO-GENERATED FROM `$REPO_ROOT/templates/src/python/grpcio_health_checking/grpc_version.py.template`!!! -VERSION = '1.11.0.dev0' +VERSION = '1.12.0.dev0' diff --git a/src/python/grpcio_reflection/grpc_version.py b/src/python/grpcio_reflection/grpc_version.py index 6322d847b1..824b73201d 100644 --- a/src/python/grpcio_reflection/grpc_version.py +++ b/src/python/grpcio_reflection/grpc_version.py @@ -14,4 +14,4 @@ # AUTO-GENERATED FROM `$REPO_ROOT/templates/src/python/grpcio_reflection/grpc_version.py.template`!!! -VERSION = '1.11.0.dev0' +VERSION = '1.12.0.dev0' diff --git a/src/python/grpcio_testing/grpc_version.py b/src/python/grpcio_testing/grpc_version.py index 1e75fea12e..5b1f4c4cc0 100644 --- a/src/python/grpcio_testing/grpc_version.py +++ b/src/python/grpcio_testing/grpc_version.py @@ -14,4 +14,4 @@ # AUTO-GENERATED FROM `$REPO_ROOT/templates/src/python/grpcio_testing/grpc_version.py.template`!!! -VERSION = '1.11.0.dev0' +VERSION = '1.12.0.dev0' diff --git a/src/python/grpcio_tests/grpc_version.py b/src/python/grpcio_tests/grpc_version.py index 0cd7bd257f..382f95018e 100644 --- a/src/python/grpcio_tests/grpc_version.py +++ b/src/python/grpcio_tests/grpc_version.py @@ -14,4 +14,4 @@ # AUTO-GENERATED FROM `$REPO_ROOT/templates/src/python/grpcio_tests/grpc_version.py.template`!!! -VERSION = '1.11.0.dev0' +VERSION = '1.12.0.dev0' diff --git a/src/ruby/lib/grpc/version.rb b/src/ruby/lib/grpc/version.rb index 256a543a9f..2cb7c4be53 100644 --- a/src/ruby/lib/grpc/version.rb +++ b/src/ruby/lib/grpc/version.rb @@ -14,5 +14,5 @@ # GRPC contains the General RPC module. module GRPC - VERSION = '1.11.0.dev' + VERSION = '1.12.0.dev' end diff --git a/src/ruby/tools/version.rb b/src/ruby/tools/version.rb index 8dc1623d6f..822f70eb0a 100644 --- a/src/ruby/tools/version.rb +++ b/src/ruby/tools/version.rb @@ -14,6 +14,6 @@ module GRPC module Tools - VERSION = '1.11.0.dev' + VERSION = '1.12.0.dev' end end diff --git a/tools/distrib/python/grpcio_tools/grpc_version.py b/tools/distrib/python/grpcio_tools/grpc_version.py index e8ca6851eb..e71f836f6d 100644 --- a/tools/distrib/python/grpcio_tools/grpc_version.py +++ b/tools/distrib/python/grpcio_tools/grpc_version.py @@ -14,4 +14,4 @@ # AUTO-GENERATED FROM `$REPO_ROOT/templates/tools/distrib/python/grpcio_tools/grpc_version.py.template`!!! -VERSION = '1.11.0.dev0' +VERSION = '1.12.0.dev0' diff --git a/tools/doxygen/Doxyfile.c++ b/tools/doxygen/Doxyfile.c++ index eb6700d529..047b27ea57 100644 --- a/tools/doxygen/Doxyfile.c++ +++ b/tools/doxygen/Doxyfile.c++ @@ -40,7 +40,7 @@ PROJECT_NAME = "GRPC C++" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 1.11.0-dev +PROJECT_NUMBER = 1.12.0-dev # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index 52a16d6e98..3e2c192864 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -40,7 +40,7 @@ PROJECT_NAME = "GRPC C++" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 1.11.0-dev +PROJECT_NUMBER = 1.12.0-dev # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a -- cgit v1.2.3 From cf5b2666e16f7b6ebc1bda4a884045d1ef1a4134 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Tue, 27 Feb 2018 11:55:10 -0800 Subject: Make GrpcProtoBufferReaderWriter public --- BUILD | 5 +- CMakeLists.txt | 15 +- Makefile | 15 +- build.yaml | 5 +- gRPC-C++.podspec | 3 +- grpc.gyp | 2 - include/grpcpp/impl/codegen/byte_buffer.h | 43 +++- include/grpcpp/impl/codegen/core_codegen.h | 3 + .../grpcpp/impl/codegen/core_codegen_interface.h | 5 + include/grpcpp/impl/codegen/proto_buffer_reader.h | 151 ++++++++++++++ include/grpcpp/impl/codegen/proto_buffer_writer.h | 168 ++++++++++++++++ include/grpcpp/impl/codegen/proto_utils.h | 220 ++++----------------- include/grpcpp/impl/codegen/slice.h | 39 ++-- include/grpcpp/support/proto_buffer_reader.h | 24 +++ include/grpcpp/support/proto_buffer_writer.h | 24 +++ src/cpp/common/core_codegen.cc | 10 + src/cpp/util/byte_buffer_cc.cc | 42 ---- src/cpp/util/slice_cc.cc | 55 ------ test/cpp/codegen/proto_utils_test.cc | 42 ++-- test/cpp/util/byte_buffer_test.cc | 6 +- test/cpp/util/slice_test.cc | 6 +- tools/doxygen/Doxyfile.c++ | 4 + tools/doxygen/Doxyfile.c++.internal | 5 +- tools/run_tests/generated/sources_and_headers.json | 9 +- 24 files changed, 574 insertions(+), 327 deletions(-) create mode 100644 include/grpcpp/impl/codegen/proto_buffer_reader.h create mode 100644 include/grpcpp/impl/codegen/proto_buffer_writer.h create mode 100644 include/grpcpp/support/proto_buffer_reader.h create mode 100644 include/grpcpp/support/proto_buffer_writer.h delete mode 100644 src/cpp/util/slice_cc.cc (limited to 'gRPC-C++.podspec') diff --git a/BUILD b/BUILD index ece6cd182d..0250eaab7c 100644 --- a/BUILD +++ b/BUILD @@ -141,7 +141,6 @@ GRPCXX_SRCS = [ "src/cpp/server/server_posix.cc", "src/cpp/thread_manager/thread_manager.cc", "src/cpp/util/byte_buffer_cc.cc", - "src/cpp/util/slice_cc.cc", "src/cpp/util/status.cc", "src/cpp/util/string_ref.cc", "src/cpp/util/time_cc.cc", @@ -245,6 +244,8 @@ GRPCXX_PUBLIC_HDRS = [ "include/grpcpp/support/byte_buffer.h", "include/grpcpp/support/channel_arguments.h", "include/grpcpp/support/config.h", + "include/grpcpp/support/proto_buffer_reader.h", + "include/grpcpp/support/proto_buffer_writer.h", "include/grpcpp/support/slice.h", "include/grpcpp/support/status.h", "include/grpcpp/support/status_code_enum.h", @@ -1871,6 +1872,8 @@ grpc_cc_library( language = "c++", public_hdrs = [ "include/grpc++/impl/codegen/proto_utils.h", + "include/grpcpp/impl/codegen/proto_buffer_reader.h", + "include/grpcpp/impl/codegen/proto_buffer_writer.h", "include/grpcpp/impl/codegen/proto_utils.h", ], deps = [ diff --git a/CMakeLists.txt b/CMakeLists.txt index d94422f741..18400ea22a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2716,7 +2716,6 @@ add_library(grpc++ src/cpp/server/server_posix.cc src/cpp/thread_manager/thread_manager.cc src/cpp/util/byte_buffer_cc.cc - src/cpp/util/slice_cc.cc src/cpp/util/status.cc src/cpp/util/string_ref.cc src/cpp/util/time_cc.cc @@ -2841,6 +2840,8 @@ foreach(_hdr include/grpcpp/support/byte_buffer.h include/grpcpp/support/channel_arguments.h include/grpcpp/support/config.h + include/grpcpp/support/proto_buffer_reader.h + include/grpcpp/support/proto_buffer_writer.h include/grpcpp/support/slice.h include/grpcpp/support/status.h include/grpcpp/support/status_code_enum.h @@ -2959,6 +2960,8 @@ foreach(_hdr include/grpcpp/impl/codegen/sync_stream.h include/grpcpp/impl/codegen/time.h include/grpc++/impl/codegen/proto_utils.h + include/grpcpp/impl/codegen/proto_buffer_reader.h + include/grpcpp/impl/codegen/proto_buffer_writer.h include/grpcpp/impl/codegen/proto_utils.h include/grpc++/impl/codegen/config_protobuf.h include/grpcpp/impl/codegen/config_protobuf.h @@ -3067,7 +3070,6 @@ add_library(grpc++_cronet src/cpp/server/server_posix.cc src/cpp/thread_manager/thread_manager.cc src/cpp/util/byte_buffer_cc.cc - src/cpp/util/slice_cc.cc src/cpp/util/status.cc src/cpp/util/string_ref.cc src/cpp/util/time_cc.cc @@ -3402,6 +3404,8 @@ foreach(_hdr include/grpcpp/support/byte_buffer.h include/grpcpp/support/channel_arguments.h include/grpcpp/support/config.h + include/grpcpp/support/proto_buffer_reader.h + include/grpcpp/support/proto_buffer_writer.h include/grpcpp/support/slice.h include/grpcpp/support/status.h include/grpcpp/support/status_code_enum.h @@ -3945,6 +3949,8 @@ foreach(_hdr include/grpc/impl/codegen/sync_posix.h include/grpc/impl/codegen/sync_windows.h include/grpc++/impl/codegen/proto_utils.h + include/grpcpp/impl/codegen/proto_buffer_reader.h + include/grpcpp/impl/codegen/proto_buffer_writer.h include/grpcpp/impl/codegen/proto_utils.h include/grpc++/impl/codegen/config_protobuf.h include/grpcpp/impl/codegen/config_protobuf.h @@ -4118,6 +4124,8 @@ foreach(_hdr include/grpc/impl/codegen/sync_posix.h include/grpc/impl/codegen/sync_windows.h include/grpc++/impl/codegen/proto_utils.h + include/grpcpp/impl/codegen/proto_buffer_reader.h + include/grpcpp/impl/codegen/proto_buffer_writer.h include/grpcpp/impl/codegen/proto_utils.h include/grpc++/impl/codegen/config_protobuf.h include/grpcpp/impl/codegen/config_protobuf.h @@ -4166,7 +4174,6 @@ add_library(grpc++_unsecure src/cpp/server/server_posix.cc src/cpp/thread_manager/thread_manager.cc src/cpp/util/byte_buffer_cc.cc - src/cpp/util/slice_cc.cc src/cpp/util/status.cc src/cpp/util/string_ref.cc src/cpp/util/time_cc.cc @@ -4290,6 +4297,8 @@ foreach(_hdr include/grpcpp/support/byte_buffer.h include/grpcpp/support/channel_arguments.h include/grpcpp/support/config.h + include/grpcpp/support/proto_buffer_reader.h + include/grpcpp/support/proto_buffer_writer.h include/grpcpp/support/slice.h include/grpcpp/support/status.h include/grpcpp/support/status_code_enum.h diff --git a/Makefile b/Makefile index 77ef1b3cbc..da5f2efebf 100644 --- a/Makefile +++ b/Makefile @@ -5019,7 +5019,6 @@ LIBGRPC++_SRC = \ src/cpp/server/server_posix.cc \ src/cpp/thread_manager/thread_manager.cc \ src/cpp/util/byte_buffer_cc.cc \ - src/cpp/util/slice_cc.cc \ src/cpp/util/status.cc \ src/cpp/util/string_ref.cc \ src/cpp/util/time_cc.cc \ @@ -5109,6 +5108,8 @@ PUBLIC_HEADERS_CXX += \ include/grpcpp/support/byte_buffer.h \ include/grpcpp/support/channel_arguments.h \ include/grpcpp/support/config.h \ + include/grpcpp/support/proto_buffer_reader.h \ + include/grpcpp/support/proto_buffer_writer.h \ include/grpcpp/support/slice.h \ include/grpcpp/support/status.h \ include/grpcpp/support/status_code_enum.h \ @@ -5227,6 +5228,8 @@ PUBLIC_HEADERS_CXX += \ include/grpcpp/impl/codegen/sync_stream.h \ include/grpcpp/impl/codegen/time.h \ include/grpc++/impl/codegen/proto_utils.h \ + include/grpcpp/impl/codegen/proto_buffer_reader.h \ + include/grpcpp/impl/codegen/proto_buffer_writer.h \ include/grpcpp/impl/codegen/proto_utils.h \ include/grpc++/impl/codegen/config_protobuf.h \ include/grpcpp/impl/codegen/config_protobuf.h \ @@ -5380,7 +5383,6 @@ LIBGRPC++_CRONET_SRC = \ src/cpp/server/server_posix.cc \ src/cpp/thread_manager/thread_manager.cc \ src/cpp/util/byte_buffer_cc.cc \ - src/cpp/util/slice_cc.cc \ src/cpp/util/status.cc \ src/cpp/util/string_ref.cc \ src/cpp/util/time_cc.cc \ @@ -5679,6 +5681,8 @@ PUBLIC_HEADERS_CXX += \ include/grpcpp/support/byte_buffer.h \ include/grpcpp/support/channel_arguments.h \ include/grpcpp/support/config.h \ + include/grpcpp/support/proto_buffer_reader.h \ + include/grpcpp/support/proto_buffer_writer.h \ include/grpcpp/support/slice.h \ include/grpcpp/support/status.h \ include/grpcpp/support/status_code_enum.h \ @@ -6207,6 +6211,8 @@ PUBLIC_HEADERS_CXX += \ include/grpc/impl/codegen/sync_posix.h \ include/grpc/impl/codegen/sync_windows.h \ include/grpc++/impl/codegen/proto_utils.h \ + include/grpcpp/impl/codegen/proto_buffer_reader.h \ + include/grpcpp/impl/codegen/proto_buffer_writer.h \ include/grpcpp/impl/codegen/proto_utils.h \ include/grpc++/impl/codegen/config_protobuf.h \ include/grpcpp/impl/codegen/config_protobuf.h \ @@ -6357,6 +6363,8 @@ PUBLIC_HEADERS_CXX += \ include/grpc/impl/codegen/sync_posix.h \ include/grpc/impl/codegen/sync_windows.h \ include/grpc++/impl/codegen/proto_utils.h \ + include/grpcpp/impl/codegen/proto_buffer_reader.h \ + include/grpcpp/impl/codegen/proto_buffer_writer.h \ include/grpcpp/impl/codegen/proto_utils.h \ include/grpc++/impl/codegen/config_protobuf.h \ include/grpcpp/impl/codegen/config_protobuf.h \ @@ -6444,7 +6452,6 @@ LIBGRPC++_UNSECURE_SRC = \ src/cpp/server/server_posix.cc \ src/cpp/thread_manager/thread_manager.cc \ src/cpp/util/byte_buffer_cc.cc \ - src/cpp/util/slice_cc.cc \ src/cpp/util/status.cc \ src/cpp/util/string_ref.cc \ src/cpp/util/time_cc.cc \ @@ -6534,6 +6541,8 @@ PUBLIC_HEADERS_CXX += \ include/grpcpp/support/byte_buffer.h \ include/grpcpp/support/channel_arguments.h \ include/grpcpp/support/config.h \ + include/grpcpp/support/proto_buffer_reader.h \ + include/grpcpp/support/proto_buffer_writer.h \ include/grpcpp/support/slice.h \ include/grpcpp/support/status.h \ include/grpcpp/support/status_code_enum.h \ diff --git a/build.yaml b/build.yaml index aa5a40d849..594df9526c 100644 --- a/build.yaml +++ b/build.yaml @@ -1164,6 +1164,8 @@ filegroups: language: c++ public_headers: - include/grpc++/impl/codegen/proto_utils.h + - include/grpcpp/impl/codegen/proto_buffer_reader.h + - include/grpcpp/impl/codegen/proto_buffer_writer.h - include/grpcpp/impl/codegen/proto_utils.h uses: - grpc++_codegen_base @@ -1254,6 +1256,8 @@ filegroups: - include/grpcpp/support/byte_buffer.h - include/grpcpp/support/channel_arguments.h - include/grpcpp/support/config.h + - include/grpcpp/support/proto_buffer_reader.h + - include/grpcpp/support/proto_buffer_writer.h - include/grpcpp/support/slice.h - include/grpcpp/support/status.h - include/grpcpp/support/status_code_enum.h @@ -1300,7 +1304,6 @@ filegroups: - src/cpp/server/server_posix.cc - src/cpp/thread_manager/thread_manager.cc - src/cpp/util/byte_buffer_cc.cc - - src/cpp/util/slice_cc.cc - src/cpp/util/status.cc - src/cpp/util/string_ref.cc - src/cpp/util/time_cc.cc diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index c5a4e50cd3..990b0a4f9d 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -112,6 +112,8 @@ Pod::Spec.new do |s| 'include/grpcpp/support/byte_buffer.h', 'include/grpcpp/support/channel_arguments.h', 'include/grpcpp/support/config.h', + 'include/grpcpp/support/proto_buffer_reader.h', + 'include/grpcpp/support/proto_buffer_writer.h', 'include/grpcpp/support/slice.h', 'include/grpcpp/support/status.h', 'include/grpcpp/support/status_code_enum.h', @@ -206,7 +208,6 @@ Pod::Spec.new do |s| 'src/cpp/server/server_posix.cc', 'src/cpp/thread_manager/thread_manager.cc', 'src/cpp/util/byte_buffer_cc.cc', - 'src/cpp/util/slice_cc.cc', 'src/cpp/util/status.cc', 'src/cpp/util/string_ref.cc', 'src/cpp/util/time_cc.cc', diff --git a/grpc.gyp b/grpc.gyp index 30664695b3..8d9422eee6 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -1342,7 +1342,6 @@ 'src/cpp/server/server_posix.cc', 'src/cpp/thread_manager/thread_manager.cc', 'src/cpp/util/byte_buffer_cc.cc', - 'src/cpp/util/slice_cc.cc', 'src/cpp/util/status.cc', 'src/cpp/util/string_ref.cc', 'src/cpp/util/time_cc.cc', @@ -1490,7 +1489,6 @@ 'src/cpp/server/server_posix.cc', 'src/cpp/thread_manager/thread_manager.cc', 'src/cpp/util/byte_buffer_cc.cc', - 'src/cpp/util/slice_cc.cc', 'src/cpp/util/status.cc', 'src/cpp/util/string_ref.cc', 'src/cpp/util/time_cc.cc', diff --git a/include/grpcpp/impl/codegen/byte_buffer.h b/include/grpcpp/impl/codegen/byte_buffer.h index e637efeb85..fda13a04e6 100644 --- a/include/grpcpp/impl/codegen/byte_buffer.h +++ b/include/grpcpp/impl/codegen/byte_buffer.h @@ -31,6 +31,8 @@ namespace grpc { +class ServerInterface; +class ByteBuffer; class ServerInterface; namespace internal { @@ -45,6 +47,7 @@ template class ServerStreamingHandler; template class DeserializeFuncType; +class GrpcByteBufferPeer; } // namespace internal /// A sequence of bytes. class ByteBuffer final { @@ -53,7 +56,30 @@ class ByteBuffer final { ByteBuffer() : buffer_(nullptr) {} /// Construct buffer from \a slices, of which there are \a nslices. - ByteBuffer(const Slice* slices, size_t nslices); + ByteBuffer(const Slice* slices, size_t nslices) { + // The following assertions check that the representation of a grpc::Slice + // is identical to that of a grpc_slice: it has a grpc_slice field, and + // nothing else. + static_assert(std::is_same::value, + "Slice must have same representation as grpc_slice"); + static_assert(sizeof(Slice) == sizeof(grpc_slice), + "Slice must have same representation as grpc_slice"); + // The following assertions check that the representation of a ByteBuffer is + // identical to grpc_byte_buffer*: it has a grpc_byte_buffer* field, + // and nothing else. + static_assert(std::is_same::value, + "ByteBuffer must have same representation as " + "grpc_byte_buffer*"); + static_assert(sizeof(ByteBuffer) == sizeof(grpc_byte_buffer*), + "ByteBuffer must have same representation as " + "grpc_byte_buffer*"); + // The const_cast is legal if grpc_raw_byte_buffer_create() does no more + // than its advertised side effect of increasing the reference count of the + // slices it processes, and such an increase does not affect the semantics + // seen by the caller of this constructor. + buffer_ = g_core_codegen_interface->grpc_raw_byte_buffer_create( + reinterpret_cast(const_cast(slices)), nslices); + } /// Constuct a byte buffer by referencing elements of existing buffer /// \a buf. Wrapper of core function grpc_byte_buffer_copy @@ -90,10 +116,18 @@ class ByteBuffer final { void Release() { buffer_ = nullptr; } /// Buffer size in bytes. - size_t Length() const; + size_t Length() const { + return buffer_ == nullptr + ? 0 + : g_core_codegen_interface->grpc_byte_buffer_length(buffer_); + } /// Swap the state of *this and *other. - void Swap(ByteBuffer* other); + void Swap(ByteBuffer* other) { + grpc_byte_buffer* tmp = other->buffer_; + other->buffer_ = buffer_; + buffer_ = tmp; + } /// Is this ByteBuffer valid? bool Valid() const { return (buffer_ != nullptr); } @@ -112,6 +146,9 @@ class ByteBuffer final { friend class internal::ServerStreamingHandler; template friend class internal::DeserializeFuncType; + friend class GrpcProtoBufferReader; + friend class GrpcProtoBufferWriter; + friend class internal::GrpcByteBufferPeer; grpc_byte_buffer* buffer_; diff --git a/include/grpcpp/impl/codegen/core_codegen.h b/include/grpcpp/impl/codegen/core_codegen.h index 0ca4ad524c..e9df96bf04 100644 --- a/include/grpcpp/impl/codegen/core_codegen.h +++ b/include/grpcpp/impl/codegen/core_codegen.h @@ -73,6 +73,7 @@ class CoreCodegen final : public CoreCodegenInterface { grpc_byte_buffer* grpc_byte_buffer_copy(grpc_byte_buffer* bb) override; void grpc_byte_buffer_destroy(grpc_byte_buffer* bb) override; + size_t grpc_byte_buffer_length(grpc_byte_buffer* bb) override; int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader* reader, grpc_byte_buffer* buffer) override; @@ -86,6 +87,8 @@ class CoreCodegen final : public CoreCodegenInterface { grpc_slice grpc_slice_new_with_user_data(void* p, size_t len, void (*destroy)(void*), void* user_data) override; + grpc_slice grpc_slice_new_with_len(void* p, size_t len, + void (*destroy)(void*, size_t)) override; grpc_slice grpc_empty_slice() override; grpc_slice grpc_slice_malloc(size_t length) override; void grpc_slice_unref(grpc_slice slice) override; diff --git a/include/grpcpp/impl/codegen/core_codegen_interface.h b/include/grpcpp/impl/codegen/core_codegen_interface.h index d72f579c8e..1167a188a2 100644 --- a/include/grpcpp/impl/codegen/core_codegen_interface.h +++ b/include/grpcpp/impl/codegen/core_codegen_interface.h @@ -81,6 +81,8 @@ class CoreCodegenInterface { virtual grpc_byte_buffer* grpc_byte_buffer_copy(grpc_byte_buffer* bb) = 0; virtual void grpc_byte_buffer_destroy(grpc_byte_buffer* bb) = 0; + virtual size_t grpc_byte_buffer_length(grpc_byte_buffer* bb) + GRPC_MUST_USE_RESULT = 0; virtual int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader* reader, grpc_byte_buffer* buffer) @@ -95,6 +97,9 @@ class CoreCodegenInterface { virtual grpc_slice grpc_slice_new_with_user_data(void* p, size_t len, void (*destroy)(void*), void* user_data) = 0; + virtual grpc_slice grpc_slice_new_with_len(void* p, size_t len, + void (*destroy)(void*, + size_t)) = 0; virtual grpc_call_error grpc_call_cancel_with_status(grpc_call* call, grpc_status_code status, const char* description, diff --git a/include/grpcpp/impl/codegen/proto_buffer_reader.h b/include/grpcpp/impl/codegen/proto_buffer_reader.h new file mode 100644 index 0000000000..149e05c74f --- /dev/null +++ b/include/grpcpp/impl/codegen/proto_buffer_reader.h @@ -0,0 +1,151 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPCPP_IMPL_CODEGEN_PROTO_BUFFER_READER_H +#define GRPCPP_IMPL_CODEGEN_PROTO_BUFFER_READER_H + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +/// This header provides an object that reads bytes directly from a +/// grpc::ByteBuffer, via the ZeroCopyInputStream interface + +namespace grpc { + +extern CoreCodegenInterface* g_core_codegen_interface; + +/// This is a specialization of the protobuf class ZeroCopyInputStream +/// The principle is to get one chunk of data at a time from the proto layer, +/// with options to backup (re-see some bytes) or skip (forward past some bytes) +/// +/// Read more about ZeroCopyInputStream interface here: +/// https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.io.zero_copy_stream#ZeroCopyInputStream +class GrpcProtoBufferReader : public ::grpc::protobuf::io::ZeroCopyInputStream { + public: + /// Constructs buffer reader from \a buffer. Will set \a status() to non ok + /// if \a buffer is invalid (the internal buffer has not been initialized). + explicit GrpcProtoBufferReader(ByteBuffer* buffer) + : byte_count_(0), backup_count_(0), status_() { + /// Implemented through a grpc_byte_buffer_reader which iterates + /// over the slices that make up a byte buffer + if (!buffer->Valid() || + !g_core_codegen_interface->grpc_byte_buffer_reader_init( + &reader_, buffer->c_buffer())) { + status_ = Status(StatusCode::INTERNAL, + "Couldn't initialize byte buffer reader"); + } + } + + ~GrpcProtoBufferReader() { + if (status_.ok()) { + g_core_codegen_interface->grpc_byte_buffer_reader_destroy(&reader_); + } + } + + /// Give the proto library a chunk of data from the stream. The caller + /// may safely read from data[0, size - 1]. + bool Next(const void** data, int* size) override { + if (!status_.ok()) { + return false; + } + /// If we have backed up previously, we need to return the backed-up slice + if (backup_count_ > 0) { + *data = GRPC_SLICE_START_PTR(slice_) + GRPC_SLICE_LENGTH(slice_) - + backup_count_; + GPR_CODEGEN_ASSERT(backup_count_ <= INT_MAX); + *size = (int)backup_count_; + backup_count_ = 0; + return true; + } + /// Otherwise get the next slice from the byte buffer reader + if (!g_core_codegen_interface->grpc_byte_buffer_reader_next(&reader_, + &slice_)) { + return false; + } + g_core_codegen_interface->grpc_slice_unref(slice_); + *data = GRPC_SLICE_START_PTR(slice_); + // On win x64, int is only 32bit + GPR_CODEGEN_ASSERT(GRPC_SLICE_LENGTH(slice_) <= INT_MAX); + byte_count_ += * size = (int)GRPC_SLICE_LENGTH(slice_); + return true; + } + + /// Returns the status of the buffer reader. + Status status() const { return status_; } + + /// The proto library calls this to indicate that we should back up \a count + /// bytes that have already been returned by the last call of Next. + /// So do the backup and have that ready for a later Next. + void BackUp(int count) override { + GPR_CODEGEN_ASSERT(count <= static_cast(GRPC_SLICE_LENGTH(slice_))); + backup_count_ = count; + } + + /// The proto library calls this to skip over \a count bytes. Implement this + /// using Next and BackUp combined. + bool Skip(int count) override { + const void* data; + int size; + while (Next(&data, &size)) { + if (size >= count) { + BackUp(size - count); + return true; + } + // size < count; + count -= size; + } + // error or we have too large count; + return false; + } + + /// Returns the total number of bytes read since this object was created. + grpc::protobuf::int64 ByteCount() const override { + return byte_count_ - backup_count_; + } + + // These protected members are needed to support internal optimizations. + // they expose internal bits of grpc core that are NOT stable. If you have + // a use case needs to use one of these functions, please send an email to + // https://groups.google.com/forum/#!forum/grpc-io. + protected: + void set_byte_count(int64_t byte_count) { byte_count_ = byte_count; } + int64_t backup_count() { return backup_count_; } + void set_backup_count(int64_t backup_count) { backup_count_ = backup_count; } + grpc_byte_buffer_reader* reader() { return &reader_; } + grpc_slice* slice() { return &slice_; } + + private: + int64_t byte_count_; ///< total bytes read since object creation + int64_t backup_count_; ///< how far backed up in the stream we are + grpc_byte_buffer_reader reader_; ///< internal object to read \a grpc_slice + ///< from the \a grpc_byte_buffer + grpc_slice slice_; ///< current slice passed back to the caller + Status status_; ///< status of the entire object +}; + +} // namespace grpc + +#endif // GRPCPP_IMPL_CODEGEN_PROTO_BUFFER_READER_H diff --git a/include/grpcpp/impl/codegen/proto_buffer_writer.h b/include/grpcpp/impl/codegen/proto_buffer_writer.h new file mode 100644 index 0000000000..faf99800cd --- /dev/null +++ b/include/grpcpp/impl/codegen/proto_buffer_writer.h @@ -0,0 +1,168 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPCPP_IMPL_CODEGEN_PROTO_BUFFER_WRITER_H +#define GRPCPP_IMPL_CODEGEN_PROTO_BUFFER_WRITER_H + +#include + +#include +#include +#include +#include +#include +#include +#include + +/// This header provides an object that writes bytes directly into a +/// grpc::ByteBuffer, via the ZeroCopyOutputStream interface + +namespace grpc { + +extern CoreCodegenInterface* g_core_codegen_interface; + +// Forward declaration for testing use only +namespace internal { +class GrpcProtoBufferWriterPeer; +} // namespace internal + +const int kGrpcProtoBufferWriterMaxBufferLength = 1024 * 1024; + +/// This is a specialization of the protobuf class ZeroCopyOutputStream. +/// The principle is to give the proto layer one buffer of bytes at a time +/// that it can use to serialize the next portion of the message, with the +/// option to "backup" if more buffer is given than required at the last buffer. +/// +/// Read more about ZeroCopyOutputStream interface here: +/// https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.io.zero_copy_stream#ZeroCopyOutputStream +class GrpcProtoBufferWriter + : public ::grpc::protobuf::io::ZeroCopyOutputStream { + public: + /// Constructor for this derived class + /// + /// \param[out] byte_buffer A pointer to the grpc::ByteBuffer created + /// \param block_size How big are the chunks to allocate at a time + /// \param total_size How many total bytes are required for this proto + GrpcProtoBufferWriter(ByteBuffer* byte_buffer, int block_size, int total_size) + : block_size_(block_size), + total_size_(total_size), + byte_count_(0), + have_backup_(false) { + GPR_CODEGEN_ASSERT(!byte_buffer->Valid()); + /// Create an empty raw byte buffer and look at its underlying slice buffer + grpc_byte_buffer* bp = + g_core_codegen_interface->grpc_raw_byte_buffer_create(NULL, 0); + byte_buffer->set_buffer(bp); + slice_buffer_ = &bp->data.raw.slice_buffer; + } + + ~GrpcProtoBufferWriter() { + if (have_backup_) { + g_core_codegen_interface->grpc_slice_unref(backup_slice_); + } + } + + /// Give the proto library the next buffer of bytes and its size. It is + /// safe for the caller to write from data[0, size - 1]. + bool Next(void** data, int* size) override { + // Protobuf should not ask for more memory than total_size_. + GPR_CODEGEN_ASSERT(byte_count_ < total_size_); + // 1. Use the remaining backup slice if we have one + // 2. Otherwise allocate a slice, up to the remaining length needed + // or our maximum allocation size + // 3. Provide the slice start and size available + // 4. Add the slice being returned to the slice buffer + size_t remain = total_size_ - byte_count_; + if (have_backup_) { + /// If we have a backup slice, we should use it first + slice_ = backup_slice_; + have_backup_ = false; + if (GRPC_SLICE_LENGTH(slice_) > remain) { + GRPC_SLICE_SET_LENGTH(slice_, remain); + } + } else { + // When less than a whole block is needed, only allocate that much. + // But make sure the allocated slice is not inlined. + size_t allocate_length = + remain > static_cast(block_size_) ? block_size_ : remain; + slice_ = g_core_codegen_interface->grpc_slice_malloc( + allocate_length > GRPC_SLICE_INLINED_SIZE + ? allocate_length + : GRPC_SLICE_INLINED_SIZE + 1); + } + *data = GRPC_SLICE_START_PTR(slice_); + // On win x64, int is only 32bit + GPR_CODEGEN_ASSERT(GRPC_SLICE_LENGTH(slice_) <= INT_MAX); + byte_count_ += * size = (int)GRPC_SLICE_LENGTH(slice_); + g_core_codegen_interface->grpc_slice_buffer_add(slice_buffer_, slice_); + return true; + } + + /// Backup by \a count bytes because Next returned more bytes than needed + /// (only used in the last buffer). \a count must be less than or equal too + /// the last buffer returned from next. + void BackUp(int count) override { + /// 1. Remove the partially-used last slice from the slice buffer + /// 2. Split it into the needed (if any) and unneeded part + /// 3. Add the needed part back to the slice buffer + /// 4. Mark that we still have the remaining part (for later use/unref) + GPR_CODEGEN_ASSERT(count <= static_cast(GRPC_SLICE_LENGTH(slice_))); + g_core_codegen_interface->grpc_slice_buffer_pop(slice_buffer_); + if ((size_t)count == GRPC_SLICE_LENGTH(slice_)) { + backup_slice_ = slice_; + } else { + backup_slice_ = g_core_codegen_interface->grpc_slice_split_tail( + &slice_, GRPC_SLICE_LENGTH(slice_) - count); + g_core_codegen_interface->grpc_slice_buffer_add(slice_buffer_, slice_); + } + // It's dangerous to keep an inlined grpc_slice as the backup slice, since + // on a following Next() call, a reference will be returned to this slice + // via GRPC_SLICE_START_PTR, which will not be an address held by + // slice_buffer_. + have_backup_ = backup_slice_.refcount != NULL; + byte_count_ -= count; + } + + /// Returns the total number of bytes written since this object was created. + grpc::protobuf::int64 ByteCount() const override { return byte_count_; } + + // These protected members are needed to support internal optimizations. + // they expose internal bits of grpc core that are NOT stable. If you have + // a use case needs to use one of these functions, please send an email to + // https://groups.google.com/forum/#!forum/grpc-io. + protected: + grpc_slice_buffer* slice_buffer() { return slice_buffer_; } + void set_byte_count(int64_t byte_count) { byte_count_ = byte_count; } + + private: + // friend for testing purposes only + friend class internal::GrpcProtoBufferWriterPeer; + const int block_size_; ///< size to alloc for each new \a grpc_slice needed + const int total_size_; ///< byte size of proto being serialized + int64_t byte_count_; ///< bytes written since this object was created + grpc_slice_buffer* + slice_buffer_; ///< internal buffer of slices holding the serialized data + bool have_backup_; ///< if we are holding a backup slice or not + grpc_slice backup_slice_; ///< holds space we can still write to, if the + ///< caller has called BackUp + grpc_slice slice_; ///< current slice passed back to the caller +}; + +} // namespace grpc + +#endif // GRPCPP_IMPL_CODEGEN_PROTO_BUFFER_WRITER_H diff --git a/include/grpcpp/impl/codegen/proto_utils.h b/include/grpcpp/impl/codegen/proto_utils.h index 81438ee1d5..ec1dccaa74 100644 --- a/include/grpcpp/impl/codegen/proto_utils.h +++ b/include/grpcpp/impl/codegen/proto_utils.h @@ -24,203 +24,62 @@ #include #include #include +#include #include #include +#include +#include #include +#include #include +/// This header provides serialization and deserialization between gRPC +/// messages serialized using protobuf and the C++ objects they represent. + namespace grpc { extern CoreCodegenInterface* g_core_codegen_interface; -namespace internal { - -class GrpcBufferWriterPeer; - -const int kGrpcBufferWriterMaxBufferLength = 1024 * 1024; - -class GrpcBufferWriter : public ::grpc::protobuf::io::ZeroCopyOutputStream { - public: - GrpcBufferWriter(grpc_byte_buffer** bp, int block_size, int total_size) - : block_size_(block_size), - total_size_(total_size), - byte_count_(0), - have_backup_(false) { - *bp = g_core_codegen_interface->grpc_raw_byte_buffer_create(NULL, 0); - slice_buffer_ = &(*bp)->data.raw.slice_buffer; - } - - ~GrpcBufferWriter() override { - if (have_backup_) { - g_core_codegen_interface->grpc_slice_unref(backup_slice_); - } - } - - bool Next(void** data, int* size) override { - // Protobuf should not ask for more memory than total_size_. - GPR_CODEGEN_ASSERT(byte_count_ < total_size_); - size_t remain = total_size_ - byte_count_; - if (have_backup_) { - slice_ = backup_slice_; - have_backup_ = false; - if (GRPC_SLICE_LENGTH(slice_) > remain) { - GRPC_SLICE_SET_LENGTH(slice_, remain); - } - } else { - // When less than a whole block is needed, only allocate that much. - // But make sure the allocated slice is not inlined. - size_t allocate_length = - remain > static_cast(block_size_) ? block_size_ : remain; - slice_ = g_core_codegen_interface->grpc_slice_malloc( - allocate_length > GRPC_SLICE_INLINED_SIZE - ? allocate_length - : GRPC_SLICE_INLINED_SIZE + 1); - } - *data = GRPC_SLICE_START_PTR(slice_); - // On win x64, int is only 32bit - GPR_CODEGEN_ASSERT(GRPC_SLICE_LENGTH(slice_) <= INT_MAX); - byte_count_ += * size = (int)GRPC_SLICE_LENGTH(slice_); - g_core_codegen_interface->grpc_slice_buffer_add(slice_buffer_, slice_); - return true; - } - - void BackUp(int count) override { - g_core_codegen_interface->grpc_slice_buffer_pop(slice_buffer_); - if ((size_t)count == GRPC_SLICE_LENGTH(slice_)) { - backup_slice_ = slice_; - } else { - backup_slice_ = g_core_codegen_interface->grpc_slice_split_tail( - &slice_, GRPC_SLICE_LENGTH(slice_) - count); - g_core_codegen_interface->grpc_slice_buffer_add(slice_buffer_, slice_); - } - // It's dangerous to keep an inlined grpc_slice as the backup slice, since - // on a following Next() call, a reference will be returned to this slice - // via GRPC_SLICE_START_PTR, which will not be an adddress held by - // slice_buffer_. - have_backup_ = backup_slice_.refcount != NULL; - byte_count_ -= count; - } - - grpc::protobuf::int64 ByteCount() const override { return byte_count_; } - - protected: - friend class GrpcBufferWriterPeer; - const int block_size_; - const int total_size_; - int64_t byte_count_; - grpc_slice_buffer* slice_buffer_; - bool have_backup_; - grpc_slice backup_slice_; - grpc_slice slice_; -}; - -class GrpcBufferReader : public ::grpc::protobuf::io::ZeroCopyInputStream { - public: - explicit GrpcBufferReader(grpc_byte_buffer* buffer) - : byte_count_(0), backup_count_(0), status_() { - if (!g_core_codegen_interface->grpc_byte_buffer_reader_init(&reader_, - buffer)) { - status_ = Status(StatusCode::INTERNAL, - "Couldn't initialize byte buffer reader"); - } - } - ~GrpcBufferReader() override { - g_core_codegen_interface->grpc_byte_buffer_reader_destroy(&reader_); - } - - bool Next(const void** data, int* size) override { - if (!status_.ok()) { - return false; - } - if (backup_count_ > 0) { - *data = GRPC_SLICE_START_PTR(slice_) + GRPC_SLICE_LENGTH(slice_) - - backup_count_; - GPR_CODEGEN_ASSERT(backup_count_ <= INT_MAX); - *size = (int)backup_count_; - backup_count_ = 0; - return true; - } - if (!g_core_codegen_interface->grpc_byte_buffer_reader_next(&reader_, - &slice_)) { - return false; - } - g_core_codegen_interface->grpc_slice_unref(slice_); - *data = GRPC_SLICE_START_PTR(slice_); - // On win x64, int is only 32bit - GPR_CODEGEN_ASSERT(GRPC_SLICE_LENGTH(slice_) <= INT_MAX); - byte_count_ += * size = (int)GRPC_SLICE_LENGTH(slice_); - return true; - } - - Status status() const { return status_; } - - void BackUp(int count) override { backup_count_ = count; } - - bool Skip(int count) override { - const void* data; - int size; - while (Next(&data, &size)) { - if (size >= count) { - BackUp(size - count); - return true; - } - // size < count; - count -= size; - } - // error or we have too large count; - return false; - } - - grpc::protobuf::int64 ByteCount() const override { - return byte_count_ - backup_count_; - } - - protected: - int64_t byte_count_; - int64_t backup_count_; - grpc_byte_buffer_reader reader_; - grpc_slice slice_; - Status status_; -}; - -// BufferWriter must be a subclass of io::ZeroCopyOutputStream. -template -Status GenericSerialize(const grpc::protobuf::Message& msg, - grpc_byte_buffer** bp, bool* own_buffer) { - static_assert( - std::is_base_of::value, - "BufferWriter must be a subclass of io::ZeroCopyOutputStream"); +// ProtoBufferWriter must be a subclass of ::protobuf::io::ZeroCopyOutputStream. +template +Status GenericSerialize(const grpc::protobuf::Message& msg, ByteBuffer* bb, + bool* own_buffer) { + static_assert(std::is_base_of::value, + "ProtoBufferWriter must be a subclass of " + "::protobuf::io::ZeroCopyOutputStream"); *own_buffer = true; int byte_size = msg.ByteSize(); if ((size_t)byte_size <= GRPC_SLICE_INLINED_SIZE) { - grpc_slice slice = g_core_codegen_interface->grpc_slice_malloc(byte_size); - GPR_CODEGEN_ASSERT( - GRPC_SLICE_END_PTR(slice) == - msg.SerializeWithCachedSizesToArray(GRPC_SLICE_START_PTR(slice))); - *bp = g_core_codegen_interface->grpc_raw_byte_buffer_create(&slice, 1); - g_core_codegen_interface->grpc_slice_unref(slice); + Slice slice(byte_size); + // We serialize directly into the allocated slices memory + GPR_CODEGEN_ASSERT(slice.end() == msg.SerializeWithCachedSizesToArray( + const_cast(slice.begin()))); + ByteBuffer tmp(&slice, 1); + bb->Swap(&tmp); return g_core_codegen_interface->ok(); } - BufferWriter writer(bp, kGrpcBufferWriterMaxBufferLength, byte_size); + ProtoBufferWriter writer(bb, kGrpcProtoBufferWriterMaxBufferLength, + byte_size); return msg.SerializeToZeroCopyStream(&writer) ? g_core_codegen_interface->ok() : Status(StatusCode::INTERNAL, "Failed to serialize message"); } -// BufferReader must be a subclass of io::ZeroCopyInputStream. -template -Status GenericDeserialize(grpc_byte_buffer* buffer, - grpc::protobuf::Message* msg) { - static_assert( - std::is_base_of::value, - "BufferReader must be a subclass of io::ZeroCopyInputStream"); +// BufferReader must be a subclass of ::protobuf::io::ZeroCopyInputStream. +template +Status GenericDeserialize(ByteBuffer* buffer, grpc::protobuf::Message* msg) { + static_assert(std::is_base_of::value, + "ProtoBufferReader must be a subclass of " + "::protobuf::io::ZeroCopyInputStream"); if (buffer == nullptr) { return Status(StatusCode::INTERNAL, "No payload"); } Status result = g_core_codegen_interface->ok(); { - BufferReader reader(buffer); + ProtoBufferReader reader(buffer); if (!reader.status().ok()) { return reader.status(); } @@ -233,12 +92,10 @@ Status GenericDeserialize(grpc_byte_buffer* buffer, result = Status(StatusCode::INTERNAL, "Did not read entire message"); } } - g_core_codegen_interface->grpc_byte_buffer_destroy(buffer); + buffer->Clear(); return result; } -} // namespace internal - // this is needed so the following class does not conflict with protobuf // serializers that utilize internal-only tools. #ifdef GRPC_OPEN_SOURCE_PROTO @@ -249,16 +106,13 @@ template class SerializationTraits::value>::type> { public: - static Status Serialize(const grpc::protobuf::Message& msg, - grpc_byte_buffer** bp, bool* own_buffer) { - return internal::GenericSerialize( - msg, bp, own_buffer); + static Status Serialize(const grpc::protobuf::Message& msg, ByteBuffer* bb, + bool* own_buffer) { + return GenericSerialize(msg, bb, own_buffer); } - static Status Deserialize(grpc_byte_buffer* buffer, - grpc::protobuf::Message* msg) { - return internal::GenericDeserialize(buffer, - msg); + static Status Deserialize(ByteBuffer* buffer, grpc::protobuf::Message* msg) { + return GenericDeserialize(buffer, msg); } }; #endif diff --git a/include/grpcpp/impl/codegen/slice.h b/include/grpcpp/impl/codegen/slice.h index fcccd4b68e..8966559dc8 100644 --- a/include/grpcpp/impl/codegen/slice.h +++ b/include/grpcpp/impl/codegen/slice.h @@ -35,34 +35,43 @@ namespace grpc { class Slice final { public: /// Construct an empty slice. - Slice(); + Slice() : slice_(g_core_codegen_interface->grpc_empty_slice()) {} /// Destructor - drops one reference. - ~Slice(); + ~Slice() { g_core_codegen_interface->grpc_slice_unref(slice_); } enum AddRef { ADD_REF }; /// Construct a slice from \a slice, adding a reference. - Slice(grpc_slice slice, AddRef); + Slice(grpc_slice slice, AddRef) + : slice_(g_core_codegen_interface->grpc_slice_ref(slice)) {} enum StealRef { STEAL_REF }; /// Construct a slice from \a slice, stealing a reference. - Slice(grpc_slice slice, StealRef); + Slice(grpc_slice slice, StealRef) : slice_(slice) {} /// Allocate a slice of specified size - Slice(size_t len); + Slice(size_t len) + : slice_(g_core_codegen_interface->grpc_slice_malloc(len)) {} /// Construct a slice from a copied buffer - Slice(const void* buf, size_t len); + Slice(const void* buf, size_t len) + : slice_(g_core_codegen_interface->grpc_slice_from_copied_buffer( + reinterpret_cast(buf), len)) {} /// Construct a slice from a copied string - Slice(const grpc::string& str); + Slice(const grpc::string& str) + : slice_(g_core_codegen_interface->grpc_slice_from_copied_buffer( + str.c_str(), str.length())) {} enum StaticSlice { STATIC_SLICE }; /// Construct a slice from a static buffer - Slice(const void* buf, size_t len, StaticSlice); + Slice(const void* buf, size_t len, StaticSlice) + : slice_(g_core_codegen_interface->grpc_slice_from_static_buffer( + reinterpret_cast(buf), len)) {} /// Copy constructor, adds a reference. - Slice(const Slice& other); + Slice(const Slice& other) + : slice_(g_core_codegen_interface->grpc_slice_ref(other.slice_)) {} /// Assignment, reference count is unchanged. Slice& operator=(Slice other) { @@ -75,14 +84,18 @@ class Slice final { /// user data pointer passed in at destruction. Can be the same as buf or /// different (e.g., if data is part of a larger structure that must be /// destroyed when the data is no longer needed) - Slice(void* buf, size_t len, void (*destroy)(void*), void* user_data); + Slice(void* buf, size_t len, void (*destroy)(void*), void* user_data) + : slice_(g_core_codegen_interface->grpc_slice_new_with_user_data( + buf, len, destroy, user_data)) {} /// Specialization of above for common case where buf == user_data Slice(void* buf, size_t len, void (*destroy)(void*)) : Slice(buf, len, destroy, buf) {} /// Similar to the above but has a destroy that also takes slice length - Slice(void* buf, size_t len, void (*destroy)(void*, size_t)); + Slice(void* buf, size_t len, void (*destroy)(void*, size_t)) + : slice_(g_core_codegen_interface->grpc_slice_new_with_len(buf, len, + destroy)) {} /// Byte size. size_t size() const { return GRPC_SLICE_LENGTH(slice_); } @@ -94,7 +107,9 @@ class Slice final { const uint8_t* end() const { return GRPC_SLICE_END_PTR(slice_); } /// Raw C slice. Caller needs to call grpc_slice_unref when done. - grpc_slice c_slice() const; + grpc_slice c_slice() const { + return g_core_codegen_interface->grpc_slice_ref(slice_); + } private: friend class ByteBuffer; diff --git a/include/grpcpp/support/proto_buffer_reader.h b/include/grpcpp/support/proto_buffer_reader.h new file mode 100644 index 0000000000..4cdb65d531 --- /dev/null +++ b/include/grpcpp/support/proto_buffer_reader.h @@ -0,0 +1,24 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPCPP_SUPPORT_PROTO_BUFFER_READER_H +#define GRPCPP_SUPPORT_PROTO_BUFFER_READER_H + +#include + +#endif // GRPCPP_SUPPORT_PROTO_BUFFER_READER_H diff --git a/include/grpcpp/support/proto_buffer_writer.h b/include/grpcpp/support/proto_buffer_writer.h new file mode 100644 index 0000000000..01cf29c457 --- /dev/null +++ b/include/grpcpp/support/proto_buffer_writer.h @@ -0,0 +1,24 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPCPP_SUPPORT_PROTO_BUFFER_WRITER_H +#define GRPCPP_SUPPORT_PROTO_BUFFER_WRITER_H + +#include + +#endif // GRPCPP_SUPPORT_PROTO_BUFFER_WRITER_H diff --git a/src/cpp/common/core_codegen.cc b/src/cpp/common/core_codegen.cc index aa9788da76..619aacadaa 100644 --- a/src/cpp/common/core_codegen.cc +++ b/src/cpp/common/core_codegen.cc @@ -98,6 +98,10 @@ void CoreCodegen::grpc_byte_buffer_destroy(grpc_byte_buffer* bb) { ::grpc_byte_buffer_destroy(bb); } +size_t CoreCodegen::grpc_byte_buffer_length(grpc_byte_buffer* bb) { + return ::grpc_byte_buffer_length(bb); +} + grpc_call_error CoreCodegen::grpc_call_cancel_with_status( grpc_call* call, grpc_status_code status, const char* description, void* reserved) { @@ -135,6 +139,12 @@ grpc_slice CoreCodegen::grpc_slice_new_with_user_data(void* p, size_t len, return ::grpc_slice_new_with_user_data(p, len, destroy, user_data); } +grpc_slice CoreCodegen::grpc_slice_new_with_len(void* p, size_t len, + void (*destroy)(void*, + size_t)) { + return ::grpc_slice_new_with_len(p, len, destroy); +} + grpc_slice CoreCodegen::grpc_empty_slice() { return ::grpc_empty_slice(); } grpc_slice CoreCodegen::grpc_slice_malloc(size_t length) { diff --git a/src/cpp/util/byte_buffer_cc.cc b/src/cpp/util/byte_buffer_cc.cc index fbc1768bcc..d976b69440 100644 --- a/src/cpp/util/byte_buffer_cc.cc +++ b/src/cpp/util/byte_buffer_cc.cc @@ -23,34 +23,6 @@ namespace grpc { -static internal::GrpcLibraryInitializer g_gli_initializer; - -ByteBuffer::ByteBuffer(const Slice* slices, size_t nslices) { - // The following assertions check that the representation of a grpc::Slice is - // identical to that of a grpc_slice: it has a grpc_slice field, and nothing - // else. - static_assert(std::is_same::value, - "Slice must have same representation as grpc_slice"); - static_assert(sizeof(Slice) == sizeof(grpc_slice), - "Slice must have same representation as grpc_slice"); - // The following assertions check that the representation of a ByteBuffer is - // identical to grpc_byte_buffer*: it has a grpc_byte_buffer* field, - // and nothing else. - static_assert(std::is_same::value, - "ByteBuffer must have same representation as " - "grpc_byte_buffer*"); - static_assert(sizeof(ByteBuffer) == sizeof(grpc_byte_buffer*), - "ByteBuffer must have same representation as " - "grpc_byte_buffer*"); - g_gli_initializer.summon(); // Make sure that initializer linked in - // The const_cast is legal if grpc_raw_byte_buffer_create() does no more - // than its advertised side effect of increasing the reference count of the - // slices it processes, and such an increase does not affect the semantics - // seen by the caller of this constructor. - buffer_ = grpc_raw_byte_buffer_create( - reinterpret_cast(const_cast(slices)), nslices); -} - Status ByteBuffer::Dump(std::vector* slices) const { slices->clear(); if (!buffer_) { @@ -69,14 +41,6 @@ Status ByteBuffer::Dump(std::vector* slices) const { return Status::OK; } -size_t ByteBuffer::Length() const { - if (buffer_) { - return grpc_byte_buffer_length(buffer_); - } else { - return 0; - } -} - ByteBuffer::ByteBuffer(const ByteBuffer& buf) : buffer_(grpc_byte_buffer_copy(buf.buffer_)) {} @@ -90,10 +54,4 @@ ByteBuffer& ByteBuffer::operator=(const ByteBuffer& buf) { return *this; } -void ByteBuffer::Swap(ByteBuffer* other) { - grpc_byte_buffer* tmp = other->buffer_; - other->buffer_ = buffer_; - buffer_ = tmp; -} - } // namespace grpc diff --git a/src/cpp/util/slice_cc.cc b/src/cpp/util/slice_cc.cc deleted file mode 100644 index c72dbdbfc0..0000000000 --- a/src/cpp/util/slice_cc.cc +++ /dev/null @@ -1,55 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include - -namespace grpc { - -Slice::Slice() : slice_(grpc_empty_slice()) {} - -Slice::~Slice() { grpc_slice_unref(slice_); } - -Slice::Slice(grpc_slice slice, AddRef) : slice_(grpc_slice_ref(slice)) {} - -Slice::Slice(grpc_slice slice, StealRef) : slice_(slice) {} - -Slice::Slice(size_t len) : slice_(grpc_slice_malloc(len)) {} - -Slice::Slice(const void* buf, size_t len) - : slice_( - grpc_slice_from_copied_buffer(static_cast(buf), len)) {} - -Slice::Slice(const grpc::string& str) - : slice_(grpc_slice_from_copied_buffer(str.c_str(), str.length())) {} - -Slice::Slice(const void* buf, size_t len, StaticSlice) - : slice_( - grpc_slice_from_static_buffer(static_cast(buf), len)) {} - -Slice::Slice(const Slice& other) : slice_(grpc_slice_ref(other.slice_)) {} - -Slice::Slice(void* buf, size_t len, void (*destroy)(void*), void* user_data) - : slice_(grpc_slice_new_with_user_data(buf, len, destroy, user_data)) {} - -Slice::Slice(void* buf, size_t len, void (*destroy)(void*, size_t)) - : slice_(grpc_slice_new_with_len(buf, len, destroy)) {} - -grpc_slice Slice::c_slice() const { return grpc_slice_ref(slice_); } - -} // namespace grpc diff --git a/test/cpp/codegen/proto_utils_test.cc b/test/cpp/codegen/proto_utils_test.cc index 836d3d8076..53e2a2864c 100644 --- a/test/cpp/codegen/proto_utils_test.cc +++ b/test/cpp/codegen/proto_utils_test.cc @@ -24,32 +24,43 @@ #include namespace grpc { + namespace internal { -// Provide access to GrpcBufferWriter internals. -class GrpcBufferWriterPeer { +// Provide access to GrpcProtoBufferWriter internals. +class GrpcProtoBufferWriterPeer { public: - explicit GrpcBufferWriterPeer(internal::GrpcBufferWriter* writer) + explicit GrpcProtoBufferWriterPeer(GrpcProtoBufferWriter* writer) : writer_(writer) {} bool have_backup() const { return writer_->have_backup_; } const grpc_slice& backup_slice() const { return writer_->backup_slice_; } const grpc_slice& slice() const { return writer_->slice_; } private: - GrpcBufferWriter* writer_; + GrpcProtoBufferWriter* writer_; +}; + +// Provide access to ByteBuffer internals. +class GrpcByteBufferPeer { + public: + explicit GrpcByteBufferPeer(ByteBuffer* bb) : bb_(bb) {} + grpc_byte_buffer* c_buffer() { return bb_->c_buffer(); } + + private: + ByteBuffer* bb_; }; class ProtoUtilsTest : public ::testing::Test {}; // Regression test for a memory corruption bug where a series of -// GrpcBufferWriter Next()/Backup() invocations could result in a dangling +// GrpcProtoBufferWriter Next()/Backup() invocations could result in a dangling // pointer returned by Next() due to the interaction between grpc_slice inlining // and GRPC_SLICE_START_PTR. TEST_F(ProtoUtilsTest, TinyBackupThenNext) { - grpc_byte_buffer* bp; + ByteBuffer bp; const int block_size = 1024; - GrpcBufferWriter writer(&bp, block_size, 8192); - GrpcBufferWriterPeer peer(&writer); + GrpcProtoBufferWriter writer(&bp, block_size, 8192); + GrpcProtoBufferWriterPeer peer(&writer); void* data; int size; @@ -63,17 +74,14 @@ TEST_F(ProtoUtilsTest, TinyBackupThenNext) { ASSERT_TRUE(writer.Next(&data, &size)); EXPECT_TRUE(peer.slice().refcount != nullptr); EXPECT_EQ(block_size, size); - - // Cleanup. - g_core_codegen_interface->grpc_byte_buffer_destroy(bp); } namespace { // Set backup_size to 0 to indicate no backup is needed. void BufferWriterTest(int block_size, int total_size, int backup_size) { - grpc_byte_buffer* bp; - GrpcBufferWriter writer(&bp, block_size, total_size); + ByteBuffer bb; + GrpcProtoBufferWriter writer(&bb, block_size, total_size); int written_size = 0; void* data; @@ -110,10 +118,11 @@ void BufferWriterTest(int block_size, int total_size, int backup_size) { writer.BackUp(backup_size); } } - EXPECT_EQ(grpc_byte_buffer_length(bp), (size_t)total_size); + EXPECT_EQ(bb.Length(), (size_t)total_size); grpc_byte_buffer_reader reader; - grpc_byte_buffer_reader_init(&reader, bp); + GrpcByteBufferPeer peer(&bb); + grpc_byte_buffer_reader_init(&reader, peer.c_buffer()); int read_bytes = 0; while (read_bytes < total_size) { grpc_slice s; @@ -126,7 +135,6 @@ void BufferWriterTest(int block_size, int total_size, int backup_size) { } EXPECT_EQ(read_bytes, total_size); grpc_byte_buffer_reader_destroy(&reader); - grpc_byte_buffer_destroy(bp); } TEST(WriterTest, TinyBlockTinyBackup) { @@ -154,7 +162,7 @@ TEST(WriterTest, LargeBlockLargeBackup) { BufferWriterTest(4096, 8192, 4095); } } // namespace grpc int main(int argc, char** argv) { - // Ensure the GrpcBufferWriter internals are initialized. + // Ensure the GrpcProtoBufferWriter internals are initialized. grpc::internal::GrpcLibraryInitializer init; init.summon(); grpc::GrpcLibraryCodegen lib; diff --git a/test/cpp/util/byte_buffer_test.cc b/test/cpp/util/byte_buffer_test.cc index 605ef15123..47a5b7f03a 100644 --- a/test/cpp/util/byte_buffer_test.cc +++ b/test/cpp/util/byte_buffer_test.cc @@ -16,7 +16,8 @@ * */ -#include +#include +#include #include #include @@ -27,6 +28,9 @@ #include namespace grpc { + +static internal::GrpcLibraryInitializer g_gli_initializer; + namespace { const char* kContent1 = "hello xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; diff --git a/test/cpp/util/slice_test.cc b/test/cpp/util/slice_test.cc index 8e06062360..dc1910038f 100644 --- a/test/cpp/util/slice_test.cc +++ b/test/cpp/util/slice_test.cc @@ -16,13 +16,17 @@ * */ -#include +#include +#include #include #include #include namespace grpc { + +static internal::GrpcLibraryInitializer g_gli_initializer; + namespace { const char* kContent = "hello xxxxxxxxxxxxxxxxxxxx world"; diff --git a/tools/doxygen/Doxyfile.c++ b/tools/doxygen/Doxyfile.c++ index 047b27ea57..22f225ec54 100644 --- a/tools/doxygen/Doxyfile.c++ +++ b/tools/doxygen/Doxyfile.c++ @@ -954,6 +954,8 @@ include/grpcpp/impl/codegen/create_auth_context.h \ include/grpcpp/impl/codegen/grpc_library.h \ include/grpcpp/impl/codegen/metadata_map.h \ include/grpcpp/impl/codegen/method_handler_impl.h \ +include/grpcpp/impl/codegen/proto_buffer_reader.h \ +include/grpcpp/impl/codegen/proto_buffer_writer.h \ include/grpcpp/impl/codegen/proto_utils.h \ include/grpcpp/impl/codegen/rpc_method.h \ include/grpcpp/impl/codegen/rpc_service_method.h \ @@ -992,6 +994,8 @@ include/grpcpp/support/async_unary_call.h \ include/grpcpp/support/byte_buffer.h \ include/grpcpp/support/channel_arguments.h \ include/grpcpp/support/config.h \ +include/grpcpp/support/proto_buffer_reader.h \ +include/grpcpp/support/proto_buffer_writer.h \ include/grpcpp/support/slice.h \ include/grpcpp/support/status.h \ include/grpcpp/support/status_code_enum.h \ diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index 3e2c192864..63d238d741 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -956,6 +956,8 @@ include/grpcpp/impl/codegen/create_auth_context.h \ include/grpcpp/impl/codegen/grpc_library.h \ include/grpcpp/impl/codegen/metadata_map.h \ include/grpcpp/impl/codegen/method_handler_impl.h \ +include/grpcpp/impl/codegen/proto_buffer_reader.h \ +include/grpcpp/impl/codegen/proto_buffer_writer.h \ include/grpcpp/impl/codegen/proto_utils.h \ include/grpcpp/impl/codegen/rpc_method.h \ include/grpcpp/impl/codegen/rpc_service_method.h \ @@ -994,6 +996,8 @@ include/grpcpp/support/async_unary_call.h \ include/grpcpp/support/byte_buffer.h \ include/grpcpp/support/channel_arguments.h \ include/grpcpp/support/config.h \ +include/grpcpp/support/proto_buffer_reader.h \ +include/grpcpp/support/proto_buffer_writer.h \ include/grpcpp/support/slice.h \ include/grpcpp/support/status.h \ include/grpcpp/support/status_code_enum.h \ @@ -1209,7 +1213,6 @@ src/cpp/server/thread_pool_interface.h \ src/cpp/thread_manager/thread_manager.cc \ src/cpp/thread_manager/thread_manager.h \ src/cpp/util/byte_buffer_cc.cc \ -src/cpp/util/slice_cc.cc \ src/cpp/util/status.cc \ src/cpp/util/string_ref.cc \ src/cpp/util/time_cc.cc \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index c7ea43fb09..c79996f818 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -10746,6 +10746,8 @@ ], "headers": [ "include/grpc++/impl/codegen/proto_utils.h", + "include/grpcpp/impl/codegen/proto_buffer_reader.h", + "include/grpcpp/impl/codegen/proto_buffer_writer.h", "include/grpcpp/impl/codegen/proto_utils.h" ], "is_filegroup": true, @@ -10753,6 +10755,8 @@ "name": "grpc++_codegen_proto", "src": [ "include/grpc++/impl/codegen/proto_utils.h", + "include/grpcpp/impl/codegen/proto_buffer_reader.h", + "include/grpcpp/impl/codegen/proto_buffer_writer.h", "include/grpcpp/impl/codegen/proto_utils.h" ], "third_party": false, @@ -10851,6 +10855,8 @@ "include/grpcpp/support/byte_buffer.h", "include/grpcpp/support/channel_arguments.h", "include/grpcpp/support/config.h", + "include/grpcpp/support/proto_buffer_reader.h", + "include/grpcpp/support/proto_buffer_writer.h", "include/grpcpp/support/slice.h", "include/grpcpp/support/status.h", "include/grpcpp/support/status_code_enum.h", @@ -10953,6 +10959,8 @@ "include/grpcpp/support/byte_buffer.h", "include/grpcpp/support/channel_arguments.h", "include/grpcpp/support/config.h", + "include/grpcpp/support/proto_buffer_reader.h", + "include/grpcpp/support/proto_buffer_writer.h", "include/grpcpp/support/slice.h", "include/grpcpp/support/status.h", "include/grpcpp/support/status_code_enum.h", @@ -10997,7 +11005,6 @@ "src/cpp/thread_manager/thread_manager.cc", "src/cpp/thread_manager/thread_manager.h", "src/cpp/util/byte_buffer_cc.cc", - "src/cpp/util/slice_cc.cc", "src/cpp/util/status.cc", "src/cpp/util/string_ref.cc", "src/cpp/util/time_cc.cc" -- cgit v1.2.3 From 2d43a45ad1540f554d89503676d2db2bc25776db Mon Sep 17 00:00:00 2001 From: Mehrdad Afshari Date: Wed, 2 May 2018 22:49:52 -0700 Subject: Regenerate projects --- CMakeLists.txt | 2 +- Makefile | 4 ++-- gRPC-C++.podspec | 4 ++-- gRPC-Core.podspec | 2 +- gRPC-ProtoRPC.podspec | 2 +- gRPC-RxLibrary.podspec | 2 +- gRPC.podspec | 2 +- package.xml | 4 ++-- src/core/lib/surface/version.cc | 2 +- src/cpp/common/version_cc.cc | 2 +- src/csharp/Grpc.Core/Version.csproj.include | 2 +- src/csharp/Grpc.Core/VersionInfo.cs | 4 ++-- src/csharp/build_packages_dotnetcli.bat | 2 +- src/csharp/build_packages_dotnetcli.sh | 4 ++-- src/objective-c/!ProtoCompiler-gRPCPlugin.podspec | 2 +- src/objective-c/GRPCClient/private/version.h | 2 +- src/objective-c/tests/version.h | 2 +- src/php/composer.json | 2 +- src/php/ext/grpc/version.h | 2 +- src/python/grpcio/grpc/_grpcio_metadata.py | 2 +- src/python/grpcio/grpc_version.py | 2 +- src/python/grpcio_health_checking/grpc_version.py | 2 +- src/python/grpcio_reflection/grpc_version.py | 2 +- src/python/grpcio_testing/grpc_version.py | 2 +- src/python/grpcio_tests/grpc_version.py | 2 +- src/ruby/lib/grpc/version.rb | 2 +- src/ruby/tools/version.rb | 2 +- tools/distrib/python/grpcio_tools/grpc_version.py | 2 +- tools/doxygen/Doxyfile.c++ | 2 +- tools/doxygen/Doxyfile.c++.internal | 2 +- 30 files changed, 35 insertions(+), 35 deletions(-) (limited to 'gRPC-C++.podspec') diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e64d2efbc..8db941239f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ cmake_minimum_required(VERSION 2.8) set(PACKAGE_NAME "grpc") -set(PACKAGE_VERSION "1.12.0-dev") +set(PACKAGE_VERSION "1.13.0-dev") set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") set(PACKAGE_TARNAME "${PACKAGE_NAME}-${PACKAGE_VERSION}") set(PACKAGE_BUGREPORT "https://github.com/grpc/grpc/issues/") diff --git a/Makefile b/Makefile index 76fa95b419..0b2024996d 100644 --- a/Makefile +++ b/Makefile @@ -421,8 +421,8 @@ Q = @ endif CORE_VERSION = 6.0.0-dev -CPP_VERSION = 1.12.0-dev -CSHARP_VERSION = 1.12.0-dev +CPP_VERSION = 1.13.0-dev +CSHARP_VERSION = 1.13.0-dev CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES)) CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS) diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 990b0a4f9d..f673dd69dc 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -23,7 +23,7 @@ Pod::Spec.new do |s| s.name = 'gRPC-C++' # TODO (mxyan): use version that match gRPC version when pod is stabilized - # version = '1.12.0-dev' + # version = '1.13.0-dev' version = '0.0.2' s.version = version s.summary = 'gRPC C++ library' @@ -31,7 +31,7 @@ Pod::Spec.new do |s| s.license = 'Apache License, Version 2.0' s.authors = { 'The gRPC contributors' => 'grpc-packages@google.com' } - grpc_version = '1.12.0-dev' + grpc_version = '1.13.0-dev' s.source = { :git => 'https://github.com/grpc/grpc.git', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index a1e0fd2ca1..49ad7ef6d6 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -22,7 +22,7 @@ Pod::Spec.new do |s| s.name = 'gRPC-Core' - version = '1.12.0-dev' + version = '1.13.0-dev' s.version = version s.summary = 'Core cross-platform gRPC library, written in C' s.homepage = 'https://grpc.io' diff --git a/gRPC-ProtoRPC.podspec b/gRPC-ProtoRPC.podspec index e98dee4a3c..17e650c264 100644 --- a/gRPC-ProtoRPC.podspec +++ b/gRPC-ProtoRPC.podspec @@ -21,7 +21,7 @@ Pod::Spec.new do |s| s.name = 'gRPC-ProtoRPC' - version = '1.12.0-dev' + version = '1.13.0-dev' s.version = version s.summary = 'RPC library for Protocol Buffers, based on gRPC' s.homepage = 'https://grpc.io' diff --git a/gRPC-RxLibrary.podspec b/gRPC-RxLibrary.podspec index 3bba14b695..b9288afd80 100644 --- a/gRPC-RxLibrary.podspec +++ b/gRPC-RxLibrary.podspec @@ -21,7 +21,7 @@ Pod::Spec.new do |s| s.name = 'gRPC-RxLibrary' - version = '1.12.0-dev' + version = '1.13.0-dev' s.version = version s.summary = 'Reactive Extensions library for iOS/OSX.' s.homepage = 'https://grpc.io' diff --git a/gRPC.podspec b/gRPC.podspec index bf73ffd22e..afc4581091 100644 --- a/gRPC.podspec +++ b/gRPC.podspec @@ -20,7 +20,7 @@ Pod::Spec.new do |s| s.name = 'gRPC' - version = '1.12.0-dev' + version = '1.13.0-dev' s.version = version s.summary = 'gRPC client library for iOS/OSX' s.homepage = 'https://grpc.io' diff --git a/package.xml b/package.xml index b9cb22b647..7dcfa302ae 100644 --- a/package.xml +++ b/package.xml @@ -13,8 +13,8 @@ 2018-01-19 - 1.12.0dev - 1.12.0dev + 1.13.0dev + 1.13.0dev beta diff --git a/src/core/lib/surface/version.cc b/src/core/lib/surface/version.cc index a712e10037..306b7c395e 100644 --- a/src/core/lib/surface/version.cc +++ b/src/core/lib/surface/version.cc @@ -25,4 +25,4 @@ const char* grpc_version_string(void) { return "6.0.0-dev"; } -const char* grpc_g_stands_for(void) { return "glorious"; } +const char* grpc_g_stands_for(void) { return "gloriosa"; } diff --git a/src/cpp/common/version_cc.cc b/src/cpp/common/version_cc.cc index d669ea21a9..54cd2076ec 100644 --- a/src/cpp/common/version_cc.cc +++ b/src/cpp/common/version_cc.cc @@ -22,5 +22,5 @@ #include namespace grpc { -grpc::string Version() { return "1.12.0-dev"; } +grpc::string Version() { return "1.13.0-dev"; } } // namespace grpc diff --git a/src/csharp/Grpc.Core/Version.csproj.include b/src/csharp/Grpc.Core/Version.csproj.include index 6e28c11df2..f5d63b77f0 100755 --- a/src/csharp/Grpc.Core/Version.csproj.include +++ b/src/csharp/Grpc.Core/Version.csproj.include @@ -1,7 +1,7 @@ - 1.12.0-dev + 1.13.0-dev 3.5.1 diff --git a/src/csharp/Grpc.Core/VersionInfo.cs b/src/csharp/Grpc.Core/VersionInfo.cs index 06a0396c34..87edddae3f 100644 --- a/src/csharp/Grpc.Core/VersionInfo.cs +++ b/src/csharp/Grpc.Core/VersionInfo.cs @@ -33,11 +33,11 @@ namespace Grpc.Core /// /// Current AssemblyFileVersion of gRPC C# assemblies /// - public const string CurrentAssemblyFileVersion = "1.12.0.0"; + public const string CurrentAssemblyFileVersion = "1.13.0.0"; /// /// Current version of gRPC C# /// - public const string CurrentVersion = "1.12.0-dev"; + public const string CurrentVersion = "1.13.0-dev"; } } diff --git a/src/csharp/build_packages_dotnetcli.bat b/src/csharp/build_packages_dotnetcli.bat index 0d65748697..924d7b1697 100755 --- a/src/csharp/build_packages_dotnetcli.bat +++ b/src/csharp/build_packages_dotnetcli.bat @@ -13,7 +13,7 @@ @rem limitations under the License. @rem Current package versions -set VERSION=1.12.0-dev +set VERSION=1.13.0-dev @rem Adjust the location of nuget.exe set NUGET=C:\nuget\nuget.exe diff --git a/src/csharp/build_packages_dotnetcli.sh b/src/csharp/build_packages_dotnetcli.sh index 66aba36089..5c73a8f95f 100755 --- a/src/csharp/build_packages_dotnetcli.sh +++ b/src/csharp/build_packages_dotnetcli.sh @@ -45,7 +45,7 @@ dotnet pack --configuration Release Grpc.Auth --output ../../../artifacts dotnet pack --configuration Release Grpc.HealthCheck --output ../../../artifacts dotnet pack --configuration Release Grpc.Reflection --output ../../../artifacts -nuget pack Grpc.nuspec -Version "1.12.0-dev" -OutputDirectory ../../artifacts -nuget pack Grpc.Tools.nuspec -Version "1.12.0-dev" -OutputDirectory ../../artifacts +nuget pack Grpc.nuspec -Version "1.13.0-dev" -OutputDirectory ../../artifacts +nuget pack Grpc.Tools.nuspec -Version "1.13.0-dev" -OutputDirectory ../../artifacts (cd ../../artifacts && zip csharp_nugets_dotnetcli.zip *.nupkg) diff --git a/src/objective-c/!ProtoCompiler-gRPCPlugin.podspec b/src/objective-c/!ProtoCompiler-gRPCPlugin.podspec index f06312bea9..515dc917d1 100644 --- a/src/objective-c/!ProtoCompiler-gRPCPlugin.podspec +++ b/src/objective-c/!ProtoCompiler-gRPCPlugin.podspec @@ -42,7 +42,7 @@ Pod::Spec.new do |s| # exclamation mark ensures that other "regular" pods will be able to find it as it'll be installed # before them. s.name = '!ProtoCompiler-gRPCPlugin' - v = '1.12.0-dev' + v = '1.13.0-dev' s.version = v s.summary = 'The gRPC ProtoC plugin generates Objective-C files from .proto services.' s.description = <<-DESC diff --git a/src/objective-c/GRPCClient/private/version.h b/src/objective-c/GRPCClient/private/version.h index 1298e7e191..6fe4a7d051 100644 --- a/src/objective-c/GRPCClient/private/version.h +++ b/src/objective-c/GRPCClient/private/version.h @@ -22,4 +22,4 @@ // instead. This file can be regenerated from the template by running // `tools/buildgen/generate_projects.sh`. -#define GRPC_OBJC_VERSION_STRING @"1.12.0-dev" +#define GRPC_OBJC_VERSION_STRING @"1.13.0-dev" diff --git a/src/objective-c/tests/version.h b/src/objective-c/tests/version.h index d36545fced..e9637099d9 100644 --- a/src/objective-c/tests/version.h +++ b/src/objective-c/tests/version.h @@ -22,5 +22,5 @@ // instead. This file can be regenerated from the template by running // `tools/buildgen/generate_projects.sh`. -#define GRPC_OBJC_VERSION_STRING @"1.12.0-dev" +#define GRPC_OBJC_VERSION_STRING @"1.13.0-dev" #define GRPC_C_VERSION_STRING @"6.0.0-dev" diff --git a/src/php/composer.json b/src/php/composer.json index 57d911db79..03dffb40ab 100644 --- a/src/php/composer.json +++ b/src/php/composer.json @@ -2,7 +2,7 @@ "name": "grpc/grpc-dev", "description": "gRPC library for PHP - for Developement use only", "license": "Apache-2.0", - "version": "1.12.0", + "version": "1.13.0", "require": { "php": ">=5.5.0", "google/protobuf": "^v3.3.0" diff --git a/src/php/ext/grpc/version.h b/src/php/ext/grpc/version.h index 37df2768bf..407d6347e6 100644 --- a/src/php/ext/grpc/version.h +++ b/src/php/ext/grpc/version.h @@ -20,6 +20,6 @@ #ifndef VERSION_H #define VERSION_H -#define PHP_GRPC_VERSION "1.12.0dev" +#define PHP_GRPC_VERSION "1.13.0dev" #endif /* VERSION_H */ diff --git a/src/python/grpcio/grpc/_grpcio_metadata.py b/src/python/grpcio/grpc/_grpcio_metadata.py index cb5da72f1f..ad53f60ad3 100644 --- a/src/python/grpcio/grpc/_grpcio_metadata.py +++ b/src/python/grpcio/grpc/_grpcio_metadata.py @@ -14,4 +14,4 @@ # AUTO-GENERATED FROM `$REPO_ROOT/templates/src/python/grpcio/grpc/_grpcio_metadata.py.template`!!! -__version__ = """1.12.0.dev0""" +__version__ = """1.13.0.dev0""" diff --git a/src/python/grpcio/grpc_version.py b/src/python/grpcio/grpc_version.py index de5a780abd..57dc26dbeb 100644 --- a/src/python/grpcio/grpc_version.py +++ b/src/python/grpcio/grpc_version.py @@ -14,4 +14,4 @@ # AUTO-GENERATED FROM `$REPO_ROOT/templates/src/python/grpcio/grpc_version.py.template`!!! -VERSION = '1.12.0.dev0' +VERSION = '1.13.0.dev0' diff --git a/src/python/grpcio_health_checking/grpc_version.py b/src/python/grpcio_health_checking/grpc_version.py index afcd316e5c..ba0d4a3b6d 100644 --- a/src/python/grpcio_health_checking/grpc_version.py +++ b/src/python/grpcio_health_checking/grpc_version.py @@ -14,4 +14,4 @@ # AUTO-GENERATED FROM `$REPO_ROOT/templates/src/python/grpcio_health_checking/grpc_version.py.template`!!! -VERSION = '1.12.0.dev0' +VERSION = '1.13.0.dev0' diff --git a/src/python/grpcio_reflection/grpc_version.py b/src/python/grpcio_reflection/grpc_version.py index 824b73201d..ea2878d9ee 100644 --- a/src/python/grpcio_reflection/grpc_version.py +++ b/src/python/grpcio_reflection/grpc_version.py @@ -14,4 +14,4 @@ # AUTO-GENERATED FROM `$REPO_ROOT/templates/src/python/grpcio_reflection/grpc_version.py.template`!!! -VERSION = '1.12.0.dev0' +VERSION = '1.13.0.dev0' diff --git a/src/python/grpcio_testing/grpc_version.py b/src/python/grpcio_testing/grpc_version.py index 5b1f4c4cc0..02f19f2283 100644 --- a/src/python/grpcio_testing/grpc_version.py +++ b/src/python/grpcio_testing/grpc_version.py @@ -14,4 +14,4 @@ # AUTO-GENERATED FROM `$REPO_ROOT/templates/src/python/grpcio_testing/grpc_version.py.template`!!! -VERSION = '1.12.0.dev0' +VERSION = '1.13.0.dev0' diff --git a/src/python/grpcio_tests/grpc_version.py b/src/python/grpcio_tests/grpc_version.py index 382f95018e..9d2e41644e 100644 --- a/src/python/grpcio_tests/grpc_version.py +++ b/src/python/grpcio_tests/grpc_version.py @@ -14,4 +14,4 @@ # AUTO-GENERATED FROM `$REPO_ROOT/templates/src/python/grpcio_tests/grpc_version.py.template`!!! -VERSION = '1.12.0.dev0' +VERSION = '1.13.0.dev0' diff --git a/src/ruby/lib/grpc/version.rb b/src/ruby/lib/grpc/version.rb index 2cb7c4be53..15f375100a 100644 --- a/src/ruby/lib/grpc/version.rb +++ b/src/ruby/lib/grpc/version.rb @@ -14,5 +14,5 @@ # GRPC contains the General RPC module. module GRPC - VERSION = '1.12.0.dev' + VERSION = '1.13.0.dev' end diff --git a/src/ruby/tools/version.rb b/src/ruby/tools/version.rb index 822f70eb0a..09d5c82674 100644 --- a/src/ruby/tools/version.rb +++ b/src/ruby/tools/version.rb @@ -14,6 +14,6 @@ module GRPC module Tools - VERSION = '1.12.0.dev' + VERSION = '1.13.0.dev' end end diff --git a/tools/distrib/python/grpcio_tools/grpc_version.py b/tools/distrib/python/grpcio_tools/grpc_version.py index e71f836f6d..f0367e2af4 100644 --- a/tools/distrib/python/grpcio_tools/grpc_version.py +++ b/tools/distrib/python/grpcio_tools/grpc_version.py @@ -14,4 +14,4 @@ # AUTO-GENERATED FROM `$REPO_ROOT/templates/tools/distrib/python/grpcio_tools/grpc_version.py.template`!!! -VERSION = '1.12.0.dev0' +VERSION = '1.13.0.dev0' diff --git a/tools/doxygen/Doxyfile.c++ b/tools/doxygen/Doxyfile.c++ index 22f225ec54..884eabb956 100644 --- a/tools/doxygen/Doxyfile.c++ +++ b/tools/doxygen/Doxyfile.c++ @@ -40,7 +40,7 @@ PROJECT_NAME = "GRPC C++" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 1.12.0-dev +PROJECT_NUMBER = 1.13.0-dev # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index 63d238d741..66796bae57 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -40,7 +40,7 @@ PROJECT_NAME = "GRPC C++" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 1.12.0-dev +PROJECT_NUMBER = 1.13.0-dev # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a -- cgit v1.2.3 From 392dad7134ebd0239425289a2c555f24109ee12a Mon Sep 17 00:00:00 2001 From: Yihua Zhang Date: Thu, 3 May 2018 20:12:20 -0700 Subject: incorporate alts to google default creds --- BUILD | 3 + build.yaml | 3 + gRPC-C++.podspec | 1 + gRPC-Core.podspec | 2 + grpc.gemspec | 1 + package.xml | 1 + .../client_channel/lb_policy/grpclb/grpclb.cc | 19 ++++- .../client_channel/lb_policy/grpclb/grpclb.h | 36 ++++++++ src/core/lib/security/credentials/credentials.h | 1 + .../google_default/google_default_credentials.cc | 98 +++++++++++++++++----- .../google_default/google_default_credentials.h | 6 ++ test/core/security/credentials_test.cc | 10 ++- tools/doxygen/Doxyfile.core.internal | 1 + tools/run_tests/generated/sources_and_headers.json | 6 ++ 14 files changed, 163 insertions(+), 25 deletions(-) create mode 100644 src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h (limited to 'gRPC-C++.podspec') diff --git a/BUILD b/BUILD index df5344821c..80b40338c3 100644 --- a/BUILD +++ b/BUILD @@ -1183,6 +1183,7 @@ grpc_cc_library( ], hdrs = [ "src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h", + "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h", "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h", "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h", "src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h", @@ -1211,6 +1212,7 @@ grpc_cc_library( ], hdrs = [ "src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h", + "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h", "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h", "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h", "src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h", @@ -1386,6 +1388,7 @@ grpc_cc_library( "src/core/lib/surface/init_secure.cc", ], hdrs = [ + "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h", "src/core/lib/security/context/security_context.h", "src/core/lib/security/credentials/alts/alts_credentials.h", "src/core/lib/security/credentials/composite/composite_credentials.h", diff --git a/build.yaml b/build.yaml index d8df33a3eb..af8de14e61 100644 --- a/build.yaml +++ b/build.yaml @@ -628,6 +628,7 @@ filegroups: - name: grpc_lb_policy_grpclb headers: - src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h + - src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h - src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h - src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h - src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h @@ -648,6 +649,7 @@ filegroups: - name: grpc_lb_policy_grpclb_secure headers: - src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h + - src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h - src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h - src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h - src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h @@ -744,6 +746,7 @@ filegroups: public_headers: - include/grpc/grpc_security.h headers: + - src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h - src/core/lib/security/context/security_context.h - src/core/lib/security/credentials/alts/alts_credentials.h - src/core/lib/security/credentials/composite/composite_credentials.h diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index f673dd69dc..fe082ef3af 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -260,6 +260,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/http/client/http_client_filter.h', 'src/core/ext/filters/http/message_compress/message_compress_filter.h', 'src/core/ext/filters/http/server/http_server_filter.h', + 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h', 'src/core/lib/security/context/security_context.h', 'src/core/lib/security/credentials/alts/alts_credentials.h', 'src/core/lib/security/credentials/composite/composite_credentials.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 49ad7ef6d6..e893eb9990 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -270,6 +270,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/http/client/http_client_filter.h', 'src/core/ext/filters/http/message_compress/message_compress_filter.h', 'src/core/ext/filters/http/server/http_server_filter.h', + 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h', 'src/core/lib/security/context/security_context.h', 'src/core/lib/security/credentials/alts/alts_credentials.h', 'src/core/lib/security/credentials/composite/composite_credentials.h', @@ -849,6 +850,7 @@ Pod::Spec.new do |s| 'src/core/ext/filters/http/client/http_client_filter.h', 'src/core/ext/filters/http/message_compress/message_compress_filter.h', 'src/core/ext/filters/http/server/http_server_filter.h', + 'src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h', 'src/core/lib/security/context/security_context.h', 'src/core/lib/security/credentials/alts/alts_credentials.h', 'src/core/lib/security/credentials/composite/composite_credentials.h', diff --git a/grpc.gemspec b/grpc.gemspec index 1681033529..bb40a3ba02 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -201,6 +201,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/http/client/http_client_filter.h ) s.files += %w( src/core/ext/filters/http/message_compress/message_compress_filter.h ) s.files += %w( src/core/ext/filters/http/server/http_server_filter.h ) + s.files += %w( src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h ) s.files += %w( src/core/lib/security/context/security_context.h ) s.files += %w( src/core/lib/security/credentials/alts/alts_credentials.h ) s.files += %w( src/core/lib/security/credentials/composite/composite_credentials.h ) diff --git a/package.xml b/package.xml index 7dcfa302ae..75a69931a4 100644 --- a/package.xml +++ b/package.xml @@ -208,6 +208,7 @@ + diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc index 1a675476f0..70a91b2567 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc @@ -76,6 +76,7 @@ #include "src/core/ext/filters/client_channel/client_channel.h" #include "src/core/ext/filters/client_channel/client_channel_factory.h" #include "src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h" +#include "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h" #include "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h" #include "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h" #include "src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h" @@ -1003,6 +1004,9 @@ grpc_channel_args* BuildBalancerChannelArgs( // address updates into the LB channel. grpc_core::FakeResolverResponseGenerator::MakeChannelArg( response_generator), + // A channel arg indicating the target is a grpclb load balancer. + grpc_channel_arg_integer_create( + const_cast(GRPC_ARG_ADDRESS_IS_GRPCLB_LOAD_BALANCER), 1), }; // Construct channel args. grpc_channel_args* new_args = grpc_channel_args_copy_and_add_and_remove( @@ -1698,9 +1702,11 @@ void GrpcLb::CreateRoundRobinPolicyLocked(const Args& args) { grpc_channel_args* GrpcLb::CreateRoundRobinPolicyArgsLocked() { grpc_lb_addresses* addresses; + bool is_backend_from_grpclb_load_balancer = false; if (serverlist_ != nullptr) { GPR_ASSERT(serverlist_->num_servers > 0); addresses = ProcessServerlist(serverlist_); + is_backend_from_grpclb_load_balancer = true; } else { // If CreateOrUpdateRoundRobinPolicyLocked() is invoked when we haven't // received any serverlist from the balancer, we use the fallback backends @@ -1714,9 +1720,18 @@ grpc_channel_args* GrpcLb::CreateRoundRobinPolicyArgsLocked() { // Replace the LB addresses in the channel args that we pass down to // the subchannel. static const char* keys_to_remove[] = {GRPC_ARG_LB_ADDRESSES}; - const grpc_arg arg = grpc_lb_addresses_create_channel_arg(addresses); + const grpc_arg args_to_add[] = { + grpc_lb_addresses_create_channel_arg(addresses), + // A channel arg indicating if the target is a backend inferred from a + // grpclb load balancer. + grpc_channel_arg_integer_create( + const_cast( + GRPC_ARG_ADDRESS_IS_BACKEND_FROM_GRPCLB_LOAD_BALANCER), + is_backend_from_grpclb_load_balancer), + }; grpc_channel_args* args = grpc_channel_args_copy_and_add_and_remove( - args_, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove), &arg, 1); + args_, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove), args_to_add, + GPR_ARRAY_SIZE(args_to_add)); grpc_lb_addresses_destroy(addresses); return args; } diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h new file mode 100644 index 0000000000..4d39c4d504 --- /dev/null +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h @@ -0,0 +1,36 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_GRPCLB_H +#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_GRPCLB_H + +#include + +/** Channel arg indicating if a target corresponding to the address is grpclb + * loadbalancer. The type of this arg is an integer and the value is treated as + * a bool. */ +#define GRPC_ARG_ADDRESS_IS_GRPCLB_LOAD_BALANCER \ + "grpc.address_is_grpclb_load_balancer" +/** Channel arg indicating if a target corresponding to the address is a backend + * received from a balancer. The type of this arg is an integer and the value is + * treated as a bool. */ +#define GRPC_ARG_ADDRESS_IS_BACKEND_FROM_GRPCLB_LOAD_BALANCER \ + "grpc.address_is_backend_from_grpclb_load_balancer" + +#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_GRPCLB_H \ + */ diff --git a/src/core/lib/security/credentials/credentials.h b/src/core/lib/security/credentials/credentials.h index b1421e83c5..b486d25ab2 100644 --- a/src/core/lib/security/credentials/credentials.h +++ b/src/core/lib/security/credentials/credentials.h @@ -45,6 +45,7 @@ typedef enum { #define GRPC_CHANNEL_CREDENTIALS_TYPE_SSL "Ssl" #define GRPC_CHANNEL_CREDENTIALS_TYPE_FAKE_TRANSPORT_SECURITY \ "FakeTransportSecurity" +#define GRPC_CHANNEL_CREDENTIALS_TYPE_GOOGLE_DEFAULT "GoogleDefault" #define GRPC_CALL_CREDENTIALS_TYPE_OAUTH2 "Oauth2" #define GRPC_CALL_CREDENTIALS_TYPE_JWT "Jwt" diff --git a/src/core/lib/security/credentials/google_default/google_default_credentials.cc b/src/core/lib/security/credentials/google_default/google_default_credentials.cc index 70d4c3ea51..4b267afe3f 100644 --- a/src/core/lib/security/credentials/google_default/google_default_credentials.cc +++ b/src/core/lib/security/credentials/google_default/google_default_credentials.cc @@ -26,12 +26,15 @@ #include #include +#include "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h" +#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/gpr/env.h" #include "src/core/lib/gpr/string.h" #include "src/core/lib/http/httpcli.h" #include "src/core/lib/http/parser.h" #include "src/core/lib/iomgr/load_file.h" #include "src/core/lib/iomgr/polling_entity.h" +#include "src/core/lib/security/credentials/alts/alts_credentials.h" #include "src/core/lib/security/credentials/google_default/google_default_credentials.h" #include "src/core/lib/security/credentials/jwt/jwt_credentials.h" #include "src/core/lib/security/credentials/oauth2/oauth2_credentials.h" @@ -45,8 +48,8 @@ /* -- Default credentials. -- */ -static grpc_channel_credentials* default_credentials = nullptr; -static int compute_engine_detection_done = 0; +static grpc_channel_credentials* g_default_credentials = nullptr; +static int g_compute_engine_detection_done = 0; static gpr_mu g_state_mu; static gpr_mu* g_polling_mu; static gpr_once g_once = GPR_ONCE_INIT; @@ -60,6 +63,52 @@ typedef struct { grpc_http_response response; } compute_engine_detector; +static void google_default_credentials_destruct( + grpc_channel_credentials* creds) { + grpc_google_default_channel_credentials* c = + reinterpret_cast(creds); + grpc_channel_credentials_unref(c->alts_creds); + grpc_channel_credentials_unref(c->ssl_creds); +} + +static grpc_security_status google_default_create_security_connector( + grpc_channel_credentials* creds, grpc_call_credentials* call_creds, + const char* target, const grpc_channel_args* args, + grpc_channel_security_connector** sc, grpc_channel_args** new_args) { + grpc_google_default_channel_credentials* c = + reinterpret_cast(creds); + bool is_grpclb_load_balancer = grpc_channel_arg_get_bool( + grpc_channel_args_find(args, GRPC_ARG_ADDRESS_IS_GRPCLB_LOAD_BALANCER), + false); + bool is_backend_from_grpclb_load_balancer = grpc_channel_arg_get_bool( + grpc_channel_args_find( + args, GRPC_ARG_ADDRESS_IS_BACKEND_FROM_GRPCLB_LOAD_BALANCER), + false); + bool use_alts = + is_grpclb_load_balancer || is_backend_from_grpclb_load_balancer; + grpc_security_status status = GRPC_SECURITY_ERROR; + status = use_alts ? c->alts_creds->vtable->create_security_connector( + c->alts_creds, call_creds, target, args, sc, new_args) + : c->ssl_creds->vtable->create_security_connector( + c->ssl_creds, call_creds, target, args, sc, new_args); + /* grpclb-specific channel args are removed from the channel args set + * to ensure backends and fallback adresses will have the same set of channel + * args. By doing that, it guarantees the connections to backends will not be + * torn down and re-connected when switching in and out of fallback mode. + */ + static const char* args_to_remove[] = { + GRPC_ARG_ADDRESS_IS_GRPCLB_LOAD_BALANCER, + GRPC_ARG_ADDRESS_IS_BACKEND_FROM_GRPCLB_LOAD_BALANCER, + }; + *new_args = grpc_channel_args_copy_and_add_and_remove( + args, args_to_remove, GPR_ARRAY_SIZE(args_to_remove), nullptr, 0); + return status; +} + +static grpc_channel_credentials_vtable google_default_credentials_vtable = { + google_default_credentials_destruct, + google_default_create_security_connector, nullptr}; + static void on_compute_engine_detection_http_response(void* user_data, grpc_error* error) { compute_engine_detector* detector = @@ -234,8 +283,8 @@ grpc_channel_credentials* grpc_google_default_credentials_create(void) { gpr_mu_lock(&g_state_mu); - if (default_credentials != nullptr) { - result = grpc_channel_credentials_ref(default_credentials); + if (g_default_credentials != nullptr) { + result = grpc_channel_credentials_ref(g_default_credentials); goto end; } @@ -253,9 +302,9 @@ grpc_channel_credentials* grpc_google_default_credentials_create(void) { /* At last try to see if we're on compute engine (do the detection only once since it requires a network test). */ - if (!compute_engine_detection_done) { + if (!g_compute_engine_detection_done) { int need_compute_engine_creds = is_stack_running_on_compute_engine(); - compute_engine_detection_done = 1; + g_compute_engine_detection_done = 1; if (need_compute_engine_creds) { call_creds = grpc_google_compute_engine_credentials_create(nullptr); if (call_creds == nullptr) { @@ -269,18 +318,25 @@ grpc_channel_credentials* grpc_google_default_credentials_create(void) { end: if (result == nullptr) { if (call_creds != nullptr) { - /* Blend with default ssl credentials and add a global reference so that - it - can be cached and re-served. */ - grpc_channel_credentials* ssl_creds = - grpc_ssl_credentials_create(nullptr, nullptr, nullptr); - default_credentials = grpc_channel_credentials_ref( - grpc_composite_channel_credentials_create(ssl_creds, call_creds, - nullptr)); - GPR_ASSERT(default_credentials != nullptr); - grpc_channel_credentials_unref(ssl_creds); + /* Create google default credentials. */ + auto creds = static_cast( + gpr_zalloc(sizeof(grpc_google_default_channel_credentials))); + creds->base.vtable = &google_default_credentials_vtable; + creds->base.type = GRPC_CHANNEL_CREDENTIALS_TYPE_GOOGLE_DEFAULT; + gpr_ref_init(&creds->base.refcount, 1); + creds->ssl_creds = grpc_ssl_credentials_create(nullptr, nullptr, nullptr); + GPR_ASSERT(creds->ssl_creds != nullptr); + grpc_alts_credentials_options* options = + grpc_alts_credentials_client_options_create(); + creds->alts_creds = grpc_alts_credentials_create(options); + grpc_alts_credentials_options_destroy(options); + /* Add a global reference so that it can be cached and re-served. */ + g_default_credentials = grpc_composite_channel_credentials_create( + &creds->base, call_creds, nullptr); + GPR_ASSERT(g_default_credentials != nullptr); + grpc_channel_credentials_unref(&creds->base); grpc_call_credentials_unref(call_creds); - result = default_credentials; + result = grpc_channel_credentials_ref(g_default_credentials); } else { gpr_log(GPR_ERROR, "Could not create google default credentials."); } @@ -299,11 +355,11 @@ void grpc_flush_cached_google_default_credentials(void) { grpc_core::ExecCtx exec_ctx; gpr_once_init(&g_once, init_default_credentials); gpr_mu_lock(&g_state_mu); - if (default_credentials != nullptr) { - grpc_channel_credentials_unref(default_credentials); - default_credentials = nullptr; + if (g_default_credentials != nullptr) { + grpc_channel_credentials_unref(g_default_credentials); + g_default_credentials = nullptr; } - compute_engine_detection_done = 0; + g_compute_engine_detection_done = 0; gpr_mu_unlock(&g_state_mu); } diff --git a/src/core/lib/security/credentials/google_default/google_default_credentials.h b/src/core/lib/security/credentials/google_default/google_default_credentials.h index b163e48631..9b4063c775 100644 --- a/src/core/lib/security/credentials/google_default/google_default_credentials.h +++ b/src/core/lib/security/credentials/google_default/google_default_credentials.h @@ -39,6 +39,12 @@ "/" GRPC_GOOGLE_WELL_KNOWN_CREDENTIALS_FILE #endif +typedef struct { + grpc_channel_credentials base; + grpc_channel_credentials* alts_creds; + grpc_channel_credentials* ssl_creds; +} grpc_google_default_channel_credentials; + void grpc_flush_cached_google_default_credentials(void); #endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_GOOGLE_DEFAULT_GOOGLE_DEFAULT_CREDENTIALS_H \ diff --git a/test/core/security/credentials_test.cc b/test/core/security/credentials_test.cc index ce92e21d73..2b90939ab8 100644 --- a/test/core/security/credentials_test.cc +++ b/test/core/security/credentials_test.cc @@ -867,6 +867,7 @@ static void set_google_default_creds_env_var_with_file_contents( static void test_google_default_creds_auth_key(void) { grpc_core::ExecCtx exec_ctx; grpc_service_account_jwt_access_credentials* jwt; + grpc_google_default_channel_credentials* default_creds; grpc_composite_channel_credentials* creds; char* json_key = test_json_key_str(); grpc_flush_cached_google_default_credentials(); @@ -875,7 +876,9 @@ static void test_google_default_creds_auth_key(void) { gpr_free(json_key); creds = reinterpret_cast( grpc_google_default_credentials_create()); - GPR_ASSERT(creds != nullptr); + default_creds = reinterpret_cast( + creds->inner_creds); + GPR_ASSERT(default_creds->ssl_creds != nullptr); jwt = reinterpret_cast( creds->call_creds); GPR_ASSERT( @@ -889,13 +892,16 @@ static void test_google_default_creds_auth_key(void) { static void test_google_default_creds_refresh_token(void) { grpc_core::ExecCtx exec_ctx; grpc_google_refresh_token_credentials* refresh; + grpc_google_default_channel_credentials* default_creds; grpc_composite_channel_credentials* creds; grpc_flush_cached_google_default_credentials(); set_google_default_creds_env_var_with_file_contents( "refresh_token_google_default_creds", test_refresh_token_str); creds = reinterpret_cast( grpc_google_default_credentials_create()); - GPR_ASSERT(creds != nullptr); + default_creds = reinterpret_cast( + creds->inner_creds); + GPR_ASSERT(default_creds->ssl_creds != nullptr); refresh = reinterpret_cast( creds->call_creds); GPR_ASSERT(strcmp(refresh->refresh_token.client_id, diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index b28641156f..82b4769544 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -885,6 +885,7 @@ src/core/ext/filters/client_channel/lb_policy.h \ src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc \ src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h \ src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc \ +src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h \ src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h \ src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc \ src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 6659724fb4..abb7005327 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -9794,6 +9794,7 @@ ], "headers": [ "src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h", + "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h", "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h", "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h", "src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h", @@ -9806,6 +9807,7 @@ "src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc", "src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h", "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc", + "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h", "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.cc", "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h", "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc", @@ -9829,6 +9831,7 @@ ], "headers": [ "src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h", + "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h", "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h", "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h", "src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h", @@ -9841,6 +9844,7 @@ "src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc", "src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h", "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc", + "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h", "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h", "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc", "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc", @@ -10026,6 +10030,7 @@ ], "headers": [ "include/grpc/grpc_security.h", + "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h", "src/core/lib/security/context/security_context.h", "src/core/lib/security/credentials/alts/alts_credentials.h", "src/core/lib/security/credentials/composite/composite_credentials.h", @@ -10053,6 +10058,7 @@ "name": "grpc_secure", "src": [ "include/grpc/grpc_security.h", + "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h", "src/core/lib/http/httpcli_security_connector.cc", "src/core/lib/security/context/security_context.cc", "src/core/lib/security/context/security_context.h", -- cgit v1.2.3 From 274840e4d304b094d1d4711d4b9572866221a4ed Mon Sep 17 00:00:00 2001 From: jiangtaoli2016 Date: Wed, 9 May 2018 14:42:48 -0700 Subject: Migrate SSL_transport_security TSI to new TSI handshaker API --- BUILD | 2 - CMakeLists.txt | 2 - Makefile | 3 - build.yaml | 2 - config.m4 | 1 - config.w32 | 1 - gRPC-C++.podspec | 1 - gRPC-Core.podspec | 3 - grpc.gemspec | 2 - grpc.gyp | 1 - package.xml | 2 - src/core/lib/http/httpcli_security_connector.cc | 4 +- .../security_connector/security_connector.cc | 7 +- src/core/tsi/ssl_transport_security.cc | 314 ++++++++++++++------- src/core/tsi/transport_security_adapter.cc | 242 ---------------- src/core/tsi/transport_security_adapter.h | 41 --- src/core/tsi/transport_security_interface.h | 2 + src/python/grpcio/grpc_core_dependencies.py | 1 - test/core/tsi/ssl_transport_security_test.cc | 13 +- tools/doxygen/Doxyfile.core.internal | 2 - tools/run_tests/generated/sources_and_headers.json | 3 - 21 files changed, 225 insertions(+), 424 deletions(-) delete mode 100644 src/core/tsi/transport_security_adapter.cc delete mode 100644 src/core/tsi/transport_security_adapter.h (limited to 'gRPC-C++.podspec') diff --git a/BUILD b/BUILD index 80b40338c3..c35a7d65e1 100644 --- a/BUILD +++ b/BUILD @@ -1625,11 +1625,9 @@ grpc_cc_library( name = "tsi_interface", srcs = [ "src/core/tsi/transport_security.cc", - "src/core/tsi/transport_security_adapter.cc", ], hdrs = [ "src/core/tsi/transport_security.h", - "src/core/tsi/transport_security_adapter.h", "src/core/tsi/transport_security_interface.h", ], language = "c++", diff --git a/CMakeLists.txt b/CMakeLists.txt index d99a71e078..190e2dd465 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1150,7 +1150,6 @@ add_library(grpc third_party/nanopb/pb_decode.c third_party/nanopb/pb_encode.c src/core/tsi/transport_security.cc - src/core/tsi/transport_security_adapter.cc src/core/ext/transport/chttp2/client/insecure/channel_create.cc src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc src/core/ext/transport/chttp2/client/authority.cc @@ -1569,7 +1568,6 @@ add_library(grpc_cronet third_party/nanopb/pb_decode.c third_party/nanopb/pb_encode.c src/core/tsi/transport_security.cc - src/core/tsi/transport_security_adapter.cc src/core/ext/transport/chttp2/client/insecure/channel_create.cc src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc src/core/ext/transport/chttp2/client/authority.cc diff --git a/Makefile b/Makefile index 3225478720..ba765f0af6 100644 --- a/Makefile +++ b/Makefile @@ -3540,7 +3540,6 @@ LIBGRPC_SRC = \ third_party/nanopb/pb_decode.c \ third_party/nanopb/pb_encode.c \ src/core/tsi/transport_security.cc \ - src/core/tsi/transport_security_adapter.cc \ src/core/ext/transport/chttp2/client/insecure/channel_create.cc \ src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \ src/core/ext/transport/chttp2/client/authority.cc \ @@ -3959,7 +3958,6 @@ LIBGRPC_CRONET_SRC = \ third_party/nanopb/pb_decode.c \ third_party/nanopb/pb_encode.c \ src/core/tsi/transport_security.cc \ - src/core/tsi/transport_security_adapter.cc \ src/core/ext/transport/chttp2/client/insecure/channel_create.cc \ src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \ src/core/ext/transport/chttp2/client/authority.cc \ @@ -24107,7 +24105,6 @@ src/core/tsi/ssl/session_cache/ssl_session_cache.cc: $(OPENSSL_DEP) src/core/tsi/ssl/session_cache/ssl_session_openssl.cc: $(OPENSSL_DEP) src/core/tsi/ssl_transport_security.cc: $(OPENSSL_DEP) src/core/tsi/transport_security.cc: $(OPENSSL_DEP) -src/core/tsi/transport_security_adapter.cc: $(OPENSSL_DEP) src/core/tsi/transport_security_grpc.cc: $(OPENSSL_DEP) src/cpp/client/cronet_credentials.cc: $(OPENSSL_DEP) src/cpp/client/secure_credentials.cc: $(OPENSSL_DEP) diff --git a/build.yaml b/build.yaml index 930236eb7d..1bc2adbb8c 100644 --- a/build.yaml +++ b/build.yaml @@ -1080,11 +1080,9 @@ filegroups: - name: tsi_interface headers: - src/core/tsi/transport_security.h - - src/core/tsi/transport_security_adapter.h - src/core/tsi/transport_security_interface.h src: - src/core/tsi/transport_security.cc - - src/core/tsi/transport_security_adapter.cc deps: - gpr secure: true diff --git a/config.m4 b/config.m4 index df06259606..ee2aca4fa5 100644 --- a/config.m4 +++ b/config.m4 @@ -321,7 +321,6 @@ if test "$PHP_GRPC" != "no"; then third_party/nanopb/pb_decode.c \ third_party/nanopb/pb_encode.c \ src/core/tsi/transport_security.cc \ - src/core/tsi/transport_security_adapter.cc \ src/core/ext/transport/chttp2/client/insecure/channel_create.cc \ src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc \ src/core/ext/transport/chttp2/client/authority.cc \ diff --git a/config.w32 b/config.w32 index f60a5b746d..abca8e22f2 100644 --- a/config.w32 +++ b/config.w32 @@ -297,7 +297,6 @@ if (PHP_GRPC != "no") { "third_party\\nanopb\\pb_decode.c " + "third_party\\nanopb\\pb_encode.c " + "src\\core\\tsi\\transport_security.cc " + - "src\\core\\tsi\\transport_security_adapter.cc " + "src\\core\\ext\\transport\\chttp2\\client\\insecure\\channel_create.cc " + "src\\core\\ext\\transport\\chttp2\\client\\insecure\\channel_create_posix.cc " + "src\\core\\ext\\transport\\chttp2\\client\\authority.cc " + diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index fe082ef3af..29b79e0b01 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -308,7 +308,6 @@ Pod::Spec.new do |s| 'src/core/tsi/alts/handshaker/handshaker.pb.h', 'src/core/tsi/alts/handshaker/transport_security_common.pb.h', 'src/core/tsi/transport_security.h', - 'src/core/tsi/transport_security_adapter.h', 'src/core/tsi/transport_security_interface.h', 'src/core/ext/transport/chttp2/client/authority.h', 'src/core/ext/transport/chttp2/client/chttp2_connector.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index f6374ebfcd..ce6ff76806 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -318,7 +318,6 @@ Pod::Spec.new do |s| 'src/core/tsi/alts/handshaker/handshaker.pb.h', 'src/core/tsi/alts/handshaker/transport_security_common.pb.h', 'src/core/tsi/transport_security.h', - 'src/core/tsi/transport_security_adapter.h', 'src/core/tsi/transport_security_interface.h', 'src/core/ext/transport/chttp2/client/authority.h', 'src/core/ext/transport/chttp2/client/chttp2_connector.h', @@ -737,7 +736,6 @@ Pod::Spec.new do |s| 'src/core/tsi/alts/handshaker/handshaker.pb.c', 'src/core/tsi/alts/handshaker/transport_security_common.pb.c', 'src/core/tsi/transport_security.cc', - 'src/core/tsi/transport_security_adapter.cc', 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', 'src/core/ext/transport/chttp2/client/authority.cc', @@ -898,7 +896,6 @@ Pod::Spec.new do |s| 'src/core/tsi/alts/handshaker/handshaker.pb.h', 'src/core/tsi/alts/handshaker/transport_security_common.pb.h', 'src/core/tsi/transport_security.h', - 'src/core/tsi/transport_security_adapter.h', 'src/core/tsi/transport_security_interface.h', 'src/core/ext/transport/chttp2/client/authority.h', 'src/core/ext/transport/chttp2/client/chttp2_connector.h', diff --git a/grpc.gemspec b/grpc.gemspec index bb40a3ba02..2a66801e34 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -253,7 +253,6 @@ Gem::Specification.new do |s| s.files += %w( third_party/nanopb/pb_decode.h ) s.files += %w( third_party/nanopb/pb_encode.h ) s.files += %w( src/core/tsi/transport_security.h ) - s.files += %w( src/core/tsi/transport_security_adapter.h ) s.files += %w( src/core/tsi/transport_security_interface.h ) s.files += %w( src/core/ext/transport/chttp2/client/authority.h ) s.files += %w( src/core/ext/transport/chttp2/client/chttp2_connector.h ) @@ -675,7 +674,6 @@ Gem::Specification.new do |s| s.files += %w( third_party/nanopb/pb_decode.c ) s.files += %w( third_party/nanopb/pb_encode.c ) s.files += %w( src/core/tsi/transport_security.cc ) - s.files += %w( src/core/tsi/transport_security_adapter.cc ) s.files += %w( src/core/ext/transport/chttp2/client/insecure/channel_create.cc ) s.files += %w( src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc ) s.files += %w( src/core/ext/transport/chttp2/client/authority.cc ) diff --git a/grpc.gyp b/grpc.gyp index fff7c5380a..5726719521 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -481,7 +481,6 @@ 'third_party/nanopb/pb_decode.c', 'third_party/nanopb/pb_encode.c', 'src/core/tsi/transport_security.cc', - 'src/core/tsi/transport_security_adapter.cc', 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', 'src/core/ext/transport/chttp2/client/authority.cc', diff --git a/package.xml b/package.xml index 75a69931a4..ac9b520fb7 100644 --- a/package.xml +++ b/package.xml @@ -260,7 +260,6 @@ - @@ -682,7 +681,6 @@ - diff --git a/src/core/lib/http/httpcli_security_connector.cc b/src/core/lib/http/httpcli_security_connector.cc index 0b53d63e77..50078c37a1 100644 --- a/src/core/lib/http/httpcli_security_connector.cc +++ b/src/core/lib/http/httpcli_security_connector.cc @@ -32,7 +32,6 @@ #include "src/core/lib/security/transport/security_handshaker.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/tsi/ssl_transport_security.h" -#include "src/core/tsi/transport_security_adapter.h" typedef struct { grpc_channel_security_connector base; @@ -65,8 +64,7 @@ static void httpcli_ssl_add_handshakers(grpc_channel_security_connector* sc, } } grpc_handshake_manager_add( - handshake_mgr, grpc_security_handshaker_create( - tsi_create_adapter_handshaker(handshaker), &sc->base)); + handshake_mgr, grpc_security_handshaker_create(handshaker, &sc->base)); } static void httpcli_ssl_check_peer(grpc_security_connector* sc, tsi_peer peer, diff --git a/src/core/lib/security/security_connector/security_connector.cc b/src/core/lib/security/security_connector/security_connector.cc index 6eae30a6e5..a30696703f 100644 --- a/src/core/lib/security/security_connector/security_connector.cc +++ b/src/core/lib/security/security_connector/security_connector.cc @@ -44,7 +44,6 @@ #include "src/core/lib/security/transport/target_authority_table.h" #include "src/core/tsi/fake_transport_security.h" #include "src/core/tsi/ssl_transport_security.h" -#include "src/core/tsi/transport_security_adapter.h" grpc_core::DebugOnlyTraceFlag grpc_trace_security_connector_refcount( false, "security_connector_refcount"); @@ -673,8 +672,7 @@ static void ssl_channel_add_handshakers(grpc_channel_security_connector* sc, } // Create handshakers. grpc_handshake_manager_add( - handshake_mgr, grpc_security_handshaker_create( - tsi_create_adapter_handshaker(tsi_hs), &sc->base)); + handshake_mgr, grpc_security_handshaker_create(tsi_hs, &sc->base)); } static const char** fill_alpn_protocol_strings(size_t* num_alpn_protocols) { @@ -782,8 +780,7 @@ static void ssl_server_add_handshakers(grpc_server_security_connector* sc, } // Create handshakers. grpc_handshake_manager_add( - handshake_mgr, grpc_security_handshaker_create( - tsi_create_adapter_handshaker(tsi_hs), &sc->base)); + handshake_mgr, grpc_security_handshaker_create(tsi_hs, &sc->base)); } int grpc_ssl_host_matches_name(const tsi_peer* peer, const char* peer_name) { diff --git a/src/core/tsi/ssl_transport_security.cc b/src/core/tsi/ssl_transport_security.cc index 8d0729ba05..8065a8b185 100644 --- a/src/core/tsi/ssl_transport_security.cc +++ b/src/core/tsi/ssl_transport_security.cc @@ -57,6 +57,7 @@ extern "C" { #define TSI_SSL_MAX_PROTECTED_FRAME_SIZE_UPPER_BOUND 16384 #define TSI_SSL_MAX_PROTECTED_FRAME_SIZE_LOWER_BOUND 1024 +#define TSI_SSL_HANDSHAKER_OUTGOING_BUFFER_INITIAL_SIZE 1024 /* Putting a macro like this and littering the source file with #if is really bad practice. @@ -105,9 +106,19 @@ typedef struct { SSL* ssl; BIO* network_io; tsi_result result; + unsigned char* outgoing_bytes_buffer; + size_t outgoing_bytes_buffer_size; tsi_ssl_handshaker_factory* factory_ref; } tsi_ssl_handshaker; +typedef struct { + tsi_handshaker_result base; + SSL* ssl; + BIO* network_io; + unsigned char* unused_bytes; + size_t unused_bytes_size; +} tsi_ssl_handshaker_result; + typedef struct { tsi_frame_protector base; SSL* ssl; @@ -994,94 +1005,15 @@ static void tsi_ssl_handshaker_factory_init( gpr_ref_init(&factory->refcount, 1); } -/* --- tsi_handshaker methods implementation. ---*/ - -static tsi_result ssl_handshaker_get_bytes_to_send_to_peer(tsi_handshaker* self, - unsigned char* bytes, - size_t* bytes_size) { - tsi_ssl_handshaker* impl = reinterpret_cast(self); - int bytes_read_from_ssl = 0; - if (bytes == nullptr || bytes_size == nullptr || *bytes_size == 0 || - *bytes_size > INT_MAX) { - return TSI_INVALID_ARGUMENT; - } - GPR_ASSERT(*bytes_size <= INT_MAX); - bytes_read_from_ssl = - BIO_read(impl->network_io, bytes, static_cast(*bytes_size)); - if (bytes_read_from_ssl < 0) { - *bytes_size = 0; - if (!BIO_should_retry(impl->network_io)) { - impl->result = TSI_INTERNAL_ERROR; - return impl->result; - } else { - return TSI_OK; - } - } - *bytes_size = static_cast(bytes_read_from_ssl); - return BIO_pending(impl->network_io) == 0 ? TSI_OK : TSI_INCOMPLETE_DATA; -} - -static tsi_result ssl_handshaker_get_result(tsi_handshaker* self) { - tsi_ssl_handshaker* impl = reinterpret_cast(self); - if ((impl->result == TSI_HANDSHAKE_IN_PROGRESS) && - SSL_is_init_finished(impl->ssl)) { - impl->result = TSI_OK; - } - return impl->result; -} - -static tsi_result ssl_handshaker_process_bytes_from_peer( - tsi_handshaker* self, const unsigned char* bytes, size_t* bytes_size) { - tsi_ssl_handshaker* impl = reinterpret_cast(self); - int bytes_written_into_ssl_size = 0; - if (bytes == nullptr || bytes_size == nullptr || *bytes_size > INT_MAX) { - return TSI_INVALID_ARGUMENT; - } - GPR_ASSERT(*bytes_size <= INT_MAX); - bytes_written_into_ssl_size = - BIO_write(impl->network_io, bytes, static_cast(*bytes_size)); - if (bytes_written_into_ssl_size < 0) { - gpr_log(GPR_ERROR, "Could not write to memory BIO."); - impl->result = TSI_INTERNAL_ERROR; - return impl->result; - } - *bytes_size = static_cast(bytes_written_into_ssl_size); - - if (!tsi_handshaker_is_in_progress(self)) { - impl->result = TSI_OK; - return impl->result; - } else { - /* Get ready to get some bytes from SSL. */ - int ssl_result = SSL_do_handshake(impl->ssl); - ssl_result = SSL_get_error(impl->ssl, ssl_result); - switch (ssl_result) { - case SSL_ERROR_WANT_READ: - if (BIO_pending(impl->network_io) == 0) { - /* We need more data. */ - return TSI_INCOMPLETE_DATA; - } else { - return TSI_OK; - } - case SSL_ERROR_NONE: - return TSI_OK; - default: { - char err_str[256]; - ERR_error_string_n(ERR_get_error(), err_str, sizeof(err_str)); - gpr_log(GPR_ERROR, "Handshake failed with fatal error %s: %s.", - ssl_error_string(ssl_result), err_str); - impl->result = TSI_PROTOCOL_FAILURE; - return impl->result; - } - } - } -} +/* --- tsi_handshaker_result methods implementation. ---*/ -static tsi_result ssl_handshaker_extract_peer(tsi_handshaker* self, - tsi_peer* peer) { +static tsi_result ssl_handshaker_result_extract_peer( + const tsi_handshaker_result* self, tsi_peer* peer) { tsi_result result = TSI_OK; const unsigned char* alpn_selected = nullptr; unsigned int alpn_selected_len; - tsi_ssl_handshaker* impl = reinterpret_cast(self); + const tsi_ssl_handshaker_result* impl = + reinterpret_cast(self); X509* peer_cert = SSL_get_peer_certificate(impl->ssl); if (peer_cert != nullptr) { result = peer_from_x509(peer_cert, 1, peer); @@ -1127,12 +1059,14 @@ static tsi_result ssl_handshaker_extract_peer(tsi_handshaker* self, return result; } -static tsi_result ssl_handshaker_create_frame_protector( - tsi_handshaker* self, size_t* max_output_protected_frame_size, +static tsi_result ssl_handshaker_result_create_frame_protector( + const tsi_handshaker_result* self, size_t* max_output_protected_frame_size, tsi_frame_protector** protector) { size_t actual_max_output_protected_frame_size = TSI_SSL_MAX_PROTECTED_FRAME_SIZE_UPPER_BOUND; - tsi_ssl_handshaker* impl = reinterpret_cast(self); + tsi_ssl_handshaker_result* impl = + reinterpret_cast( + const_cast(self)); tsi_ssl_frame_protector* protector_impl = static_cast( gpr_zalloc(sizeof(*protector_impl))); @@ -1160,35 +1094,217 @@ static tsi_result ssl_handshaker_create_frame_protector( return TSI_INTERNAL_ERROR; } - /* Transfer ownership of ssl and network_io to the frame protector. It is OK - * as the caller cannot call anything else but destroy on the handshaker - * after this call. */ + /* Transfer ownership of ssl and network_io to the frame protector. */ protector_impl->ssl = impl->ssl; impl->ssl = nullptr; protector_impl->network_io = impl->network_io; impl->network_io = nullptr; - protector_impl->base.vtable = &frame_protector_vtable; *protector = &protector_impl->base; return TSI_OK; } +static tsi_result ssl_handshaker_result_get_unused_bytes( + const tsi_handshaker_result* self, const unsigned char** bytes, + size_t* bytes_size) { + const tsi_ssl_handshaker_result* impl = + reinterpret_cast(self); + *bytes_size = impl->unused_bytes_size; + *bytes = impl->unused_bytes; + return TSI_OK; +} + +static void ssl_handshaker_result_destroy(tsi_handshaker_result* self) { + tsi_ssl_handshaker_result* impl = + reinterpret_cast(self); + SSL_free(impl->ssl); + BIO_free(impl->network_io); + gpr_free(impl->unused_bytes); + gpr_free(impl); +} + +static const tsi_handshaker_result_vtable handshaker_result_vtable = { + ssl_handshaker_result_extract_peer, + nullptr, /* create_zero_copy_grpc_protector */ + ssl_handshaker_result_create_frame_protector, + ssl_handshaker_result_get_unused_bytes, + ssl_handshaker_result_destroy, +}; + +static tsi_result ssl_handshaker_result_create( + tsi_ssl_handshaker* handshaker, const unsigned char* unused_bytes, + size_t unused_bytes_size, tsi_handshaker_result** handshaker_result) { + if (handshaker == nullptr || handshaker_result == nullptr || + (unused_bytes_size > 0 && unused_bytes == nullptr)) { + return TSI_INVALID_ARGUMENT; + } + tsi_ssl_handshaker_result* result = + static_cast(gpr_zalloc(sizeof(*result))); + result->base.vtable = &handshaker_result_vtable; + /* Transfer ownership of ssl and network_io to the handshaker result. */ + result->ssl = handshaker->ssl; + handshaker->ssl = nullptr; + result->network_io = handshaker->network_io; + handshaker->network_io = nullptr; + if (unused_bytes_size > 0) { + result->unused_bytes = + static_cast(gpr_malloc(unused_bytes_size)); + memcpy(result->unused_bytes, unused_bytes, unused_bytes_size); + } + result->unused_bytes_size = unused_bytes_size; + *handshaker_result = &result->base; + return TSI_OK; +} + +/* --- tsi_handshaker methods implementation. ---*/ + +static tsi_result ssl_handshaker_get_bytes_to_send_to_peer( + tsi_ssl_handshaker* impl, unsigned char* bytes, size_t* bytes_size) { + int bytes_read_from_ssl = 0; + if (bytes == nullptr || bytes_size == nullptr || *bytes_size == 0 || + *bytes_size > INT_MAX) { + return TSI_INVALID_ARGUMENT; + } + GPR_ASSERT(*bytes_size <= INT_MAX); + bytes_read_from_ssl = + BIO_read(impl->network_io, bytes, static_cast(*bytes_size)); + if (bytes_read_from_ssl < 0) { + *bytes_size = 0; + if (!BIO_should_retry(impl->network_io)) { + impl->result = TSI_INTERNAL_ERROR; + return impl->result; + } else { + return TSI_OK; + } + } + *bytes_size = static_cast(bytes_read_from_ssl); + return BIO_pending(impl->network_io) == 0 ? TSI_OK : TSI_INCOMPLETE_DATA; +} + +static tsi_result ssl_handshaker_get_result(tsi_ssl_handshaker* impl) { + if ((impl->result == TSI_HANDSHAKE_IN_PROGRESS) && + SSL_is_init_finished(impl->ssl)) { + impl->result = TSI_OK; + } + return impl->result; +} + +static tsi_result ssl_handshaker_process_bytes_from_peer( + tsi_ssl_handshaker* impl, const unsigned char* bytes, size_t* bytes_size) { + int bytes_written_into_ssl_size = 0; + if (bytes == nullptr || bytes_size == nullptr || *bytes_size > INT_MAX) { + return TSI_INVALID_ARGUMENT; + } + GPR_ASSERT(*bytes_size <= INT_MAX); + bytes_written_into_ssl_size = + BIO_write(impl->network_io, bytes, static_cast(*bytes_size)); + if (bytes_written_into_ssl_size < 0) { + gpr_log(GPR_ERROR, "Could not write to memory BIO."); + impl->result = TSI_INTERNAL_ERROR; + return impl->result; + } + *bytes_size = static_cast(bytes_written_into_ssl_size); + + if (ssl_handshaker_get_result(impl) != TSI_HANDSHAKE_IN_PROGRESS) { + impl->result = TSI_OK; + return impl->result; + } else { + /* Get ready to get some bytes from SSL. */ + int ssl_result = SSL_do_handshake(impl->ssl); + ssl_result = SSL_get_error(impl->ssl, ssl_result); + switch (ssl_result) { + case SSL_ERROR_WANT_READ: + if (BIO_pending(impl->network_io) == 0) { + /* We need more data. */ + return TSI_INCOMPLETE_DATA; + } else { + return TSI_OK; + } + case SSL_ERROR_NONE: + return TSI_OK; + default: { + char err_str[256]; + ERR_error_string_n(ERR_get_error(), err_str, sizeof(err_str)); + gpr_log(GPR_ERROR, "Handshake failed with fatal error %s: %s.", + ssl_error_string(ssl_result), err_str); + impl->result = TSI_PROTOCOL_FAILURE; + return impl->result; + } + } + } +} + static void ssl_handshaker_destroy(tsi_handshaker* self) { tsi_ssl_handshaker* impl = reinterpret_cast(self); SSL_free(impl->ssl); BIO_free(impl->network_io); + gpr_free(impl->outgoing_bytes_buffer); tsi_ssl_handshaker_factory_unref(impl->factory_ref); gpr_free(impl); } +static tsi_result ssl_handshaker_next( + tsi_handshaker* self, const unsigned char* received_bytes, + size_t received_bytes_size, const unsigned char** bytes_to_send, + size_t* bytes_to_send_size, tsi_handshaker_result** handshaker_result, + tsi_handshaker_on_next_done_cb cb, void* user_data) { + /* Input sanity check. */ + if ((received_bytes_size > 0 && received_bytes == nullptr) || + bytes_to_send == nullptr || bytes_to_send_size == nullptr || + handshaker_result == nullptr) { + return TSI_INVALID_ARGUMENT; + } + /* If there are received bytes, process them first. */ + tsi_ssl_handshaker* impl = reinterpret_cast(self); + tsi_result status = TSI_OK; + size_t bytes_consumed = received_bytes_size; + if (received_bytes_size > 0) { + status = ssl_handshaker_process_bytes_from_peer(impl, received_bytes, + &bytes_consumed); + if (status != TSI_OK) return status; + } + /* Get bytes to send to the peer, if available. */ + size_t offset = 0; + do { + size_t to_send_size = impl->outgoing_bytes_buffer_size - offset; + status = ssl_handshaker_get_bytes_to_send_to_peer( + impl, impl->outgoing_bytes_buffer + offset, &to_send_size); + offset += to_send_size; + if (status == TSI_INCOMPLETE_DATA) { + impl->outgoing_bytes_buffer_size *= 2; + impl->outgoing_bytes_buffer = static_cast(gpr_realloc( + impl->outgoing_bytes_buffer, impl->outgoing_bytes_buffer_size)); + } + } while (status == TSI_INCOMPLETE_DATA); + if (status != TSI_OK) return status; + *bytes_to_send = impl->outgoing_bytes_buffer; + *bytes_to_send_size = offset; + /* If handshake completes, create tsi_handshaker_result. */ + if (ssl_handshaker_get_result(impl) == TSI_HANDSHAKE_IN_PROGRESS) { + *handshaker_result = nullptr; + } else { + size_t unused_bytes_size = received_bytes_size - bytes_consumed; + const unsigned char* unused_bytes = + unused_bytes_size == 0 ? nullptr : received_bytes + bytes_consumed; + status = ssl_handshaker_result_create(impl, unused_bytes, unused_bytes_size, + handshaker_result); + if (status == TSI_OK) { + /* Indicates that the handshake has completed and that a handshaker_result + * has been created. */ + self->handshaker_result_created = true; + } + } + return status; +} + static const tsi_handshaker_vtable handshaker_vtable = { - ssl_handshaker_get_bytes_to_send_to_peer, - ssl_handshaker_process_bytes_from_peer, - ssl_handshaker_get_result, - ssl_handshaker_extract_peer, - ssl_handshaker_create_frame_protector, + nullptr, /* get_bytes_to_send_to_peer -- deprecated */ + nullptr, /* process_bytes_from_peer -- deprecated */ + nullptr, /* get_result -- deprecated */ + nullptr, /* extract_peer -- deprecated */ + nullptr, /* create_frame_protector -- deprecated */ ssl_handshaker_destroy, - nullptr, + ssl_handshaker_next, nullptr, /* shutdown */ }; @@ -1267,6 +1383,10 @@ static tsi_result create_tsi_ssl_handshaker(SSL_CTX* ctx, int is_client, impl->ssl = ssl; impl->network_io = network_io; impl->result = TSI_HANDSHAKE_IN_PROGRESS; + impl->outgoing_bytes_buffer_size = + TSI_SSL_HANDSHAKER_OUTGOING_BUFFER_INITIAL_SIZE; + impl->outgoing_bytes_buffer = + static_cast(gpr_zalloc(impl->outgoing_bytes_buffer_size)); impl->base.vtable = &handshaker_vtable; impl->factory_ref = tsi_ssl_handshaker_factory_ref(factory); diff --git a/src/core/tsi/transport_security_adapter.cc b/src/core/tsi/transport_security_adapter.cc deleted file mode 100644 index 642188e619..0000000000 --- a/src/core/tsi/transport_security_adapter.cc +++ /dev/null @@ -1,242 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include - -#include "src/core/tsi/transport_security_adapter.h" - -#include - -#include -#include -#include "src/core/tsi/transport_security.h" - -#define TSI_ADAPTER_INITIAL_BUFFER_SIZE 256 - -/* --- tsi_adapter_handshaker_result implementation ---*/ - -typedef struct { - tsi_handshaker_result base; - tsi_handshaker* wrapped; - unsigned char* unused_bytes; - size_t unused_bytes_size; -} tsi_adapter_handshaker_result; - -static tsi_result adapter_result_extract_peer(const tsi_handshaker_result* self, - tsi_peer* peer) { - tsi_adapter_handshaker_result* impl = (tsi_adapter_handshaker_result*)self; - return tsi_handshaker_extract_peer(impl->wrapped, peer); -} - -static tsi_result adapter_result_create_frame_protector( - const tsi_handshaker_result* self, size_t* max_output_protected_frame_size, - tsi_frame_protector** protector) { - tsi_adapter_handshaker_result* impl = (tsi_adapter_handshaker_result*)self; - return tsi_handshaker_create_frame_protector( - impl->wrapped, max_output_protected_frame_size, protector); -} - -static tsi_result adapter_result_get_unused_bytes( - const tsi_handshaker_result* self, const unsigned char** bytes, - size_t* byte_size) { - tsi_adapter_handshaker_result* impl = (tsi_adapter_handshaker_result*)self; - *bytes = impl->unused_bytes; - *byte_size = impl->unused_bytes_size; - return TSI_OK; -} - -static void adapter_result_destroy(tsi_handshaker_result* self) { - tsi_adapter_handshaker_result* impl = - reinterpret_cast(self); - tsi_handshaker_destroy(impl->wrapped); - gpr_free(impl->unused_bytes); - gpr_free(self); -} - -static const tsi_handshaker_result_vtable result_vtable = { - adapter_result_extract_peer, - nullptr, /* create_zero_copy_grpc_protector */ - adapter_result_create_frame_protector, - adapter_result_get_unused_bytes, - adapter_result_destroy, -}; - -/* Ownership of wrapped tsi_handshaker is transferred to the result object. */ -static tsi_result tsi_adapter_create_handshaker_result( - tsi_handshaker* wrapped, const unsigned char* unused_bytes, - size_t unused_bytes_size, tsi_handshaker_result** handshaker_result) { - if (wrapped == nullptr || - (unused_bytes_size > 0 && unused_bytes == nullptr)) { - return TSI_INVALID_ARGUMENT; - } - tsi_adapter_handshaker_result* impl = - static_cast(gpr_zalloc(sizeof(*impl))); - impl->base.vtable = &result_vtable; - impl->wrapped = wrapped; - impl->unused_bytes_size = unused_bytes_size; - if (unused_bytes_size > 0) { - impl->unused_bytes = - static_cast(gpr_malloc(unused_bytes_size)); - memcpy(impl->unused_bytes, unused_bytes, unused_bytes_size); - } else { - impl->unused_bytes = nullptr; - } - *handshaker_result = &impl->base; - return TSI_OK; -} - -/* --- tsi_adapter_handshaker implementation ---*/ - -typedef struct { - tsi_handshaker base; - tsi_handshaker* wrapped; - unsigned char* adapter_buffer; - size_t adapter_buffer_size; -} tsi_adapter_handshaker; - -static tsi_result adapter_get_bytes_to_send_to_peer(tsi_handshaker* self, - unsigned char* bytes, - size_t* bytes_size) { - return tsi_handshaker_get_bytes_to_send_to_peer( - tsi_adapter_handshaker_get_wrapped(self), bytes, bytes_size); -} - -static tsi_result adapter_process_bytes_from_peer(tsi_handshaker* self, - const unsigned char* bytes, - size_t* bytes_size) { - return tsi_handshaker_process_bytes_from_peer( - tsi_adapter_handshaker_get_wrapped(self), bytes, bytes_size); -} - -static tsi_result adapter_get_result(tsi_handshaker* self) { - return tsi_handshaker_get_result(tsi_adapter_handshaker_get_wrapped(self)); -} - -static tsi_result adapter_extract_peer(tsi_handshaker* self, tsi_peer* peer) { - return tsi_handshaker_extract_peer(tsi_adapter_handshaker_get_wrapped(self), - peer); -} - -static tsi_result adapter_create_frame_protector( - tsi_handshaker* self, size_t* max_protected_frame_size, - tsi_frame_protector** protector) { - return tsi_handshaker_create_frame_protector( - tsi_adapter_handshaker_get_wrapped(self), max_protected_frame_size, - protector); -} - -static void adapter_destroy(tsi_handshaker* self) { - tsi_adapter_handshaker* impl = - reinterpret_cast(self); - tsi_handshaker_destroy(impl->wrapped); - gpr_free(impl->adapter_buffer); - gpr_free(self); -} - -static void adapter_shutdown(tsi_handshaker* self) { - tsi_adapter_handshaker* impl = - reinterpret_cast(self); - tsi_handshaker_shutdown(impl->wrapped); -} - -static tsi_result adapter_next( - tsi_handshaker* self, const unsigned char* received_bytes, - size_t received_bytes_size, const unsigned char** bytes_to_send, - size_t* bytes_to_send_size, tsi_handshaker_result** handshaker_result, - tsi_handshaker_on_next_done_cb cb, void* user_data) { - /* Input sanity check. */ - if ((received_bytes_size > 0 && received_bytes == nullptr) || - bytes_to_send == nullptr || bytes_to_send_size == nullptr || - handshaker_result == nullptr) { - return TSI_INVALID_ARGUMENT; - } - - /* If there are received bytes, process them first. */ - tsi_adapter_handshaker* impl = - reinterpret_cast(self); - tsi_result status = TSI_OK; - size_t bytes_consumed = received_bytes_size; - if (received_bytes_size > 0) { - status = tsi_handshaker_process_bytes_from_peer( - impl->wrapped, received_bytes, &bytes_consumed); - if (status != TSI_OK) return status; - } - - /* Get bytes to send to the peer, if available. */ - size_t offset = 0; - do { - size_t to_send_size = impl->adapter_buffer_size - offset; - status = tsi_handshaker_get_bytes_to_send_to_peer( - impl->wrapped, impl->adapter_buffer + offset, &to_send_size); - offset += to_send_size; - if (status == TSI_INCOMPLETE_DATA) { - impl->adapter_buffer_size *= 2; - impl->adapter_buffer = static_cast( - gpr_realloc(impl->adapter_buffer, impl->adapter_buffer_size)); - } - } while (status == TSI_INCOMPLETE_DATA); - if (status != TSI_OK) return status; - *bytes_to_send = impl->adapter_buffer; - *bytes_to_send_size = offset; - - /* If handshake completes, create tsi_handshaker_result. */ - if (tsi_handshaker_is_in_progress(impl->wrapped)) { - *handshaker_result = nullptr; - } else { - size_t unused_bytes_size = received_bytes_size - bytes_consumed; - const unsigned char* unused_bytes = - unused_bytes_size == 0 ? nullptr : received_bytes + bytes_consumed; - status = tsi_adapter_create_handshaker_result( - impl->wrapped, unused_bytes, unused_bytes_size, handshaker_result); - if (status == TSI_OK) { - impl->base.handshaker_result_created = true; - impl->wrapped = nullptr; - } - } - return status; -} - -static const tsi_handshaker_vtable handshaker_vtable = { - adapter_get_bytes_to_send_to_peer, - adapter_process_bytes_from_peer, - adapter_get_result, - adapter_extract_peer, - adapter_create_frame_protector, - adapter_destroy, - adapter_next, - adapter_shutdown, -}; - -tsi_handshaker* tsi_create_adapter_handshaker(tsi_handshaker* wrapped) { - GPR_ASSERT(wrapped != nullptr); - tsi_adapter_handshaker* impl = - static_cast(gpr_zalloc(sizeof(*impl))); - impl->base.vtable = &handshaker_vtable; - impl->wrapped = wrapped; - impl->adapter_buffer_size = TSI_ADAPTER_INITIAL_BUFFER_SIZE; - impl->adapter_buffer = - static_cast(gpr_malloc(impl->adapter_buffer_size)); - return &impl->base; -} - -tsi_handshaker* tsi_adapter_handshaker_get_wrapped(tsi_handshaker* adapter) { - if (adapter == nullptr) return nullptr; - tsi_adapter_handshaker* impl = - reinterpret_cast(adapter); - return impl->wrapped; -} diff --git a/src/core/tsi/transport_security_adapter.h b/src/core/tsi/transport_security_adapter.h deleted file mode 100644 index f83ecc53e5..0000000000 --- a/src/core/tsi/transport_security_adapter.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef GRPC_CORE_TSI_TRANSPORT_SECURITY_ADAPTER_H -#define GRPC_CORE_TSI_TRANSPORT_SECURITY_ADAPTER_H - -#include - -#include "src/core/tsi/transport_security_interface.h" - -/* Create a tsi handshaker that takes an implementation of old interface and - converts into an implementation of new interface. In the old interface, - there are get_bytes_to_send_to_peer, process_bytes_from_peer, get_result, - extract_peer, and create_frame_protector. In the new interface, only next - method is needed. See transport_security_interface.h for details. Note that - this tsi adapter handshaker is temporary. It will be removed once TSI has - been fully migrated to the new interface. - Ownership of input tsi_handshaker is transferred to this new adapter. */ -tsi_handshaker* tsi_create_adapter_handshaker(tsi_handshaker* wrapped); - -/* Given a tsi adapter handshaker, return the original wrapped handshaker. The - adapter still owns the wrapped handshaker which should not be destroyed by - the caller. */ -tsi_handshaker* tsi_adapter_handshaker_get_wrapped(tsi_handshaker* adapter); - -#endif /* GRPC_CORE_TSI_TRANSPORT_SECURITY_ADAPTER_H */ diff --git a/src/core/tsi/transport_security_interface.h b/src/core/tsi/transport_security_interface.h index 07f2bdfd81..7a0cdc3453 100644 --- a/src/core/tsi/transport_security_interface.h +++ b/src/core/tsi/transport_security_interface.h @@ -333,6 +333,8 @@ void tsi_handshaker_result_destroy(tsi_handshaker_result* self); ------------------------------------------------------------------------ */ typedef struct tsi_handshaker tsi_handshaker; +/* TODO(jiangtaoli2016): Cleans up deprecated methods when we are ready. */ + /* TO BE DEPRECATED SOON. Use tsi_handshaker_next instead. Gets bytes that need to be sent to the peer. - bytes is the buffer that will be written with the data to be sent to the diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 234f7634e2..699d504c12 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -296,7 +296,6 @@ CORE_SOURCE_FILES = [ 'third_party/nanopb/pb_decode.c', 'third_party/nanopb/pb_encode.c', 'src/core/tsi/transport_security.cc', - 'src/core/tsi/transport_security_adapter.cc', 'src/core/ext/transport/chttp2/client/insecure/channel_create.cc', 'src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc', 'src/core/ext/transport/chttp2/client/authority.cc', diff --git a/test/core/tsi/ssl_transport_security_test.cc b/test/core/tsi/ssl_transport_security_test.cc index cf1ac82413..b477904d60 100644 --- a/test/core/tsi/ssl_transport_security_test.cc +++ b/test/core/tsi/ssl_transport_security_test.cc @@ -24,7 +24,6 @@ #include "src/core/lib/security/security_connector/security_connector.h" #include "src/core/tsi/ssl_transport_security.h" #include "src/core/tsi/transport_security.h" -#include "src/core/tsi/transport_security_adapter.h" #include "src/core/tsi/transport_security_interface.h" #include "test/core/tsi/transport_security_test_lib.h" #include "test/core/util/test_config.h" @@ -164,19 +163,13 @@ static void ssl_test_setup_handshakers(tsi_test_fixture* fixture) { &server_options, &ssl_fixture->server_handshaker_factory) == TSI_OK); /* Create server and client handshakers. */ - tsi_handshaker* client_handshaker = nullptr; GPR_ASSERT(tsi_ssl_client_handshaker_factory_create_handshaker( ssl_fixture->client_handshaker_factory, ssl_fixture->server_name_indication, - &client_handshaker) == TSI_OK); - ssl_fixture->base.client_handshaker = - tsi_create_adapter_handshaker(client_handshaker); - tsi_handshaker* server_handshaker = nullptr; + &ssl_fixture->base.client_handshaker) == TSI_OK); GPR_ASSERT(tsi_ssl_server_handshaker_factory_create_handshaker( - ssl_fixture->server_handshaker_factory, &server_handshaker) == - TSI_OK); - ssl_fixture->base.server_handshaker = - tsi_create_adapter_handshaker(server_handshaker); + ssl_fixture->server_handshaker_factory, + &ssl_fixture->base.server_handshaker) == TSI_OK); } static void check_alpn(ssl_tsi_test_fixture* ssl_fixture, diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 82b4769544..0969b9cfb2 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -1496,8 +1496,6 @@ src/core/tsi/ssl_transport_security.h \ src/core/tsi/ssl_types.h \ src/core/tsi/transport_security.cc \ src/core/tsi/transport_security.h \ -src/core/tsi/transport_security_adapter.cc \ -src/core/tsi/transport_security_adapter.h \ src/core/tsi/transport_security_grpc.cc \ src/core/tsi/transport_security_grpc.h \ src/core/tsi/transport_security_interface.h \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 7fc32d973a..4f0fc1d30d 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -10702,7 +10702,6 @@ ], "headers": [ "src/core/tsi/transport_security.h", - "src/core/tsi/transport_security_adapter.h", "src/core/tsi/transport_security_interface.h" ], "is_filegroup": true, @@ -10711,8 +10710,6 @@ "src": [ "src/core/tsi/transport_security.cc", "src/core/tsi/transport_security.h", - "src/core/tsi/transport_security_adapter.cc", - "src/core/tsi/transport_security_adapter.h", "src/core/tsi/transport_security_interface.h" ], "third_party": false, -- cgit v1.2.3