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
@@ -21,6 +21,7 @@
21
21
 
22
22
  #include <grpc/support/port_platform.h>
23
23
 
24
+ #include "src/core/lib/gprpp/ref_counted_ptr.h"
24
25
  #include "src/core/lib/security/credentials/credentials.h"
25
26
 
26
27
  #define GRPC_GOOGLE_CLOUD_SDK_CONFIG_DIRECTORY "gcloud"
@@ -39,11 +40,33 @@
39
40
  "/" GRPC_GOOGLE_WELL_KNOWN_CREDENTIALS_FILE
40
41
  #endif
41
42
 
42
- typedef struct {
43
- grpc_channel_credentials base;
44
- grpc_channel_credentials* alts_creds;
45
- grpc_channel_credentials* ssl_creds;
46
- } grpc_google_default_channel_credentials;
43
+ class grpc_google_default_channel_credentials
44
+ : public grpc_channel_credentials {
45
+ public:
46
+ grpc_google_default_channel_credentials(
47
+ grpc_core::RefCountedPtr<grpc_channel_credentials> alts_creds,
48
+ grpc_core::RefCountedPtr<grpc_channel_credentials> ssl_creds)
49
+ : grpc_channel_credentials(GRPC_CHANNEL_CREDENTIALS_TYPE_GOOGLE_DEFAULT),
50
+ alts_creds_(std::move(alts_creds)),
51
+ ssl_creds_(std::move(ssl_creds)) {}
52
+
53
+ ~grpc_google_default_channel_credentials() override = default;
54
+
55
+ grpc_core::RefCountedPtr<grpc_channel_security_connector>
56
+ create_security_connector(
57
+ grpc_core::RefCountedPtr<grpc_call_credentials> call_creds,
58
+ const char* target, const grpc_channel_args* args,
59
+ grpc_channel_args** new_args) override;
60
+
61
+ const grpc_channel_credentials* alts_creds() const {
62
+ return alts_creds_.get();
63
+ }
64
+ const grpc_channel_credentials* ssl_creds() const { return ssl_creds_.get(); }
65
+
66
+ private:
67
+ grpc_core::RefCountedPtr<grpc_channel_credentials> alts_creds_;
68
+ grpc_core::RefCountedPtr<grpc_channel_credentials> ssl_creds_;
69
+ };
47
70
 
