summaryrefslogtreecommitdiff
path: root/opt/profanity/openssl-omemo-c.patch
diff options
context:
space:
mode:
Diffstat (limited to 'opt/profanity/openssl-omemo-c.patch')
-rw-r--r--opt/profanity/openssl-omemo-c.patch136
1 files changed, 136 insertions, 0 deletions
diff --git a/opt/profanity/openssl-omemo-c.patch b/opt/profanity/openssl-omemo-c.patch
new file mode 100644
index 0000000..45f6ac1
--- /dev/null
+++ b/opt/profanity/openssl-omemo-c.patch
@@ -0,0 +1,136 @@
+--- a/src/omemo/omemo.c
++++ b/src/omemo/omemo.c
+@@ -118,9 +118,9 @@
+
+ prof_add_shutdown_routine(_omemo_close);
+
+- gcry_error_t crypt_res = omemo_crypto_init();
++ int crypt_res = omemo_crypto_init();
+ if (crypt_res != 0) {
+- cons_show("Error initializing OMEMO crypto: %s", gcry_strerror(crypt_res));
++ cons_show("Error initializing OMEMO crypto: %d", crypt_res);
+ }
+
+ pthread_mutexattr_init(&omemo_static_data.attr);
+@@ -300,7 +300,7 @@
+ log_info("Generate long term OMEMO cryptography materials");
+
+ /* Device ID */
+- gcry_randomize(&omemo_ctx.device_id, 4, GCRY_VERY_STRONG_RANDOM);
++ RAND_bytes((unsigned char *)&omemo_ctx.device_id, 4);
+ omemo_ctx.device_id &= 0x7fffffff;
+ g_key_file_set_uint64(omemo_ctx.identity.keyfile, OMEMO_STORE_GROUP_IDENTITY, OMEMO_STORE_KEY_DEVICE_ID, omemo_ctx.device_id);
+ log_info("[OMEMO] device id: %d", omemo_ctx.device_id);
+@@ -708,7 +708,7 @@
+ log_error("[OMEMO] No prekeys found for %s device %d", jid, device_id);
+ goto out;
+ }
+- gcry_randomize(&prekey_index, sizeof(int), GCRY_STRONG_RANDOM);
++ RAND_bytes((unsigned char *)&prekey_index, sizeof(int));
+ prekey_index %= prekeys_len;
+ omemo_key_t* prekey = g_list_nth_data(prekeys, prekey_index);
+
+@@ -780,10 +780,11 @@
+ goto out;
+ }
+ tag_len = AES128_GCM_TAG_LENGTH;
+- tag = gcry_malloc_secure(tag_len);
+- key_tag = gcry_malloc_secure(AES128_GCM_KEY_LENGTH + AES128_GCM_TAG_LENGTH);
++ tag = malloc(tag_len);
++ key_tag = malloc(AES128_GCM_KEY_LENGTH + AES128_GCM_TAG_LENGTH);
+
+- key = gcry_random_bytes_secure(AES128_GCM_KEY_LENGTH + AES128_GCM_IV_LENGTH, GCRY_VERY_STRONG_RANDOM);
++ key = malloc(AES128_GCM_KEY_LENGTH + AES128_GCM_IV_LENGTH);
++ RAND_bytes(key, AES128_GCM_KEY_LENGTH + AES128_GCM_IV_LENGTH);
+ iv = key + AES128_GCM_KEY_LENGTH;
+
+ res = aes128gcm_encrypt(ciphertext, &ciphertext_len, tag, &tag_len, (const unsigned char* const)message, strlen(message), iv, key);
+@@ -999,9 +1000,9 @@
+ omemo_sessions_keyfile_save();
+ g_list_free_full(keys, (GDestroyNotify)omemo_key_free);
+ free(ciphertext);
+- gcry_free(key);
+- gcry_free(tag);
+- gcry_free(key_tag);
++ free(key);
++ free(tag);
++ free(key_tag);
+
+ return id;
+ }
+@@ -1158,7 +1159,7 @@
+ signal_buffer_data(plaintext_key) + AES128_GCM_KEY_LENGTH);
+ signal_buffer_free(plaintext_key);
+ if (res != 0) {
+- log_error("[OMEMO][RECV] cannot decrypt message: %s", gcry_strerror(res));
++ log_error("[OMEMO][RECV] cannot decrypt message, res=%d", res);
+ free(plaintext);
+ *error = OMEMO_ERR_DECRYPT_FAILED;
+ return NULL;
+@@ -2010,29 +2011,28 @@
+ void
+ omemo_free(void* a)
+ {
+- gcry_free(a);
++ free(a);
+ }
+
+ char*
+ omemo_encrypt_file(FILE* in, FILE* out, off_t file_size, int* gcry_res)
+ {
+- unsigned char* key = gcry_random_bytes_secure(
+- OMEMO_AESGCM_KEY_LENGTH,
+- GCRY_VERY_STRONG_RANDOM);
++ unsigned char* key = malloc(OMEMO_AESGCM_KEY_LENGTH);
++ RAND_bytes(key, OMEMO_AESGCM_KEY_LENGTH);
+
+ // Create nonce/IV with random bytes.
+ unsigned char nonce[OMEMO_AESGCM_NONCE_LENGTH];
+- gcry_create_nonce(nonce, OMEMO_AESGCM_NONCE_LENGTH);
++ RAND_bytes(nonce, OMEMO_AESGCM_NONCE_LENGTH);
+
+ char* fragment = aes256gcm_create_secure_fragment(key, nonce);
+ *gcry_res = aes256gcm_crypt_file(in, out, file_size, key, nonce, TRUE);
+
+- if (*gcry_res != GPG_ERR_NO_ERROR) {
+- gcry_free(fragment);
++ if (*gcry_res != 0) {
++ free(fragment);
+ fragment = NULL;
+ }
+
+- gcry_free(key);
++ free(key);
+
+ return fragment;
+ }
+@@ -2063,7 +2063,7 @@
+ }
+ }
+
+-gcry_error_t
++int
+ omemo_decrypt_file(FILE* in, FILE* out, off_t file_size, const char* fragment)
+ {
+ char nonce_hex[AESGCM_URL_NONCE_LEN];
+@@ -2076,17 +2076,17 @@
+ memcpy(key_hex, &(fragment[key_pos]), AESGCM_URL_KEY_LEN);
+
+ unsigned char nonce[OMEMO_AESGCM_NONCE_LENGTH];
+- unsigned char* key = gcry_malloc_secure(OMEMO_AESGCM_KEY_LENGTH);
++ unsigned char* key = malloc(OMEMO_AESGCM_KEY_LENGTH);
+
+ _bytes_from_hex(nonce_hex, AESGCM_URL_NONCE_LEN,
+ nonce, OMEMO_AESGCM_NONCE_LENGTH);
+ _bytes_from_hex(key_hex, AESGCM_URL_KEY_LEN,
+ key, OMEMO_AESGCM_KEY_LENGTH);
+
+- gcry_error_t crypt_res;
++ int crypt_res;
+ crypt_res = aes256gcm_crypt_file(in, out, file_size, key, nonce, FALSE);
+
+- gcry_free(key);
++ free(key);
+
+ return crypt_res;
+ }