From e6dd77fc029687950d7999dd29a8a0bd8adbb3d3 Mon Sep 17 00:00:00 2001 From: Paul Lietar Date: Sun, 20 Mar 2016 14:00:59 +0000 Subject: [PATCH] Add missing file from previous commit. --- src/spotilocal.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/spotilocal.rs diff --git a/src/spotilocal.rs b/src/spotilocal.rs new file mode 100644 index 00000000..754518df --- /dev/null +++ b/src/spotilocal.rs @@ -0,0 +1,22 @@ +use hyper::net::Openssl; +use openssl::crypto::pkey::PKey; +use openssl::ssl::{SslContext, SslMethod, SSL_VERIFY_NONE}; +use openssl::ssl::error::SslError; +use openssl::x509::X509; +use std::io::Cursor; +use std::sync::Arc; + +static SPOTILOCAL_CERT : &'static [u8] = include_bytes!("data/spotilocal.cert"); +static SPOTILOCAL_KEY : &'static [u8] = include_bytes!("data/spotilocal.key"); + +pub fn 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) }) +}