|
|
@ -29,6 +29,7 @@ |
|
|
|
#include <grpc/support/string_util.h> |
|
|
|
#include <grpc/support/string_util.h> |
|
|
|
#include <grpc/support/sync.h> |
|
|
|
#include <grpc/support/sync.h> |
|
|
|
#include <grpc/support/thd_id.h> |
|
|
|
#include <grpc/support/thd_id.h> |
|
|
|
|
|
|
|
#include "src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.h" |
|
|
|
|
|
|
|
|
|
|
|
#include "src/core/lib/gprpp/thd.h" |
|
|
|
#include "src/core/lib/gprpp/thd.h" |
|
|
|
#include "src/core/lib/iomgr/closure.h" |
|
|
|
#include "src/core/lib/iomgr/closure.h" |
|
|
@ -63,6 +64,7 @@ typedef struct alts_tsi_handshaker_result { |
|
|
|
size_t unused_bytes_size; |
|
|
|
size_t unused_bytes_size; |
|
|
|
grpc_slice rpc_versions; |
|
|
|
grpc_slice rpc_versions; |
|
|
|
bool is_client; |
|
|
|
bool is_client; |
|
|
|
|
|
|
|
grpc_slice serialized_context; |
|
|
|
} alts_tsi_handshaker_result; |
|
|
|
} alts_tsi_handshaker_result; |
|
|
|
|
|
|
|
|
|
|
|
static tsi_result handshaker_result_extract_peer( |
|
|
|
static tsi_result handshaker_result_extract_peer( |
|
|
@ -74,7 +76,7 @@ static tsi_result handshaker_result_extract_peer( |
|
|
|
alts_tsi_handshaker_result* result = |
|
|
|
alts_tsi_handshaker_result* result = |
|
|
|
reinterpret_cast<alts_tsi_handshaker_result*>( |
|
|
|
reinterpret_cast<alts_tsi_handshaker_result*>( |
|
|
|
const_cast<tsi_handshaker_result*>(self)); |
|
|
|
const_cast<tsi_handshaker_result*>(self)); |
|
|
|
GPR_ASSERT(kTsiAltsNumOfPeerProperties == 3); |
|
|
|
GPR_ASSERT(kTsiAltsNumOfPeerProperties == 4); |
|
|
|
tsi_result ok = tsi_construct_peer(kTsiAltsNumOfPeerProperties, peer); |
|
|
|
tsi_result ok = tsi_construct_peer(kTsiAltsNumOfPeerProperties, peer); |
|
|
|
int index = 0; |
|
|
|
int index = 0; |
|
|
|
if (ok != TSI_OK) { |
|
|
|
if (ok != TSI_OK) { |
|
|
@ -104,7 +106,16 @@ static tsi_result handshaker_result_extract_peer( |
|
|
|
ok = tsi_construct_string_peer_property( |
|
|
|
ok = tsi_construct_string_peer_property( |
|
|
|
TSI_ALTS_RPC_VERSIONS, |
|
|
|
TSI_ALTS_RPC_VERSIONS, |
|
|
|
reinterpret_cast<char*>(GRPC_SLICE_START_PTR(result->rpc_versions)), |
|
|
|
reinterpret_cast<char*>(GRPC_SLICE_START_PTR(result->rpc_versions)), |
|
|
|
GRPC_SLICE_LENGTH(result->rpc_versions), &peer->properties[2]); |
|
|
|
GRPC_SLICE_LENGTH(result->rpc_versions), &peer->properties[index]); |
|
|
|
|
|
|
|
if (ok != TSI_OK) { |
|
|
|
|
|
|
|
tsi_peer_destruct(peer); |
|
|
|
|
|
|
|
gpr_log(GPR_ERROR, "Failed to set tsi peer property"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
index++; |
|
|
|
|
|
|
|
GPR_ASSERT(&peer->properties[index] != nullptr); |
|
|
|
|
|
|
|
ok = tsi_construct_string_peer_property( |
|
|
|
|
|
|
|
TSI_ALTS_CONTEXT, reinterpret_cast<char*>(GRPC_SLICE_START_PTR(result->serialized_context)), GRPC_SLICE_LENGTH(result->serialized_context), |
|
|
|
|
|
|
|
&peer->properties[index]); |
|
|
|
if (ok != TSI_OK) { |
|
|
|
if (ok != TSI_OK) { |
|
|
|
tsi_peer_destruct(peer); |
|
|
|
tsi_peer_destruct(peer); |
|
|
|
gpr_log(GPR_ERROR, "Failed to set tsi peer property"); |
|
|
|
gpr_log(GPR_ERROR, "Failed to set tsi peer property"); |
|
|
@ -223,6 +234,27 @@ tsi_result alts_tsi_handshaker_result_create(grpc_gcp_HandshakerResp* resp, |
|
|
|
gpr_log(GPR_ERROR, "Peer does not set RPC protocol versions."); |
|
|
|
gpr_log(GPR_ERROR, "Peer does not set RPC protocol versions."); |
|
|
|
return TSI_FAILED_PRECONDITION; |
|
|
|
return TSI_FAILED_PRECONDITION; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
upb_strview application_protocol = grpc_gcp_HandshakerResult_application_protocol(hresult); |
|
|
|
|
|
|
|
if (application_protocol.size == 0) { |
|
|
|
|
|
|
|
gpr_log(GPR_ERROR, "Invalid application protocol"); |
|
|
|
|
|
|
|
return TSI_FAILED_PRECONDITION; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
upb_strview record_protocol = grpc_gcp_HandshakerResult_record_protocol(hresult); |
|
|
|
|
|
|
|
if (record_protocol.size == 0) { |
|
|
|
|
|
|
|
gpr_log(GPR_ERROR, "Invalid record protocol"); |
|
|
|
|
|
|
|
return TSI_FAILED_PRECONDITION; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const grpc_gcp_Identity* local_identity = |
|
|
|
|
|
|
|
grpc_gcp_HandshakerResult_local_identity(hresult); |
|
|
|
|
|
|
|
if (local_identity == nullptr) { |
|
|
|
|
|
|
|
gpr_log(GPR_ERROR, "Invalid local identity"); |
|
|
|
|
|
|
|
return TSI_FAILED_PRECONDITION; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
upb_strview local_service_account = grpc_gcp_Identity_service_account(local_identity); |
|
|
|
|
|
|
|
if (local_service_account.size == 0) { |
|
|
|
|
|
|
|
gpr_log(GPR_ERROR, "Invalid local service account"); |
|
|
|
|
|
|
|
return TSI_FAILED_PRECONDITION; |
|
|
|
|
|
|
|
} |
|
|
|
alts_tsi_handshaker_result* result = |
|
|
|
alts_tsi_handshaker_result* result = |
|
|
|
static_cast<alts_tsi_handshaker_result*>(gpr_zalloc(sizeof(*result))); |
|
|
|
static_cast<alts_tsi_handshaker_result*>(gpr_zalloc(sizeof(*result))); |
|
|
|
result->key_data = |
|
|
|
result->key_data = |
|
|
@ -231,13 +263,29 @@ tsi_result alts_tsi_handshaker_result_create(grpc_gcp_HandshakerResp* resp, |
|
|
|
result->peer_identity = |
|
|
|
result->peer_identity = |
|
|
|
static_cast<char*>(gpr_zalloc(service_account.size + 1)); |
|
|
|
static_cast<char*>(gpr_zalloc(service_account.size + 1)); |
|
|
|
memcpy(result->peer_identity, service_account.data, service_account.size); |
|
|
|
memcpy(result->peer_identity, service_account.data, service_account.size); |
|
|
|
upb::Arena arena; |
|
|
|
upb::Arena rpc_protocol_arena; |
|
|
|
bool serialized = grpc_gcp_rpc_protocol_versions_encode( |
|
|
|
bool serialized = grpc_gcp_rpc_protocol_versions_encode( |
|
|
|
peer_rpc_version, arena.ptr(), &result->rpc_versions); |
|
|
|
peer_rpc_version, rpc_protocol_arena.ptr(), &result->rpc_versions); |
|
|
|
if (!serialized) { |
|
|
|
if (!serialized) { |
|
|
|
gpr_log(GPR_ERROR, "Failed to serialize peer's RPC protocol versions."); |
|
|
|
gpr_log(GPR_ERROR, "Failed to serialize peer's RPC protocol versions."); |
|
|
|
return TSI_FAILED_PRECONDITION; |
|
|
|
return TSI_FAILED_PRECONDITION; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
upb::Arena context_arena; |
|
|
|
|
|
|
|
grpc_gcp_AltsContext* context = grpc_gcp_AltsContext_new(context_arena.ptr()); |
|
|
|
|
|
|
|
grpc_gcp_AltsContext_set_application_protocol(context, application_protocol); |
|
|
|
|
|
|
|
grpc_gcp_AltsContext_set_record_protocol(context, record_protocol); |
|
|
|
|
|
|
|
grpc_gcp_AltsContext_set_security_level(context, 2); |
|
|
|
|
|
|
|
grpc_gcp_AltsContext_set_peer_service_account(context, service_account); |
|
|
|
|
|
|
|
grpc_gcp_AltsContext_set_local_service_account(context, local_service_account); |
|
|
|
|
|
|
|
grpc_gcp_AltsContext_set_peer_rpc_versions(context, const_cast<grpc_gcp_RpcProtocolVersions*>(peer_rpc_version)); |
|
|
|
|
|
|
|
size_t serialized_ctx_length; |
|
|
|
|
|
|
|
char* serialized_ctx = |
|
|
|
|
|
|
|
grpc_gcp_AltsContext_serialize(context, context_arena.ptr(), &serialized_ctx_length); |
|
|
|
|
|
|
|
if (serialized_ctx == nullptr) { |
|
|
|
|
|
|
|
gpr_log(GPR_ERROR, "Failed to serialize peer's ALTS context."); |
|
|
|
|
|
|
|
return TSI_FAILED_PRECONDITION; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
result->serialized_context = grpc_slice_from_copied_buffer(serialized_ctx, serialized_ctx_length); |
|
|
|
result->is_client = is_client; |
|
|
|
result->is_client = is_client; |
|
|
|
result->base.vtable = &result_vtable; |
|
|
|
result->base.vtable = &result_vtable; |
|
|
|
*self = &result->base; |
|
|
|
*self = &result->base; |
|
|
|