2016-02-16 18:19:30 +01:00
|
|
|
package akka.stream.impl.io
|
|
|
|
|
|
2017-03-07 12:39:15 +01:00
|
|
|
import javax.net.ssl.{ SSLEngine, SSLSession }
|
2016-02-16 18:19:30 +01:00
|
|
|
|
2016-07-27 13:29:23 +02:00
|
|
|
import akka.NotUsed
|
2016-11-17 16:07:24 +01:00
|
|
|
import akka.actor.ActorSystem
|
2016-02-16 18:19:30 +01:00
|
|
|
import akka.stream._
|
2016-07-27 13:29:23 +02:00
|
|
|
import akka.stream.impl.StreamLayout.AtomicModule
|
2016-02-16 18:19:30 +01:00
|
|
|
import akka.stream.TLSProtocol._
|
2017-03-07 12:39:15 +01:00
|
|
|
import akka.stream.impl.{ TlsModuleIslandTag, TraversalBuilder }
|
2016-02-16 18:19:30 +01:00
|
|
|
import akka.util.ByteString
|
|
|
|
|
|
2016-11-17 16:07:24 +01:00
|
|
|
import scala.util.Try
|
|
|
|
|
|
2016-02-16 18:19:30 +01:00
|
|
|
/**
|
|
|
|
|
* INTERNAL API.
|
|
|
|
|
*/
|
2016-11-17 16:07:24 +01:00
|
|
|
private[stream] final case class TlsModule(plainIn: Inlet[SslTlsOutbound], plainOut: Outlet[SslTlsInbound],
|
|
|
|
|
cipherIn: Inlet[ByteString], cipherOut: Outlet[ByteString],
|
2016-07-27 13:29:23 +02:00
|
|
|
shape: BidiShape[SslTlsOutbound, ByteString, ByteString, SslTlsInbound],
|
|
|
|
|
attributes: Attributes,
|
2016-11-17 16:07:24 +01:00
|
|
|
createSSLEngine: ActorSystem ⇒ SSLEngine, // ActorSystem is only needed to support the AkkaSSLConfig legacy, see #21753
|
2017-02-23 12:00:54 +01:00
|
|
|
verifySession: (ActorSystem, SSLSession) ⇒ Try[Unit], // ActorSystem is only needed to support the AkkaSSLConfig legacy, see #21753
|
2016-07-27 13:29:23 +02:00
|
|
|
closing: TLSClosing)
|
|
|
|
|
extends AtomicModule[BidiShape[SslTlsOutbound, ByteString, ByteString, SslTlsInbound], NotUsed] {
|
2016-02-16 18:19:30 +01:00
|
|
|
|
2016-03-11 17:08:30 +01:00
|
|
|
override def withAttributes(att: Attributes): TlsModule = copy(attributes = att)
|
|
|
|
|
|
2016-11-17 16:07:24 +01:00
|
|
|
override def toString: String = f"TlsModule($closing) [${System.identityHashCode(this)}%08x]"
|
2016-07-27 13:29:23 +02:00
|
|
|
|
2017-03-07 19:40:50 +01:00
|
|
|
override private[stream] def traversalBuilder = TraversalBuilder.atomic(this, attributes).makeIsland(TlsModuleIslandTag)
|
2016-02-16 18:19:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* INTERNAL API.
|
|
|
|
|
*/
|
2016-11-17 16:07:24 +01:00
|
|
|
private[stream] object TlsModule {
|
|
|
|
|
def apply(
|
|
|
|
|
attributes: Attributes,
|
|
|
|
|
createSSLEngine: ActorSystem ⇒ SSLEngine, // ActorSystem is only needed to support the AkkaSSLConfig legacy, see #21753
|
2017-02-23 12:00:54 +01:00
|
|
|
verifySession: (ActorSystem, SSLSession) ⇒ Try[Unit], // ActorSystem is only needed to support the AkkaSSLConfig legacy, see #21753
|
2016-11-17 16:07:24 +01:00
|
|
|
closing: TLSClosing): TlsModule = {
|
|
|
|
|
val name = attributes.nameOrDefault(s"StreamTls()")
|
2016-02-16 18:19:30 +01:00
|
|
|
val cipherIn = Inlet[ByteString](s"$name.cipherIn")
|
|
|
|
|
val cipherOut = Outlet[ByteString](s"$name.cipherOut")
|
|
|
|
|
val plainIn = Inlet[SslTlsOutbound](s"$name.transportIn")
|
|
|
|
|
val plainOut = Outlet[SslTlsInbound](s"$name.transportOut")
|
|
|
|
|
val shape = new BidiShape(plainIn, cipherOut, cipherIn, plainOut)
|
2017-02-23 12:00:54 +01:00
|
|
|
TlsModule(plainIn, plainOut, cipherIn, cipherOut, shape, attributes, createSSLEngine, verifySession, closing)
|
2016-02-16 18:19:30 +01:00
|
|
|
}
|
|
|
|
|
}
|