Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Commit

Permalink
Rewrite crate using the native-tls crate
Browse files Browse the repository at this point in the history
The purpose of this rewrite is to reuse all of awesome logic in the native-tls
crate rather than rewriting it. The native-tls crate already naturally supports
async I/O everywhere so let's just take advantage of it! As a result, this crate
is now stripped of all #[cfg] code essentially and now just provides two
extension traits for `TlsConnector` and `TlsAcceptor`. The extension traits
provide a `connect_async` and `accept_async` function, respectively, which
handles retry logic with mid-handshake streams automatically.

Currently this rewrites drops two current features of this crate: forcing usage
of OpenSSL and a rustls backend. I hope to reenable both of these features
through support in the native-tls crate shortly, however.
  • Loading branch information
alexcrichton committed Dec 15, 2016
1 parent 3d49e52 commit b121025
Show file tree
Hide file tree
Showing 12 changed files with 352 additions and 1,490 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ before_script:
script:
- cargo build
- cargo test
- cargo test --features force-openssl
- cargo test --features force-rustls
- cargo doc --no-deps
after_success:
- travis-cargo --only nightly doc-upload
Expand Down
49 changes: 24 additions & 25 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,39 @@ for nonblocking I/O streams.
"""

[dependencies]
cfg-if = "0.1"
futures = "0.1"
log = "0.3"
tokio-core = "0.1"

# Optional dependency that can be enabled with the `force-openssl` feature
openssl = { version = "0.8", optional = true }
openssl-verify = { version = "0.2", optional = true }
futures = "0.1.4"
tokio-core = "0.1.1"
native-tls = "0.1"

# Optional dependency to use `rustls` as a backend, enabled with `force-rustls`
rustls = { version = "0.1.2", optional = true }
webpki-roots = { version = "0.2", optional = true }
[dev-dependencies]
env_logger = { version = "0.3", default-features = false }
cfg-if = "0.1"

[target.'cfg(all(unix, not(target_os = "macos")))'.dependencies]
openssl = "0.8"
openssl-verify = "0.2"
[target.'cfg(all(not(target_os = "macos"), not(windows)))'.dev-dependencies]
openssl = "0.9"

[target.'cfg(target_os = "macos")'.dependencies]
[target.'cfg(target_os = "macos")'.dev-dependencies]
security-framework = "0.1"

[target.'cfg(windows)'.dependencies]
schannel = "0.1"

[target.'cfg(windows)'.dev-dependencies]
advapi32-sys = "0.2"
crypt32-sys = "0.2"
kernel32-sys = "0.2"
schannel = "0.1"
winapi = "0.2"

[dev-dependencies]
env_logger = "0.3"
webpki = "0.3"
untrusted = "0.3"
[replace.'native-tls:0.1.0']
git = 'https://github.com/alexcrichton/rust-native-tls'
branch = 'changes'

[replace.'security-framework:0.1.9']
git = 'https://github.com/alexcrichton/rust-security-framework'
branch = 'handshake2'

[replace.'security-framework-sys:0.1.9']
git = 'https://github.com/alexcrichton/rust-security-framework'
branch = 'handshake2'

[features]
force-openssl = ["openssl", "openssl-verify"]
force-rustls = ["rustls", "webpki-roots"]
[replace.'schannel:0.1.1']
git = 'https://github.com/alexcrichton/schannel-rs'
branch = 'export-pkcs12'
1 change: 0 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ build: false
test_script:
- cargo build
- cargo test
- cargo test --features force-rustls
13 changes: 9 additions & 4 deletions examples/download-rust-lang.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
extern crate futures;
extern crate native_tls;
extern crate tokio_core;
extern crate tokio_tls;

use std::io;
use std::net::ToSocketAddrs;

use futures::Future;
use tokio_core::reactor::Core;
use native_tls::TlsConnector;
use tokio_core::net::TcpStream;
use tokio_tls::ClientContext;
use tokio_core::reactor::Core;
use tokio_tls::TlsConnectorExt;

fn main() {
let mut core = Core::new().unwrap();
let addr = "www.rust-lang.org:443".to_socket_addrs().unwrap().next().unwrap();

let socket = TcpStream::connect(&addr, &core.handle());
let cx = TlsConnector::builder().unwrap().build().unwrap();

let tls_handshake = socket.and_then(|socket| {
let cx = ClientContext::new().unwrap();
cx.handshake("www.rust-lang.org", socket)
cx.connect_async("www.rust-lang.org", socket).map_err(|e| {
io::Error::new(io::ErrorKind::Other, e)
})
});
let request = tls_handshake.and_then(|socket| {
tokio_core::io::write_all(socket, "\
Expand Down
Loading

0 comments on commit b121025

Please sign in to comment.