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.

Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1228 -988
  3. data/etc/roots.pem +242 -30
  4. data/include/grpc/grpc.h +2 -1
  5. data/include/grpc/grpc_security_constants.h +3 -3
  6. data/include/grpc/impl/codegen/atm_gcc_sync.h +2 -0
  7. data/include/grpc/impl/codegen/atm_windows.h +2 -0
  8. data/include/grpc/impl/codegen/compression_types.h +2 -1
  9. data/include/grpc/impl/codegen/grpc_types.h +1 -1
  10. data/include/grpc/impl/codegen/port_platform.h +9 -0
  11. data/src/core/ext/filters/client_channel/client_channel.cc +163 -882
  12. data/src/core/ext/filters/client_channel/health/health_check_client.cc +2 -4
  13. data/src/core/ext/filters/client_channel/health/health_check_client.h +2 -3
  14. data/src/core/ext/filters/client_channel/lb_policy.cc +1 -1
  15. data/src/core/ext/filters/client_channel/lb_policy.h +8 -17
  16. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +176 -216
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +1 -1
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +20 -23
  19. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +1 -1
  20. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +49 -52
  21. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +13 -35
  22. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +31 -30
  23. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +69 -225
  24. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h +1 -1
  25. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +20 -23
  26. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +1 -1
  27. data/src/core/ext/filters/client_channel/lb_policy_factory.h +2 -84
  28. data/src/core/ext/filters/client_channel/request_routing.cc +936 -0
  29. data/src/core/ext/filters/client_channel/request_routing.h +177 -0
  30. data/src/core/ext/filters/client_channel/resolver.cc +1 -1
  31. data/src/core/ext/filters/client_channel/resolver.h +1 -1
  32. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +37 -26
  33. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +30 -18
  34. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +119 -100
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +8 -5
  36. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +5 -4
  37. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +2 -1
  38. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +12 -14
  39. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +5 -9
  40. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -1
  41. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +1 -2
  42. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +17 -17
  43. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +45 -52
  44. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +13 -17
  45. data/src/core/ext/filters/client_channel/server_address.cc +103 -0
  46. data/src/core/ext/filters/client_channel/server_address.h +108 -0
  47. data/src/core/ext/filters/client_channel/subchannel.cc +10 -8
  48. data/src/core/ext/filters/client_channel/subchannel.h +9 -6
  49. data/src/core/ext/filters/client_channel/subchannel_index.cc +20 -27
  50. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +3 -2
  51. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +8 -9
  52. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +1 -1
  53. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +1 -1
  54. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +8 -11
  55. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +24 -54
  56. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -1
  57. data/src/core/ext/transport/chttp2/transport/context_list.cc +67 -0
  58. data/src/core/ext/transport/chttp2/transport/context_list.h +53 -0
  59. data/src/core/ext/transport/chttp2/transport/internal.h +38 -11
  60. data/src/core/ext/transport/chttp2/transport/writing.cc +5 -0
  61. data/src/core/ext/transport/inproc/inproc_transport.cc +1 -1
  62. data/src/core/lib/channel/channelz.cc +19 -18
  63. data/src/core/lib/channel/channelz.h +7 -1
  64. data/src/core/lib/channel/channelz_registry.cc +3 -2
  65. data/src/core/lib/debug/trace.cc +3 -0
  66. data/src/core/lib/debug/trace.h +5 -3
  67. data/src/core/lib/gpr/sync_posix.cc +96 -4
  68. data/src/core/lib/gprpp/inlined_vector.h +25 -19
  69. data/src/core/lib/gprpp/memory.h +2 -11
  70. data/src/core/lib/gprpp/orphanable.h +18 -82
  71. data/src/core/lib/gprpp/ref_counted.h +75 -84
  72. data/src/core/lib/gprpp/ref_counted_ptr.h +22 -17
  73. data/src/core/lib/http/httpcli_security_connector.cc +101 -94
  74. data/src/core/lib/http/parser.h +5 -5
  75. data/src/core/lib/iomgr/buffer_list.cc +16 -5
  76. data/src/core/lib/iomgr/buffer_list.h +10 -3
  77. data/src/core/lib/iomgr/call_combiner.cc +50 -2
  78. data/src/core/lib/iomgr/call_combiner.h +29 -2
  79. data/src/core/lib/iomgr/dynamic_annotations.h +67 -0
  80. data/src/core/lib/iomgr/endpoint.cc +4 -0
  81. data/src/core/lib/iomgr/endpoint.h +3 -0
  82. data/src/core/lib/iomgr/endpoint_pair_posix.cc +2 -2
  83. data/src/core/lib/iomgr/ev_epoll1_linux.cc +4 -0
  84. data/src/core/lib/iomgr/ev_epollex_linux.cc +4 -0
  85. data/src/core/lib/iomgr/ev_poll_posix.cc +4 -0
  86. data/src/core/lib/iomgr/ev_posix.cc +15 -7
  87. data/src/core/lib/iomgr/ev_posix.h +10 -0
  88. data/src/core/lib/iomgr/exec_ctx.cc +13 -0
  89. data/src/core/lib/iomgr/fork_posix.cc +1 -1
  90. data/src/core/lib/iomgr/internal_errqueue.cc +36 -3
  91. data/src/core/lib/iomgr/internal_errqueue.h +7 -1
  92. data/src/core/lib/iomgr/iomgr.cc +7 -0
  93. data/src/core/lib/iomgr/iomgr.h +4 -0
  94. data/src/core/lib/iomgr/iomgr_custom.cc +3 -1
  95. data/src/core/lib/iomgr/iomgr_internal.cc +4 -0
  96. data/src/core/lib/iomgr/iomgr_internal.h +4 -0
  97. data/src/core/lib/iomgr/iomgr_posix.cc +6 -1
  98. data/src/core/lib/iomgr/iomgr_windows.cc +4 -1
  99. data/src/core/lib/iomgr/port.h +1 -2
  100. data/src/core/lib/iomgr/resource_quota.cc +1 -0
  101. data/src/core/lib/iomgr/sockaddr_utils.cc +1 -0
  102. data/src/core/lib/iomgr/tcp_custom.cc +4 -1
  103. data/src/core/lib/iomgr/tcp_posix.cc +95 -35
  104. data/src/core/lib/iomgr/tcp_windows.cc +4 -1
  105. data/src/core/lib/iomgr/timer_manager.cc +6 -0
  106. data/src/core/lib/security/context/security_context.cc +75 -108
  107. data/src/core/lib/security/context/security_context.h +59 -35
  108. data/src/core/lib/security/credentials/alts/alts_credentials.cc +36 -48
  109. data/src/core/lib/security/credentials/alts/alts_credentials.h +37 -10
  110. data/src/core/lib/security/credentials/composite/composite_credentials.cc +97 -157
  111. data/src/core/lib/security/credentials/composite/composite_credentials.h +60 -24
  112. data/src/core/lib/security/credentials/credentials.cc +18 -142
  113. data/src/core/lib/security/credentials/credentials.h +119 -95
  114. data/src/core/lib/security/credentials/fake/fake_credentials.cc +46 -71
  115. data/src/core/lib/security/credentials/fake/fake_credentials.h +23 -5
  116. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +144 -51
  117. data/src/core/lib/security/credentials/google_default/google_default_credentials.h +28 -5
  118. data/src/core/lib/security/credentials/iam/iam_credentials.cc +27 -35
  119. data/src/core/lib/security/credentials/iam/iam_credentials.h +18 -4
  120. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +60 -69
  121. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +29 -10
  122. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +2 -0
  123. data/src/core/lib/security/credentials/local/local_credentials.cc +19 -32
  124. data/src/core/lib/security/credentials/local/local_credentials.h +32 -11
  125. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +130 -149
  126. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +74 -29
  127. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +59 -77
  128. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +40 -17
  129. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +66 -83
  130. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +58 -15
  131. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +152 -177
  132. data/src/core/lib/security/security_connector/alts/alts_security_connector.h +12 -10
  133. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +210 -215
  134. data/src/core/lib/security/security_connector/fake/fake_security_connector.h +9 -6
  135. data/src/core/lib/security/security_connector/local/local_security_connector.cc +176 -169
  136. data/src/core/lib/security/security_connector/local/local_security_connector.h +10 -9
  137. data/src/core/lib/security/security_connector/security_connector.cc +41 -124
  138. data/src/core/lib/security/security_connector/security_connector.h +102 -105
  139. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +348 -370
  140. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.h +14 -12
  141. data/src/core/lib/security/security_connector/ssl_utils.cc +13 -9
  142. data/src/core/lib/security/security_connector/ssl_utils.h +3 -1
  143. data/src/core/lib/security/transport/client_auth_filter.cc +50 -50
  144. data/src/core/lib/security/transport/secure_endpoint.cc +7 -1
  145. data/src/core/lib/security/transport/security_handshaker.cc +82 -66
  146. data/src/core/lib/security/transport/server_auth_filter.cc +15 -13
  147. data/src/core/lib/surface/init.cc +1 -0
  148. data/src/core/lib/surface/server.cc +13 -11
  149. data/src/core/lib/surface/server.h +6 -6
  150. data/src/core/lib/surface/version.cc +2 -2
  151. data/src/core/lib/transport/metadata.cc +1 -0
  152. data/src/core/lib/transport/static_metadata.cc +228 -221
  153. data/src/core/lib/transport/static_metadata.h +75 -71
  154. data/src/core/lib/transport/transport.cc +2 -1
  155. data/src/core/lib/transport/transport.h +5 -1
  156. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +9 -2
  157. data/src/core/tsi/ssl_transport_security.cc +35 -24
  158. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +1 -1
  159. data/src/ruby/lib/grpc/generic/rpc_server.rb +61 -0
  160. data/src/ruby/lib/grpc/generic/service.rb +1 -1
  161. data/src/ruby/lib/grpc/version.rb +1 -1
  162. data/src/ruby/pb/grpc/health/checker.rb +2 -3
  163. data/src/ruby/spec/generic/rpc_server_spec.rb +22 -0
  164. data/src/ruby/spec/support/services.rb +1 -0
  165. metadata +37 -32
  166. data/src/core/ext/filters/client_channel/lb_policy_factory.cc +0 -163
