From 959dd8d78e986ddbf7716b76618f4d26d0fd55db Mon Sep 17 00:00:00 2001 From: Rui Rafael Date: Mon, 1 Jul 2024 17:18:37 +0100 Subject: [PATCH 1/3] Replaced call to cipher_aes_encrypt_bytes with cipher_aes_encrypt which internally generates random IV --- cipher.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cipher.c b/cipher.c index 6af63c5..fbb3b4b 100644 --- a/cipher.c +++ b/cipher.c @@ -478,7 +478,7 @@ char *cipher_encrypt_private_key(struct private_key *private_key, unsigned char *key_ptext; unsigned char *ctext = NULL; char *key_hex_dst; - char *ctext_hex = NULL; + char *encrypted_base64 = NULL; size_t len, ctext_len, hex_len; if (!private_key->len) @@ -495,12 +495,13 @@ char *cipher_encrypt_private_key(struct private_key *private_key, memcpy(key_ptext + strlen(LP_PKEY_PREFIX) + hex_len, LP_PKEY_SUFFIX, strlen(LP_PKEY_SUFFIX)); + + ctext_len = cipher_aes_encrypt(key_ptext, key, &ctext); - ctext_len = cipher_aes_encrypt_bytes(key_ptext, len, key, key, &ctext); - bytes_to_hex(ctext, &ctext_hex, ctext_len); + encrypted_base64 = cipher_base64(ctext, ctext_len); free(ctext); - return ctext_hex; + return encrypted_base64; } /* From 43ed10148fc703e13bdff234bc9d2283ccd0e57c Mon Sep 17 00:00:00 2001 From: Rui Rafael Date: Tue, 2 Jul 2024 15:23:46 +0100 Subject: [PATCH 2/3] Fixed memory leak --- cipher.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cipher.c b/cipher.c index fbb3b4b..232ed10 100644 --- a/cipher.c +++ b/cipher.c @@ -501,6 +501,8 @@ char *cipher_encrypt_private_key(struct private_key *private_key, encrypted_base64 = cipher_base64(ctext, ctext_len); free(ctext); + free(key_ptext); + return encrypted_base64; } From 5f0ba02d05beff9a4ac0715d1682c6f5c30f3eea Mon Sep 17 00:00:00 2001 From: Rui Rafael Date: Thu, 4 Jul 2024 12:32:25 +0100 Subject: [PATCH 3/3] Adapted description of functionto match new base64 model --- cipher.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cipher.c b/cipher.c index 232ed10..425aa71 100644 --- a/cipher.c +++ b/cipher.c @@ -470,7 +470,7 @@ void cipher_decrypt_private_key(const char *key_hex, } /* - * Encrypt RSA sharing key. Encrypted key is returned as a hex-encoded string. + * Encrypt RSA sharing key. Encrypted key is returned as a base64 string. */ char *cipher_encrypt_private_key(struct private_key *private_key, unsigned const char key[KDF_HASH_LEN])