From cda16ca06a634711e1476463f355af3690071f99 Mon Sep 17 00:00:00 2001 From: darken Date: Fri, 6 Jun 2025 03:14:16 +0200 Subject: [PATCH] Extend tests and fix payload parsing This commit enhances the test coverage for `AirPodsProTest` by: - Verifying the hex representation of the public payload data. - Confirming that the private payload is null when no IRK/EncKey is set. - Verifying the hex representation of the private payload data when IRK/EncKey are set. Additionally, a fix is introduced in `AppleFactory.kt` to correctly parse the public payload by taking only the first 9 bytes instead of 16. This ensures that the private payload is only processed if the incoming message length matches the expected `PAIRING_MESSAGE_LENGTH`. --- .../java/eu/darken/capod/pods/core/apple/AppleFactory.kt | 3 ++- .../darken/capod/pods/core/apple/airpods/AirPodsProTest.kt | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app-common/src/main/java/eu/darken/capod/pods/core/apple/AppleFactory.kt b/app-common/src/main/java/eu/darken/capod/pods/core/apple/AppleFactory.kt index 32676590..8feca1d4 100644 --- a/app-common/src/main/java/eu/darken/capod/pods/core/apple/AppleFactory.kt +++ b/app-common/src/main/java/eu/darken/capod/pods/core/apple/AppleFactory.kt @@ -65,10 +65,11 @@ class AppleFactory @Inject constructor( val payload = ProximityPayload( public = ProximityPayload.Public( - proximityMessage.data.take(16).toUByteArray() + proximityMessage.data.take(9).toUByteArray() ), private = run { if (!isIrkMatch) return@run null + if (proximityMessage.data.size != ProximityPairing.PAIRING_MESSAGE_LENGTH) return@run null val encKey = generalSettings.mainDeviceEncryptionKey.value if (encKey == null) return@run null diff --git a/app-common/src/test/java/eu/darken/capod/pods/core/apple/airpods/AirPodsProTest.kt b/app-common/src/test/java/eu/darken/capod/pods/core/apple/airpods/AirPodsProTest.kt index 7b05a351..aedc527b 100644 --- a/app-common/src/test/java/eu/darken/capod/pods/core/apple/airpods/AirPodsProTest.kt +++ b/app-common/src/test/java/eu/darken/capod/pods/core/apple/airpods/AirPodsProTest.kt @@ -1,5 +1,6 @@ package eu.darken.capod.pods.core.apple.airpods +import eu.darken.capod.common.toHex import eu.darken.capod.pods.core.PodDevice import eu.darken.capod.pods.core.apple.BaseAirPodsTest import eu.darken.capod.pods.core.apple.HasAppleColor @@ -201,6 +202,9 @@ class AirPodsProTest : BaseAirPodsTest() { batteryCasePercent shouldBe 0.8f isCaseCharging shouldBe false + + payload.public.data.toByteArray().toHex(" ") shouldBe "01 0E 20 51 9A 98 33 00 04" + payload.private shouldBe null } setKeyIRK("79-04-65-1E-E2-CC-D9-26-F2-6E-20-EE-3E-CC-DE-79") setKeyEnc("3B-9C-80-57-E6-45-7F-F2-1B-8E-07-63-6C-99-E0-29") @@ -212,6 +216,9 @@ class AirPodsProTest : BaseAirPodsTest() { batteryCasePercent shouldBe 0.86f isCaseCharging shouldBe false + + payload.public.data.toByteArray().toHex(" ") shouldBe "01 0E 20 51 9A 98 33 00 04" + payload.private!!.data.toByteArray().toHex(" ") shouldBe "44 E4 62 56 17 FA 06 31 E4 0A 01 13 31 13 4C 40" } } } \ No newline at end of file