diff options
Diffstat (limited to 'src/core/tsi')
-rw-r--r-- | src/core/tsi/fake_transport_security.cc | 216 | ||||
-rw-r--r-- | src/core/tsi/fake_transport_security.h | 10 | ||||
-rw-r--r-- | src/core/tsi/gts_transport_security.cc | 2 | ||||
-rw-r--r-- | src/core/tsi/gts_transport_security.h | 6 | ||||
-rw-r--r-- | src/core/tsi/ssl_transport_security.cc | 407 | ||||
-rw-r--r-- | src/core/tsi/ssl_transport_security.h | 50 | ||||
-rw-r--r-- | src/core/tsi/transport_security.cc | 90 | ||||
-rw-r--r-- | src/core/tsi/transport_security.h | 108 | ||||
-rw-r--r-- | src/core/tsi/transport_security_adapter.cc | 90 | ||||
-rw-r--r-- | src/core/tsi/transport_security_adapter.h | 4 | ||||
-rw-r--r-- | src/core/tsi/transport_security_grpc.cc | 22 | ||||
-rw-r--r-- | src/core/tsi/transport_security_grpc.h | 38 | ||||
-rw-r--r-- | src/core/tsi/transport_security_interface.h | 80 |
13 files changed, 563 insertions, 560 deletions
diff --git a/src/core/tsi/fake_transport_security.cc b/src/core/tsi/fake_transport_security.cc index 349dcf5cb8..b12dde31fb 100644 --- a/src/core/tsi/fake_transport_security.cc +++ b/src/core/tsi/fake_transport_security.cc @@ -41,7 +41,7 @@ where the size field value is the size of the size field plus the size of the data encoded in little endian on 4 bytes. */ typedef struct { - unsigned char *data; + unsigned char* data; size_t size; size_t allocated_size; size_t offset; @@ -63,7 +63,7 @@ typedef struct { int needs_incoming_message; tsi_fake_frame incoming_frame; tsi_fake_frame outgoing_frame; - unsigned char *outgoing_bytes_buffer; + unsigned char* outgoing_bytes_buffer; size_t outgoing_bytes_buffer_size; tsi_result result; } tsi_fake_handshaker; @@ -85,10 +85,10 @@ typedef struct { /* --- Utils. ---*/ -static const char *tsi_fake_handshake_message_strings[] = { +static const char* tsi_fake_handshake_message_strings[] = { "CLIENT_INIT", "SERVER_INIT", "CLIENT_FINISHED", "SERVER_FINISHED"}; -static const char *tsi_fake_handshake_message_to_string(int msg) { +static const char* tsi_fake_handshake_message_to_string(int msg) { if (msg < 0 || msg >= TSI_FAKE_HANDSHAKE_MESSAGE_MAX) { gpr_log(GPR_ERROR, "Invalid message %d", msg); return "UNKNOWN"; @@ -97,7 +97,7 @@ static const char *tsi_fake_handshake_message_to_string(int msg) { } static tsi_result tsi_fake_handshake_message_from_string( - const char *msg_string, tsi_fake_handshake_message *msg) { + const char* msg_string, tsi_fake_handshake_message* msg) { for (int i = 0; i < TSI_FAKE_HANDSHAKE_MESSAGE_MAX; i++) { if (strncmp(msg_string, tsi_fake_handshake_message_strings[i], strlen(tsi_fake_handshake_message_strings[i])) == 0) { @@ -109,22 +109,22 @@ static tsi_result tsi_fake_handshake_message_from_string( return TSI_DATA_CORRUPTED; } -static uint32_t load32_little_endian(const unsigned char *buf) { +static uint32_t load32_little_endian(const unsigned char* buf) { return ((uint32_t)(buf[0]) | (uint32_t)(buf[1] << 8) | (uint32_t)(buf[2] << 16) | (uint32_t)(buf[3] << 24)); } -static void store32_little_endian(uint32_t value, unsigned char *buf) { +static void store32_little_endian(uint32_t value, unsigned char* buf) { buf[3] = (unsigned char)((value >> 24) & 0xFF); buf[2] = (unsigned char)((value >> 16) & 0xFF); buf[1] = (unsigned char)((value >> 8) & 0xFF); buf[0] = (unsigned char)((value)&0xFF); } -static uint32_t read_frame_size(const grpc_slice_buffer *sb) { +static uint32_t read_frame_size(const grpc_slice_buffer* sb) { GPR_ASSERT(sb != NULL && sb->length >= TSI_FAKE_FRAME_HEADER_SIZE); uint8_t frame_size_buffer[TSI_FAKE_FRAME_HEADER_SIZE]; - uint8_t *buf = frame_size_buffer; + uint8_t* buf = frame_size_buffer; /* Copies the first 4 bytes to a temporary buffer. */ size_t remaining = TSI_FAKE_FRAME_HEADER_SIZE; for (size_t i = 0; i < sb->count; i++) { @@ -143,7 +143,7 @@ static uint32_t read_frame_size(const grpc_slice_buffer *sb) { return load32_little_endian(frame_size_buffer); } -static void tsi_fake_frame_reset(tsi_fake_frame *frame, int needs_draining) { +static void tsi_fake_frame_reset(tsi_fake_frame* frame, int needs_draining) { frame->offset = 0; frame->needs_draining = needs_draining; if (!needs_draining) frame->size = 0; @@ -151,13 +151,13 @@ static void tsi_fake_frame_reset(tsi_fake_frame *frame, int needs_draining) { /* Checks if the frame's allocated size is at least frame->size, and reallocs * more memory if necessary. */ -static void tsi_fake_frame_ensure_size(tsi_fake_frame *frame) { +static void tsi_fake_frame_ensure_size(tsi_fake_frame* frame) { if (frame->data == NULL) { frame->allocated_size = frame->size; - frame->data = (unsigned char *)gpr_malloc(frame->allocated_size); + frame->data = (unsigned char*)gpr_malloc(frame->allocated_size); } else if (frame->size > frame->allocated_size) { - unsigned char *new_data = - (unsigned char *)gpr_realloc(frame->data, frame->size); + unsigned char* new_data = + (unsigned char*)gpr_realloc(frame->data, frame->size); frame->data = new_data; frame->allocated_size = frame->size; } @@ -166,17 +166,17 @@ static void tsi_fake_frame_ensure_size(tsi_fake_frame *frame) { /* Decodes the serialized fake frame contained in incoming_bytes, and fills * frame with the contents of the decoded frame. * This method should not be called if frame->needs_framing is not 0. */ -static tsi_result tsi_fake_frame_decode(const unsigned char *incoming_bytes, - size_t *incoming_bytes_size, - tsi_fake_frame *frame) { +static tsi_result tsi_fake_frame_decode(const unsigned char* incoming_bytes, + size_t* incoming_bytes_size, + tsi_fake_frame* frame) { size_t available_size = *incoming_bytes_size; size_t to_read_size = 0; - const unsigned char *bytes_cursor = incoming_bytes; + const unsigned char* bytes_cursor = incoming_bytes; if (frame->needs_draining) return TSI_INTERNAL_ERROR; if (frame->data == NULL) { frame->allocated_size = TSI_FAKE_FRAME_INITIAL_ALLOCATED_SIZE; - frame->data = (unsigned char *)gpr_malloc(frame->allocated_size); + frame->data = (unsigned char*)gpr_malloc(frame->allocated_size); } if (frame->offset < TSI_FAKE_FRAME_HEADER_SIZE) { @@ -215,9 +215,9 @@ static tsi_result tsi_fake_frame_decode(const unsigned char *incoming_bytes, /* Encodes a fake frame into its wire format and places the result in * outgoing_bytes. outgoing_bytes_size indicates the size of the encoded frame. * This method should not be called if frame->needs_framing is 0. */ -static tsi_result tsi_fake_frame_encode(unsigned char *outgoing_bytes, - size_t *outgoing_bytes_size, - tsi_fake_frame *frame) { +static tsi_result tsi_fake_frame_encode(unsigned char* outgoing_bytes, + size_t* outgoing_bytes_size, + tsi_fake_frame* frame) { size_t to_write_size = frame->size - frame->offset; if (!frame->needs_draining) return TSI_INTERNAL_ERROR; if (*outgoing_bytes_size < to_write_size) { @@ -233,8 +233,8 @@ static tsi_result tsi_fake_frame_encode(unsigned char *outgoing_bytes, /* Sets the payload of a fake frame to contain the given data blob, where * data_size indicates the size of data. */ -static tsi_result tsi_fake_frame_set_data(unsigned char *data, size_t data_size, - tsi_fake_frame *frame) { +static tsi_result tsi_fake_frame_set_data(unsigned char* data, size_t data_size, + tsi_fake_frame* frame) { frame->offset = 0; frame->size = data_size + TSI_FAKE_FRAME_HEADER_SIZE; tsi_fake_frame_ensure_size(frame); @@ -245,24 +245,24 @@ static tsi_result tsi_fake_frame_set_data(unsigned char *data, size_t data_size, } /* Destroys the contents of a fake frame. */ -static void tsi_fake_frame_destruct(tsi_fake_frame *frame) { +static void tsi_fake_frame_destruct(tsi_fake_frame* frame) { if (frame->data != NULL) gpr_free(frame->data); } /* --- tsi_frame_protector methods implementation. ---*/ -static tsi_result fake_protector_protect(tsi_frame_protector *self, - const unsigned char *unprotected_bytes, - size_t *unprotected_bytes_size, - unsigned char *protected_output_frames, - size_t *protected_output_frames_size) { +static tsi_result fake_protector_protect(tsi_frame_protector* self, + const unsigned char* unprotected_bytes, + size_t* unprotected_bytes_size, + unsigned char* protected_output_frames, + size_t* protected_output_frames_size) { tsi_result result = TSI_OK; - tsi_fake_frame_protector *impl = (tsi_fake_frame_protector *)self; + tsi_fake_frame_protector* impl = (tsi_fake_frame_protector*)self; unsigned char frame_header[TSI_FAKE_FRAME_HEADER_SIZE]; - tsi_fake_frame *frame = &impl->protect_frame; + tsi_fake_frame* frame = &impl->protect_frame; size_t saved_output_size = *protected_output_frames_size; size_t drained_size = 0; - size_t *num_bytes_written = protected_output_frames_size; + size_t* num_bytes_written = protected_output_frames_size; *num_bytes_written = 0; /* Try to drain first. */ @@ -313,11 +313,11 @@ static tsi_result fake_protector_protect(tsi_frame_protector *self, } static tsi_result fake_protector_protect_flush( - tsi_frame_protector *self, unsigned char *protected_output_frames, - size_t *protected_output_frames_size, size_t *still_pending_size) { + tsi_frame_protector* self, unsigned char* protected_output_frames, + size_t* protected_output_frames_size, size_t* still_pending_size) { tsi_result result = TSI_OK; - tsi_fake_frame_protector *impl = (tsi_fake_frame_protector *)self; - tsi_fake_frame *frame = &impl->protect_frame; + tsi_fake_frame_protector* impl = (tsi_fake_frame_protector*)self; + tsi_fake_frame* frame = &impl->protect_frame; if (!frame->needs_draining) { /* Create a short frame. */ frame->size = frame->offset; @@ -334,15 +334,15 @@ static tsi_result fake_protector_protect_flush( } static tsi_result fake_protector_unprotect( - tsi_frame_protector *self, const unsigned char *protected_frames_bytes, - size_t *protected_frames_bytes_size, unsigned char *unprotected_bytes, - size_t *unprotected_bytes_size) { + tsi_frame_protector* self, const unsigned char* protected_frames_bytes, + size_t* protected_frames_bytes_size, unsigned char* unprotected_bytes, + size_t* unprotected_bytes_size) { tsi_result result = TSI_OK; - tsi_fake_frame_protector *impl = (tsi_fake_frame_protector *)self; - tsi_fake_frame *frame = &impl->unprotect_frame; + tsi_fake_frame_protector* impl = (tsi_fake_frame_protector*)self; + tsi_fake_frame* frame = &impl->unprotect_frame; size_t saved_output_size = *unprotected_bytes_size; size_t drained_size = 0; - size_t *num_bytes_written = unprotected_bytes_size; + size_t* num_bytes_written = unprotected_bytes_size; *num_bytes_written = 0; /* Try to drain first. */ @@ -382,29 +382,31 @@ static tsi_result fake_protector_unprotect( return result; } -static void fake_protector_destroy(tsi_frame_protector *self) { - tsi_fake_frame_protector *impl = (tsi_fake_frame_protector *)self; +static void fake_protector_destroy(tsi_frame_protector* self) { + tsi_fake_frame_protector* impl = (tsi_fake_frame_protector*)self; tsi_fake_frame_destruct(&impl->protect_frame); tsi_fake_frame_destruct(&impl->unprotect_frame); gpr_free(self); } static const tsi_frame_protector_vtable frame_protector_vtable = { - fake_protector_protect, fake_protector_protect_flush, - fake_protector_unprotect, fake_protector_destroy, + fake_protector_protect, + fake_protector_protect_flush, + fake_protector_unprotect, + fake_protector_destroy, }; /* --- tsi_zero_copy_grpc_protector methods implementation. ---*/ static tsi_result fake_zero_copy_grpc_protector_protect( - grpc_exec_ctx *exec_ctx, tsi_zero_copy_grpc_protector *self, - grpc_slice_buffer *unprotected_slices, - grpc_slice_buffer *protected_slices) { + grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self, + grpc_slice_buffer* unprotected_slices, + grpc_slice_buffer* protected_slices) { if (self == NULL || unprotected_slices == NULL || protected_slices == NULL) { return TSI_INVALID_ARGUMENT; } - tsi_fake_zero_copy_grpc_protector *impl = - (tsi_fake_zero_copy_grpc_protector *)self; + tsi_fake_zero_copy_grpc_protector* impl = + (tsi_fake_zero_copy_grpc_protector*)self; /* Protects each frame. */ while (unprotected_slices->length > 0) { size_t frame_length = @@ -421,14 +423,14 @@ static tsi_result fake_zero_copy_grpc_protector_protect( } static tsi_result fake_zero_copy_grpc_protector_unprotect( - grpc_exec_ctx *exec_ctx, tsi_zero_copy_grpc_protector *self, - grpc_slice_buffer *protected_slices, - grpc_slice_buffer *unprotected_slices) { + grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self, + grpc_slice_buffer* protected_slices, + grpc_slice_buffer* unprotected_slices) { if (self == NULL || unprotected_slices == NULL || protected_slices == NULL) { return TSI_INVALID_ARGUMENT; } - tsi_fake_zero_copy_grpc_protector *impl = - (tsi_fake_zero_copy_grpc_protector *)self; + tsi_fake_zero_copy_grpc_protector* impl = + (tsi_fake_zero_copy_grpc_protector*)self; grpc_slice_buffer_move_into(protected_slices, &impl->protected_sb); /* Unprotect each frame, if we get a full frame. */ while (impl->protected_sb.length >= TSI_FAKE_FRAME_HEADER_SIZE) { @@ -456,10 +458,10 @@ static tsi_result fake_zero_copy_grpc_protector_unprotect( } static void fake_zero_copy_grpc_protector_destroy( - grpc_exec_ctx *exec_ctx, tsi_zero_copy_grpc_protector *self) { + grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self) { if (self == NULL) return; - tsi_fake_zero_copy_grpc_protector *impl = - (tsi_fake_zero_copy_grpc_protector *)self; + tsi_fake_zero_copy_grpc_protector* impl = + (tsi_fake_zero_copy_grpc_protector*)self; grpc_slice_buffer_destroy_internal(exec_ctx, &impl->header_sb); grpc_slice_buffer_destroy_internal(exec_ctx, &impl->protected_sb); gpr_free(impl); @@ -476,12 +478,12 @@ static const tsi_zero_copy_grpc_protector_vtable typedef struct { tsi_handshaker_result base; - unsigned char *unused_bytes; + unsigned char* unused_bytes; size_t unused_bytes_size; } fake_handshaker_result; static tsi_result fake_handshaker_result_extract_peer( - const tsi_handshaker_result *self, tsi_peer *peer) { + const tsi_handshaker_result* self, tsi_peer* peer) { /* Construct a tsi_peer with 1 property: certificate type. */ tsi_result result = tsi_construct_peer(1, peer); if (result != TSI_OK) return result; @@ -493,32 +495,32 @@ static tsi_result fake_handshaker_result_extract_peer( } static tsi_result fake_handshaker_result_create_zero_copy_grpc_protector( - void *exec_ctx, const tsi_handshaker_result *self, - size_t *max_output_protected_frame_size, - tsi_zero_copy_grpc_protector **protector) { + void* exec_ctx, const tsi_handshaker_result* self, + size_t* max_output_protected_frame_size, + tsi_zero_copy_grpc_protector** protector) { *protector = tsi_create_fake_zero_copy_grpc_protector(max_output_protected_frame_size); return TSI_OK; } static tsi_result fake_handshaker_result_create_frame_protector( - const tsi_handshaker_result *self, size_t *max_output_protected_frame_size, - tsi_frame_protector **protector) { + const tsi_handshaker_result* self, size_t* max_output_protected_frame_size, + tsi_frame_protector** protector) { *protector = tsi_create_fake_frame_protector(max_output_protected_frame_size); return TSI_OK; } static tsi_result fake_handshaker_result_get_unused_bytes( - const tsi_handshaker_result *self, const unsigned char **bytes, - size_t *bytes_size) { - fake_handshaker_result *result = (fake_handshaker_result *)self; + const tsi_handshaker_result* self, const unsigned char** bytes, + size_t* bytes_size) { + fake_handshaker_result* result = (fake_handshaker_result*)self; *bytes_size = result->unused_bytes_size; *bytes = result->unused_bytes; return TSI_OK; } -static void fake_handshaker_result_destroy(tsi_handshaker_result *self) { - fake_handshaker_result *result = (fake_handshaker_result *)self; +static void fake_handshaker_result_destroy(tsi_handshaker_result* self) { + fake_handshaker_result* result = (fake_handshaker_result*)self; gpr_free(result->unused_bytes); gpr_free(self); } @@ -532,17 +534,17 @@ static const tsi_handshaker_result_vtable handshaker_result_vtable = { }; static tsi_result fake_handshaker_result_create( - const unsigned char *unused_bytes, size_t unused_bytes_size, - tsi_handshaker_result **handshaker_result) { + const unsigned char* unused_bytes, size_t unused_bytes_size, + tsi_handshaker_result** handshaker_result) { if ((unused_bytes_size > 0 && unused_bytes == NULL) || handshaker_result == NULL) { return TSI_INVALID_ARGUMENT; } - fake_handshaker_result *result = - (fake_handshaker_result *)gpr_zalloc(sizeof(*result)); + fake_handshaker_result* result = + (fake_handshaker_result*)gpr_zalloc(sizeof(*result)); result->base.vtable = &handshaker_result_vtable; if (unused_bytes_size > 0) { - result->unused_bytes = (unsigned char *)gpr_malloc(unused_bytes_size); + result->unused_bytes = (unsigned char*)gpr_malloc(unused_bytes_size); memcpy(result->unused_bytes, unused_bytes, unused_bytes_size); } result->unused_bytes_size = unused_bytes_size; @@ -553,8 +555,8 @@ static tsi_result fake_handshaker_result_create( /* --- tsi_handshaker methods implementation. ---*/ static tsi_result fake_handshaker_get_bytes_to_send_to_peer( - tsi_handshaker *self, unsigned char *bytes, size_t *bytes_size) { - tsi_fake_handshaker *impl = (tsi_fake_handshaker *)self; + tsi_handshaker* self, unsigned char* bytes, size_t* bytes_size) { + tsi_fake_handshaker* impl = (tsi_fake_handshaker*)self; tsi_result result = TSI_OK; if (impl->needs_incoming_message || impl->result == TSI_OK) { *bytes_size = 0; @@ -563,9 +565,9 @@ static tsi_result fake_handshaker_get_bytes_to_send_to_peer( if (!impl->outgoing_frame.needs_draining) { tsi_fake_handshake_message next_message_to_send = (tsi_fake_handshake_message)(impl->next_message_to_send + 2); - const char *msg_string = + const char* msg_string = tsi_fake_handshake_message_to_string(impl->next_message_to_send); - result = tsi_fake_frame_set_data((unsigned char *)msg_string, + result = tsi_fake_frame_set_data((unsigned char*)msg_string, strlen(msg_string), &impl->outgoing_frame); if (result != TSI_OK) return result; if (next_message_to_send > TSI_FAKE_HANDSHAKE_MESSAGE_MAX) { @@ -594,9 +596,9 @@ static tsi_result fake_handshaker_get_bytes_to_send_to_peer( } static tsi_result fake_handshaker_process_bytes_from_peer( - tsi_handshaker *self, const unsigned char *bytes, size_t *bytes_size) { + tsi_handshaker* self, const unsigned char* bytes, size_t* bytes_size) { tsi_result result = TSI_OK; - tsi_fake_handshaker *impl = (tsi_fake_handshaker *)self; + tsi_fake_handshaker* impl = (tsi_fake_handshaker*)self; tsi_fake_handshake_message expected_msg = (tsi_fake_handshake_message)(impl->next_message_to_send - 1); tsi_fake_handshake_message received_msg; @@ -610,7 +612,7 @@ static tsi_result fake_handshaker_process_bytes_from_peer( /* We now have a complete frame. */ result = tsi_fake_handshake_message_from_string( - (const char *)impl->incoming_frame.data + TSI_FAKE_FRAME_HEADER_SIZE, + (const char*)impl->incoming_frame.data + TSI_FAKE_FRAME_HEADER_SIZE, &received_msg); if (result != TSI_OK) { impl->result = result; @@ -637,13 +639,13 @@ static tsi_result fake_handshaker_process_bytes_from_peer( return TSI_OK; } -static tsi_result fake_handshaker_get_result(tsi_handshaker *self) { - tsi_fake_handshaker *impl = (tsi_fake_handshaker *)self; +static tsi_result fake_handshaker_get_result(tsi_handshaker* self) { + tsi_fake_handshaker* impl = (tsi_fake_handshaker*)self; return impl->result; } -static void fake_handshaker_destroy(tsi_handshaker *self) { - tsi_fake_handshaker *impl = (tsi_fake_handshaker *)self; +static void fake_handshaker_destroy(tsi_handshaker* self) { + tsi_fake_handshaker* impl = (tsi_fake_handshaker*)self; tsi_fake_frame_destruct(&impl->incoming_frame); tsi_fake_frame_destruct(&impl->outgoing_frame); gpr_free(impl->outgoing_bytes_buffer); @@ -651,17 +653,17 @@ static void fake_handshaker_destroy(tsi_handshaker *self) { } static tsi_result fake_handshaker_next( - tsi_handshaker *self, const unsigned char *received_bytes, - size_t received_bytes_size, const unsigned char **bytes_to_send, - size_t *bytes_to_send_size, tsi_handshaker_result **handshaker_result, - tsi_handshaker_on_next_done_cb cb, void *user_data) { + tsi_handshaker* self, const unsigned char* received_bytes, + size_t received_bytes_size, const unsigned char** bytes_to_send, + size_t* bytes_to_send_size, tsi_handshaker_result** handshaker_result, + tsi_handshaker_on_next_done_cb cb, void* user_data) { /* Sanity check the arguments. */ if ((received_bytes_size > 0 && received_bytes == NULL) || bytes_to_send == NULL || bytes_to_send_size == NULL || handshaker_result == NULL) { return TSI_INVALID_ARGUMENT; } - tsi_fake_handshaker *handshaker = (tsi_fake_handshaker *)self; + tsi_fake_handshaker* handshaker = (tsi_fake_handshaker*)self; tsi_result result = TSI_OK; /* Decode and process a handshake frame from the peer. */ @@ -683,8 +685,8 @@ static tsi_result fake_handshaker_next( if (result == TSI_INCOMPLETE_DATA) { handshaker->outgoing_bytes_buffer_size *= 2; handshaker->outgoing_bytes_buffer = - (unsigned char *)gpr_realloc(handshaker->outgoing_bytes_buffer, - handshaker->outgoing_bytes_buffer_size); + (unsigned char*)gpr_realloc(handshaker->outgoing_bytes_buffer, + handshaker->outgoing_bytes_buffer_size); } } while (result == TSI_INCOMPLETE_DATA); if (result != TSI_OK) return result; @@ -696,7 +698,7 @@ static tsi_result fake_handshaker_next( *handshaker_result = NULL; } else { /* Calculate the unused bytes. */ - const unsigned char *unused_bytes = NULL; + const unsigned char* unused_bytes = NULL; size_t unused_bytes_size = received_bytes_size - consumed_bytes_size; if (unused_bytes_size > 0) { unused_bytes = received_bytes + consumed_bytes_size; @@ -724,15 +726,15 @@ static const tsi_handshaker_vtable handshaker_vtable = { fake_handshaker_next, }; -tsi_handshaker *tsi_create_fake_handshaker(int is_client) { - tsi_fake_handshaker *impl = (tsi_fake_handshaker *)gpr_zalloc(sizeof(*impl)); +tsi_handshaker* tsi_create_fake_handshaker(int is_client) { + tsi_fake_handshaker* impl = (tsi_fake_handshaker*)gpr_zalloc(sizeof(*impl)); impl->base.vtable = &handshaker_vtable; impl->is_client = is_client; impl->result = TSI_HANDSHAKE_IN_PROGRESS; impl->outgoing_bytes_buffer_size = TSI_FAKE_HANDSHAKER_OUTGOING_BUFFER_INITIAL_SIZE; impl->outgoing_bytes_buffer = - (unsigned char *)gpr_malloc(impl->outgoing_bytes_buffer_size); + (unsigned char*)gpr_malloc(impl->outgoing_bytes_buffer_size); if (is_client) { impl->needs_incoming_message = 0; impl->next_message_to_send = TSI_FAKE_CLIENT_INIT; @@ -743,10 +745,10 @@ tsi_handshaker *tsi_create_fake_handshaker(int is_client) { return &impl->base; } -tsi_frame_protector *tsi_create_fake_frame_protector( - size_t *max_protected_frame_size) { - tsi_fake_frame_protector *impl = - (tsi_fake_frame_protector *)gpr_zalloc(sizeof(*impl)); +tsi_frame_protector* tsi_create_fake_frame_protector( + size_t* max_protected_frame_size) { + tsi_fake_frame_protector* impl = + (tsi_fake_frame_protector*)gpr_zalloc(sizeof(*impl)); impl->max_frame_size = (max_protected_frame_size == NULL) ? TSI_FAKE_DEFAULT_FRAME_SIZE : *max_protected_frame_size; @@ -754,10 +756,10 @@ tsi_frame_protector *tsi_create_fake_frame_protector( return &impl->base; } -tsi_zero_copy_grpc_protector *tsi_create_fake_zero_copy_grpc_protector( - size_t *max_protected_frame_size) { - tsi_fake_zero_copy_grpc_protector *impl = - (tsi_fake_zero_copy_grpc_protector *)gpr_zalloc(sizeof(*impl)); +tsi_zero_copy_grpc_protector* tsi_create_fake_zero_copy_grpc_protector( + size_t* max_protected_frame_size) { + tsi_fake_zero_copy_grpc_protector* impl = + (tsi_fake_zero_copy_grpc_protector*)gpr_zalloc(sizeof(*impl)); grpc_slice_buffer_init(&impl->header_sb); grpc_slice_buffer_init(&impl->protected_sb); impl->max_frame_size = (max_protected_frame_size == NULL) diff --git a/src/core/tsi/fake_transport_security.h b/src/core/tsi/fake_transport_security.h index 6159708a84..b90b9962f7 100644 --- a/src/core/tsi/fake_transport_security.h +++ b/src/core/tsi/fake_transport_security.h @@ -33,16 +33,16 @@ extern "C" { No cryptography is performed in these objects. They just simulate handshake messages going back and forth for the handshaker and do some framing on cleartext data for the protector. */ -tsi_handshaker *tsi_create_fake_handshaker(int is_client); +tsi_handshaker* tsi_create_fake_handshaker(int is_client); /* Creates a protector directly without going through the handshake phase. */ -tsi_frame_protector *tsi_create_fake_frame_protector( - size_t *max_protected_frame_size); +tsi_frame_protector* tsi_create_fake_frame_protector( + size_t* max_protected_frame_size); /* Creates a zero-copy protector directly without going through the handshake * phase. */ -tsi_zero_copy_grpc_protector *tsi_create_fake_zero_copy_grpc_protector( - size_t *max_protected_frame_size); +tsi_zero_copy_grpc_protector* tsi_create_fake_zero_copy_grpc_protector( + size_t* max_protected_frame_size); #ifdef __cplusplus } diff --git a/src/core/tsi/gts_transport_security.cc b/src/core/tsi/gts_transport_security.cc index d37f3bf8f6..1dfd8c4df0 100644 --- a/src/core/tsi/gts_transport_security.cc +++ b/src/core/tsi/gts_transport_security.cc @@ -22,7 +22,7 @@ static gts_shared_resource g_gts_resource; -gts_shared_resource *gts_get_shared_resource(void) { return &g_gts_resource; } +gts_shared_resource* gts_get_shared_resource(void) { return &g_gts_resource; } extern "C" void grpc_tsi_gts_init() { memset(&g_gts_resource, 0, sizeof(gts_shared_resource)); diff --git a/src/core/tsi/gts_transport_security.h b/src/core/tsi/gts_transport_security.h index 9590038ed0..8bc2107270 100644 --- a/src/core/tsi/gts_transport_security.h +++ b/src/core/tsi/gts_transport_security.h @@ -29,14 +29,14 @@ extern "C" { typedef struct gts_shared_resource { gpr_thd_id thread_id; - grpc_channel *channel; - grpc_completion_queue *cq; + grpc_channel* channel; + grpc_completion_queue* cq; gpr_mu mu; } gts_shared_resource; /* This method returns the address of gts_shared_resource object shared by all * TSI handshakes. */ -gts_shared_resource *gts_get_shared_resource(void); +gts_shared_resource* gts_get_shared_resource(void); #ifdef __cplusplus } diff --git a/src/core/tsi/ssl_transport_security.cc b/src/core/tsi/ssl_transport_security.cc index b1c69e9c7b..c1c2de6ca9 100644 --- a/src/core/tsi/ssl_transport_security.cc +++ b/src/core/tsi/ssl_transport_security.cc @@ -70,14 +70,14 @@ extern "C" { /* --- Structure definitions. ---*/ struct tsi_ssl_handshaker_factory { - const tsi_ssl_handshaker_factory_vtable *vtable; + const tsi_ssl_handshaker_factory_vtable* vtable; gpr_refcount refcount; }; struct tsi_ssl_client_handshaker_factory { tsi_ssl_handshaker_factory base; - SSL_CTX *ssl_context; - unsigned char *alpn_protocol_list; + SSL_CTX* ssl_context; + unsigned char* alpn_protocol_list; size_t alpn_protocol_list_length; }; @@ -86,28 +86,28 @@ struct tsi_ssl_server_handshaker_factory { The tsi_peer array contains the subject names of the server certificates associated with the contexts at the same index. */ tsi_ssl_handshaker_factory base; - SSL_CTX **ssl_contexts; - tsi_peer *ssl_context_x509_subject_names; + SSL_CTX** ssl_contexts; + tsi_peer* ssl_context_x509_subject_names; size_t ssl_context_count; - unsigned char *alpn_protocol_list; + unsigned char* alpn_protocol_list; size_t alpn_protocol_list_length; }; typedef struct { tsi_handshaker base; - SSL *ssl; - BIO *into_ssl; - BIO *from_ssl; + SSL* ssl; + BIO* into_ssl; + BIO* from_ssl; tsi_result result; - tsi_ssl_handshaker_factory *factory_ref; + tsi_ssl_handshaker_factory* factory_ref; } tsi_ssl_handshaker; typedef struct { tsi_frame_protector base; - SSL *ssl; - BIO *into_ssl; - BIO *from_ssl; - unsigned char *buffer; + SSL* ssl; + BIO* into_ssl; + BIO* from_ssl; + unsigned char* buffer; size_t buffer_size; size_t buffer_offset; } tsi_ssl_frame_protector; @@ -115,9 +115,9 @@ typedef struct { /* --- Library Initialization. ---*/ static gpr_once init_openssl_once = GPR_ONCE_INIT; -static gpr_mu *openssl_mutexes = NULL; +static gpr_mu* openssl_mutexes = NULL; -static void openssl_locking_cb(int mode, int type, const char *file, int line) { +static void openssl_locking_cb(int mode, int type, const char* file, int line) { if (mode & CRYPTO_LOCK) { gpr_mu_lock(&openssl_mutexes[type]); } else { @@ -137,7 +137,7 @@ static void init_openssl(void) { OpenSSL_add_all_algorithms(); num_locks = CRYPTO_num_locks(); GPR_ASSERT(num_locks > 0); - openssl_mutexes = (gpr_mu *)gpr_malloc((size_t)num_locks * sizeof(gpr_mu)); + openssl_mutexes = (gpr_mu*)gpr_malloc((size_t)num_locks * sizeof(gpr_mu)); for (i = 0; i < CRYPTO_num_locks(); i++) { gpr_mu_init(&openssl_mutexes[i]); } @@ -147,7 +147,7 @@ static void init_openssl(void) { /* --- Ssl utils. ---*/ -static const char *ssl_error_string(int error) { +static const char* ssl_error_string(int error) { switch (error) { case SSL_ERROR_NONE: return "SSL_ERROR_NONE"; @@ -173,8 +173,8 @@ static const char *ssl_error_string(int error) { } /* TODO(jboeuf): Remove when we are past the debugging phase with this code. */ -static void ssl_log_where_info(const SSL *ssl, int where, int flag, - const char *msg) { +static void ssl_log_where_info(const SSL* ssl, int where, int flag, + const char* msg) { if ((where & flag) && GRPC_TRACER_ON(tsi_tracing_enabled)) { gpr_log(GPR_INFO, "%20.20s - %30.30s - %5.10s", msg, SSL_state_string_long(ssl), SSL_state_string(ssl)); @@ -182,7 +182,7 @@ static void ssl_log_where_info(const SSL *ssl, int where, int flag, } /* Used for debugging. TODO(jboeuf): Remove when code is mature enough. */ -static void ssl_info_callback(const SSL *ssl, int where, int ret) { +static void ssl_info_callback(const SSL* ssl, int where, int ret) { if (ret == 0) { gpr_log(GPR_ERROR, "ssl_info_callback: error occured.\n"); return; @@ -195,7 +195,7 @@ static void ssl_info_callback(const SSL *ssl, int where, int ret) { /* Returns 1 if name looks like an IP address, 0 otherwise. This is a very rough heuristic, and only handles IPv6 in hexadecimal form. */ -static int looks_like_ip_address(const char *name) { +static int looks_like_ip_address(const char* name) { size_t i; size_t dot_count = 0; size_t num_size = 0; @@ -220,12 +220,12 @@ static int looks_like_ip_address(const char *name) { } /* Gets the subject CN from an X509 cert. */ -static tsi_result ssl_get_x509_common_name(X509 *cert, unsigned char **utf8, - size_t *utf8_size) { +static tsi_result ssl_get_x509_common_name(X509* cert, unsigned char** utf8, + size_t* utf8_size) { int common_name_index = -1; - X509_NAME_ENTRY *common_name_entry = NULL; - ASN1_STRING *common_name_asn1 = NULL; - X509_NAME *subject_name = X509_get_subject_name(cert); + X509_NAME_ENTRY* common_name_entry = NULL; + ASN1_STRING* common_name_asn1 = NULL; + X509_NAME* subject_name = X509_get_subject_name(cert); int utf8_returned_size = 0; if (subject_name == NULL) { gpr_log(GPR_ERROR, "Could not get subject name from certificate."); @@ -260,8 +260,8 @@ static tsi_result ssl_get_x509_common_name(X509 *cert, unsigned char **utf8, /* Gets the subject CN of an X509 cert as a tsi_peer_property. */ static tsi_result peer_property_from_x509_common_name( - X509 *cert, tsi_peer_property *property) { - unsigned char *common_name; + X509* cert, tsi_peer_property* property) { + unsigned char* common_name; size_t common_name_size; tsi_result result = ssl_get_x509_common_name(cert, &common_name, &common_name_size); @@ -275,35 +275,34 @@ static tsi_result peer_property_from_x509_common_name( } result = tsi_construct_string_peer_property( TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, - common_name == NULL ? "" : (const char *)common_name, common_name_size, + common_name == NULL ? "" : (const char*)common_name, common_name_size, property); OPENSSL_free(common_name); return result; } /* Gets the X509 cert in PEM format as a tsi_peer_property. */ -static tsi_result add_pem_certificate(X509 *cert, tsi_peer_property *property) { - BIO *bio = BIO_new(BIO_s_mem()); +static tsi_result add_pem_certificate(X509* cert, tsi_peer_property* property) { + BIO* bio = BIO_new(BIO_s_mem()); if (!PEM_write_bio_X509(bio, cert)) { BIO_free(bio); return TSI_INTERNAL_ERROR; } - char *contents; + char* contents; long len = BIO_get_mem_data(bio, &contents); if (len <= 0) { BIO_free(bio); return TSI_INTERNAL_ERROR; } tsi_result result = tsi_construct_string_peer_property( - TSI_X509_PEM_CERT_PROPERTY, (const char *)contents, (size_t)len, - property); + TSI_X509_PEM_CERT_PROPERTY, (const char*)contents, (size_t)len, property); BIO_free(bio); return result; } /* Gets the subject SANs from an X509 cert as a tsi_peer_property. */ static tsi_result add_subject_alt_names_properties_to_peer( - tsi_peer *peer, GENERAL_NAMES *subject_alt_names, + tsi_peer* peer, GENERAL_NAMES* subject_alt_names, size_t subject_alt_name_count) { size_t i; tsi_result result = TSI_OK; @@ -312,11 +311,11 @@ static tsi_result add_subject_alt_names_properties_to_peer( peer->property_count -= subject_alt_name_count; for (i = 0; i < subject_alt_name_count; i++) { - GENERAL_NAME *subject_alt_name = + GENERAL_NAME* subject_alt_name = sk_GENERAL_NAME_value(subject_alt_names, TSI_SIZE_AS_SIZE(i)); /* Filter out the non-dns entries names. */ if (subject_alt_name->type == GEN_DNS) { - unsigned char *name = NULL; + unsigned char* name = NULL; int name_size; name_size = ASN1_STRING_to_UTF8(&name, subject_alt_name->d.dNSName); if (name_size < 0) { @@ -325,7 +324,7 @@ static tsi_result add_subject_alt_names_properties_to_peer( break; } result = tsi_construct_string_peer_property( - TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, (const char *)name, + TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, (const char*)name, (size_t)name_size, &peer->properties[peer->property_count++]); OPENSSL_free(name); } else if (subject_alt_name->type == GEN_IPADD) { @@ -341,7 +340,7 @@ static tsi_result add_subject_alt_names_properties_to_peer( result = TSI_INTERNAL_ERROR; break; } - const char *name = inet_ntop(af, subject_alt_name->d.iPAddress->data, + const char* name = inet_ntop(af, subject_alt_name->d.iPAddress->data, ntop_buf, INET6_ADDRSTRLEN); if (name == NULL) { gpr_log(GPR_ERROR, "Could not get IP string from asn1 octet."); @@ -359,11 +358,11 @@ static tsi_result add_subject_alt_names_properties_to_peer( } /* Gets information about the peer's X509 cert as a tsi_peer object. */ -static tsi_result peer_from_x509(X509 *cert, int include_certificate_type, - tsi_peer *peer) { +static tsi_result peer_from_x509(X509* cert, int include_certificate_type, + tsi_peer* peer) { /* TODO(jboeuf): Maybe add more properties. */ - GENERAL_NAMES *subject_alt_names = - (GENERAL_NAMES *)X509_get_ext_d2i(cert, NID_subject_alt_name, 0, 0); + GENERAL_NAMES* subject_alt_names = + (GENERAL_NAMES*)X509_get_ext_d2i(cert, NID_subject_alt_name, 0, 0); int subject_alt_name_count = (subject_alt_names != NULL) ? (int)sk_GENERAL_NAME_num(subject_alt_names) : 0; @@ -415,8 +414,8 @@ static void log_ssl_error_stack(void) { } /* Performs an SSL_read and handle errors. */ -static tsi_result do_ssl_read(SSL *ssl, unsigned char *unprotected_bytes, - size_t *unprotected_bytes_size) { +static tsi_result do_ssl_read(SSL* ssl, unsigned char* unprotected_bytes, + size_t* unprotected_bytes_size) { int read_from_ssl; GPR_ASSERT(*unprotected_bytes_size <= INT_MAX); read_from_ssl = @@ -448,7 +447,7 @@ static tsi_result do_ssl_read(SSL *ssl, unsigned char *unprotected_bytes, } /* Performs an SSL_write and handle errors. */ -static tsi_result do_ssl_write(SSL *ssl, unsigned char *unprotected_bytes, +static tsi_result do_ssl_write(SSL* ssl, unsigned char* unprotected_bytes, size_t unprotected_bytes_size) { int ssl_write_result; GPR_ASSERT(unprotected_bytes_size <= INT_MAX); @@ -470,18 +469,18 @@ static tsi_result do_ssl_write(SSL *ssl, unsigned char *unprotected_bytes, } /* Loads an in-memory PEM certificate chain into the SSL context. */ -static tsi_result ssl_ctx_use_certificate_chain(SSL_CTX *context, - const char *pem_cert_chain, +static tsi_result ssl_ctx_use_certificate_chain(SSL_CTX* context, + const char* pem_cert_chain, size_t pem_cert_chain_size) { tsi_result result = TSI_OK; - X509 *certificate = NULL; - BIO *pem; + X509* certificate = NULL; + BIO* pem; GPR_ASSERT(pem_cert_chain_size <= INT_MAX); - pem = BIO_new_mem_buf((void *)pem_cert_chain, (int)pem_cert_chain_size); + pem = BIO_new_mem_buf((void*)pem_cert_chain, (int)pem_cert_chain_size); if (pem == NULL) return TSI_OUT_OF_RESOURCES; do { - certificate = PEM_read_bio_X509_AUX(pem, NULL, NULL, (void *)""); + certificate = PEM_read_bio_X509_AUX(pem, NULL, NULL, (void*)""); if (certificate == NULL) { result = TSI_INVALID_ARGUMENT; break; @@ -491,8 +490,8 @@ static tsi_result ssl_ctx_use_certificate_chain(SSL_CTX *context, break; } while (1) { - X509 *certificate_authority = - PEM_read_bio_X509(pem, NULL, NULL, (void *)""); + X509* certificate_authority = + PEM_read_bio_X509(pem, NULL, NULL, (void*)""); if (certificate_authority == NULL) { ERR_clear_error(); break; /* Done reading. */ @@ -514,16 +513,16 @@ static tsi_result ssl_ctx_use_certificate_chain(SSL_CTX *context, } /* Loads an in-memory PEM private key into the SSL context. */ -static tsi_result ssl_ctx_use_private_key(SSL_CTX *context, const char *pem_key, +static tsi_result ssl_ctx_use_private_key(SSL_CTX* context, const char* pem_key, size_t pem_key_size) { tsi_result result = TSI_OK; - EVP_PKEY *private_key = NULL; - BIO *pem; + EVP_PKEY* private_key = NULL; + BIO* pem; GPR_ASSERT(pem_key_size <= INT_MAX); - pem = BIO_new_mem_buf((void *)pem_key, (int)pem_key_size); + pem = BIO_new_mem_buf((void*)pem_key, (int)pem_key_size); if (pem == NULL) return TSI_OUT_OF_RESOURCES; do { - private_key = PEM_read_bio_PrivateKey(pem, NULL, NULL, (void *)""); + private_key = PEM_read_bio_PrivateKey(pem, NULL, NULL, (void*)""); if (private_key == NULL) { result = TSI_INVALID_ARGUMENT; break; @@ -540,19 +539,19 @@ static tsi_result ssl_ctx_use_private_key(SSL_CTX *context, const char *pem_key, /* Loads in-memory PEM verification certs into the SSL context and optionally returns the verification cert names (root_names can be NULL). */ -static tsi_result ssl_ctx_load_verification_certs(SSL_CTX *context, - const char *pem_roots, +static tsi_result ssl_ctx_load_verification_certs(SSL_CTX* context, + const char* pem_roots, size_t pem_roots_size, STACK_OF(X509_NAME) * *root_names) { tsi_result result = TSI_OK; size_t num_roots = 0; - X509 *root = NULL; - X509_NAME *root_name = NULL; - BIO *pem; - X509_STORE *root_store; + X509* root = NULL; + X509_NAME* root_name = NULL; + BIO* pem; + X509_STORE* root_store; GPR_ASSERT(pem_roots_size <= INT_MAX); - pem = BIO_new_mem_buf((void *)pem_roots, (int)pem_roots_size); + pem = BIO_new_mem_buf((void*)pem_roots, (int)pem_roots_size); root_store = SSL_CTX_get_cert_store(context); if (root_store == NULL) return TSI_INVALID_ARGUMENT; if (pem == NULL) return TSI_OUT_OF_RESOURCES; @@ -562,7 +561,7 @@ static tsi_result ssl_ctx_load_verification_certs(SSL_CTX *context, } while (1) { - root = PEM_read_bio_X509_AUX(pem, NULL, NULL, (void *)""); + root = PEM_read_bio_X509_AUX(pem, NULL, NULL, (void*)""); if (root == NULL) { ERR_clear_error(); break; /* We're at the end of stream. */ @@ -611,8 +610,8 @@ static tsi_result ssl_ctx_load_verification_certs(SSL_CTX *context, /* Populates the SSL context with a private key and a cert chain, and sets the cipher list and the ephemeral ECDH key. */ static tsi_result populate_ssl_context( - SSL_CTX *context, const tsi_ssl_pem_key_cert_pair *key_cert_pair, - const char *cipher_list) { + SSL_CTX* context, const tsi_ssl_pem_key_cert_pair* key_cert_pair, + const char* cipher_list) { tsi_result result = TSI_OK; if (key_cert_pair != NULL) { if (key_cert_pair->cert_chain != NULL) { @@ -637,7 +636,7 @@ static tsi_result populate_ssl_context( return TSI_INVALID_ARGUMENT; } { - EC_KEY *ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); + EC_KEY* ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); if (!SSL_CTX_set_tmp_ecdh(context, ecdh)) { gpr_log(GPR_ERROR, "Could not set ephemeral ECDH key."); EC_KEY_free(ecdh); @@ -650,15 +649,15 @@ static tsi_result populate_ssl_context( } /* Extracts the CN and the SANs from an X509 cert as a peer object. */ -static tsi_result extract_x509_subject_names_from_pem_cert(const char *pem_cert, - tsi_peer *peer) { +static tsi_result extract_x509_subject_names_from_pem_cert(const char* pem_cert, + tsi_peer* peer) { tsi_result result = TSI_OK; - X509 *cert = NULL; - BIO *pem; - pem = BIO_new_mem_buf((void *)pem_cert, (int)strlen(pem_cert)); + X509* cert = NULL; + BIO* pem; + pem = BIO_new_mem_buf((void*)pem_cert, (int)strlen(pem_cert)); if (pem == NULL) return TSI_OUT_OF_RESOURCES; - cert = PEM_read_bio_X509(pem, NULL, NULL, (void *)""); + cert = PEM_read_bio_X509(pem, NULL, NULL, (void*)""); if (cert == NULL) { gpr_log(GPR_ERROR, "Invalid certificate"); result = TSI_INVALID_ARGUMENT; @@ -672,10 +671,10 @@ static tsi_result extract_x509_subject_names_from_pem_cert(const char *pem_cert, /* Builds the alpn protocol name list according to rfc 7301. */ static tsi_result build_alpn_protocol_name_list( - const char **alpn_protocols, uint16_t num_alpn_protocols, - unsigned char **protocol_name_list, size_t *protocol_name_list_length) { + const char** alpn_protocols, uint16_t num_alpn_protocols, + unsigned char** protocol_name_list, size_t* protocol_name_list_length) { uint16_t i; - unsigned char *current; + unsigned char* current; *protocol_name_list = NULL; *protocol_name_list_length = 0; if (num_alpn_protocols == 0) return TSI_INVALID_ARGUMENT; @@ -687,7 +686,7 @@ static tsi_result build_alpn_protocol_name_list( } *protocol_name_list_length += length + 1; } - *protocol_name_list = (unsigned char *)gpr_malloc(*protocol_name_list_length); + *protocol_name_list = (unsigned char*)gpr_malloc(*protocol_name_list_length); if (*protocol_name_list == NULL) return TSI_OUT_OF_RESOURCES; current = *protocol_name_list; for (i = 0; i < num_alpn_protocols; i++) { @@ -709,18 +708,18 @@ static tsi_result build_alpn_protocol_name_list( // the server's certificate, but we need to pull it anyway, in case a higher // layer wants to look at it. In this case the verification may fail, but // we don't really care. -static int NullVerifyCallback(int preverify_ok, X509_STORE_CTX *ctx) { +static int NullVerifyCallback(int preverify_ok, X509_STORE_CTX* ctx) { return 1; } /* --- tsi_frame_protector methods implementation. ---*/ -static tsi_result ssl_protector_protect(tsi_frame_protector *self, - const unsigned char *unprotected_bytes, - size_t *unprotected_bytes_size, - unsigned char *protected_output_frames, - size_t *protected_output_frames_size) { - tsi_ssl_frame_protector *impl = (tsi_ssl_frame_protector *)self; +static tsi_result ssl_protector_protect(tsi_frame_protector* self, + const unsigned char* unprotected_bytes, + size_t* unprotected_bytes_size, + unsigned char* protected_output_frames, + size_t* protected_output_frames_size) { + tsi_ssl_frame_protector* impl = (tsi_ssl_frame_protector*)self; int read_from_ssl; size_t available; tsi_result result = TSI_OK; @@ -771,10 +770,10 @@ static tsi_result ssl_protector_protect(tsi_frame_protector *self, } static tsi_result ssl_protector_protect_flush( - tsi_frame_protector *self, unsigned char *protected_output_frames, - size_t *protected_output_frames_size, size_t *still_pending_size) { + tsi_frame_protector* self, unsigned char* protected_output_frames, + size_t* protected_output_frames_size, size_t* still_pending_size) { tsi_result result = TSI_OK; - tsi_ssl_frame_protector *impl = (tsi_ssl_frame_protector *)self; + tsi_ssl_frame_protector* impl = (tsi_ssl_frame_protector*)self; int read_from_ssl = 0; int pending; @@ -804,14 +803,14 @@ static tsi_result ssl_protector_protect_flush( } static tsi_result ssl_protector_unprotect( - tsi_frame_protector *self, const unsigned char *protected_frames_bytes, - size_t *protected_frames_bytes_size, unsigned char *unprotected_bytes, - size_t *unprotected_bytes_size) { + tsi_frame_protector* self, const unsigned char* protected_frames_bytes, + size_t* protected_frames_bytes_size, unsigned char* unprotected_bytes, + size_t* unprotected_bytes_size) { tsi_result result = TSI_OK; int written_into_ssl = 0; size_t output_bytes_size = *unprotected_bytes_size; size_t output_bytes_offset = 0; - tsi_ssl_frame_protector *impl = (tsi_ssl_frame_protector *)self; + tsi_ssl_frame_protector* impl = (tsi_ssl_frame_protector*)self; /* First, try to read remaining data from ssl. */ result = do_ssl_read(impl->ssl, unprotected_bytes, unprotected_bytes_size); @@ -845,22 +844,24 @@ static tsi_result ssl_protector_unprotect( return result; } -static void ssl_protector_destroy(tsi_frame_protector *self) { - tsi_ssl_frame_protector *impl = (tsi_ssl_frame_protector *)self; +static void ssl_protector_destroy(tsi_frame_protector* self) { + tsi_ssl_frame_protector* impl = (tsi_ssl_frame_protector*)self; if (impl->buffer != NULL) gpr_free(impl->buffer); if (impl->ssl != NULL) SSL_free(impl->ssl); gpr_free(self); } static const tsi_frame_protector_vtable frame_protector_vtable = { - ssl_protector_protect, ssl_protector_protect_flush, ssl_protector_unprotect, + ssl_protector_protect, + ssl_protector_protect_flush, + ssl_protector_unprotect, ssl_protector_destroy, }; /* --- tsi_server_handshaker_factory methods implementation. --- */ static void tsi_ssl_handshaker_factory_destroy( - tsi_ssl_handshaker_factory *self) { + tsi_ssl_handshaker_factory* self) { if (self == NULL) return; if (self->vtable != NULL && self->vtable->destroy != NULL) { @@ -871,14 +872,14 @@ static void tsi_ssl_handshaker_factory_destroy( * any memory, it should be free'd here. */ } -static tsi_ssl_handshaker_factory *tsi_ssl_handshaker_factory_ref( - tsi_ssl_handshaker_factory *self) { +static tsi_ssl_handshaker_factory* tsi_ssl_handshaker_factory_ref( + tsi_ssl_handshaker_factory* self) { if (self == NULL) return NULL; gpr_refn(&self->refcount, 1); return self; } -static void tsi_ssl_handshaker_factory_unref(tsi_ssl_handshaker_factory *self) { +static void tsi_ssl_handshaker_factory_unref(tsi_ssl_handshaker_factory* self) { if (self == NULL) return; if (gpr_unref(&self->refcount)) { @@ -891,7 +892,7 @@ static tsi_ssl_handshaker_factory_vtable handshaker_factory_vtable = {NULL}; /* Initializes a tsi_ssl_handshaker_factory object. Caller is responsible for * allocating memory for the factory. */ static void tsi_ssl_handshaker_factory_init( - tsi_ssl_handshaker_factory *factory) { + tsi_ssl_handshaker_factory* factory) { GPR_ASSERT(factory != NULL); factory->vtable = &handshaker_factory_vtable; @@ -900,10 +901,10 @@ static void tsi_ssl_handshaker_factory_init( /* --- tsi_handshaker methods implementation. ---*/ -static tsi_result ssl_handshaker_get_bytes_to_send_to_peer(tsi_handshaker *self, - unsigned char *bytes, - size_t *bytes_size) { - tsi_ssl_handshaker *impl = (tsi_ssl_handshaker *)self; +static tsi_result ssl_handshaker_get_bytes_to_send_to_peer(tsi_handshaker* self, + unsigned char* bytes, + size_t* bytes_size) { + tsi_ssl_handshaker* impl = (tsi_ssl_handshaker*)self; int bytes_read_from_ssl = 0; if (bytes == NULL || bytes_size == NULL || *bytes_size == 0 || *bytes_size > INT_MAX) { @@ -924,8 +925,8 @@ static tsi_result ssl_handshaker_get_bytes_to_send_to_peer(tsi_handshaker *self, return BIO_pending(impl->from_ssl) == 0 ? TSI_OK : TSI_INCOMPLETE_DATA; } -static tsi_result ssl_handshaker_get_result(tsi_handshaker *self) { - tsi_ssl_handshaker *impl = (tsi_ssl_handshaker *)self; +static tsi_result ssl_handshaker_get_result(tsi_handshaker* self) { + tsi_ssl_handshaker* impl = (tsi_ssl_handshaker*)self; if ((impl->result == TSI_HANDSHAKE_IN_PROGRESS) && SSL_is_init_finished(impl->ssl)) { impl->result = TSI_OK; @@ -934,8 +935,8 @@ static tsi_result ssl_handshaker_get_result(tsi_handshaker *self) { } static tsi_result ssl_handshaker_process_bytes_from_peer( - tsi_handshaker *self, const unsigned char *bytes, size_t *bytes_size) { - tsi_ssl_handshaker *impl = (tsi_ssl_handshaker *)self; + tsi_handshaker* self, const unsigned char* bytes, size_t* bytes_size) { + tsi_ssl_handshaker* impl = (tsi_ssl_handshaker*)self; int bytes_written_into_ssl_size = 0; if (bytes == NULL || bytes_size == 0 || *bytes_size > INT_MAX) { return TSI_INVALID_ARGUMENT; @@ -979,13 +980,13 @@ static tsi_result ssl_handshaker_process_bytes_from_peer( } } -static tsi_result ssl_handshaker_extract_peer(tsi_handshaker *self, - tsi_peer *peer) { +static tsi_result ssl_handshaker_extract_peer(tsi_handshaker* self, + tsi_peer* peer) { tsi_result result = TSI_OK; - const unsigned char *alpn_selected = NULL; + const unsigned char* alpn_selected = NULL; unsigned int alpn_selected_len; - tsi_ssl_handshaker *impl = (tsi_ssl_handshaker *)self; - X509 *peer_cert = SSL_get_peer_certificate(impl->ssl); + tsi_ssl_handshaker* impl = (tsi_ssl_handshaker*)self; + X509* peer_cert = SSL_get_peer_certificate(impl->ssl); if (peer_cert != NULL) { result = peer_from_x509(peer_cert, 1, peer); X509_free(peer_cert); @@ -1001,13 +1002,13 @@ static tsi_result ssl_handshaker_extract_peer(tsi_handshaker *self, } if (alpn_selected != NULL) { size_t i; - tsi_peer_property *new_properties = (tsi_peer_property *)gpr_zalloc( + tsi_peer_property* new_properties = (tsi_peer_property*)gpr_zalloc( sizeof(*new_properties) * (peer->property_count + 1)); for (i = 0; i < peer->property_count; i++) { new_properties[i] = peer->properties[i]; } result = tsi_construct_string_peer_property( - TSI_SSL_ALPN_SELECTED_PROTOCOL, (const char *)alpn_selected, + TSI_SSL_ALPN_SELECTED_PROTOCOL, (const char*)alpn_selected, alpn_selected_len, &new_properties[peer->property_count]); if (result != TSI_OK) { gpr_free(new_properties); @@ -1021,13 +1022,13 @@ static tsi_result ssl_handshaker_extract_peer(tsi_handshaker *self, } static tsi_result ssl_handshaker_create_frame_protector( - tsi_handshaker *self, size_t *max_output_protected_frame_size, - tsi_frame_protector **protector) { + tsi_handshaker* self, size_t* max_output_protected_frame_size, + tsi_frame_protector** protector) { size_t actual_max_output_protected_frame_size = TSI_SSL_MAX_PROTECTED_FRAME_SIZE_UPPER_BOUND; - tsi_ssl_handshaker *impl = (tsi_ssl_handshaker *)self; - tsi_ssl_frame_protector *protector_impl = - (tsi_ssl_frame_protector *)gpr_zalloc(sizeof(*protector_impl)); + tsi_ssl_handshaker* impl = (tsi_ssl_handshaker*)self; + tsi_ssl_frame_protector* protector_impl = + (tsi_ssl_frame_protector*)gpr_zalloc(sizeof(*protector_impl)); if (max_output_protected_frame_size != NULL) { if (*max_output_protected_frame_size > @@ -1044,7 +1045,7 @@ static tsi_result ssl_handshaker_create_frame_protector( protector_impl->buffer_size = actual_max_output_protected_frame_size - TSI_SSL_MAX_PROTECTION_OVERHEAD; protector_impl->buffer = - (unsigned char *)gpr_malloc(protector_impl->buffer_size); + (unsigned char*)gpr_malloc(protector_impl->buffer_size); if (protector_impl->buffer == NULL) { gpr_log(GPR_ERROR, "Could not allocated buffer for tsi_ssl_frame_protector."); @@ -1064,8 +1065,8 @@ static tsi_result ssl_handshaker_create_frame_protector( return TSI_OK; } -static void ssl_handshaker_destroy(tsi_handshaker *self) { - tsi_ssl_handshaker *impl = (tsi_ssl_handshaker *)self; +static void ssl_handshaker_destroy(tsi_handshaker* self) { + tsi_ssl_handshaker* impl = (tsi_ssl_handshaker*)self; SSL_free(impl->ssl); /* The BIO objects are owned by ssl */ tsi_ssl_handshaker_factory_unref(impl->factory_ref); gpr_free(impl); @@ -1083,14 +1084,14 @@ static const tsi_handshaker_vtable handshaker_vtable = { /* --- tsi_ssl_handshaker_factory common methods. --- */ -static tsi_result create_tsi_ssl_handshaker(SSL_CTX *ctx, int is_client, - const char *server_name_indication, - tsi_ssl_handshaker_factory *factory, - tsi_handshaker **handshaker) { - SSL *ssl = SSL_new(ctx); - BIO *into_ssl = NULL; - BIO *from_ssl = NULL; - tsi_ssl_handshaker *impl = NULL; +static tsi_result create_tsi_ssl_handshaker(SSL_CTX* ctx, int is_client, + const char* server_name_indication, + tsi_ssl_handshaker_factory* factory, + tsi_handshaker** handshaker) { + SSL* ssl = SSL_new(ctx); + BIO* into_ssl = NULL; + BIO* from_ssl = NULL; + tsi_ssl_handshaker* impl = NULL; *handshaker = NULL; if (ctx == NULL) { gpr_log(GPR_ERROR, "SSL Context is null. Should never happen."); @@ -1135,7 +1136,7 @@ static tsi_result create_tsi_ssl_handshaker(SSL_CTX *ctx, int is_client, SSL_set_accept_state(ssl); } - impl = (tsi_ssl_handshaker *)gpr_zalloc(sizeof(*impl)); + impl = (tsi_ssl_handshaker*)gpr_zalloc(sizeof(*impl)); impl->ssl = ssl; impl->into_ssl = into_ssl; impl->from_ssl = from_ssl; @@ -1147,16 +1148,16 @@ static tsi_result create_tsi_ssl_handshaker(SSL_CTX *ctx, int is_client, return TSI_OK; } -static int select_protocol_list(const unsigned char **out, - unsigned char *outlen, - const unsigned char *client_list, +static int select_protocol_list(const unsigned char** out, + unsigned char* outlen, + const unsigned char* client_list, size_t client_list_len, - const unsigned char *server_list, + const unsigned char* server_list, size_t server_list_len) { - const unsigned char *client_current = client_list; + const unsigned char* client_current = client_list; while ((unsigned int)(client_current - client_list) < client_list_len) { unsigned char client_current_len = *(client_current++); - const unsigned char *server_current = server_list; + const unsigned char* server_current = server_list; while ((server_current >= server_list) && (uintptr_t)(server_current - server_list) < server_list_len) { unsigned char server_current_len = *(server_current++); @@ -1176,36 +1177,36 @@ static int select_protocol_list(const unsigned char **out, /* --- tsi_ssl_client_handshaker_factory methods implementation. --- */ tsi_result tsi_ssl_client_handshaker_factory_create_handshaker( - tsi_ssl_client_handshaker_factory *self, const char *server_name_indication, - tsi_handshaker **handshaker) { + tsi_ssl_client_handshaker_factory* self, const char* server_name_indication, + tsi_handshaker** handshaker) { return create_tsi_ssl_handshaker(self->ssl_context, 1, server_name_indication, &self->base, handshaker); } void tsi_ssl_client_handshaker_factory_unref( - tsi_ssl_client_handshaker_factory *self) { + tsi_ssl_client_handshaker_factory* self) { if (self == NULL) return; tsi_ssl_handshaker_factory_unref(&self->base); } static void tsi_ssl_client_handshaker_factory_destroy( - tsi_ssl_handshaker_factory *factory) { + tsi_ssl_handshaker_factory* factory) { if (factory == NULL) return; - tsi_ssl_client_handshaker_factory *self = - (tsi_ssl_client_handshaker_factory *)factory; + tsi_ssl_client_handshaker_factory* self = + (tsi_ssl_client_handshaker_factory*)factory; if (self->ssl_context != NULL) SSL_CTX_free(self->ssl_context); if (self->alpn_protocol_list != NULL) gpr_free(self->alpn_protocol_list); gpr_free(self); } -static int client_handshaker_factory_npn_callback(SSL *ssl, unsigned char **out, - unsigned char *outlen, - const unsigned char *in, +static int client_handshaker_factory_npn_callback(SSL* ssl, unsigned char** out, + unsigned char* outlen, + const unsigned char* in, unsigned int inlen, - void *arg) { - tsi_ssl_client_handshaker_factory *factory = - (tsi_ssl_client_handshaker_factory *)arg; - return select_protocol_list((const unsigned char **)out, outlen, + void* arg) { + tsi_ssl_client_handshaker_factory* factory = + (tsi_ssl_client_handshaker_factory*)arg; + return select_protocol_list((const unsigned char**)out, outlen, factory->alpn_protocol_list, factory->alpn_protocol_list_length, in, inlen); } @@ -1213,7 +1214,7 @@ static int client_handshaker_factory_npn_callback(SSL *ssl, unsigned char **out, /* --- tsi_ssl_server_handshaker_factory methods implementation. --- */ tsi_result tsi_ssl_server_handshaker_factory_create_handshaker( - tsi_ssl_server_handshaker_factory *self, tsi_handshaker **handshaker) { + tsi_ssl_server_handshaker_factory* self, tsi_handshaker** handshaker) { if (self->ssl_context_count == 0) return TSI_INVALID_ARGUMENT; /* Create the handshaker with the first context. We will switch if needed because of SNI in ssl_server_handshaker_factory_servername_callback. */ @@ -1222,16 +1223,16 @@ tsi_result tsi_ssl_server_handshaker_factory_create_handshaker( } void tsi_ssl_server_handshaker_factory_unref( - tsi_ssl_server_handshaker_factory *self) { + tsi_ssl_server_handshaker_factory* self) { if (self == NULL) return; tsi_ssl_handshaker_factory_unref(&self->base); } static void tsi_ssl_server_handshaker_factory_destroy( - tsi_ssl_handshaker_factory *factory) { + tsi_ssl_handshaker_factory* factory) { if (factory == NULL) return; - tsi_ssl_server_handshaker_factory *self = - (tsi_ssl_server_handshaker_factory *)factory; + tsi_ssl_server_handshaker_factory* self = + (tsi_ssl_server_handshaker_factory*)factory; size_t i; for (i = 0; i < self->ssl_context_count; i++) { if (self->ssl_contexts[i] != NULL) { @@ -1247,10 +1248,10 @@ static void tsi_ssl_server_handshaker_factory_destroy( gpr_free(self); } -static int does_entry_match_name(const char *entry, size_t entry_length, - const char *name) { - const char *dot; - const char *name_subdomain = NULL; +static int does_entry_match_name(const char* entry, size_t entry_length, + const char* name) { + const char* dot; + const char* name_subdomain = NULL; size_t name_length = strlen(name); size_t name_subdomain_length; if (entry_length == 0) return 0; @@ -1295,12 +1296,12 @@ static int does_entry_match_name(const char *entry, size_t entry_length, strncmp(entry, name_subdomain, entry_length) == 0); } -static int ssl_server_handshaker_factory_servername_callback(SSL *ssl, int *ap, - void *arg) { - tsi_ssl_server_handshaker_factory *impl = - (tsi_ssl_server_handshaker_factory *)arg; +static int ssl_server_handshaker_factory_servername_callback(SSL* ssl, int* ap, + void* arg) { + tsi_ssl_server_handshaker_factory* impl = + (tsi_ssl_server_handshaker_factory*)arg; size_t i = 0; - const char *servername = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name); + const char* servername = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name); if (servername == NULL || strlen(servername) == 0) { return SSL_TLSEXT_ERR_NOACK; } @@ -1318,10 +1319,10 @@ static int ssl_server_handshaker_factory_servername_callback(SSL *ssl, int *ap, #if TSI_OPENSSL_ALPN_SUPPORT static int server_handshaker_factory_alpn_callback( - SSL *ssl, const unsigned char **out, unsigned char *outlen, - const unsigned char *in, unsigned int inlen, void *arg) { - tsi_ssl_server_handshaker_factory *factory = - (tsi_ssl_server_handshaker_factory *)arg; + SSL* ssl, const unsigned char** out, unsigned char* outlen, + const unsigned char* in, unsigned int inlen, void* arg) { + tsi_ssl_server_handshaker_factory* factory = + (tsi_ssl_server_handshaker_factory*)arg; return select_protocol_list(out, outlen, in, inlen, factory->alpn_protocol_list, factory->alpn_protocol_list_length); @@ -1329,9 +1330,9 @@ static int server_handshaker_factory_alpn_callback( #endif /* TSI_OPENSSL_ALPN_SUPPORT */ static int server_handshaker_factory_npn_advertised_callback( - SSL *ssl, const unsigned char **out, unsigned int *outlen, void *arg) { - tsi_ssl_server_handshaker_factory *factory = - (tsi_ssl_server_handshaker_factory *)arg; + SSL* ssl, const unsigned char** out, unsigned int* outlen, void* arg) { + tsi_ssl_server_handshaker_factory* factory = + (tsi_ssl_server_handshaker_factory*)arg; *out = factory->alpn_protocol_list; GPR_ASSERT(factory->alpn_protocol_list_length <= UINT_MAX); *outlen = (unsigned int)factory->alpn_protocol_list_length; @@ -1344,12 +1345,12 @@ static tsi_ssl_handshaker_factory_vtable client_handshaker_factory_vtable = { tsi_ssl_client_handshaker_factory_destroy}; tsi_result tsi_create_ssl_client_handshaker_factory( - const tsi_ssl_pem_key_cert_pair *pem_key_cert_pair, - const char *pem_root_certs, const char *cipher_suites, - const char **alpn_protocols, uint16_t num_alpn_protocols, - tsi_ssl_client_handshaker_factory **factory) { - SSL_CTX *ssl_context = NULL; - tsi_ssl_client_handshaker_factory *impl = NULL; + const tsi_ssl_pem_key_cert_pair* pem_key_cert_pair, + const char* pem_root_certs, const char* cipher_suites, + const char** alpn_protocols, uint16_t num_alpn_protocols, + tsi_ssl_client_handshaker_factory** factory) { + SSL_CTX* ssl_context = NULL; + tsi_ssl_client_handshaker_factory* impl = NULL; tsi_result result = TSI_OK; gpr_once_init(&init_openssl_once, init_openssl); @@ -1364,7 +1365,7 @@ tsi_result tsi_create_ssl_client_handshaker_factory( return TSI_INVALID_ARGUMENT; } - impl = (tsi_ssl_client_handshaker_factory *)gpr_zalloc(sizeof(*impl)); + impl = (tsi_ssl_client_handshaker_factory*)gpr_zalloc(sizeof(*impl)); tsi_ssl_handshaker_factory_init(&impl->base); impl->base.vtable = &client_handshaker_factory_vtable; @@ -1419,11 +1420,11 @@ static tsi_ssl_handshaker_factory_vtable server_handshaker_factory_vtable = { tsi_ssl_server_handshaker_factory_destroy}; tsi_result tsi_create_ssl_server_handshaker_factory( - const tsi_ssl_pem_key_cert_pair *pem_key_cert_pairs, - size_t num_key_cert_pairs, const char *pem_client_root_certs, - int force_client_auth, const char *cipher_suites, - const char **alpn_protocols, uint16_t num_alpn_protocols, - tsi_ssl_server_handshaker_factory **factory) { + const tsi_ssl_pem_key_cert_pair* pem_key_cert_pairs, + size_t num_key_cert_pairs, const char* pem_client_root_certs, + int force_client_auth, const char* cipher_suites, + const char** alpn_protocols, uint16_t num_alpn_protocols, + tsi_ssl_server_handshaker_factory** factory) { return tsi_create_ssl_server_handshaker_factory_ex( pem_key_cert_pairs, num_key_cert_pairs, pem_client_root_certs, force_client_auth ? TSI_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY @@ -1432,12 +1433,12 @@ tsi_result tsi_create_ssl_server_handshaker_factory( } tsi_result tsi_create_ssl_server_handshaker_factory_ex( - const tsi_ssl_pem_key_cert_pair *pem_key_cert_pairs, - size_t num_key_cert_pairs, const char *pem_client_root_certs, + const tsi_ssl_pem_key_cert_pair* pem_key_cert_pairs, + size_t num_key_cert_pairs, const char* pem_client_root_certs, tsi_client_certificate_request_type client_certificate_request, - const char *cipher_suites, const char **alpn_protocols, - uint16_t num_alpn_protocols, tsi_ssl_server_handshaker_factory **factory) { - tsi_ssl_server_handshaker_factory *impl = NULL; + const char* cipher_suites, const char** alpn_protocols, + uint16_t num_alpn_protocols, tsi_ssl_server_handshaker_factory** factory) { + tsi_ssl_server_handshaker_factory* impl = NULL; tsi_result result = TSI_OK; size_t i = 0; @@ -1449,14 +1450,14 @@ tsi_result tsi_create_ssl_server_handshaker_factory_ex( return TSI_INVALID_ARGUMENT; } - impl = (tsi_ssl_server_handshaker_factory *)gpr_zalloc(sizeof(*impl)); + impl = (tsi_ssl_server_handshaker_factory*)gpr_zalloc(sizeof(*impl)); tsi_ssl_handshaker_factory_init(&impl->base); impl->base.vtable = &server_handshaker_factory_vtable; impl->ssl_contexts = - (SSL_CTX **)gpr_zalloc(num_key_cert_pairs * sizeof(SSL_CTX *)); + (SSL_CTX**)gpr_zalloc(num_key_cert_pairs * sizeof(SSL_CTX*)); impl->ssl_context_x509_subject_names = - (tsi_peer *)gpr_zalloc(num_key_cert_pairs * sizeof(tsi_peer)); + (tsi_peer*)gpr_zalloc(num_key_cert_pairs * sizeof(tsi_peer)); if (impl->ssl_contexts == NULL || impl->ssl_context_x509_subject_names == NULL) { tsi_ssl_handshaker_factory_unref(&impl->base); @@ -1487,7 +1488,7 @@ tsi_result tsi_create_ssl_server_handshaker_factory_ex( if (result != TSI_OK) break; if (pem_client_root_certs != NULL) { - STACK_OF(X509_NAME) *root_names = NULL; + STACK_OF(X509_NAME)* root_names = NULL; result = ssl_ctx_load_verification_certs( impl->ssl_contexts[i], pem_client_root_certs, strlen(pem_client_root_certs), &root_names); @@ -1552,15 +1553,15 @@ tsi_result tsi_create_ssl_server_handshaker_factory_ex( /* --- tsi_ssl utils. --- */ -int tsi_ssl_peer_matches_name(const tsi_peer *peer, const char *name) { +int tsi_ssl_peer_matches_name(const tsi_peer* peer, const char* name) { size_t i = 0; size_t san_count = 0; - const tsi_peer_property *cn_property = NULL; + const tsi_peer_property* cn_property = NULL; int like_ip = looks_like_ip_address(name); /* Check the SAN first. */ for (i = 0; i < peer->property_count; i++) { - const tsi_peer_property *property = &peer->properties[i]; + const tsi_peer_property* property = &peer->properties[i]; if (property->name == NULL) continue; if (strcmp(property->name, TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY) == 0) { @@ -1594,13 +1595,13 @@ int tsi_ssl_peer_matches_name(const tsi_peer *peer, const char *name) { } /* --- Testing support. --- */ -const tsi_ssl_handshaker_factory_vtable *tsi_ssl_handshaker_factory_swap_vtable( - tsi_ssl_handshaker_factory *factory, - tsi_ssl_handshaker_factory_vtable *new_vtable) { +const tsi_ssl_handshaker_factory_vtable* tsi_ssl_handshaker_factory_swap_vtable( + tsi_ssl_handshaker_factory* factory, + tsi_ssl_handshaker_factory_vtable* new_vtable) { GPR_ASSERT(factory != NULL); GPR_ASSERT(factory->vtable != NULL); - const tsi_ssl_handshaker_factory_vtable *orig_vtable = factory->vtable; + const tsi_ssl_handshaker_factory_vtable* orig_vtable = factory->vtable; factory->vtable = new_vtable; return orig_vtable; } diff --git a/src/core/tsi/ssl_transport_security.h b/src/core/tsi/ssl_transport_security.h index 3abfdf5ed8..595c4ccaec 100644 --- a/src/core/tsi/ssl_transport_security.h +++ b/src/core/tsi/ssl_transport_security.h @@ -49,11 +49,11 @@ typedef struct tsi_ssl_client_handshaker_factory typedef struct { /* private_key is the NULL-terminated string containing the PEM encoding of the client's private key. */ - const char *private_key; + const char* private_key; /* cert_chain is the NULL-terminated string containing the PEM encoding of the client's certificate chain. */ - const char *cert_chain; + const char* cert_chain; } tsi_ssl_pem_key_cert_pair; /* Creates a client handshaker factory. @@ -78,10 +78,10 @@ typedef struct { - This method returns TSI_OK on success or TSI_INVALID_PARAMETER in the case where a parameter is invalid. */ tsi_result tsi_create_ssl_client_handshaker_factory( - const tsi_ssl_pem_key_cert_pair *pem_key_cert_pair, - const char *pem_root_certs, const char *cipher_suites, - const char **alpn_protocols, uint16_t num_alpn_protocols, - tsi_ssl_client_handshaker_factory **factory); + const tsi_ssl_pem_key_cert_pair* pem_key_cert_pair, + const char* pem_root_certs, const char* cipher_suites, + const char** alpn_protocols, uint16_t num_alpn_protocols, + tsi_ssl_client_handshaker_factory** factory); /* Creates a client handshaker. - self is the factory from which the handshaker will be created. @@ -93,13 +93,13 @@ tsi_result tsi_create_ssl_client_handshaker_factory( - This method returns TSI_OK on success or TSI_INVALID_PARAMETER in the case where a parameter is invalid. */ tsi_result tsi_ssl_client_handshaker_factory_create_handshaker( - tsi_ssl_client_handshaker_factory *self, const char *server_name_indication, - tsi_handshaker **handshaker); + tsi_ssl_client_handshaker_factory* self, const char* server_name_indication, + tsi_handshaker** handshaker); /* Decrements reference count of the handshaker factory. Handshaker factory will * be destroyed once no references exist. */ void tsi_ssl_client_handshaker_factory_unref( - tsi_ssl_client_handshaker_factory *factory); + tsi_ssl_client_handshaker_factory* factory); /* --- tsi_ssl_server_handshaker_factory object --- @@ -130,11 +130,11 @@ typedef struct tsi_ssl_server_handshaker_factory - This method returns TSI_OK on success or TSI_INVALID_PARAMETER in the case where a parameter is invalid. */ tsi_result tsi_create_ssl_server_handshaker_factory( - const tsi_ssl_pem_key_cert_pair *pem_key_cert_pairs, - size_t num_key_cert_pairs, const char *pem_client_root_certs, - int force_client_auth, const char *cipher_suites, - const char **alpn_protocols, uint16_t num_alpn_protocols, - tsi_ssl_server_handshaker_factory **factory); + const tsi_ssl_pem_key_cert_pair* pem_key_cert_pairs, + size_t num_key_cert_pairs, const char* pem_client_root_certs, + int force_client_auth, const char* cipher_suites, + const char** alpn_protocols, uint16_t num_alpn_protocols, + tsi_ssl_server_handshaker_factory** factory); /* Same as tsi_create_ssl_server_handshaker_factory method except uses tsi_client_certificate_request_type to support more ways to handle client @@ -143,11 +143,11 @@ tsi_result tsi_create_ssl_server_handshaker_factory( authenticate with an SSL cert. Note that this option is ignored if pem_client_root_certs is NULL or pem_client_roots_certs_size is 0 */ tsi_result tsi_create_ssl_server_handshaker_factory_ex( - const tsi_ssl_pem_key_cert_pair *pem_key_cert_pairs, - size_t num_key_cert_pairs, const char *pem_client_root_certs, + const tsi_ssl_pem_key_cert_pair* pem_key_cert_pairs, + size_t num_key_cert_pairs, const char* pem_client_root_certs, tsi_client_certificate_request_type client_certificate_request, - const char *cipher_suites, const char **alpn_protocols, - uint16_t num_alpn_protocols, tsi_ssl_server_handshaker_factory **factory); + const char* cipher_suites, const char** alpn_protocols, + uint16_t num_alpn_protocols, tsi_ssl_server_handshaker_factory** factory); /* Creates a server handshaker. - self is the factory from which the handshaker will be created. @@ -156,19 +156,19 @@ tsi_result tsi_create_ssl_server_handshaker_factory_ex( - This method returns TSI_OK on success or TSI_INVALID_PARAMETER in the case where a parameter is invalid. */ tsi_result tsi_ssl_server_handshaker_factory_create_handshaker( - tsi_ssl_server_handshaker_factory *self, tsi_handshaker **handshaker); + tsi_ssl_server_handshaker_factory* self, tsi_handshaker** handshaker); /* Decrements reference count of the handshaker factory. Handshaker factory will * be destroyed once no references exist. */ void tsi_ssl_server_handshaker_factory_unref( - tsi_ssl_server_handshaker_factory *self); + tsi_ssl_server_handshaker_factory* self); /* Util that checks that an ssl peer matches a specific name. Still TODO(jboeuf): - handle mixed case. - handle %encoded chars. - handle public suffix wildchar more strictly (e.g. *.co.uk) */ -int tsi_ssl_peer_matches_name(const tsi_peer *peer, const char *name); +int tsi_ssl_peer_matches_name(const tsi_peer* peer, const char* name); /* --- Testing support. --- @@ -180,7 +180,7 @@ typedef struct tsi_ssl_handshaker_factory tsi_ssl_handshaker_factory; /* Function pointer to handshaker_factory destructor. */ typedef void (*tsi_ssl_handshaker_factory_destructor)( - tsi_ssl_handshaker_factory *factory); + tsi_ssl_handshaker_factory* factory); /* Virtual table for tsi_ssl_handshaker_factory. */ typedef struct { @@ -189,9 +189,9 @@ typedef struct { /* Set destructor of handshaker_factory to new_destructor, returns previous destructor. */ -const tsi_ssl_handshaker_factory_vtable *tsi_ssl_handshaker_factory_swap_vtable( - tsi_ssl_handshaker_factory *factory, - tsi_ssl_handshaker_factory_vtable *new_vtable); +const tsi_ssl_handshaker_factory_vtable* tsi_ssl_handshaker_factory_swap_vtable( + tsi_ssl_handshaker_factory* factory, + tsi_ssl_handshaker_factory_vtable* new_vtable); #ifdef __cplusplus } diff --git a/src/core/tsi/transport_security.cc b/src/core/tsi/transport_security.cc index 21bd8eba78..78e7be249c 100644 --- a/src/core/tsi/transport_security.cc +++ b/src/core/tsi/transport_security.cc @@ -30,7 +30,7 @@ grpc_tracer_flag tsi_tracing_enabled = GRPC_TRACER_INITIALIZER(false, "tsi"); /* --- tsi_result common implementation. --- */ -const char *tsi_result_to_string(tsi_result result) { +const char* tsi_result_to_string(tsi_result result) { switch (result) { case TSI_OK: return "TSI_OK"; @@ -69,11 +69,11 @@ const char *tsi_result_to_string(tsi_result result) { Calls specific implementation after state/input validation. */ -tsi_result tsi_frame_protector_protect(tsi_frame_protector *self, - const unsigned char *unprotected_bytes, - size_t *unprotected_bytes_size, - unsigned char *protected_output_frames, - size_t *protected_output_frames_size) { +tsi_result tsi_frame_protector_protect(tsi_frame_protector* self, + const unsigned char* unprotected_bytes, + size_t* unprotected_bytes_size, + unsigned char* protected_output_frames, + size_t* protected_output_frames_size) { if (self == NULL || self->vtable == NULL || unprotected_bytes == NULL || unprotected_bytes_size == NULL || protected_output_frames == NULL || protected_output_frames_size == NULL) { @@ -86,8 +86,8 @@ tsi_result tsi_frame_protector_protect(tsi_frame_protector *self, } tsi_result tsi_frame_protector_protect_flush( - tsi_frame_protector *self, unsigned char *protected_output_frames, - size_t *protected_output_frames_size, size_t *still_pending_size) { + tsi_frame_protector* self, unsigned char* protected_output_frames, + size_t* protected_output_frames_size, size_t* still_pending_size) { if (self == NULL || self->vtable == NULL || protected_output_frames == NULL || protected_output_frames_size == NULL || still_pending_size == NULL) { return TSI_INVALID_ARGUMENT; @@ -99,9 +99,9 @@ tsi_result tsi_frame_protector_protect_flush( } tsi_result tsi_frame_protector_unprotect( - tsi_frame_protector *self, const unsigned char *protected_frames_bytes, - size_t *protected_frames_bytes_size, unsigned char *unprotected_bytes, - size_t *unprotected_bytes_size) { + tsi_frame_protector* self, const unsigned char* protected_frames_bytes, + size_t* protected_frames_bytes_size, unsigned char* unprotected_bytes, + size_t* unprotected_bytes_size) { if (self == NULL || self->vtable == NULL || protected_frames_bytes == NULL || protected_frames_bytes_size == NULL || unprotected_bytes == NULL || unprotected_bytes_size == NULL) { @@ -113,7 +113,7 @@ tsi_result tsi_frame_protector_unprotect( unprotected_bytes_size); } -void tsi_frame_protector_destroy(tsi_frame_protector *self) { +void tsi_frame_protector_destroy(tsi_frame_protector* self) { if (self == NULL) return; self->vtable->destroy(self); } @@ -122,9 +122,9 @@ void tsi_frame_protector_destroy(tsi_frame_protector *self) { Calls specific implementation after state/input validation. */ -tsi_result tsi_handshaker_get_bytes_to_send_to_peer(tsi_handshaker *self, - unsigned char *bytes, - size_t *bytes_size) { +tsi_result tsi_handshaker_get_bytes_to_send_to_peer(tsi_handshaker* self, + unsigned char* bytes, + size_t* bytes_size) { if (self == NULL || self->vtable == NULL || bytes == NULL || bytes_size == NULL) { return TSI_INVALID_ARGUMENT; @@ -134,9 +134,9 @@ tsi_result tsi_handshaker_get_bytes_to_send_to_peer(tsi_handshaker *self, return self->vtable->get_bytes_to_send_to_peer(self, bytes, bytes_size); } -tsi_result tsi_handshaker_process_bytes_from_peer(tsi_handshaker *self, - const unsigned char *bytes, - size_t *bytes_size) { +tsi_result tsi_handshaker_process_bytes_from_peer(tsi_handshaker* self, + const unsigned char* bytes, + size_t* bytes_size) { if (self == NULL || self->vtable == NULL || bytes == NULL || bytes_size == NULL) { return TSI_INVALID_ARGUMENT; @@ -146,14 +146,14 @@ tsi_result tsi_handshaker_process_bytes_from_peer(tsi_handshaker *self, return self->vtable->process_bytes_from_peer(self, bytes, bytes_size); } -tsi_result tsi_handshaker_get_result(tsi_handshaker *self) { +tsi_result tsi_handshaker_get_result(tsi_handshaker* self) { if (self == NULL || self->vtable == NULL) return TSI_INVALID_ARGUMENT; if (self->frame_protector_created) return TSI_FAILED_PRECONDITION; if (self->vtable->get_result == NULL) return TSI_UNIMPLEMENTED; return self->vtable->get_result(self); } -tsi_result tsi_handshaker_extract_peer(tsi_handshaker *self, tsi_peer *peer) { +tsi_result tsi_handshaker_extract_peer(tsi_handshaker* self, tsi_peer* peer) { if (self == NULL || self->vtable == NULL || peer == NULL) { return TSI_INVALID_ARGUMENT; } @@ -167,8 +167,8 @@ tsi_result tsi_handshaker_extract_peer(tsi_handshaker *self, tsi_peer *peer) { } tsi_result tsi_handshaker_create_frame_protector( - tsi_handshaker *self, size_t *max_protected_frame_size, - tsi_frame_protector **protector) { + tsi_handshaker* self, size_t* max_protected_frame_size, + tsi_frame_protector** protector) { tsi_result result; if (self == NULL || self->vtable == NULL || protector == NULL) { return TSI_INVALID_ARGUMENT; @@ -185,10 +185,10 @@ tsi_result tsi_handshaker_create_frame_protector( } tsi_result tsi_handshaker_next( - tsi_handshaker *self, const unsigned char *received_bytes, - size_t received_bytes_size, const unsigned char **bytes_to_send, - size_t *bytes_to_send_size, tsi_handshaker_result **handshaker_result, - tsi_handshaker_on_next_done_cb cb, void *user_data) { + tsi_handshaker* self, const unsigned char* received_bytes, + size_t received_bytes_size, const unsigned char** bytes_to_send, + size_t* bytes_to_send_size, tsi_handshaker_result** handshaker_result, + tsi_handshaker_on_next_done_cb cb, void* user_data) { if (self == NULL || self->vtable == NULL) return TSI_INVALID_ARGUMENT; if (self->handshaker_result_created) return TSI_FAILED_PRECONDITION; if (self->vtable->next == NULL) return TSI_UNIMPLEMENTED; @@ -197,15 +197,15 @@ tsi_result tsi_handshaker_next( handshaker_result, cb, user_data); } -void tsi_handshaker_destroy(tsi_handshaker *self) { +void tsi_handshaker_destroy(tsi_handshaker* self) { if (self == NULL) return; self->vtable->destroy(self); } /* --- tsi_handshaker_result implementation. --- */ -tsi_result tsi_handshaker_result_extract_peer(const tsi_handshaker_result *self, - tsi_peer *peer) { +tsi_result tsi_handshaker_result_extract_peer(const tsi_handshaker_result* self, + tsi_peer* peer) { if (self == NULL || self->vtable == NULL || peer == NULL) { return TSI_INVALID_ARGUMENT; } @@ -215,8 +215,8 @@ tsi_result tsi_handshaker_result_extract_peer(const tsi_handshaker_result *self, } tsi_result tsi_handshaker_result_create_frame_protector( - const tsi_handshaker_result *self, size_t *max_protected_frame_size, - tsi_frame_protector **protector) { + const tsi_handshaker_result* self, size_t* max_protected_frame_size, + tsi_frame_protector** protector) { if (self == NULL || self->vtable == NULL || protector == NULL) { return TSI_INVALID_ARGUMENT; } @@ -226,8 +226,8 @@ tsi_result tsi_handshaker_result_create_frame_protector( } tsi_result tsi_handshaker_result_get_unused_bytes( - const tsi_handshaker_result *self, const unsigned char **bytes, - size_t *bytes_size) { + const tsi_handshaker_result* self, const unsigned char** bytes, + size_t* bytes_size) { if (self == NULL || self->vtable == NULL || bytes == NULL || bytes_size == NULL) { return TSI_INVALID_ARGUMENT; @@ -236,7 +236,7 @@ tsi_result tsi_handshaker_result_get_unused_bytes( return self->vtable->get_unused_bytes(self, bytes, bytes_size); } -void tsi_handshaker_result_destroy(tsi_handshaker_result *self) { +void tsi_handshaker_result_destroy(tsi_handshaker_result* self) { if (self == NULL) return; self->vtable->destroy(self); } @@ -249,7 +249,7 @@ tsi_peer_property tsi_init_peer_property(void) { return property; } -static void tsi_peer_destroy_list_property(tsi_peer_property *children, +static void tsi_peer_destroy_list_property(tsi_peer_property* children, size_t child_count) { size_t i; for (i = 0; i < child_count; i++) { @@ -258,7 +258,7 @@ static void tsi_peer_destroy_list_property(tsi_peer_property *children, gpr_free(children); } -void tsi_peer_property_destruct(tsi_peer_property *property) { +void tsi_peer_property_destruct(tsi_peer_property* property) { if (property->name != NULL) { gpr_free(property->name); } @@ -268,7 +268,7 @@ void tsi_peer_property_destruct(tsi_peer_property *property) { *property = tsi_init_peer_property(); /* Reset everything to 0. */ } -void tsi_peer_destruct(tsi_peer *self) { +void tsi_peer_destruct(tsi_peer* self) { if (self == NULL) return; if (self->properties != NULL) { tsi_peer_destroy_list_property(self->properties, self->property_count); @@ -278,26 +278,26 @@ void tsi_peer_destruct(tsi_peer *self) { } tsi_result tsi_construct_allocated_string_peer_property( - const char *name, size_t value_length, tsi_peer_property *property) { + const char* name, size_t value_length, tsi_peer_property* property) { *property = tsi_init_peer_property(); if (name != NULL) property->name = gpr_strdup(name); if (value_length > 0) { - property->value.data = (char *)gpr_zalloc(value_length); + property->value.data = (char*)gpr_zalloc(value_length); property->value.length = value_length; } return TSI_OK; } tsi_result tsi_construct_string_peer_property_from_cstring( - const char *name, const char *value, tsi_peer_property *property) { + const char* name, const char* value, tsi_peer_property* property) { return tsi_construct_string_peer_property(name, value, strlen(value), property); } -tsi_result tsi_construct_string_peer_property(const char *name, - const char *value, +tsi_result tsi_construct_string_peer_property(const char* name, + const char* value, size_t value_length, - tsi_peer_property *property) { + tsi_peer_property* property) { tsi_result result = tsi_construct_allocated_string_peer_property( name, value_length, property); if (result != TSI_OK) return result; @@ -307,10 +307,10 @@ tsi_result tsi_construct_string_peer_property(const char *name, return TSI_OK; } -tsi_result tsi_construct_peer(size_t property_count, tsi_peer *peer) { +tsi_result tsi_construct_peer(size_t property_count, tsi_peer* peer) { memset(peer, 0, sizeof(tsi_peer)); if (property_count > 0) { - peer->properties = (tsi_peer_property *)gpr_zalloc( + peer->properties = (tsi_peer_property*)gpr_zalloc( property_count * sizeof(tsi_peer_property)); peer->property_count = property_count; } diff --git a/src/core/tsi/transport_security.h b/src/core/tsi/transport_security.h index 3bba38149c..d639f857fe 100644 --- a/src/core/tsi/transport_security.h +++ b/src/core/tsi/transport_security.h @@ -33,52 +33,52 @@ extern grpc_tracer_flag tsi_tracing_enabled; /* Base for tsi_frame_protector implementations. See transport_security_interface.h for documentation. */ typedef struct { - tsi_result (*protect)(tsi_frame_protector *self, - const unsigned char *unprotected_bytes, - size_t *unprotected_bytes_size, - unsigned char *protected_output_frames, - size_t *protected_output_frames_size); - tsi_result (*protect_flush)(tsi_frame_protector *self, - unsigned char *protected_output_frames, - size_t *protected_output_frames_size, - size_t *still_pending_size); - tsi_result (*unprotect)(tsi_frame_protector *self, - const unsigned char *protected_frames_bytes, - size_t *protected_frames_bytes_size, - unsigned char *unprotected_bytes, - size_t *unprotected_bytes_size); - void (*destroy)(tsi_frame_protector *self); + tsi_result (*protect)(tsi_frame_protector* self, + const unsigned char* unprotected_bytes, + size_t* unprotected_bytes_size, + unsigned char* protected_output_frames, + size_t* protected_output_frames_size); + tsi_result (*protect_flush)(tsi_frame_protector* self, + unsigned char* protected_output_frames, + size_t* protected_output_frames_size, + size_t* still_pending_size); + tsi_result (*unprotect)(tsi_frame_protector* self, + const unsigned char* protected_frames_bytes, + size_t* protected_frames_bytes_size, + unsigned char* unprotected_bytes, + size_t* unprotected_bytes_size); + void (*destroy)(tsi_frame_protector* self); } tsi_frame_protector_vtable; struct tsi_frame_protector { - const tsi_frame_protector_vtable *vtable; + const tsi_frame_protector_vtable* vtable; }; /* Base for tsi_handshaker implementations. See transport_security_interface.h for documentation. */ typedef struct { - tsi_result (*get_bytes_to_send_to_peer)(tsi_handshaker *self, - unsigned char *bytes, - size_t *bytes_size); - tsi_result (*process_bytes_from_peer)(tsi_handshaker *self, - const unsigned char *bytes, - size_t *bytes_size); - tsi_result (*get_result)(tsi_handshaker *self); - tsi_result (*extract_peer)(tsi_handshaker *self, tsi_peer *peer); - tsi_result (*create_frame_protector)(tsi_handshaker *self, - size_t *max_protected_frame_size, - tsi_frame_protector **protector); - void (*destroy)(tsi_handshaker *self); - tsi_result (*next)(tsi_handshaker *self, const unsigned char *received_bytes, + tsi_result (*get_bytes_to_send_to_peer)(tsi_handshaker* self, + unsigned char* bytes, + size_t* bytes_size); + tsi_result (*process_bytes_from_peer)(tsi_handshaker* self, + const unsigned char* bytes, + size_t* bytes_size); + tsi_result (*get_result)(tsi_handshaker* self); + tsi_result (*extract_peer)(tsi_handshaker* self, tsi_peer* peer); + tsi_result (*create_frame_protector)(tsi_handshaker* self, + size_t* max_protected_frame_size, + tsi_frame_protector** protector); + void (*destroy)(tsi_handshaker* self); + tsi_result (*next)(tsi_handshaker* self, const unsigned char* received_bytes, size_t received_bytes_size, - const unsigned char **bytes_to_send, - size_t *bytes_to_send_size, - tsi_handshaker_result **handshaker_result, - tsi_handshaker_on_next_done_cb cb, void *user_data); + const unsigned char** bytes_to_send, + size_t* bytes_to_send_size, + tsi_handshaker_result** handshaker_result, + tsi_handshaker_on_next_done_cb cb, void* user_data); } tsi_handshaker_vtable; struct tsi_handshaker { - const tsi_handshaker_vtable *vtable; + const tsi_handshaker_vtable* vtable; bool frame_protector_created; bool handshaker_result_created; }; @@ -92,39 +92,39 @@ struct tsi_handshaker { needs to compile in other applications, where grpc_exec_ctx is not defined. */ typedef struct { - tsi_result (*extract_peer)(const tsi_handshaker_result *self, tsi_peer *peer); + tsi_result (*extract_peer)(const tsi_handshaker_result* self, tsi_peer* peer); tsi_result (*create_zero_copy_grpc_protector)( - void *exec_ctx, const tsi_handshaker_result *self, - size_t *max_output_protected_frame_size, - tsi_zero_copy_grpc_protector **protector); - tsi_result (*create_frame_protector)(const tsi_handshaker_result *self, - size_t *max_output_protected_frame_size, - tsi_frame_protector **protector); - tsi_result (*get_unused_bytes)(const tsi_handshaker_result *self, - const unsigned char **bytes, - size_t *bytes_size); - void (*destroy)(tsi_handshaker_result *self); + void* exec_ctx, const tsi_handshaker_result* self, + size_t* max_output_protected_frame_size, + tsi_zero_copy_grpc_protector** protector); + tsi_result (*create_frame_protector)(const tsi_handshaker_result* self, + size_t* max_output_protected_frame_size, + tsi_frame_protector** protector); + tsi_result (*get_unused_bytes)(const tsi_handshaker_result* self, + const unsigned char** bytes, + size_t* bytes_size); + void (*destroy)(tsi_handshaker_result* self); } tsi_handshaker_result_vtable; struct tsi_handshaker_result { - const tsi_handshaker_result_vtable *vtable; + const tsi_handshaker_result_vtable* vtable; }; /* Peer and property construction/destruction functions. */ -tsi_result tsi_construct_peer(size_t property_count, tsi_peer *peer); +tsi_result tsi_construct_peer(size_t property_count, tsi_peer* peer); tsi_peer_property tsi_init_peer_property(void); -void tsi_peer_property_destruct(tsi_peer_property *property); -tsi_result tsi_construct_string_peer_property(const char *name, - const char *value, +void tsi_peer_property_destruct(tsi_peer_property* property); +tsi_result tsi_construct_string_peer_property(const char* name, + const char* value, size_t value_length, - tsi_peer_property *property); + tsi_peer_property* property); tsi_result tsi_construct_allocated_string_peer_property( - const char *name, size_t value_length, tsi_peer_property *property); + const char* name, size_t value_length, tsi_peer_property* property); tsi_result tsi_construct_string_peer_property_from_cstring( - const char *name, const char *value, tsi_peer_property *property); + const char* name, const char* value, tsi_peer_property* property); /* Utils. */ -char *tsi_strdup(const char *src); /* Sadly, no strdup in C89. */ +char* tsi_strdup(const char* src); /* Sadly, no strdup in C89. */ #ifdef __cplusplus } diff --git a/src/core/tsi/transport_security_adapter.cc b/src/core/tsi/transport_security_adapter.cc index e399e42758..ec4e7d8cef 100644 --- a/src/core/tsi/transport_security_adapter.cc +++ b/src/core/tsi/transport_security_adapter.cc @@ -30,36 +30,36 @@ typedef struct { tsi_handshaker_result base; - tsi_handshaker *wrapped; - unsigned char *unused_bytes; + tsi_handshaker* wrapped; + unsigned char* unused_bytes; size_t unused_bytes_size; } tsi_adapter_handshaker_result; -static tsi_result adapter_result_extract_peer(const tsi_handshaker_result *self, - tsi_peer *peer) { - tsi_adapter_handshaker_result *impl = (tsi_adapter_handshaker_result *)self; +static tsi_result adapter_result_extract_peer(const tsi_handshaker_result* self, + tsi_peer* peer) { + tsi_adapter_handshaker_result* impl = (tsi_adapter_handshaker_result*)self; return tsi_handshaker_extract_peer(impl->wrapped, peer); } static tsi_result adapter_result_create_frame_protector( - const tsi_handshaker_result *self, size_t *max_output_protected_frame_size, - tsi_frame_protector **protector) { - tsi_adapter_handshaker_result *impl = (tsi_adapter_handshaker_result *)self; + const tsi_handshaker_result* self, size_t* max_output_protected_frame_size, + tsi_frame_protector** protector) { + tsi_adapter_handshaker_result* impl = (tsi_adapter_handshaker_result*)self; return tsi_handshaker_create_frame_protector( impl->wrapped, max_output_protected_frame_size, protector); } static tsi_result adapter_result_get_unused_bytes( - const tsi_handshaker_result *self, const unsigned char **bytes, - size_t *byte_size) { - tsi_adapter_handshaker_result *impl = (tsi_adapter_handshaker_result *)self; + const tsi_handshaker_result* self, const unsigned char** bytes, + size_t* byte_size) { + tsi_adapter_handshaker_result* impl = (tsi_adapter_handshaker_result*)self; *bytes = impl->unused_bytes; *byte_size = impl->unused_bytes_size; return TSI_OK; } -static void adapter_result_destroy(tsi_handshaker_result *self) { - tsi_adapter_handshaker_result *impl = (tsi_adapter_handshaker_result *)self; +static void adapter_result_destroy(tsi_handshaker_result* self) { + tsi_adapter_handshaker_result* impl = (tsi_adapter_handshaker_result*)self; tsi_handshaker_destroy(impl->wrapped); gpr_free(impl->unused_bytes); gpr_free(self); @@ -75,18 +75,18 @@ static const tsi_handshaker_result_vtable result_vtable = { /* Ownership of wrapped tsi_handshaker is transferred to the result object. */ static tsi_result tsi_adapter_create_handshaker_result( - tsi_handshaker *wrapped, const unsigned char *unused_bytes, - size_t unused_bytes_size, tsi_handshaker_result **handshaker_result) { + tsi_handshaker* wrapped, const unsigned char* unused_bytes, + size_t unused_bytes_size, tsi_handshaker_result** handshaker_result) { if (wrapped == NULL || (unused_bytes_size > 0 && unused_bytes == NULL)) { return TSI_INVALID_ARGUMENT; } - tsi_adapter_handshaker_result *impl = - (tsi_adapter_handshaker_result *)gpr_zalloc(sizeof(*impl)); + tsi_adapter_handshaker_result* impl = + (tsi_adapter_handshaker_result*)gpr_zalloc(sizeof(*impl)); impl->base.vtable = &result_vtable; impl->wrapped = wrapped; impl->unused_bytes_size = unused_bytes_size; if (unused_bytes_size > 0) { - impl->unused_bytes = (unsigned char *)gpr_malloc(unused_bytes_size); + impl->unused_bytes = (unsigned char*)gpr_malloc(unused_bytes_size); memcpy(impl->unused_bytes, unused_bytes, unused_bytes_size); } else { impl->unused_bytes = NULL; @@ -99,54 +99,54 @@ static tsi_result tsi_adapter_create_handshaker_result( typedef struct { tsi_handshaker base; - tsi_handshaker *wrapped; - unsigned char *adapter_buffer; + tsi_handshaker* wrapped; + unsigned char* adapter_buffer; size_t adapter_buffer_size; } tsi_adapter_handshaker; -static tsi_result adapter_get_bytes_to_send_to_peer(tsi_handshaker *self, - unsigned char *bytes, - size_t *bytes_size) { +static tsi_result adapter_get_bytes_to_send_to_peer(tsi_handshaker* self, + unsigned char* bytes, + size_t* bytes_size) { return tsi_handshaker_get_bytes_to_send_to_peer( tsi_adapter_handshaker_get_wrapped(self), bytes, bytes_size); } -static tsi_result adapter_process_bytes_from_peer(tsi_handshaker *self, - const unsigned char *bytes, - size_t *bytes_size) { +static tsi_result adapter_process_bytes_from_peer(tsi_handshaker* self, + const unsigned char* bytes, + size_t* bytes_size) { return tsi_handshaker_process_bytes_from_peer( tsi_adapter_handshaker_get_wrapped(self), bytes, bytes_size); } -static tsi_result adapter_get_result(tsi_handshaker *self) { +static tsi_result adapter_get_result(tsi_handshaker* self) { return tsi_handshaker_get_result(tsi_adapter_handshaker_get_wrapped(self)); } -static tsi_result adapter_extract_peer(tsi_handshaker *self, tsi_peer *peer) { +static tsi_result adapter_extract_peer(tsi_handshaker* self, tsi_peer* peer) { return tsi_handshaker_extract_peer(tsi_adapter_handshaker_get_wrapped(self), peer); } static tsi_result adapter_create_frame_protector( - tsi_handshaker *self, size_t *max_protected_frame_size, - tsi_frame_protector **protector) { + tsi_handshaker* self, size_t* max_protected_frame_size, + tsi_frame_protector** protector) { return tsi_handshaker_create_frame_protector( tsi_adapter_handshaker_get_wrapped(self), max_protected_frame_size, protector); } -static void adapter_destroy(tsi_handshaker *self) { - tsi_adapter_handshaker *impl = (tsi_adapter_handshaker *)self; +static void adapter_destroy(tsi_handshaker* self) { + tsi_adapter_handshaker* impl = (tsi_adapter_handshaker*)self; tsi_handshaker_destroy(impl->wrapped); gpr_free(impl->adapter_buffer); gpr_free(self); } static tsi_result adapter_next( - tsi_handshaker *self, const unsigned char *received_bytes, - size_t received_bytes_size, const unsigned char **bytes_to_send, - size_t *bytes_to_send_size, tsi_handshaker_result **handshaker_result, - tsi_handshaker_on_next_done_cb cb, void *user_data) { + tsi_handshaker* self, const unsigned char* received_bytes, + size_t received_bytes_size, const unsigned char** bytes_to_send, + size_t* bytes_to_send_size, tsi_handshaker_result** handshaker_result, + tsi_handshaker_on_next_done_cb cb, void* user_data) { /* Input sanity check. */ if ((received_bytes_size > 0 && received_bytes == NULL) || bytes_to_send == NULL || bytes_to_send_size == NULL || @@ -155,7 +155,7 @@ static tsi_result adapter_next( } /* If there are received bytes, process them first. */ - tsi_adapter_handshaker *impl = (tsi_adapter_handshaker *)self; + tsi_adapter_handshaker* impl = (tsi_adapter_handshaker*)self; tsi_result status = TSI_OK; size_t bytes_consumed = received_bytes_size; if (received_bytes_size > 0) { @@ -173,7 +173,7 @@ static tsi_result adapter_next( offset += to_send_size; if (status == TSI_INCOMPLETE_DATA) { impl->adapter_buffer_size *= 2; - impl->adapter_buffer = (unsigned char *)gpr_realloc( + impl->adapter_buffer = (unsigned char*)gpr_realloc( impl->adapter_buffer, impl->adapter_buffer_size); } } while (status == TSI_INCOMPLETE_DATA); @@ -186,7 +186,7 @@ static tsi_result adapter_next( *handshaker_result = NULL; } else { size_t unused_bytes_size = received_bytes_size - bytes_consumed; - const unsigned char *unused_bytes = + const unsigned char* unused_bytes = unused_bytes_size == 0 ? NULL : received_bytes + bytes_consumed; status = tsi_adapter_create_handshaker_result( impl->wrapped, unused_bytes, unused_bytes_size, handshaker_result); @@ -208,19 +208,19 @@ static const tsi_handshaker_vtable handshaker_vtable = { adapter_next, }; -tsi_handshaker *tsi_create_adapter_handshaker(tsi_handshaker *wrapped) { +tsi_handshaker* tsi_create_adapter_handshaker(tsi_handshaker* wrapped) { GPR_ASSERT(wrapped != NULL); - tsi_adapter_handshaker *impl = - (tsi_adapter_handshaker *)gpr_zalloc(sizeof(*impl)); + tsi_adapter_handshaker* impl = + (tsi_adapter_handshaker*)gpr_zalloc(sizeof(*impl)); impl->base.vtable = &handshaker_vtable; impl->wrapped = wrapped; impl->adapter_buffer_size = TSI_ADAPTER_INITIAL_BUFFER_SIZE; - impl->adapter_buffer = (unsigned char *)gpr_malloc(impl->adapter_buffer_size); + impl->adapter_buffer = (unsigned char*)gpr_malloc(impl->adapter_buffer_size); return &impl->base; } -tsi_handshaker *tsi_adapter_handshaker_get_wrapped(tsi_handshaker *adapter) { +tsi_handshaker* tsi_adapter_handshaker_get_wrapped(tsi_handshaker* adapter) { if (adapter == NULL) return NULL; - tsi_adapter_handshaker *impl = (tsi_adapter_handshaker *)adapter; + tsi_adapter_handshaker* impl = (tsi_adapter_handshaker*)adapter; return impl->wrapped; } diff --git a/src/core/tsi/transport_security_adapter.h b/src/core/tsi/transport_security_adapter.h index 02f33d4c1c..232705f02c 100644 --- a/src/core/tsi/transport_security_adapter.h +++ b/src/core/tsi/transport_security_adapter.h @@ -33,12 +33,12 @@ extern "C" { this tsi adapter handshaker is temporary. It will be removed once TSI has been fully migrated to the new interface. Ownership of input tsi_handshaker is transferred to this new adapter. */ -tsi_handshaker *tsi_create_adapter_handshaker(tsi_handshaker *wrapped); +tsi_handshaker* tsi_create_adapter_handshaker(tsi_handshaker* wrapped); /* Given a tsi adapter handshaker, return the original wrapped handshaker. The adapter still owns the wrapped handshaker which should not be destroyed by the caller. */ -tsi_handshaker *tsi_adapter_handshaker_get_wrapped(tsi_handshaker *adapter); +tsi_handshaker* tsi_adapter_handshaker_get_wrapped(tsi_handshaker* adapter); #ifdef __cplusplus } diff --git a/src/core/tsi/transport_security_grpc.cc b/src/core/tsi/transport_security_grpc.cc index affd995230..3c986475c4 100644 --- a/src/core/tsi/transport_security_grpc.cc +++ b/src/core/tsi/transport_security_grpc.cc @@ -20,9 +20,9 @@ /* This method creates a tsi_zero_copy_grpc_protector object. */ tsi_result tsi_handshaker_result_create_zero_copy_grpc_protector( - grpc_exec_ctx *exec_ctx, const tsi_handshaker_result *self, - size_t *max_output_protected_frame_size, - tsi_zero_copy_grpc_protector **protector) { + grpc_exec_ctx* exec_ctx, const tsi_handshaker_result* self, + size_t* max_output_protected_frame_size, + tsi_zero_copy_grpc_protector** protector) { if (exec_ctx == NULL || self == NULL || self->vtable == NULL || protector == NULL) { return TSI_INVALID_ARGUMENT; @@ -39,9 +39,9 @@ tsi_result tsi_handshaker_result_create_zero_copy_grpc_protector( Calls specific implementation after state/input validation. */ tsi_result tsi_zero_copy_grpc_protector_protect( - grpc_exec_ctx *exec_ctx, tsi_zero_copy_grpc_protector *self, - grpc_slice_buffer *unprotected_slices, - grpc_slice_buffer *protected_slices) { + grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self, + grpc_slice_buffer* unprotected_slices, + grpc_slice_buffer* protected_slices) { if (exec_ctx == NULL || self == NULL || self->vtable == NULL || unprotected_slices == NULL || protected_slices == NULL) { return TSI_INVALID_ARGUMENT; @@ -52,9 +52,9 @@ tsi_result tsi_zero_copy_grpc_protector_protect( } tsi_result tsi_zero_copy_grpc_protector_unprotect( - grpc_exec_ctx *exec_ctx, tsi_zero_copy_grpc_protector *self, - grpc_slice_buffer *protected_slices, - grpc_slice_buffer *unprotected_slices) { + grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self, + grpc_slice_buffer* protected_slices, + grpc_slice_buffer* unprotected_slices) { if (exec_ctx == NULL || self == NULL || self->vtable == NULL || protected_slices == NULL || unprotected_slices == NULL) { return TSI_INVALID_ARGUMENT; @@ -64,8 +64,8 @@ tsi_result tsi_zero_copy_grpc_protector_unprotect( unprotected_slices); } -void tsi_zero_copy_grpc_protector_destroy(grpc_exec_ctx *exec_ctx, - tsi_zero_copy_grpc_protector *self) { +void tsi_zero_copy_grpc_protector_destroy(grpc_exec_ctx* exec_ctx, + tsi_zero_copy_grpc_protector* self) { if (self == NULL) return; self->vtable->destroy(exec_ctx, self); } diff --git a/src/core/tsi/transport_security_grpc.h b/src/core/tsi/transport_security_grpc.h index ca6755c12f..1c54693ec9 100644 --- a/src/core/tsi/transport_security_grpc.h +++ b/src/core/tsi/transport_security_grpc.h @@ -30,9 +30,9 @@ extern "C" { assuming there is no fatal error. The caller is responsible for destroying the protector. */ tsi_result tsi_handshaker_result_create_zero_copy_grpc_protector( - grpc_exec_ctx *exec_ctx, const tsi_handshaker_result *self, - size_t *max_output_protected_frame_size, - tsi_zero_copy_grpc_protector **protector); + grpc_exec_ctx* exec_ctx, const tsi_handshaker_result* self, + size_t* max_output_protected_frame_size, + tsi_zero_copy_grpc_protector** protector); /* -- tsi_zero_copy_grpc_protector object -- */ @@ -43,8 +43,8 @@ tsi_result tsi_handshaker_result_create_zero_copy_grpc_protector( - This method returns TSI_OK in case of success or a specific error code in case of failure. */ tsi_result tsi_zero_copy_grpc_protector_protect( - grpc_exec_ctx *exec_ctx, tsi_zero_copy_grpc_protector *self, - grpc_slice_buffer *unprotected_slices, grpc_slice_buffer *protected_slices); + grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self, + grpc_slice_buffer* unprotected_slices, grpc_slice_buffer* protected_slices); /* Outputs unprotected bytes. - protected_slices is the bytes of protected frames. @@ -53,28 +53,28 @@ tsi_result tsi_zero_copy_grpc_protector_protect( there is not enough data to output in which case unprotected_slices has 0 bytes. */ tsi_result tsi_zero_copy_grpc_protector_unprotect( - grpc_exec_ctx *exec_ctx, tsi_zero_copy_grpc_protector *self, - grpc_slice_buffer *protected_slices, grpc_slice_buffer *unprotected_slices); + grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self, + grpc_slice_buffer* protected_slices, grpc_slice_buffer* unprotected_slices); /* Destroys the tsi_zero_copy_grpc_protector object. */ -void tsi_zero_copy_grpc_protector_destroy(grpc_exec_ctx *exec_ctx, - tsi_zero_copy_grpc_protector *self); +void tsi_zero_copy_grpc_protector_destroy(grpc_exec_ctx* exec_ctx, + tsi_zero_copy_grpc_protector* self); /* Base for tsi_zero_copy_grpc_protector implementations. */ typedef struct { - tsi_result (*protect)(grpc_exec_ctx *exec_ctx, - tsi_zero_copy_grpc_protector *self, - grpc_slice_buffer *unprotected_slices, - grpc_slice_buffer *protected_slices); - tsi_result (*unprotect)(grpc_exec_ctx *exec_ctx, - tsi_zero_copy_grpc_protector *self, - grpc_slice_buffer *protected_slices, - grpc_slice_buffer *unprotected_slices); - void (*destroy)(grpc_exec_ctx *exec_ctx, tsi_zero_copy_grpc_protector *self); + tsi_result (*protect)(grpc_exec_ctx* exec_ctx, + tsi_zero_copy_grpc_protector* self, + grpc_slice_buffer* unprotected_slices, + grpc_slice_buffer* protected_slices); + tsi_result (*unprotect)(grpc_exec_ctx* exec_ctx, + tsi_zero_copy_grpc_protector* self, + grpc_slice_buffer* protected_slices, + grpc_slice_buffer* unprotected_slices); + void (*destroy)(grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self); } tsi_zero_copy_grpc_protector_vtable; struct tsi_zero_copy_grpc_protector { - const tsi_zero_copy_grpc_protector_vtable *vtable; + const tsi_zero_copy_grpc_protector_vtable* vtable; }; #ifdef __cplusplus diff --git a/src/core/tsi/transport_security_interface.h b/src/core/tsi/transport_security_interface.h index 80c426bbdb..54942a6b2a 100644 --- a/src/core/tsi/transport_security_interface.h +++ b/src/core/tsi/transport_security_interface.h @@ -56,7 +56,7 @@ typedef enum { TSI_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY, } tsi_client_certificate_request_type; -const char *tsi_result_to_string(tsi_result result); +const char* tsi_result_to_string(tsi_result result); /* --- tsi tracing --- */ @@ -131,11 +131,11 @@ typedef struct tsi_frame_protector tsi_frame_protector; if (result != TSI_OK) HandleError(result); ------------------------------------------------------------------------ */ -tsi_result tsi_frame_protector_protect(tsi_frame_protector *self, - const unsigned char *unprotected_bytes, - size_t *unprotected_bytes_size, - unsigned char *protected_output_frames, - size_t *protected_output_frames_size); +tsi_result tsi_frame_protector_protect(tsi_frame_protector* self, + const unsigned char* unprotected_bytes, + size_t* unprotected_bytes_size, + unsigned char* protected_output_frames, + size_t* protected_output_frames_size); /* Indicates that we need to flush the bytes buffered in the protector and get the resulting frame. @@ -146,8 +146,8 @@ tsi_result tsi_frame_protector_protect(tsi_frame_protector *self, - still_pending_bytes is an output parameter indicating the number of bytes that still need to be flushed from the protector.*/ tsi_result tsi_frame_protector_protect_flush( - tsi_frame_protector *self, unsigned char *protected_output_frames, - size_t *protected_output_frames_size, size_t *still_pending_size); + tsi_frame_protector* self, unsigned char* protected_output_frames, + size_t* protected_output_frames_size, size_t* still_pending_size); /* Outputs unprotected bytes. - protected_frames_bytes is an input only parameter and points to the @@ -172,12 +172,12 @@ tsi_result tsi_frame_protector_protect_flush( needs to be read before new protected data can be processed in which case protected_frames_size will be set to 0. */ tsi_result tsi_frame_protector_unprotect( - tsi_frame_protector *self, const unsigned char *protected_frames_bytes, - size_t *protected_frames_bytes_size, unsigned char *unprotected_bytes, - size_t *unprotected_bytes_size); + tsi_frame_protector* self, const unsigned char* protected_frames_bytes, + size_t* protected_frames_bytes_size, unsigned char* unprotected_bytes, + size_t* unprotected_bytes_size); /* Destroys the tsi_frame_protector object. */ -void tsi_frame_protector_destroy(tsi_frame_protector *self); +void tsi_frame_protector_destroy(tsi_frame_protector* self); /* --- tsi_peer objects --- @@ -189,20 +189,20 @@ void tsi_frame_protector_destroy(tsi_frame_protector *self); /* Property values may contain NULL characters just like C++ strings. The length field gives the length of the string. */ typedef struct tsi_peer_property { - char *name; + char* name; struct { - char *data; + char* data; size_t length; } value; } tsi_peer_property; typedef struct { - tsi_peer_property *properties; + tsi_peer_property* properties; size_t property_count; } tsi_peer; /* Destructs the tsi_peer object. */ -void tsi_peer_destruct(tsi_peer *self); +void tsi_peer_destruct(tsi_peer* self); /* --- tsi_handshaker_result object --- @@ -215,27 +215,27 @@ typedef struct tsi_handshaker_result tsi_handshaker_result; /* This method extracts tsi peer. It returns TSI_OK assuming there is no fatal error. The caller is responsible for destructing the peer. */ -tsi_result tsi_handshaker_result_extract_peer(const tsi_handshaker_result *self, - tsi_peer *peer); +tsi_result tsi_handshaker_result_extract_peer(const tsi_handshaker_result* self, + tsi_peer* peer); /* This method creates a tsi_frame_protector object. It returns TSI_OK assuming there is no fatal error. The caller is responsible for destroying the protector. */ tsi_result tsi_handshaker_result_create_frame_protector( - const tsi_handshaker_result *self, size_t *max_output_protected_frame_size, - tsi_frame_protector **protector); + const tsi_handshaker_result* self, size_t* max_output_protected_frame_size, + tsi_frame_protector** protector); /* This method returns the unused bytes from the handshake. It returns TSI_OK assuming there is no fatal error. Ownership of the bytes is retained by the handshaker result. As a consequence, the caller must not free the bytes. */ tsi_result tsi_handshaker_result_get_unused_bytes( - const tsi_handshaker_result *self, const unsigned char **bytes, - size_t *byte_size); + const tsi_handshaker_result* self, const unsigned char** bytes, + size_t* byte_size); /* This method releases the tsi_handshaker_handshaker object. After this method is called, no other method can be called on the object. */ -void tsi_handshaker_result_destroy(tsi_handshaker_result *self); +void tsi_handshaker_result_destroy(tsi_handshaker_result* self); /* --- tsi_handshaker objects ---- @@ -346,9 +346,9 @@ typedef struct tsi_handshaker tsi_handshaker; needs to be called again to get all the bytes to send to the peer (there was more data to write than the specified bytes_size). In case of a fatal error in the handshake, another specific error code is returned. */ -tsi_result tsi_handshaker_get_bytes_to_send_to_peer(tsi_handshaker *self, - unsigned char *bytes, - size_t *bytes_size); +tsi_result tsi_handshaker_get_bytes_to_send_to_peer(tsi_handshaker* self, + unsigned char* bytes, + size_t* bytes_size); /* TO BE DEPRECATED SOON. Use tsi_handshaker_next instead. Processes bytes received from the peer. @@ -360,9 +360,9 @@ tsi_result tsi_handshaker_get_bytes_to_send_to_peer(tsi_handshaker *self, needs to be called again to complete the data needed for processing. In case of a fatal error in the handshake, another specific error code is returned. */ -tsi_result tsi_handshaker_process_bytes_from_peer(tsi_handshaker *self, - const unsigned char *bytes, - size_t *bytes_size); +tsi_result tsi_handshaker_process_bytes_from_peer(tsi_handshaker* self, + const unsigned char* bytes, + size_t* bytes_size); /* TO BE DEPRECATED SOON. Gets the result of the handshaker. @@ -370,7 +370,7 @@ tsi_result tsi_handshaker_process_bytes_from_peer(tsi_handshaker *self, errors. Returns TSI_HANDSHAKE_IN_PROGRESS if the handshaker is not done yet but no error has been encountered so far. Otherwise the handshaker failed with the returned error. */ -tsi_result tsi_handshaker_get_result(tsi_handshaker *self); +tsi_result tsi_handshaker_get_result(tsi_handshaker* self); /* TO BE DEPRECATED SOON. Returns 1 if the handshake is in progress, 0 otherwise. */ @@ -382,7 +382,7 @@ tsi_result tsi_handshaker_get_result(tsi_handshaker *self); tsi_handshaker_is_in_progress returns 1, it returns TSI_OK otherwise assuming the handshaker is not in a fatal error state. The caller is responsible for destructing the peer. */ -tsi_result tsi_handshaker_extract_peer(tsi_handshaker *self, tsi_peer *peer); +tsi_result tsi_handshaker_extract_peer(tsi_handshaker* self, tsi_peer* peer); /* TO BE DEPRECATED SOON. Use tsi_handshaker_result_create_frame_protector instead. @@ -403,8 +403,8 @@ tsi_result tsi_handshaker_extract_peer(tsi_handshaker *self, tsi_peer *peer); the handshaker is not in a fatal error state. The caller is responsible for destroying the protector. */ tsi_result tsi_handshaker_create_frame_protector( - tsi_handshaker *self, size_t *max_output_protected_frame_size, - tsi_frame_protector **protector); + tsi_handshaker* self, size_t* max_output_protected_frame_size, + tsi_frame_protector** protector); /* Callback function definition for tsi_handshaker_next. - status indicates the status of the next operation. @@ -414,8 +414,8 @@ tsi_result tsi_handshaker_create_frame_protector( - handshaker_result is the result of handshake when the handshake completes, is NULL otherwise. */ typedef void (*tsi_handshaker_on_next_done_cb)( - tsi_result status, void *user_data, const unsigned char *bytes_to_send, - size_t bytes_to_send_size, tsi_handshaker_result *handshaker_result); + tsi_result status, void* user_data, const unsigned char* bytes_to_send, + size_t bytes_to_send_size, tsi_handshaker_result* handshaker_result); /* Conduct a next step of the handshake. - received_bytes is the buffer containing the data received from the peer. @@ -437,14 +437,14 @@ typedef void (*tsi_handshaker_on_next_done_cb)( the caller should not free bytes_to_send, as the buffer is owned by the tsi_handshaker object. */ tsi_result tsi_handshaker_next( - tsi_handshaker *self, const unsigned char *received_bytes, - size_t received_bytes_size, const unsigned char **bytes_to_send, - size_t *bytes_to_send_size, tsi_handshaker_result **handshaker_result, - tsi_handshaker_on_next_done_cb cb, void *user_data); + tsi_handshaker* self, const unsigned char* received_bytes, + size_t received_bytes_size, const unsigned char** bytes_to_send, + size_t* bytes_to_send_size, tsi_handshaker_result** handshaker_result, + tsi_handshaker_on_next_done_cb cb, void* user_data); /* This method releases the tsi_handshaker object. After this method is called, no other method can be called on the object. */ -void tsi_handshaker_destroy(tsi_handshaker *self); +void tsi_handshaker_destroy(tsi_handshaker* self); /* This method initializes the necessary shared objects used for tsi implementation. */ |