Skip to content

Commit

Permalink
refresh cNonce after each issuer response; update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vkanellopoulos committed Jun 18, 2024
1 parent 8b7a48c commit edcc6ad
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ object [Companion](index.md)
| Name | Summary |
|---------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [invoke](invoke.md) | [androidJvm]<br>operator fun [invoke](invoke.md)(block: [OpenId4VciManager.Config.Builder](../-builder/index.md).() -&gt; [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)): [OpenId4VciManager.Config](../index.md)<br>Create an instance of [Config](../index.md) |
| [make](make.md) | [androidJvm]<br>fun [make](make.md)(block: [OpenId4VciManager.Config.Builder](../-builder/index.md).() -&gt; [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)): [OpenId4VciManager.Config](../index.md)<br>Create an instance of [Config](../index.md) |
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ operator fun [invoke](invoke.md)(block: [OpenId4VciManager.Config.Builder](../-b
-&gt; [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)): [OpenId4VciManager.Config](../index.md)

Create an instance of [Config](../index.md)

#### Parameters

androidJvm

| | |
|-------|------------------------------------------------------------|
| block | the block to configure the [Builder](../-builder/index.md) |
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//[wallet-core](../../../../../index.md)/[eu.europa.ec.eudi.wallet.issue.openid4vci](../../../index.md)/[OpenId4VciManager](../../index.md)/[Config](../index.md)/[Companion](index.md)/[make](make.md)

# make

[androidJvm]\
fun [make](make.md)(block: [OpenId4VciManager.Config.Builder](../-builder/index.md).()
-&gt; [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)): [OpenId4VciManager.Config](../index.md)

Create an instance of [Config](../index.md)

#### Parameters

androidJvm

| | |
|-------|------------------------------------------------------------|
| block | the block to configure the [Builder](../-builder/index.md) |
1 change: 1 addition & 0 deletions docs/wallet-core/package-list
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ $dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Conf
$dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Config.Builder/withIssuerUrl/#kotlin.String/PointingToDeclaration/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-config/-builder/with-issuer-url.md
$dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Config.Companion///PointingToDeclaration/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-config/-companion/index.md
$dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Config.Companion/invoke/#kotlin.Function1[eu.europa.ec.eudi.wallet.issue.openid4vci.OpenId4VciManager.Config.Builder,kotlin.Unit]/PointingToDeclaration/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-config/-companion/invoke.md
$dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Config.Companion/make/#kotlin.Function1[eu.europa.ec.eudi.wallet.issue.openid4vci.OpenId4VciManager.Config.Builder,kotlin.Unit]/PointingToDeclaration/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-config/-companion/make.md
$dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Config.LogLevel.Companion///PointingToDeclaration/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-config/-log-level/-companion/index.md
$dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Config.LogLevel.Companion/DEBUG/#/PointingToDeclaration/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-config/-log-level/-companion/-d-e-b-u-g.md
$dokka.location:eu.europa.ec.eudi.wallet.issue.openid4vci/OpenId4VciManager.Config.LogLevel.Companion/DEBUG_WITH_HTTP/#/PointingToDeclaration/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-open-id4-vci-manager/-config/-log-level/-companion/-d-e-b-u-g_-w-i-t-h_-h-t-t-p.md
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import org.bouncycastle.util.encoders.Hex
import java.net.URI
import java.util.*
import java.util.concurrent.Executor
import java.util.concurrent.atomic.AtomicReference

/**
* Default implementation of [OpenId4VciManager].
Expand Down Expand Up @@ -224,7 +225,7 @@ internal class DefaultOpenId4VciManager(
).getOrThrow()

val addedDocuments = mutableSetOf<DocumentId>()

val cNonceHolder = AtomicReference<CNonce>().apply { update(authorizedRequest) }
offer.offeredDocuments.forEach { item ->
val issuanceRequest = documentManager
.createIssuanceRequest(item, config.useStrongBoxIfSupported)
Expand All @@ -237,10 +238,12 @@ internal class DefaultOpenId4VciManager(
item.configurationIdentifier,
item.configuration,
issuanceRequest,
cNonceHolder,
addedDocuments,
onEvent
)
}
cNonceHolder.set(null)
onEvent(IssueEvent.Finished(addedDocuments.toList()))
}
}
Expand Down Expand Up @@ -271,6 +274,7 @@ internal class DefaultOpenId4VciManager(
* @param credentialConfigurationIdentifier The credential configuration identifier.
* @param credentialConfiguration The credential configuration.
* @param issuanceRequest The issuance request.
* @param cNonceHolder The cNonce holder. Holds the fresh cNonce.
* @param addedDocuments The added documents.
* @param onEvent The event listener.
* @throws Exception If an error occurs during the issuance.
Expand All @@ -281,6 +285,7 @@ internal class DefaultOpenId4VciManager(
credentialConfigurationIdentifier: CredentialConfigurationIdentifier,
credentialConfiguration: CredentialConfiguration,
issuanceRequest: IssuanceRequest,
cNonceHolder: AtomicReference<CNonce>,
addedDocuments: MutableSet<DocumentId>,
onEvent: OpenId4VciManager.OnResult<IssueEvent>
) {
Expand All @@ -293,15 +298,17 @@ internal class DefaultOpenId4VciManager(
payload,
credentialConfiguration,
issuanceRequest,
cNonceHolder,
addedDocuments,
onEvent
)

is AuthorizedRequest.ProofRequired -> doRequestSingleWithProof(
authRequest,
authRequest.copy(cNonce = cNonceHolder.get()),
payload,
credentialConfiguration,
issuanceRequest,
cNonceHolder,
addedDocuments,
onEvent
)
Expand All @@ -314,6 +321,7 @@ internal class DefaultOpenId4VciManager(
* @param payload The issuance request payload.
* @param credentialConfiguration The credential configuration.
* @param issuanceRequest The issuance request.
* @param cNonceHolder The cNonce holder. Holds the fresh cNonce.
* @param addedDocuments The added documents.
* @param onEvent The event listener.
* @receiver The issuer.
Expand All @@ -324,18 +332,22 @@ internal class DefaultOpenId4VciManager(
payload: IssuanceRequestPayload,
credentialConfiguration: CredentialConfiguration,
issuanceRequest: IssuanceRequest,
cNonceHolder: AtomicReference<CNonce>,
addedDocuments: MutableSet<DocumentId>,
onEvent: OpenId4VciManager.OnResult<IssueEvent>
) {
logDebug("doRequestSingleNoProof for ${issuanceRequest.documentId}")
when (val outcome = authRequest.requestSingle(payload).getOrThrow()) {
val outcome = authRequest.requestSingle(payload).getOrThrow()
cNonceHolder.update(outcome)
when (outcome) {
is SubmittedRequest.InvalidProof -> {
logDebug("doRequestSingleNoProof invalid proof")
doRequestSingleWithProof(
authRequest.handleInvalidProof(outcome.cNonce),
payload,
credentialConfiguration,
issuanceRequest,
cNonceHolder,
addedDocuments,
onEvent
)
Expand All @@ -361,6 +373,7 @@ internal class DefaultOpenId4VciManager(
* @param payload The issuance request payload.
* @param credentialConfiguration The credential configuration.
* @param issuanceRequest The issuance request.
* @param cNonceHolder The cNonce holder. Holds the fresh cNonce.
* @param addedDocuments The added documents.
* @param onEvent The event listener.
* @receiver The issuer.
Expand All @@ -371,6 +384,7 @@ internal class DefaultOpenId4VciManager(
payload: IssuanceRequestPayload,
credentialConfiguration: CredentialConfiguration,
issuanceRequest: IssuanceRequest,
cNonceHolder: AtomicReference<CNonce>,
addedDocuments: MutableSet<DocumentId>,
onEvent: OpenId4VciManager.OnResult<IssueEvent>
) {
Expand All @@ -379,8 +393,7 @@ internal class DefaultOpenId4VciManager(
logDebug("doRequestSingleWithProof proofSigner: ${proofSigner::class.java.name}")
try {
val outcome = authRequest.requestSingle(payload, proofSigner.popSigner).getOrThrow()
// refresh cNonce for next issuing
// outcome.cNonce
cNonceHolder.update(outcome)
when (outcome) {
is SubmittedRequest.Failed -> {
clearFailedIssuance(issuanceRequest)
Expand All @@ -403,6 +416,7 @@ internal class DefaultOpenId4VciManager(
onEvent,
addedDocuments
)

}

} catch (e: Throwable) {
Expand All @@ -418,6 +432,7 @@ internal class DefaultOpenId4VciManager(
payload,
credentialConfiguration,
issuanceRequest,
cNonceHolder,
addedDocuments,
onEvent
)
Expand All @@ -437,6 +452,41 @@ internal class DefaultOpenId4VciManager(
}
}

/**
* Updates the cNonce.
* @param authRequest The authorized request.
* @receiver The cNonce holder.
*/
private fun AtomicReference<CNonce>.update(authRequest: AuthorizedRequest) {
when (authRequest) {
is AuthorizedRequest.NoProofRequired -> {}
is AuthorizedRequest.ProofRequired -> {
val prev = getAndSet(authRequest.cNonce)
logDebug("cNonceUpdate: $prev -> ${authRequest.cNonce}")
}
}
}

/**
* Updates the cNonce.
* @param submittedRequest The submitted request.
* @receiver The cNonce holder.
*/
private fun AtomicReference<CNonce>.update(submittedRequest: SubmittedRequest) {
when (submittedRequest) {
is SubmittedRequest.Failed -> {}
is SubmittedRequest.InvalidProof -> {
val prev = getAndSet(submittedRequest.cNonce)
logDebug("cNonceUpdate: $prev -> ${submittedRequest.cNonce}")
}

is SubmittedRequest.Success -> {
val prev = getAndSet(submittedRequest.cNonce)
logDebug("cNonceUpdate: $prev -> ${submittedRequest.cNonce}")
}
}
}

/**
* Stores the issued credential.
* @param issuedCredential The issued credential.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*
* 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.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package eu.europa.ec.eudi.wallet.documentsTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*
* 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.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package eu.europa.ec.eudi.wallet.documentsTest.util
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*
* 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.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package eu.europa.ec.eudi.wallet.internal
Expand Down

0 comments on commit edcc6ad

Please sign in to comment.