Skip to content

Commit

Permalink
fix get metadata for xiaomi devices; add logs for document's public k…
Browse files Browse the repository at this point in the history
…ey on issuing
  • Loading branch information
vkanellopoulos committed Jan 26, 2024
1 parent b9664ea commit a2f17cd
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 11 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" }
Expand All @@ -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" }
Expand All @@ -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" }
Expand Down
3 changes: 3 additions & 0 deletions wallet-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -132,6 +138,7 @@ class OpenId4VciManager(
onResultUnderExecutor
)
} catch (e: Throwable) {
Log.e(TAG, "issueDocument", e)
onResultUnderExecutor(IssueDocumentResult.Failure(e))
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -91,6 +95,7 @@ internal class ProofSigner(
}

companion object {
private const val TAG = "ProofSigner"
private val algorithmMap = mapOf(
JWSAlgorithm.ES256 to Algorithm.SHA256withECDSA,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -53,17 +55,30 @@ 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") + "://"
+ getString("openid4vciAuthorizeHost", "localhost")
+ getString("openid4vciAuthorizePath", "/authorize")
)

}
}

@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()

0 comments on commit a2f17cd

Please sign in to comment.