diff options
-rw-r--r-- | sender.c | 15 |
1 files changed, 8 insertions, 7 deletions
@@ -12,7 +12,6 @@ | |||
12 | #include "mbedtls/ctr_drbg.h" | 12 | #include "mbedtls/ctr_drbg.h" |
13 | #include "mbedtls/gcm.h" | 13 | #include "mbedtls/gcm.h" |
14 | 14 | ||
15 | |||
16 | static const unsigned char pubkey[] = | 15 | static const unsigned char pubkey[] = |
17 | "-----BEGIN PUBLIC KEY-----\n" | 16 | "-----BEGIN PUBLIC KEY-----\n" |
18 | "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwWlNmLHOOzZpdrfp+EAA\n" | 17 | "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwWlNmLHOOzZpdrfp+EAA\n" |
@@ -24,22 +23,23 @@ static const unsigned char pubkey[] = | |||
24 | "SwIDAQAB \n" | 23 | "SwIDAQAB \n" |
25 | "-----END PUBLIC KEY----- \n"; | 24 | "-----END PUBLIC KEY----- \n"; |
26 | 25 | ||
27 | static const unsigned char pp[] = "IJUHZGFDXTZKHJKHGFDHZLUÖDRTFGHHJGHH"; | 26 | static const unsigned char pp[] = "9bf308b7ae027baa46091d980632e27b"; |
28 | static const char *logging_host = "localhost"; | 27 | static const char *logging_host = "endpoint-de9XDJ0fH7.gsmk.de"; |
29 | static const char *logging_port = "58132"; | 28 | static const char *logging_port = "8238"; |
30 | 29 | ||
31 | static struct sockaddr_storage logging_host_address; | 30 | static struct sockaddr_storage logging_host_address; |
32 | static socklen_t logging_host_address_len = 0; | 31 | static socklen_t logging_host_address_len = 0; |
33 | static int logging_socket = -1; | 32 | static int logging_socket = -1; |
33 | typedef uint64_t SessionId_t; | ||
34 | 34 | ||
35 | enum { SESSION_ID_LENGTH = 8, AES_KEY_LENGTH = 16, GCM_IV_LENGTH = 16, GCM_TAG_LENGTH = 16 }; | 35 | enum { SESSION_ID_LENGTH = 8, AES_KEY_LENGTH = 16, GCM_IV_LENGTH = 16, GCM_TAG_LENGTH = 16 }; |
36 | static uint64_t session_id = 0x0123456789abcdef; | 36 | static SessionId_t session_id; |
37 | static uint8_t aes_key[16] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }; | 37 | static uint8_t aes_key[16]; |
38 | static mbedtls_gcm_context ctx; | 38 | static mbedtls_gcm_context ctx; |
39 | 39 | ||
40 | void send_udp(int sock, mbedtls_ctr_drbg_context *ctr_drbg, const uint8_t *text, size_t len) { | 40 | void send_udp(int sock, mbedtls_ctr_drbg_context *ctr_drbg, const uint8_t *text, size_t len) { |
41 | uint8_t iv[GCM_IV_LENGTH]; | 41 | uint8_t iv[GCM_IV_LENGTH]; |
42 | mbedtls_ctr_drbg_random(ctr_drbg, iv, sizeof(GCM_IV_LENGTH)); | 42 | mbedtls_ctr_drbg_random(ctr_drbg, iv, GCM_IV_LENGTH); |
43 | 43 | ||
44 | const size_t total_length = 1 + SESSION_ID_LENGTH + GCM_IV_LENGTH + GCM_TAG_LENGTH + len; | 44 | const size_t total_length = 1 + SESSION_ID_LENGTH + GCM_IV_LENGTH + GCM_TAG_LENGTH + len; |
45 | uint8_t *output = alloca(total_length); | 45 | uint8_t *output = alloca(total_length); |
@@ -66,6 +66,7 @@ void new_session(int sock, mbedtls_ctr_drbg_context *ctr_drbg) { | |||
66 | mbedtls_pk_context pk; | 66 | mbedtls_pk_context pk; |
67 | mbedtls_pk_init(&pk); | 67 | mbedtls_pk_init(&pk); |
68 | int ret = 0; | 68 | int ret = 0; |
69 | printf("%zd\n", sizeof(pubkey)); | ||
69 | if ((ret = mbedtls_pk_parse_public_key(&pk, pubkey, sizeof(pubkey)) ) != 0 ) | 70 | if ((ret = mbedtls_pk_parse_public_key(&pk, pubkey, sizeof(pubkey)) ) != 0 ) |
70 | errx(-1, "mbedtls_pk_parse_public_keyfile returned -0x%04x\n", -ret ); | 71 | errx(-1, "mbedtls_pk_parse_public_keyfile returned -0x%04x\n", -ret ); |
71 | 72 | ||