grpc 1.14.2 → 1.15.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 (113) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +307 -12
  3. data/etc/roots.pem +40 -163
  4. data/include/grpc/grpc.h +49 -0
  5. data/include/grpc/grpc_security.h +0 -6
  6. data/include/grpc/grpc_security_constants.h +6 -0
  7. data/include/grpc/impl/codegen/grpc_types.h +17 -2
  8. data/include/grpc/impl/codegen/port_platform.h +41 -4
  9. data/include/grpc/support/sync.h +0 -16
  10. data/src/{cpp → core}/ext/filters/census/grpc_context.cc +0 -0
  11. data/src/core/ext/filters/client_channel/client_channel.cc +40 -11
  12. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +11 -9
  13. data/src/core/ext/filters/client_channel/client_channel_channelz.h +4 -2
  14. data/src/core/ext/filters/client_channel/lb_policy.h +14 -11
  15. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +67 -90
  16. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +108 -91
  17. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +79 -25
  18. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +40 -0
  19. data/src/core/ext/filters/client_channel/resolver.h +8 -0
  20. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +11 -3
  21. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +13 -10
  22. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +18 -4
  23. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +13 -5
  24. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +537 -0
  25. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +6 -5
  26. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +11 -0
  27. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +29 -0
  28. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +29 -0
  29. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +9 -0
  30. data/src/core/ext/filters/client_channel/subchannel.cc +21 -8
  31. data/src/core/ext/filters/client_channel/subchannel.h +7 -0
  32. data/src/core/ext/filters/http/client_authority_filter.cc +1 -1
  33. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +24 -0
  34. data/src/core/ext/transport/chttp2/transport/flow_control.cc +10 -7
  35. data/src/core/lib/channel/channel_stack.h +1 -1
  36. data/src/core/lib/channel/channel_trace.cc +1 -1
  37. data/src/core/lib/channel/channel_trace.h +1 -1
  38. data/src/core/lib/channel/channelz.cc +37 -27
  39. data/src/core/lib/channel/channelz.h +13 -4
  40. data/src/core/lib/channel/channelz_registry.cc +89 -4
  41. data/src/core/lib/channel/channelz_registry.h +56 -39
  42. data/src/core/lib/gpr/arena.cc +33 -40
  43. data/src/core/lib/gprpp/fork.cc +41 -33
  44. data/src/core/lib/gprpp/fork.h +13 -4
  45. data/src/core/lib/gprpp/mutex_lock.h +42 -0
  46. data/src/core/lib/gprpp/orphanable.h +4 -2
  47. data/src/core/lib/gprpp/ref_counted.h +4 -2
  48. data/src/core/lib/gprpp/ref_counted_ptr.h +65 -13
  49. data/src/core/lib/iomgr/call_combiner.h +4 -1
  50. data/src/core/lib/iomgr/ev_epoll1_linux.cc +77 -17
  51. data/src/core/lib/iomgr/ev_epollex_linux.cc +8 -26
  52. data/src/core/lib/iomgr/ev_epollsig_linux.cc +10 -28
  53. data/src/core/lib/iomgr/ev_poll_posix.cc +144 -35
  54. data/src/core/lib/iomgr/ev_posix.cc +58 -9
  55. data/src/core/lib/iomgr/ev_posix.h +22 -8
  56. data/src/core/lib/iomgr/exec_ctx.cc +6 -0
  57. data/src/core/lib/iomgr/exec_ctx.h +2 -0
  58. data/src/core/lib/iomgr/executor.cc +148 -72
  59. data/src/core/lib/iomgr/executor.h +39 -6
  60. data/src/core/lib/iomgr/fork_posix.cc +12 -1
  61. data/src/core/lib/iomgr/iocp_windows.cc +9 -4
  62. data/src/core/lib/iomgr/lockfree_event.cc +5 -1
  63. data/src/core/lib/iomgr/port.h +15 -2
  64. data/src/core/lib/iomgr/resolve_address_posix.cc +3 -2
  65. data/src/core/lib/iomgr/resolve_address_windows.cc +3 -2
  66. data/src/core/lib/iomgr/resource_quota.cc +78 -0
  67. data/src/core/lib/iomgr/resource_quota.h +16 -0
  68. data/src/core/lib/iomgr/socket_mutator.cc +1 -1
  69. data/src/core/lib/iomgr/socket_mutator.h +1 -1
  70. data/src/core/lib/iomgr/socket_windows.cc +33 -0
  71. data/src/core/lib/iomgr/socket_windows.h +6 -0
  72. data/src/core/lib/iomgr/tcp_windows.cc +2 -2
  73. data/src/core/lib/iomgr/tcp_windows.h +2 -0
  74. data/src/core/lib/iomgr/timer.h +3 -2
  75. data/src/core/lib/json/json.cc +2 -1
  76. data/src/core/lib/security/credentials/jwt/json_token.h +2 -0
  77. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +2 -0
  78. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -1
  79. data/src/core/lib/security/security_connector/load_system_roots.h +29 -0
  80. data/src/core/lib/security/security_connector/load_system_roots_fallback.cc +32 -0
  81. data/src/core/lib/security/security_connector/load_system_roots_linux.cc +165 -0
  82. data/src/core/lib/security/security_connector/load_system_roots_linux.h +44 -0
  83. data/src/core/lib/security/security_connector/security_connector.cc +23 -4
  84. data/src/core/lib/security/transport/client_auth_filter.cc +0 -4
  85. data/src/core/lib/security/transport/server_auth_filter.cc +0 -2
  86. data/src/core/lib/surface/call.cc +7 -3
  87. data/src/core/lib/surface/channel.cc +18 -2
  88. data/src/core/lib/surface/completion_queue.cc +152 -15
  89. data/src/core/lib/surface/completion_queue.h +20 -1
  90. data/src/core/lib/surface/completion_queue_factory.cc +13 -4
  91. data/src/core/lib/surface/init.cc +2 -2
  92. data/src/core/lib/surface/init.h +0 -1
  93. data/src/core/lib/surface/version.cc +2 -2
  94. data/src/core/lib/transport/service_config.cc +2 -2
  95. data/src/core/lib/transport/service_config.h +3 -3
  96. data/src/core/lib/transport/transport.h +2 -0
  97. data/src/core/tsi/alts/crypt/aes_gcm.cc +2 -0
  98. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +8 -0
  99. data/src/core/tsi/grpc_shadow_boringssl.h +3006 -0
  100. data/src/core/tsi/ssl/session_cache/ssl_session.h +2 -0
  101. data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +5 -5
  102. data/src/core/tsi/ssl/session_cache/ssl_session_cache.h +2 -0
  103. data/src/core/tsi/ssl_transport_security.cc +5 -3
  104. data/src/core/tsi/ssl_types.h +2 -0
  105. data/src/ruby/ext/grpc/extconf.rb +1 -26
  106. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +12 -0
  107. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +18 -0
  108. data/src/ruby/lib/grpc/version.rb +1 -1
  109. data/src/ruby/spec/generic/client_stub_spec.rb +3 -3
  110. data/third_party/address_sorting/address_sorting.c +7 -2
  111. data/third_party/address_sorting/address_sorting_windows.c +43 -3
  112. data/third_party/address_sorting/include/address_sorting/address_sorting.h +3 -0
  113. metadata +40 -31
