grpc 1.17.1 → 1.18.0.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/Makefile +1228 -988
- data/etc/roots.pem +242 -30
- data/include/grpc/grpc.h +2 -1
- data/include/grpc/grpc_security_constants.h +3 -3
- data/include/grpc/impl/codegen/atm_gcc_sync.h +2 -0
- data/include/grpc/impl/codegen/atm_windows.h +2 -0
- data/include/grpc/impl/codegen/compression_types.h +2 -1
- data/include/grpc/impl/codegen/grpc_types.h +1 -1
- data/include/grpc/impl/codegen/port_platform.h +9 -0
- data/src/core/ext/filters/client_channel/client_channel.cc +163 -882
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +2 -4
- data/src/core/ext/filters/client_channel/health/health_check_client.h +2 -3
- data/src/core/ext/filters/client_channel/lb_policy.cc +1 -1
- data/src/core/ext/filters/client_channel/lb_policy.h +8 -17
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +176 -216
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +20 -23
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +49 -52
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +13 -35
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +31 -30
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +69 -225
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +20 -23
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +2 -84
- data/src/core/ext/filters/client_channel/request_routing.cc +936 -0
- data/src/core/ext/filters/client_channel/request_routing.h +177 -0
- data/src/core/ext/filters/client_channel/resolver.cc +1 -1
- data/src/core/ext/filters/client_channel/resolver.h +1 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +37 -26
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +30 -18
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +119 -100
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +8 -5
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +5 -4
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +2 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +12 -14
- data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +5 -9
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -1
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +1 -2
- data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +17 -17
- data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +45 -52
- data/src/core/ext/filters/client_channel/resolver_result_parsing.h +13 -17
- data/src/core/ext/filters/client_channel/server_address.cc +103 -0
- data/src/core/ext/filters/client_channel/server_address.h +108 -0
- data/src/core/ext/filters/client_channel/subchannel.cc +10 -8
- data/src/core/ext/filters/client_channel/subchannel.h +9 -6
- data/src/core/ext/filters/client_channel/subchannel_index.cc +20 -27
- data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +3 -2
- data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +8 -9
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +1 -1
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +1 -1
- data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +8 -11
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +24 -54
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -1
- data/src/core/ext/transport/chttp2/transport/context_list.cc +67 -0
- data/src/core/ext/transport/chttp2/transport/context_list.h +53 -0
- data/src/core/ext/transport/chttp2/transport/internal.h +38 -11
- data/src/core/ext/transport/chttp2/transport/writing.cc +5 -0
- data/src/core/ext/transport/inproc/inproc_transport.cc +1 -1
- data/src/core/lib/channel/channelz.cc +19 -18
- data/src/core/lib/channel/channelz.h +7 -1
- data/src/core/lib/channel/channelz_registry.cc +3 -2
- data/src/core/lib/debug/trace.cc +3 -0
- data/src/core/lib/debug/trace.h +5 -3
- data/src/core/lib/gpr/sync_posix.cc +96 -4
- data/src/core/lib/gprpp/inlined_vector.h +25 -19
- data/src/core/lib/gprpp/memory.h +2 -11
- data/src/core/lib/gprpp/orphanable.h +18 -82
- data/src/core/lib/gprpp/ref_counted.h +75 -84
- data/src/core/lib/gprpp/ref_counted_ptr.h +22 -17
- data/src/core/lib/http/httpcli_security_connector.cc +101 -94
- data/src/core/lib/http/parser.h +5 -5
- data/src/core/lib/iomgr/buffer_list.cc +16 -5
- data/src/core/lib/iomgr/buffer_list.h +10 -3
- data/src/core/lib/iomgr/call_combiner.cc +50 -2
- data/src/core/lib/iomgr/call_combiner.h +29 -2
- data/src/core/lib/iomgr/dynamic_annotations.h +67 -0
- data/src/core/lib/iomgr/endpoint.cc +4 -0
- data/src/core/lib/iomgr/endpoint.h +3 -0
- data/src/core/lib/iomgr/endpoint_pair_posix.cc +2 -2
- data/src/core/lib/iomgr/ev_epoll1_linux.cc +4 -0
- data/src/core/lib/iomgr/ev_epollex_linux.cc +4 -0
- data/src/core/lib/iomgr/ev_poll_posix.cc +4 -0
- data/src/core/lib/iomgr/ev_posix.cc +15 -7
- data/src/core/lib/iomgr/ev_posix.h +10 -0
- data/src/core/lib/iomgr/exec_ctx.cc +13 -0
- data/src/core/lib/iomgr/fork_posix.cc +1 -1
- data/src/core/lib/iomgr/internal_errqueue.cc +36 -3
- data/src/core/lib/iomgr/internal_errqueue.h +7 -1
- data/src/core/lib/iomgr/iomgr.cc +7 -0
- data/src/core/lib/iomgr/iomgr.h +4 -0
- data/src/core/lib/iomgr/iomgr_custom.cc +3 -1
- data/src/core/lib/iomgr/iomgr_internal.cc +4 -0
- data/src/core/lib/iomgr/iomgr_internal.h +4 -0
- data/src/core/lib/iomgr/iomgr_posix.cc +6 -1
- data/src/core/lib/iomgr/iomgr_windows.cc +4 -1
- data/src/core/lib/iomgr/port.h +1 -2
- data/src/core/lib/iomgr/resource_quota.cc +1 -0
- data/src/core/lib/iomgr/sockaddr_utils.cc +1 -0
- data/src/core/lib/iomgr/tcp_custom.cc +4 -1
- data/src/core/lib/iomgr/tcp_posix.cc +95 -35
- data/src/core/lib/iomgr/tcp_windows.cc +4 -1
- data/src/core/lib/iomgr/timer_manager.cc +6 -0
- data/src/core/lib/security/context/security_context.cc +75 -108
- data/src/core/lib/security/context/security_context.h +59 -35
- data/src/core/lib/security/credentials/alts/alts_credentials.cc +36 -48
- data/src/core/lib/security/credentials/alts/alts_credentials.h +37 -10
- data/src/core/lib/security/credentials/composite/composite_credentials.cc +97 -157
- data/src/core/lib/security/credentials/composite/composite_credentials.h +60 -24
- data/src/core/lib/security/credentials/credentials.cc +18 -142
- data/src/core/lib/security/credentials/credentials.h +119 -95
- data/src/core/lib/security/credentials/fake/fake_credentials.cc +46 -71
- data/src/core/lib/security/credentials/fake/fake_credentials.h +23 -5
- data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +144 -51
- data/src/core/lib/security/credentials/google_default/google_default_credentials.h +28 -5
- data/src/core/lib/security/credentials/iam/iam_credentials.cc +27 -35
- data/src/core/lib/security/credentials/iam/iam_credentials.h +18 -4
- data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +60 -69
- data/src/core/lib/security/credentials/jwt/jwt_credentials.h +29 -10
- data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +2 -0
- data/src/core/lib/security/credentials/local/local_credentials.cc +19 -32
- data/src/core/lib/security/credentials/local/local_credentials.h +32 -11
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +130 -149
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +74 -29
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +59 -77
- data/src/core/lib/security/credentials/plugin/plugin_credentials.h +40 -17
- data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +66 -83
- data/src/core/lib/security/credentials/ssl/ssl_credentials.h +58 -15
- data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +152 -177
- data/src/core/lib/security/security_connector/alts/alts_security_connector.h +12 -10
- data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +210 -215
- data/src/core/lib/security/security_connector/fake/fake_security_connector.h +9 -6
- data/src/core/lib/security/security_connector/local/local_security_connector.cc +176 -169
- data/src/core/lib/security/security_connector/local/local_security_connector.h +10 -9
- data/src/core/lib/security/security_connector/security_connector.cc +41 -124
- data/src/core/lib/security/security_connector/security_connector.h +102 -105
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +348 -370
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.h +14 -12
- data/src/core/lib/security/security_connector/ssl_utils.cc +13 -9
- data/src/core/lib/security/security_connector/ssl_utils.h +3 -1
- data/src/core/lib/security/transport/client_auth_filter.cc +50 -50
- data/src/core/lib/security/transport/secure_endpoint.cc +7 -1
- data/src/core/lib/security/transport/security_handshaker.cc +82 -66
- data/src/core/lib/security/transport/server_auth_filter.cc +15 -13
- data/src/core/lib/surface/init.cc +1 -0
- data/src/core/lib/surface/server.cc +13 -11
- data/src/core/lib/surface/server.h +6 -6
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/metadata.cc +1 -0
- data/src/core/lib/transport/static_metadata.cc +228 -221
- data/src/core/lib/transport/static_metadata.h +75 -71
- data/src/core/lib/transport/transport.cc +2 -1
- data/src/core/lib/transport/transport.h +5 -1
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +9 -2
- data/src/core/tsi/ssl_transport_security.cc +35 -24
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +1 -1
- data/src/ruby/lib/grpc/generic/rpc_server.rb +61 -0
- data/src/ruby/lib/grpc/generic/service.rb +1 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/grpc/health/checker.rb +2 -3
- data/src/ruby/spec/generic/rpc_server_spec.rb +22 -0
- data/src/ruby/spec/support/services.rb +1 -0
- metadata +37 -32
- data/src/core/ext/filters/client_channel/lb_policy_factory.cc +0 -163
@@ -54,46 +54,91 @@ void grpc_auth_refresh_token_destruct(grpc_auth_refresh_token* refresh_token);
|
|
54
54
|
// This object is a base for credentials that need to acquire an oauth2 token
|
55
55
|
// from an http service.
|
56
56
|
|
57
|
-
|
58
|
-
grpc_httpcli_context* http_context,
|
59
|
-
grpc_polling_entity* pollent,
|
60
|
-
grpc_iomgr_cb_func cb,
|
61
|
-
grpc_millis deadline);
|
62
|
-
|
63
|
-
typedef struct grpc_oauth2_pending_get_request_metadata {
|
57
|
+
struct grpc_oauth2_pending_get_request_metadata {
|
64
58
|
grpc_credentials_mdelem_array* md_array;
|
65
59
|
grpc_closure* on_request_metadata;
|
66
60
|
grpc_polling_entity* pollent;
|
67
61
|
struct grpc_oauth2_pending_get_request_metadata* next;
|
68
|
-
}
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
bool
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
62
|
+
};
|
63
|
+
|
64
|
+
class grpc_oauth2_token_fetcher_credentials : public grpc_call_credentials {
|
65
|
+
public:
|
66
|
+
grpc_oauth2_token_fetcher_credentials();
|
67
|
+
~grpc_oauth2_token_fetcher_credentials() override;
|
68
|
+
|
69
|
+
bool get_request_metadata(grpc_polling_entity* pollent,
|
70
|
+
grpc_auth_metadata_context context,
|
71
|
+
grpc_credentials_mdelem_array* md_array,
|
72
|
+
grpc_closure* on_request_metadata,
|
73
|
+
grpc_error** error) override;
|
74
|
+
|
75
|
+
void cancel_get_request_metadata(grpc_credentials_mdelem_array* md_array,
|
76
|
+
grpc_error* error) override;
|
77
|
+
|
78
|
+
void on_http_response(grpc_credentials_metadata_request* r,
|
79
|
+
grpc_error* error);
|
80
|
+
|
81
|
+
GRPC_ABSTRACT_BASE_CLASS
|
82
|
+
|
83
|
+
protected:
|
84
|
+
virtual void fetch_oauth2(grpc_credentials_metadata_request* req,
|
85
|
+
grpc_httpcli_context* httpcli_context,
|
86
|
+
grpc_polling_entity* pollent, grpc_iomgr_cb_func cb,
|
87
|
+
grpc_millis deadline) GRPC_ABSTRACT;
|
88
|
+
|
89
|
+
private:
|
90
|
+
gpr_mu mu_;
|
91
|
+
grpc_mdelem access_token_md_ = GRPC_MDNULL;
|
92
|
+
gpr_timespec token_expiration_;
|
93
|
+
bool token_fetch_pending_ = false;
|
94
|
+
grpc_oauth2_pending_get_request_metadata* pending_requests_ = nullptr;
|
95
|
+
grpc_httpcli_context httpcli_context_;
|
96
|
+
grpc_polling_entity pollent_;
|
97
|
+
};
|
81
98
|
|
82
99
|
// Google refresh token credentials.
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
100
|
+
class grpc_google_refresh_token_credentials final
|
101
|
+
: public grpc_oauth2_token_fetcher_credentials {
|
102
|
+
public:
|
103
|
+
grpc_google_refresh_token_credentials(grpc_auth_refresh_token refresh_token);
|
104
|
+
~grpc_google_refresh_token_credentials() override;
|
105
|
+
|
106
|
+
const grpc_auth_refresh_token& refresh_token() const {
|
107
|
+
return refresh_token_;
|
108
|
+
}
|
109
|
+
|
110
|
+
protected:
|
111
|
+
void fetch_oauth2(grpc_credentials_metadata_request* req,
|
112
|
+
grpc_httpcli_context* httpcli_context,
|
113
|
+
grpc_polling_entity* pollent, grpc_iomgr_cb_func cb,
|
114
|
+
grpc_millis deadline) override;
|
115
|
+
|
116
|
+
private:
|
117
|
+
grpc_auth_refresh_token refresh_token_;
|
118
|
+
};
|
87
119
|
|
88
120
|
// Access token credentials.
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
121
|
+
class grpc_access_token_credentials final : public grpc_call_credentials {
|
122
|
+
public:
|
123
|
+
grpc_access_token_credentials(const char* access_token);
|
124
|
+
~grpc_access_token_credentials() override;
|
125
|
+
|
126
|
+
bool get_request_metadata(grpc_polling_entity* pollent,
|
127
|
+
grpc_auth_metadata_context context,
|
128
|
+
grpc_credentials_mdelem_array* md_array,
|
129
|
+
grpc_closure* on_request_metadata,
|
130
|
+
grpc_error** error) override;
|
131
|
+
|
132
|
+
void cancel_get_request_metadata(grpc_credentials_mdelem_array* md_array,
|
133
|
+
grpc_error* error) override;
|
134
|
+
|
135
|
+
private:
|
136
|
+
grpc_mdelem access_token_md_;
|
137
|
+
};
|
93
138
|
|
94
139
|
// Private constructor for refresh token credentials from an already parsed
|
95
140
|
// refresh token. Takes ownership of the refresh token.
|
96
|
-
grpc_call_credentials
|
141
|
+
grpc_core::RefCountedPtr<grpc_call_credentials>
|
97
142
|
grpc_refresh_token_credentials_create_from_auth_refresh_token(
|
98
143
|
grpc_auth_refresh_token token);
|
99
144
|
|
@@ -35,20 +35,17 @@
|
|
35
35
|
|
36
36
|
grpc_core::TraceFlag grpc_plugin_credentials_trace(false, "plugin_credentials");
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
if (c->plugin.state != nullptr && c->plugin.destroy != nullptr) {
|
43
|
-
c->plugin.destroy(c->plugin.state);
|
38
|
+
grpc_plugin_credentials::~grpc_plugin_credentials() {
|
39
|
+
gpr_mu_destroy(&mu_);
|
40
|
+
if (plugin_.state != nullptr && plugin_.destroy != nullptr) {
|
41
|
+
plugin_.destroy(plugin_.state);
|
44
42
|
}
|
45
43
|
}
|
46
44
|
|
47
|
-
|
48
|
-
|
49
|
-
grpc_plugin_credentials_pending_request* pending_request) {
|
45
|
+
void grpc_plugin_credentials::pending_request_remove_locked(
|
46
|
+
pending_request* pending_request) {
|
50
47
|
if (pending_request->prev == nullptr) {
|
51
|
-
|
48
|
+
pending_requests_ = pending_request->next;
|
52
49
|
} else {
|
53
50
|
pending_request->prev->next = pending_request->next;
|
54
51
|
}
|
@@ -62,17 +59,17 @@ static void pending_request_remove_locked(
|
|
62
59
|
// cancelled out from under us.
|
63
60
|
// When this returns, r->cancelled indicates whether the request was
|
64
61
|
// cancelled before completion.
|
65
|
-
|
66
|
-
|
67
|
-
gpr_mu_lock(&
|
68
|
-
if (!r->cancelled) pending_request_remove_locked(r
|
69
|
-
gpr_mu_unlock(&
|
62
|
+
void grpc_plugin_credentials::pending_request_complete(pending_request* r) {
|
63
|
+
GPR_DEBUG_ASSERT(r->creds == this);
|
64
|
+
gpr_mu_lock(&mu_);
|
65
|
+
if (!r->cancelled) pending_request_remove_locked(r);
|
66
|
+
gpr_mu_unlock(&mu_);
|
70
67
|
// Ref to credentials not needed anymore.
|
71
|
-
|
68
|
+
Unref();
|
72
69
|
}
|
73
70
|
|
74
71
|
static grpc_error* process_plugin_result(
|
75
|
-
|
72
|
+
grpc_plugin_credentials::pending_request* r, const grpc_metadata* md,
|
76
73
|
size_t num_md, grpc_status_code status, const char* error_details) {
|
77
74
|
grpc_error* error = GRPC_ERROR_NONE;
|
78
75
|
if (status != GRPC_STATUS_OK) {
|
@@ -119,8 +116,8 @@ static void plugin_md_request_metadata_ready(void* request,
|
|
119
116
|
/* called from application code */
|
120
117
|
grpc_core::ExecCtx exec_ctx(GRPC_EXEC_CTX_FLAG_IS_FINISHED |
|
121
118
|
GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP);
|
122
|
-
|
123
|
-
static_cast<
|
119
|
+
grpc_plugin_credentials::pending_request* r =
|
120
|
+
static_cast<grpc_plugin_credentials::pending_request*>(request);
|
124
121
|
if (grpc_plugin_credentials_trace.enabled()) {
|
125
122
|
gpr_log(GPR_INFO,
|
126
123
|
"plugin_credentials[%p]: request %p: plugin returned "
|
@@ -128,7 +125,7 @@ static void plugin_md_request_metadata_ready(void* request,
|
|
128
125
|
r->creds, r);
|
129
126
|
}
|
130
127
|
// Remove request from pending list if not previously cancelled.
|
131
|
-
pending_request_complete(r);
|
128
|
+
r->creds->pending_request_complete(r);
|
132
129
|
// If it has not been cancelled, process it.
|
133
130
|
if (!r->cancelled) {
|
134
131
|
grpc_error* error =
|
@@ -143,65 +140,59 @@ static void plugin_md_request_metadata_ready(void* request,
|
|
143
140
|
gpr_free(r);
|
144
141
|
}
|
145
142
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
grpc_closure* on_request_metadata,
|
151
|
-
grpc_error** error) {
|
152
|
-
grpc_plugin_credentials* c =
|
153
|
-
reinterpret_cast<grpc_plugin_credentials*>(creds);
|
143
|
+
bool grpc_plugin_credentials::get_request_metadata(
|
144
|
+
grpc_polling_entity* pollent, grpc_auth_metadata_context context,
|
145
|
+
grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata,
|
146
|
+
grpc_error** error) {
|
154
147
|
bool retval = true; // Synchronous return.
|
155
|
-
if (
|
148
|
+
if (plugin_.get_metadata != nullptr) {
|
156
149
|
// Create pending_request object.
|
157
|
-
|
158
|
-
static_cast<
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
pending_request->on_request_metadata = on_request_metadata;
|
150
|
+
pending_request* request =
|
151
|
+
static_cast<pending_request*>(gpr_zalloc(sizeof(*request)));
|
152
|
+
request->creds = this;
|
153
|
+
request->md_array = md_array;
|
154
|
+
request->on_request_metadata = on_request_metadata;
|
163
155
|
// Add it to the pending list.
|
164
|
-
gpr_mu_lock(&
|
165
|
-
if (
|
166
|
-
|
156
|
+
gpr_mu_lock(&mu_);
|
157
|
+
if (pending_requests_ != nullptr) {
|
158
|
+
pending_requests_->prev = request;
|
167
159
|
}
|
168
|
-
|
169
|
-
|
170
|
-
gpr_mu_unlock(&
|
160
|
+
request->next = pending_requests_;
|
161
|
+
pending_requests_ = request;
|
162
|
+
gpr_mu_unlock(&mu_);
|
171
163
|
// Invoke the plugin. The callback holds a ref to us.
|
172
164
|
if (grpc_plugin_credentials_trace.enabled()) {
|
173
165
|
gpr_log(GPR_INFO, "plugin_credentials[%p]: request %p: invoking plugin",
|
174
|
-
|
166
|
+
this, request);
|
175
167
|
}
|
176
|
-
|
168
|
+
Ref().release();
|
177
169
|
grpc_metadata creds_md[GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX];
|
178
170
|
size_t num_creds_md = 0;
|
179
171
|
grpc_status_code status = GRPC_STATUS_OK;
|
180
172
|
const char* error_details = nullptr;
|
181
|
-
if (!
|
182
|
-
|
183
|
-
|
184
|
-
&status, &error_details)) {
|
173
|
+
if (!plugin_.get_metadata(
|
174
|
+
plugin_.state, context, plugin_md_request_metadata_ready, request,
|
175
|
+
creds_md, &num_creds_md, &status, &error_details)) {
|
185
176
|
if (grpc_plugin_credentials_trace.enabled()) {
|
186
177
|
gpr_log(GPR_INFO,
|
187
178
|
"plugin_credentials[%p]: request %p: plugin will return "
|
188
179
|
"asynchronously",
|
189
|
-
|
180
|
+
this, request);
|
190
181
|
}
|
191
182
|
return false; // Asynchronous return.
|
192
183
|
}
|
193
184
|
// Returned synchronously.
|
194
185
|
// Remove request from pending list if not previously cancelled.
|
195
|
-
pending_request_complete(
|
186
|
+
request->creds->pending_request_complete(request);
|
196
187
|
// If the request was cancelled, the error will have been returned
|
197
188
|
// asynchronously by plugin_cancel_get_request_metadata(), so return
|
198
189
|
// false. Otherwise, process the result.
|
199
|
-
if (
|
190
|
+
if (request->cancelled) {
|
200
191
|
if (grpc_plugin_credentials_trace.enabled()) {
|
201
192
|
gpr_log(GPR_INFO,
|
202
193
|
"plugin_credentials[%p]: request %p was cancelled, error "
|
203
194
|
"will be returned asynchronously",
|
204
|
-
|
195
|
+
this, request);
|
205
196
|
}
|
206
197
|
retval = false;
|
207
198
|
} else {
|
@@ -209,10 +200,10 @@ static bool plugin_get_request_metadata(grpc_call_credentials* creds,
|
|
209
200
|
gpr_log(GPR_INFO,
|
210
201
|
"plugin_credentials[%p]: request %p: plugin returned "
|
211
202
|
"synchronously",
|
212
|
-
|
203
|
+
this, request);
|
213
204
|
}
|
214
|
-
*error = process_plugin_result(
|
215
|
-
|
205
|
+
*error = process_plugin_result(request, creds_md, num_creds_md, status,
|
206
|
+
error_details);
|
216
207
|
}
|
217
208
|
// Clean up.
|
218
209
|
for (size_t i = 0; i < num_creds_md; ++i) {
|
@@ -220,51 +211,42 @@ static bool plugin_get_request_metadata(grpc_call_credentials* creds,
|
|
220
211
|
grpc_slice_unref_internal(creds_md[i].value);
|
221
212
|
}
|
222
213
|
gpr_free((void*)error_details);
|
223
|
-
gpr_free(
|
214
|
+
gpr_free(request);
|
224
215
|
}
|
225
216
|
return retval;
|
226
217
|
}
|
227
218
|
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
reinterpret_cast<grpc_plugin_credentials*>(creds);
|
233
|
-
gpr_mu_lock(&c->mu);
|
234
|
-
for (grpc_plugin_credentials_pending_request* pending_request =
|
235
|
-
c->pending_requests;
|
219
|
+
void grpc_plugin_credentials::cancel_get_request_metadata(
|
220
|
+
grpc_credentials_mdelem_array* md_array, grpc_error* error) {
|
221
|
+
gpr_mu_lock(&mu_);
|
222
|
+
for (pending_request* pending_request = pending_requests_;
|
236
223
|
pending_request != nullptr; pending_request = pending_request->next) {
|
237
224
|
if (pending_request->md_array == md_array) {
|
238
225
|
if (grpc_plugin_credentials_trace.enabled()) {
|
239
|
-
gpr_log(GPR_INFO, "plugin_credentials[%p]: cancelling request %p",
|
226
|
+
gpr_log(GPR_INFO, "plugin_credentials[%p]: cancelling request %p", this,
|
240
227
|
pending_request);
|
241
228
|
}
|
242
229
|
pending_request->cancelled = true;
|
243
230
|
GRPC_CLOSURE_SCHED(pending_request->on_request_metadata,
|
244
231
|
GRPC_ERROR_REF(error));
|
245
|
-
pending_request_remove_locked(
|
232
|
+
pending_request_remove_locked(pending_request);
|
246
233
|
break;
|
247
234
|
}
|
248
235
|
}
|
249
|
-
gpr_mu_unlock(&
|
236
|
+
gpr_mu_unlock(&mu_);
|
250
237
|
GRPC_ERROR_UNREF(error);
|
251
238
|
}
|
252
239
|
|
253
|
-
|
254
|
-
|
255
|
-
|
240
|
+
grpc_plugin_credentials::grpc_plugin_credentials(
|
241
|
+
grpc_metadata_credentials_plugin plugin)
|
242
|
+
: grpc_call_credentials(plugin.type), plugin_(plugin) {
|
243
|
+
gpr_mu_init(&mu_);
|
244
|
+
}
|
256
245
|
|
257
246
|
grpc_call_credentials* grpc_metadata_credentials_create_from_plugin(
|
258
247
|
grpc_metadata_credentials_plugin plugin, void* reserved) {
|
259
|
-
grpc_plugin_credentials* c =
|
260
|
-
static_cast<grpc_plugin_credentials*>(gpr_zalloc(sizeof(*c)));
|
261
248
|
GRPC_API_TRACE("grpc_metadata_credentials_create_from_plugin(reserved=%p)", 1,
|
262
249
|
(reserved));
|
263
250
|
GPR_ASSERT(reserved == nullptr);
|
264
|
-
|
265
|
-
c->base.vtable = &plugin_vtable;
|
266
|
-
gpr_ref_init(&c->base.refcount, 1);
|
267
|
-
c->plugin = plugin;
|
268
|
-
gpr_mu_init(&c->mu);
|
269
|
-
return &c->base;
|
251
|
+
return grpc_core::New<grpc_plugin_credentials>(plugin);
|
270
252
|
}
|
@@ -25,22 +25,45 @@
|
|
25
25
|
|
26
26
|
extern grpc_core::TraceFlag grpc_plugin_credentials_trace;
|
27
27
|
|
28
|
-
struct
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
28
|
+
// This type is forward declared as a C struct and we cannot define it as a
|
29
|
+
// class. Otherwise, compiler will complain about type mismatch due to
|
30
|
+
// -Wmismatched-tags.
|
31
|
+
struct grpc_plugin_credentials final : public grpc_call_credentials {
|
32
|
+
public:
|
33
|
+
struct pending_request {
|
34
|
+
bool cancelled;
|
35
|
+
struct grpc_plugin_credentials* creds;
|
36
|
+
grpc_credentials_mdelem_array* md_array;
|
37
|
+
grpc_closure* on_request_metadata;
|
38
|
+
struct pending_request* prev;
|
39
|
+
struct pending_request* next;
|
40
|
+
};
|
41
|
+
|
42
|
+
explicit grpc_plugin_credentials(grpc_metadata_credentials_plugin plugin);
|
43
|
+
~grpc_plugin_credentials() override;
|
44
|
+
|
45
|
+
bool get_request_metadata(grpc_polling_entity* pollent,
|
46
|
+
grpc_auth_metadata_context context,
|
47
|
+
grpc_credentials_mdelem_array* md_array,
|
48
|
+
grpc_closure* on_request_metadata,
|
49
|
+
grpc_error** error) override;
|
50
|
+
|
51
|
+
void cancel_get_request_metadata(grpc_credentials_mdelem_array* md_array,
|
52
|
+
grpc_error* error) override;
|
53
|
+
|
54
|
+
// Checks if the request has been cancelled.
|
55
|
+
// If not, removes it from the pending list, so that it cannot be
|
56
|
+
// cancelled out from under us.
|
57
|
+
// When this returns, r->cancelled indicates whether the request was
|
58
|
+
// cancelled before completion.
|
59
|
+
void pending_request_complete(pending_request* r);
|
60
|
+
|
61
|
+
private:
|
62
|
+
void pending_request_remove_locked(pending_request* pending_request);
|
63
|
+
|
64
|
+
grpc_metadata_credentials_plugin plugin_;
|
65
|
+
gpr_mu mu_;
|
66
|
+
pending_request* pending_requests_ = nullptr;
|
67
|
+
};
|
45
68
|
|
46
69
|
#endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_PLUGIN_PLUGIN_CREDENTIALS_H */
|
@@ -44,22 +44,27 @@ void grpc_tsi_ssl_pem_key_cert_pairs_destroy(tsi_ssl_pem_key_cert_pair* kp,
|
|
44
44
|
gpr_free(kp);
|
45
45
|
}
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
47
|
+
grpc_ssl_credentials::grpc_ssl_credentials(
|
48
|
+
const char* pem_root_certs, grpc_ssl_pem_key_cert_pair* pem_key_cert_pair,
|
49
|
+
const verify_peer_options* verify_options)
|
50
|
+
: grpc_channel_credentials(GRPC_CHANNEL_CREDENTIALS_TYPE_SSL) {
|
51
|
+
build_config(pem_root_certs, pem_key_cert_pair, verify_options);
|
52
|
+
}
|
53
|
+
|
54
|
+
grpc_ssl_credentials::~grpc_ssl_credentials() {
|
55
|
+
gpr_free(config_.pem_root_certs);
|
56
|
+
grpc_tsi_ssl_pem_key_cert_pairs_destroy(config_.pem_key_cert_pair, 1);
|
57
|
+
if (config_.verify_options.verify_peer_destruct != nullptr) {
|
58
|
+
config_.verify_options.verify_peer_destruct(
|
59
|
+
config_.verify_options.verify_peer_callback_userdata);
|
54
60
|
}
|
55
61
|
}
|
56
62
|
|
57
|
-
|
58
|
-
|
63
|
+
grpc_core::RefCountedPtr<grpc_channel_security_connector>
|
64
|
+
grpc_ssl_credentials::create_security_connector(
|
65
|
+
grpc_core::RefCountedPtr<grpc_call_credentials> call_creds,
|
59
66
|
const char* target, const grpc_channel_args* args,
|
60
|
-
|
61
|
-
grpc_ssl_credentials* c = reinterpret_cast<grpc_ssl_credentials*>(creds);
|
62
|
-
grpc_security_status status = GRPC_SECURITY_OK;
|
67
|
+
grpc_channel_args** new_args) {
|
63
68
|
const char* overridden_target_name = nullptr;
|
64
69
|
tsi_ssl_session_cache* ssl_session_cache = nullptr;
|
65
70
|
for (size_t i = 0; args && i < args->num_args; i++) {
|
@@ -74,52 +79,47 @@ static grpc_security_status ssl_create_security_connector(
|
|
74
79
|
static_cast<tsi_ssl_session_cache*>(arg->value.pointer.p);
|
75
80
|
}
|
76
81
|
}
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
+
grpc_core::RefCountedPtr<grpc_channel_security_connector> sc =
|
83
|
+
grpc_ssl_channel_security_connector_create(
|
84
|
+
this->Ref(), std::move(call_creds), &config_, target,
|
85
|
+
overridden_target_name, ssl_session_cache);
|
86
|
+
if (sc == nullptr) {
|
87
|
+
return sc;
|
82
88
|
}
|
83
89
|
grpc_arg new_arg = grpc_channel_arg_string_create(
|
84
90
|
(char*)GRPC_ARG_HTTP2_SCHEME, (char*)"https");
|
85
91
|
*new_args = grpc_channel_args_copy_and_add(args, &new_arg, 1);
|
86
|
-
return
|
92
|
+
return sc;
|
87
93
|
}
|
88
94
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
grpc_ssl_pem_key_cert_pair* pem_key_cert_pair,
|
94
|
-
const verify_peer_options* verify_options,
|
95
|
-
grpc_ssl_config* config) {
|
96
|
-
if (pem_root_certs != nullptr) {
|
97
|
-
config->pem_root_certs = gpr_strdup(pem_root_certs);
|
98
|
-
}
|
95
|
+
void grpc_ssl_credentials::build_config(
|
96
|
+
const char* pem_root_certs, grpc_ssl_pem_key_cert_pair* pem_key_cert_pair,
|
97
|
+
const verify_peer_options* verify_options) {
|
98
|
+
config_.pem_root_certs = gpr_strdup(pem_root_certs);
|
99
99
|
if (pem_key_cert_pair != nullptr) {
|
100
100
|
GPR_ASSERT(pem_key_cert_pair->private_key != nullptr);
|
101
101
|
GPR_ASSERT(pem_key_cert_pair->cert_chain != nullptr);
|
102
|
-
|
102
|
+
config_.pem_key_cert_pair = static_cast<tsi_ssl_pem_key_cert_pair*>(
|
103
103
|
gpr_zalloc(sizeof(tsi_ssl_pem_key_cert_pair)));
|
104
|
-
|
104
|
+
config_.pem_key_cert_pair->cert_chain =
|
105
105
|
gpr_strdup(pem_key_cert_pair->cert_chain);
|
106
|
-
|
106
|
+
config_.pem_key_cert_pair->private_key =
|
107
107
|
gpr_strdup(pem_key_cert_pair->private_key);
|
108
|
+
} else {
|
109
|
+
config_.pem_key_cert_pair = nullptr;
|
108
110
|
}
|
109
111
|
if (verify_options != nullptr) {
|
110
|
-
memcpy(&
|
112
|
+
memcpy(&config_.verify_options, verify_options,
|
111
113
|
sizeof(verify_peer_options));
|
112
114
|
} else {
|
113
115
|
// Otherwise set all options to default values
|
114
|
-
memset(&
|
116
|
+
memset(&config_.verify_options, 0, sizeof(verify_peer_options));
|
115
117
|
}
|
116
118
|
}
|
117
119
|
|
118
120
|
grpc_channel_credentials* grpc_ssl_credentials_create(
|
119
121
|
const char* pem_root_certs, grpc_ssl_pem_key_cert_pair* pem_key_cert_pair,
|
120
122
|
const verify_peer_options* verify_options, void* reserved) {
|
121
|
-
grpc_ssl_credentials* c = static_cast<grpc_ssl_credentials*>(
|
122
|
-
gpr_zalloc(sizeof(grpc_ssl_credentials)));
|
123
123
|
GRPC_API_TRACE(
|
124
124
|
"grpc_ssl_credentials_create(pem_root_certs=%s, "
|
125
125
|
"pem_key_cert_pair=%p, "
|
@@ -127,12 +127,9 @@ grpc_channel_credentials* grpc_ssl_credentials_create(
|
|
127
127
|
"reserved=%p)",
|
128
128
|
4, (pem_root_certs, pem_key_cert_pair, verify_options, reserved));
|
129
129
|
GPR_ASSERT(reserved == nullptr);
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
ssl_build_config(pem_root_certs, pem_key_cert_pair, verify_options,
|
134
|
-
&c->config);
|
135
|
-
return &c->base;
|
130
|
+
|
131
|
+
return grpc_core::New<grpc_ssl_credentials>(pem_root_certs, pem_key_cert_pair,
|
132
|
+
verify_options);
|
136
133
|
}
|
137
134
|
|
138
135
|
//
|
@@ -145,21 +142,29 @@ struct grpc_ssl_server_credentials_options {
|
|
145
142
|
grpc_ssl_server_certificate_config_fetcher* certificate_config_fetcher;
|
146
143
|
};
|
147
144
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
145
|
+
grpc_ssl_server_credentials::grpc_ssl_server_credentials(
|
146
|
+
const grpc_ssl_server_credentials_options& options)
|
147
|
+
: grpc_server_credentials(GRPC_CHANNEL_CREDENTIALS_TYPE_SSL) {
|
148
|
+
if (options.certificate_config_fetcher != nullptr) {
|
149
|
+
config_.client_certificate_request = options.client_certificate_request;
|
150
|
+
certificate_config_fetcher_ = *options.certificate_config_fetcher;
|
151
|
+
} else {
|
152
|
+
build_config(options.certificate_config->pem_root_certs,
|
153
|
+
options.certificate_config->pem_key_cert_pairs,
|
154
|
+
options.certificate_config->num_key_cert_pairs,
|
155
|
+
options.client_certificate_request);
|
156
|
+
}
|
154
157
|
}
|
155
158
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
+
grpc_ssl_server_credentials::~grpc_ssl_server_credentials() {
|
160
|
+
grpc_tsi_ssl_pem_key_cert_pairs_destroy(config_.pem_key_cert_pairs,
|
161
|
+
config_.num_key_cert_pairs);
|
162
|
+
gpr_free(config_.pem_root_certs);
|
163
|
+
}
|
164
|
+
grpc_core::RefCountedPtr<grpc_server_security_connector>
|
165
|
+
grpc_ssl_server_credentials::create_security_connector() {
|
166
|
+
return grpc_ssl_server_security_connector_create(this->Ref());
|
159
167
|
}
|
160
|
-
|
161
|
-
static grpc_server_credentials_vtable ssl_server_vtable = {
|
162
|
-
ssl_server_destruct, ssl_server_create_security_connector};
|
163
168
|
|
164
169
|
tsi_ssl_pem_key_cert_pair* grpc_convert_grpc_to_tsi_cert_pairs(
|
165
170
|
const grpc_ssl_pem_key_cert_pair* pem_key_cert_pairs,
|
@@ -179,18 +184,15 @@ tsi_ssl_pem_key_cert_pair* grpc_convert_grpc_to_tsi_cert_pairs(
|
|
179
184
|
return tsi_pairs;
|
180
185
|
}
|
181
186
|
|
182
|
-
|
187
|
+
void grpc_ssl_server_credentials::build_config(
|
183
188
|
const char* pem_root_certs, grpc_ssl_pem_key_cert_pair* pem_key_cert_pairs,
|
184
189
|
size_t num_key_cert_pairs,
|
185
|
-
grpc_ssl_client_certificate_request_type client_certificate_request
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
config->pem_root_certs = gpr_strdup(pem_root_certs);
|
190
|
-
}
|
191
|
-
config->pem_key_cert_pairs = grpc_convert_grpc_to_tsi_cert_pairs(
|
190
|
+
grpc_ssl_client_certificate_request_type client_certificate_request) {
|
191
|
+
config_.client_certificate_request = client_certificate_request;
|
192
|
+
config_.pem_root_certs = gpr_strdup(pem_root_certs);
|
193
|
+
config_.pem_key_cert_pairs = grpc_convert_grpc_to_tsi_cert_pairs(
|
192
194
|
pem_key_cert_pairs, num_key_cert_pairs);
|
193
|
-
|
195
|
+
config_.num_key_cert_pairs = num_key_cert_pairs;
|
194
196
|
}
|
195
197
|
|
196
198
|
grpc_ssl_server_certificate_config* grpc_ssl_server_certificate_config_create(
|
@@ -200,9 +202,7 @@ grpc_ssl_server_certificate_config* grpc_ssl_server_certificate_config_create(
|
|
200
202
|
grpc_ssl_server_certificate_config* config =
|
201
203
|
static_cast<grpc_ssl_server_certificate_config*>(
|
202
204
|
gpr_zalloc(sizeof(grpc_ssl_server_certificate_config)));
|
203
|
-
|
204
|
-
config->pem_root_certs = gpr_strdup(pem_root_certs);
|
205
|
-
}
|
205
|
+
config->pem_root_certs = gpr_strdup(pem_root_certs);
|
206
206
|
if (num_key_cert_pairs > 0) {
|
207
207
|
GPR_ASSERT(pem_key_cert_pairs != nullptr);
|
208
208
|
config->pem_key_cert_pairs = static_cast<grpc_ssl_pem_key_cert_pair*>(
|
@@ -311,7 +311,6 @@ grpc_server_credentials* grpc_ssl_server_credentials_create_ex(
|
|
311
311
|
grpc_server_credentials* grpc_ssl_server_credentials_create_with_options(
|
312
312
|
grpc_ssl_server_credentials_options* options) {
|
313
313
|
grpc_server_credentials* retval = nullptr;
|
314
|
-
grpc_ssl_server_credentials* c = nullptr;
|
315
314
|
|
316
315
|
if (options == nullptr) {
|
317
316
|
gpr_log(GPR_ERROR,
|
@@ -331,23 +330,7 @@ grpc_server_credentials* grpc_ssl_server_credentials_create_with_options(
|
|
331
330
|
goto done;
|
332
331
|
}
|
333
332
|
|
334
|
-
|
335
|
-
gpr_zalloc(sizeof(grpc_ssl_server_credentials)));
|
336
|
-
c->base.type = GRPC_CHANNEL_CREDENTIALS_TYPE_SSL;
|
337
|
-
gpr_ref_init(&c->base.refcount, 1);
|
338
|
-
c->base.vtable = &ssl_server_vtable;
|
339
|
-
|
340
|
-
if (options->certificate_config_fetcher != nullptr) {
|
341
|
-
c->config.client_certificate_request = options->client_certificate_request;
|
342
|
-
c->certificate_config_fetcher = *options->certificate_config_fetcher;
|
343
|
-
} else {
|
344
|
-
ssl_build_server_config(options->certificate_config->pem_root_certs,
|
345
|
-
options->certificate_config->pem_key_cert_pairs,
|
346
|
-
options->certificate_config->num_key_cert_pairs,
|
347
|
-
options->client_certificate_request, &c->config);
|
348
|
-
}
|
349
|
-
|
350
|
-
retval = &c->base;
|
333
|
+
retval = grpc_core::New<grpc_ssl_server_credentials>(*options);
|
351
334
|
|
352
335
|
done:
|
353
336
|
grpc_ssl_server_credentials_options_destroy(options);
|