Skip to content

Commit 4a40751

Browse files
vopatekjlaine
authored andcommitted
Use SRTP_MAX_SRTCP_TRAILER_LEN for protect_rtcp
Applying protection to RTCP packets can add more bytes to the packet than RTP does.
1 parent ffa9856 commit 4a40751

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/pylibsrtp/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@
3939
]
4040

4141

42+
# SRTP_MAX_TAG_LEN + SRTP_MAX_MKI_LEN
4243
SRTP_MAX_TRAILER_LEN = 16 + 128
4344

45+
# SRTP_SRCTP_INDEX_LEN + SRTP_MAX_TAG_LEN + SRTP_MAX_MKI_LEN
46+
SRTP_MAX_SRTCP_TRAILER_LEN = 4 + 16 + 128
47+
4448

4549
class Error(Exception):
4650
"""
@@ -238,7 +242,7 @@ def protect_rtcp(self, packet: bytes) -> bytes:
238242
:param packet: :class:`bytes`
239243
:rtype: :class:`bytes`
240244
"""
241-
return self.__process(packet, lib.srtp_protect_rtcp, SRTP_MAX_TRAILER_LEN)
245+
return self.__process(packet, lib.srtp_protect_rtcp, SRTP_MAX_SRTCP_TRAILER_LEN)
242246

243247
def unprotect(self, packet: bytes) -> bytes:
244248
"""

tests/test_session.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import secrets
33
from unittest import TestCase
44

5+
import pylibsrtp
56
from pylibsrtp import Error, Policy, Session
67

78
RTP = (
@@ -207,7 +208,7 @@ def test_rtp_any_ssrc(self):
207208

208209
# bad length
209210
with self.assertRaises(ValueError) as cm:
210-
tx_session.protect(b"0" * 1500)
211+
tx_session.protect(b"0" * (1501 - pylibsrtp.SRTP_MAX_TRAILER_LEN))
211212
self.assertEqual(str(cm.exception), "packet is too long")
212213

213214
# unprotect RTP
@@ -244,7 +245,9 @@ def test_rtcp_any_ssrc(self):
244245

245246
# bad length
246247
with self.assertRaises(ValueError) as cm:
247-
tx_session.protect_rtcp(b"0" * 1500)
248+
tx_session.protect_rtcp(
249+
b"0" * (1501 - pylibsrtp.SRTP_MAX_SRTCP_TRAILER_LEN)
250+
)
248251
self.assertEqual(str(cm.exception), "packet is too long")
249252

250253
# unprotect RTCP

0 commit comments

Comments
 (0)