|
|
|
@ -53,11 +53,12 @@ static int encrypt_and_crc(struct stcp_conn *c, const uint8_t *data, size_t data |
|
|
|
|
|
|
|
|
|
|
|
static int decrypt_and_check(uint8_t *data, size_t len, struct sc_stream_state *stream, size_t *out_len) { |
|
|
|
static int decrypt_and_check(uint8_t *data, size_t len, struct sc_stream_state *stream, size_t *out_len) { |
|
|
|
if (sc_stream_xor(stream, data, len) != SC_OK) { DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "stream_xor failed"); return -1; } |
|
|
|
if (sc_stream_xor(stream, data, len) != SC_OK) { DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "stream_xor failed"); return -1; } |
|
|
|
|
|
|
|
log_dump(DEBUG_LEVEL_ERROR, DEBUG_CATEGORY_DEBUG, "decrypt_and_check AFTER xor", data, len); |
|
|
|
size_t data_len = len - SC_CRC32_SIZE; |
|
|
|
size_t data_len = len - SC_CRC32_SIZE; |
|
|
|
uint32_t recv_crc = ((uint32_t)data[data_len]) | ((uint32_t)data[data_len + 1] << 8) | |
|
|
|
uint32_t recv_crc = ((uint32_t)data[data_len]) | ((uint32_t)data[data_len + 1] << 8) | |
|
|
|
((uint32_t)data[data_len + 2] << 16) | ((uint32_t)data[data_len + 3] << 24); |
|
|
|
((uint32_t)data[data_len + 2] << 16) | ((uint32_t)data[data_len + 3] << 24); |
|
|
|
uint32_t calc_crc = crc32_calc(data, data_len); |
|
|
|
uint32_t calc_crc = crc32_calc(data, data_len); |
|
|
|
if (recv_crc != calc_crc) { DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "CRC mismatch"); return -1; } |
|
|
|
if (recv_crc != calc_crc) { DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "CRC mismatch recv=%08x calc=%08x", recv_crc, calc_crc); return -1; } |
|
|
|
*out_len = data_len; |
|
|
|
*out_len = data_len; |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -155,6 +156,7 @@ static void client_send_handshake(struct stcp_conn *c, const uint8_t *server_pub |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void process_server_response(struct stcp_conn *c) { |
|
|
|
static void process_server_response(struct stcp_conn *c) { |
|
|
|
|
|
|
|
log_dump(DEBUG_LEVEL_ERROR, DEBUG_CATEGORY_DEBUG, "stcp_client process_srv_resp recv_buf", c->recv_buf, c->recv_buf_len); |
|
|
|
if (!c->hs_key_processed) { |
|
|
|
if (!c->hs_key_processed) { |
|
|
|
const uint8_t *salt = c->recv_buf; |
|
|
|
const uint8_t *salt = c->recv_buf; |
|
|
|
const uint8_t *enc_pubkey = salt + SC_PUBKEY_ENC_SALT_SIZE; |
|
|
|
const uint8_t *enc_pubkey = salt + SC_PUBKEY_ENC_SALT_SIZE; |
|
|
|
|