Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.exploit.keeper.controller.external

import com.linecorp.armeria.server.ServerBuilder
import jakarta.inject.Singleton
import org.exploit.keeper.constant.common.ErrorType
import org.exploit.keeper.constant.permission.Permission
import org.exploit.keeper.controller.support.ControllerSupport
import org.exploit.keeper.exception.TKeeperException
import org.exploit.keeper.model.api.incoming.Sign
import org.exploit.keeper.service.compose.KeeperComposer
import org.exploit.keeper.util.extension.http.hasPermission
import org.exploit.keeper.util.validation.InputValidator

@Singleton
class ComposeController(
private val composer: KeeperComposer,
private val support: ControllerSupport
): ExternalController {
override fun register(sb: ServerBuilder) = with(support) {
sb.publicPost("/v2/keeper/compose", Sign::class.java) { ctx, body ->
if (!ctx.hasPermission(Permission.keySign(body.keyId)))
throw TKeeperException(ErrorType.ACCESS_DENIED)

if (!InputValidator.isValidKeyId(body.keyId))
throw TKeeperException(ErrorType.INVALID_KEY_ID)

composer.compose(body)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.exploit.keeper.model.api.outgoing

import org.exploit.keeper.model.capability.HasImposters
import org.exploit.keeper.model.outcome.Outcome

data class CalculatedSignature(
val type: String,
val signature64: String? = null,
val generation: Int,
override val imposters: List<String>,
): HasImposters
): HasImposters, Outcome
3 changes: 3 additions & 0 deletions src/main/kotlin/org/exploit/keeper/model/outcome/Outcome.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.exploit.keeper.model.outcome

interface Outcome
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.exploit.keeper.service.compose

import jakarta.inject.Singleton
import org.exploit.keeper.model.api.incoming.Sign
import org.exploit.keeper.model.outcome.Outcome
import org.exploit.keeper.service.compose.spi.Composer
import org.exploit.keeper.service.signature.registry.SigningSessionManager
import org.exploit.keeper.util.extension.equalsIgnoreCase

@Singleton
class KeeperComposer(private val manager: SigningSessionManager, private val composers: List<Composer>) {
fun compose(body: Sign): Outcome {
val signature = manager.coordinate(body)

val command = body.command

val composer = composers.find {
it.type.equalsIgnoreCase(body.command.type)
} ?: return signature

return composer.compose(command, signature)
}
}
11 changes: 11 additions & 0 deletions src/main/kotlin/org/exploit/keeper/service/compose/spi/Composer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.exploit.keeper.service.compose.spi

import org.exploit.keeper.model.api.outgoing.CalculatedSignature
import org.exploit.keeper.model.command.Command
import org.exploit.keeper.model.outcome.Outcome

interface Composer {
val type: String

fun compose(command: Command, signature: CalculatedSignature): Outcome
}