diff --git a/src/zrtp/commit.cc b/src/zrtp/commit.cc index fdd2f82..b12260f 100644 --- a/src/zrtp/commit.cc +++ b/src/zrtp/commit.cc @@ -66,23 +66,15 @@ uvgrtp::zrtp_msg::commit::commit(zrtp_session_t& session): uvgrtp::zrtp_msg::commit::~commit() {} - -rtp_error_t uvgrtp::zrtp_msg::commit::parse_msg(uvgrtp::zrtp_msg::receiver& receiver, zrtp_session_t& session) +rtp_error_t uvgrtp::zrtp_msg::commit::parse_msg(uvgrtp::zrtp_msg::zrtp_commit* commit, zrtp_session_t& session, size_t len) { - ssize_t len = 0; allocate_rframe(sizeof(zrtp_commit)); + zrtp_commit* msg = commit; - if ((len = receiver.get_msg(rframe_, rlen_)) < 0) { - UVG_LOG_ERROR("Failed to get message from ZRTP receiver"); - return RTP_INVALID_VALUE; - } - - zrtp_commit *msg = (zrtp_commit *)rframe_; - - session.sas_type = msg->sas_type; - session.hash_algo = msg->hash_algo; - session.cipher_algo = msg->cipher_algo; - session.auth_tag_type = msg->auth_tag_type; + session.sas_type = msg->sas_type; + session.hash_algo = msg->hash_algo; + session.cipher_algo = msg->cipher_algo; + session.auth_tag_type = msg->auth_tag_type; session.key_agreement_type = msg->key_agreement_type; if (session.key_agreement_type == MULT) @@ -90,7 +82,7 @@ rtp_error_t uvgrtp::zrtp_msg::commit::parse_msg(uvgrtp::zrtp_msg::receiver& rece else memcpy(session.hash_ctx.r_hvi, msg->hvi, 32); - memcpy(&session.hash_ctx.r_mac[2], &msg->mac, 8); + memcpy(&session.hash_ctx.r_mac[2], &msg->mac, 8); memcpy(session.hash_ctx.r_hash[2], msg->hash, 32); if (session.r_msg.commit.second) @@ -99,9 +91,14 @@ rtp_error_t uvgrtp::zrtp_msg::commit::parse_msg(uvgrtp::zrtp_msg::receiver& rece } /* Finally make a copy of the message and save it for later use */ - session.r_msg.commit.first = len; - session.r_msg.commit.second = (uvgrtp::zrtp_msg::zrtp_commit *)new uint8_t[len]; + session.r_msg.commit.first = len; + session.r_msg.commit.second = (uvgrtp::zrtp_msg::zrtp_commit*)new uint8_t[len]; memcpy(session.r_msg.commit.second, msg, len); return RTP_OK; } + +rtp_error_t uvgrtp::zrtp_msg::commit::parse_msg(uvgrtp::zrtp_msg::receiver& receiver, zrtp_session_t& session) +{ + return RTP_OK; +} diff --git a/src/zrtp/commit.hh b/src/zrtp/commit.hh index 06ebc56..746780a 100644 --- a/src/zrtp/commit.hh +++ b/src/zrtp/commit.hh @@ -48,6 +48,7 @@ namespace uvgrtp { ~commit(); /* TODO: */ + virtual rtp_error_t parse_msg(uvgrtp::zrtp_msg::zrtp_commit* commit, zrtp_session_t& session, size_t len); virtual rtp_error_t parse_msg(uvgrtp::zrtp_msg::receiver& receiver, zrtp_session_t& session); }; } diff --git a/src/zrtp/confirm.cc b/src/zrtp/confirm.cc index 5eb07fb..e2cf7da 100644 --- a/src/zrtp/confirm.cc +++ b/src/zrtp/confirm.cc @@ -73,22 +73,23 @@ uvgrtp::zrtp_msg::confirm::~confirm() {} rtp_error_t uvgrtp::zrtp_msg::confirm::parse_msg(uvgrtp::zrtp_msg::receiver& receiver, zrtp_session_t& session) +{ + return RTP_OK; +} + +rtp_error_t uvgrtp::zrtp_msg::confirm::parse_msg(uvgrtp::zrtp_msg::zrtp_confirm* confirm, zrtp_session_t& session) { allocate_rframe(sizeof(zrtp_confirm)); - if (receiver.get_msg(rframe_, rlen_) < 0) { - UVG_LOG_ERROR("Failed to get message from ZRTP receiver"); - return RTP_INVALID_VALUE; - } - - zrtp_confirm* msg = (zrtp_confirm*)rframe_; + zrtp_confirm* msg = confirm; uvgrtp::crypto::aes::cfb* aes_cfb = nullptr; - uvgrtp::crypto::hmac::sha256 *hmac_sha256 = nullptr; + uvgrtp::crypto::hmac::sha256* hmac_sha256 = nullptr; - if (!memcmp(&msg->msg_start.msgblock, (const void *)ZRTP_CONFRIM1, sizeof(uint64_t))) { - aes_cfb = new uvgrtp::crypto::aes::cfb(session.key_ctx.zrtp_keyr, 16, msg->cfb_iv); + if (!memcmp(&msg->msg_start.msgblock, (const void*)ZRTP_CONFRIM1, sizeof(uint64_t))) { + aes_cfb = new uvgrtp::crypto::aes::cfb(session.key_ctx.zrtp_keyr, 16, msg->cfb_iv); hmac_sha256 = new uvgrtp::crypto::hmac::sha256(session.key_ctx.hmac_keyr, 32); - } else { - aes_cfb = new uvgrtp::crypto::aes::cfb(session.key_ctx.zrtp_keyi, 16, msg->cfb_iv); + } + else { + aes_cfb = new uvgrtp::crypto::aes::cfb(session.key_ctx.zrtp_keyi, 16, msg->cfb_iv); hmac_sha256 = new uvgrtp::crypto::hmac::sha256(session.key_ctx.hmac_keyi, 32); } @@ -97,10 +98,10 @@ rtp_error_t uvgrtp::zrtp_msg::confirm::parse_msg(uvgrtp::zrtp_msg::receiver& rec uint64_t cmac = 0; /* Verify confirm_mac before decrypting the message */ - hmac_sha256->update((uint8_t *)msg->hash, 40); + hmac_sha256->update((uint8_t*)msg->hash, 40); hmac_sha256->final(mac_full); - memcpy(&mac, mac_full, sizeof(uint64_t)); + memcpy(&mac, mac_full, sizeof(uint64_t)); memcpy(&cmac, msg->confirm_mac, sizeof(uint64_t)); if (mac != cmac) @@ -113,10 +114,11 @@ rtp_error_t uvgrtp::zrtp_msg::confirm::parse_msg(uvgrtp::zrtp_msg::receiver& rec { delete hmac_sha256; } + UVG_LOG_INFO("mac %u, cmac %u", mac, cmac); return RTP_INVALID_VALUE; } - aes_cfb->decrypt((uint8_t *)msg->hash, (uint8_t *)msg->hash, 40); + aes_cfb->decrypt((uint8_t*)msg->hash, (uint8_t*)msg->hash, 40); /* Finally save the first hash H0 so we can verify other MAC values received. * The first (last) remote mac is not used */ diff --git a/src/zrtp/confirm.hh b/src/zrtp/confirm.hh index 3af3427..3f00c5a 100644 --- a/src/zrtp/confirm.hh +++ b/src/zrtp/confirm.hh @@ -54,6 +54,7 @@ namespace uvgrtp { /* TODO: */ virtual rtp_error_t parse_msg(uvgrtp::zrtp_msg::receiver& receiver, zrtp_session_t& session); + virtual rtp_error_t parse_msg(uvgrtp::zrtp_msg::zrtp_confirm* confirm, zrtp_session_t& session); }; } } diff --git a/src/zrtp/dh_kxchng.cc b/src/zrtp/dh_kxchng.cc index ec1c5b4..55bbaf2 100644 --- a/src/zrtp/dh_kxchng.cc +++ b/src/zrtp/dh_kxchng.cc @@ -95,18 +95,12 @@ uvgrtp::zrtp_msg::dh_key_exchange::dh_key_exchange(struct zrtp_dh *dh): uvgrtp::zrtp_msg::dh_key_exchange::~dh_key_exchange() {} -rtp_error_t uvgrtp::zrtp_msg::dh_key_exchange::parse_msg(uvgrtp::zrtp_msg::receiver& receiver, zrtp_session_t& session) +rtp_error_t uvgrtp::zrtp_msg::dh_key_exchange::parse_msg(uvgrtp::zrtp_msg::zrtp_dh* dh, zrtp_session_t& session, size_t len) { UVG_LOG_DEBUG("Parsing DHPart1/DHPart2 message..."); - ssize_t len = 0; allocate_rframe(sizeof(zrtp_dh)); - if ((len = receiver.get_msg(rframe_, rlen_)) < 0) { - UVG_LOG_ERROR("Failed to get message from ZRTP receiver"); - return RTP_INVALID_VALUE; - } - - zrtp_dh *msg = (zrtp_dh *)rframe_; + zrtp_dh* msg = dh; memcpy(session.dh_ctx.remote_public, msg->pk, 384); @@ -119,7 +113,7 @@ rtp_error_t uvgrtp::zrtp_msg::dh_key_exchange::parse_msg(uvgrtp::zrtp_msg::recei session.secrets.s3 = nullptr; /* Save the MAC value so we can check if later */ - memcpy(&session.hash_ctx.r_mac[1], &msg->mac, 8); + memcpy(&session.hash_ctx.r_mac[1], &msg->mac, 8); memcpy(&session.hash_ctx.r_hash[1], msg->hash, 32); if (session.r_msg.dh.second) @@ -128,9 +122,14 @@ rtp_error_t uvgrtp::zrtp_msg::dh_key_exchange::parse_msg(uvgrtp::zrtp_msg::recei } /* Finally make a copy of the message and save it for later use */ - session.r_msg.dh.first = len; - session.r_msg.dh.second = (uvgrtp::zrtp_msg::zrtp_dh *)new uint8_t[len]; + session.r_msg.dh.first = len; + session.r_msg.dh.second = (uvgrtp::zrtp_msg::zrtp_dh*)new uint8_t[len]; memcpy(session.r_msg.dh.second, msg, len); return RTP_OK; } + +rtp_error_t uvgrtp::zrtp_msg::dh_key_exchange::parse_msg(uvgrtp::zrtp_msg::receiver& receiver, zrtp_session_t& session) +{ + return RTP_OK; +} diff --git a/src/zrtp/dh_kxchng.hh b/src/zrtp/dh_kxchng.hh index a19e394..ef476bb 100644 --- a/src/zrtp/dh_kxchng.hh +++ b/src/zrtp/dh_kxchng.hh @@ -43,6 +43,7 @@ namespace uvgrtp { /* TODO: */ virtual rtp_error_t parse_msg(uvgrtp::zrtp_msg::receiver& receiver, zrtp_session_t& session); + virtual rtp_error_t parse_msg(uvgrtp::zrtp_msg::zrtp_dh* dh, zrtp_session_t& session, size_t len); }; } diff --git a/src/zrtp/hello.cc b/src/zrtp/hello.cc index 1330efa..4616d66 100644 --- a/src/zrtp/hello.cc +++ b/src/zrtp/hello.cc @@ -74,21 +74,16 @@ uvgrtp::zrtp_msg::hello::hello(zrtp_session_t& session): uvgrtp::zrtp_msg::hello::~hello() {} -rtp_error_t uvgrtp::zrtp_msg::hello::parse_msg(uvgrtp::zrtp_msg::receiver& receiver, zrtp_session_t& session) +rtp_error_t uvgrtp::zrtp_msg::hello::parse_msg(uvgrtp::zrtp_msg::zrtp_hello* hello, zrtp_session_t& session, size_t len) { - ssize_t len = 0; allocate_rframe(sizeof(zrtp_hello) + 5 * 8); - if ((len = receiver.get_msg(rframe_, rlen_)) < 0) { - UVG_LOG_ERROR("Failed to get message from ZRTP receiver"); - return RTP_INVALID_VALUE; - } + zrtp_hello* msg = hello; - zrtp_hello *msg = (zrtp_hello *)rframe_; - - if (strncmp((const char *)&msg->version, ZRTP_VERSION, 4)) { + if (strncmp((const char*)&msg->version, ZRTP_VERSION, 4)) { UVG_LOG_ERROR("Invalid ZRTP version!"); session.capabilities.version = 0; - } else { + } + else { session.capabilities.version = 110; } @@ -101,7 +96,7 @@ rtp_error_t uvgrtp::zrtp_msg::hello::parse_msg(uvgrtp::zrtp_msg::receiver& recei session.capabilities.sas_types.push_back(B32); /* Save the MAC value so we can check if later */ - memcpy(&session.hash_ctx.r_mac[3], &msg->mac, 8); + memcpy(&session.hash_ctx.r_mac[3], &msg->mac, 8); memcpy(&session.hash_ctx.r_hash[3], msg->hash, 32); /* Save ZID */ @@ -113,9 +108,14 @@ rtp_error_t uvgrtp::zrtp_msg::hello::parse_msg(uvgrtp::zrtp_msg::receiver& recei } /* Finally make a copy of the message and save it for later use */ - session.r_msg.hello.first = len; - session.r_msg.hello.second = (uvgrtp::zrtp_msg::zrtp_hello *)new uint8_t[len]; + session.r_msg.hello.first = len; + session.r_msg.hello.second = (uvgrtp::zrtp_msg::zrtp_hello*)new uint8_t[len]; memcpy(session.r_msg.hello.second, msg, len); return RTP_OK; } + +rtp_error_t uvgrtp::zrtp_msg::hello::parse_msg(uvgrtp::zrtp_msg::receiver& receiver, zrtp_session_t& session) +{ + return RTP_OK; +} diff --git a/src/zrtp/hello.hh b/src/zrtp/hello.hh index 0acc9c3..a7d1228 100644 --- a/src/zrtp/hello.hh +++ b/src/zrtp/hello.hh @@ -63,6 +63,7 @@ namespace uvgrtp { /* TODO: */ virtual rtp_error_t parse_msg(uvgrtp::zrtp_msg::receiver& receiver, zrtp_session_t& session); + virtual rtp_error_t parse_msg(uvgrtp::zrtp_msg::zrtp_hello* hello, zrtp_session_t& session, size_t len); }; } }