2016-02-16 18:19:30 +01:00
|
|
|
package akka.stream.impl.io
|
|
|
|
|
|
|
|
|
|
import javax.net.ssl.SSLContext
|
|
|
|
|
|
|
|
|
|
import akka.stream._
|
2016-03-11 17:08:30 +01:00
|
|
|
import akka.stream.impl.StreamLayout.{ CompositeModule, AtomicModule }
|
2016-02-16 18:19:30 +01:00
|
|
|
import akka.stream.TLSProtocol._
|
|
|
|
|
import akka.util.ByteString
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* INTERNAL API.
|
|
|
|
|
*/
|
|
|
|
|
private[akka] final case class TlsModule(plainIn: Inlet[SslTlsOutbound], plainOut: Outlet[SslTlsInbound],
|
|
|
|
|
cipherIn: Inlet[ByteString], cipherOut: Outlet[ByteString],
|
|
|
|
|
shape: Shape, attributes: Attributes,
|
|
|
|
|
sslContext: SSLContext,
|
|
|
|
|
firstSession: NegotiateNewSession,
|
2016-03-11 17:08:30 +01:00
|
|
|
role: TLSRole, closing: TLSClosing, hostInfo: Option[(String, Int)]) extends AtomicModule {
|
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)
|
|
|
|
|
override def carbonCopy: TlsModule =
|
2016-02-16 18:19:30 +01:00
|
|
|
TlsModule(attributes, sslContext, firstSession, role, closing, hostInfo)
|
|
|
|
|
|
|
|
|
|
override def replaceShape(s: Shape) =
|
|
|
|
|
if (s != shape) {
|
|
|
|
|
shape.requireSamePortsAs(s)
|
|
|
|
|
CompositeModule(this, s)
|
|
|
|
|
} else this
|
2016-03-11 17:08:30 +01:00
|
|
|
|
|
|
|
|
override def toString: String = f"TlsModule($firstSession, $role, $closing, $hostInfo) [${System.identityHashCode(this)}%08x]"
|
2016-02-16 18:19:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* INTERNAL API.
|
|
|
|
|
*/
|
|
|
|
|
private[akka] object TlsModule {
|
|
|
|
|
def apply(attributes: Attributes, sslContext: SSLContext, firstSession: NegotiateNewSession, role: TLSRole, closing: TLSClosing, hostInfo: Option[(String, Int)]): TlsModule = {
|
|
|
|
|
val name = attributes.nameOrDefault(s"StreamTls($role)")
|
|
|
|
|
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)
|
|
|
|
|
TlsModule(plainIn, plainOut, cipherIn, cipherOut, shape, attributes, sslContext, firstSession, role, closing, hostInfo)
|
|
|
|
|
}
|
|
|
|
|
}
|