io.netty.handler.ssl.NotSslRecordException
Hi,
I am trying to run gateway application as https service.
On Startup, I am getting the error - " io.netty.handler.ssl.NotSslRecordException: not an SSL/TLS record"
Exception logs:
2018-01-15 17:30:30.165 DEBUG [gateway-server,,,] 14674 --- [ctor-http-nio-2] r.ipc.netty.http.server.HttpServer : [id: 0x4978794e, L:/172.28.168.89:8887 - R:/172.28.168.89:56004] USER_EVENT: SslHandshakeCompletionEvent(io.netty.handler.ssl.NotSslRecordException: not an SSL/TLS record: 474554202f6163747561746f722f6865616c746820485454502f312e310d0a486f73743a203137322e32382e3136382e38393a383838370d0a557365722d4167656e743a20436f6e73756c204865616c746820436865636b0d0a4163636570743a20746578742f706c61696e2c20746578742f2a2c202a2f2a0d0a4163636570742d456e636f64696e673a20677a69700d0a436f6e6e656374696f6e3a20636c6f73650d0a0d0a) 2018-01-15 17:30:30.166 ERROR [gateway-server,,,] 14674 --- [ctor-http-nio-2] r.i.n.channel.CloseableContextHandler : Handler failure while no child channelOperation was present
io.netty.handler.ssl.NotSslRecordException: not an SSL/TLS record: 474554202f6163747561746f722f6865616c746820485454502f312e310d0a486f73743a203137322e32382e3136382e38393a383838370d0a557365722d4167656e743a20436f6e73756c204865616c746820436865636b0d0a4163636570743a20746578742f706c61696e2c20746578742f2a2c202a2f2a0d0a4163636570742d456e636f64696e673a20677a69700d0a436f6e6e656374696f6e3a20636c6f73650d0a0d0a at io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1137) [netty-handler-4.1.17.Final.jar:4.1.17.Final] at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1193) [netty-handler-4.1.17.Final.jar:4.1.17.Final] at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:489) [netty-codec-4.1.17.Final.jar:4.1.17.Final] at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:428) [netty-codec-4.1.17.Final.jar:4.1.17.Final] at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:265) [netty-codec-4.1.17.Final.jar:4.1.17.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [netty-transport-4.1.17.Final.jar:4.1.17.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [netty-transport-4.1.17.Final.jar:4.1.17.Final] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) [netty-transport-4.1.17.Final.jar:4.1.17.Final] at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1359) [netty-transport-4.1.17.Final.jar:4.1.17.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [netty-transport-4.1.17.Final.jar:4.1.17.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [netty-transport-4.1.17.Final.jar:4.1.17.Final] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:935) [netty-transport-4.1.17.Final.jar:4.1.17.Final] at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:138) [netty-transport-4.1.17.Final.jar:4.1.17.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645) [netty-transport-4.1.17.Final.jar:4.1.17.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580) [netty-transport-4.1.17.Final.jar:4.1.17.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497) [netty-transport-4.1.17.Final.jar:4.1.17.Final] at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459) [netty-transport-4.1.17.Final.jar:4.1.17.Final] at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858) [netty-common-4.1.17.Final.jar:4.1.17.Final] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151]
2018-01-15 17:30:30.174 DEBUG [gateway-server,,,] 14674 --- [ctor-http-nio-2] r.ipc.netty.http.server.HttpServer : [id: 0x4978794e, L:/172.28.168.89:8887 ! R:/172.28.168.89:56004] EXCEPTION: io.netty.handler.codec.DecoderException: io.netty.handler.ssl.NotSslRecordException: not an SSL/TLS record: 474554202f6163747561746f722f6865616c746820485454502f312e310d0a486f73743a203137322e32382e3136382e38393a383838370d0a557365722d4167656e743a20436f6e73756c204865616c746820436865636b0d0a4163636570743a20746578742f706c61696e2c20746578742f2a2c202a2f2a0d0a4163636570742d456e636f64696e673a20677a69700d0a436f6e6e656374696f6e3a20636c6f73650d0a0d0a
io.netty.handler.codec.DecoderException: io.netty.handler.ssl.NotSslRecordException: not an SSL/TLS record: 474554202f6163747561746f722f6865616c746820485454502f312e310d0a486f73743a203137322e32382e3136382e38393a383838370d0a557365722d4167656e743a20436f6e73756c204865616c746820436865636b0d0a4163636570743a20746578742f706c61696e2c20746578742f2a2c202a2f2a0d0a4163636570742d456e636f64696e673a20677a69700d0a436f6e6e656374696f6e3a20636c6f73650d0a0d0a at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:459) ~[netty-codec-4.1.17.Final.jar:4.1.17.Final] at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:265) ~[netty-codec-4.1.17.Final.jar:4.1.17.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [netty-transport-4.1.17.Final.jar:4.1.17.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [netty-transport-4.1.17.Final.jar:4.1.17.Final] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) [netty-transport-4.1.17.Final.jar:4.1.17.Final] at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1359) [netty-transport-4.1.17.Final.jar:4.1.17.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [netty-transport-4.1.17.Final.jar:4.1.17.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [netty-transport-4.1.17.Final.jar:4.1.17.Final] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:935) [netty-transport-4.1.17.Final.jar:4.1.17.Final] at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:138) [netty-transport-4.1.17.Final.jar:4.1.17.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645) [netty-transport-4.1.17.Final.jar:4.1.17.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580) [netty-transport-4.1.17.Final.jar:4.1.17.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497) [netty-transport-4.1.17.Final.jar:4.1.17.Final] at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459) [netty-transport-4.1.17.Final.jar:4.1.17.Final] at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858) [netty-common-4.1.17.Final.jar:4.1.17.Final] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151] Caused by: io.netty.handler.ssl.NotSslRecordException: not an SSL/TLS record: 474554202f6163747561746f722f6865616c746820485454502f312e310d0a486f73743a203137322e32382e3136382e38393a383838370d0a557365722d4167656e743a20436f6e73756c204865616c746820436865636b0d0a4163636570743a20746578742f706c61696e2c20746578742f2a2c202a2f2a0d0a4163636570742d456e636f64696e673a20677a69700d0a436f6e6e656374696f6e3a20636c6f73650d0a0d0a at io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1137) ~[netty-handler-4.1.17.Final.jar:4.1.17.Final] at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1193) ~[netty-handler-4.1.17.Final.jar:4.1.17.Final] at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:489) ~[netty-codec-4.1.17.Final.jar:4.1.17.Final] at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:428) ~[netty-codec-4.1.17.Final.jar:4.1.17.Final] ... 15 common frames omitted
2018-01-15 17:30:30.178 DEBUG [gateway-server,,,] 14674 --- [ctor-http-nio-2] r.ipc.netty.http.server.HttpServer : [id: 0x4978794e, L:/172.28.168.89:8887 ! R:/172.28.168.89:56004]
I don't know if this is specific to gateway or Spring Boot 2 with Netty
ok. How do i enable ssl for a gateway application application?
See the spring boot 2 documentation
@pravinkumarb84 in a nutshell, you need a SSL certificate and these config values set, (assuming you use yml properties)
server:
ssl:
key-alias: <yours-cert-alias>
enabled: true
key-password: <your-key-pwd>
key-store: selfsigned.jks
key-store-type: JKS
key-store-provider: SUN
key-store-password: <your-jks-pwd>
Thanks @saiyedzaidi and @spencergibb I have configured SSL for my application now.
I am getting this issue as well. Can any of you post a working config? Also, what version of dependencies ended up working?
I configured SSL
server:
port: 8081
ssl:
key-alias: tomcat
enabled: true
key-password: chengxun
key-store: classpath:tomcat.keystore
key-store-type: JKS
key-store-provider: SUN
key-store-password: chengxun
But still reporting this error:
io.netty.handler.ssl.NotSslRecordException: not an SSL/TLS record: 485454502f312e3120343030200d0a436f6e74656e742d547970653a20746578742f68746d6c3b636861727365743d7574662d380d0a436f6e74656e742d4c616e67756167653a20656e0d0a436f6e74656e742d4c656e6774683a203830300d0a446174653a205468752c203139204a756c20323031382030393a32313a313920474d540d0a436f6e6e656374696f6e3a20636c6f73650d0a0d0a3c21646f63747970652068746d6c3e3c68746d6c206c616e673d22656e223e3c686561643e3c7469746c653e48545450205374617475732034303020e280932042616420526571756573743c2f7469746c653e3c7374796c6520747970653d22746578742f637373223e6831207b666f6e742d66616d696c793a5461686f6d612c417269616c2c73616e732d73657269663b636f6c6f723a77686974653b6261636b67726f756e642d636f6c6f723a233532354437363b666f6e742d73697a653a323270783b7d206832207b666f6e742d66616d696c793a5461686f6d612c417269616c2c73616e732d73657269663b636f6c6f723a77686974653b6261636b67726f756e642d636f6c6f723a233532354437363b666f6e742d73697a653a313670783b7d206833207b666f6e742d66616d696c793a5461686f6d612c417269616c2c73616e732d73657269663b636f6c6f723a77686974653b6261636b67726f756e642d636f6c6f723a233532354437363b666f6e742d73697a653a313470783b7d20626f6479207b666f6e742d66616d696c793a5461686f6d612c417269616c2c73616e732d73657269663b636f6c6f723a626c61636b3b6261636b67726f756e642d636f6c6f723a77686974653b7d2062207b666f6e742d66616d696c793a5461686f6d612c417269616c2c73616e732d73657269663b636f6c6f723a77686974653b6261636b67726f756e642d636f6c6f723a233532354437363b7d2070207b666f6e742d66616d696c793a5461686f6d612c417269616c2c73616e732d73657269663b6261636b67726f756e643a77686974653b636f6c6f723a626c61636b3b666f6e742d73697a653a313270783b7d2061207b636f6c6f723a626c61636b3b7d20612e6e616d65207b636f6c6f723a626c61636b3b7d202e6c696e65207b6865696768743a3170783b6261636b67726f756e642d636f6c6f723a233532354437363b626f726465723a6e6f6e653b7d3c2f7374796c653e3c2f686561643e3c626f64793e3c68313e48545450205374617475732034303020e280932042616420526571756573743c2f68313e3c2f626f64793e3c2f68746d6c3e
at io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1156) [netty-handler-4.1.25.Final.jar:4.1.25.Final]
at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1221) [netty-handler-4.1.25.Final.jar:4.1.25.Final]
at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:489) ~[netty-codec-4.1.25.Final.jar:4.1.25.Final]
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:428) ~[netty-codec-4.1.25.Final.jar:4.1.25.Final]
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:265) ~[netty-codec-4.1.25.Final.jar:4.1.25.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[netty-transport-4.1.25.Final.jar:4.1.25.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[netty-transport-4.1.25.Final.jar:4.1.25.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) ~[netty-transport-4.1.25.Final.jar:4.1.25.Final]
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) ~[netty-transport-4.1.25.Final.jar:4.1.25.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[netty-transport-4.1.25.Final.jar:4.1.25.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[netty-transport-4.1.25.Final.jar:4.1.25.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) ~[netty-transport-4.1.25.Final.jar:4.1.25.Final]
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) ~[netty-transport-4.1.25.Final.jar:4.1.25.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:647) ~[netty-transport-4.1.25.Final.jar:4.1.25.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:582) ~[netty-transport-4.1.25.Final.jar:4.1.25.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:499) ~[netty-transport-4.1.25.Final.jar:4.1.25.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:461) ~[netty-transport-4.1.25.Final.jar:4.1.25.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884) ~[netty-common-4.1.25.Final.jar:4.1.25.Final]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_162]
Need all microservices to be configured with SSL?
There are two hops involved. The first from the external client to the gateway and then another hop from the gateway to back end. Your change just allows SSL over the first hop. To configure SSL for the second hop you need to have your back end listening on https and configure the route URI to start with https.
On Thu, 19 Jul 2018 at 05:29, Yang-xinwu [email protected] wrote:
Need all microservices to be configured with SSL?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/spring-cloud/spring-cloud-gateway/issues/160#issuecomment-406215138, or mute the thread https://github.com/notifications/unsubscribe-auth/AQOvoOJlJxbTMKmTNCwze-eygsGKvnwLks5uIFGTgaJpZM4RewFW .
Might be related to #1842
Gateway actually use https protocol when call the api through the gateway to visit other micro service. Zuul will convert https requests to http requests to the background microservice. So, Gateway requires us to add filters to implement the conversion by ourselves. @Component public class SchemeFilter implements GlobalFilter, Ordered {
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
Object uriObj = exchange.getAttributes().get(GATEWAY_REQUEST_URL_ATTR);
if (uriObj != null) {
URI uri = (URI) uriObj;
uri = this.upgradeConnection(uri, "http");
exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, uri);
}
return chain.filter(exchange);
}
private URI upgradeConnection(URI uri, String scheme) {
UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUri(uri).scheme(scheme);
if (uri.getRawQuery() != null) {
// When building the URI, UriComponentsBuilder verify the allowed characters and does not
// support the '+' so we replace it for its equivalent '%20'.
// See issue https://jira.spring.io/browse/SPR-10172
uriComponentsBuilder.replaceQuery(uri.getRawQuery().replace("+", "%20"));
}
return uriComponentsBuilder.build(true).toUri();
}
public int getOrder() {
return 10101;
}
}