grpc 1.26.0 → 1.27.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.
- checksums.yaml +4 -4
- data/Makefile +1654 -1519
- data/etc/roots.pem +44 -0
- data/include/grpc/grpc_security.h +37 -15
- data/include/grpc/grpc_security_constants.h +27 -0
- data/include/grpc/impl/codegen/grpc_types.h +14 -0
- data/include/grpc/impl/codegen/port_platform.h +1 -1
- data/src/core/ext/filters/client_channel/client_channel.cc +0 -20
- data/src/core/ext/filters/client_channel/http_proxy.cc +4 -4
- data/src/core/ext/filters/client_channel/lb_policy.cc +4 -3
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +191 -201
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc +89 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +40 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +3 -2
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +88 -121
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +28 -57
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +0 -7
- data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +8 -9
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +53 -34
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +18 -5
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +24 -19
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +2 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +4 -2
- data/src/core/ext/filters/client_channel/server_address.cc +6 -9
- data/src/core/ext/filters/client_channel/server_address.h +3 -10
- data/src/core/ext/filters/client_channel/xds/xds_api.cc +394 -150
- data/src/core/ext/filters/client_channel/xds/xds_api.h +75 -35
- data/src/core/ext/filters/client_channel/xds/xds_bootstrap.cc +59 -22
- data/src/core/ext/filters/client_channel/xds/xds_bootstrap.h +13 -9
- data/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc +8 -6
- data/src/core/ext/filters/client_channel/xds/xds_client.cc +456 -175
- data/src/core/ext/filters/client_channel/xds/xds_client.h +33 -21
- data/src/core/ext/filters/client_channel/xds/xds_client_stats.cc +5 -8
- data/src/core/ext/filters/client_channel/xds/xds_client_stats.h +18 -24
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +2 -2
- data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c +13 -5
- data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +34 -0
- data/src/core/lib/channel/channelz.h +11 -1
- data/src/core/lib/gpr/time_precise.cc +1 -1
- data/src/core/lib/gprpp/optional.h +26 -0
- data/src/core/lib/gprpp/string_view.h +14 -10
- data/src/core/lib/iomgr/executor.cc +1 -1
- data/src/core/lib/iomgr/fork_posix.cc +4 -0
- data/src/core/lib/iomgr/poller/eventmanager_libuv.cc +87 -0
- data/src/core/lib/iomgr/poller/eventmanager_libuv.h +88 -0
- data/src/core/lib/iomgr/socket_utils_common_posix.cc +14 -0
- data/src/core/lib/iomgr/socket_utils_posix.h +12 -0
- data/src/core/lib/iomgr/tcp_custom.h +3 -0
- data/src/core/lib/iomgr/tcp_posix.cc +607 -56
- data/src/core/lib/iomgr/tcp_server_custom.cc +15 -2
- data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +8 -0
- data/src/core/lib/json/json.h +11 -1
- data/src/core/lib/json/json_reader.cc +206 -28
- data/src/core/lib/json/json_writer.cc +111 -24
- data/src/core/lib/security/credentials/composite/composite_credentials.cc +7 -0
- data/src/core/lib/security/credentials/composite/composite_credentials.h +5 -1
- data/src/core/lib/security/credentials/credentials.h +10 -1
- data/src/core/lib/security/credentials/fake/fake_credentials.h +2 -1
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -1
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +6 -4
- data/src/core/lib/security/credentials/plugin/plugin_credentials.h +2 -1
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +20 -0
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +8 -0
- data/src/core/lib/security/credentials/tls/{spiffe_credentials.cc → tls_credentials.cc} +23 -24
- data/src/core/lib/security/credentials/tls/{spiffe_credentials.h → tls_credentials.h} +9 -9
- data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +13 -0
- data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +22 -2
- data/src/core/lib/security/security_connector/load_system_roots_fallback.cc +2 -2
- data/src/core/lib/security/security_connector/load_system_roots_linux.cc +2 -2
- data/src/core/lib/security/security_connector/local/local_security_connector.cc +30 -3
- data/src/core/lib/security/security_connector/ssl_utils.cc +45 -3
- data/src/core/lib/security/security_connector/ssl_utils.h +12 -0
- data/src/core/lib/security/security_connector/tls/{spiffe_security_connector.cc → tls_security_connector.cc} +82 -69
- data/src/core/lib/security/security_connector/tls/{spiffe_security_connector.h → tls_security_connector.h} +17 -18
- data/src/core/lib/security/transport/client_auth_filter.cc +33 -0
- data/src/core/lib/surface/completion_queue.cc +22 -1
- data/src/core/lib/surface/version.cc +1 -1
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +11 -1
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +1 -1
- data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +3 -3
- data/src/core/tsi/fake_transport_security.cc +7 -3
- data/src/core/tsi/fake_transport_security.h +2 -0
- data/src/core/tsi/ssl_transport_security.cc +144 -8
- data/src/core/tsi/ssl_transport_security.h +15 -1
- data/src/core/tsi/transport_security.cc +13 -0
- data/src/core/tsi/transport_security_grpc.cc +2 -2
- data/src/core/tsi/transport_security_grpc.h +2 -2
- data/src/core/tsi/transport_security_interface.h +12 -0
- data/src/ruby/bin/math_pb.rb +5 -5
- data/src/ruby/ext/grpc/rb_call_credentials.c +4 -1
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +4 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/grpc/health/v1/health_pb.rb +3 -3
- data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +1 -1
- data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +23 -13
- data/third_party/abseil-cpp/absl/algorithm/algorithm.h +159 -0
- data/third_party/abseil-cpp/absl/base/attributes.h +609 -0
- data/third_party/abseil-cpp/absl/base/call_once.h +226 -0
- data/third_party/abseil-cpp/absl/base/casts.h +184 -0
- data/third_party/abseil-cpp/absl/base/config.h +622 -0
- data/third_party/abseil-cpp/absl/base/const_init.h +76 -0
- data/third_party/abseil-cpp/absl/base/dynamic_annotations.cc +129 -0
- data/third_party/abseil-cpp/absl/base/dynamic_annotations.h +389 -0
- data/third_party/abseil-cpp/absl/base/internal/atomic_hook.h +179 -0
- data/third_party/abseil-cpp/absl/base/internal/bits.h +218 -0
- data/third_party/abseil-cpp/absl/base/internal/cycleclock.cc +107 -0
- data/third_party/abseil-cpp/absl/base/internal/cycleclock.h +94 -0
- data/third_party/abseil-cpp/absl/base/internal/endian.h +266 -0
- data/third_party/abseil-cpp/absl/base/internal/hide_ptr.h +51 -0
- data/third_party/abseil-cpp/absl/base/internal/identity.h +37 -0
- data/third_party/abseil-cpp/absl/base/internal/inline_variable.h +107 -0
- data/third_party/abseil-cpp/absl/base/internal/invoke.h +187 -0
- data/third_party/abseil-cpp/absl/base/internal/low_level_scheduling.h +107 -0
- data/third_party/abseil-cpp/absl/base/internal/per_thread_tls.h +52 -0
- data/third_party/abseil-cpp/absl/base/internal/raw_logging.cc +237 -0
- data/third_party/abseil-cpp/absl/base/internal/raw_logging.h +179 -0
- data/third_party/abseil-cpp/absl/base/internal/scheduling_mode.h +58 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock.cc +233 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock.h +243 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_akaros.inc +35 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_linux.inc +67 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_posix.inc +46 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_wait.cc +81 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_wait.h +93 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_win32.inc +37 -0
- data/third_party/abseil-cpp/absl/base/internal/sysinfo.cc +414 -0
- data/third_party/abseil-cpp/absl/base/internal/sysinfo.h +66 -0
- data/third_party/abseil-cpp/absl/base/internal/thread_annotations.h +271 -0
- data/third_party/abseil-cpp/absl/base/internal/thread_identity.cc +140 -0
- data/third_party/abseil-cpp/absl/base/internal/thread_identity.h +250 -0
- data/third_party/abseil-cpp/absl/base/internal/throw_delegate.cc +108 -0
- data/third_party/abseil-cpp/absl/base/internal/throw_delegate.h +75 -0
- data/third_party/abseil-cpp/absl/base/internal/tsan_mutex_interface.h +66 -0
- data/third_party/abseil-cpp/absl/base/internal/unaligned_access.h +158 -0
- data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.cc +103 -0
- data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.h +124 -0
- data/third_party/abseil-cpp/absl/base/log_severity.cc +27 -0
- data/third_party/abseil-cpp/absl/base/log_severity.h +121 -0
- data/third_party/abseil-cpp/absl/base/macros.h +220 -0
- data/third_party/abseil-cpp/absl/base/optimization.h +181 -0
- data/third_party/abseil-cpp/absl/base/options.h +214 -0
- data/third_party/abseil-cpp/absl/base/policy_checks.h +111 -0
- data/third_party/abseil-cpp/absl/base/port.h +26 -0
- data/third_party/abseil-cpp/absl/base/thread_annotations.h +280 -0
- data/third_party/abseil-cpp/absl/container/inlined_vector.h +848 -0
- data/third_party/abseil-cpp/absl/container/internal/compressed_tuple.h +265 -0
- data/third_party/abseil-cpp/absl/container/internal/inlined_vector.h +892 -0
- data/third_party/abseil-cpp/absl/memory/memory.h +695 -0
- data/third_party/abseil-cpp/absl/meta/type_traits.h +759 -0
- data/third_party/abseil-cpp/absl/numeric/int128.cc +404 -0
- data/third_party/abseil-cpp/absl/numeric/int128.h +1091 -0
- data/third_party/abseil-cpp/absl/numeric/int128_have_intrinsic.inc +302 -0
- data/third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc +308 -0
- data/third_party/abseil-cpp/absl/strings/ascii.cc +200 -0
- data/third_party/abseil-cpp/absl/strings/ascii.h +241 -0
- data/third_party/abseil-cpp/absl/strings/charconv.cc +985 -0
- data/third_party/abseil-cpp/absl/strings/charconv.h +119 -0
- data/third_party/abseil-cpp/absl/strings/escaping.cc +949 -0
- data/third_party/abseil-cpp/absl/strings/escaping.h +164 -0
- data/third_party/abseil-cpp/absl/strings/internal/char_map.h +156 -0
- data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.cc +359 -0
- data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.h +421 -0
- data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.cc +504 -0
- data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.h +99 -0
- data/third_party/abseil-cpp/absl/strings/internal/escaping.cc +180 -0
- data/third_party/abseil-cpp/absl/strings/internal/escaping.h +58 -0
- data/third_party/abseil-cpp/absl/strings/internal/memutil.cc +112 -0
- data/third_party/abseil-cpp/absl/strings/internal/memutil.h +148 -0
- data/third_party/abseil-cpp/absl/strings/internal/ostringstream.cc +36 -0
- data/third_party/abseil-cpp/absl/strings/internal/ostringstream.h +89 -0
- data/third_party/abseil-cpp/absl/strings/internal/resize_uninitialized.h +73 -0
- data/third_party/abseil-cpp/absl/strings/internal/stl_type_traits.h +248 -0
- data/third_party/abseil-cpp/absl/strings/internal/str_join_internal.h +314 -0
- data/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h +455 -0
- data/third_party/abseil-cpp/absl/strings/internal/utf8.cc +53 -0
- data/third_party/abseil-cpp/absl/strings/internal/utf8.h +50 -0
- data/third_party/abseil-cpp/absl/strings/match.cc +40 -0
- data/third_party/abseil-cpp/absl/strings/match.h +90 -0
- data/third_party/abseil-cpp/absl/strings/numbers.cc +916 -0
- data/third_party/abseil-cpp/absl/strings/numbers.h +263 -0
- data/third_party/abseil-cpp/absl/strings/str_cat.cc +246 -0
- data/third_party/abseil-cpp/absl/strings/str_cat.h +408 -0
- data/third_party/abseil-cpp/absl/strings/str_join.h +293 -0
- data/third_party/abseil-cpp/absl/strings/str_replace.cc +82 -0
- data/third_party/abseil-cpp/absl/strings/str_replace.h +219 -0
- data/third_party/abseil-cpp/absl/strings/str_split.cc +139 -0
- data/third_party/abseil-cpp/absl/strings/str_split.h +513 -0
- data/third_party/abseil-cpp/absl/strings/string_view.cc +235 -0
- data/third_party/abseil-cpp/absl/strings/string_view.h +615 -0
- data/third_party/abseil-cpp/absl/strings/strip.h +91 -0
- data/third_party/abseil-cpp/absl/strings/substitute.cc +171 -0
- data/third_party/abseil-cpp/absl/strings/substitute.h +693 -0
- data/third_party/abseil-cpp/absl/types/bad_optional_access.cc +48 -0
- data/third_party/abseil-cpp/absl/types/bad_optional_access.h +78 -0
- data/third_party/abseil-cpp/absl/types/internal/optional.h +396 -0
- data/third_party/abseil-cpp/absl/types/internal/span.h +128 -0
- data/third_party/abseil-cpp/absl/types/optional.h +776 -0
- data/third_party/abseil-cpp/absl/types/span.h +713 -0
- data/third_party/abseil-cpp/absl/utility/utility.h +350 -0
- data/third_party/upb/upb/decode.c +4 -0
- data/third_party/upb/upb/port.c +0 -1
- data/third_party/upb/upb/port_def.inc +1 -3
- data/third_party/upb/upb/table.c +2 -1
- metadata +147 -43
- data/src/core/lib/json/json_common.h +0 -34
- data/src/core/lib/json/json_reader.h +0 -146
- data/src/core/lib/json/json_string.cc +0 -367
- data/src/core/lib/json/json_writer.h +0 -84
@@ -16,8 +16,8 @@
|
|
16
16
|
*
|
17
17
|
*/
|
18
18
|
|
19
|
-
#ifndef
|
20
|
-
#define
|
19
|
+
#ifndef GRPC_CORE_LIB_SECURITY_SECURITY_CONNECTOR_TLS_TLS_SECURITY_CONNECTOR_H
|
20
|
+
#define GRPC_CORE_LIB_SECURITY_SECURITY_CONNECTOR_TLS_TLS_SECURITY_CONNECTOR_H
|
21
21
|
|
22
22
|
#include <grpc/support/port_platform.h>
|
23
23
|
|
@@ -25,27 +25,27 @@
|
|
25
25
|
#include "src/core/lib/security/context/security_context.h"
|
26
26
|
#include "src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h"
|
27
27
|
|
28
|
-
#define
|
28
|
+
#define GRPC_TLS_TRANSPORT_SECURITY_TYPE "tls"
|
29
29
|
|
30
30
|
namespace grpc_core {
|
31
31
|
|
32
|
-
//
|
33
|
-
class
|
32
|
+
// TLS channel security connector.
|
33
|
+
class TlsChannelSecurityConnector final
|
34
34
|
: public grpc_channel_security_connector {
|
35
35
|
public:
|
36
|
-
// static factory method to create a
|
36
|
+
// static factory method to create a TLS channel security connector.
|
37
37
|
static grpc_core::RefCountedPtr<grpc_channel_security_connector>
|
38
|
-
|
38
|
+
CreateTlsChannelSecurityConnector(
|
39
39
|
grpc_core::RefCountedPtr<grpc_channel_credentials> channel_creds,
|
40
40
|
grpc_core::RefCountedPtr<grpc_call_credentials> request_metadata_creds,
|
41
41
|
const char* target_name, const char* overridden_target_name,
|
42
42
|
tsi_ssl_session_cache* ssl_session_cache);
|
43
43
|
|
44
|
-
|
44
|
+
TlsChannelSecurityConnector(
|
45
45
|
grpc_core::RefCountedPtr<grpc_channel_credentials> channel_creds,
|
46
46
|
grpc_core::RefCountedPtr<grpc_call_credentials> request_metadata_creds,
|
47
47
|
const char* target_name, const char* overridden_target_name);
|
48
|
-
~
|
48
|
+
~TlsChannelSecurityConnector() override;
|
49
49
|
|
50
50
|
void add_handshakers(const grpc_channel_args* args,
|
51
51
|
grpc_pollset_set* interested_parties,
|
@@ -105,18 +105,17 @@ class SpiffeChannelSecurityConnector final
|
|
105
105
|
grpc_core::RefCountedPtr<grpc_tls_key_materials_config> key_materials_config_;
|
106
106
|
};
|
107
107
|
|
108
|
-
//
|
109
|
-
class
|
110
|
-
: public grpc_server_security_connector {
|
108
|
+
// TLS server security connector.
|
109
|
+
class TlsServerSecurityConnector final : public grpc_server_security_connector {
|
111
110
|
public:
|
112
|
-
// static factory method to create a
|
111
|
+
// static factory method to create a TLS server security connector.
|
113
112
|
static grpc_core::RefCountedPtr<grpc_server_security_connector>
|
114
|
-
|
113
|
+
CreateTlsServerSecurityConnector(
|
115
114
|
grpc_core::RefCountedPtr<grpc_server_credentials> server_creds);
|
116
115
|
|
117
|
-
explicit
|
116
|
+
explicit TlsServerSecurityConnector(
|
118
117
|
grpc_core::RefCountedPtr<grpc_server_credentials> server_creds);
|
119
|
-
~
|
118
|
+
~TlsServerSecurityConnector() override;
|
120
119
|
|
121
120
|
void add_handshakers(const grpc_channel_args* args,
|
122
121
|
grpc_pollset_set* interested_parties,
|
@@ -149,10 +148,10 @@ class SpiffeServerSecurityConnector final
|
|
149
148
|
grpc_status_code TlsFetchKeyMaterials(
|
150
149
|
const grpc_core::RefCountedPtr<grpc_tls_key_materials_config>&
|
151
150
|
key_materials_config,
|
152
|
-
const grpc_tls_credentials_options& options,
|
151
|
+
const grpc_tls_credentials_options& options, bool server_config,
|
153
152
|
grpc_ssl_certificate_config_reload_status* status);
|
154
153
|
|
155
154
|
} // namespace grpc_core
|
156
155
|
|
157
|
-
#endif /*
|
156
|
+
#endif /* GRPC_CORE_LIB_SECURITY_SECURITY_CONNECTOR_TLS_TLS_SECURITY_CONNECTOR_H \
|
158
157
|
*/
|
@@ -266,6 +266,39 @@ static void send_security_metadata(grpc_call_element* elem,
|
|
266
266
|
call_creds_has_md ? ctx->creds->Ref() : channel_call_creds->Ref();
|
267
267
|
}
|
268
268
|
|
269
|
+
/* Check security level of call credential and channel, and do not send
|
270
|
+
* metadata if the check fails. */
|
271
|
+
grpc_auth_property_iterator it = grpc_auth_context_find_properties_by_name(
|
272
|
+
chand->auth_context.get(), GRPC_TRANSPORT_SECURITY_LEVEL_PROPERTY_NAME);
|
273
|
+
const grpc_auth_property* prop = grpc_auth_property_iterator_next(&it);
|
274
|
+
if (prop == nullptr) {
|
275
|
+
grpc_transport_stream_op_batch_finish_with_failure(
|
276
|
+
batch,
|
277
|
+
grpc_error_set_int(
|
278
|
+
GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
279
|
+
"Established channel does not have an auth property "
|
280
|
+
"representing a security level."),
|
281
|
+
GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAUTHENTICATED),
|
282
|
+
calld->call_combiner);
|
283
|
+
return;
|
284
|
+
}
|
285
|
+
grpc_security_level call_cred_security_level =
|
286
|
+
calld->creds->min_security_level();
|
287
|
+
int is_security_level_ok = grpc_check_security_level(
|
288
|
+
grpc_tsi_security_level_string_to_enum(prop->value),
|
289
|
+
call_cred_security_level);
|
290
|
+
if (!is_security_level_ok) {
|
291
|
+
grpc_transport_stream_op_batch_finish_with_failure(
|
292
|
+
batch,
|
293
|
+
grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
294
|
+
"Established channel does not have a sufficient "
|
295
|
+
"security level to transfer call credential."),
|
296
|
+
GRPC_ERROR_INT_GRPC_STATUS,
|
297
|
+
GRPC_STATUS_UNAUTHENTICATED),
|
298
|
+
calld->call_combiner);
|
299
|
+
return;
|
300
|
+
}
|
301
|
+
|
269
302
|
grpc_auth_metadata_context_build(
|
270
303
|
chand->security_connector->url_scheme(), calld->host, calld->method,
|
271
304
|
chand->auth_context.get(), &calld->auth_md_context);
|
@@ -241,7 +241,14 @@ class CqEventQueue {
|
|
241
241
|
};
|
242
242
|
|
243
243
|
struct cq_next_data {
|
244
|
-
~cq_next_data() {
|
244
|
+
~cq_next_data() {
|
245
|
+
GPR_ASSERT(queue.num_items() == 0);
|
246
|
+
#ifndef NDEBUG
|
247
|
+
if (pending_events.Load(grpc_core::MemoryOrder::ACQUIRE) != 0) {
|
248
|
+
gpr_log(GPR_ERROR, "Destroying CQ without draining it fully.");
|
249
|
+
}
|
250
|
+
#endif
|
251
|
+
}
|
245
252
|
|
246
253
|
/** Completed events for completion-queues of type GRPC_CQ_NEXT */
|
247
254
|
CqEventQueue queue;
|
@@ -267,6 +274,11 @@ struct cq_pluck_data {
|
|
267
274
|
~cq_pluck_data() {
|
268
275
|
GPR_ASSERT(completed_head.next ==
|
269
276
|
reinterpret_cast<uintptr_t>(&completed_head));
|
277
|
+
#ifndef NDEBUG
|
278
|
+
if (pending_events.Load(grpc_core::MemoryOrder::ACQUIRE) != 0) {
|
279
|
+
gpr_log(GPR_ERROR, "Destroying CQ without draining it fully.");
|
280
|
+
}
|
281
|
+
#endif
|
270
282
|
}
|
271
283
|
|
272
284
|
/** Completed events for completion-queues of type GRPC_CQ_PLUCK */
|
@@ -298,6 +310,15 @@ struct cq_callback_data {
|
|
298
310
|
cq_callback_data(
|
299
311
|
grpc_experimental_completion_queue_functor* shutdown_callback)
|
300
312
|
: shutdown_callback(shutdown_callback) {}
|
313
|
+
|
314
|
+
~cq_callback_data() {
|
315
|
+
#ifndef NDEBUG
|
316
|
+
if (pending_events.Load(grpc_core::MemoryOrder::ACQUIRE) != 0) {
|
317
|
+
gpr_log(GPR_ERROR, "Destroying CQ without draining it fully.");
|
318
|
+
}
|
319
|
+
#endif
|
320
|
+
}
|
321
|
+
|
301
322
|
/** No actual completed events queue, unlike other types */
|
302
323
|
|
303
324
|
/** Number of pending events (+1 if we're not shutdown).
|
@@ -86,7 +86,7 @@ static tsi_result handshaker_result_extract_peer(
|
|
86
86
|
alts_tsi_handshaker_result* result =
|
87
87
|
reinterpret_cast<alts_tsi_handshaker_result*>(
|
88
88
|
const_cast<tsi_handshaker_result*>(self));
|
89
|
-
GPR_ASSERT(kTsiAltsNumOfPeerProperties ==
|
89
|
+
GPR_ASSERT(kTsiAltsNumOfPeerProperties == 5);
|
90
90
|
tsi_result ok = tsi_construct_peer(kTsiAltsNumOfPeerProperties, peer);
|
91
91
|
int index = 0;
|
92
92
|
if (ok != TSI_OK) {
|
@@ -131,6 +131,16 @@ static tsi_result handshaker_result_extract_peer(
|
|
131
131
|
tsi_peer_destruct(peer);
|
132
132
|
gpr_log(GPR_ERROR, "Failed to set tsi peer property");
|
133
133
|
}
|
134
|
+
index++;
|
135
|
+
GPR_ASSERT(&peer->properties[index] != nullptr);
|
136
|
+
ok = tsi_construct_string_peer_property_from_cstring(
|
137
|
+
TSI_SECURITY_LEVEL_PEER_PROPERTY,
|
138
|
+
tsi_security_level_to_string(TSI_PRIVACY_AND_INTEGRITY),
|
139
|
+
&peer->properties[index]);
|
140
|
+
if (ok != TSI_OK) {
|
141
|
+
tsi_peer_destruct(peer);
|
142
|
+
gpr_log(GPR_ERROR, "Failed to set tsi peer property");
|
143
|
+
}
|
134
144
|
GPR_ASSERT(++index == kTsiAltsNumOfPeerProperties);
|
135
145
|
return ok;
|
136
146
|
}
|
@@ -234,11 +234,11 @@ static void alts_zero_copy_grpc_protector_destroy(
|
|
234
234
|
}
|
235
235
|
|
236
236
|
static tsi_result alts_zero_copy_grpc_protector_max_frame_size(
|
237
|
-
tsi_zero_copy_grpc_protector* self, size_t
|
238
|
-
if (self == nullptr) return TSI_INVALID_ARGUMENT;
|
237
|
+
tsi_zero_copy_grpc_protector* self, size_t* max_frame_size) {
|
238
|
+
if (self == nullptr || max_frame_size == nullptr) return TSI_INVALID_ARGUMENT;
|
239
239
|
alts_zero_copy_grpc_protector* protector =
|
240
240
|
reinterpret_cast<alts_zero_copy_grpc_protector*>(self);
|
241
|
-
max_frame_size = protector->max_protected_frame_size;
|
241
|
+
*max_frame_size = protector->max_protected_frame_size;
|
242
242
|
return TSI_OK;
|
243
243
|
}
|
244
244
|
|
@@ -495,14 +495,18 @@ typedef struct {
|
|
495
495
|
} fake_handshaker_result;
|
496
496
|
|
497
497
|
static tsi_result fake_handshaker_result_extract_peer(
|
498
|
-
const tsi_handshaker_result*
|
499
|
-
/* Construct a tsi_peer with 1 property: certificate type. */
|
500
|
-
tsi_result result = tsi_construct_peer(
|
498
|
+
const tsi_handshaker_result* self, tsi_peer* peer) {
|
499
|
+
/* Construct a tsi_peer with 1 property: certificate type, security_level. */
|
500
|
+
tsi_result result = tsi_construct_peer(2, peer);
|
501
501
|
if (result != TSI_OK) return result;
|
502
502
|
result = tsi_construct_string_peer_property_from_cstring(
|
503
503
|
TSI_CERTIFICATE_TYPE_PEER_PROPERTY, TSI_FAKE_CERTIFICATE_TYPE,
|
504
504
|
&peer->properties[0]);
|
505
505
|
if (result != TSI_OK) tsi_peer_destruct(peer);
|
506
|
+
result = tsi_construct_string_peer_property_from_cstring(
|
507
|
+
TSI_SECURITY_LEVEL_PEER_PROPERTY,
|
508
|
+
tsi_security_level_to_string(TSI_SECURITY_NONE), &peer->properties[1]);
|
509
|
+
if (result != TSI_OK) tsi_peer_destruct(peer);
|
506
510
|
return result;
|
507
511
|
}
|
508
512
|
|
@@ -25,6 +25,8 @@
|
|
25
25
|
|
26
26
|
/* Value for the TSI_CERTIFICATE_TYPE_PEER_PROPERTY property for FAKE certs. */
|
27
27
|
#define TSI_FAKE_CERTIFICATE_TYPE "FAKE"
|
28
|
+
/* Value of the TSI_SECURITY_LEVEL_PEER_PROPERTY property for FAKE certs. */
|
29
|
+
#define TSI_FAKE_SECURITY_LEVEL "TSI_SECURITY_NONE"
|
28
30
|
|
29
31
|
/* Creates a fake handshaker that will create a fake frame protector.
|
30
32
|
|
@@ -35,6 +35,7 @@
|
|
35
35
|
#include <sys/socket.h>
|
36
36
|
#endif
|
37
37
|
|
38
|
+
#include <grpc/grpc_security.h>
|
38
39
|
#include <grpc/support/alloc.h>
|
39
40
|
#include <grpc/support/log.h>
|
40
41
|
#include <grpc/support/string_util.h>
|
@@ -44,6 +45,7 @@
|
|
44
45
|
extern "C" {
|
45
46
|
#include <openssl/bio.h>
|
46
47
|
#include <openssl/crypto.h> /* For OPENSSL_free */
|
48
|
+
#include <openssl/engine.h>
|
47
49
|
#include <openssl/err.h>
|
48
50
|
#include <openssl/ssl.h>
|
49
51
|
#include <openssl/x509.h>
|
@@ -135,6 +137,9 @@ typedef struct {
|
|
135
137
|
static gpr_once g_init_openssl_once = GPR_ONCE_INIT;
|
136
138
|
static int g_ssl_ctx_ex_factory_index = -1;
|
137
139
|
static const unsigned char kSslSessionIdContext[] = {'g', 'r', 'p', 'c'};
|
140
|
+
#ifndef OPENSSL_IS_BORINGSSL
|
141
|
+
static const char kSslEnginePrefix[] = "engine:";
|
142
|
+
#endif
|
138
143
|
|
139
144
|
#if OPENSSL_VERSION_NUMBER < 0x10100000
|
140
145
|
static gpr_mu* g_openssl_mutexes = nullptr;
|
@@ -561,9 +566,84 @@ static tsi_result ssl_ctx_use_certificate_chain(SSL_CTX* context,
|
|
561
566
|
return result;
|
562
567
|
}
|
563
568
|
|
564
|
-
|
565
|
-
static tsi_result
|
566
|
-
|
569
|
+
#ifndef OPENSSL_IS_BORINGSSL
|
570
|
+
static tsi_result ssl_ctx_use_engine_private_key(SSL_CTX* context,
|
571
|
+
const char* pem_key,
|
572
|
+
size_t pem_key_size) {
|
573
|
+
tsi_result result = TSI_OK;
|
574
|
+
EVP_PKEY* private_key = nullptr;
|
575
|
+
ENGINE* engine = nullptr;
|
576
|
+
char* engine_name = nullptr;
|
577
|
+
// Parse key which is in following format engine:<engine_id>:<key_id>
|
578
|
+
do {
|
579
|
+
char* engine_start = (char*)pem_key + strlen(kSslEnginePrefix);
|
580
|
+
char* engine_end = (char*)strchr(engine_start, ':');
|
581
|
+
if (engine_end == nullptr) {
|
582
|
+
result = TSI_INVALID_ARGUMENT;
|
583
|
+
break;
|
584
|
+
}
|
585
|
+
char* key_id = engine_end + 1;
|
586
|
+
int engine_name_length = engine_end - engine_start;
|
587
|
+
if (engine_name_length == 0) {
|
588
|
+
result = TSI_INVALID_ARGUMENT;
|
589
|
+
break;
|
590
|
+
}
|
591
|
+
engine_name = static_cast<char*>(gpr_zalloc(engine_name_length + 1));
|
592
|
+
memcpy(engine_name, engine_start, engine_name_length);
|
593
|
+
gpr_log(GPR_DEBUG, "ENGINE key: %s", engine_name);
|
594
|
+
ENGINE_load_dynamic();
|
595
|
+
engine = ENGINE_by_id(engine_name);
|
596
|
+
if (engine == nullptr) {
|
597
|
+
// If not available at ENGINE_DIR, use dynamic to load from
|
598
|
+
// current working directory.
|
599
|
+
engine = ENGINE_by_id("dynamic");
|
600
|
+
if (engine == nullptr) {
|
601
|
+
gpr_log(GPR_ERROR, "Cannot load dynamic engine");
|
602
|
+
result = TSI_INVALID_ARGUMENT;
|
603
|
+
break;
|
604
|
+
}
|
605
|
+
if (!ENGINE_ctrl_cmd_string(engine, "ID", engine_name, 0) ||
|
606
|
+
!ENGINE_ctrl_cmd_string(engine, "DIR_LOAD", "2", 0) ||
|
607
|
+
!ENGINE_ctrl_cmd_string(engine, "DIR_ADD", ".", 0) ||
|
608
|
+
!ENGINE_ctrl_cmd_string(engine, "LIST_ADD", "1", 0) ||
|
609
|
+
!ENGINE_ctrl_cmd_string(engine, "LOAD", NULL, 0)) {
|
610
|
+
gpr_log(GPR_ERROR, "Cannot find engine");
|
611
|
+
result = TSI_INVALID_ARGUMENT;
|
612
|
+
break;
|
613
|
+
}
|
614
|
+
}
|
615
|
+
if (!ENGINE_set_default(engine, ENGINE_METHOD_ALL)) {
|
616
|
+
gpr_log(GPR_ERROR, "ENGINE_set_default with ENGINE_METHOD_ALL failed");
|
617
|
+
result = TSI_INVALID_ARGUMENT;
|
618
|
+
break;
|
619
|
+
}
|
620
|
+
if (!ENGINE_init(engine)) {
|
621
|
+
gpr_log(GPR_ERROR, "ENGINE_init failed");
|
622
|
+
result = TSI_INVALID_ARGUMENT;
|
623
|
+
break;
|
624
|
+
}
|
625
|
+
private_key = ENGINE_load_private_key(engine, key_id, 0, 0);
|
626
|
+
if (private_key == nullptr) {
|
627
|
+
gpr_log(GPR_ERROR, "ENGINE_load_private_key failed");
|
628
|
+
result = TSI_INVALID_ARGUMENT;
|
629
|
+
break;
|
630
|
+
}
|
631
|
+
if (!SSL_CTX_use_PrivateKey(context, private_key)) {
|
632
|
+
gpr_log(GPR_ERROR, "SSL_CTX_use_PrivateKey failed");
|
633
|
+
result = TSI_INVALID_ARGUMENT;
|
634
|
+
break;
|
635
|
+
}
|
636
|
+
} while (0);
|
637
|
+
if (engine != nullptr) ENGINE_free(engine);
|
638
|
+
if (private_key != nullptr) EVP_PKEY_free(private_key);
|
639
|
+
if (engine_name != nullptr) gpr_free(engine_name);
|
640
|
+
return result;
|
641
|
+
}
|
642
|
+
#endif /* OPENSSL_IS_BORINGSSL */
|
643
|
+
|
644
|
+
static tsi_result ssl_ctx_use_pem_private_key(SSL_CTX* context,
|
645
|
+
const char* pem_key,
|
646
|
+
size_t pem_key_size) {
|
567
647
|
tsi_result result = TSI_OK;
|
568
648
|
EVP_PKEY* private_key = nullptr;
|
569
649
|
BIO* pem;
|
@@ -586,6 +666,20 @@ static tsi_result ssl_ctx_use_private_key(SSL_CTX* context, const char* pem_key,
|
|
586
666
|
return result;
|
587
667
|
}
|
588
668
|
|
669
|
+
/* Loads an in-memory PEM private key into the SSL context. */
|
670
|
+
static tsi_result ssl_ctx_use_private_key(SSL_CTX* context, const char* pem_key,
|
671
|
+
size_t pem_key_size) {
|
672
|
+
// BoringSSL does not have ENGINE support
|
673
|
+
#ifndef OPENSSL_IS_BORINGSSL
|
674
|
+
if (strncmp(pem_key, kSslEnginePrefix, strlen(kSslEnginePrefix)) == 0) {
|
675
|
+
return ssl_ctx_use_engine_private_key(context, pem_key, pem_key_size);
|
676
|
+
} else
|
677
|
+
#endif /* OPENSSL_IS_BORINGSSL */
|
678
|
+
{
|
679
|
+
return ssl_ctx_use_pem_private_key(context, pem_key, pem_key_size);
|
680
|
+
}
|
681
|
+
}
|
682
|
+
|
589
683
|
/* Loads in-memory PEM verification certs into the SSL context and optionally
|
590
684
|
returns the verification cert names (root_names can be NULL). */
|
591
685
|
static tsi_result x509_store_load_certs(X509_STORE* cert_store,
|
@@ -1024,6 +1118,29 @@ static void tsi_ssl_handshaker_factory_init(
|
|
1024
1118
|
gpr_ref_init(&factory->refcount, 1);
|
1025
1119
|
}
|
1026
1120
|
|
1121
|
+
/* Gets the X509 cert chain in PEM format as a tsi_peer_property. */
|
1122
|
+
tsi_result tsi_ssl_get_cert_chain_contents(STACK_OF(X509) * peer_chain,
|
1123
|
+
tsi_peer_property* property) {
|
1124
|
+
BIO* bio = BIO_new(BIO_s_mem());
|
1125
|
+
for (int i = 0; i < sk_X509_num(peer_chain); i++) {
|
1126
|
+
if (!PEM_write_bio_X509(bio, sk_X509_value(peer_chain, i))) {
|
1127
|
+
BIO_free(bio);
|
1128
|
+
return TSI_INTERNAL_ERROR;
|
1129
|
+
}
|
1130
|
+
}
|
1131
|
+
char* contents;
|
1132
|
+
long len = BIO_get_mem_data(bio, &contents);
|
1133
|
+
if (len <= 0) {
|
1134
|
+
BIO_free(bio);
|
1135
|
+
return TSI_INTERNAL_ERROR;
|
1136
|
+
}
|
1137
|
+
tsi_result result = tsi_construct_string_peer_property(
|
1138
|
+
TSI_X509_PEM_CERT_CHAIN_PROPERTY, (const char*)contents,
|
1139
|
+
static_cast<size_t>(len), property);
|
1140
|
+
BIO_free(bio);
|
1141
|
+
return result;
|
1142
|
+
}
|
1143
|
+
|
1027
1144
|
/* --- tsi_handshaker_result methods implementation. ---*/
|
1028
1145
|
static tsi_result ssl_handshaker_result_extract_peer(
|
1029
1146
|
const tsi_handshaker_result* self, tsi_peer* peer) {
|
@@ -1032,7 +1149,6 @@ static tsi_result ssl_handshaker_result_extract_peer(
|
|
1032
1149
|
unsigned int alpn_selected_len;
|
1033
1150
|
const tsi_ssl_handshaker_result* impl =
|
1034
1151
|
reinterpret_cast<const tsi_ssl_handshaker_result*>(self);
|
1035
|
-
// TODO(yihuazhang): Return a full certificate chain as a peer property.
|
1036
1152
|
X509* peer_cert = SSL_get_peer_certificate(impl->ssl);
|
1037
1153
|
if (peer_cert != nullptr) {
|
1038
1154
|
result = peer_from_x509(peer_cert, 1, peer);
|
@@ -1047,10 +1163,14 @@ static tsi_result ssl_handshaker_result_extract_peer(
|
|
1047
1163
|
SSL_get0_next_proto_negotiated(impl->ssl, &alpn_selected,
|
1048
1164
|
&alpn_selected_len);
|
1049
1165
|
}
|
1050
|
-
|
1166
|
+
// When called on the client side, the stack also contains the
|
1167
|
+
// peer's certificate; When called on the server side,
|
1168
|
+
// the peer's certificate is not present in the stack
|
1169
|
+
STACK_OF(X509)* peer_chain = SSL_get_peer_cert_chain(impl->ssl);
|
1051
1170
|
// 1 is for session reused property.
|
1052
|
-
size_t new_property_count = peer->property_count +
|
1171
|
+
size_t new_property_count = peer->property_count + 3;
|
1053
1172
|
if (alpn_selected != nullptr) new_property_count++;
|
1173
|
+
if (peer_chain != nullptr) new_property_count++;
|
1054
1174
|
tsi_peer_property* new_properties = static_cast<tsi_peer_property*>(
|
1055
1175
|
gpr_zalloc(sizeof(*new_properties) * new_property_count));
|
1056
1176
|
for (size_t i = 0; i < peer->property_count; i++) {
|
@@ -1058,7 +1178,12 @@ static tsi_result ssl_handshaker_result_extract_peer(
|
|
1058
1178
|
}
|
1059
1179
|
if (peer->properties != nullptr) gpr_free(peer->properties);
|
1060
1180
|
peer->properties = new_properties;
|
1061
|
-
|
1181
|
+
// Add peer chain if available
|
1182
|
+
if (peer_chain != nullptr) {
|
1183
|
+
result = tsi_ssl_get_cert_chain_contents(
|
1184
|
+
peer_chain, &peer->properties[peer->property_count]);
|
1185
|
+
if (result == TSI_OK) peer->property_count++;
|
1186
|
+
}
|
1062
1187
|
if (alpn_selected != nullptr) {
|
1063
1188
|
result = tsi_construct_string_peer_property(
|
1064
1189
|
TSI_SSL_ALPN_SELECTED_PROTOCOL,
|
@@ -1067,6 +1192,13 @@ static tsi_result ssl_handshaker_result_extract_peer(
|
|
1067
1192
|
if (result != TSI_OK) return result;
|
1068
1193
|
peer->property_count++;
|
1069
1194
|
}
|
1195
|
+
// Add security_level peer property.
|
1196
|
+
result = tsi_construct_string_peer_property_from_cstring(
|
1197
|
+
TSI_SECURITY_LEVEL_PEER_PROPERTY,
|
1198
|
+
tsi_security_level_to_string(TSI_PRIVACY_AND_INTEGRITY),
|
1199
|
+
&peer->properties[peer->property_count]);
|
1200
|
+
if (result != TSI_OK) return result;
|
1201
|
+
peer->property_count++;
|
1070
1202
|
|
1071
1203
|
const char* session_reused = SSL_session_reused(impl->ssl) ? "true" : "false";
|
1072
1204
|
result = tsi_construct_string_peer_property_from_cstring(
|
@@ -1733,7 +1865,11 @@ tsi_result tsi_create_ssl_client_handshaker_factory_with_options(
|
|
1733
1865
|
tsi_ssl_handshaker_factory_unref(&impl->base);
|
1734
1866
|
return result;
|
1735
1867
|
}
|
1736
|
-
|
1868
|
+
if (options->skip_server_certificate_verification) {
|
1869
|
+
SSL_CTX_set_verify(ssl_context, SSL_VERIFY_PEER, NullVerifyCallback);
|
1870
|
+
} else {
|
1871
|
+
SSL_CTX_set_verify(ssl_context, SSL_VERIFY_PEER, nullptr);
|
1872
|
+
}
|
1737
1873
|
/* TODO(jboeuf): Add revocation verification. */
|
1738
1874
|
|
1739
1875
|
*factory = impl;
|