ktorio / ktor

Framework for quickly creating connected applications in Kotlin with minimal effort
https://ktor.io
Apache License 2.0
13.07k stars 1.07k forks source link

Support HTTPS in CIO server #886

Open rnett opened 5 years ago

rnett commented 5 years ago

Ktor Version

1.1.1

Ktor Engine Used(client or server and name)

N/A - Raw Sockets

JVM Version, Operating System and Relevant Context

1.8.0_172, Windows.

I'm trying to create a basic client/server socket connection. It works fine without TLS.

When I enable TLS using .tls(Dispatchers.IO, randomAlgorithm = SecureRandom().algorithm) (on client and server) I get the exception Expecting ServerHello but got ClientHello (on both client and server). I'm using SecureRandom().algorithm so that it works on windows (I want it to be cross platform but haven't looked into it yet). It evaluates to SHA1PRNG.

Exception in thread "main" java.lang.IllegalStateException: Expected TLS handshake ServerHello but got ClientHello
    at io.ktor.network.tls.TLSClientHandshake.receiveServerHello(TLSClientHandshake.kt:204)
    at io.ktor.network.tls.TLSClientHandshake.negotiate(TLSClientHandshake.kt:164)
    at io.ktor.network.tls.TLSClientSession.start(TLSClientSession.kt:32)
    at io.ktor.network.tls.TLSKt.tls(TLS.kt:24)
    at io.ktor.network.tls.TLSKt.tls$default(TLS.kt:16)
    at com.rnett.submit.client.ClientKt$sendFiles$1.invokeSuspend(Client.kt:41)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
    at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:233)
    at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.kt:116)
    at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:76)
    at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:53)
    at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
    at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:35)
    at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
    at com.rnett.submit.client.ClientKt.sendFiles(Client.kt:38)
    at com.rnett.submit.client.ClientKt.sendFiles$default(Client.kt:38)
    at com.rnett.submit.client.Client.main(Client.kt:30)

On the client and:

Exception in thread "main" java.lang.IllegalStateException: Expected TLS handshake ServerHello but got ClientHello
    at io.ktor.network.tls.TLSClientHandshake.receiveServerHello(TLSClientHandshake.kt:204)
    at io.ktor.network.tls.TLSClientHandshake$receiveServerHello$1.invokeSuspend(TLSClientHandshake.kt)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
    at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:233)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:742)

on the server.

I think it might be related to (and possibly fixed by) #394, but that is just a wild guess.

e5l commented 5 years ago

Hi @rnett, thanks for the report. tls is supported on the client side only for now

rnett commented 5 years ago

Ah. Is there any kind of time line for server implementation?

e5l commented 5 years ago

It's in plans, but there is no ETA.

oleg-larshin commented 4 years ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.