quininer / tokio-rustls

Asynchronous TLS/SSL streams for Tokio using Rustls.
142 stars 38 forks source link

Bind multiple tls on the same port #58

Closed ghost closed 4 years ago

ghost commented 4 years ago

May I ask if there is a way to bind multiple sites on port 443, I have multiple certificates.

while let Ok ((stream, _)) = listener.accept().await {

    if let Ok(tls_stream) = tls1.accept(stream).await {
        // https://example1.com
    }

    if let Ok(tls_stream) = tls2.accept(stream).await {
        // https://example1.com
    }

}

Related issues: #42

Thank you for creating this crate.

quininer commented 4 years ago

I think you can use ResolvesServerCertUsingSNI to choose different certificates for different sni, and use get_sni_hostname in TlsStream to distinguish different sites.

ghost commented 4 years ago

The problem has been resolved, thank you for your reply