From 66d319bf1b4a624500597db906069d86e31ec5c1 Mon Sep 17 00:00:00 2001 From: Moritz Heidkamp Date: Tue, 5 Nov 2024 13:54:19 +0100 Subject: [PATCH] Fix SRTP double-encryption on send It turns out that the SRTP send implementation was redundantly encrypting payloads when using the 4-ary `sendPacket` method. The override for that method in `SRTPProtocolImpl` would encrypt the payload data and then proceed to invoke its parent's implementation. That one in turn would invoke the 5-ary `sendPacket` method which is also overriden in `SRTPProtocolImpl`. That override would encrypt the payload a second time, resulting in garbled data on the receiver's end. Fixed by removing the 4-ary override from `SRTPProtocolImpl`. --- .../com/phono/srtplight/SRTPProtocolImpl.java | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/main/java/com/phono/srtplight/SRTPProtocolImpl.java b/src/main/java/com/phono/srtplight/SRTPProtocolImpl.java index 450905f..d845d2e 100644 --- a/src/main/java/com/phono/srtplight/SRTPProtocolImpl.java +++ b/src/main/java/com/phono/srtplight/SRTPProtocolImpl.java @@ -377,21 +377,6 @@ public void sendPacket(byte[] data, long stamp, char seqno, int ptype, boolean m } - @Override - public void sendPacket(byte[] data, long stamp, int ptype, boolean marker) throws SocketException, - IOException { - try { - if (_doCrypt) { - _scOut.deriveKeys(stamp); - encrypt(data, (int) _csrcid, _seqno); - } - super.sendPacket(data, stamp, ptype, marker); - } catch (GeneralSecurityException ex) { - Log.error("problem encrypting packet" + ex.getMessage()); - ex.printStackTrace(); - } - } - static ByteBuffer getPepper(int ssrc, long idx) { //(SSRC * 2^64) XOR (i * 2^16) ByteBuffer pepper = ByteBuffer.allocate(16);