| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include <aws/io/private/tls_channel_handler_shared.h> |
| 7 |
|
| 8 |
#include <aws/common/clock.h> |
| 9 |
#include <aws/io/tls_channel_handler.h> |
| 10 |
|
| 11 |
#if defined(AWS_USE_SECITEM) |
| 12 |
static bool s_is_use_secitem = true; |
| 13 |
#else |
| 14 |
static bool s_is_use_secitem = false; |
| 15 |
#endif |
| 16 |
bool aws_is_using_secitem(void) { |
| 17 |
return s_is_use_secitem; |
| 18 |
} |
| 19 |
|
| 20 |
static void s_tls_timeout_task_fn(struct aws_channel_task *channel_task, void *arg, enum aws_task_status status) { |
| 21 |
(void)channel_task; |
| 22 |
|
| 23 |
if (status != AWS_TASK_STATUS_RUN_READY) { |
| 24 |
return; |
| 25 |
} |
| 26 |
|
| 27 |
struct aws_tls_channel_handler_shared *tls_handler_shared = arg; |
| 28 |
if (tls_handler_shared->stats.handshake_status != AWS_TLS_NEGOTIATION_STATUS_ONGOING) { |
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
struct aws_channel *channel = tls_handler_shared->handler->slot->channel; |
| 33 |
aws_channel_shutdown(channel, AWS_IO_TLS_NEGOTIATION_TIMEOUT); |
| 34 |
} |
| 35 |
|
| 36 |
void aws_tls_channel_handler_shared_init( |
| 37 |
struct aws_tls_channel_handler_shared *tls_handler_shared, |
| 38 |
struct aws_channel_handler *handler, |
| 39 |
struct aws_tls_connection_options *options) { |
| 40 |
tls_handler_shared->handler = handler; |
| 41 |
tls_handler_shared->tls_timeout_ms = options->timeout_ms; |
| 42 |
aws_crt_statistics_tls_init(&tls_handler_shared->stats); |
| 43 |
aws_channel_task_init(&tls_handler_shared->timeout_task, s_tls_timeout_task_fn, tls_handler_shared, "tls_timeout"); |
| 44 |
} |
| 45 |
|
| 46 |
void aws_tls_channel_handler_shared_clean_up(struct aws_tls_channel_handler_shared *tls_handler_shared) { |
| 47 |
(void)tls_handler_shared; |
| 48 |
} |
| 49 |
|
| 50 |
void aws_on_drive_tls_negotiation(struct aws_tls_channel_handler_shared *tls_handler_shared) { |
| 51 |
if (tls_handler_shared->stats.handshake_status == AWS_TLS_NEGOTIATION_STATUS_NONE) { |
| 52 |
tls_handler_shared->stats.handshake_status = AWS_TLS_NEGOTIATION_STATUS_ONGOING; |
| 53 |
|
| 54 |
uint64_t now = 0; |
| 55 |
aws_channel_current_clock_time(tls_handler_shared->handler->slot->channel, &now); |
| 56 |
tls_handler_shared->stats.handshake_start_ns = now; |
| 57 |
|
| 58 |
if (tls_handler_shared->tls_timeout_ms > 0) { |
| 59 |
uint64_t timeout_ns = |
| 60 |
now + aws_timestamp_convert( |
| 61 |
tls_handler_shared->tls_timeout_ms, AWS_TIMESTAMP_MILLIS, AWS_TIMESTAMP_NANOS, NULL); |
| 62 |
|
| 63 |
aws_channel_schedule_task_future( |
| 64 |
tls_handler_shared->handler->slot->channel, &tls_handler_shared->timeout_task, timeout_ns); |
| 65 |
} |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
void aws_on_tls_negotiation_completed(struct aws_tls_channel_handler_shared *tls_handler_shared, int error_code) { |
| 70 |
tls_handler_shared->stats.handshake_status = |
| 71 |
(error_code == AWS_ERROR_SUCCESS) ? AWS_TLS_NEGOTIATION_STATUS_SUCCESS : AWS_TLS_NEGOTIATION_STATUS_FAILURE; |
| 72 |
aws_channel_current_clock_time( |
| 73 |
tls_handler_shared->handler->slot->channel, &tls_handler_shared->stats.handshake_end_ns); |
| 74 |
} |
| 75 |
|
| 76 |
bool aws_tls_options_buf_is_set(const struct aws_byte_buf *buf) { |
| 77 |
return buf->allocator != NULL; |
| 78 |
} |