Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #18: Issue on digest and disclosure order mismatch #19

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.ewc.eudi_wallet_oidc_android.models.PresentationRequest
import com.ewc.eudi_wallet_oidc_android.services.verification.VerificationService
import com.github.decentraliseddataexchange.presentationexchangesdk.models.MatchedCredential
import com.google.gson.Gson
import com.google.gson.JsonArray
import com.google.gson.JsonElement
import com.google.gson.JsonObject
import com.google.gson.JsonParser
Expand Down Expand Up @@ -155,7 +156,8 @@ class SDJWTService : SDJWTServiceInterface {
val jsonObject = Gson().fromJson(jsonString, JsonObject::class.java)

val hashList: MutableList<String> = mutableListOf()
val disclosures = getDisclosuresFromSDJWT(credential)
var disclosures = getDisclosuresFromSDJWT(credential)
disclosures = disclosures?.filter { it != null && it.isNotBlank() }
disclosures?.forEach { encodedString ->
try {
val hash = calculateSHA256Hash(encodedString)
Expand Down Expand Up @@ -185,8 +187,8 @@ class SDJWTService : SDJWTServiceInterface {
val sdList = jsonObject.getAsJsonArray("_sd")

hashList.forEachIndexed { index, hash ->
val sdKey = sdList[index].asString
if (hash == sdKey) {

if (isStringPresentInJSONArray(sdList, hash)) {
try {
val disclosure = Base64.decode(
disclosures[index],
Expand All @@ -212,6 +214,16 @@ class SDJWTService : SDJWTServiceInterface {
}
}

private fun isStringPresentInJSONArray(jsonArray: JsonArray, searchString: String): Boolean {
for (i in 0 until jsonArray.size()) {
val element = jsonArray.elementAt(i).asString
if (element == searchString) {
return true
}
}
return false
}

private fun extractKeyValue(decodedString: String): Pair<String, String> {
val jsonArray = JsonParser.parseString(decodedString).asJsonArray
val key = jsonArray[1].asString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ class VerificationService : VerificationServiceInterface {
val descriptor = DescriptorMap(
id = inputDescriptors.id,
path = "$",
format = "jwt_vp",
format = presentationDefinition.format?.keys?.first(),
pathNested = PathNested(
id = inputDescriptors.id,
format = "jwt_vc",
Expand Down