From a2f17cd2ea01eafdae5d2c42b89f36c0955a4237 Mon Sep 17 00:00:00 2001 From: vkanellopoulos Date: Fri, 26 Jan 2024 12:59:20 +0200 Subject: [PATCH] fix get metadata for xiaomi devices; add logs for document's public key on issuing --- gradle.properties | 4 +-- gradle/libs.versions.toml | 4 +++ wallet-core/build.gradle | 3 ++ .../issue/openid4vci/OpenId4VciManager.kt | 9 +++++- .../document/issue/openid4vci/ProofSigner.kt | 7 ++++- .../ec/eudi/wallet/internal/Extensions.kt | 29 ++++++++++++++----- 6 files changed, 45 insertions(+), 11 deletions(-) diff --git a/gradle.properties b/gradle.properties index b74d9d71..14315a37 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 2023 European Commission +# Copyright (c) 2023-2024 European Commission # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -43,7 +43,7 @@ systemProp.sonar.gradle.skipCompile=true systemProp.sonar.coverage.jacoco.xmlReportPaths=build/reports/jacoco/testDebugUnitTestCoverage/testDebugUnitTestCoverage.xml,build/reports/jacoco/testReleaseUnitTestCoverage/testReleaseUnitTestCoverage.xml systemProp.sonar.projectName=eudi-lib-android-wallet-core -VERSION_NAME=0.3.1-SNAPSHOT +VERSION_NAME=0.3.2-SNAPSHOT SONATYPE_HOST=S01 SONATYPE_AUTOMATIC_RELEASE=false diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8ce9d3e5..96a608d4 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,6 +4,7 @@ biometricKtx = "1.1.0" bouncy-castle = "1.67" cbor = "0.9" coreTesting = "2.2.0" +coseJava = "1.1.0" dependency-license-report = "2.4" dependencycheck = "8.4.2" espresso-contrib = "3.5.1" @@ -31,6 +32,7 @@ sonarqube = "4.4.1.3373" test-core = "1.4.0" test-rules = "1.4.0" test-runner = "1.4.0" +upokecenter-cbor = "4.5.2" [libraries] android-identity-credential = { module = "com.android.identity:identity-credential-android", version.ref = "identity-credential-android" } @@ -41,6 +43,7 @@ bouncy-castle-pkix = { module = "org.bouncycastle:bcpkix-jdk15on", version.ref = bouncy-castle-prov = { module = "org.bouncycastle:bcprov-jdk15on", version.ref = "bouncy-castle" } cbor = { module = "co.nstant.in:cbor", version.ref = "cbor" } core-testing = { module = "androidx.arch.core:core-testing", version.ref = "coreTesting" } +cose-java = { module = "com.augustcellars.cose:cose-java", version.ref = "coseJava" } espresso-contrib = { module = "androidx.test.espresso:espresso-contrib", version.ref = "espresso-contrib" } espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "espresso-core" } espresso-intents = { module = "androidx.test.espresso:espresso-intents", version.ref = "espresso-core" } @@ -62,6 +65,7 @@ test-core = { module = "androidx.test:core", version.ref = "test-core" } test-coreKtx = { module = "androidx.test:core-ktx", version.ref = "test-core" } test-rules = { module = "androidx.test:rules", version.ref = "test-rules" } test-runner = { module = "androidx.test:runner", version.ref = "test-runner" } +upokecenter-cbor = { module = "com.upokecenter:cbor", version.ref = "upokecenter-cbor" } [plugins] android-library = { id = "com.android.library", version.ref = "gradle-plugin" } diff --git a/wallet-core/build.gradle b/wallet-core/build.gradle index a8456249..e67827d6 100644 --- a/wallet-core/build.gradle +++ b/wallet-core/build.gradle @@ -104,6 +104,9 @@ dependencies { implementation libs.bouncy.castle.prov implementation libs.bouncy.castle.pkix + implementation libs.upokecenter.cbor + implementation libs.cose.java + testImplementation libs.junit testImplementation libs.json testImplementation libs.mockk diff --git a/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/document/issue/openid4vci/OpenId4VciManager.kt b/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/document/issue/openid4vci/OpenId4VciManager.kt index c5e5c46b..ddbcea12 100644 --- a/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/document/issue/openid4vci/OpenId4VciManager.kt +++ b/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/document/issue/openid4vci/OpenId4VciManager.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 European Commission + * Copyright (c) 2023-2024 European Commission * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,6 +43,8 @@ import eu.europa.ec.eudi.wallet.document.DocumentManager import eu.europa.ec.eudi.wallet.document.IssuanceRequest import eu.europa.ec.eudi.wallet.document.issue.IssueDocumentResult import eu.europa.ec.eudi.wallet.document.issue.openid4vci.OpenId4VciManager.AuthorizationCallback +import eu.europa.ec.eudi.wallet.internal.coseBytes +import eu.europa.ec.eudi.wallet.internal.coseDebug import eu.europa.ec.eudi.wallet.internal.mainExecutor import eu.europa.ec.eudi.wallet.internal.openId4VciAuthorizationRedirectUri import kotlinx.coroutines.CoroutineScope @@ -124,6 +126,10 @@ class OpenId4VciManager( .apply { name = credential.name } + .also { + Log.d(TAG, "Document's PublicKey in COSE Bytes: ${it.publicKey.coseBytes}") + Log.d(TAG, "Document's PublicKey in COSE: ${it.publicKey.coseDebug}") + } issuer.handleAuthorizedRequest( authorizedRequest, @@ -132,6 +138,7 @@ class OpenId4VciManager( onResultUnderExecutor ) } catch (e: Throwable) { + Log.e(TAG, "issueDocument", e) onResultUnderExecutor(IssueDocumentResult.Failure(e)) } } diff --git a/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/document/issue/openid4vci/ProofSigner.kt b/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/document/issue/openid4vci/ProofSigner.kt index c4c745cb..172bb1a2 100644 --- a/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/document/issue/openid4vci/ProofSigner.kt +++ b/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/document/issue/openid4vci/ProofSigner.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 European Commission + * Copyright (c) 2023-2024 European Commission * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package eu.europa.ec.eudi.wallet.document.issue.openid4vci +import android.util.Log import androidx.biometric.BiometricPrompt.CryptoObject import com.nimbusds.jose.JOSEException import com.nimbusds.jose.JWSAlgorithm @@ -42,6 +43,9 @@ internal class ProofSigner( ) : BaseProofSigner { private val jwk = JWK.parseFromPEMEncodedObjects(issuanceRequest.publicKey.pem) + .also { + Log.d(TAG, "Document's PublicKey in JWK: ${it.toJSONString()}") + } var userAuthRequired: UserAuthRequired = UserAuthRequired.No private set @@ -91,6 +95,7 @@ internal class ProofSigner( } companion object { + private const val TAG = "ProofSigner" private val algorithmMap = mapOf( JWSAlgorithm.ES256 to Algorithm.SHA256withECDSA, ) diff --git a/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/internal/Extensions.kt b/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/internal/Extensions.kt index b1878d43..37164c8b 100644 --- a/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/internal/Extensions.kt +++ b/wallet-core/src/main/java/eu/europa/ec/eudi/wallet/internal/Extensions.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 European Commission + * Copyright (c) 2023-2024 European Commission * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,14 +16,16 @@ package eu.europa.ec.eudi.wallet.internal +import COSE.OneKey import android.content.Context -import android.content.pm.PackageManager.ApplicationInfoFlags import android.content.pm.PackageManager.GET_META_DATA import android.os.Build import androidx.annotation.RawRes import androidx.core.content.ContextCompat import kotlinx.coroutines.runBlocking +import org.bouncycastle.util.encoders.Hex import java.net.URI +import java.security.PublicKey import java.security.cert.CertificateFactory import java.security.cert.X509Certificate import java.util.concurrent.Executor @@ -53,12 +55,13 @@ internal fun Context.executeOnMain(block: suspend () -> Unit) { } @get:JvmSynthetic +@get:Suppress("DEPRECATION") +/** + * Keep deprecation for Xiaomi compatibility + */ internal val Context.openId4VciAuthorizationRedirectUri: URI get() = with( - packageManager.getApplicationInfo( - packageName, - ApplicationInfoFlags.of(GET_META_DATA.toLong()) - ).metaData + packageManager.getApplicationInfo(packageName, GET_META_DATA).metaData ) { URI.create( getString("openid4vciAuthorizeScheme", "https") + "://" @@ -66,4 +69,16 @@ internal val Context.openId4VciAuthorizationRedirectUri: URI + getString("openid4vciAuthorizePath", "/authorize") ) - } \ No newline at end of file + } + +@get:JvmSynthetic +internal val PublicKey.cose: OneKey + get() = OneKey(this, null) + +@get:JvmSynthetic +internal val PublicKey.coseBytes: String + get() = Hex.toHexString(cose.EncodeToBytes()) + +@get:JvmSynthetic +internal val PublicKey.coseDebug: String + get() = cose.AsCBOR().ToJSONString() \ No newline at end of file