Home / Class/ ConscryptAlpnSslEngine Class — netty Architecture

ConscryptAlpnSslEngine Class — netty Architecture

Architecture documentation for the ConscryptAlpnSslEngine class in ConscryptAlpnSslEngine.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  cf2a325c_a7ae_a5d2_40e3_1815d19cd517["ConscryptAlpnSslEngine"]
  e51572cf_5b72_0ca1_2650_98c58f05ef33["ConscryptAlpnSslEngine.java"]
  cf2a325c_a7ae_a5d2_40e3_1815d19cd517 -->|defined in| e51572cf_5b72_0ca1_2650_98c58f05ef33
  2c3f3c07_0f3f_3760_0157_e8f9833a9fc9["ConscryptAlpnSslEngine()"]
  cf2a325c_a7ae_a5d2_40e3_1815d19cd517 -->|method| 2c3f3c07_0f3f_3760_0157_e8f9833a9fc9
  5b9eb2e0_0433_a889_2293_18b4554fc173["calculateOutNetBufSize()"]
  cf2a325c_a7ae_a5d2_40e3_1815d19cd517 -->|method| 5b9eb2e0_0433_a889_2293_18b4554fc173
  0ee92bd4_7695_3030_f045_5bc214e84419["calculateRequiredOutBufSpace()"]
  cf2a325c_a7ae_a5d2_40e3_1815d19cd517 -->|method| 0ee92bd4_7695_3030_f045_5bc214e84419
  bf5680be_0fe9_8b3e_04a7_22022b2eb7be["calculateSpace()"]
  cf2a325c_a7ae_a5d2_40e3_1815d19cd517 -->|method| bf5680be_0fe9_8b3e_04a7_22022b2eb7be
  fd93a528_e935_37d9_404a_fb9335eb1a7d["SSLEngineResult()"]
  cf2a325c_a7ae_a5d2_40e3_1815d19cd517 -->|method| fd93a528_e935_37d9_404a_fb9335eb1a7d

Relationship Graph

Source Code

handler/src/main/java/io/netty/handler/ssl/ConscryptAlpnSslEngine.java lines 44–212

abstract class ConscryptAlpnSslEngine extends JdkSslEngine {
    private static final boolean USE_BUFFER_ALLOCATOR = SystemPropertyUtil.getBoolean(
            "io.netty.handler.ssl.conscrypt.useBufferAllocator", true);

    static ConscryptAlpnSslEngine newClientEngine(SSLEngine engine, ByteBufAllocator alloc,
            JdkApplicationProtocolNegotiator applicationNegotiator) {
        return new ClientEngine(engine, alloc, applicationNegotiator);
    }

    static ConscryptAlpnSslEngine newServerEngine(SSLEngine engine, ByteBufAllocator alloc,
            JdkApplicationProtocolNegotiator applicationNegotiator) {
        return new ServerEngine(engine, alloc, applicationNegotiator);
    }

    private ConscryptAlpnSslEngine(SSLEngine engine, ByteBufAllocator alloc, List<String> protocols) {
        super(engine);

        // Configure the Conscrypt engine to use Netty's buffer allocator. This is a trade-off of memory vs
        // performance.
        //
        // If no allocator is provided, the engine will internally allocate a direct buffer of max packet size in
        // order to optimize JNI calls (this happens the first time it is provided a non-direct buffer from the
        // application).
        //
        // Alternatively, if an allocator is provided, no internal buffer will be created and direct buffers will be
        // retrieved from the allocator on-demand.
        if (USE_BUFFER_ALLOCATOR) {
            Conscrypt.setBufferAllocator(engine, new BufferAllocatorAdapter(alloc));
        }

        // Set the list of supported ALPN protocols on the engine.
        Conscrypt.setApplicationProtocols(engine, protocols.toArray(EmptyArrays.EMPTY_STRINGS));
    }

    /**
     * Calculates the maximum size of the encrypted output buffer required to wrap the given plaintext bytes. Assumes
     * as a worst case that there is one TLS record per buffer.
     *
     * @param plaintextBytes the number of plaintext bytes to be wrapped.
     * @param numBuffers the number of buffers that the plaintext bytes are spread across.
     * @return the maximum size of the encrypted output buffer required for the wrap operation.
     */
    final int calculateOutNetBufSize(int plaintextBytes, int numBuffers) {
        // Assuming a max of one frame per component in a composite buffer.
        return calculateSpace(plaintextBytes, numBuffers, Integer.MAX_VALUE);
    }

    /**
     * Calculate the space necessary in an out buffer to hold the max size that the given
     * plaintextBytes and numBuffers can produce when encrypted. Assumes as a worst case
     * that there is one TLS record per buffer.
     * @param plaintextBytes the number of plaintext bytes to be wrapped.
     * @param numBuffers the number of buffers that the plaintext bytes are spread across.
     * @return the maximum size of the encrypted output buffer required for the wrap operation.
     */
    final int calculateRequiredOutBufSpace(int plaintextBytes, int numBuffers) {
        return calculateSpace(plaintextBytes, numBuffers, Conscrypt.maxEncryptedPacketLength());
    }

    private int calculateSpace(int plaintextBytes, int numBuffers, long maxPacketLength) {
         long maxOverhead = (long) Conscrypt.maxSealOverhead(getWrappedEngine()) * numBuffers;
         return (int) min(maxPacketLength, plaintextBytes + maxOverhead);
    }

    final SSLEngineResult unwrap(ByteBuffer[] srcs, ByteBuffer[] dests) throws SSLException {
        return Conscrypt.unwrap(getWrappedEngine(), srcs, dests);
    }

    private static final class ClientEngine extends ConscryptAlpnSslEngine {
        private final ProtocolSelectionListener protocolListener;

        ClientEngine(SSLEngine engine, ByteBufAllocator alloc,
                JdkApplicationProtocolNegotiator applicationNegotiator) {
            super(engine, alloc, applicationNegotiator.protocols());
            // Register for completion of the handshake.
            Conscrypt.setHandshakeListener(engine, new HandshakeListener() {
                @Override
                public void onHandshakeFinished() throws SSLException {
                    selectProtocol();
                }
            });

Frequently Asked Questions

What is the ConscryptAlpnSslEngine class?
ConscryptAlpnSslEngine is a class in the netty codebase, defined in handler/src/main/java/io/netty/handler/ssl/ConscryptAlpnSslEngine.java.
Where is ConscryptAlpnSslEngine defined?
ConscryptAlpnSslEngine is defined in handler/src/main/java/io/netty/handler/ssl/ConscryptAlpnSslEngine.java at line 44.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free