Skip to content

Commit 7d20c51

Browse files
authored
Merge pull request #737 from pabuhler/cherry-pick-pr-773-to-main
Fix srtp_unprotect_rtcp_mki when RTP auth != RTCP
2 parents 74a68ee + d7ed43a commit 7d20c51

File tree

2 files changed

+81
-15
lines changed

2 files changed

+81
-15
lines changed

srtp/srtp.c

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,10 +1744,11 @@ static void srtp_calc_aead_iv(srtp_session_keys_t *session_keys,
17441744
v128_xor(iv, &in, &salt);
17451745
}
17461746

1747-
srtp_err_status_t srtp_get_session_keys_for_packet(
1747+
static srtp_err_status_t srtp_get_session_keys_for_packet(
17481748
srtp_stream_ctx_t *stream,
17491749
const uint8_t *hdr,
17501750
size_t pkt_octet_len,
1751+
size_t tag_len,
17511752
srtp_session_keys_t **session_keys)
17521753
{
17531754
if (!stream->use_mki) {
@@ -1756,15 +1757,6 @@ srtp_err_status_t srtp_get_session_keys_for_packet(
17561757
}
17571758

17581759
size_t mki_start_location = pkt_octet_len;
1759-
size_t tag_len = 0;
1760-
1761-
// Determine the authentication tag size
1762-
if (stream->session_keys[0].rtp_cipher->algorithm == SRTP_AES_GCM_128 ||
1763-
stream->session_keys[0].rtp_cipher->algorithm == SRTP_AES_GCM_256) {
1764-
tag_len = 0;
1765-
} else {
1766-
tag_len = srtp_auth_get_tag_length(stream->session_keys[0].rtp_auth);
1767-
}
17681760

17691761
if (tag_len > mki_start_location) {
17701762
return srtp_err_status_bad_mki;
@@ -1789,6 +1781,46 @@ srtp_err_status_t srtp_get_session_keys_for_packet(
17891781
return srtp_err_status_bad_mki;
17901782
}
17911783

1784+
static srtp_err_status_t srtp_get_session_keys_for_rtp_packet(
1785+
srtp_stream_ctx_t *stream,
1786+
const uint8_t *hdr,
1787+
size_t pkt_octet_len,
1788+
srtp_session_keys_t **session_keys)
1789+
{
1790+
size_t tag_len = 0;
1791+
1792+
// Determine the authentication tag size
1793+
if (stream->session_keys[0].rtp_cipher->algorithm == SRTP_AES_GCM_128 ||
1794+
stream->session_keys[0].rtp_cipher->algorithm == SRTP_AES_GCM_256) {
1795+
tag_len = 0;
1796+
} else {
1797+
tag_len = srtp_auth_get_tag_length(stream->session_keys[0].rtp_auth);
1798+
}
1799+
1800+
return srtp_get_session_keys_for_packet(stream, hdr, pkt_octet_len, tag_len,
1801+
session_keys);
1802+
}
1803+
1804+
static srtp_err_status_t srtp_get_session_keys_for_rtcp_packet(
1805+
srtp_stream_ctx_t *stream,
1806+
const uint8_t *hdr,
1807+
size_t pkt_octet_len,
1808+
srtp_session_keys_t **session_keys)
1809+
{
1810+
size_t tag_len = 0;
1811+
1812+
// Determine the authentication tag size
1813+
if (stream->session_keys[0].rtcp_cipher->algorithm == SRTP_AES_GCM_128 ||
1814+
stream->session_keys[0].rtcp_cipher->algorithm == SRTP_AES_GCM_256) {
1815+
tag_len = 0;
1816+
} else {
1817+
tag_len = srtp_auth_get_tag_length(stream->session_keys[0].rtcp_auth);
1818+
}
1819+
1820+
return srtp_get_session_keys_for_packet(stream, hdr, pkt_octet_len, tag_len,
1821+
session_keys);
1822+
}
1823+
17921824
static srtp_err_status_t srtp_estimate_index(srtp_rdbx_t *rdbx,
17931825
uint32_t roc,
17941826
srtp_xtd_seq_num_t *est,
@@ -2590,8 +2622,8 @@ srtp_err_status_t srtp_unprotect(srtp_t ctx,
25902622
debug_print(mod_srtp, "estimated u_packet index: %016" PRIx64, est);
25912623

25922624
/* Determine if MKI is being used and what session keys should be used */
2593-
status =
2594-
srtp_get_session_keys_for_packet(stream, srtp, srtp_len, &session_keys);
2625+
status = srtp_get_session_keys_for_rtp_packet(stream, srtp, srtp_len,
2626+
&session_keys);
25952627
if (status) {
25962628
return status;
25972629
}
@@ -4267,8 +4299,8 @@ srtp_err_status_t srtp_unprotect_rtcp(srtp_t ctx,
42674299
/*
42684300
* Determine if MKI is being used and what session keys should be used
42694301
*/
4270-
status = srtp_get_session_keys_for_packet(stream, srtcp, srtcp_len,
4271-
&session_keys);
4302+
status = srtp_get_session_keys_for_rtcp_packet(stream, srtcp, srtcp_len,
4303+
&session_keys);
42724304
if (status) {
42734305
return status;
42744306
}

test/srtp_driver.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5122,7 +5122,40 @@ const srtp_policy_t aes_256_hmac_policy = {
51225122
true, /* no mki */
51235123
TEST_MKI_ID_SIZE, /* mki size */
51245124
128, /* replay window size */
5125-
0, /* retransmission not allowed */
5125+
false, /* retransmission not allowed */
5126+
NULL, /* no encrypted extension headers */
5127+
0, /* list of encrypted extension headers is empty */
5128+
NULL
5129+
};
5130+
5131+
const srtp_policy_t aes_256_hmac_32_policy = {
5132+
{ ssrc_any_outbound, 0 }, /* SSRC */
5133+
{
5134+
/* SRTP policy */
5135+
SRTP_AES_ICM_256, /* cipher type */
5136+
SRTP_AES_ICM_256_KEY_LEN_WSALT, /* cipher key length in octets */
5137+
SRTP_HMAC_SHA1, /* authentication func type */
5138+
20, /* auth key length in octets */
5139+
4, /* auth tag length in octets */
5140+
sec_serv_conf_and_auth /* security services flag */
5141+
},
5142+
{
5143+
/* SRTCP policy */
5144+
SRTP_AES_ICM_256, /* cipher type */
5145+
SRTP_AES_ICM_256_KEY_LEN_WSALT, /* cipher key length in octets */
5146+
SRTP_HMAC_SHA1, /* authentication func type */
5147+
20, /* auth key length in octets */
5148+
10, /* auth tag length in octets.
5149+
80 bits per RFC 3711. */
5150+
sec_serv_conf_and_auth /* security services flag */
5151+
},
5152+
NULL,
5153+
(srtp_master_key_t **)test_256_keys,
5154+
2, /* indicates the number of Master keys */
5155+
true, /* no mki */
5156+
TEST_MKI_ID_SIZE, /* mki size */
5157+
128, /* replay window size */
5158+
false, /* retransmission not allowed */
51265159
NULL, /* no encrypted extension headers */
51275160
0, /* list of encrypted extension headers is empty */
51285161
NULL
@@ -5181,6 +5214,7 @@ const srtp_policy_t *policy_array[] = {
51815214
#endif
51825215
&null_policy,
51835216
&aes_256_hmac_policy,
5217+
&aes_256_hmac_32_policy,
51845218
NULL
51855219
};
51865220
// clang-format on

0 commit comments

Comments
 (0)