parent
2e5e99f410
commit
b1faa18a1e
@ -27,6 +27,7 @@ with-eui48 = ["eui48"]
|
|||||||
with-openssl = ["openssl"]
|
with-openssl = ["openssl"]
|
||||||
with-native-tls = ["native-tls"]
|
with-native-tls = ["native-tls"]
|
||||||
with-rustc-serialize = ["rustc-serialize"]
|
with-rustc-serialize = ["rustc-serialize"]
|
||||||
|
with-schannel = ["schannel"]
|
||||||
with-security-framework = ["security-framework"]
|
with-security-framework = ["security-framework"]
|
||||||
with-serde_json = ["serde_json"]
|
with-serde_json = ["serde_json"]
|
||||||
with-time = ["time"]
|
with-time = ["time"]
|
||||||
@ -47,6 +48,7 @@ eui48 = { version = "0.1", optional = true }
|
|||||||
openssl = { version = "0.9", optional = true }
|
openssl = { version = "0.9", optional = true }
|
||||||
native-tls = { version = "0.1", optional = true }
|
native-tls = { version = "0.1", optional = true }
|
||||||
rustc-serialize = { version = "0.3", optional = true }
|
rustc-serialize = { version = "0.3", optional = true }
|
||||||
|
schannel = { version = "0.1", optional = true }
|
||||||
security-framework = { version = "0.1.2", optional = true }
|
security-framework = { version = "0.1.2", optional = true }
|
||||||
serde_json = { version = ">= 0.6, < 0.9", optional = true }
|
serde_json = { version = ">= 0.6, < 0.9", optional = true }
|
||||||
time = { version = "0.1.14", optional = true }
|
time = { version = "0.1.14", optional = true }
|
||||||
|
@ -43,9 +43,9 @@
|
|||||||
//!
|
//!
|
||||||
//! This crate supports TLS secured connections. The `TlsMode` enum is passed to connection methods
|
//! This crate supports TLS secured connections. The `TlsMode` enum is passed to connection methods
|
||||||
//! and indicates if the connection will not, may, or must be secured by TLS. The TLS implementation
|
//! and indicates if the connection will not, may, or must be secured by TLS. The TLS implementation
|
||||||
//! is pluggable through the `TlsHandshake` trait. Implementations for OpenSSL and OSX's Secure
|
//! is pluggable through the `TlsHandshake` trait. Implementations for OpenSSL, Secure Transport,
|
||||||
//! Transport are provided behind the `with-openssl`, `with-security-framework`, and
|
//! SChannel, and the `native-tls` crate are provided behind the `with-openssl`,
|
||||||
//! `with-native-tls` feature flags respectively.
|
//! `with-security-framework`, `with-schannel`, and `with-native-tls` feature flags respectively.
|
||||||
//!
|
//!
|
||||||
//! ## Examples
|
//! ## Examples
|
||||||
//!
|
//!
|
||||||
|
@ -5,12 +5,14 @@ use std::error::Error;
|
|||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
#[cfg(feature = "with-openssl")]
|
|
||||||
pub mod openssl;
|
|
||||||
#[cfg(feature = "with-security-framework")]
|
|
||||||
pub mod security_framework;
|
|
||||||
#[cfg(feature = "with-native-tls")]
|
#[cfg(feature = "with-native-tls")]
|
||||||
pub mod native_tls;
|
pub mod native_tls;
|
||||||
|
#[cfg(feature = "with-openssl")]
|
||||||
|
pub mod openssl;
|
||||||
|
#[cfg(feature = "with-schannel")]
|
||||||
|
pub mod schannel;
|
||||||
|
#[cfg(feature = "with-security-framework")]
|
||||||
|
pub mod security_framework;
|
||||||
|
|
||||||
/// A trait implemented by TLS streams.
|
/// A trait implemented by TLS streams.
|
||||||
pub trait TlsStream: fmt::Debug + Read + Write + Send {
|
pub trait TlsStream: fmt::Debug + Read + Write + Send {
|
||||||
|
51
src/tls/schannel.rs
Normal file
51
src/tls/schannel.rs
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
//! SChannel support.
|
||||||
|
|
||||||
|
extern crate schannel;
|
||||||
|
|
||||||
|
use std::error::Error;
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
|
use self::schannel::schannel_cred::{SchannelCred, Direction};
|
||||||
|
use self::schannel::tls_stream;
|
||||||
|
use tls::{TlsStream, Stream, TlsHandshake};
|
||||||
|
|
||||||
|
impl TlsStream for tls_stream::TlsStream<Stream> {
|
||||||
|
fn get_ref(&self) -> &Stream {
|
||||||
|
self.get_ref()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_mut(&mut self) -> &mut Stream {
|
||||||
|
self.get_mut()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A `TlsHandshake` implementation that uses the `schannel` crate.
|
||||||
|
///
|
||||||
|
/// Requires the `with-schannel` feature.
|
||||||
|
pub struct Schannel(());
|
||||||
|
|
||||||
|
impl fmt::Debug for Schannel {
|
||||||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
fmt.debug_struct("Schannel").finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Schannel {
|
||||||
|
/// Constructs a new `SChannel` with a default configuration.
|
||||||
|
pub fn new() -> Schannel {
|
||||||
|
Schannel(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TlsHandshake for Schannel {
|
||||||
|
fn tls_handshake(&self,
|
||||||
|
host: &str,
|
||||||
|
stream: Stream)
|
||||||
|
-> Result<Box<TlsStream>, Box<Error + Sync + Send>> {
|
||||||
|
let creds = try!(SchannelCred::builder().acquire(Direction::Outbound));
|
||||||
|
let stream = try!(tls_stream::Builder::new()
|
||||||
|
.domain(host)
|
||||||
|
.connect(creds, stream));
|
||||||
|
Ok(Box::new(stream))
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user