Skip to content

Commit

Permalink
Adjust metadata and add check for adding zkpOption
Browse files Browse the repository at this point in the history
  • Loading branch information
Jdu278 committed Aug 8, 2024
1 parent 323d2f8 commit 707d531
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ internal fun beans(clock: Clock) = beans {
WalletApi.requestJwtByReference(env.publicUrl()),
WalletApi.presentationDefinitionByReference(env.publicUrl()),
ref(),
WalletApi.requestZkpKey(env.publicUrl()),
)
}

Expand Down Expand Up @@ -351,11 +352,6 @@ private fun Environment.clientMetaData(publicUrl: String): ClientMetaData {
authorizationEncryptedResponseAlg,
authorizationEncryptedResponseEnc,
) ?: defaultJarmOption,
zkpOption = WalletApi.requestZkpKey(publicUrl),
vpFormats = mapOf(
"vc+sd-jwt+zkp" to VpFormat(listOf("secp256r1-sha256")),
"mso_mdoc+zkp" to VpFormat(listOf("secp256r1-sha256")),
),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ class SignRequestObjectNimbus : SignRequestObject {
jwkSet?.let { this.jwkSet = it }
jwkSetUri?.let { this.jwkSetURI = it.toURI() }
setCustomField("subject_syntax_types_supported", c.subjectSyntaxTypesSupported)
setCustomField("vp_formats", c.vpFormats)
setCustomField("vp_token_zkp_key_uri", (c.zkpOption as ByReference).buildUrl)

if ("direct_post.jwt" == responseMode) {
c.jarmOption.jwsAlg?.let { setCustomField("authorization_signed_response_alg", it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ sealed interface Presentation {
/**
* A presentation process that has been just requested
*/
class Requested(
data class Requested(
override val id: TransactionId,
override val initiatedAt: Instant,
override val type: PresentationType,
Expand All @@ -148,6 +148,7 @@ sealed interface Presentation {
val responseMode: ResponseModeOption,
val presentationDefinitionMode: EmbedOption<RequestId>,
val getWalletResponseMethod: GetWalletResponseMethod,
val zkpOption: EmbedOption<RequestId>? = null,
) : Presentation

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ data class ClientMetaData(
val idTokenEncryptedResponseEnc: String,
val subjectSyntaxTypesSupported: List<String>,
val jarmOption: JarmOption,
val zkpOption: EmbedOption<RequestId>,
val vpFormats: Map<String, Any>,
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package eu.europa.ec.eudi.verifier.endpoint.port.input
import arrow.core.raise.Raise
import arrow.core.raise.ensure
import arrow.core.raise.ensureNotNull
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import eu.europa.ec.eudi.prex.PresentationDefinition
import eu.europa.ec.eudi.verifier.endpoint.domain.*
import eu.europa.ec.eudi.verifier.endpoint.port.out.cfg.CreateQueryWalletResponseRedirectUri
Expand Down Expand Up @@ -149,7 +151,7 @@ class InitTransactionLive(
private val requestJarByReference: EmbedOption.ByReference<RequestId>,
private val presentationDefinitionByReference: EmbedOption.ByReference<RequestId>,
private val createQueryWalletResponseRedirectUri: CreateQueryWalletResponseRedirectUri,

private val zkpOption: EmbedOption.ByReference<RequestId>,
) : InitTransaction {

context(Raise<ValidationError>)
Expand All @@ -161,9 +163,8 @@ class InitTransactionLive(
val responseMode = responseMode(initTransactionTO)
val newEphemeralEcPublicKey = ephemeralEncryptionKeyPair(responseMode)
val getWalletResponseMethod = getWalletResponseMethod(initTransactionTO)

// Initialize presentation
val requestedPresentation = Presentation.Requested(
var requestedPresentation = Presentation.Requested(
id = generateTransactionId(),
initiatedAt = clock.instant(),
requestId = generateRequestId(),
Expand All @@ -174,6 +175,18 @@ class InitTransactionLive(
presentationDefinitionMode = presentationDefinitionMode(initTransactionTO),
getWalletResponseMethod = getWalletResponseMethod,
)

initTransactionTO.presentationDefinition?.format?.let { format ->
val objectMapper = ObjectMapper()
val json: JsonNode = objectMapper.valueToTree(format)

// add the zkp uri to the presentation if zkp is required
if (json.has("vc+sd-jwt+zkp") || json.has("mso_mdoc+zkp")) {
requestedPresentation = requestedPresentation.copy(
zkpOption = zkpOption,
)
}
}
// create request, which may update presentation
val (updatedPresentation, request) = createRequest(requestedPresentation, jarMode(initTransactionTO))

Expand Down
21 changes: 3 additions & 18 deletions src/test/kotlin/eu/europa/ec/eudi/verifier/endpoint/TestContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ import org.springframework.context.support.GenericApplicationContext
import org.springframework.core.annotation.AliasFor
import org.springframework.core.io.ClassPathResource
import org.springframework.test.context.ContextConfiguration
import java.net.URI
import java.net.URL
import java.net.URLConnection
import java.net.URLStreamHandler
import java.security.KeyStore
import java.time.Clock
import java.time.Instant
Expand All @@ -69,27 +65,13 @@ object TestContext {
}
}

class VpFormat
private val vpFormatExample = VpFormat()
private val vpFormats = mapOf("exampleFormat" to vpFormatExample)
val clientMetaData = ClientMetaData(
jwkOption = ByValue,
idTokenSignedResponseAlg = JWSAlgorithm.RS256.name,
idTokenEncryptedResponseAlg = JWEAlgorithm.RSA_OAEP_256.name,
idTokenEncryptedResponseEnc = EncryptionMethod.A128CBC_HS256.name,
subjectSyntaxTypesSupported = listOf("urn:ietf:params:oauth:jwk-thumbprint", "did:example", "did:key"),
jarmOption = ParseJarmOptionNimbus(null, JWEAlgorithm.ECDH_ES.name, "A256GCM")!!,
vpFormats = vpFormats,
zkpOption = EmbedOption.byReference {
URL.of(
URI("tt"),
object : URLStreamHandler() {
override fun openConnection(u: URL?): URLConnection {
TODO("Not yet implemented")
}
},
)
},
)
val jarSigningConfig: SigningConfig = SigningConfig(rsaJwk, JWSAlgorithm.RS256)
val clientIdScheme = ClientIdScheme.X509SanDns("client-id", jarSigningConfig)
Expand All @@ -105,6 +87,7 @@ object TestContext {
verifierConfig: VerifierConfig,
requestJarByReference: EmbedOption.ByReference<RequestId>,
presentationDefinitionByReference: EmbedOption.ByReference<RequestId>,
zkpOption: EmbedOption.ByReference<RequestId>,
): InitTransaction =
InitTransactionLive(
generatedTransactionId,
Expand All @@ -117,6 +100,8 @@ object TestContext {
requestJarByReference,
presentationDefinitionByReference,
CreateQueryWalletResponseRedirectUri.Simple,
zkpOption,

)

fun getRequestObject(verifierConfig: VerifierConfig, presentationInitiatedAt: Instant): GetRequestObject =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class InitTransactionTest {
verifierConfig,
EmbedOption.byReference { _ -> uri },
EmbedOption.byReference { _ -> uri },
EmbedOption.byReference { _ -> uri },
)

val jwtSecuredAuthorizationRequest = either { useCase(input) }.getOrElse { fail("Unexpected $it") }
Expand Down Expand Up @@ -93,6 +94,7 @@ class InitTransactionTest {
verifierConfig,
EmbedOption.byReference { _ -> uri },
EmbedOption.byReference { _ -> uri },
EmbedOption.byReference { _ -> uri },
)

val jwtSecuredAuthorizationRequest = either { useCase(input) }.getOrElse { fail("Unexpected $it") }
Expand Down Expand Up @@ -146,6 +148,7 @@ class InitTransactionTest {
verifierConfig,
EmbedOption.byReference { _ -> uri },
EmbedOption.byReference { _ -> uri },
EmbedOption.byReference { _ -> uri },
)

val jwtSecuredAuthorizationRequest = either { useCase(input) }.getOrElse { fail("Unexpected $it") }
Expand Down Expand Up @@ -173,6 +176,7 @@ class InitTransactionTest {
verifierConfig,
EmbedOption.byReference { _ -> uri },
EmbedOption.byReference { _ -> uri },
EmbedOption.byReference { _ -> uri },
)

// we expect the Authorization Request to contain a request_uri
Expand Down Expand Up @@ -200,6 +204,7 @@ class InitTransactionTest {
verifierConfig,
EmbedOption.byReference { _ -> uri },
EmbedOption.byReference { _ -> uri },
EmbedOption.byReference { _ -> uri },
)

// we expect the Authorization Request to contain a request that contains a presentation_definition_uri
Expand All @@ -221,6 +226,7 @@ class InitTransactionTest {
verifierConfig,
EmbedOption.byReference { _ -> uri },
EmbedOption.byReference { _ -> uri },
EmbedOption.byReference { _ -> uri },
)

val invalidPlaceHolderInput = InitTransactionTO(
Expand Down Expand Up @@ -277,6 +283,7 @@ class InitTransactionTest {
verifierConfig,
EmbedOption.byReference { _ -> uri },
EmbedOption.byReference { _ -> uri },
EmbedOption.byReference { _ -> uri },
)

either { useCase(input) }.getOrElse { fail("Unexpected $it") }
Expand All @@ -299,6 +306,7 @@ class InitTransactionTest {
verifierConfig,
EmbedOption.byReference { _ -> uri },
EmbedOption.byReference { _ -> uri },
EmbedOption.byReference { _ -> uri },
)

either { useCase(input) }.getOrElse { fail("Unexpected $it") }
Expand Down

0 comments on commit 707d531

Please sign in to comment.