Allow empty keys to clear IRK/EncKey

This commit modifies the handling of Identity Resolving Key (IRK) and Encryption Key (EncKey) to allow users to clear these values by providing an empty input.

Specifically:
- In `GeneralSettingsFragment.kt`, the `onKey` callbacks for both IRK and EncKey dialogs now use `takeIf { it.isNotEmpty() }` after converting the input hex string to a byte array. This ensures that an empty input results in `null` being set for the respective key.
- In `PodMonitor.kt`, when determining the main device, `mainDeviceIdentityKey.value` is now checked with `takeIf { it.isNotEmpty() }` to ensure an empty IRK is treated as no IRK being configured.
- In `AppleFactory.kt`, when attempting to decrypt the private payload, `mainDeviceEncryptionKey.value` is now checked with `takeIf { it.isNotEmpty() }` to ensure an empty EncKey prevents decryption attempts.
This commit is contained in:
darken
2025-06-30 14:12:32 +02:00
committed by Matthias Urhahn
parent 3c777d377e
commit 977f135c50
3 changed files with 8 additions and 4 deletions
@@ -198,7 +198,7 @@ class PodMonitor @Inject constructor(
}
private fun determineMainDevice(pods: List<PodDevice>): PodDevice? {
val identityKey = generalSettings.mainDeviceIdentityKey.value
val identityKey = generalSettings.mainDeviceIdentityKey.value?.takeIf { it.isNotEmpty() }
if (identityKey != null) {
val irkHit = pods.filterIsInstance<ApplePods>().firstOrNull { it.flags.isIRKMatch }
log(TAG) { "IRK is configured, main device irkHit=$irkHit" }
@@ -71,7 +71,7 @@ class AppleFactory @Inject constructor(
if (!isIrkMatch) return@run null
if (proximityMessage.data.size != ProximityPairing.PAIRING_MESSAGE_LENGTH) return@run null
val encKey = generalSettings.mainDeviceEncryptionKey.value
val encKey = generalSettings.mainDeviceEncryptionKey.value?.takeIf { it.isNotEmpty() }
if (encKey == null) return@run null
val encrypted = proximityMessage.data.takeLast(16).toUByteArray().toByteArray()
@@ -55,7 +55,9 @@ class GeneralSettingsFragment : PreferenceFragment3() {
AirPodKeyInputDialog(requireContext()).create(
mode = AirPodKeyInputDialog.Mode.IRK,
current = generalSettings.mainDeviceIdentityKey.value?.toHex() ?: "",
onKey = { generalSettings.mainDeviceIdentityKey.value = it.fromHex() },
onKey = { raw ->
generalSettings.mainDeviceIdentityKey.value = raw.fromHex().takeIf { it.isNotEmpty() }
},
onGuide = { webpageTool.open("https://github.com/d4rken-org/capod/wiki/airpod-Keys") }
).show()
true
@@ -64,7 +66,9 @@ class GeneralSettingsFragment : PreferenceFragment3() {
AirPodKeyInputDialog(requireContext()).create(
mode = AirPodKeyInputDialog.Mode.ENC,
current = generalSettings.mainDeviceEncryptionKey.value?.toHex() ?: "",
onKey = { generalSettings.mainDeviceEncryptionKey.value = it.fromHex() },
onKey = { raw ->
generalSettings.mainDeviceEncryptionKey.value = raw.fromHex().takeIf { it.isNotEmpty() }
},
onGuide = { webpageTool.open("https://github.com/d4rken-org/capod/wiki/airpod-Keys") }
).show()
true