@@ -24,19 +24,22 @@
24
24
  #include <grpc/grpc_security.h>
25
25
 
26
26
  #include "src/core/lib/channel/handshaker.h"
27
+ #include "src/core/lib/gprpp/ref_counted_ptr.h"
27
28
  #include "src/core/lib/security/security_connector/security_connector.h"
28
29
 
29
30
  #define GRPC_FAKE_SECURITY_URL_SCHEME "http+fake_security"
30
31
 
31
32
  /* Creates a fake connector that emulates real channel security. */
32
- grpc_channel_security_connector* grpc_fake_channel_security_connector_create(
33
- grpc_channel_credentials* channel_creds,
34
- grpc_call_credentials* request_metadata_creds, const char* target,
35
- const grpc_channel_args* args);
33
+ grpc_core::RefCountedPtr<grpc_channel_security_connector>
34
+ grpc_fake_channel_security_connector_create(
35
+ grpc_core::RefCountedPtr<grpc_channel_credentials> channel_creds,
36
+ grpc_core::RefCountedPtr<grpc_call_credentials> request_metadata_creds,
37
+ const char* target, const grpc_channel_args* args);
36
38
 
37
39
  /* Creates a fake connector that emulates real server security. */
38
- grpc_server_security_connector* grpc_fake_server_security_connector_create(
39
- grpc_server_credentials* server_creds);
40
+ grpc_core::RefCountedPtr<grpc_server_security_connector>
41
+ grpc_fake_server_security_connector_create(
42
+ grpc_core::RefCountedPtr<grpc_server_credentials> server_creds);
40
43
 
