grpc 1.18.0 → 1.19.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.

Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +301 -33
  3. data/include/grpc/grpc_security.h +195 -0
  4. data/include/grpc/impl/codegen/grpc_types.h +17 -1
  5. data/include/grpc/impl/codegen/port_platform.h +36 -0
  6. data/include/grpc/impl/codegen/slice.h +1 -1
  7. data/src/core/ext/filters/client_channel/channel_connectivity.cc +2 -0
  8. data/src/core/ext/filters/client_channel/client_channel.cc +74 -69
  9. data/src/core/ext/filters/client_channel/client_channel.h +2 -2
  10. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +5 -6
  11. data/src/core/ext/filters/client_channel/client_channel_channelz.h +5 -4
  12. data/src/core/ext/filters/client_channel/client_channel_factory.cc +2 -2
  13. data/src/core/ext/filters/client_channel/client_channel_factory.h +4 -4
  14. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +3 -3
  15. data/src/core/ext/filters/client_channel/global_subchannel_pool.cc +176 -0
  16. data/src/core/ext/filters/client_channel/global_subchannel_pool.h +68 -0
  17. data/src/core/ext/filters/client_channel/health/health_check_client.cc +10 -8
  18. data/src/core/ext/filters/client_channel/health/health_check_client.h +1 -1
  19. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +146 -156
  20. data/src/core/ext/filters/client_channel/lb_policy.cc +30 -1
  21. data/src/core/ext/filters/client_channel/lb_policy.h +29 -1
  22. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +28 -30
  23. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +5 -8
  24. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +5 -8
  25. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +23 -24
  26. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +80 -15
  27. data/src/core/ext/filters/client_channel/lb_policy_factory.h +6 -1
  28. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +2 -2
  29. data/src/core/ext/filters/client_channel/lb_policy_registry.h +1 -1
  30. data/src/core/ext/filters/client_channel/local_subchannel_pool.cc +96 -0
  31. data/src/core/ext/filters/client_channel/local_subchannel_pool.h +56 -0
  32. data/src/core/ext/filters/client_channel/parse_address.cc +24 -5
  33. data/src/core/ext/filters/client_channel/request_routing.cc +13 -3
  34. data/src/core/ext/filters/client_channel/request_routing.h +5 -1
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +11 -6
  36. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +2 -2
  37. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +7 -35
  38. data/src/core/ext/filters/client_channel/subchannel.cc +698 -791
  39. data/src/core/ext/filters/client_channel/subchannel.h +213 -123
  40. data/src/core/ext/filters/client_channel/subchannel_pool_interface.cc +97 -0
  41. data/src/core/ext/filters/client_channel/subchannel_pool_interface.h +94 -0
  42. data/src/core/ext/filters/http/client_authority_filter.cc +5 -2
  43. data/src/core/ext/filters/max_age/max_age_filter.cc +1 -1
  44. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +13 -12
  45. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +5 -7
  46. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +19 -27
  47. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +18 -19
  48. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +27 -6
  49. data/src/core/ext/transport/chttp2/transport/flow_control.cc +1 -1
  50. data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +3 -2
  51. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +1 -1
  52. data/src/core/ext/transport/chttp2/transport/writing.cc +8 -5
  53. data/src/core/lib/channel/handshaker.cc +141 -214
  54. data/src/core/lib/channel/handshaker.h +110 -101
  55. data/src/core/lib/channel/handshaker_factory.h +11 -19
  56. data/src/core/lib/channel/handshaker_registry.cc +64 -52
  57. data/src/core/lib/channel/handshaker_registry.h +21 -16
  58. data/src/core/lib/gpr/log_posix.cc +2 -1
  59. data/src/core/lib/gpr/time.cc +8 -0
  60. data/src/core/lib/gpr/time_posix.cc +8 -2
  61. data/src/core/lib/gprpp/optional.h +47 -0
  62. data/src/core/lib/http/httpcli_security_connector.cc +13 -14
  63. data/src/core/lib/iomgr/buffer_list.cc +182 -24
  64. data/src/core/lib/iomgr/buffer_list.h +70 -8
  65. data/src/core/lib/iomgr/combiner.cc +11 -3
  66. data/src/core/lib/iomgr/error.cc +9 -5
  67. data/src/core/lib/iomgr/ev_epoll1_linux.cc +3 -0
  68. data/src/core/lib/iomgr/ev_epollex_linux.cc +136 -162
  69. data/src/core/lib/iomgr/ev_poll_posix.cc +3 -0
  70. data/src/core/lib/iomgr/ev_posix.cc +4 -0
  71. data/src/core/lib/iomgr/ev_posix.h +4 -0
  72. data/src/core/lib/iomgr/exec_ctx.cc +1 -0
  73. data/src/core/lib/iomgr/exec_ctx.h +137 -8
  74. data/src/core/lib/iomgr/executor.cc +122 -87
  75. data/src/core/lib/iomgr/executor.h +53 -48
  76. data/src/core/lib/iomgr/fork_posix.cc +6 -4
  77. data/src/core/lib/iomgr/{network_status_tracker.cc → grpc_if_nametoindex.h} +8 -14
  78. data/src/core/lib/iomgr/grpc_if_nametoindex_posix.cc +42 -0
  79. data/src/core/lib/iomgr/{network_status_tracker.h → grpc_if_nametoindex_unsupported.cc} +15 -9
  80. data/src/core/lib/iomgr/internal_errqueue.h +105 -3
  81. data/src/core/lib/iomgr/iomgr.cc +6 -5
  82. data/src/core/lib/iomgr/iomgr.h +8 -0
  83. data/src/core/lib/iomgr/iomgr_custom.cc +6 -2
  84. data/src/core/lib/iomgr/iomgr_internal.cc +4 -0
  85. data/src/core/lib/iomgr/iomgr_internal.h +4 -0
  86. data/src/core/lib/iomgr/iomgr_posix.cc +10 -1
  87. data/src/core/lib/iomgr/iomgr_windows.cc +8 -1
  88. data/src/core/lib/iomgr/port.h +1 -0
  89. data/src/core/lib/iomgr/resolve_address_posix.cc +4 -3
  90. data/src/core/lib/iomgr/resolve_address_windows.cc +2 -1
  91. data/src/core/lib/iomgr/tcp_custom.cc +0 -4
  92. data/src/core/lib/iomgr/tcp_posix.cc +58 -44
  93. data/src/core/lib/iomgr/tcp_uv.cc +0 -1
  94. data/src/core/lib/iomgr/tcp_windows.cc +0 -4
  95. data/src/core/lib/iomgr/timer_manager.cc +8 -0
  96. data/src/core/lib/iomgr/udp_server.cc +6 -4
  97. data/src/core/lib/json/json.cc +1 -4
  98. data/src/core/lib/security/credentials/alts/alts_credentials.cc +1 -1
  99. data/src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc +2 -2
  100. data/src/core/lib/security/credentials/composite/composite_credentials.h +4 -0
  101. data/src/core/lib/security/credentials/credentials.h +9 -1
  102. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +15 -2
  103. data/src/core/lib/security/credentials/google_default/google_default_credentials.h +2 -0
  104. data/src/core/lib/security/credentials/jwt/json_token.cc +1 -1
  105. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +1 -0
  106. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +3 -2
  107. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +2 -2
  108. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +1 -0
  109. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +192 -0
  110. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +213 -0
  111. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +10 -8
  112. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +6 -10
  113. data/src/core/lib/security/security_connector/local/local_security_connector.cc +10 -8
  114. data/src/core/lib/security/security_connector/security_connector.h +2 -2
  115. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +4 -6
  116. data/src/core/lib/security/security_connector/ssl_utils.h +33 -0
  117. data/src/core/lib/security/transport/security_handshaker.cc +267 -300
  118. data/src/core/lib/security/transport/security_handshaker.h +11 -2
  119. data/src/core/lib/security/transport/server_auth_filter.cc +1 -0
  120. data/src/core/lib/surface/call.cc +5 -1
  121. data/src/core/lib/surface/channel_init.h +5 -0
  122. data/src/core/lib/surface/completion_queue.cc +4 -7
  123. data/src/core/lib/surface/init.cc +5 -3
  124. data/src/core/lib/surface/init_secure.cc +1 -1
  125. data/src/core/lib/surface/server.cc +19 -17
  126. data/src/core/lib/surface/version.cc +1 -1
  127. data/src/core/lib/transport/service_config.h +1 -0
  128. data/src/core/lib/transport/static_metadata.cc +279 -279
  129. data/src/core/lib/transport/transport.cc +5 -3
  130. data/src/core/tsi/ssl_transport_security.cc +10 -4
  131. data/src/ruby/ext/grpc/extconf.rb +12 -4
  132. data/src/ruby/ext/grpc/rb_call_credentials.c +8 -5
  133. data/src/ruby/ext/grpc/rb_channel.c +14 -10
  134. data/src/ruby/ext/grpc/rb_channel_credentials.c +8 -4
  135. data/src/ruby/ext/grpc/rb_compression_options.c +9 -7
  136. data/src/ruby/ext/grpc/rb_event_thread.c +2 -0
  137. data/src/ruby/ext/grpc/rb_grpc.c +22 -23
  138. data/src/ruby/ext/grpc/rb_grpc.h +4 -2
  139. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +18 -0
  140. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +27 -0
  141. data/src/ruby/ext/grpc/rb_server.c +8 -4
  142. data/src/ruby/lib/grpc/version.rb +1 -1
  143. metadata +46 -39
  144. data/src/core/ext/filters/client_channel/subchannel_index.cc +0 -248
  145. data/src/core/ext/filters/client_channel/subchannel_index.h +0 -76
  146. data/src/core/lib/channel/handshaker_factory.cc +0 -42
