multiplex: Update ZRTP parse_msg functions
This commit is contained in:
parent
ac7f31713a
commit
b73636dcae
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue