From 8ef84da0a05c18eaf52be5296c1f65e6ed98cfcf Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Tue, 6 Mar 2018 16:12:53 +0100 Subject: [PATCH] fix lime to make sure zrtp trust is indexed by scheme, username and domain only instead of full sip uri --- coreapi/lime.c | 22 ++++++++++++++++------ coreapi/linphonecall.c | 10 ++++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/coreapi/lime.c b/coreapi/lime.c index c702db6cc..486895c25 100644 --- a/coreapi/lime.c +++ b/coreapi/lime.c @@ -765,8 +765,9 @@ bool_t linphone_chat_room_lime_available(LinphoneChatRoom *cr) { if (zrtp_cache_db != NULL) { bool_t res; limeURIKeys_t associatedKeys; - char *peer = linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(cr)); - + char *peer = ms_strdup_printf("%s:%s@%s" , linphone_address_get_scheme(linphone_chat_room_get_peer_address(cr)) + , linphone_address_get_username(linphone_chat_room_get_peer_address(cr)) + , linphone_address_get_domain(linphone_chat_room_get_peer_address(cr))); /* retrieve keys associated to the peer URI */ associatedKeys.peerURI = bctbx_strdup(peer); associatedKeys.selfURI = NULL; /* TODO : there is no sender associated to chatroom so check for any local URI available, shall we add sender to chatroom? */ @@ -806,8 +807,13 @@ int lime_im_encryption_engine_process_incoming_message_cb(LinphoneImEncryptionEn errcode = 500; return errcode; } - peerUri = linphone_address_as_string_uri_only(msg->from); - selfUri = linphone_address_as_string_uri_only(msg->to); + peerUri = ms_strdup_printf("%s:%s@%s" , linphone_address_get_scheme(msg->from) + , linphone_address_get_username(msg->from) + , linphone_address_get_domain(msg->from)); + selfUri = ms_strdup_printf("%s:%s@%s" , linphone_address_get_scheme(msg->to) + , linphone_address_get_username(msg->to) + , linphone_address_get_domain(msg->to)); + retval = lime_decryptMultipartMessage(zrtp_cache_db, (uint8_t *)msg->message, selfUri, peerUri, &decrypted_body, &decrypted_content_type, bctbx_time_string_to_sec(lp_config_get_string(lc->config, "sip", "lime_key_validity", "0"))); ms_free(peerUri); @@ -871,8 +877,12 @@ int lime_im_encryption_engine_process_outgoing_message_cb(LinphoneImEncryptionEn } else { int retval; uint8_t *crypted_body = NULL; - char *selfUri = linphone_address_as_string_uri_only(msg->from); - char *peerUri = linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(room)); + char *peerUri = ms_strdup_printf("%s:%s@%s" , linphone_address_get_scheme(linphone_chat_room_get_peer_address(room)) + , linphone_address_get_username(linphone_chat_room_get_peer_address(room)) + , linphone_address_get_domain(linphone_chat_room_get_peer_address(room))); + char *selfUri = ms_strdup_printf("%s:%s@%s" , linphone_address_get_scheme(msg->from) + , linphone_address_get_username(msg->from) + , linphone_address_get_domain(msg->from)); retval = lime_createMultipartMessage(zrtp_cache_db, msg->content_type, (uint8_t *)msg->message, selfUri, peerUri, &crypted_body); if (retval != 0) { /* fail to encrypt */ diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index 20ff1d679..59ada4ad2 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -2760,8 +2760,14 @@ void linphone_call_init_audio_stream(LinphoneCall *call){ /* init zrtp even if we didn't explicitely set it, just in case peer offers it */ if (linphone_core_media_encryption_supported(lc, LinphoneMediaEncryptionZRTP)) { - char *peerUri = linphone_address_as_string_uri_only((call->dir==LinphoneCallIncoming) ? call->log->from : call->log->to); - char *selfUri = linphone_address_as_string_uri_only((call->dir==LinphoneCallIncoming) ? call->log->to : call->log->from); + LinphoneAddress *peerAddr = (call->dir==LinphoneCallIncoming) ? call->log->from : call->log->to; + LinphoneAddress *selfAddr = (call->dir==LinphoneCallIncoming) ? call->log->to : call->log->from; + char *peerUri = ms_strdup_printf("%s:%s@%s" , linphone_address_get_scheme(peerAddr) + , linphone_address_get_username(peerAddr) + , linphone_address_get_domain(peerAddr)); + char *selfUri = ms_strdup_printf("%s:%s@%s" , linphone_address_get_scheme(selfAddr) + , linphone_address_get_username(selfAddr) + , linphone_address_get_domain(selfAddr)); MSZrtpParams params; memset(¶ms,0,sizeof(MSZrtpParams)); /*call->current_params.media_encryption will be set later when zrtp is activated*/