Fix HMAC checksum using client seed for outgoing packets
This commit is contained in:
1 parent
f622d29dca
commit
0879c17d63
3 files changed
+13
-7
No files matched your search
+9
-5
@@ -17,6 +17,8 @@ import de.fiereu.openmmo.server.protocol.tls.checksum.Checksum
|
||||
import de.fiereu.openmmo.server.protocol.tls.checksum.NoOpChecksum
|
||||
import io.netty.channel.ChannelHandlerContext
|
||||
import io.netty.channel.ChannelPipeline
|
||||
import io.netty.handler.logging.LogLevel
|
||||
import io.netty.handler.logging.LoggingHandler
|
||||
import io.netty.handler.timeout.WriteTimeoutHandler
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
@@ -38,6 +40,7 @@ class DefaultChannelHandlerProvider(
|
||||
override fun configurePipeline(pipeline: ChannelPipeline) {
|
||||
pipeline.addLast("timeout", WriteTimeoutHandler(serverConfig.writeTimeoutSeconds, TimeUnit.SECONDS))
|
||||
|
||||
pipeline.addLast("frame-logger", LoggingHandler("frame-logger", LogLevel.TRACE))
|
||||
pipeline.addLast("frame-decoder", PacketFrameDecoder())
|
||||
pipeline.addLast("frame-encoder", PacketFrameEncoder())
|
||||
|
||||
@@ -48,7 +51,7 @@ class DefaultChannelHandlerProvider(
|
||||
pipeline.addLast("tls-decryption", TlsDecryptionHandler(tlsContext))
|
||||
pipeline.addLast("tls-encryption", TlsEncryptionHandler(tlsContext))
|
||||
|
||||
|
||||
pipeline.addLast("protocol-logger", LoggingHandler("protocol-logger", LogLevel.TRACE))
|
||||
pipeline.addLast("protocol", TlsProtocolHandler(tlsProtocol, tlsConfig, this))
|
||||
}
|
||||
|
||||
@@ -58,17 +61,18 @@ class DefaultChannelHandlerProvider(
|
||||
* Will be called from the [TlsProtocolHandler] once the handshake is complete and a checksum algorithm is negotiated.
|
||||
*
|
||||
* @param ctx The channel handler context.
|
||||
* @param newChecksum The new checksum algorithm to use.
|
||||
* @param newChecksumIncoming The new checksum algorithm for incoming packets.
|
||||
* @param newChecksumOutgoing The new checksum algorithm for outgoing packets.
|
||||
*/
|
||||
fun switchChecksum(ctx: ChannelHandlerContext, newChecksum: Checksum) {
|
||||
fun switchChecksum(ctx: ChannelHandlerContext, newChecksumIncoming: Checksum, newChecksumOutgoing: Checksum) {
|
||||
val pipeline = ctx.pipeline()
|
||||
|
||||
if (pipeline.get("checksum-decoder") != null) {
|
||||
pipeline.replace("checksum-decoder", "checksum-decoder", ChecksumFrameDecoder(newChecksum))
|
||||
pipeline.replace("checksum-decoder", "checksum-decoder", ChecksumFrameDecoder(newChecksumIncoming))
|
||||
}
|
||||
|
||||
if (pipeline.get("checksum-encoder") != null) {
|
||||
pipeline.replace("checksum-encoder", "checksum-encoder", ChecksumFrameEncoder(newChecksum))
|
||||
pipeline.replace("checksum-encoder", "checksum-encoder", ChecksumFrameEncoder(newChecksumOutgoing))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ class DefaultTlsContext(
|
||||
private val decryptionCipher: Cipher // Client to server
|
||||
|
||||
fun getClientSeed(): ByteArray = clientSeed.copyOf()
|
||||
fun getServerSeed(): ByteArray = serverSeed.copyOf()
|
||||
|
||||
init {
|
||||
val sharedSecret = performKeyAgreement(privateKey, publicKey)
|
||||
|
||||
@@ -65,9 +65,10 @@ class TlsProtocolHandler(
|
||||
connectionKeyPair.second,
|
||||
event.packet.clientPublicKey
|
||||
)
|
||||
val checksum = ChecksumFactory.create(tlsConfig.checksumSize, tlsContext.getClientSeed())
|
||||
val checksumIncoming = ChecksumFactory.create(tlsConfig.checksumSize, tlsContext.getClientSeed())
|
||||
val checksumOutgoing = ChecksumFactory.create(tlsConfig.checksumSize, tlsContext.getServerSeed())
|
||||
|
||||
channelHandlerProvider.switchChecksum(event.ctx, checksum)
|
||||
channelHandlerProvider.switchChecksum(event.ctx, checksumIncoming, checksumOutgoing)
|
||||
channelHandlerProvider.switchTlsContext(event.ctx, tlsContext)
|
||||
channelHandlerProvider.enableProtocolHandler(event.ctx)
|
||||
log.info { "Client ${event.ctx.channel().remoteAddress()} completed TLS handshake. Switching to next protocol." }
|
||||
|
||||
Reference in new issue
Block a user