aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/command/cmd_funcs.c7
-rw-r--r--src/omemo/crypto.c31
-rw-r--r--src/omemo/crypto.h11
-rw-r--r--src/omemo/omemo.c32
-rw-r--r--src/omemo/omemo.h9
-rw-r--r--tests/unittests/omemo/stub_omemo.c40
-rw-r--r--tests/unittests/test_omemo.c10
-rw-r--r--tests/unittests/test_omemo.h2
8 files changed, 59 insertions, 83 deletions
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index f000ae1e..25d21264 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -73,7 +73,6 @@
#include "plugins/plugins.h"
#include "ui/ui.h"
#include "ui/window_list.h"
-#include "omemo/crypto.h"
#include "xmpp/xmpp.h"
#include "xmpp/connection.h"
#include "xmpp/contact.h"
@@ -4873,8 +4872,8 @@ cmd_sendfile(ProfWin* window, const char* const command, gchar** args)
FILE *tmpfh = fdopen(tmpfd, "wb");
int crypt_res;
- alt_scheme = AES256_GCM_URL_SCHEME;
- alt_fragment = aes256gcm_encrypt_file(fh, tmpfh, file_size(fd), &crypt_res);
+ alt_scheme = OMEMO_AESGCM_URL_SCHEME;
+ alt_fragment = omemo_encrypt_file(fh, tmpfh, file_size(fd), &crypt_res);
if (crypt_res != 0) {
char *msg = "Failed to encrypt file.";
cons_show_error(msg);
@@ -4949,7 +4948,7 @@ cmd_sendfile(ProfWin* window, const char* const command, gchar** args)
out:
#ifdef HAVE_OMEMO
if (alt_fragment != NULL)
- aes256gcm_fragment_free(alt_fragment);
+ omemo_free(alt_fragment);
#endif
if (filename != NULL)
free(filename);
diff --git a/src/omemo/crypto.c b/src/omemo/crypto.c
index 7dd3be10..3be64636 100644
--- a/src/omemo/crypto.c
+++ b/src/omemo/crypto.c
@@ -479,34 +479,3 @@ char *aes256gcm_create_secure_fragment(unsigned char *key, unsigned char *nonce)
return fragment;
}
-
-void aes256gcm_fragment_free(char *fragment) {
- gcry_free(fragment);
-}
-
-char *aes256gcm_encrypt_file(FILE *in, FILE *out, off_t file_size, int *gcry_res) {
- unsigned char *key = gcry_random_bytes_secure(
- AES256_GCM_KEY_LENGTH,
- GCRY_VERY_STRONG_RANDOM);
-
- // Create nonce/IV with random bytes.
- unsigned char nonce[AES256_GCM_NONCE_LENGTH];
- gcry_create_nonce(nonce, AES256_GCM_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);
- fragment = NULL;
- }
-
- gcry_free(key);
-
- return fragment;
-}
-
-//int aes256gcm_decrypt_file(FILE *in, FILE *out, off_t file_size,
-// unsigned char key[], unsigned char nonce[]) {
-// return aes256gcm_crypt_file(in, out, file_size, key, nonce, false);
-//}
diff --git a/src/omemo/crypto.h b/src/omemo/crypto.h
index f24fa163..e8d91ecc 100644
--- a/src/omemo/crypto.h
+++ b/src/omemo/crypto.h
@@ -33,13 +33,13 @@
*
*/
#include <stdio.h>
+#include <stdbool.h>
#include <signal/signal_protocol_types.h>
#define AES128_GCM_KEY_LENGTH 16
#define AES128_GCM_IV_LENGTH 12
#define AES128_GCM_TAG_LENGTH 16
-#define AES256_GCM_URL_SCHEME "aesgcm"
#define AES256_GCM_KEY_LENGTH 32
#define AES256_GCM_NONCE_LENGTH 12
@@ -186,9 +186,8 @@ int aes128gcm_decrypt(unsigned char *plaintext,
size_t ciphertext_len, const unsigned char *const iv, size_t iv_len,
const unsigned char *const key, const unsigned char *const tag);
-char *aes256gcm_encrypt_file(FILE *in, FILE *out, off_t file_size, int *gcry_res);
+int aes256gcm_crypt_file(FILE *in, FILE *out, off_t file_size,
+ unsigned char key[], unsigned char nonce[], bool encrypt);
-//int aes256gcm_decrypt_file(FILE *in, FILE *out, off_t file_size,
-// unsigned char key[], unsigned char nonce[]);
-
-void aes256gcm_fragment_free(char *fragment);
+char *aes256gcm_create_secure_fragment(unsigned char *key,
+ unsigned char *nonce);
diff --git a/src/omemo/omemo.c b/src/omemo/omemo.c
index c6c34ac1..c6f92e46 100644
--- a/src/omemo/omemo.c
+++ b/src/omemo/omemo.c
@@ -1653,3 +1653,35 @@ _generate_signed_pre_key(void)
signal_protocol_signed_pre_key_store_key(omemo_ctx.store, signed_pre_key);
SIGNAL_UNREF(signed_pre_key);
}
+
+
+void omemo_free(void *a) {
+ gcry_free(a);
+}
+
+char *omemo_encrypt_file(FILE *in, FILE *out, off_t file_size, int *gcry_res) {
+ unsigned char *key = gcry_random_bytes_secure(
+ AES256_GCM_KEY_LENGTH,
+ GCRY_VERY_STRONG_RANDOM);
+
+ // Create nonce/IV with random bytes.
+ unsigned char nonce[AES256_GCM_NONCE_LENGTH];
+ gcry_create_nonce(nonce, AES256_GCM_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);
+ fragment = NULL;
+ }
+
+ gcry_free(key);
+
+ return fragment;
+}
+
+//int omemo_decrypt_file(FILE *in, FILE *out, off_t file_size,
+// unsigned char key[], unsigned char nonce[]) {
+// return aes256gcm_crypt_file(in, out, file_size, key, nonce, false);
+//}
diff --git a/src/omemo/omemo.h b/src/omemo/omemo.h
index ecfc42d9..0bddd9cd 100644
--- a/src/omemo/omemo.h
+++ b/src/omemo/omemo.h
@@ -40,6 +40,8 @@
#define OMEMO_ERR_UNSUPPORTED_CRYPTO -10000
#define OMEMO_ERR_GCRYPT -20000
+#define OMEMO_AESGCM_URL_SCHEME "aesgcm"
+
typedef enum {
PROF_OMEMOPOLICY_MANUAL,
PROF_OMEMOPOLICY_AUTOMATIC,
@@ -93,5 +95,8 @@ void omemo_start_muc_sessions(const char* const roomjid);
void omemo_start_device_session(const char* const jid, uint32_t device_id, GList* prekeys, uint32_t signed_prekey_id, const unsigned char* const signed_prekey, size_t signed_prekey_len, const unsigned char* const signature, size_t signature_len, const unsigned char* const identity_key, size_t identity_key_len);
gboolean omemo_loaded(void);
-char* omemo_on_message_send(ProfWin* win, const char* const message, gboolean request_receipt, gboolean muc, const char* const replace_id);
-char* omemo_on_message_recv(const char* const from, uint32_t sid, const unsigned char* const iv, size_t iv_len, GList* keys, const unsigned char* const payload, size_t payload_len, gboolean muc, gboolean* trusted);
+char * omemo_on_message_send(ProfWin *win, const char *const message, gboolean request_receipt, gboolean muc, const char *const replace_id);
+char * omemo_on_message_recv(const char *const from, uint32_t sid, const unsigned char *const iv, size_t iv_len, GList *keys, const unsigned char *const payload, size_t payload_len, gboolean muc, gboolean *trusted);
+
+char *omemo_encrypt_file(FILE *in, FILE *out, off_t file_size, int *gcry_res);
+void omemo_free(void *a);
diff --git a/tests/unittests/omemo/stub_omemo.c b/tests/unittests/omemo/stub_omemo.c
index 448d5a0d..7cca34d5 100644
--- a/tests/unittests/omemo/stub_omemo.c
+++ b/tests/unittests/omemo/stub_omemo.c
@@ -79,31 +79,15 @@ omemo_own_fingerprint(gboolean formatted)
return NULL;
}
-void
-omemo_start_muc_sessions(const char* const roomjid)
-{
-}
-void
-omemo_start_session(const char* const barejid)
-{
-}
-void
-omemo_trust(const char* const jid, const char* const fingerprint_formatted)
-{
-}
-void
-omemo_untrust(const char* const jid, const char* const fingerprint_formatted)
-{
-}
-void
-omemo_devicelist_publish(GList* device_list)
-{
-}
-void
-omemo_publish_crypto_materials(void)
-{
-}
-void
-omemo_start_sessions(void)
-{
-}
+void omemo_start_muc_sessions(const char *const roomjid) {}
+void omemo_start_session(const char *const barejid) {}
+void omemo_trust(const char *const jid, const char *const fingerprint_formatted) {}
+void omemo_untrust(const char *const jid, const char *const fingerprint_formatted) {}
+void omemo_devicelist_publish(GList *device_list) {}
+void omemo_publish_crypto_materials(void) {}
+void omemo_start_sessions(void) {}
+
+char *omemo_encrypt_file(FILE *in, FILE *out, off_t file_size, int *gcry_res) {
+ return NULL;
+};
+void omemo_free(void *a) {};
diff --git a/tests/unittests/test_omemo.c b/tests/unittests/test_omemo.c
deleted file mode 100644
index 4c239e6c..00000000
--- a/tests/unittests/test_omemo.c
+++ /dev/null
@@ -1,10 +0,0 @@
-#include <cmocka.h>
-#include <setjmp.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <stdlib.h>
-
-#include "omemo/crypto.h"
-
-void test_omemo_aesgcm256_encrypt_file(void **state) {}
-void test_omemo_aesgcm256_encrypt_file(void **state) {}
diff --git a/tests/unittests/test_omemo.h b/tests/unittests/test_omemo.h
deleted file mode 100644
index b945121c..00000000
--- a/tests/unittests/test_omemo.h
+++ /dev/null
@@ -1,2 +0,0 @@
-void test_omemo_aesgcm256_encrypt_file(void **state);
-void test_omemo_aesgcm256_decrypt_file(void **state);