41
44
  #endif /* GRPC_CORE_LIB_SECURITY_SECURITY_CONNECTOR_FAKE_FAKE_SECURITY_CONNECTOR_H \
42
45
  */
@@ -30,217 +30,224 @@
30
30
 
31
31
  #include "src/core/ext/filters/client_channel/client_channel.h"
32
32
  #include "src/core/lib/channel/channel_args.h"
33
+ #include "src/core/lib/gprpp/ref_counted_ptr.h"
33
34
  #include "src/core/lib/iomgr/pollset.h"
35
+ #include "src/core/lib/iomgr/resolve_address.h"
36
+ #include "src/core/lib/iomgr/sockaddr.h"
37
+ #include "src/core/lib/iomgr/sockaddr_utils.h"
38
+ #include "src/core/lib/iomgr/socket_utils.h"
39
+ #include "src/core/lib/iomgr/unix_sockets_posix.h"
34
40
  #include "src/core/lib/security/credentials/local/local_credentials.h"
35
41
  #include "src/core/lib/security/transport/security_handshaker.h"
36
42
  #include "src/core/tsi/local_transport_security.h"
37
43
 
38
44
  #define GRPC_UDS_URI_PATTERN "unix:"
39
- #define GRPC_UDS_URL_SCHEME "unix"
40
45
  #define GRPC_LOCAL_TRANSPORT_SECURITY_TYPE "local"
