Skip to content

Commit

Permalink
chore: add revocation policy debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeplotean committed Feb 5, 2025
1 parent fd1d7c8 commit c2c32fa
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package id.walt.policies.policies

import io.github.oshai.kotlinlogging.KotlinLogging
import io.ktor.client.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.request.*
Expand All @@ -16,6 +17,8 @@ import java.util.zip.GZIPInputStream

@Serializable
actual class RevocationPolicy : RevocationPolicyMp() {
private val logger = KotlinLogging.logger {}

@JvmBlocking
@JvmAsync
actual override suspend fun verify(data: JsonObject, args: Any?, context: Map<String, Any>): Result<Any> {
Expand All @@ -24,8 +27,11 @@ actual class RevocationPolicy : RevocationPolicyMp() {
JsonObject(mapOf("policy_available" to JsonPrimitive(false)))
)

logger.debug { "Credential status: $credentialStatus" }
val statusListIndex = credentialStatus.jsonObject["statusListIndex"]?.jsonPrimitive?.content?.toULong()
val statusListCredentialUrl = credentialStatus.jsonObject["statusListCredential"]?.jsonPrimitive?.content
logger.debug { "Status list index: $statusListIndex" }
logger.debug { "Credential URL: $statusListCredentialUrl" }

val httpClient = HttpClient {
install(ContentNegotiation) {
Expand All @@ -36,10 +42,12 @@ actual class RevocationPolicy : RevocationPolicyMp() {
val response = runCatching { httpClient.get(statusListCredentialUrl!!).bodyAsText() }.getOrElse {
return Result.failure(Throwable("Error when getting Status List Credential from $statusListCredentialUrl"))
}
logger.debug { "Credential URL response: $response" }
// response is a jwt
val bitValue = getRevocationStatusValue(response, statusListIndex).getOrElse {
return Result.failure(Throwable(it.cause))
}

checkStatus(bitValue).getOrElse {
return Result.failure(Throwable("Credential has been revoked"))
}
Expand All @@ -57,9 +65,13 @@ actual class RevocationPolicy : RevocationPolicyMp() {
val payload = response.substringAfter(".").substringBefore(".")
.let { Json.decodeFromString<JsonObject>(Base64Utils.decode(it).decodeToString()) }

logger.debug { "Payload: $payload" }
val credentialSubject = payload["vc"]!!.jsonObject["credentialSubject"]?.jsonObject!!
logger.debug { "CredentialSubject: $credentialSubject" }
val encodedList = credentialSubject["encodedList"]?.jsonPrimitive?.content ?: ""
logger.debug { "EncodedList: $encodedList" }
val bitValue = get(encodedList, statusListIndex)
logger.debug { "EncodedList[$statusListIndex] = $bitValue" }
// ensure bitValue always consists of valid binary characters (0,1)
require(!bitValue.isNullOrEmpty()) { "Null or empty bit value" }
require(isBinaryValue(bitValue)) { "Invalid bit value: $bitValue" }
Expand Down

0 comments on commit c2c32fa

Please sign in to comment.