Skip to content

Commit

Permalink
Fix String.fromBase64Url() extension.
Browse files Browse the repository at this point in the history
Turns out that Base64.UrlSafe.decode() changed its behavior in Kotlin
2.0 and we missed this and EU PID documents no longer has SD-JWT VC
credentials as a result.

The root problem is that Base64.UrlSafe.decode() no longer ignores
padding and our API contract in String.fromBase64Url() extension says
it will. Fix this by using withPadding(PaddingOption.ABSENT_OPTIONAL)
available in Kotlin 2.0.21.

Also fix errornous credential.delete() call in the catch handler
invoked when that call had already thrown.

Test: EU PID now has SD-JWT VC credentials again.
Signed-off-by: David Zeuthen <[email protected]>
  • Loading branch information
davidz25 committed Nov 4, 2024
1 parent 322b109 commit 19cf25e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 17 deletions.
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ androidx-test-junit = "1.1.5"
compose-plugin = "1.7.0-rc01"
faceDetection = "16.1.6"
junit = "4.13.2"
kotlin = "2.0.0"
kotlin = "2.0.21"
kotlinx-coroutines = "1.8.1"
kotlinx-io = "0.4.0"
kotlinx-datetime = "0.6.0"
kotlinx-serialization = "1.7.0"
bouncy-castle = "1.78.1"
tink = "1.13.0"
jetbrainsKotlinJvm = "2.0.0"
ksp = "2.0.0-1.0.22"
jetbrainsKotlinJvm = "2.0.21"
ksp = "2.0.21-1.0.26"
androidx-biometrics = "1.2.0-alpha05"
volley = "1.2.1"
cbor = "0.9"
Expand Down
12 changes: 0 additions & 12 deletions identity/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ kotlin {
implementation(libs.kotlinx.coroutines.core)
implementation(libs.kotlinx.serialization.json)
}
languageSettings {
languageVersion = "1.9"
apiVersion = "1.9"
}
}

val commonTest by getting {
Expand All @@ -70,10 +66,6 @@ kotlin {
implementation(libs.kotlin.test)
implementation(libs.kotlinx.coroutine.test)
}
languageSettings {
languageVersion = "1.9"
apiVersion = "1.9"
}
}

val jvmMain by getting {
Expand All @@ -82,10 +74,6 @@ kotlin {
implementation(libs.bouncy.castle.bcpkix)
implementation(libs.tink)
}
languageSettings {
languageVersion = "1.9"
apiVersion = "1.9"
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ class Document private constructor(
// that secure area implementations do not use IllegalArgumentException for transient
// errors (like server connections).
Logger.e(TAG, "Error accessing $credentialType ${credential.identifier}, deleting it", err)
credential.delete()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.android.identity.util

import kotlin.io.encoding.Base64
import kotlin.io.encoding.Base64.PaddingOption
import kotlin.io.encoding.ExperimentalEncodingApi

/**
Expand All @@ -17,4 +18,6 @@ fun ByteArray.toBase64Url(): String = Base64.UrlSafe.encode(this).trimEnd('=')
* This works for both strings with or without padding.
*/
@OptIn(ExperimentalEncodingApi::class)
fun String.fromBase64Url(): ByteArray = Base64.UrlSafe.decode(this)
fun String.fromBase64Url(): ByteArray {
return Base64.UrlSafe.withPadding(PaddingOption.ABSENT_OPTIONAL).decode(this)
}

0 comments on commit 19cf25e

Please sign in to comment.