41
46
 
42
- typedef struct {
43
- grpc_channel_security_connector base;
44
- char* target_name;
45
- } grpc_local_channel_security_connector;
47
+ namespace {
46
48
 
47
- typedef struct {
48
- grpc_server_security_connector base;
49
- } grpc_local_server_security_connector;
50
-
51
- static void local_channel_destroy(grpc_security_connector* sc) {
52
- if (sc == nullptr) {
53
- return;
54
- }
55
- auto c = reinterpret_cast<grpc_local_channel_security_connector*>(sc);
56
- grpc_call_credentials_unref(c->base.request_metadata_creds);
57
- grpc_channel_credentials_unref(c->base.channel_creds);
58
- gpr_free(c->target_name);
59
- gpr_free(sc);
60
- }
61
-
62
- static void local_server_destroy(grpc_security_connector* sc) {
63
- if (sc == nullptr) {
64
- return;
65
- }
66
- auto c = reinterpret_cast<grpc_local_server_security_connector*>(sc);
67
- grpc_server_credentials_unref(c->base.server_creds);
68
- gpr_free(sc);
69
- }
70
-
71
- static void local_channel_add_handshakers(
72
- grpc_channel_security_connector* sc, grpc_pollset_set* interested_parties,
73
- grpc_handshake_manager* handshake_manager) {
74
- tsi_handshaker* handshaker = nullptr;
75
- GPR_ASSERT(local_tsi_handshaker_create(true /* is_client */, &handshaker) ==
76
- TSI_OK);
77
- grpc_handshake_manager_add(handshake_manager, grpc_security_handshaker_create(
78
- handshaker, &sc->base));
79
- }
80
-
81
- static void local_server_add_handshakers(
82
- grpc_server_security_connector* sc, grpc_pollset_set* interested_parties,
83
- grpc_handshake_manager* handshake_manager) {
84
- tsi_handshaker* handshaker = nullptr;
85
- GPR_ASSERT(local_tsi_handshaker_create(false /* is_client */, &handshaker) ==
86
- TSI_OK);
87
- grpc_handshake_manager_add(handshake_manager, grpc_security_handshaker_create(
88
- handshaker, &sc->base));
89
- }
90
-
91
- static int local_channel_cmp(grpc_security_connector* sc1,
92
- grpc_security_connector* sc2) {
93
- grpc_local_channel_security_connector* c1 =
94
- reinterpret_cast<grpc_local_channel_security_connector*>(sc1);
95
- grpc_local_channel_security_connector* c2 =
96
- reinterpret_cast<grpc_local_channel_security_connector*>(sc2);
97
- int c = grpc_channel_security_connector_cmp(&c1->base, &c2->base);
98
- if (c != 0) return c;
99
- return strcmp(c1->target_name, c2->target_name);
100
- }
101
-
102
- static int local_server_cmp(grpc_security_connector* sc1,
103
- grpc_security_connector* sc2) {
104
- grpc_local_server_security_connector* c1 =
105
- reinterpret_cast<grpc_local_server_security_connector*>(sc1);
106
- grpc_local_server_security_connector* c2 =
107
- reinterpret_cast<grpc_local_server_security_connector*>(sc2);
108
- return grpc_server_security_connector_cmp(&c1->base, &c2->base);
109
- }
110
-
111
- static grpc_security_status local_auth_context_create(grpc_auth_context** ctx) {
112
- if (ctx == nullptr) {
113
- gpr_log(GPR_ERROR, "Invalid arguments to local_auth_context_create()");
114
- return GRPC_SECURITY_ERROR;
115
- }
49
+ grpc_core::RefCountedPtr<grpc_auth_context> local_auth_context_create() {
116
50
  /* Create auth context. */
117
- *ctx = grpc_auth_context_create(nullptr);
51
+ grpc_core::RefCountedPtr<grpc_auth_context> ctx =
52
+ grpc_core::MakeRefCounted<grpc_auth_context>(nullptr);
118
53
  grpc_auth_context_add_cstring_property(
119
- *ctx, GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME,
54
+ ctx.get(), GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME,
120
55
  GRPC_LOCAL_TRANSPORT_SECURITY_TYPE);
121
56
  GPR_ASSERT(grpc_auth_context_set_peer_identity_property_name(
122
- *ctx, GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME) == 1);
123
- return GRPC_SECURITY_OK;
57
+ ctx.get(), GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME) == 1);
58
+ return ctx;
124
59
  }
