aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlns <matzeton@googlemail.com>2020-06-08 19:16:33 +0200
committerlns <matzeton@googlemail.com>2020-06-08 19:16:33 +0200
commit44b764cff8f8bcfd10751760d4e304f0a19398a2 (patch)
treebdacb7c3dcf546f0ce603818defe3e17e0ba9296
parent6c10fd5e3e563791008a22803a536e7436fee073 (diff)
switched header->body_size to a u32, means that one can encrypt/decrypt 4.2GB with only one header sent
-rw-r--r--client.c3
-rw-r--r--protocol.c16
-rw-r--r--protocol.h8
3 files changed, 14 insertions, 13 deletions
diff --git a/client.c b/client.c
index aa58a92..b15a198 100644
--- a/client.c
+++ b/client.c
@@ -41,7 +41,8 @@ static void send_data(struct connection * const state)
close(data_fd);
data_fd = -1;
} else {
- LOG(NOTICE, "Send DATA: %zd", bytes_read);
+ LOG(NOTICE, "Send DATA: %zd bytes, buffer capacity %0.2f%% unused", bytes_read,
+ 100.0f - ((float)bytes_read / sizeof(buf)) * 100.0f);
}
}
}
diff --git a/protocol.c b/protocol.c
index 8f43584..f73dd77 100644
--- a/protocol.c
+++ b/protocol.c
@@ -161,7 +161,7 @@ static enum recv_return run_protocol_callback(struct connection * const state,
struct protocol_header const * const hdr = (struct protocol_header *)decrypted->pointer;
enum header_types type = (enum header_types)hdr->pdu_type;
size_t min_size = 0;
- uint16_t size = hdr->body_size;
+ uint32_t size = hdr->body_size;
switch (state->state) {
case CONNECTION_INVALID:
@@ -201,25 +201,25 @@ static void header_ntoh(struct protocol_header * const hdr)
{
hdr->magic = ntohl(hdr->magic);
hdr->pdu_type = ntohs(hdr->pdu_type);
- hdr->body_size = ntohs(hdr->body_size);
+ hdr->body_size = ntohl(hdr->body_size);
}
static enum recv_return validate_header(struct protocol_header const * const hdr, size_t buffer_size)
{
enum header_types type = (enum header_types)hdr->pdu_type;
- uint16_t size;
+ uint32_t size;
if (hdr->magic != PROTOCOL_MAGIC) {
return RECV_CORRUPT_PACKET;
}
size = hdr->body_size;
- /* following check does not make sense if sizeof(header.body_size) == 2 and WINDOW_SIZE >= 65535 */
-#if WINDOW_SIZE < 65535
+ /* following check does not make sense if sizeof(header.body_size) == 2 and WINDOW_SIZE >= (65535*2) */
+#if WINDOW_SIZE < (65535*2)
if (size > WINDOW_SIZE) {
return RECV_CORRUPT_PACKET;
}
-#elif WINDOW_SIZE > 65535
+#elif WINDOW_SIZE > (65535*2)
#error "Remember to change that code part if you've changed the type of header.body_size e.g. to uint32_t"
#endif
if (size > buffer_size) {
@@ -416,13 +416,13 @@ enum recv_return process_received(struct connection * const state,
* PDU send functionality *
**************************/
-static void protocol_response(void * const buffer, uint16_t body_and_payload_size, enum header_types type)
+static void protocol_response(void * const buffer, uint32_t body_and_payload_size, enum header_types type)
{
struct protocol_header * const header = (struct protocol_header *)buffer;
header->magic = htonl(PROTOCOL_MAGIC);
header->pdu_type = htons((uint16_t)type);
- header->body_size = htons(body_and_payload_size - sizeof(*header));
+ header->body_size = htonl(body_and_payload_size - sizeof(*header));
}
void protocol_response_client_auth(unsigned char out[CRYPT_PACKET_SIZE_CLIENT_AUTH],
diff --git a/protocol.h b/protocol.h
index 1232fbb..1a7b6b5 100644
--- a/protocol.h
+++ b/protocol.h
@@ -11,8 +11,8 @@
#define PROTOCOL_MAGIC 0xBAADC0DE
#define PROTOCOL_VERSION 0xDEADCAFE
#define PROTOCOL_TIME_STRLEN 32
-#define WINDOW_SIZE 65535
-#if WINDOW_SIZE > 65535
+#define WINDOW_SIZE (65535*2)
+#if WINDOW_SIZE > (65535*2)
#error "Window size is limited by sizeof(header.body_size)"
#endif
@@ -52,8 +52,8 @@ enum header_types {
struct protocol_header {
uint32_t magic;
- uint16_t pdu_type;
- uint16_t body_size;
+ uint32_t pdu_type;
+ uint32_t body_size;
} PROTOCOL_ATTRIBUTES;
struct protocol_client_auth {