Hi i use netty on Android to host a webserver and ...
# ktor
k
Hi i use netty on Android to host a webserver and would like to use ssl. I created a certificate as shown here https://github.com/myfreax/android-ssl-certificate I added it to ktor and the server starts and isn’t available on http anymore as expected. Code:
Copy code
sslConnector(
            keyStore = keystore,
            keyAlias = keyAlias,
            keyStorePassword = { keyStorePassword.toCharArray() },
            privateKeyPassword = { keyPassword.toCharArray() },
        ) {
            // this.host = "0.0.0.0"
            this.keyStorePath = file
            this.port = port
        }
Unfortunately i get a crash
Copy code
[eventLoopGroupProxy-3-1] WARN io.netty.channel.DefaultChannelPipeline - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
io.netty.handler.codec.DecoderException: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.isEmpty()' on a null object reference
	at io.netty.handler.codec.ByteToMessageDecoder.callDecode(Unknown Source:103)
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(Unknown Source:53)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(SourceFile:2)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(SourceFile:1)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(SourceFile:1)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(Unknown Source:0)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(SourceFile:2)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(SourceFile:1)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(SourceFile:2)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(Unknown Source:101)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(SourceFile:1)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(Unknown Source:24)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(Unknown Source:4)
	at io.netty.channel.nio.NioEventLoop.run(Unknown Source:131)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(Unknown Source:41)
	at io.netty.util.internal.ThreadExecutorMap$2.run(Unknown Source:8)
	at io.ktor.server.netty.EventLoopGroupProxy$Companion.create$lambda$1$lambda$0(Unknown Source:5)
	at io.ktor.server.netty.EventLoopGroupProxy$Companion.$r8$lambda$XgnKz7L6tCWRUaIAa7SVURwtFE4(SourceFile:1)
	at androidx.core.app.ActivityCompat$$ExternalSyntheticLambda0.run(SourceFile:31)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(Unknown Source:2)
	at java.lang.Thread.run(Thread.java:1012)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.isEmpty()' on a null object reference
	at io.netty.handler.ssl.JdkAlpnSslEngine$AlpnSelector.checkUnsupported(Unknown Source:11)
	at io.netty.handler.ssl.JdkAlpnSslEngine.verifyProtocolSelection(Unknown Source:41)
	at io.netty.handler.ssl.JdkAlpnSslEngine.wrap(SourceFile:3)
	at io.netty.handler.ssl.SslHandler.wrap(SourceFile:1)
	at io.netty.handler.ssl.SslHandler.wrapNonAppData(Unknown Source:30)
	at io.netty.handler.ssl.SslHandler.unwrap(Unknown Source:169)
	at io.netty.handler.ssl.SslHandler.decodeJdkCompatible(Unknown Source:39)
	at io.netty.handler.ssl.SslHandler.decode(Unknown Source:13)
	at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(Unknown Source:5)
	at io.netty.handler.codec.ByteToMessageDecoder.callDecode(Unknown Source:33)
	... 20 more
seems like in JdkAlpnSslEngine
String protocol = getApplicationProtocol();
produces a null value. Any idea how to fix it?
🧵 1
My workaround for now is to downgrade to 2.1.0. I'll still see the erros in the log but socket won't hang up
p
Hey @Kilian did you ever manage to fix it without downgrading? I’m having the same issue on an Android 10 device using Ktor version 2.3.13.
k
i actually don’t remember. Did you try upgrading to Ktor3 ?
p
Thanks for your reply! I was about to try that out. But was curious to find out if there was a fix without migrating to 3.x.x. Let me give upgrading a try, I’ll let you know.
The issue was also present on 3.x.x. However I found out it works when I disable http2 using
enableHttp2 = false
on the
NettyApplicationEngine.Configuration
. Not sure how that’s connected though.