@@ -481,8 +481,9 @@ void GrpcUdpListener::OnRead(grpc_error* error, void* do_read_arg) {
481
481
  if (udp_handler_->Read()) {
482
482
  /* There maybe more packets to read. Schedule read_more_cb_ closure to run
483
483
  * after finishing this event loop. */
484
- GRPC_CLOSURE_INIT(&do_read_closure_, do_read, do_read_arg,
485
- grpc_executor_scheduler(GRPC_EXECUTOR_LONG));
484
+ GRPC_CLOSURE_INIT(
485
+ &do_read_closure_, do_read, do_read_arg,
486
+ grpc_core::Executor::Scheduler(grpc_core::ExecutorJobType::LONG));
486
487
  GRPC_CLOSURE_SCHED(&do_read_closure_, GRPC_ERROR_NONE);
487
488
  } else {
488
489
  /* Finish reading all the packets, re-arm the notification event so we can
@@ -542,8 +543,9 @@ void GrpcUdpListener::OnCanWrite(grpc_error* error, void* do_write_arg) {
542
543
  }
543
544
 
544
545
  /* Schedule actual write in another thread. */
545
- GRPC_CLOSURE_INIT(&do_write_closure_, do_write, do_write_arg,
546
- grpc_executor_scheduler(GRPC_EXECUTOR_LONG));
546
+ GRPC_CLOSURE_INIT(
547
+ &do_write_closure_, do_write, do_write_arg,
548
+ grpc_core::Executor::Scheduler(grpc_core::ExecutorJobType::LONG));
547
549
 
548
550
  GRPC_CLOSURE_SCHED(&do_write_closure_, GRPC_ERROR_NONE);
549
551
  }
@@ -35,24 +35,21 @@ grpc_json* grpc_json_create(grpc_json_type type) {
35
35
  }
36
36
 
37
37
  void grpc_json_destroy(grpc_json* json) {
38
+ if (json == nullptr) return;
38
39
  while (json->child) {
39
40
  grpc_json_destroy(json->child);
40
41
  }
41
-
42
42
  if (json->next) {
43
43
  json->next->prev = json->prev;
44
44
  }
45
-
46
45
  if (json->prev) {
47
46
  json->prev->next = json->next;
48
47
  } else if (json->parent) {
49
48
  json->parent->child = json->next;
50
49
  }
51
-
52
50
  if (json->owns_value) {
53
51
  gpr_free((void*)json->value);
54
52
  }
55
-
56
53
  gpr_free(json);
57
54
  }
58
55
 
@@ -31,7 +31,7 @@
31
31
  #include "src/core/lib/security/security_connector/alts/alts_security_connector.h"
32
32
 
33
33
  #define GRPC_CREDENTIALS_TYPE_ALTS "Alts"
34
- #define GRPC_ALTS_HANDSHAKER_SERVICE_URL "metadata.google.internal:8080"
34
+ #define GRPC_ALTS_HANDSHAKER_SERVICE_URL "metadata.google.internal.:8080"
35
35
 
36
36
  grpc_alts_credentials::grpc_alts_credentials(
37
37
  const grpc_alts_credentials_options* options,
@@ -25,8 +25,8 @@
25
25
  #include <grpc/support/log.h>
26
26
 
27
27
  bool grpc_alts_is_running_on_gcp() {
28
- gpr_log(GPR_ERROR,
29
- "Platforms other than Linux and Windows are not supported");
28
+ gpr_log(GPR_INFO,
29
+ "ALTS: Platforms other than Linux and Windows are not supported");
30
30
  return false;
31
31
  }
32
32
 
@@ -49,6 +49,10 @@ class grpc_composite_channel_credentials : public grpc_channel_credentials {
49
49
  const char* target, const grpc_channel_args* args,
50
50
  grpc_channel_args** new_args) override;
51
51
 
52
+ grpc_channel_args* update_arguments(grpc_channel_args* args) override {
53
+ return inner_creds_->update_arguments(args);
54
+ }
55
+
52
56
  const grpc_channel_credentials* inner_creds() const {
53
57
  return inner_creds_.get();
54
58
  }
@@ -60,7 +60,7 @@ typedef enum {
60
60
 
61
61
  #define GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS 60
62
62
 
63
- #define GRPC_COMPUTE_ENGINE_METADATA_HOST "metadata.google.internal"
63
+ #define GRPC_COMPUTE_ENGINE_METADATA_HOST "metadata.google.internal."
64
64
  #define GRPC_COMPUTE_ENGINE_METADATA_TOKEN_PATH \
65
65
  "/computeMetadata/v1/instance/service-accounts/default/token"
66
66
 
@@ -123,6 +123,14 @@ struct grpc_channel_credentials
123
123
  return Ref();
124
124
  }
125
125
 
126
+ // Allows credentials to optionally modify a parent channel's args.
127
+ // By default, leave channel args as is. The callee takes ownership
128
+ // of the passed-in channel args, and the caller takes ownership
129
+ // of the returned channel args.
130
+ virtual grpc_channel_args* update_arguments(grpc_channel_args* args) {
131
+ return args;
132
+ }
133
+
126
134
  const char* type() const { return type_; }
127
135
 
128
136
  GRPC_ABSTRACT_BASE_CLASS
@@ -46,7 +46,7 @@
46
46
 
47
47
  /* -- Constants. -- */
48
48
 
49
- #define GRPC_COMPUTE_ENGINE_DETECTION_HOST "metadata.google.internal"
49
+ #define GRPC_COMPUTE_ENGINE_DETECTION_HOST "metadata.google.internal."
50
50
 
51
51
  /* -- Default credentials. -- */
52
52
 
@@ -114,6 +114,19 @@ grpc_google_default_channel_credentials::create_security_connector(
114
114
  return sc;
115
115
  }
116
116
 
117
+ grpc_channel_args* grpc_google_default_channel_credentials::update_arguments(
118
+ grpc_channel_args* args) {
119
+ grpc_channel_args* updated = args;
120
+ if (grpc_channel_args_find(args, GRPC_ARG_DNS_ENABLE_SRV_QUERIES) ==
121
+ nullptr) {
122
+ grpc_arg new_srv_arg = grpc_channel_arg_integer_create(
123
+ const_cast<char*>(GRPC_ARG_DNS_ENABLE_SRV_QUERIES), true);
124
+ updated = grpc_channel_args_copy_and_add(args, &new_srv_arg, 1);
125
+ grpc_channel_args_destroy(args);
126
+ }
127
+ return updated;
128
+ }
129
+
117
130
  static void on_metadata_server_detection_http_response(void* user_data,
118
131
  grpc_error* error) {
119
132
  metadata_server_detector* detector =
@@ -259,7 +272,7 @@ end:
259
272
  GPR_ASSERT((result == nullptr) + (error == GRPC_ERROR_NONE) == 1);
260
273
  if (creds_path != nullptr) gpr_free(creds_path);
261
274
  grpc_slice_unref_internal(creds_data);
262
- if (json != nullptr) grpc_json_destroy(json);
275
+ grpc_json_destroy(json);
263
276
  *creds = result;
264
277
  return error;
265
278
  }
@@ -58,6 +58,8 @@ class grpc_google_default_channel_credentials
58
58
  const char* target, const grpc_channel_args* args,
59
59
  grpc_channel_args** new_args) override;
60
60
 
61
+ grpc_channel_args* update_arguments(grpc_channel_args* args) override;
62
+
61
63
  const grpc_channel_credentials* alts_creds() const {
62
64
  return alts_creds_.get();
63
65
  }
@@ -121,7 +121,7 @@ grpc_auth_json_key grpc_auth_json_key_create_from_string(
121
121
  char* scratchpad = gpr_strdup(json_string);
122
122
  grpc_json* json = grpc_json_parse_string(scratchpad);
123
123
  grpc_auth_json_key result = grpc_auth_json_key_create_from_json(json);
124
- if (json != nullptr) grpc_json_destroy(json);
124
+ grpc_json_destroy(json);
125
125
  gpr_free(scratchpad);
126
126
  return result;
127
127
  }
@@ -174,6 +174,7 @@ grpc_call_credentials* grpc_service_account_jwt_access_credentials_create(
174
174
  gpr_free(clean_json);
175
175
  }
176
176
  GPR_ASSERT(reserved == nullptr);
177
+ grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
177
178
  grpc_core::ExecCtx exec_ctx;
178
179
  return grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
179
180
  grpc_auth_json_key_create_from_string(json_key), token_lifetime)
