rsocket / rsocket-java

Java implementation of RSocket
http://rsocket.io
Apache License 2.0
2.36k stars 354 forks source link

WSS rsocket server support #312

Closed mitermayer closed 7 years ago

mitermayer commented 7 years ago

Does rsocket-java support "wss" server ? NettyUriTransportRegistryTest (https://github.com/rsocket/rsocket-java/blob/25e11fad5ab6ad8a281e233689d4a157f65dfd3a/rsocket-transport-netty/src/test/java/io/rsocket/transport/netty/NettyUriTransportRegistryTest.java#L38) shows the intention for supporting "ws" but does it also supports "wss " ?

@Test
  public void testWsServer() {
    ServerTransport transport = UriTransportRegistry.serverForUri("ws://localhost:9898");

    assertTrue(transport instanceof WebsocketServerTransport);
  }

Would be great to have an end to end example of secure websocket rsocket server and client interaction.

yschimke commented 7 years ago

rsocket-java does but just not via the URI scheme currently. I can provide an example and possibly even support it via the URI params.

yschimke commented 7 years ago

@mitermayer First question, do you have keys you want to use? Or do you want it self signed?

    HttpServer s = HttpServer.create(o -> {
      try {
        SslContext ctxt = SslContextBuilder.forServer(new File("CERT_FILE"), new File("KEY_FILE")).build();
        o.sslContext(ctxt);
      } catch (SSLException e) {
        e.printStackTrace();
      }

      o.sslSelfSigned();

      o.listen(4430);
    });
    WebsocketServerTransport t = WebsocketServerTransport.create(s);
mitermayer commented 7 years ago

Just for reference, doing the above and still fails when trying to start a server using SSL.

The server code used for the rsocket websocket server is:

        RSocketServer.create(
                WebsocketTransportServer.create(
                    HttpServer.create(options -> options.listen(port).sslContext(sslCtx))))
        ...

The client code used to connect to the secure weboscket rsocket server is:

      RSocketClient client =
          RSocketClient.create(
              WebsocketTransportClient.create(
                  HttpClient.create(
                      options -> options.sslSupport().connect(host, port))),
     ...

The stack trace error is: (I have changed the record to XXXXXXXXXXXX.... deliberatly for data integrity):

2017-06-15 09:28:57,607 ERROR (Loggers.java:190) Handler failure while no child channelOperation was present ([reactor-http-nio-1] reactor.ipc.netty.channel.CloseableContextHandler)
io.netty.handler.ssl.NotSslRecordException: not an SSL/TLS record: XXXXXXXXXXXX....
        at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1103)
        at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:489)
        at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:428)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:265)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
        at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:134)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:644)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:579)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:496)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:458)
        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
        at java.lang.Thread.run(Thread.java:745)
mitermayer commented 7 years ago

Just for a bit more context, the client and server interaction works as expected when SSL is disabled.

yschimke commented 7 years ago

@mitermayer I'm seeing the same failure

https://github.com/rsocket/rsocket-java/pull/314/files

yschimke commented 7 years ago

https://github.com/rsocket/rsocket-java/pull/315