Reputation: 764
I have read the related question in stackoverflow. However, the answer only tell how to config about auth check. I need to encrpt all transferred data with rsocket in spring boot. How can I use tls in spring boot with SSL/TLS. I can't find any supported method when I init my rsocket client as shown below, although I know that rsocket it self can support SSL/TLS. I find some examples: The example
this.rsocketRequester = rsocketRequesterBuilder.setupRoute("sidecar-client")
.setupData("test_data")
.rsocketConnector(connector -> connector.acceptor(responder))
.connectTcp("localhost", 7000)
.block();
Summary of my question:
1. Does rsocket in springboot support SSL/TLS ?
2. If spring boot support rsocket with SSL/TLS, are there any examples can be referenced
Upvotes: 5
Views: 2705
Reputation: 69
Yes - you need to configure SSL / TLS as you would normally irrespective of using rsocket or not.
In your application.yml add the following lines :
server:
port: 8443
ssl:
enabled: true
client-auth: none
protocol: "TLS"
key-store: "classpath:certs/local/server.jks"
key-store-type: "JKS"
key-store-password: "changeit"
trust-store: "classpath:certs/trust.jks"
trust-store-password: "changeit"
spring:
rsocket:
server:
mapping-path: "/"
transport: websocket
And on the client side use wss instead of ws
const _rSocketClient = function()
{
return new RSocketClient({
setup: {
// ms btw sending keepalive to server
keepAlive: 60000,
// ms timeout if no keepalive response
lifetime: 180000,
// format of `data`
dataMimeType: 'application/json',
// format of `metadata`
metadataMimeType: MESSAGE_RSOCKET_COMPOSITE_METADATA.string,
},
transport: new RSocketWebSocketClient(
{
// Connect as secure websocket
url : "wss://" + R_SOCKET_HOST + ":" + R_SOCKET_PORT,
debug: true
},
BufferEncoders
),
});
}
I couldn't find any examples either and had to learn by doing it myself. Most of the RSocket examples that you would find uses RSocketFactory which is now deprecated and the api keeps changing - so always get the latest and try it yourself.
Upvotes: 3
Reputation: 13448
Yes, modifying your example
Secure TCP (SSL)
this.rsocketRequester = rsocketRequesterBuilder.setupRoute("sidecar-client")
.setupData("test_data")
.rsocketConnector(connector -> connector.acceptor(responder))
.connect(TcpClientTransport.create(TcpClient.create().secure().host("localhost").port(7000)))
.block();
or secure websockets
this.rsocketRequester = rsocketRequesterBuilder.setupRoute("sidecar-client")
.setupData("test_data")
.rsocketConnector(connector -> connector.acceptor(responder))
.connectWebSocket(URI.create("https://rsocket-demo.herokuapp.com/rsocket"))
.block();
Upvotes: 3