Skip to content

Commit

Permalink
Run spotless and add TestContext
Browse files Browse the repository at this point in the history
  • Loading branch information
Jdu278 committed Aug 7, 2024
1 parent e5be5e5 commit 323d2f8
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 18 deletions.
3 changes: 0 additions & 3 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version("0.6.0")

}

dependencyResolutionManagement {
Expand All @@ -10,9 +9,7 @@ dependencyResolutionManagement {
maven {
url = uri("https://jitpack.io")
}

}
}

rootProject.name = "eudi-srv-web-verifier-endpoint-23220-4-kt"

Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ private fun Environment.clientMetaData(publicUrl: String): ClientMetaData {
zkpOption = WalletApi.requestZkpKey(publicUrl),
vpFormats = mapOf(
"vc+sd-jwt+zkp" to VpFormat(listOf("secp256r1-sha256")),
"mso_mdoc+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 @@ -64,7 +64,7 @@ class WalletApi(
GET(JARM_JWK_SET_PATH, this@WalletApi::handleGetJarmJwks)
POST(
ZKP_JWK_SET_PATH,
this@WalletApi::handlePostZkpJwk
this@WalletApi::handlePostZkpJwk,
)
}

Expand Down Expand Up @@ -119,7 +119,8 @@ class WalletApi(
logger.info(
response.fold(
{ "Verifier UI will poll for Wallet Response" },
{ "Wallet must redirect to ${it.redirectUri}" })
{ "Wallet must redirect to ${it.redirectUri}" },
),
)
ok().json().bodyValueAndAwait(response.getOrElse { JsonObject(emptyMap()) })
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ sealed interface Presentation {
}
}


class TimedOut private constructor(
override val id: TransactionId,
override val initiatedAt: Instant,
Expand Down Expand Up @@ -322,7 +321,6 @@ sealed interface Presentation {
}
}


fun Presentation.isExpired(at: Instant): Boolean {
fun Instant.isBeforeOrEqual(at: Instant) = isBefore(at) || this == at
return when (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ sealed interface JarmOption {
}

data class VpFormat(
val proofType: List<String>
val proofType: List<String>,
)

/**
Expand All @@ -94,7 +94,7 @@ data class ClientMetaData(
val subjectSyntaxTypesSupported: List<String>,
val jarmOption: JarmOption,
val zkpOption: EmbedOption<RequestId>,
val vpFormats: Map<String, VpFormat>
val vpFormats: Map<String, Any>,
)

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright (c) 2023 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
*
* 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.
*/
package eu.europa.ec.eudi.verifier.endpoint.port.input

import arrow.core.raise.Raise
Expand All @@ -14,7 +29,6 @@ import java.security.interfaces.ECPublicKey
import java.security.spec.X509EncodedKeySpec
import java.util.*


sealed interface ZkpJwkError {
data class ProcessingError(val message: String, val error: Throwable) : ZkpJwkError
}
Expand All @@ -23,7 +37,7 @@ data class ChallengeRequest(
val id: String,
val digest: String,
val r: String,
val proofType: String
val proofType: String,
)

data class EphemeralKeyResponse(
Expand All @@ -32,7 +46,7 @@ data class EphemeralKeyResponse(
val kty: String,
val crv: String,
val x: String,
val y: String
val y: String,
)

private const val publicKeyPEM = """
Expand All @@ -56,10 +70,8 @@ class PostZkpJwkRequestLive(
private val storePresentation: StorePresentation,
) : PostZkpJwkRequest {


context(Raise<ZkpJwkError>)
override suspend operator fun invoke(request: ServerRequest, requestId: RequestId): List<EphemeralKeyResponse> {

val pem = publicKeyPEM.replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", "")
val keyBytes = Base64.getDecoder().decode(pem)
val keySpec = X509EncodedKeySpec(keyBytes)
Expand Down Expand Up @@ -93,8 +105,8 @@ class PostZkpJwkRequestLive(
kty = "EC",
crv = "P-256",
x = x,
y = y
y = y,
)
}
}
}
}
19 changes: 19 additions & 0 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,6 +41,10 @@ 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 @@ -64,13 +68,28 @@ object TestContext {
RSAKey.load(keystore, "client-id", "".toCharArray())
}
}

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 Down

0 comments on commit 323d2f8

Please sign in to comment.