Skip to content

Commit

Permalink
ISO: Include challenge in device signature and verify it
Browse files Browse the repository at this point in the history
  • Loading branch information
nodh committed Aug 2, 2023
1 parent c1a1ab8 commit 9c98def
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class HolderAgent(
val deviceSignature = coseService.createSignedCose(
protectedHeader = CoseHeader(algorithm = CoseAlgorithm.ES256),
unprotectedHeader = null,
payload = null, //TODO challenge
payload = challenge.encodeToByteArray(),
addKeyId = false
).getOrNull() ?: return null
.also { Napier.w("Could not create DeviceAuth for presentation") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,14 @@ class Validator(
.also { Napier.w("DeviceSignature not verified") }
}

val deviceSignaturePayload = deviceSignature.payload
?: return Verifier.VerifyPresentationResult.InvalidStructure(doc.serialize().encodeBase16())
.also { Napier.w("DeviceSignature does not contain challenge") }
if (!deviceSignaturePayload.contentEquals(challenge.encodeToByteArray())) {
return Verifier.VerifyPresentationResult.InvalidStructure(doc.serialize().encodeBase16())
.also { Napier.w("DeviceSignature does not contain correct challenge") }
}

val issuerSignedItems = issuerSigned.namespaces?.get(NAMESPACE_MDL)
?: return Verifier.VerifyPresentationResult.InvalidStructure(doc.serialize().encodeBase16())
.also { Napier.w("No issuer signed items in ${issuerSigned.namespaces}") }
Expand Down

0 comments on commit 9c98def

Please sign in to comment.