From f9c9f3e17cf918a0746cfccdce44b360a0ee86c0 Mon Sep 17 00:00:00 2001 From: Thomas Diesler Date: Fri, 28 Jul 2023 12:20:13 +0200 Subject: [PATCH 1/2] [#329] CredentialStatusPolicy fails with NPE without credentialStatus --- .../CredentialPropertyVerificationPolicies.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/id/walt/auditor/policies/CredentialPropertyVerificationPolicies.kt b/src/main/kotlin/id/walt/auditor/policies/CredentialPropertyVerificationPolicies.kt index 7714ed64..265b8792 100644 --- a/src/main/kotlin/id/walt/auditor/policies/CredentialPropertyVerificationPolicies.kt +++ b/src/main/kotlin/id/walt/auditor/policies/CredentialPropertyVerificationPolicies.kt @@ -50,15 +50,15 @@ class ExpirationDateAfterPolicy : SimpleVerificationPolicy() { class CredentialStatusPolicy : SimpleVerificationPolicy() { override val description: String = "Verify by credential status" - override fun doVerify(vc: VerifiableCredential): VerificationPolicyResult = runCatching { - Klaxon().parse(vc.toJson())!!.credentialStatus!!.let { cs -> - RevocationClientService.check(vc).let { - if (!it.isRevoked) VerificationPolicyResult.success() - else failResult(it, cs) - } - } - }.getOrElse { - VerificationPolicyResult.failure(it) + override fun doVerify(vc: VerifiableCredential): VerificationPolicyResult { + val maybeCredentialStatus = Klaxon().parse(vc.toJson())!!.credentialStatus + return maybeCredentialStatus?.let { cs -> runCatching { + RevocationClientService.check(vc).let { + if (!it.isRevoked) VerificationPolicyResult.success() + else failResult(it, cs) + } + }.getOrElse { VerificationPolicyResult.failure(it) } + } ?: VerificationPolicyResult.success() } private fun failResult(status: RevocationStatus, cs: CredentialStatus) = when (status) { From c7d220e2c8211217f9b15f2052b0a309261b9fc4 Mon Sep 17 00:00:00 2001 From: Thomas Diesler Date: Mon, 31 Jul 2023 14:39:00 +0200 Subject: [PATCH 2/2] [#331] Prefer IllegalStateException on revoked VC --- .../auditor/policies/CredentialPropertyVerificationPolicies.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/id/walt/auditor/policies/CredentialPropertyVerificationPolicies.kt b/src/main/kotlin/id/walt/auditor/policies/CredentialPropertyVerificationPolicies.kt index 265b8792..ed1d7bb9 100644 --- a/src/main/kotlin/id/walt/auditor/policies/CredentialPropertyVerificationPolicies.kt +++ b/src/main/kotlin/id/walt/auditor/policies/CredentialPropertyVerificationPolicies.kt @@ -65,7 +65,7 @@ class CredentialStatusPolicy : SimpleVerificationPolicy() { is TokenRevocationStatus -> "CredentialStatus (type ${cs.type}) was REVOKED at timestamp ${status.timeOfRevocation} for id ${cs.id}." else -> "CredentialStatus ${cs.type} was REVOKED for id ${cs.id}" }.let { - VerificationPolicyResult.failure(IllegalArgumentException(it)) + VerificationPolicyResult.failure(IllegalStateException(it)) } }