@@ -353,6 +353,7 @@ static verifier_cb_ctx* verifier_cb_ctx_create(
353
353
  grpc_jwt_claims* claims, const char* audience, grpc_slice signature,
354
354
  const char* signed_jwt, size_t signed_jwt_len, void* user_data,
355
355
  grpc_jwt_verification_done_cb cb) {
356
+ grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
356
357
  grpc_core::ExecCtx exec_ctx;
357
358
  verifier_cb_ctx* ctx =
358
359
  static_cast<verifier_cb_ctx*>(gpr_zalloc(sizeof(verifier_cb_ctx)));
@@ -666,7 +667,7 @@ static void on_keys_retrieved(void* user_data, grpc_error* error) {
666
667
  }
667
668
 
668
669
  end:
669
- if (json != nullptr) grpc_json_destroy(json);
670
+ grpc_json_destroy(json);
670
671
  EVP_PKEY_free(verification_key);
671
672
  ctx->user_cb(ctx->user_data, status, claims);
672
673
  verifier_cb_ctx_destroy(ctx);
@@ -719,7 +720,7 @@ static void on_openid_config_retrieved(void* user_data, grpc_error* error) {
719
720
  return;
720
721
 
721
722
  error:
722
- if (json != nullptr) grpc_json_destroy(json);
723
+ grpc_json_destroy(json);
723
724
  ctx->user_cb(ctx->user_data, GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR, nullptr);
724
725
  verifier_cb_ctx_destroy(ctx);
725
726
  }
@@ -80,7 +80,7 @@ grpc_auth_refresh_token grpc_auth_refresh_token_create_from_string(
80
80
  grpc_json* json = grpc_json_parse_string(scratchpad);
81
81
  grpc_auth_refresh_token result =
82
82
  grpc_auth_refresh_token_create_from_json(json);
83
- if (json != nullptr) grpc_json_destroy(json);
83
+ grpc_json_destroy(json);
84
84
  gpr_free(scratchpad);
85
85
  return result;
86
86
  }
@@ -199,7 +199,7 @@ end:
199
199
  }
