wearefair-grpc 1.3.1.pre.c → 1.4.0.fair
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Makefile +418 -126
- data/include/grpc/grpc.h +15 -69
- data/include/grpc/grpc_security.h +1 -1
- data/include/grpc/impl/codegen/compression_types.h +3 -4
- data/include/grpc/impl/codegen/gpr_types.h +0 -1
- data/include/grpc/impl/codegen/grpc_types.h +69 -3
- data/include/grpc/impl/codegen/port_platform.h +6 -0
- data/include/grpc/impl/codegen/slice.h +2 -1
- data/include/grpc/load_reporting.h +6 -6
- data/include/grpc/slice.h +25 -3
- data/include/grpc/slice_buffer.h +4 -0
- data/src/core/ext/census/context.c +1 -1
- data/src/core/ext/census/resource.c +3 -1
- data/src/core/ext/filters/client_channel/channel_connectivity.c +1 -1
- data/src/core/ext/filters/client_channel/client_channel.c +158 -100
- data/src/core/ext/filters/client_channel/client_channel_plugin.c +3 -2
- data/src/core/ext/filters/client_channel/lb_policy.c +2 -1
- data/src/core/ext/filters/client_channel/lb_policy.h +5 -6
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.c +153 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h +42 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.c +344 -88
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.c +133 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +65 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.c +47 -5
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +6 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +19 -8
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +63 -34
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.c +2 -1
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.c +13 -12
- data/src/core/ext/filters/client_channel/lb_policy_factory.c +28 -5
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +18 -4
- data/src/core/ext/filters/client_channel/parse_address.c +37 -7
- data/src/core/ext/filters/client_channel/parse_address.h +11 -8
- data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.c +3 -3
- data/src/core/ext/filters/client_channel/subchannel.c +19 -16
- data/src/core/ext/filters/client_channel/subchannel.h +1 -0
- data/src/core/ext/filters/client_channel/uri_parser.c +36 -22
- data/src/core/ext/filters/client_channel/uri_parser.h +1 -1
- data/src/core/{lib/channel → ext/filters/deadline}/deadline_filter.c +42 -17
- data/src/core/{lib/channel → ext/filters/deadline}/deadline_filter.h +8 -9
- data/src/core/{lib/channel → ext/filters/http/client}/http_client_filter.c +19 -11
- data/src/core/{lib/channel → ext/filters/http/client}/http_client_filter.h +3 -6
- data/src/core/ext/filters/http/http_filters_plugin.c +104 -0
- data/src/core/{lib/channel/compress_filter.c → ext/filters/http/message_compress/message_compress_filter.c} +124 -23
- data/src/core/{lib/channel/compress_filter.h → ext/filters/http/message_compress/message_compress_filter.h} +5 -6
- data/src/core/{lib/channel → ext/filters/http/server}/http_server_filter.c +4 -6
- data/src/core/{lib/channel → ext/filters/http/server}/http_server_filter.h +3 -3
- data/src/core/ext/filters/load_reporting/load_reporting.c +2 -25
- data/src/core/ext/filters/load_reporting/load_reporting_filter.c +26 -1
- data/src/core/ext/filters/max_age/max_age_filter.c +14 -14
- data/src/core/{lib/channel → ext/filters/message_size}/message_size_filter.c +91 -47
- data/src/core/{lib/channel → ext/filters/message_size}/message_size_filter.h +3 -3
- data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +1 -1
- data/src/core/ext/transport/chttp2/server/chttp2_server.c +2 -2
- data/src/core/ext/transport/chttp2/transport/bin_decoder.c +2 -2
- data/src/core/ext/transport/chttp2/transport/bin_encoder.c +3 -3
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +296 -172
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -2
- data/src/core/ext/transport/chttp2/transport/frame_data.c +203 -164
- data/src/core/ext/transport/chttp2/transport/frame_data.h +8 -14
- data/src/core/ext/transport/chttp2/transport/frame_goaway.c +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_ping.c +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_settings.c +5 -5
- data/src/core/ext/transport/chttp2/transport/frame_window_update.c +1 -1
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +4 -4
- data/src/core/ext/transport/chttp2/transport/hpack_parser.c +2 -4
- data/src/core/ext/transport/chttp2/transport/hpack_table.c +4 -3
- data/src/core/ext/transport/chttp2/transport/internal.h +50 -33
- data/src/core/ext/transport/chttp2/transport/parsing.c +10 -11
- data/src/core/ext/transport/chttp2/transport/writing.c +32 -13
- data/src/core/lib/channel/channel_args.c +28 -9
- data/src/core/lib/channel/channel_args.h +5 -1
- data/src/core/lib/channel/channel_stack.c +1 -1
- data/src/core/lib/channel/channel_stack.h +2 -2
- data/src/core/lib/channel/channel_stack_builder.c +13 -1
- data/src/core/lib/channel/channel_stack_builder.h +5 -1
- data/src/core/lib/channel/connected_channel.c +3 -1
- data/src/core/lib/channel/context.h +2 -2
- data/src/core/lib/compression/message_compress.c +2 -2
- data/src/core/lib/debug/trace.c +13 -6
- data/src/core/lib/debug/trace.h +27 -1
- data/src/core/lib/http/httpcli.c +1 -1
- data/src/core/lib/http/httpcli_security_connector.c +6 -10
- data/src/core/lib/http/parser.c +2 -2
- data/src/core/lib/http/parser.h +2 -1
- data/src/core/lib/iomgr/combiner.c +6 -6
- data/src/core/lib/iomgr/combiner.h +2 -1
- data/src/core/lib/iomgr/error.c +12 -5
- data/src/core/lib/iomgr/error.h +13 -13
- data/src/core/lib/iomgr/ev_epoll1_linux.c +984 -0
- data/src/core/lib/iomgr/ev_epoll1_linux.h +44 -0
- data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.c +2146 -0
- data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.h +43 -0
- data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.c +1337 -0
- data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.h +43 -0
- data/src/core/lib/iomgr/ev_epollex_linux.c +1511 -0
- data/src/core/lib/iomgr/ev_epollex_linux.h +43 -0
- data/src/core/lib/iomgr/{ev_epoll_linux.c → ev_epollsig_linux.c} +24 -31
- data/src/core/lib/iomgr/{ev_epoll_linux.h → ev_epollsig_linux.h} +4 -4
- data/src/core/lib/iomgr/ev_poll_posix.c +12 -27
- data/src/core/lib/iomgr/ev_poll_posix.h +2 -2
- data/src/core/lib/iomgr/ev_posix.c +22 -8
- data/src/core/lib/iomgr/ev_posix.h +4 -3
- data/src/core/lib/iomgr/exec_ctx.c +5 -0
- data/src/core/lib/iomgr/exec_ctx.h +2 -0
- data/src/core/lib/iomgr/iomgr.c +4 -0
- data/src/core/lib/iomgr/iomgr.h +3 -0
- data/src/core/lib/iomgr/is_epollexclusive_available.c +116 -0
- data/src/core/lib/iomgr/is_epollexclusive_available.h +41 -0
- data/src/core/lib/iomgr/lockfree_event.c +16 -0
- data/src/core/lib/iomgr/pollset.h +2 -5
- data/src/core/lib/iomgr/pollset_uv.c +1 -1
- data/src/core/lib/iomgr/pollset_windows.c +3 -3
- data/src/core/lib/iomgr/resource_quota.c +9 -8
- data/src/core/lib/iomgr/resource_quota.h +2 -1
- data/src/core/lib/iomgr/sockaddr_utils.h +1 -1
- data/src/core/lib/iomgr/socket_mutator.h +2 -0
- data/src/core/lib/iomgr/sys_epoll_wrapper.h +43 -0
- data/src/core/lib/iomgr/tcp_client_posix.c +6 -6
- data/src/core/lib/iomgr/tcp_client_uv.c +3 -3
- data/src/core/lib/iomgr/tcp_posix.c +7 -7
- data/src/core/lib/iomgr/tcp_posix.h +2 -1
- data/src/core/lib/iomgr/tcp_server_posix.c +1 -1
- data/src/core/lib/iomgr/tcp_uv.c +6 -6
- data/src/core/lib/iomgr/tcp_uv.h +2 -1
- data/src/core/lib/iomgr/tcp_windows.c +1 -1
- data/src/core/lib/iomgr/timer_generic.c +24 -25
- data/src/core/lib/iomgr/timer_manager.c +276 -0
- data/src/core/lib/iomgr/timer_manager.h +52 -0
- data/src/core/lib/iomgr/timer_uv.c +6 -0
- data/src/core/lib/iomgr/udp_server.c +42 -9
- data/src/core/lib/iomgr/udp_server.h +3 -1
- data/src/core/lib/security/credentials/credentials.c +0 -1
- data/src/core/lib/security/credentials/fake/fake_credentials.c +23 -0
- data/src/core/lib/security/credentials/fake/fake_credentials.h +12 -9
- data/src/core/lib/security/credentials/google_default/google_default_credentials.c +1 -1
- data/src/core/lib/security/credentials/jwt/jwt_credentials.c +1 -1
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +1 -1
- data/src/core/lib/security/credentials/ssl/ssl_credentials.c +24 -53
- data/src/core/lib/security/transport/client_auth_filter.c +9 -3
- data/src/core/lib/security/transport/secure_endpoint.c +7 -7
- data/src/core/lib/security/transport/secure_endpoint.h +1 -1
- data/src/core/lib/security/transport/security_connector.c +32 -51
- data/src/core/lib/security/transport/security_connector.h +10 -14
- data/src/core/lib/slice/b64.c +1 -1
- data/src/core/lib/slice/percent_encoding.c +3 -3
- data/src/core/lib/slice/slice.c +66 -33
- data/src/core/lib/slice/slice_buffer.c +25 -6
- data/src/core/lib/slice/slice_hash_table.c +33 -35
- data/src/core/lib/slice/slice_hash_table.h +7 -12
- data/src/core/lib/support/atomic.h +45 -0
- data/src/core/lib/support/atomic_with_atm.h +70 -0
- data/src/core/lib/support/atomic_with_std.h +48 -0
- data/src/core/lib/support/avl.c +14 -14
- data/src/core/lib/support/memory.h +74 -0
- data/src/core/lib/support/mpscq.c +12 -1
- data/src/core/lib/support/mpscq.h +4 -0
- data/src/core/lib/support/stack_lockfree.c +3 -36
- data/src/core/lib/support/time_posix.c +8 -0
- data/src/core/lib/support/tmpfile_posix.c +10 -10
- data/src/core/lib/surface/alarm.c +3 -1
- data/src/core/lib/surface/api_trace.c +2 -1
- data/src/core/lib/surface/api_trace.h +2 -2
- data/src/core/lib/surface/byte_buffer_reader.c +1 -1
- data/src/core/lib/surface/call.c +65 -22
- data/src/core/lib/surface/call.h +4 -2
- data/src/core/lib/surface/channel_init.c +2 -19
- data/src/core/lib/surface/channel_stack_type.c +18 -0
- data/src/core/lib/surface/channel_stack_type.h +2 -0
- data/src/core/lib/surface/completion_queue.c +249 -83
- data/src/core/lib/surface/completion_queue.h +18 -13
- data/src/core/lib/surface/completion_queue_factory.c +24 -9
- data/src/core/lib/surface/init.c +1 -52
- data/src/core/lib/surface/{lame_client.c → lame_client.cc} +37 -26
- data/src/core/lib/surface/server.c +50 -27
- data/src/core/lib/surface/server.h +2 -1
- data/src/core/lib/surface/version.c +2 -2
- data/src/core/lib/transport/bdp_estimator.c +20 -9
- data/src/core/lib/transport/bdp_estimator.h +5 -1
- data/src/core/lib/transport/byte_stream.c +23 -9
- data/src/core/lib/transport/byte_stream.h +15 -6
- data/src/core/lib/transport/connectivity_state.c +6 -6
- data/src/core/lib/transport/connectivity_state.h +2 -1
- data/src/core/lib/transport/service_config.c +6 -13
- data/src/core/lib/transport/service_config.h +2 -2
- data/src/core/lib/transport/static_metadata.c +403 -389
- data/src/core/lib/transport/static_metadata.h +127 -114
- data/src/core/plugin_registry/grpc_plugin_registry.c +12 -0
- data/src/core/tsi/fake_transport_security.c +5 -4
- data/src/core/tsi/ssl_transport_security.c +71 -82
- data/src/core/tsi/ssl_transport_security.h +39 -61
- data/src/core/tsi/transport_security.c +83 -2
- data/src/core/tsi/transport_security.h +27 -2
- data/src/core/tsi/transport_security_adapter.c +236 -0
- data/src/core/tsi/transport_security_adapter.h +62 -0
- data/src/core/tsi/transport_security_interface.h +179 -66
- data/src/ruby/ext/grpc/extconf.rb +2 -1
- data/src/ruby/ext/grpc/rb_byte_buffer.c +8 -6
- data/src/ruby/ext/grpc/rb_call.c +56 -48
- data/src/ruby/ext/grpc/rb_call.h +3 -4
- data/src/ruby/ext/grpc/rb_call_credentials.c +23 -22
- data/src/ruby/ext/grpc/rb_channel.c +45 -29
- data/src/ruby/ext/grpc/rb_channel_args.c +11 -9
- data/src/ruby/ext/grpc/rb_channel_credentials.c +16 -12
- data/src/ruby/ext/grpc/rb_completion_queue.c +7 -9
- data/src/ruby/ext/grpc/rb_compression_options.c +7 -6
- data/src/ruby/ext/grpc/rb_event_thread.c +10 -12
- data/src/ruby/ext/grpc/rb_event_thread.h +1 -2
- data/src/ruby/ext/grpc/rb_grpc.c +11 -15
- data/src/ruby/ext/grpc/rb_grpc.h +2 -2
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +14 -6
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +22 -10
- data/src/ruby/ext/grpc/rb_server.c +26 -28
- data/src/ruby/lib/grpc/version.rb +1 -1
- metadata +40 -18
- data/src/ruby/lib/grpc/grpc_c.bundle +0 -0
- data/src/ruby/lib/grpc/grpc_c.so +0 -0
@@ -75,7 +75,7 @@ typedef struct {
|
|
75
75
|
gpr_refcount ref;
|
76
76
|
} secure_endpoint;
|
77
77
|
|
78
|
-
|
78
|
+
grpc_tracer_flag grpc_trace_secure_endpoint = GRPC_TRACER_INITIALIZER(false);
|
79
79
|
|
80
80
|
static void destroy(grpc_exec_ctx *exec_ctx, secure_endpoint *secure_ep) {
|
81
81
|
secure_endpoint *ep = secure_ep;
|
@@ -130,14 +130,14 @@ static void secure_endpoint_ref(secure_endpoint *ep) { gpr_ref(&ep->ref); }
|
|
130
130
|
static void flush_read_staging_buffer(secure_endpoint *ep, uint8_t **cur,
|
131
131
|
uint8_t **end) {
|
132
132
|
grpc_slice_buffer_add(ep->read_buffer, ep->read_staging_buffer);
|
133
|
-
ep->read_staging_buffer =
|
133
|
+
ep->read_staging_buffer = GRPC_SLICE_MALLOC(STAGING_BUFFER_SIZE);
|
134
134
|
*cur = GRPC_SLICE_START_PTR(ep->read_staging_buffer);
|
135
135
|
*end = GRPC_SLICE_END_PTR(ep->read_staging_buffer);
|
136
136
|
}
|
137
137
|
|
138
138
|
static void call_read_cb(grpc_exec_ctx *exec_ctx, secure_endpoint *ep,
|
139
139
|
grpc_error *error) {
|
140
|
-
if (grpc_trace_secure_endpoint) {
|
140
|
+
if (GRPC_TRACER_ON(grpc_trace_secure_endpoint)) {
|
141
141
|
size_t i;
|
142
142
|
for (i = 0; i < ep->read_buffer->count; i++) {
|
143
143
|
char *data = grpc_dump_slice(ep->read_buffer->slices[i],
|
@@ -252,7 +252,7 @@ static void endpoint_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *secure_ep,
|
|
252
252
|
static void flush_write_staging_buffer(secure_endpoint *ep, uint8_t **cur,
|
253
253
|
uint8_t **end) {
|
254
254
|
grpc_slice_buffer_add(&ep->output_buffer, ep->write_staging_buffer);
|
255
|
-
ep->write_staging_buffer =
|
255
|
+
ep->write_staging_buffer = GRPC_SLICE_MALLOC(STAGING_BUFFER_SIZE);
|
256
256
|
*cur = GRPC_SLICE_START_PTR(ep->write_staging_buffer);
|
257
257
|
*end = GRPC_SLICE_END_PTR(ep->write_staging_buffer);
|
258
258
|
}
|
@@ -269,7 +269,7 @@ static void endpoint_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *secure_ep,
|
|
269
269
|
|
270
270
|
grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &ep->output_buffer);
|
271
271
|
|
272
|
-
if (grpc_trace_secure_endpoint) {
|
272
|
+
if (GRPC_TRACER_ON(grpc_trace_secure_endpoint)) {
|
273
273
|
for (i = 0; i < slices->count; i++) {
|
274
274
|
char *data =
|
275
275
|
grpc_dump_slice(slices->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII);
|
@@ -415,8 +415,8 @@ grpc_endpoint *grpc_secure_endpoint_create(
|
|
415
415
|
grpc_slice_buffer_add(&ep->leftover_bytes,
|
416
416
|
grpc_slice_ref_internal(leftover_slices[i]));
|
417
417
|
}
|
418
|
-
ep->write_staging_buffer =
|
419
|
-
ep->read_staging_buffer =
|
418
|
+
ep->write_staging_buffer = GRPC_SLICE_MALLOC(STAGING_BUFFER_SIZE);
|
419
|
+
ep->read_staging_buffer = GRPC_SLICE_MALLOC(STAGING_BUFFER_SIZE);
|
420
420
|
grpc_slice_buffer_init(&ep->output_buffer);
|
421
421
|
grpc_slice_buffer_init(&ep->source_buffer);
|
422
422
|
ep->read_buffer = NULL;
|
@@ -39,7 +39,7 @@
|
|
39
39
|
|
40
40
|
struct tsi_frame_protector;
|
41
41
|
|
42
|
-
extern
|
42
|
+
extern grpc_tracer_flag grpc_trace_secure_endpoint;
|
43
43
|
|
44
44
|
/* Takes ownership of protector and to_wrap, and refs leftover_slices. */
|
45
45
|
grpc_endpoint *grpc_secure_endpoint_create(
|
@@ -78,9 +78,8 @@ void grpc_set_ssl_roots_override_callback(grpc_ssl_roots_override_callback cb) {
|
|
78
78
|
|
79
79
|
/* Defines the cipher suites that we accept by default. All these cipher suites
|
80
80
|
are compliant with HTTP2. */
|
81
|
-
#define GRPC_SSL_CIPHER_SUITES
|
82
|
-
"ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-
|
83
|
-
"SHA384:ECDHE-RSA-AES256-GCM-SHA384"
|
81
|
+
#define GRPC_SSL_CIPHER_SUITES \
|
82
|
+
"ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384"
|
84
83
|
|
85
84
|
static gpr_once cipher_suites_once = GPR_ONCE_INIT;
|
86
85
|
static const char *cipher_suites = NULL;
|
@@ -423,12 +422,8 @@ grpc_channel_security_connector *grpc_fake_channel_security_connector_create(
|
|
423
422
|
c->base.check_call_host = fake_channel_check_call_host;
|
424
423
|
c->base.add_handshakers = fake_channel_add_handshakers;
|
425
424
|
c->target = gpr_strdup(target);
|
426
|
-
const
|
427
|
-
|
428
|
-
if (expected_target_arg != NULL) {
|
429
|
-
GPR_ASSERT(expected_target_arg->type == GRPC_ARG_STRING);
|
430
|
-
c->expected_targets = gpr_strdup(expected_target_arg->value.string);
|
431
|
-
}
|
425
|
+
const char *expected_targets = grpc_fake_transport_get_expected_targets(args);
|
426
|
+
c->expected_targets = gpr_strdup(expected_targets);
|
432
427
|
c->is_lb_channel = (grpc_lb_targets_info_find_in_args(args) != NULL);
|
433
428
|
return &c->base;
|
434
429
|
}
|
@@ -699,6 +694,7 @@ static grpc_security_connector_vtable ssl_channel_vtable = {
|
|
699
694
|
static grpc_security_connector_vtable ssl_server_vtable = {
|
700
695
|
ssl_server_destroy, ssl_server_check_peer};
|
701
696
|
|
697
|
+
/* returns a NULL terminated slice. */
|
702
698
|
static grpc_slice compute_default_pem_root_certs_once(void) {
|
703
699
|
grpc_slice result = grpc_empty_slice();
|
704
700
|
|
@@ -707,7 +703,7 @@ static grpc_slice compute_default_pem_root_certs_once(void) {
|
|
707
703
|
gpr_getenv(GRPC_DEFAULT_SSL_ROOTS_FILE_PATH_ENV_VAR);
|
708
704
|
if (default_root_certs_path != NULL) {
|
709
705
|
GRPC_LOG_IF_ERROR("load_file",
|
710
|
-
grpc_load_file(default_root_certs_path,
|
706
|
+
grpc_load_file(default_root_certs_path, 1, &result));
|
711
707
|
gpr_free(default_root_certs_path);
|
712
708
|
}
|
713
709
|
|
@@ -718,15 +714,18 @@ static grpc_slice compute_default_pem_root_certs_once(void) {
|
|
718
714
|
ovrd_res = ssl_roots_override_cb(&pem_root_certs);
|
719
715
|
if (ovrd_res == GRPC_SSL_ROOTS_OVERRIDE_OK) {
|
720
716
|
GPR_ASSERT(pem_root_certs != NULL);
|
721
|
-
result =
|
717
|
+
result = grpc_slice_from_copied_buffer(
|
718
|
+
pem_root_certs,
|
719
|
+
strlen(pem_root_certs) + 1); // NULL terminator.
|
722
720
|
}
|
721
|
+
gpr_free(pem_root_certs);
|
723
722
|
}
|
724
723
|
|
725
724
|
/* Fall back to installed certs if needed. */
|
726
725
|
if (GRPC_SLICE_IS_EMPTY(result) &&
|
727
726
|
ovrd_res != GRPC_SSL_ROOTS_OVERRIDE_FAIL_PERMANENTLY) {
|
728
727
|
GRPC_LOG_IF_ERROR("load_file",
|
729
|
-
grpc_load_file(installed_roots_path,
|
728
|
+
grpc_load_file(installed_roots_path, 1, &result));
|
730
729
|
}
|
731
730
|
return result;
|
732
731
|
}
|
@@ -766,13 +765,14 @@ get_tsi_client_certificate_request_type(
|
|
766
765
|
}
|
767
766
|
}
|
768
767
|
|
769
|
-
|
768
|
+
const char *grpc_get_default_ssl_roots(void) {
|
770
769
|
/* TODO(jboeuf@google.com): Maybe revisit the approach which consists in
|
771
770
|
loading all the roots once for the lifetime of the process. */
|
772
771
|
static gpr_once once = GPR_ONCE_INIT;
|
773
772
|
gpr_once_init(&once, init_default_pem_root_certs);
|
774
|
-
|
775
|
-
|
773
|
+
return GRPC_SLICE_IS_EMPTY(default_pem_root_certs)
|
774
|
+
? NULL
|
775
|
+
: (const char *)GRPC_SLICE_START_PTR(default_pem_root_certs);
|
776
776
|
}
|
777
777
|
|
778
778
|
grpc_security_status grpc_ssl_channel_security_connector_create(
|
@@ -780,22 +780,16 @@ grpc_security_status grpc_ssl_channel_security_connector_create(
|
|
780
780
|
const grpc_ssl_config *config, const char *target_name,
|
781
781
|
const char *overridden_target_name, grpc_channel_security_connector **sc) {
|
782
782
|
size_t num_alpn_protocols = grpc_chttp2_num_alpn_versions();
|
783
|
-
const
|
783
|
+
const char **alpn_protocol_strings =
|
784
784
|
gpr_malloc(sizeof(const char *) * num_alpn_protocols);
|
785
|
-
unsigned char *alpn_protocol_string_lengths =
|
786
|
-
gpr_malloc(sizeof(unsigned char) * num_alpn_protocols);
|
787
785
|
tsi_result result = TSI_OK;
|
788
786
|
grpc_ssl_channel_security_connector *c;
|
789
787
|
size_t i;
|
790
|
-
const
|
791
|
-
size_t pem_root_certs_size;
|
788
|
+
const char *pem_root_certs;
|
792
789
|
char *port;
|
793
790
|
|
794
791
|
for (i = 0; i < num_alpn_protocols; i++) {
|
795
|
-
alpn_protocol_strings[i] =
|
796
|
-
(const unsigned char *)grpc_chttp2_get_alpn_version_index(i);
|
797
|
-
alpn_protocol_string_lengths[i] =
|
798
|
-
(unsigned char)strlen(grpc_chttp2_get_alpn_version_index(i));
|
792
|
+
alpn_protocol_strings[i] = grpc_chttp2_get_alpn_version_index(i);
|
799
793
|
}
|
800
794
|
|
801
795
|
if (config == NULL || target_name == NULL) {
|
@@ -803,14 +797,13 @@ grpc_security_status grpc_ssl_channel_security_connector_create(
|
|
803
797
|
goto error;
|
804
798
|
}
|
805
799
|
if (config->pem_root_certs == NULL) {
|
806
|
-
|
807
|
-
if (pem_root_certs == NULL
|
800
|
+
pem_root_certs = grpc_get_default_ssl_roots();
|
801
|
+
if (pem_root_certs == NULL) {
|
808
802
|
gpr_log(GPR_ERROR, "Could not get default pem root certs.");
|
809
803
|
goto error;
|
810
804
|
}
|
811
805
|
} else {
|
812
806
|
pem_root_certs = config->pem_root_certs;
|
813
|
-
pem_root_certs_size = config->pem_root_certs_size;
|
814
807
|
}
|
815
808
|
|
816
809
|
c = gpr_zalloc(sizeof(grpc_ssl_channel_security_connector));
|
@@ -827,11 +820,12 @@ grpc_security_status grpc_ssl_channel_security_connector_create(
|
|
827
820
|
if (overridden_target_name != NULL) {
|
828
821
|
c->overridden_target_name = gpr_strdup(overridden_target_name);
|
829
822
|
}
|
823
|
+
|
824
|
+
bool has_key_cert_pair = config->pem_key_cert_pair.private_key != NULL &&
|
825
|
+
config->pem_key_cert_pair.cert_chain != NULL;
|
830
826
|
result = tsi_create_ssl_client_handshaker_factory(
|
831
|
-
config->
|
832
|
-
|
833
|
-
pem_root_certs_size, ssl_cipher_suites(), alpn_protocol_strings,
|
834
|
-
alpn_protocol_string_lengths, (uint16_t)num_alpn_protocols,
|
827
|
+
has_key_cert_pair ? &config->pem_key_cert_pair : NULL, pem_root_certs,
|
828
|
+
ssl_cipher_suites(), alpn_protocol_strings, (uint16_t)num_alpn_protocols,
|
835
829
|
&c->handshaker_factory);
|
836
830
|
if (result != TSI_OK) {
|
837
831
|
gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.",
|
@@ -842,12 +836,10 @@ grpc_security_status grpc_ssl_channel_security_connector_create(
|
|
842
836
|
}
|
843
837
|
*sc = &c->base;
|
844
838
|
gpr_free((void *)alpn_protocol_strings);
|
845
|
-
gpr_free(alpn_protocol_string_lengths);
|
846
839
|
return GRPC_SECURITY_OK;
|
847
840
|
|
848
841
|
error:
|
849
842
|
gpr_free((void *)alpn_protocol_strings);
|
850
|
-
gpr_free(alpn_protocol_string_lengths);
|
851
843
|
return GRPC_SECURITY_ERROR;
|
852
844
|
}
|
853
845
|
|
@@ -855,19 +847,14 @@ grpc_security_status grpc_ssl_server_security_connector_create(
|
|
855
847
|
grpc_exec_ctx *exec_ctx, const grpc_ssl_server_config *config,
|
856
848
|
grpc_server_security_connector **sc) {
|
857
849
|
size_t num_alpn_protocols = grpc_chttp2_num_alpn_versions();
|
858
|
-
const
|
850
|
+
const char **alpn_protocol_strings =
|
859
851
|
gpr_malloc(sizeof(const char *) * num_alpn_protocols);
|
860
|
-
unsigned char *alpn_protocol_string_lengths =
|
861
|
-
gpr_malloc(sizeof(unsigned char) * num_alpn_protocols);
|
862
852
|
tsi_result result = TSI_OK;
|
863
853
|
grpc_ssl_server_security_connector *c;
|
864
854
|
size_t i;
|
865
855
|
|
866
856
|
for (i = 0; i < num_alpn_protocols; i++) {
|
867
|
-
alpn_protocol_strings[i] =
|
868
|
-
(const unsigned char *)grpc_chttp2_get_alpn_version_index(i);
|
869
|
-
alpn_protocol_string_lengths[i] =
|
870
|
-
(unsigned char)strlen(grpc_chttp2_get_alpn_version_index(i));
|
857
|
+
alpn_protocol_strings[i] = grpc_chttp2_get_alpn_version_index(i);
|
871
858
|
}
|
872
859
|
|
873
860
|
if (config == NULL || config->num_key_cert_pairs == 0) {
|
@@ -880,15 +867,11 @@ grpc_security_status grpc_ssl_server_security_connector_create(
|
|
880
867
|
c->base.base.url_scheme = GRPC_SSL_URL_SCHEME;
|
881
868
|
c->base.base.vtable = &ssl_server_vtable;
|
882
869
|
result = tsi_create_ssl_server_handshaker_factory_ex(
|
883
|
-
|
884
|
-
config->
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
get_tsi_client_certificate_request_type(
|
889
|
-
config->client_certificate_request),
|
890
|
-
ssl_cipher_suites(), alpn_protocol_strings, alpn_protocol_string_lengths,
|
891
|
-
(uint16_t)num_alpn_protocols, &c->handshaker_factory);
|
870
|
+
config->pem_key_cert_pairs, config->num_key_cert_pairs,
|
871
|
+
config->pem_root_certs, get_tsi_client_certificate_request_type(
|
872
|
+
config->client_certificate_request),
|
873
|
+
ssl_cipher_suites(), alpn_protocol_strings, (uint16_t)num_alpn_protocols,
|
874
|
+
&c->handshaker_factory);
|
892
875
|
if (result != TSI_OK) {
|
893
876
|
gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.",
|
894
877
|
tsi_result_to_string(result));
|
@@ -899,11 +882,9 @@ grpc_security_status grpc_ssl_server_security_connector_create(
|
|
899
882
|
c->base.add_handshakers = ssl_server_add_handshakers;
|
900
883
|
*sc = &c->base;
|
901
884
|
gpr_free((void *)alpn_protocol_strings);
|
902
|
-
gpr_free(alpn_protocol_string_lengths);
|
903
885
|
return GRPC_SECURITY_OK;
|
904
886
|
|
905
887
|
error:
|
906
888
|
gpr_free((void *)alpn_protocol_strings);
|
907
|
-
gpr_free(alpn_protocol_string_lengths);
|
908
889
|
return GRPC_SECURITY_ERROR;
|
909
890
|
}
|
@@ -34,11 +34,14 @@
|
|
34
34
|
#ifndef GRPC_CORE_LIB_SECURITY_TRANSPORT_SECURITY_CONNECTOR_H
|
35
35
|
#define GRPC_CORE_LIB_SECURITY_TRANSPORT_SECURITY_CONNECTOR_H
|
36
36
|
|
37
|
+
#include <stdbool.h>
|
38
|
+
|
37
39
|
#include <grpc/grpc_security.h>
|
38
40
|
|
39
41
|
#include "src/core/lib/channel/handshaker.h"
|
40
42
|
#include "src/core/lib/iomgr/endpoint.h"
|
41
43
|
#include "src/core/lib/iomgr/tcp_server.h"
|
44
|
+
#include "src/core/tsi/ssl_transport_security.h"
|
42
45
|
#include "src/core/tsi/transport_security_interface.h"
|
43
46
|
|
44
47
|
/* --- status enum. --- */
|
@@ -184,13 +187,10 @@ grpc_server_security_connector *grpc_fake_server_security_connector_create(
|
|
184
187
|
void);
|
185
188
|
|
186
189
|
/* Config for ssl clients. */
|
190
|
+
|
187
191
|
typedef struct {
|
188
|
-
|
189
|
-
|
190
|
-
unsigned char *pem_cert_chain;
|
191
|
-
size_t pem_cert_chain_size;
|
192
|
-
unsigned char *pem_root_certs;
|
193
|
-
size_t pem_root_certs_size;
|
192
|
+
tsi_ssl_pem_key_cert_pair pem_key_cert_pair;
|
193
|
+
char *pem_root_certs;
|
194
194
|
} grpc_ssl_config;
|
195
195
|
|
196
196
|
/* Creates an SSL channel_security_connector.
|
@@ -211,21 +211,17 @@ grpc_security_status grpc_ssl_channel_security_connector_create(
|
|
211
211
|
const grpc_ssl_config *config, const char *target_name,
|
212
212
|
const char *overridden_target_name, grpc_channel_security_connector **sc);
|
213
213
|
|
214
|
-
/* Gets the default ssl roots. */
|
215
|
-
|
214
|
+
/* Gets the default ssl roots. Returns NULL if not found. */
|
215
|
+
const char *grpc_get_default_ssl_roots(void);
|
216
216
|
|
217
217
|
/* Exposed for TESTING ONLY!. */
|
218
218
|
grpc_slice grpc_get_default_ssl_roots_for_testing(void);
|
219
219
|
|
220
220
|
/* Config for ssl servers. */
|
221
221
|
typedef struct {
|
222
|
-
|
223
|
-
size_t *pem_private_keys_sizes;
|
224
|
-
unsigned char **pem_cert_chains;
|
225
|
-
size_t *pem_cert_chains_sizes;
|
222
|
+
tsi_ssl_pem_key_cert_pair *pem_key_cert_pairs;
|
226
223
|
size_t num_key_cert_pairs;
|
227
|
-
|
228
|
-
size_t pem_root_certs_size;
|
224
|
+
char *pem_root_certs;
|
229
225
|
grpc_ssl_client_certificate_request_type client_certificate_request;
|
230
226
|
} grpc_ssl_server_config;
|
231
227
|
|
data/src/core/lib/slice/b64.c
CHANGED
@@ -202,7 +202,7 @@ static int decode_group(const unsigned char *codes, size_t num_codes,
|
|
202
202
|
|
203
203
|
grpc_slice grpc_base64_decode_with_len(grpc_exec_ctx *exec_ctx, const char *b64,
|
204
204
|
size_t b64_len, int url_safe) {
|
205
|
-
grpc_slice result =
|
205
|
+
grpc_slice result = GRPC_SLICE_MALLOC(b64_len);
|
206
206
|
unsigned char *current = GRPC_SLICE_START_PTR(result);
|
207
207
|
size_t result_size = 0;
|
208
208
|
unsigned char codes[4];
|
@@ -71,7 +71,7 @@ grpc_slice grpc_percent_encode_slice(grpc_slice slice,
|
|
71
71
|
return grpc_slice_ref_internal(slice);
|
72
72
|
}
|
73
73
|
// second pass: actually encode
|
74
|
-
grpc_slice out =
|
74
|
+
grpc_slice out = GRPC_SLICE_MALLOC(output_length);
|
75
75
|
uint8_t *q = GRPC_SLICE_START_PTR(out);
|
76
76
|
for (p = slice_start; p < slice_end; p++) {
|
77
77
|
if (is_unreserved_character(*p, unreserved_bytes)) {
|
@@ -125,7 +125,7 @@ bool grpc_strict_percent_decode_slice(grpc_slice slice_in,
|
|
125
125
|
return true;
|
126
126
|
}
|
127
127
|
p = GRPC_SLICE_START_PTR(slice_in);
|
128
|
-
*slice_out =
|
128
|
+
*slice_out = GRPC_SLICE_MALLOC(out_length);
|
129
129
|
uint8_t *q = GRPC_SLICE_START_PTR(*slice_out);
|
130
130
|
while (p != in_end) {
|
131
131
|
if (*p == '%') {
|
@@ -163,7 +163,7 @@ grpc_slice grpc_permissive_percent_decode_slice(grpc_slice slice_in) {
|
|
163
163
|
return grpc_slice_ref_internal(slice_in);
|
164
164
|
}
|
165
165
|
p = GRPC_SLICE_START_PTR(slice_in);
|
166
|
-
grpc_slice out =
|
166
|
+
grpc_slice out = GRPC_SLICE_MALLOC(out_length);
|
167
167
|
uint8_t *q = GRPC_SLICE_START_PTR(out);
|
168
168
|
while (p != in_end) {
|
169
169
|
if (*p == '%') {
|
data/src/core/lib/slice/slice.c
CHANGED
@@ -55,6 +55,13 @@ grpc_slice grpc_empty_slice(void) {
|
|
55
55
|
return out;
|
56
56
|
}
|
57
57
|
|
58
|
+
grpc_slice grpc_slice_copy(grpc_slice s) {
|
59
|
+
grpc_slice out = GRPC_SLICE_MALLOC(GRPC_SLICE_LENGTH(s));
|
60
|
+
memcpy(GRPC_SLICE_START_PTR(out), GRPC_SLICE_START_PTR(s),
|
61
|
+
GRPC_SLICE_LENGTH(s));
|
62
|
+
return out;
|
63
|
+
}
|
64
|
+
|
58
65
|
grpc_slice grpc_slice_ref_internal(grpc_slice slice) {
|
59
66
|
if (slice.refcount) {
|
60
67
|
slice.refcount->vtable->ref(slice.refcount);
|
@@ -198,7 +205,7 @@ grpc_slice grpc_slice_new_with_len(void *p, size_t len,
|
|
198
205
|
|
199
206
|
grpc_slice grpc_slice_from_copied_buffer(const char *source, size_t length) {
|
200
207
|
if (length == 0) return grpc_empty_slice();
|
201
|
-
grpc_slice slice =
|
208
|
+
grpc_slice slice = GRPC_SLICE_MALLOC(length);
|
202
209
|
memcpy(GRPC_SLICE_START_PTR(slice), source, length);
|
203
210
|
return slice;
|
204
211
|
}
|
@@ -228,35 +235,42 @@ static const grpc_slice_refcount_vtable malloc_vtable = {
|
|
228
235
|
malloc_ref, malloc_unref, grpc_slice_default_eq_impl,
|
229
236
|
grpc_slice_default_hash_impl};
|
230
237
|
|
238
|
+
grpc_slice grpc_slice_malloc_large(size_t length) {
|
239
|
+
grpc_slice slice;
|
240
|
+
|
241
|
+
/* Memory layout used by the slice created here:
|
242
|
+
|
243
|
+
+-----------+----------------------------------------------------------+
|
244
|
+
| refcount | bytes |
|
245
|
+
+-----------+----------------------------------------------------------+
|
246
|
+
|
247
|
+
refcount is a malloc_refcount
|
248
|
+
bytes is an array of bytes of the requested length
|
249
|
+
Both parts are placed in the same allocation returned from gpr_malloc */
|
250
|
+
malloc_refcount *rc = gpr_malloc(sizeof(malloc_refcount) + length);
|
251
|
+
|
252
|
+
/* Initial refcount on rc is 1 - and it's up to the caller to release
|
253
|
+
this reference. */
|
254
|
+
gpr_ref_init(&rc->refs, 1);
|
255
|
+
|
256
|
+
rc->base.vtable = &malloc_vtable;
|
257
|
+
rc->base.sub_refcount = &rc->base;
|
258
|
+
|
259
|
+
/* Build up the slice to be returned. */
|
260
|
+
/* The slices refcount points back to the allocated block. */
|
261
|
+
slice.refcount = &rc->base;
|
262
|
+
/* The data bytes are placed immediately after the refcount struct */
|
263
|
+
slice.data.refcounted.bytes = (uint8_t *)(rc + 1);
|
264
|
+
/* And the length of the block is set to the requested length */
|
265
|
+
slice.data.refcounted.length = length;
|
266
|
+
return slice;
|
267
|
+
}
|
268
|
+
|
231
269
|
grpc_slice grpc_slice_malloc(size_t length) {
|
232
270
|
grpc_slice slice;
|
233
271
|
|
234
272
|
if (length > sizeof(slice.data.inlined.bytes)) {
|
235
|
-
|
236
|
-
|
237
|
-
+-----------+----------------------------------------------------------+
|
238
|
-
| refcount | bytes |
|
239
|
-
+-----------+----------------------------------------------------------+
|
240
|
-
|
241
|
-
refcount is a malloc_refcount
|
242
|
-
bytes is an array of bytes of the requested length
|
243
|
-
Both parts are placed in the same allocation returned from gpr_malloc */
|
244
|
-
malloc_refcount *rc = gpr_malloc(sizeof(malloc_refcount) + length);
|
245
|
-
|
246
|
-
/* Initial refcount on rc is 1 - and it's up to the caller to release
|
247
|
-
this reference. */
|
248
|
-
gpr_ref_init(&rc->refs, 1);
|
249
|
-
|
250
|
-
rc->base.vtable = &malloc_vtable;
|
251
|
-
rc->base.sub_refcount = &rc->base;
|
252
|
-
|
253
|
-
/* Build up the slice to be returned. */
|
254
|
-
/* The slices refcount points back to the allocated block. */
|
255
|
-
slice.refcount = &rc->base;
|
256
|
-
/* The data bytes are placed immediately after the refcount struct */
|
257
|
-
slice.data.refcounted.bytes = (uint8_t *)(rc + 1);
|
258
|
-
/* And the length of the block is set to the requested length */
|
259
|
-
slice.data.refcounted.length = length;
|
273
|
+
return grpc_slice_malloc_large(length);
|
260
274
|
} else {
|
261
275
|
/* small slice: just inline the data */
|
262
276
|
slice.refcount = NULL;
|
@@ -306,7 +320,8 @@ grpc_slice grpc_slice_sub(grpc_slice source, size_t begin, size_t end) {
|
|
306
320
|
return subset;
|
307
321
|
}
|
308
322
|
|
309
|
-
grpc_slice
|
323
|
+
grpc_slice grpc_slice_split_tail_maybe_ref(grpc_slice *source, size_t split,
|
324
|
+
grpc_slice_ref_whom ref_whom) {
|
310
325
|
grpc_slice tail;
|
311
326
|
|
312
327
|
if (source->refcount == NULL) {
|
@@ -320,28 +335,46 @@ grpc_slice grpc_slice_split_tail(grpc_slice *source, size_t split) {
|
|
320
335
|
} else {
|
321
336
|
size_t tail_length = source->data.refcounted.length - split;
|
322
337
|
GPR_ASSERT(source->data.refcounted.length >= split);
|
323
|
-
if (tail_length < sizeof(tail.data.inlined.bytes)
|
338
|
+
if (tail_length < sizeof(tail.data.inlined.bytes) &&
|
339
|
+
ref_whom != GRPC_SLICE_REF_TAIL) {
|
324
340
|
/* Copy out the bytes - it'll be cheaper than refcounting */
|
325
341
|
tail.refcount = NULL;
|
326
342
|
tail.data.inlined.length = (uint8_t)tail_length;
|
327
343
|
memcpy(tail.data.inlined.bytes, source->data.refcounted.bytes + split,
|
328
344
|
tail_length);
|
345
|
+
source->refcount = source->refcount->sub_refcount;
|
329
346
|
} else {
|
330
347
|
/* Build the result */
|
331
|
-
|
332
|
-
|
333
|
-
|
348
|
+
switch (ref_whom) {
|
349
|
+
case GRPC_SLICE_REF_TAIL:
|
350
|
+
tail.refcount = source->refcount->sub_refcount;
|
351
|
+
source->refcount = &noop_refcount;
|
352
|
+
break;
|
353
|
+
case GRPC_SLICE_REF_HEAD:
|
354
|
+
tail.refcount = &noop_refcount;
|
355
|
+
source->refcount = source->refcount->sub_refcount;
|
356
|
+
break;
|
357
|
+
case GRPC_SLICE_REF_BOTH:
|
358
|
+
tail.refcount = source->refcount->sub_refcount;
|
359
|
+
source->refcount = source->refcount->sub_refcount;
|
360
|
+
/* Bump the refcount */
|
361
|
+
tail.refcount->vtable->ref(tail.refcount);
|
362
|
+
break;
|
363
|
+
}
|
334
364
|
/* Point into the source array */
|
335
365
|
tail.data.refcounted.bytes = source->data.refcounted.bytes + split;
|
336
366
|
tail.data.refcounted.length = tail_length;
|
337
367
|
}
|
338
|
-
source->refcount = source->refcount->sub_refcount;
|
339
368
|
source->data.refcounted.length = split;
|
340
369
|
}
|
341
370
|
|
342
371
|
return tail;
|
343
372
|
}
|
344
373
|
|
374
|
+
grpc_slice grpc_slice_split_tail(grpc_slice *source, size_t split) {
|
375
|
+
return grpc_slice_split_tail_maybe_ref(source, split, GRPC_SLICE_REF_BOTH);
|
376
|
+
}
|
377
|
+
|
345
378
|
grpc_slice grpc_slice_split_head(grpc_slice *source, size_t split) {
|
346
379
|
grpc_slice head;
|
347
380
|
|
@@ -459,7 +492,7 @@ int grpc_slice_slice(grpc_slice haystack, grpc_slice needle) {
|
|
459
492
|
}
|
460
493
|
|
461
494
|
grpc_slice grpc_slice_dup(grpc_slice a) {
|
462
|
-
grpc_slice copy =
|
495
|
+
grpc_slice copy = GRPC_SLICE_MALLOC(GRPC_SLICE_LENGTH(a));
|
463
496
|
memcpy(GRPC_SLICE_START_PTR(copy), GRPC_SLICE_START_PTR(a),
|
464
497
|
GRPC_SLICE_LENGTH(a));
|
465
498
|
return copy;
|