grpc 1.13.0 → 1.14.0

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 (213) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +403 -153
  3. data/include/grpc/grpc.h +0 -8
  4. data/include/grpc/grpc_security.h +59 -2
  5. data/include/grpc/impl/codegen/grpc_types.h +8 -2
  6. data/include/grpc/impl/codegen/log.h +112 -0
  7. data/include/grpc/module.modulemap +2 -0
  8. data/include/grpc/support/log.h +2 -88
  9. data/include/grpc/support/string_util.h +2 -0
  10. data/src/boringssl/err_data.c +597 -593
  11. data/src/core/ext/filters/client_channel/client_channel.cc +715 -770
  12. data/src/core/ext/filters/client_channel/client_channel.h +5 -0
  13. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +111 -0
  14. data/src/core/ext/filters/client_channel/client_channel_channelz.h +69 -0
  15. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +9 -0
  16. data/src/core/ext/filters/client_channel/http_proxy.cc +22 -5
  17. data/src/core/ext/filters/client_channel/lb_policy.h +15 -0
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +3 -0
  19. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +3 -3
  20. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +3 -1
  21. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.c +19 -0
  22. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.h +54 -0
  23. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.c +19 -0
  24. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.h +54 -0
  25. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +4 -17
  26. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +37 -63
  27. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +79 -0
  28. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +5 -2
  29. data/src/core/ext/filters/client_channel/lb_policy_factory.cc +8 -0
  30. data/src/core/ext/filters/client_channel/lb_policy_factory.h +4 -0
  31. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +2 -2
  32. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +317 -0
  33. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +48 -9
  34. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +40 -293
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +106 -84
  36. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +6 -2
  37. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +6 -5
  38. data/src/core/ext/filters/client_channel/subchannel.cc +36 -6
  39. data/src/core/ext/filters/client_channel/subchannel.h +4 -0
  40. data/src/core/ext/filters/deadline/deadline_filter.cc +18 -15
  41. data/src/core/ext/filters/deadline/deadline_filter.h +5 -5
  42. data/src/core/ext/filters/http/client/http_client_filter.cc +10 -9
  43. data/src/core/ext/filters/http/server/http_server_filter.h +1 -1
  44. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +1 -1
  45. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +3 -2
  46. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +33 -22
  47. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +1 -1
  48. data/src/core/ext/transport/chttp2/transport/internal.h +10 -3
  49. data/src/core/ext/transport/chttp2/transport/stream_lists.cc +17 -0
  50. data/src/core/ext/transport/chttp2/transport/writing.cc +21 -16
  51. data/src/core/ext/transport/inproc/inproc_transport.cc +46 -6
  52. data/src/core/lib/channel/channel_stack.cc +22 -24
  53. data/src/core/lib/channel/channel_trace.cc +28 -63
  54. data/src/core/lib/channel/channel_trace.h +13 -17
  55. data/src/core/lib/channel/channelz.cc +143 -0
  56. data/src/core/lib/channel/channelz.h +124 -0
  57. data/src/core/lib/channel/channelz_registry.cc +7 -24
  58. data/src/core/lib/channel/channelz_registry.h +12 -8
  59. data/src/core/lib/channel/connected_channel.cc +8 -1
  60. data/src/core/{ext/filters/load_reporting/server_load_reporting_filter.h → lib/gpr/alloc.h} +7 -9
  61. data/src/core/lib/gpr/arena.cc +8 -8
  62. data/src/core/lib/gpr/string.cc +28 -0
  63. data/src/core/lib/gpr/string.h +10 -0
  64. data/src/core/lib/gprpp/abstract.h +5 -2
  65. data/src/core/lib/gprpp/inlined_vector.h +57 -3
  66. data/src/core/lib/gprpp/memory.h +2 -2
  67. data/src/core/lib/gprpp/ref_counted_ptr.h +5 -0
  68. data/src/core/lib/gprpp/thd_posix.cc +1 -1
  69. data/src/core/lib/iomgr/call_combiner.h +80 -0
  70. data/src/core/lib/iomgr/closure.h +3 -2
  71. data/src/core/lib/iomgr/endpoint_pair_posix.cc +2 -2
  72. data/src/core/lib/iomgr/error.cc +12 -0
  73. data/src/core/lib/iomgr/error.h +5 -0
  74. data/src/core/lib/iomgr/ev_epoll1_linux.cc +36 -9
  75. data/src/core/lib/iomgr/ev_epollex_linux.cc +172 -46
  76. data/src/core/lib/iomgr/ev_epollsig_linux.cc +47 -21
  77. data/src/core/lib/iomgr/ev_poll_posix.cc +10 -4
  78. data/src/core/lib/iomgr/ev_posix.cc +17 -9
  79. data/src/core/lib/iomgr/ev_posix.h +20 -4
  80. data/src/core/lib/iomgr/executor.cc +196 -140
  81. data/src/core/lib/iomgr/executor.h +47 -14
  82. data/src/core/lib/iomgr/iomgr.cc +2 -0
  83. data/src/core/lib/iomgr/iomgr.h +5 -0
  84. data/src/core/lib/iomgr/is_epollexclusive_available.cc +1 -0
  85. data/src/core/lib/iomgr/socket_utils.h +9 -0
  86. data/src/core/lib/iomgr/socket_utils_common_posix.cc +4 -0
  87. data/src/core/lib/iomgr/socket_utils_uv.cc +4 -0
  88. data/src/core/lib/iomgr/socket_utils_windows.cc +4 -0
  89. data/src/core/lib/iomgr/tcp_client_posix.cc +3 -5
  90. data/src/core/lib/iomgr/tcp_posix.cc +6 -1
  91. data/src/core/lib/iomgr/tcp_server_posix.cc +3 -3
  92. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +1 -1
  93. data/src/core/lib/iomgr/timer_manager.cc +0 -1
  94. data/src/core/lib/iomgr/udp_server.cc +2 -3
  95. data/src/core/lib/json/json.cc +10 -0
  96. data/src/core/lib/json/json.h +5 -0
  97. data/src/core/lib/security/context/security_context.cc +8 -8
  98. data/src/core/lib/security/context/security_context.h +6 -2
  99. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +2 -1
  100. data/src/core/lib/security/credentials/local/local_credentials.cc +77 -0
  101. data/src/core/lib/security/credentials/local/local_credentials.h +40 -0
  102. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +17 -3
  103. data/src/core/lib/security/security_connector/local_security_connector.cc +245 -0
  104. data/src/core/lib/security/security_connector/local_security_connector.h +58 -0
  105. data/src/core/lib/security/security_connector/security_connector.cc +30 -5
  106. data/src/core/lib/security/security_connector/security_connector.h +1 -0
  107. data/src/core/lib/security/transport/client_auth_filter.cc +5 -1
  108. data/src/core/lib/security/transport/server_auth_filter.cc +4 -5
  109. data/src/core/lib/surface/call.cc +75 -32
  110. data/src/core/lib/surface/call.h +2 -0
  111. data/src/core/lib/surface/channel.cc +32 -13
  112. data/src/core/lib/surface/channel.h +4 -0
  113. data/src/core/lib/surface/version.cc +1 -1
  114. data/src/core/lib/transport/transport.cc +20 -9
  115. data/src/core/lib/transport/transport.h +12 -10
  116. data/src/core/lib/transport/transport_op_string.cc +0 -7
  117. data/src/core/plugin_registry/grpc_plugin_registry.cc +0 -4
  118. data/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h +2 -2
  119. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +2 -1
  120. data/src/core/tsi/alts/handshaker/altscontext.pb.c +0 -1
  121. data/src/core/tsi/alts/handshaker/altscontext.pb.h +1 -2
  122. data/src/core/tsi/alts/handshaker/handshaker.pb.c +0 -1
  123. data/src/core/tsi/alts/handshaker/handshaker.pb.h +1 -2
  124. data/src/core/tsi/alts/handshaker/transport_security_common.pb.c +0 -1
  125. data/src/core/tsi/alts/handshaker/transport_security_common.pb.h +1 -1
  126. data/src/core/tsi/alts/handshaker/transport_security_common_api.h +2 -2
  127. data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc +47 -1
  128. data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h +3 -1
  129. data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +12 -11
  130. data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.h +7 -2
  131. data/src/core/tsi/local_transport_security.cc +209 -0
  132. data/src/core/tsi/local_transport_security.h +51 -0
  133. data/src/core/tsi/ssl_transport_security.cc +2 -3
  134. data/src/{core/ext → cpp/ext/filters}/census/grpc_context.cc +0 -0
  135. data/src/ruby/ext/grpc/rb_channel_credentials.c +3 -3
  136. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +18 -18
  137. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +29 -29
  138. data/src/ruby/lib/grpc/generic/active_call.rb +19 -23
  139. data/src/ruby/lib/grpc/version.rb +1 -1
  140. data/src/ruby/spec/call_credentials_spec.rb +1 -1
  141. data/src/ruby/spec/call_spec.rb +1 -1
  142. data/src/ruby/spec/channel_credentials_spec.rb +1 -1
  143. data/src/ruby/spec/channel_spec.rb +1 -1
  144. data/src/ruby/spec/client_auth_spec.rb +1 -12
  145. data/src/ruby/spec/client_server_spec.rb +1 -1
  146. data/src/ruby/spec/compression_options_spec.rb +1 -1
  147. data/src/ruby/spec/error_sanity_spec.rb +1 -1
  148. data/src/ruby/spec/generic/client_stub_spec.rb +13 -1
  149. data/src/ruby/spec/generic/rpc_desc_spec.rb +1 -1
  150. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +1 -1
  151. data/src/ruby/spec/generic/service_spec.rb +1 -1
  152. data/src/ruby/spec/google_rpc_status_utils_spec.rb +1 -12
  153. data/src/ruby/spec/pb/duplicate/codegen_spec.rb +1 -0
  154. data/src/ruby/spec/pb/health/checker_spec.rb +1 -1
  155. data/src/ruby/spec/server_credentials_spec.rb +1 -1
  156. data/src/ruby/spec/server_spec.rb +1 -1
  157. data/src/ruby/spec/spec_helper.rb +1 -0
  158. data/src/ruby/spec/support/services.rb +1 -1
  159. data/src/ruby/spec/time_consts_spec.rb +1 -1
  160. data/third_party/boringssl/crypto/asn1/tasn_dec.c +40 -19
  161. data/third_party/boringssl/crypto/bytestring/cbs.c +1 -0
  162. data/third_party/boringssl/crypto/cipher_extra/e_aesccm.c +47 -15
  163. data/third_party/boringssl/crypto/ec_extra/ec_asn1.c +9 -10
  164. data/third_party/boringssl/crypto/ecdh/ecdh.c +4 -3
  165. data/third_party/boringssl/crypto/fipsmodule/bn/add.c +30 -54
  166. data/third_party/boringssl/crypto/fipsmodule/bn/bn.c +7 -1
  167. data/third_party/boringssl/crypto/fipsmodule/bn/cmp.c +8 -8
  168. data/third_party/boringssl/crypto/fipsmodule/bn/div.c +97 -11
  169. data/third_party/boringssl/crypto/fipsmodule/bn/gcd.c +274 -218
  170. data/third_party/boringssl/crypto/fipsmodule/bn/internal.h +111 -34
  171. data/third_party/boringssl/crypto/fipsmodule/bn/montgomery.c +2 -2
  172. data/third_party/boringssl/crypto/fipsmodule/bn/montgomery_inv.c +1 -1
  173. data/third_party/boringssl/crypto/fipsmodule/bn/mul.c +24 -6
  174. data/third_party/boringssl/crypto/fipsmodule/bn/prime.c +324 -63
  175. data/third_party/boringssl/crypto/fipsmodule/bn/random.c +74 -21
  176. data/third_party/boringssl/crypto/fipsmodule/bn/shift.c +128 -86
  177. data/third_party/boringssl/crypto/fipsmodule/bn/sqrt.c +1 -1
  178. data/third_party/boringssl/crypto/fipsmodule/ec/ec_key.c +67 -112
  179. data/third_party/boringssl/crypto/fipsmodule/ec/internal.h +8 -1
  180. data/third_party/boringssl/crypto/fipsmodule/ec/oct.c +5 -5
  181. data/third_party/boringssl/crypto/fipsmodule/ec/p224-64.c +9 -17
  182. data/third_party/boringssl/crypto/fipsmodule/ec/p256-x86_64-table.h +5378 -5418
  183. data/third_party/boringssl/crypto/fipsmodule/ec/simple.c +32 -32
  184. data/third_party/boringssl/crypto/fipsmodule/ecdsa/ecdsa.c +5 -11
  185. data/third_party/boringssl/crypto/fipsmodule/rsa/blinding.c +16 -40
  186. data/third_party/boringssl/crypto/fipsmodule/rsa/internal.h +1 -6
  187. data/third_party/boringssl/crypto/fipsmodule/rsa/rsa.c +41 -29
  188. data/third_party/boringssl/crypto/fipsmodule/rsa/rsa_impl.c +63 -49
  189. data/third_party/boringssl/crypto/x509/vpm_int.h +1 -0
  190. data/third_party/boringssl/crypto/x509/x509_vfy.c +4 -0
  191. data/third_party/boringssl/crypto/x509/x509_vpm.c +44 -22
  192. data/third_party/boringssl/include/openssl/aead.h +8 -2
  193. data/third_party/boringssl/include/openssl/asn1.h +1 -0
  194. data/third_party/boringssl/include/openssl/base.h +4 -0
  195. data/third_party/boringssl/include/openssl/bn.h +13 -3
  196. data/third_party/boringssl/include/openssl/bytestring.h +4 -4
  197. data/third_party/boringssl/include/openssl/ec.h +10 -4
  198. data/third_party/boringssl/include/openssl/ec_key.h +0 -3
  199. data/third_party/boringssl/include/openssl/rsa.h +1 -0
  200. data/third_party/boringssl/include/openssl/ssl.h +8 -3
  201. data/third_party/boringssl/include/openssl/ssl3.h +0 -1
  202. data/third_party/boringssl/include/openssl/x509.h +1 -0
  203. data/third_party/boringssl/include/openssl/x509v3.h +1 -0
  204. data/third_party/boringssl/ssl/handshake_client.cc +36 -64
  205. data/third_party/boringssl/ssl/ssl_cipher.cc +4 -0
  206. data/third_party/boringssl/ssl/ssl_lib.cc +1 -1
  207. metadata +45 -38
  208. data/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc +0 -222
  209. data/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc +0 -71
  210. data/src/core/ext/filters/load_reporting/server_load_reporting_plugin.h +0 -61
  211. data/src/ruby/spec/pb/package_with_underscore/checker_spec.rb +0 -51
  212. data/src/ruby/spec/pb/package_with_underscore/data.proto +0 -23
  213. data/src/ruby/spec/pb/package_with_underscore/service.proto +0 -23
