diff --git a/waltid-services/waltid-wallet-api/src/main/kotlin/id/walt/webwallet/service/credentials/status/StatusListCredentialStatusService.kt b/waltid-services/waltid-wallet-api/src/main/kotlin/id/walt/webwallet/service/credentials/status/StatusListCredentialStatusService.kt index 89c33f244..f835afcd4 100644 --- a/waltid-services/waltid-wallet-api/src/main/kotlin/id/walt/webwallet/service/credentials/status/StatusListCredentialStatusService.kt +++ b/waltid-services/waltid-wallet-api/src/main/kotlin/id/walt/webwallet/service/credentials/status/StatusListCredentialStatusService.kt @@ -1,5 +1,6 @@ package id.walt.webwallet.service.credentials.status +import id.walt.crypto.utils.Base64Utils.base64toBase64Url import id.walt.webwallet.service.BitStringValueParser import id.walt.webwallet.service.credentials.CredentialValidator import id.walt.webwallet.service.credentials.status.fetch.StatusListCredentialFetchFactory @@ -29,7 +30,7 @@ class StatusListCredentialStatusService( extractCredentialSubject(credential) ?: error("STATUS_RETRIEVAL_ERROR (-128)") credentialValidator.validate(entry.statusPurpose, subject.statusPurpose, subject.type, credential) .takeIf { it }?.let { - getStatusBit(subject.encodedList, entry.statusListIndex, subject.statusSize)?.let { + getStatusBit(subject.encodedList.base64toBase64Url(), entry.statusListIndex, subject.statusSize)?.let { val bit = it.joinToString("") CredentialStatusResult( type = entry.statusPurpose, @@ -40,10 +41,13 @@ class StatusListCredentialStatusService( } ?: error("STATUS_VERIFICATION_ERROR (-129)") } ?: error("Error parsing status list entry") - private fun extractCredentialSubject(credential: JsonObject): StatusListCredentialSubject? = - JsonUtils.tryGetData(credential, "credentialSubject")?.let { - json.decodeFromJsonElement(it) - } + private fun extractCredentialSubject(credential: JsonObject): StatusListCredentialSubject? = let { + JsonUtils.tryGetData(credential, "credentialSubject") ?: JsonUtils.tryGetData( + credential, "vc.credentialSubject" + ) + }?.let { + json.decodeFromJsonElement(it) + } private fun getStatusBit(bitstring: String, idx: ULong, bitSize: Int) = bitStringValueParser.get(bitstring, idx, bitSize) diff --git a/waltid-services/waltid-wallet-api/src/main/kotlin/id/walt/webwallet/service/credentials/status/fetch/DefaultStatusListCredentialFetchStrategy.kt b/waltid-services/waltid-wallet-api/src/main/kotlin/id/walt/webwallet/service/credentials/status/fetch/DefaultStatusListCredentialFetchStrategy.kt index 3b7144632..72c2e4e74 100644 --- a/waltid-services/waltid-wallet-api/src/main/kotlin/id/walt/webwallet/service/credentials/status/fetch/DefaultStatusListCredentialFetchStrategy.kt +++ b/waltid-services/waltid-wallet-api/src/main/kotlin/id/walt/webwallet/service/credentials/status/fetch/DefaultStatusListCredentialFetchStrategy.kt @@ -1,5 +1,6 @@ package id.walt.webwallet.service.credentials.status.fetch +import id.walt.crypto.utils.JwsUtils.decodeJws import io.ktor.client.* import io.ktor.client.request.* import io.ktor.client.statement.* @@ -11,8 +12,9 @@ class DefaultStatusListCredentialFetchStrategy( ) : StatusListCredentialFetchStrategy { private val json = Json { ignoreUnknownKeys = true } - override suspend fun fetch(url: String): JsonObject = http.get(url).bodyAsText().let { - json.decodeFromString(it) + override suspend fun fetch(url: String): JsonObject = http.get(url).bodyAsText().let { content -> + runCatching { content.decodeJws().payload }.fold(onSuccess = { it }, onFailure = { + json.decodeFromString(content) + }) } - } \ No newline at end of file diff --git a/waltid-services/waltid-wallet-api/src/main/kotlin/id/walt/webwallet/service/credentials/status/fetch/StatusListCredentialFetchStrategy.kt b/waltid-services/waltid-wallet-api/src/main/kotlin/id/walt/webwallet/service/credentials/status/fetch/StatusListCredentialFetchStrategy.kt index e254f3731..76688f132 100644 --- a/waltid-services/waltid-wallet-api/src/main/kotlin/id/walt/webwallet/service/credentials/status/fetch/StatusListCredentialFetchStrategy.kt +++ b/waltid-services/waltid-wallet-api/src/main/kotlin/id/walt/webwallet/service/credentials/status/fetch/StatusListCredentialFetchStrategy.kt @@ -12,7 +12,7 @@ class StatusListCredentialFetchFactory( ) { private val didPattern = "^did:([^:]+):(.+)" private val urlPattern = - "^((https?:)(\\/\\/\\/?)([\\w]*(?::[\\w]*)?@)?([\\d\\w\\.-]+)(?::(\\d+))?)?([\\/\\\\w\\.()-]*)?(?:([?][^#]*)?(#.*)?)*" + "^https?:\\/\\/(?:www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,}\\.[a-zA-Z0-9()]{1,}\\b(?:[-a-zA-Z0-9()@:%_\\+.~#?&\\/=]*)\$" fun new(url: String) = when { didPattern.toRegex().matches(url) -> entraStrategy diff --git a/waltid-services/waltid-wallet-api/src/main/kotlin/id/walt/webwallet/usecase/credential/CredentialStatusUseCase.kt b/waltid-services/waltid-wallet-api/src/main/kotlin/id/walt/webwallet/usecase/credential/CredentialStatusUseCase.kt index 97cea602c..38e121aad 100644 --- a/waltid-services/waltid-wallet-api/src/main/kotlin/id/walt/webwallet/usecase/credential/CredentialStatusUseCase.kt +++ b/waltid-services/waltid-wallet-api/src/main/kotlin/id/walt/webwallet/usecase/credential/CredentialStatusUseCase.kt @@ -22,10 +22,12 @@ class CredentialStatusUseCase( } } ?: error("Credential not found or invalid document for id: $credentialId") + private val jsonModule = Json { ignoreUnknownKeys = true } + private fun getStatusEntry(json: JsonObject) = json.jsonObject["credentialStatus"]?.let { when (it) { - is JsonArray -> Json.decodeFromJsonElement>(it) - is JsonObject -> listOf(Json.decodeFromJsonElement(it)) + is JsonArray -> jsonModule.decodeFromJsonElement>(it) + is JsonObject -> listOf(jsonModule.decodeFromJsonElement(it)) else -> null } } ?: emptyList()