Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hyper 0.x server support #5142

Open
goatgoose opened this issue Feb 24, 2025 · 0 comments
Open

Hyper 0.x server support #5142

goatgoose opened this issue Feb 24, 2025 · 0 comments

Comments

@goatgoose
Copy link
Contributor

Problem:

s2n-tls-hyper provides hyper 1.x client compatibility. Hyper 1.x servers can use s2n-tls-tokio directly, and as such, no support is provided in s2n-tls-hyper.

However, hyper 0.x servers do require a compatibility layer in order to work with s2n-tls. We should provide support for this in s2n-tls-hyper, for applications that haven't yet migrated to hyper 1.x.

Solution:

@jmayclin implemented the following tls-listener adapter for s2n-tls, which allows s2n-tls to be used with the hyper 0.x server.

tls-listener adapter

// this struct is a new-type wrapper to allow a foreign trait to be implemented
// on the TlsAcceptor struct
#[derive(Clone)]
pub struct MyS2NAcceptor(s2n_tls_tokio::TlsAcceptor);

impl MyS2NAcceptor {
    /// create an S2NAcceptor from an S2N Config.
    pub fn new(config: s2n_tls::config::Config) -> Self {
        let acceptor = s2n_tls_tokio::TlsAcceptor::new(config);
        MyS2NAcceptor(acceptor)
    }
}

// implement the tls_listener::AsyncTls trait over a connection type C, for MyS2NTokioAcceptor
impl tls_listener::AsyncTls for MyS2NAcceptor {
    type Stream = s2n_tls_tokio::TlsStream;
    type Error = s2n_tls::error::Error;

    type AcceptFuture = Pin> + Send>>;

    fn accept(&self, stream: C) -> Self::AcceptFuture {
        let tls = self.clone();
        Box::pin(async move { s2n_tls_tokio::TlsAcceptor::accept(&tls.0, stream).await })
    }
}

We should add this tls-listener adapter to s2n-tls-hyper behind a feature flag.

Requirements / Acceptance Criteria:

In addition to this adapter, we should add a self-talk test that echos bytes to a client, similar to the existing hyper 1.x client self-talk tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants