grpc 1.10.0 → 1.11.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grpc might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Makefile +2098 -501
- data/include/grpc/byte_buffer.h +2 -0
- data/include/grpc/byte_buffer_reader.h +2 -0
- data/include/grpc/census.h +2 -0
- data/include/grpc/fork.h +2 -0
- data/include/grpc/grpc.h +10 -0
- data/include/grpc/grpc_cronet.h +2 -0
- data/include/grpc/grpc_posix.h +2 -1
- data/include/grpc/grpc_security.h +21 -0
- data/include/grpc/grpc_security_constants.h +1 -0
- data/include/grpc/impl/codegen/byte_buffer.h +2 -0
- data/include/grpc/impl/codegen/grpc_types.h +24 -0
- data/include/grpc/impl/codegen/slice.h +1 -1
- data/include/grpc/impl/codegen/sync.h +1 -0
- data/include/grpc/impl/codegen/sync_custom.h +2 -0
- data/include/grpc/impl/codegen/sync_generic.h +2 -0
- data/include/grpc/impl/codegen/sync_posix.h +2 -0
- data/include/grpc/impl/codegen/sync_windows.h +2 -0
- data/include/grpc/slice.h +2 -0
- data/include/grpc/slice_buffer.h +2 -0
- data/include/grpc/status.h +2 -0
- data/include/grpc/support/alloc.h +2 -2
- data/include/grpc/support/atm.h +2 -0
- data/include/grpc/support/atm_gcc_atomic.h +2 -0
- data/include/grpc/support/atm_gcc_sync.h +2 -0
- data/include/grpc/support/atm_windows.h +2 -0
- data/include/grpc/support/log.h +1 -1
- data/include/grpc/support/sync.h +2 -0
- data/include/grpc/support/sync_custom.h +2 -0
- data/include/grpc/support/sync_generic.h +2 -0
- data/include/grpc/support/sync_posix.h +2 -0
- data/include/grpc/support/sync_windows.h +2 -0
- data/include/grpc/support/time.h +2 -0
- data/src/boringssl/err_data.c +444 -438
- data/src/core/ext/census/grpc_context.cc +2 -0
- data/src/core/ext/filters/client_channel/backup_poller.cc +13 -8
- data/src/core/ext/filters/client_channel/backup_poller.h +3 -2
- data/src/core/ext/filters/client_channel/channel_connectivity.cc +2 -0
- data/src/core/ext/filters/client_channel/client_channel.cc +1988 -433
- data/src/core/ext/filters/client_channel/client_channel.h +2 -0
- data/src/core/ext/filters/client_channel/client_channel_factory.cc +2 -0
- data/src/core/ext/filters/client_channel/client_channel_factory.h +2 -0
- data/src/core/ext/filters/client_channel/client_channel_plugin.cc +2 -27
- data/src/core/ext/filters/client_channel/connector.cc +2 -0
- data/src/core/ext/filters/client_channel/connector.h +2 -0
- data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +2 -0
- data/src/core/ext/filters/client_channel/http_proxy.cc +2 -0
- data/src/core/ext/filters/client_channel/lb_policy.cc +2 -0
- data/src/core/ext/filters/client_channel/lb_policy.h +2 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +2 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h +2 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +96 -78
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +9 -17
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +70 -62
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +2 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +2 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +2 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +2 -0
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +4 -2
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +4 -2
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc +2 -0
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +2 -0
- data/src/core/ext/filters/client_channel/lb_policy_factory.cc +3 -1
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +2 -1
- data/src/core/ext/filters/client_channel/lb_policy_registry.cc +2 -0
- data/src/core/ext/filters/client_channel/lb_policy_registry.h +2 -1
- data/src/core/ext/filters/client_channel/method_params.cc +178 -0
- data/src/core/ext/filters/client_channel/method_params.h +74 -0
- data/src/core/ext/filters/client_channel/parse_address.cc +17 -13
- data/src/core/ext/filters/client_channel/parse_address.h +2 -0
- data/src/core/ext/filters/client_channel/proxy_mapper.cc +2 -0
- data/src/core/ext/filters/client_channel/proxy_mapper.h +2 -0
- data/src/core/ext/filters/client_channel/proxy_mapper_registry.cc +2 -0
- data/src/core/ext/filters/client_channel/proxy_mapper_registry.h +2 -0
- data/src/core/ext/filters/client_channel/resolver.cc +2 -0
- data/src/core/ext/filters/client_channel/resolver.h +6 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +24 -5
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +2 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +1 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +55 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +8 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +1 -0
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +30 -3
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +7 -0
- data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +2 -1
- data/src/core/ext/filters/client_channel/resolver_factory.h +2 -0
- data/src/core/ext/filters/client_channel/resolver_registry.cc +2 -0
- data/src/core/ext/filters/client_channel/resolver_registry.h +2 -0
- data/src/core/ext/filters/client_channel/retry_throttle.cc +102 -120
- data/src/core/ext/filters/client_channel/retry_throttle.h +52 -25
- data/src/core/ext/filters/client_channel/subchannel.cc +14 -4
- data/src/core/ext/filters/client_channel/subchannel.h +10 -1
- data/src/core/ext/filters/client_channel/subchannel_index.cc +2 -0
- data/src/core/ext/filters/client_channel/subchannel_index.h +2 -0
- data/src/core/ext/filters/client_channel/uri_parser.cc +2 -1
- data/src/core/ext/filters/client_channel/uri_parser.h +2 -1
- data/src/core/ext/filters/deadline/deadline_filter.cc +2 -1
- data/src/core/ext/filters/deadline/deadline_filter.h +2 -0
- data/src/core/ext/filters/http/client/http_client_filter.cc +27 -25
- data/src/core/ext/filters/http/client/http_client_filter.h +2 -0
- data/src/core/ext/filters/http/client_authority_filter.cc +156 -0
- data/src/core/ext/filters/http/client_authority_filter.h +34 -0
- data/src/core/ext/filters/http/http_filters_plugin.cc +2 -0
- data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +21 -22
- data/src/core/ext/filters/http/message_compress/message_compress_filter.h +2 -0
- data/src/core/ext/filters/http/server/http_server_filter.cc +11 -8
- data/src/core/ext/filters/http/server/http_server_filter.h +2 -0
- data/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc +2 -0
- data/src/core/ext/filters/load_reporting/server_load_reporting_filter.h +2 -0
- data/src/core/ext/filters/load_reporting/server_load_reporting_plugin.h +2 -0
- data/src/core/ext/filters/max_age/max_age_filter.cc +2 -0
- data/src/core/ext/filters/max_age/max_age_filter.h +2 -0
- data/src/core/ext/filters/message_size/message_size_filter.cc +52 -49
- data/src/core/ext/filters/message_size/message_size_filter.h +2 -0
- data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc +5 -1
- data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.h +2 -0
- data/src/core/ext/filters/workarounds/workaround_utils.cc +2 -0
- data/src/core/ext/filters/workarounds/workaround_utils.h +2 -0
- data/src/core/ext/transport/chttp2/alpn/alpn.cc +3 -1
- data/src/core/ext/transport/chttp2/alpn/alpn.h +2 -0
- data/src/core/ext/transport/chttp2/client/authority.cc +42 -0
- data/src/core/ext/transport/chttp2/client/authority.h +36 -0
- data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +2 -0
- data/src/core/ext/transport/chttp2/client/chttp2_connector.h +2 -0
- data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +10 -3
- data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +2 -2
- data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +37 -25
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +2 -0
- data/src/core/ext/transport/chttp2/server/chttp2_server.h +3 -1
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc +2 -1
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +2 -1
- data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +2 -0
- data/src/core/ext/transport/chttp2/transport/bin_decoder.cc +3 -1
- data/src/core/ext/transport/chttp2/transport/bin_decoder.h +2 -0
- data/src/core/ext/transport/chttp2/transport/bin_encoder.cc +2 -0
- data/src/core/ext/transport/chttp2/transport/bin_encoder.h +2 -0
- data/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc +2 -0
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +152 -182
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +2 -0
- data/src/core/ext/transport/chttp2/transport/flow_control.cc +2 -0
- data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -0
- data/src/core/ext/transport/chttp2/transport/frame.h +2 -1
- data/src/core/ext/transport/chttp2/transport/frame_data.cc +15 -19
- data/src/core/ext/transport/chttp2/transport/frame_data.h +7 -5
- data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +2 -0
- data/src/core/ext/transport/chttp2/transport/frame_goaway.h +2 -2
- data/src/core/ext/transport/chttp2/transport/frame_ping.cc +2 -0
- data/src/core/ext/transport/chttp2/transport/frame_ping.h +2 -1
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +2 -0
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +2 -1
- data/src/core/ext/transport/chttp2/transport/frame_settings.cc +2 -0
- data/src/core/ext/transport/chttp2/transport/frame_settings.h +2 -2
- data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +2 -0
- data/src/core/ext/transport/chttp2/transport/frame_window_update.h +2 -1
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +2 -0
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +2 -1
- data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +2 -1
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +2 -2
- data/src/core/ext/transport/chttp2/transport/hpack_table.cc +2 -0
- data/src/core/ext/transport/chttp2/transport/hpack_table.h +2 -1
- data/src/core/ext/transport/chttp2/transport/http2_settings.cc +2 -0
- data/src/core/ext/transport/chttp2/transport/http2_settings.h +2 -0
- data/src/core/ext/transport/chttp2/transport/huffsyms.cc +2 -0
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +3 -2
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +2 -0
- data/src/core/ext/transport/chttp2/transport/internal.h +60 -24
- data/src/core/ext/transport/chttp2/transport/parsing.cc +2 -4
- data/src/core/ext/transport/chttp2/transport/stream_lists.cc +2 -0
- data/src/core/ext/transport/chttp2/transport/stream_map.cc +2 -0
- data/src/core/ext/transport/chttp2/transport/varint.cc +2 -0
- data/src/core/ext/transport/chttp2/transport/writing.cc +10 -6
- data/src/core/ext/transport/inproc/inproc_plugin.cc +2 -0
- data/src/core/ext/transport/inproc/inproc_transport.cc +20 -23
- data/src/core/ext/transport/inproc/inproc_transport.h +2 -0
- data/src/core/lib/avl/avl.cc +2 -0
- data/src/core/lib/avl/avl.h +2 -0
- data/src/core/lib/backoff/backoff.cc +2 -0
- data/src/core/lib/backoff/backoff.h +2 -0
- data/src/core/lib/channel/channel_args.h +2 -0
- data/src/core/lib/channel/channel_stack.cc +3 -1
- data/src/core/lib/channel/channel_stack.h +2 -0
- data/src/core/lib/channel/channel_stack_builder.cc +2 -0
- data/src/core/lib/channel/channel_stack_builder.h +2 -0
- data/src/core/lib/channel/channel_trace.cc +239 -0
- data/src/core/lib/channel/channel_trace.h +133 -0
- data/src/core/lib/channel/channel_trace_registry.cc +80 -0
- data/src/core/lib/channel/channel_trace_registry.h +43 -0
- data/src/core/lib/channel/connected_channel.cc +2 -0
- data/src/core/lib/channel/connected_channel.h +2 -0
- data/src/core/lib/channel/handshaker.cc +2 -0
- data/src/core/lib/channel/handshaker.h +2 -0
- data/src/core/lib/channel/handshaker_factory.cc +2 -0
- data/src/core/lib/channel/handshaker_factory.h +2 -1
- data/src/core/lib/channel/handshaker_registry.cc +2 -0
- data/src/core/lib/channel/handshaker_registry.h +2 -1
- data/src/core/lib/channel/status_util.cc +100 -0
- data/src/core/lib/channel/status_util.h +58 -0
- data/src/core/lib/compression/algorithm_metadata.h +2 -0
- data/src/core/lib/compression/compression.cc +2 -0
- data/src/core/lib/compression/compression_internal.cc +2 -0
- data/src/core/lib/compression/compression_internal.h +2 -0
- data/src/core/lib/compression/message_compress.cc +2 -0
- data/src/core/lib/compression/message_compress.h +2 -0
- data/src/core/lib/compression/stream_compression.cc +2 -0
- data/src/core/lib/compression/stream_compression.h +2 -0
- data/src/core/lib/compression/stream_compression_gzip.cc +2 -0
- data/src/core/lib/compression/stream_compression_gzip.h +2 -0
- data/src/core/lib/compression/stream_compression_identity.cc +2 -1
- data/src/core/lib/compression/stream_compression_identity.h +2 -0
- data/src/core/lib/debug/stats.cc +2 -0
- data/src/core/lib/debug/stats.h +2 -0
- data/src/core/lib/debug/stats_data.cc +3 -1
- data/src/core/lib/debug/stats_data.h +2 -0
- data/src/core/lib/debug/trace.cc +2 -0
- data/src/core/lib/debug/trace.h +2 -1
- data/src/core/lib/gpr/alloc.cc +2 -1
- data/src/core/lib/gpr/arena.cc +47 -0
- data/src/core/lib/gpr/arena.h +2 -0
- data/src/core/lib/gpr/atm.cc +2 -0
- data/src/core/lib/gpr/cpu_linux.cc +5 -1
- data/src/core/lib/gpr/cpu_posix.cc +1 -1
- data/src/core/lib/gpr/env.h +2 -0
- data/src/core/lib/gpr/fork.cc +2 -0
- data/src/core/lib/gpr/host_port.cc +2 -0
- data/src/core/lib/gpr/log.cc +2 -1
- data/src/core/lib/gpr/log_linux.cc +1 -0
- data/src/core/lib/gpr/mpscq.cc +2 -0
- data/src/core/lib/gpr/mpscq.h +2 -0
- data/src/core/lib/gpr/murmur_hash.cc +2 -0
- data/src/core/lib/gpr/spinlock.h +2 -0
- data/src/core/lib/gpr/string.cc +2 -1
- data/src/core/lib/gpr/string.h +2 -2
- data/src/core/lib/gpr/sync.cc +2 -0
- data/src/core/lib/gpr/time.cc +2 -0
- data/src/core/lib/gpr/time_posix.cc +1 -0
- data/src/core/lib/gpr/time_precise.cc +2 -0
- data/src/core/lib/gpr/time_precise.h +2 -0
- data/src/core/lib/gpr/tls_gcc.h +2 -0
- data/src/core/lib/gpr/tls_msvc.h +2 -0
- data/src/core/lib/gpr/tls_pthread.h +2 -0
- data/src/core/lib/gpr/tmpfile.h +2 -0
- data/src/core/lib/gprpp/atomic_with_atm.h +2 -0
- data/src/core/lib/gprpp/atomic_with_std.h +2 -0
- data/src/core/lib/gprpp/inlined_vector.h +2 -0
- data/src/core/lib/gprpp/manual_constructor.h +3 -1
- data/src/core/lib/gprpp/memory.h +5 -3
- data/src/core/lib/gprpp/orphanable.h +3 -0
- data/src/core/lib/gprpp/ref_counted.h +4 -0
- data/src/core/lib/gprpp/ref_counted_ptr.h +3 -0
- data/src/core/lib/gprpp/thd.h +135 -0
- data/src/core/lib/gprpp/thd_posix.cc +209 -0
- data/src/core/lib/gprpp/thd_windows.cc +162 -0
- data/src/core/lib/http/format_request.cc +2 -0
- data/src/core/lib/http/format_request.h +2 -0
- data/src/core/lib/http/httpcli.cc +2 -0
- data/src/core/lib/http/httpcli.h +2 -0
- data/src/core/lib/http/httpcli_security_connector.cc +16 -7
- data/src/core/lib/http/parser.cc +2 -0
- data/src/core/lib/http/parser.h +2 -1
- data/src/core/lib/iomgr/call_combiner.cc +2 -0
- data/src/core/lib/iomgr/call_combiner.h +2 -1
- data/src/core/lib/iomgr/combiner.cc +2 -0
- data/src/core/lib/iomgr/combiner.h +2 -0
- data/src/core/lib/iomgr/endpoint.cc +4 -0
- data/src/core/lib/iomgr/endpoint.h +2 -0
- data/src/core/lib/iomgr/endpoint_pair.h +2 -0
- data/src/core/lib/iomgr/endpoint_pair_posix.cc +2 -0
- data/src/core/lib/iomgr/endpoint_pair_uv.cc +2 -0
- data/src/core/lib/iomgr/endpoint_pair_windows.cc +7 -4
- data/src/core/lib/iomgr/error.h +2 -0
- data/src/core/lib/iomgr/error_internal.h +2 -0
- data/src/core/lib/iomgr/ev_epoll1_linux.cc +2 -0
- data/src/core/lib/iomgr/ev_epoll1_linux.h +2 -0
- data/src/core/lib/iomgr/ev_epollex_linux.cc +4 -18
- data/src/core/lib/iomgr/ev_epollex_linux.h +2 -0
- data/src/core/lib/iomgr/ev_epollsig_linux.cc +2 -0
- data/src/core/lib/iomgr/ev_epollsig_linux.h +2 -0
- data/src/core/lib/iomgr/ev_poll_posix.cc +61 -31
- data/src/core/lib/iomgr/ev_poll_posix.h +2 -0
- data/src/core/lib/iomgr/ev_posix.cc +35 -19
- data/src/core/lib/iomgr/ev_posix.h +2 -0
- data/src/core/lib/iomgr/ev_windows.cc +2 -0
- data/src/core/lib/iomgr/exec_ctx.cc +3 -1
- data/src/core/lib/iomgr/exec_ctx.h +21 -9
- data/src/core/lib/iomgr/executor.cc +13 -11
- data/src/core/lib/iomgr/executor.h +2 -0
- data/src/core/lib/iomgr/fork_posix.cc +4 -2
- data/src/core/lib/iomgr/fork_windows.cc +2 -0
- data/src/core/lib/iomgr/gethostname_fallback.cc +2 -0
- data/src/core/lib/iomgr/gethostname_host_name_max.cc +2 -0
- data/src/core/lib/iomgr/gethostname_sysconf.cc +2 -0
- data/src/core/lib/iomgr/iocp_windows.cc +3 -1
- data/src/core/lib/iomgr/iocp_windows.h +3 -0
- data/src/core/lib/iomgr/iomgr.cc +2 -1
- data/src/core/lib/iomgr/iomgr.h +2 -0
- data/src/core/lib/iomgr/iomgr_custom.cc +63 -0
- data/src/core/lib/iomgr/iomgr_custom.h +47 -0
- data/src/core/lib/iomgr/iomgr_internal.cc +43 -0
- data/src/core/lib/iomgr/iomgr_internal.h +14 -0
- data/src/core/lib/iomgr/iomgr_posix.cc +30 -3
- data/src/core/lib/iomgr/iomgr_posix.h +2 -0
- data/src/core/lib/iomgr/iomgr_uv.cc +17 -20
- data/src/core/lib/iomgr/iomgr_windows.cc +29 -3
- data/src/core/lib/iomgr/is_epollexclusive_available.cc +2 -0
- data/src/core/lib/iomgr/is_epollexclusive_available.h +2 -0
- data/src/core/lib/iomgr/load_file.cc +2 -0
- data/src/core/lib/iomgr/load_file.h +2 -0
- data/src/core/lib/iomgr/lockfree_event.cc +2 -0
- data/src/core/lib/iomgr/lockfree_event.h +14 -1
- data/src/core/lib/iomgr/nameser.h +2 -0
- data/src/core/lib/iomgr/network_status_tracker.cc +3 -1
- data/src/core/lib/iomgr/network_status_tracker.h +2 -0
- data/src/core/lib/iomgr/polling_entity.cc +2 -0
- data/src/core/lib/iomgr/polling_entity.h +2 -0
- data/src/core/lib/iomgr/pollset.cc +56 -0
- data/src/core/lib/iomgr/pollset.h +19 -0
- data/src/core/lib/iomgr/pollset_custom.cc +106 -0
- data/src/core/lib/iomgr/{timer_generic.h → pollset_custom.h} +15 -17
- data/src/core/lib/iomgr/pollset_set.cc +55 -0
- data/src/core/lib/iomgr/pollset_set.h +13 -0
- data/src/core/lib/iomgr/pollset_set_custom.cc +48 -0
- data/src/core/lib/iomgr/{pollset_uv.h → pollset_set_custom.h} +6 -7
- data/src/core/lib/iomgr/pollset_set_windows.cc +17 -10
- data/src/core/lib/iomgr/pollset_set_windows.h +2 -0
- data/src/core/lib/iomgr/pollset_uv.cc +42 -105
- data/src/core/lib/iomgr/pollset_windows.cc +20 -12
- data/src/core/lib/iomgr/pollset_windows.h +2 -0
- data/src/core/lib/iomgr/port.h +10 -19
- data/src/core/lib/iomgr/resolve_address.cc +50 -0
- data/src/core/lib/iomgr/resolve_address.h +39 -10
- data/src/core/lib/iomgr/resolve_address_custom.cc +187 -0
- data/src/core/lib/iomgr/resolve_address_custom.h +43 -0
- data/src/core/lib/iomgr/resolve_address_posix.cc +10 -22
- data/src/core/lib/iomgr/resolve_address_windows.cc +10 -22
- data/src/core/lib/iomgr/resource_quota.cc +2 -0
- data/src/core/lib/iomgr/resource_quota.h +3 -5
- data/src/core/lib/iomgr/sockaddr.h +3 -11
- data/src/core/lib/iomgr/sockaddr_custom.h +54 -0
- data/src/core/lib/iomgr/sockaddr_posix.h +26 -0
- data/src/core/lib/iomgr/sockaddr_utils.cc +91 -71
- data/src/core/lib/iomgr/sockaddr_utils.h +4 -0
- data/src/core/lib/iomgr/sockaddr_windows.h +21 -0
- data/src/core/lib/iomgr/socket_factory_posix.cc +2 -0
- data/src/core/lib/iomgr/socket_factory_posix.h +2 -0
- data/src/core/lib/iomgr/socket_mutator.cc +2 -0
- data/src/core/lib/iomgr/socket_mutator.h +2 -0
- data/src/core/lib/iomgr/socket_utils.h +11 -0
- data/src/core/lib/iomgr/socket_utils_common_posix.cc +15 -6
- data/src/core/lib/iomgr/socket_utils_linux.cc +4 -4
- data/src/core/lib/iomgr/socket_utils_posix.cc +3 -2
- data/src/core/lib/iomgr/socket_utils_posix.h +2 -0
- data/src/core/lib/iomgr/socket_utils_uv.cc +13 -2
- data/src/core/lib/iomgr/socket_utils_windows.cc +10 -0
- data/src/core/lib/iomgr/socket_windows.cc +2 -0
- data/src/core/lib/iomgr/socket_windows.h +2 -1
- data/src/core/lib/iomgr/sys_epoll_wrapper.h +2 -0
- data/src/core/lib/iomgr/tcp_client.cc +36 -0
- data/src/core/lib/iomgr/tcp_client.h +13 -0
- data/src/core/lib/iomgr/tcp_client_custom.cc +151 -0
- data/src/core/lib/iomgr/tcp_client_posix.cc +11 -24
- data/src/core/lib/iomgr/tcp_client_posix.h +2 -0
- data/src/core/lib/iomgr/tcp_client_windows.cc +10 -23
- data/src/core/lib/iomgr/tcp_custom.cc +365 -0
- data/src/core/lib/iomgr/tcp_custom.h +81 -0
- data/src/core/lib/iomgr/tcp_posix.cc +3 -1
- data/src/core/lib/iomgr/tcp_posix.h +2 -0
- data/src/core/lib/iomgr/tcp_server.cc +73 -0
- data/src/core/lib/iomgr/tcp_server.h +24 -0
- data/src/core/lib/iomgr/tcp_server_custom.cc +472 -0
- data/src/core/lib/iomgr/tcp_server_posix.cc +41 -23
- data/src/core/lib/iomgr/tcp_server_utils_posix.h +2 -0
- data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +7 -7
- data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +8 -6
- data/src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc +2 -0
- data/src/core/lib/iomgr/tcp_server_windows.cc +43 -21
- data/src/core/lib/iomgr/tcp_uv.cc +308 -314
- data/src/core/lib/iomgr/tcp_windows.cc +3 -1
- data/src/core/lib/iomgr/tcp_windows.h +2 -0
- data/src/core/lib/iomgr/time_averaged_stats.cc +2 -0
- data/src/core/lib/iomgr/timer.cc +45 -0
- data/src/core/lib/iomgr/timer.h +36 -15
- data/src/core/lib/iomgr/timer_custom.cc +93 -0
- data/src/core/lib/iomgr/timer_custom.h +43 -0
- data/src/core/lib/iomgr/timer_generic.cc +12 -10
- data/src/core/lib/iomgr/timer_heap.cc +2 -4
- data/src/core/lib/iomgr/timer_heap.h +2 -0
- data/src/core/lib/iomgr/timer_manager.cc +12 -20
- data/src/core/lib/iomgr/timer_manager.h +2 -0
- data/src/core/lib/iomgr/timer_uv.cc +15 -49
- data/src/core/lib/iomgr/udp_server.cc +271 -230
- data/src/core/lib/iomgr/udp_server.h +44 -20
- data/src/core/lib/iomgr/unix_sockets_posix.cc +10 -7
- data/src/core/lib/iomgr/unix_sockets_posix.h +2 -0
- data/src/core/lib/iomgr/unix_sockets_posix_noop.cc +2 -0
- data/src/core/lib/iomgr/wakeup_fd_cv.cc +3 -1
- data/src/core/lib/iomgr/wakeup_fd_cv.h +2 -0
- data/src/core/lib/iomgr/wakeup_fd_eventfd.cc +2 -0
- data/src/core/lib/iomgr/wakeup_fd_nospecial.cc +2 -0
- data/src/core/lib/iomgr/wakeup_fd_pipe.cc +2 -0
- data/src/core/lib/iomgr/wakeup_fd_pipe.h +2 -0
- data/src/core/lib/iomgr/wakeup_fd_posix.cc +2 -0
- data/src/core/lib/iomgr/wakeup_fd_posix.h +2 -0
- data/src/core/lib/json/json.cc +38 -0
- data/src/core/lib/json/json.h +22 -1
- data/src/core/lib/json/json_reader.cc +2 -2
- data/src/core/lib/json/json_reader.h +1 -0
- data/src/core/lib/json/json_string.cc +2 -0
- data/src/core/lib/json/json_writer.cc +2 -2
- data/src/core/lib/json/json_writer.h +2 -0
- data/src/core/lib/profiling/basic_timers.cc +11 -9
- data/src/core/lib/profiling/timers.h +6 -3
- data/src/core/lib/security/context/security_context.cc +2 -0
- data/src/core/lib/security/context/security_context.h +2 -0
- data/src/core/lib/security/credentials/alts/alts_credentials.cc +119 -0
- data/src/core/lib/security/credentials/alts/alts_credentials.h +102 -0
- data/src/core/lib/security/credentials/alts/check_gcp_environment.cc +72 -0
- data/src/core/lib/security/credentials/alts/check_gcp_environment.h +57 -0
- data/src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc +67 -0
- data/src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc +33 -0
- data/src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc +114 -0
- data/src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc +126 -0
- data/src/core/lib/security/credentials/alts/grpc_alts_credentials_options.cc +46 -0
- data/src/core/lib/security/credentials/alts/grpc_alts_credentials_options.h +112 -0
- data/src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc +58 -0
- data/src/core/lib/security/credentials/composite/composite_credentials.cc +2 -0
- data/src/core/lib/security/credentials/composite/composite_credentials.h +2 -0
- data/src/core/lib/security/credentials/credentials.cc +2 -0
- data/src/core/lib/security/credentials/credentials.h +2 -0
- data/src/core/lib/security/credentials/credentials_metadata.cc +2 -0
- data/src/core/lib/security/credentials/fake/fake_credentials.cc +2 -3
- data/src/core/lib/security/credentials/fake/fake_credentials.h +5 -0
- data/src/core/lib/security/credentials/google_default/credentials_generic.cc +2 -0
- data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +2 -0
- data/src/core/lib/security/credentials/iam/iam_credentials.cc +2 -0
- data/src/core/lib/security/credentials/iam/iam_credentials.h +2 -0
- data/src/core/lib/security/credentials/jwt/json_token.cc +2 -0
- data/src/core/lib/security/credentials/jwt/json_token.h +2 -0
- data/src/core/lib/security/credentials/jwt/jwt_credentials.h +2 -0
- data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +2 -0
- data/src/core/lib/security/credentials/jwt/jwt_verifier.h +2 -0
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +2 -0
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +2 -0
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +2 -0
- data/src/core/lib/security/credentials/plugin/plugin_credentials.h +2 -0
- data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +11 -2
- data/src/core/lib/security/credentials/ssl/ssl_credentials.h +2 -0
- data/src/core/lib/security/security_connector/alts_security_connector.cc +287 -0
- data/src/core/lib/security/security_connector/alts_security_connector.h +69 -0
- data/src/core/lib/security/security_connector/security_connector.cc +174 -74
- data/src/core/lib/security/security_connector/security_connector.h +41 -7
- data/src/core/lib/security/transport/auth_filters.h +2 -0
- data/src/core/lib/security/transport/client_auth_filter.cc +14 -28
- data/src/core/lib/security/transport/secure_endpoint.cc +2 -0
- data/src/core/lib/security/transport/secure_endpoint.h +2 -0
- data/src/core/lib/security/transport/security_handshaker.cc +2 -0
- data/src/core/lib/security/transport/security_handshaker.h +2 -1
- data/src/core/lib/security/transport/server_auth_filter.cc +2 -0
- data/src/core/lib/security/transport/target_authority_table.cc +75 -0
- data/src/core/lib/security/transport/{lb_targets_info.h → target_authority_table.h} +16 -8
- data/src/core/lib/security/transport/tsi_error.cc +2 -0
- data/src/core/lib/security/transport/tsi_error.h +2 -0
- data/src/core/lib/security/util/json_util.cc +2 -0
- data/src/core/lib/security/util/json_util.h +2 -0
- data/src/core/lib/slice/b64.cc +2 -0
- data/src/core/lib/slice/b64.h +2 -0
- data/src/core/lib/slice/percent_encoding.cc +2 -0
- data/src/core/lib/slice/percent_encoding.h +2 -0
- data/src/core/lib/slice/slice.cc +2 -0
- data/src/core/lib/slice/slice_buffer.cc +3 -1
- data/src/core/lib/slice/slice_hash_table.h +178 -45
- data/src/core/lib/slice/slice_intern.cc +2 -0
- data/src/core/lib/slice/slice_internal.h +2 -2
- data/src/core/lib/slice/slice_string_helpers.cc +2 -0
- data/src/core/lib/slice/slice_string_helpers.h +2 -1
- data/src/core/lib/slice/slice_weak_hash_table.h +105 -0
- data/src/core/lib/surface/api_trace.cc +3 -1
- data/src/core/lib/surface/api_trace.h +2 -0
- data/src/core/lib/surface/byte_buffer.cc +3 -0
- data/src/core/lib/surface/byte_buffer_reader.cc +3 -0
- data/src/core/lib/surface/call.cc +46 -80
- data/src/core/lib/surface/call.h +2 -0
- data/src/core/lib/surface/call_details.cc +2 -0
- data/src/core/lib/surface/call_log_batch.cc +2 -0
- data/src/core/lib/surface/call_test_only.h +2 -0
- data/src/core/lib/surface/channel.cc +72 -41
- data/src/core/lib/surface/channel.h +2 -0
- data/src/core/lib/surface/channel_init.cc +2 -0
- data/src/core/lib/surface/channel_init.h +2 -0
- data/src/core/lib/surface/channel_ping.cc +2 -0
- data/src/core/lib/surface/channel_stack_type.cc +3 -2
- data/src/core/lib/surface/channel_stack_type.h +2 -0
- data/src/core/lib/surface/completion_queue.h +2 -0
- data/src/core/lib/surface/completion_queue_factory.cc +3 -1
- data/src/core/lib/surface/completion_queue_factory.h +2 -0
- data/src/core/lib/surface/event_string.cc +2 -0
- data/src/core/lib/surface/event_string.h +2 -0
- data/src/core/lib/surface/init.cc +5 -2
- data/src/core/lib/surface/init_secure.cc +5 -2
- data/src/core/lib/surface/lame_client.cc +7 -5
- data/src/core/lib/surface/lame_client.h +2 -0
- data/src/core/lib/surface/metadata_array.cc +2 -0
- data/src/core/lib/surface/server.cc +2 -0
- data/src/core/lib/surface/server.h +2 -0
- data/src/core/lib/surface/validate_metadata.cc +2 -1
- data/src/core/lib/surface/validate_metadata.h +2 -0
- data/src/core/lib/surface/version.cc +4 -2
- data/src/core/lib/transport/bdp_estimator.cc +2 -0
- data/src/core/lib/transport/byte_stream.cc +94 -116
- data/src/core/lib/transport/byte_stream.h +111 -78
- data/src/core/lib/transport/connectivity_state.cc +2 -0
- data/src/core/lib/transport/connectivity_state.h +3 -1
- data/src/core/lib/transport/error_utils.cc +2 -0
- data/src/core/lib/transport/error_utils.h +2 -0
- data/src/core/lib/transport/metadata.cc +2 -0
- data/src/core/lib/transport/metadata.h +3 -1
- data/src/core/lib/transport/metadata_batch.cc +26 -0
- data/src/core/lib/transport/metadata_batch.h +12 -1
- data/src/core/lib/transport/pid_controller.cc +2 -0
- data/src/core/lib/transport/pid_controller.h +2 -0
- data/src/core/lib/transport/service_config.cc +21 -175
- data/src/core/lib/transport/service_config.h +223 -35
- data/src/core/lib/transport/static_metadata.cc +310 -294
- data/src/core/lib/transport/static_metadata.h +96 -82
- data/src/core/lib/transport/status_conversion.cc +2 -0
- data/src/core/lib/transport/status_conversion.h +3 -0
- data/src/core/lib/transport/status_metadata.cc +54 -0
- data/src/core/lib/{iomgr/timer_uv.h → transport/status_metadata.h} +10 -12
- data/src/core/lib/transport/timeout_encoding.cc +2 -1
- data/src/core/lib/transport/timeout_encoding.h +2 -0
- data/src/core/lib/transport/transport.cc +3 -1
- data/src/core/lib/transport/transport.h +33 -7
- data/src/core/lib/transport/transport_impl.h +2 -0
- data/src/core/lib/transport/transport_op_string.cc +10 -3
- data/src/core/plugin_registry/grpc_plugin_registry.cc +10 -4
- data/src/core/tsi/alts/crypt/aes_gcm.cc +687 -0
- data/src/core/tsi/alts/crypt/gsec.cc +189 -0
- data/src/core/tsi/alts/crypt/gsec.h +454 -0
- data/src/core/tsi/alts/frame_protector/alts_counter.cc +118 -0
- data/src/core/tsi/alts/frame_protector/alts_counter.h +98 -0
- data/src/core/tsi/alts/frame_protector/alts_crypter.cc +66 -0
- data/src/core/tsi/alts/frame_protector/alts_crypter.h +255 -0
- data/src/core/tsi/alts/frame_protector/alts_frame_protector.cc +407 -0
- data/src/core/tsi/alts/frame_protector/alts_frame_protector.h +55 -0
- data/src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.cc +114 -0
- data/src/core/tsi/alts/frame_protector/alts_record_protocol_crypter_common.h +114 -0
- data/src/core/tsi/alts/frame_protector/alts_seal_privacy_integrity_crypter.cc +105 -0
- data/src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc +103 -0
- data/src/core/tsi/alts/frame_protector/frame_handler.cc +218 -0
- data/src/core/tsi/alts/frame_protector/frame_handler.h +236 -0
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +316 -0
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.h +137 -0
- data/src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc +520 -0
- data/src/core/tsi/alts/handshaker/alts_handshaker_service_api.h +323 -0
- data/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc +143 -0
- data/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h +149 -0
- data/src/core/tsi/alts/handshaker/alts_tsi_event.cc +73 -0
- data/src/core/tsi/alts/handshaker/alts_tsi_event.h +93 -0
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +483 -0
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +83 -0
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h +52 -0
- data/src/core/tsi/alts/handshaker/alts_tsi_utils.cc +58 -0
- data/src/core/tsi/alts/handshaker/alts_tsi_utils.h +52 -0
- data/src/core/tsi/alts/handshaker/altscontext.pb.c +48 -0
- data/src/core/tsi/alts/handshaker/altscontext.pb.h +64 -0
- data/src/core/tsi/alts/handshaker/handshaker.pb.c +123 -0
- data/src/core/tsi/alts/handshaker/handshaker.pb.h +255 -0
- data/src/core/tsi/alts/handshaker/transport_security_common.pb.c +50 -0
- data/src/core/tsi/alts/handshaker/transport_security_common.pb.h +78 -0
- data/src/core/tsi/alts/handshaker/transport_security_common_api.cc +196 -0
- data/src/core/tsi/alts/handshaker/transport_security_common_api.h +163 -0
- data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc +180 -0
- data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h +52 -0
- data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc +144 -0
- data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h +49 -0
- data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h +91 -0
- data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc +174 -0
- data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h +100 -0
- data/src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc +476 -0
- data/src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h +199 -0
- data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +296 -0
- data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h +52 -0
- data/src/core/tsi/alts_transport_security.cc +3 -1
- data/src/core/tsi/alts_transport_security.h +4 -2
- data/src/core/tsi/fake_transport_security.cc +2 -1
- data/src/core/tsi/fake_transport_security.h +2 -0
- data/src/core/tsi/ssl/session_cache/ssl_session.h +73 -0
- data/src/core/tsi/ssl/session_cache/ssl_session_boringssl.cc +58 -0
- data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +211 -0
- data/src/core/tsi/ssl/session_cache/ssl_session_cache.h +93 -0
- data/src/core/tsi/ssl/session_cache/ssl_session_openssl.cc +76 -0
- data/src/core/tsi/ssl_transport_security.cc +266 -62
- data/src/core/tsi/ssl_transport_security.h +128 -6
- data/src/core/tsi/ssl_types.h +2 -0
- data/src/core/tsi/transport_security.cc +2 -0
- data/src/core/tsi/transport_security.h +2 -0
- data/src/core/tsi/transport_security_adapter.cc +2 -0
- data/src/core/tsi/transport_security_adapter.h +2 -0
- data/src/core/tsi/transport_security_grpc.cc +2 -0
- data/src/core/tsi/transport_security_grpc.h +2 -0
- data/src/core/tsi/transport_security_interface.h +2 -0
- data/src/ruby/ext/grpc/extconf.rb +1 -2
- data/src/ruby/ext/grpc/rb_call.c +1 -13
- data/src/ruby/ext/grpc/rb_channel.c +6 -6
- data/src/ruby/ext/grpc/rb_compression_options.c +1 -1
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +10 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +15 -0
- data/src/ruby/lib/grpc/core/time_consts.rb +1 -1
- data/src/ruby/lib/grpc/generic/bidi_call.rb +19 -8
- data/src/ruby/lib/grpc/generic/client_stub.rb +6 -10
- data/src/ruby/lib/grpc/generic/interceptors.rb +1 -1
- data/src/ruby/lib/grpc/generic/rpc_server.rb +2 -2
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/spec/generic/client_stub_spec.rb +133 -0
- data/src/ruby/spec/pb/package_with_underscore/checker_spec.rb +54 -0
- data/src/ruby/spec/pb/package_with_underscore/data.proto +23 -0
- data/src/ruby/spec/pb/package_with_underscore/service.proto +23 -0
- data/third_party/address_sorting/address_sorting.c +369 -0
- data/third_party/address_sorting/address_sorting_internal.h +70 -0
- data/third_party/address_sorting/address_sorting_posix.c +97 -0
- data/third_party/address_sorting/address_sorting_windows.c +55 -0
- data/third_party/address_sorting/include/address_sorting/address_sorting.h +110 -0
- data/third_party/boringssl/crypto/asn1/a_enum.c +20 -9
- data/third_party/boringssl/crypto/asn1/a_i2d_fp.c +3 -0
- data/third_party/boringssl/crypto/asn1/a_int.c +19 -8
- data/third_party/boringssl/crypto/asn1/a_object.c +0 -128
- data/third_party/boringssl/crypto/asn1/asn1_locl.h +3 -0
- data/third_party/boringssl/crypto/asn1/tasn_fre.c +2 -4
- data/third_party/boringssl/crypto/asn1/tasn_new.c +3 -2
- data/third_party/boringssl/crypto/bn_extra/bn_asn1.c +0 -16
- data/third_party/boringssl/crypto/buf/buf.c +14 -0
- data/third_party/boringssl/crypto/bytestring/cbb.c +93 -0
- data/third_party/boringssl/crypto/conf/conf.c +2 -2
- data/third_party/boringssl/crypto/cpu-intel.c +17 -17
- data/third_party/boringssl/crypto/crypto.c +16 -4
- data/third_party/boringssl/crypto/curve25519/spake25519.c +11 -11
- data/third_party/boringssl/crypto/curve25519/x25519-x86_64.c +1 -1
- data/third_party/boringssl/crypto/dsa/dsa.c +9 -21
- data/third_party/boringssl/crypto/ec_extra/ec_asn1.c +2 -2
- data/third_party/boringssl/crypto/ecdsa_extra/ecdsa_asn1.c +1 -8
- data/third_party/boringssl/crypto/evp/p_rsa_asn1.c +2 -23
- data/third_party/boringssl/crypto/ex_data.c +0 -1
- data/third_party/boringssl/crypto/fipsmodule/bn/add.c +7 -11
- data/third_party/boringssl/crypto/fipsmodule/bn/asm/x86_64-gcc.c +19 -16
- data/third_party/boringssl/crypto/fipsmodule/bn/cmp.c +15 -0
- data/third_party/boringssl/crypto/fipsmodule/bn/div.c +53 -46
- data/third_party/boringssl/crypto/fipsmodule/bn/exponentiation.c +242 -85
- data/third_party/boringssl/crypto/fipsmodule/bn/generic.c +42 -47
- data/third_party/boringssl/crypto/fipsmodule/bn/internal.h +176 -34
- data/third_party/boringssl/crypto/fipsmodule/bn/montgomery.c +118 -65
- data/third_party/boringssl/crypto/fipsmodule/bn/mul.c +94 -61
- data/third_party/boringssl/crypto/fipsmodule/bn/random.c +79 -63
- data/third_party/boringssl/crypto/fipsmodule/bn/shift.c +26 -28
- data/third_party/boringssl/crypto/fipsmodule/cipher/cipher.c +2 -0
- data/third_party/boringssl/crypto/fipsmodule/ec/ec.c +250 -149
- data/third_party/boringssl/crypto/fipsmodule/ec/ec_montgomery.c +0 -27
- data/third_party/boringssl/crypto/fipsmodule/ec/internal.h +54 -20
- data/third_party/boringssl/crypto/fipsmodule/ec/oct.c +3 -3
- data/third_party/boringssl/crypto/fipsmodule/ec/p224-64.c +7 -41
- data/third_party/boringssl/crypto/fipsmodule/ec/p256-64.c +6 -40
- data/third_party/boringssl/crypto/fipsmodule/ec/p256-x86_64.c +17 -122
- data/third_party/boringssl/crypto/fipsmodule/ec/simple.c +3 -64
- data/third_party/boringssl/crypto/fipsmodule/ec/wnaf.c +27 -9
- data/third_party/boringssl/crypto/fipsmodule/ecdsa/ecdsa.c +203 -205
- data/third_party/boringssl/crypto/fipsmodule/modes/cbc.c +14 -15
- data/third_party/boringssl/crypto/fipsmodule/modes/cfb.c +12 -8
- data/third_party/boringssl/crypto/fipsmodule/modes/ctr.c +4 -3
- data/third_party/boringssl/crypto/fipsmodule/modes/gcm.c +25 -36
- data/third_party/boringssl/crypto/fipsmodule/modes/internal.h +10 -0
- data/third_party/boringssl/crypto/fipsmodule/rsa/internal.h +0 -4
- data/third_party/boringssl/crypto/fipsmodule/rsa/rsa.c +2 -0
- data/third_party/boringssl/crypto/fipsmodule/rsa/rsa_impl.c +9 -19
- data/third_party/boringssl/crypto/lhash/lhash.c +19 -0
- data/third_party/boringssl/crypto/obj/obj.c +29 -69
- data/third_party/boringssl/crypto/pem/pem_lib.c +2 -2
- data/third_party/boringssl/crypto/poly1305/poly1305_vec.c +4 -55
- data/third_party/boringssl/crypto/rsa_extra/rsa_asn1.c +3 -22
- data/third_party/boringssl/crypto/x509/by_dir.c +1 -3
- data/third_party/boringssl/crypto/x509/by_file.c +0 -1
- data/third_party/boringssl/crypto/x509/x509_lu.c +0 -1
- data/third_party/boringssl/crypto/x509/x509_obj.c +1 -3
- data/third_party/boringssl/crypto/x509/x509_txt.c +0 -6
- data/third_party/boringssl/crypto/x509/x509_vfy.c +0 -1
- data/third_party/boringssl/crypto/x509/x509_vpm.c +0 -1
- data/third_party/boringssl/crypto/x509/x_algor.c +2 -2
- data/third_party/boringssl/crypto/x509v3/v3_alt.c +3 -4
- data/third_party/boringssl/crypto/x509v3/v3_genn.c +1 -0
- data/third_party/boringssl/crypto/x509v3/v3_info.c +1 -2
- data/third_party/boringssl/crypto/x509v3/v3_lib.c +15 -7
- data/third_party/boringssl/crypto/x509v3/v3_utl.c +41 -2
- data/third_party/boringssl/include/openssl/asn1.h +0 -1
- data/third_party/boringssl/include/openssl/base.h +1 -1
- data/third_party/boringssl/include/openssl/bio.h +5 -2
- data/third_party/boringssl/include/openssl/bn.h +2 -17
- data/third_party/boringssl/include/openssl/buf.h +4 -0
- data/third_party/boringssl/include/openssl/bytestring.h +11 -0
- data/third_party/boringssl/include/openssl/chacha.h +5 -1
- data/third_party/boringssl/include/openssl/cipher.h +10 -0
- data/third_party/boringssl/include/openssl/conf.h +4 -8
- data/third_party/boringssl/include/openssl/dsa.h +2 -18
- data/third_party/boringssl/include/openssl/ec.h +5 -5
- data/third_party/boringssl/include/openssl/ecdsa.h +10 -28
- data/third_party/boringssl/include/openssl/evp.h +0 -4
- data/third_party/boringssl/include/openssl/lhash.h +1 -18
- data/third_party/boringssl/include/openssl/obj.h +1 -0
- data/third_party/boringssl/include/openssl/rsa.h +3 -4
- data/third_party/boringssl/include/openssl/ssl.h +35 -54
- data/third_party/boringssl/include/openssl/ssl3.h +2 -0
- data/third_party/boringssl/include/openssl/stack.h +1 -1
- data/third_party/boringssl/include/openssl/tls1.h +1 -16
- data/third_party/boringssl/include/openssl/x509.h +3 -2
- data/third_party/boringssl/include/openssl/x509_vfy.h +0 -2
- data/third_party/boringssl/include/openssl/x509v3.h +1 -0
- data/third_party/boringssl/ssl/custom_extensions.cc +1 -1
- data/third_party/boringssl/ssl/d1_both.cc +120 -129
- data/third_party/boringssl/ssl/d1_lib.cc +23 -21
- data/third_party/boringssl/ssl/d1_pkt.cc +39 -143
- data/third_party/boringssl/ssl/dtls_method.cc +16 -23
- data/third_party/boringssl/ssl/dtls_record.cc +11 -4
- data/third_party/boringssl/ssl/handshake.cc +109 -40
- data/third_party/boringssl/ssl/handshake_client.cc +104 -96
- data/third_party/boringssl/ssl/handshake_server.cc +62 -72
- data/third_party/boringssl/ssl/internal.h +397 -318
- data/third_party/boringssl/ssl/s3_both.cc +173 -191
- data/third_party/boringssl/ssl/s3_lib.cc +26 -34
- data/third_party/boringssl/ssl/s3_pkt.cc +105 -247
- data/third_party/boringssl/ssl/ssl_asn1.cc +22 -22
- data/third_party/boringssl/ssl/ssl_buffer.cc +98 -108
- data/third_party/boringssl/ssl/ssl_cert.cc +12 -1
- data/third_party/boringssl/ssl/ssl_cipher.cc +23 -28
- data/third_party/boringssl/ssl/ssl_key_share.cc +11 -6
- data/third_party/boringssl/ssl/ssl_lib.cc +190 -113
- data/third_party/boringssl/ssl/ssl_privkey.cc +76 -106
- data/third_party/boringssl/ssl/ssl_session.cc +3 -3
- data/third_party/boringssl/ssl/ssl_stat.cc +3 -3
- data/third_party/boringssl/ssl/ssl_transcript.cc +38 -22
- data/third_party/boringssl/ssl/ssl_versions.cc +64 -31
- data/third_party/boringssl/ssl/t1_enc.cc +137 -154
- data/third_party/boringssl/ssl/t1_lib.cc +463 -478
- data/third_party/boringssl/ssl/tls13_both.cc +57 -58
- data/third_party/boringssl/ssl/tls13_client.cc +256 -121
- data/third_party/boringssl/ssl/tls13_enc.cc +187 -72
- data/third_party/boringssl/ssl/tls13_server.cc +187 -86
- data/third_party/boringssl/ssl/tls_method.cc +20 -30
- data/third_party/boringssl/ssl/tls_record.cc +77 -40
- data/third_party/boringssl/third_party/fiat/curve25519.c +5062 -0
- data/third_party/boringssl/{crypto/curve25519 → third_party/fiat}/internal.h +40 -27
- data/third_party/nanopb/pb.h +1 -1
- metadata +147 -45
- data/src/core/lib/gpr/thd.cc +0 -49
- data/src/core/lib/gpr/thd.h +0 -71
- data/src/core/lib/gpr/thd_posix.cc +0 -154
- data/src/core/lib/gpr/thd_windows.cc +0 -107
- data/src/core/lib/iomgr/iomgr_uv.h +0 -37
- data/src/core/lib/iomgr/pollset_set_uv.cc +0 -43
- data/src/core/lib/iomgr/resolve_address_uv.cc +0 -284
- data/src/core/lib/iomgr/tcp_client_uv.cc +0 -175
- data/src/core/lib/iomgr/tcp_server_uv.cc +0 -471
- data/src/core/lib/iomgr/tcp_uv.h +0 -51
- data/src/core/lib/security/transport/lb_targets_info.cc +0 -59
- data/src/core/lib/slice/slice_hash_table.cc +0 -145
- data/third_party/boringssl/crypto/curve25519/curve25519.c +0 -4938
@@ -75,9 +75,16 @@ char* grpc_transport_stream_op_batch_string(
|
|
75
75
|
|
76
76
|
if (op->send_message) {
|
77
77
|
gpr_strvec_add(&b, gpr_strdup(" "));
|
78
|
-
|
79
|
-
|
80
|
-
|
78
|
+
if (op->payload->send_message.send_message != nullptr) {
|
79
|
+
gpr_asprintf(&tmp, "SEND_MESSAGE:flags=0x%08x:len=%d",
|
80
|
+
op->payload->send_message.send_message->flags(),
|
81
|
+
op->payload->send_message.send_message->length());
|
82
|
+
} else {
|
83
|
+
// This can happen when we check a batch after the transport has
|
84
|
+
// processed and cleared the send_message op.
|
85
|
+
tmp =
|
86
|
+
gpr_strdup("SEND_MESSAGE(flag and length unknown, already orphaned)");
|
87
|
+
}
|
81
88
|
gpr_strvec_add(&b, tmp);
|
82
89
|
}
|
83
90
|
|
@@ -16,18 +16,20 @@
|
|
16
16
|
*
|
17
17
|
*/
|
18
18
|
|
19
|
+
#include <grpc/support/port_platform.h>
|
20
|
+
|
19
21
|
#include <grpc/grpc.h>
|
20
22
|
|
21
23
|
void grpc_http_filters_init(void);
|
22
24
|
void grpc_http_filters_shutdown(void);
|
23
25
|
void grpc_chttp2_plugin_init(void);
|
24
26
|
void grpc_chttp2_plugin_shutdown(void);
|
25
|
-
void grpc_tsi_alts_init(void);
|
26
|
-
void grpc_tsi_alts_shutdown(void);
|
27
27
|
void grpc_deadline_filter_init(void);
|
28
28
|
void grpc_deadline_filter_shutdown(void);
|
29
29
|
void grpc_client_channel_init(void);
|
30
30
|
void grpc_client_channel_shutdown(void);
|
31
|
+
void grpc_tsi_alts_init(void);
|
32
|
+
void grpc_tsi_alts_shutdown(void);
|
31
33
|
void grpc_inproc_plugin_init(void);
|
32
34
|
void grpc_inproc_plugin_shutdown(void);
|
33
35
|
void grpc_resolver_fake_init(void);
|
@@ -50,6 +52,8 @@ void grpc_max_age_filter_init(void);
|
|
50
52
|
void grpc_max_age_filter_shutdown(void);
|
51
53
|
void grpc_message_size_filter_init(void);
|
52
54
|
void grpc_message_size_filter_shutdown(void);
|
55
|
+
void grpc_client_authority_filter_init(void);
|
56
|
+
void grpc_client_authority_filter_shutdown(void);
|
53
57
|
void grpc_workaround_cronet_compression_filter_init(void);
|
54
58
|
void grpc_workaround_cronet_compression_filter_shutdown(void);
|
55
59
|
|
@@ -58,12 +62,12 @@ void grpc_register_built_in_plugins(void) {
|
|
58
62
|
grpc_http_filters_shutdown);
|
59
63
|
grpc_register_plugin(grpc_chttp2_plugin_init,
|
60
64
|
grpc_chttp2_plugin_shutdown);
|
61
|
-
grpc_register_plugin(grpc_tsi_alts_init,
|
62
|
-
grpc_tsi_alts_shutdown);
|
63
65
|
grpc_register_plugin(grpc_deadline_filter_init,
|
64
66
|
grpc_deadline_filter_shutdown);
|
65
67
|
grpc_register_plugin(grpc_client_channel_init,
|
66
68
|
grpc_client_channel_shutdown);
|
69
|
+
grpc_register_plugin(grpc_tsi_alts_init,
|
70
|
+
grpc_tsi_alts_shutdown);
|
67
71
|
grpc_register_plugin(grpc_inproc_plugin_init,
|
68
72
|
grpc_inproc_plugin_shutdown);
|
69
73
|
grpc_register_plugin(grpc_resolver_fake_init,
|
@@ -86,6 +90,8 @@ void grpc_register_built_in_plugins(void) {
|
|
86
90
|
grpc_max_age_filter_shutdown);
|
87
91
|
grpc_register_plugin(grpc_message_size_filter_init,
|
88
92
|
grpc_message_size_filter_shutdown);
|
93
|
+
grpc_register_plugin(grpc_client_authority_filter_init,
|
94
|
+
grpc_client_authority_filter_shutdown);
|
89
95
|
grpc_register_plugin(grpc_workaround_cronet_compression_filter_init,
|
90
96
|
grpc_workaround_cronet_compression_filter_shutdown);
|
91
97
|
}
|
@@ -0,0 +1,687 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2018 gRPC authors.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
|
19
|
+
#include <grpc/support/port_platform.h>
|
20
|
+
|
21
|
+
#include "src/core/tsi/alts/crypt/gsec.h"
|
22
|
+
|
23
|
+
#include <openssl/bio.h>
|
24
|
+
#include <openssl/buffer.h>
|
25
|
+
#include <openssl/err.h>
|
26
|
+
#include <openssl/evp.h>
|
27
|
+
#include <openssl/hmac.h>
|
28
|
+
#include <string.h>
|
29
|
+
|
30
|
+
#include <grpc/support/alloc.h>
|
31
|
+
|
32
|
+
constexpr size_t kKdfKeyLen = 32;
|
33
|
+
constexpr size_t kKdfCounterLen = 6;
|
34
|
+
constexpr size_t kKdfCounterOffset = 2;
|
35
|
+
constexpr size_t kRekeyAeadKeyLen = kAes128GcmKeyLength;
|
36
|
+
|
37
|
+
/* Struct for additional data required if rekeying is enabled. */
|
38
|
+
struct gsec_aes_gcm_aead_rekey_data {
|
39
|
+
uint8_t kdf_counter[kKdfCounterLen];
|
40
|
+
uint8_t nonce_mask[kAesGcmNonceLength];
|
41
|
+
};
|
42
|
+
|
43
|
+
/* Main struct for AES_GCM crypter interface. */
|
44
|
+
struct gsec_aes_gcm_aead_crypter {
|
45
|
+
gsec_aead_crypter crypter;
|
46
|
+
size_t key_length;
|
47
|
+
size_t nonce_length;
|
48
|
+
size_t tag_length;
|
49
|
+
uint8_t* key;
|
50
|
+
gsec_aes_gcm_aead_rekey_data* rekey_data;
|
51
|
+
EVP_CIPHER_CTX* ctx;
|
52
|
+
};
|
53
|
+
|
54
|
+
static char* aes_gcm_get_openssl_errors() {
|
55
|
+
BIO* bio = BIO_new(BIO_s_mem());
|
56
|
+
ERR_print_errors(bio);
|
57
|
+
BUF_MEM* mem = nullptr;
|
58
|
+
char* error_msg = nullptr;
|
59
|
+
BIO_get_mem_ptr(bio, &mem);
|
60
|
+
if (mem != nullptr) {
|
61
|
+
error_msg = static_cast<char*>(gpr_malloc(mem->length + 1));
|
62
|
+
memcpy(error_msg, mem->data, mem->length);
|
63
|
+
error_msg[mem->length] = '\0';
|
64
|
+
}
|
65
|
+
BIO_free_all(bio);
|
66
|
+
return error_msg;
|
67
|
+
}
|
68
|
+
|
69
|
+
static void aes_gcm_format_errors(const char* error_msg, char** error_details) {
|
70
|
+
if (error_details == nullptr) {
|
71
|
+
return;
|
72
|
+
}
|
73
|
+
unsigned long error = ERR_get_error();
|
74
|
+
if (error == 0 && error_msg != nullptr) {
|
75
|
+
*error_details = static_cast<char*>(gpr_malloc(strlen(error_msg) + 1));
|
76
|
+
memcpy(*error_details, error_msg, strlen(error_msg) + 1);
|
77
|
+
return;
|
78
|
+
}
|
79
|
+
char* openssl_errors = aes_gcm_get_openssl_errors();
|
80
|
+
if (openssl_errors != nullptr && error_msg != nullptr) {
|
81
|
+
size_t len = strlen(error_msg) + strlen(openssl_errors) + 2; /* ", " */
|
82
|
+
*error_details = static_cast<char*>(gpr_malloc(len + 1));
|
83
|
+
snprintf(*error_details, len + 1, "%s, %s", error_msg, openssl_errors);
|
84
|
+
gpr_free(openssl_errors);
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
static grpc_status_code gsec_aes_gcm_aead_crypter_max_ciphertext_and_tag_length(
|
89
|
+
const gsec_aead_crypter* crypter, size_t plaintext_length,
|
90
|
+
size_t* max_ciphertext_and_tag_length, char** error_details) {
|
91
|
+
if (max_ciphertext_and_tag_length == nullptr) {
|
92
|
+
aes_gcm_format_errors("max_ciphertext_and_tag_length is nullptr.",
|
93
|
+
error_details);
|
94
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
95
|
+
}
|
96
|
+
gsec_aes_gcm_aead_crypter* aes_gcm_crypter =
|
97
|
+
reinterpret_cast<gsec_aes_gcm_aead_crypter*>(
|
98
|
+
const_cast<gsec_aead_crypter*>(crypter));
|
99
|
+
*max_ciphertext_and_tag_length =
|
100
|
+
plaintext_length + aes_gcm_crypter->tag_length;
|
101
|
+
return GRPC_STATUS_OK;
|
102
|
+
}
|
103
|
+
|
104
|
+
static grpc_status_code gsec_aes_gcm_aead_crypter_max_plaintext_length(
|
105
|
+
const gsec_aead_crypter* crypter, size_t ciphertext_and_tag_length,
|
106
|
+
size_t* max_plaintext_length, char** error_details) {
|
107
|
+
if (max_plaintext_length == nullptr) {
|
108
|
+
aes_gcm_format_errors("max_plaintext_length is nullptr.", error_details);
|
109
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
110
|
+
}
|
111
|
+
gsec_aes_gcm_aead_crypter* aes_gcm_crypter =
|
112
|
+
reinterpret_cast<gsec_aes_gcm_aead_crypter*>(
|
113
|
+
const_cast<gsec_aead_crypter*>(crypter));
|
114
|
+
if (ciphertext_and_tag_length < aes_gcm_crypter->tag_length) {
|
115
|
+
*max_plaintext_length = 0;
|
116
|
+
aes_gcm_format_errors(
|
117
|
+
"ciphertext_and_tag_length is smaller than tag_length.", error_details);
|
118
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
119
|
+
}
|
120
|
+
*max_plaintext_length =
|
121
|
+
ciphertext_and_tag_length - aes_gcm_crypter->tag_length;
|
122
|
+
return GRPC_STATUS_OK;
|
123
|
+
}
|
124
|
+
|
125
|
+
static grpc_status_code gsec_aes_gcm_aead_crypter_nonce_length(
|
126
|
+
const gsec_aead_crypter* crypter, size_t* nonce_length,
|
127
|
+
char** error_details) {
|
128
|
+
if (nonce_length == nullptr) {
|
129
|
+
aes_gcm_format_errors("nonce_length is nullptr.", error_details);
|
130
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
131
|
+
}
|
132
|
+
gsec_aes_gcm_aead_crypter* aes_gcm_crypter =
|
133
|
+
reinterpret_cast<gsec_aes_gcm_aead_crypter*>(
|
134
|
+
const_cast<gsec_aead_crypter*>(crypter));
|
135
|
+
*nonce_length = aes_gcm_crypter->nonce_length;
|
136
|
+
return GRPC_STATUS_OK;
|
137
|
+
}
|
138
|
+
|
139
|
+
static grpc_status_code gsec_aes_gcm_aead_crypter_key_length(
|
140
|
+
const gsec_aead_crypter* crypter, size_t* key_length,
|
141
|
+
char** error_details) {
|
142
|
+
if (key_length == nullptr) {
|
143
|
+
aes_gcm_format_errors("key_length is nullptr.", error_details);
|
144
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
145
|
+
}
|
146
|
+
gsec_aes_gcm_aead_crypter* aes_gcm_crypter =
|
147
|
+
reinterpret_cast<gsec_aes_gcm_aead_crypter*>(
|
148
|
+
const_cast<gsec_aead_crypter*>(crypter));
|
149
|
+
*key_length = aes_gcm_crypter->key_length;
|
150
|
+
return GRPC_STATUS_OK;
|
151
|
+
}
|
152
|
+
|
153
|
+
static grpc_status_code gsec_aes_gcm_aead_crypter_tag_length(
|
154
|
+
const gsec_aead_crypter* crypter, size_t* tag_length,
|
155
|
+
char** error_details) {
|
156
|
+
if (tag_length == nullptr) {
|
157
|
+
aes_gcm_format_errors("tag_length is nullptr.", error_details);
|
158
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
159
|
+
}
|
160
|
+
gsec_aes_gcm_aead_crypter* aes_gcm_crypter =
|
161
|
+
reinterpret_cast<gsec_aes_gcm_aead_crypter*>(
|
162
|
+
const_cast<gsec_aead_crypter*>(crypter));
|
163
|
+
*tag_length = aes_gcm_crypter->tag_length;
|
164
|
+
return GRPC_STATUS_OK;
|
165
|
+
}
|
166
|
+
|
167
|
+
static void aes_gcm_mask_nonce(uint8_t* dst, const uint8_t* nonce,
|
168
|
+
const uint8_t* mask) {
|
169
|
+
uint64_t mask1;
|
170
|
+
uint32_t mask2;
|
171
|
+
memcpy(&mask1, mask, sizeof(mask1));
|
172
|
+
memcpy(&mask2, mask + sizeof(mask1), sizeof(mask2));
|
173
|
+
uint64_t nonce1;
|
174
|
+
uint32_t nonce2;
|
175
|
+
memcpy(&nonce1, nonce, sizeof(nonce1));
|
176
|
+
memcpy(&nonce2, nonce + sizeof(nonce1), sizeof(nonce2));
|
177
|
+
nonce1 ^= mask1;
|
178
|
+
nonce2 ^= mask2;
|
179
|
+
memcpy(dst, &nonce1, sizeof(nonce1));
|
180
|
+
memcpy(dst + sizeof(nonce1), &nonce2, sizeof(nonce2));
|
181
|
+
}
|
182
|
+
|
183
|
+
static grpc_status_code aes_gcm_derive_aead_key(uint8_t* dst,
|
184
|
+
const uint8_t* kdf_key,
|
185
|
+
const uint8_t* kdf_counter) {
|
186
|
+
unsigned char buf[EVP_MAX_MD_SIZE];
|
187
|
+
unsigned char ctr = 1;
|
188
|
+
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
189
|
+
HMAC_CTX hmac;
|
190
|
+
HMAC_CTX_init(&hmac);
|
191
|
+
if (!HMAC_Init_ex(&hmac, kdf_key, kKdfKeyLen, EVP_sha256(), nullptr) ||
|
192
|
+
!HMAC_Update(&hmac, kdf_counter, kKdfCounterLen) ||
|
193
|
+
!HMAC_Update(&hmac, &ctr, 1) || !HMAC_Final(&hmac, buf, nullptr)) {
|
194
|
+
HMAC_CTX_cleanup(&hmac);
|
195
|
+
return GRPC_STATUS_INTERNAL;
|
196
|
+
}
|
197
|
+
HMAC_CTX_cleanup(&hmac);
|
198
|
+
#else
|
199
|
+
HMAC_CTX* hmac = HMAC_CTX_new();
|
200
|
+
if (hmac == nullptr) {
|
201
|
+
return GRPC_STATUS_INTERNAL;
|
202
|
+
}
|
203
|
+
if (!HMAC_Init_ex(hmac, kdf_key, kKdfKeyLen, EVP_sha256(), nullptr) ||
|
204
|
+
!HMAC_Update(hmac, kdf_counter, kKdfCounterLen) ||
|
205
|
+
!HMAC_Update(hmac, &ctr, 1) || !HMAC_Final(hmac, buf, nullptr)) {
|
206
|
+
HMAC_CTX_free(hmac);
|
207
|
+
return GRPC_STATUS_INTERNAL;
|
208
|
+
}
|
209
|
+
HMAC_CTX_free(hmac);
|
210
|
+
#endif
|
211
|
+
memcpy(dst, buf, kRekeyAeadKeyLen);
|
212
|
+
return GRPC_STATUS_OK;
|
213
|
+
}
|
214
|
+
|
215
|
+
static grpc_status_code aes_gcm_rekey_if_required(
|
216
|
+
gsec_aes_gcm_aead_crypter* aes_gcm_crypter, const uint8_t* nonce,
|
217
|
+
char** error_details) {
|
218
|
+
// If rekey_data is nullptr, then rekeying is not supported and not required.
|
219
|
+
// If bytes 2-7 of kdf_counter differ from the (per message) nonce, then the
|
220
|
+
// encryption key is recomputed from a new kdf_counter to ensure that we don't
|
221
|
+
// encrypt more than 2^16 messages per encryption key (in each direction).
|
222
|
+
if (aes_gcm_crypter->rekey_data == nullptr ||
|
223
|
+
memcmp(aes_gcm_crypter->rekey_data->kdf_counter,
|
224
|
+
nonce + kKdfCounterOffset, kKdfCounterLen) == 0) {
|
225
|
+
return GRPC_STATUS_OK;
|
226
|
+
}
|
227
|
+
memcpy(aes_gcm_crypter->rekey_data->kdf_counter, nonce + kKdfCounterOffset,
|
228
|
+
kKdfCounterLen);
|
229
|
+
uint8_t aead_key[kRekeyAeadKeyLen];
|
230
|
+
if (aes_gcm_derive_aead_key(aead_key, aes_gcm_crypter->key,
|
231
|
+
aes_gcm_crypter->rekey_data->kdf_counter) !=
|
232
|
+
GRPC_STATUS_OK) {
|
233
|
+
aes_gcm_format_errors("Rekeying failed in key derivation.", error_details);
|
234
|
+
return GRPC_STATUS_INTERNAL;
|
235
|
+
}
|
236
|
+
if (!EVP_DecryptInit_ex(aes_gcm_crypter->ctx, nullptr, nullptr, aead_key,
|
237
|
+
nullptr)) {
|
238
|
+
aes_gcm_format_errors("Rekeying failed in context update.", error_details);
|
239
|
+
return GRPC_STATUS_INTERNAL;
|
240
|
+
}
|
241
|
+
return GRPC_STATUS_OK;
|
242
|
+
}
|
243
|
+
|
244
|
+
static grpc_status_code gsec_aes_gcm_aead_crypter_encrypt_iovec(
|
245
|
+
gsec_aead_crypter* crypter, const uint8_t* nonce, size_t nonce_length,
|
246
|
+
const struct iovec* aad_vec, size_t aad_vec_length,
|
247
|
+
const struct iovec* plaintext_vec, size_t plaintext_vec_length,
|
248
|
+
struct iovec ciphertext_vec, size_t* ciphertext_bytes_written,
|
249
|
+
char** error_details) {
|
250
|
+
gsec_aes_gcm_aead_crypter* aes_gcm_crypter =
|
251
|
+
reinterpret_cast<gsec_aes_gcm_aead_crypter*>(crypter);
|
252
|
+
// Input checks
|
253
|
+
if (nonce == nullptr) {
|
254
|
+
aes_gcm_format_errors("Nonce buffer is nullptr.", error_details);
|
255
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
256
|
+
}
|
257
|
+
if (kAesGcmNonceLength != nonce_length) {
|
258
|
+
aes_gcm_format_errors("Nonce buffer has the wrong length.", error_details);
|
259
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
260
|
+
}
|
261
|
+
if (aad_vec_length > 0 && aad_vec == nullptr) {
|
262
|
+
aes_gcm_format_errors("Non-zero aad_vec_length but aad_vec is nullptr.",
|
263
|
+
error_details);
|
264
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
265
|
+
}
|
266
|
+
if (plaintext_vec_length > 0 && plaintext_vec == nullptr) {
|
267
|
+
aes_gcm_format_errors(
|
268
|
+
"Non-zero plaintext_vec_length but plaintext_vec is nullptr.",
|
269
|
+
error_details);
|
270
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
271
|
+
}
|
272
|
+
if (ciphertext_bytes_written == nullptr) {
|
273
|
+
aes_gcm_format_errors("bytes_written is nullptr.", error_details);
|
274
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
275
|
+
}
|
276
|
+
*ciphertext_bytes_written = 0;
|
277
|
+
// rekey if required
|
278
|
+
if (aes_gcm_rekey_if_required(aes_gcm_crypter, nonce, error_details) !=
|
279
|
+
GRPC_STATUS_OK) {
|
280
|
+
return GRPC_STATUS_INTERNAL;
|
281
|
+
}
|
282
|
+
// mask nonce if required
|
283
|
+
const uint8_t* nonce_aead = nonce;
|
284
|
+
uint8_t nonce_masked[kAesGcmNonceLength];
|
285
|
+
if (aes_gcm_crypter->rekey_data != nullptr) {
|
286
|
+
aes_gcm_mask_nonce(nonce_masked, aes_gcm_crypter->rekey_data->nonce_mask,
|
287
|
+
nonce);
|
288
|
+
nonce_aead = nonce_masked;
|
289
|
+
}
|
290
|
+
// init openssl context
|
291
|
+
if (!EVP_EncryptInit_ex(aes_gcm_crypter->ctx, nullptr, nullptr, nullptr,
|
292
|
+
nonce_aead)) {
|
293
|
+
aes_gcm_format_errors("Initializing nonce failed", error_details);
|
294
|
+
return GRPC_STATUS_INTERNAL;
|
295
|
+
}
|
296
|
+
// process aad
|
297
|
+
size_t i;
|
298
|
+
for (i = 0; i < aad_vec_length; i++) {
|
299
|
+
const uint8_t* aad = static_cast<uint8_t*>(aad_vec[i].iov_base);
|
300
|
+
size_t aad_length = aad_vec[i].iov_len;
|
301
|
+
if (aad_length == 0) {
|
302
|
+
continue;
|
303
|
+
}
|
304
|
+
size_t aad_bytes_read = 0;
|
305
|
+
if (aad == nullptr) {
|
306
|
+
aes_gcm_format_errors("aad is nullptr.", error_details);
|
307
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
308
|
+
}
|
309
|
+
if (!EVP_EncryptUpdate(aes_gcm_crypter->ctx, nullptr,
|
310
|
+
reinterpret_cast<int*>(&aad_bytes_read), aad,
|
311
|
+
static_cast<int>(aad_length)) ||
|
312
|
+
aad_bytes_read != aad_length) {
|
313
|
+
aes_gcm_format_errors("Setting authenticated associated data failed",
|
314
|
+
error_details);
|
315
|
+
return GRPC_STATUS_INTERNAL;
|
316
|
+
}
|
317
|
+
}
|
318
|
+
uint8_t* ciphertext = static_cast<uint8_t*>(ciphertext_vec.iov_base);
|
319
|
+
size_t ciphertext_length = ciphertext_vec.iov_len;
|
320
|
+
if (ciphertext == nullptr) {
|
321
|
+
aes_gcm_format_errors("ciphertext is nullptr.", error_details);
|
322
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
323
|
+
}
|
324
|
+
// process plaintext
|
325
|
+
for (i = 0; i < plaintext_vec_length; i++) {
|
326
|
+
const uint8_t* plaintext = static_cast<uint8_t*>(plaintext_vec[i].iov_base);
|
327
|
+
size_t plaintext_length = plaintext_vec[i].iov_len;
|
328
|
+
if (plaintext == nullptr) {
|
329
|
+
if (plaintext_length == 0) {
|
330
|
+
continue;
|
331
|
+
}
|
332
|
+
aes_gcm_format_errors("plaintext is nullptr.", error_details);
|
333
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
334
|
+
}
|
335
|
+
if (ciphertext_length < plaintext_length) {
|
336
|
+
aes_gcm_format_errors(
|
337
|
+
"ciphertext is not large enough to hold the result.", error_details);
|
338
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
339
|
+
}
|
340
|
+
int bytes_written = 0;
|
341
|
+
int bytes_to_write = static_cast<int>(plaintext_length);
|
342
|
+
if (!EVP_EncryptUpdate(aes_gcm_crypter->ctx, ciphertext, &bytes_written,
|
343
|
+
plaintext, bytes_to_write)) {
|
344
|
+
aes_gcm_format_errors("Encrypting plaintext failed.", error_details);
|
345
|
+
return GRPC_STATUS_INTERNAL;
|
346
|
+
}
|
347
|
+
if (bytes_written > bytes_to_write) {
|
348
|
+
aes_gcm_format_errors("More bytes written than expected.", error_details);
|
349
|
+
return GRPC_STATUS_INTERNAL;
|
350
|
+
}
|
351
|
+
ciphertext += bytes_written;
|
352
|
+
ciphertext_length -= bytes_written;
|
353
|
+
}
|
354
|
+
int bytes_written_temp = 0;
|
355
|
+
if (!EVP_EncryptFinal_ex(aes_gcm_crypter->ctx, nullptr,
|
356
|
+
&bytes_written_temp)) {
|
357
|
+
aes_gcm_format_errors("Finalizing encryption failed.", error_details);
|
358
|
+
return GRPC_STATUS_INTERNAL;
|
359
|
+
}
|
360
|
+
if (bytes_written_temp != 0) {
|
361
|
+
aes_gcm_format_errors("Openssl wrote some unexpected bytes.",
|
362
|
+
error_details);
|
363
|
+
return GRPC_STATUS_INTERNAL;
|
364
|
+
}
|
365
|
+
if (ciphertext_length < kAesGcmTagLength) {
|
366
|
+
aes_gcm_format_errors("ciphertext is too small to hold a tag.",
|
367
|
+
error_details);
|
368
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
369
|
+
}
|
370
|
+
|
371
|
+
if (!EVP_CIPHER_CTX_ctrl(aes_gcm_crypter->ctx, EVP_CTRL_GCM_GET_TAG,
|
372
|
+
kAesGcmTagLength, ciphertext)) {
|
373
|
+
aes_gcm_format_errors("Writing tag failed.", error_details);
|
374
|
+
return GRPC_STATUS_INTERNAL;
|
375
|
+
}
|
376
|
+
ciphertext += kAesGcmTagLength;
|
377
|
+
ciphertext_length -= kAesGcmTagLength;
|
378
|
+
*ciphertext_bytes_written = ciphertext_vec.iov_len - ciphertext_length;
|
379
|
+
return GRPC_STATUS_OK;
|
380
|
+
}
|
381
|
+
|
382
|
+
static grpc_status_code gsec_aes_gcm_aead_crypter_decrypt_iovec(
|
383
|
+
gsec_aead_crypter* crypter, const uint8_t* nonce, size_t nonce_length,
|
384
|
+
const struct iovec* aad_vec, size_t aad_vec_length,
|
385
|
+
const struct iovec* ciphertext_vec, size_t ciphertext_vec_length,
|
386
|
+
struct iovec plaintext_vec, size_t* plaintext_bytes_written,
|
387
|
+
char** error_details) {
|
388
|
+
gsec_aes_gcm_aead_crypter* aes_gcm_crypter =
|
389
|
+
reinterpret_cast<gsec_aes_gcm_aead_crypter*>(
|
390
|
+
const_cast<gsec_aead_crypter*>(crypter));
|
391
|
+
if (nonce == nullptr) {
|
392
|
+
aes_gcm_format_errors("Nonce buffer is nullptr.", error_details);
|
393
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
394
|
+
}
|
395
|
+
if (kAesGcmNonceLength != nonce_length) {
|
396
|
+
aes_gcm_format_errors("Nonce buffer has the wrong length.", error_details);
|
397
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
398
|
+
}
|
399
|
+
if (aad_vec_length > 0 && aad_vec == nullptr) {
|
400
|
+
aes_gcm_format_errors("Non-zero aad_vec_length but aad_vec is nullptr.",
|
401
|
+
error_details);
|
402
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
403
|
+
}
|
404
|
+
if (ciphertext_vec_length > 0 && ciphertext_vec == nullptr) {
|
405
|
+
aes_gcm_format_errors(
|
406
|
+
"Non-zero plaintext_vec_length but plaintext_vec is nullptr.",
|
407
|
+
error_details);
|
408
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
409
|
+
}
|
410
|
+
// Compute the total length so we can ensure we don't pass the tag into
|
411
|
+
// EVP_decrypt.
|
412
|
+
size_t total_ciphertext_length = 0;
|
413
|
+
size_t i;
|
414
|
+
for (i = 0; i < ciphertext_vec_length; i++) {
|
415
|
+
total_ciphertext_length += ciphertext_vec[i].iov_len;
|
416
|
+
}
|
417
|
+
if (total_ciphertext_length < kAesGcmTagLength) {
|
418
|
+
aes_gcm_format_errors("ciphertext is too small to hold a tag.",
|
419
|
+
error_details);
|
420
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
421
|
+
}
|
422
|
+
if (plaintext_bytes_written == nullptr) {
|
423
|
+
aes_gcm_format_errors("bytes_written is nullptr.", error_details);
|
424
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
425
|
+
}
|
426
|
+
*plaintext_bytes_written = 0;
|
427
|
+
// rekey if required
|
428
|
+
if (aes_gcm_rekey_if_required(aes_gcm_crypter, nonce, error_details) !=
|
429
|
+
GRPC_STATUS_OK) {
|
430
|
+
aes_gcm_format_errors("Rekeying failed.", error_details);
|
431
|
+
return GRPC_STATUS_INTERNAL;
|
432
|
+
}
|
433
|
+
// mask nonce if required
|
434
|
+
const uint8_t* nonce_aead = nonce;
|
435
|
+
uint8_t nonce_masked[kAesGcmNonceLength];
|
436
|
+
if (aes_gcm_crypter->rekey_data != nullptr) {
|
437
|
+
aes_gcm_mask_nonce(nonce_masked, aes_gcm_crypter->rekey_data->nonce_mask,
|
438
|
+
nonce);
|
439
|
+
nonce_aead = nonce_masked;
|
440
|
+
}
|
441
|
+
// init openssl context
|
442
|
+
if (!EVP_DecryptInit_ex(aes_gcm_crypter->ctx, nullptr, nullptr, nullptr,
|
443
|
+
nonce_aead)) {
|
444
|
+
aes_gcm_format_errors("Initializing nonce failed.", error_details);
|
445
|
+
return GRPC_STATUS_INTERNAL;
|
446
|
+
}
|
447
|
+
// process aad
|
448
|
+
for (i = 0; i < aad_vec_length; i++) {
|
449
|
+
const uint8_t* aad = static_cast<uint8_t*>(aad_vec[i].iov_base);
|
450
|
+
size_t aad_length = aad_vec[i].iov_len;
|
451
|
+
if (aad_length == 0) {
|
452
|
+
continue;
|
453
|
+
}
|
454
|
+
size_t aad_bytes_read = 0;
|
455
|
+
if (aad == nullptr) {
|
456
|
+
aes_gcm_format_errors("aad is nullptr.", error_details);
|
457
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
458
|
+
}
|
459
|
+
if (!EVP_DecryptUpdate(aes_gcm_crypter->ctx, nullptr,
|
460
|
+
reinterpret_cast<int*>(&aad_bytes_read), aad,
|
461
|
+
static_cast<int>(aad_length)) ||
|
462
|
+
aad_bytes_read != aad_length) {
|
463
|
+
aes_gcm_format_errors("Setting authenticated associated data failed.",
|
464
|
+
error_details);
|
465
|
+
return GRPC_STATUS_INTERNAL;
|
466
|
+
}
|
467
|
+
}
|
468
|
+
// process ciphertext
|
469
|
+
uint8_t* plaintext = static_cast<uint8_t*>(plaintext_vec.iov_base);
|
470
|
+
size_t plaintext_length = plaintext_vec.iov_len;
|
471
|
+
if (plaintext_length > 0 && plaintext == nullptr) {
|
472
|
+
aes_gcm_format_errors(
|
473
|
+
"plaintext is nullptr, but plaintext_length is positive.",
|
474
|
+
error_details);
|
475
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
476
|
+
}
|
477
|
+
const uint8_t* ciphertext = nullptr;
|
478
|
+
size_t ciphertext_length = 0;
|
479
|
+
for (i = 0;
|
480
|
+
i < ciphertext_vec_length && total_ciphertext_length > kAesGcmTagLength;
|
481
|
+
i++) {
|
482
|
+
ciphertext = static_cast<uint8_t*>(ciphertext_vec[i].iov_base);
|
483
|
+
ciphertext_length = ciphertext_vec[i].iov_len;
|
484
|
+
if (ciphertext == nullptr) {
|
485
|
+
if (ciphertext_length == 0) {
|
486
|
+
continue;
|
487
|
+
}
|
488
|
+
aes_gcm_format_errors("ciphertext is nullptr.", error_details);
|
489
|
+
memset(plaintext_vec.iov_base, 0x00, plaintext_vec.iov_len);
|
490
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
491
|
+
}
|
492
|
+
size_t bytes_written = 0;
|
493
|
+
size_t bytes_to_write = ciphertext_length;
|
494
|
+
// Don't include the tag
|
495
|
+
if (bytes_to_write > total_ciphertext_length - kAesGcmTagLength) {
|
496
|
+
bytes_to_write = total_ciphertext_length - kAesGcmTagLength;
|
497
|
+
}
|
498
|
+
if (plaintext_length < bytes_to_write) {
|
499
|
+
aes_gcm_format_errors(
|
500
|
+
"Not enough plaintext buffer to hold encrypted ciphertext.",
|
501
|
+
error_details);
|
502
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
503
|
+
}
|
504
|
+
if (!EVP_DecryptUpdate(aes_gcm_crypter->ctx, plaintext,
|
505
|
+
reinterpret_cast<int*>(&bytes_written), ciphertext,
|
506
|
+
static_cast<int>(bytes_to_write))) {
|
507
|
+
aes_gcm_format_errors("Decrypting ciphertext failed.", error_details);
|
508
|
+
memset(plaintext_vec.iov_base, 0x00, plaintext_vec.iov_len);
|
509
|
+
return GRPC_STATUS_INTERNAL;
|
510
|
+
}
|
511
|
+
if (bytes_written > ciphertext_length) {
|
512
|
+
aes_gcm_format_errors("More bytes written than expected.", error_details);
|
513
|
+
memset(plaintext_vec.iov_base, 0x00, plaintext_vec.iov_len);
|
514
|
+
return GRPC_STATUS_INTERNAL;
|
515
|
+
}
|
516
|
+
ciphertext += bytes_written;
|
517
|
+
ciphertext_length -= bytes_written;
|
518
|
+
total_ciphertext_length -= bytes_written;
|
519
|
+
plaintext += bytes_written;
|
520
|
+
plaintext_length -= bytes_written;
|
521
|
+
}
|
522
|
+
if (total_ciphertext_length > kAesGcmTagLength) {
|
523
|
+
aes_gcm_format_errors(
|
524
|
+
"Not enough plaintext buffer to hold encrypted ciphertext.",
|
525
|
+
error_details);
|
526
|
+
memset(plaintext_vec.iov_base, 0x00, plaintext_vec.iov_len);
|
527
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
528
|
+
}
|
529
|
+
uint8_t tag[kAesGcmTagLength];
|
530
|
+
uint8_t* tag_tmp = tag;
|
531
|
+
if (ciphertext_length > 0) {
|
532
|
+
memcpy(tag_tmp, ciphertext, ciphertext_length);
|
533
|
+
tag_tmp += ciphertext_length;
|
534
|
+
total_ciphertext_length -= ciphertext_length;
|
535
|
+
}
|
536
|
+
for (; i < ciphertext_vec_length; i++) {
|
537
|
+
ciphertext = static_cast<uint8_t*>(ciphertext_vec[i].iov_base);
|
538
|
+
ciphertext_length = ciphertext_vec[i].iov_len;
|
539
|
+
if (ciphertext == nullptr) {
|
540
|
+
if (ciphertext_length == 0) {
|
541
|
+
continue;
|
542
|
+
}
|
543
|
+
aes_gcm_format_errors("ciphertext is nullptr.", error_details);
|
544
|
+
memset(plaintext_vec.iov_base, 0x00, plaintext_vec.iov_len);
|
545
|
+
return GRPC_STATUS_INVALID_ARGUMENT;
|
546
|
+
}
|
547
|
+
memcpy(tag_tmp, ciphertext, ciphertext_length);
|
548
|
+
tag_tmp += ciphertext_length;
|
549
|
+
total_ciphertext_length -= ciphertext_length;
|
550
|
+
}
|
551
|
+
if (!EVP_CIPHER_CTX_ctrl(aes_gcm_crypter->ctx, EVP_CTRL_GCM_SET_TAG,
|
552
|
+
kAesGcmTagLength, reinterpret_cast<void*>(tag))) {
|
553
|
+
aes_gcm_format_errors("Setting tag failed.", error_details);
|
554
|
+
memset(plaintext_vec.iov_base, 0x00, plaintext_vec.iov_len);
|
555
|
+
return GRPC_STATUS_INTERNAL;
|
556
|
+
}
|
557
|
+
int bytes_written_temp = 0;
|
558
|
+
if (!EVP_DecryptFinal_ex(aes_gcm_crypter->ctx, nullptr,
|
559
|
+
&bytes_written_temp)) {
|
560
|
+
aes_gcm_format_errors("Checking tag failed.", error_details);
|
561
|
+
memset(plaintext_vec.iov_base, 0x00, plaintext_vec.iov_len);
|
562
|
+
return GRPC_STATUS_FAILED_PRECONDITION;
|
563
|
+
}
|
564
|
+
if (bytes_written_temp != 0) {
|
565
|
+
aes_gcm_format_errors("Openssl wrote some unexpected bytes.",
|
566
|
+
error_details);
|
567
|
+
memset(plaintext_vec.iov_base, 0x00, plaintext_vec.iov_len);
|
568
|
+
return GRPC_STATUS_INTERNAL;
|
569
|
+
}
|
570
|
+
*plaintext_bytes_written = plaintext_vec.iov_len - plaintext_length;
|
571
|
+
return GRPC_STATUS_OK;
|
572
|
+
}
|
573
|
+
|
574
|
+
static void gsec_aes_gcm_aead_crypter_destroy(gsec_aead_crypter* crypter) {
|
575
|
+
gsec_aes_gcm_aead_crypter* aes_gcm_crypter =
|
576
|
+
reinterpret_cast<gsec_aes_gcm_aead_crypter*>(
|
577
|
+
const_cast<gsec_aead_crypter*>(crypter));
|
578
|
+
gpr_free(aes_gcm_crypter->key);
|
579
|
+
gpr_free(aes_gcm_crypter->rekey_data);
|
580
|
+
EVP_CIPHER_CTX_free(aes_gcm_crypter->ctx);
|
581
|
+
}
|
582
|
+
|
583
|
+
static const gsec_aead_crypter_vtable vtable = {
|
584
|
+
gsec_aes_gcm_aead_crypter_encrypt_iovec,
|
585
|
+
gsec_aes_gcm_aead_crypter_decrypt_iovec,
|
586
|
+
gsec_aes_gcm_aead_crypter_max_ciphertext_and_tag_length,
|
587
|
+
gsec_aes_gcm_aead_crypter_max_plaintext_length,
|
588
|
+
gsec_aes_gcm_aead_crypter_nonce_length,
|
589
|
+
gsec_aes_gcm_aead_crypter_key_length,
|
590
|
+
gsec_aes_gcm_aead_crypter_tag_length,
|
591
|
+
gsec_aes_gcm_aead_crypter_destroy};
|
592
|
+
|
593
|
+
static grpc_status_code aes_gcm_new_evp_cipher_ctx(
|
594
|
+
gsec_aes_gcm_aead_crypter* aes_gcm_crypter, char** error_details) {
|
595
|
+
const EVP_CIPHER* cipher = nullptr;
|
596
|
+
bool is_rekey = aes_gcm_crypter->rekey_data != nullptr;
|
597
|
+
switch (is_rekey ? kRekeyAeadKeyLen : aes_gcm_crypter->key_length) {
|
598
|
+
case kAes128GcmKeyLength:
|
599
|
+
cipher = EVP_aes_128_gcm();
|
600
|
+
break;
|
601
|
+
case kAes256GcmKeyLength:
|
602
|
+
cipher = EVP_aes_256_gcm();
|
603
|
+
break;
|
604
|
+
}
|
605
|
+
const uint8_t* aead_key = aes_gcm_crypter->key;
|
606
|
+
uint8_t aead_key_rekey[kRekeyAeadKeyLen];
|
607
|
+
if (is_rekey) {
|
608
|
+
if (aes_gcm_derive_aead_key(aead_key_rekey, aes_gcm_crypter->key,
|
609
|
+
aes_gcm_crypter->rekey_data->kdf_counter) !=
|
610
|
+
GRPC_STATUS_OK) {
|
611
|
+
aes_gcm_format_errors("Deriving key failed.", error_details);
|
612
|
+
return GRPC_STATUS_INTERNAL;
|
613
|
+
}
|
614
|
+
aead_key = aead_key_rekey;
|
615
|
+
}
|
616
|
+
if (!EVP_DecryptInit_ex(aes_gcm_crypter->ctx, cipher, nullptr, aead_key,
|
617
|
+
nullptr)) {
|
618
|
+
aes_gcm_format_errors("Setting key failed.", error_details);
|
619
|
+
return GRPC_STATUS_INTERNAL;
|
620
|
+
}
|
621
|
+
if (!EVP_CIPHER_CTX_ctrl(aes_gcm_crypter->ctx, EVP_CTRL_GCM_SET_IVLEN,
|
622
|
+
static_cast<int>(aes_gcm_crypter->nonce_length),
|
623
|
+
nullptr)) {
|
624
|
+
aes_gcm_format_errors("Setting nonce length failed.", error_details);
|
625
|
+
return GRPC_STATUS_INTERNAL;
|
626
|
+
}
|
627
|
+
return GRPC_STATUS_OK;
|
628
|
+
}
|
629
|
+
|
630
|
+
grpc_status_code gsec_aes_gcm_aead_crypter_create(const uint8_t* key,
|
631
|
+
size_t key_length,
|
632
|
+
size_t nonce_length,
|
633
|
+
size_t tag_length, bool rekey,
|
634
|
+
gsec_aead_crypter** crypter,
|
635
|
+
char** error_details) {
|
636
|
+
if (key == nullptr) {
|
637
|
+
aes_gcm_format_errors("key is nullptr.", error_details);
|
638
|
+
return GRPC_STATUS_FAILED_PRECONDITION;
|
639
|
+
}
|
640
|
+
if (crypter == nullptr) {
|
641
|
+
aes_gcm_format_errors("crypter is nullptr.", error_details);
|
642
|
+
return GRPC_STATUS_FAILED_PRECONDITION;
|
643
|
+
}
|
644
|
+
*crypter = nullptr;
|
645
|
+
if ((rekey && key_length != kAes128GcmRekeyKeyLength) ||
|
646
|
+
(!rekey && key_length != kAes128GcmKeyLength &&
|
647
|
+
key_length != kAes256GcmKeyLength) ||
|
648
|
+
(tag_length != kAesGcmTagLength) ||
|
649
|
+
(nonce_length != kAesGcmNonceLength)) {
|
650
|
+
aes_gcm_format_errors(
|
651
|
+
"Invalid key and/or nonce and/or tag length are provided at AEAD "
|
652
|
+
"crypter instance construction time.",
|
653
|
+
error_details);
|
654
|
+
return GRPC_STATUS_FAILED_PRECONDITION;
|
655
|
+
}
|
656
|
+
gsec_aes_gcm_aead_crypter* aes_gcm_crypter =
|
657
|
+
static_cast<gsec_aes_gcm_aead_crypter*>(
|
658
|
+
gpr_malloc(sizeof(gsec_aes_gcm_aead_crypter)));
|
659
|
+
aes_gcm_crypter->crypter.vtable = &vtable;
|
660
|
+
aes_gcm_crypter->nonce_length = nonce_length;
|
661
|
+
aes_gcm_crypter->tag_length = tag_length;
|
662
|
+
if (rekey) {
|
663
|
+
aes_gcm_crypter->key_length = kKdfKeyLen;
|
664
|
+
aes_gcm_crypter->rekey_data = static_cast<gsec_aes_gcm_aead_rekey_data*>(
|
665
|
+
gpr_malloc(sizeof(gsec_aes_gcm_aead_rekey_data)));
|
666
|
+
memcpy(aes_gcm_crypter->rekey_data->nonce_mask, key + kKdfKeyLen,
|
667
|
+
kAesGcmNonceLength);
|
668
|
+
// Set kdf_counter to all-zero for initial key derivation.
|
669
|
+
memset(aes_gcm_crypter->rekey_data->kdf_counter, 0, kKdfCounterLen);
|
670
|
+
} else {
|
671
|
+
aes_gcm_crypter->key_length = key_length;
|
672
|
+
aes_gcm_crypter->rekey_data = nullptr;
|
673
|
+
}
|
674
|
+
aes_gcm_crypter->key =
|
675
|
+
static_cast<uint8_t*>(gpr_malloc(aes_gcm_crypter->key_length));
|
676
|
+
memcpy(aes_gcm_crypter->key, key, aes_gcm_crypter->key_length);
|
677
|
+
aes_gcm_crypter->ctx = EVP_CIPHER_CTX_new();
|
678
|
+
grpc_status_code status =
|
679
|
+
aes_gcm_new_evp_cipher_ctx(aes_gcm_crypter, error_details);
|
680
|
+
if (status != GRPC_STATUS_OK) {
|
681
|
+
gsec_aes_gcm_aead_crypter_destroy(&aes_gcm_crypter->crypter);
|
682
|
+
gpr_free(aes_gcm_crypter);
|
683
|
+
return status;
|
684
|
+
}
|
685
|
+
*crypter = &aes_gcm_crypter->crypter;
|
686
|
+
return GRPC_STATUS_OK;
|
687
|
+
}
|