125
60
 
126
- static void local_check_peer(grpc_security_connector* sc, tsi_peer peer,
127
- grpc_auth_context** auth_context,
128
- grpc_closure* on_peer_checked) {
129
- grpc_security_status status;
61
+ void local_check_peer(grpc_security_connector* sc, tsi_peer peer,
62
+ grpc_endpoint* ep,
63
+ grpc_core::RefCountedPtr<grpc_auth_context>* auth_context,
64
+ grpc_closure* on_peer_checked,
65
+ grpc_local_connect_type type) {
66
+ int fd = grpc_endpoint_get_fd(ep);
67
+ grpc_resolved_address resolved_addr;
68
+ memset(&resolved_addr, 0, sizeof(resolved_addr));
69
+ resolved_addr.len = GRPC_MAX_SOCKADDR_SIZE;
70
+ bool is_endpoint_local = false;
71
+ if (getsockname(fd, reinterpret_cast<grpc_sockaddr*>(resolved_addr.addr),
72
+ &resolved_addr.len) == 0) {
73
+ grpc_resolved_address addr_normalized;
74
+ grpc_resolved_address* addr =
75
+ grpc_sockaddr_is_v4mapped(&resolved_addr, &addr_normalized)
76
+ ? &addr_normalized
77
+ : &resolved_addr;
78
+ grpc_sockaddr* sock_addr = reinterpret_cast<grpc_sockaddr*>(&addr->addr);
79
+ // UDS
80
+ if (type == UDS && grpc_is_unix_socket(addr)) {
81
+ is_endpoint_local = true;
82
+ // IPV4
83
+ } else if (type == LOCAL_TCP && sock_addr->sa_family == GRPC_AF_INET) {
84
+ const grpc_sockaddr_in* addr4 =
85
+ reinterpret_cast<const grpc_sockaddr_in*>(sock_addr);
86
+ if (grpc_htonl(addr4->sin_addr.s_addr) == INADDR_LOOPBACK) {
87
+ is_endpoint_local = true;
88
+ }
89
+ // IPv6
90
+ } else if (type == LOCAL_TCP && sock_addr->sa_family == GRPC_AF_INET6) {
91
+ const grpc_sockaddr_in6* addr6 =
92
+ reinterpret_cast<const grpc_sockaddr_in6*>(addr);
93
+ if (memcmp(&addr6->sin6_addr, &in6addr_loopback,
94
+ sizeof(in6addr_loopback)) == 0) {
95
+ is_endpoint_local = true;
96
+ }
97
+ }
98
+ }
99
+ grpc_error* error = GRPC_ERROR_NONE;
100
+ if (!is_endpoint_local) {
101
+ error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
102
+ "Endpoint is neither UDS or TCP loopback address.");
103
+ GRPC_CLOSURE_SCHED(on_peer_checked, error);
104
+ return;
105
+ }
130
106
  /* Create an auth context which is necessary to pass the santiy check in
131
107
  * {client, server}_auth_filter that verifies if the peer's auth context is
132
108
  * obtained during handshakes. The auth context is only checked for its
133
109
  * existence and not actually used.
134
110
  */
135
- status = local_auth_context_create(auth_context);
136
- grpc_error* error = status == GRPC_SECURITY_OK
137
- ? GRPC_ERROR_NONE
138
- : GRPC_ERROR_CREATE_FROM_STATIC_STRING(
139
- "Could not create local auth context");
111
+ *auth_context = local_auth_context_create();
112
+ error = *auth_context != nullptr ? GRPC_ERROR_NONE
113
+ : GRPC_ERROR_CREATE_FROM_STATIC_STRING(
114
+ "Could not create local auth context");
140
115
  GRPC_CLOSURE_SCHED(on_peer_checked, error);
141
116
  }
