From 28d5816c0686a798406144c740a3f2e8b15322f2 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Fri, 4 Nov 2016 16:26:36 +0100 Subject: [PATCH] Added belle_sip_request_t parameter to im encryption engine callbacks to authorize read/write of SIP headers --- coreapi/bellesip_sal/sal_op_message.c | 7 +++---- coreapi/im_encryption_engine.c | 8 ++++++++ coreapi/im_encryption_engine.h | 12 ++++++++---- coreapi/lime.c | 8 ++++---- coreapi/lime.h | 4 ++-- coreapi/linphonecore.h | 1 + 6 files changed, 26 insertions(+), 14 deletions(-) diff --git a/coreapi/bellesip_sal/sal_op_message.c b/coreapi/bellesip_sal/sal_op_message.c index 48243a548..c1858b4b4 100644 --- a/coreapi/bellesip_sal/sal_op_message.c +++ b/coreapi/bellesip_sal/sal_op_message.c @@ -20,7 +20,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "linphonecore.h" #include "private.h" -#include "lime.h" #include static void process_error( SalOp* op) { @@ -90,7 +89,7 @@ void sal_process_incoming_message(SalOp *op,const belle_sip_request_event_t *eve belle_sip_header_from_t* from_header; belle_sip_header_content_type_t* content_type; belle_sip_response_t* resp; - int errcode=500; + int errcode = 500; belle_sip_header_call_id_t* call_id = belle_sip_message_get_header_by_type(req,belle_sip_header_call_id_t); belle_sip_header_cseq_t* cseq = belle_sip_message_get_header_by_type(req,belle_sip_header_cseq_t); belle_sip_header_date_t *date=belle_sip_message_get_header_by_type(req,belle_sip_header_date_t); @@ -112,7 +111,7 @@ void sal_process_incoming_message(SalOp *op,const belle_sip_request_event_t *eve LinphoneImEncryptionEngineCbs *imee_cbs = linphone_im_encryption_engine_get_callbacks(imee); LinphoneImEncryptionEngineIncomingMessageCb cb_process_incoming_message = linphone_im_encryption_engine_cbs_get_process_incoming_message(imee_cbs); if (cb_process_incoming_message) { - retval = cb_process_incoming_message(lc, belle_sip_header_content_type_get_type(content_type), belle_sip_header_content_type_get_subtype(content_type), + retval = cb_process_incoming_message(lc, req, belle_sip_header_content_type_get_type(content_type), belle_sip_header_content_type_get_subtype(content_type), belle_sip_message_get_body(BELLE_SIP_MESSAGE(req)), (char **)&decryptedMessage); } } @@ -234,7 +233,7 @@ int sal_message_send(SalOp *op, const char *from, const char *to, const char* co LinphoneImEncryptionEngineCbs *imee_cbs = linphone_im_encryption_engine_get_callbacks(imee); LinphoneImEncryptionEngineOutgoingMessageCb cb_process_outgoing_message = linphone_im_encryption_engine_cbs_get_process_outgoing_message(imee_cbs); if (cb_process_outgoing_message) { - retval = cb_process_outgoing_message(lc, peer_uri, content_type, msg, (char **)&multipartEncryptedMessage, &content_length); + retval = cb_process_outgoing_message(lc, req, peer_uri, content_type, msg, (char **)&multipartEncryptedMessage, &content_length); } } if (retval > 0) { diff --git a/coreapi/im_encryption_engine.c b/coreapi/im_encryption_engine.c index 95b019eac..b7b43b676 100644 --- a/coreapi/im_encryption_engine.c +++ b/coreapi/im_encryption_engine.c @@ -59,6 +59,14 @@ void linphone_im_encryption_engine_destory(LinphoneImEncryptionEngine *imee) { ms_free(imee); } +void *linphone_im_encryption_engine_get_user_data(const LinphoneImEncryptionEngine *imee) { + return imee->user_data; +} + +void linphone_im_encryption_engine_set_user_data(LinphoneImEncryptionEngine *imee, void *data) { + imee->user_data = data; +} + LinphoneImEncryptionEngineCbs* linphone_im_encryption_engine_get_callbacks(const LinphoneImEncryptionEngine *imee) { return imee->callbacks; } diff --git a/coreapi/im_encryption_engine.h b/coreapi/im_encryption_engine.h index 17ac20ea3..a5742d721 100644 --- a/coreapi/im_encryption_engine.h +++ b/coreapi/im_encryption_engine.h @@ -26,17 +26,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #define LINPHONE_PUBLIC MS2_PUBLIC #endif -typedef int (*LinphoneImEncryptionEngineIncomingMessageCb)(LinphoneCore* lc, const char* content_type, const char* content_subtype, const char* body, char** decrypted_body); +typedef int (*LinphoneImEncryptionEngineIncomingMessageCb)(LinphoneCore* lc, belle_sip_request_t* req, const char* content_type, const char* content_subtype, const char* body, char** decrypted_body); -typedef int (*LinphoneImEncryptionEngineOutgoingMessageCb)(LinphoneCore* lc, const char *peer_uri, const char* content_type, const char* body, char** crypted_body, size_t* content_length); +typedef int (*LinphoneImEncryptionEngineOutgoingMessageCb)(LinphoneCore* lc, belle_sip_request_t* req, const char *peer_uri, const char* content_type, const char* body, char** crypted_body, size_t* content_length); typedef struct _LinphoneImEncryptionEngineCbs LinphoneImEncryptionEngineCbs; typedef struct _LinphoneImEncryptionEngine LinphoneImEncryptionEngine; -LINPHONE_PUBLIC LinphoneImEncryptionEngineCbs *linphone_im_encryption_engine_cbs_new(void); +LinphoneImEncryptionEngineCbs *linphone_im_encryption_engine_cbs_new(void); -LINPHONE_PUBLIC void linphone_im_encryption_engine_cbs_destory(LinphoneImEncryptionEngineCbs *cbs); +void linphone_im_encryption_engine_cbs_destory(LinphoneImEncryptionEngineCbs *cbs); LINPHONE_PUBLIC void *linphone_im_encryption_engine_cbs_get_user_data(const LinphoneImEncryptionEngineCbs *cbs); @@ -46,6 +46,10 @@ LINPHONE_PUBLIC LinphoneImEncryptionEngine *linphone_im_encryption_engine_new(vo LINPHONE_PUBLIC void linphone_im_encryption_engine_destory(LinphoneImEncryptionEngine *imee); +LINPHONE_PUBLIC void *linphone_im_encryption_engine_get_user_data(const LinphoneImEncryptionEngine *imee); + +LINPHONE_PUBLIC void linphone_im_encryption_engine_set_user_data(LinphoneImEncryptionEngine *imee, void *data); + LINPHONE_PUBLIC LinphoneImEncryptionEngineCbs* linphone_im_encryption_engine_get_callbacks(const LinphoneImEncryptionEngine *imee); LINPHONE_PUBLIC LinphoneImEncryptionEngineIncomingMessageCb linphone_im_encryption_engine_cbs_get_process_incoming_message(LinphoneImEncryptionEngineCbs *cbs); diff --git a/coreapi/lime.c b/coreapi/lime.c index 845f2de98..fd246198e 100644 --- a/coreapi/lime.c +++ b/coreapi/lime.c @@ -818,7 +818,7 @@ static bool_t is_cipher_xml(const char* content_type, const char *content_subtyp && strcmp("cipher.vnd.gsma.rcs-ft-http+xml",content_subtype)==0); } -int lime_im_encryption_engine_process_incoming_message_cb(LinphoneCore* lc, const char* content_type, const char* content_subtype, const char* body, char** decrypted_body) { +int lime_im_encryption_engine_process_incoming_message_cb(LinphoneCore* lc, belle_sip_request_t* req, const char* content_type, const char* content_subtype, const char* body, char** decrypted_body) { int errcode = -1; /* check if we have a xml/cipher message to be decrypted */ if (is_cipher_xml(content_type, content_subtype)) { @@ -875,7 +875,7 @@ int lime_im_encryption_engine_process_incoming_message_cb(LinphoneCore* lc, cons return errcode; } -int lime_im_encryption_engine_process_outgoing_message_cb(LinphoneCore* lc, const char *peer_uri, const char* content_type, const char* body, char** crypted_body, size_t* content_length) { +int lime_im_encryption_engine_process_outgoing_message_cb(LinphoneCore* lc, belle_sip_request_t* req, const char *peer_uri, const char* content_type, const char* body, char** crypted_body, size_t* content_length) { int errcode = -1; /* shall we try to encrypt the message?*/ if ((strcmp(content_type, "xml/cipher") == 0) || ((strcmp(content_type, "application/cipher.vnd.gsma.rcs-ft-http+xml") == 0))) { @@ -952,10 +952,10 @@ int lime_getCachedRcvKeyByZid(xmlDocPtr cacheBuffer, limeKey_t *associatedKey) { int lime_decryptMessage(limeKey_t *key, uint8_t *encryptedMessage, uint32_t messageLength, uint8_t selfZID[12], uint8_t *plainMessage) { return LIME_NOT_ENABLED; } -int lime_im_encryption_engine_process_incoming_message_cb(LinphoneCore* lc, const char* content_type, const char* content_subtype, const char* body, char** decrypted_body) { +int lime_im_encryption_engine_process_incoming_message_cb(LinphoneCore* lc, belle_sip_request_t* req, const char* content_type, const char* content_subtype, const char* body, char** decrypted_body) { return 500; } -int lime_im_encryption_engine_process_outgoing_message_cb(LinphoneCore* lc, const char *peer_uri, const char* content_type, const char* body, char** crypted_body, size_t* content_length) { +int lime_im_encryption_engine_process_outgoing_message_cb(LinphoneCore* lc, belle_sip_request_t* req, const char *peer_uri, const char* content_type, const char* body, char** crypted_body, size_t* content_length) { return 500; } #endif /* HAVE_LIME */ diff --git a/coreapi/lime.h b/coreapi/lime.h index db2ef6994..717f57064 100644 --- a/coreapi/lime.h +++ b/coreapi/lime.h @@ -205,8 +205,8 @@ LINPHONE_PUBLIC char *lime_error_code_to_string(int errorCode); */ LINPHONE_PUBLIC bool_t lime_is_available(void); -int lime_im_encryption_engine_process_incoming_message_cb(LinphoneCore* lc, const char* content_type, const char* content_subtype, const char* body, char** decrypted_body); +int lime_im_encryption_engine_process_incoming_message_cb(LinphoneCore* lc, belle_sip_request_t* req, const char* content_type, const char* content_subtype, const char* body, char** decrypted_body); -int lime_im_encryption_engine_process_outgoing_message_cb(LinphoneCore* lc, const char *peer_uri, const char* content_type, const char* body, char** crypted_body, size_t* content_length); +int lime_im_encryption_engine_process_outgoing_message_cb(LinphoneCore* lc, belle_sip_request_t* req, const char *peer_uri, const char* content_type, const char* body, char** crypted_body, size_t* content_length); #endif /* LIME_H */ diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index fbdff8de4..d51d25cf8 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -19,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #ifndef LINPHONECORE_H #define LINPHONECORE_H +#include "belle-sip/belle-sip.h" #include "ortp/ortp.h" #include "ortp/payloadtype.h" #include "mediastreamer2/mscommon.h"