grpc 0.13.0 → 0.13.1.pre1
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/.yardopts +1 -0
- data/Makefile +1114 -937
- data/include/grpc/census.h +71 -89
- data/include/grpc/compression.h +7 -7
- data/include/grpc/grpc.h +65 -68
- data/include/grpc/grpc_security.h +38 -38
- data/include/grpc/impl/codegen/alloc.h +7 -7
- data/include/grpc/impl/codegen/byte_buffer.h +13 -13
- data/include/grpc/impl/codegen/grpc_types.h +7 -2
- data/include/grpc/impl/codegen/log.h +5 -5
- data/include/grpc/impl/codegen/port_platform.h +14 -6
- data/include/grpc/impl/codegen/slice.h +15 -15
- data/include/grpc/impl/codegen/slice_buffer.h +17 -17
- data/include/grpc/impl/codegen/sync.h +26 -22
- data/include/grpc/impl/codegen/time.h +22 -24
- data/include/grpc/support/avl.h +9 -8
- data/include/grpc/support/cmdline.h +12 -12
- data/include/grpc/support/cpu.h +2 -2
- data/include/grpc/support/histogram.h +22 -22
- data/include/grpc/support/host_port.h +2 -2
- data/include/grpc/support/log_win32.h +1 -1
- data/include/grpc/support/string_util.h +2 -2
- data/include/grpc/support/subprocess.h +5 -5
- data/include/grpc/support/thd.h +9 -9
- data/include/grpc/support/useful.h +3 -1
- data/src/core/census/context.c +64 -85
- data/src/core/census/grpc_filter.c +2 -2
- data/src/core/census/mlog.c +600 -0
- data/src/core/census/mlog.h +95 -0
- data/src/core/channel/channel_args.c +67 -6
- data/src/core/channel/channel_args.h +7 -1
- data/src/core/channel/client_channel.c +26 -36
- data/src/core/channel/client_uchannel.c +1 -1
- data/src/core/channel/http_client_filter.c +2 -2
- data/src/core/channel/http_server_filter.c +2 -2
- data/src/core/channel/subchannel_call_holder.c +5 -7
- data/src/core/client_config/connector.c +3 -2
- data/src/core/client_config/connector.h +2 -2
- data/src/core/client_config/lb_policies/load_balancer_api.c +163 -0
- data/src/core/client_config/lb_policies/load_balancer_api.h +85 -0
- data/src/core/client_config/lb_policies/pick_first.c +10 -11
- data/src/core/client_config/lb_policies/round_robin.c +7 -8
- data/src/core/client_config/lb_policy.c +3 -3
- data/src/core/client_config/lb_policy.h +3 -2
- data/src/core/client_config/subchannel.c +51 -21
- data/src/core/client_config/subchannel.h +15 -6
- data/src/core/client_config/subchannel_index.c +261 -0
- data/src/core/client_config/subchannel_index.h +77 -0
- data/src/core/compression/{algorithm.c → compression_algorithm.c} +0 -0
- data/src/core/httpcli/httpcli.c +13 -11
- data/src/core/httpcli/httpcli.h +3 -2
- data/src/core/httpcli/httpcli_security_connector.c +7 -7
- data/src/core/iomgr/fd_posix.c +4 -2
- data/src/core/iomgr/iocp_windows.c +10 -6
- data/src/core/iomgr/iocp_windows.h +9 -2
- data/src/core/iomgr/iomgr.c +18 -2
- data/src/core/iomgr/iomgr_internal.h +5 -1
- data/src/core/iomgr/pollset.h +9 -10
- data/src/core/iomgr/pollset_multipoller_with_epoll.c +1 -0
- data/src/core/iomgr/pollset_multipoller_with_poll_posix.c +10 -5
- data/src/core/iomgr/pollset_posix.c +30 -35
- data/src/core/iomgr/pollset_posix.h +10 -6
- data/src/core/iomgr/pollset_set.h +3 -9
- data/src/core/iomgr/pollset_set_posix.c +23 -3
- data/src/core/iomgr/pollset_set_posix.h +2 -18
- data/src/core/iomgr/pollset_set_windows.c +3 -3
- data/src/core/iomgr/pollset_set_windows.h +2 -2
- data/src/core/iomgr/pollset_windows.c +24 -21
- data/src/core/iomgr/pollset_windows.h +1 -5
- data/src/core/iomgr/tcp_client_posix.c +7 -5
- data/src/core/iomgr/tcp_posix.c +4 -2
- data/src/core/iomgr/tcp_server_windows.c +1 -2
- data/src/core/iomgr/timer.c +2 -3
- data/src/core/iomgr/timer.h +21 -1
- data/src/core/iomgr/timer_heap.c +10 -12
- data/src/core/iomgr/udp_server.c +5 -4
- data/src/core/iomgr/udp_server.h +1 -0
- data/src/core/iomgr/workqueue_posix.c +1 -0
- data/src/core/iomgr/workqueue_posix.h +3 -1
- data/src/core/proto/grpc/lb/v0/load_balancer.pb.c +119 -0
- data/src/core/proto/grpc/lb/v0/load_balancer.pb.h +182 -0
- data/src/core/security/{base64.c → b64.c} +1 -1
- data/src/core/security/{base64.h → b64.h} +1 -1
- data/src/core/security/client_auth_filter.c +0 -1
- data/src/core/security/credentials.c +12 -5
- data/src/core/security/credentials.h +3 -3
- data/src/core/security/google_default_credentials.c +24 -19
- data/src/core/security/handshake.c +15 -7
- data/src/core/security/handshake.h +2 -1
- data/src/core/security/json_token.c +1 -1
- data/src/core/security/jwt_verifier.c +1 -1
- data/src/core/security/security_connector.c +84 -64
- data/src/core/security/security_connector.h +42 -22
- data/src/core/security/security_context.c +8 -3
- data/src/core/security/server_auth_filter.c +2 -2
- data/src/core/security/server_secure_chttp2.c +7 -7
- data/src/core/support/avl.c +2 -2
- data/src/core/support/env_linux.c +17 -0
- data/src/core/support/{file.c → load_file.c} +2 -2
- data/src/core/support/{file.h → load_file.h} +4 -12
- data/src/core/support/sync.c +6 -1
- data/src/core/support/time_posix.c +1 -1
- data/src/core/{iomgr/timer_internal.h → support/tmpfile.h} +17 -23
- data/src/core/support/{file_posix.c → tmpfile_posix.c} +2 -2
- data/src/core/support/{file_win32.c → tmpfile_win32.c} +2 -2
- data/src/core/surface/alarm.c +3 -2
- data/src/core/surface/call.c +102 -52
- data/src/core/surface/channel_create.c +1 -1
- data/src/core/surface/completion_queue.c +73 -41
- data/src/core/surface/init.c +4 -0
- data/src/core/surface/lame_client.c +1 -2
- data/src/core/surface/secure_channel_create.c +6 -7
- data/src/core/surface/server.c +13 -5
- data/src/core/surface/validate_metadata.c +1 -1
- data/src/core/surface/version.c +1 -1
- data/src/core/transport/chttp2/internal.h +22 -10
- data/src/core/transport/chttp2/parsing.c +3 -3
- data/src/core/transport/chttp2/stream_lists.c +39 -21
- data/src/core/transport/chttp2/writing.c +19 -28
- data/src/core/transport/chttp2_transport.c +80 -37
- data/src/core/transport/metadata.c +8 -0
- data/src/core/transport/static_metadata.c +17 -17
- data/src/core/transport/static_metadata.h +3 -3
- data/src/core/transport/transport.c +2 -1
- data/src/core/transport/transport.h +12 -5
- data/src/ruby/ext/grpc/extconf.rb +1 -0
- data/src/ruby/ext/grpc/rb_call.c +6 -0
- data/src/ruby/ext/grpc/rb_call_credentials.c +12 -14
- data/src/ruby/ext/grpc/rb_channel.c +8 -14
- data/src/ruby/ext/grpc/rb_channel_credentials.c +11 -12
- data/src/ruby/ext/grpc/rb_grpc.c +19 -18
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +4 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +8 -2
- data/src/ruby/lib/grpc/core/time_consts.rb +2 -2
- data/src/ruby/lib/grpc/errors.rb +2 -2
- data/src/ruby/lib/grpc/generic/rpc_server.rb +58 -39
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/README.md +2 -2
- data/src/ruby/pb/generate_proto_ruby.sh +2 -2
- data/src/ruby/pb/grpc/health/checker.rb +11 -11
- data/src/ruby/pb/grpc/health/v1/health.rb +28 -0
- data/src/ruby/pb/grpc/health/{v1alpha → v1}/health_services.rb +4 -4
- data/src/ruby/spec/client_server_spec.rb +2 -1
- data/src/ruby/spec/generic/rpc_server_spec.rb +3 -22
- data/src/ruby/spec/pb/health/checker_spec.rb +22 -36
- data/third_party/nanopb/pb.h +547 -0
- data/third_party/nanopb/pb_common.c +97 -0
- data/third_party/nanopb/pb_common.h +42 -0
- data/third_party/nanopb/pb_decode.c +1319 -0
- data/third_party/nanopb/pb_decode.h +149 -0
- data/third_party/nanopb/pb_encode.c +690 -0
- data/third_party/nanopb/pb_encode.h +154 -0
- metadata +32 -16
- data/src/ruby/pb/grpc/health/v1alpha/health.rb +0 -29
@@ -310,7 +310,6 @@ static void init_channel_elem(grpc_exec_ctx *exec_ctx,
|
|
310
310
|
GPR_ASSERT(auth_context != NULL);
|
311
311
|
|
312
312
|
/* initialize members */
|
313
|
-
GPR_ASSERT(sc->is_client_side);
|
314
313
|
chand->security_connector =
|
315
314
|
(grpc_channel_security_connector *)GRPC_SECURITY_CONNECTOR_REF(
|
316
315
|
sc, "client_auth_filter");
|
@@ -166,7 +166,7 @@ void grpc_server_credentials_release(grpc_server_credentials *creds) {
|
|
166
166
|
}
|
167
167
|
|
168
168
|
grpc_security_status grpc_server_credentials_create_security_connector(
|
169
|
-
grpc_server_credentials *creds,
|
169
|
+
grpc_server_credentials *creds, grpc_server_security_connector **sc) {
|
170
170
|
if (creds == NULL || creds->vtable->create_security_connector == NULL) {
|
171
171
|
gpr_log(GPR_ERROR, "Server credentials cannot create security context.");
|
172
172
|
return GRPC_SECURITY_ERROR;
|
@@ -196,14 +196,21 @@ static void *server_credentials_pointer_arg_copy(void *p) {
|
|
196
196
|
return grpc_server_credentials_ref(p);
|
197
197
|
}
|
198
198
|
|
199
|
+
static int server_credentials_pointer_cmp(void *a, void *b) {
|
200
|
+
return GPR_ICMP(a, b);
|
201
|
+
}
|
202
|
+
|
203
|
+
static const grpc_arg_pointer_vtable cred_ptr_vtable = {
|
204
|
+
server_credentials_pointer_arg_copy, server_credentials_pointer_arg_destroy,
|
205
|
+
server_credentials_pointer_cmp};
|
206
|
+
|
199
207
|
grpc_arg grpc_server_credentials_to_arg(grpc_server_credentials *p) {
|
200
208
|
grpc_arg arg;
|
201
209
|
memset(&arg, 0, sizeof(grpc_arg));
|
202
210
|
arg.type = GRPC_ARG_POINTER;
|
203
211
|
arg.key = GRPC_SERVER_CREDENTIALS_ARG;
|
204
212
|
arg.value.pointer.p = p;
|
205
|
-
arg.value.pointer.
|
206
|
-
arg.value.pointer.destroy = server_credentials_pointer_arg_destroy;
|
213
|
+
arg.value.pointer.vtable = &cred_ptr_vtable;
|
207
214
|
return arg;
|
208
215
|
}
|
209
216
|
|
@@ -291,7 +298,7 @@ static grpc_security_status ssl_create_security_connector(
|
|
291
298
|
}
|
292
299
|
|
293
300
|
static grpc_security_status ssl_server_create_security_connector(
|
294
|
-
grpc_server_credentials *creds,
|
301
|
+
grpc_server_credentials *creds, grpc_server_security_connector **sc) {
|
295
302
|
grpc_ssl_server_credentials *c = (grpc_ssl_server_credentials *)creds;
|
296
303
|
return grpc_ssl_server_security_connector_create(&c->config, sc);
|
297
304
|
}
|
@@ -887,7 +894,7 @@ static grpc_security_status fake_transport_security_create_security_connector(
|
|
887
894
|
|
888
895
|
static grpc_security_status
|
889
896
|
fake_transport_security_server_create_security_connector(
|
890
|
-
grpc_server_credentials *c,
|
897
|
+
grpc_server_credentials *c, grpc_server_security_connector **sc) {
|
891
898
|
*sc = grpc_fake_server_security_connector_create();
|
892
899
|
return GRPC_SECURITY_OK;
|
893
900
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/*
|
2
2
|
*
|
3
|
-
* Copyright 2015, Google Inc.
|
3
|
+
* Copyright 2015-2016, Google Inc.
|
4
4
|
* All rights reserved.
|
5
5
|
*
|
6
6
|
* Redistribution and use in source and binary forms, with or without
|
@@ -234,7 +234,7 @@ grpc_refresh_token_credentials_create_from_auth_refresh_token(
|
|
234
234
|
typedef struct {
|
235
235
|
void (*destruct)(grpc_server_credentials *c);
|
236
236
|
grpc_security_status (*create_security_connector)(
|
237
|
-
grpc_server_credentials *c,
|
237
|
+
grpc_server_credentials *c, grpc_server_security_connector **sc);
|
238
238
|
} grpc_server_credentials_vtable;
|
239
239
|
|
240
240
|
struct grpc_server_credentials {
|
@@ -245,7 +245,7 @@ struct grpc_server_credentials {
|
|
245
245
|
};
|
246
246
|
|
247
247
|
grpc_security_status grpc_server_credentials_create_security_connector(
|
248
|
-
grpc_server_credentials *creds,
|
248
|
+
grpc_server_credentials *creds, grpc_server_security_connector **sc);
|
249
249
|
|
250
250
|
grpc_server_credentials *grpc_server_credentials_ref(
|
251
251
|
grpc_server_credentials *creds);
|
@@ -41,7 +41,7 @@
|
|
41
41
|
|
42
42
|
#include "src/core/httpcli/httpcli.h"
|
43
43
|
#include "src/core/support/env.h"
|
44
|
-
#include "src/core/support/
|
44
|
+
#include "src/core/support/load_file.h"
|
45
45
|
#include "src/core/surface/api_trace.h"
|
46
46
|
|
47
47
|
/* -- Constants. -- */
|
@@ -52,13 +52,14 @@
|
|
52
52
|
|
53
53
|
static grpc_channel_credentials *default_credentials = NULL;
|
54
54
|
static int compute_engine_detection_done = 0;
|
55
|
-
static gpr_mu
|
55
|
+
static gpr_mu g_state_mu;
|
56
|
+
static gpr_mu *g_polling_mu;
|
56
57
|
static gpr_once g_once = GPR_ONCE_INIT;
|
57
58
|
|
58
|
-
static void init_default_credentials(void) { gpr_mu_init(&
|
59
|
+
static void init_default_credentials(void) { gpr_mu_init(&g_state_mu); }
|
59
60
|
|
60
61
|
typedef struct {
|
61
|
-
grpc_pollset pollset;
|
62
|
+
grpc_pollset *pollset;
|
62
63
|
int is_done;
|
63
64
|
int success;
|
64
65
|
} compute_engine_detector;
|
@@ -80,10 +81,10 @@ static void on_compute_engine_detection_http_response(
|
|
80
81
|
}
|
81
82
|
}
|
82
83
|
}
|
83
|
-
gpr_mu_lock(
|
84
|
+
gpr_mu_lock(g_polling_mu);
|
84
85
|
detector->is_done = 1;
|
85
|
-
grpc_pollset_kick(
|
86
|
-
gpr_mu_unlock(
|
86
|
+
grpc_pollset_kick(detector->pollset, NULL);
|
87
|
+
gpr_mu_unlock(g_polling_mu);
|
87
88
|
}
|
88
89
|
|
89
90
|
static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, bool s) {
|
@@ -101,7 +102,8 @@ static int is_stack_running_on_compute_engine(void) {
|
|
101
102
|
on compute engine. */
|
102
103
|
gpr_timespec max_detection_delay = gpr_time_from_seconds(1, GPR_TIMESPAN);
|
103
104
|
|
104
|
-
|
105
|
+
detector.pollset = gpr_malloc(grpc_pollset_size());
|
106
|
+
grpc_pollset_init(detector.pollset, &g_polling_mu);
|
105
107
|
detector.is_done = 0;
|
106
108
|
detector.success = 0;
|
107
109
|
|
@@ -112,7 +114,7 @@ static int is_stack_running_on_compute_engine(void) {
|
|
112
114
|
grpc_httpcli_context_init(&context);
|
113
115
|
|
114
116
|
grpc_httpcli_get(
|
115
|
-
&exec_ctx, &context,
|
117
|
+
&exec_ctx, &context, detector.pollset, &request,
|
116
118
|
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), max_detection_delay),
|
117
119
|
on_compute_engine_detection_http_response, &detector);
|
118
120
|
|
@@ -120,19 +122,22 @@ static int is_stack_running_on_compute_engine(void) {
|
|
120
122
|
|
121
123
|
/* Block until we get the response. This is not ideal but this should only be
|
122
124
|
called once for the lifetime of the process by the default credentials. */
|
123
|
-
gpr_mu_lock(
|
125
|
+
gpr_mu_lock(g_polling_mu);
|
124
126
|
while (!detector.is_done) {
|
125
|
-
grpc_pollset_worker worker;
|
126
|
-
grpc_pollset_work(&exec_ctx,
|
127
|
+
grpc_pollset_worker *worker = NULL;
|
128
|
+
grpc_pollset_work(&exec_ctx, detector.pollset, &worker,
|
127
129
|
gpr_now(GPR_CLOCK_MONOTONIC),
|
128
130
|
gpr_inf_future(GPR_CLOCK_MONOTONIC));
|
129
131
|
}
|
130
|
-
gpr_mu_unlock(
|
132
|
+
gpr_mu_unlock(g_polling_mu);
|
131
133
|
|
132
134
|
grpc_httpcli_context_destroy(&context);
|
133
|
-
grpc_closure_init(&destroy_closure, destroy_pollset,
|
134
|
-
grpc_pollset_shutdown(&exec_ctx,
|
135
|
+
grpc_closure_init(&destroy_closure, destroy_pollset, detector.pollset);
|
136
|
+
grpc_pollset_shutdown(&exec_ctx, detector.pollset, &destroy_closure);
|
135
137
|
grpc_exec_ctx_finish(&exec_ctx);
|
138
|
+
g_polling_mu = NULL;
|
139
|
+
|
140
|
+
gpr_free(detector.pollset);
|
136
141
|
|
137
142
|
return detector.success;
|
138
143
|
}
|
@@ -184,7 +189,7 @@ grpc_channel_credentials *grpc_google_default_credentials_create(void) {
|
|
184
189
|
|
185
190
|
gpr_once_init(&g_once, init_default_credentials);
|
186
191
|
|
187
|
-
gpr_mu_lock(&
|
192
|
+
gpr_mu_lock(&g_state_mu);
|
188
193
|
|
189
194
|
if (default_credentials != NULL) {
|
190
195
|
result = grpc_channel_credentials_ref(default_credentials);
|
@@ -230,19 +235,19 @@ end:
|
|
230
235
|
gpr_log(GPR_ERROR, "Could not create google default credentials.");
|
231
236
|
}
|
232
237
|
}
|
233
|
-
gpr_mu_unlock(&
|
238
|
+
gpr_mu_unlock(&g_state_mu);
|
234
239
|
return result;
|
235
240
|
}
|
236
241
|
|
237
242
|
void grpc_flush_cached_google_default_credentials(void) {
|
238
243
|
gpr_once_init(&g_once, init_default_credentials);
|
239
|
-
gpr_mu_lock(&
|
244
|
+
gpr_mu_lock(&g_state_mu);
|
240
245
|
if (default_credentials != NULL) {
|
241
246
|
grpc_channel_credentials_unref(default_credentials);
|
242
247
|
default_credentials = NULL;
|
243
248
|
}
|
244
249
|
compute_engine_detection_done = 0;
|
245
|
-
gpr_mu_unlock(&
|
250
|
+
gpr_mu_unlock(&g_state_mu);
|
246
251
|
}
|
247
252
|
|
248
253
|
/* -- Well known credentials path. -- */
|
@@ -33,6 +33,7 @@
|
|
33
33
|
|
34
34
|
#include "src/core/security/handshake.h"
|
35
35
|
|
36
|
+
#include <stdbool.h>
|
36
37
|
#include <string.h>
|
37
38
|
|
38
39
|
#include "src/core/security/security_context.h"
|
@@ -46,6 +47,7 @@
|
|
46
47
|
typedef struct {
|
47
48
|
grpc_security_connector *connector;
|
48
49
|
tsi_handshaker *handshaker;
|
50
|
+
bool is_client_side;
|
49
51
|
unsigned char *handshake_buffer;
|
50
52
|
size_t handshake_buffer_size;
|
51
53
|
grpc_endpoint *wrapped_endpoint;
|
@@ -67,9 +69,11 @@ static void on_handshake_data_sent_to_peer(grpc_exec_ctx *exec_ctx, void *setup,
|
|
67
69
|
bool success);
|
68
70
|
|
69
71
|
static void security_connector_remove_handshake(grpc_security_handshake *h) {
|
72
|
+
GPR_ASSERT(!h->is_client_side);
|
70
73
|
grpc_security_connector_handshake_list *node;
|
71
74
|
grpc_security_connector_handshake_list *tmp;
|
72
|
-
|
75
|
+
grpc_server_security_connector *sc =
|
76
|
+
(grpc_server_security_connector *)h->connector;
|
73
77
|
gpr_mu_lock(&sc->mu);
|
74
78
|
node = sc->handshaking_handshakes;
|
75
79
|
if (node && node->handshake == h) {
|
@@ -94,7 +98,7 @@ static void security_connector_remove_handshake(grpc_security_handshake *h) {
|
|
94
98
|
static void security_handshake_done(grpc_exec_ctx *exec_ctx,
|
95
99
|
grpc_security_handshake *h,
|
96
100
|
int is_success) {
|
97
|
-
if (!h->
|
101
|
+
if (!h->is_client_side) {
|
98
102
|
security_connector_remove_handshake(h);
|
99
103
|
}
|
100
104
|
if (is_success) {
|
@@ -290,6 +294,7 @@ static void on_handshake_data_sent_to_peer(grpc_exec_ctx *exec_ctx,
|
|
290
294
|
void grpc_do_security_handshake(grpc_exec_ctx *exec_ctx,
|
291
295
|
tsi_handshaker *handshaker,
|
292
296
|
grpc_security_connector *connector,
|
297
|
+
bool is_client_side,
|
293
298
|
grpc_endpoint *nonsecure_endpoint,
|
294
299
|
grpc_security_handshake_done_cb cb,
|
295
300
|
void *user_data) {
|
@@ -298,6 +303,7 @@ void grpc_do_security_handshake(grpc_exec_ctx *exec_ctx,
|
|
298
303
|
memset(h, 0, sizeof(grpc_security_handshake));
|
299
304
|
h->handshaker = handshaker;
|
300
305
|
h->connector = GRPC_SECURITY_CONNECTOR_REF(connector, "handshake");
|
306
|
+
h->is_client_side = is_client_side;
|
301
307
|
h->handshake_buffer_size = GRPC_INITIAL_HANDSHAKE_BUFFER_SIZE;
|
302
308
|
h->handshake_buffer = gpr_malloc(h->handshake_buffer_size);
|
303
309
|
h->wrapped_endpoint = nonsecure_endpoint;
|
@@ -310,13 +316,15 @@ void grpc_do_security_handshake(grpc_exec_ctx *exec_ctx,
|
|
310
316
|
gpr_slice_buffer_init(&h->left_overs);
|
311
317
|
gpr_slice_buffer_init(&h->outgoing);
|
312
318
|
gpr_slice_buffer_init(&h->incoming);
|
313
|
-
if (!
|
319
|
+
if (!is_client_side) {
|
320
|
+
grpc_server_security_connector *server_connector =
|
321
|
+
(grpc_server_security_connector *)connector;
|
314
322
|
handshake_node = gpr_malloc(sizeof(grpc_security_connector_handshake_list));
|
315
323
|
handshake_node->handshake = h;
|
316
|
-
gpr_mu_lock(&
|
317
|
-
handshake_node->next =
|
318
|
-
|
319
|
-
gpr_mu_unlock(&
|
324
|
+
gpr_mu_lock(&server_connector->mu);
|
325
|
+
handshake_node->next = server_connector->handshaking_handshakes;
|
326
|
+
server_connector->handshaking_handshakes = handshake_node;
|
327
|
+
gpr_mu_unlock(&server_connector->mu);
|
320
328
|
}
|
321
329
|
send_handshake_bytes_to_peer(exec_ctx, h);
|
322
330
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/*
|
2
2
|
*
|
3
|
-
* Copyright 2015, Google Inc.
|
3
|
+
* Copyright 2015-2016, Google Inc.
|
4
4
|
* All rights reserved.
|
5
5
|
*
|
6
6
|
* Redistribution and use in source and binary forms, with or without
|
@@ -41,6 +41,7 @@
|
|
41
41
|
void grpc_do_security_handshake(grpc_exec_ctx *exec_ctx,
|
42
42
|
tsi_handshaker *handshaker,
|
43
43
|
grpc_security_connector *connector,
|
44
|
+
bool is_client_side,
|
44
45
|
grpc_endpoint *nonsecure_endpoint,
|
45
46
|
grpc_security_handshake_done_cb cb,
|
46
47
|
void *user_data);
|
@@ -33,22 +33,23 @@
|
|
33
33
|
|
34
34
|
#include "src/core/security/security_connector.h"
|
35
35
|
|
36
|
+
#include <stdbool.h>
|
36
37
|
#include <string.h>
|
37
38
|
|
39
|
+
#include <grpc/support/alloc.h>
|
40
|
+
#include <grpc/support/host_port.h>
|
41
|
+
#include <grpc/support/log.h>
|
42
|
+
#include <grpc/support/slice_buffer.h>
|
43
|
+
#include <grpc/support/string_util.h>
|
44
|
+
|
38
45
|
#include "src/core/security/credentials.h"
|
39
46
|
#include "src/core/security/handshake.h"
|
40
47
|
#include "src/core/security/secure_endpoint.h"
|
41
48
|
#include "src/core/security/security_context.h"
|
42
49
|
#include "src/core/support/env.h"
|
43
|
-
#include "src/core/support/
|
50
|
+
#include "src/core/support/load_file.h"
|
44
51
|
#include "src/core/support/string.h"
|
45
52
|
#include "src/core/transport/chttp2/alpn.h"
|
46
|
-
|
47
|
-
#include <grpc/support/alloc.h>
|
48
|
-
#include <grpc/support/host_port.h>
|
49
|
-
#include <grpc/support/log.h>
|
50
|
-
#include <grpc/support/slice_buffer.h>
|
51
|
-
#include <grpc/support/string_util.h>
|
52
53
|
#include "src/core/tsi/fake_transport_security.h"
|
53
54
|
#include "src/core/tsi/ssl_transport_security.h"
|
54
55
|
|
@@ -110,31 +111,39 @@ const tsi_peer_property *tsi_peer_get_property_by_name(const tsi_peer *peer,
|
|
110
111
|
return NULL;
|
111
112
|
}
|
112
113
|
|
113
|
-
void
|
114
|
-
|
114
|
+
void grpc_server_security_connector_shutdown(
|
115
|
+
grpc_exec_ctx *exec_ctx, grpc_server_security_connector *connector) {
|
115
116
|
grpc_security_connector_handshake_list *tmp;
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
117
|
+
gpr_mu_lock(&connector->mu);
|
118
|
+
while (connector->handshaking_handshakes) {
|
119
|
+
tmp = connector->handshaking_handshakes;
|
120
|
+
grpc_security_handshake_shutdown(
|
121
|
+
exec_ctx, connector->handshaking_handshakes->handshake);
|
122
|
+
connector->handshaking_handshakes = tmp->next;
|
123
|
+
gpr_free(tmp);
|
124
|
+
}
|
125
|
+
gpr_mu_unlock(&connector->mu);
|
126
|
+
}
|
127
|
+
|
128
|
+
void grpc_channel_security_connector_do_handshake(
|
129
|
+
grpc_exec_ctx *exec_ctx, grpc_channel_security_connector *sc,
|
130
|
+
grpc_endpoint *nonsecure_endpoint, grpc_security_handshake_done_cb cb,
|
131
|
+
void *user_data) {
|
132
|
+
if (sc == NULL || nonsecure_endpoint == NULL) {
|
133
|
+
cb(exec_ctx, user_data, GRPC_SECURITY_ERROR, NULL, NULL);
|
134
|
+
} else {
|
135
|
+
sc->do_handshake(exec_ctx, sc, nonsecure_endpoint, cb, user_data);
|
126
136
|
}
|
127
137
|
}
|
128
138
|
|
129
|
-
void
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
void *user_data) {
|
139
|
+
void grpc_server_security_connector_do_handshake(
|
140
|
+
grpc_exec_ctx *exec_ctx, grpc_server_security_connector *sc,
|
141
|
+
grpc_tcp_server_acceptor *acceptor, grpc_endpoint *nonsecure_endpoint,
|
142
|
+
grpc_security_handshake_done_cb cb, void *user_data) {
|
134
143
|
if (sc == NULL || nonsecure_endpoint == NULL) {
|
135
144
|
cb(exec_ctx, user_data, GRPC_SECURITY_ERROR, NULL, NULL);
|
136
145
|
} else {
|
137
|
-
sc->
|
146
|
+
sc->do_handshake(exec_ctx, sc, acceptor, nonsecure_endpoint, cb, user_data);
|
138
147
|
}
|
139
148
|
}
|
140
149
|
|
@@ -202,12 +211,17 @@ static void *connector_pointer_arg_copy(void *p) {
|
|
202
211
|
return GRPC_SECURITY_CONNECTOR_REF(p, "connector_pointer_arg");
|
203
212
|
}
|
204
213
|
|
214
|
+
static int connector_pointer_cmp(void *a, void *b) { return GPR_ICMP(a, b); }
|
215
|
+
|
216
|
+
static const grpc_arg_pointer_vtable connector_pointer_vtable = {
|
217
|
+
connector_pointer_arg_copy, connector_pointer_arg_destroy,
|
218
|
+
connector_pointer_cmp};
|
219
|
+
|
205
220
|
grpc_arg grpc_security_connector_to_arg(grpc_security_connector *sc) {
|
206
221
|
grpc_arg result;
|
207
222
|
result.type = GRPC_ARG_POINTER;
|
208
223
|
result.key = GRPC_SECURITY_CONNECTOR_ARG;
|
209
|
-
result.value.pointer.
|
210
|
-
result.value.pointer.copy = connector_pointer_arg_copy;
|
224
|
+
result.value.pointer.vtable = &connector_pointer_vtable;
|
211
225
|
result.value.pointer.p = sc;
|
212
226
|
return result;
|
213
227
|
}
|
@@ -243,7 +257,8 @@ static void fake_channel_destroy(grpc_security_connector *sc) {
|
|
243
257
|
}
|
244
258
|
|
245
259
|
static void fake_server_destroy(grpc_security_connector *sc) {
|
246
|
-
|
260
|
+
grpc_server_security_connector *c = (grpc_server_security_connector *)sc;
|
261
|
+
gpr_mu_destroy(&c->mu);
|
247
262
|
gpr_free(sc);
|
248
263
|
}
|
249
264
|
|
@@ -293,49 +308,52 @@ static void fake_channel_check_call_host(grpc_exec_ctx *exec_ctx,
|
|
293
308
|
}
|
294
309
|
|
295
310
|
static void fake_channel_do_handshake(grpc_exec_ctx *exec_ctx,
|
296
|
-
|
311
|
+
grpc_channel_security_connector *sc,
|
297
312
|
grpc_endpoint *nonsecure_endpoint,
|
298
313
|
grpc_security_handshake_done_cb cb,
|
299
314
|
void *user_data) {
|
300
|
-
grpc_do_security_handshake(exec_ctx, tsi_create_fake_handshaker(1), sc,
|
301
|
-
nonsecure_endpoint, cb, user_data);
|
315
|
+
grpc_do_security_handshake(exec_ctx, tsi_create_fake_handshaker(1), &sc->base,
|
316
|
+
true, nonsecure_endpoint, cb, user_data);
|
302
317
|
}
|
303
318
|
|
304
319
|
static void fake_server_do_handshake(grpc_exec_ctx *exec_ctx,
|
305
|
-
|
320
|
+
grpc_server_security_connector *sc,
|
321
|
+
grpc_tcp_server_acceptor *acceptor,
|
306
322
|
grpc_endpoint *nonsecure_endpoint,
|
307
323
|
grpc_security_handshake_done_cb cb,
|
308
324
|
void *user_data) {
|
309
|
-
grpc_do_security_handshake(exec_ctx, tsi_create_fake_handshaker(0), sc,
|
310
|
-
nonsecure_endpoint, cb, user_data);
|
325
|
+
grpc_do_security_handshake(exec_ctx, tsi_create_fake_handshaker(0), &sc->base,
|
326
|
+
false, nonsecure_endpoint, cb, user_data);
|
311
327
|
}
|
312
328
|
|
313
329
|
static grpc_security_connector_vtable fake_channel_vtable = {
|
314
|
-
fake_channel_destroy,
|
330
|
+
fake_channel_destroy, fake_check_peer};
|
315
331
|
|
316
|
-
static grpc_security_connector_vtable fake_server_vtable = {
|
317
|
-
|
332
|
+
static grpc_security_connector_vtable fake_server_vtable = {fake_server_destroy,
|
333
|
+
fake_check_peer};
|
318
334
|
|
319
335
|
grpc_channel_security_connector *grpc_fake_channel_security_connector_create(
|
320
336
|
grpc_call_credentials *request_metadata_creds) {
|
321
337
|
grpc_channel_security_connector *c = gpr_malloc(sizeof(*c));
|
322
338
|
memset(c, 0, sizeof(*c));
|
323
339
|
gpr_ref_init(&c->base.refcount, 1);
|
324
|
-
c->base.is_client_side = 1;
|
325
340
|
c->base.url_scheme = GRPC_FAKE_SECURITY_URL_SCHEME;
|
326
341
|
c->base.vtable = &fake_channel_vtable;
|
327
342
|
c->request_metadata_creds = grpc_call_credentials_ref(request_metadata_creds);
|
328
343
|
c->check_call_host = fake_channel_check_call_host;
|
344
|
+
c->do_handshake = fake_channel_do_handshake;
|
329
345
|
return c;
|
330
346
|
}
|
331
347
|
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
c
|
337
|
-
c->
|
338
|
-
c->
|
348
|
+
grpc_server_security_connector *grpc_fake_server_security_connector_create(
|
349
|
+
void) {
|
350
|
+
grpc_server_security_connector *c =
|
351
|
+
gpr_malloc(sizeof(grpc_server_security_connector));
|
352
|
+
memset(c, 0, sizeof(*c));
|
353
|
+
gpr_ref_init(&c->base.refcount, 1);
|
354
|
+
c->base.vtable = &fake_server_vtable;
|
355
|
+
c->base.url_scheme = GRPC_FAKE_SECURITY_URL_SCHEME;
|
356
|
+
c->do_handshake = fake_server_do_handshake;
|
339
357
|
gpr_mu_init(&c->mu);
|
340
358
|
return c;
|
341
359
|
}
|
@@ -350,7 +368,7 @@ typedef struct {
|
|
350
368
|
} grpc_ssl_channel_security_connector;
|
351
369
|
|
352
370
|
typedef struct {
|
353
|
-
|
371
|
+
grpc_server_security_connector base;
|
354
372
|
tsi_ssl_handshaker_factory *handshaker_factory;
|
355
373
|
} grpc_ssl_server_security_connector;
|
356
374
|
|
@@ -373,12 +391,12 @@ static void ssl_server_destroy(grpc_security_connector *sc) {
|
|
373
391
|
if (c->handshaker_factory != NULL) {
|
374
392
|
tsi_ssl_handshaker_factory_destroy(c->handshaker_factory);
|
375
393
|
}
|
376
|
-
gpr_mu_destroy(&
|
394
|
+
gpr_mu_destroy(&c->base.mu);
|
377
395
|
gpr_free(sc);
|
378
396
|
}
|
379
397
|
|
380
398
|
static grpc_security_status ssl_create_handshaker(
|
381
|
-
tsi_ssl_handshaker_factory *handshaker_factory,
|
399
|
+
tsi_ssl_handshaker_factory *handshaker_factory, bool is_client,
|
382
400
|
const char *peer_name, tsi_handshaker **handshaker) {
|
383
401
|
tsi_result result = TSI_OK;
|
384
402
|
if (handshaker_factory == NULL) return GRPC_SECURITY_ERROR;
|
@@ -393,7 +411,7 @@ static grpc_security_status ssl_create_handshaker(
|
|
393
411
|
}
|
394
412
|
|
395
413
|
static void ssl_channel_do_handshake(grpc_exec_ctx *exec_ctx,
|
396
|
-
|
414
|
+
grpc_channel_security_connector *sc,
|
397
415
|
grpc_endpoint *nonsecure_endpoint,
|
398
416
|
grpc_security_handshake_done_cb cb,
|
399
417
|
void *user_data) {
|
@@ -401,20 +419,21 @@ static void ssl_channel_do_handshake(grpc_exec_ctx *exec_ctx,
|
|
401
419
|
(grpc_ssl_channel_security_connector *)sc;
|
402
420
|
tsi_handshaker *handshaker;
|
403
421
|
grpc_security_status status = ssl_create_handshaker(
|
404
|
-
c->handshaker_factory,
|
422
|
+
c->handshaker_factory, true,
|
405
423
|
c->overridden_target_name != NULL ? c->overridden_target_name
|
406
424
|
: c->target_name,
|
407
425
|
&handshaker);
|
408
426
|
if (status != GRPC_SECURITY_OK) {
|
409
427
|
cb(exec_ctx, user_data, status, NULL, NULL);
|
410
428
|
} else {
|
411
|
-
grpc_do_security_handshake(exec_ctx, handshaker, sc,
|
412
|
-
user_data);
|
429
|
+
grpc_do_security_handshake(exec_ctx, handshaker, &sc->base, true,
|
430
|
+
nonsecure_endpoint, cb, user_data);
|
413
431
|
}
|
414
432
|
}
|
415
433
|
|
416
434
|
static void ssl_server_do_handshake(grpc_exec_ctx *exec_ctx,
|
417
|
-
|
435
|
+
grpc_server_security_connector *sc,
|
436
|
+
grpc_tcp_server_acceptor *acceptor,
|
418
437
|
grpc_endpoint *nonsecure_endpoint,
|
419
438
|
grpc_security_handshake_done_cb cb,
|
420
439
|
void *user_data) {
|
@@ -422,12 +441,12 @@ static void ssl_server_do_handshake(grpc_exec_ctx *exec_ctx,
|
|
422
441
|
(grpc_ssl_server_security_connector *)sc;
|
423
442
|
tsi_handshaker *handshaker;
|
424
443
|
grpc_security_status status =
|
425
|
-
ssl_create_handshaker(c->handshaker_factory,
|
444
|
+
ssl_create_handshaker(c->handshaker_factory, false, NULL, &handshaker);
|
426
445
|
if (status != GRPC_SECURITY_OK) {
|
427
446
|
cb(exec_ctx, user_data, status, NULL, NULL);
|
428
447
|
} else {
|
429
|
-
grpc_do_security_handshake(exec_ctx, handshaker, sc,
|
430
|
-
user_data);
|
448
|
+
grpc_do_security_handshake(exec_ctx, handshaker, &sc->base, false,
|
449
|
+
nonsecure_endpoint, cb, user_data);
|
431
450
|
}
|
432
451
|
}
|
433
452
|
|
@@ -598,10 +617,10 @@ static void ssl_channel_check_call_host(grpc_exec_ctx *exec_ctx,
|
|
598
617
|
}
|
599
618
|
|
600
619
|
static grpc_security_connector_vtable ssl_channel_vtable = {
|
601
|
-
ssl_channel_destroy,
|
620
|
+
ssl_channel_destroy, ssl_channel_check_peer};
|
602
621
|
|
603
622
|
static grpc_security_connector_vtable ssl_server_vtable = {
|
604
|
-
ssl_server_destroy,
|
623
|
+
ssl_server_destroy, ssl_server_check_peer};
|
605
624
|
|
606
625
|
static gpr_slice compute_default_pem_root_certs_once(void) {
|
607
626
|
gpr_slice result = gpr_empty_slice();
|
@@ -695,11 +714,11 @@ grpc_security_status grpc_ssl_channel_security_connector_create(
|
|
695
714
|
|
696
715
|
gpr_ref_init(&c->base.base.refcount, 1);
|
697
716
|
c->base.base.vtable = &ssl_channel_vtable;
|
698
|
-
c->base.base.is_client_side = 1;
|
699
717
|
c->base.base.url_scheme = GRPC_SSL_URL_SCHEME;
|
700
718
|
c->base.request_metadata_creds =
|
701
719
|
grpc_call_credentials_ref(request_metadata_creds);
|
702
720
|
c->base.check_call_host = ssl_channel_check_call_host;
|
721
|
+
c->base.do_handshake = ssl_channel_do_handshake;
|
703
722
|
gpr_split_host_port(target_name, &c->target_name, &port);
|
704
723
|
gpr_free(port);
|
705
724
|
if (overridden_target_name != NULL) {
|
@@ -730,7 +749,7 @@ error:
|
|
730
749
|
}
|
731
750
|
|
732
751
|
grpc_security_status grpc_ssl_server_security_connector_create(
|
733
|
-
const grpc_ssl_server_config *config,
|
752
|
+
const grpc_ssl_server_config *config, grpc_server_security_connector **sc) {
|
734
753
|
size_t num_alpn_protocols = grpc_chttp2_num_alpn_versions();
|
735
754
|
const unsigned char **alpn_protocol_strings =
|
736
755
|
gpr_malloc(sizeof(const char *) * num_alpn_protocols);
|
@@ -754,9 +773,9 @@ grpc_security_status grpc_ssl_server_security_connector_create(
|
|
754
773
|
c = gpr_malloc(sizeof(grpc_ssl_server_security_connector));
|
755
774
|
memset(c, 0, sizeof(grpc_ssl_server_security_connector));
|
756
775
|
|
757
|
-
gpr_ref_init(&c->base.refcount, 1);
|
758
|
-
c->base.url_scheme = GRPC_SSL_URL_SCHEME;
|
759
|
-
c->base.vtable = &ssl_server_vtable;
|
776
|
+
gpr_ref_init(&c->base.base.refcount, 1);
|
777
|
+
c->base.base.url_scheme = GRPC_SSL_URL_SCHEME;
|
778
|
+
c->base.base.vtable = &ssl_server_vtable;
|
760
779
|
result = tsi_create_ssl_server_handshaker_factory(
|
761
780
|
(const unsigned char **)config->pem_private_keys,
|
762
781
|
config->pem_private_keys_sizes,
|
@@ -769,11 +788,12 @@ grpc_security_status grpc_ssl_server_security_connector_create(
|
|
769
788
|
if (result != TSI_OK) {
|
770
789
|
gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.",
|
771
790
|
tsi_result_to_string(result));
|
772
|
-
ssl_server_destroy(&c->base);
|
791
|
+
ssl_server_destroy(&c->base.base);
|
773
792
|
*sc = NULL;
|
774
793
|
goto error;
|
775
794
|
}
|
776
795
|
gpr_mu_init(&c->base.mu);
|
796
|
+
c->base.do_handshake = ssl_server_do_handshake;
|
777
797
|
*sc = &c->base;
|
778
798
|
gpr_free((void *)alpn_protocol_strings);
|
779
799
|
gpr_free(alpn_protocol_string_lengths);
|