Skip to content

Commit 596e30e

Browse files
authored
Merge pull request #733 from vopatek/fix-rtcp-mki-when-rtp-short-auth
Fix srtp_unprotect_rtcp_mki when RTP auth != RTCP
2 parents 2b1330d + 63a19f4 commit 596e30e

File tree

2 files changed

+79
-16
lines changed

2 files changed

+79
-16
lines changed

srtp/srtp.c

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,24 +1638,16 @@ static void srtp_calc_aead_iv(srtp_session_keys_t *session_keys,
16381638
v128_xor(iv, &in, &salt);
16391639
}
16401640

1641-
srtp_session_keys_t *srtp_get_session_keys(srtp_stream_ctx_t *stream,
1642-
const uint8_t *hdr,
1643-
unsigned int pkt_octet_len,
1644-
unsigned int *mki_size)
1641+
static srtp_session_keys_t *srtp_get_session_keys(srtp_stream_ctx_t *stream,
1642+
const uint8_t *hdr,
1643+
unsigned int pkt_octet_len,
1644+
unsigned int *mki_size,
1645+
unsigned int tag_len)
16451646
{
16461647
unsigned int base_mki_start_location = pkt_octet_len;
16471648
unsigned int mki_start_location = 0;
1648-
unsigned int tag_len = 0;
16491649
unsigned int i = 0;
16501650

1651-
// Determine the authentication tag size
1652-
if (stream->session_keys[0].rtp_cipher->algorithm == SRTP_AES_GCM_128 ||
1653-
stream->session_keys[0].rtp_cipher->algorithm == SRTP_AES_GCM_256) {
1654-
tag_len = 0;
1655-
} else {
1656-
tag_len = srtp_auth_get_tag_length(stream->session_keys[0].rtp_auth);
1657-
}
1658-
16591651
if (tag_len > base_mki_start_location) {
16601652
*mki_size = 0;
16611653
return NULL;
@@ -1680,6 +1672,44 @@ srtp_session_keys_t *srtp_get_session_keys(srtp_stream_ctx_t *stream,
16801672
return NULL;
16811673
}
16821674

1675+
static srtp_session_keys_t *srtp_get_session_keys_rtp(
1676+
srtp_stream_ctx_t *stream,
1677+
const uint8_t *hdr,
1678+
unsigned int pkt_octet_len,
1679+
unsigned int *mki_size)
1680+
{
1681+
unsigned int tag_len = 0;
1682+
1683+
// Determine the authentication tag size
1684+
if (stream->session_keys[0].rtp_cipher->algorithm == SRTP_AES_GCM_128 ||
1685+
stream->session_keys[0].rtp_cipher->algorithm == SRTP_AES_GCM_256) {
1686+
tag_len = 0;
1687+
} else {
1688+
tag_len = srtp_auth_get_tag_length(stream->session_keys[0].rtp_auth);
1689+
}
1690+
1691+
return srtp_get_session_keys(stream, hdr, pkt_octet_len, mki_size, tag_len);
1692+
}
1693+
1694+
static srtp_session_keys_t *srtp_get_session_keys_rtcp(
1695+
srtp_stream_ctx_t *stream,
1696+
const uint8_t *hdr,
1697+
unsigned int pkt_octet_len,
1698+
unsigned int *mki_size)
1699+
{
1700+
unsigned int tag_len = 0;
1701+
1702+
// Determine the authentication tag size
1703+
if (stream->session_keys[0].rtcp_cipher->algorithm == SRTP_AES_GCM_128 ||
1704+
stream->session_keys[0].rtcp_cipher->algorithm == SRTP_AES_GCM_256) {
1705+
tag_len = 0;
1706+
} else {
1707+
tag_len = srtp_auth_get_tag_length(stream->session_keys[0].rtcp_auth);
1708+
}
1709+
1710+
return srtp_get_session_keys(stream, hdr, pkt_octet_len, mki_size, tag_len);
1711+
}
1712+
16831713
static srtp_err_status_t srtp_estimate_index(srtp_rdbx_t *rdbx,
16841714
uint32_t roc,
16851715
srtp_xtd_seq_num_t *est,
@@ -2583,8 +2613,8 @@ srtp_err_status_t srtp_unprotect_mki(srtp_ctx_t *ctx,
25832613
/* Determine if MKI is being used and what session keys should be used */
25842614
if (use_mki) {
25852615
session_keys =
2586-
srtp_get_session_keys(stream, (const uint8_t *)hdr,
2587-
(unsigned int)*pkt_octet_len, &mki_size);
2616+
srtp_get_session_keys_rtp(stream, (const uint8_t *)hdr,
2617+
(unsigned int)*pkt_octet_len, &mki_size);
25882618

25892619
if (session_keys == NULL)
25902620
return srtp_err_status_bad_mki;
@@ -4293,7 +4323,7 @@ srtp_err_status_t srtp_unprotect_rtcp_mki(srtp_t ctx,
42934323
* Determine if MKI is being used and what session keys should be used
42944324
*/
42954325
if (use_mki) {
4296-
session_keys = srtp_get_session_keys(
4326+
session_keys = srtp_get_session_keys_rtcp(
42974327
stream, (uint8_t *)hdr, (unsigned int)*pkt_octet_len, &mki_size);
42984328

42994329
if (session_keys == NULL)

test/srtp_driver.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4279,6 +4279,38 @@ const srtp_policy_t aes_256_hmac_policy = {
42794279
NULL
42804280
};
42814281

4282+
const srtp_policy_t aes_256_hmac_32_policy = {
4283+
{ ssrc_any_outbound, 0 }, /* SSRC */
4284+
{
4285+
/* SRTP policy */
4286+
SRTP_AES_ICM_256, /* cipher type */
4287+
SRTP_AES_ICM_256_KEY_LEN_WSALT, /* cipher key length in octets */
4288+
SRTP_HMAC_SHA1, /* authentication func type */
4289+
20, /* auth key length in octets */
4290+
4, /* auth tag length in octets */
4291+
sec_serv_conf_and_auth /* security services flag */
4292+
},
4293+
{
4294+
/* SRTCP policy */
4295+
SRTP_AES_ICM_256, /* cipher type */
4296+
SRTP_AES_ICM_256_KEY_LEN_WSALT, /* cipher key length in octets */
4297+
SRTP_HMAC_SHA1, /* authentication func type */
4298+
20, /* auth key length in octets */
4299+
10, /* auth tag length in octets.
4300+
80 bits per RFC 3711. */
4301+
sec_serv_conf_and_auth /* security services flag */
4302+
},
4303+
NULL,
4304+
(srtp_master_key_t **)test_256_keys,
4305+
2, /* indicates the number of Master keys */
4306+
NULL, /* indicates that EKT is not in use */
4307+
128, /* replay window size */
4308+
0, /* retransmission not allowed */
4309+
NULL, /* no encrypted extension headers */
4310+
0, /* list of encrypted extension headers is empty */
4311+
NULL
4312+
};
4313+
42824314
char ekt_test_policy = 'x';
42834315

42844316
const srtp_policy_t hmac_only_with_ekt_policy = {
@@ -4333,6 +4365,7 @@ const srtp_policy_t *policy_array[] = {
43334365
#endif
43344366
&null_policy,
43354367
&aes_256_hmac_policy,
4368+
&aes_256_hmac_32_policy,
43364369
NULL
43374370
};
43384371
// clang-format on

0 commit comments

Comments
 (0)