Skip to content

Commit

Permalink
fix eu-digital-identity-wallet#60; log payload of issuing request; up…
Browse files Browse the repository at this point in the history
…date README.md
  • Loading branch information
vkanellopoulos committed Jun 10, 2024
1 parent 0681480 commit 859622f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 46 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,26 @@ The released software is a initial development release version:

### Dependencies

In order to use snapshot versions add the following to your project's settings.gradle file:

```groovy
dependencyResolutionManagement {
// ...
maven {
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
mavenContent { snapshotsOnly() }
}
// ...
}
```

To include the library in your project, add the following dependencies to your app's build.gradle
file.

```groovy
dependencies {
implementation "eu.europa.ec.eudi:eudi-lib-android-wallet-core:0.9.3-SNAPSHOT"
implementation "eu.europa.ec.eudi:eudi-lib-android-wallet-core:0.9.4-SNAPSHOT"
implementation "androidx.biometric:biometric-ktx:1.2.0-alpha05"
}
```
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ systemProp.sonar.host.url=https://sonarcloud.io
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.9.3-SNAPSHOT
VERSION_NAME=0.9.4-SNAPSHOT

SONATYPE_HOST=S01
SONATYPE_AUTOMATIC_RELEASE=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ internal class DefaultOpenId4VciManager(
addedDocuments: MutableSet<DocumentId>,
onEvent: OpenId4VciManager.OnResult<IssueEvent>
) {
val payload = IssuanceRequestPayload.ConfigurationBased(credentialConfigurationIdentifier, null)
val claimSet = null
val payload = IssuanceRequestPayload.ConfigurationBased(credentialConfigurationIdentifier, claimSet)
Log.d(TAG, "doIssueCredential payload: $payload")
when (authRequest) {
is AuthorizedRequest.NoProofRequired -> doRequestSingleNoProof(
authRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

package eu.europa.ec.eudi.wallet.issue.openid4vci

import android.security.keystore.KeyGenParameterSpec
import android.security.keystore.KeyProperties.DIGEST_SHA256
import android.security.keystore.KeyProperties.PURPOSE_SIGN
import com.nimbusds.jose.JOSEException
import com.nimbusds.jose.JWSAlgorithm
import com.nimbusds.jose.JWSHeader
Expand All @@ -29,11 +26,12 @@ import com.nimbusds.jose.jwk.JWK
import com.nimbusds.jose.util.Base64URL
import eu.europa.ec.eudi.openid4vci.JwtBindingKey
import eu.europa.ec.eudi.openid4vci.PopSigner
import org.bouncycastle.jce.provider.BouncyCastleProvider
import java.security.KeyPair
import java.security.KeyPairGenerator
import java.security.KeyStore
import java.security.Signature
import java.time.Instant
import java.util.*
import java.security.spec.ECGenParameterSpec


/**
* A [JWSSigner] implementation for DPoP.
Expand All @@ -45,15 +43,20 @@ import java.util.*
*/
internal class JWSDPoPSigner private constructor() : JWSSigner {

private val BC by lazy { BouncyCastleProvider() }
private val keyPair: KeyPair by lazy {
val kg: KeyPairGenerator = KeyPairGenerator.getInstance("EC", BC)
val params = ECGenParameterSpec("secp256r1")
kg.initialize(params)
kg.generateKeyPair()
}

private val jcaContext = JCAContext()

override fun getJCAContext(): JCAContext = jcaContext

private val keyStore: KeyStore
get() = KeyStore.getInstance("AndroidKeyStore").apply { load(null) }

private val jwk: JWK
get() = JWK.parseFromPEMEncodedObjects(keyStore.getCertificate(KEY_ALIAS).publicKey.pem)
get() = JWK.parseFromPEMEncodedObjects(keyPair.public.pem)

val popSigner: PopSigner.Jwt
get() = PopSigner.Jwt(
Expand All @@ -62,13 +65,6 @@ internal class JWSDPoPSigner private constructor() : JWSSigner {
jwsSigner = this
)

/**
* Initializes the DPoP signer by generating a key pair.
*/
init {
generateKeyPair()
}

override fun sign(header: JWSHeader, signingInput: ByteArray): Base64URL {
val algorithm = SupportedAlgorithms[header.algorithm]
?: throw JOSEException(
Expand All @@ -77,7 +73,7 @@ internal class JWSDPoPSigner private constructor() : JWSSigner {
supportedJWSAlgorithms()
)
)
val privateKey = (keyStore.getEntry(KEY_ALIAS, null) as KeyStore.PrivateKeyEntry).privateKey
val privateKey = keyPair.private
val signature = Signature.getInstance(algorithm).apply {
initSign(privateKey)
update(signingInput)
Expand All @@ -87,35 +83,10 @@ internal class JWSDPoPSigner private constructor() : JWSSigner {

override fun supportedJWSAlgorithms(): MutableSet<JWSAlgorithm> = SupportedAlgorithms.keys.toMutableSet()

/**
* Generates a key pair for DPoP.
*/
private fun generateKeyPair() {
if (keyStore.containsAlias(KEY_ALIAS)) {
keyStore.deleteEntry(KEY_ALIAS)
}
val now = Instant.now()
val notBefore = Date.from(now)
val notAfter = Date.from(now.plusSeconds(180L))
val keySpec = KeyGenParameterSpec.Builder(KEY_ALIAS, PURPOSE_SIGN)
.setDigests(DIGEST_SHA256)
.setUserAuthenticationRequired(false)
.setKeyValidityStart(notBefore)
.setKeyValidityEnd(notAfter)
.setCertificateNotBefore(notBefore)
.setCertificateNotAfter(notAfter)
.build()
with(KeyPairGenerator.getInstance("EC", "AndroidKeyStore")) {
initialize(keySpec)
generateKeyPair()
}
}

/**
* Companion object for the JWSDPoPSigner class.
*/
companion object {
private const val KEY_ALIAS = "eu.europa.ec.eudi.wallet.issue.openid4vci.DPoPKey"

/**
* Supported algorithms for DPoP.
Expand Down

0 comments on commit 859622f

Please sign in to comment.