From 0cc73c3e2cdf4cd7286a1b8b4b2788325cb0484c Mon Sep 17 00:00:00 2001 From: Szymon Sasin Date: Fri, 18 Aug 2023 13:32:03 +0300 Subject: [PATCH] Remove redundant getSessionCid method --- .../org/opencoap/ssl/transport/DtlsServer.kt | 4 ---- .../ssl/transport/DtlsServerTransport.kt | 2 -- .../opencoap/ssl/transport/DtlsServerTest.kt | 18 ------------------ .../ssl/transport/DtlsServerTransportTest.kt | 10 ---------- 4 files changed, 34 deletions(-) diff --git a/kotlin-mbedtls/src/main/kotlin/org/opencoap/ssl/transport/DtlsServer.kt b/kotlin-mbedtls/src/main/kotlin/org/opencoap/ssl/transport/DtlsServer.kt index a379f57b..3beff7a9 100644 --- a/kotlin-mbedtls/src/main/kotlin/org/opencoap/ssl/transport/DtlsServer.kt +++ b/kotlin-mbedtls/src/main/kotlin/org/opencoap/ssl/transport/DtlsServer.kt @@ -50,10 +50,6 @@ class DtlsServer( private val sessions = mutableMapOf() private val cidSize = sslConfig.cidSupplier.next().size val numberOfSessions get() = sessions.size - fun getSessionCid(inet: InetSocketAddress): ByteArray? { - val dtlsState = sessions[inet] as? DtlsSession - return dtlsState?.sessionContext?.cid - } fun handleReceived(adr: InetSocketAddress, buf: ByteBuffer): ReceiveResult { val cid by lazy { SslContext.peekCID(cidSize, buf) } diff --git a/kotlin-mbedtls/src/main/kotlin/org/opencoap/ssl/transport/DtlsServerTransport.kt b/kotlin-mbedtls/src/main/kotlin/org/opencoap/ssl/transport/DtlsServerTransport.kt index ab60541e..5ca80aa7 100644 --- a/kotlin-mbedtls/src/main/kotlin/org/opencoap/ssl/transport/DtlsServerTransport.kt +++ b/kotlin-mbedtls/src/main/kotlin/org/opencoap/ssl/transport/DtlsServerTransport.kt @@ -114,6 +114,4 @@ class DtlsServerTransport private constructor( executor.supply { dtlsServer.putSessionAuthenticationContext(adr, key, value) } - - fun getSessionCid(adr: InetSocketAddress) = executor.supply { dtlsServer.getSessionCid(adr) } } diff --git a/kotlin-mbedtls/src/test/kotlin/org/opencoap/ssl/transport/DtlsServerTest.kt b/kotlin-mbedtls/src/test/kotlin/org/opencoap/ssl/transport/DtlsServerTest.kt index d2e76cee..d7be02ba 100644 --- a/kotlin-mbedtls/src/test/kotlin/org/opencoap/ssl/transport/DtlsServerTest.kt +++ b/kotlin-mbedtls/src/test/kotlin/org/opencoap/ssl/transport/DtlsServerTest.kt @@ -226,24 +226,6 @@ class DtlsServerTest { clientSession.close() } - @Test - fun `should find session cid`() { - // given - val clientSession = clientHandshake() - val cid = dtlsServer.getSessionCid(localAddress(2_5684)) - assert(cid!!.isNotEmpty()) - clientSession.close() - } - - @Test - fun `shouldn't find session cid`() { - // given - val clientSession = clientHandshake() - val cid = dtlsServer.getSessionCid(localAddress(1234)) - assertEquals(null, cid) - clientSession.close() - } - private fun clientHandshake(): SslSession { val send: (ByteBuffer) -> Unit = { dtlsServer.handleReceived(localAddress(2_5684), it) } val cliHandshake = clientConf.newContext(localAddress(5684)) diff --git a/kotlin-mbedtls/src/test/kotlin/org/opencoap/ssl/transport/DtlsServerTransportTest.kt b/kotlin-mbedtls/src/test/kotlin/org/opencoap/ssl/transport/DtlsServerTransportTest.kt index 6fea7730..887db82d 100644 --- a/kotlin-mbedtls/src/test/kotlin/org/opencoap/ssl/transport/DtlsServerTransportTest.kt +++ b/kotlin-mbedtls/src/test/kotlin/org/opencoap/ssl/transport/DtlsServerTransportTest.kt @@ -24,7 +24,6 @@ import org.awaitility.kotlin.await import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertFalse -import org.junit.jupiter.api.Assertions.assertNull import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test import org.opencoap.ssl.CertificateAuth @@ -438,15 +437,6 @@ class DtlsServerTransportTest { assertTrue(server.executor() is ScheduledThreadPoolExecutor) } - @Test - fun `should not return cid`() { - server = DtlsServerTransport.create(conf, lifecycleCallbacks = sslLifecycleCallbacks).listen(echoHandler) - val client = DtlsTransmitter.connect(server, clientConfig).await() - client.send("hello!") - val cid = server.getSessionCid(localAddress(1234)).await() - assertNull(cid) - } - @Test fun `should set and use session context`() { // given