summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sender.c15
1 files 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 @@
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
16static const unsigned char pubkey[] = 15static 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
27static const unsigned char pp[] = "IJUHZGFDXTZKHJKHGFDHZLUÖDRTFGHHJGHH"; 26static const unsigned char pp[] = "9bf308b7ae027baa46091d980632e27b";
28static const char *logging_host = "localhost"; 27static const char *logging_host = "endpoint-de9XDJ0fH7.gsmk.de";
29static const char *logging_port = "58132"; 28static const char *logging_port = "8238";
30 29
31static struct sockaddr_storage logging_host_address; 30static struct sockaddr_storage logging_host_address;
32static socklen_t logging_host_address_len = 0; 31static socklen_t logging_host_address_len = 0;
33static int logging_socket = -1; 32static int logging_socket = -1;
33typedef uint64_t SessionId_t;
34 34
35enum { SESSION_ID_LENGTH = 8, AES_KEY_LENGTH = 16, GCM_IV_LENGTH = 16, GCM_TAG_LENGTH = 16 }; 35enum { SESSION_ID_LENGTH = 8, AES_KEY_LENGTH = 16, GCM_IV_LENGTH = 16, GCM_TAG_LENGTH = 16 };
36static uint64_t session_id = 0x0123456789abcdef; 36static SessionId_t session_id;
37static uint8_t aes_key[16] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }; 37static uint8_t aes_key[16];
38static mbedtls_gcm_context ctx; 38static mbedtls_gcm_context ctx;
39 39
40void send_udp(int sock, mbedtls_ctr_drbg_context *ctr_drbg, const uint8_t *text, size_t len) { 40void 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;
69printf("%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