-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from tmccombs/tls-native
Tls native
- Loading branch information
Showing
12 changed files
with
184 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/target | ||
**/*.rs.bk | ||
Cargo.lock | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Changelog | ||
|
||
## 0.4.0 - 2022-02-22 | ||
|
||
NOTE: This release contains several breaking changes. | ||
|
||
### Added | ||
|
||
- Support for [`native-tls`](https://github.com/sfackler/rust-native-tls). | ||
|
||
### Changed | ||
|
||
- The TLS backend is now configurable. Both rustls and native-tls are supported. Other backends can also be used by implementing the `AsyncTls` trait. | ||
- You must now supply either the `rustls` or `native-tls` features to get support for a tls backend. | ||
- Unfortunately, the machinery for this required adding an additional type parameter to `TlsListener`. | ||
- The `TlsListener` stream now returns a `tls_listener::Error` instead of `std::io::Error` type. | ||
- Signatures of `TcpListener::new()` and `builder()` have changed to now take an argument of the TLS type rather than a `rustls::ServerConfig`, | ||
to update existing calls, replace `builder(config)` with `builder(Arc::new(config).into())`. | ||
|
||
### Fixed | ||
|
||
- Crate will now compile when linked against a target that doesn't explicitly enable the `tokio/time` and `hyper/tcp` | ||
features. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,32 @@ | ||
[package] | ||
name = "tls-listener" | ||
description = "wrap incoming Stream of connections in TLS" | ||
version = "0.3.0" | ||
version = "0.4.0" | ||
authors = ["Thayne McCombs <[email protected]>"] | ||
repository = "https://github.com/tmccombs/tls-listener" | ||
edition = "2018" | ||
license = "Apache-2.0" | ||
|
||
[features] | ||
default = ["tokio-net"] | ||
rustls = ["tokio-rustls"] | ||
native-tls = ["tokio-native-tls"] | ||
|
||
tokio-net = ["tokio/net"] | ||
hyper-h1 = ["hyper", "hyper/http1"] | ||
hyper-h2 = ["hyper", "hyper/http2"] | ||
|
||
[dependencies] | ||
futures-util = "0.3.8" | ||
tokio = "1.0" | ||
tokio-rustls = "0.23.0" | ||
hyper = { version = "0.14.1", features = ["server", "tcp"], optional = true } | ||
pin-project-lite = "0.2.8" | ||
#tokio-native-tls = "0.3.0" | ||
|
||
[dependencies.hyper] | ||
version = "0.14.1" | ||
features = ["server"] | ||
optional = true | ||
thiserror = "1.0.30" | ||
tokio = { version = "1.0", features = ["time"] } | ||
tokio-native-tls = { version = "0.3.0", optional = true } | ||
tokio-rustls = { version = "0.23.0", optional = true } | ||
|
||
[dev-dependencies] | ||
hyper = { version = "0.14.1", features = ["server", "http1", "tcp", "stream"] } | ||
hyper = { version = "0.14.1", features = ["http1", "stream"] } | ||
tokio = { version = "1.0", features = ["rt", "macros", "net", "io-util"] } | ||
|
||
[[example]] | ||
|
@@ -51,5 +50,5 @@ path = "examples/http-low-level.rs" | |
required-features = ["hyper-h1"] | ||
|
||
[package.metadata.docs.rs] | ||
all-features = true | ||
features = ["rustls", "native-tls", "hyper-h1", "hyper-h2"] | ||
rustdoc-args = ["--cfg", "docsrs"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,33 @@ | ||
use tokio_rustls::rustls::{Certificate, PrivateKey, ServerConfig}; | ||
#[cfg(feature = "rustls")] | ||
mod cert { | ||
pub const CERT: &[u8] = include_bytes!("local.cert"); | ||
pub const PKEY: &[u8] = include_bytes!("local.key"); | ||
} | ||
#[cfg(feature = "native-tls")] | ||
const PFX: &[u8] = include_bytes!("local.pfx"); | ||
|
||
#[cfg(feature = "rustls")] | ||
pub fn tls_acceptor() -> tokio_rustls::TlsAcceptor { | ||
use std::sync::Arc; | ||
use tokio_rustls::rustls::{Certificate, PrivateKey, ServerConfig}; | ||
|
||
const CERT: &[u8] = include_bytes!("local.cert"); | ||
const PKEY: &[u8] = include_bytes!("local.key"); | ||
let key = PrivateKey(cert::PKEY.into()); | ||
let cert = Certificate(cert::CERT.into()); | ||
|
||
Arc::new( | ||
ServerConfig::builder() | ||
.with_safe_defaults() | ||
.with_no_client_auth() | ||
.with_single_cert(vec![cert], key) | ||
.unwrap(), | ||
) | ||
.into() | ||
} | ||
|
||
pub fn tls_config() -> ServerConfig { | ||
let key = PrivateKey(PKEY.into()); | ||
let cert = Certificate(CERT.into()); | ||
#[cfg(all(feature = "native-tls", not(feature = "rustls")))] | ||
pub fn tls_acceptor() -> tokio_native_tls::TlsAcceptor { | ||
use tokio_native_tls::native_tls::{Identity, TlsAcceptor}; | ||
|
||
ServerConfig::builder() | ||
.with_safe_defaults() | ||
.with_no_client_auth() | ||
.with_single_cert(vec![cert], key) | ||
.unwrap() | ||
let identity = Identity::from_pkcs12(PFX, "").unwrap(); | ||
TlsAcceptor::builder(identity).build().unwrap().into() | ||
} |
Oops, something went wrong.