diff options
| author | Benjamin Fry <[email protected]> | 2017-02-14 23:17:55 -0800 |
|---|---|---|
| committer | Benjamin Fry <[email protected]> | 2017-02-16 19:49:14 -0800 |
| commit | f8298882a41e0ca1f43d0fa7b475f302f4f20fca (patch) | |
| tree | 52b1554c5e9154b6bf841632eb4ec28a54acde64 /openssl/src | |
| parent | Update 1.1.0 version (diff) | |
| download | rust-openssl-f8298882a41e0ca1f43d0fa7b475f302f4f20fca.tar.xz rust-openssl-f8298882a41e0ca1f43d0fa7b475f302f4f20fca.zip | |
add set_verify_cert_store() to ssl ctx
Diffstat (limited to 'openssl/src')
| -rw-r--r-- | openssl/src/ssl/mod.rs | 13 | ||||
| -rw-r--r-- | openssl/src/ssl/tests/mod.rs | 25 |
2 files changed, 38 insertions, 0 deletions
diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index 5a65aa77..bcfcadf9 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -99,6 +99,8 @@ use ec::EcKeyRef; use ec::EcKey; use x509::{X509StoreContextRef, X509FileType, X509, X509Ref, X509VerifyError, X509Name}; use x509::store::{X509StoreBuilderRef, X509StoreRef}; +#[cfg(any(all(feature = "v101", ossl101), all(feature = "v102", ossl102)))] +use x509::store::X509Store; #[cfg(any(ossl102, ossl110))] use verify::X509VerifyParamRef; use pkey::PKeyRef; @@ -652,6 +654,17 @@ impl SslContextBuilder { } } + /// Sets a custom X509Store for verifying peer certificates + #[cfg(any(all(feature = "v101", ossl101), all(feature = "v102", ossl102)))] + pub fn set_verify_cert_store(&mut self, cert_store: X509Store) -> Result<(), ErrorStack> { + unsafe { + // set0 will free, set1 increments, and then requires a free + let ptr = cert_store.as_ptr(); + mem::forget(cert_store); + cvt(ffi::SSL_CTX_set0_verify_cert_store(self.as_ptr(), ptr) as c_int).map(|_|()) + } + } + pub fn set_read_ahead(&mut self, read_ahead: bool) { unsafe { ffi::SSL_CTX_set_read_ahead(self.as_ptr(), read_ahead as c_long); diff --git a/openssl/src/ssl/tests/mod.rs b/openssl/src/ssl/tests/mod.rs index 9c00e3ed..5b52a524 100644 --- a/openssl/src/ssl/tests/mod.rs +++ b/openssl/src/ssl/tests/mod.rs @@ -173,9 +173,15 @@ macro_rules! run_test( use ssl::SSL_VERIFY_PEER; use hash::MessageDigest; use x509::X509StoreContext; + #[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))] + use x509::X509; + #[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))] + use x509::store::X509StoreBuilder; use hex::FromHex; use foreign_types::ForeignTypeRef; use super::Server; + #[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))] + use super::ROOT_CERT; #[test] fn sslv23() { @@ -221,6 +227,25 @@ run_test!(verify_trusted, |method, stream| { } }); +#[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))] +run_test!(verify_trusted_with_set_cert, |method, stream| { + let x509 = X509::from_pem(ROOT_CERT).unwrap(); + let mut store = X509StoreBuilder::new().unwrap(); + store.add_cert(x509).unwrap(); + + let mut ctx = SslContext::builder(method).unwrap(); + ctx.set_verify(SSL_VERIFY_PEER); + + match ctx.set_verify_cert_store(store.build()) { + Ok(_) => {} + Err(err) => panic!("Unexpected error {:?}", err), + } + match Ssl::new(&ctx.build()).unwrap().connect(stream) { + Ok(_) => (), + Err(err) => panic!("Expected success, got {:?}", err), + } +}); + run_test!(verify_untrusted_callback_override_ok, |method, stream| { let mut ctx = SslContext::builder(method).unwrap(); ctx.set_verify_callback(SSL_VERIFY_PEER, |_, _| true); |