Spotless: exclude JOOQ generated code, run spotlessApply and fix task dependencies

This commit is contained in:
fiereu committed 2025-08-25 13:47:32 +02:00
1 parent 545d4321ab
commit 1c08dabd6d
13 files changed
+168 -187

No files matched your search

@@ -8,30 +8,29 @@ import java.security.interfaces.ECPrivateKey
import java.security.interfaces.ECPublicKey
/**
* TLS Protocol implementation.
* This protocol handles the initial TLS handshake before any secure communication can take place.
* TLS Protocol implementation. This protocol handles the initial TLS handshake before any secure
* communication can take place.
*
* The flow is as follows:
* 1. Client sends a ClientHello packet to initiate the handshake.
* 2. Server responds with a ServerHello packet.
* -> The client knows the servers public key and its own private key. And it can derive a shared secret using ECDH.
* -> Every packet the client now would receive is expected to be secured.
* -> Client switches to next protocol (e.g. LoginProtocol) after the handshake is complete.
* 3. Client sends a ClientReady packet with its public key.
* -> The server can now secure its communication with the client using the shared secret.
* -> Server switches to next protocol (e.g. LoginProtocol) after the handshake is complete.
* 2. Server responds with a ServerHello packet. -> The client knows the servers public key and its
* own private key. And it can derive a shared secret using ECDH. -> Every packet the client now
* would receive is expected to be secured. -> Client switches to next protocol (e.g.
* LoginProtocol) after the handshake is complete.
* 3. Client sends a ClientReady packet with its public key. -> The server can now secure its
* communication with the client using the shared secret. -> Server switches to next protocol
* (e.g. LoginProtocol) after the handshake is complete.
*/
abstract class TlsProtocol() : Protocol() {
abstract class TlsProtocol() : Protocol() {
override val async: Boolean
get() = false
}
class TlsServerProtocol(
serverKeyPair: Pair<ECPrivateKey, ECPublicKey>
) : TlsProtocol() {
class TlsServerProtocol(serverKeyPair: Pair<ECPrivateKey, ECPublicKey>) : TlsProtocol() {
init {
incomingPacket(0x00u, ClientHelloPacketDeserializer())
outgoingPacket(0x01u, ServerHelloPacket::class, ServerHelloPacketSerializer(serverKeyPair.first))
outgoingPacket(
0x01u, ServerHelloPacket::class, ServerHelloPacketSerializer(serverKeyPair.first))
incomingPacket(0x02u, ClientReadyPacketDeserializer())
}
}
@@ -43,4 +42,3 @@ class TlsClientProtocol() : TlsProtocol() {
outgoingPacket(0x02u, ClientReadyPacket::class, ClientReadyPacketSerializer())
}
}
@@ -7,9 +7,7 @@ import de.fiereu.openmmo.protocols.tls.util.toUncompressedPoint
import io.netty.buffer.ByteBuf
import java.security.interfaces.ECPublicKey
data class ClientReadyPacket(
val clientPublicKey: ECPublicKey
)
data class ClientReadyPacket(val clientPublicKey: ECPublicKey)
class ClientReadyPacketSerializer : PacketSerializer<ClientReadyPacket> {
@@ -16,14 +16,10 @@ import java.security.interfaces.ECPublicKey
* @property publicKey The public key generated for this connection.
* @property checksumSize The size of the checksum used for this connection.
*/
data class ServerHelloPacket(
val publicKey: ECPublicKey,
val checksumSize: Int
)
data class ServerHelloPacket(val publicKey: ECPublicKey, val checksumSize: Int)
class ServerHelloPacketSerializer(
private val serverRootPrivateKey: ECPrivateKey
) : PacketSerializer<ServerHelloPacket> {
class ServerHelloPacketSerializer(private val serverRootPrivateKey: ECPrivateKey) :
PacketSerializer<ServerHelloPacket> {
override fun serialize(packet: ServerHelloPacket, buffer: ByteBuf) {
val publicKeyBytes = packet.publicKey.toUncompressedPoint()
@@ -39,12 +35,13 @@ class ServerHelloPacketSerializer(
}
}
class ServerHelloPacketDeserializer : PacketDeserializer<ServerHelloPacketDeserializer.ServerHelloPacket> {
class ServerHelloPacketDeserializer :
PacketDeserializer<ServerHelloPacketDeserializer.ServerHelloPacket> {
data class ServerHelloPacket(
val clientPublicKey: PublicKey,
val signature: ByteArray,
val checksumSize: Int
val clientPublicKey: PublicKey,
val signature: ByteArray,
val checksumSize: Int
)
override fun deserialize(buffer: ByteBuf): ServerHelloPacket {
@@ -3,14 +3,13 @@ package de.fiereu.openmmo.protocols.tls.util
import java.math.BigInteger
import java.security.AlgorithmParameters
import java.security.KeyFactory
import java.security.Security
import java.security.Signature
import java.security.interfaces.ECPrivateKey
import java.security.interfaces.ECPublicKey
import java.security.spec.ECGenParameterSpec
import java.security.spec.ECParameterSpec
import java.security.spec.ECPoint
import java.security.spec.ECPublicKeySpec
import java.security.Signature
import java.security.interfaces.ECPrivateKey
private const val uncompressedPointIndicator: Byte = 0x04
@@ -93,4 +92,4 @@ fun ECPublicKey.verify(data: ByteArray, signatureBytes: ByteArray): Boolean {
signature.initVerify(this)
signature.update(data)
return signature.verify(signatureBytes)
}
}