@@ -53,7 +53,7 @@
53
53
 
54
54
  extern grpc_core::TraceFlag grpc_tcp_trace;
55
55
 
56
- static grpc_error* set_non_block(SOCKET sock) {
56
+ grpc_error* grpc_tcp_set_non_block(SOCKET sock) {
57
57
  int status;
58
58
  uint32_t param = 1;
59
59
  DWORD ret;
@@ -90,7 +90,7 @@ static grpc_error* enable_loopback_fast_path(SOCKET sock) {
90
90
 
91
91
  grpc_error* grpc_tcp_prepare_socket(SOCKET sock) {
92
92
  grpc_error* err;
93
- err = set_non_block(sock);
93
+ err = grpc_tcp_set_non_block(sock);
94
94
  if (err != GRPC_ERROR_NONE) return err;
95
95
  err = set_dualstack(sock);
96
96
  if (err != GRPC_ERROR_NONE) return err;
@@ -46,6 +46,8 @@ grpc_endpoint* grpc_tcp_create(grpc_winsocket* socket,
46
46
 
47
47
  grpc_error* grpc_tcp_prepare_socket(SOCKET sock);
48
48
 
49
+ grpc_error* grpc_tcp_set_non_block(SOCKET sock);
50
+
49
51
  #endif
50
52
 
51
53
  #endif /* GRPC_CORE_LIB_IOMGR_TCP_WINDOWS_H */
@@ -61,10 +61,11 @@ typedef struct grpc_timer_vtable {
61
61
 
62
62
  /* Initialize *timer. When expired or canceled, closure will be called with
63
63
  error set to indicate if it expired (GRPC_ERROR_NONE) or was canceled
64
- (GRPC_ERROR_CANCELLED). timer_cb is guaranteed to be called exactly once, and
64
+ (GRPC_ERROR_CANCELLED). *closure is guaranteed to be called exactly once, and
65
65
  application code should check the error to determine how it was invoked. The
66
66
  application callback is also responsible for maintaining information about
67
- when to free up any user-level state. */
67
+ when to free up any user-level state. Behavior is undefined for a deadline of
68
+ GRPC_MILLIS_INF_FUTURE. */
68
69
  void grpc_timer_init(grpc_timer* timer, grpc_millis deadline,
69
70
  grpc_closure* closure);
70
71
 
@@ -58,6 +58,8 @@ void grpc_json_destroy(grpc_json* json) {
58
58
 
59
59
  grpc_json* grpc_json_link_child(grpc_json* parent, grpc_json* child,
60
60
  grpc_json* sibling) {
61
+ // link child up to parent
62
+ child->parent = parent;
61
63
  // first child case.
62
64
  if (parent->child == nullptr) {
63
65
  GPR_ASSERT(sibling == nullptr);
@@ -81,7 +83,6 @@ grpc_json* grpc_json_create_child(grpc_json* sibling, grpc_json* parent,
81
83
  grpc_json* child = grpc_json_create(type);
82
84
  grpc_json_link_child(parent, child, sibling);
83
85
  child->owns_value = owns_value;
84
- child->parent = parent;
85
86
  child->value = value;
86
87
  child->key = key;
87
88
  return child;
@@ -21,6 +21,8 @@
21
21
 
22
22
  #include <grpc/support/port_platform.h>
23
23
 
24
+ #include "src/core/tsi/grpc_shadow_boringssl.h"
25
+
24
26
  #include <grpc/slice.h>
25
27
  #include <openssl/rsa.h>
26
28
 
@@ -18,6 +18,8 @@
18
18
 
19
19
  #include <grpc/support/port_platform.h>
20
20
 
21
+ #include "src/core/tsi/grpc_shadow_boringssl.h"
22
+
21
23
  #include "src/core/lib/security/credentials/jwt/jwt_verifier.h"
22
24
 
23
25
  #include <limits.h>
@@ -235,7 +235,7 @@ static void on_oauth2_token_fetcher_http_response(void* user_data,
235
235
  access_token_md);
236
236
  } else {
237
237
  error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
238
- "Error occured when fetching oauth2 token.", &error, 1);
238
+ "Error occurred when fetching oauth2 token.", &error, 1);
239
239
  }
240
240
  GRPC_CLOSURE_SCHED(pending_request->on_request_metadata, error);
241
241
  grpc_polling_entity_del_from_pollset_set(
@@ -0,0 +1,29 @@
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_LOAD_SYSTEM_ROOTS_H
20
+ #define GRPC_CORE_LIB_SECURITY_SECURITY_CONNECTOR_LOAD_SYSTEM_ROOTS_H
21
+
22
+ namespace grpc_core {
23
+
24
+ // Returns a slice containing roots from the OS trust store
25
+ grpc_slice LoadSystemRootCerts();
26
+
27
+ } // namespace grpc_core
28
+
29
+ #endif /* GRPC_CORE_LIB_SECURITY_SECURITY_CONNECTOR_LOAD_SYSTEM_ROOTS_H */
@@ -0,0 +1,32 @@
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 <grpc/slice_buffer.h>
22
+ #include "src/core/lib/security/security_connector/load_system_roots.h"
23
+
24
+ #ifndef GPR_LINUX
25
+
26
+ namespace grpc_core {
27
+
28
+ grpc_slice LoadSystemRootCerts() { return grpc_empty_slice(); }
29
+
30
+ } // namespace grpc_core
31
+
32
+ #endif /* GPR_LINUX */
@@ -0,0 +1,165 @@
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 <grpc/slice_buffer.h>
22
+ #include "src/core/lib/security/security_connector/load_system_roots_linux.h"
23
+
24
+ #ifdef GPR_LINUX
25
+
26
+ #include "src/core/lib/security/security_connector/load_system_roots.h"
27
+
28
+ #include <dirent.h>
29
+ #include <fcntl.h>
30
+ #include <stdbool.h>
31
+ #include <string.h>
32
+ #include <sys/param.h>
33
+ #include <sys/stat.h>
34
+ #include <sys/types.h>
35
+ #include <unistd.h>
36
+
37
+ #include <grpc/support/alloc.h>
38
+ #include <grpc/support/log.h>
39
+ #include <grpc/support/string_util.h>
40
+
41
+ #include "src/core/lib/gpr/env.h"
42
+ #include "src/core/lib/gpr/string.h"
43
+ #include "src/core/lib/gpr/useful.h"
44
+ #include "src/core/lib/gprpp/inlined_vector.h"
45
+ #include "src/core/lib/iomgr/load_file.h"
46
+
47
+ namespace grpc_core {
48
+ namespace {
49
+
50
+ const char* kLinuxCertFiles[] = {
51
+ "/etc/ssl/certs/ca-certificates.crt", "/etc/pki/tls/certs/ca-bundle.crt",
52
+ "/etc/ssl/ca-bundle.pem", "/etc/pki/tls/cacert.pem",
53
+ "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem"};
54
+ const char* kLinuxCertDirectories[] = {
55
+ "/etc/ssl/certs", "/system/etc/security/cacerts", "/usr/local/share/certs",
56
+ "/etc/pki/tls/certs", "/etc/openssl/certs"};
57
+
58
+ grpc_slice GetSystemRootCerts() {
59
+ grpc_slice valid_bundle_slice = grpc_empty_slice();
60
+ size_t num_cert_files_ = GPR_ARRAY_SIZE(kLinuxCertFiles);
61
+ for (size_t i = 0; i < num_cert_files_; i++) {
62
+ grpc_error* error =
63
+ grpc_load_file(kLinuxCertFiles[i], 1, &valid_bundle_slice);
64
+ if (error == GRPC_ERROR_NONE) {
65
+ return valid_bundle_slice;
66
+ }
67
+ }
68
+ return grpc_empty_slice();
69
+ }
70
+
71
+ } // namespace
72
+
73
+ void GetAbsoluteFilePath(const char* valid_file_dir,
74
+ const char* file_entry_name, char* path_buffer) {
75
+ if (valid_file_dir != nullptr && file_entry_name != nullptr) {
76
+ int path_len = snprintf(path_buffer, MAXPATHLEN, "%s/%s", valid_file_dir,
77
+ file_entry_name);
78
+ if (path_len == 0) {
79
+ gpr_log(GPR_ERROR, "failed to get absolute path for file: %s",
80
+ file_entry_name);
81
+ }
82
+ }
83
+ }
84
+
85
+ grpc_slice CreateRootCertsBundle(const char* certs_directory) {
86
+ grpc_slice bundle_slice = grpc_empty_slice();
87
+ if (certs_directory == nullptr) {
88
+ return bundle_slice;
89
+ }
90
+ DIR* ca_directory = opendir(certs_directory);
91
+ if (ca_directory == nullptr) {
92
+ return bundle_slice;
93
+ }
94
+ struct FileData {
95
+ char path[MAXPATHLEN];
96
+ off_t size;
97
+ };
98
+ InlinedVector<FileData, 2> roots_filenames;
99
+ size_t total_bundle_size = 0;
100
+ struct dirent* directory_entry;
101
+ while ((directory_entry = readdir(ca_directory)) != nullptr) {
102
+ struct stat dir_entry_stat;
103
+ const char* file_entry_name = directory_entry->d_name;
104
+ FileData file_data;
105
+ GetAbsoluteFilePath(certs_directory, file_entry_name, file_data.path);
106
+ int stat_return = stat(file_data.path, &dir_entry_stat);
107
+ if (stat_return == -1 || !S_ISREG(dir_entry_stat.st_mode)) {
108
+ // no subdirectories.
109
+ if (stat_return == -1) {
110
+ gpr_log(GPR_ERROR, "failed to get status for file: %s", file_data.path);
111
+ }
112
+ continue;
113
+ }
114
+ file_data.size = dir_entry_stat.st_size;
115
+ total_bundle_size += file_data.size;
116
+ roots_filenames.push_back(file_data);
117
+ }
118
+ closedir(ca_directory);
119
+ char* bundle_string = static_cast<char*>(gpr_zalloc(total_bundle_size + 1));
120
+ size_t bytes_read = 0;
121
+ for (size_t i = 0; i < roots_filenames.size(); i++) {
122
+ int file_descriptor = open(roots_filenames[i].path, O_RDONLY);
123
+ if (file_descriptor != -1) {
124
+ // Read file into bundle.
125
+ size_t cert_file_size = roots_filenames[i].size;
126
+ int read_ret =
127
+ read(file_descriptor, bundle_string + bytes_read, cert_file_size);
128
+ if (read_ret != -1) {
129
+ bytes_read += read_ret;
130
+ } else {
131
+ gpr_log(GPR_ERROR, "failed to read file: %s", roots_filenames[i].path);
132
+ }
133
+ }
134
+ }
135
+ bundle_slice = grpc_slice_new(bundle_string, bytes_read, gpr_free);
136
+ return bundle_slice;
137
+ }
138
+
139
+ grpc_slice LoadSystemRootCerts() {
140
+ grpc_slice result = grpc_empty_slice();
141
+ // Prioritize user-specified custom directory if flag is set.
142
+ char* custom_dir = gpr_getenv("GRPC_SYSTEM_SSL_ROOTS_DIR");
143
+ if (custom_dir != nullptr) {
144
+ result = CreateRootCertsBundle(custom_dir);
145
+ gpr_free(custom_dir);
146
+ }
147
+ // If the custom directory is empty/invalid/not specified, fallback to
148
+ // distribution-specific directory.
149
+ if (GRPC_SLICE_IS_EMPTY(result)) {
150
+ result = GetSystemRootCerts();
151
+ }
152
+ if (GRPC_SLICE_IS_EMPTY(result)) {
153
+ for (size_t i = 0; i < GPR_ARRAY_SIZE(kLinuxCertDirectories); i++) {
154
+ result = CreateRootCertsBundle(kLinuxCertDirectories[i]);
155
+ if (!GRPC_SLICE_IS_EMPTY(result)) {
156
+ break;
157
+ }
158
+ }
159
+ }
160
+ return result;
161
+ }
162
+
163
+ } // namespace grpc_core
164
+
165
+ #endif /* GPR_LINUX */
@@ -0,0 +1,44 @@
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_LOAD_SYSTEM_ROOTS_LINUX_H
20
+ #define GRPC_CORE_LIB_SECURITY_SECURITY_CONNECTOR_LOAD_SYSTEM_ROOTS_LINUX_H
21
+
22
+ #include <grpc/support/port_platform.h>
23
+
24
+ #ifdef GPR_LINUX
25
+
26
+ namespace grpc_core {
27
+
28
+ // Creates a bundle slice containing the contents of all certificate files in
29
+ // a directory.
30
+ // Returns such slice.
31
+ // Exposed for testing purposes only.
32
+ grpc_slice CreateRootCertsBundle(const char* certs_directory);
33
+
34
+ // Gets the absolute file path needed to load a certificate file.
35
+ // Populates path_buffer, which must be of size MAXPATHLEN.
36
+ // Exposed for testing purposes only.
37
+ void GetAbsoluteFilePath(const char* valid_file_dir,
38
+ const char* file_entry_name, char* path_buffer);
39
+
40
+ } // namespace grpc_core
41
+
42
+ #endif /* GPR_LINUX */
43
+ #endif /* GRPC_CORE_LIB_SECURITY_SECURITY_CONNECTOR_LOAD_SYSTEM_ROOTS_LINUX_H \
44
+ */
@@ -21,7 +21,6 @@
21
21
  #include "src/core/lib/security/security_connector/security_connector.h"
22
22
 
23
23
  #include <stdbool.h>
24
- #include <string.h>
25
24
 
26
25
  #include <grpc/slice_buffer.h>
27
26
  #include <grpc/support/alloc.h>
@@ -39,6 +38,7 @@
39
38
  #include "src/core/lib/security/credentials/credentials.h"
40
39
  #include "src/core/lib/security/credentials/fake/fake_credentials.h"
41
40
  #include "src/core/lib/security/credentials/ssl/ssl_credentials.h"
41
+ #include "src/core/lib/security/security_connector/load_system_roots.h"
42
42
  #include "src/core/lib/security/transport/secure_endpoint.h"
43
43
  #include "src/core/lib/security/transport/security_handshaker.h"
44
44
  #include "src/core/lib/security/transport/target_authority_table.h"
@@ -57,6 +57,16 @@ static const char* installed_roots_path =
57
57
  INSTALL_PREFIX "/share/grpc/roots.pem";
58
58
  #endif
59
59
 
60
+ /** Environment variable used as a flag to enable/disable loading system root
61
+ certificates from the OS trust store. */
62
+ #ifndef GRPC_USE_SYSTEM_SSL_ROOTS_ENV_VAR
63
+ #define GRPC_USE_SYSTEM_SSL_ROOTS_ENV_VAR "GRPC_USE_SYSTEM_SSL_ROOTS"
64
+ #endif
65
+
66
+ #ifndef TSI_OPENSSL_ALPN_SUPPORT
67
+ #define TSI_OPENSSL_ALPN_SUPPORT 1
68
+ #endif
69
+
60
70
  /* -- Overridden default roots. -- */
61
71
 
62
72
  static grpc_ssl_roots_override_callback ssl_roots_override_cb = nullptr;
@@ -850,7 +860,8 @@ grpc_auth_context* grpc_ssl_peer_to_auth_context(const tsi_peer* peer) {
850
860
  static grpc_error* ssl_check_peer(grpc_security_connector* sc,
851
861
  const char* peer_name, const tsi_peer* peer,
852
862
  grpc_auth_context** auth_context) {
853
- /* Check the ALPN. */
863
+ #if TSI_OPENSSL_ALPN_SUPPORT
864
+ /* Check the ALPN if ALPN is supported. */
854
865
  const tsi_peer_property* p =
855
866
  tsi_peer_get_property_by_name(peer, TSI_SSL_ALPN_SELECTED_PROTOCOL);
856
867
  if (p == nullptr) {
@@ -861,7 +872,7 @@ static grpc_error* ssl_check_peer(grpc_security_connector* sc,
861
872
  return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
862
873
  "Cannot check peer: invalid ALPN value.");
863
874
  }
864
-
875
+ #endif /* TSI_OPENSSL_ALPN_SUPPORT */
865
876
  /* Check the peer name if specified. */
866
877
  if (peer_name != nullptr && !grpc_ssl_host_matches_name(peer, peer_name)) {
867
878
  char* msg;
@@ -1181,6 +1192,10 @@ const char* DefaultSslRootStore::GetPemRootCerts() {
1181
1192
 
1182
1193
  grpc_slice DefaultSslRootStore::ComputePemRootCerts() {
1183
1194
  grpc_slice result = grpc_empty_slice();
1195
+ char* use_system_roots_env_value =
1196
+ gpr_getenv(GRPC_USE_SYSTEM_SSL_ROOTS_ENV_VAR);
1197
+ const bool use_system_roots = gpr_is_true(use_system_roots_env_value);
1198
+ gpr_free(use_system_roots_env_value);
1184
1199
  // First try to load the roots from the environment.
1185
1200
  char* default_root_certs_path =
1186
1201
  gpr_getenv(GRPC_DEFAULT_SSL_ROOTS_FILE_PATH_ENV_VAR);
@@ -1202,7 +1217,11 @@ grpc_slice DefaultSslRootStore::ComputePemRootCerts() {
1202
1217
  }
1203
1218
  gpr_free(pem_root_certs);
1204
1219
  }
1205
- // Fall back to installed certs if needed.
1220
+ // Try loading roots from OS trust store if flag is enabled.
1221
+ if (GRPC_SLICE_IS_EMPTY(result) && use_system_roots) {
1222
+ result = LoadSystemRootCerts();
1223
+ }
1224
+ // Fallback to roots manually shipped with gRPC.
1206
1225
  if (GRPC_SLICE_IS_EMPTY(result) &&
1207
1226
  ovrd_res != GRPC_SSL_ROOTS_OVERRIDE_FAIL_PERMANENTLY) {
1208
1227
  GRPC_LOG_IF_ERROR("load_file",
@@ -167,7 +167,6 @@ static void cancel_get_request_metadata(void* arg, grpc_error* error) {
167
167
  grpc_call_credentials_cancel_get_request_metadata(
168
168
  calld->creds, &calld->md_array, GRPC_ERROR_REF(error));
169
169
  }
170
- GRPC_CALL_STACK_UNREF(calld->owning_call, "cancel_get_request_metadata");
171
170
  }
172
171
 
173
172
  static void send_security_metadata(grpc_call_element* elem,
@@ -222,7 +221,6 @@ static void send_security_metadata(grpc_call_element* elem,
222
221
  GRPC_ERROR_UNREF(error);
223
222
  } else {
224
223
  // Async return; register cancellation closure with call combiner.
225
- GRPC_CALL_STACK_REF(calld->owning_call, "cancel_get_request_metadata");
226
224
  grpc_call_combiner_set_notify_on_cancel(
227
225
  calld->call_combiner,
228
226
  GRPC_CLOSURE_INIT(&calld->get_request_metadata_cancel_closure,
@@ -265,7 +263,6 @@ static void cancel_check_call_host(void* arg, grpc_error* error) {
265
263
  chand->security_connector, &calld->async_result_closure,
266
264
  GRPC_ERROR_REF(error));
267
265
  }
268
- GRPC_CALL_STACK_UNREF(calld->owning_call, "cancel_check_call_host");
269
266
  }
270
267
 
271
268
  static void auth_start_transport_stream_op_batch(
@@ -318,7 +315,6 @@ static void auth_start_transport_stream_op_batch(
318
315
  GRPC_ERROR_UNREF(error);
319
316
  } else {
320
317
  // Async return; register cancellation closure with call combiner.
321
- GRPC_CALL_STACK_REF(calld->owning_call, "cancel_check_call_host");
322
318
  grpc_call_combiner_set_notify_on_cancel(
323
319
  calld->call_combiner,
324
320
  GRPC_CLOSURE_INIT(&calld->check_call_host_cancel_closure,