Skip to content

The HTTPS proxy could be refactored and renamed to be a generic SSL proxy #826

Open

Description

@Wonshtrum

With the coming of Http2 and TCP over TLS, we may want to reuse and convert the HTTPS proxy as a generic SSL endpoint that redirects to Http2, Http1.1, or TCP clusters via ALPN.

Thoughts @FlorentinDUBOIS @Geal ?

Activity

  1. added this to the v0.15.0 milestone on Nov 8, 2022
  2. self-assigned this
    on Nov 8, 2022
  3. Wonshtrum commented on Nov 9, 2022

    @Wonshtrum
    MemberAuthor

    For the moment I am mainly concerned with the TCP TLS implementation. The alternatives are:

    1. add a completely new and independent proxy (similar to how HTTP and HTTPS are separated)
    2. add TLS capabilities to the already existing TCP proxy (solution explored here TCP over TLS #823)
    3. add TCP protocol to the already existing HTTPS proxy

    The first solution requires a lot of code, mainly copy-pasted from the openssl and rustls implementation of the HTTPS proxy. Following the design of HTTPS, it would require the workers to have a TCPSProvider struct which hold either a tcps_openssl or tcps_rustls proxy. It also shares a common limitation/problem with solution 2: multiple proxies now are responsible for managing certificates. Which means more code duplication, it becomes hard to know if a certificate was added on unknown listeners, it makes it impossible to support both HTTPS and TCPS on the same listeners.

    Solution 3 would be best implemented by refactoring the HTTPS proxy in a generic TLS proxy, as proposed at the beginning of this issue.

    Equivalent solutions to 1 and 3 could be proposed to finish the HTTP2 implementation:

    1. add a completely new and independent HTTP2 proxy
    2. no equivalent
    3. add HTTP2 to the already existing HTTPS proxy

    The current implementation of HTTP2 (in 0.14) seems to stir in the proposed direction (solution 3) as it shares the HTTPS proxy with HTTP. To finish the implementation the HTTPS proxy has to become less "HTTP centric". For example, HTTP2 is already able to ask for backend connection, but connect_to_backend only works if it is in the Http state.

  4. Wonshtrum commented on Nov 9, 2022

    @Wonshtrum
    MemberAuthor

    What I propose:

    pub struct Server {
        pub poll: Poll,
        shutting_down: Option<MessageId>,
        accept_ready: HashSet<ListenToken>,
        channel: ProxyChannel,
        http: Rc<RefCell<http::Proxy>>,
    -    https: HttpsProvider,
    +    tls: Rc<RefCell<tls::Proxy>>,
        tcp: Rc<RefCell<tcp::Proxy>>,
        config_state: ConfigState,
        scm: ScmSocket,
        sessions: Rc<RefCell<SessionManager>>,
        pool: Rc<RefCell<Pool>>,
        backends: Rc<RefCell<BackendMap>>,
        scm_listeners: Option<Listeners>,
        zombie_check_interval: Duration,
        accept_queue: VecDeque<(TcpStream, ListenToken, Protocol, Instant)>,
        accept_queue_timeout: Duration,
        base_sessions_count: usize,
    }
    • merge the https_openssl::Proxy and https_rustls::configuration::Proxy common parts (like connect_to_backend) to avoid unnecessary code duplication
      fn connect_to_backend(

      fn connect_to_backend(
    • implement tls:Proxy as a generic TLS endpoint that redirects to other, independently implemented, protocols (in our case: HTTP, HTTP2 and TCP). Which, sadly, means an enormous State machine:
    pub enum State {
        // do we need TCP's SendProxyProtocol and RelayProxyProtocol?
        ExpectOpenssl(protocol::proxy_protocol::expect::ExpectProxyProtocol<TcpStream>, ..),
        ExpectRustls(protocol::proxy_protocol::expect::ExpectProxyProtocol<TcpStream>, ..),
        HandshakeOpenssl(protocol::openssl::TlsHandshake),
        HandshakeRustls(protocol::rustls::TlsHandshake),
        HttpOpenssl(protocol::http::Http<SslStream<TcpStream>, Listener>),
        HttpRustls(protocol::http::Http<FrontRustls, Listener>),
        PipeOpenssl(protocol::pipe::Pipe<SslStream<TcpStream>, Listener>),
        PipeRustls(protocol::pipe::Pipe<FrontRustls, Listener>),
        Http2Openssl(protocol::h2::Http2<SslStream<TcpStream>>),
        Http2Rustls(protocol::h2::Http2<FrontRustls>),
    }
    • rewrite connect_to_backend to handle TCPS and H2
    • update every frontend lookup to use SNI switching
    • make sure the state machine is always coherent. With my current understanding it should look something like that:
    flowchart LR
        start --> Swicth{expect? provider?}
        Swicth -->|true, openssl| ExpectOpenssl
        Swicth -->|true, rustls| ExpectRustls
        Swicth -->|false, openssl| HandshakeOpenssl
        Swicth -->|false, rustls| HandshakeRustls
        ExpectOpenssl --> HandshakeOpenssl
        ExpectRustls --> HandshakeRustls
        HandshakeOpenssl --> SwicthOpenssl{FindFrontendProto}
        HandshakeRustls --> SwicthRustls{FindFrontendProto}
        SwicthOpenssl -->|http2| Http2Openssl
        SwicthOpenssl -->|http| HttpOpenssl
        SwicthOpenssl -->|tcp| PipeOpenssl
        SwicthRustls -->|tcp| PipeRustls
        SwicthRustls -->|http| HttpRustls
        SwicthRustls -->|http2| Http2Rustls
        HttpOpenssl -->|websocket| PipeOpenssl
        HttpRustls -->|websocket| PipeRustls
    
    Loading
    • update config parsing and merge TCPS/HTTPS/H2 Listeners
      • add supported ALPN protocols on each Listeners (either manually or automatically)
  5. Wonshtrum commented on Nov 9, 2022

    @Wonshtrum
    MemberAuthor

    This would enable a 3 phases plan:

    • one PR to remove HttpsProvider and merge https_openssl::Proxy and https_rustls::configuration::Proxy in a single tls::Proxy. This doesn't add any functionality to the HTTPS proxy
    • one PR to add TCPS in the tls::Proxy
    • one PR to finish the HTTP2 implementation in tls::Proxy
  6. Keksoj commented on Nov 9, 2022

    @Keksoj

    I'm all in.

  7. Wonshtrum commented on Nov 9, 2022

    @Wonshtrum
    MemberAuthor

    A caveat to this design: we need to have a single TLS Listener that accommodates all "TLS supported" protocols (TCP, HTTP, and HTTP2 for now). We also need to have a two-part scheme to filter frontends and find, for a given connection, which frontend to redirect to. Currently, demultiplexing is implemented in two phases:

    • L4 indicates a Listener, Listeners are linked to exactly one Proxy (TCP, HTTP, HTTPS)
    • the proxy finds the appropriate Frontend with:
      • nothing (TCP Listeners are linked to exactly one Frontend) for TCP proxy
      • L7 (hostname/path/method) for the HTTP proxy
      • L7 (hostname/path/method) for the HTTPS proxy

    In the new architecture, I think we will have to rely on the SNI and ALPN protocol in the TLS proxy. So this should look like:

    • L4 indicates a Listener, Listeners are linked to exactly one Proxy (TCP, HTTP, TLS)
    • the proxy finds the appropriate Frontend with:
      • nothing for the TCP proxy
      • L7 (hostname/path/method) for the HTTP proxy
      • the TLS proxy first determines the Frontend Protocol using L6 (SNI/ALPN), then:
        • L6 (SNI) for TCPS protocol
        • L7 (hostname/path/method) for HTTPS protocol
        • L7 (hostname/path/method) for HTTP2 protocol
    flowchart LR
        L4{L4} -->|port| Listeners{Listeners}
        Listeners --> TCP
        Listeners --> HTTP
        Listeners --> TLS
        Protocol --> TCP
        Protocol --> HTTP
        Protocol --> HTTP2
        L7 -->|path| Frontends
        L7 -->|method| Frontends
        L7 -->|hostname| Frontends
        L6 -->|sni, alpn| Protocol
        HTTP2 --> L7
        HTTP --> L7{L7}
        TCP --> Frontends
        TLS --> L6{L6}
        Frontends -->|lb| Cluster
    
    Loading
  8. FlorentinDUBOIS commented on Nov 9, 2022

    @FlorentinDUBOIS
    Collaborator

    To me, the state machine for the TLS should not treat OpenSSL or Rustls differently. It should to me, be like:

    SslStream::new(tls_provider); // we gave the tls provider to use at the creation, the provider could be hide behind a trait or a generic with a trait condition
    
    pub enum State {
        // do we need TCP's SendProxyProtocol and RelayProxyProtocol?
        Expect(protocol::proxy_protocol::expect::ExpectProxyProtocol<TcpStream>, ..),
        Handshake(protocol::tls::TlsHandshake),
        Http(protocol::http::Http<SslStream<TcpStream>, Listener>),
        Pipe(protocol::pipe::Pipe<SslStream<TcpStream>, Listener>),
        H2(protocol::h2::H2<SslStream<TcpStream>>),
    }
  9. Geal commented on Nov 10, 2022

    @Geal
    Member

    taking a step back here, let's think about usage: while this would make more sense from an architecture point of view, I would not overestimate the need for TCP over TLS. Has this been asked a lot? If not I would put this off until other changes.

    First, I'd recommend removing support for OpenSSL. It was kept mainly for TLS 1.0 and 1.1, that were not implemented in rustls. Now that everybody is moving off those protocols, keeping OpenSSL does not make sense. That should greatly simplify the code and configuration, and reduce the number of dependencies and build issues.

    Something that could be done to make the architecture nicer, would be to reverse the hierarchy. Instead of having one global TCP proxy, one HTTP proxy and one HTTPS proxy, it would start at the listener. A listener then has some protocol (TCP or TLS) and routing (HTTP 1 & 2, passthrough).
    From there you don't need to make one TLS proxy that handles everything, but stack them in a more natural way, with the outer protocol negotiating a stream (just returning a TCP stream or negotiating a TLS connection) then from there see to which rotocol it upgrades, depending on what's configured, and what's asked by the client (ALPN, websocket upgrade, etc).

    But really, start by removing OpenSSL, because any change you can envision will be way easier with one less implementation 😄

  10. modified the milestones: v0.15.0, HTTP2 on Dec 9, 2022
  11. FlorentinDUBOIS commented on May 2, 2026

    @FlorentinDUBOIS
    Collaborator

    State of #826 — May 2026

    Quick recap, since this issue has been quiet since November 2022 and several
    pieces of the original proposal have either landed or been intentionally
    reshaped on main.

    Original 2022 plan (for reference)

    1. Replace the HttpsProvider enum with a single tls::Proxy, merging
      https_openssl::Proxy and https_rustls::configuration::Proxy.
    2. Add TCP-over-TLS (TCPS) inside that tls::Proxy.
    3. Finish the HTTP/2 implementation inside the same proxy, ALPN-driven.

    @Geal also recommended dropping OpenSSL entirely as a simplifying first step
    before any of the above; @FlorentinDUBOIS proposed a single,
    provider-agnostic state machine instead of parallel *Openssl / *Rustls
    arms.

    What landed on main

    • HttpsProvider enum is gone. https_openssl.rs and the
      https_rustls/ subtree have been merged into a single lib/src/https.rs.
      Server now holds one https::HttpsProxy instead of an enum dispatch
      (lib/src/server.rs:485-486).
    • OpenSSL is no longer a separate TLS proxy implementation. It survives
      only as a crypto provider for rustls via the rustls-openssl adapter,
      selectable through the crypto-openssl cargo feature alongside
      crypto-ring (default), crypto-aws-lc-rs, and fips. Provider
      precedence (fips > ring > aws-lc-rs > openssl) is resolved at runtime in
      lib/src/crypto.rs::default_provider(). This matches @Geal's "remove
      OpenSSL first" recommendation in spirit: the TLS implementation is
      single-stack rustls; OpenSSL is reduced to optional FFI for libcrypto.
    • HTTP/2 is finished, via the unified Mux session layer landed in PR
      feat(h2): HTTP/2 support via unified Mux session layer #1209 (merged 2026-04-27). The Mux layer replaces the old Http<Front>
      protocol module: a single Mux<Front, L> session owns frontend and
      backend Connection enums (Connection::H1(ConnectionH1) /
      Connection::H2(ConnectionH2)) and a shared Vec<Stream>, so all four
      H1↔H2 frontend/backend combinations are covered. The lineage of this
      work goes back to @Wonshtrum's mux_v1 design, with contributions from
      @hcaumeil on the H2↔H2 SETTINGS handshake and the H1→H2 upgrade path;
      the feat/h2-mux branch extracted, hardened, and shipped that design for
      production.
    • Provider-agnostic state machine. Per @FlorentinDUBOIS's earlier
      proposal, the inner state machine is no longer parallelised by TLS
      provider. There is one TLS handshake module
      (lib/src/protocol/rustls.rs) and one HTTPS proxy.
    • ALPN-driven post-handshake dispatch is in place. lib/src/https.rs
      branches on the negotiated ALPN protocol: h2 →
      mux::Connection::new_h2_server, http/1.1 →
      mux::Connection::new_h1_server. Listener-level disable_http11 and
      strict_sni_binding knobs were added; rejected ALPN values bump
      https.alpn.rejected.{unsupported,http11_disabled}.

    What did not land (and why it matters)

    • TCP over TLS (TCPS). This was @Wonshtrum's primary motivator in the
      original thread, and was already explored in the closed TCP over TLS #823. Drafts on
      the tcp-tls and devel/edemolis/test/read_tls branches still exist,
      but TCPS is not in main. The Mux layer does not include a
      Pipe-style passthrough as a fourth dispatch arm, and there is no
      SNI-only frontend lookup for non-HTTP TLS clients. The L6/L7 demux flow
      chart from the November 2022 thread (TLS proxy → SNI → {TCPS, HTTPS,
      H2}) is still applicable as a design starting point for any TCPS
      follow-up.
    • HttpsProxy → tls::Proxy rename. The proxy is still named
      https::HttpsProxy in Server. Server still owns three proxies
      (http::HttpProxy, https::HttpsProxy, tcp::TcpProxy). Renaming
      today, without a second protocol behind ALPN, would just be churn; it
      should be bundled with TCPS when that work resumes.

    Where the relevant code lives now

    • lib/src/https.rs — single HTTPS proxy (rustls-only).
    • lib/src/tls.rs — certificate resolver, fingerprint cache, SNI policy.
    • lib/src/protocol/rustls.rs — TLS handshake protocol module.
    • lib/src/protocol/mux/ — unified H1/H2 session
      (mod.rs, connection.rs, h1.rs, h2.rs, stream.rs, parser.rs,
      pkawa.rs, router.rs, converter.rs, serializer.rs, answers.rs,
      auth.rs, shared.rs). LIFECYCLE.md next to the module is the
      canonical on-branch lifecycle reference.
    • lib/src/server.rs — still three proxies, no tls::Proxy yet.
    • lib/src/crypto.rs — runtime crypto-provider selection.

    Where this leaves the issue

    The HTTPS-side scope of #826 is effectively done: openssl proxy retired,
    H2 finished, ALPN dispatch in place, single provider-agnostic state
    machine. The only remaining open item from this thread is TCPS, which
    #823 also targeted.

  12. added
    tls
    on May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementtls

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions