From 0f97e870ebb67a1b88f1f5180c6eab5b82ca5459 Mon Sep 17 00:00:00 2001 From: Wenpeng Song <wenpeng.song@iopsys.eu> Date: Thu, 23 Mar 2023 13:02:54 +0000 Subject: [PATCH] Sync SSRC of RTCP and RTP before encryption Libsrtp expects RTCP and RTP from the one session has the same SSRC. Otherwise the encryption fails. (cherry picked from commit 94735f530fcf361e791fff5abfe2c46d7873a392) --- res/res_srtp.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/res/res_srtp.c b/res/res_srtp.c index e10421cbb4..ea129e1299 100644 --- a/res/res_srtp.c +++ b/res/res_srtp.c @@ -504,6 +504,12 @@ static int ast_srtp_protect(struct ast_srtp *srtp, void **buf, int *len, int rtc memcpy(localbuf, *buf, *len); + if(rtcp){ + // align ssrc with length of 32bits. + memcpy(localbuf+4, srtp->buf+8, 4); + memcpy(srtp->rtcpbuf+4, srtp->buf+8, 4); + } + if ((res = rtcp ? srtp_protect_rtcp(srtp->session, localbuf, len) : srtp_protect(srtp->session, localbuf, len)) != err_status_ok && res != err_status_replay_fail) { ast_log(LOG_WARNING, "SRTP protect: %s\n", srtp_errstr(res)); return -1; -- GitLab