Here's a full example which does just that:
https://github.com/typesafehub/activator-akka-stream-java8/blob/master/src/main/java/sample/stream/TcpTLSEcho.java

Happy hakking


On Mar 11, 2017 10:43 AM, "Pablo Milanese" <[email protected]>
wrote:

> Hello !.
>
> I am actually looking for an example of the combinations of
> *akka.streams.javadsl.Tcp* and *akka.streams.javadsl.TLS* to create
> custom SSL/TLS enabled TCP servers and clients, but I couldn't find
> anything ..
>
> I think I have resolved the akka-streams-tcp, but I can't find how can I
> join the TLS API on the things that I have:
>
> Here's my code for TCP connections using akka streams:
>
>
>
>   private val connectionsSource: Source[IncomingConnection, 
> Future[ServerBinding]] =
>     Tcp(context.system)
>       .bind(transportConfig.getHost, transportConfig.getPort)
>
>   private val connectionsSink: Sink[IncomingConnection, Future[Done]] =
>     Sink.foreach(handleIncomingConnection)
>
>   private val connectionsGraph: RunnableGraph[(Future[ServerBinding], 
> Future[Done])] =
>     connectionsSource.toMat(connectionsSink)(Keep.both)
>
>   private val echo: Flow[ByteString, ByteString, NotUsed] =
>
>     Flow[ByteString]
>       .via(Framing.delimiter(ByteString("\n"), maximumFrameLength = 256, 
> allowTruncation = true))
>       .map(_.utf8String)
>       .map { text =>
>         log.info(s"Received message: $text")
>         ByteString(text + "!!!\n")
>       }
>
>   def handleIncomingConnection(connection: IncomingConnection) {
>     log.info(s"New client at ${connection.remoteAddress}")
>     val flowGraph = connection.flow.joinMat(echo)(Keep.both)
>     flowGraph.run()
>   }
>
>   private val mat = connectionsGraph.run()
>
>
>
> And from the other side, the TLS part:
>
> ( I have a Function to take the SSLContext .. but is the only thing that I
> have ...)
>
> def initSslContext(): SSLContext = {
>   val password = "password"
>
>   val keyStore = KeyStore.getInstance(KeyStore.getDefaultType)
>   keyStore.load(getClass.getResourceAsStream("/keystore"), 
> password.toCharArray)
>
>   val trustStore = KeyStore.getInstance(KeyStore.getDefaultType)
>   trustStore.load(getClass.getResourceAsStream("/truststore"), 
> password.toCharArray)
>
>   val keyManagerFactory = 
> KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm)
>   keyManagerFactory.init(keyStore, password.toCharArray)
>
>   val trustManagerFactory = 
> TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm)
>   trustManagerFactory.init(trustStore)
>
>   val context = SSLContext.getInstance("TLS")
>   context.init(keyManagerFactory.getKeyManagers, 
> trustManagerFactory.getTrustManagers, new SecureRandom)
>
>   for (protocol <- context.getSupportedSSLParameters.getProtocols) {
>     log.info(s"Supported protocol: $protocol")
>   }
>   context
> }
>
>
>
> If anyone has an example, or something I would appreciate.
>
> Thank You!
> Pablo
>
>
>
> --
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/
> current/additional/faq.html
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
> ---
> You received this message because you are subscribed to the Google Groups
> "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to