mirror of
https://github.com/d4rken-org/capod.git
synced 2026-09-14 18:26:11 -04:00
fix(device): Keep a log line for rejected malformed addresses
Structurally broken addresses now fail the octet parse instead of throwing, so the catch-all error log no longer fires for them. Log the rejection at WARN with a redacted address so support logs still show it. Fixes review finding F1.
This commit is contained in:
@@ -30,7 +30,12 @@ class RPAChecker @Inject constructor() {
|
||||
fun resolve(address: BluetoothAddress, irk: IdentityResolvingKey): AddressOrder? = try {
|
||||
val octets = address.parseOctets()
|
||||
when {
|
||||
octets == null -> null
|
||||
octets == null -> {
|
||||
log(TAG, Logging.Priority.WARN) {
|
||||
"Failed to resolve RPA, malformed address: ${address.redactedForLogs()}"
|
||||
}
|
||||
null
|
||||
}
|
||||
matchesHash(octets, irk) -> AddressOrder.STANDARD
|
||||
else -> octets.reversedArray()
|
||||
.takeIf { it.isRpaShaped() && matchesHash(it, irk) }
|
||||
|
||||
@@ -162,4 +162,32 @@ class RPACheckerTest : BaseTest() {
|
||||
captured.any { (_, message) -> message.contains(keyHex, ignoreCase = true) } shouldBe false
|
||||
captured.any { (_, message) -> message.contains(resolvingAddress) } shouldBe false
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a malformed address is logged as a warning`() {
|
||||
val captured = mutableListOf<Pair<Logging.Priority, String>>()
|
||||
val capturingLogger = object : Logging.Logger {
|
||||
override fun log(
|
||||
priority: Logging.Priority,
|
||||
tag: String,
|
||||
message: String,
|
||||
metaData: Map<String, Any>?,
|
||||
) {
|
||||
captured.add(priority to message)
|
||||
}
|
||||
}
|
||||
|
||||
Logging.clearAll()
|
||||
Logging.install(capturingLogger)
|
||||
try {
|
||||
RPAChecker().verify(address = "123", irk = irkHex.fromHex()) shouldBe false
|
||||
} finally {
|
||||
Logging.clearAll()
|
||||
Logging.install(JUnitLogger())
|
||||
}
|
||||
|
||||
captured.any { (priority, message) ->
|
||||
priority == Logging.Priority.WARN && message.contains("malformed")
|
||||
} shouldBe true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user