Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate DTLS message before decryption #59

Merged
merged 14 commits into from
Nov 6, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class DtlsChannelHandler @JvmOverloads constructor(

private fun loadSession(result: DtlsServer.ReceiveResult.CidSessionMissing, msg: DatagramPacket, ctx: ChannelHandlerContext) {
sessionStore.read(result.cid)
.thenApplyAsync({ sessBuf -> dtlsServer.loadSession(sessBuf, msg.sender(), result.cid) }, ctx.executor())
.thenApplyAsync({ sessBuf -> dtlsServer.loadSession(sessBuf, msg.sender(), result.cid, msg.content().nioBuffer()) }, ctx.executor())
.whenComplete { isLoaded: Boolean?, _ ->
if (isLoaded == true) {
channelRead(ctx, msg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class DtlsServer(
updateSessionAuthenticationContext(adr, ctx.authenticationContext)
}

fun loadSession(sessBuf: SessionWithContext?, adr: InetSocketAddress, cid: ByteArray, dtlsPacket: ByteBuffer? = null): Boolean {
fun loadSession(sessBuf: SessionWithContext?, adr: InetSocketAddress, cid: ByteArray, dtlsPacket: ByteBuffer): Boolean {
return try {
if (sessBuf == null) {
logger.warn("[{}] [CID:{}] DTLS session not found", adr, cid.toHex())
Expand All @@ -152,7 +152,7 @@ class DtlsServer(
}

val sslSession = sslConfig.loadSession(cid, sessBuf.sessionBlob, adr)
dtlsPacket?.let {
dtlsPacket.let {
JuhaPekkaa marked this conversation as resolved.
Show resolved Hide resolved
val verificationResult = sslSession.checkRecord(it)
if (verificationResult is SslSession.VerificationResult.Invalid) {
logger.warn("[{}] [CID:{}] Record verification failed: {}", adr, cid.toHex(), verificationResult.message)
Expand Down
Loading