spotilocal.rs 853 B

12345678910111213141516171819202122
  1. use hyper::net::Openssl;
  2. use openssl::crypto::pkey::PKey;
  3. use openssl::ssl::{SslContext, SslMethod, SSL_VERIFY_NONE};
  4. use openssl::ssl::error::SslError;
  5. use openssl::x509::X509;
  6. use std::io::Cursor;
  7. use std::sync::Arc;
  8. static SPOTILOCAL_CERT : &'static [u8] = include_bytes!("data/spotilocal.cert");
  9. static SPOTILOCAL_KEY : &'static [u8] = include_bytes!("data/spotilocal.key");
  10. pub fn ssl_context() -> Result<Openssl, SslError> {
  11. let cert = try!(X509::from_pem(&mut Cursor::new(SPOTILOCAL_CERT)));
  12. let key = try!(PKey::private_key_from_pem(&mut Cursor::new(SPOTILOCAL_KEY)));
  13. let mut ctx = try!(SslContext::new(SslMethod::Sslv23));
  14. try!(ctx.set_cipher_list("DEFAULT"));
  15. try!(ctx.set_private_key(&key));
  16. try!(ctx.set_certificate(&cert));
  17. ctx.set_verify(SSL_VERIFY_NONE, None);
  18. Ok(Openssl { context: Arc::new(ctx) })
  19. }