From 3c18bfdc8149f6cb1bd8f25f6328872f2fa74f6a Mon Sep 17 00:00:00 2001 From: crsawyer Date: Fri, 12 Jan 2024 08:49:49 -0600 Subject: [PATCH] P25-P2 Encryption Synchronization ReSync (#1792) * resync ess processor on PTT, END_PTT, HANGTIME, or IDLE * Re-order of AbstractVoiceTimeslot. Voice2 should be processed first, as any accumulated ESS information applies to the following Voice slots * Update P25 MBE recorders to include synchronized encryption information --------- Co-authored-by: Sawyer, Caleb (US) - ISR --- .../p25/audio/P25P1CallSequenceRecorder.java | 24 +++++++++++++++++++ .../p25/audio/P25P2CallSequenceRecorder.java | 18 ++++++++++++++ .../p25/phase2/P25P2MessageProcessor.java | 21 ++++++++++++++-- 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/dsheirer/module/decode/p25/audio/P25P1CallSequenceRecorder.java b/src/main/java/io/github/dsheirer/module/decode/p25/audio/P25P1CallSequenceRecorder.java index 7584cdf2d..dfd6b5ab8 100644 --- a/src/main/java/io/github/dsheirer/module/decode/p25/audio/P25P1CallSequenceRecorder.java +++ b/src/main/java/io/github/dsheirer/module/decode/p25/audio/P25P1CallSequenceRecorder.java @@ -25,6 +25,9 @@ import io.github.dsheirer.bits.BinaryMessage; import io.github.dsheirer.message.IMessage; import io.github.dsheirer.module.decode.p25.phase1.message.P25Message; +import io.github.dsheirer.module.decode.p25.phase1.message.hdu.HDUMessage; +import io.github.dsheirer.module.decode.p25.phase1.message.hdu.HeaderData; +import io.github.dsheirer.identifier.encryption.EncryptionKeyIdentifier; import io.github.dsheirer.module.decode.p25.phase1.message.lc.LinkControlWord; import io.github.dsheirer.module.decode.p25.phase1.message.lc.motorola.LCMotorolaPatchGroupVoiceChannelUpdate; import io.github.dsheirer.module.decode.p25.phase1.message.lc.motorola.LCMotorolaPatchGroupVoiceChannelUser; @@ -124,6 +127,10 @@ else if(message instanceof TDUMessage) { flush(); } + else if (message instanceof HDUMessage) + { + process((HDUMessage)message); + } } private void process(TDULinkControlMessage tdulc) @@ -228,4 +235,21 @@ private void process(LDU2Message ldu2Message) mCallSequence.setEncryptionSyncParameters(parameters); } } + + private void process(HDUMessage hduMessage) + { + if(mCallSequence == null) + { + mCallSequence = new MBECallSequence(PROTOCOL); + } + + HeaderData hd = hduMessage.getHeaderData(); + + if (hd.isEncryptedAudio()) + { + mCallSequence.setEncrypted(true); + Phase2EncryptionSyncParameters esp = new Phase2EncryptionSyncParameters((EncryptionKeyIdentifier)hd.getEncryptionKey(), hd.getMessageIndicator()); + mCallSequence.setEncryptionSyncParameters(esp); + } + } } diff --git a/src/main/java/io/github/dsheirer/module/decode/p25/audio/P25P2CallSequenceRecorder.java b/src/main/java/io/github/dsheirer/module/decode/p25/audio/P25P2CallSequenceRecorder.java index aba52e0a2..c01cca254 100644 --- a/src/main/java/io/github/dsheirer/module/decode/p25/audio/P25P2CallSequenceRecorder.java +++ b/src/main/java/io/github/dsheirer/module/decode/p25/audio/P25P2CallSequenceRecorder.java @@ -27,6 +27,7 @@ import io.github.dsheirer.audio.codec.mbe.MBECallSequenceRecorder; import io.github.dsheirer.bits.BinaryMessage; import io.github.dsheirer.message.IMessage; +import io.github.dsheirer.module.decode.p25.phase2.message.EncryptionSynchronizationSequence; import io.github.dsheirer.module.decode.p25.phase2.message.P25P2Message; import io.github.dsheirer.module.decode.p25.phase2.message.mac.MacMessage; import io.github.dsheirer.module.decode.p25.phase2.message.mac.MacStructure; @@ -153,6 +154,10 @@ else if(message instanceof MacMessage) { process((MacMessage)message); } + else if (message instanceof EncryptionSynchronizationSequence) + { + processEss((EncryptionSynchronizationSequence)message); + } } /** @@ -382,5 +387,18 @@ private void processPTT(MacStructure mac) { mLog.warn("Expected push-to-talk structure but found: " + mac.getClass()); } } + + private void processEss(EncryptionSynchronizationSequence ess) + { + if(mCallSequence == null) + { + mCallSequence = new MBECallSequence(PROTOCOL); + } + if (ess.isEncrypted()) + { + mCallSequence.setEncrypted(true); + mCallSequence.setEncryptionSyncParameters(ess); + } + } } } diff --git a/src/main/java/io/github/dsheirer/module/decode/p25/phase2/P25P2MessageProcessor.java b/src/main/java/io/github/dsheirer/module/decode/p25/phase2/P25P2MessageProcessor.java index 314f0ae50..bcf16dbe2 100644 --- a/src/main/java/io/github/dsheirer/module/decode/p25/phase2/P25P2MessageProcessor.java +++ b/src/main/java/io/github/dsheirer/module/decode/p25/phase2/P25P2MessageProcessor.java @@ -101,11 +101,30 @@ public void receive(IMessage message) mFrequencyBandMap.put(bandIdentifier.getIdentifier(), bandIdentifier); } + switch(macMessage.getMacPduType()) + { + case MAC_1_PTT: + case MAC_2_END_PTT: + case MAC_6_HANGTIME: + case MAC_3_IDLE: + if (timeslot.getTimeslot() == 0) + { + mESSProcessor0.reset(); + } + else + { + mESSProcessor1.reset(); + } + break; + } + mMessageListener.receive(macMessage); } } else if(timeslot instanceof AbstractVoiceTimeslot) { + mMessageListener.receive(timeslot); + if(timeslot.getTimeslot() == 0) { mESSProcessor0.process((AbstractVoiceTimeslot)timeslot); @@ -139,8 +158,6 @@ else if(timeslot instanceof AbstractVoiceTimeslot) } } - mMessageListener.receive(timeslot); - } else {