Skip to content

Commit 60c0d6c

Browse files
committed
Add controller parameters violation
1 parent aae8a44 commit 60c0d6c

File tree

12 files changed

+58
-34
lines changed

12 files changed

+58
-34
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ repositories {
2222
dependencies {
2323
implementation 'io.quarkiverse.loggingsentry:quarkus-logging-sentry:2.1.3'
2424
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
25+
implementation("io.quarkus:quarkus-hibernate-validator")
2526
implementation 'io.quarkus:quarkus-rest'
2627
implementation 'io.quarkus:quarkus-rest-jackson'
2728
implementation 'io.quarkus:quarkus-config-yaml'

src/main/kotlin/org/exploit/keeper/component/JacksonCustomizer.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class JacksonCustomizer: ObjectMapperCustomizer {
4242
if (value.signum() < 0) {
4343
hex = "-$hex"
4444
}
45+
4546
gen.writeString(hex)
4647
}
4748

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.exploit.keeper.component.exception
2+
3+
import jakarta.validation.ConstraintViolationException
4+
import jakarta.ws.rs.core.Response
5+
import jakarta.ws.rs.ext.ExceptionMapper
6+
import jakarta.ws.rs.ext.Provider
7+
8+
@Provider
9+
class ConstrainValidationException: ExceptionMapper<ConstraintViolationException> {
10+
override fun toResponse(p0: ConstraintViolationException): Response {
11+
return Response.status(Response.Status.BAD_REQUEST)
12+
.build()
13+
}
14+
}

src/main/kotlin/org/exploit/keeper/controller/keeper/CentralController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.exploit.keeper.controller.keeper
22

3-
import io.smallrye.common.constraint.NotNull
43
import io.smallrye.mutiny.Uni
4+
import jakarta.validation.constraints.NotNull
55
import jakarta.ws.rs.GET
66
import jakarta.ws.rs.Path
77
import jakarta.ws.rs.QueryParam

src/main/kotlin/org/exploit/keeper/controller/keeper/KeyGenController.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.exploit.keeper.controller.keeper
22

33
import io.smallrye.mutiny.Uni
4+
import jakarta.validation.constraints.NotNull
45
import jakarta.ws.rs.POST
56
import jakarta.ws.rs.Path
67
import jakarta.ws.rs.container.ContainerRequestContext
@@ -18,7 +19,7 @@ class KeyGenController(
1819
) {
1920
@POST
2021
@Path("/generate")
21-
fun generate(body: Generate): Uni<Void> {
22+
fun generate(@NotNull body: Generate): Uni<Void> {
2223
policyChecker.ensureHasPermission(ctx, Permission.generateKey())
2324

2425
return dkg.generateKey(

src/main/kotlin/org/exploit/keeper/controller/keeper/SignatureController.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.exploit.keeper.controller.keeper
22

33
import io.quarkus.arc.All
44
import io.smallrye.mutiny.Uni
5+
import jakarta.validation.constraints.NotNull
56
import jakarta.ws.rs.BadRequestException
67
import jakarta.ws.rs.POST
78
import jakarta.ws.rs.Path
@@ -31,7 +32,7 @@ class SignatureController(
3132
) {
3233
@POST
3334
@Path("/sign")
34-
fun sign(body: Sign): Uni<TSSResult> {
35+
fun sign(@NotNull body: Sign): Uni<TSSResult> {
3536
policyChecker.ensureHasPermission(ctx, Permission.keySign(body.keyId))
3637

3738
if (!keeper.initialized() || keeper.sealed())
@@ -45,7 +46,7 @@ class SignatureController(
4546

4647
@POST
4748
@Path("/sign/verify")
48-
fun verify(body: Verify): Uni<VerifyResult> {
49+
fun verify(@NotNull body: Verify): Uni<VerifyResult> {
4950
policyChecker.ensureHasPermission(ctx, Permission.keyVerify(body.keyId))
5051

5152
if (!keeper.initialized() || keeper.sealed())

src/main/kotlin/org/exploit/keeper/controller/keeper/StorageController.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.exploit.keeper.controller.keeper
22

3+
import jakarta.validation.constraints.NotNull
34
import jakarta.ws.rs.Path
45
import jakarta.ws.rs.container.ContainerRequestContext
56
import org.exploit.keeper.constant.Permission
@@ -16,7 +17,7 @@ class StorageController(
1617
) {
1718
@Path("/store")
1819
@ResponseStatus(204)
19-
fun store(body: Store) {
20+
fun store(@NotNull body: Store) {
2021
policyChecker.ensureHasPermission(ctx, Permission.storageWrite())
2122
storage.store(body)
2223
}

src/main/kotlin/org/exploit/keeper/controller/keeper/SystemController.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.exploit.keeper.controller.keeper
22

3+
import jakarta.validation.constraints.NotNull
34
import jakarta.ws.rs.*
45
import jakarta.ws.rs.container.ContainerRequestContext
56
import org.exploit.keeper.constant.Permission
@@ -32,7 +33,7 @@ class SystemController(
3233

3334
@PUT
3435
@Path("/unseal")
35-
fun unseal(req: Unseal): Progress {
36+
fun unseal(@NotNull req: Unseal): Progress {
3637
policyChecker.ensureHasPermission(ctx, Permission.systemUnseal())
3738

3839
val payloads = buildList {

src/main/kotlin/org/exploit/keeper/controller/key/PublicKeyController.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.exploit.keeper.controller.key
22

3+
import jakarta.validation.constraints.NotNull
34
import jakarta.ws.rs.GET
45
import jakarta.ws.rs.Path
56
import org.exploit.keeper.extension.toBase64
@@ -10,6 +11,6 @@ import org.exploit.keeper.service.pub.share.PublicKeyShareCalculator
1011
class PublicKeyController(private val pubShare: PublicKeyShareCalculator) {
1112
@GET
1213
@Path("/{keyId}")
13-
fun getPublicKey(keyId: String): PublicKeyDto =
14+
fun getPublicKey(@NotNull keyId: String): PublicKeyDto =
1415
PublicKeyDto(pubShare.pubKeyShare(keyId).share.encode(true).toBase64())
1516
}

src/main/kotlin/org/exploit/keeper/controller/keygen/SystemKeyGenController.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.exploit.keeper.controller.keygen
22

33
import io.smallrye.mutiny.Uni
4+
import jakarta.validation.constraints.NotNull
45
import jakarta.ws.rs.*
56
import org.exploit.keeper.api.auth.KeeperAuthenticator
67
import org.exploit.keeper.constant.CurveName
@@ -18,27 +19,27 @@ class SystemKeyGenController(
1819
@POST
1920
@Path("/init")
2021
fun init(
21-
@QueryParam("keyId") keyId: String,
22-
@QueryParam("curve") curve: CurveName,
23-
@QueryParam("overwrite") overwrite: Boolean
22+
@NotNull @QueryParam("keyId") keyId: String,
23+
@NotNull @QueryParam("curve") curve: CurveName,
24+
@QueryParam("overwrite") overwrite: Boolean?
2425
) {
25-
generator.init(keyId, KeeperCurve.fromName(curve), overwrite)
26+
generator.init(keyId, KeeperCurve.fromName(curve), overwrite ?: false)
2627
}
2728

2829
@POST
2930
@Path("/collect")
30-
fun collect(@QueryParam("keyId") keyId: String): Uni<Void> =
31+
fun collect(@NotNull @QueryParam("keyId") keyId: String): Uni<Void> =
3132
collector.collect(keyId).toUni()
3233

3334
@POST
3435
@Path("/compute")
35-
fun compute(@QueryParam("keyId") keyId: String) {
36+
fun compute(@NotNull @QueryParam("keyId") keyId: String) {
3637
generator.compute(keyId)
3738
}
3839

3940
@POST
4041
@Path("/abort")
41-
fun abort(@QueryParam("keyId") sessionId: String) {
42+
fun abort(@NotNull @QueryParam("keyId") sessionId: String) {
4243
generator.abort(sessionId)
4344
}
4445

src/main/kotlin/org/exploit/keeper/controller/signature/FrostController.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.exploit.keeper.controller.signature
22

33
import io.smallrye.mutiny.Uni
44
import jakarta.inject.Singleton
5+
import jakarta.validation.constraints.NotNull
56
import jakarta.ws.rs.*
67
import org.exploit.keeper.api.auth.KeeperAuthenticator
78
import org.exploit.keeper.constant.CurveName
@@ -21,7 +22,7 @@ class FrostController(
2122
) {
2223
@POST
2324
@Path("/init")
24-
fun init(body: InitSession) {
25+
fun init(@NotNull body: InitSession) {
2526
manager(body.curve).createSession(
2627
body.sessionId,
2728
body.keyId,
@@ -34,8 +35,8 @@ class FrostController(
3435
@POST
3536
@Path("/commitment")
3637
fun storeCommitment(
37-
@QueryParam("sessionId") sessionId: String,
38-
@HeaderParam(KeeperAuthenticator.HEADER_INSTANCE_ID) peerId: Int,
38+
@NotNull @QueryParam("sessionId") sessionId: String,
39+
@NotNull @HeaderParam(KeeperAuthenticator.HEADER_INSTANCE_ID) peerId: Int,
3940
body: FrostOperationCommitment
4041
) {
4142
manager(sessionId).respondent
@@ -45,22 +46,22 @@ class FrostController(
4546

4647
@POST
4748
@Path("/commitment/broadcast")
48-
fun broadcast(@QueryParam("sessionId") sessionId: String): Uni<Void> =
49+
fun broadcast(@NotNull @QueryParam("sessionId") sessionId: String): Uni<Void> =
4950
manager(sessionId).respondent
5051
.commitment
5152
.broadcast(sessionId)
5253
.toUni()
5354

5455
@GET
5556
@Path("/signature/z")
56-
fun computeZ(@QueryParam("sessionId") sessionId: String): ComputedZ =
57+
fun computeZ(@NotNull @QueryParam("sessionId") sessionId: String): ComputedZ =
5758
manager(sessionId).respondent
5859
.sigPart
5960
.computeZ(sessionId)
6061

6162
@GET
6263
@Path("/abort")
63-
fun abort(@QueryParam("sessionId") sessionId: String) {
64+
fun abort(@NotNull @QueryParam("sessionId") sessionId: String) {
6465
manager(sessionId).clear(sessionId)
6566
}
6667

src/main/kotlin/org/exploit/keeper/controller/signature/GG20Controller.kt

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.exploit.keeper.controller.signature
22

33
import io.smallrye.mutiny.Uni
44
import jakarta.inject.Singleton
5+
import jakarta.validation.constraints.NotNull
56
import jakarta.ws.rs.*
67
import org.exploit.gmp.BigInt
78
import org.exploit.keeper.api.auth.KeeperAuthenticator
@@ -26,7 +27,7 @@ class GG20Controller(
2627
) {
2728
@POST
2829
@Path("/init")
29-
fun init(session: InitSession) {
30+
fun init(@NotNull session: InitSession) {
3031
manager(session.curve).createSession(
3132
sessionId = session.sessionId,
3233
keyId = session.keyId,
@@ -39,9 +40,9 @@ class GG20Controller(
3940
@POST
4041
@Path("/commitment")
4142
fun storeCommitment(
42-
@QueryParam("sessionId") sessionId: String,
43-
@HeaderParam(KeeperAuthenticator.HEADER_INSTANCE_ID) peerId: Int,
44-
body: GG20GammaCommitmentDto
43+
@NotNull @QueryParam("sessionId") sessionId: String,
44+
@NotNull @HeaderParam(KeeperAuthenticator.HEADER_INSTANCE_ID) peerId: Int,
45+
@NotNull body: GG20GammaCommitmentDto
4546
) {
4647
manager(sessionId).respondent.commitment
4748
.storeCommitment(sessionId, peerId, body)
@@ -50,7 +51,7 @@ class GG20Controller(
5051
@POST
5152
@Path("/commitment/broadcast")
5253
fun broadcast(
53-
@QueryParam("sessionId") sessionId: String
54+
@NotNull @QueryParam("sessionId") sessionId: String
5455
): Uni<Void> =
5556
manager(sessionId).respondent
5657
.commitment
@@ -59,16 +60,16 @@ class GG20Controller(
5960

6061
@POST
6162
@Path("/mta/exchange")
62-
fun exchange(@QueryParam("sessionId") sessionId: String): Uni<Void> =
63+
fun exchange(@NotNull @QueryParam("sessionId") sessionId: String): Uni<Void> =
6364
manager(sessionId).respondent.mta
6465
.exchange(sessionId)
6566
.toUni()
6667

6768
@POST
6869
@Path("/mta/compute")
6970
fun compute(
70-
@HeaderParam(KeeperAuthenticator.HEADER_INSTANCE_ID) idx: Int,
71-
body: GG20MtAComputeRequest
71+
@NotNull @HeaderParam(KeeperAuthenticator.HEADER_INSTANCE_ID) idx: Int,
72+
@NotNull body: GG20MtAComputeRequest
7273
): GG20MtAResult =
7374
manager(body.sessionId)
7475
.respondent.mta
@@ -77,31 +78,31 @@ class GG20Controller(
7778
@POST
7879
@Path("/prephase")
7980
fun storeOfflinePhase(
80-
@QueryParam("sessionId") sessionId: String,
81-
@HeaderParam(KeeperAuthenticator.HEADER_INSTANCE_ID) idx: Int,
82-
body: GG20OfflinePhaseData
81+
@NotNull @QueryParam("sessionId") sessionId: String,
82+
@NotNull @HeaderParam(KeeperAuthenticator.HEADER_INSTANCE_ID) idx: Int,
83+
@NotNull body: GG20OfflinePhaseData
8384
) {
8485
manager(sessionId).respondent.offlinePhase
8586
.store(sessionId, idx, body)
8687
}
8788

8889
@POST
8990
@Path("/prephase/broadcast")
90-
fun broadcastOfflinePhase(@QueryParam("sessionId") sessionId: String): Uni<Void> =
91+
fun broadcastOfflinePhase(@NotNull @QueryParam("sessionId") sessionId: String): Uni<Void> =
9192
manager(sessionId).respondent
9293
.offlinePhase
9394
.broadcast(sessionId)
9495
.toUni()
9596

9697
@GET
9798
@Path("/signature/s")
98-
fun computeS(@QueryParam("sessionId") sessionId: String): Value<BigInt> =
99+
fun computeS(@NotNull @QueryParam("sessionId") sessionId: String): Value<BigInt> =
99100
manager(sessionId).respondent.sigPart
100101
.computePartialS(sessionId, finalize = true)
101102

102103
@POST
103104
@Path("/abort")
104-
fun abort(@QueryParam("sessionId") sessionId: String) {
105+
fun abort(@NotNull @QueryParam("sessionId") sessionId: String) {
105106
manager(sessionId).clear(sessionId)
106107
}
107108

0 commit comments

Comments
 (0)