142
117
 
143
- static grpc_security_connector_vtable local_channel_vtable = {
144
- local_channel_destroy, local_check_peer, local_channel_cmp};
145
-
146
- static grpc_security_connector_vtable local_server_vtable = {
147
- local_server_destroy, local_check_peer, local_server_cmp};
148
-
149
- static bool local_check_call_host(grpc_channel_security_connector* sc,
150
- const char* host,
151
- grpc_auth_context* auth_context,
152
- grpc_closure* on_call_host_checked,
153
- grpc_error** error) {
154
- grpc_local_channel_security_connector* local_sc =
155
- reinterpret_cast<grpc_local_channel_security_connector*>(sc);
156
- if (host == nullptr || local_sc == nullptr ||
157
- strcmp(host, local_sc->target_name) != 0) {
158
- *error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
159
- "local call host does not match target name");
118
+ class grpc_local_channel_security_connector final
119
+ : public grpc_channel_security_connector {
120
+ public:
121
+ grpc_local_channel_security_connector(
122
+ grpc_core::RefCountedPtr<grpc_channel_credentials> channel_creds,
123
+ grpc_core::RefCountedPtr<grpc_call_credentials> request_metadata_creds,
124
+ const char* target_name)
125
+ : grpc_channel_security_connector(nullptr, std::move(channel_creds),
126
+ std::move(request_metadata_creds)),
127
+ target_name_(gpr_strdup(target_name)) {}
128
+
129
+ ~grpc_local_channel_security_connector() override { gpr_free(target_name_); }
130
+
131
+ void add_handshakers(grpc_pollset_set* interested_parties,
132
+ grpc_handshake_manager* handshake_manager) override {
133
+ tsi_handshaker* handshaker = nullptr;
134
+ GPR_ASSERT(local_tsi_handshaker_create(true /* is_client */, &handshaker) ==
135
+ TSI_OK);
136
+ grpc_handshake_manager_add(
137
+ handshake_manager, grpc_security_handshaker_create(handshaker, this));
160
138
  }
161
- return true;
162
- }
163
139
 
164
- static void local_cancel_check_call_host(grpc_channel_security_connector* sc,
165
- grpc_closure* on_call_host_checked,
166
- grpc_error* error) {
167
- GRPC_ERROR_UNREF(error);
168
- }
140
+ int cmp(const grpc_security_connector* other_sc) const override {
141
+ auto* other =
142
+ reinterpret_cast<const grpc_local_channel_security_connector*>(
143
+ other_sc);
144
+ int c = channel_security_connector_cmp(other);
145
+ if (c != 0) return c;
146
+ return strcmp(target_name_, other->target_name_);
147
+ }
148
+
149
+ void check_peer(tsi_peer peer, grpc_endpoint* ep,
150
+ grpc_core::RefCountedPtr<grpc_auth_context>* auth_context,
151
+ grpc_closure* on_peer_checked) override {
152
+ grpc_local_credentials* creds =
153
+ reinterpret_cast<grpc_local_credentials*>(mutable_channel_creds());
154
+ local_check_peer(this, peer, ep, auth_context, on_peer_checked,
155
+ creds->connect_type());
156
+ }
157
+
158
+ bool check_call_host(const char* host, grpc_auth_context* auth_context,
159
+ grpc_closure* on_call_host_checked,
160
+ grpc_error** error) override {
161
+ if (host == nullptr || strcmp(host, target_name_) != 0) {
162
+ *error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
163
+ "local call host does not match target name");
164
+ }
165
+ return true;
166
+ }
167
+
168
+ void cancel_check_call_host(grpc_closure* on_call_host_checked,
169
+ grpc_error* error) override {
170
+ GRPC_ERROR_UNREF(error);
171
+ }
169
172
 
