Skip to content

Commit 70784fd

Browse files
committed
cryptex and enc xtn hdr is not a valid combination
backport of the behavior in 3.x added in b40766c
1 parent 3d61a8a commit 70784fd

3 files changed

Lines changed: 54 additions & 1 deletion

File tree

include/srtp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1759,7 +1759,8 @@ srtp_err_status_t srtp_get_stream_roc(srtp_t session,
17591759
* @param enable whether to enable sending and receiving cryptex.
17601760
*
17611761
* @returns srtp_err_status_ok on success, or srtp_err_status_bad_param if the
1762-
* stream or template cannot be found for the given SSRC.
1762+
* stream or template cannot be found for the given SSRC or if enabling cryptex
1763+
* would conflict with encrypted header extensions configured on the stream.
17631764
*/
17641765
srtp_err_status_t srtp_set_stream_use_cryptex(srtp_t session,
17651766
const srtp_ssrc_t *ssrc,

srtp/srtp.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5155,6 +5155,9 @@ srtp_err_status_t srtp_set_stream_use_cryptex(srtp_t session,
51555155
if (stream == NULL) {
51565156
return srtp_err_status_bad_param;
51575157
}
5158+
if (enable && stream->enc_xtn_hdr_count > 0) {
5159+
return srtp_err_status_bad_param;
5160+
}
51585161
stream->use_cryptex = enable != 0;
51595162
break;
51605163
case ssrc_any_inbound:
@@ -5164,6 +5167,9 @@ srtp_err_status_t srtp_set_stream_use_cryptex(srtp_t session,
51645167
if (session->stream_template == NULL) {
51655168
return srtp_err_status_bad_param;
51665169
}
5170+
if (enable && session->stream_template->enc_xtn_hdr_count > 0) {
5171+
return srtp_err_status_bad_param;
5172+
}
51675173
session->stream_template->use_cryptex = enable != 0;
51685174
data.template = session->stream_template;
51695175
srtp_stream_list_for_each(session->stream_list,

test/srtp_driver.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ srtp_err_status_t srtp_test_cryptex_disable(void);
117117

118118
srtp_err_status_t srtp_test_require_cryptex(void);
119119

120+
srtp_err_status_t srtp_test_cryptex_and_enc_xtn_hdr_invalid(void);
121+
120122
double srtp_bits_per_second(int msg_len_octets, const srtp_policy_t *policy);
121123

122124
double srtp_rejections_per_second(int msg_len_octets,
@@ -694,6 +696,14 @@ int main(int argc, char *argv[])
694696
printf("failed\n");
695697
exit(1);
696698
}
699+
700+
printf("testing cryptex_and_enc_xtn_hdr_invalid()...");
701+
if (srtp_test_cryptex_and_enc_xtn_hdr_invalid() == srtp_err_status_ok) {
702+
printf("passed\n");
703+
} else {
704+
printf("failed\n");
705+
exit(1);
706+
}
697707
}
698708

699709
if (do_stream_list) {
@@ -2758,6 +2768,42 @@ srtp_err_status_t srtp_test_require_cryptex(void)
27582768
return srtp_err_status_ok;
27592769
}
27602770

2771+
srtp_err_status_t srtp_test_cryptex_and_enc_xtn_hdr_invalid(void)
2772+
{
2773+
int headers[] = { 1 };
2774+
2775+
srtp_policy_t policy;
2776+
memset(&policy, 0, sizeof(policy));
2777+
srtp_crypto_policy_set_rtp_default(&policy.rtp);
2778+
srtp_crypto_policy_set_rtcp_default(&policy.rtcp);
2779+
policy.ssrc.type = ssrc_specific;
2780+
policy.ssrc.value = 0xcafebabe;
2781+
policy.key = test_key;
2782+
policy.window_size = 128;
2783+
policy.allow_repeat_tx = 0;
2784+
policy.enc_xtn_hdr = headers;
2785+
policy.enc_xtn_hdr_count = sizeof(headers) / sizeof(headers[0]);
2786+
policy.next = NULL;
2787+
2788+
srtp_t srtp_snd;
2789+
CHECK_OK(srtp_create(&srtp_snd, &policy));
2790+
CHECK_RETURN(srtp_set_stream_use_cryptex(srtp_snd, &policy.ssrc, 1),
2791+
srtp_err_status_bad_param);
2792+
/* disabling is still allowed */
2793+
CHECK_OK(srtp_set_stream_use_cryptex(srtp_snd, &policy.ssrc, 0));
2794+
CHECK_OK(srtp_dealloc(srtp_snd));
2795+
2796+
policy.ssrc.type = ssrc_any_outbound;
2797+
srtp_t srtp_snd_wildcard;
2798+
CHECK_OK(srtp_create(&srtp_snd_wildcard, &policy));
2799+
CHECK_RETURN(
2800+
srtp_set_stream_use_cryptex(srtp_snd_wildcard, &policy.ssrc, 1),
2801+
srtp_err_status_bad_param);
2802+
CHECK_OK(srtp_dealloc(srtp_snd_wildcard));
2803+
2804+
return srtp_err_status_ok;
2805+
}
2806+
27612807
#ifdef GCM
27622808
/*
27632809
* srtp_validate_gcm() verifies the correctness of libsrtp by comparing

0 commit comments

Comments
 (0)