From c56df049d6816630a92e11e57ee1e4267913f18e Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sat, 16 Jan 2021 16:32:03 +0100 Subject: Turn SessionId_t in its own type --- sender.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/sender.c b/sender.c index 9cc7a71..69cc527 100644 --- a/sender.c +++ b/sender.c @@ -12,7 +12,6 @@ #include "mbedtls/ctr_drbg.h" #include "mbedtls/gcm.h" - static const unsigned char pubkey[] = "-----BEGIN PUBLIC KEY-----\n" "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwWlNmLHOOzZpdrfp+EAA\n" @@ -24,22 +23,23 @@ static const unsigned char pubkey[] = "SwIDAQAB \n" "-----END PUBLIC KEY----- \n"; -static const unsigned char pp[] = "IJUHZGFDXTZKHJKHGFDHZLUÖDRTFGHHJGHH"; -static const char *logging_host = "localhost"; -static const char *logging_port = "58132"; +static const unsigned char pp[] = "9bf308b7ae027baa46091d980632e27b"; +static const char *logging_host = "endpoint-de9XDJ0fH7.gsmk.de"; +static const char *logging_port = "8238"; static struct sockaddr_storage logging_host_address; static socklen_t logging_host_address_len = 0; static int logging_socket = -1; +typedef uint64_t SessionId_t; enum { SESSION_ID_LENGTH = 8, AES_KEY_LENGTH = 16, GCM_IV_LENGTH = 16, GCM_TAG_LENGTH = 16 }; -static uint64_t session_id = 0x0123456789abcdef; -static uint8_t aes_key[16] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }; +static SessionId_t session_id; +static uint8_t aes_key[16]; static mbedtls_gcm_context ctx; void send_udp(int sock, mbedtls_ctr_drbg_context *ctr_drbg, const uint8_t *text, size_t len) { uint8_t iv[GCM_IV_LENGTH]; - mbedtls_ctr_drbg_random(ctr_drbg, iv, sizeof(GCM_IV_LENGTH)); + mbedtls_ctr_drbg_random(ctr_drbg, iv, GCM_IV_LENGTH); const size_t total_length = 1 + SESSION_ID_LENGTH + GCM_IV_LENGTH + GCM_TAG_LENGTH + len; uint8_t *output = alloca(total_length); @@ -66,6 +66,7 @@ void new_session(int sock, mbedtls_ctr_drbg_context *ctr_drbg) { mbedtls_pk_context pk; mbedtls_pk_init(&pk); int ret = 0; +printf("%zd\n", sizeof(pubkey)); if ((ret = mbedtls_pk_parse_public_key(&pk, pubkey, sizeof(pubkey)) ) != 0 ) errx(-1, "mbedtls_pk_parse_public_keyfile returned -0x%04x\n", -ret ); -- cgit v1.2.3