170
- grpc_security_status grpc_local_channel_security_connector_create(
171
- grpc_channel_credentials* channel_creds,
172
- grpc_call_credentials* request_metadata_creds,
173
- const grpc_channel_args* args, const char* target_name,
174
- grpc_channel_security_connector** sc) {
175
- if (channel_creds == nullptr || sc == nullptr || target_name == nullptr) {
173
+ const char* target_name() const { return target_name_; }
174
+
175
+ private:
176
+ char* target_name_;
177
+ };
178
+
179
+ class grpc_local_server_security_connector final
180
+ : public grpc_server_security_connector {
181
+ public:
182
+ grpc_local_server_security_connector(
183
+ grpc_core::RefCountedPtr<grpc_server_credentials> server_creds)
184
+ : grpc_server_security_connector(nullptr, std::move(server_creds)) {}
185
+ ~grpc_local_server_security_connector() override = default;
186
+
187
+ void add_handshakers(grpc_pollset_set* interested_parties,
188
+ grpc_handshake_manager* handshake_manager) override {
189
+ tsi_handshaker* handshaker = nullptr;
190
+ GPR_ASSERT(local_tsi_handshaker_create(false /* is_client */,
191
+ &handshaker) == TSI_OK);
192
+ grpc_handshake_manager_add(
193
+ handshake_manager, grpc_security_handshaker_create(handshaker, this));
194
+ }
195
+
196
+ void check_peer(tsi_peer peer, grpc_endpoint* ep,
197
+ grpc_core::RefCountedPtr<grpc_auth_context>* auth_context,
198
+ grpc_closure* on_peer_checked) override {
199
+ grpc_local_server_credentials* creds =
200
+ static_cast<grpc_local_server_credentials*>(mutable_server_creds());
201
+ local_check_peer(this, peer, ep, auth_context, on_peer_checked,
202
+ creds->connect_type());
203
+ }
204
+
205
+ int cmp(const grpc_security_connector* other) const override {
206
+ return server_security_connector_cmp(
207
+ static_cast<const grpc_server_security_connector*>(other));
208
+ }
209
+ };
210
+ } // namespace
211
+
212
+ grpc_core::RefCountedPtr<grpc_channel_security_connector>
213
+ grpc_local_channel_security_connector_create(
214
+ grpc_core::RefCountedPtr<grpc_channel_credentials> channel_creds,
215
+ grpc_core::RefCountedPtr<grpc_call_credentials> request_metadata_creds,
216
+ const grpc_channel_args* args, const char* target_name) {
217
+ if (channel_creds == nullptr || target_name == nullptr) {
176
218
  gpr_log(
177
219
  GPR_ERROR,
178
220
  "Invalid arguments to grpc_local_channel_security_connector_create()");
179
- return GRPC_SECURITY_ERROR;
221
+ return nullptr;
180
222
  }
181
- // Check if local_connect_type is UDS. Only UDS is supported for now.
223
+ // Perform sanity check on UDS address. For TCP local connection, the check
224
+ // will be done during check_peer procedure.
182
225
  grpc_local_credentials* creds =
183
- reinterpret_cast<grpc_local_credentials*>(channel_creds);
184
- if (creds->connect_type != UDS) {
185
- gpr_log(GPR_ERROR,
186
- "Invalid local channel type to "
187
- "grpc_local_channel_security_connector_create()");
188
- return GRPC_SECURITY_ERROR;
189
- }
190
- // Check if target_name is a valid UDS address.
226
+ static_cast<grpc_local_credentials*>(channel_creds.get());
191
227
  const grpc_arg* server_uri_arg =
192
228
  grpc_channel_args_find(args, GRPC_ARG_SERVER_URI);
193
229
  const char* server_uri_str = grpc_channel_arg_get_string(server_uri_arg);
194
- if (strncmp(GRPC_UDS_URI_PATTERN, server_uri_str,
230
+ if (creds->connect_type() == UDS &&
231
+ strncmp(GRPC_UDS_URI_PATTERN, server_uri_str,
195
232
  strlen(GRPC_UDS_URI_PATTERN)) != 0) {
196
233
  gpr_log(GPR_ERROR,
197
- "Invalid target_name to "
234
+ "Invalid UDS target name to "
198
235
  "grpc_local_channel_security_connector_create()");
199
- return GRPC_SECURITY_ERROR;
236
+ return nullptr;
200
237
  }
201
- auto c = static_cast<grpc_local_channel_security_connector*>(
202
- gpr_zalloc(sizeof(grpc_local_channel_security_connector)));
203
- gpr_ref_init(&c->base.base.refcount, 1);
204
- c->base.base.vtable = &local_channel_vtable;
205
- c->base.add_handshakers = local_channel_add_handshakers;
206
- c->base.channel_creds = grpc_channel_credentials_ref(channel_creds);
207
- c->base.request_metadata_creds =
208
- grpc_call_credentials_ref(request_metadata_creds);
209
- c->base.check_call_host = local_check_call_host;
210
- c->base.cancel_check_call_host = local_cancel_check_call_host;
211
- c->base.base.url_scheme =
212
- creds->connect_type == UDS ? GRPC_UDS_URL_SCHEME : nullptr;
213
- c->target_name = gpr_strdup(target_name);
214
- *sc = &c->base;
215
- return GRPC_SECURITY_OK;
238
+ return grpc_core::MakeRefCounted<grpc_local_channel_security_connector>(
239
+ channel_creds, request_metadata_creds, target_name);
216
240
  }
217
241
 
218
- grpc_security_status grpc_local_server_security_connector_create(
219
- grpc_server_credentials* server_creds,
220
- grpc_server_security_connector** sc) {
221
- if (server_creds == nullptr || sc == nullptr) {
242
+ grpc_core::RefCountedPtr<grpc_server_security_connector>
243
+ grpc_local_server_security_connector_create(
244
+ grpc_core::RefCountedPtr<grpc_server_credentials> server_creds) {
245
+ if (server_creds == nullptr) {
222
246
  gpr_log(
223
247
  GPR_ERROR,
224
248
  "Invalid arguments to grpc_local_server_security_connector_create()");
225
- return GRPC_SECURITY_ERROR;
226
- }
227
- // Check if local_connect_type is UDS. Only UDS is supported for now.
228
- grpc_local_server_credentials* creds =
229
- reinterpret_cast<grpc_local_server_credentials*>(server_creds);
230
- if (creds->connect_type != UDS) {
231
- gpr_log(GPR_ERROR,
232
- "Invalid local server type to "
233
- "grpc_local_server_security_connector_create()");
234
- return GRPC_SECURITY_ERROR;
249
+ return nullptr;
235
250
  }
236
- auto c = static_cast<grpc_local_server_security_connector*>(
237
- gpr_zalloc(sizeof(grpc_local_server_security_connector)));
238
- gpr_ref_init(&c->base.base.refcount, 1);
239
- c->base.base.vtable = &local_server_vtable;
240
- c->base.server_creds = grpc_server_credentials_ref(server_creds);
241
- c->base.base.url_scheme =
242
- creds->connect_type == UDS ? GRPC_UDS_URL_SCHEME : nullptr;
243
- c->base.add_handshakers = local_server_add_handshakers;
244
- *sc = &c->base;
245
- return GRPC_SECURITY_OK;
251
+ return grpc_core::MakeRefCounted<grpc_local_server_security_connector>(
252
+ std::move(server_creds));
246
253
  }
@@ -34,13 +34,13 @@
34
34
  * - sc: address of local channel security connector instance to be returned
35
35
  * from the method.
36
36
  *
37
- * It returns GRPC_SECURITY_OK on success, and an error stauts code on failure.
37
+ * It returns nullptr on failure.
38
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);
39
+ grpc_core::RefCountedPtr<grpc_channel_security_connector>
40
+ grpc_local_channel_security_connector_create(
41
+ grpc_core::RefCountedPtr<grpc_channel_credentials> channel_creds,
42
+ grpc_core::RefCountedPtr<grpc_call_credentials> request_metadata_creds,
43
+ const grpc_channel_args* args, const char* target_name);
44
44
 
45
45
  /**
46
46
  * This method creates a local server security connector.
@@ -49,10 +49,11 @@ grpc_security_status grpc_local_channel_security_connector_create(
49
49
  * - sc: address of local server security connector instance to be returned from
50
50
  * the method.
51
51
  *
52
- * It returns GRPC_SECURITY_OK on success, and an error status code on failure.
52
+ * It returns nullptr on failure.
53
53
  */
54
- grpc_security_status grpc_local_server_security_connector_create(
55
- grpc_server_credentials* server_creds, grpc_server_security_connector** sc);
54
+ grpc_core::RefCountedPtr<grpc_server_security_connector>
55
+ grpc_local_server_security_connector_create(
56
+ grpc_core::RefCountedPtr<grpc_server_credentials> server_creds);
56
57
 
57
58
  #endif /* GRPC_CORE_LIB_SECURITY_SECURITY_CONNECTOR_LOCAL_LOCAL_SECURITY_CONNECTOR_H \
58
59
  */