Move file encryption function to public header
This commit is contained in:
@@ -73,7 +73,6 @@
|
|||||||
#include "plugins/plugins.h"
|
#include "plugins/plugins.h"
|
||||||
#include "ui/ui.h"
|
#include "ui/ui.h"
|
||||||
#include "ui/window_list.h"
|
#include "ui/window_list.h"
|
||||||
#include "omemo/crypto.h"
|
|
||||||
#include "xmpp/xmpp.h"
|
#include "xmpp/xmpp.h"
|
||||||
#include "xmpp/connection.h"
|
#include "xmpp/connection.h"
|
||||||
#include "xmpp/contact.h"
|
#include "xmpp/contact.h"
|
||||||
@@ -4873,8 +4872,8 @@ cmd_sendfile(ProfWin* window, const char* const command, gchar** args)
|
|||||||
FILE *tmpfh = fdopen(tmpfd, "wb");
|
FILE *tmpfh = fdopen(tmpfd, "wb");
|
||||||
|
|
||||||
int crypt_res;
|
int crypt_res;
|
||||||
alt_scheme = AES256_GCM_URL_SCHEME;
|
alt_scheme = OMEMO_AESGCM_URL_SCHEME;
|
||||||
alt_fragment = aes256gcm_encrypt_file(fh, tmpfh, file_size(fd), &crypt_res);
|
alt_fragment = omemo_encrypt_file(fh, tmpfh, file_size(fd), &crypt_res);
|
||||||
if (crypt_res != 0) {
|
if (crypt_res != 0) {
|
||||||
char *msg = "Failed to encrypt file.";
|
char *msg = "Failed to encrypt file.";
|
||||||
cons_show_error(msg);
|
cons_show_error(msg);
|
||||||
@@ -4949,7 +4948,7 @@ cmd_sendfile(ProfWin* window, const char* const command, gchar** args)
|
|||||||
out:
|
out:
|
||||||
#ifdef HAVE_OMEMO
|
#ifdef HAVE_OMEMO
|
||||||
if (alt_fragment != NULL)
|
if (alt_fragment != NULL)
|
||||||
aes256gcm_fragment_free(alt_fragment);
|
omemo_free(alt_fragment);
|
||||||
#endif
|
#endif
|
||||||
if (filename != NULL)
|
if (filename != NULL)
|
||||||
free(filename);
|
free(filename);
|
||||||
|
|||||||
@@ -479,34 +479,3 @@ char *aes256gcm_create_secure_fragment(unsigned char *key, unsigned char *nonce)
|
|||||||
|
|
||||||
return fragment;
|
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);
|
|
||||||
//}
|
|
||||||
|
|||||||
@@ -33,13 +33,13 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <signal/signal_protocol_types.h>
|
#include <signal/signal_protocol_types.h>
|
||||||
|
|
||||||
#define AES128_GCM_KEY_LENGTH 16
|
#define AES128_GCM_KEY_LENGTH 16
|
||||||
#define AES128_GCM_IV_LENGTH 12
|
#define AES128_GCM_IV_LENGTH 12
|
||||||
#define AES128_GCM_TAG_LENGTH 16
|
#define AES128_GCM_TAG_LENGTH 16
|
||||||
|
|
||||||
#define AES256_GCM_URL_SCHEME "aesgcm"
|
|
||||||
#define AES256_GCM_KEY_LENGTH 32
|
#define AES256_GCM_KEY_LENGTH 32
|
||||||
#define AES256_GCM_NONCE_LENGTH 12
|
#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,
|
size_t ciphertext_len, const unsigned char *const iv, size_t iv_len,
|
||||||
const unsigned char *const key, const unsigned char *const tag);
|
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,
|
char *aes256gcm_create_secure_fragment(unsigned char *key,
|
||||||
// unsigned char key[], unsigned char nonce[]);
|
unsigned char *nonce);
|
||||||
|
|
||||||
void aes256gcm_fragment_free(char *fragment);
|
|
||||||
|
|||||||
@@ -1653,3 +1653,35 @@ _generate_signed_pre_key(void)
|
|||||||
signal_protocol_signed_pre_key_store_key(omemo_ctx.store, signed_pre_key);
|
signal_protocol_signed_pre_key_store_key(omemo_ctx.store, signed_pre_key);
|
||||||
SIGNAL_UNREF(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);
|
||||||
|
//}
|
||||||
|
|||||||
@@ -40,6 +40,8 @@
|
|||||||
#define OMEMO_ERR_UNSUPPORTED_CRYPTO -10000
|
#define OMEMO_ERR_UNSUPPORTED_CRYPTO -10000
|
||||||
#define OMEMO_ERR_GCRYPT -20000
|
#define OMEMO_ERR_GCRYPT -20000
|
||||||
|
|
||||||
|
#define OMEMO_AESGCM_URL_SCHEME "aesgcm"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
PROF_OMEMOPOLICY_MANUAL,
|
PROF_OMEMOPOLICY_MANUAL,
|
||||||
PROF_OMEMOPOLICY_AUTOMATIC,
|
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);
|
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);
|
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_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_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);
|
||||||
|
|||||||
@@ -79,31 +79,15 @@ omemo_own_fingerprint(gboolean formatted)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void omemo_start_muc_sessions(const char *const roomjid) {}
|
||||||
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
|
void omemo_devicelist_publish(GList *device_list) {}
|
||||||
omemo_start_session(const char* const barejid)
|
void omemo_publish_crypto_materials(void) {}
|
||||||
{
|
void omemo_start_sessions(void) {}
|
||||||
}
|
|
||||||
void
|
char *omemo_encrypt_file(FILE *in, FILE *out, off_t file_size, int *gcry_res) {
|
||||||
omemo_trust(const char* const jid, const char* const fingerprint_formatted)
|
return NULL;
|
||||||
{
|
};
|
||||||
}
|
void omemo_free(void *a) {};
|
||||||
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)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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) {}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
void test_omemo_aesgcm256_encrypt_file(void **state);
|
|
||||||
void test_omemo_aesgcm256_decrypt_file(void **state);
|
|
||||||
Reference in New Issue
Block a user