Class TLS

java.lang.Object
org.apache.pekko.stream.javadsl.TLS

public class TLS extends Object
Stream cipher support based upon JSSE.

The underlying SSLEngine has four ports: plaintext input/output and ciphertext input/output. These are modeled as a pekko.stream.BidiShape element for use in stream topologies, where the plaintext ports are on the left hand side of the shape and the ciphertext ports on the right hand side.

Configuring JSSE is a rather complex topic, please refer to the JDK platform documentation or the excellent user guide that is part of the Play Framework documentation. The philosophy of this integration into Pekko Streams is to expose all knobs and dials to client code and therefore not limit the configuration possibilities. In particular the client code will have to provide the SSLEngine, which is typically created from a SSLContext. Handshake parameters and other parameters are defined when creating the SSLEngine.

'''IMPORTANT NOTE'''

The TLS specification until version 1.2 did not permit half-closing of the user data session that it transports—to be precise a half-close will always promptly lead to a full close. This means that canceling the plaintext output or completing the plaintext input of the SslTls operator will lead to full termination of the secure connection, subject to the closing policy described below. Bytes not yet accepted by the operator may be discarded. When cancellation closes the connection, the legacy-actor engine also discards accepted plaintext. The graph-stage engine stops accepting plaintext and attempts to send data already accepted for the established session, subject to transport availability. This drain includes up to 64 queued messages plus any plaintext already buffered for wrapping; message sizes are unbounded, so cancellation can delay termination until that data is sent. Data queued after a renegotiation request is discarded, and draining stops if a new handshake is required. A TLS 1.3 post-handshake message such as a KeyUpdate is not a new handshake and does not stop the drain; in TLS 1.2 any further handshake stops it. The drain continues after a TLS 1.3 peer sends close_notify, but a TLS 1.2 close_notify ends it. The engine is selected with pekko.stream.materializer.tls.engine, which defaults to legacy-actor.

Especially for a client the common idiom of attaching a finite Source to the plaintext input and transforming the plaintext response bytes coming out will not work out of the box due to early termination of the connection. For this reason there is a parameter that determines whether the SslTls operator shall ignore completion and/or cancellation events, and the default is to ignore completion (in view of the client–server scenario). In order to terminate the connection the client will then need to cancel the plaintext output as soon as all expected bytes have been received. When ignoring both types of events the operator will shut down once both events have been received. See also TLSClosing. For now, half-closing is also not supported with TLS 1.3 where the spec allows it.

  • Constructor Details

    • TLS

      public TLS()
  • Method Details

    • create

      public static BidiFlow<TLSProtocol.SslTlsOutbound,ByteString,ByteString,TLSProtocol.SslTlsInbound,NotUsed> create(Creator<? extends SSLEngine> sslEngineCreator, Procedure<SSLSession> sessionVerifier, TLSClosing closing)
      Create a StreamTls pekko.stream.javadsl.BidiFlow. This is a low-level interface.

      You specify a factory sslEngineCreator to create an SSLEngine that must already be configured for client and server mode and with all the parameters for the first session.

      You can specify a verification function sessionVerifier that will be called after every successful handshake to verify additional session information.

      For a description of the closing parameter please refer to TLSClosing.

    • create

      Create a StreamTls pekko.stream.javadsl.BidiFlow. This is a low-level interface.

      You specify a factory sslEngineCreator to create an SSLEngine that must already be configured for client and server mode and with all the parameters for the first session.

      For a description of the closing parameter please refer to TLSClosing.