Skip to content

Commit

Permalink
Merge pull request websockets-rs#6 from avadacatavra/bump-hyper
Browse files Browse the repository at this point in the history
bumped hyper and openssl
  • Loading branch information
nox authored Mar 6, 2017
2 parents c8d2568 + 16b6691 commit de05e90
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ license = "MIT"
name = "websocket"

[dependencies]
hyper = "0.9"
hyper = "0.10"
unicase = "1.0.1"
openssl = "0.7.6"
openssl = "0.9"
url = "1.0"
rustc-serialize = "0.3.16"
bitflags = "0.7"
Expand Down
13 changes: 7 additions & 6 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use stream::WebSocketStream;
use dataframe::DataFrame;
use ws::dataframe::DataFrame as DataFrameable;

use openssl::ssl::{SslContext, SslMethod, SslStream};
use openssl::ssl::{Ssl, SslMethod, SslContextBuilder, SslContext};

pub use self::request::Request;
pub use self::response::Response;
Expand Down Expand Up @@ -68,8 +68,8 @@ impl Client<DataFrame, Sender<WebSocketStream>, Receiver<WebSocketStream>> {
/// A connection is established, however the request is not sent to
/// the server until a call to ```send()```.
pub fn connect<T: ToWebSocketUrlComponents>(components: T) -> WebSocketResult<Request<WebSocketStream, WebSocketStream>> {
let context = try!(SslContext::new(SslMethod::Tlsv1));
Client::connect_ssl_context(components, &context)
let context = try!(SslContextBuilder::new(SslMethod::tls()));
Client::connect_ssl_context(components, &context.build())
}
/// Connects to the specified wss:// URL using the given SSL context.
///
Expand All @@ -86,10 +86,11 @@ impl Client<DataFrame, Sender<WebSocketStream>, Receiver<WebSocketStream>> {
));

let stream = if secure {
let sslstream = try!(SslStream::connect(context, connection));
let ssl = try!(Ssl::new(context));
let sslstream = try!(ssl.connect(connection)
.map_err(::result::WebSocketError::HandshakeError));
WebSocketStream::Ssl(sslstream)
}
else {
} else {
WebSocketStream::Tcp(connection)
};

Expand Down
4 changes: 2 additions & 2 deletions src/header/accept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::fmt::{self, Debug};
use std::str::FromStr;
use serialize::base64::{ToBase64, FromBase64, STANDARD};
use header::WebSocketKey;
use openssl::crypto::hash::{self, hash};
use openssl::hash::{self, hash};
use result::{WebSocketResult, WebSocketError};

static MAGIC_GUID: &'static str = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
Expand Down Expand Up @@ -54,7 +54,7 @@ impl WebSocketAccept {
let mut concat_key = String::with_capacity(serialized.len() + 36);
concat_key.push_str(&serialized[..]);
concat_key.push_str(MAGIC_GUID);
let output = hash(hash::Type::SHA1, concat_key.as_bytes());
let output = hash(hash::MessageDigest::sha1(), concat_key.as_bytes()).unwrap();
let mut iter = output.into_iter();
let mut bytes = [0u8; 20];
for i in bytes.iter_mut() {
Expand Down
14 changes: 13 additions & 1 deletion src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use std::str::Utf8Error;
use std::error::Error;
use std::convert::From;
use std::fmt;
use openssl::ssl::error::SslError;
use std::net::TcpStream;
use openssl::error::ErrorStack as SslError;
use openssl::ssl::HandshakeError;
use hyper::Error as HttpError;
use url::ParseError;

Expand All @@ -27,6 +29,8 @@ pub enum WebSocketError {
NoDataAvailable,
/// An input/output error
IoError(io::Error),
/// An Ssl Handshake error
HandshakeError(HandshakeError<TcpStream>),
/// An HTTP parsing error
HttpError(HttpError),
/// A URL parsing error
Expand Down Expand Up @@ -56,6 +60,7 @@ impl Error for WebSocketError {
WebSocketError::DataFrameError(_) => "WebSocket data frame error",
WebSocketError::NoDataAvailable => "No data available",
WebSocketError::IoError(_) => "I/O failure",
WebSocketError::HandshakeError(_) => "SSL Handshake failure",
WebSocketError::HttpError(_) => "HTTP failure",
WebSocketError::UrlError(_) => "URL failure",
WebSocketError::SslError(_) => "SSL failure",
Expand All @@ -67,6 +72,7 @@ impl Error for WebSocketError {
fn cause(&self) -> Option<&Error> {
match *self {
WebSocketError::IoError(ref error) => Some(error),
WebSocketError::HandshakeError(ref error) => Some(error),
WebSocketError::HttpError(ref error) => Some(error),
WebSocketError::UrlError(ref error) => Some(error),
WebSocketError::SslError(ref error) => Some(error),
Expand All @@ -86,6 +92,12 @@ impl From<io::Error> for WebSocketError {
}
}

impl From<HandshakeError<TcpStream>> for WebSocketError {
fn from(err: HandshakeError<TcpStream>) -> WebSocketError {
WebSocketError::HandshakeError(err)
}
}

impl From<HttpError> for WebSocketError {
fn from(err: HttpError) -> WebSocketError {
WebSocketError::HttpError(err)
Expand Down
4 changes: 2 additions & 2 deletions src/stream.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Provides the default stream type for WebSocket connections.
extern crate net2;

use std::io::{self, Read, Write};
use std::io::{self, ErrorKind, Read, Write};
use self::net2::TcpStreamExt;
use openssl::ssl::SslStream;

Expand Down Expand Up @@ -80,7 +80,7 @@ impl WebSocketStream {
pub fn try_clone(&self) -> io::Result<WebSocketStream> {
Ok(match *self {
WebSocketStream::Tcp(ref inner) => WebSocketStream::Tcp(try!(inner.try_clone())),
WebSocketStream::Ssl(ref inner) => WebSocketStream::Ssl(try!(inner.try_clone())),
WebSocketStream::Ssl(_) => return Err(io::Error::new(ErrorKind::Other, "can't clone an ssl stream")),
})
}

Expand Down

0 comments on commit de05e90

Please sign in to comment.