grpc 1.78.1 → 1.80.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Makefile +22 -8
- data/include/grpc/credentials.h +47 -37
- data/include/grpc/credentials_cpp.h +39 -0
- data/include/grpc/event_engine/event_engine.h +8 -3
- data/include/grpc/grpc.h +4 -0
- data/include/grpc/impl/call.h +9 -0
- data/include/grpc/impl/channel_arg_names.h +7 -0
- data/include/grpc/module.modulemap +2 -0
- data/include/grpc/private_key_signer.h +104 -0
- data/include/grpc/support/port_platform.h +6 -0
- data/src/core/call/call_filters.h +101 -78
- data/src/core/call/call_spine.h +91 -68
- data/src/core/call/call_state.h +60 -4
- data/src/core/call/client_call.cc +9 -9
- data/src/core/call/client_call.h +1 -1
- data/src/core/call/metadata_batch.cc +2 -0
- data/src/core/call/metadata_batch.h +48 -1
- data/src/core/call/metadata_info.cc +35 -0
- data/src/core/call/metadata_info.h +2 -0
- data/src/core/call/simple_slice_based_metadata.h +2 -1
- data/src/core/channelz/channelz.cc +9 -6
- data/src/core/channelz/channelz.h +7 -4
- data/src/core/channelz/property_list.h +5 -0
- data/src/core/channelz/v2tov1/convert.cc +1 -1
- data/src/core/channelz/v2tov1/legacy_api.cc +164 -307
- data/src/core/client_channel/buffered_call.cc +7 -3
- data/src/core/client_channel/buffered_call.h +11 -5
- data/src/core/client_channel/client_channel.cc +106 -44
- data/src/core/client_channel/client_channel.h +3 -6
- data/src/core/client_channel/client_channel_filter.cc +90 -64
- data/src/core/client_channel/client_channel_filter.h +3 -6
- data/src/core/client_channel/client_channel_internal.h +5 -0
- data/src/core/client_channel/config_selector.h +17 -12
- data/src/core/client_channel/dynamic_filters.cc +8 -7
- data/src/core/client_channel/dynamic_filters.h +7 -5
- data/src/core/client_channel/retry_filter.cc +1 -1
- data/src/core/client_channel/retry_filter.h +2 -2
- data/src/core/client_channel/subchannel.cc +1682 -266
- data/src/core/client_channel/subchannel.h +411 -134
- data/src/core/client_channel/subchannel_stream_client.cc +22 -18
- data/src/core/client_channel/subchannel_stream_client.h +8 -9
- data/src/core/client_channel/subchannel_stream_limiter.cc +76 -0
- data/src/core/client_channel/subchannel_stream_limiter.h +51 -0
- data/src/core/config/config_vars.cc +9 -1
- data/src/core/config/config_vars.h +6 -0
- data/src/core/credentials/call/call_creds_registry.h +51 -22
- data/src/core/credentials/call/call_creds_registry_init.cc +86 -2
- data/src/core/credentials/call/external/aws_external_account_credentials.cc +2 -2
- data/src/core/credentials/call/external/external_account_credentials.cc +11 -4
- data/src/core/credentials/call/external/file_external_account_credentials.cc +2 -2
- data/src/core/credentials/transport/channel_creds_registry.h +71 -20
- data/src/core/credentials/transport/channel_creds_registry_init.cc +338 -29
- data/src/core/credentials/transport/ssl/ssl_credentials.cc +43 -24
- data/src/core/credentials/transport/ssl/ssl_credentials.h +7 -1
- data/src/core/credentials/transport/ssl/ssl_security_connector.cc +2 -8
- data/src/core/credentials/transport/ssl/ssl_security_connector.h +4 -3
- data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.cc +25 -5
- data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.h +7 -5
- data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.cc +181 -109
- data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.h +55 -42
- data/src/core/credentials/transport/tls/grpc_tls_credentials_options.cc +28 -23
- data/src/core/credentials/transport/tls/grpc_tls_credentials_options.h +26 -23
- data/src/core/credentials/transport/tls/spiffe_utils.cc +2 -2
- data/src/core/credentials/transport/tls/ssl_utils.cc +18 -18
- data/src/core/credentials/transport/tls/ssl_utils.h +12 -10
- data/src/core/credentials/transport/tls/tls_security_connector.cc +106 -74
- data/src/core/credentials/transport/tls/tls_security_connector.h +12 -8
- data/src/core/credentials/transport/xds/xds_credentials.cc +76 -32
- data/src/core/credentials/transport/xds/xds_credentials.h +4 -2
- data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +117 -35
- data/src/core/ext/filters/fault_injection/fault_injection_filter.h +42 -4
- data/src/core/ext/filters/gcp_authentication/gcp_authentication_filter.cc +58 -29
- data/src/core/ext/filters/gcp_authentication/gcp_authentication_filter.h +19 -11
- data/src/core/ext/filters/stateful_session/stateful_session_filter.cc +82 -25
- data/src/core/ext/filters/stateful_session/stateful_session_filter.h +28 -3
- data/src/core/ext/filters/stateful_session/stateful_session_service_config_parser.cc +9 -7
- data/src/core/ext/filters/stateful_session/stateful_session_service_config_parser.h +1 -1
- data/src/core/ext/transport/chttp2/transport/call_tracer_wrapper.h +7 -1
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +117 -67
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +2 -0
- data/src/core/ext/transport/chttp2/transport/flow_control.h +11 -1
- data/src/core/ext/transport/chttp2/transport/frame.cc +2 -15
- data/src/core/ext/transport/chttp2/transport/frame.h +0 -4
- data/src/core/ext/transport/chttp2/transport/goaway.cc +17 -2
- data/src/core/ext/transport/chttp2/transport/goaway.h +27 -6
- data/src/core/ext/transport/chttp2/transport/header_assembler.h +8 -21
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +101 -40
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +95 -0
- data/src/core/ext/transport/chttp2/transport/http2_client_transport.cc +923 -772
- data/src/core/ext/transport/chttp2/transport/http2_client_transport.h +406 -423
- data/src/core/ext/transport/chttp2/transport/http2_settings.cc +1 -0
- data/src/core/ext/transport/chttp2/transport/http2_settings.h +8 -1
- data/src/core/ext/transport/chttp2/transport/http2_settings_promises.h +25 -13
- data/src/core/ext/transport/chttp2/transport/http2_transport.cc +71 -24
- data/src/core/ext/transport/chttp2/transport/http2_transport.h +25 -49
- data/src/core/ext/transport/chttp2/transport/http2_ztrace_collector.h +2 -2
- data/src/core/ext/transport/chttp2/transport/incoming_metadata_tracker.h +29 -9
- data/src/core/ext/transport/chttp2/transport/internal.h +6 -2
- data/src/core/ext/transport/chttp2/transport/keepalive.cc +14 -20
- data/src/core/ext/transport/chttp2/transport/keepalive.h +9 -6
- data/src/core/ext/transport/chttp2/transport/parsing.cc +11 -0
- data/src/core/ext/transport/chttp2/transport/ping_promise.cc +34 -74
- data/src/core/ext/transport/chttp2/transport/ping_promise.h +123 -79
- data/src/core/ext/transport/chttp2/transport/security_frame.h +233 -3
- data/src/core/ext/transport/chttp2/transport/stream.h +152 -73
- data/src/core/ext/transport/chttp2/transport/stream_data_queue.h +155 -85
- data/src/core/ext/transport/chttp2/transport/transport_common.h +0 -5
- data/src/core/ext/transport/chttp2/transport/writable_streams.h +8 -7
- data/src/core/ext/transport/chttp2/transport/write_cycle.cc +86 -0
- data/src/core/ext/transport/chttp2/transport/write_cycle.h +355 -0
- data/src/core/ext/transport/chttp2/transport/writing.cc +31 -29
- data/src/core/ext/upb-gen/cel/expr/checked.upb.h +1875 -0
- data/src/core/ext/upb-gen/cel/expr/checked.upb_minitable.c +409 -0
- data/src/core/ext/upb-gen/cel/expr/checked.upb_minitable.h +56 -0
- data/src/core/ext/upb-gen/cel/expr/syntax.upb.h +2223 -0
- data/src/core/ext/upb-gen/cel/expr/syntax.upb_minitable.c +489 -0
- data/src/core/ext/upb-gen/cel/expr/syntax.upb_minitable.h +60 -0
- data/src/core/ext/upb-gen/envoy/config/accesslog/v3/accesslog.upb.h +2 -1
- data/src/core/ext/upb-gen/envoy/config/bootstrap/v3/bootstrap.upb.h +130 -18
- data/src/core/ext/upb-gen/envoy/config/bootstrap/v3/bootstrap.upb_minitable.c +18 -13
- data/src/core/ext/upb-gen/envoy/config/cluster/v3/cluster.upb.h +70 -38
- data/src/core/ext/upb-gen/envoy/config/cluster/v3/cluster.upb_minitable.c +20 -17
- data/src/core/ext/upb-gen/envoy/config/common/matcher/v3/matcher.upb.h +26 -10
- data/src/core/ext/upb-gen/envoy/config/common/matcher/v3/matcher.upb_minitable.c +8 -7
- data/src/core/ext/upb-gen/envoy/config/common/mutation_rules/v3/mutation_rules.upb.h +495 -0
- data/src/core/ext/upb-gen/envoy/config/common/mutation_rules/v3/mutation_rules.upb_minitable.c +114 -0
- data/src/core/ext/upb-gen/envoy/config/common/mutation_rules/v3/mutation_rules.upb_minitable.h +36 -0
- data/src/core/ext/upb-gen/envoy/config/core/v3/address.upb.h +26 -10
- data/src/core/ext/upb-gen/envoy/config/core/v3/address.upb_minitable.c +8 -7
- data/src/core/ext/upb-gen/envoy/config/core/v3/cel.upb.h +121 -0
- data/src/core/ext/upb-gen/envoy/config/core/v3/cel.upb_minitable.c +54 -0
- data/src/core/ext/upb-gen/envoy/config/core/v3/cel.upb_minitable.h +32 -0
- data/src/core/ext/upb-gen/envoy/config/core/v3/grpc_service.upb.h +143 -9
- data/src/core/ext/upb-gen/envoy/config/core/v3/grpc_service.upb_minitable.c +18 -6
- data/src/core/ext/upb-gen/envoy/config/core/v3/protocol.upb.h +112 -11
- data/src/core/ext/upb-gen/envoy/config/core/v3/protocol.upb_minitable.c +22 -9
- data/src/core/ext/upb-gen/envoy/config/core/v3/proxy_protocol.upb.h +276 -0
- data/src/core/ext/upb-gen/envoy/config/core/v3/proxy_protocol.upb_minitable.c +60 -5
- data/src/core/ext/upb-gen/envoy/config/core/v3/proxy_protocol.upb_minitable.h +4 -0
- data/src/core/ext/upb-gen/envoy/config/endpoint/v3/endpoint_components.upb.h +72 -0
- data/src/core/ext/upb-gen/envoy/config/endpoint/v3/endpoint_components.upb_minitable.c +23 -2
- data/src/core/ext/upb-gen/envoy/config/endpoint/v3/endpoint_components.upb_minitable.h +2 -0
- data/src/core/ext/upb-gen/envoy/config/listener/v3/listener.upb.h +129 -13
- data/src/core/ext/upb-gen/envoy/config/listener/v3/listener.upb_minitable.c +36 -10
- data/src/core/ext/upb-gen/envoy/config/listener/v3/listener.upb_minitable.h +2 -0
- data/src/core/ext/upb-gen/envoy/config/listener/v3/quic_config.upb.h +30 -0
- data/src/core/ext/upb-gen/envoy/config/listener/v3/quic_config.upb_minitable.c +5 -3
- data/src/core/ext/upb-gen/envoy/config/metrics/v3/metrics_service.upb.h +16 -0
- data/src/core/ext/upb-gen/envoy/config/metrics/v3/metrics_service.upb_minitable.c +4 -3
- data/src/core/ext/upb-gen/envoy/config/metrics/v3/stats.upb.h +31 -0
- data/src/core/ext/upb-gen/envoy/config/metrics/v3/stats.upb_minitable.c +5 -3
- data/src/core/ext/upb-gen/envoy/config/overload/v3/overload.upb.h +2 -1
- data/src/core/ext/upb-gen/envoy/config/rbac/v3/rbac.upb.h +63 -0
- data/src/core/ext/upb-gen/envoy/config/rbac/v3/rbac.upb_minitable.c +12 -7
- data/src/core/ext/upb-gen/envoy/config/route/v3/route.upb.h +97 -81
- data/src/core/ext/upb-gen/envoy/config/route/v3/route.upb_minitable.c +40 -23
- data/src/core/ext/upb-gen/envoy/config/route/v3/route_components.upb.h +604 -228
- data/src/core/ext/upb-gen/envoy/config/route/v3/route_components.upb_minitable.c +146 -100
- data/src/core/ext/upb-gen/envoy/config/tap/v3/common.upb.h +30 -0
- data/src/core/ext/upb-gen/envoy/config/tap/v3/common.upb_minitable.c +5 -3
- data/src/core/ext/upb-gen/envoy/config/trace/v3/opentelemetry.upb.h +35 -3
- data/src/core/ext/upb-gen/envoy/config/trace/v3/opentelemetry.upb_minitable.c +7 -4
- data/src/core/ext/upb-gen/envoy/config/trace/v3/zipkin.upb.h +66 -14
- data/src/core/ext/upb-gen/envoy/config/trace/v3/zipkin.upb_minitable.c +22 -11
- data/src/core/ext/upb-gen/envoy/extensions/clusters/aggregate/v3/cluster.upb.h +87 -0
- data/src/core/ext/upb-gen/envoy/extensions/clusters/aggregate/v3/cluster.upb_minitable.c +29 -2
- data/src/core/ext/upb-gen/envoy/extensions/clusters/aggregate/v3/cluster.upb_minitable.h +2 -0
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/rbac/v3/rbac.upb.h +0 -1
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/rbac/v3/rbac.upb_minitable.c +0 -1
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/stateful_session/v3/stateful_session.upb.h +20 -4
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/stateful_session/v3/stateful_session.upb_minitable.c +5 -4
- data/src/core/ext/upb-gen/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +239 -60
- data/src/core/ext/upb-gen/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb_minitable.c +59 -28
- data/src/core/ext/upb-gen/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb_minitable.h +2 -0
- data/src/core/ext/upb-gen/envoy/extensions/grpc_service/call_credentials/access_token/v3/access_token_credentials.upb.h +89 -0
- data/src/core/ext/upb-gen/envoy/extensions/grpc_service/call_credentials/access_token/v3/access_token_credentials.upb_minitable.c +50 -0
- data/src/core/ext/upb-gen/envoy/extensions/grpc_service/call_credentials/access_token/v3/access_token_credentials.upb_minitable.h +32 -0
- data/src/core/ext/upb-gen/envoy/extensions/grpc_service/channel_credentials/tls/v3/tls_credentials.upb.h +135 -0
- data/src/core/ext/upb-gen/envoy/extensions/grpc_service/channel_credentials/tls/v3/tls_credentials.upb_minitable.c +53 -0
- data/src/core/ext/upb-gen/envoy/extensions/grpc_service/channel_credentials/tls/v3/tls_credentials.upb_minitable.h +32 -0
- data/src/core/ext/upb-gen/envoy/extensions/grpc_service/channel_credentials/xds/v3/xds_credentials.upb.h +105 -0
- data/src/core/ext/upb-gen/envoy/extensions/grpc_service/channel_credentials/xds/v3/xds_credentials.upb_minitable.c +51 -0
- data/src/core/ext/upb-gen/envoy/extensions/grpc_service/channel_credentials/xds/v3/xds_credentials.upb_minitable.h +32 -0
- data/src/core/ext/upb-gen/envoy/extensions/load_balancing_policies/client_side_weighted_round_robin/v3/client_side_weighted_round_robin.upb.h +32 -0
- data/src/core/ext/upb-gen/envoy/extensions/load_balancing_policies/client_side_weighted_round_robin/v3/client_side_weighted_round_robin.upb_minitable.c +6 -3
- data/src/core/ext/upb-gen/envoy/extensions/load_balancing_policies/common/v3/common.upb.h +206 -0
- data/src/core/ext/upb-gen/envoy/extensions/load_balancing_policies/common/v3/common.upb_minitable.c +41 -8
- data/src/core/ext/upb-gen/envoy/extensions/load_balancing_policies/common/v3/common.upb_minitable.h +2 -0
- data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/tls/v3/common.upb.h +64 -0
- data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/tls/v3/common.upb_minitable.c +4 -3
- data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/tls/v3/secret.upb.h +64 -0
- data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/tls/v3/secret.upb_minitable.c +31 -5
- data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/tls/v3/secret.upb_minitable.h +2 -0
- data/src/core/ext/upb-gen/envoy/extensions/upstreams/http/v3/http_protocol_options.upb.h +283 -14
- data/src/core/ext/upb-gen/envoy/extensions/upstreams/http/v3/http_protocol_options.upb_minitable.c +48 -11
- data/src/core/ext/upb-gen/envoy/extensions/upstreams/http/v3/http_protocol_options.upb_minitable.h +2 -0
- data/src/core/ext/upb-gen/envoy/type/http/v3/cookie.upb.h +144 -6
- data/src/core/ext/upb-gen/envoy/type/http/v3/cookie.upb_minitable.c +35 -7
- data/src/core/ext/upb-gen/envoy/type/http/v3/cookie.upb_minitable.h +2 -0
- data/src/core/ext/upb-gen/envoy/type/tracing/v3/custom_tag.upb.h +42 -21
- data/src/core/ext/upb-gen/envoy/type/tracing/v3/custom_tag.upb_minitable.c +9 -8
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/promise.upb.h +164 -1
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/promise.upb_minitable.c +37 -6
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/promise.upb_minitable.h +2 -0
- data/src/core/ext/upb-gen/xds/type/matcher/v3/cel.upb.h +0 -1
- data/src/core/ext/upb-gen/xds/type/matcher/v3/cel.upb_minitable.c +0 -1
- data/src/core/ext/upb-gen/xds/type/matcher/v3/http_inputs.upb.h +0 -1
- data/src/core/ext/upb-gen/xds/type/matcher/v3/http_inputs.upb_minitable.c +0 -1
- data/src/core/ext/upb-gen/xds/type/matcher/v3/matcher.upb.h +26 -11
- data/src/core/ext/upb-gen/xds/type/matcher/v3/matcher.upb_minitable.c +8 -8
- data/src/core/ext/upb-gen/xds/type/matcher/v3/string.upb.h +33 -0
- data/src/core/ext/upb-gen/xds/type/matcher/v3/string.upb_minitable.c +14 -3
- data/src/core/ext/upb-gen/xds/type/v3/cel.upb.h +90 -10
- data/src/core/ext/upb-gen/xds/type/v3/cel.upb_minitable.c +18 -7
- data/src/core/ext/upbdefs-gen/cel/expr/checked.upbdefs.c +248 -0
- data/src/core/ext/upbdefs-gen/cel/expr/checked.upbdefs.h +97 -0
- data/src/core/ext/upbdefs-gen/cel/expr/syntax.upbdefs.c +283 -0
- data/src/core/ext/upbdefs-gen/cel/expr/syntax.upbdefs.h +107 -0
- data/src/core/ext/upbdefs-gen/envoy/config/accesslog/v3/accesslog.upbdefs.c +213 -211
- data/src/core/ext/upbdefs-gen/envoy/config/bootstrap/v3/bootstrap.upbdefs.c +635 -614
- data/src/core/ext/upbdefs-gen/envoy/config/cluster/v3/cluster.upbdefs.c +1012 -1000
- data/src/core/ext/upbdefs-gen/envoy/config/common/matcher/v3/matcher.upbdefs.c +276 -273
- data/src/core/ext/upbdefs-gen/envoy/config/common/mutation_rules/v3/mutation_rules.upbdefs.c +152 -0
- data/src/core/ext/upbdefs-gen/envoy/config/common/mutation_rules/v3/mutation_rules.upbdefs.h +47 -0
- data/src/core/ext/upbdefs-gen/envoy/config/core/v3/address.upbdefs.c +149 -144
- data/src/core/ext/upbdefs-gen/envoy/config/core/v3/base.upbdefs.c +367 -370
- data/src/core/ext/upbdefs-gen/envoy/config/core/v3/cel.upbdefs.c +63 -0
- data/src/core/ext/upbdefs-gen/envoy/config/core/v3/cel.upbdefs.h +37 -0
- data/src/core/ext/upbdefs-gen/envoy/config/core/v3/grpc_service.upbdefs.c +297 -284
- data/src/core/ext/upbdefs-gen/envoy/config/core/v3/protocol.upbdefs.c +492 -469
- data/src/core/ext/upbdefs-gen/envoy/config/core/v3/proxy_protocol.upbdefs.c +74 -43
- data/src/core/ext/upbdefs-gen/envoy/config/core/v3/proxy_protocol.upbdefs.h +10 -0
- data/src/core/ext/upbdefs-gen/envoy/config/core/v3/substitution_format_string.upbdefs.c +60 -59
- data/src/core/ext/upbdefs-gen/envoy/config/endpoint/v3/endpoint_components.upbdefs.c +202 -184
- data/src/core/ext/upbdefs-gen/envoy/config/endpoint/v3/endpoint_components.upbdefs.h +5 -0
- data/src/core/ext/upbdefs-gen/envoy/config/listener/v3/listener.upbdefs.c +354 -339
- data/src/core/ext/upbdefs-gen/envoy/config/listener/v3/listener.upbdefs.h +5 -0
- data/src/core/ext/upbdefs-gen/envoy/config/listener/v3/quic_config.upbdefs.c +28 -19
- data/src/core/ext/upbdefs-gen/envoy/config/metrics/v3/metrics_service.upbdefs.c +30 -27
- data/src/core/ext/upbdefs-gen/envoy/config/metrics/v3/stats.upbdefs.c +71 -66
- data/src/core/ext/upbdefs-gen/envoy/config/overload/v3/overload.upbdefs.c +94 -91
- data/src/core/ext/upbdefs-gen/envoy/config/rbac/v3/rbac.upbdefs.c +386 -369
- data/src/core/ext/upbdefs-gen/envoy/config/route/v3/route.upbdefs.c +60 -57
- data/src/core/ext/upbdefs-gen/envoy/config/route/v3/route_components.upbdefs.c +1974 -1884
- data/src/core/ext/upbdefs-gen/envoy/config/tap/v3/common.upbdefs.c +119 -112
- data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/opentelemetry.upbdefs.c +62 -51
- data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/zipkin.upbdefs.c +109 -88
- data/src/core/ext/upbdefs-gen/envoy/extensions/clusters/aggregate/v3/cluster.upbdefs.c +54 -36
- data/src/core/ext/upbdefs-gen/envoy/extensions/clusters/aggregate/v3/cluster.upbdefs.h +5 -0
- data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/rbac/v3/rbac.upbdefs.c +78 -84
- data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/stateful_session/v3/stateful_session.upbdefs.c +48 -46
- data/src/core/ext/upbdefs-gen/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.c +1041 -984
- data/src/core/ext/upbdefs-gen/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.h +5 -0
- data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/tls/v3/common.upbdefs.c +304 -290
- data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/tls/v3/secret.upbdefs.c +94 -77
- data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/tls/v3/secret.upbdefs.h +5 -0
- data/src/core/ext/upbdefs-gen/envoy/extensions/upstreams/http/v3/http_protocol_options.upbdefs.c +246 -193
- data/src/core/ext/upbdefs-gen/envoy/extensions/upstreams/http/v3/http_protocol_options.upbdefs.h +5 -0
- data/src/core/ext/upbdefs-gen/envoy/type/http/v3/cookie.upbdefs.c +37 -23
- data/src/core/ext/upbdefs-gen/envoy/type/http/v3/cookie.upbdefs.h +5 -0
- data/src/core/ext/upbdefs-gen/envoy/type/tracing/v3/custom_tag.upbdefs.c +5 -3
- data/src/core/ext/upbdefs-gen/google/api/http.upbdefs.c +4 -4
- data/src/core/ext/upbdefs-gen/google/api/httpbody.upbdefs.c +4 -5
- data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/v2/promise.upbdefs.c +113 -87
- data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/v2/promise.upbdefs.h +5 -0
- data/src/core/ext/upbdefs-gen/udpa/annotations/migrate.upbdefs.c +5 -5
- data/src/core/ext/upbdefs-gen/udpa/annotations/security.upbdefs.c +6 -5
- data/src/core/ext/upbdefs-gen/udpa/annotations/sensitive.upbdefs.c +5 -5
- data/src/core/ext/upbdefs-gen/udpa/annotations/status.upbdefs.c +5 -5
- data/src/core/ext/upbdefs-gen/udpa/annotations/versioning.upbdefs.c +5 -5
- data/src/core/ext/upbdefs-gen/xds/type/matcher/v3/cel.upbdefs.c +25 -30
- data/src/core/ext/upbdefs-gen/xds/type/matcher/v3/http_inputs.upbdefs.c +14 -20
- data/src/core/ext/upbdefs-gen/xds/type/matcher/v3/matcher.upbdefs.c +180 -183
- data/src/core/ext/upbdefs-gen/xds/type/matcher/v3/string.upbdefs.c +56 -47
- data/src/core/ext/upbdefs-gen/xds/type/v3/cel.upbdefs.c +69 -47
- data/src/core/filter/filter_chain.h +95 -0
- data/src/core/handshaker/http_connect/{http_connect_handshaker.cc → http_connect_client_handshaker.cc} +32 -31
- data/src/core/handshaker/http_connect/{http_connect_handshaker.h → http_connect_client_handshaker.h} +4 -4
- data/src/core/handshaker/http_connect/http_proxy_mapper.cc +1 -1
- data/src/core/handshaker/http_connect/xds_http_proxy_mapper.cc +1 -1
- data/src/core/handshaker/security/pipelined_secure_endpoint.cc +14 -13
- data/src/core/handshaker/security/secure_endpoint.cc +282 -68
- data/src/core/handshaker/security/secure_endpoint.h +0 -7
- data/src/core/lib/channel/channel_args.h +1 -1
- data/src/core/lib/channel/promise_based_filter.cc +17 -4
- data/src/core/lib/channel/promise_based_filter.h +3 -2
- data/src/core/lib/debug/trace_flags.cc +2 -0
- data/src/core/lib/debug/trace_flags.h +1 -0
- data/src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc +35 -8
- data/src/core/lib/event_engine/cf_engine/dns_service_resolver.h +1 -2
- data/src/core/lib/event_engine/event_engine.cc +9 -0
- data/src/core/lib/event_engine/extensions/tcp_trace.h +0 -3
- data/src/core/lib/event_engine/posix_engine/ev_poll_posix.cc +2 -2
- data/src/core/lib/event_engine/posix_engine/posix_endpoint.h +1 -1
- data/src/core/lib/event_engine/posix_engine/posix_engine.cc +34 -9
- data/src/core/lib/event_engine/posix_engine/posix_engine.h +24 -2
- data/src/core/lib/event_engine/posix_engine/posix_engine_listener.cc +1 -3
- data/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc +141 -14
- data/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.h +19 -2
- data/src/core/lib/event_engine/posix_engine/posix_interface.h +7 -0
- data/src/core/lib/event_engine/posix_engine/posix_interface_posix.cc +21 -3
- data/src/core/lib/event_engine/posix_engine/posix_interface_windows.cc +16 -0
- data/src/core/lib/experiments/experiments.cc +309 -201
- data/src/core/lib/experiments/experiments.h +141 -80
- data/src/core/lib/iomgr/event_engine_shims/endpoint.cc +2 -2
- data/src/core/lib/iomgr/resolve_address.h +0 -2
- data/src/core/lib/iomgr/resolved_address.h +0 -2
- data/src/core/lib/iomgr/tcp_posix.cc +13 -5
- data/src/core/lib/iomgr/tcp_server.cc +0 -5
- data/src/core/lib/iomgr/tcp_server.h +0 -7
- data/src/core/lib/iomgr/tcp_server_posix.cc +0 -17
- data/src/core/lib/iomgr/tcp_server_utils_posix.h +0 -3
- data/src/core/lib/iomgr/tcp_server_windows.cc +12 -51
- data/src/core/lib/promise/all_ok.h +17 -12
- data/src/core/lib/promise/cancel_callback.h +12 -13
- data/src/core/lib/promise/detail/join_state.h +626 -0
- data/src/core/lib/promise/detail/promise_factory.h +14 -14
- data/src/core/lib/promise/for_each.h +32 -8
- data/src/core/lib/promise/if.h +9 -7
- data/src/core/lib/promise/loop.h +18 -16
- data/src/core/lib/promise/map.h +54 -47
- data/src/core/lib/promise/mpsc.h +11 -10
- data/src/core/lib/promise/observable.h +6 -6
- data/src/core/lib/promise/party.h +25 -19
- data/src/core/lib/promise/poll.h +5 -5
- data/src/core/lib/promise/prioritized_race.h +10 -7
- data/src/core/lib/promise/promise.h +16 -11
- data/src/core/lib/promise/race.h +6 -5
- data/src/core/lib/promise/seq.h +109 -74
- data/src/core/lib/promise/try_join.h +14 -6
- data/src/core/lib/promise/try_seq.h +76 -60
- data/src/core/lib/resource_quota/api.cc +7 -0
- data/src/core/lib/resource_quota/arena.h +1 -1
- data/src/core/lib/resource_quota/memory_quota.cc +4 -1
- data/src/core/lib/resource_quota/resource_quota.cc +2 -1
- data/src/core/lib/resource_quota/resource_quota.h +3 -0
- data/src/core/lib/resource_quota/stream_quota.cc +77 -1
- data/src/core/lib/resource_quota/stream_quota.h +64 -1
- data/src/core/lib/resource_quota/telemetry.h +1 -1
- data/src/core/lib/surface/call.cc +13 -0
- data/src/core/lib/surface/call_utils.h +58 -43
- data/src/core/lib/surface/channel.h +1 -4
- data/src/core/lib/surface/completion_queue.cc +13 -6
- data/src/core/lib/surface/validate_metadata.cc +20 -15
- data/src/core/lib/surface/validate_metadata.h +3 -1
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/promise_endpoint.cc +1 -1
- data/src/core/lib/transport/promise_endpoint.h +1 -1
- data/src/core/lib/transport/transport.h +5 -0
- data/src/core/load_balancing/health_check_client.cc +1 -15
- data/src/core/load_balancing/health_check_client_internal.h +0 -2
- data/src/core/load_balancing/oob_backend_metric.cc +1 -5
- data/src/core/load_balancing/oob_backend_metric_internal.h +0 -1
- data/src/core/load_balancing/xds/xds_cluster_impl.cc +12 -9
- data/src/core/plugin_registry/grpc_plugin_registry.cc +3 -2
- data/src/core/resolver/xds/xds_resolver.cc +162 -116
- data/src/core/server/server.cc +18 -1
- data/src/core/server/server.h +2 -0
- data/src/core/server/xds_server_config_fetcher.cc +4 -4
- data/src/core/telemetry/call_tracer.cc +87 -2
- data/src/core/telemetry/call_tracer.h +46 -8
- data/src/core/telemetry/instrument.cc +102 -40
- data/src/core/telemetry/instrument.h +246 -65
- data/src/core/tsi/fake_transport_security.cc +3 -1
- data/src/core/tsi/ssl_transport_security.cc +516 -137
- data/src/core/tsi/ssl_transport_security.h +28 -22
- data/src/core/tsi/ssl_transport_security_utils.cc +2 -2
- data/src/core/tsi/ssl_transport_security_utils.h +2 -2
- data/src/core/util/bitset.h +6 -0
- data/src/core/util/function_signature.h +3 -1
- data/src/core/util/http_client/httpcli_security_connector.cc +2 -1
- data/src/core/util/json/json_reader.cc +0 -4
- data/src/core/xds/grpc/certificate_provider_store.cc +2 -1
- data/src/core/xds/grpc/certificate_provider_store.h +3 -17
- data/src/core/xds/grpc/certificate_provider_store_interface.h +61 -0
- data/src/core/xds/grpc/xds_bootstrap_grpc.cc +48 -0
- data/src/core/xds/grpc/xds_bootstrap_grpc.h +18 -0
- data/src/core/xds/grpc/xds_certificate_provider.cc +7 -2
- data/src/core/xds/grpc/xds_certificate_provider.h +13 -2
- data/src/core/xds/grpc/xds_client_grpc.cc +13 -6
- data/src/core/xds/grpc/xds_client_grpc.h +10 -7
- data/src/core/xds/grpc/xds_cluster.cc +18 -4
- data/src/core/xds/grpc/xds_cluster.h +17 -2
- data/src/core/xds/grpc/xds_cluster_parser.cc +36 -11
- data/src/core/xds/grpc/xds_common_types.cc +45 -0
- data/src/core/xds/grpc/xds_common_types.h +31 -0
- data/src/core/xds/grpc/xds_common_types_parser.cc +274 -16
- data/src/core/xds/grpc/xds_common_types_parser.h +12 -0
- data/src/core/xds/grpc/xds_http_fault_filter.cc +128 -24
- data/src/core/xds/grpc/xds_http_fault_filter.h +19 -10
- data/src/core/xds/grpc/xds_http_filter.cc +38 -0
- data/src/core/xds/grpc/xds_http_filter.h +70 -47
- data/src/core/xds/grpc/xds_http_filter_registry.cc +48 -14
- data/src/core/xds/grpc/xds_http_filter_registry.h +29 -15
- data/src/core/xds/grpc/xds_http_gcp_authn_filter.cc +88 -22
- data/src/core/xds/grpc/xds_http_gcp_authn_filter.h +22 -11
- data/src/core/xds/grpc/xds_http_rbac_filter.cc +36 -20
- data/src/core/xds/grpc/xds_http_rbac_filter.h +19 -10
- data/src/core/xds/grpc/xds_http_stateful_session_filter.cc +143 -26
- data/src/core/xds/grpc/xds_http_stateful_session_filter.h +19 -10
- data/src/core/xds/grpc/xds_listener.cc +4 -1
- data/src/core/xds/grpc/xds_listener.h +10 -2
- data/src/core/xds/grpc/xds_listener_parser.cc +23 -18
- data/src/core/xds/grpc/xds_matcher.cc +40 -5
- data/src/core/xds/grpc/xds_matcher.h +13 -0
- data/src/core/xds/grpc/xds_matcher_action.h +1 -1
- data/src/core/xds/grpc/xds_matcher_parse.cc +60 -40
- data/src/core/xds/grpc/xds_matcher_parse.h +2 -1
- data/src/core/xds/grpc/xds_route_config.cc +12 -1
- data/src/core/xds/grpc/xds_route_config.h +15 -2
- data/src/core/xds/grpc/xds_route_config_parser.cc +11 -5
- data/src/core/xds/grpc/xds_routing.cc +181 -6
- data/src/core/xds/grpc/xds_routing.h +57 -0
- data/src/core/xds/grpc/xds_server_grpc.cc +55 -43
- data/src/core/xds/grpc/xds_server_grpc.h +13 -6
- data/src/core/xds/grpc/xds_server_grpc_interface.h +3 -2
- data/src/core/xds/grpc/xds_transport_grpc.cc +12 -6
- data/src/core/xds/grpc/xds_transport_grpc.h +5 -1
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +12 -8
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +18 -12
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/generate_proto_ruby.sh +1 -1
- metadata +42 -6
- data/src/core/ext/transport/chttp2/transport/security_frame.cc +0 -31
- data/src/core/handshaker/security/legacy_secure_endpoint.cc +0 -597
|
@@ -18,11 +18,14 @@
|
|
|
18
18
|
|
|
19
19
|
#include "src/core/tsi/ssl_transport_security.h"
|
|
20
20
|
|
|
21
|
+
#include <grpc/private_key_signer.h>
|
|
21
22
|
#include <grpc/support/port_platform.h>
|
|
22
23
|
#include <limits.h>
|
|
23
24
|
#include <string.h>
|
|
24
25
|
|
|
26
|
+
#include <cstddef>
|
|
25
27
|
#include <cstdlib>
|
|
28
|
+
#include <utility>
|
|
26
29
|
|
|
27
30
|
// TODO(jboeuf): refactor inet_ntop into a portability header.
|
|
28
31
|
// Note: for whomever reads this and tries to refactor this, this
|
|
@@ -55,6 +58,8 @@
|
|
|
55
58
|
|
|
56
59
|
#include "src/core/credentials/transport/tls/grpc_tls_crl_provider.h"
|
|
57
60
|
#include "src/core/credentials/transport/tls/ssl_utils.h"
|
|
61
|
+
#include "src/core/lib/event_engine/default_event_engine.h"
|
|
62
|
+
#include "src/core/lib/iomgr/exec_ctx.h"
|
|
58
63
|
#include "src/core/lib/surface/init.h"
|
|
59
64
|
#include "src/core/tsi/ssl/key_logging/ssl_key_logging.h"
|
|
60
65
|
#include "src/core/tsi/ssl/session_cache/ssl_session_cache.h"
|
|
@@ -62,17 +67,19 @@
|
|
|
62
67
|
#include "src/core/tsi/ssl_types.h"
|
|
63
68
|
#include "src/core/tsi/transport_security.h"
|
|
64
69
|
#include "src/core/tsi/transport_security_interface.h"
|
|
65
|
-
#include "src/core/util/crash.h"
|
|
66
70
|
#include "src/core/util/env.h"
|
|
67
71
|
#include "src/core/util/grpc_check.h"
|
|
68
72
|
#include "src/core/util/match.h"
|
|
73
|
+
#include "src/core/util/ref_counted.h"
|
|
74
|
+
#include "src/core/util/ref_counted_ptr.h"
|
|
69
75
|
#include "src/core/util/sync.h"
|
|
70
76
|
#include "src/core/util/useful.h"
|
|
77
|
+
#include "absl/base/thread_annotations.h"
|
|
78
|
+
#include "absl/functional/bind_front.h"
|
|
71
79
|
#include "absl/log/log.h"
|
|
72
80
|
#include "absl/strings/match.h"
|
|
73
81
|
#include "absl/strings/numbers.h"
|
|
74
82
|
#include "absl/strings/str_cat.h"
|
|
75
|
-
#include "absl/strings/str_split.h"
|
|
76
83
|
#include "absl/strings/string_view.h"
|
|
77
84
|
|
|
78
85
|
// Name of the environment variable controlling OpenSSL cleanup timeout.
|
|
@@ -101,6 +108,9 @@ const size_t kMaxChainLength = 100;
|
|
|
101
108
|
|
|
102
109
|
using TlsSessionKeyLogger = tsi::TlsSessionKeyLoggerCache::TlsSessionKeyLogger;
|
|
103
110
|
|
|
111
|
+
using tsi::PrivateKey;
|
|
112
|
+
using tsi::RootCertInfo;
|
|
113
|
+
|
|
104
114
|
// --- Structure definitions. ---
|
|
105
115
|
|
|
106
116
|
struct tsi_ssl_root_certs_store {
|
|
@@ -110,8 +120,14 @@ struct tsi_ssl_root_certs_store {
|
|
|
110
120
|
struct tsi_ssl_handshaker_factory {
|
|
111
121
|
const tsi_ssl_handshaker_factory_vtable* vtable;
|
|
112
122
|
gpr_refcount refcount;
|
|
123
|
+
#if defined(OPENSSL_IS_BORINGSSL)
|
|
124
|
+
std::shared_ptr<grpc_core::PrivateKeySigner> key_signer;
|
|
125
|
+
#endif
|
|
113
126
|
};
|
|
114
127
|
|
|
128
|
+
static void tsi_ssl_handshaker_factory_unref(
|
|
129
|
+
tsi_ssl_handshaker_factory* factory);
|
|
130
|
+
|
|
115
131
|
struct tsi_ssl_client_handshaker_factory {
|
|
116
132
|
tsi_ssl_handshaker_factory base;
|
|
117
133
|
SSL_CTX* ssl_context;
|
|
@@ -119,7 +135,7 @@ struct tsi_ssl_client_handshaker_factory {
|
|
|
119
135
|
size_t alpn_protocol_list_length;
|
|
120
136
|
grpc_core::RefCountedPtr<tsi::SslSessionLRUCache> session_cache;
|
|
121
137
|
grpc_core::RefCountedPtr<TlsSessionKeyLogger> key_logger;
|
|
122
|
-
std::shared_ptr<RootCertInfo> root_cert_info;
|
|
138
|
+
std::shared_ptr<tsi::RootCertInfo> root_cert_info;
|
|
123
139
|
};
|
|
124
140
|
|
|
125
141
|
struct tsi_ssl_server_handshaker_factory {
|
|
@@ -133,18 +149,67 @@ struct tsi_ssl_server_handshaker_factory {
|
|
|
133
149
|
unsigned char* alpn_protocol_list;
|
|
134
150
|
size_t alpn_protocol_list_length;
|
|
135
151
|
grpc_core::RefCountedPtr<TlsSessionKeyLogger> key_logger;
|
|
136
|
-
std::shared_ptr<RootCertInfo> root_cert_info;
|
|
152
|
+
std::shared_ptr<tsi::RootCertInfo> root_cert_info;
|
|
137
153
|
};
|
|
138
154
|
|
|
139
|
-
|
|
140
|
-
|
|
155
|
+
// Tracks the arguments for a pending call to tsi_handshaker_next().
|
|
156
|
+
struct HandshakerNextArgs {
|
|
157
|
+
// Input args.
|
|
158
|
+
std::vector<uint8_t> received_bytes;
|
|
159
|
+
size_t original_received_bytes_size = 0;
|
|
160
|
+
tsi_handshaker_on_next_done_cb cb;
|
|
161
|
+
void* user_data;
|
|
162
|
+
std::string* error_ptr = nullptr;
|
|
163
|
+
|
|
164
|
+
// Output args.
|
|
165
|
+
const unsigned char* bytes_to_send = nullptr;
|
|
166
|
+
size_t bytes_to_send_size = 0;
|
|
167
|
+
tsi_handshaker_result* handshaker_result = nullptr;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
struct tsi_ssl_handshaker : public tsi_handshaker,
|
|
171
|
+
public grpc_core::RefCounted<tsi_ssl_handshaker> {
|
|
172
|
+
tsi_ssl_handshaker() = default;
|
|
173
|
+
~tsi_ssl_handshaker() override {
|
|
174
|
+
SSL_free(ssl);
|
|
175
|
+
BIO_free(network_io);
|
|
176
|
+
gpr_free(outgoing_bytes_buffer);
|
|
177
|
+
tsi_ssl_handshaker_factory_unref(factory_ref);
|
|
178
|
+
}
|
|
179
|
+
|
|
141
180
|
SSL* ssl;
|
|
142
181
|
BIO* network_io;
|
|
143
182
|
tsi_result result;
|
|
144
183
|
unsigned char* outgoing_bytes_buffer;
|
|
145
184
|
size_t outgoing_bytes_buffer_size;
|
|
146
185
|
tsi_ssl_handshaker_factory* factory_ref;
|
|
186
|
+
grpc_core::Mutex mu;
|
|
187
|
+
bool is_shutdown ABSL_GUARDED_BY(mu) = false;
|
|
188
|
+
|
|
189
|
+
// Will be set if there is a pending call to tsi_handshaker_next(),
|
|
190
|
+
// or nullopt if not.
|
|
191
|
+
std::optional<HandshakerNextArgs> handshaker_next_args ABSL_GUARDED_BY(mu);
|
|
192
|
+
void MaybeSetError(std::string error) const
|
|
193
|
+
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&mu) {
|
|
194
|
+
if (!handshaker_next_args.has_value()) return;
|
|
195
|
+
if (handshaker_next_args->error_ptr == nullptr) return;
|
|
196
|
+
*handshaker_next_args->error_ptr = std::move(error);
|
|
197
|
+
}
|
|
198
|
+
#if defined(OPENSSL_IS_BORINGSSL)
|
|
199
|
+
// The signed_bytes are populated when the signature process is completed if
|
|
200
|
+
// the Private Key offload was successful. If there was an error during the
|
|
201
|
+
// signature, the status will be returned.
|
|
202
|
+
absl::StatusOr<std::string> signed_bytes ABSL_GUARDED_BY(mu) = "";
|
|
203
|
+
// The handle for an in-flight async signing operation.
|
|
204
|
+
std::shared_ptr<grpc_core::PrivateKeySigner::AsyncSigningHandle>
|
|
205
|
+
signing_handle ABSL_GUARDED_BY(mu);
|
|
206
|
+
#endif
|
|
147
207
|
};
|
|
208
|
+
|
|
209
|
+
static std::pair<tsi_result, std::optional<HandshakerNextArgs>>
|
|
210
|
+
ssl_handshaker_next_async(tsi_ssl_handshaker* self)
|
|
211
|
+
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&tsi_ssl_handshaker::mu);
|
|
212
|
+
|
|
148
213
|
struct tsi_ssl_handshaker_result {
|
|
149
214
|
tsi_handshaker_result base;
|
|
150
215
|
SSL* ssl;
|
|
@@ -163,9 +228,43 @@ struct tsi_ssl_frame_protector {
|
|
|
163
228
|
// concurrently.
|
|
164
229
|
gpr_mu mu;
|
|
165
230
|
};
|
|
166
|
-
// --- Library Initialization. ---
|
|
167
231
|
|
|
168
232
|
namespace {
|
|
233
|
+
|
|
234
|
+
// --- Library Initialization. ---
|
|
235
|
+
|
|
236
|
+
#if defined(OPENSSL_IS_BORINGSSL)
|
|
237
|
+
|
|
238
|
+
absl::StatusOr<grpc_core::PrivateKeySigner::SignatureAlgorithm>
|
|
239
|
+
ToSignatureAlgorithmClass(uint16_t algorithm) {
|
|
240
|
+
switch (algorithm) {
|
|
241
|
+
case SSL_SIGN_RSA_PKCS1_SHA256:
|
|
242
|
+
return grpc_core::PrivateKeySigner::SignatureAlgorithm::kRsaPkcs1Sha256;
|
|
243
|
+
case SSL_SIGN_RSA_PKCS1_SHA384:
|
|
244
|
+
return grpc_core::PrivateKeySigner::SignatureAlgorithm::kRsaPkcs1Sha384;
|
|
245
|
+
case SSL_SIGN_RSA_PKCS1_SHA512:
|
|
246
|
+
return grpc_core::PrivateKeySigner::SignatureAlgorithm::kRsaPkcs1Sha512;
|
|
247
|
+
case SSL_SIGN_ECDSA_SECP256R1_SHA256:
|
|
248
|
+
return grpc_core::PrivateKeySigner::SignatureAlgorithm::
|
|
249
|
+
kEcdsaSecp256r1Sha256;
|
|
250
|
+
case SSL_SIGN_ECDSA_SECP384R1_SHA384:
|
|
251
|
+
return grpc_core::PrivateKeySigner::SignatureAlgorithm::
|
|
252
|
+
kEcdsaSecp384r1Sha384;
|
|
253
|
+
case SSL_SIGN_ECDSA_SECP521R1_SHA512:
|
|
254
|
+
return grpc_core::PrivateKeySigner::SignatureAlgorithm::
|
|
255
|
+
kEcdsaSecp521r1Sha512;
|
|
256
|
+
case SSL_SIGN_RSA_PSS_RSAE_SHA256:
|
|
257
|
+
return grpc_core::PrivateKeySigner::SignatureAlgorithm::kRsaPssRsaeSha256;
|
|
258
|
+
case SSL_SIGN_RSA_PSS_RSAE_SHA384:
|
|
259
|
+
return grpc_core::PrivateKeySigner::SignatureAlgorithm::kRsaPssRsaeSha384;
|
|
260
|
+
case SSL_SIGN_RSA_PSS_RSAE_SHA512:
|
|
261
|
+
return grpc_core::PrivateKeySigner::SignatureAlgorithm::kRsaPssRsaeSha512;
|
|
262
|
+
}
|
|
263
|
+
return absl::InvalidArgumentError("Unknown signature algorithm.");
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
#endif // OPENSSL_IS_BORINGSSL
|
|
267
|
+
|
|
169
268
|
// Builds the alpn protocol name list according to rfc 7301.
|
|
170
269
|
// OpenSSL requires <const char**> for the input to the alpn methods.
|
|
171
270
|
tsi_result BuildAlpnProtocolNameList(const char** alpn_protocols,
|
|
@@ -256,6 +355,122 @@ static int g_ssl_ctx_ex_crl_provider_index = -1;
|
|
|
256
355
|
static int g_ssl_ctx_ex_spiffe_bundle_map_index = -1;
|
|
257
356
|
static const unsigned char kSslSessionIdContext[] = {'g', 'r', 'p', 'c'};
|
|
258
357
|
static int g_ssl_ex_verified_root_cert_index = -1;
|
|
358
|
+
static int g_ssl_ex_handshaker_index = -1;
|
|
359
|
+
|
|
360
|
+
#if defined(OPENSSL_IS_BORINGSSL)
|
|
361
|
+
static tsi_ssl_handshaker* GetHandshaker(const SSL* ssl) {
|
|
362
|
+
if (ssl == nullptr) return nullptr;
|
|
363
|
+
GRPC_CHECK_NE(g_ssl_ex_handshaker_index, -1);
|
|
364
|
+
return static_cast<tsi_ssl_handshaker*>(
|
|
365
|
+
SSL_get_ex_data(ssl, g_ssl_ex_handshaker_index));
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// Invoked by the private key signer when it runs asynchronously.
|
|
369
|
+
void TlsOffloadSignDoneCallback(
|
|
370
|
+
grpc_core::RefCountedPtr<tsi_ssl_handshaker> handshaker,
|
|
371
|
+
absl::StatusOr<std::string> signed_data) {
|
|
372
|
+
grpc_core::ExecCtx exec_ctx;
|
|
373
|
+
std::optional<HandshakerNextArgs> next_args;
|
|
374
|
+
tsi_result result = TSI_INTERNAL_ERROR;
|
|
375
|
+
{
|
|
376
|
+
grpc_core::MutexLock lock(&handshaker->mu);
|
|
377
|
+
if (handshaker->is_shutdown) return;
|
|
378
|
+
handshaker->signed_bytes = std::move(signed_data);
|
|
379
|
+
handshaker->signing_handle.reset();
|
|
380
|
+
// Once the signed bytes are obtained, tell everything to resume the
|
|
381
|
+
// pending async operation.
|
|
382
|
+
auto async_result = ssl_handshaker_next_async(handshaker.get());
|
|
383
|
+
result = async_result.first;
|
|
384
|
+
next_args = std::move(async_result.second);
|
|
385
|
+
}
|
|
386
|
+
if (next_args.has_value() && next_args->cb != nullptr) {
|
|
387
|
+
next_args->cb(result, next_args->user_data, next_args->bytes_to_send,
|
|
388
|
+
next_args->bytes_to_send_size, next_args->handshaker_result);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// Invoked by BoringSSL to get the result of the private key signing.
|
|
393
|
+
enum ssl_private_key_result_t TlsPrivateKeyOffloadComplete(SSL* ssl,
|
|
394
|
+
uint8_t* out,
|
|
395
|
+
size_t* out_len,
|
|
396
|
+
size_t max_out)
|
|
397
|
+
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&tsi_ssl_handshaker::mu) {
|
|
398
|
+
auto* handshaker = GetHandshaker(ssl);
|
|
399
|
+
if (handshaker == nullptr) return ssl_private_key_failure;
|
|
400
|
+
if (!handshaker->signed_bytes.ok() || handshaker->signed_bytes->empty()) {
|
|
401
|
+
if (!handshaker->signed_bytes.ok()) {
|
|
402
|
+
handshaker->MaybeSetError(handshaker->signed_bytes.status().ToString());
|
|
403
|
+
}
|
|
404
|
+
return ssl_private_key_failure;
|
|
405
|
+
}
|
|
406
|
+
// Important bit is moving the signed data where it needs to go
|
|
407
|
+
const std::string& signed_data = *handshaker->signed_bytes;
|
|
408
|
+
if (signed_data.length() > max_out) {
|
|
409
|
+
// Result is too large.
|
|
410
|
+
handshaker->MaybeSetError("Result exceeds output limit");
|
|
411
|
+
return ssl_private_key_failure;
|
|
412
|
+
}
|
|
413
|
+
memcpy(out, signed_data.data(), signed_data.length());
|
|
414
|
+
*out_len = signed_data.length();
|
|
415
|
+
// Tell BoringSSL we're done
|
|
416
|
+
return ssl_private_key_success;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// Invoked by BoringSSL during the handshake to do private key signing.
|
|
420
|
+
enum ssl_private_key_result_t TlsPrivateKeySignWrapper(
|
|
421
|
+
SSL* ssl, uint8_t* out, size_t* out_len, size_t max_out,
|
|
422
|
+
uint16_t signature_algorithm, const uint8_t* in, size_t in_len)
|
|
423
|
+
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&tsi_ssl_handshaker::mu) {
|
|
424
|
+
tsi_ssl_handshaker* handshaker = GetHandshaker(ssl);
|
|
425
|
+
if (handshaker == nullptr) {
|
|
426
|
+
return ssl_private_key_failure;
|
|
427
|
+
}
|
|
428
|
+
if (handshaker->is_shutdown) {
|
|
429
|
+
handshaker->MaybeSetError("Handshaker is shuting down");
|
|
430
|
+
return ssl_private_key_failure;
|
|
431
|
+
}
|
|
432
|
+
// Create the completion callback by binding the current context.
|
|
433
|
+
auto done_callback =
|
|
434
|
+
absl::bind_front(TlsOffloadSignDoneCallback, handshaker->Ref());
|
|
435
|
+
// Call the user's sign function. It can be sync or async.
|
|
436
|
+
// When the user's sign function is async, the contract is that they MUST
|
|
437
|
+
// invoke the callback when complete in their implementation, and their impl
|
|
438
|
+
// MUST not block.
|
|
439
|
+
auto algorithm = ToSignatureAlgorithmClass(signature_algorithm);
|
|
440
|
+
if (!algorithm.ok()) {
|
|
441
|
+
handshaker->MaybeSetError(algorithm.status().ToString());
|
|
442
|
+
return ssl_private_key_failure;
|
|
443
|
+
}
|
|
444
|
+
grpc_core::PrivateKeySigner* signer =
|
|
445
|
+
handshaker->factory_ref->key_signer.get();
|
|
446
|
+
if (signer == nullptr) {
|
|
447
|
+
handshaker->MaybeSetError("PrivateKeySigner is null");
|
|
448
|
+
return ssl_private_key_failure;
|
|
449
|
+
}
|
|
450
|
+
auto result =
|
|
451
|
+
signer->Sign(absl::string_view(reinterpret_cast<const char*>(in), in_len),
|
|
452
|
+
*algorithm, done_callback);
|
|
453
|
+
// Handle synchronous return.
|
|
454
|
+
return grpc_core::MatchMutable(
|
|
455
|
+
&result,
|
|
456
|
+
[&](absl::StatusOr<std::string>* status_or_string)
|
|
457
|
+
ABSL_NO_THREAD_SAFETY_ANALYSIS {
|
|
458
|
+
handshaker->signed_bytes = std::move(*status_or_string);
|
|
459
|
+
return TlsPrivateKeyOffloadComplete(ssl, out, out_len, max_out);
|
|
460
|
+
},
|
|
461
|
+
[&](std::shared_ptr<grpc_core::PrivateKeySigner::AsyncSigningHandle>*
|
|
462
|
+
async_handler) ABSL_NO_THREAD_SAFETY_ANALYSIS {
|
|
463
|
+
handshaker->signing_handle = std::move(*async_handler);
|
|
464
|
+
return ssl_private_key_retry;
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
const SSL_PRIVATE_KEY_METHOD TlsOffloadPrivateKeyMethod = {
|
|
469
|
+
TlsPrivateKeySignWrapper,
|
|
470
|
+
nullptr, // decrypt not implemented for this use case
|
|
471
|
+
TlsPrivateKeyOffloadComplete};
|
|
472
|
+
#endif // defined(OPENSSL_IS_BORINGSSL)
|
|
473
|
+
|
|
259
474
|
#if !defined(OPENSSL_IS_BORINGSSL) && !defined(OPENSSL_NO_ENGINE)
|
|
260
475
|
static const char kSslEnginePrefix[] = "engine:";
|
|
261
476
|
#endif
|
|
@@ -351,8 +566,11 @@ static void init_openssl(void) {
|
|
|
351
566
|
g_ssl_ex_verified_root_cert_index = SSL_get_ex_new_index(
|
|
352
567
|
0, nullptr, nullptr, nullptr, verified_root_cert_free);
|
|
353
568
|
GRPC_CHECK_NE(g_ssl_ex_verified_root_cert_index, -1);
|
|
354
|
-
}
|
|
355
569
|
|
|
570
|
+
g_ssl_ex_handshaker_index =
|
|
571
|
+
SSL_get_ex_new_index(0, nullptr, nullptr, nullptr, nullptr);
|
|
572
|
+
GRPC_CHECK_NE(g_ssl_ex_handshaker_index, -1);
|
|
573
|
+
}
|
|
356
574
|
// --- Ssl utils. ---
|
|
357
575
|
|
|
358
576
|
// TODO(jboeuf): Remove when we are past the debugging phase with this code.
|
|
@@ -918,21 +1136,40 @@ static tsi_result populate_ssl_context(
|
|
|
918
1136
|
const char* cipher_list) {
|
|
919
1137
|
tsi_result result = TSI_OK;
|
|
920
1138
|
if (key_cert_pair != nullptr) {
|
|
921
|
-
if (key_cert_pair->cert_chain
|
|
922
|
-
result = ssl_ctx_use_certificate_chain(
|
|
923
|
-
|
|
1139
|
+
if (!key_cert_pair->cert_chain.empty()) {
|
|
1140
|
+
result = ssl_ctx_use_certificate_chain(
|
|
1141
|
+
context, key_cert_pair->cert_chain.c_str(),
|
|
1142
|
+
key_cert_pair->cert_chain.length());
|
|
924
1143
|
if (result != TSI_OK) {
|
|
925
1144
|
LOG(ERROR) << "Invalid cert chain file.";
|
|
926
1145
|
return result;
|
|
927
1146
|
}
|
|
928
1147
|
}
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
1148
|
+
result = grpc_core::Match(
|
|
1149
|
+
key_cert_pair->private_key,
|
|
1150
|
+
[&](const std::string& pem_root_certs) {
|
|
1151
|
+
tsi_result result = TSI_OK;
|
|
1152
|
+
result = ssl_ctx_use_private_key(context, pem_root_certs.data(),
|
|
1153
|
+
pem_root_certs.length());
|
|
1154
|
+
if (result != TSI_OK || !SSL_CTX_check_private_key(context)) {
|
|
1155
|
+
LOG(ERROR) << "Invalid private key.";
|
|
1156
|
+
return result != TSI_OK ? result : TSI_INVALID_ARGUMENT;
|
|
1157
|
+
}
|
|
1158
|
+
return result;
|
|
1159
|
+
},
|
|
1160
|
+
[&](const std::shared_ptr<grpc_core::PrivateKeySigner>& key_signer) {
|
|
1161
|
+
#if defined(OPENSSL_IS_BORINGSSL)
|
|
1162
|
+
if (key_signer != nullptr) {
|
|
1163
|
+
SSL_CTX_set_private_key_method(context,
|
|
1164
|
+
&TlsOffloadPrivateKeyMethod);
|
|
1165
|
+
}
|
|
1166
|
+
return TSI_OK;
|
|
1167
|
+
#else
|
|
1168
|
+
return TSI_UNIMPLEMENTED;
|
|
1169
|
+
#endif // defined(OPENSSL_IS_BORINGSSL)
|
|
1170
|
+
});
|
|
1171
|
+
if (result != TSI_OK) {
|
|
1172
|
+
return result;
|
|
936
1173
|
}
|
|
937
1174
|
}
|
|
938
1175
|
if ((cipher_list != nullptr) &&
|
|
@@ -1100,12 +1337,12 @@ static absl::StatusOr<X509_CRL*> GetCrlFromProvider(
|
|
|
1100
1337
|
if (provider == nullptr) {
|
|
1101
1338
|
return absl::InvalidArgumentError("CrlProvider is null.");
|
|
1102
1339
|
}
|
|
1103
|
-
absl::StatusOr<std::string> issuer_name =
|
|
1340
|
+
absl::StatusOr<std::string> issuer_name = tsi::IssuerFromCert(cert);
|
|
1104
1341
|
if (!issuer_name.ok()) {
|
|
1105
1342
|
GRPC_TRACE_LOG(tsi, INFO) << "Could not get certificate issuer name";
|
|
1106
1343
|
return absl::InvalidArgumentError(issuer_name.status().message());
|
|
1107
1344
|
}
|
|
1108
|
-
absl::StatusOr<std::string> akid =
|
|
1345
|
+
absl::StatusOr<std::string> akid = tsi::AkidFromCertificate(cert);
|
|
1109
1346
|
std::string akid_to_use;
|
|
1110
1347
|
if (!akid.ok()) {
|
|
1111
1348
|
GRPC_TRACE_LOG(tsi, INFO)
|
|
@@ -1140,12 +1377,12 @@ static bool ValidateCrl(X509* cert, X509* issuer, X509_CRL* crl) {
|
|
|
1140
1377
|
// RFC5280 6.3.3
|
|
1141
1378
|
// 6.3.3a we do not support distribution points
|
|
1142
1379
|
// 6.3.3b verify issuer and scope
|
|
1143
|
-
valid =
|
|
1380
|
+
valid = tsi::VerifyCrlCertIssuerNamesMatch(crl, cert);
|
|
1144
1381
|
if (!valid) {
|
|
1145
1382
|
VLOG(2) << "CRL and cert issuer names mismatched.";
|
|
1146
1383
|
return valid;
|
|
1147
1384
|
}
|
|
1148
|
-
valid =
|
|
1385
|
+
valid = tsi::HasCrlSignBit(issuer);
|
|
1149
1386
|
if (!valid) {
|
|
1150
1387
|
VLOG(2) << "CRL issuer not allowed to sign CRLs.";
|
|
1151
1388
|
return valid;
|
|
@@ -1156,7 +1393,7 @@ static bool ValidateCrl(X509* cert, X509* issuer, X509_CRL* crl) {
|
|
|
1156
1393
|
// 6.3.3f We only support direct CRLs so these paths are by definition the
|
|
1157
1394
|
// same.
|
|
1158
1395
|
// 6.3.3g Verify CRL Signature
|
|
1159
|
-
valid =
|
|
1396
|
+
valid = tsi::VerifyCrlSignature(crl, issuer);
|
|
1160
1397
|
if (!valid) {
|
|
1161
1398
|
VLOG(2) << "Crl signature check failed.";
|
|
1162
1399
|
}
|
|
@@ -1287,7 +1524,7 @@ static absl::StatusOr<std::string> GetSpiffeUriFromCert(X509* cert) {
|
|
|
1287
1524
|
"validation. Must "
|
|
1288
1525
|
"have exactly one URI SAN that is the SPIFFE ID.");
|
|
1289
1526
|
}
|
|
1290
|
-
spiffe_uri =
|
|
1527
|
+
spiffe_uri = tsi::ParseUriString(subject_alt_name);
|
|
1291
1528
|
}
|
|
1292
1529
|
}
|
|
1293
1530
|
}
|
|
@@ -1509,7 +1746,7 @@ static tsi_result ssl_protector_protect(tsi_frame_protector* self,
|
|
|
1509
1746
|
tsi_ssl_frame_protector* impl =
|
|
1510
1747
|
reinterpret_cast<tsi_ssl_frame_protector*>(self);
|
|
1511
1748
|
gpr_mu_lock(&impl->mu);
|
|
1512
|
-
tsi_result result =
|
|
1749
|
+
tsi_result result = tsi::SslProtectorProtect(
|
|
1513
1750
|
unprotected_bytes, impl->buffer_size, impl->buffer_offset, impl->buffer,
|
|
1514
1751
|
impl->ssl, impl->network_io, unprotected_bytes_size,
|
|
1515
1752
|
protected_output_frames, protected_output_frames_size);
|
|
@@ -1523,7 +1760,7 @@ static tsi_result ssl_protector_protect_flush(
|
|
|
1523
1760
|
tsi_ssl_frame_protector* impl =
|
|
1524
1761
|
reinterpret_cast<tsi_ssl_frame_protector*>(self);
|
|
1525
1762
|
gpr_mu_lock(&impl->mu);
|
|
1526
|
-
tsi_result result =
|
|
1763
|
+
tsi_result result = tsi::SslProtectorProtectFlush(
|
|
1527
1764
|
impl->buffer_offset, impl->buffer, impl->ssl, impl->network_io,
|
|
1528
1765
|
protected_output_frames, protected_output_frames_size,
|
|
1529
1766
|
still_pending_size);
|
|
@@ -1538,7 +1775,7 @@ static tsi_result ssl_protector_unprotect(
|
|
|
1538
1775
|
tsi_ssl_frame_protector* impl =
|
|
1539
1776
|
reinterpret_cast<tsi_ssl_frame_protector*>(self);
|
|
1540
1777
|
gpr_mu_lock(&impl->mu);
|
|
1541
|
-
tsi_result result =
|
|
1778
|
+
tsi_result result = tsi::SslProtectorUnprotect(
|
|
1542
1779
|
protected_frames_bytes, impl->ssl, impl->network_io,
|
|
1543
1780
|
protected_frames_bytes_size, unprotected_bytes, unprotected_bytes_size);
|
|
1544
1781
|
gpr_mu_unlock(&impl->mu);
|
|
@@ -1791,13 +2028,13 @@ static const tsi_handshaker_result_vtable handshaker_result_vtable = {
|
|
|
1791
2028
|
ssl_handshaker_result_destroy,
|
|
1792
2029
|
};
|
|
1793
2030
|
|
|
1794
|
-
static tsi_result ssl_handshaker_result_create(
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
if (handshaker == nullptr
|
|
1799
|
-
|
|
1800
|
-
|
|
2031
|
+
static tsi_result ssl_handshaker_result_create(tsi_ssl_handshaker* handshaker,
|
|
2032
|
+
unsigned char* unused_bytes,
|
|
2033
|
+
size_t unused_bytes_size)
|
|
2034
|
+
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&tsi_ssl_handshaker::mu) {
|
|
2035
|
+
if (handshaker == nullptr) return TSI_INVALID_ARGUMENT;
|
|
2036
|
+
if (unused_bytes_size > 0 && unused_bytes == nullptr) {
|
|
2037
|
+
handshaker->MaybeSetError("invalid argument");
|
|
1801
2038
|
return TSI_INVALID_ARGUMENT;
|
|
1802
2039
|
}
|
|
1803
2040
|
tsi_ssl_handshaker_result* result =
|
|
@@ -1811,18 +2048,18 @@ static tsi_result ssl_handshaker_result_create(
|
|
|
1811
2048
|
// Transfer ownership of |unused_bytes| to the handshaker result.
|
|
1812
2049
|
result->unused_bytes = unused_bytes;
|
|
1813
2050
|
result->unused_bytes_size = unused_bytes_size;
|
|
1814
|
-
|
|
2051
|
+
handshaker->handshaker_next_args->handshaker_result = &result->base;
|
|
1815
2052
|
return TSI_OK;
|
|
1816
2053
|
}
|
|
1817
2054
|
|
|
1818
2055
|
// --- tsi_handshaker methods implementation. ---
|
|
1819
2056
|
|
|
1820
2057
|
static tsi_result ssl_handshaker_get_bytes_to_send_to_peer(
|
|
1821
|
-
tsi_ssl_handshaker* impl, unsigned char* bytes, size_t* bytes_size
|
|
1822
|
-
|
|
2058
|
+
tsi_ssl_handshaker* impl, unsigned char* bytes, size_t* bytes_size)
|
|
2059
|
+
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&tsi_ssl_handshaker::mu) {
|
|
1823
2060
|
int bytes_read_from_ssl = 0;
|
|
1824
2061
|
if (bytes == nullptr || bytes_size == nullptr || *bytes_size > INT_MAX) {
|
|
1825
|
-
|
|
2062
|
+
impl->MaybeSetError("invalid argument");
|
|
1826
2063
|
return TSI_INVALID_ARGUMENT;
|
|
1827
2064
|
}
|
|
1828
2065
|
GRPC_CHECK_LE(*bytes_size, static_cast<size_t>(INT_MAX));
|
|
@@ -1831,7 +2068,7 @@ static tsi_result ssl_handshaker_get_bytes_to_send_to_peer(
|
|
|
1831
2068
|
if (bytes_read_from_ssl < 0) {
|
|
1832
2069
|
*bytes_size = 0;
|
|
1833
2070
|
if (!BIO_should_retry(impl->network_io)) {
|
|
1834
|
-
|
|
2071
|
+
impl->MaybeSetError("error reading from BIO");
|
|
1835
2072
|
impl->result = TSI_INTERNAL_ERROR;
|
|
1836
2073
|
return impl->result;
|
|
1837
2074
|
} else {
|
|
@@ -1850,8 +2087,8 @@ static tsi_result ssl_handshaker_get_result(tsi_ssl_handshaker* impl) {
|
|
|
1850
2087
|
return impl->result;
|
|
1851
2088
|
}
|
|
1852
2089
|
|
|
1853
|
-
static tsi_result ssl_handshaker_do_handshake(tsi_ssl_handshaker* impl
|
|
1854
|
-
|
|
2090
|
+
static tsi_result ssl_handshaker_do_handshake(tsi_ssl_handshaker* impl)
|
|
2091
|
+
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&tsi_ssl_handshaker::mu) {
|
|
1855
2092
|
if (ssl_handshaker_get_result(impl) != TSI_HANDSHAKE_IN_PROGRESS) {
|
|
1856
2093
|
impl->result = TSI_OK;
|
|
1857
2094
|
return impl->result;
|
|
@@ -1872,6 +2109,10 @@ static tsi_result ssl_handshaker_do_handshake(tsi_ssl_handshaker* impl,
|
|
|
1872
2109
|
return TSI_OK;
|
|
1873
2110
|
case SSL_ERROR_WANT_WRITE:
|
|
1874
2111
|
return TSI_DRAIN_BUFFER;
|
|
2112
|
+
#if defined(OPENSSL_IS_BORINGSSL)
|
|
2113
|
+
case SSL_ERROR_WANT_PRIVATE_KEY_OPERATION:
|
|
2114
|
+
return TSI_ASYNC;
|
|
2115
|
+
#endif
|
|
1875
2116
|
default: {
|
|
1876
2117
|
char err_str[256];
|
|
1877
2118
|
ERR_error_string_n(ERR_get_error(), err_str, sizeof(err_str));
|
|
@@ -1882,12 +2123,16 @@ static tsi_result ssl_handshaker_do_handshake(tsi_ssl_handshaker* impl,
|
|
|
1882
2123
|
verify_result_str = absl::StrCat(": ", verify_err);
|
|
1883
2124
|
}
|
|
1884
2125
|
LOG(INFO) << "Handshake failed with error "
|
|
1885
|
-
<<
|
|
2126
|
+
<< tsi::SslErrorString(ssl_result) << ": " << err_str
|
|
1886
2127
|
<< verify_result_str;
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
2128
|
+
std::string signer_error;
|
|
2129
|
+
#if defined(OPENSSL_IS_BORINGSSL)
|
|
2130
|
+
signer_error =
|
|
2131
|
+
absl::StrCat(": ", impl->signed_bytes.status().ToString());
|
|
2132
|
+
#endif
|
|
2133
|
+
impl->MaybeSetError(absl::StrCat(tsi::SslErrorString(ssl_result), ": ",
|
|
2134
|
+
err_str, verify_result_str,
|
|
2135
|
+
signer_error));
|
|
1891
2136
|
impl->result = TSI_PROTOCOL_FAILURE;
|
|
1892
2137
|
return impl->result;
|
|
1893
2138
|
}
|
|
@@ -1896,11 +2141,11 @@ static tsi_result ssl_handshaker_do_handshake(tsi_ssl_handshaker* impl,
|
|
|
1896
2141
|
}
|
|
1897
2142
|
|
|
1898
2143
|
static tsi_result ssl_handshaker_process_bytes_from_peer(
|
|
1899
|
-
tsi_ssl_handshaker* impl, const unsigned char* bytes, size_t* bytes_size
|
|
1900
|
-
|
|
2144
|
+
tsi_ssl_handshaker* impl, const unsigned char* bytes, size_t* bytes_size)
|
|
2145
|
+
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&tsi_ssl_handshaker::mu) {
|
|
1901
2146
|
int bytes_written_into_ssl_size = 0;
|
|
1902
2147
|
if (bytes == nullptr || bytes_size == nullptr || *bytes_size > INT_MAX) {
|
|
1903
|
-
|
|
2148
|
+
impl->MaybeSetError("invalid argument");
|
|
1904
2149
|
return TSI_INVALID_ARGUMENT;
|
|
1905
2150
|
}
|
|
1906
2151
|
GRPC_CHECK_LE(*bytes_size, static_cast<size_t>(INT_MAX));
|
|
@@ -1908,32 +2153,28 @@ static tsi_result ssl_handshaker_process_bytes_from_peer(
|
|
|
1908
2153
|
BIO_write(impl->network_io, bytes, static_cast<int>(*bytes_size));
|
|
1909
2154
|
if (bytes_written_into_ssl_size < 0) {
|
|
1910
2155
|
LOG(ERROR) << "Could not write to memory BIO.";
|
|
1911
|
-
|
|
2156
|
+
impl->MaybeSetError("could not write to memory BIO");
|
|
1912
2157
|
impl->result = TSI_INTERNAL_ERROR;
|
|
1913
2158
|
return impl->result;
|
|
1914
2159
|
}
|
|
1915
2160
|
*bytes_size = static_cast<size_t>(bytes_written_into_ssl_size);
|
|
1916
|
-
return ssl_handshaker_do_handshake(impl
|
|
2161
|
+
return ssl_handshaker_do_handshake(impl);
|
|
1917
2162
|
}
|
|
1918
2163
|
|
|
1919
2164
|
static void ssl_handshaker_destroy(tsi_handshaker* self) {
|
|
1920
|
-
tsi_ssl_handshaker* impl =
|
|
1921
|
-
|
|
1922
|
-
BIO_free(impl->network_io);
|
|
1923
|
-
gpr_free(impl->outgoing_bytes_buffer);
|
|
1924
|
-
tsi_ssl_handshaker_factory_unref(impl->factory_ref);
|
|
1925
|
-
gpr_free(impl);
|
|
2165
|
+
tsi_ssl_handshaker* impl = static_cast<tsi_ssl_handshaker*>(self);
|
|
2166
|
+
impl->Unref();
|
|
1926
2167
|
}
|
|
1927
2168
|
|
|
1928
2169
|
// Removes the bytes remaining in |impl->SSL|'s read BIO and writes them to
|
|
1929
2170
|
// |bytes_remaining|.
|
|
1930
2171
|
static tsi_result ssl_bytes_remaining(tsi_ssl_handshaker* impl,
|
|
1931
2172
|
unsigned char** bytes_remaining,
|
|
1932
|
-
size_t* bytes_remaining_size
|
|
1933
|
-
|
|
1934
|
-
if (impl == nullptr
|
|
1935
|
-
|
|
1936
|
-
|
|
2173
|
+
size_t* bytes_remaining_size)
|
|
2174
|
+
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&tsi_ssl_handshaker::mu) {
|
|
2175
|
+
if (impl == nullptr) return TSI_INVALID_ARGUMENT;
|
|
2176
|
+
if (bytes_remaining == nullptr || bytes_remaining_size == nullptr) {
|
|
2177
|
+
impl->MaybeSetError("invalid argument");
|
|
1937
2178
|
return TSI_INVALID_ARGUMENT;
|
|
1938
2179
|
}
|
|
1939
2180
|
// Attempt to read all of the bytes in SSL's read BIO. These bytes should
|
|
@@ -1951,9 +2192,8 @@ static tsi_result ssl_bytes_remaining(tsi_ssl_handshaker* impl,
|
|
|
1951
2192
|
<< "Failed to read the expected number of bytes from SSL object.";
|
|
1952
2193
|
gpr_free(*bytes_remaining);
|
|
1953
2194
|
*bytes_remaining = nullptr;
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
}
|
|
2195
|
+
impl->MaybeSetError(
|
|
2196
|
+
"Failed to read the expected number of bytes from SSL object.");
|
|
1957
2197
|
return TSI_INTERNAL_ERROR;
|
|
1958
2198
|
}
|
|
1959
2199
|
*bytes_remaining_size = static_cast<size_t>(bytes_read);
|
|
@@ -1964,16 +2204,15 @@ static tsi_result ssl_bytes_remaining(tsi_ssl_handshaker* impl,
|
|
|
1964
2204
|
// By doing that, we drain SSL bio buffer used to hold handshake data.
|
|
1965
2205
|
// This API needs to be repeatedly called until all handshake data are
|
|
1966
2206
|
// received from SSL.
|
|
1967
|
-
static tsi_result ssl_handshaker_write_output_buffer(
|
|
1968
|
-
size_t* bytes_written
|
|
1969
|
-
|
|
1970
|
-
tsi_ssl_handshaker* impl = reinterpret_cast<tsi_ssl_handshaker*>(self);
|
|
2207
|
+
static tsi_result ssl_handshaker_write_output_buffer(tsi_ssl_handshaker* impl,
|
|
2208
|
+
size_t* bytes_written)
|
|
2209
|
+
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&tsi_ssl_handshaker::mu) {
|
|
1971
2210
|
tsi_result status = TSI_OK;
|
|
1972
2211
|
size_t offset = *bytes_written;
|
|
1973
2212
|
do {
|
|
1974
2213
|
size_t to_send_size = impl->outgoing_bytes_buffer_size - offset;
|
|
1975
2214
|
status = ssl_handshaker_get_bytes_to_send_to_peer(
|
|
1976
|
-
impl, impl->outgoing_bytes_buffer + offset, &to_send_size
|
|
2215
|
+
impl, impl->outgoing_bytes_buffer + offset, &to_send_size);
|
|
1977
2216
|
offset += to_send_size;
|
|
1978
2217
|
if (status == TSI_INCOMPLETE_DATA) {
|
|
1979
2218
|
impl->outgoing_bytes_buffer_size *= 2;
|
|
@@ -1985,28 +2224,17 @@ static tsi_result ssl_handshaker_write_output_buffer(tsi_handshaker* self,
|
|
|
1985
2224
|
return status;
|
|
1986
2225
|
}
|
|
1987
2226
|
|
|
1988
|
-
static tsi_result
|
|
1989
|
-
|
|
1990
|
-
size_t received_bytes_size,
|
|
1991
|
-
const unsigned char** bytes_to_send,
|
|
1992
|
-
size_t* bytes_to_send_size,
|
|
1993
|
-
tsi_handshaker_result** handshaker_result,
|
|
1994
|
-
tsi_handshaker_on_next_done_cb /*cb*/,
|
|
1995
|
-
void* /*user_data*/, std::string* error) {
|
|
1996
|
-
// Input sanity check.
|
|
1997
|
-
if ((received_bytes_size > 0 && received_bytes == nullptr) ||
|
|
1998
|
-
bytes_to_send == nullptr || bytes_to_send_size == nullptr ||
|
|
1999
|
-
handshaker_result == nullptr) {
|
|
2000
|
-
if (error != nullptr) *error = "invalid argument";
|
|
2001
|
-
return TSI_INVALID_ARGUMENT;
|
|
2002
|
-
}
|
|
2227
|
+
static tsi_result ssl_handshaker_next_impl(tsi_ssl_handshaker* self)
|
|
2228
|
+
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&tsi_ssl_handshaker::mu) {
|
|
2003
2229
|
// If there are received bytes, process them first.
|
|
2004
|
-
tsi_ssl_handshaker* impl = reinterpret_cast<tsi_ssl_handshaker*>(self);
|
|
2005
2230
|
tsi_result status = TSI_OK;
|
|
2006
2231
|
size_t bytes_written = 0;
|
|
2007
|
-
if (
|
|
2008
|
-
|
|
2009
|
-
|
|
2232
|
+
if (!self->handshaker_next_args->received_bytes.empty()) {
|
|
2233
|
+
size_t received_bytes_size =
|
|
2234
|
+
self->handshaker_next_args->received_bytes.size();
|
|
2235
|
+
unsigned char* received_bytes =
|
|
2236
|
+
self->handshaker_next_args->received_bytes.data();
|
|
2237
|
+
unsigned char* remaining_bytes_to_write_to_openssl = received_bytes;
|
|
2010
2238
|
size_t remaining_bytes_to_write_to_openssl_size = received_bytes_size;
|
|
2011
2239
|
size_t number_bio_write_attempts = 0;
|
|
2012
2240
|
while (remaining_bytes_to_write_to_openssl_size > 0 &&
|
|
@@ -2017,32 +2245,55 @@ static tsi_result ssl_handshaker_next(tsi_handshaker* self,
|
|
|
2017
2245
|
size_t bytes_written_to_openssl =
|
|
2018
2246
|
remaining_bytes_to_write_to_openssl_size;
|
|
2019
2247
|
status = ssl_handshaker_process_bytes_from_peer(
|
|
2020
|
-
|
|
2021
|
-
error);
|
|
2248
|
+
self, remaining_bytes_to_write_to_openssl, &bytes_written_to_openssl);
|
|
2022
2249
|
// As long as the BIO is full, drive the SSL handshake to consume bytes
|
|
2023
2250
|
// from the BIO. If the SSL handshake returns any bytes, write them to
|
|
2024
2251
|
// the peer.
|
|
2025
2252
|
while (status == TSI_DRAIN_BUFFER) {
|
|
2026
|
-
status =
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2253
|
+
status = ssl_handshaker_write_output_buffer(self, &bytes_written);
|
|
2254
|
+
if (status != TSI_OK) {
|
|
2255
|
+
return status;
|
|
2256
|
+
}
|
|
2257
|
+
status = ssl_handshaker_do_handshake(self);
|
|
2030
2258
|
}
|
|
2031
2259
|
// Move the pointer to the first byte not yet successfully written to
|
|
2032
2260
|
// the BIO.
|
|
2033
2261
|
remaining_bytes_to_write_to_openssl_size -= bytes_written_to_openssl;
|
|
2034
2262
|
remaining_bytes_to_write_to_openssl += bytes_written_to_openssl;
|
|
2035
2263
|
}
|
|
2264
|
+
// Update the received_bytes in handshaker_next_args.
|
|
2265
|
+
if (remaining_bytes_to_write_to_openssl_size > 0) {
|
|
2266
|
+
size_t bytes_to_remove =
|
|
2267
|
+
self->handshaker_next_args->received_bytes.size() -
|
|
2268
|
+
remaining_bytes_to_write_to_openssl_size;
|
|
2269
|
+
self->handshaker_next_args->received_bytes.erase(
|
|
2270
|
+
self->handshaker_next_args->received_bytes.begin(),
|
|
2271
|
+
self->handshaker_next_args->received_bytes.begin() + bytes_to_remove);
|
|
2272
|
+
} else {
|
|
2273
|
+
self->handshaker_next_args->received_bytes.clear();
|
|
2274
|
+
}
|
|
2275
|
+
#if defined(OPENSSL_IS_BORINGSSL)
|
|
2276
|
+
} else if (self->factory_ref->key_signer != nullptr) {
|
|
2277
|
+
// During the PrivateKeyOffload signature, an empty call to
|
|
2278
|
+
// ssl_handshaker_do_handshake needs to be forced after the async offload
|
|
2279
|
+
// has completed.
|
|
2280
|
+
status = ssl_handshaker_do_handshake(self);
|
|
2281
|
+
#endif
|
|
2282
|
+
}
|
|
2283
|
+
|
|
2284
|
+
if (status != TSI_OK) {
|
|
2285
|
+
return status;
|
|
2036
2286
|
}
|
|
2037
|
-
if (status != TSI_OK) return status;
|
|
2038
2287
|
// Get bytes to send to the peer, if available.
|
|
2039
|
-
status = ssl_handshaker_write_output_buffer(self, &bytes_written
|
|
2040
|
-
if (status != TSI_OK)
|
|
2041
|
-
|
|
2042
|
-
|
|
2288
|
+
status = ssl_handshaker_write_output_buffer(self, &bytes_written);
|
|
2289
|
+
if (status != TSI_OK) {
|
|
2290
|
+
return status;
|
|
2291
|
+
}
|
|
2292
|
+
self->handshaker_next_args->bytes_to_send = self->outgoing_bytes_buffer;
|
|
2293
|
+
self->handshaker_next_args->bytes_to_send_size = bytes_written;
|
|
2043
2294
|
// If handshake completes, create tsi_handshaker_result.
|
|
2044
|
-
if (ssl_handshaker_get_result(
|
|
2045
|
-
|
|
2295
|
+
if (ssl_handshaker_get_result(self) == TSI_HANDSHAKE_IN_PROGRESS) {
|
|
2296
|
+
self->handshaker_next_args->handshaker_result = nullptr;
|
|
2046
2297
|
} else {
|
|
2047
2298
|
// Any bytes that remain in |impl->ssl|'s read BIO after the handshake is
|
|
2048
2299
|
// complete must be extracted and set to the unused bytes of the
|
|
@@ -2050,17 +2301,19 @@ static tsi_result ssl_handshaker_next(tsi_handshaker* self,
|
|
|
2050
2301
|
// bytes from the peer that must be processed.
|
|
2051
2302
|
unsigned char* unused_bytes = nullptr;
|
|
2052
2303
|
size_t unused_bytes_size = 0;
|
|
2053
|
-
status =
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2304
|
+
status = ssl_bytes_remaining(self, &unused_bytes, &unused_bytes_size);
|
|
2305
|
+
if (status != TSI_OK) {
|
|
2306
|
+
return status;
|
|
2307
|
+
}
|
|
2308
|
+
if (unused_bytes_size >
|
|
2309
|
+
self->handshaker_next_args->original_received_bytes_size) {
|
|
2057
2310
|
LOG(ERROR) << "More unused bytes than received bytes.";
|
|
2058
2311
|
gpr_free(unused_bytes);
|
|
2059
|
-
|
|
2312
|
+
self->MaybeSetError("More unused bytes than received bytes.");
|
|
2060
2313
|
return TSI_INTERNAL_ERROR;
|
|
2061
2314
|
}
|
|
2062
|
-
status =
|
|
2063
|
-
|
|
2315
|
+
status =
|
|
2316
|
+
ssl_handshaker_result_create(self, unused_bytes, unused_bytes_size);
|
|
2064
2317
|
if (status == TSI_OK) {
|
|
2065
2318
|
// Indicates that the handshake has completed and that a
|
|
2066
2319
|
// handshaker_result has been created.
|
|
@@ -2068,7 +2321,8 @@ static tsi_result ssl_handshaker_next(tsi_handshaker* self,
|
|
|
2068
2321
|
// Output Cipher information
|
|
2069
2322
|
if (GRPC_TRACE_FLAG_ENABLED(tsi)) {
|
|
2070
2323
|
tsi_ssl_handshaker_result* result =
|
|
2071
|
-
reinterpret_cast<tsi_ssl_handshaker_result*>(
|
|
2324
|
+
reinterpret_cast<tsi_ssl_handshaker_result*>(
|
|
2325
|
+
self->handshaker_next_args->handshaker_result);
|
|
2072
2326
|
auto cipher = SSL_get_current_cipher(result->ssl);
|
|
2073
2327
|
if (cipher != nullptr) {
|
|
2074
2328
|
GRPC_TRACE_LOG(tsi, INFO) << absl::StrFormat(
|
|
@@ -2081,6 +2335,104 @@ static tsi_result ssl_handshaker_next(tsi_handshaker* self,
|
|
|
2081
2335
|
return status;
|
|
2082
2336
|
}
|
|
2083
2337
|
|
|
2338
|
+
// Wrapper for ssl_handshaker_next_impl() when called from an async callback.
|
|
2339
|
+
// For example, this would be called from the key signer's callback.
|
|
2340
|
+
static std::pair<tsi_result, std::optional<HandshakerNextArgs>>
|
|
2341
|
+
ssl_handshaker_next_async(tsi_ssl_handshaker* self)
|
|
2342
|
+
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&tsi_ssl_handshaker::mu) {
|
|
2343
|
+
if (self->is_shutdown || !self->handshaker_next_args.has_value()) {
|
|
2344
|
+
return {TSI_HANDSHAKE_SHUTDOWN, std::nullopt};
|
|
2345
|
+
}
|
|
2346
|
+
tsi_result result = ssl_handshaker_next_impl(self);
|
|
2347
|
+
if (result != TSI_ASYNC) {
|
|
2348
|
+
// We now have a result to return to the caller via the callback.
|
|
2349
|
+
std::optional<HandshakerNextArgs> args =
|
|
2350
|
+
std::move(self->handshaker_next_args);
|
|
2351
|
+
self->handshaker_next_args.reset();
|
|
2352
|
+
return {result, std::move(args)};
|
|
2353
|
+
}
|
|
2354
|
+
return {TSI_ASYNC, std::nullopt};
|
|
2355
|
+
}
|
|
2356
|
+
|
|
2357
|
+
// Entry point when the security handshaker calls tsi_handshaker_next().
|
|
2358
|
+
static tsi_result ssl_handshaker_next(
|
|
2359
|
+
tsi_handshaker* self, const unsigned char* received_bytes,
|
|
2360
|
+
size_t received_bytes_size, const unsigned char** bytes_to_send,
|
|
2361
|
+
size_t* bytes_to_send_size, tsi_handshaker_result** handshaker_result,
|
|
2362
|
+
tsi_handshaker_on_next_done_cb cb, void* user_data, std::string* error) {
|
|
2363
|
+
// Input sanity check.
|
|
2364
|
+
if ((received_bytes_size > 0 && received_bytes == nullptr) ||
|
|
2365
|
+
bytes_to_send == nullptr || bytes_to_send_size == nullptr ||
|
|
2366
|
+
handshaker_result == nullptr) {
|
|
2367
|
+
if (error != nullptr) *error = "invalid argument";
|
|
2368
|
+
return TSI_INVALID_ARGUMENT;
|
|
2369
|
+
}
|
|
2370
|
+
tsi_ssl_handshaker* impl = static_cast<tsi_ssl_handshaker*>(self);
|
|
2371
|
+
grpc_core::MutexLock lock(&impl->mu);
|
|
2372
|
+
if (impl->is_shutdown) {
|
|
2373
|
+
if (error != nullptr) *error = "Handshaker shutdown";
|
|
2374
|
+
return TSI_HANDSHAKE_SHUTDOWN;
|
|
2375
|
+
}
|
|
2376
|
+
// Store args in impl->handshaker_next_args.
|
|
2377
|
+
impl->handshaker_next_args.emplace();
|
|
2378
|
+
if (received_bytes_size > 0) {
|
|
2379
|
+
impl->handshaker_next_args->received_bytes.assign(
|
|
2380
|
+
received_bytes, received_bytes + received_bytes_size);
|
|
2381
|
+
}
|
|
2382
|
+
impl->handshaker_next_args->original_received_bytes_size =
|
|
2383
|
+
received_bytes_size;
|
|
2384
|
+
impl->handshaker_next_args->cb = cb;
|
|
2385
|
+
impl->handshaker_next_args->user_data = user_data;
|
|
2386
|
+
impl->handshaker_next_args->error_ptr = error;
|
|
2387
|
+
// Now do the actual work.
|
|
2388
|
+
tsi_result result = ssl_handshaker_next_impl(impl);
|
|
2389
|
+
// If returning synchronously, propagate output and clear args.
|
|
2390
|
+
if (result != TSI_ASYNC) {
|
|
2391
|
+
*bytes_to_send = impl->handshaker_next_args->bytes_to_send;
|
|
2392
|
+
*bytes_to_send_size = impl->handshaker_next_args->bytes_to_send_size;
|
|
2393
|
+
*handshaker_result = impl->handshaker_next_args->handshaker_result;
|
|
2394
|
+
impl->handshaker_next_args.reset();
|
|
2395
|
+
}
|
|
2396
|
+
return result;
|
|
2397
|
+
}
|
|
2398
|
+
|
|
2399
|
+
static void ssl_handshaker_shutdown(tsi_handshaker* self) {
|
|
2400
|
+
#if defined(OPENSSL_IS_BORINGSSL)
|
|
2401
|
+
tsi_ssl_handshaker* impl = static_cast<tsi_ssl_handshaker*>(self);
|
|
2402
|
+
std::shared_ptr<grpc_core::PrivateKeySigner::AsyncSigningHandle>
|
|
2403
|
+
signing_handle;
|
|
2404
|
+
std::optional<HandshakerNextArgs> next_args;
|
|
2405
|
+
{
|
|
2406
|
+
grpc_core::MutexLock lock(&impl->mu);
|
|
2407
|
+
if (impl->ssl == nullptr) return;
|
|
2408
|
+
impl->is_shutdown = true;
|
|
2409
|
+
if (impl->factory_ref->key_signer != nullptr &&
|
|
2410
|
+
impl->signing_handle != nullptr) {
|
|
2411
|
+
signing_handle = std::move(impl->signing_handle);
|
|
2412
|
+
}
|
|
2413
|
+
if (impl->handshaker_next_args.has_value()) {
|
|
2414
|
+
next_args = std::move(*impl->handshaker_next_args);
|
|
2415
|
+
impl->handshaker_next_args.reset();
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
if (signing_handle != nullptr) {
|
|
2419
|
+
impl->factory_ref->key_signer->Cancel(signing_handle);
|
|
2420
|
+
}
|
|
2421
|
+
if (next_args.has_value()) {
|
|
2422
|
+
grpc_event_engine::experimental::GetDefaultEventEngine()->Run(
|
|
2423
|
+
[args = std::move(*next_args)]() mutable {
|
|
2424
|
+
if (args.error_ptr != nullptr) {
|
|
2425
|
+
*args.error_ptr = "Handshaker shutdown";
|
|
2426
|
+
}
|
|
2427
|
+
if (args.cb != nullptr) {
|
|
2428
|
+
args.cb(TSI_HANDSHAKE_SHUTDOWN, args.user_data, nullptr, 0,
|
|
2429
|
+
args.handshaker_result);
|
|
2430
|
+
}
|
|
2431
|
+
});
|
|
2432
|
+
}
|
|
2433
|
+
#endif // defined(OPENSSL_IS_BORINGSSL)
|
|
2434
|
+
}
|
|
2435
|
+
|
|
2084
2436
|
static const tsi_handshaker_vtable handshaker_vtable = {
|
|
2085
2437
|
nullptr, // get_bytes_to_send_to_peer -- deprecated
|
|
2086
2438
|
nullptr, // process_bytes_from_peer -- deprecated
|
|
@@ -2089,7 +2441,7 @@ static const tsi_handshaker_vtable handshaker_vtable = {
|
|
|
2089
2441
|
nullptr, // create_frame_protector -- deprecated
|
|
2090
2442
|
ssl_handshaker_destroy,
|
|
2091
2443
|
ssl_handshaker_next,
|
|
2092
|
-
|
|
2444
|
+
ssl_handshaker_shutdown,
|
|
2093
2445
|
};
|
|
2094
2446
|
|
|
2095
2447
|
// --- tsi_ssl_handshaker_factory common methods. ---
|
|
@@ -2196,7 +2548,7 @@ static tsi_result create_tsi_ssl_handshaker(
|
|
|
2196
2548
|
if (ssl_result != SSL_ERROR_WANT_READ) {
|
|
2197
2549
|
LOG(ERROR)
|
|
2198
2550
|
<< "Unexpected error received from first SSL_do_handshake call: "
|
|
2199
|
-
<<
|
|
2551
|
+
<< tsi::SslErrorString(ssl_result);
|
|
2200
2552
|
SSL_free(ssl);
|
|
2201
2553
|
BIO_free(network_io);
|
|
2202
2554
|
return TSI_INTERNAL_ERROR;
|
|
@@ -2205,7 +2557,7 @@ static tsi_result create_tsi_ssl_handshaker(
|
|
|
2205
2557
|
SSL_set_accept_state(ssl);
|
|
2206
2558
|
}
|
|
2207
2559
|
|
|
2208
|
-
impl =
|
|
2560
|
+
impl = new tsi_ssl_handshaker();
|
|
2209
2561
|
impl->ssl = ssl;
|
|
2210
2562
|
impl->network_io = network_io;
|
|
2211
2563
|
impl->result = TSI_HANDSHAKE_IN_PROGRESS;
|
|
@@ -2213,9 +2565,14 @@ static tsi_result create_tsi_ssl_handshaker(
|
|
|
2213
2565
|
TSI_SSL_HANDSHAKER_OUTGOING_BUFFER_INITIAL_SIZE;
|
|
2214
2566
|
impl->outgoing_bytes_buffer =
|
|
2215
2567
|
static_cast<unsigned char*>(gpr_zalloc(impl->outgoing_bytes_buffer_size));
|
|
2216
|
-
impl->
|
|
2568
|
+
impl->vtable = &handshaker_vtable;
|
|
2217
2569
|
impl->factory_ref = tsi_ssl_handshaker_factory_ref(factory);
|
|
2218
|
-
*handshaker =
|
|
2570
|
+
*handshaker = impl;
|
|
2571
|
+
|
|
2572
|
+
if (!SSL_set_ex_data(ssl, g_ssl_ex_handshaker_index, impl)) {
|
|
2573
|
+
return TSI_INTERNAL_ERROR;
|
|
2574
|
+
}
|
|
2575
|
+
|
|
2219
2576
|
return TSI_OK;
|
|
2220
2577
|
}
|
|
2221
2578
|
|
|
@@ -2456,7 +2813,8 @@ tsi_result tsi_create_ssl_client_handshaker_factory(
|
|
|
2456
2813
|
tsi_ssl_client_handshaker_options options;
|
|
2457
2814
|
options.pem_key_cert_pair = pem_key_cert_pair;
|
|
2458
2815
|
if (pem_root_certs != nullptr) {
|
|
2459
|
-
options.root_cert_info =
|
|
2816
|
+
options.root_cert_info =
|
|
2817
|
+
std::make_shared<tsi::RootCertInfo>(pem_root_certs);
|
|
2460
2818
|
}
|
|
2461
2819
|
options.cipher_suites = cipher_suites;
|
|
2462
2820
|
options.alpn_protocols = alpn_protocols;
|
|
@@ -2490,7 +2848,7 @@ tsi_result tsi_create_ssl_client_handshaker_factory_with_options(
|
|
|
2490
2848
|
SSL_CTX_set_options(ssl_context, SSL_OP_NO_RENEGOTIATION);
|
|
2491
2849
|
#endif
|
|
2492
2850
|
if (ssl_context == nullptr) {
|
|
2493
|
-
|
|
2851
|
+
tsi::LogSslErrorStack();
|
|
2494
2852
|
LOG(ERROR) << "Could not create ssl context.";
|
|
2495
2853
|
return TSI_INVALID_ARGUMENT;
|
|
2496
2854
|
}
|
|
@@ -2537,6 +2895,18 @@ tsi_result tsi_create_ssl_client_handshaker_factory_with_options(
|
|
|
2537
2895
|
options->cipher_suites);
|
|
2538
2896
|
if (result != TSI_OK) break;
|
|
2539
2897
|
|
|
2898
|
+
#if defined(OPENSSL_IS_BORINGSSL)
|
|
2899
|
+
if (options->pem_key_cert_pair != nullptr) {
|
|
2900
|
+
grpc_core::Match(
|
|
2901
|
+
options->pem_key_cert_pair->private_key, [](const std::string&) {},
|
|
2902
|
+
[&](const std::shared_ptr<grpc_core::PrivateKeySigner>& key_signer) {
|
|
2903
|
+
// The Handshaker Factory will own a shared copy of the reference
|
|
2904
|
+
// passed through the options.
|
|
2905
|
+
impl->base.key_signer = key_signer;
|
|
2906
|
+
});
|
|
2907
|
+
}
|
|
2908
|
+
#endif
|
|
2909
|
+
|
|
2540
2910
|
#if OPENSSL_VERSION_NUMBER >= 0x10100000
|
|
2541
2911
|
// X509_STORE_up_ref is only available since OpenSSL 1.1.
|
|
2542
2912
|
if (options->root_store != nullptr) {
|
|
@@ -2639,30 +3009,28 @@ static tsi_ssl_handshaker_factory_vtable server_handshaker_factory_vtable = {
|
|
|
2639
3009
|
tsi_ssl_server_handshaker_factory_destroy};
|
|
2640
3010
|
|
|
2641
3011
|
tsi_result tsi_create_ssl_server_handshaker_factory(
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
tsi_ssl_server_handshaker_factory** factory) {
|
|
3012
|
+
std::vector<tsi_ssl_pem_key_cert_pair> pem_key_cert_pairs,
|
|
3013
|
+
const char* pem_client_root_certs, int force_client_auth,
|
|
3014
|
+
const char* cipher_suites, const char** alpn_protocols,
|
|
3015
|
+
uint16_t num_alpn_protocols, tsi_ssl_server_handshaker_factory** factory) {
|
|
2647
3016
|
return tsi_create_ssl_server_handshaker_factory_ex(
|
|
2648
|
-
pem_key_cert_pairs,
|
|
3017
|
+
pem_key_cert_pairs, pem_client_root_certs,
|
|
2649
3018
|
force_client_auth ? TSI_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY
|
|
2650
3019
|
: TSI_DONT_REQUEST_CLIENT_CERTIFICATE,
|
|
2651
3020
|
cipher_suites, alpn_protocols, num_alpn_protocols, factory);
|
|
2652
3021
|
}
|
|
2653
3022
|
|
|
2654
3023
|
tsi_result tsi_create_ssl_server_handshaker_factory_ex(
|
|
2655
|
-
|
|
2656
|
-
|
|
3024
|
+
std::vector<tsi_ssl_pem_key_cert_pair> pem_key_cert_pairs,
|
|
3025
|
+
const char* pem_client_root_certs,
|
|
2657
3026
|
tsi_client_certificate_request_type client_certificate_request,
|
|
2658
3027
|
const char* cipher_suites, const char** alpn_protocols,
|
|
2659
3028
|
uint16_t num_alpn_protocols, tsi_ssl_server_handshaker_factory** factory) {
|
|
2660
3029
|
tsi_ssl_server_handshaker_options options;
|
|
2661
3030
|
options.pem_key_cert_pairs = pem_key_cert_pairs;
|
|
2662
|
-
options.num_key_cert_pairs = num_key_cert_pairs;
|
|
2663
3031
|
if (pem_client_root_certs != nullptr) {
|
|
2664
3032
|
options.root_cert_info =
|
|
2665
|
-
std::make_shared<RootCertInfo>(pem_client_root_certs);
|
|
3033
|
+
std::make_shared<tsi::RootCertInfo>(pem_client_root_certs);
|
|
2666
3034
|
}
|
|
2667
3035
|
options.client_certificate_request = client_certificate_request;
|
|
2668
3036
|
options.cipher_suites = cipher_suites;
|
|
@@ -2683,8 +3051,7 @@ tsi_result tsi_create_ssl_server_handshaker_factory_with_options(
|
|
|
2683
3051
|
|
|
2684
3052
|
if (factory == nullptr) return TSI_INVALID_ARGUMENT;
|
|
2685
3053
|
*factory = nullptr;
|
|
2686
|
-
if (options->
|
|
2687
|
-
options->pem_key_cert_pairs == nullptr) {
|
|
3054
|
+
if (options->pem_key_cert_pairs.empty()) {
|
|
2688
3055
|
return TSI_INVALID_ARGUMENT;
|
|
2689
3056
|
}
|
|
2690
3057
|
|
|
@@ -2693,15 +3060,15 @@ tsi_result tsi_create_ssl_server_handshaker_factory_with_options(
|
|
|
2693
3060
|
impl->base.vtable = &server_handshaker_factory_vtable;
|
|
2694
3061
|
|
|
2695
3062
|
impl->ssl_contexts = static_cast<SSL_CTX**>(
|
|
2696
|
-
gpr_zalloc(options->
|
|
3063
|
+
gpr_zalloc(options->pem_key_cert_pairs.size() * sizeof(SSL_CTX*)));
|
|
2697
3064
|
impl->ssl_context_x509_subject_names = static_cast<tsi_peer*>(
|
|
2698
|
-
gpr_zalloc(options->
|
|
3065
|
+
gpr_zalloc(options->pem_key_cert_pairs.size() * sizeof(tsi_peer)));
|
|
2699
3066
|
if (impl->ssl_contexts == nullptr ||
|
|
2700
3067
|
impl->ssl_context_x509_subject_names == nullptr) {
|
|
2701
3068
|
tsi_ssl_handshaker_factory_unref(&impl->base);
|
|
2702
3069
|
return TSI_OUT_OF_RESOURCES;
|
|
2703
3070
|
}
|
|
2704
|
-
impl->ssl_context_count = options->
|
|
3071
|
+
impl->ssl_context_count = options->pem_key_cert_pairs.size();
|
|
2705
3072
|
if (options->root_cert_info != nullptr) {
|
|
2706
3073
|
impl->root_cert_info = options->root_cert_info;
|
|
2707
3074
|
}
|
|
@@ -2720,7 +3087,7 @@ tsi_result tsi_create_ssl_server_handshaker_factory_with_options(
|
|
|
2720
3087
|
impl->key_logger = options->key_logger->Ref();
|
|
2721
3088
|
}
|
|
2722
3089
|
|
|
2723
|
-
for (i = 0; i < options->
|
|
3090
|
+
for (i = 0; i < options->pem_key_cert_pairs.size(); i++) {
|
|
2724
3091
|
do {
|
|
2725
3092
|
#if OPENSSL_VERSION_NUMBER >= 0x10100000
|
|
2726
3093
|
impl->ssl_contexts[i] = SSL_CTX_new(TLS_method());
|
|
@@ -2731,7 +3098,7 @@ tsi_result tsi_create_ssl_server_handshaker_factory_with_options(
|
|
|
2731
3098
|
SSL_CTX_set_options(impl->ssl_contexts[i], SSL_OP_NO_RENEGOTIATION);
|
|
2732
3099
|
#endif
|
|
2733
3100
|
if (impl->ssl_contexts[i] == nullptr) {
|
|
2734
|
-
|
|
3101
|
+
tsi::LogSslErrorStack();
|
|
2735
3102
|
LOG(ERROR) << "Could not create ssl context.";
|
|
2736
3103
|
result = TSI_OUT_OF_RESOURCES;
|
|
2737
3104
|
break;
|
|
@@ -2747,6 +3114,16 @@ tsi_result tsi_create_ssl_server_handshaker_factory_with_options(
|
|
|
2747
3114
|
options->cipher_suites);
|
|
2748
3115
|
if (result != TSI_OK) break;
|
|
2749
3116
|
|
|
3117
|
+
#if defined(OPENSSL_IS_BORINGSSL)
|
|
3118
|
+
if (impl->base.key_signer == nullptr) {
|
|
3119
|
+
grpc_core::Match(
|
|
3120
|
+
options->pem_key_cert_pairs[i].private_key,
|
|
3121
|
+
[](const std::string&) {},
|
|
3122
|
+
[&](const std::shared_ptr<grpc_core::PrivateKeySigner>&
|
|
3123
|
+
key_signer) { impl->base.key_signer = key_signer; });
|
|
3124
|
+
}
|
|
3125
|
+
#endif
|
|
3126
|
+
|
|
2750
3127
|
// TODO(elessar): Provide ability to disable session ticket keys.
|
|
2751
3128
|
|
|
2752
3129
|
// Allow client cache sessions (it's needed for OpenSSL only).
|
|
@@ -2849,7 +3226,7 @@ tsi_result tsi_create_ssl_server_handshaker_factory_with_options(
|
|
|
2849
3226
|
#endif
|
|
2850
3227
|
|
|
2851
3228
|
result = tsi_ssl_extract_x509_subject_names_from_pem_cert(
|
|
2852
|
-
options->pem_key_cert_pairs[i].cert_chain,
|
|
3229
|
+
options->pem_key_cert_pairs[i].cert_chain.c_str(),
|
|
2853
3230
|
&impl->ssl_context_x509_subject_names[i]);
|
|
2854
3231
|
if (result != TSI_OK) break;
|
|
2855
3232
|
|
|
@@ -2931,15 +3308,17 @@ int tsi_ssl_peer_matches_name(const tsi_peer* peer, absl::string_view name) {
|
|
|
2931
3308
|
return 0; // Not found.
|
|
2932
3309
|
}
|
|
2933
3310
|
|
|
2934
|
-
|
|
3311
|
+
namespace tsi {
|
|
3312
|
+
bool IsRootCertInfoEmpty(const tsi::RootCertInfo* root_cert_info) {
|
|
2935
3313
|
if (root_cert_info == nullptr) return true;
|
|
2936
|
-
return Match(
|
|
3314
|
+
return grpc_core::Match(
|
|
2937
3315
|
*root_cert_info,
|
|
2938
3316
|
[&](const std::string& pem_root_certs) { return pem_root_certs.empty(); },
|
|
2939
3317
|
[&](const grpc_core::SpiffeBundleMap& spiffe_bundle_map) {
|
|
2940
3318
|
return spiffe_bundle_map.size() == 0;
|
|
2941
3319
|
});
|
|
2942
3320
|
}
|
|
3321
|
+
} // namespace tsi
|
|
2943
3322
|
|
|
2944
3323
|
// --- Testing support. ---
|
|
2945
3324
|
const tsi_ssl_handshaker_factory_vtable* tsi_ssl_handshaker_factory_swap_vtable(
|