@@ -66,12 +66,13 @@ tsi_ssl_pem_key_cert_pair* ConvertToTsiPemKeyCertPair(
66
66
grpc_status_code TlsFetchKeyMaterials (
67
67
const grpc_core::RefCountedPtr<grpc_tls_key_materials_config>&
68
68
key_materials_config,
69
- const grpc_tls_credentials_options& options,
69
+ const grpc_tls_credentials_options& options, bool server_config,
70
70
grpc_ssl_certificate_config_reload_status* reload_status) {
71
71
GPR_ASSERT (key_materials_config != nullptr );
72
72
bool is_key_materials_empty =
73
73
key_materials_config->pem_key_cert_pair_list ().empty ();
74
- if (options.credential_reload_config () == nullptr && is_key_materials_empty) {
74
+ if (options.credential_reload_config () == nullptr && is_key_materials_empty &&
75
+ server_config) {
75
76
gpr_log (GPR_ERROR,
76
77
" Either credential reload config or key materials should be "
77
78
" provisioned." );
@@ -190,9 +191,8 @@ void TlsChannelSecurityConnector::check_peer(
190
191
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING (
191
192
" Cannot check peer: missing pem cert property." );
192
193
} else {
193
- char * peer_pem = static_cast <char *>(gpr_malloc (p->value .length + 1 ));
194
+ char * peer_pem = static_cast <char *>(gpr_zalloc (p->value .length + 1 ));
194
195
memcpy (peer_pem, p->value .data , p->value .length );
195
- peer_pem[p->value .length ] = ' \0 ' ;
196
196
GPR_ASSERT (check_arg_ != nullptr );
197
197
check_arg_->peer_cert = check_arg_->peer_cert == nullptr
198
198
? gpr_strdup (peer_pem)
@@ -202,6 +202,18 @@ void TlsChannelSecurityConnector::check_peer(
202
202
: check_arg_->target_name ;
203
203
on_peer_checked_ = on_peer_checked;
204
204
gpr_free (peer_pem);
205
+ const tsi_peer_property* chain = tsi_peer_get_property_by_name (
206
+ &peer, TSI_X509_PEM_CERT_CHAIN_PROPERTY);
207
+ if (chain != nullptr ) {
208
+ char * peer_pem_chain =
209
+ static_cast <char *>(gpr_zalloc (chain->value .length + 1 ));
210
+ memcpy (peer_pem_chain, chain->value .data , chain->value .length );
211
+ check_arg_->peer_cert_full_chain =
212
+ check_arg_->peer_cert_full_chain == nullptr
213
+ ? gpr_strdup (peer_pem_chain)
214
+ : check_arg_->peer_cert_full_chain ;
215
+ gpr_free (peer_pem_chain);
216
+ }
205
217
int callback_status = config->Schedule (check_arg_);
206
218
/* Server authorization check is handled asynchronously. */
207
219
if (callback_status) {
@@ -272,16 +284,21 @@ TlsChannelSecurityConnector::CreateTlsChannelSecurityConnector(
272
284
273
285
grpc_security_status TlsChannelSecurityConnector::ReplaceHandshakerFactory (
274
286
tsi_ssl_session_cache* ssl_session_cache) {
287
+ const TlsCredentials* creds =
288
+ static_cast <const TlsCredentials*>(channel_creds ());
289
+ tsi_server_verification_option server_verification_option =
290
+ grpc_get_tsi_server_verification_option (
291
+ creds->options ().server_verification_option ());
275
292
/* Free the client handshaker factory if exists. */
276
293
if (client_handshaker_factory_) {
277
294
tsi_ssl_client_handshaker_factory_unref (client_handshaker_factory_);
278
295
}
279
- GPR_ASSERT (!key_materials_config_->pem_key_cert_pair_list ().empty ());
280
296
tsi_ssl_pem_key_cert_pair* pem_key_cert_pair = ConvertToTsiPemKeyCertPair (
281
297
key_materials_config_->pem_key_cert_pair_list ());
282
298
grpc_security_status status = grpc_ssl_tsi_client_handshaker_factory_init (
283
299
pem_key_cert_pair, key_materials_config_->pem_root_certs (),
284
- ssl_session_cache, &client_handshaker_factory_);
300
+ server_verification_option, ssl_session_cache,
301
+ &client_handshaker_factory_);
285
302
/* Free memory. */
286
303
grpc_tsi_ssl_pem_key_cert_pairs_destroy (pem_key_cert_pair, 1 );
287
304
return status;
@@ -305,7 +322,7 @@ grpc_security_status TlsChannelSecurityConnector::InitializeHandshakerFactory(
305
322
}
306
323
grpc_ssl_certificate_config_reload_status reload_status =
307
324
GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_UNCHANGED;
308
- if (TlsFetchKeyMaterials (key_materials_config_, creds->options (),
325
+ if (TlsFetchKeyMaterials (key_materials_config_, creds->options (), false ,
309
326
&reload_status) != GRPC_STATUS_OK) {
310
327
/* Raise an error if key materials are not populated. */
311
328
return GRPC_SECURITY_ERROR;
@@ -319,7 +336,7 @@ grpc_security_status TlsChannelSecurityConnector::RefreshHandshakerFactory() {
319
336
static_cast <const TlsCredentials*>(channel_creds ());
320
337
grpc_ssl_certificate_config_reload_status reload_status =
321
338
GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_UNCHANGED;
322
- if (TlsFetchKeyMaterials (key_materials_config_, creds->options (),
339
+ if (TlsFetchKeyMaterials (key_materials_config_, creds->options (), false ,
323
340
&reload_status) != GRPC_STATUS_OK) {
324
341
return GRPC_SECURITY_ERROR;
325
342
}
@@ -507,7 +524,7 @@ grpc_security_status TlsServerSecurityConnector::InitializeHandshakerFactory() {
507
524
}
508
525
grpc_ssl_certificate_config_reload_status reload_status =
509
526
GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_UNCHANGED;
510
- if (TlsFetchKeyMaterials (key_materials_config_, creds->options (),
527
+ if (TlsFetchKeyMaterials (key_materials_config_, creds->options (), true ,
511
528
&reload_status) != GRPC_STATUS_OK) {
512
529
/* Raise an error if key materials are not populated. */
513
530
return GRPC_SECURITY_ERROR;
@@ -521,7 +538,7 @@ grpc_security_status TlsServerSecurityConnector::RefreshHandshakerFactory() {
521
538
static_cast <const TlsServerCredentials*>(server_creds ());
522
539
grpc_ssl_certificate_config_reload_status reload_status =
523
540
GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_UNCHANGED;
524
- if (TlsFetchKeyMaterials (key_materials_config_, creds->options (),
541
+ if (TlsFetchKeyMaterials (key_materials_config_, creds->options (), true ,
525
542
&reload_status) != GRPC_STATUS_OK) {
526
543
return GRPC_SECURITY_ERROR;
527
544
}
0 commit comments