Add I/O error handling and use filenames instead of file descriptors
This commit is contained in:
@@ -35,7 +35,6 @@
|
||||
#include <assert.h>
|
||||
#include <signal/signal_protocol.h>
|
||||
#include <signal/signal_protocol_types.h>
|
||||
#include <gcrypt.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "omemo/omemo.h"
|
||||
@@ -377,7 +376,7 @@ out:
|
||||
return res;
|
||||
}
|
||||
|
||||
int
|
||||
gcry_error_t
|
||||
aes256gcm_crypt_file(FILE* in, FILE* out, off_t file_size,
|
||||
unsigned char key[], unsigned char nonce[], bool encrypt)
|
||||
{
|
||||
@@ -416,7 +415,7 @@ aes256gcm_crypt_file(FILE* in, FILE* out, off_t file_size,
|
||||
off_t bytes_read = 0, bytes_available = 0, read_size = 0;
|
||||
while (bytes_read < file_size) {
|
||||
bytes_available = file_size - bytes_read;
|
||||
if (!bytes_available) {
|
||||
if (!bytes_available || ferror(in) != 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <signal/signal_protocol_types.h>
|
||||
#include <gcrypt.h>
|
||||
|
||||
#define AES128_GCM_KEY_LENGTH 16
|
||||
#define AES128_GCM_IV_LENGTH 12
|
||||
@@ -183,8 +184,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);
|
||||
|
||||
int aes256gcm_crypt_file(FILE* in, FILE* out, off_t file_size,
|
||||
unsigned char key[], unsigned char nonce[], bool encrypt);
|
||||
gcry_error_t aes256gcm_crypt_file(FILE* in, FILE* out, off_t file_size,
|
||||
unsigned char key[], unsigned char nonce[], bool encrypt);
|
||||
|
||||
char* aes256gcm_create_secure_fragment(unsigned char* key,
|
||||
unsigned char* nonce);
|
||||
|
||||
@@ -1713,7 +1713,7 @@ _bytes_from_hex(const char* hex, size_t hex_size,
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
gcry_error_t
|
||||
omemo_decrypt_file(FILE* in, FILE* out, off_t file_size, const char* fragment)
|
||||
{
|
||||
char nonce_hex[AESGCM_URL_NONCE_LEN];
|
||||
@@ -1733,7 +1733,8 @@ omemo_decrypt_file(FILE* in, FILE* out, off_t file_size, const char* fragment)
|
||||
_bytes_from_hex(key_hex, AESGCM_URL_KEY_LEN,
|
||||
key, OMEMO_AESGCM_KEY_LENGTH);
|
||||
|
||||
int crypt_res = aes256gcm_crypt_file(in, out, file_size, key, nonce, false);
|
||||
gcry_error_t crypt_res;
|
||||
crypt_res = aes256gcm_crypt_file(in, out, file_size, key, nonce, false);
|
||||
|
||||
gcry_free(key);
|
||||
|
||||
|
||||
@@ -101,6 +101,5 @@ char* omemo_on_message_send(ProfWin* win, const char* const message, gboolean re
|
||||
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);
|
||||
int omemo_decrypt_file(FILE* in, FILE* out, off_t file_size, const char* fragment);
|
||||
void omemo_free(void* a);
|
||||
gcry_error_t omemo_decrypt_file(FILE* in, FILE* out, off_t file_size, const char* fragment); void omemo_free(void* a);
|
||||
int omemo_parse_aesgcm_url(const char* aesgcm_url, char** https_url, char** fragment);
|
||||
|
||||
Reference in New Issue
Block a user