@@ -0,0 +1,40 @@
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_LOCAL_LOCAL_CREDENTIALS_H
20
+ #define GRPC_CORE_LIB_SECURITY_CREDENTIALS_LOCAL_LOCAL_CREDENTIALS_H
21
+
22
+ #include <grpc/support/port_platform.h>
23
+
24
+ #include <grpc/grpc_security.h>
25
+
26
+ #include "src/core/lib/security/credentials/credentials.h"
27
+
28
+ /* Main struct for grpc local channel credential. */
29
+ typedef struct grpc_local_credentials {
30
+ grpc_channel_credentials base;
31
+ grpc_local_connect_type connect_type;
32
+ } grpc_local_credentials;
33
+
34
+ /* Main struct for grpc local server credential. */
35
+ typedef struct grpc_local_server_credentials {
36
+ grpc_server_credentials base;
37
+ grpc_local_connect_type connect_type;
38
+ } grpc_local_server_credentials;
39
+
40
+ #endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_LOCAL_LOCAL_CREDENTIALS_H */
@@ -48,6 +48,10 @@ static void ssl_destruct(grpc_channel_credentials* creds) {
48
48
  grpc_ssl_credentials* c = reinterpret_cast<grpc_ssl_credentials*>(creds);
49
49
  gpr_free(c->config.pem_root_certs);
50
50
  grpc_tsi_ssl_pem_key_cert_pairs_destroy(c->config.pem_key_cert_pair, 1);
51
+ if (c->config.verify_options.verify_peer_destruct != nullptr) {
52
+ c->config.verify_options.verify_peer_destruct(
53
+ c->config.verify_options.verify_peer_callback_userdata);
54
+ }
51
55
  }
