Skip to content

Commit

Permalink
ISO: Keep fallback verification of presentation documents in place
Browse files Browse the repository at this point in the history
  • Loading branch information
nodh committed Jan 15, 2025
1 parent 60ba49d commit 693c357
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,29 @@ class Validator(
return IsoDocumentParsed(mso = mso, validItems = validItems, invalidItems = invalidItems)
}

@Deprecated("This is just here to keep functionality implemented before, to be deleted after 5.3.0")
fun verifyDocumentFallback(mso: MobileSecurityObject, doc: Document, challenge: String): Boolean {
val walletKey = mso.deviceKeyInfo.deviceKey
val deviceSignature = doc.deviceSigned.deviceAuth.deviceSignature ?: run {
Napier.w("DeviceSignature is null: ${doc.deviceSigned.deviceAuth}")
throw IllegalArgumentException("deviceSignature")
}

verifierCoseService.verifyCose(deviceSignature, walletKey).onFailure {
Napier.w("DeviceSignature not verified: ${doc.deviceSigned.deviceAuth}", it)
throw IllegalArgumentException("deviceSignature")
}
val deviceSignaturePayload = deviceSignature.payload ?: run {
Napier.w("DeviceSignature does not contain challenge")
throw IllegalArgumentException("challenge")
}
if (!deviceSignaturePayload.contentEquals(challenge.encodeToByteArray())) {
Napier.w("DeviceSignature does not contain correct challenge")
throw IllegalArgumentException("challenge")
}
return true
}

/**
* Verify that calculated digests equal the corresponding digest values in the MSO.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class VerifierAgent(
* that shall include the [challenge] (sent by this verifier),
* as well as the expected [identifier] (identifying this verifier).
*/
@Deprecated("Use specific methods instead")
@Deprecated("Use specific methods instead, to be deleted after 5.3.0")
override suspend fun verifyPresentation(it: String, challenge: String): VerifyPresentationResult {
val input = it
val sdJwtSigned = runCatching { SdJwtSigned.parse(input) }.getOrNull()
Expand All @@ -54,7 +54,9 @@ class VerifierAgent(
?.let { bytes -> Document.deserialize(bytes).getOrNull() }
if (document != null) {
val verifiedDocument = runCatching {
validator.verifyDocument(document, { _, _ -> true })
validator.verifyDocument(document) { mso, document ->
validator.verifyDocumentFallback(mso, document, challenge)
}
}.getOrElse {
return VerifyPresentationResult.ValidationError(it)
}
Expand All @@ -64,7 +66,9 @@ class VerifierAgent(
?.let { bytes -> DeviceResponse.deserialize(bytes).getOrNull() }
if (deviceResponse != null) {
val result = runCatching {
validator.verifyDeviceResponse(deviceResponse, { _, _ -> true })
validator.verifyDeviceResponse(deviceResponse) { mso, document ->
validator.verifyDocumentFallback(mso, document, challenge)
}
}.getOrElse {
return VerifyPresentationResult.ValidationError(it)
}
Expand Down

0 comments on commit 693c357

Please sign in to comment.