From db1c043cd0aa29d10d3c613f091605eb707d8996 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Tue, 21 Feb 2017 10:26:33 +0100 Subject: [PATCH] Improved IM encryption engine API --- coreapi/chat_file_transfer.c | 12 ++++++------ coreapi/lime.c | 12 ++++++------ coreapi/lime.h | 4 ++-- include/linphone/im_encryption_engine.h | 5 +++-- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/coreapi/chat_file_transfer.c b/coreapi/chat_file_transfer.c index 7c83ec52d..064ab52c0 100644 --- a/coreapi/chat_file_transfer.c +++ b/coreapi/chat_file_transfer.c @@ -134,8 +134,8 @@ static int on_send_body(belle_sip_user_body_handler_t *bh, belle_sip_message_t * LinphoneImEncryptionEngineCbs *imee_cbs = linphone_im_encryption_engine_get_callbacks(imee); LinphoneImEncryptionEngineCbsUploadingFileCb cb_process_uploading_file = linphone_im_encryption_engine_cbs_get_process_uploading_file(imee_cbs); if (cb_process_uploading_file) { - char *encrypted_buffer = (char *)ms_malloc0(*size); - retval = cb_process_uploading_file(imee, msg, offset, (const char *)buffer, size, encrypted_buffer); + uint8_t *encrypted_buffer = (uint8_t *)ms_malloc0(*size); + retval = cb_process_uploading_file(imee, msg, offset, (const uint8_t *)buffer, size, encrypted_buffer); if (retval == 0) { memcpy(buffer, encrypted_buffer, *size); } @@ -363,7 +363,7 @@ static void on_recv_body(belle_sip_user_body_handler_t *bh, belle_sip_message_t LinphoneCore *lc = NULL; LinphoneImEncryptionEngine *imee = NULL; int retval = -1; - char *decrypted_buffer = NULL; + uint8_t *decrypted_buffer = NULL; if (!msg->chat_room) { linphone_chat_message_cancel_file_transfer(msg); @@ -385,13 +385,13 @@ static void on_recv_body(belle_sip_user_body_handler_t *bh, belle_sip_message_t return; } - decrypted_buffer = (char *)ms_malloc0(size); + decrypted_buffer = (uint8_t *)ms_malloc0(size); imee = linphone_core_get_im_encryption_engine(lc); if (imee) { LinphoneImEncryptionEngineCbs *imee_cbs = linphone_im_encryption_engine_get_callbacks(imee); LinphoneImEncryptionEngineCbsDownloadingFileCb cb_process_downloading_file = linphone_im_encryption_engine_cbs_get_process_downloading_file(imee_cbs); if (cb_process_downloading_file) { - retval = cb_process_downloading_file(imee, msg, (const char *)buffer, size, decrypted_buffer); + retval = cb_process_downloading_file(imee, msg, offset, (const uint8_t *)buffer, size, decrypted_buffer); if (retval == 0) { memcpy(buffer, decrypted_buffer, size); } @@ -428,7 +428,7 @@ static void on_recv_end(belle_sip_user_body_handler_t *bh, void *data) { LinphoneImEncryptionEngineCbs *imee_cbs = linphone_im_encryption_engine_get_callbacks(imee); LinphoneImEncryptionEngineCbsDownloadingFileCb cb_process_downloading_file = linphone_im_encryption_engine_cbs_get_process_downloading_file(imee_cbs); if (cb_process_downloading_file) { - retval = cb_process_downloading_file(imee, msg, NULL, 0, NULL); + retval = cb_process_downloading_file(imee, msg, 0, NULL, 0, NULL); } } diff --git a/coreapi/lime.c b/coreapi/lime.c index 1ee677307..d8b33e9aa 100644 --- a/coreapi/lime.c +++ b/coreapi/lime.c @@ -1002,7 +1002,7 @@ int lime_im_encryption_engine_process_outgoing_message_cb(LinphoneImEncryptionEn return errcode; } -int lime_im_encryption_engine_process_downloading_file_cb(LinphoneImEncryptionEngine *engine, LinphoneChatMessage *msg, const char *buffer, size_t size, char *decrypted_buffer) { +int lime_im_encryption_engine_process_downloading_file_cb(LinphoneImEncryptionEngine *engine, LinphoneChatMessage *msg, size_t offset, const uint8_t *buffer, size_t size, uint8_t *decrypted_buffer) { if (linphone_content_get_key(msg->file_transfer_information) == NULL) return -1; if (buffer == NULL || size == 0) { @@ -1010,11 +1010,11 @@ int lime_im_encryption_engine_process_downloading_file_cb(LinphoneImEncryptionEn } return lime_decryptFile(linphone_content_get_cryptoContext_address(msg->file_transfer_information), - (unsigned char *)linphone_content_get_key(msg->file_transfer_information), size, decrypted_buffer, + (unsigned char *)linphone_content_get_key(msg->file_transfer_information), size, (char *)decrypted_buffer, (char *)buffer); } -int lime_im_encryption_engine_process_uploading_file_cb(LinphoneImEncryptionEngine *engine, LinphoneChatMessage *msg, size_t offset, const char *buffer, size_t *size, char *encrypted_buffer) { +int lime_im_encryption_engine_process_uploading_file_cb(LinphoneImEncryptionEngine *engine, LinphoneChatMessage *msg, size_t offset, const uint8_t *buffer, size_t *size, uint8_t *encrypted_buffer) { size_t file_size = linphone_content_get_size(msg->file_transfer_information); if (linphone_content_get_key(msg->file_transfer_information) == NULL) return -1; @@ -1030,7 +1030,7 @@ int lime_im_encryption_engine_process_uploading_file_cb(LinphoneImEncryptionEngi return lime_encryptFile(linphone_content_get_cryptoContext_address(msg->file_transfer_information), (unsigned char *)linphone_content_get_key(msg->file_transfer_information), *size, - (char *)buffer, encrypted_buffer); + (char *)buffer, (char *)encrypted_buffer); } bool_t lime_im_encryption_engine_is_file_encryption_enabled_cb(LinphoneImEncryptionEngine *engine, LinphoneChatRoom *room) { @@ -1079,10 +1079,10 @@ int lime_im_encryption_engine_process_incoming_message_cb(LinphoneImEncryptionEn int lime_im_encryption_engine_process_outgoing_message_cb(LinphoneImEncryptionEngine *engine, LinphoneChatRoom *room, LinphoneChatMessage *msg) { return 500; } -int lime_im_encryption_engine_process_downloading_file_cb(LinphoneImEncryptionEngine *engine, LinphoneChatMessage *msg, const char *buffer, size_t size, char *decrypted_buffer) { +int lime_im_encryption_engine_process_downloading_file_cb(LinphoneImEncryptionEngine *engine, LinphoneChatMessage *msg, size_t offset, const uint8_t *buffer, size_t size, uint8_t *decrypted_buffer) { return 500; } -int lime_im_encryption_engine_process_uploading_file_cb(LinphoneImEncryptionEngine *engine, LinphoneChatMessage *msg, size_t offset, const char *buffer, size_t *size, char *encrypted_buffer) { +int lime_im_encryption_engine_process_uploading_file_cb(LinphoneImEncryptionEngine *engine, LinphoneChatMessage *msg, size_t offset, const uint8_t *buffer, size_t *size, uint8_t *encrypted_buffer) { return 500; } bool_t lime_im_encryption_engine_is_file_encryption_enabled_cb(LinphoneImEncryptionEngine *engine, LinphoneChatRoom *room) { diff --git a/coreapi/lime.h b/coreapi/lime.h index 616a74059..67753c038 100644 --- a/coreapi/lime.h +++ b/coreapi/lime.h @@ -208,9 +208,9 @@ int lime_im_encryption_engine_process_incoming_message_cb(LinphoneImEncryptionEn int lime_im_encryption_engine_process_outgoing_message_cb(LinphoneImEncryptionEngine *engine, LinphoneChatRoom *room, LinphoneChatMessage *msg); -int lime_im_encryption_engine_process_downloading_file_cb(LinphoneImEncryptionEngine *engine, LinphoneChatMessage *msg, const char *buffer, size_t size, char *decrypted_buffer); +int lime_im_encryption_engine_process_downloading_file_cb(LinphoneImEncryptionEngine *engine, LinphoneChatMessage *msg, size_t offset, const uint8_t *buffer, size_t size, uint8_t *decrypted_buffer); -int lime_im_encryption_engine_process_uploading_file_cb(LinphoneImEncryptionEngine *engine, LinphoneChatMessage *msg, size_t offset, const char *buffer, size_t *size, char *encrypted_buffer); +int lime_im_encryption_engine_process_uploading_file_cb(LinphoneImEncryptionEngine *engine, LinphoneChatMessage *msg, size_t offset, const uint8_t *buffer, size_t *size, uint8_t *encrypted_buffer); bool_t lime_im_encryption_engine_is_file_encryption_enabled_cb(LinphoneImEncryptionEngine *engine, LinphoneChatRoom *room); diff --git a/include/linphone/im_encryption_engine.h b/include/linphone/im_encryption_engine.h index 7f340d6b0..a0182b9a9 100644 --- a/include/linphone/im_encryption_engine.h +++ b/include/linphone/im_encryption_engine.h @@ -66,12 +66,13 @@ typedef void (*LinphoneImEncryptionEngineCbsGenerateFileTransferKeyCb)(LinphoneI * Callback to decrypt downloading file * @param engine LinphoneImEncryptionEngine object * @param msg LinphoneChatMessage object + * @param offset The current offset of the upload * @param buffer Encrypted data buffer * @param size Size of the encrypted data buffer * @param decrypted_buffer Buffer in which to write the decrypted data * @return -1 if nothing to be done, 0 on success or an integer > 0 for error */ -typedef int (*LinphoneImEncryptionEngineCbsDownloadingFileCb)(LinphoneImEncryptionEngine *engine, LinphoneChatMessage *msg, const char *buffer, size_t size, char *decrypted_buffer); +typedef int (*LinphoneImEncryptionEngineCbsDownloadingFileCb)(LinphoneImEncryptionEngine *engine, LinphoneChatMessage *msg, size_t offset, const uint8_t *buffer, size_t size, uint8_t *decrypted_buffer); /** * Callback to encrypt uploading file @@ -83,7 +84,7 @@ typedef int (*LinphoneImEncryptionEngineCbsDownloadingFileCb)(LinphoneImEncrypti * @param encrypted_buffer Buffer in which to write the encrypted data * @return -1 if nothing to be done, 0 on success or an integer > 0 for error */ -typedef int (*LinphoneImEncryptionEngineCbsUploadingFileCb)(LinphoneImEncryptionEngine *engine, LinphoneChatMessage *msg, size_t offset, const char *buffer, size_t *size, char *encrypted_buffer); +typedef int (*LinphoneImEncryptionEngineCbsUploadingFileCb)(LinphoneImEncryptionEngine *engine, LinphoneChatMessage *msg, size_t offset, const uint8_t *buffer, size_t *size, uint8_t *encrypted_buffer); /** * Acquire a reference to the LinphoneImEncryptionEngineCbs.