52
56
 
53
57
  static grpc_security_status ssl_create_security_connector(
@@ -87,6 +91,7 @@ static grpc_channel_credentials_vtable ssl_vtable = {
87
91
 
88
92
  static void ssl_build_config(const char* pem_root_certs,
89
93
  grpc_ssl_pem_key_cert_pair* pem_key_cert_pair,
94
+ const verify_peer_options* verify_options,
90
95
  grpc_ssl_config* config) {
91
96
  if (pem_root_certs != nullptr) {
92
97
  config->pem_root_certs = gpr_strdup(pem_root_certs);
@@ -101,23 +106,32 @@ static void ssl_build_config(const char* pem_root_certs,
101
106
  config->pem_key_cert_pair->private_key =
102
107
  gpr_strdup(pem_key_cert_pair->private_key);
103
108
  }
109
+ if (verify_options != nullptr) {
110
+ memcpy(&config->verify_options, verify_options,
111
+ sizeof(verify_peer_options));
112
+ } else {
113
+ // Otherwise set all options to default values
114
+ memset(&config->verify_options, 0, sizeof(verify_peer_options));
115
+ }
104
116
  }
105
117
 
106
118
  grpc_channel_credentials* grpc_ssl_credentials_create(
107
119
  const char* pem_root_certs, grpc_ssl_pem_key_cert_pair* pem_key_cert_pair,
108
- void* reserved) {
120
+ const verify_peer_options* verify_options, void* reserved) {
109
121
  grpc_ssl_credentials* c = static_cast<grpc_ssl_credentials*>(
110
122
  gpr_zalloc(sizeof(grpc_ssl_credentials)));
111
123
  GRPC_API_TRACE(
112
124
  "grpc_ssl_credentials_create(pem_root_certs=%s, "
113
125
  "pem_key_cert_pair=%p, "
126
+ "verify_options=%p, "
114
127
  "reserved=%p)",
115
- 3, (pem_root_certs, pem_key_cert_pair, reserved));
128
+ 4, (pem_root_certs, pem_key_cert_pair, verify_options, reserved));
116
129
  GPR_ASSERT(reserved == nullptr);
117
130
  c->base.type = GRPC_CHANNEL_CREDENTIALS_TYPE_SSL;
118
131
  c->base.vtable = &ssl_vtable;
119
132
  gpr_ref_init(&c->base.refcount, 1);
120
- ssl_build_config(pem_root_certs, pem_key_cert_pair, &c->config);
133
+ ssl_build_config(pem_root_certs, pem_key_cert_pair, verify_options,
134
+ &c->config);
121
135
  return &c->base;
122
136
  }
123
137
 
@@ -0,0 +1,245 @@
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/security_connector/local_security_connector.h"
22
+
23
+ #include <stdbool.h>
24
+ #include <string.h>
25
+
26
+ #include <grpc/grpc.h>
27
+ #include <grpc/support/alloc.h>
28
+ #include <grpc/support/log.h>
29
+ #include <grpc/support/string_util.h>
30
+
31
+ #include "src/core/ext/filters/client_channel/client_channel.h"
32
+ #include "src/core/lib/channel/channel_args.h"
33
+ #include "src/core/lib/security/credentials/local/local_credentials.h"
34
+ #include "src/core/lib/security/transport/security_handshaker.h"
35
+ #include "src/core/tsi/local_transport_security.h"
36
+
37
+ #define GRPC_UDS_URI_PATTERN "unix:"
38
+ #define GRPC_UDS_URL_SCHEME "unix"
39
+ #define GRPC_LOCAL_TRANSPORT_SECURITY_TYPE "local"
40
+
41
+ typedef struct {
42
+ grpc_channel_security_connector base;
43
+ char* target_name;
44
+ } grpc_local_channel_security_connector;
45
+
46
+ typedef struct {
47
+ grpc_server_security_connector base;
48
+ } grpc_local_server_security_connector;
49
+
50
+ static void local_channel_destroy(grpc_security_connector* sc) {
51
+ if (sc == nullptr) {
52
+ return;
53
+ }
54
+ auto c = reinterpret_cast<grpc_local_channel_security_connector*>(sc);
55
+ grpc_call_credentials_unref(c->base.request_metadata_creds);
56
+ grpc_channel_credentials_unref(c->base.channel_creds);
57
+ gpr_free(c->target_name);
58
+ gpr_free(sc);
59
+ }
60
+
61
+ static void local_server_destroy(grpc_security_connector* sc) {
62
+ if (sc == nullptr) {
63
+ return;
64
+ }
65
+ auto c = reinterpret_cast<grpc_local_server_security_connector*>(sc);
66
+ grpc_server_credentials_unref(c->base.server_creds);
67
+ gpr_free(sc);
68
+ }
69
+
70
+ static void local_channel_add_handshakers(
71
+ grpc_channel_security_connector* sc,
72
+ grpc_handshake_manager* handshake_manager) {
73
+ tsi_handshaker* handshaker = nullptr;
74
+ GPR_ASSERT(local_tsi_handshaker_create(true /* is_client */, &handshaker) ==
75
+ TSI_OK);
76
+ grpc_handshake_manager_add(handshake_manager, grpc_security_handshaker_create(
77
+ handshaker, &sc->base));
78
+ }
79
+
80
+ static void local_server_add_handshakers(
81
+ grpc_server_security_connector* sc,
82
+ grpc_handshake_manager* handshake_manager) {
83
+ tsi_handshaker* handshaker = nullptr;
84
+ GPR_ASSERT(local_tsi_handshaker_create(false /* is_client */, &handshaker) ==
85
+ TSI_OK);
86
+ grpc_handshake_manager_add(handshake_manager, grpc_security_handshaker_create(
87
+ handshaker, &sc->base));
88
+ }
89
+
90
+ static int local_channel_cmp(grpc_security_connector* sc1,
91
+ grpc_security_connector* sc2) {
92
+ grpc_local_channel_security_connector* c1 =
93
+ reinterpret_cast<grpc_local_channel_security_connector*>(sc1);
94
+ grpc_local_channel_security_connector* c2 =
95
+ reinterpret_cast<grpc_local_channel_security_connector*>(sc2);
96
+ int c = grpc_channel_security_connector_cmp(&c1->base, &c2->base);
97
+ if (c != 0) return c;
98
+ return strcmp(c1->target_name, c2->target_name);
99
+ }
100
+
101
+ static int local_server_cmp(grpc_security_connector* sc1,
102
+ grpc_security_connector* sc2) {
103
+ grpc_local_server_security_connector* c1 =
104
+ reinterpret_cast<grpc_local_server_security_connector*>(sc1);
105
+ grpc_local_server_security_connector* c2 =
106
+ reinterpret_cast<grpc_local_server_security_connector*>(sc2);
107
+ return grpc_server_security_connector_cmp(&c1->base, &c2->base);
108
+ }
109
+
110
+ static grpc_security_status local_auth_context_create(grpc_auth_context** ctx) {
111
+ if (ctx == nullptr) {
112
+ gpr_log(GPR_ERROR, "Invalid arguments to local_auth_context_create()");
113
+ return GRPC_SECURITY_ERROR;
114
+ }
115
+ /* Create auth context. */
116
+ *ctx = grpc_auth_context_create(nullptr);
117
+ grpc_auth_context_add_cstring_property(
118
+ *ctx, GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME,
119
+ GRPC_LOCAL_TRANSPORT_SECURITY_TYPE);
120
+ GPR_ASSERT(grpc_auth_context_set_peer_identity_property_name(
121
+ *ctx, GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME) == 1);
122
+ return GRPC_SECURITY_OK;
123
+ }
124
+
125
+ static void local_check_peer(grpc_security_connector* sc, tsi_peer peer,
126
+ grpc_auth_context** auth_context,
127
+ grpc_closure* on_peer_checked) {
128
+ grpc_security_status status;
129
+ /* Create an auth context which is necessary to pass the santiy check in
130
+ * {client, server}_auth_filter that verifies if the peer's auth context is
131
+ * obtained during handshakes. The auth context is only checked for its
132
+ * existence and not actually used.
133
+ */
134
+ status = local_auth_context_create(auth_context);
135
+ grpc_error* error = status == GRPC_SECURITY_OK
136
+ ? GRPC_ERROR_NONE
137
+ : GRPC_ERROR_CREATE_FROM_STATIC_STRING(
138
+ "Could not create local auth context");
139
+ GRPC_CLOSURE_SCHED(on_peer_checked, error);
140
+ }
141
+
142
+ static grpc_security_connector_vtable local_channel_vtable = {
143
+ local_channel_destroy, local_check_peer, local_channel_cmp};
144
+
145
+ static grpc_security_connector_vtable local_server_vtable = {
146
+ local_server_destroy, local_check_peer, local_server_cmp};
147
+
148
+ static bool local_check_call_host(grpc_channel_security_connector* sc,
149
+ const char* host,
150
+ grpc_auth_context* auth_context,
151
+ grpc_closure* on_call_host_checked,
152
+ grpc_error** error) {
153
+ grpc_local_channel_security_connector* local_sc =
154
+ reinterpret_cast<grpc_local_channel_security_connector*>(sc);
155
+ if (host == nullptr || local_sc == nullptr ||
156
+ strcmp(host, local_sc->target_name) != 0) {
157
+ *error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
158
+ "local call host does not match target name");
159
+ }
160
+ return true;
161
+ }
162
+
163
+ static void local_cancel_check_call_host(grpc_channel_security_connector* sc,
164
+ grpc_closure* on_call_host_checked,
165
+ grpc_error* error) {
166
+ GRPC_ERROR_UNREF(error);
167
+ }
168
+
169
+ grpc_security_status grpc_local_channel_security_connector_create(
170
+ grpc_channel_credentials* channel_creds,
171
+ grpc_call_credentials* request_metadata_creds,
172
+ const grpc_channel_args* args, const char* target_name,
173
+ grpc_channel_security_connector** sc) {
174
+ if (channel_creds == nullptr || sc == nullptr || target_name == nullptr) {
175
+ gpr_log(
176
+ GPR_ERROR,
177
+ "Invalid arguments to grpc_local_channel_security_connector_create()");
178
+ return GRPC_SECURITY_ERROR;
179
+ }
180
+ // Check if local_connect_type is UDS. Only UDS is supported for now.
181
+ grpc_local_credentials* creds =
182
+ reinterpret_cast<grpc_local_credentials*>(channel_creds);
183
+ if (creds->connect_type != UDS) {
184
+ gpr_log(GPR_ERROR,
185
+ "Invalid local channel type to "
186
+ "grpc_local_channel_security_connector_create()");
187
+ return GRPC_SECURITY_ERROR;
188
+ }
189
+ // Check if target_name is a valid UDS address.
190
+ const grpc_arg* server_uri_arg =
191
+ grpc_channel_args_find(args, GRPC_ARG_SERVER_URI);
192
+ const char* server_uri_str = grpc_channel_arg_get_string(server_uri_arg);
193
+ if (strncmp(GRPC_UDS_URI_PATTERN, server_uri_str,
194
+ strlen(GRPC_UDS_URI_PATTERN)) != 0) {
195
+ gpr_log(GPR_ERROR,
196
+ "Invalid target_name to "
197
+ "grpc_local_channel_security_connector_create()");
198
+ return GRPC_SECURITY_ERROR;
199
+ }
200
+ auto c = static_cast<grpc_local_channel_security_connector*>(
201
+ gpr_zalloc(sizeof(grpc_local_channel_security_connector)));
202
+ gpr_ref_init(&c->base.base.refcount, 1);
203
+ c->base.base.vtable = &local_channel_vtable;
204
+ c->base.add_handshakers = local_channel_add_handshakers;
205
+ c->base.channel_creds = grpc_channel_credentials_ref(channel_creds);
206
+ c->base.request_metadata_creds =
207
+ grpc_call_credentials_ref(request_metadata_creds);
208
+ c->base.check_call_host = local_check_call_host;
209
+ c->base.cancel_check_call_host = local_cancel_check_call_host;
210
+ c->base.base.url_scheme =
211
+ creds->connect_type == UDS ? GRPC_UDS_URL_SCHEME : nullptr;
212
+ c->target_name = gpr_strdup(target_name);
213
+ *sc = &c->base;
214
+ return GRPC_SECURITY_OK;
215
+ }
216
+
217
+ grpc_security_status grpc_local_server_security_connector_create(
218
+ grpc_server_credentials* server_creds,
219
+ grpc_server_security_connector** sc) {
220
+ if (server_creds == nullptr || sc == nullptr) {
221
+ gpr_log(
222
+ GPR_ERROR,
223
+ "Invalid arguments to grpc_local_server_security_connector_create()");
224
+ return GRPC_SECURITY_ERROR;
225
+ }
226
+ // Check if local_connect_type is UDS. Only UDS is supported for now.
227
+ grpc_local_server_credentials* creds =
228
+ reinterpret_cast<grpc_local_server_credentials*>(server_creds);
229
+ if (creds->connect_type != UDS) {
230
+ gpr_log(GPR_ERROR,
231
+ "Invalid local server type to "
232
+ "grpc_local_server_security_connector_create()");
233
+ return GRPC_SECURITY_ERROR;
234
+ }
235
+ auto c = static_cast<grpc_local_server_security_connector*>(
236
+ gpr_zalloc(sizeof(grpc_local_server_security_connector)));
237
+ gpr_ref_init(&c->base.base.refcount, 1);
238
+ c->base.base.vtable = &local_server_vtable;
239
+ c->base.server_creds = grpc_server_credentials_ref(server_creds);
240
+ c->base.base.url_scheme =
241
+ creds->connect_type == UDS ? GRPC_UDS_URL_SCHEME : nullptr;
242
+ c->base.add_handshakers = local_server_add_handshakers;
243
+ *sc = &c->base;
244
+ return GRPC_SECURITY_OK;
245
+ }
@@ -0,0 +1,58 @@
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_SECURITY_CONNECTOR_LOCAL_SECURITY_CONNECTOR_H
20
+ #define GRPC_CORE_LIB_SECURITY_SECURITY_CONNECTOR_LOCAL_SECURITY_CONNECTOR_H
21
+
22
+ #include <grpc/support/port_platform.h>
23
+
24
+ #include "src/core/lib/security/context/security_context.h"
25
+
26
+ /**
27
+ * This method creates a local channel security connector.
28
+ *
29
+ * - channel_creds: channel credential instance.
30
+ * - request_metadata_creds: credential object which will be sent with each
31
+ * request. This parameter can be nullptr.
32
+ * - target_name: the name of the endpoint that the channel is connecting to.
33
+ * - args: channel args passed from the caller.
34
+ * - sc: address of local channel security connector instance to be returned
35
+ * from the method.
36
+ *
37
+ * It returns GRPC_SECURITY_OK on success, and an error stauts code on failure.
38
+ */
39
+ grpc_security_status grpc_local_channel_security_connector_create(
40
+ grpc_channel_credentials* channel_creds,
41
+ grpc_call_credentials* request_metadata_creds,
42
+ const grpc_channel_args* args, const char* target_name,
43
+ grpc_channel_security_connector** sc);
44
+
45
+ /**
46
+ * This method creates a local server security connector.
47
+ *
48
+ * - server_creds: server credential instance.
49
+ * - sc: address of local server security connector instance to be returned from
50
+ * the method.
51
+ *
52
+ * It returns GRPC_SECURITY_OK on success, and an error status code on failure.
53
+ */
54
+ grpc_security_status grpc_local_server_security_connector_create(
55
+ grpc_server_credentials* server_creds, grpc_server_security_connector** sc);
56
+
57
+ #endif /* GRPC_CORE_LIB_SECURITY_SECURITY_CONNECTOR_LOCAL_SECURITY_CONNECTOR_H \
58
+ */
@@ -620,6 +620,7 @@ typedef struct {
620
620
  tsi_ssl_client_handshaker_factory* client_handshaker_factory;
621
621
  char* target_name;
622
622
  char* overridden_target_name;
623
+ const verify_peer_options* verify_options;
623
624
  } grpc_ssl_channel_security_connector;
624
625
 
625
626
  typedef struct {
@@ -878,11 +879,34 @@ static void ssl_channel_check_peer(grpc_security_connector* sc, tsi_peer peer,
878
879
  grpc_closure* on_peer_checked) {
879
880
  grpc_ssl_channel_security_connector* c =
880
881
  reinterpret_cast<grpc_ssl_channel_security_connector*>(sc);
881
- grpc_error* error = ssl_check_peer(sc,
882
- c->overridden_target_name != nullptr
883
- ? c->overridden_target_name
884
- : c->target_name,
885
- &peer, auth_context);
882
+ const char* target_name = c->overridden_target_name != nullptr
883
+ ? c->overridden_target_name
884
+ : c->target_name;
885
+ grpc_error* error = ssl_check_peer(sc, target_name, &peer, auth_context);
886
+ if (error == GRPC_ERROR_NONE &&
887
+ c->verify_options->verify_peer_callback != nullptr) {
888
+ const tsi_peer_property* p =
889
+ tsi_peer_get_property_by_name(&peer, TSI_X509_PEM_CERT_PROPERTY);
890
+ if (p == nullptr) {
891
+ error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
892
+ "Cannot check peer: missing pem cert property.");
893
+ } else {
894
+ char* peer_pem = static_cast<char*>(gpr_malloc(p->value.length + 1));
895
+ memcpy(peer_pem, p->value.data, p->value.length);
896
+ peer_pem[p->value.length] = '\0';
897
+ int callback_status = c->verify_options->verify_peer_callback(
898
+ target_name, peer_pem,
899
+ c->verify_options->verify_peer_callback_userdata);
900
+ gpr_free(peer_pem);
901
+ if (callback_status) {
902
+ char* msg;
903
+ gpr_asprintf(&msg, "Verify peer callback returned a failure (%d)",
904
+ callback_status);
905
+ error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg);
906
+ gpr_free(msg);
907
+ }
908
+ }
909
+ }
886
910
  GRPC_CLOSURE_SCHED(on_peer_checked, error);
887
911
  tsi_peer_destruct(&peer);
888
912
  }
@@ -1047,6 +1071,7 @@ grpc_security_status grpc_ssl_channel_security_connector_create(
1047
1071
  if (overridden_target_name != nullptr) {
1048
1072
  c->overridden_target_name = gpr_strdup(overridden_target_name);
1049
1073
  }
1074
+ c->verify_options = &config->verify_options;
1050
1075
 
1051
1076
  has_key_cert_pair = config->pem_key_cert_pair != nullptr &&
1052
1077
  config->pem_key_cert_pair->private_key != nullptr &&