200
200
  if (null_terminated_body != nullptr) gpr_free(null_terminated_body);
201
201
  if (new_access_token != nullptr) gpr_free(new_access_token);
202
- if (json != nullptr) grpc_json_destroy(json);
202
+ grpc_json_destroy(json);
203
203
  return status;
204
204
  }
205
205
 
@@ -114,6 +114,7 @@ static void plugin_md_request_metadata_ready(void* request,
114
114
  grpc_status_code status,
115
115
  const char* error_details) {
116
116
  /* called from application code */
117
+ grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
117
118
  grpc_core::ExecCtx exec_ctx(GRPC_EXEC_CTX_FLAG_IS_FINISHED |
118
119
  GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP);
119
120
  grpc_plugin_credentials::pending_request* r =
@@ -0,0 +1,192 @@
1
+ /*
2
+ *
3
+ * Copyright 2018 gRPC authors.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ */
18
+
19
+ #include <grpc/support/port_platform.h>
20
+
21
+ #include "src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h"
22
+
23
+ #include <stdlib.h>
24
+ #include <string.h>
25
+
26
+ #include <grpc/support/alloc.h>
27
+ #include <grpc/support/log.h>
28
+ #include <grpc/support/string_util.h>
29
+
30
+ /** -- gRPC TLS key materials config API implementation. -- **/
31
+ void grpc_tls_key_materials_config::set_key_materials(
32
+ grpc_core::UniquePtr<char> pem_root_certs,
33
+ PemKeyCertPairList pem_key_cert_pair_list) {
34
+ pem_key_cert_pair_list_ = std::move(pem_key_cert_pair_list);
35
+ pem_root_certs_ = std::move(pem_root_certs);
36
+ }
37
+
38
+ /** -- gRPC TLS credential reload config API implementation. -- **/
39
+ grpc_tls_credential_reload_config::grpc_tls_credential_reload_config(
40
+ const void* config_user_data,
41
+ int (*schedule)(void* config_user_data,
42
+ grpc_tls_credential_reload_arg* arg),
43
+ void (*cancel)(void* config_user_data, grpc_tls_credential_reload_arg* arg),
44
+ void (*destruct)(void* config_user_data))
45
+ : config_user_data_(const_cast<void*>(config_user_data)),
46
+ schedule_(schedule),
47
+ cancel_(cancel),
48
+ destruct_(destruct) {}
49
+
50
+ grpc_tls_credential_reload_config::~grpc_tls_credential_reload_config() {
51
+ if (destruct_ != nullptr) {
52
+ destruct_((void*)config_user_data_);
53
+ }
54
+ }
55
+
56
+ /** -- gRPC TLS server authorization check API implementation. -- **/
57
+ grpc_tls_server_authorization_check_config::
58
+ grpc_tls_server_authorization_check_config(
59
+ const void* config_user_data,
60
+ int (*schedule)(void* config_user_data,
61
+ grpc_tls_server_authorization_check_arg* arg),
62
+ void (*cancel)(void* config_user_data,
63
+ grpc_tls_server_authorization_check_arg* arg),
64
+ void (*destruct)(void* config_user_data))
65
+ : config_user_data_(const_cast<void*>(config_user_data)),
66
+ schedule_(schedule),
67
+ cancel_(cancel),
68
+ destruct_(destruct) {}
69
+
70
+ grpc_tls_server_authorization_check_config::
71
+ ~grpc_tls_server_authorization_check_config() {
72
+ if (destruct_ != nullptr) {
73
+ destruct_((void*)config_user_data_);
74
+ }
75
+ }
76
+
77
+ /** -- Wrapper APIs declared in grpc_security.h -- **/
78
+ grpc_tls_credentials_options* grpc_tls_credentials_options_create() {
79
+ return grpc_core::New<grpc_tls_credentials_options>();
80
+ }
81
+
82
+ int grpc_tls_credentials_options_set_cert_request_type(
83
+ grpc_tls_credentials_options* options,
84
+ grpc_ssl_client_certificate_request_type type) {
85
+ if (options == nullptr) {
86
+ gpr_log(GPR_ERROR,
87
+ "Invalid nullptr arguments to "
88
+ "grpc_tls_credentials_options_set_cert_request_type()");
89
+ return 0;
90
+ }
91
+ options->set_cert_request_type(type);
92
+ return 1;
93
+ }
94
+
95
+ int grpc_tls_credentials_options_set_key_materials_config(
96
+ grpc_tls_credentials_options* options,
97
+ grpc_tls_key_materials_config* config) {
98
+ if (options == nullptr || config == nullptr) {
99
+ gpr_log(GPR_ERROR,
100
+ "Invalid nullptr arguments to "
101
+ "grpc_tls_credentials_options_set_key_materials_config()");
102
+ return 0;
103
+ }
104
+ options->set_key_materials_config(config->Ref());
105
+ return 1;
106
+ }
107
+
108
+ int grpc_tls_credentials_options_set_credential_reload_config(
109
+ grpc_tls_credentials_options* options,
110
+ grpc_tls_credential_reload_config* config) {
111
+ if (options == nullptr || config == nullptr) {
112
+ gpr_log(GPR_ERROR,
113
+ "Invalid nullptr arguments to "
114
+ "grpc_tls_credentials_options_set_credential_reload_config()");
115
+ return 0;
116
+ }
117
+ options->set_credential_reload_config(config->Ref());
118
+ return 1;
119
+ }
120
+
121
+ int grpc_tls_credentials_options_set_server_authorization_check_config(
122
+ grpc_tls_credentials_options* options,
123
+ grpc_tls_server_authorization_check_config* config) {
124
+ if (options == nullptr || config == nullptr) {
125
+ gpr_log(
126
+ GPR_ERROR,
127
+ "Invalid nullptr arguments to "
128
+ "grpc_tls_credentials_options_set_server_authorization_check_config()");
129
+ return 0;
130
+ }
131
+ options->set_server_authorization_check_config(config->Ref());
132
+ return 1;
133
+ }
134
+
135
+ grpc_tls_key_materials_config* grpc_tls_key_materials_config_create() {
136
+ return grpc_core::New<grpc_tls_key_materials_config>();
137
+ }
138
+
139
+ int grpc_tls_key_materials_config_set_key_materials(
140
+ grpc_tls_key_materials_config* config, const char* root_certs,
141
+ const grpc_ssl_pem_key_cert_pair** key_cert_pairs, size_t num) {
142
+ if (config == nullptr || key_cert_pairs == nullptr || num == 0) {
143
+ gpr_log(GPR_ERROR,
144
+ "Invalid arguments to "
145
+ "grpc_tls_key_materials_config_set_key_materials()");
146
+ return 0;
147
+ }
148
+ grpc_core::UniquePtr<char> pem_root(const_cast<char*>(root_certs));
149
+ grpc_tls_key_materials_config::PemKeyCertPairList cert_pair_list;
150
+ for (size_t i = 0; i < num; i++) {
151
+ grpc_core::PemKeyCertPair key_cert_pair(
152
+ const_cast<grpc_ssl_pem_key_cert_pair*>(key_cert_pairs[i]));
153
+ cert_pair_list.emplace_back(std::move(key_cert_pair));
154
+ }
155
+ config->set_key_materials(std::move(pem_root), std::move(cert_pair_list));
156
+ gpr_free(key_cert_pairs);
157
+ return 1;
158
+ }
159
+
160
+ grpc_tls_credential_reload_config* grpc_tls_credential_reload_config_create(
161
+ const void* config_user_data,
162
+ int (*schedule)(void* config_user_data,
163
+ grpc_tls_credential_reload_arg* arg),
164
+ void (*cancel)(void* config_user_data, grpc_tls_credential_reload_arg* arg),
165
+ void (*destruct)(void* config_user_data)) {
166
+ if (schedule == nullptr) {
167
+ gpr_log(
168
+ GPR_ERROR,
169
+ "Schedule API is nullptr in creating TLS credential reload config.");
170
+ return nullptr;
171
+ }
172
+ return grpc_core::New<grpc_tls_credential_reload_config>(
173
+ config_user_data, schedule, cancel, destruct);
174
+ }
175
+
176
+ grpc_tls_server_authorization_check_config*
177
+ grpc_tls_server_authorization_check_config_create(
178
+ const void* config_user_data,
179
+ int (*schedule)(void* config_user_data,
180
+ grpc_tls_server_authorization_check_arg* arg),
181
+ void (*cancel)(void* config_user_data,
182
+ grpc_tls_server_authorization_check_arg* arg),
183
+ void (*destruct)(void* config_user_data)) {
184
+ if (schedule == nullptr) {
185
+ gpr_log(GPR_ERROR,
186
+ "Schedule API is nullptr in creating TLS server authorization "
187
+ "check config.");
188
+ return nullptr;
189
+ }
190
+ return grpc_core::New<grpc_tls_server_authorization_check_config>(
191
+ config_user_data, schedule, cancel, destruct);
192
+ }
@@ -0,0 +1,213 @@
1
+ /*
2
+ *
3
+ * Copyright 2018 gRPC authors.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ */
18
+
19
+ #ifndef GRPC_CORE_LIB_SECURITY_CREDENTIALS_TLS_GRPC_TLS_CREDENTIALS_OPTIONS_H
20
+ #define GRPC_CORE_LIB_SECURITY_CREDENTIALS_TLS_GRPC_TLS_CREDENTIALS_OPTIONS_H
21
+
22
+ #include <grpc/support/port_platform.h>
23
+
24
+ #include <grpc/grpc_security.h>
25
+
26
+ #include "src/core/lib/gprpp/inlined_vector.h"
27
+ #include "src/core/lib/gprpp/ref_counted.h"
28
+ #include "src/core/lib/security/security_connector/ssl_utils.h"
29
+
30
+ /** TLS key materials config. **/
31
+ struct grpc_tls_key_materials_config
32
+ : public grpc_core::RefCounted<grpc_tls_key_materials_config> {
33
+ public:
34
+ typedef grpc_core::InlinedVector<grpc_core::PemKeyCertPair, 1>
35
+ PemKeyCertPairList;
36
+
37
+ /** Getters for member fields. **/
38
+ const char* pem_root_certs() const { return pem_root_certs_.get(); }
39
+ const PemKeyCertPairList& pem_key_cert_pair_list() const {
40
+ return pem_key_cert_pair_list_;
41
+ }
42
+
43
+ /** Setters for member fields. **/
44
+ void set_key_materials(grpc_core::UniquePtr<char> pem_root_certs,
45
+ PemKeyCertPairList pem_key_cert_pair_list);
46
+
47
+ private:
48
+ PemKeyCertPairList pem_key_cert_pair_list_;
49
+ grpc_core::UniquePtr<char> pem_root_certs_;
50
+ };
51
+
52
+ /** TLS credential reload config. **/
53
+ struct grpc_tls_credential_reload_config
54
+ : public grpc_core::RefCounted<grpc_tls_credential_reload_config> {
55
+ public:
56
+ grpc_tls_credential_reload_config(
57
+ const void* config_user_data,
58
+ int (*schedule)(void* config_user_data,
59
+ grpc_tls_credential_reload_arg* arg),
60
+ void (*cancel)(void* config_user_data,
61
+ grpc_tls_credential_reload_arg* arg),
62
+ void (*destruct)(void* config_user_data));
63
+ ~grpc_tls_credential_reload_config();
64
+
65
+ int Schedule(grpc_tls_credential_reload_arg* arg) const {
66
+ return schedule_(config_user_data_, arg);
67
+ }
68
+ void Cancel(grpc_tls_credential_reload_arg* arg) const {
69
+ if (cancel_ == nullptr) {
70
+ gpr_log(GPR_ERROR, "cancel API is nullptr.");
71
+ return;
72
+ }
73
+ cancel_(config_user_data_, arg);
74
+ }
75
+
76
+ private:
77
+ /** config-specific, read-only user data that works for all channels created
78
+ with a credential using the config. */
79
+ void* config_user_data_;
80
+ /** callback function for invoking credential reload API. The implementation
81
+ of this method has to be non-blocking, but can be performed synchronously
82
+ or asynchronously.
83
+ If processing occurs synchronously, it populates \a arg->key_materials, \a
84
+ arg->status, and \a arg->error_details and returns zero.
85
+ If processing occurs asynchronously, it returns a non-zero value.
86
+ Application then invokes \a arg->cb when processing is completed. Note that
87
+ \a arg->cb cannot be invoked before \a schedule returns.
88
+ */
89
+ int (*schedule_)(void* config_user_data, grpc_tls_credential_reload_arg* arg);
90
+ /** callback function for cancelling a credential reload request scheduled via
91
+ an asynchronous \a schedule. \a arg is used to pinpoint an exact reloading
92
+ request to be cancelled, and the operation may not have any effect if the
93
+ request has already been processed. */
94
+ void (*cancel_)(void* config_user_data, grpc_tls_credential_reload_arg* arg);
95
+ /** callback function for cleaning up any data associated with credential
96
+ reload config. */
97
+ void (*destruct_)(void* config_user_data);
98
+ };
99
+
100
+ /** TLS server authorization check config. **/
101
+ struct grpc_tls_server_authorization_check_config
102
+ : public grpc_core::RefCounted<grpc_tls_server_authorization_check_config> {
103
+ public:
104
+ grpc_tls_server_authorization_check_config(
105
+ const void* config_user_data,
106
+ int (*schedule)(void* config_user_data,
107
+ grpc_tls_server_authorization_check_arg* arg),
108
+ void (*cancel)(void* config_user_data,
109
+ grpc_tls_server_authorization_check_arg* arg),
110
+ void (*destruct)(void* config_user_data));
111
+ ~grpc_tls_server_authorization_check_config();
112
+
113
+ int Schedule(grpc_tls_server_authorization_check_arg* arg) const {
114
+ return schedule_(config_user_data_, arg);
115
+ }
116
+ void Cancel(grpc_tls_server_authorization_check_arg* arg) const {
117
+ if (cancel_ == nullptr) {
118
+ gpr_log(GPR_ERROR, "cancel API is nullptr.");
119
+ return;
120
+ }
121
+ cancel_(config_user_data_, arg);
122
+ }
123
+
124
+ private:
125
+ /** config-specific, read-only user data that works for all channels created
126
+ with a Credential using the config. */
127
+ void* config_user_data_;
128
+
129
+ /** callback function for invoking server authorization check. The
130
+ implementation of this method has to be non-blocking, but can be performed
131
+ synchronously or asynchronously.
132
+ If processing occurs synchronously, it populates \a arg->result, \a
133
+ arg->status, and \a arg->error_details, and returns zero.
134
+ If processing occurs asynchronously, it returns a non-zero value.
135
+ Application then invokes \a arg->cb when processing is completed. Note that
136
+ \a arg->cb cannot be invoked before \a schedule() returns.
137
+ */
138
+ int (*schedule_)(void* config_user_data,
139
+ grpc_tls_server_authorization_check_arg* arg);
140
+
141
+ /** callback function for canceling a server authorization check request. */
142
+ void (*cancel_)(void* config_user_data,
143
+ grpc_tls_server_authorization_check_arg* arg);
144
+
145
+ /** callback function for cleaning up any data associated with server
146
+ authorization check config. */
147
+ void (*destruct_)(void* config_user_data);
148
+ };
149
+
150
+ /* TLS credentials options. */
151
+ struct grpc_tls_credentials_options
152
+ : public grpc_core::RefCounted<grpc_tls_credentials_options> {
153
+ public:
154
+ ~grpc_tls_credentials_options() {
155
+ if (key_materials_config_.get() != nullptr) {
156
+ key_materials_config_.get()->Unref();
157
+ }
158
+ if (credential_reload_config_.get() != nullptr) {
159
+ credential_reload_config_.get()->Unref();
160
+ }
161
+ if (server_authorization_check_config_.get() != nullptr) {
162
+ server_authorization_check_config_.get()->Unref();
163
+ }
164
+ }
165
+
166
+ /* Getters for member fields. */
167
+ grpc_ssl_client_certificate_request_type cert_request_type() const {
168
+ return cert_request_type_;
169
+ }
170
+ const grpc_tls_key_materials_config* key_materials_config() const {
171
+ return key_materials_config_.get();
172
+ }
173
+ const grpc_tls_credential_reload_config* credential_reload_config() const {
174
+ return credential_reload_config_.get();
175
+ }
176
+ const grpc_tls_server_authorization_check_config*
177
+ server_authorization_check_config() const {
178
+ return server_authorization_check_config_.get();
179
+ }
180
+ grpc_tls_key_materials_config* mutable_key_materials_config() {
181
+ return key_materials_config_.get();
182
+ }
183
+
184
+ /* Setters for member fields. */
185
+ void set_cert_request_type(
186
+ const grpc_ssl_client_certificate_request_type type) {
187
+ cert_request_type_ = type;
188
+ }
189
+ void set_key_materials_config(
190
+ grpc_core::RefCountedPtr<grpc_tls_key_materials_config> config) {
191
+ key_materials_config_ = std::move(config);
192
+ }
193
+ void set_credential_reload_config(
194
+ grpc_core::RefCountedPtr<grpc_tls_credential_reload_config> config) {
195
+ credential_reload_config_ = std::move(config);
196
+ }
197
+ void set_server_authorization_check_config(
198
+ grpc_core::RefCountedPtr<grpc_tls_server_authorization_check_config>
199
+ config) {
200
+ server_authorization_check_config_ = std::move(config);
201
+ }
202
+
203
+ private:
204
+ grpc_ssl_client_certificate_request_type cert_request_type_;
205
+ grpc_core::RefCountedPtr<grpc_tls_key_materials_config> key_materials_config_;
206
+ grpc_core::RefCountedPtr<grpc_tls_credential_reload_config>
207
+ credential_reload_config_;
208
+ grpc_core::RefCountedPtr<grpc_tls_server_authorization_check_config>
209
+ server_authorization_check_config_;
210
+ };
211
+
212
+ #endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_TLS_GRPC_TLS_CREDENTIALS_OPTIONS_H \
213
+ */