grpc 1.0.1 → 1.1.2
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 +3696 -867
- data/etc/roots.pem +39 -111
- data/include/grpc/byte_buffer.h +64 -1
- data/include/grpc/census.h +40 -96
- data/include/grpc/compression.h +2 -1
- data/include/grpc/grpc.h +42 -7
- data/include/grpc/grpc_posix.h +8 -5
- data/include/grpc/impl/codegen/atm.h +3 -0
- data/include/grpc/impl/codegen/atm_gcc_atomic.h +2 -0
- data/include/grpc/impl/codegen/atm_gcc_sync.h +8 -0
- data/include/grpc/impl/codegen/atm_windows.h +4 -0
- data/include/grpc/impl/codegen/byte_buffer_reader.h +4 -4
- data/include/grpc/impl/codegen/compression_types.h +1 -1
- data/include/grpc/impl/codegen/connectivity_state.h +2 -0
- data/include/grpc/impl/codegen/exec_ctx_fwd.h +41 -0
- data/include/grpc/impl/codegen/gpr_slice.h +84 -0
- data/include/grpc/impl/codegen/{alloc.h → gpr_types.h} +30 -29
- data/include/grpc/impl/codegen/grpc_types.h +91 -9
- data/include/grpc/impl/codegen/port_platform.h +25 -92
- data/include/grpc/impl/codegen/slice.h +54 -97
- data/include/grpc/impl/codegen/sync.h +0 -253
- data/include/grpc/module.modulemap +0 -2
- data/include/grpc/slice.h +132 -0
- data/include/grpc/{impl/codegen/slice_buffer.h → slice_buffer.h} +22 -39
- data/include/grpc/support/alloc.h +40 -1
- data/include/grpc/support/log.h +80 -1
- data/include/grpc/support/log_windows.h +2 -0
- data/include/grpc/support/string_util.h +1 -1
- data/include/grpc/support/sync.h +252 -0
- data/include/grpc/support/time.h +67 -1
- data/src/boringssl/err_data.c +639 -627
- data/src/core/ext/census/base_resources.c +71 -0
- data/src/core/ext/census/base_resources.h +39 -0
- data/src/core/ext/census/gen/census.pb.c +26 -29
- data/src/core/ext/census/gen/census.pb.h +68 -67
- data/src/core/ext/census/gen/trace_context.pb.c +81 -0
- data/src/core/ext/census/gen/trace_context.pb.h +99 -0
- data/src/core/ext/census/grpc_filter.c +22 -16
- data/src/core/ext/census/grpc_plugin.c +2 -1
- data/src/core/ext/census/initialize.c +16 -4
- data/src/core/ext/census/mlog.h +1 -1
- data/src/core/ext/census/placeholders.c +0 -45
- data/src/core/ext/census/resource.c +312 -0
- data/src/core/ext/census/resource.h +63 -0
- data/src/core/ext/census/trace_context.c +86 -0
- data/src/core/ext/census/trace_context.h +68 -0
- data/src/core/ext/census/tracing.c +8 -2
- data/src/core/ext/{client_config → client_channel}/channel_connectivity.c +8 -4
- data/src/core/ext/client_channel/client_channel.c +1218 -0
- data/src/core/ext/{client_config → client_channel}/client_channel.h +8 -11
- data/src/core/ext/{client_config → client_channel}/client_channel_factory.c +33 -3
- data/src/core/ext/{client_config → client_channel}/client_channel_factory.h +15 -8
- data/src/core/ext/{client_config/client_config_plugin.c → client_channel/client_channel_plugin.c} +16 -15
- data/src/core/ext/{client_config → client_channel}/connector.c +1 -1
- data/src/core/ext/{client_config → client_channel}/connector.h +5 -8
- data/{include/grpc/support/slice_buffer.h → src/core/ext/client_channel/default_initial_connect_string.c} +4 -5
- data/src/core/ext/client_channel/http_connect_handshaker.c +399 -0
- data/src/core/ext/client_channel/http_connect_handshaker.h +52 -0
- data/src/core/ext/{client_config → client_channel}/initial_connect_string.c +6 -7
- data/src/core/ext/{client_config → client_channel}/initial_connect_string.h +10 -10
- data/src/core/ext/{client_config → client_channel}/lb_policy.c +11 -11
- data/src/core/ext/{client_config → client_channel}/lb_policy.h +68 -27
- data/src/core/ext/client_channel/lb_policy_factory.c +163 -0
- data/src/core/ext/{client_config → client_channel}/lb_policy_factory.h +64 -9
- data/src/core/ext/{client_config → client_channel}/lb_policy_registry.c +6 -4
- data/src/core/ext/{client_config → client_channel}/lb_policy_registry.h +4 -4
- data/src/core/ext/{client_config → client_channel}/parse_address.c +21 -14
- data/src/core/ext/{client_config → client_channel}/parse_address.h +8 -10
- data/src/core/ext/{client_config → client_channel}/resolver.c +3 -4
- data/src/core/ext/{client_config → client_channel}/resolver.h +11 -15
- data/src/core/ext/{client_config → client_channel}/resolver_factory.c +4 -3
- data/src/core/ext/{client_config → client_channel}/resolver_factory.h +13 -11
- data/src/core/ext/{client_config → client_channel}/resolver_registry.c +54 -34
- data/src/core/ext/{client_config → client_channel}/resolver_registry.h +21 -8
- data/src/core/ext/{client_config → client_channel}/subchannel.c +208 -119
- data/src/core/ext/{client_config → client_channel}/subchannel.h +21 -11
- data/src/core/ext/{client_config → client_channel}/subchannel_index.c +6 -17
- data/src/core/ext/{client_config → client_channel}/subchannel_index.h +7 -7
- data/src/core/ext/{client_config → client_channel}/uri_parser.c +21 -28
- data/src/core/ext/{client_config → client_channel}/uri_parser.h +3 -3
- data/src/core/ext/lb_policy/grpclb/grpclb.c +1406 -0
- data/src/core/ext/lb_policy/grpclb/grpclb.h +44 -0
- data/src/core/ext/lb_policy/grpclb/load_balancer_api.c +117 -37
- data/src/core/ext/lb_policy/grpclb/load_balancer_api.h +31 -12
- data/src/core/ext/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +6 -36
- data/src/core/ext/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +22 -42
- data/src/core/ext/lb_policy/pick_first/pick_first.c +64 -46
- data/src/core/ext/lb_policy/round_robin/round_robin.c +324 -160
- data/src/core/ext/load_reporting/load_reporting.c +7 -56
- data/src/core/ext/load_reporting/load_reporting.h +41 -28
- data/src/core/ext/load_reporting/load_reporting_filter.c +132 -42
- data/src/core/ext/load_reporting/load_reporting_filter.h +1 -0
- data/src/core/ext/resolver/dns/native/dns_resolver.c +88 -80
- data/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +57 -102
- data/src/core/ext/transport/chttp2/alpn/alpn.c +1 -1
- data/src/core/ext/transport/chttp2/client/chttp2_connector.c +253 -0
- data/src/core/{lib/iomgr/ev_poll_and_epoll_posix.h → ext/transport/chttp2/client/chttp2_connector.h} +5 -5
- data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +31 -160
- data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c +5 -5
- data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +44 -243
- data/src/core/ext/transport/chttp2/server/chttp2_server.c +342 -0
- data/src/core/ext/transport/chttp2/server/chttp2_server.h +47 -0
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c +11 -124
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c +20 -9
- data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +28 -236
- data/src/core/ext/transport/chttp2/transport/bin_decoder.c +31 -27
- data/src/core/ext/transport/chttp2/transport/bin_decoder.h +5 -4
- data/src/core/ext/transport/chttp2/transport/bin_encoder.c +25 -22
- data/src/core/ext/transport/chttp2/transport/bin_encoder.h +8 -7
- data/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +0 -3
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +1345 -1521
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -1
- data/src/core/ext/transport/chttp2/transport/frame.h +3 -5
- data/src/core/ext/transport/chttp2/transport/frame_data.c +50 -47
- data/src/core/ext/transport/chttp2/transport/frame_data.h +8 -9
- data/src/core/ext/transport/chttp2/transport/frame_goaway.c +19 -21
- data/src/core/ext/transport/chttp2/transport/frame_goaway.h +9 -8
- data/src/core/ext/transport/chttp2/transport/frame_ping.c +13 -12
- data/src/core/ext/transport/chttp2/transport/frame_ping.h +6 -6
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +31 -19
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +8 -7
- data/src/core/ext/transport/chttp2/transport/frame_settings.c +22 -25
- data/src/core/ext/transport/chttp2/transport/frame_settings.h +9 -8
- data/src/core/ext/transport/chttp2/transport/frame_window_update.c +26 -18
- data/src/core/ext/transport/chttp2/transport/frame_window_update.h +5 -6
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +68 -58
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +8 -5
- data/src/core/ext/transport/chttp2/transport/hpack_parser.c +327 -214
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +14 -9
- data/src/core/ext/transport/chttp2/transport/hpack_table.c +24 -19
- data/src/core/ext/transport/chttp2/transport/hpack_table.h +9 -6
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +2 -2
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +1 -1
- data/src/core/ext/transport/chttp2/transport/internal.h +284 -436
- data/src/core/ext/transport/chttp2/transport/parsing.c +355 -590
- data/src/core/ext/transport/chttp2/transport/stream_lists.c +36 -309
- data/src/core/ext/transport/chttp2/transport/stream_map.c +13 -34
- data/src/core/ext/transport/chttp2/transport/stream_map.h +3 -4
- data/src/core/ext/transport/chttp2/transport/writing.c +174 -286
- data/src/core/lib/channel/channel_args.c +70 -13
- data/src/core/lib/channel/channel_args.h +28 -2
- data/src/core/lib/channel/channel_stack.c +77 -28
- data/src/core/lib/channel/channel_stack.h +61 -23
- data/src/core/lib/channel/channel_stack_builder.c +33 -25
- data/src/core/lib/channel/channel_stack_builder.h +17 -8
- data/src/core/lib/channel/compress_filter.c +52 -36
- data/src/core/lib/channel/connected_channel.c +20 -12
- data/src/core/lib/channel/connected_channel.h +2 -1
- data/src/core/lib/channel/context.h +13 -1
- data/src/core/lib/channel/deadline_filter.c +344 -0
- data/src/core/lib/channel/deadline_filter.h +99 -0
- data/src/core/lib/channel/handshaker.c +240 -0
- data/src/core/lib/channel/handshaker.h +164 -0
- data/src/core/lib/{security/credentials/google_default/credentials_windows.c → channel/handshaker_factory.c} +16 -23
- data/src/core/lib/channel/handshaker_factory.h +66 -0
- data/src/core/lib/channel/handshaker_registry.c +113 -0
- data/src/core/{ext/client_config/client_config.h → lib/channel/handshaker_registry.h} +26 -16
- data/src/core/lib/channel/http_client_filter.c +248 -46
- data/src/core/lib/channel/http_client_filter.h +3 -0
- data/src/core/lib/channel/http_server_filter.c +136 -24
- data/src/core/lib/channel/message_size_filter.c +261 -0
- data/src/core/lib/channel/message_size_filter.h +39 -0
- data/src/core/lib/compression/message_compress.c +43 -37
- data/src/core/lib/compression/message_compress.h +7 -5
- data/src/core/lib/http/format_request.c +26 -11
- data/src/core/lib/http/format_request.h +7 -5
- data/src/core/lib/http/httpcli.c +45 -27
- data/src/core/lib/http/httpcli.h +4 -4
- data/src/core/lib/http/httpcli_security_connector.c +56 -46
- data/src/core/lib/http/parser.c +17 -14
- data/src/core/lib/http/parser.h +4 -2
- data/src/core/lib/iomgr/closure.c +49 -7
- data/src/core/lib/iomgr/closure.h +56 -14
- data/src/core/lib/iomgr/combiner.c +422 -0
- data/src/core/lib/iomgr/combiner.h +64 -0
- data/src/core/lib/iomgr/endpoint.c +8 -2
- data/src/core/lib/iomgr/endpoint.h +17 -7
- data/src/core/lib/iomgr/endpoint_pair.h +3 -2
- data/src/core/lib/iomgr/endpoint_pair_posix.c +9 -8
- data/src/core/{ext/client_config/lb_policy_factory.c → lib/iomgr/endpoint_pair_uv.c} +18 -13
- data/src/core/lib/iomgr/endpoint_pair_windows.c +7 -6
- data/src/core/lib/iomgr/error.c +72 -6
- data/src/core/lib/iomgr/error.h +30 -3
- data/src/core/lib/iomgr/ev_epoll_linux.c +500 -382
- data/src/core/lib/iomgr/ev_epoll_linux.h +3 -2
- data/src/core/lib/iomgr/ev_poll_posix.c +317 -30
- data/src/core/lib/iomgr/ev_poll_posix.h +1 -0
- data/src/core/lib/iomgr/ev_posix.c +26 -5
- data/src/core/lib/iomgr/ev_posix.h +12 -1
- data/src/core/lib/iomgr/exec_ctx.c +27 -94
- data/src/core/lib/iomgr/exec_ctx.h +19 -22
- data/src/core/lib/iomgr/executor.c +29 -8
- data/src/core/lib/iomgr/executor.h +2 -4
- data/src/core/lib/iomgr/iocp_windows.c +3 -4
- data/src/core/lib/iomgr/iomgr.c +14 -10
- data/src/core/lib/iomgr/iomgr.h +6 -2
- data/src/core/lib/iomgr/iomgr_posix.c +2 -2
- data/src/core/lib/iomgr/iomgr_uv.c +49 -0
- data/src/core/lib/iomgr/iomgr_windows.c +2 -2
- data/src/core/lib/iomgr/load_file.c +3 -3
- data/src/core/lib/iomgr/load_file.h +2 -2
- data/src/core/lib/iomgr/network_status_tracker.c +1 -1
- data/src/core/lib/iomgr/pollset_set_uv.c +62 -0
- data/src/core/lib/iomgr/pollset_set_windows.c +3 -3
- data/src/core/lib/iomgr/pollset_uv.c +142 -0
- data/src/core/lib/iomgr/pollset_uv.h +42 -0
- data/src/core/lib/iomgr/pollset_windows.c +5 -6
- data/src/core/lib/iomgr/port.h +129 -0
- data/src/core/lib/iomgr/resolve_address.h +2 -1
- data/src/core/lib/iomgr/resolve_address_posix.c +14 -13
- data/src/core/lib/iomgr/resolve_address_uv.c +233 -0
- data/src/core/lib/iomgr/resolve_address_windows.c +14 -12
- data/src/core/lib/iomgr/resource_quota.c +832 -0
- data/src/core/lib/iomgr/resource_quota.h +159 -0
- data/src/core/lib/iomgr/sockaddr.h +10 -2
- data/src/core/lib/iomgr/sockaddr_utils.c +63 -36
- data/src/core/lib/iomgr/sockaddr_utils.h +14 -14
- data/src/core/lib/iomgr/socket_mutator.c +98 -0
- data/src/core/lib/iomgr/socket_mutator.h +80 -0
- data/src/core/lib/iomgr/socket_utils.h +42 -0
- data/src/core/lib/iomgr/socket_utils_common_posix.c +28 -13
- data/src/core/lib/iomgr/socket_utils_linux.c +11 -5
- data/src/core/lib/iomgr/socket_utils_posix.c +10 -7
- data/src/core/lib/iomgr/socket_utils_posix.h +11 -4
- data/src/core/lib/iomgr/socket_utils_uv.c +49 -0
- data/src/core/lib/iomgr/socket_utils_windows.c +52 -0
- data/src/core/lib/iomgr/socket_windows.c +14 -6
- data/src/core/lib/iomgr/socket_windows.h +1 -0
- data/src/core/lib/iomgr/tcp_client.h +8 -2
- data/src/core/lib/iomgr/tcp_client_posix.c +131 -82
- data/src/core/lib/iomgr/tcp_client_posix.h +45 -0
- data/src/core/lib/iomgr/tcp_client_uv.c +190 -0
- data/src/core/lib/iomgr/tcp_client_windows.c +54 -30
- data/src/core/lib/iomgr/tcp_posix.c +135 -56
- data/src/core/lib/iomgr/tcp_posix.h +2 -2
- data/src/core/lib/iomgr/tcp_server.h +14 -6
- data/src/core/lib/iomgr/tcp_server_posix.c +154 -118
- data/src/core/lib/iomgr/tcp_server_uv.c +388 -0
- data/src/core/lib/iomgr/tcp_server_windows.c +127 -100
- data/src/core/lib/iomgr/tcp_uv.c +367 -0
- data/src/core/lib/iomgr/tcp_uv.h +59 -0
- data/src/core/lib/iomgr/tcp_windows.c +65 -48
- data/src/core/lib/iomgr/tcp_windows.h +3 -1
- data/src/core/lib/iomgr/timer.h +21 -21
- data/src/core/lib/iomgr/{timer.c → timer_generic.c} +15 -10
- data/src/core/lib/iomgr/timer_generic.h +49 -0
- data/src/core/lib/iomgr/timer_heap.c +6 -0
- data/src/core/lib/iomgr/timer_uv.c +99 -0
- data/src/core/lib/iomgr/timer_uv.h +47 -0
- data/src/core/lib/iomgr/udp_server.c +116 -98
- data/src/core/lib/iomgr/udp_server.h +5 -3
- data/src/core/lib/iomgr/unix_sockets_posix.c +14 -6
- data/src/core/lib/iomgr/unix_sockets_posix.h +6 -5
- data/src/core/lib/iomgr/unix_sockets_posix_noop.c +4 -4
- data/src/core/lib/iomgr/wakeup_fd_cv.c +118 -0
- data/src/core/lib/iomgr/wakeup_fd_cv.h +80 -0
- data/src/core/lib/iomgr/wakeup_fd_eventfd.c +3 -3
- data/src/core/lib/iomgr/wakeup_fd_nospecial.c +3 -3
- data/src/core/lib/iomgr/wakeup_fd_pipe.c +12 -6
- data/src/core/lib/iomgr/wakeup_fd_posix.c +34 -5
- data/src/core/lib/iomgr/wakeup_fd_posix.h +5 -0
- data/src/core/lib/iomgr/workqueue.h +12 -20
- data/src/core/{ext/client_config/client_config.c → lib/iomgr/workqueue_uv.c} +24 -33
- data/{include/grpc/support/slice.h → src/core/lib/iomgr/workqueue_uv.h} +4 -6
- data/src/core/lib/iomgr/workqueue_windows.c +9 -8
- data/src/core/lib/json/json.c +3 -3
- data/src/core/lib/json/json.h +11 -11
- data/src/core/lib/json/json_reader.c +9 -5
- data/src/core/lib/profiling/basic_timers.c +10 -1
- data/src/core/lib/profiling/timers.h +2 -0
- data/src/core/lib/security/context/security_context.c +13 -3
- data/src/core/lib/security/context/security_context.h +20 -0
- data/src/core/lib/security/credentials/composite/composite_credentials.c +28 -14
- data/src/core/lib/security/credentials/composite/composite_credentials.h +2 -2
- data/src/core/lib/security/credentials/credentials.c +48 -19
- data/src/core/lib/security/credentials/credentials.h +36 -19
- data/src/core/lib/security/credentials/credentials_metadata.c +11 -8
- data/src/core/lib/security/credentials/fake/fake_credentials.c +15 -11
- data/src/core/lib/security/credentials/google_default/{credentials_posix.c → credentials_generic.c} +7 -14
- data/src/core/lib/security/credentials/google_default/google_default_credentials.c +33 -21
- data/src/core/lib/security/credentials/google_default/google_default_credentials.h +14 -0
- data/src/core/lib/security/credentials/iam/iam_credentials.c +3 -2
- data/src/core/lib/security/credentials/jwt/json_token.c +1 -0
- data/src/core/lib/security/credentials/jwt/json_token.h +1 -1
- data/src/core/lib/security/credentials/jwt/jwt_credentials.c +54 -19
- data/src/core/lib/security/credentials/jwt/jwt_credentials.h +2 -1
- data/src/core/lib/security/credentials/jwt/jwt_verifier.c +129 -79
- data/src/core/lib/security/credentials/jwt/jwt_verifier.h +9 -6
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +63 -28
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +1 -1
- data/src/core/lib/security/credentials/plugin/plugin_credentials.c +32 -11
- data/src/core/lib/security/credentials/ssl/ssl_credentials.c +13 -9
- data/src/core/lib/security/transport/client_auth_filter.c +33 -27
- data/src/core/lib/security/transport/secure_endpoint.c +93 -68
- data/src/core/lib/security/transport/secure_endpoint.h +2 -2
- data/src/core/lib/security/transport/security_connector.c +133 -168
- data/src/core/lib/security/transport/security_connector.h +31 -46
- data/src/core/lib/security/transport/security_handshaker.c +501 -0
- data/src/core/lib/security/transport/{handshake.h → security_handshaker.h} +10 -10
- data/src/core/lib/security/transport/server_auth_filter.c +50 -38
- data/src/core/lib/security/util/b64.c +11 -8
- data/src/core/lib/security/util/b64.h +5 -4
- data/src/core/lib/slice/percent_encoding.c +182 -0
- data/src/core/lib/slice/percent_encoding.h +78 -0
- data/src/core/lib/{support → slice}/slice.c +81 -50
- data/src/core/lib/{support → slice}/slice_buffer.c +78 -60
- data/src/core/lib/slice/slice_internal.h +49 -0
- data/src/core/lib/slice/slice_string_helpers.c +90 -0
- data/src/core/lib/{iomgr/workqueue_posix.h → slice/slice_string_helpers.h} +18 -18
- data/src/core/lib/support/backoff.c +24 -13
- data/src/core/lib/support/backoff.h +5 -2
- data/src/core/lib/support/env.h +0 -2
- data/src/core/lib/support/log.c +5 -4
- data/src/core/lib/support/log_linux.c +0 -1
- data/src/core/lib/support/log_posix.c +1 -1
- data/src/core/lib/support/mpscq.c +83 -0
- data/src/core/lib/support/mpscq.h +65 -0
- data/src/core/lib/support/string.c +58 -49
- data/src/core/lib/support/string.h +11 -8
- data/src/core/lib/support/subprocess_posix.c +5 -2
- data/src/core/lib/support/thd.c +1 -1
- data/src/core/lib/support/time.c +43 -79
- data/src/core/lib/support/time_posix.c +1 -1
- data/src/core/lib/support/tmpfile.h +0 -2
- data/src/core/lib/surface/alarm.c +4 -1
- data/src/core/lib/surface/byte_buffer.c +17 -11
- data/src/core/lib/surface/byte_buffer_reader.c +23 -15
- data/src/core/lib/surface/call.c +294 -276
- data/src/core/lib/surface/call.h +24 -9
- data/src/core/lib/surface/call_log_batch.c +5 -3
- data/src/core/lib/surface/channel.c +127 -111
- data/src/core/lib/surface/channel.h +14 -5
- data/src/core/lib/surface/channel_init.c +1 -1
- data/src/core/lib/surface/channel_init.h +10 -1
- data/src/core/lib/surface/channel_ping.c +7 -6
- data/src/core/lib/surface/completion_queue.c +154 -18
- data/src/core/lib/surface/completion_queue.h +5 -0
- data/src/core/lib/surface/init.c +40 -6
- data/src/core/lib/surface/init.h +1 -0
- data/src/core/lib/surface/init_secure.c +5 -2
- data/src/core/lib/surface/lame_client.c +28 -18
- data/src/core/lib/surface/server.c +134 -87
- data/src/core/lib/surface/server.h +8 -0
- data/src/core/lib/surface/validate_metadata.c +1 -1
- data/src/core/lib/surface/version.c +3 -1
- data/src/core/lib/transport/byte_stream.c +7 -4
- data/src/core/lib/transport/byte_stream.h +6 -10
- data/src/core/lib/transport/connectivity_state.c +21 -12
- data/src/core/lib/transport/connectivity_state.h +4 -1
- data/src/core/lib/transport/mdstr_hash_table.c +118 -0
- data/src/core/lib/transport/mdstr_hash_table.h +77 -0
- data/src/core/lib/transport/metadata.c +83 -60
- data/src/core/lib/transport/metadata.h +41 -23
- data/src/core/lib/transport/metadata_batch.c +17 -11
- data/src/core/lib/transport/metadata_batch.h +20 -6
- data/src/core/lib/transport/pid_controller.c +57 -0
- data/src/core/lib/transport/pid_controller.h +64 -0
- data/src/core/lib/transport/service_config.c +251 -0
- data/src/core/lib/transport/service_config.h +71 -0
- data/src/core/lib/transport/static_metadata.c +18 -16
- data/src/core/lib/transport/static_metadata.h +113 -107
- data/src/core/{ext/transport/chttp2 → lib}/transport/timeout_encoding.c +3 -3
- data/src/core/{ext/transport/chttp2 → lib}/transport/timeout_encoding.h +7 -7
- data/src/core/lib/transport/transport.c +84 -23
- data/src/core/lib/transport/transport.h +53 -8
- data/src/core/lib/transport/transport_impl.h +3 -0
- data/src/core/lib/transport/transport_op_string.c +92 -20
- data/src/core/lib/tsi/ssl_transport_security.c +3 -1
- data/src/core/plugin_registry/grpc_plugin_registry.c +8 -4
- data/src/ruby/ext/grpc/extconf.rb +0 -1
- data/src/ruby/ext/grpc/rb_byte_buffer.c +8 -7
- data/src/ruby/ext/grpc/rb_call.c +15 -5
- data/src/ruby/ext/grpc/rb_channel.c +1 -1
- data/src/ruby/ext/grpc/rb_compression_options.c +466 -0
- data/src/{core/ext/client_config/default_initial_connect_string.c → ruby/ext/grpc/rb_compression_options.h} +10 -5
- data/src/ruby/ext/grpc/rb_grpc.c +3 -1
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +198 -190
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +306 -294
- data/src/ruby/ext/grpc/rb_server.c +18 -12
- data/src/ruby/lib/grpc/errors.rb +154 -2
- data/src/ruby/lib/grpc/generic/active_call.rb +144 -63
- data/src/ruby/lib/grpc/generic/bidi_call.rb +18 -2
- data/src/ruby/lib/grpc/generic/client_stub.rb +7 -5
- data/src/ruby/lib/grpc/generic/rpc_desc.rb +39 -13
- data/src/ruby/lib/grpc/generic/rpc_server.rb +51 -24
- data/src/ruby/lib/grpc/generic/service.rb +3 -2
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/grpc/health/checker.rb +3 -1
- data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +7 -0
- data/src/ruby/pb/test/client.rb +307 -7
- data/src/ruby/pb/test/server.rb +26 -1
- data/src/ruby/spec/compression_options_spec.rb +164 -0
- data/src/ruby/spec/error_sanity_spec.rb +64 -0
- data/src/ruby/spec/generic/active_call_spec.rb +290 -12
- data/src/ruby/spec/generic/client_stub_spec.rb +91 -41
- data/src/ruby/spec/generic/rpc_desc_spec.rb +36 -16
- data/src/ruby/spec/generic/rpc_server_pool_spec.rb +22 -28
- data/src/ruby/spec/generic/rpc_server_spec.rb +6 -6
- data/src/ruby/spec/pb/health/checker_spec.rb +27 -19
- data/src/ruby/spec/spec_helper.rb +2 -0
- data/third_party/boringssl/crypto/aes/aes.c +12 -12
- data/third_party/boringssl/crypto/aes/mode_wrappers.c +6 -2
- data/third_party/boringssl/crypto/asn1/a_d2i_fp.c +28 -13
- data/third_party/boringssl/crypto/asn1/a_gentm.c +2 -0
- data/third_party/boringssl/crypto/asn1/a_object.c +7 -3
- data/third_party/boringssl/crypto/asn1/a_strnid.c +1 -0
- data/third_party/boringssl/crypto/asn1/a_time.c +0 -11
- data/third_party/boringssl/crypto/asn1/a_type.c +0 -2
- data/third_party/boringssl/crypto/asn1/a_utctm.c +1 -30
- data/third_party/boringssl/crypto/asn1/asn1_lib.c +56 -76
- data/third_party/boringssl/crypto/asn1/asn1_locl.h +0 -10
- data/third_party/boringssl/crypto/asn1/asn1_par.c +0 -322
- data/third_party/boringssl/crypto/asn1/f_enum.c +1 -108
- data/third_party/boringssl/crypto/asn1/f_int.c +1 -106
- data/third_party/boringssl/crypto/asn1/f_string.c +1 -106
- data/third_party/boringssl/crypto/asn1/tasn_dec.c +10 -14
- data/third_party/boringssl/crypto/asn1/tasn_enc.c +17 -11
- data/third_party/boringssl/crypto/asn1/tasn_typ.c +29 -42
- data/third_party/boringssl/crypto/asn1/tasn_utl.c +1 -1
- data/third_party/boringssl/crypto/base64/base64.c +249 -285
- data/third_party/boringssl/crypto/bio/bio.c +13 -23
- data/third_party/boringssl/crypto/bio/bio_mem.c +3 -2
- data/third_party/boringssl/crypto/bio/connect.c +12 -3
- data/third_party/boringssl/crypto/bio/fd.c +22 -15
- data/third_party/boringssl/crypto/bio/file.c +2 -38
- data/third_party/boringssl/crypto/bio/hexdump.c +1 -2
- data/third_party/boringssl/crypto/bio/internal.h +3 -0
- data/third_party/boringssl/crypto/bio/pair.c +1 -1
- data/third_party/boringssl/crypto/bio/socket.c +10 -2
- data/third_party/boringssl/crypto/bio/socket_helper.c +2 -2
- data/third_party/boringssl/crypto/bn/asm/x86_64-gcc.c +0 -8
- data/third_party/boringssl/crypto/bn/bn.c +38 -0
- data/third_party/boringssl/crypto/bn/cmp.c +25 -0
- data/third_party/boringssl/crypto/bn/convert.c +73 -76
- data/third_party/boringssl/crypto/bn/div.c +136 -70
- data/third_party/boringssl/crypto/bn/exponentiation.c +86 -381
- data/third_party/boringssl/crypto/bn/gcd.c +213 -296
- data/third_party/boringssl/crypto/bn/generic.c +0 -80
- data/third_party/boringssl/crypto/bn/internal.h +15 -3
- data/third_party/boringssl/crypto/bn/montgomery.c +57 -207
- data/third_party/boringssl/crypto/bn/montgomery_inv.c +160 -0
- data/third_party/boringssl/crypto/bn/mul.c +2 -1
- data/third_party/boringssl/crypto/bn/prime.c +24 -8
- data/third_party/boringssl/crypto/bn/random.c +47 -33
- data/third_party/boringssl/crypto/bn/sqrt.c +4 -5
- data/third_party/boringssl/crypto/buf/buf.c +25 -21
- data/third_party/boringssl/crypto/bytestring/ber.c +1 -0
- data/third_party/boringssl/crypto/bytestring/cbb.c +50 -22
- data/third_party/boringssl/crypto/bytestring/cbs.c +28 -4
- data/third_party/boringssl/crypto/chacha/{chacha_generic.c → chacha.c} +56 -29
- data/third_party/boringssl/crypto/cipher/aead.c +11 -22
- data/third_party/boringssl/crypto/cipher/cipher.c +2 -2
- data/third_party/boringssl/crypto/cipher/e_aes.c +53 -103
- data/third_party/boringssl/crypto/cipher/e_chacha20poly1305.c +2 -8
- data/third_party/boringssl/crypto/cipher/e_des.c +3 -5
- data/third_party/boringssl/crypto/cipher/e_null.c +1 -1
- data/third_party/boringssl/crypto/cipher/e_rc2.c +1 -1
- data/third_party/boringssl/crypto/cipher/e_rc4.c +1 -1
- data/third_party/boringssl/crypto/cipher/e_ssl3.c +3 -63
- data/third_party/boringssl/crypto/cipher/e_tls.c +12 -83
- data/third_party/boringssl/crypto/cipher/internal.h +8 -10
- data/third_party/boringssl/crypto/cipher/tls_cbc.c +69 -40
- data/third_party/boringssl/crypto/conf/conf.c +2 -1
- data/third_party/boringssl/crypto/cpu-aarch64-linux.c +61 -0
- data/third_party/boringssl/crypto/cpu-arm-linux.c +360 -0
- data/third_party/boringssl/crypto/cpu-arm.c +0 -161
- data/third_party/boringssl/crypto/cpu-intel.c +5 -3
- data/third_party/boringssl/{ssl/test/scoped_types.h → crypto/cpu-ppc64le.c} +21 -9
- data/third_party/boringssl/crypto/crypto.c +29 -7
- data/third_party/boringssl/crypto/curve25519/curve25519.c +284 -242
- data/third_party/boringssl/crypto/curve25519/internal.h +64 -0
- data/third_party/boringssl/crypto/curve25519/spake25519.c +464 -0
- data/third_party/boringssl/crypto/curve25519/x25519-x86_64.c +21 -0
- data/third_party/boringssl/crypto/dh/check.c +22 -6
- data/third_party/boringssl/crypto/dh/dh.c +45 -21
- data/third_party/boringssl/crypto/dh/dh_asn1.c +96 -20
- data/third_party/boringssl/crypto/dh/params.c +30 -78
- data/third_party/boringssl/crypto/digest/digest.c +3 -3
- data/third_party/boringssl/crypto/dsa/dsa.c +59 -29
- data/third_party/boringssl/crypto/dsa/dsa_asn1.c +4 -0
- data/third_party/boringssl/crypto/ec/ec.c +84 -140
- data/third_party/boringssl/crypto/ec/ec_asn1.c +82 -52
- data/third_party/boringssl/crypto/ec/ec_key.c +15 -15
- data/third_party/boringssl/crypto/ec/ec_montgomery.c +87 -50
- data/third_party/boringssl/crypto/ec/internal.h +12 -36
- data/third_party/boringssl/crypto/ec/oct.c +11 -11
- data/third_party/boringssl/crypto/ec/p224-64.c +59 -116
- data/third_party/boringssl/crypto/ec/p256-64.c +88 -163
- data/third_party/boringssl/crypto/ec/p256-x86_64.c +46 -58
- data/third_party/boringssl/crypto/ec/simple.c +81 -201
- data/third_party/boringssl/crypto/ec/util-64.c +0 -74
- data/third_party/boringssl/crypto/ecdh/ecdh.c +7 -1
- data/third_party/boringssl/crypto/ecdsa/ecdsa.c +28 -46
- data/third_party/boringssl/crypto/ecdsa/ecdsa_asn1.c +1 -0
- data/third_party/boringssl/crypto/engine/engine.c +1 -1
- data/third_party/boringssl/crypto/err/err.c +3 -3
- data/third_party/boringssl/crypto/evp/evp.c +14 -59
- data/third_party/boringssl/crypto/evp/evp_asn1.c +144 -87
- data/third_party/boringssl/crypto/evp/evp_ctx.c +7 -7
- data/third_party/boringssl/crypto/evp/internal.h +4 -46
- data/third_party/boringssl/crypto/evp/p_dsa_asn1.c +8 -157
- data/third_party/boringssl/crypto/evp/p_ec.c +1 -1
- data/third_party/boringssl/crypto/evp/p_ec_asn1.c +22 -170
- data/third_party/boringssl/crypto/evp/p_rsa.c +1 -1
- data/third_party/boringssl/crypto/evp/p_rsa_asn1.c +10 -548
- data/third_party/boringssl/crypto/evp/print.c +520 -0
- data/third_party/boringssl/crypto/ex_data.c +4 -6
- data/third_party/boringssl/crypto/hkdf/hkdf.c +38 -17
- data/third_party/boringssl/crypto/hmac/hmac.c +6 -6
- data/third_party/boringssl/crypto/internal.h +57 -77
- data/third_party/boringssl/crypto/lhash/lhash.c +6 -10
- data/third_party/boringssl/crypto/md4/md4.c +9 -0
- data/third_party/boringssl/crypto/mem.c +19 -19
- data/third_party/boringssl/crypto/modes/cfb.c +5 -6
- data/third_party/boringssl/crypto/modes/ctr.c +10 -18
- data/third_party/boringssl/crypto/modes/gcm.c +100 -66
- data/third_party/boringssl/crypto/modes/internal.h +15 -27
- data/third_party/boringssl/crypto/modes/ofb.c +9 -22
- data/third_party/boringssl/crypto/newhope/error_correction.c +131 -0
- data/third_party/boringssl/crypto/newhope/internal.h +71 -0
- data/third_party/boringssl/crypto/newhope/newhope.c +174 -0
- data/third_party/boringssl/crypto/newhope/ntt.c +148 -0
- data/third_party/boringssl/crypto/newhope/poly.c +183 -0
- data/third_party/boringssl/crypto/newhope/precomp.c +306 -0
- data/third_party/boringssl/crypto/newhope/reduce.c +42 -0
- data/third_party/boringssl/crypto/obj/obj.c +111 -135
- data/third_party/boringssl/crypto/obj/obj_dat.h +4 -10
- data/third_party/boringssl/crypto/pem/pem_lib.c +6 -43
- data/third_party/boringssl/crypto/pem/pem_pkey.c +10 -19
- data/third_party/boringssl/crypto/pkcs8/p5_pbe.c +1 -0
- data/third_party/boringssl/crypto/pkcs8/p5_pbev2.c +2 -1
- data/third_party/boringssl/crypto/pkcs8/p8_pkey.c +2 -2
- data/third_party/boringssl/crypto/pkcs8/pkcs8.c +95 -87
- data/third_party/boringssl/crypto/{test/test_util.h → poly1305/internal.h} +15 -10
- data/third_party/boringssl/crypto/poly1305/poly1305.c +8 -15
- data/third_party/boringssl/crypto/poly1305/poly1305_arm.c +1 -0
- data/third_party/boringssl/crypto/poly1305/poly1305_vec.c +3 -3
- data/third_party/boringssl/crypto/rand/deterministic.c +47 -0
- data/third_party/boringssl/crypto/rand/rand.c +4 -1
- data/third_party/boringssl/crypto/rand/urandom.c +5 -7
- data/third_party/boringssl/crypto/rand/windows.c +5 -8
- data/third_party/boringssl/crypto/rc4/rc4.c +24 -209
- data/third_party/boringssl/crypto/refcount_lock.c +2 -2
- data/third_party/boringssl/crypto/rsa/blinding.c +74 -232
- data/third_party/boringssl/crypto/rsa/internal.h +5 -13
- data/third_party/boringssl/crypto/rsa/padding.c +64 -63
- data/third_party/boringssl/crypto/rsa/rsa.c +50 -28
- data/third_party/boringssl/crypto/rsa/rsa_asn1.c +8 -16
- data/third_party/boringssl/crypto/rsa/rsa_impl.c +134 -122
- data/third_party/boringssl/crypto/sha/sha256.c +2 -2
- data/third_party/boringssl/crypto/sha/sha512.c +7 -7
- data/third_party/boringssl/crypto/stack/stack.c +13 -22
- data/third_party/boringssl/crypto/thread.c +21 -12
- data/third_party/boringssl/crypto/thread_none.c +6 -2
- data/third_party/boringssl/crypto/thread_pthread.c +16 -7
- data/third_party/boringssl/crypto/thread_win.c +38 -85
- data/third_party/boringssl/crypto/x509/a_sign.c +3 -3
- data/third_party/boringssl/crypto/x509/a_strex.c +1 -1
- data/third_party/boringssl/crypto/x509/a_verify.c +2 -2
- data/third_party/boringssl/crypto/{evp → x509}/algorithm.c +37 -53
- data/third_party/boringssl/crypto/x509/asn1_gen.c +1 -2
- data/third_party/boringssl/crypto/x509/by_dir.c +6 -6
- data/third_party/boringssl/crypto/x509/internal.h +66 -0
- data/third_party/boringssl/crypto/x509/rsa_pss.c +385 -0
- data/third_party/boringssl/crypto/x509/t_x509.c +10 -12
- data/third_party/boringssl/crypto/x509/x509.c +5 -0
- data/third_party/boringssl/crypto/x509/x509_att.c +9 -3
- data/third_party/boringssl/crypto/x509/x509_lu.c +34 -44
- data/third_party/boringssl/crypto/x509/x509_obj.c +19 -2
- data/third_party/boringssl/crypto/x509/x509_r2x.c +9 -5
- data/third_party/boringssl/crypto/x509/x509_set.c +5 -0
- data/third_party/boringssl/crypto/x509/x509_txt.c +5 -0
- data/third_party/boringssl/crypto/x509/x509_vfy.c +63 -32
- data/third_party/boringssl/crypto/x509/x509_vpm.c +29 -18
- data/third_party/boringssl/crypto/x509/x509cset.c +2 -1
- data/third_party/boringssl/crypto/x509/x_crl.c +2 -2
- data/third_party/boringssl/crypto/x509/x_name.c +14 -17
- data/third_party/boringssl/crypto/x509/x_pubkey.c +10 -7
- data/third_party/boringssl/crypto/x509/x_x509.c +67 -6
- data/third_party/boringssl/crypto/x509v3/pcy_cache.c +2 -2
- data/third_party/boringssl/crypto/x509v3/pcy_tree.c +2 -1
- data/third_party/boringssl/crypto/x509v3/v3_conf.c +4 -3
- data/third_party/boringssl/crypto/x509v3/v3_cpols.c +5 -0
- data/third_party/boringssl/crypto/x509v3/v3_prn.c +0 -3
- data/third_party/boringssl/crypto/x509v3/v3_purp.c +2 -2
- data/third_party/boringssl/crypto/x509v3/v3_utl.c +2 -1
- data/third_party/boringssl/include/openssl/aead.h +72 -73
- data/third_party/boringssl/include/openssl/arm_arch.h +0 -6
- data/third_party/boringssl/include/openssl/asn1.h +103 -235
- data/third_party/boringssl/include/openssl/asn1_mac.h +17 -74
- data/third_party/boringssl/include/openssl/asn1t.h +1 -11
- data/third_party/boringssl/include/openssl/base.h +145 -3
- data/third_party/boringssl/include/openssl/base64.h +20 -17
- data/third_party/boringssl/include/openssl/bio.h +59 -34
- data/third_party/boringssl/include/openssl/bn.h +118 -51
- data/third_party/boringssl/include/openssl/buf.h +15 -0
- data/third_party/boringssl/include/openssl/bytestring.h +52 -4
- data/third_party/boringssl/include/openssl/chacha.h +2 -2
- data/third_party/boringssl/include/openssl/cipher.h +18 -1
- data/third_party/boringssl/include/openssl/cmac.h +11 -0
- data/third_party/boringssl/include/openssl/conf.h +13 -2
- data/third_party/boringssl/include/openssl/cpu.h +20 -23
- data/third_party/boringssl/include/openssl/crypto.h +22 -1
- data/third_party/boringssl/include/openssl/curve25519.h +96 -4
- data/third_party/boringssl/include/openssl/dh.h +71 -16
- data/third_party/boringssl/include/openssl/digest.h +38 -11
- data/third_party/boringssl/include/openssl/dsa.h +40 -4
- data/third_party/boringssl/include/openssl/ec.h +44 -18
- data/third_party/boringssl/include/openssl/ec_key.h +27 -6
- data/third_party/boringssl/include/openssl/ecdsa.h +11 -0
- data/third_party/boringssl/include/openssl/engine.h +11 -0
- data/third_party/boringssl/include/openssl/evp.h +52 -88
- data/third_party/boringssl/include/openssl/hkdf.h +24 -4
- data/third_party/boringssl/include/openssl/hmac.h +20 -6
- data/third_party/boringssl/include/openssl/md4.h +4 -0
- data/third_party/boringssl/include/openssl/mem.h +19 -0
- data/third_party/boringssl/include/openssl/newhope.h +158 -0
- data/third_party/boringssl/include/openssl/nid.h +4166 -0
- data/third_party/boringssl/include/openssl/obj.h +31 -3
- data/third_party/boringssl/include/openssl/obj_mac.h +17 -4143
- data/third_party/boringssl/include/openssl/{opensslfeatures.h → opensslconf.h} +3 -3
- data/third_party/boringssl/include/openssl/pem.h +5 -0
- data/third_party/boringssl/include/openssl/pkcs8.h +12 -0
- data/third_party/boringssl/include/openssl/rand.h +6 -0
- data/third_party/boringssl/include/openssl/rc4.h +6 -0
- data/third_party/boringssl/{crypto/dh/internal.h → include/openssl/ripemd.h} +38 -11
- data/third_party/boringssl/include/openssl/rsa.h +127 -65
- data/third_party/boringssl/include/openssl/sha.h +14 -10
- data/third_party/boringssl/include/openssl/ssl.h +561 -275
- data/third_party/boringssl/include/openssl/ssl3.h +18 -25
- data/third_party/boringssl/include/openssl/stack.h +2 -4
- data/third_party/boringssl/include/openssl/stack_macros.h +321 -353
- data/third_party/boringssl/include/openssl/thread.h +31 -13
- data/third_party/boringssl/include/openssl/time_support.h +1 -0
- data/third_party/boringssl/include/openssl/tls1.h +37 -33
- data/third_party/boringssl/include/openssl/x509.h +69 -26
- data/third_party/boringssl/include/openssl/x509_vfy.h +12 -10
- data/third_party/boringssl/include/openssl/x509v3.h +23 -2
- data/third_party/boringssl/ssl/custom_extensions.c +3 -5
- data/third_party/boringssl/ssl/d1_both.c +463 -499
- data/third_party/boringssl/ssl/d1_lib.c +38 -109
- data/third_party/boringssl/ssl/d1_pkt.c +173 -334
- data/third_party/boringssl/ssl/d1_srtp.c +20 -18
- data/third_party/boringssl/ssl/{d1_meth.c → dtls_method.c} +88 -15
- data/third_party/boringssl/ssl/dtls_record.c +27 -26
- data/third_party/boringssl/ssl/{s3_clnt.c → handshake_client.c} +816 -904
- data/third_party/boringssl/ssl/handshake_server.c +1932 -0
- data/third_party/boringssl/ssl/internal.h +712 -439
- data/third_party/boringssl/ssl/s3_both.c +445 -257
- data/third_party/boringssl/ssl/s3_enc.c +53 -36
- data/third_party/boringssl/ssl/s3_lib.c +23 -268
- data/third_party/boringssl/ssl/s3_pkt.c +168 -364
- data/third_party/boringssl/ssl/ssl_aead_ctx.c +46 -17
- data/third_party/boringssl/ssl/ssl_asn1.c +56 -26
- data/third_party/boringssl/ssl/ssl_buffer.c +16 -24
- data/third_party/boringssl/ssl/ssl_cert.c +324 -49
- data/third_party/boringssl/ssl/ssl_cipher.c +205 -150
- data/third_party/boringssl/ssl/ssl_ecdh.c +287 -51
- data/third_party/boringssl/ssl/ssl_file.c +21 -68
- data/third_party/boringssl/ssl/ssl_lib.c +881 -510
- data/third_party/boringssl/ssl/ssl_rsa.c +404 -34
- data/third_party/boringssl/ssl/ssl_session.c +324 -103
- data/third_party/boringssl/ssl/ssl_stat.c +6 -88
- data/third_party/boringssl/ssl/t1_enc.c +23 -39
- data/third_party/boringssl/ssl/t1_lib.c +1120 -622
- data/third_party/boringssl/ssl/tls13_both.c +440 -0
- data/third_party/boringssl/ssl/tls13_client.c +682 -0
- data/third_party/boringssl/ssl/tls13_enc.c +391 -0
- data/third_party/boringssl/ssl/tls13_server.c +672 -0
- data/third_party/boringssl/ssl/{s3_meth.c → tls_method.c} +100 -21
- data/third_party/boringssl/ssl/tls_record.c +159 -77
- data/third_party/nanopb/pb.h +60 -28
- data/third_party/nanopb/pb_decode.c +120 -92
- data/third_party/nanopb/pb_decode.h +3 -3
- data/third_party/nanopb/pb_encode.c +73 -67
- data/third_party/nanopb/pb_encode.h +4 -4
- metadata +155 -89
- data/include/grpc/impl/codegen/byte_buffer.h +0 -122
- data/include/grpc/impl/codegen/log.h +0 -118
- data/include/grpc/impl/codegen/time.h +0 -130
- data/src/core/ext/client_config/client_channel.c +0 -593
- data/src/core/ext/client_config/subchannel_call_holder.c +0 -272
- data/src/core/ext/client_config/subchannel_call_holder.h +0 -99
- data/src/core/lib/iomgr/ev_poll_and_epoll_posix.c +0 -2046
- data/src/core/lib/iomgr/workqueue_posix.c +0 -151
- data/src/core/lib/security/transport/handshake.c +0 -368
- data/third_party/boringssl/crypto/asn1/a_bytes.c +0 -308
- data/third_party/boringssl/crypto/asn1/bio_asn1.c +0 -477
- data/third_party/boringssl/crypto/asn1/bio_ndef.c +0 -251
- data/third_party/boringssl/crypto/asn1/t_pkey.c +0 -110
- data/third_party/boringssl/crypto/asn1/tasn_prn.c +0 -596
- data/third_party/boringssl/crypto/chacha/chacha_vec.c +0 -328
- data/third_party/boringssl/crypto/directory.h +0 -66
- data/third_party/boringssl/crypto/directory_posix.c +0 -108
- data/third_party/boringssl/crypto/directory_win.c +0 -144
- data/third_party/boringssl/crypto/test/scoped_types.h +0 -140
- data/third_party/boringssl/include/openssl/pqueue.h +0 -146
- data/third_party/boringssl/ssl/d1_clnt.c +0 -561
- data/third_party/boringssl/ssl/d1_srvr.c +0 -476
- data/third_party/boringssl/ssl/pqueue/pqueue.c +0 -197
- data/third_party/boringssl/ssl/s3_srvr.c +0 -2272
- data/third_party/boringssl/ssl/test/async_bio.h +0 -45
- data/third_party/boringssl/ssl/test/packeted_bio.h +0 -44
- data/third_party/boringssl/ssl/test/test_config.h +0 -110
@@ -116,17 +116,15 @@
|
|
116
116
|
|
117
117
|
#include <openssl/ssl.h>
|
118
118
|
|
119
|
-
#include <stdio.h>
|
120
119
|
#include <string.h>
|
121
120
|
|
122
121
|
#include <openssl/bytestring.h>
|
123
122
|
#include <openssl/err.h>
|
124
|
-
#include <openssl/obj.h>
|
125
123
|
|
126
124
|
#include "internal.h"
|
127
125
|
|
128
126
|
|
129
|
-
const SRTP_PROTECTION_PROFILE kSRTPProfiles[] = {
|
127
|
+
static const SRTP_PROTECTION_PROFILE kSRTPProfiles[] = {
|
130
128
|
{
|
131
129
|
"SRTP_AES128_CM_SHA1_80", SRTP_AES128_CM_SHA1_80,
|
132
130
|
},
|
@@ -162,27 +160,27 @@ static int find_profile_by_name(const char *profile_name,
|
|
162
160
|
|
163
161
|
static int ssl_ctx_make_profiles(const char *profiles_string,
|
164
162
|
STACK_OF(SRTP_PROTECTION_PROFILE) **out) {
|
165
|
-
STACK_OF(SRTP_PROTECTION_PROFILE) *profiles
|
166
|
-
|
167
|
-
const char *col;
|
168
|
-
const char *ptr = profiles_string;
|
169
|
-
|
170
|
-
profiles = sk_SRTP_PROTECTION_PROFILE_new_null();
|
163
|
+
STACK_OF(SRTP_PROTECTION_PROFILE) *profiles =
|
164
|
+
sk_SRTP_PROTECTION_PROFILE_new_null();
|
171
165
|
if (profiles == NULL) {
|
172
166
|
OPENSSL_PUT_ERROR(SSL, SSL_R_SRTP_COULD_NOT_ALLOCATE_PROFILES);
|
173
167
|
return 0;
|
174
168
|
}
|
175
169
|
|
170
|
+
const char *col;
|
171
|
+
const char *ptr = profiles_string;
|
176
172
|
do {
|
177
|
-
const SRTP_PROTECTION_PROFILE *p;
|
178
|
-
|
179
173
|
col = strchr(ptr, ':');
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
174
|
+
|
175
|
+
const SRTP_PROTECTION_PROFILE *profile;
|
176
|
+
if (!find_profile_by_name(ptr, &profile,
|
177
|
+
col ? (size_t)(col - ptr) : strlen(ptr))) {
|
184
178
|
OPENSSL_PUT_ERROR(SSL, SSL_R_SRTP_UNKNOWN_PROTECTION_PROFILE);
|
185
|
-
|
179
|
+
goto err;
|
180
|
+
}
|
181
|
+
|
182
|
+
if (!sk_SRTP_PROTECTION_PROFILE_push(profiles, profile)) {
|
183
|
+
goto err;
|
186
184
|
}
|
187
185
|
|
188
186
|
if (col) {
|
@@ -190,9 +188,13 @@ static int ssl_ctx_make_profiles(const char *profiles_string,
|
|
190
188
|
}
|
191
189
|
} while (col);
|
192
190
|
|
191
|
+
sk_SRTP_PROTECTION_PROFILE_free(*out);
|
193
192
|
*out = profiles;
|
194
|
-
|
195
193
|
return 1;
|
194
|
+
|
195
|
+
err:
|
196
|
+
sk_SRTP_PROTECTION_PROFILE_free(profiles);
|
197
|
+
return 0;
|
196
198
|
}
|
197
199
|
|
198
200
|
int SSL_CTX_set_srtp_profiles(SSL_CTX *ctx, const char *profiles) {
|
@@ -212,7 +214,7 @@ STACK_OF(SRTP_PROTECTION_PROFILE) *SSL_get_srtp_profiles(SSL *ssl) {
|
|
212
214
|
return ssl->srtp_profiles;
|
213
215
|
}
|
214
216
|
|
215
|
-
if (ssl->ctx
|
217
|
+
if (ssl->ctx->srtp_profiles != NULL) {
|
216
218
|
return ssl->ctx->srtp_profiles;
|
217
219
|
}
|
218
220
|
|
@@ -56,51 +56,124 @@
|
|
56
56
|
|
57
57
|
#include <openssl/ssl.h>
|
58
58
|
|
59
|
+
#include <assert.h>
|
60
|
+
#include <string.h>
|
61
|
+
|
62
|
+
#include <openssl/buf.h>
|
63
|
+
#include <openssl/err.h>
|
64
|
+
|
59
65
|
#include "internal.h"
|
60
66
|
|
61
67
|
|
62
|
-
static
|
68
|
+
static int dtls1_version_from_wire(uint16_t *out_version,
|
69
|
+
uint16_t wire_version) {
|
70
|
+
switch (wire_version) {
|
71
|
+
case DTLS1_VERSION:
|
72
|
+
/* DTLS 1.0 maps to TLS 1.1, not TLS 1.0. */
|
73
|
+
*out_version = TLS1_1_VERSION;
|
74
|
+
return 1;
|
75
|
+
case DTLS1_2_VERSION:
|
76
|
+
*out_version = TLS1_2_VERSION;
|
77
|
+
return 1;
|
78
|
+
}
|
79
|
+
|
80
|
+
return 0;
|
81
|
+
}
|
82
|
+
|
83
|
+
static uint16_t dtls1_version_to_wire(uint16_t version) {
|
84
|
+
switch (version) {
|
85
|
+
case TLS1_1_VERSION:
|
86
|
+
/* DTLS 1.0 maps to TLS 1.1, not TLS 1.0. */
|
87
|
+
return DTLS1_VERSION;
|
88
|
+
case TLS1_2_VERSION:
|
89
|
+
return DTLS1_2_VERSION;
|
90
|
+
}
|
91
|
+
|
92
|
+
/* It is an error to use this function with an invalid version. */
|
93
|
+
assert(0);
|
94
|
+
return 0;
|
95
|
+
}
|
96
|
+
|
97
|
+
static int dtls1_set_read_state(SSL *ssl, SSL_AEAD_CTX *aead_ctx) {
|
98
|
+
/* Cipher changes are illegal when there are buffered incoming messages. */
|
99
|
+
if (dtls_has_incoming_messages(ssl)) {
|
100
|
+
OPENSSL_PUT_ERROR(SSL, SSL_R_BUFFERED_MESSAGES_ON_CIPHER_CHANGE);
|
101
|
+
ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE);
|
102
|
+
SSL_AEAD_CTX_free(aead_ctx);
|
103
|
+
return 0;
|
104
|
+
}
|
105
|
+
|
106
|
+
ssl->d1->r_epoch++;
|
107
|
+
memset(&ssl->d1->bitmap, 0, sizeof(ssl->d1->bitmap));
|
108
|
+
memset(ssl->s3->read_sequence, 0, sizeof(ssl->s3->read_sequence));
|
109
|
+
|
110
|
+
SSL_AEAD_CTX_free(ssl->s3->aead_read_ctx);
|
111
|
+
ssl->s3->aead_read_ctx = aead_ctx;
|
112
|
+
return 1;
|
113
|
+
}
|
114
|
+
|
115
|
+
static int dtls1_set_write_state(SSL *ssl, SSL_AEAD_CTX *aead_ctx) {
|
116
|
+
ssl->d1->w_epoch++;
|
117
|
+
memcpy(ssl->d1->last_write_sequence, ssl->s3->write_sequence,
|
118
|
+
sizeof(ssl->s3->write_sequence));
|
119
|
+
memset(ssl->s3->write_sequence, 0, sizeof(ssl->s3->write_sequence));
|
120
|
+
|
121
|
+
SSL_AEAD_CTX_free(ssl->s3->aead_write_ctx);
|
122
|
+
ssl->s3->aead_write_ctx = aead_ctx;
|
123
|
+
return 1;
|
124
|
+
}
|
125
|
+
|
126
|
+
static const SSL_PROTOCOL_METHOD kDTLSProtocolMethod = {
|
63
127
|
1 /* is_dtls */,
|
128
|
+
TLS1_1_VERSION,
|
129
|
+
TLS1_2_VERSION,
|
130
|
+
dtls1_version_from_wire,
|
131
|
+
dtls1_version_to_wire,
|
64
132
|
dtls1_new,
|
65
133
|
dtls1_free,
|
66
|
-
dtls1_accept,
|
67
|
-
dtls1_connect,
|
68
134
|
dtls1_get_message,
|
135
|
+
dtls1_hash_current_message,
|
136
|
+
dtls1_release_current_message,
|
69
137
|
dtls1_read_app_data,
|
70
138
|
dtls1_read_change_cipher_spec,
|
71
139
|
dtls1_read_close_notify,
|
72
140
|
dtls1_write_app_data,
|
73
141
|
dtls1_dispatch_alert,
|
74
142
|
dtls1_supports_cipher,
|
75
|
-
|
76
|
-
|
77
|
-
|
143
|
+
dtls1_init_message,
|
144
|
+
dtls1_finish_message,
|
145
|
+
dtls1_write_message,
|
146
|
+
dtls1_send_change_cipher_spec,
|
147
|
+
dtls1_expect_flight,
|
148
|
+
dtls1_received_flight,
|
149
|
+
dtls1_set_read_state,
|
150
|
+
dtls1_set_write_state,
|
78
151
|
};
|
79
152
|
|
80
153
|
const SSL_METHOD *DTLS_method(void) {
|
81
|
-
static const SSL_METHOD
|
154
|
+
static const SSL_METHOD kMethod = {
|
82
155
|
0,
|
83
|
-
&
|
156
|
+
&kDTLSProtocolMethod,
|
84
157
|
};
|
85
|
-
return &
|
158
|
+
return &kMethod;
|
86
159
|
}
|
87
160
|
|
88
161
|
/* Legacy version-locked methods. */
|
89
162
|
|
90
163
|
const SSL_METHOD *DTLSv1_2_method(void) {
|
91
|
-
static const SSL_METHOD
|
164
|
+
static const SSL_METHOD kMethod = {
|
92
165
|
DTLS1_2_VERSION,
|
93
|
-
&
|
166
|
+
&kDTLSProtocolMethod,
|
94
167
|
};
|
95
|
-
return &
|
168
|
+
return &kMethod;
|
96
169
|
}
|
97
170
|
|
98
171
|
const SSL_METHOD *DTLSv1_method(void) {
|
99
|
-
static const SSL_METHOD
|
172
|
+
static const SSL_METHOD kMethod = {
|
100
173
|
DTLS1_VERSION,
|
101
|
-
&
|
174
|
+
&kDTLSProtocolMethod,
|
102
175
|
};
|
103
|
-
return &
|
176
|
+
return &kMethod;
|
104
177
|
}
|
105
178
|
|
106
179
|
/* Legacy side-specific methods. */
|
@@ -118,6 +118,7 @@
|
|
118
118
|
#include <openssl/err.h>
|
119
119
|
|
120
120
|
#include "internal.h"
|
121
|
+
#include "../crypto/internal.h"
|
121
122
|
|
122
123
|
|
123
124
|
/* to_u64_be treats |in| as a 8-byte big-endian integer and returns the value as
|
@@ -171,10 +172,12 @@ static void dtls1_bitmap_record(DTLS1_BITMAP *bitmap,
|
|
171
172
|
}
|
172
173
|
}
|
173
174
|
|
174
|
-
enum ssl_open_record_t dtls_open_record(
|
175
|
-
|
176
|
-
|
177
|
-
|
175
|
+
enum ssl_open_record_t dtls_open_record(SSL *ssl, uint8_t *out_type, CBS *out,
|
176
|
+
size_t *out_consumed,
|
177
|
+
uint8_t *out_alert, uint8_t *in,
|
178
|
+
size_t in_len) {
|
179
|
+
*out_consumed = 0;
|
180
|
+
|
178
181
|
CBS cbs;
|
179
182
|
CBS_init(&cbs, in, in_len);
|
180
183
|
|
@@ -195,10 +198,8 @@ enum ssl_open_record_t dtls_open_record(
|
|
195
198
|
return ssl_open_record_discard;
|
196
199
|
}
|
197
200
|
|
198
|
-
|
199
|
-
|
200
|
-
DTLS1_RT_HEADER_LENGTH, ssl, ssl->msg_callback_arg);
|
201
|
-
}
|
201
|
+
ssl_do_msg_callback(ssl, 0 /* read */, SSL3_RT_HEADER, in,
|
202
|
+
DTLS1_RT_HEADER_LENGTH);
|
202
203
|
|
203
204
|
uint16_t epoch = (((uint16_t)sequence[0]) << 8) | sequence[1];
|
204
205
|
if (epoch != ssl->d1->r_epoch ||
|
@@ -211,11 +212,9 @@ enum ssl_open_record_t dtls_open_record(
|
|
211
212
|
return ssl_open_record_discard;
|
212
213
|
}
|
213
214
|
|
214
|
-
/* Decrypt the body. */
|
215
|
-
|
216
|
-
|
217
|
-
type, version, sequence, CBS_data(&body),
|
218
|
-
CBS_len(&body))) {
|
215
|
+
/* Decrypt the body in-place. */
|
216
|
+
if (!SSL_AEAD_CTX_open(ssl->s3->aead_read_ctx, out, type, version, sequence,
|
217
|
+
(uint8_t *)CBS_data(&body), CBS_len(&body))) {
|
219
218
|
/* Bad packets are silently dropped in DTLS. See section 4.2.1 of RFC 6347.
|
220
219
|
* Clear the error queue of any errors decryption may have added. Drop the
|
221
220
|
* entire packet as it must not have come from the peer.
|
@@ -226,9 +225,10 @@ enum ssl_open_record_t dtls_open_record(
|
|
226
225
|
*out_consumed = in_len - CBS_len(&cbs);
|
227
226
|
return ssl_open_record_discard;
|
228
227
|
}
|
228
|
+
*out_consumed = in_len - CBS_len(&cbs);
|
229
229
|
|
230
230
|
/* Check the plaintext length. */
|
231
|
-
if (
|
231
|
+
if (CBS_len(out) > SSL3_RT_MAX_PLAIN_LENGTH) {
|
232
232
|
OPENSSL_PUT_ERROR(SSL, SSL_R_DATA_LENGTH_TOO_LONG);
|
233
233
|
*out_alert = SSL_AD_RECORD_OVERFLOW;
|
234
234
|
return ssl_open_record_error;
|
@@ -239,15 +239,24 @@ enum ssl_open_record_t dtls_open_record(
|
|
239
239
|
/* TODO(davidben): Limit the number of empty records as in TLS? This is only
|
240
240
|
* useful if we also limit discarded packets. */
|
241
241
|
|
242
|
+
if (type == SSL3_RT_ALERT) {
|
243
|
+
return ssl_process_alert(ssl, out_alert, CBS_data(out), CBS_len(out));
|
244
|
+
}
|
245
|
+
|
246
|
+
ssl->s3->warning_alert_count = 0;
|
247
|
+
|
242
248
|
*out_type = type;
|
243
|
-
*out_len = plaintext_len;
|
244
|
-
*out_consumed = in_len - CBS_len(&cbs);
|
245
249
|
return ssl_open_record_success;
|
246
250
|
}
|
247
251
|
|
248
252
|
int dtls_seal_record(SSL *ssl, uint8_t *out, size_t *out_len, size_t max_out,
|
249
253
|
uint8_t type, const uint8_t *in, size_t in_len,
|
250
254
|
enum dtls1_use_epoch_t use_epoch) {
|
255
|
+
if (buffers_alias(in, in_len, out, max_out)) {
|
256
|
+
OPENSSL_PUT_ERROR(SSL, SSL_R_OUTPUT_ALIASES_INPUT);
|
257
|
+
return 0;
|
258
|
+
}
|
259
|
+
|
251
260
|
/* Determine the parameters for the current epoch. */
|
252
261
|
uint16_t epoch = ssl->d1->w_epoch;
|
253
262
|
SSL_AEAD_CTX *aead = ssl->s3->aead_write_ctx;
|
@@ -265,12 +274,6 @@ int dtls_seal_record(SSL *ssl, uint8_t *out, size_t *out_len, size_t max_out,
|
|
265
274
|
OPENSSL_PUT_ERROR(SSL, SSL_R_BUFFER_TOO_SMALL);
|
266
275
|
return 0;
|
267
276
|
}
|
268
|
-
/* Check the record header does not alias any part of the input.
|
269
|
-
* |SSL_AEAD_CTX_seal| will internally enforce other aliasing requirements. */
|
270
|
-
if (in < out + DTLS1_RT_HEADER_LENGTH && out < in + in_len) {
|
271
|
-
OPENSSL_PUT_ERROR(SSL, SSL_R_OUTPUT_ALIASES_INPUT);
|
272
|
-
return 0;
|
273
|
-
}
|
274
277
|
|
275
278
|
out[0] = type;
|
276
279
|
|
@@ -299,10 +302,8 @@ int dtls_seal_record(SSL *ssl, uint8_t *out, size_t *out_len, size_t max_out,
|
|
299
302
|
|
300
303
|
*out_len = DTLS1_RT_HEADER_LENGTH + ciphertext_len;
|
301
304
|
|
302
|
-
|
303
|
-
|
304
|
-
DTLS1_RT_HEADER_LENGTH, ssl, ssl->msg_callback_arg);
|
305
|
-
}
|
305
|
+
ssl_do_msg_callback(ssl, 1 /* write */, SSL3_RT_HEADER, out,
|
306
|
+
DTLS1_RT_HEADER_LENGTH);
|
306
307
|
|
307
308
|
return 1;
|
308
309
|
}
|
@@ -150,7 +150,6 @@
|
|
150
150
|
#include <openssl/ssl.h>
|
151
151
|
|
152
152
|
#include <assert.h>
|
153
|
-
#include <stdio.h>
|
154
153
|
#include <string.h>
|
155
154
|
|
156
155
|
#include <openssl/bn.h>
|
@@ -163,184 +162,184 @@
|
|
163
162
|
#include <openssl/evp.h>
|
164
163
|
#include <openssl/md5.h>
|
165
164
|
#include <openssl/mem.h>
|
166
|
-
#include <openssl/obj.h>
|
167
165
|
#include <openssl/rand.h>
|
168
166
|
#include <openssl/x509.h>
|
169
167
|
#include <openssl/x509v3.h>
|
170
168
|
|
171
169
|
#include "internal.h"
|
172
|
-
#include "../crypto/dh/internal.h"
|
173
170
|
|
174
171
|
|
172
|
+
static int ssl3_send_client_hello(SSL *ssl);
|
173
|
+
static int dtls1_get_hello_verify(SSL *ssl);
|
174
|
+
static int ssl3_get_server_hello(SSL *ssl);
|
175
|
+
static int ssl3_get_server_certificate(SSL *ssl);
|
176
|
+
static int ssl3_get_cert_status(SSL *ssl);
|
177
|
+
static int ssl3_verify_server_cert(SSL *ssl);
|
178
|
+
static int ssl3_get_server_key_exchange(SSL *ssl);
|
179
|
+
static int ssl3_get_certificate_request(SSL *ssl);
|
180
|
+
static int ssl3_get_server_hello_done(SSL *ssl);
|
181
|
+
static int ssl3_send_client_certificate(SSL *ssl);
|
182
|
+
static int ssl3_send_client_key_exchange(SSL *ssl);
|
183
|
+
static int ssl3_send_cert_verify(SSL *ssl);
|
184
|
+
static int ssl3_send_next_proto(SSL *ssl);
|
185
|
+
static int ssl3_send_channel_id(SSL *ssl);
|
186
|
+
static int ssl3_get_new_session_ticket(SSL *ssl);
|
187
|
+
|
175
188
|
int ssl3_connect(SSL *ssl) {
|
176
|
-
BUF_MEM *buf = NULL;
|
177
|
-
void (*cb)(const SSL *ssl, int type, int value) = NULL;
|
178
189
|
int ret = -1;
|
179
|
-
int
|
190
|
+
int state, skip = 0;
|
180
191
|
|
181
192
|
assert(ssl->handshake_func == ssl3_connect);
|
182
193
|
assert(!ssl->server);
|
183
|
-
assert(!SSL_IS_DTLS(ssl));
|
184
|
-
|
185
|
-
ERR_clear_error();
|
186
|
-
ERR_clear_system_error();
|
187
|
-
|
188
|
-
if (ssl->info_callback != NULL) {
|
189
|
-
cb = ssl->info_callback;
|
190
|
-
} else if (ssl->ctx->info_callback != NULL) {
|
191
|
-
cb = ssl->ctx->info_callback;
|
192
|
-
}
|
193
|
-
|
194
|
-
ssl->in_handshake++;
|
195
194
|
|
196
195
|
for (;;) {
|
197
196
|
state = ssl->state;
|
198
197
|
|
199
198
|
switch (ssl->state) {
|
200
|
-
case
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
if (ssl->init_buf == NULL) {
|
206
|
-
buf = BUF_MEM_new();
|
207
|
-
if (buf == NULL ||
|
208
|
-
!BUF_MEM_grow(buf, SSL3_RT_MAX_PLAIN_LENGTH)) {
|
209
|
-
ret = -1;
|
210
|
-
goto end;
|
211
|
-
}
|
199
|
+
case SSL_ST_INIT:
|
200
|
+
ssl->state = SSL_ST_CONNECT;
|
201
|
+
skip = 1;
|
202
|
+
break;
|
212
203
|
|
213
|
-
|
214
|
-
|
215
|
-
}
|
204
|
+
case SSL_ST_CONNECT:
|
205
|
+
ssl_do_info_callback(ssl, SSL_CB_HANDSHAKE_START, 1);
|
216
206
|
|
217
|
-
|
207
|
+
ssl->s3->hs = ssl_handshake_new(tls13_client_handshake);
|
208
|
+
if (ssl->s3->hs == NULL) {
|
218
209
|
ret = -1;
|
219
210
|
goto end;
|
220
211
|
}
|
221
212
|
|
222
|
-
|
223
|
-
|
224
|
-
if (!ssl3_init_handshake_buffer(ssl)) {
|
225
|
-
OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
|
213
|
+
if (!ssl_init_wbio_buffer(ssl)) {
|
226
214
|
ret = -1;
|
227
215
|
goto end;
|
228
216
|
}
|
229
217
|
|
230
218
|
ssl->state = SSL3_ST_CW_CLNT_HELLO_A;
|
231
|
-
ssl->init_num = 0;
|
232
219
|
break;
|
233
220
|
|
234
221
|
case SSL3_ST_CW_CLNT_HELLO_A:
|
235
222
|
case SSL3_ST_CW_CLNT_HELLO_B:
|
236
|
-
ssl->shutdown = 0;
|
237
223
|
ret = ssl3_send_client_hello(ssl);
|
238
224
|
if (ret <= 0) {
|
239
225
|
goto end;
|
240
226
|
}
|
241
|
-
ssl->state = SSL3_ST_CR_SRVR_HELLO_A;
|
242
|
-
ssl->init_num = 0;
|
243
227
|
|
244
|
-
|
245
|
-
|
246
|
-
|
228
|
+
if (!SSL_is_dtls(ssl) || ssl->d1->send_cookie) {
|
229
|
+
ssl->s3->tmp.next_state = SSL3_ST_CR_SRVR_HELLO_A;
|
230
|
+
} else {
|
231
|
+
ssl->s3->tmp.next_state = DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A;
|
247
232
|
}
|
233
|
+
ssl->state = SSL3_ST_CW_FLUSH;
|
234
|
+
break;
|
248
235
|
|
236
|
+
case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:
|
237
|
+
assert(SSL_is_dtls(ssl));
|
238
|
+
ret = dtls1_get_hello_verify(ssl);
|
239
|
+
if (ret <= 0) {
|
240
|
+
goto end;
|
241
|
+
}
|
242
|
+
if (ssl->d1->send_cookie) {
|
243
|
+
ssl->method->received_flight(ssl);
|
244
|
+
ssl->state = SSL3_ST_CW_CLNT_HELLO_A;
|
245
|
+
} else {
|
246
|
+
ssl->state = SSL3_ST_CR_SRVR_HELLO_A;
|
247
|
+
}
|
249
248
|
break;
|
250
249
|
|
251
250
|
case SSL3_ST_CR_SRVR_HELLO_A:
|
252
|
-
case SSL3_ST_CR_SRVR_HELLO_B:
|
253
251
|
ret = ssl3_get_server_hello(ssl);
|
252
|
+
if (ssl->state == SSL_ST_TLS13) {
|
253
|
+
break;
|
254
|
+
}
|
254
255
|
if (ret <= 0) {
|
255
256
|
goto end;
|
256
257
|
}
|
257
258
|
|
258
|
-
if (ssl->
|
259
|
-
ssl->state =
|
260
|
-
if (ssl->tlsext_ticket_expected) {
|
261
|
-
/* receive renewed session ticket */
|
262
|
-
ssl->state = SSL3_ST_CR_SESSION_TICKET_A;
|
263
|
-
}
|
259
|
+
if (ssl->session != NULL) {
|
260
|
+
ssl->state = SSL3_ST_CR_SESSION_TICKET_A;
|
264
261
|
} else {
|
265
262
|
ssl->state = SSL3_ST_CR_CERT_A;
|
266
263
|
}
|
267
|
-
ssl->init_num = 0;
|
268
264
|
break;
|
269
265
|
|
270
266
|
case SSL3_ST_CR_CERT_A:
|
271
|
-
|
272
|
-
if (ssl_cipher_has_server_public_key(ssl->s3->tmp.new_cipher)) {
|
267
|
+
if (ssl_cipher_uses_certificate_auth(ssl->s3->tmp.new_cipher)) {
|
273
268
|
ret = ssl3_get_server_certificate(ssl);
|
274
269
|
if (ret <= 0) {
|
275
270
|
goto end;
|
276
271
|
}
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
272
|
+
} else {
|
273
|
+
skip = 1;
|
274
|
+
}
|
275
|
+
ssl->state = SSL3_ST_CR_CERT_STATUS_A;
|
276
|
+
break;
|
277
|
+
|
278
|
+
case SSL3_ST_CR_CERT_STATUS_A:
|
279
|
+
if (ssl->s3->tmp.certificate_status_expected) {
|
280
|
+
ret = ssl3_get_cert_status(ssl);
|
281
|
+
if (ret <= 0) {
|
282
|
+
goto end;
|
281
283
|
}
|
282
284
|
} else {
|
283
285
|
skip = 1;
|
284
|
-
ssl->state = SSL3_ST_CR_KEY_EXCH_A;
|
285
286
|
}
|
286
|
-
ssl->
|
287
|
+
ssl->state = SSL3_ST_VERIFY_SERVER_CERT;
|
287
288
|
break;
|
288
289
|
|
289
290
|
case SSL3_ST_VERIFY_SERVER_CERT:
|
290
|
-
|
291
|
-
|
292
|
-
|
291
|
+
if (ssl_cipher_uses_certificate_auth(ssl->s3->tmp.new_cipher)) {
|
292
|
+
ret = ssl3_verify_server_cert(ssl);
|
293
|
+
if (ret <= 0) {
|
294
|
+
goto end;
|
295
|
+
}
|
296
|
+
} else {
|
297
|
+
skip = 1;
|
293
298
|
}
|
294
|
-
|
295
299
|
ssl->state = SSL3_ST_CR_KEY_EXCH_A;
|
296
|
-
ssl->init_num = 0;
|
297
300
|
break;
|
298
301
|
|
299
302
|
case SSL3_ST_CR_KEY_EXCH_A:
|
300
|
-
case SSL3_ST_CR_KEY_EXCH_B:
|
301
303
|
ret = ssl3_get_server_key_exchange(ssl);
|
302
304
|
if (ret <= 0) {
|
303
305
|
goto end;
|
304
306
|
}
|
305
307
|
ssl->state = SSL3_ST_CR_CERT_REQ_A;
|
306
|
-
ssl->init_num = 0;
|
307
308
|
break;
|
308
309
|
|
309
310
|
case SSL3_ST_CR_CERT_REQ_A:
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
311
|
+
if (ssl_cipher_uses_certificate_auth(ssl->s3->tmp.new_cipher)) {
|
312
|
+
ret = ssl3_get_certificate_request(ssl);
|
313
|
+
if (ret <= 0) {
|
314
|
+
goto end;
|
315
|
+
}
|
316
|
+
} else {
|
317
|
+
skip = 1;
|
314
318
|
}
|
315
319
|
ssl->state = SSL3_ST_CR_SRVR_DONE_A;
|
316
|
-
ssl->init_num = 0;
|
317
320
|
break;
|
318
321
|
|
319
322
|
case SSL3_ST_CR_SRVR_DONE_A:
|
320
|
-
|
321
|
-
ret = ssl3_get_server_done(ssl);
|
323
|
+
ret = ssl3_get_server_hello_done(ssl);
|
322
324
|
if (ret <= 0) {
|
323
325
|
goto end;
|
324
326
|
}
|
325
|
-
|
326
|
-
|
327
|
-
} else {
|
328
|
-
ssl->state = SSL3_ST_CW_KEY_EXCH_A;
|
329
|
-
}
|
330
|
-
ssl->init_num = 0;
|
331
|
-
|
327
|
+
ssl->method->received_flight(ssl);
|
328
|
+
ssl->state = SSL3_ST_CW_CERT_A;
|
332
329
|
break;
|
333
330
|
|
334
331
|
case SSL3_ST_CW_CERT_A:
|
335
332
|
case SSL3_ST_CW_CERT_B:
|
336
333
|
case SSL3_ST_CW_CERT_C:
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
334
|
+
if (ssl->s3->tmp.cert_request) {
|
335
|
+
ret = ssl3_send_client_certificate(ssl);
|
336
|
+
if (ret <= 0) {
|
337
|
+
goto end;
|
338
|
+
}
|
339
|
+
} else {
|
340
|
+
skip = 1;
|
341
341
|
}
|
342
342
|
ssl->state = SSL3_ST_CW_KEY_EXCH_A;
|
343
|
-
ssl->init_num = 0;
|
344
343
|
break;
|
345
344
|
|
346
345
|
case SSL3_ST_CW_KEY_EXCH_A:
|
@@ -349,44 +348,30 @@ int ssl3_connect(SSL *ssl) {
|
|
349
348
|
if (ret <= 0) {
|
350
349
|
goto end;
|
351
350
|
}
|
352
|
-
|
353
|
-
* of nothing is sent, but no verify packet is sent */
|
354
|
-
if (ssl->s3->tmp.cert_req == 1) {
|
355
|
-
ssl->state = SSL3_ST_CW_CERT_VRFY_A;
|
356
|
-
} else {
|
357
|
-
ssl->state = SSL3_ST_CW_CHANGE_A;
|
358
|
-
}
|
359
|
-
|
360
|
-
ssl->init_num = 0;
|
351
|
+
ssl->state = SSL3_ST_CW_CERT_VRFY_A;
|
361
352
|
break;
|
362
353
|
|
363
354
|
case SSL3_ST_CW_CERT_VRFY_A:
|
364
355
|
case SSL3_ST_CW_CERT_VRFY_B:
|
365
356
|
case SSL3_ST_CW_CERT_VRFY_C:
|
366
|
-
|
367
|
-
|
368
|
-
|
357
|
+
if (ssl->s3->tmp.cert_request) {
|
358
|
+
ret = ssl3_send_cert_verify(ssl);
|
359
|
+
if (ret <= 0) {
|
360
|
+
goto end;
|
361
|
+
}
|
362
|
+
} else {
|
363
|
+
skip = 1;
|
369
364
|
}
|
370
|
-
ssl->state =
|
371
|
-
ssl->init_num = 0;
|
365
|
+
ssl->state = SSL3_ST_CW_CHANGE;
|
372
366
|
break;
|
373
367
|
|
374
|
-
case
|
375
|
-
|
376
|
-
ret = ssl3_send_change_cipher_spec(ssl, SSL3_ST_CW_CHANGE_A,
|
377
|
-
SSL3_ST_CW_CHANGE_B);
|
368
|
+
case SSL3_ST_CW_CHANGE:
|
369
|
+
ret = ssl->method->send_change_cipher_spec(ssl);
|
378
370
|
if (ret <= 0) {
|
379
371
|
goto end;
|
380
372
|
}
|
381
373
|
|
382
|
-
ssl->state =
|
383
|
-
if (ssl->s3->tlsext_channel_id_valid) {
|
384
|
-
ssl->state = SSL3_ST_CW_CHANNEL_ID_A;
|
385
|
-
}
|
386
|
-
if (ssl->s3->next_proto_neg_seen) {
|
387
|
-
ssl->state = SSL3_ST_CW_NEXT_PROTO_A;
|
388
|
-
}
|
389
|
-
ssl->init_num = 0;
|
374
|
+
ssl->state = SSL3_ST_CW_NEXT_PROTO_A;
|
390
375
|
|
391
376
|
if (!tls1_change_cipher_state(ssl, SSL3_CHANGE_CIPHER_CLIENT_WRITE)) {
|
392
377
|
ret = -1;
|
@@ -397,23 +382,26 @@ int ssl3_connect(SSL *ssl) {
|
|
397
382
|
|
398
383
|
case SSL3_ST_CW_NEXT_PROTO_A:
|
399
384
|
case SSL3_ST_CW_NEXT_PROTO_B:
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
if (ssl->s3->tlsext_channel_id_valid) {
|
406
|
-
ssl->state = SSL3_ST_CW_CHANNEL_ID_A;
|
385
|
+
if (ssl->s3->next_proto_neg_seen) {
|
386
|
+
ret = ssl3_send_next_proto(ssl);
|
387
|
+
if (ret <= 0) {
|
388
|
+
goto end;
|
389
|
+
}
|
407
390
|
} else {
|
408
|
-
|
391
|
+
skip = 1;
|
409
392
|
}
|
393
|
+
ssl->state = SSL3_ST_CW_CHANNEL_ID_A;
|
410
394
|
break;
|
411
395
|
|
412
396
|
case SSL3_ST_CW_CHANNEL_ID_A:
|
413
397
|
case SSL3_ST_CW_CHANNEL_ID_B:
|
414
|
-
|
415
|
-
|
416
|
-
|
398
|
+
if (ssl->s3->tlsext_channel_id_valid) {
|
399
|
+
ret = ssl3_send_channel_id(ssl);
|
400
|
+
if (ret <= 0) {
|
401
|
+
goto end;
|
402
|
+
}
|
403
|
+
} else {
|
404
|
+
skip = 1;
|
417
405
|
}
|
418
406
|
ssl->state = SSL3_ST_CW_FINISHED_A;
|
419
407
|
break;
|
@@ -427,7 +415,7 @@ int ssl3_connect(SSL *ssl) {
|
|
427
415
|
}
|
428
416
|
ssl->state = SSL3_ST_CW_FLUSH;
|
429
417
|
|
430
|
-
if (ssl->
|
418
|
+
if (ssl->session != NULL) {
|
431
419
|
ssl->s3->tmp.next_state = SSL_ST_OK;
|
432
420
|
} else {
|
433
421
|
/* This is a non-resumption handshake. If it involves ChannelID, then
|
@@ -445,39 +433,33 @@ int ssl3_connect(SSL *ssl) {
|
|
445
433
|
!ssl->s3->initial_handshake_complete) {
|
446
434
|
ssl->s3->tmp.next_state = SSL3_ST_FALSE_START;
|
447
435
|
} else {
|
448
|
-
|
449
|
-
if (ssl->tlsext_ticket_expected) {
|
450
|
-
ssl->s3->tmp.next_state = SSL3_ST_CR_SESSION_TICKET_A;
|
451
|
-
} else {
|
452
|
-
ssl->s3->tmp.next_state = SSL3_ST_CR_CHANGE;
|
453
|
-
}
|
436
|
+
ssl->s3->tmp.next_state = SSL3_ST_CR_SESSION_TICKET_A;
|
454
437
|
}
|
455
438
|
}
|
456
|
-
ssl->init_num = 0;
|
457
439
|
break;
|
458
440
|
|
441
|
+
case SSL3_ST_FALSE_START:
|
442
|
+
ssl->state = SSL3_ST_CR_SESSION_TICKET_A;
|
443
|
+
ssl->s3->tmp.in_false_start = 1;
|
444
|
+
|
445
|
+
ssl_free_wbio_buffer(ssl);
|
446
|
+
ret = 1;
|
447
|
+
goto end;
|
448
|
+
|
459
449
|
case SSL3_ST_CR_SESSION_TICKET_A:
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
450
|
+
if (ssl->tlsext_ticket_expected) {
|
451
|
+
ret = ssl3_get_new_session_ticket(ssl);
|
452
|
+
if (ret <= 0) {
|
453
|
+
goto end;
|
454
|
+
}
|
455
|
+
} else {
|
456
|
+
skip = 1;
|
464
457
|
}
|
465
458
|
ssl->state = SSL3_ST_CR_CHANGE;
|
466
|
-
ssl->init_num = 0;
|
467
|
-
break;
|
468
|
-
|
469
|
-
case SSL3_ST_CR_CERT_STATUS_A:
|
470
|
-
case SSL3_ST_CR_CERT_STATUS_B:
|
471
|
-
ret = ssl3_get_cert_status(ssl);
|
472
|
-
if (ret <= 0) {
|
473
|
-
goto end;
|
474
|
-
}
|
475
|
-
ssl->state = SSL3_ST_VERIFY_SERVER_CERT;
|
476
|
-
ssl->init_num = 0;
|
477
459
|
break;
|
478
460
|
|
479
461
|
case SSL3_ST_CR_CHANGE:
|
480
|
-
ret = ssl->method->
|
462
|
+
ret = ssl->method->read_change_cipher_spec(ssl);
|
481
463
|
if (ret <= 0) {
|
482
464
|
goto end;
|
483
465
|
}
|
@@ -490,57 +472,76 @@ int ssl3_connect(SSL *ssl) {
|
|
490
472
|
break;
|
491
473
|
|
492
474
|
case SSL3_ST_CR_FINISHED_A:
|
493
|
-
|
494
|
-
ret = ssl3_get_finished(ssl, SSL3_ST_CR_FINISHED_A,
|
495
|
-
SSL3_ST_CR_FINISHED_B);
|
475
|
+
ret = ssl3_get_finished(ssl);
|
496
476
|
if (ret <= 0) {
|
497
477
|
goto end;
|
498
478
|
}
|
479
|
+
ssl->method->received_flight(ssl);
|
499
480
|
|
500
|
-
if (ssl->
|
501
|
-
ssl->state =
|
481
|
+
if (ssl->session != NULL) {
|
482
|
+
ssl->state = SSL3_ST_CW_CHANGE;
|
502
483
|
} else {
|
503
484
|
ssl->state = SSL_ST_OK;
|
504
485
|
}
|
505
|
-
ssl->init_num = 0;
|
506
486
|
break;
|
507
487
|
|
508
488
|
case SSL3_ST_CW_FLUSH:
|
509
|
-
ssl->rwstate = SSL_WRITING;
|
510
489
|
if (BIO_flush(ssl->wbio) <= 0) {
|
490
|
+
ssl->rwstate = SSL_WRITING;
|
511
491
|
ret = -1;
|
512
492
|
goto end;
|
513
493
|
}
|
514
|
-
ssl->rwstate = SSL_NOTHING;
|
515
494
|
ssl->state = ssl->s3->tmp.next_state;
|
495
|
+
if (ssl->state != SSL_ST_OK) {
|
496
|
+
ssl->method->expect_flight(ssl);
|
497
|
+
}
|
516
498
|
break;
|
517
499
|
|
518
|
-
case
|
519
|
-
|
520
|
-
if (
|
521
|
-
|
522
|
-
} else {
|
523
|
-
ssl->state = SSL3_ST_CR_CHANGE;
|
500
|
+
case SSL_ST_TLS13:
|
501
|
+
ret = tls13_handshake(ssl);
|
502
|
+
if (ret <= 0) {
|
503
|
+
goto end;
|
524
504
|
}
|
525
|
-
ssl->
|
526
|
-
|
527
|
-
ssl_free_wbio_buffer(ssl);
|
528
|
-
ret = 1;
|
529
|
-
goto end;
|
505
|
+
ssl->state = SSL_ST_OK;
|
506
|
+
break;
|
530
507
|
|
531
508
|
case SSL_ST_OK:
|
532
|
-
/*
|
509
|
+
/* Clean a few things up. */
|
533
510
|
ssl3_cleanup_key_block(ssl);
|
511
|
+
ssl->method->release_current_message(ssl, 1 /* free_buffer */);
|
512
|
+
|
513
|
+
SSL_SESSION_free(ssl->s3->established_session);
|
514
|
+
if (ssl->session != NULL) {
|
515
|
+
SSL_SESSION_up_ref(ssl->session);
|
516
|
+
ssl->s3->established_session = ssl->session;
|
517
|
+
} else {
|
518
|
+
/* We make a copy of the session in order to maintain the immutability
|
519
|
+
* of the new established_session due to False Start. The caller may
|
520
|
+
* have taken a reference to the temporary session. */
|
521
|
+
ssl->s3->established_session =
|
522
|
+
SSL_SESSION_dup(ssl->s3->new_session, SSL_SESSION_DUP_ALL);
|
523
|
+
if (ssl->s3->established_session == NULL) {
|
524
|
+
/* Do not stay in SSL_ST_OK, to avoid confusing |SSL_in_init|
|
525
|
+
* callers. */
|
526
|
+
ssl->state = SSL_ST_ERROR;
|
527
|
+
skip = 1;
|
528
|
+
ret = -1;
|
529
|
+
goto end;
|
530
|
+
}
|
531
|
+
ssl->s3->established_session->not_resumable = 0;
|
534
532
|
|
535
|
-
|
536
|
-
|
533
|
+
SSL_SESSION_free(ssl->s3->new_session);
|
534
|
+
ssl->s3->new_session = NULL;
|
535
|
+
}
|
537
536
|
|
538
537
|
/* Remove write buffering now. */
|
539
538
|
ssl_free_wbio_buffer(ssl);
|
540
539
|
|
540
|
+
ssl_handshake_free(ssl->s3->hs);
|
541
|
+
ssl->s3->hs = NULL;
|
542
|
+
|
541
543
|
const int is_initial_handshake = !ssl->s3->initial_handshake_complete;
|
542
544
|
|
543
|
-
ssl->init_num = 0;
|
544
545
|
ssl->s3->tmp.in_false_start = 0;
|
545
546
|
ssl->s3->initial_handshake_complete = 1;
|
546
547
|
|
@@ -550,12 +551,12 @@ int ssl3_connect(SSL *ssl) {
|
|
550
551
|
}
|
551
552
|
|
552
553
|
ret = 1;
|
553
|
-
|
554
|
-
|
555
|
-
if (cb != NULL) {
|
556
|
-
cb(ssl, SSL_CB_HANDSHAKE_DONE, 1);
|
557
|
-
}
|
554
|
+
ssl_do_info_callback(ssl, SSL_CB_HANDSHAKE_DONE, 1);
|
555
|
+
goto end;
|
558
556
|
|
557
|
+
case SSL_ST_ERROR:
|
558
|
+
OPENSSL_PUT_ERROR(SSL, SSL_R_SSL_HANDSHAKE_FAILURE);
|
559
|
+
ret = -1;
|
559
560
|
goto end;
|
560
561
|
|
561
562
|
default:
|
@@ -564,27 +565,35 @@ int ssl3_connect(SSL *ssl) {
|
|
564
565
|
goto end;
|
565
566
|
}
|
566
567
|
|
567
|
-
if (!ssl->s3->tmp.reuse_message && !skip) {
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
ssl->state = new_state;
|
573
|
-
}
|
568
|
+
if (!ssl->s3->tmp.reuse_message && !skip && ssl->state != state) {
|
569
|
+
int new_state = ssl->state;
|
570
|
+
ssl->state = state;
|
571
|
+
ssl_do_info_callback(ssl, SSL_CB_CONNECT_LOOP, 1);
|
572
|
+
ssl->state = new_state;
|
574
573
|
}
|
575
574
|
skip = 0;
|
576
575
|
}
|
577
576
|
|
578
577
|
end:
|
579
|
-
ssl
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
578
|
+
ssl_do_info_callback(ssl, SSL_CB_CONNECT_EXIT, ret);
|
579
|
+
return ret;
|
580
|
+
}
|
581
|
+
|
582
|
+
uint16_t ssl_get_grease_value(const SSL *ssl, enum ssl_grease_index_t index) {
|
583
|
+
/* Use the client_random for entropy. This both avoids calling |RAND_bytes| on
|
584
|
+
* a single byte repeatedly and ensures the values are deterministic. This
|
585
|
+
* allows the same ClientHello be sent twice for a HelloRetryRequest or the
|
586
|
+
* same group be advertised in both supported_groups and key_shares. */
|
587
|
+
uint16_t ret = ssl->s3->client_random[index];
|
588
|
+
/* This generates a random value of the form 0xωaωa, for all 0 ≤ ω < 16. */
|
589
|
+
ret = (ret & 0xf0) | 0x0a;
|
590
|
+
ret |= ret << 8;
|
584
591
|
return ret;
|
585
592
|
}
|
586
593
|
|
587
|
-
static int
|
594
|
+
static int ssl_write_client_cipher_list(SSL *ssl, CBB *out,
|
595
|
+
uint16_t min_version,
|
596
|
+
uint16_t max_version) {
|
588
597
|
/* Prepare disabled cipher masks. */
|
589
598
|
ssl_set_client_disabled(ssl);
|
590
599
|
|
@@ -593,25 +602,42 @@ static int ssl3_write_client_cipher_list(SSL *ssl, CBB *out) {
|
|
593
602
|
return 0;
|
594
603
|
}
|
595
604
|
|
605
|
+
/* Add a fake cipher suite. See draft-davidben-tls-grease-01. */
|
606
|
+
if (ssl->ctx->grease_enabled &&
|
607
|
+
!CBB_add_u16(&child, ssl_get_grease_value(ssl, ssl_grease_cipher))) {
|
608
|
+
return 0;
|
609
|
+
}
|
610
|
+
|
596
611
|
STACK_OF(SSL_CIPHER) *ciphers = SSL_get_ciphers(ssl);
|
597
612
|
|
598
613
|
int any_enabled = 0;
|
599
|
-
size_t i;
|
600
|
-
for (i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) {
|
614
|
+
for (size_t i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) {
|
601
615
|
const SSL_CIPHER *cipher = sk_SSL_CIPHER_value(ciphers, i);
|
602
616
|
/* Skip disabled ciphers */
|
603
617
|
if ((cipher->algorithm_mkey & ssl->cert->mask_k) ||
|
604
618
|
(cipher->algorithm_auth & ssl->cert->mask_a)) {
|
605
619
|
continue;
|
606
620
|
}
|
607
|
-
if (SSL_CIPHER_get_min_version(cipher) >
|
608
|
-
|
621
|
+
if (SSL_CIPHER_get_min_version(cipher) > max_version ||
|
622
|
+
SSL_CIPHER_get_max_version(cipher) < min_version) {
|
609
623
|
continue;
|
610
624
|
}
|
611
625
|
any_enabled = 1;
|
612
626
|
if (!CBB_add_u16(&child, ssl_cipher_get_value(cipher))) {
|
613
627
|
return 0;
|
614
628
|
}
|
629
|
+
/* Add PSK ciphers for TLS 1.3 resumption. */
|
630
|
+
uint16_t session_version;
|
631
|
+
if (ssl->session != NULL &&
|
632
|
+
ssl->method->version_from_wire(&session_version,
|
633
|
+
ssl->session->ssl_version) &&
|
634
|
+
session_version >= TLS1_3_VERSION) {
|
635
|
+
uint16_t resumption_cipher;
|
636
|
+
if (ssl_cipher_get_ecdhe_psk_cipher(cipher, &resumption_cipher) &&
|
637
|
+
!CBB_add_u16(&child, resumption_cipher)) {
|
638
|
+
return 0;
|
639
|
+
}
|
640
|
+
}
|
615
641
|
}
|
616
642
|
|
617
643
|
/* If all ciphers were disabled, return the error to the caller. */
|
@@ -627,26 +653,64 @@ static int ssl3_write_client_cipher_list(SSL *ssl, CBB *out) {
|
|
627
653
|
if (!CBB_add_u16(&child, SSL3_CK_SCSV & 0xffff)) {
|
628
654
|
return 0;
|
629
655
|
}
|
630
|
-
/* The renegotiation extension is required to be at index zero. */
|
631
|
-
ssl->s3->tmp.extensions.sent |= (1u << 0);
|
632
656
|
}
|
633
657
|
|
634
|
-
if (
|
635
|
-
|
636
|
-
|
658
|
+
if (ssl->mode & SSL_MODE_SEND_FALLBACK_SCSV) {
|
659
|
+
if (!CBB_add_u16(&child, SSL3_CK_FALLBACK_SCSV & 0xffff)) {
|
660
|
+
return 0;
|
661
|
+
}
|
637
662
|
}
|
638
663
|
|
639
664
|
return CBB_flush(out);
|
640
665
|
}
|
641
666
|
|
642
|
-
int
|
667
|
+
int ssl_add_client_hello_body(SSL *ssl, CBB *body) {
|
668
|
+
uint16_t min_version, max_version;
|
669
|
+
if (!ssl_get_version_range(ssl, &min_version, &max_version)) {
|
670
|
+
return 0;
|
671
|
+
}
|
672
|
+
|
673
|
+
/* Renegotiations do not participate in session resumption. */
|
674
|
+
int has_session = ssl->session != NULL &&
|
675
|
+
!ssl->s3->initial_handshake_complete;
|
676
|
+
|
677
|
+
CBB child;
|
678
|
+
if (!CBB_add_u16(body, ssl->client_version) ||
|
679
|
+
!CBB_add_bytes(body, ssl->s3->client_random, SSL3_RANDOM_SIZE) ||
|
680
|
+
!CBB_add_u8_length_prefixed(body, &child) ||
|
681
|
+
(has_session &&
|
682
|
+
!CBB_add_bytes(&child, ssl->session->session_id,
|
683
|
+
ssl->session->session_id_length))) {
|
684
|
+
return 0;
|
685
|
+
}
|
686
|
+
|
687
|
+
if (SSL_is_dtls(ssl)) {
|
688
|
+
if (!CBB_add_u8_length_prefixed(body, &child) ||
|
689
|
+
!CBB_add_bytes(&child, ssl->d1->cookie, ssl->d1->cookie_len)) {
|
690
|
+
return 0;
|
691
|
+
}
|
692
|
+
}
|
693
|
+
|
694
|
+
size_t header_len =
|
695
|
+
SSL_is_dtls(ssl) ? DTLS1_HM_HEADER_LENGTH : SSL3_HM_HEADER_LENGTH;
|
696
|
+
if (!ssl_write_client_cipher_list(ssl, body, min_version, max_version) ||
|
697
|
+
!CBB_add_u8(body, 1 /* one compression method */) ||
|
698
|
+
!CBB_add_u8(body, 0 /* null compression */) ||
|
699
|
+
!ssl_add_clienthello_tlsext(ssl, body, header_len + CBB_len(body))) {
|
700
|
+
return 0;
|
701
|
+
}
|
702
|
+
|
703
|
+
return 1;
|
704
|
+
}
|
705
|
+
|
706
|
+
static int ssl3_send_client_hello(SSL *ssl) {
|
643
707
|
if (ssl->state == SSL3_ST_CW_CLNT_HELLO_B) {
|
644
|
-
return
|
708
|
+
return ssl->method->write_message(ssl);
|
645
709
|
}
|
646
710
|
|
647
|
-
/*
|
648
|
-
*
|
649
|
-
if (
|
711
|
+
/* The handshake buffer is reset on every ClientHello. Notably, in DTLS, we
|
712
|
+
* may send multiple ClientHellos if we receive HelloVerifyRequest. */
|
713
|
+
if (!ssl3_init_handshake_buffer(ssl)) {
|
650
714
|
OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
|
651
715
|
return -1;
|
652
716
|
}
|
@@ -654,99 +718,115 @@ int ssl3_send_client_hello(SSL *ssl) {
|
|
654
718
|
CBB cbb;
|
655
719
|
CBB_zero(&cbb);
|
656
720
|
|
721
|
+
uint16_t min_version, max_version;
|
722
|
+
if (!ssl_get_version_range(ssl, &min_version, &max_version)) {
|
723
|
+
goto err;
|
724
|
+
}
|
725
|
+
|
657
726
|
assert(ssl->state == SSL3_ST_CW_CLNT_HELLO_A);
|
658
727
|
if (!ssl->s3->have_version) {
|
659
|
-
|
660
|
-
/* Disabling all versions is silly: return an error. */
|
661
|
-
if (max_version == 0) {
|
662
|
-
OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_SSL_VERSION);
|
663
|
-
goto err;
|
664
|
-
}
|
665
|
-
|
666
|
-
ssl->version = max_version;
|
728
|
+
ssl->version = ssl->method->version_to_wire(max_version);
|
667
729
|
/* Only set |ssl->client_version| on the initial handshake. Renegotiations,
|
668
730
|
* although locked to a version, reuse the value. When using the plain RSA
|
669
731
|
* key exchange, the ClientHello version is checked in the premaster secret.
|
670
732
|
* Some servers fail when this value changes. */
|
671
|
-
ssl->client_version =
|
733
|
+
ssl->client_version = ssl->version;
|
734
|
+
|
735
|
+
if (max_version >= TLS1_3_VERSION) {
|
736
|
+
ssl->client_version = ssl->method->version_to_wire(TLS1_2_VERSION);
|
737
|
+
}
|
672
738
|
}
|
673
739
|
|
674
|
-
/* If the configured session has expired or was created at a
|
675
|
-
*
|
676
|
-
if (ssl->session != NULL
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
740
|
+
/* If the configured session has expired or was created at a disabled
|
741
|
+
* version, drop it. */
|
742
|
+
if (ssl->session != NULL) {
|
743
|
+
uint16_t session_version;
|
744
|
+
if (!ssl->method->version_from_wire(&session_version,
|
745
|
+
ssl->session->ssl_version) ||
|
746
|
+
(session_version < TLS1_3_VERSION &&
|
747
|
+
ssl->session->session_id_length == 0) ||
|
748
|
+
ssl->session->not_resumable ||
|
749
|
+
!ssl_session_is_time_valid(ssl, ssl->session) ||
|
750
|
+
session_version < min_version || session_version > max_version) {
|
751
|
+
ssl_set_session(ssl, NULL);
|
752
|
+
}
|
682
753
|
}
|
683
754
|
|
684
755
|
/* If resending the ClientHello in DTLS after a HelloVerifyRequest, don't
|
685
756
|
* renegerate the client_random. The random must be reused. */
|
686
|
-
if ((!
|
687
|
-
!
|
688
|
-
sizeof(ssl->s3->client_random), 0 /* client */)) {
|
757
|
+
if ((!SSL_is_dtls(ssl) || !ssl->d1->send_cookie) &&
|
758
|
+
!RAND_bytes(ssl->s3->client_random, sizeof(ssl->s3->client_random))) {
|
689
759
|
goto err;
|
690
760
|
}
|
691
761
|
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
CBB child;
|
697
|
-
if (!CBB_init_fixed(&cbb, ssl_handshake_start(ssl),
|
698
|
-
ssl->init_buf->max - SSL_HM_HEADER_LENGTH(ssl)) ||
|
699
|
-
!CBB_add_u16(&cbb, ssl->client_version) ||
|
700
|
-
!CBB_add_bytes(&cbb, ssl->s3->client_random, SSL3_RANDOM_SIZE) ||
|
701
|
-
!CBB_add_u8_length_prefixed(&cbb, &child) ||
|
702
|
-
(has_session &&
|
703
|
-
!CBB_add_bytes(&child, ssl->session->session_id,
|
704
|
-
ssl->session->session_id_length))) {
|
762
|
+
CBB body;
|
763
|
+
if (!ssl->method->init_message(ssl, &cbb, &body, SSL3_MT_CLIENT_HELLO) ||
|
764
|
+
!ssl_add_client_hello_body(ssl, &body) ||
|
765
|
+
!ssl->method->finish_message(ssl, &cbb)) {
|
705
766
|
goto err;
|
706
767
|
}
|
707
768
|
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
769
|
+
ssl->state = SSL3_ST_CW_CLNT_HELLO_B;
|
770
|
+
return ssl->method->write_message(ssl);
|
771
|
+
|
772
|
+
err:
|
773
|
+
CBB_cleanup(&cbb);
|
774
|
+
return -1;
|
775
|
+
}
|
776
|
+
|
777
|
+
static int dtls1_get_hello_verify(SSL *ssl) {
|
778
|
+
int al;
|
779
|
+
CBS hello_verify_request, cookie;
|
780
|
+
uint16_t server_version;
|
781
|
+
|
782
|
+
int ret = ssl->method->ssl_get_message(ssl, -1, ssl_hash_message);
|
783
|
+
if (ret <= 0) {
|
784
|
+
return ret;
|
713
785
|
}
|
714
786
|
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
!ssl_add_clienthello_tlsext(ssl, &cbb,
|
720
|
-
CBB_len(&cbb) + SSL_HM_HEADER_LENGTH(ssl)) ||
|
721
|
-
!CBB_finish(&cbb, NULL, &length) ||
|
722
|
-
!ssl_set_handshake_header(ssl, SSL3_MT_CLIENT_HELLO, length)) {
|
723
|
-
goto err;
|
787
|
+
if (ssl->s3->tmp.message_type != DTLS1_MT_HELLO_VERIFY_REQUEST) {
|
788
|
+
ssl->d1->send_cookie = 0;
|
789
|
+
ssl->s3->tmp.reuse_message = 1;
|
790
|
+
return 1;
|
724
791
|
}
|
725
792
|
|
726
|
-
ssl->
|
727
|
-
return ssl_do_write(ssl);
|
793
|
+
CBS_init(&hello_verify_request, ssl->init_msg, ssl->init_num);
|
728
794
|
|
729
|
-
|
730
|
-
|
795
|
+
if (!CBS_get_u16(&hello_verify_request, &server_version) ||
|
796
|
+
!CBS_get_u8_length_prefixed(&hello_verify_request, &cookie) ||
|
797
|
+
CBS_len(&hello_verify_request) != 0) {
|
798
|
+
al = SSL_AD_DECODE_ERROR;
|
799
|
+
OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
|
800
|
+
goto f_err;
|
801
|
+
}
|
802
|
+
|
803
|
+
if (CBS_len(&cookie) > sizeof(ssl->d1->cookie)) {
|
804
|
+
al = SSL_AD_ILLEGAL_PARAMETER;
|
805
|
+
goto f_err;
|
806
|
+
}
|
807
|
+
|
808
|
+
memcpy(ssl->d1->cookie, CBS_data(&cookie), CBS_len(&cookie));
|
809
|
+
ssl->d1->cookie_len = CBS_len(&cookie);
|
810
|
+
|
811
|
+
ssl->d1->send_cookie = 1;
|
812
|
+
return 1;
|
813
|
+
|
814
|
+
f_err:
|
815
|
+
ssl3_send_alert(ssl, SSL3_AL_FATAL, al);
|
731
816
|
return -1;
|
732
817
|
}
|
733
818
|
|
734
|
-
int ssl3_get_server_hello(SSL *ssl) {
|
819
|
+
static int ssl3_get_server_hello(SSL *ssl) {
|
735
820
|
STACK_OF(SSL_CIPHER) *sk;
|
736
821
|
const SSL_CIPHER *c;
|
737
822
|
CERT *ct = ssl->cert;
|
738
|
-
int al = SSL_AD_INTERNAL_ERROR
|
739
|
-
long n;
|
823
|
+
int al = SSL_AD_INTERNAL_ERROR;
|
740
824
|
CBS server_hello, server_random, session_id;
|
741
|
-
uint16_t
|
825
|
+
uint16_t server_wire_version, cipher_suite;
|
742
826
|
uint8_t compression_method;
|
743
827
|
|
744
|
-
|
745
|
-
|
746
|
-
20000, /* ?? */
|
747
|
-
ssl_hash_message, &ok);
|
748
|
-
|
749
|
-
if (!ok) {
|
828
|
+
int ret = ssl->method->ssl_get_message(ssl, -1, ssl_hash_message);
|
829
|
+
if (ret <= 0) {
|
750
830
|
uint32_t err = ERR_peek_error();
|
751
831
|
if (ERR_GET_LIB(err) == ERR_LIB_SSL &&
|
752
832
|
ERR_GET_REASON(err) == SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE) {
|
@@ -758,71 +838,91 @@ int ssl3_get_server_hello(SSL *ssl) {
|
|
758
838
|
* See https://crbug.com/446505. */
|
759
839
|
OPENSSL_PUT_ERROR(SSL, SSL_R_HANDSHAKE_FAILURE_ON_CLIENT_HELLO);
|
760
840
|
}
|
761
|
-
return
|
841
|
+
return ret;
|
842
|
+
}
|
843
|
+
|
844
|
+
if (ssl->s3->tmp.message_type != SSL3_MT_SERVER_HELLO &&
|
845
|
+
ssl->s3->tmp.message_type != SSL3_MT_HELLO_RETRY_REQUEST) {
|
846
|
+
ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE);
|
847
|
+
OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_MESSAGE);
|
848
|
+
return -1;
|
762
849
|
}
|
763
850
|
|
764
|
-
CBS_init(&server_hello, ssl->init_msg,
|
851
|
+
CBS_init(&server_hello, ssl->init_msg, ssl->init_num);
|
765
852
|
|
766
|
-
if (!CBS_get_u16(&server_hello, &
|
767
|
-
!CBS_get_bytes(&server_hello, &server_random, SSL3_RANDOM_SIZE) ||
|
768
|
-
!CBS_get_u8_length_prefixed(&server_hello, &session_id) ||
|
769
|
-
CBS_len(&session_id) > SSL3_SESSION_ID_SIZE ||
|
770
|
-
!CBS_get_u16(&server_hello, &cipher_suite) ||
|
771
|
-
!CBS_get_u8(&server_hello, &compression_method)) {
|
853
|
+
if (!CBS_get_u16(&server_hello, &server_wire_version)) {
|
772
854
|
al = SSL_AD_DECODE_ERROR;
|
773
855
|
OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
|
774
856
|
goto f_err;
|
775
857
|
}
|
776
858
|
|
859
|
+
uint16_t min_version, max_version, server_version;
|
860
|
+
if (!ssl_get_version_range(ssl, &min_version, &max_version) ||
|
861
|
+
!ssl->method->version_from_wire(&server_version, server_wire_version) ||
|
862
|
+
server_version < min_version || server_version > max_version) {
|
863
|
+
OPENSSL_PUT_ERROR(SSL, SSL_R_UNSUPPORTED_PROTOCOL);
|
864
|
+
al = SSL_AD_PROTOCOL_VERSION;
|
865
|
+
goto f_err;
|
866
|
+
}
|
867
|
+
|
777
868
|
assert(ssl->s3->have_version == ssl->s3->initial_handshake_complete);
|
778
869
|
if (!ssl->s3->have_version) {
|
779
|
-
|
780
|
-
OPENSSL_PUT_ERROR(SSL, SSL_R_UNSUPPORTED_PROTOCOL);
|
781
|
-
ssl->version = server_version;
|
782
|
-
/* Mark the version as fixed so the record-layer version is not clamped
|
783
|
-
* to TLS 1.0. */
|
784
|
-
ssl->s3->have_version = 1;
|
785
|
-
al = SSL_AD_PROTOCOL_VERSION;
|
786
|
-
goto f_err;
|
787
|
-
}
|
788
|
-
ssl->version = server_version;
|
870
|
+
ssl->version = server_wire_version;
|
789
871
|
ssl->s3->enc_method = ssl3_get_enc_method(server_version);
|
790
872
|
assert(ssl->s3->enc_method != NULL);
|
791
873
|
/* At this point, the connection's version is known and ssl->version is
|
792
874
|
* fixed. Begin enforcing the record-layer version. */
|
793
875
|
ssl->s3->have_version = 1;
|
794
|
-
} else if (
|
876
|
+
} else if (server_wire_version != ssl->version) {
|
795
877
|
OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_SSL_VERSION);
|
796
878
|
al = SSL_AD_PROTOCOL_VERSION;
|
797
879
|
goto f_err;
|
798
880
|
}
|
799
881
|
|
800
|
-
|
801
|
-
|
882
|
+
if (ssl3_protocol_version(ssl) >= TLS1_3_VERSION) {
|
883
|
+
ssl->state = SSL_ST_TLS13;
|
884
|
+
return 1;
|
885
|
+
}
|
802
886
|
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
887
|
+
ssl_clear_tls13_state(ssl);
|
888
|
+
|
889
|
+
if (ssl->s3->tmp.message_type != SSL3_MT_SERVER_HELLO) {
|
890
|
+
ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE);
|
891
|
+
OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_MESSAGE);
|
892
|
+
return -1;
|
893
|
+
}
|
894
|
+
|
895
|
+
if (!CBS_get_bytes(&server_hello, &server_random, SSL3_RANDOM_SIZE) ||
|
896
|
+
!CBS_get_u8_length_prefixed(&server_hello, &session_id) ||
|
897
|
+
CBS_len(&session_id) > SSL3_SESSION_ID_SIZE ||
|
898
|
+
!CBS_get_u16(&server_hello, &cipher_suite) ||
|
899
|
+
!CBS_get_u8(&server_hello, &compression_method)) {
|
900
|
+
al = SSL_AD_DECODE_ERROR;
|
901
|
+
OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
|
902
|
+
goto f_err;
|
903
|
+
}
|
904
|
+
|
905
|
+
/* Copy over the server random. */
|
906
|
+
memcpy(ssl->s3->server_random, CBS_data(&server_random), SSL3_RANDOM_SIZE);
|
907
|
+
|
908
|
+
/* TODO(davidben): Implement the TLS 1.1 and 1.2 downgrade sentinels once TLS
|
909
|
+
* 1.3 is finalized and we are not implementing a draft version. */
|
910
|
+
|
911
|
+
if (!ssl->s3->initial_handshake_complete && ssl->session != NULL &&
|
912
|
+
ssl->session->session_id_length != 0 &&
|
913
|
+
CBS_mem_equal(&session_id, ssl->session->session_id,
|
914
|
+
ssl->session->session_id_length)) {
|
915
|
+
ssl->s3->session_reused = 1;
|
816
916
|
} else {
|
817
917
|
/* The session wasn't resumed. Create a fresh SSL_SESSION to
|
818
918
|
* fill out. */
|
819
|
-
ssl
|
919
|
+
ssl_set_session(ssl, NULL);
|
820
920
|
if (!ssl_get_new_session(ssl, 0 /* client */)) {
|
821
921
|
goto f_err;
|
822
922
|
}
|
823
923
|
/* Note: session_id could be empty. */
|
824
|
-
ssl->
|
825
|
-
memcpy(ssl->
|
924
|
+
ssl->s3->new_session->session_id_length = CBS_len(&session_id);
|
925
|
+
memcpy(ssl->s3->new_session->session_id, CBS_data(&session_id),
|
826
926
|
CBS_len(&session_id));
|
827
927
|
}
|
828
928
|
|
@@ -836,7 +936,8 @@ int ssl3_get_server_hello(SSL *ssl) {
|
|
836
936
|
/* If the cipher is disabled then we didn't sent it in the ClientHello, so if
|
837
937
|
* the server selected it, it's an error. */
|
838
938
|
if ((c->algorithm_mkey & ct->mask_k) || (c->algorithm_auth & ct->mask_a) ||
|
839
|
-
SSL_CIPHER_get_min_version(c) > ssl3_protocol_version(ssl)
|
939
|
+
SSL_CIPHER_get_min_version(c) > ssl3_protocol_version(ssl) ||
|
940
|
+
SSL_CIPHER_get_max_version(c) < ssl3_protocol_version(ssl)) {
|
840
941
|
al = SSL_AD_ILLEGAL_PARAMETER;
|
841
942
|
OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CIPHER_RETURNED);
|
842
943
|
goto f_err;
|
@@ -850,7 +951,7 @@ int ssl3_get_server_hello(SSL *ssl) {
|
|
850
951
|
goto f_err;
|
851
952
|
}
|
852
953
|
|
853
|
-
if (ssl->
|
954
|
+
if (ssl->session != NULL) {
|
854
955
|
if (ssl->session->cipher != c) {
|
855
956
|
al = SSL_AD_ILLEGAL_PARAMETER;
|
856
957
|
OPENSSL_PUT_ERROR(SSL, SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED);
|
@@ -861,8 +962,15 @@ int ssl3_get_server_hello(SSL *ssl) {
|
|
861
962
|
OPENSSL_PUT_ERROR(SSL, SSL_R_OLD_SESSION_VERSION_NOT_RETURNED);
|
862
963
|
goto f_err;
|
863
964
|
}
|
965
|
+
if (!ssl_session_is_context_valid(ssl, ssl->session)) {
|
966
|
+
/* This is actually a client application bug. */
|
967
|
+
al = SSL_AD_ILLEGAL_PARAMETER;
|
968
|
+
OPENSSL_PUT_ERROR(SSL,
|
969
|
+
SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT);
|
970
|
+
goto f_err;
|
971
|
+
}
|
864
972
|
} else {
|
865
|
-
ssl->
|
973
|
+
ssl->s3->new_session->cipher = c;
|
866
974
|
}
|
867
975
|
ssl->s3->tmp.new_cipher = c;
|
868
976
|
|
@@ -871,10 +979,11 @@ int ssl3_get_server_hello(SSL *ssl) {
|
|
871
979
|
goto f_err;
|
872
980
|
}
|
873
981
|
|
874
|
-
/* If doing a full handshake
|
875
|
-
*
|
876
|
-
*
|
877
|
-
if (ssl->
|
982
|
+
/* If doing a full handshake, the server may request a client certificate
|
983
|
+
* which requires hashing the handshake transcript. Otherwise, the handshake
|
984
|
+
* buffer may be released. */
|
985
|
+
if (ssl->session != NULL ||
|
986
|
+
!ssl_cipher_uses_certificate_auth(ssl->s3->tmp.new_cipher)) {
|
878
987
|
ssl3_free_handshake_buffer(ssl);
|
879
988
|
}
|
880
989
|
|
@@ -895,11 +1004,11 @@ int ssl3_get_server_hello(SSL *ssl) {
|
|
895
1004
|
if (CBS_len(&server_hello) != 0) {
|
896
1005
|
/* wrong packet length */
|
897
1006
|
al = SSL_AD_DECODE_ERROR;
|
898
|
-
OPENSSL_PUT_ERROR(SSL,
|
1007
|
+
OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
|
899
1008
|
goto f_err;
|
900
1009
|
}
|
901
1010
|
|
902
|
-
if (ssl->
|
1011
|
+
if (ssl->session != NULL &&
|
903
1012
|
ssl->s3->tmp.extended_master_secret !=
|
904
1013
|
ssl->session->extended_master_secret) {
|
905
1014
|
al = SSL_AD_HANDSHAKE_FAILURE;
|
@@ -919,184 +1028,131 @@ err:
|
|
919
1028
|
return -1;
|
920
1029
|
}
|
921
1030
|
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
EVP_PKEY *pkey = X509_get_pubkey(leaf);
|
928
|
-
if (pkey == NULL) {
|
929
|
-
goto err;
|
1031
|
+
static int ssl3_get_server_certificate(SSL *ssl) {
|
1032
|
+
int ret =
|
1033
|
+
ssl->method->ssl_get_message(ssl, SSL3_MT_CERTIFICATE, ssl_hash_message);
|
1034
|
+
if (ret <= 0) {
|
1035
|
+
return ret;
|
930
1036
|
}
|
931
1037
|
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
if (
|
937
|
-
|
1038
|
+
CBS cbs;
|
1039
|
+
CBS_init(&cbs, ssl->init_msg, ssl->init_num);
|
1040
|
+
uint8_t alert;
|
1041
|
+
STACK_OF(X509) *chain = ssl_parse_cert_chain(ssl, &alert, NULL, &cbs);
|
1042
|
+
if (chain == NULL) {
|
1043
|
+
ssl3_send_alert(ssl, SSL3_AL_FATAL, alert);
|
938
1044
|
goto err;
|
939
1045
|
}
|
940
1046
|
|
941
|
-
if (
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
if ((leaf->ex_flags & EXFLAG_KUSAGE) &&
|
947
|
-
!(leaf->ex_kusage & X509v3_KU_DIGITAL_SIGNATURE)) {
|
948
|
-
OPENSSL_PUT_ERROR(SSL, SSL_R_ECC_CERT_NOT_FOR_SIGNING);
|
949
|
-
goto err;
|
950
|
-
}
|
1047
|
+
if (sk_X509_num(chain) == 0 || CBS_len(&cbs) != 0) {
|
1048
|
+
OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
|
1049
|
+
ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
|
1050
|
+
goto err;
|
1051
|
+
}
|
951
1052
|
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
1053
|
+
X509 *leaf = sk_X509_value(chain, 0);
|
1054
|
+
if (!ssl_check_leaf_certificate(ssl, leaf)) {
|
1055
|
+
ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
|
1056
|
+
goto err;
|
956
1057
|
}
|
957
1058
|
|
958
|
-
|
1059
|
+
/* NOTE: Unlike the server half, the client's copy of |cert_chain| includes
|
1060
|
+
* the leaf. */
|
1061
|
+
sk_X509_pop_free(ssl->s3->new_session->cert_chain, X509_free);
|
1062
|
+
ssl->s3->new_session->cert_chain = chain;
|
1063
|
+
|
1064
|
+
X509_free(ssl->s3->new_session->peer);
|
1065
|
+
X509_up_ref(leaf);
|
1066
|
+
ssl->s3->new_session->peer = leaf;
|
1067
|
+
|
1068
|
+
return 1;
|
959
1069
|
|
960
1070
|
err:
|
961
|
-
|
962
|
-
return
|
1071
|
+
sk_X509_pop_free(chain, X509_free);
|
1072
|
+
return -1;
|
963
1073
|
}
|
964
1074
|
|
965
|
-
int
|
966
|
-
int al
|
967
|
-
|
968
|
-
|
969
|
-
STACK_OF(X509) *sk = NULL;
|
970
|
-
EVP_PKEY *pkey = NULL;
|
971
|
-
CBS cbs, certificate_list;
|
972
|
-
const uint8_t *data;
|
973
|
-
|
974
|
-
n = ssl->method->ssl_get_message(ssl, SSL3_ST_CR_CERT_A, SSL3_ST_CR_CERT_B,
|
975
|
-
SSL3_MT_CERTIFICATE, (long)ssl->max_cert_list,
|
976
|
-
ssl_hash_message, &ok);
|
1075
|
+
static int ssl3_get_cert_status(SSL *ssl) {
|
1076
|
+
int al;
|
1077
|
+
CBS certificate_status, ocsp_response;
|
1078
|
+
uint8_t status_type;
|
977
1079
|
|
978
|
-
|
979
|
-
|
1080
|
+
int ret = ssl->method->ssl_get_message(ssl, -1, ssl_hash_message);
|
1081
|
+
if (ret <= 0) {
|
1082
|
+
return ret;
|
980
1083
|
}
|
981
1084
|
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
goto err;
|
1085
|
+
if (ssl->s3->tmp.message_type != SSL3_MT_CERTIFICATE_STATUS) {
|
1086
|
+
/* A server may send status_request in ServerHello and then change
|
1087
|
+
* its mind about sending CertificateStatus. */
|
1088
|
+
ssl->s3->tmp.reuse_message = 1;
|
1089
|
+
return 1;
|
988
1090
|
}
|
989
1091
|
|
990
|
-
|
991
|
-
|
992
|
-
|
1092
|
+
CBS_init(&certificate_status, ssl->init_msg, ssl->init_num);
|
1093
|
+
if (!CBS_get_u8(&certificate_status, &status_type) ||
|
1094
|
+
status_type != TLSEXT_STATUSTYPE_ocsp ||
|
1095
|
+
!CBS_get_u24_length_prefixed(&certificate_status, &ocsp_response) ||
|
1096
|
+
CBS_len(&ocsp_response) == 0 ||
|
1097
|
+
CBS_len(&certificate_status) != 0) {
|
993
1098
|
al = SSL_AD_DECODE_ERROR;
|
994
1099
|
OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
|
995
1100
|
goto f_err;
|
996
1101
|
}
|
997
1102
|
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
OPENSSL_PUT_ERROR(SSL, SSL_R_CERT_LENGTH_MISMATCH);
|
1003
|
-
goto f_err;
|
1004
|
-
}
|
1005
|
-
/* A u24 length cannot overflow a long. */
|
1006
|
-
data = CBS_data(&certificate);
|
1007
|
-
x = d2i_X509(NULL, &data, (long)CBS_len(&certificate));
|
1008
|
-
if (x == NULL) {
|
1009
|
-
al = SSL_AD_BAD_CERTIFICATE;
|
1010
|
-
OPENSSL_PUT_ERROR(SSL, ERR_R_ASN1_LIB);
|
1011
|
-
goto f_err;
|
1012
|
-
}
|
1013
|
-
if (data != CBS_data(&certificate) + CBS_len(&certificate)) {
|
1014
|
-
al = SSL_AD_DECODE_ERROR;
|
1015
|
-
OPENSSL_PUT_ERROR(SSL, SSL_R_CERT_LENGTH_MISMATCH);
|
1016
|
-
goto f_err;
|
1017
|
-
}
|
1018
|
-
if (!sk_X509_push(sk, x)) {
|
1019
|
-
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
1020
|
-
goto err;
|
1021
|
-
}
|
1022
|
-
x = NULL;
|
1023
|
-
}
|
1024
|
-
|
1025
|
-
X509 *leaf = sk_X509_value(sk, 0);
|
1026
|
-
if (!ssl3_check_leaf_certificate(ssl, leaf)) {
|
1027
|
-
al = SSL_AD_ILLEGAL_PARAMETER;
|
1103
|
+
if (!CBS_stow(&ocsp_response, &ssl->s3->new_session->ocsp_response,
|
1104
|
+
&ssl->s3->new_session->ocsp_response_length)) {
|
1105
|
+
al = SSL_AD_INTERNAL_ERROR;
|
1106
|
+
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
1028
1107
|
goto f_err;
|
1029
1108
|
}
|
1109
|
+
return 1;
|
1030
1110
|
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
sk = NULL;
|
1036
|
-
|
1037
|
-
X509_free(ssl->session->peer);
|
1038
|
-
ssl->session->peer = X509_up_ref(leaf);
|
1039
|
-
|
1040
|
-
ssl->session->verify_result = ssl->verify_result;
|
1041
|
-
|
1042
|
-
ret = 1;
|
1111
|
+
f_err:
|
1112
|
+
ssl3_send_alert(ssl, SSL3_AL_FATAL, al);
|
1113
|
+
return -1;
|
1114
|
+
}
|
1043
1115
|
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1116
|
+
static int ssl3_verify_server_cert(SSL *ssl) {
|
1117
|
+
if (!ssl_verify_cert_chain(ssl, &ssl->s3->new_session->verify_result,
|
1118
|
+
ssl->s3->new_session->cert_chain)) {
|
1119
|
+
return -1;
|
1047
1120
|
}
|
1048
1121
|
|
1049
|
-
|
1050
|
-
EVP_PKEY_free(pkey);
|
1051
|
-
X509_free(x);
|
1052
|
-
sk_X509_pop_free(sk, X509_free);
|
1053
|
-
return ret;
|
1122
|
+
return 1;
|
1054
1123
|
}
|
1055
1124
|
|
1056
|
-
int ssl3_get_server_key_exchange(SSL *ssl) {
|
1057
|
-
|
1058
|
-
int al, ok;
|
1125
|
+
static int ssl3_get_server_key_exchange(SSL *ssl) {
|
1126
|
+
int al;
|
1059
1127
|
EVP_PKEY *pkey = NULL;
|
1060
1128
|
DH *dh = NULL;
|
1061
1129
|
EC_KEY *ecdh = NULL;
|
1062
1130
|
EC_POINT *srvr_ecpoint = NULL;
|
1063
1131
|
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
ssl, SSL3_ST_CR_KEY_EXCH_A, SSL3_ST_CR_KEY_EXCH_B, -1, ssl->max_cert_list,
|
1068
|
-
ssl_hash_message, &ok);
|
1069
|
-
if (!ok) {
|
1070
|
-
return n;
|
1132
|
+
int ret = ssl->method->ssl_get_message(ssl, -1, ssl_hash_message);
|
1133
|
+
if (ret <= 0) {
|
1134
|
+
return ret;
|
1071
1135
|
}
|
1072
1136
|
|
1073
1137
|
if (ssl->s3->tmp.message_type != SSL3_MT_SERVER_KEY_EXCHANGE) {
|
1138
|
+
/* Some ciphers (pure PSK) have an optional ServerKeyExchange message. */
|
1074
1139
|
if (ssl_cipher_requires_server_key_exchange(ssl->s3->tmp.new_cipher)) {
|
1075
1140
|
OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_MESSAGE);
|
1076
1141
|
ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE);
|
1077
1142
|
return -1;
|
1078
1143
|
}
|
1079
1144
|
|
1080
|
-
/* In plain PSK ciphersuite, ServerKeyExchange may be omitted to send no
|
1081
|
-
* identity hint. */
|
1082
|
-
if (ssl->s3->tmp.new_cipher->algorithm_auth & SSL_aPSK) {
|
1083
|
-
/* TODO(davidben): This should be reset in one place with the rest of the
|
1084
|
-
* handshake state. */
|
1085
|
-
OPENSSL_free(ssl->s3->tmp.peer_psk_identity_hint);
|
1086
|
-
ssl->s3->tmp.peer_psk_identity_hint = NULL;
|
1087
|
-
}
|
1088
1145
|
ssl->s3->tmp.reuse_message = 1;
|
1089
1146
|
return 1;
|
1090
1147
|
}
|
1091
1148
|
|
1092
1149
|
/* Retain a copy of the original CBS to compute the signature over. */
|
1093
1150
|
CBS server_key_exchange;
|
1094
|
-
CBS_init(&server_key_exchange, ssl->init_msg,
|
1151
|
+
CBS_init(&server_key_exchange, ssl->init_msg, ssl->init_num);
|
1095
1152
|
CBS server_key_exchange_orig = server_key_exchange;
|
1096
1153
|
|
1097
1154
|
uint32_t alg_k = ssl->s3->tmp.new_cipher->algorithm_mkey;
|
1098
1155
|
uint32_t alg_a = ssl->s3->tmp.new_cipher->algorithm_auth;
|
1099
|
-
EVP_MD_CTX_init(&md_ctx);
|
1100
1156
|
|
1101
1157
|
if (alg_a & SSL_aPSK) {
|
1102
1158
|
CBS psk_identity_hint;
|
@@ -1123,8 +1179,13 @@ int ssl3_get_server_key_exchange(SSL *ssl) {
|
|
1123
1179
|
goto f_err;
|
1124
1180
|
}
|
1125
1181
|
|
1126
|
-
/* Save
|
1127
|
-
|
1182
|
+
/* Save non-empty identity hints as a C string. Empty identity hints we
|
1183
|
+
* treat as missing. Plain PSK makes it possible to send either no hint
|
1184
|
+
* (omit ServerKeyExchange) or an empty hint, while ECDHE_PSK can only spell
|
1185
|
+
* empty hint. Having different capabilities is odd, so we interpret empty
|
1186
|
+
* and missing as identical. */
|
1187
|
+
if (CBS_len(&psk_identity_hint) != 0 &&
|
1188
|
+
!CBS_strdup(&psk_identity_hint, &ssl->s3->hs->peer_psk_identity_hint)) {
|
1128
1189
|
al = SSL_AD_INTERNAL_ERROR;
|
1129
1190
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
1130
1191
|
goto f_err;
|
@@ -1155,11 +1216,11 @@ int ssl3_get_server_key_exchange(SSL *ssl) {
|
|
1155
1216
|
goto err;
|
1156
1217
|
}
|
1157
1218
|
|
1158
|
-
ssl->
|
1159
|
-
if (ssl->
|
1219
|
+
ssl->s3->new_session->key_exchange_info = DH_num_bits(dh);
|
1220
|
+
if (ssl->s3->new_session->key_exchange_info < 1024) {
|
1160
1221
|
OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_DH_P_LENGTH);
|
1161
1222
|
goto err;
|
1162
|
-
} else if (ssl->
|
1223
|
+
} else if (ssl->s3->new_session->key_exchange_info > 4096) {
|
1163
1224
|
/* Overly large DHE groups are prohibitively expensive, so enforce a limit
|
1164
1225
|
* to prevent a server from causing us to perform too expensive of a
|
1165
1226
|
* computation. */
|
@@ -1175,26 +1236,27 @@ int ssl3_get_server_key_exchange(SSL *ssl) {
|
|
1175
1236
|
if (!CBS_stow(&dh_Ys, &ssl->s3->tmp.peer_key, &peer_key_len)) {
|
1176
1237
|
goto err;
|
1177
1238
|
}
|
1178
|
-
/* |dh_Ys|
|
1239
|
+
/* |dh_Ys| was initialized with CBS_get_u16_length_prefixed, so peer_key_len
|
1240
|
+
* fits in a uint16_t. */
|
1179
1241
|
assert(sizeof(ssl->s3->tmp.peer_key_len) == 2 && peer_key_len <= 0xffff);
|
1180
1242
|
ssl->s3->tmp.peer_key_len = (uint16_t)peer_key_len;
|
1181
1243
|
} else if (alg_k & SSL_kECDHE) {
|
1182
1244
|
/* Parse the server parameters. */
|
1183
|
-
uint8_t
|
1184
|
-
uint16_t
|
1245
|
+
uint8_t group_type;
|
1246
|
+
uint16_t group_id;
|
1185
1247
|
CBS point;
|
1186
|
-
if (!CBS_get_u8(&server_key_exchange, &
|
1187
|
-
|
1188
|
-
!CBS_get_u16(&server_key_exchange, &
|
1248
|
+
if (!CBS_get_u8(&server_key_exchange, &group_type) ||
|
1249
|
+
group_type != NAMED_CURVE_TYPE ||
|
1250
|
+
!CBS_get_u16(&server_key_exchange, &group_id) ||
|
1189
1251
|
!CBS_get_u8_length_prefixed(&server_key_exchange, &point)) {
|
1190
1252
|
al = SSL_AD_DECODE_ERROR;
|
1191
1253
|
OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
|
1192
1254
|
goto f_err;
|
1193
1255
|
}
|
1194
|
-
ssl->
|
1256
|
+
ssl->s3->new_session->key_exchange_info = group_id;
|
1195
1257
|
|
1196
|
-
/* Ensure the
|
1197
|
-
if (!
|
1258
|
+
/* Ensure the group is consistent with preferences. */
|
1259
|
+
if (!tls1_check_group_id(ssl, group_id)) {
|
1198
1260
|
al = SSL_AD_ILLEGAL_PARAMETER;
|
1199
1261
|
OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CURVE);
|
1200
1262
|
goto f_err;
|
@@ -1202,11 +1264,29 @@ int ssl3_get_server_key_exchange(SSL *ssl) {
|
|
1202
1264
|
|
1203
1265
|
/* Initialize ECDH and save the peer public key for later. */
|
1204
1266
|
size_t peer_key_len;
|
1205
|
-
if (!SSL_ECDH_CTX_init(&ssl->s3->tmp.ecdh_ctx,
|
1267
|
+
if (!SSL_ECDH_CTX_init(&ssl->s3->tmp.ecdh_ctx, group_id) ||
|
1206
1268
|
!CBS_stow(&point, &ssl->s3->tmp.peer_key, &peer_key_len)) {
|
1207
1269
|
goto err;
|
1208
1270
|
}
|
1209
|
-
/* |point|
|
1271
|
+
/* |point| was initialized with CBS_get_u8_length_prefixed, so peer_key_len
|
1272
|
+
* fits in a uint16_t. */
|
1273
|
+
assert(sizeof(ssl->s3->tmp.peer_key_len) == 2 && peer_key_len <= 0xffff);
|
1274
|
+
ssl->s3->tmp.peer_key_len = (uint16_t)peer_key_len;
|
1275
|
+
} else if (alg_k & SSL_kCECPQ1) {
|
1276
|
+
SSL_ECDH_CTX_init_for_cecpq1(&ssl->s3->tmp.ecdh_ctx);
|
1277
|
+
CBS key;
|
1278
|
+
if (!CBS_get_u16_length_prefixed(&server_key_exchange, &key)) {
|
1279
|
+
al = SSL_AD_DECODE_ERROR;
|
1280
|
+
OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
|
1281
|
+
goto f_err;
|
1282
|
+
}
|
1283
|
+
|
1284
|
+
size_t peer_key_len;
|
1285
|
+
if (!CBS_stow(&key, &ssl->s3->tmp.peer_key, &peer_key_len)) {
|
1286
|
+
goto err;
|
1287
|
+
}
|
1288
|
+
/* |key| was initialized with CBS_get_u16_length_prefixed, so peer_key_len
|
1289
|
+
* fits in a uint16_t. */
|
1210
1290
|
assert(sizeof(ssl->s3->tmp.peer_key_len) == 2 && peer_key_len <= 0xffff);
|
1211
1291
|
ssl->s3->tmp.peer_key_len = (uint16_t)peer_key_len;
|
1212
1292
|
} else if (!(alg_k & SSL_kPSK)) {
|
@@ -1223,29 +1303,31 @@ int ssl3_get_server_key_exchange(SSL *ssl) {
|
|
1223
1303
|
CBS_len(&server_key_exchange_orig) - CBS_len(&server_key_exchange));
|
1224
1304
|
|
1225
1305
|
/* ServerKeyExchange should be signed by the server's public key. */
|
1226
|
-
if (
|
1227
|
-
pkey = X509_get_pubkey(ssl->
|
1306
|
+
if (ssl_cipher_uses_certificate_auth(ssl->s3->tmp.new_cipher)) {
|
1307
|
+
pkey = X509_get_pubkey(ssl->s3->new_session->peer);
|
1228
1308
|
if (pkey == NULL) {
|
1229
1309
|
goto err;
|
1230
1310
|
}
|
1231
1311
|
|
1232
|
-
|
1312
|
+
uint16_t signature_algorithm = 0;
|
1233
1313
|
if (ssl3_protocol_version(ssl) >= TLS1_2_VERSION) {
|
1234
|
-
|
1235
|
-
if (!CBS_get_u8(&server_key_exchange, &hash) ||
|
1236
|
-
!CBS_get_u8(&server_key_exchange, &signature)) {
|
1314
|
+
if (!CBS_get_u16(&server_key_exchange, &signature_algorithm)) {
|
1237
1315
|
al = SSL_AD_DECODE_ERROR;
|
1238
1316
|
OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
|
1239
1317
|
goto f_err;
|
1240
1318
|
}
|
1241
|
-
if (!tls12_check_peer_sigalg(ssl, &
|
1319
|
+
if (!tls12_check_peer_sigalg(ssl, &al, signature_algorithm)) {
|
1242
1320
|
goto f_err;
|
1243
1321
|
}
|
1244
|
-
ssl->s3->tmp.
|
1322
|
+
ssl->s3->tmp.peer_signature_algorithm = signature_algorithm;
|
1245
1323
|
} else if (pkey->type == EVP_PKEY_RSA) {
|
1246
|
-
|
1324
|
+
signature_algorithm = SSL_SIGN_RSA_PKCS1_MD5_SHA1;
|
1325
|
+
} else if (pkey->type == EVP_PKEY_EC) {
|
1326
|
+
signature_algorithm = SSL_SIGN_ECDSA_SHA1;
|
1247
1327
|
} else {
|
1248
|
-
|
1328
|
+
al = SSL_AD_UNSUPPORTED_CERTIFICATE;
|
1329
|
+
OPENSSL_PUT_ERROR(SSL, SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE);
|
1330
|
+
goto f_err;
|
1249
1331
|
}
|
1250
1332
|
|
1251
1333
|
/* The last field in |server_key_exchange| is the signature. */
|
@@ -1257,15 +1339,30 @@ int ssl3_get_server_key_exchange(SSL *ssl) {
|
|
1257
1339
|
goto f_err;
|
1258
1340
|
}
|
1259
1341
|
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
!
|
1266
|
-
|
1267
|
-
!
|
1268
|
-
|
1342
|
+
CBB transcript;
|
1343
|
+
uint8_t *transcript_data;
|
1344
|
+
size_t transcript_len;
|
1345
|
+
if (!CBB_init(&transcript, 2*SSL3_RANDOM_SIZE + CBS_len(¶meter)) ||
|
1346
|
+
!CBB_add_bytes(&transcript, ssl->s3->client_random, SSL3_RANDOM_SIZE) ||
|
1347
|
+
!CBB_add_bytes(&transcript, ssl->s3->server_random, SSL3_RANDOM_SIZE) ||
|
1348
|
+
!CBB_add_bytes(&transcript, CBS_data(¶meter), CBS_len(¶meter)) ||
|
1349
|
+
!CBB_finish(&transcript, &transcript_data, &transcript_len)) {
|
1350
|
+
CBB_cleanup(&transcript);
|
1351
|
+
al = SSL_AD_INTERNAL_ERROR;
|
1352
|
+
OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
|
1353
|
+
goto f_err;
|
1354
|
+
}
|
1355
|
+
|
1356
|
+
int sig_ok = ssl_public_key_verify(
|
1357
|
+
ssl, CBS_data(&signature), CBS_len(&signature), signature_algorithm,
|
1358
|
+
pkey, transcript_data, transcript_len);
|
1359
|
+
OPENSSL_free(transcript_data);
|
1360
|
+
|
1361
|
+
#if defined(BORINGSSL_UNSAFE_FUZZER_MODE)
|
1362
|
+
sig_ok = 1;
|
1363
|
+
ERR_clear_error();
|
1364
|
+
#endif
|
1365
|
+
if (!sig_ok) {
|
1269
1366
|
/* bad signature */
|
1270
1367
|
al = SSL_AD_DECRYPT_ERROR;
|
1271
1368
|
OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_SIGNATURE);
|
@@ -1282,7 +1379,6 @@ int ssl3_get_server_key_exchange(SSL *ssl) {
|
|
1282
1379
|
}
|
1283
1380
|
}
|
1284
1381
|
EVP_PKEY_free(pkey);
|
1285
|
-
EVP_MD_CTX_cleanup(&md_ctx);
|
1286
1382
|
return 1;
|
1287
1383
|
|
1288
1384
|
f_err:
|
@@ -1292,35 +1388,18 @@ err:
|
|
1292
1388
|
DH_free(dh);
|
1293
1389
|
EC_POINT_free(srvr_ecpoint);
|
1294
1390
|
EC_KEY_free(ecdh);
|
1295
|
-
EVP_MD_CTX_cleanup(&md_ctx);
|
1296
1391
|
return -1;
|
1297
1392
|
}
|
1298
1393
|
|
1299
|
-
static int
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
int ssl3_get_certificate_request(SSL *ssl) {
|
1304
|
-
int ok, ret = 0;
|
1305
|
-
unsigned long n;
|
1306
|
-
X509_NAME *xn = NULL;
|
1307
|
-
STACK_OF(X509_NAME) *ca_sk = NULL;
|
1308
|
-
CBS cbs;
|
1309
|
-
CBS certificate_types;
|
1310
|
-
CBS certificate_authorities;
|
1311
|
-
const uint8_t *data;
|
1312
|
-
|
1313
|
-
n = ssl->method->ssl_get_message(ssl, SSL3_ST_CR_CERT_REQ_A,
|
1314
|
-
SSL3_ST_CR_CERT_REQ_B, -1, ssl->max_cert_list,
|
1315
|
-
ssl_hash_message, &ok);
|
1316
|
-
|
1317
|
-
if (!ok) {
|
1318
|
-
return n;
|
1394
|
+
static int ssl3_get_certificate_request(SSL *ssl) {
|
1395
|
+
int msg_ret = ssl->method->ssl_get_message(ssl, -1, ssl_hash_message);
|
1396
|
+
if (msg_ret <= 0) {
|
1397
|
+
return msg_ret;
|
1319
1398
|
}
|
1320
1399
|
|
1321
|
-
ssl->s3->tmp.
|
1400
|
+
ssl->s3->tmp.cert_request = 0;
|
1322
1401
|
|
1323
|
-
if (ssl->s3->tmp.message_type ==
|
1402
|
+
if (ssl->s3->tmp.message_type == SSL3_MT_SERVER_HELLO_DONE) {
|
1324
1403
|
ssl->s3->tmp.reuse_message = 1;
|
1325
1404
|
/* If we get here we don't need the handshake buffer as we won't be doing
|
1326
1405
|
* client auth. */
|
@@ -1330,29 +1409,25 @@ int ssl3_get_certificate_request(SSL *ssl) {
|
|
1330
1409
|
|
1331
1410
|
if (ssl->s3->tmp.message_type != SSL3_MT_CERTIFICATE_REQUEST) {
|
1332
1411
|
ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE);
|
1333
|
-
OPENSSL_PUT_ERROR(SSL,
|
1334
|
-
|
1412
|
+
OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_MESSAGE);
|
1413
|
+
return -1;
|
1335
1414
|
}
|
1336
1415
|
|
1337
|
-
|
1338
|
-
|
1339
|
-
ca_sk = sk_X509_NAME_new(ca_dn_cmp);
|
1340
|
-
if (ca_sk == NULL) {
|
1341
|
-
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
1342
|
-
goto err;
|
1343
|
-
}
|
1416
|
+
CBS cbs;
|
1417
|
+
CBS_init(&cbs, ssl->init_msg, ssl->init_num);
|
1344
1418
|
|
1345
|
-
/*
|
1419
|
+
/* Get the certificate types. */
|
1420
|
+
CBS certificate_types;
|
1346
1421
|
if (!CBS_get_u8_length_prefixed(&cbs, &certificate_types)) {
|
1347
1422
|
ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
|
1348
1423
|
OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
|
1349
|
-
|
1424
|
+
return -1;
|
1350
1425
|
}
|
1351
1426
|
|
1352
1427
|
if (!CBS_stow(&certificate_types, &ssl->s3->tmp.certificate_types,
|
1353
1428
|
&ssl->s3->tmp.num_certificate_types)) {
|
1354
1429
|
ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
|
1355
|
-
|
1430
|
+
return -1;
|
1356
1431
|
}
|
1357
1432
|
|
1358
1433
|
if (ssl3_protocol_version(ssl) >= TLS1_2_VERSION) {
|
@@ -1361,223 +1436,111 @@ int ssl3_get_certificate_request(SSL *ssl) {
|
|
1361
1436
|
!tls1_parse_peer_sigalgs(ssl, &supported_signature_algorithms)) {
|
1362
1437
|
ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
|
1363
1438
|
OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
|
1364
|
-
|
1439
|
+
return -1;
|
1365
1440
|
}
|
1366
1441
|
}
|
1367
1442
|
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1443
|
+
uint8_t alert;
|
1444
|
+
STACK_OF(X509_NAME) *ca_sk = ssl_parse_client_CA_list(ssl, &alert, &cbs);
|
1445
|
+
if (ca_sk == NULL) {
|
1446
|
+
ssl3_send_alert(ssl, SSL3_AL_FATAL, alert);
|
1447
|
+
return -1;
|
1373
1448
|
}
|
1374
1449
|
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
OPENSSL_PUT_ERROR(SSL, SSL_R_CA_DN_TOO_LONG);
|
1381
|
-
goto err;
|
1382
|
-
}
|
1383
|
-
|
1384
|
-
data = CBS_data(&distinguished_name);
|
1385
|
-
|
1386
|
-
/* A u16 length cannot overflow a long. */
|
1387
|
-
xn = d2i_X509_NAME(NULL, &data, (long)CBS_len(&distinguished_name));
|
1388
|
-
if (xn == NULL) {
|
1389
|
-
ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
|
1390
|
-
OPENSSL_PUT_ERROR(SSL, ERR_R_ASN1_LIB);
|
1391
|
-
goto err;
|
1392
|
-
}
|
1393
|
-
|
1394
|
-
if (!CBS_skip(&distinguished_name, data - CBS_data(&distinguished_name))) {
|
1395
|
-
ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
|
1396
|
-
OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
|
1397
|
-
goto err;
|
1398
|
-
}
|
1399
|
-
|
1400
|
-
if (CBS_len(&distinguished_name) != 0) {
|
1401
|
-
ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
|
1402
|
-
OPENSSL_PUT_ERROR(SSL, SSL_R_CA_DN_LENGTH_MISMATCH);
|
1403
|
-
goto err;
|
1404
|
-
}
|
1405
|
-
|
1406
|
-
if (!sk_X509_NAME_push(ca_sk, xn)) {
|
1407
|
-
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
1408
|
-
goto err;
|
1409
|
-
}
|
1450
|
+
if (CBS_len(&cbs) != 0) {
|
1451
|
+
ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
|
1452
|
+
sk_X509_NAME_pop_free(ca_sk, X509_NAME_free);
|
1453
|
+
OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
|
1454
|
+
return -1;
|
1410
1455
|
}
|
1411
1456
|
|
1412
|
-
|
1413
|
-
ssl->s3->tmp.cert_req = 1;
|
1457
|
+
ssl->s3->tmp.cert_request = 1;
|
1414
1458
|
sk_X509_NAME_pop_free(ssl->s3->tmp.ca_names, X509_NAME_free);
|
1415
1459
|
ssl->s3->tmp.ca_names = ca_sk;
|
1416
|
-
|
1417
|
-
|
1418
|
-
ret = 1;
|
1419
|
-
|
1420
|
-
err:
|
1421
|
-
sk_X509_NAME_pop_free(ca_sk, X509_NAME_free);
|
1422
|
-
return ret;
|
1460
|
+
return 1;
|
1423
1461
|
}
|
1424
1462
|
|
1425
|
-
int
|
1426
|
-
int
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1431
|
-
if (!ok) {
|
1432
|
-
return n;
|
1463
|
+
static int ssl3_get_server_hello_done(SSL *ssl) {
|
1464
|
+
int ret = ssl->method->ssl_get_message(ssl, SSL3_MT_SERVER_HELLO_DONE,
|
1465
|
+
ssl_hash_message);
|
1466
|
+
if (ret <= 0) {
|
1467
|
+
return ret;
|
1433
1468
|
}
|
1434
1469
|
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
if (!CBS_get_u32(&new_session_ticket, &ticket_lifetime_hint) ||
|
1439
|
-
!CBS_get_u16_length_prefixed(&new_session_ticket, &ticket) ||
|
1440
|
-
CBS_len(&new_session_ticket) != 0) {
|
1441
|
-
al = SSL_AD_DECODE_ERROR;
|
1470
|
+
/* ServerHelloDone is empty. */
|
1471
|
+
if (ssl->init_num > 0) {
|
1472
|
+
ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
|
1442
1473
|
OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
|
1443
|
-
|
1444
|
-
}
|
1445
|
-
|
1446
|
-
if (CBS_len(&ticket) == 0) {
|
1447
|
-
/* RFC 5077 allows a server to change its mind and send no ticket after
|
1448
|
-
* negotiating the extension. The value of |tlsext_ticket_expected| is
|
1449
|
-
* checked in |ssl_update_cache| so is cleared here to avoid an unnecessary
|
1450
|
-
* update. */
|
1451
|
-
ssl->tlsext_ticket_expected = 0;
|
1452
|
-
return 1;
|
1453
|
-
}
|
1454
|
-
|
1455
|
-
if (ssl->hit) {
|
1456
|
-
/* The server is sending a new ticket for an existing session. Sessions are
|
1457
|
-
* immutable once established, so duplicate all but the ticket of the
|
1458
|
-
* existing session. */
|
1459
|
-
uint8_t *bytes;
|
1460
|
-
size_t bytes_len;
|
1461
|
-
if (!SSL_SESSION_to_bytes_for_ticket(ssl->session, &bytes, &bytes_len)) {
|
1462
|
-
goto err;
|
1463
|
-
}
|
1464
|
-
SSL_SESSION *new_session = SSL_SESSION_from_bytes(bytes, bytes_len);
|
1465
|
-
OPENSSL_free(bytes);
|
1466
|
-
if (new_session == NULL) {
|
1467
|
-
/* This should never happen. */
|
1468
|
-
OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
|
1469
|
-
goto err;
|
1470
|
-
}
|
1471
|
-
|
1472
|
-
SSL_SESSION_free(ssl->session);
|
1473
|
-
ssl->session = new_session;
|
1474
|
-
}
|
1475
|
-
|
1476
|
-
if (!CBS_stow(&ticket, &ssl->session->tlsext_tick,
|
1477
|
-
&ssl->session->tlsext_ticklen)) {
|
1478
|
-
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
1479
|
-
goto err;
|
1480
|
-
}
|
1481
|
-
ssl->session->tlsext_tick_lifetime_hint = ticket_lifetime_hint;
|
1482
|
-
|
1483
|
-
/* Generate a session ID for this session based on the session ticket. We use
|
1484
|
-
* the session ID mechanism for detecting ticket resumption. This also fits in
|
1485
|
-
* with assumptions elsewhere in OpenSSL.*/
|
1486
|
-
if (!EVP_Digest(CBS_data(&ticket), CBS_len(&ticket), ssl->session->session_id,
|
1487
|
-
&ssl->session->session_id_length, EVP_sha256(), NULL)) {
|
1488
|
-
goto err;
|
1474
|
+
return -1;
|
1489
1475
|
}
|
1490
1476
|
|
1491
1477
|
return 1;
|
1492
|
-
|
1493
|
-
f_err:
|
1494
|
-
ssl3_send_alert(ssl, SSL3_AL_FATAL, al);
|
1495
|
-
err:
|
1496
|
-
return -1;
|
1497
1478
|
}
|
1498
1479
|
|
1499
|
-
int
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
if (ssl->s3->tmp.message_type != SSL3_MT_CERTIFICATE_STATUS) {
|
1514
|
-
/* A server may send status_request in ServerHello and then change
|
1515
|
-
* its mind about sending CertificateStatus. */
|
1516
|
-
ssl->s3->tmp.reuse_message = 1;
|
1517
|
-
return 1;
|
1518
|
-
}
|
1519
|
-
|
1520
|
-
CBS_init(&certificate_status, ssl->init_msg, n);
|
1521
|
-
if (!CBS_get_u8(&certificate_status, &status_type) ||
|
1522
|
-
status_type != TLSEXT_STATUSTYPE_ocsp ||
|
1523
|
-
!CBS_get_u24_length_prefixed(&certificate_status, &ocsp_response) ||
|
1524
|
-
CBS_len(&ocsp_response) == 0 ||
|
1525
|
-
CBS_len(&certificate_status) != 0) {
|
1526
|
-
al = SSL_AD_DECODE_ERROR;
|
1527
|
-
OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
|
1528
|
-
goto f_err;
|
1529
|
-
}
|
1480
|
+
static int ssl3_send_client_certificate(SSL *ssl) {
|
1481
|
+
if (ssl->state == SSL3_ST_CW_CERT_A) {
|
1482
|
+
/* Call cert_cb to update the certificate. */
|
1483
|
+
if (ssl->cert->cert_cb) {
|
1484
|
+
int ret = ssl->cert->cert_cb(ssl, ssl->cert->cert_cb_arg);
|
1485
|
+
if (ret < 0) {
|
1486
|
+
ssl->rwstate = SSL_X509_LOOKUP;
|
1487
|
+
return -1;
|
1488
|
+
}
|
1489
|
+
if (ret == 0) {
|
1490
|
+
ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
|
1491
|
+
return -1;
|
1492
|
+
}
|
1493
|
+
}
|
1530
1494
|
|
1531
|
-
|
1532
|
-
&ssl->session->ocsp_response_length)) {
|
1533
|
-
al = SSL_AD_INTERNAL_ERROR;
|
1534
|
-
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
1535
|
-
goto f_err;
|
1495
|
+
ssl->state = SSL3_ST_CW_CERT_B;
|
1536
1496
|
}
|
1537
|
-
return 1;
|
1538
|
-
|
1539
|
-
f_err:
|
1540
|
-
ssl3_send_alert(ssl, SSL3_AL_FATAL, al);
|
1541
|
-
return -1;
|
1542
|
-
}
|
1543
1497
|
|
1544
|
-
|
1545
|
-
|
1546
|
-
|
1498
|
+
if (ssl->state == SSL3_ST_CW_CERT_B) {
|
1499
|
+
/* Call client_cert_cb to update the certificate. */
|
1500
|
+
int should_retry;
|
1501
|
+
if (!ssl_do_client_cert_cb(ssl, &should_retry)) {
|
1502
|
+
if (should_retry) {
|
1503
|
+
ssl->rwstate = SSL_X509_LOOKUP;
|
1504
|
+
}
|
1505
|
+
return -1;
|
1506
|
+
}
|
1547
1507
|
|
1548
|
-
|
1549
|
-
|
1550
|
-
|
1551
|
-
|
1508
|
+
if (!ssl_has_certificate(ssl)) {
|
1509
|
+
ssl->s3->tmp.cert_request = 0;
|
1510
|
+
/* Without a client certificate, the handshake buffer may be released. */
|
1511
|
+
ssl3_free_handshake_buffer(ssl);
|
1552
1512
|
|
1553
|
-
|
1554
|
-
|
1555
|
-
|
1513
|
+
if (ssl->version == SSL3_VERSION) {
|
1514
|
+
/* In SSL 3.0, send no certificate by skipping both messages. */
|
1515
|
+
ssl3_send_alert(ssl, SSL3_AL_WARNING, SSL_AD_NO_CERTIFICATE);
|
1516
|
+
return 1;
|
1517
|
+
}
|
1518
|
+
}
|
1556
1519
|
|
1557
|
-
|
1558
|
-
|
1559
|
-
|
1560
|
-
|
1561
|
-
return -1;
|
1520
|
+
if (!ssl3_output_cert_chain(ssl)) {
|
1521
|
+
return -1;
|
1522
|
+
}
|
1523
|
+
ssl->state = SSL3_ST_CW_CERT_C;
|
1562
1524
|
}
|
1563
1525
|
|
1564
|
-
|
1526
|
+
assert(ssl->state == SSL3_ST_CW_CERT_C);
|
1527
|
+
return ssl->method->write_message(ssl);
|
1565
1528
|
}
|
1566
1529
|
|
1567
1530
|
OPENSSL_COMPILE_ASSERT(sizeof(size_t) >= sizeof(unsigned),
|
1568
1531
|
SIZE_T_IS_SMALLER_THAN_UNSIGNED);
|
1569
1532
|
|
1570
|
-
int ssl3_send_client_key_exchange(SSL *ssl) {
|
1533
|
+
static int ssl3_send_client_key_exchange(SSL *ssl) {
|
1571
1534
|
if (ssl->state == SSL3_ST_CW_KEY_EXCH_B) {
|
1572
|
-
return
|
1535
|
+
return ssl->method->write_message(ssl);
|
1573
1536
|
}
|
1574
1537
|
assert(ssl->state == SSL3_ST_CW_KEY_EXCH_A);
|
1575
1538
|
|
1576
1539
|
uint8_t *pms = NULL;
|
1577
1540
|
size_t pms_len = 0;
|
1578
|
-
CBB cbb;
|
1579
|
-
if (!
|
1580
|
-
|
1541
|
+
CBB cbb, body;
|
1542
|
+
if (!ssl->method->init_message(ssl, &cbb, &body,
|
1543
|
+
SSL3_MT_CLIENT_KEY_EXCHANGE)) {
|
1581
1544
|
goto err;
|
1582
1545
|
}
|
1583
1546
|
|
@@ -1596,7 +1559,7 @@ int ssl3_send_client_key_exchange(SSL *ssl) {
|
|
1596
1559
|
char identity[PSK_MAX_IDENTITY_LEN + 1];
|
1597
1560
|
memset(identity, 0, sizeof(identity));
|
1598
1561
|
psk_len = ssl->psk_client_callback(
|
1599
|
-
ssl, ssl->s3->
|
1562
|
+
ssl, ssl->s3->hs->peer_psk_identity_hint, identity, sizeof(identity),
|
1600
1563
|
psk, sizeof(psk));
|
1601
1564
|
if (psk_len == 0) {
|
1602
1565
|
OPENSSL_PUT_ERROR(SSL, SSL_R_PSK_IDENTITY_NOT_FOUND);
|
@@ -1605,19 +1568,19 @@ int ssl3_send_client_key_exchange(SSL *ssl) {
|
|
1605
1568
|
}
|
1606
1569
|
assert(psk_len <= PSK_MAX_PSK_LEN);
|
1607
1570
|
|
1608
|
-
OPENSSL_free(ssl->
|
1609
|
-
ssl->
|
1610
|
-
if (ssl->
|
1571
|
+
OPENSSL_free(ssl->s3->new_session->psk_identity);
|
1572
|
+
ssl->s3->new_session->psk_identity = BUF_strdup(identity);
|
1573
|
+
if (ssl->s3->new_session->psk_identity == NULL) {
|
1611
1574
|
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
1612
1575
|
goto err;
|
1613
1576
|
}
|
1614
1577
|
|
1615
1578
|
/* Write out psk_identity. */
|
1616
1579
|
CBB child;
|
1617
|
-
if (!CBB_add_u16_length_prefixed(&
|
1580
|
+
if (!CBB_add_u16_length_prefixed(&body, &child) ||
|
1618
1581
|
!CBB_add_bytes(&child, (const uint8_t *)identity,
|
1619
1582
|
OPENSSL_strnlen(identity, sizeof(identity))) ||
|
1620
|
-
!CBB_flush(&
|
1583
|
+
!CBB_flush(&body)) {
|
1621
1584
|
goto err;
|
1622
1585
|
}
|
1623
1586
|
}
|
@@ -1631,7 +1594,7 @@ int ssl3_send_client_key_exchange(SSL *ssl) {
|
|
1631
1594
|
goto err;
|
1632
1595
|
}
|
1633
1596
|
|
1634
|
-
EVP_PKEY *pkey = X509_get_pubkey(ssl->
|
1597
|
+
EVP_PKEY *pkey = X509_get_pubkey(ssl->s3->new_session->peer);
|
1635
1598
|
if (pkey == NULL) {
|
1636
1599
|
goto err;
|
1637
1600
|
}
|
@@ -1643,7 +1606,6 @@ int ssl3_send_client_key_exchange(SSL *ssl) {
|
|
1643
1606
|
goto err;
|
1644
1607
|
}
|
1645
1608
|
|
1646
|
-
ssl->session->key_exchange_info = EVP_PKEY_bits(pkey);
|
1647
1609
|
EVP_PKEY_free(pkey);
|
1648
1610
|
|
1649
1611
|
pms[0] = ssl->client_version >> 8;
|
@@ -1652,11 +1614,11 @@ int ssl3_send_client_key_exchange(SSL *ssl) {
|
|
1652
1614
|
goto err;
|
1653
1615
|
}
|
1654
1616
|
|
1655
|
-
CBB child, *enc_pms = &
|
1617
|
+
CBB child, *enc_pms = &body;
|
1656
1618
|
size_t enc_pms_len;
|
1657
1619
|
/* In TLS, there is a length prefix. */
|
1658
1620
|
if (ssl->version > SSL3_VERSION) {
|
1659
|
-
if (!CBB_add_u16_length_prefixed(&
|
1621
|
+
if (!CBB_add_u16_length_prefixed(&body, &child)) {
|
1660
1622
|
goto err;
|
1661
1623
|
}
|
1662
1624
|
enc_pms = &child;
|
@@ -1669,34 +1631,27 @@ int ssl3_send_client_key_exchange(SSL *ssl) {
|
|
1669
1631
|
/* Log the premaster secret, if logging is enabled. */
|
1670
1632
|
!ssl_log_rsa_client_key_exchange(ssl, ptr, enc_pms_len, pms, pms_len) ||
|
1671
1633
|
!CBB_did_write(enc_pms, enc_pms_len) ||
|
1672
|
-
!CBB_flush(&
|
1634
|
+
!CBB_flush(&body)) {
|
1673
1635
|
goto err;
|
1674
1636
|
}
|
1675
|
-
} else if (alg_k & (SSL_kECDHE|SSL_kDHE)) {
|
1676
|
-
/* Generate a keypair and serialize the public half.
|
1677
|
-
* prefix while DHE uses u16. */
|
1637
|
+
} else if (alg_k & (SSL_kECDHE|SSL_kDHE|SSL_kCECPQ1)) {
|
1638
|
+
/* Generate a keypair and serialize the public half. */
|
1678
1639
|
CBB child;
|
1679
|
-
|
1680
|
-
if (alg_k & SSL_kECDHE) {
|
1681
|
-
child_ok = CBB_add_u8_length_prefixed(&cbb, &child);
|
1682
|
-
} else {
|
1683
|
-
child_ok = CBB_add_u16_length_prefixed(&cbb, &child);
|
1684
|
-
}
|
1685
|
-
|
1686
|
-
if (!child_ok ||
|
1687
|
-
!SSL_ECDH_CTX_generate_keypair(&ssl->s3->tmp.ecdh_ctx, &child) ||
|
1688
|
-
!CBB_flush(&cbb)) {
|
1640
|
+
if (!SSL_ECDH_CTX_add_key(&ssl->s3->tmp.ecdh_ctx, &body, &child)) {
|
1689
1641
|
goto err;
|
1690
1642
|
}
|
1691
1643
|
|
1692
1644
|
/* Compute the premaster. */
|
1693
1645
|
uint8_t alert;
|
1694
|
-
if (!
|
1695
|
-
|
1696
|
-
|
1646
|
+
if (!SSL_ECDH_CTX_accept(&ssl->s3->tmp.ecdh_ctx, &child, &pms, &pms_len,
|
1647
|
+
&alert, ssl->s3->tmp.peer_key,
|
1648
|
+
ssl->s3->tmp.peer_key_len)) {
|
1697
1649
|
ssl3_send_alert(ssl, SSL3_AL_FATAL, alert);
|
1698
1650
|
goto err;
|
1699
1651
|
}
|
1652
|
+
if (!CBB_flush(&body)) {
|
1653
|
+
goto err;
|
1654
|
+
}
|
1700
1655
|
|
1701
1656
|
/* The key exchange state may now be discarded. */
|
1702
1657
|
SSL_ECDH_CTX_cleanup(&ssl->s3->tmp.ecdh_ctx);
|
@@ -1744,26 +1699,26 @@ int ssl3_send_client_key_exchange(SSL *ssl) {
|
|
1744
1699
|
|
1745
1700
|
/* The message must be added to the finished hash before calculating the
|
1746
1701
|
* master secret. */
|
1747
|
-
|
1748
|
-
if (!CBB_finish(&cbb, NULL, &length) ||
|
1749
|
-
!ssl_set_handshake_header(ssl, SSL3_MT_CLIENT_KEY_EXCHANGE, length)) {
|
1702
|
+
if (!ssl->method->finish_message(ssl, &cbb)) {
|
1750
1703
|
goto err;
|
1751
1704
|
}
|
1752
1705
|
ssl->state = SSL3_ST_CW_KEY_EXCH_B;
|
1753
1706
|
|
1754
|
-
ssl->
|
1755
|
-
tls1_generate_master_secret(ssl, ssl->
|
1756
|
-
|
1707
|
+
ssl->s3->new_session->master_key_length =
|
1708
|
+
tls1_generate_master_secret(ssl, ssl->s3->new_session->master_key, pms,
|
1709
|
+
pms_len);
|
1710
|
+
if (ssl->s3->new_session->master_key_length == 0) {
|
1757
1711
|
goto err;
|
1758
1712
|
}
|
1759
|
-
ssl->
|
1713
|
+
ssl->s3->new_session->extended_master_secret =
|
1714
|
+
ssl->s3->tmp.extended_master_secret;
|
1760
1715
|
OPENSSL_cleanse(pms, pms_len);
|
1761
1716
|
OPENSSL_free(pms);
|
1762
1717
|
|
1763
|
-
|
1764
|
-
return ssl_do_write(ssl);
|
1718
|
+
return ssl->method->write_message(ssl);
|
1765
1719
|
|
1766
1720
|
err:
|
1721
|
+
CBB_cleanup(&cbb);
|
1767
1722
|
if (pms != NULL) {
|
1768
1723
|
OPENSSL_cleanse(pms, pms_len);
|
1769
1724
|
OPENSSL_free(pms);
|
@@ -1771,75 +1726,88 @@ err:
|
|
1771
1726
|
return -1;
|
1772
1727
|
}
|
1773
1728
|
|
1774
|
-
int ssl3_send_cert_verify(SSL *ssl) {
|
1729
|
+
static int ssl3_send_cert_verify(SSL *ssl) {
|
1775
1730
|
if (ssl->state == SSL3_ST_CW_CERT_VRFY_C) {
|
1776
|
-
return
|
1731
|
+
return ssl->method->write_message(ssl);
|
1777
1732
|
}
|
1778
1733
|
|
1779
|
-
|
1780
|
-
|
1781
|
-
|
1734
|
+
assert(ssl_has_private_key(ssl));
|
1735
|
+
|
1736
|
+
CBB cbb, body, child;
|
1737
|
+
if (!ssl->method->init_message(ssl, &cbb, &body,
|
1738
|
+
SSL3_MT_CERTIFICATE_VERIFY)) {
|
1782
1739
|
goto err;
|
1783
1740
|
}
|
1784
1741
|
|
1785
|
-
|
1742
|
+
uint16_t signature_algorithm;
|
1743
|
+
if (!tls1_choose_signature_algorithm(ssl, &signature_algorithm)) {
|
1744
|
+
goto err;
|
1745
|
+
}
|
1746
|
+
if (ssl3_protocol_version(ssl) >= TLS1_2_VERSION) {
|
1747
|
+
/* Write out the digest type in TLS 1.2. */
|
1748
|
+
if (!CBB_add_u16(&body, signature_algorithm)) {
|
1749
|
+
OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
|
1750
|
+
goto err;
|
1751
|
+
}
|
1752
|
+
}
|
1786
1753
|
|
1754
|
+
/* Set aside space for the signature. */
|
1787
1755
|
const size_t max_sig_len = ssl_private_key_max_signature_len(ssl);
|
1788
|
-
|
1756
|
+
uint8_t *ptr;
|
1757
|
+
if (!CBB_add_u16_length_prefixed(&body, &child) ||
|
1758
|
+
!CBB_reserve(&child, &ptr, max_sig_len)) {
|
1759
|
+
goto err;
|
1760
|
+
}
|
1761
|
+
|
1762
|
+
size_t sig_len = max_sig_len;
|
1789
1763
|
enum ssl_private_key_result_t sign_result;
|
1790
1764
|
if (ssl->state == SSL3_ST_CW_CERT_VRFY_A) {
|
1791
|
-
/*
|
1792
|
-
|
1793
|
-
if (ssl3_protocol_version(ssl)
|
1794
|
-
|
1795
|
-
|
1796
|
-
OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
|
1765
|
+
/* The SSL3 construction for CertificateVerify does not decompose into a
|
1766
|
+
* single final digest and signature, and must be special-cased. */
|
1767
|
+
if (ssl3_protocol_version(ssl) == SSL3_VERSION) {
|
1768
|
+
if (ssl->cert->key_method != NULL) {
|
1769
|
+
OPENSSL_PUT_ERROR(SSL, SSL_R_UNSUPPORTED_PROTOCOL_FOR_CUSTOM_KEY);
|
1797
1770
|
goto err;
|
1798
1771
|
}
|
1799
|
-
}
|
1800
1772
|
|
1801
|
-
|
1802
|
-
|
1803
|
-
|
1804
|
-
|
1805
|
-
|
1806
|
-
|
1807
|
-
|
1773
|
+
const EVP_MD *md;
|
1774
|
+
uint8_t digest[EVP_MAX_MD_SIZE];
|
1775
|
+
size_t digest_len;
|
1776
|
+
if (!ssl3_cert_verify_hash(ssl, &md, digest, &digest_len,
|
1777
|
+
signature_algorithm)) {
|
1778
|
+
goto err;
|
1779
|
+
}
|
1780
|
+
|
1781
|
+
sign_result = ssl_private_key_success;
|
1782
|
+
|
1783
|
+
EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new(ssl->cert->privatekey, NULL);
|
1784
|
+
if (pctx == NULL ||
|
1785
|
+
!EVP_PKEY_sign_init(pctx) ||
|
1786
|
+
!EVP_PKEY_CTX_set_signature_md(pctx, md) ||
|
1787
|
+
!EVP_PKEY_sign(pctx, ptr, &sig_len, digest, digest_len)) {
|
1788
|
+
EVP_PKEY_CTX_free(pctx);
|
1789
|
+
sign_result = ssl_private_key_failure;
|
1790
|
+
goto err;
|
1791
|
+
}
|
1792
|
+
EVP_PKEY_CTX_free(pctx);
|
1793
|
+
} else {
|
1794
|
+
sign_result = ssl_private_key_sign(
|
1795
|
+
ssl, ptr, &sig_len, max_sig_len, signature_algorithm,
|
1796
|
+
(const uint8_t *)ssl->s3->handshake_buffer->data,
|
1797
|
+
ssl->s3->handshake_buffer->length);
|
1808
1798
|
}
|
1809
1799
|
|
1810
1800
|
/* The handshake buffer is no longer necessary. */
|
1811
1801
|
ssl3_free_handshake_buffer(ssl);
|
1812
|
-
|
1813
|
-
/* Sign the digest. */
|
1814
|
-
uint8_t *ptr;
|
1815
|
-
if (!CBB_add_u16_length_prefixed(&cbb, &child) ||
|
1816
|
-
!CBB_reserve(&child, &ptr, max_sig_len)) {
|
1817
|
-
goto err;
|
1818
|
-
}
|
1819
|
-
sign_result = ssl_private_key_sign(ssl, ptr, &sig_len, max_sig_len, md,
|
1820
|
-
digest, digest_len);
|
1821
1802
|
} else {
|
1822
1803
|
assert(ssl->state == SSL3_ST_CW_CERT_VRFY_B);
|
1823
|
-
|
1824
|
-
/* Skip over the already written signature algorithm and retry the
|
1825
|
-
* signature. */
|
1826
|
-
uint8_t *ptr;
|
1827
|
-
if ((ssl3_protocol_version(ssl) >= TLS1_2_VERSION &&
|
1828
|
-
!CBB_did_write(&cbb, 2)) ||
|
1829
|
-
!CBB_add_u16_length_prefixed(&cbb, &child) ||
|
1830
|
-
!CBB_reserve(&child, &ptr, max_sig_len)) {
|
1831
|
-
goto err;
|
1832
|
-
}
|
1833
|
-
sign_result =
|
1834
|
-
ssl_private_key_sign_complete(ssl, ptr, &sig_len, max_sig_len);
|
1804
|
+
sign_result = ssl_private_key_complete(ssl, ptr, &sig_len, max_sig_len);
|
1835
1805
|
}
|
1836
1806
|
|
1837
1807
|
switch (sign_result) {
|
1838
1808
|
case ssl_private_key_success:
|
1839
|
-
ssl->rwstate = SSL_NOTHING;
|
1840
1809
|
break;
|
1841
1810
|
case ssl_private_key_failure:
|
1842
|
-
ssl->rwstate = SSL_NOTHING;
|
1843
1811
|
goto err;
|
1844
1812
|
case ssl_private_key_retry:
|
1845
1813
|
ssl->rwstate = SSL_PRIVATE_KEY_OPERATION;
|
@@ -1847,118 +1815,22 @@ int ssl3_send_cert_verify(SSL *ssl) {
|
|
1847
1815
|
goto err;
|
1848
1816
|
}
|
1849
1817
|
|
1850
|
-
size_t length;
|
1851
1818
|
if (!CBB_did_write(&child, sig_len) ||
|
1852
|
-
!
|
1853
|
-
!ssl_set_handshake_header(ssl, SSL3_MT_CERTIFICATE_VERIFY, length)) {
|
1819
|
+
!ssl->method->finish_message(ssl, &cbb)) {
|
1854
1820
|
goto err;
|
1855
1821
|
}
|
1856
1822
|
|
1857
1823
|
ssl->state = SSL3_ST_CW_CERT_VRFY_C;
|
1858
|
-
return
|
1824
|
+
return ssl->method->write_message(ssl);
|
1859
1825
|
|
1860
1826
|
err:
|
1861
1827
|
CBB_cleanup(&cbb);
|
1862
1828
|
return -1;
|
1863
1829
|
}
|
1864
1830
|
|
1865
|
-
|
1866
|
-
* configured. */
|
1867
|
-
static int ssl3_has_client_certificate(SSL *ssl) {
|
1868
|
-
return ssl->cert && ssl->cert->x509 && ssl_has_private_key(ssl);
|
1869
|
-
}
|
1870
|
-
|
1871
|
-
int ssl3_send_client_certificate(SSL *ssl) {
|
1872
|
-
X509 *x509 = NULL;
|
1873
|
-
EVP_PKEY *pkey = NULL;
|
1874
|
-
int i;
|
1875
|
-
|
1876
|
-
if (ssl->state == SSL3_ST_CW_CERT_A) {
|
1877
|
-
/* Let cert callback update client certificates if required */
|
1878
|
-
if (ssl->cert->cert_cb) {
|
1879
|
-
i = ssl->cert->cert_cb(ssl, ssl->cert->cert_cb_arg);
|
1880
|
-
if (i < 0) {
|
1881
|
-
ssl->rwstate = SSL_X509_LOOKUP;
|
1882
|
-
return -1;
|
1883
|
-
}
|
1884
|
-
if (i == 0) {
|
1885
|
-
ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
|
1886
|
-
return 0;
|
1887
|
-
}
|
1888
|
-
ssl->rwstate = SSL_NOTHING;
|
1889
|
-
}
|
1890
|
-
|
1891
|
-
if (ssl3_has_client_certificate(ssl)) {
|
1892
|
-
ssl->state = SSL3_ST_CW_CERT_C;
|
1893
|
-
} else {
|
1894
|
-
ssl->state = SSL3_ST_CW_CERT_B;
|
1895
|
-
}
|
1896
|
-
}
|
1897
|
-
|
1898
|
-
/* We need to get a client cert */
|
1899
|
-
if (ssl->state == SSL3_ST_CW_CERT_B) {
|
1900
|
-
/* If we get an error, we need to:
|
1901
|
-
* ssl->rwstate=SSL_X509_LOOKUP; return(-1);
|
1902
|
-
* We then get retried later */
|
1903
|
-
i = ssl_do_client_cert_cb(ssl, &x509, &pkey);
|
1904
|
-
if (i < 0) {
|
1905
|
-
ssl->rwstate = SSL_X509_LOOKUP;
|
1906
|
-
return -1;
|
1907
|
-
}
|
1908
|
-
ssl->rwstate = SSL_NOTHING;
|
1909
|
-
if (i == 1 && pkey != NULL && x509 != NULL) {
|
1910
|
-
ssl->state = SSL3_ST_CW_CERT_B;
|
1911
|
-
if (!SSL_use_certificate(ssl, x509) || !SSL_use_PrivateKey(ssl, pkey)) {
|
1912
|
-
i = 0;
|
1913
|
-
}
|
1914
|
-
} else if (i == 1) {
|
1915
|
-
i = 0;
|
1916
|
-
OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_DATA_RETURNED_BY_CALLBACK);
|
1917
|
-
}
|
1918
|
-
|
1919
|
-
X509_free(x509);
|
1920
|
-
EVP_PKEY_free(pkey);
|
1921
|
-
if (i && !ssl3_has_client_certificate(ssl)) {
|
1922
|
-
i = 0;
|
1923
|
-
}
|
1924
|
-
if (i == 0) {
|
1925
|
-
if (ssl->version == SSL3_VERSION) {
|
1926
|
-
ssl->s3->tmp.cert_req = 0;
|
1927
|
-
ssl3_send_alert(ssl, SSL3_AL_WARNING, SSL_AD_NO_CERTIFICATE);
|
1928
|
-
return 1;
|
1929
|
-
} else {
|
1930
|
-
ssl->s3->tmp.cert_req = 2;
|
1931
|
-
/* There is no client certificate, so the handshake buffer may be
|
1932
|
-
* released. */
|
1933
|
-
ssl3_free_handshake_buffer(ssl);
|
1934
|
-
}
|
1935
|
-
}
|
1936
|
-
|
1937
|
-
/* Ok, we have a cert */
|
1938
|
-
ssl->state = SSL3_ST_CW_CERT_C;
|
1939
|
-
}
|
1940
|
-
|
1941
|
-
if (ssl->state == SSL3_ST_CW_CERT_C) {
|
1942
|
-
if (ssl->s3->tmp.cert_req == 2) {
|
1943
|
-
/* Send an empty Certificate message. */
|
1944
|
-
uint8_t *p = ssl_handshake_start(ssl);
|
1945
|
-
l2n3(0, p);
|
1946
|
-
if (!ssl_set_handshake_header(ssl, SSL3_MT_CERTIFICATE, 3)) {
|
1947
|
-
return -1;
|
1948
|
-
}
|
1949
|
-
} else if (!ssl3_output_cert_chain(ssl)) {
|
1950
|
-
return -1;
|
1951
|
-
}
|
1952
|
-
ssl->state = SSL3_ST_CW_CERT_D;
|
1953
|
-
}
|
1954
|
-
|
1955
|
-
/* SSL3_ST_CW_CERT_D */
|
1956
|
-
return ssl_do_write(ssl);
|
1957
|
-
}
|
1958
|
-
|
1959
|
-
int ssl3_send_next_proto(SSL *ssl) {
|
1831
|
+
static int ssl3_send_next_proto(SSL *ssl) {
|
1960
1832
|
if (ssl->state == SSL3_ST_CW_NEXT_PROTO_B) {
|
1961
|
-
return
|
1833
|
+
return ssl->method->write_message(ssl);
|
1962
1834
|
}
|
1963
1835
|
|
1964
1836
|
assert(ssl->state == SSL3_ST_CW_NEXT_PROTO_A);
|
@@ -1966,30 +1838,26 @@ int ssl3_send_next_proto(SSL *ssl) {
|
|
1966
1838
|
static const uint8_t kZero[32] = {0};
|
1967
1839
|
size_t padding_len = 32 - ((ssl->s3->next_proto_negotiated_len + 2) % 32);
|
1968
1840
|
|
1969
|
-
CBB cbb, child;
|
1970
|
-
|
1971
|
-
|
1972
|
-
if (!CBB_init_fixed(&cbb, ssl_handshake_start(ssl),
|
1973
|
-
ssl->init_buf->max - SSL_HM_HEADER_LENGTH(ssl)) ||
|
1974
|
-
!CBB_add_u8_length_prefixed(&cbb, &child) ||
|
1841
|
+
CBB cbb, body, child;
|
1842
|
+
if (!ssl->method->init_message(ssl, &cbb, &body, SSL3_MT_NEXT_PROTO) ||
|
1843
|
+
!CBB_add_u8_length_prefixed(&body, &child) ||
|
1975
1844
|
!CBB_add_bytes(&child, ssl->s3->next_proto_negotiated,
|
1976
1845
|
ssl->s3->next_proto_negotiated_len) ||
|
1977
|
-
!CBB_add_u8_length_prefixed(&
|
1846
|
+
!CBB_add_u8_length_prefixed(&body, &child) ||
|
1978
1847
|
!CBB_add_bytes(&child, kZero, padding_len) ||
|
1979
|
-
!
|
1980
|
-
!ssl_set_handshake_header(ssl, SSL3_MT_NEXT_PROTO, length)) {
|
1848
|
+
!ssl->method->finish_message(ssl, &cbb)) {
|
1981
1849
|
OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
|
1982
1850
|
CBB_cleanup(&cbb);
|
1983
1851
|
return -1;
|
1984
1852
|
}
|
1985
1853
|
|
1986
1854
|
ssl->state = SSL3_ST_CW_NEXT_PROTO_B;
|
1987
|
-
return
|
1855
|
+
return ssl->method->write_message(ssl);
|
1988
1856
|
}
|
1989
1857
|
|
1990
|
-
int ssl3_send_channel_id(SSL *ssl) {
|
1858
|
+
static int ssl3_send_channel_id(SSL *ssl) {
|
1991
1859
|
if (ssl->state == SSL3_ST_CW_CHANNEL_ID_B) {
|
1992
|
-
return
|
1860
|
+
return ssl->method->write_message(ssl);
|
1993
1861
|
}
|
1994
1862
|
|
1995
1863
|
assert(ssl->state == SSL3_ST_CW_CHANNEL_ID_A);
|
@@ -2010,7 +1878,6 @@ int ssl3_send_channel_id(SSL *ssl) {
|
|
2010
1878
|
ssl->rwstate = SSL_CHANNEL_ID_LOOKUP;
|
2011
1879
|
return -1;
|
2012
1880
|
}
|
2013
|
-
ssl->rwstate = SSL_NOTHING;
|
2014
1881
|
|
2015
1882
|
EC_KEY *ec_key = EVP_PKEY_get0_EC_KEY(ssl->tlsext_channel_id_private);
|
2016
1883
|
if (ec_key == NULL) {
|
@@ -2040,26 +1907,21 @@ int ssl3_send_channel_id(SSL *ssl) {
|
|
2040
1907
|
goto err;
|
2041
1908
|
}
|
2042
1909
|
|
2043
|
-
CBB cbb, child;
|
2044
|
-
|
2045
|
-
|
2046
|
-
|
2047
|
-
|
2048
|
-
!CBB_add_u16(&cbb, TLSEXT_TYPE_channel_id) ||
|
2049
|
-
!CBB_add_u16_length_prefixed(&cbb, &child) ||
|
2050
|
-
!BN_bn2cbb_padded(&child, 32, x) ||
|
2051
|
-
!BN_bn2cbb_padded(&child, 32, y) ||
|
1910
|
+
CBB cbb, body, child;
|
1911
|
+
if (!ssl->method->init_message(ssl, &cbb, &body, SSL3_MT_CHANNEL_ID) ||
|
1912
|
+
!CBB_add_u16(&body, TLSEXT_TYPE_channel_id) ||
|
1913
|
+
!CBB_add_u16_length_prefixed(&body, &child) ||
|
1914
|
+
!BN_bn2cbb_padded(&child, 32, x) || !BN_bn2cbb_padded(&child, 32, y) ||
|
2052
1915
|
!BN_bn2cbb_padded(&child, 32, sig->r) ||
|
2053
1916
|
!BN_bn2cbb_padded(&child, 32, sig->s) ||
|
2054
|
-
!
|
2055
|
-
!ssl_set_handshake_header(ssl, SSL3_MT_ENCRYPTED_EXTENSIONS, length)) {
|
1917
|
+
!ssl->method->finish_message(ssl, &cbb)) {
|
2056
1918
|
OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
|
2057
1919
|
CBB_cleanup(&cbb);
|
2058
1920
|
goto err;
|
2059
1921
|
}
|
2060
1922
|
|
2061
1923
|
ssl->state = SSL3_ST_CW_CHANNEL_ID_B;
|
2062
|
-
ret =
|
1924
|
+
ret = ssl->method->write_message(ssl);
|
2063
1925
|
|
2064
1926
|
err:
|
2065
1927
|
BN_free(x);
|
@@ -2068,23 +1930,73 @@ err:
|
|
2068
1930
|
return ret;
|
2069
1931
|
}
|
2070
1932
|
|
2071
|
-
int
|
2072
|
-
|
2073
|
-
|
1933
|
+
static int ssl3_get_new_session_ticket(SSL *ssl) {
|
1934
|
+
int ret = ssl->method->ssl_get_message(ssl, SSL3_MT_NEW_SESSION_TICKET,
|
1935
|
+
ssl_hash_message);
|
1936
|
+
if (ret <= 0) {
|
1937
|
+
return ret;
|
2074
1938
|
}
|
2075
|
-
return ssl->ctx->client_cert_cb(ssl, out_x509, out_pkey);
|
2076
|
-
}
|
2077
1939
|
|
2078
|
-
|
2079
|
-
|
2080
|
-
|
2081
|
-
|
2082
|
-
|
2083
|
-
|
2084
|
-
|
2085
|
-
|
2086
|
-
|
1940
|
+
CBS new_session_ticket, ticket;
|
1941
|
+
uint32_t tlsext_tick_lifetime_hint;
|
1942
|
+
CBS_init(&new_session_ticket, ssl->init_msg, ssl->init_num);
|
1943
|
+
if (!CBS_get_u32(&new_session_ticket, &tlsext_tick_lifetime_hint) ||
|
1944
|
+
!CBS_get_u16_length_prefixed(&new_session_ticket, &ticket) ||
|
1945
|
+
CBS_len(&new_session_ticket) != 0) {
|
1946
|
+
ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
|
1947
|
+
OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
|
1948
|
+
return -1;
|
2087
1949
|
}
|
2088
1950
|
|
2089
|
-
|
1951
|
+
if (CBS_len(&ticket) == 0) {
|
1952
|
+
/* RFC 5077 allows a server to change its mind and send no ticket after
|
1953
|
+
* negotiating the extension. The value of |tlsext_ticket_expected| is
|
1954
|
+
* checked in |ssl_update_cache| so is cleared here to avoid an unnecessary
|
1955
|
+
* update. */
|
1956
|
+
ssl->tlsext_ticket_expected = 0;
|
1957
|
+
return 1;
|
1958
|
+
}
|
1959
|
+
|
1960
|
+
int session_renewed = ssl->session != NULL;
|
1961
|
+
SSL_SESSION *session = ssl->s3->new_session;
|
1962
|
+
if (session_renewed) {
|
1963
|
+
/* The server is sending a new ticket for an existing session. Sessions are
|
1964
|
+
* immutable once established, so duplicate all but the ticket of the
|
1965
|
+
* existing session. */
|
1966
|
+
session = SSL_SESSION_dup(ssl->session, SSL_SESSION_INCLUDE_NONAUTH);
|
1967
|
+
if (session == NULL) {
|
1968
|
+
/* This should never happen. */
|
1969
|
+
OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
|
1970
|
+
goto err;
|
1971
|
+
}
|
1972
|
+
}
|
1973
|
+
|
1974
|
+
if (!CBS_stow(&ticket, &session->tlsext_tick, &session->tlsext_ticklen)) {
|
1975
|
+
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
|
1976
|
+
goto err;
|
1977
|
+
}
|
1978
|
+
session->tlsext_tick_lifetime_hint = tlsext_tick_lifetime_hint;
|
1979
|
+
|
1980
|
+
/* Generate a session ID for this session based on the session ticket. We use
|
1981
|
+
* the session ID mechanism for detecting ticket resumption. This also fits in
|
1982
|
+
* with assumptions elsewhere in OpenSSL.*/
|
1983
|
+
if (!EVP_Digest(CBS_data(&ticket), CBS_len(&ticket),
|
1984
|
+
session->session_id, &session->session_id_length,
|
1985
|
+
EVP_sha256(), NULL)) {
|
1986
|
+
goto err;
|
1987
|
+
}
|
1988
|
+
|
1989
|
+
if (session_renewed) {
|
1990
|
+
session->not_resumable = 0;
|
1991
|
+
SSL_SESSION_free(ssl->session);
|
1992
|
+
ssl->session = session;
|
1993
|
+
}
|
1994
|
+
|
1995
|
+
return 1;
|
1996
|
+
|
1997
|
+
err:
|
1998
|
+
if (session_renewed) {
|
1999
|
+
SSL_SESSION_free(session);
|
2000
|
+
}
|
2001
|
+
return -1;
|
2090
2002
|
}
|