From a36ee089fef5c24e979616eb74954c306ade00ec Mon Sep 17 00:00:00 2001 From: night0721 Date: Wed, 25 Sep 2024 17:23:09 +0100 Subject: [PATCH] Add sample public keys and more error check --- src/lib/key.c | 6 ++++++ src/zen/ui.c | 16 ++++++++++------ src/zen/zen.c | 13 ++++++++++--- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/lib/key.c b/src/lib/key.c index 2ebca9c..4e27592 100644 --- a/src/lib/key.c +++ b/src/lib/key.c @@ -125,6 +125,12 @@ uint8_t *get_pk_from_ks(char *username) } else if (strcmp(username, "palanix") == 0) { sodium_hex2bin(bin, bin_len, "932aee08aa338108e49f65a5c4f0eb0a08a15bf717fdf8c0ff60eefd0ea014ae", PK_ED25519_SIZE * 2, NULL, NULL, NULL); return bin; + } else if (strcmp(username, "martinmimi") == 0) { + sodium_hex2bin(bin, bin_len, "3d381d61114234bcb0e17d650e0be2e3528b592af665f1c503ba2667c69f2d72", PK_ED25519_SIZE * 2, NULL, NULL, NULL); + return bin; + } else if (strcmp(username, "finnimo") == 0) { + sodium_hex2bin(bin, bin_len, "fdd6710716a01d1421a341017d087945c721151c4d541b46092ec2bbc31d7e8f", PK_ED25519_SIZE * 2, NULL, NULL, NULL); + return bin; } return NULL; } diff --git a/src/zen/ui.c b/src/zen/ui.c index 5690d3c..954d1fc 100644 --- a/src/zen/ui.c +++ b/src/zen/ui.c @@ -24,8 +24,6 @@ int sockfd; static int curs_pos = 0; static char content[MAX_MESSAGE_LENGTH]; -void send_message(); - /* * Free and close everything */ @@ -538,11 +536,17 @@ void send_message() uint8_t from_pk[PK_X25519_SIZE]; uint8_t to_pk[PK_X25519_SIZE]; uint8_t from_sk[SK_X25519_SIZE]; - crypto_sign_ed25519_pk_to_curve25519(from_pk, kp_from->pk.raw); - crypto_sign_ed25519_pk_to_curve25519(to_pk, pk_to); - crypto_sign_ed25519_sk_to_curve25519(from_sk, kp_from->sk); + if (crypto_sign_ed25519_pk_to_curve25519(from_pk, kp_from->pk.raw) != 0 + ) { + error(1, "Error converting ED25519 PK to X25519 PK"); + } + if (crypto_sign_ed25519_pk_to_curve25519(to_pk, pk_to) != 0) { + error(1, "Error converting ED25519 PK to X25519 PK"); + } + if (crypto_sign_ed25519_sk_to_curve25519(from_sk, kp_from->sk) != 0) { + error(1, "Error converting ED25519 SK to X25519 SK"); + } - if (crypto_kx_client_session_keys(shared_key, NULL, from_pk, from_sk, to_pk) != 0) { deinit(); diff --git a/src/zen/zen.c b/src/zen/zen.c index 9ae2ca3..4762ca2 100644 --- a/src/zen/zen.c +++ b/src/zen/zen.c @@ -100,9 +100,16 @@ void *receive_worker(void *arg) uint8_t to_pk[PK_X25519_SIZE]; uint8_t from_pk[PK_X25519_SIZE]; uint8_t to_sk[SK_X25519_SIZE]; - crypto_sign_ed25519_pk_to_curve25519(to_pk, kp_to->pk.raw); - crypto_sign_ed25519_pk_to_curve25519(from_pk, pk_from); - crypto_sign_ed25519_sk_to_curve25519(to_sk, kp_to->sk); + if (crypto_sign_ed25519_pk_to_curve25519(to_pk, kp_to->pk.raw) + != 0) { + error(1, "Error converting ED25519 PK to X25519 PK"); + } + if (crypto_sign_ed25519_pk_to_curve25519(from_pk, pk_from) != 0) { + error(1, "Error converting ED25519 PK to X25519 PK"); + } + if (crypto_sign_ed25519_sk_to_curve25519(to_sk, kp_to->sk) != 0) { + error(1, "Error converting ED25519 SK to X25519 SK"); + } if (crypto_kx_server_session_keys(shared_key, NULL, to_pk, to_sk, from_pk) != 0) {