From b3280ae276144006d95431f9fe57edd0f8fe95a9 Mon Sep 17 00:00:00 2001 From: Viktor Krikun Date: Tue, 6 Dec 2011 22:16:39 +0000 Subject: [PATCH] Send empty SAS during enrollment and other improvements (refs #25) --- src/zrtp.c | 4 ++++ src/zrtp_iface_cache.c | 4 ++-- src/zrtp_pbx.c | 39 ++++++++++++++++++++++++++++++++++++--- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/zrtp.c b/src/zrtp.c index d5a228150d..d0002a7d3d 100644 --- a/src/zrtp.c +++ b/src/zrtp.c @@ -831,6 +831,10 @@ zrtp_status_t zrtp_profile_check(const zrtp_profile_t* profile, zrtp_global_t* z { uint8_t i = 0; + if (!profile || !zrtp) { + return zrtp_status_bad_param; + } + /* * Fail if the required base components are not present in the profile. */ diff --git a/src/zrtp_iface_cache.c b/src/zrtp_iface_cache.c index b3e1500f3d..ae1b454666 100644 --- a/src/zrtp_iface_cache.c +++ b/src/zrtp_iface_cache.c @@ -912,8 +912,8 @@ void zrtp_def_cache_foreach( zrtp_global_t *global, if (delete) { { char idstr[24*2+1]; - ZRTP_LOG(3,(_ZTU_,"\zrtp_def_cache_foreach() Delete element id=%s index=%u\n", - hex2str(elem->id, sizeof(elem->id), idstr, sizeof(idstr)), + ZRTP_LOG(3,(_ZTU_,"\trtp_def_cache_foreach() Delete element id=%s index=%u\n", + hex2str((const char*)elem->id, sizeof(elem->id), idstr, sizeof(idstr)), elem->_index)); } diff --git a/src/zrtp_pbx.c b/src/zrtp_pbx.c index f0fff569bf..f4f5a906c4 100644 --- a/src/zrtp_pbx.c +++ b/src/zrtp_pbx.c @@ -299,6 +299,10 @@ zrtp_status_t _zrtp_machine_process_while_in_sasrelaying( zrtp_stream_t* stream, /*---------------------------------------------------------------------------*/ zrtp_status_t zrtp_stream_registration_start(zrtp_stream_t* stream, uint32_t ssrc) { + if (!stream) { + return zrtp_status_bad_param; + } + ZRTP_LOG(3,(_ZTU_,"START REGISTRATION STREAM ID=%u mode=%s state=%s.\n", stream->id, zrtp_log_mode2str(stream->mode), zrtp_log_state2str(stream->state))); @@ -313,6 +317,10 @@ zrtp_status_t zrtp_stream_registration_start(zrtp_stream_t* stream, uint32_t ssr zrtp_status_t zrtp_stream_registration_secure(zrtp_stream_t* stream) { + if (!stream) { + return zrtp_status_bad_param; + } + ZRTP_LOG(3,(_ZTU_,"SECURE REGISTRATION STREAM ID=%u mode=%s state=%s.\n", stream->id, zrtp_log_mode2str(stream->mode), zrtp_log_state2str(stream->state))); @@ -331,6 +339,10 @@ zrtp_status_t zrtp_register_with_trusted_mitm(zrtp_stream_t* stream) zrtp_session_t *session = stream->session; zrtp_status_t s = zrtp_status_bad_param; + if (!stream) { + return zrtp_status_bad_param; + } + ZRTP_LOG(3,(_ZTU_,"MARKING this call as REGISTRATION ID=%u\n", stream->id)); if (NULL == stream->zrtp->cb.cache_cb.on_get_mitm) { @@ -399,7 +411,11 @@ zrtp_status_t zrtp_register_with_trusted_mitm(zrtp_stream_t* stream) /*---------------------------------------------------------------------------*/ zrtp_status_t zrtp_link_mitm_calls(zrtp_stream_t *stream1, zrtp_stream_t *stream2) { - ZRTP_LOG(3,(_ZTU_,"Link to MiTM call together stream1=%u stream2=%u.\n", stream1->id, stream2->id)); + if (!stream1 || !stream2) { + return zrtp_status_bad_param; + } + + ZRTP_LOG(3,(_ZTU_,"Link to MiTM call together stream1=%u stream2=%u.\n", stream1->id, stream2->id)); /* This APi is for MiTM endpoints only. */ if (stream1->zrtp->is_mitm) { @@ -452,6 +468,10 @@ zrtp_status_t zrtp_update_remote_options( zrtp_stream_t* stream, zrtp_status_t s = zrtp_status_ok; char buff[256]; + if (!stream) { + return zrtp_status_bad_param; + } + ZRTP_LOG(3,(_ZTU_,"UPDATE REMOTE SAS OPTIONS mode. ID=%u\n", stream->id)); ZRTP_LOG(3,(_ZTU_,"transf_sas=%s scheme=%d.\n", transf_sas_value ? hex2str((const char*)transf_sas_value->buffer, transf_sas_value->length, (char*)buff, sizeof(buff)) : "NULL", @@ -515,6 +535,10 @@ zrtp_status_t zrtp_resolve_mitm_call( zrtp_stream_t* stream1, zrtp_stream_t* non_enrolled = NULL; zrtp_sas_id_t mitm_sas_scheme = ZRTP_COMP_UNKN; zrtp_status_t s = zrtp_status_ok; + + if (!stream1 || !stream2) { + return zrtp_status_bad_param; + } ZRTP_LOG(3,(_ZTU_,"RESOLVE MITM CALL s1=%u, s2=%u...\n", stream1->id, stream2->id)); @@ -605,8 +629,9 @@ zrtp_status_t zrtp_resolve_mitm_call( zrtp_stream_t* stream1, return s; } + /* NOTE: new request from Philip Zimmermann - always send SASRelay to BOTH parties. */ /* If non-enrolled party has SAS scheme different from chosen one - update */ - if (non_enrolled->session->sasscheme->base.id != mitm_sas_scheme) { + /*if (non_enrolled->session->sasscheme->base.id != mitm_sas_scheme) { */ s = zrtp_update_remote_options( non_enrolled, mitm_sas_scheme, NULL, @@ -615,7 +640,7 @@ zrtp_status_t zrtp_resolve_mitm_call( zrtp_stream_t* stream1, if (zrtp_status_ok != s) { return s; } - } + /*}*/ return s; } @@ -623,12 +648,20 @@ zrtp_status_t zrtp_resolve_mitm_call( zrtp_stream_t* stream1, /*---------------------------------------------------------------------------*/ uint8_t zrtp_is_user_enrolled(zrtp_stream_t* stream) { + if (!stream) { + return zrtp_status_bad_param; + } + return ( (stream->session->secrets.cached & ZRTP_BIT_PBX) && (stream->session->secrets.matches & ZRTP_BIT_PBX) ); } zrtp_stream_t* zrtp_choose_one_enrolled(zrtp_stream_t* stream1, zrtp_stream_t* stream2) { + if (!stream1 || !stream2) { + return NULL; + } + if (zrtp_memcmp( stream1->session->zid.buffer, stream2->session->zid.buffer, stream1->session->zid.length) > 0) {