diff --git a/.travis.yml b/.travis.yml index 2b20de2e..dc0293a5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ addons: script: - cargo build - cargo build --features with-tremor - #- cargo build --features facebook + - cargo build --features facebook # Building without syntex only works on nightly - if [[ $(rustc --version) == *"nightly"* ]]; then cargo build --no-default-features; diff --git a/Cargo.lock b/Cargo.lock index 78fa71aa..5006aa19 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -107,6 +107,8 @@ name = "cookie" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ + "openssl 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -172,6 +174,7 @@ dependencies = [ "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", "solicit 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index cde8f21f..26b61527 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,6 +58,6 @@ json_macros = { git = "https://github.com/plietar/json_macros" } discovery = ["dns-sd"] with-syntex = ["syntex", "protobuf_macros/with-syntex", "json_macros/with-syntex"] with-tremor = ["tremor"] -#facebook = ["hyper/ssl", "openssl"] +facebook = ["hyper/ssl", "openssl"] static-appkey = [] default = ["with-syntex"] diff --git a/src/authentication/facebook.rs b/src/authentication/facebook.rs index 0931ae0b..ae609bc4 100644 --- a/src/authentication/facebook.rs +++ b/src/authentication/facebook.rs @@ -1,38 +1,19 @@ use hyper; -use hyper::net::Openssl; use hyper::net::NetworkListener; use hyper::server::Request; use hyper::server::Response; use hyper::uri::RequestUri; use hyper::header::AccessControlAllowOrigin; -use openssl::ssl::{SslContext, SslMethod, SSL_VERIFY_NONE}; -use openssl::ssl::error::SslError; -use openssl::crypto::pkey::PKey; -use openssl::x509::X509; use rand::{self, Rng}; use rustc_serialize::json; use std::collections::BTreeMap; -use std::io::{Cursor, Read}; -use std::sync::{mpsc, Arc, Mutex}; +use std::io::Read; +use std::sync::{mpsc, Mutex}; use url; use protocol::authentication::AuthenticationType; use authentication::Credentials; - -static SPOTILOCAL_CERT : &'static [u8] = include_bytes!("data/spotilocal.cert"); -static SPOTILOCAL_KEY : &'static [u8] = include_bytes!("data/spotilocal.key"); - -fn spotilocal_ssl_context() -> Result { - let cert = try!(X509::from_pem(&mut Cursor::new(SPOTILOCAL_CERT))); - let key = try!(PKey::private_key_from_pem(&mut Cursor::new(SPOTILOCAL_KEY))); - - let mut ctx = try!(SslContext::new(SslMethod::Sslv23)); - try!(ctx.set_cipher_list("DEFAULT")); - try!(ctx.set_private_key(&key)); - try!(ctx.set_certificate(&cert)); - ctx.set_verify(SSL_VERIFY_NONE, None); - Ok(Openssl { context: Arc::new(ctx) }) -} +use ::spotilocal::ssl_context; struct ServerHandler { token_tx: Mutex>, @@ -93,7 +74,7 @@ pub fn facebook_login() -> Result { csrf: csrf.clone() }; - let ssl = spotilocal_ssl_context().unwrap(); + let ssl = ssl_context().unwrap(); let mut listener = hyper::net::HttpsListener::new("127.0.0.1:0", ssl).unwrap(); let port = listener.local_addr().unwrap().port(); diff --git a/src/authentication/mod.rs b/src/authentication/mod.rs index e4ace3f6..575fd869 100644 --- a/src/authentication/mod.rs +++ b/src/authentication/mod.rs @@ -172,11 +172,10 @@ pub fn discovery_login(device_name: &str, device_id: &str) -> Result Result { Err(()) diff --git a/src/lib.in.rs b/src/lib.in.rs index f820f4d4..e98487aa 100644 --- a/src/lib.in.rs +++ b/src/lib.in.rs @@ -17,4 +17,7 @@ pub mod spirc; pub mod link; pub mod stream; +#[cfg(feature = "facebook")] +pub mod spotilocal; + pub use album_cover::get_album_cover;