48
71
  namespace grpc_core {
49
72
  namespace internal {
@@ -22,6 +22,7 @@
22
22
 
23
23
  #include <string.h>
24
24
 
25
+ #include "src/core/lib/gprpp/ref_counted_ptr.h"
25
26
  #include "src/core/lib/surface/api_trace.h"
26
27
 
27
28
  #include <grpc/support/alloc.h>
@@ -29,32 +30,37 @@
29
30
  #include <grpc/support/string_util.h>
30
31
  #include <grpc/support/sync.h>
31
32
 
32
- static void iam_destruct(grpc_call_credentials* creds) {
33
- grpc_google_iam_credentials* c =
34
- reinterpret_cast<grpc_google_iam_credentials*>(creds);
35
- grpc_credentials_mdelem_array_destroy(&c->md_array);
33
+ grpc_google_iam_credentials::~grpc_google_iam_credentials() {
34
+ grpc_credentials_mdelem_array_destroy(&md_array_);
36
35
  }
37
36
 
38
- static bool iam_get_request_metadata(grpc_call_credentials* creds,
39
- grpc_polling_entity* pollent,
40
- grpc_auth_metadata_context context,
41
- grpc_credentials_mdelem_array* md_array,
42
- grpc_closure* on_request_metadata,
43
- grpc_error** error) {
44
- grpc_google_iam_credentials* c =
45
- reinterpret_cast<grpc_google_iam_credentials*>(creds);
46
- grpc_credentials_mdelem_array_append(md_array, &c->md_array);
37
+ bool grpc_google_iam_credentials::get_request_metadata(
38
+ grpc_polling_entity* pollent, grpc_auth_metadata_context context,
39
+ grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata,
40
+ grpc_error** error) {
41
+ grpc_credentials_mdelem_array_append(md_array, &md_array_);
47
42
  return true;
48
43
  }
49
44
 
50
- static void iam_cancel_get_request_metadata(
51
- grpc_call_credentials* c, grpc_credentials_mdelem_array* md_array,
52
- grpc_error* error) {
45
+ void grpc_google_iam_credentials::cancel_get_request_metadata(
46
+ grpc_credentials_mdelem_array* md_array, grpc_error* error) {
53
47
  GRPC_ERROR_UNREF(error);
54
48
  }
55
49
 
56
- static grpc_call_credentials_vtable iam_vtable = {
57
- iam_destruct, iam_get_request_metadata, iam_cancel_get_request_metadata};
50
+ grpc_google_iam_credentials::grpc_google_iam_credentials(
51
+ const char* token, const char* authority_selector)
52
+ : grpc_call_credentials(GRPC_CALL_CREDENTIALS_TYPE_IAM) {
53
+ grpc_mdelem md = grpc_mdelem_from_slices(
54
+ grpc_slice_from_static_string(GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY),
55
+ grpc_slice_from_copied_string(token));
56
+ grpc_credentials_mdelem_array_add(&md_array_, md);
57
+ GRPC_MDELEM_UNREF(md);
58
+ md = grpc_mdelem_from_slices(
59
+ grpc_slice_from_static_string(GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY),
60
+ grpc_slice_from_copied_string(authority_selector));
61
+ grpc_credentials_mdelem_array_add(&md_array_, md);
62
+ GRPC_MDELEM_UNREF(md);
63
+ }
58
64
 
59
65
  grpc_call_credentials* grpc_google_iam_credentials_create(
60
66
  const char* token, const char* authority_selector, void* reserved) {
@@ -66,21 +72,7 @@ grpc_call_credentials* grpc_google_iam_credentials_create(
66
72
  GPR_ASSERT(reserved == nullptr);
67
73
  GPR_ASSERT(token != nullptr);
68
74
  GPR_ASSERT(authority_selector != nullptr);
69
- grpc_google_iam_credentials* c =
70
- static_cast<grpc_google_iam_credentials*>(gpr_zalloc(sizeof(*c)));
71
- c->base.type = GRPC_CALL_CREDENTIALS_TYPE_IAM;
72
- c->base.vtable = &iam_vtable;
73
- gpr_ref_init(&c->base.refcount, 1);
74
- grpc_mdelem md = grpc_mdelem_from_slices(
75
- grpc_slice_from_static_string(GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY),
76
- grpc_slice_from_copied_string(token));
77
- grpc_credentials_mdelem_array_add(&c->md_array, md);
78
- GRPC_MDELEM_UNREF(md);
79
- md = grpc_mdelem_from_slices(
80
- grpc_slice_from_static_string(GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY),
81
- grpc_slice_from_copied_string(authority_selector));
82
- grpc_credentials_mdelem_array_add(&c->md_array, md);
83
- GRPC_MDELEM_UNREF(md);
84
-
85
- return &c->base;
75
+ return grpc_core::MakeRefCounted<grpc_google_iam_credentials>(
76
+ token, authority_selector)
77
+ .release();
86
78
  }
@@ -23,9 +23,23 @@
23
23
 
24
24
  #include "src/core/lib/security/credentials/credentials.h"
25
25
 
26
- typedef struct {
27
- grpc_call_credentials base;
28
- grpc_credentials_mdelem_array md_array;
29
- } grpc_google_iam_credentials;
26
+ class grpc_google_iam_credentials : public grpc_call_credentials {
27
+ public:
28
+ grpc_google_iam_credentials(const char* token,
29
+ const char* authority_selector);
30
+ ~grpc_google_iam_credentials() override;
31
+
32
+ bool get_request_metadata(grpc_polling_entity* pollent,
33
+ grpc_auth_metadata_context context,
34
+ grpc_credentials_mdelem_array* md_array,
35
+ grpc_closure* on_request_metadata,
36
+ grpc_error** error) override;
37
+
38
+ void cancel_get_request_metadata(grpc_credentials_mdelem_array* md_array,
39
+ grpc_error* error) override;
40
+
41
+ private:
42
+ grpc_credentials_mdelem_array md_array_;
43
+ };
30
44
 
31
45
  #endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_IAM_IAM_CREDENTIALS_H */
@@ -23,6 +23,8 @@
23
23
  #include <inttypes.h>
24
24
  #include <string.h>
25
25
 
26
+ #include "src/core/lib/gprpp/ref_counted.h"
27
+ #include "src/core/lib/gprpp/ref_counted_ptr.h"
26
28
  #include "src/core/lib/surface/api_trace.h"
27
29
 
28
30
  #include <grpc/support/alloc.h>
@@ -30,71 +32,66 @@
30
32
  #include <grpc/support/string_util.h>
31
33
  #include <grpc/support/sync.h>
32
34
 
33
- static void jwt_reset_cache(grpc_service_account_jwt_access_credentials* c) {
34
- GRPC_MDELEM_UNREF(c->cached.jwt_md);
35
- c->cached.jwt_md = GRPC_MDNULL;
36
- if (c->cached.service_url != nullptr) {
37
- gpr_free(c->cached.service_url);
38
- c->cached.service_url = nullptr;
35
+ void grpc_service_account_jwt_access_credentials::reset_cache() {
36
+ GRPC_MDELEM_UNREF(cached_.jwt_md);
37
+ cached_.jwt_md = GRPC_MDNULL;
38
+ if (cached_.service_url != nullptr) {
39
+ gpr_free(cached_.service_url);
40
+ cached_.service_url = nullptr;
39
41
  }
40
- c->cached.jwt_expiration = gpr_inf_past(GPR_CLOCK_REALTIME);
42
+ cached_.jwt_expiration = gpr_inf_past(GPR_CLOCK_REALTIME);
41
43
  }
42
44
 
43
- static void jwt_destruct(grpc_call_credentials* creds) {
44
- grpc_service_account_jwt_access_credentials* c =
45
- reinterpret_cast<grpc_service_account_jwt_access_credentials*>(creds);
46
- grpc_auth_json_key_destruct(&c->key);
47
- jwt_reset_cache(c);
48
- gpr_mu_destroy(&c->cache_mu);
45
+ grpc_service_account_jwt_access_credentials::
46
+ ~grpc_service_account_jwt_access_credentials() {
47
+ grpc_auth_json_key_destruct(&key_);
48
+ reset_cache();
49
+ gpr_mu_destroy(&cache_mu_);
49
50
  }
50
51
 
51
- static bool jwt_get_request_metadata(grpc_call_credentials* creds,
52
- grpc_polling_entity* pollent,
53
- grpc_auth_metadata_context context,
54
- grpc_credentials_mdelem_array* md_array,
55
- grpc_closure* on_request_metadata,
56
- grpc_error** error) {
57
- grpc_service_account_jwt_access_credentials* c =
58
- reinterpret_cast<grpc_service_account_jwt_access_credentials*>(creds);
52
+ bool grpc_service_account_jwt_access_credentials::get_request_metadata(
53
+ grpc_polling_entity* pollent, grpc_auth_metadata_context context,
54
+ grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata,
55
+ grpc_error** error) {
59
56
  gpr_timespec refresh_threshold = gpr_time_from_seconds(
60
57
  GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS, GPR_TIMESPAN);
61
58
 
62
59
  /* See if we can return a cached jwt. */
63
60
  grpc_mdelem jwt_md = GRPC_MDNULL;
64
61
  {
65
- gpr_mu_lock(&c->cache_mu);
66
- if (c->cached.service_url != nullptr &&
67
- strcmp(c->cached.service_url, context.service_url) == 0 &&
68
- !GRPC_MDISNULL(c->cached.jwt_md) &&
69
- (gpr_time_cmp(gpr_time_sub(c->cached.jwt_expiration,
70
- gpr_now(GPR_CLOCK_REALTIME)),
71
- refresh_threshold) > 0)) {
72
- jwt_md = GRPC_MDELEM_REF(c->cached.jwt_md);
62
+ gpr_mu_lock(&cache_mu_);
63
+ if (cached_.service_url != nullptr &&
64
+ strcmp(cached_.service_url, context.service_url) == 0 &&
65
+ !GRPC_MDISNULL(cached_.jwt_md) &&
66
+ (gpr_time_cmp(
67
+ gpr_time_sub(cached_.jwt_expiration, gpr_now(GPR_CLOCK_REALTIME)),
68
+ refresh_threshold) > 0)) {
69
+ jwt_md = GRPC_MDELEM_REF(cached_.jwt_md);
73
70
  }
74
- gpr_mu_unlock(&c->cache_mu);
71
+ gpr_mu_unlock(&cache_mu_);
75
72
  }
76
73
 
77
74
  if (GRPC_MDISNULL(jwt_md)) {
78
75
  char* jwt = nullptr;
79
76
  /* Generate a new jwt. */
80
- gpr_mu_lock(&c->cache_mu);
81
- jwt_reset_cache(c);
82
- jwt = grpc_jwt_encode_and_sign(&c->key, context.service_url,
83
- c->jwt_lifetime, nullptr);
77
+ gpr_mu_lock(&cache_mu_);
78
+ reset_cache();
79
+ jwt = grpc_jwt_encode_and_sign(&key_, context.service_url, jwt_lifetime_,
80
+ nullptr);
84
81
  if (jwt != nullptr) {
85
82
  char* md_value;
86
83
  gpr_asprintf(&md_value, "Bearer %s", jwt);
87
84
  gpr_free(jwt);
88
- c->cached.jwt_expiration =
89
- gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), c->jwt_lifetime);
90
- c->cached.service_url = gpr_strdup(context.service_url);
91
- c->cached.jwt_md = grpc_mdelem_from_slices(
85
+ cached_.jwt_expiration =
86
+ gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), jwt_lifetime_);
87
+ cached_.service_url = gpr_strdup(context.service_url);
88
+ cached_.jwt_md = grpc_mdelem_from_slices(
92
89
  grpc_slice_from_static_string(GRPC_AUTHORIZATION_METADATA_KEY),
93
90
  grpc_slice_from_copied_string(md_value));
94
91
  gpr_free(md_value);
95
- jwt_md = GRPC_MDELEM_REF(c->cached.jwt_md);
92
+ jwt_md = GRPC_MDELEM_REF(cached_.jwt_md);
96
93
  }
97
- gpr_mu_unlock(&c->cache_mu);
94
+ gpr_mu_unlock(&cache_mu_);
98
95
  }
99
96
 
100
97
  if (!GRPC_MDISNULL(jwt_md)) {
@@ -106,29 +103,15 @@ static bool jwt_get_request_metadata(grpc_call_credentials* creds,
106
103
  return true;
107
104
  }
108
105
 
109
- static void jwt_cancel_get_request_metadata(
110
- grpc_call_credentials* c, grpc_credentials_mdelem_array* md_array,
111
- grpc_error* error) {
106
+ void grpc_service_account_jwt_access_credentials::cancel_get_request_metadata(
107
+ grpc_credentials_mdelem_array* md_array, grpc_error* error) {
112
108
  GRPC_ERROR_UNREF(error);
113
109
  }
114
110
 
115
- static grpc_call_credentials_vtable jwt_vtable = {
116
- jwt_destruct, jwt_get_request_metadata, jwt_cancel_get_request_metadata};
117
-
118
- grpc_call_credentials*
119
- grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
120
- grpc_auth_json_key key, gpr_timespec token_lifetime) {
121
- grpc_service_account_jwt_access_credentials* c;
122
- if (!grpc_auth_json_key_is_valid(&key)) {
123
- gpr_log(GPR_ERROR, "Invalid input for jwt credentials creation");
124
- return nullptr;
125
- }
126
- c = static_cast<grpc_service_account_jwt_access_credentials*>(
127
- gpr_zalloc(sizeof(grpc_service_account_jwt_access_credentials)));
128
- c->base.type = GRPC_CALL_CREDENTIALS_TYPE_JWT;
129
- gpr_ref_init(&c->base.refcount, 1);
130
- c->base.vtable = &jwt_vtable;
131
- c->key = key;
111
+ grpc_service_account_jwt_access_credentials::
112
+ grpc_service_account_jwt_access_credentials(grpc_auth_json_key key,
113
+ gpr_timespec token_lifetime)
114
+ : grpc_call_credentials(GRPC_CALL_CREDENTIALS_TYPE_JWT), key_(key) {
132
115
  gpr_timespec max_token_lifetime = grpc_max_auth_token_lifetime();
133
116
  if (gpr_time_cmp(token_lifetime, max_token_lifetime) > 0) {
134
117
  gpr_log(GPR_INFO,
@@ -136,10 +119,20 @@ grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
136
119
  static_cast<int>(max_token_lifetime.tv_sec));
137
120
  token_lifetime = grpc_max_auth_token_lifetime();
138
121
  }
139
- c->jwt_lifetime = token_lifetime;
140
- gpr_mu_init(&c->cache_mu);
141
- jwt_reset_cache(c);
142
- return &c->base;
122
+ jwt_lifetime_ = token_lifetime;
123
+ gpr_mu_init(&cache_mu_);
124
+ reset_cache();
125
+ }
126
+
127
+ grpc_core::RefCountedPtr<grpc_call_credentials>
128
+ grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
129
+ grpc_auth_json_key key, gpr_timespec token_lifetime) {
130
+ if (!grpc_auth_json_key_is_valid(&key)) {
131
+ gpr_log(GPR_ERROR, "Invalid input for jwt credentials creation");
132
+ return nullptr;
133
+ }
134
+ return grpc_core::MakeRefCounted<grpc_service_account_jwt_access_credentials>(
135
+ key, token_lifetime);
143
136
  }
144
137
 
145
138
  static char* redact_private_key(const char* json_key) {
@@ -182,9 +175,7 @@ grpc_call_credentials* grpc_service_account_jwt_access_credentials_create(
182
175
  }
183
176
  GPR_ASSERT(reserved == nullptr);
184
177
  grpc_core::ExecCtx exec_ctx;
185
- grpc_call_credentials* creds =
186
- grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
187
- grpc_auth_json_key_create_from_string(json_key), token_lifetime);
188
-
189
- return creds;
178
+ return grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
179
+ grpc_auth_json_key_create_from_string(json_key), token_lifetime)
180
+ .release();
190
181
  }
@@ -24,25 +24,44 @@
24
24
  #include "src/core/lib/security/credentials/credentials.h"
25
25
  #include "src/core/lib/security/credentials/jwt/json_token.h"
26
26
 
27
- typedef struct {
28
- grpc_call_credentials base;
27
+ class grpc_service_account_jwt_access_credentials
28
+ : public grpc_call_credentials {
29
+ public:
30
+ grpc_service_account_jwt_access_credentials(grpc_auth_json_key key,
31
+ gpr_timespec token_lifetime);
32
+ ~grpc_service_account_jwt_access_credentials() override;
33
+
34
+ bool get_request_metadata(grpc_polling_entity* pollent,
35
+ grpc_auth_metadata_context context,
36
+ grpc_credentials_mdelem_array* md_array,
37
+ grpc_closure* on_request_metadata,
38
+ grpc_error** error) override;
39
+
40
+ void cancel_get_request_metadata(grpc_credentials_mdelem_array* md_array,
41
+ grpc_error* error) override;
42
+
43
+ const gpr_timespec& jwt_lifetime() const { return jwt_lifetime_; }
44
+ const grpc_auth_json_key& key() const { return key_; }
45
+
46
+ private:
47
+ void reset_cache();
29
48
 
30
49
  // Have a simple cache for now with just 1 entry. We could have a map based on
31
50
  // the service_url for a more sophisticated one.
32
- gpr_mu cache_mu;
51
+ gpr_mu cache_mu_;
33
52
  struct {
34
- grpc_mdelem jwt_md;
35
- char* service_url;
53
+ grpc_mdelem jwt_md = GRPC_MDNULL;
54
+ char* service_url = nullptr;
36
55
  gpr_timespec jwt_expiration;
37
- } cached;
56
+ } cached_;
38
57
 
39
- grpc_auth_json_key key;
40
- gpr_timespec jwt_lifetime;
41
- } grpc_service_account_jwt_access_credentials;
58
+ grpc_auth_json_key key_;
59
+ gpr_timespec jwt_lifetime_;
60
+ };
42
61
 
43
62
  // Private constructor for jwt credentials from an already parsed json key.
44
63
  // Takes ownership of the key.
45
- grpc_call_credentials*
64
+ grpc_core::RefCountedPtr<grpc_call_credentials>
46
65
  grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
47
66
  grpc_auth_json_key key, gpr_timespec token_lifetime);
48
67
 
@@ -31,7 +31,9 @@
31
31
  #include <grpc/support/sync.h>
32
32
 
33
33
  extern "C" {
34
+ #include <openssl/bn.h>
34
35
  #include <openssl/pem.h>
36
+ #include <openssl/rsa.h>
35
37
  }
36
38
 
37
39
  #include "src/core/lib/gpr/string.h"
@@ -29,49 +29,36 @@
29
29
 
30
30
  #define GRPC_CREDENTIALS_TYPE_LOCAL "Local"
31
31
 
32
- static void local_credentials_destruct(grpc_channel_credentials* creds) {}
33
-
34
- static void local_server_credentials_destruct(grpc_server_credentials* creds) {}
35
-
36
- static grpc_security_status local_create_security_connector(
37
- grpc_channel_credentials* creds,
38
- grpc_call_credentials* request_metadata_creds, const char* target_name,
39
- const grpc_channel_args* args, grpc_channel_security_connector** sc,
32
+ grpc_core::RefCountedPtr<grpc_channel_security_connector>
33
+ grpc_local_credentials::create_security_connector(
34
+ grpc_core::RefCountedPtr<grpc_call_credentials> request_metadata_creds,
35
+ const char* target_name, const grpc_channel_args* args,
40
36
  grpc_channel_args** new_args) {
41
37
  return grpc_local_channel_security_connector_create(
42
- creds, request_metadata_creds, args, target_name, sc);
38
+ this->Ref(), std::move(request_metadata_creds), args, target_name);
43
39
  }
44
40
 
45
- static grpc_security_status local_server_create_security_connector(
46
- grpc_server_credentials* creds, grpc_server_security_connector** sc) {
47
- return grpc_local_server_security_connector_create(creds, sc);
41
+ grpc_core::RefCountedPtr<grpc_server_security_connector>
42
+ grpc_local_server_credentials::create_security_connector() {
43
+ return grpc_local_server_security_connector_create(this->Ref());
48
44
  }
49
45
 
50
- static const grpc_channel_credentials_vtable local_credentials_vtable = {
51
- local_credentials_destruct, local_create_security_connector,
52
- /*duplicate_without_call_credentials=*/nullptr};
53
-
54
- static const grpc_server_credentials_vtable local_server_credentials_vtable = {
55
- local_server_credentials_destruct, local_server_create_security_connector};
46
+ grpc_local_credentials::grpc_local_credentials(
47
+ grpc_local_connect_type connect_type)
48
+ : grpc_channel_credentials(GRPC_CREDENTIALS_TYPE_LOCAL),
49
+ connect_type_(connect_type) {}
56
50
 
57
51
  grpc_channel_credentials* grpc_local_credentials_create(
58
52
  grpc_local_connect_type connect_type) {
59
- auto creds = static_cast<grpc_local_credentials*>(
60
- gpr_zalloc(sizeof(grpc_local_credentials)));
61
- creds->connect_type = connect_type;
62
- creds->base.type = GRPC_CREDENTIALS_TYPE_LOCAL;
63
- creds->base.vtable = &local_credentials_vtable;
64
- gpr_ref_init(&creds->base.refcount, 1);
65
- return &creds->base;
53
+ return grpc_core::New<grpc_local_credentials>(connect_type);
66
54
  }
67
55
 
56
+ grpc_local_server_credentials::grpc_local_server_credentials(
57
+ grpc_local_connect_type connect_type)
58
+ : grpc_server_credentials(GRPC_CREDENTIALS_TYPE_LOCAL),
59
+ connect_type_(connect_type) {}
60
+
68
61
  grpc_server_credentials* grpc_local_server_credentials_create(
69
62
  grpc_local_connect_type connect_type) {
70
- auto creds = static_cast<grpc_local_server_credentials*>(
71
- gpr_zalloc(sizeof(grpc_local_server_credentials)));
72
- creds->connect_type = connect_type;
73
- creds->base.type = GRPC_CREDENTIALS_TYPE_LOCAL;
74
- creds->base.vtable = &local_server_credentials_vtable;
75
- gpr_ref_init(&creds->base.refcount, 1);
76
- return &creds->base;
63
+ return grpc_core::New<grpc_local_server_credentials>(connect_type);
77
64
  }