-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
servo: Merge #11115 - Use openssl-verify to check certificate + hostn…
…ame (from mbrubeck:openssl-verify); r=jdm Fixes #4954. r? jdm This is based on hyperium/hyper#472, though it doesn't re-use that code directly because Servo configures its own OpenSSL context. Source-Repo: https://github.com/servo/servo Source-Revision: 40be84df26ce3ce80851e751374154c015506921 UltraBlame original commit: 4403e83bbb8e763bb0f0e8509051a286eb73ec41
- Loading branch information
Showing
9 changed files
with
94 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
|
||
|
||
|
||
|
||
use hyper::client::Pool; | ||
use hyper::net::{HttpStream, HttpsConnector, SslClient}; | ||
use openssl::ssl::{SSL_OP_NO_SSLV2, SSL_OP_NO_SSLV3, SSL_VERIFY_PEER}; | ||
use openssl::ssl::{Ssl, SslContext, SslMethod, SslStream}; | ||
use std::sync::Arc; | ||
use util::resource_files::resources_dir_path; | ||
|
||
pub type Connector = HttpsConnector<ServoSslClient>; | ||
|
||
|
||
|
||
|
||
|
||
const DEFAULT_CIPHERS: &'static str = concat!( | ||
"ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:", | ||
"ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:", | ||
"DHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:", | ||
"ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:", | ||
"ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA:", | ||
"ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:", | ||
"DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-RSA-DES-CBC3-SHA:", | ||
"ECDHE-ECDSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:", | ||
"AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA" | ||
); | ||
|
||
pub fn create_http_connector() -> Arc<Pool<Connector>> { | ||
let mut context = SslContext::new(SslMethod::Sslv23).unwrap(); | ||
context.set_CA_file(&resources_dir_path().join("certs")).unwrap(); | ||
context.set_cipher_list(DEFAULT_CIPHERS).unwrap(); | ||
context.set_options(SSL_OP_NO_SSLV2 | SSL_OP_NO_SSLV3); | ||
let connector = HttpsConnector::new(ServoSslClient { | ||
context: Arc::new(context) | ||
}); | ||
|
||
Arc::new(Pool::with_connector(Default::default(), connector)) | ||
} | ||
|
||
pub struct ServoSslClient { | ||
context: Arc<SslContext>, | ||
} | ||
|
||
impl SslClient for ServoSslClient { | ||
type Stream = SslStream<HttpStream>; | ||
|
||
fn wrap_client(&self, stream: HttpStream, host: &str) -> Result<Self::Stream, ::hyper::Error> { | ||
let mut ssl = try!(Ssl::new(&self.context)); | ||
try!(ssl.set_hostname(host)); | ||
let host = host.to_owned(); | ||
ssl.set_verify_callback(SSL_VERIFY_PEER, move |p, x| { | ||
::openssl_verify::verify_callback(&host, p, x) | ||
}); | ||
SslStream::connect(ssl, stream).map_err(From::from) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.