From 993aa7bc8ba52494ecc15353fe0278445903cab5 Mon Sep 17 00:00:00 2001 From: mikeplotean Date: Tue, 18 Apr 2023 15:15:27 +0300 Subject: [PATCH] updated ebsi-trusted-issuer-did policy to check for ebsi type did --- .../id/walt/auditor/policies/EbsiVerificationPolicies.kt | 4 ++-- src/main/kotlin/id/walt/services/did/DidService.kt | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/id/walt/auditor/policies/EbsiVerificationPolicies.kt b/src/main/kotlin/id/walt/auditor/policies/EbsiVerificationPolicies.kt index 80ed5fbb..1c35ef67 100644 --- a/src/main/kotlin/id/walt/auditor/policies/EbsiVerificationPolicies.kt +++ b/src/main/kotlin/id/walt/auditor/policies/EbsiVerificationPolicies.kt @@ -52,8 +52,8 @@ class EbsiTrustedIssuerDidPolicy : SimpleVerificationPolicy() { override val description: String = "Verify by trusted issuer did" override fun doVerify(vc: VerifiableCredential): VerificationPolicyResult { return try { - DidService.loadOrResolveAnyDid(vc.issuerId!!)?.let { VerificationPolicyResult.success() } - ?: VerificationPolicyResult.failure() + if (!DidService.isDidEbsiV1(vc.issuerId!!)) VerificationPolicyResult.failure(IllegalArgumentException("Not an ebsi v1 did")) + else DidService.loadOrResolveAnyDid(vc.issuerId!!)?.let { VerificationPolicyResult.success() } ?: VerificationPolicyResult.failure() } catch (e: ClientRequestException) { VerificationPolicyResult.failure( IllegalArgumentException( diff --git a/src/main/kotlin/id/walt/services/did/DidService.kt b/src/main/kotlin/id/walt/services/did/DidService.kt index 4afbbfc5..55ec3e49 100644 --- a/src/main/kotlin/id/walt/services/did/DidService.kt +++ b/src/main/kotlin/id/walt/services/did/DidService.kt @@ -527,10 +527,14 @@ object DidService { } //endregion - fun isDidEbsiV2(did: String): Boolean { + fun isDidEbsiV1(did: String): Boolean = checkIsDidEbsiAndVersion(did, 1) + + fun isDidEbsiV2(did: String): Boolean = checkIsDidEbsiAndVersion(did, 2) + + fun checkIsDidEbsiAndVersion(did: String, version: Int): Boolean { return DidUrl.isDidUrl(did) && DidUrl.from(did).let { didUrl -> - didUrl.method == DidMethod.ebsi.name && Multibase.decode(didUrl.identifier).first().toInt() == 2 + didUrl.method == DidMethod.ebsi.name && Multibase.decode(didUrl.identifier).first().toInt() == version } }