aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/ssl
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2016-08-17 19:30:57 -0700
committerSteven Fackler <[email protected]>2016-08-17 19:30:57 -0700
commitcd69343d67081ab9c070f21d58918433a44f97bf (patch)
tree34367513c37714a94cad3ccd0326f82ee796795b /openssl/src/ssl
parentIgnore flickering test on windows (diff)
downloadrust-openssl-cd69343d67081ab9c070f21d58918433a44f97bf.tar.xz
rust-openssl-cd69343d67081ab9c070f21d58918433a44f97bf.zip
Fix SslContext::add_extra_chain_cert
SSL_CTX_add_extra_chain_cert assumes ownership of the certificate, so the method really needs to take an X509 by value. Work around this by manually cloning the cert. This method has been around for over a year but I'm guessing nobody actually used it since it produces a nice double free into segfault!
Diffstat (limited to 'openssl/src/ssl')
-rw-r--r--openssl/src/ssl/mod.rs11
-rw-r--r--openssl/src/ssl/tests/mod.rs8
2 files changed, 16 insertions, 3 deletions
diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs
index 64a2ccaf..6e365af6 100644
--- a/openssl/src/ssl/mod.rs
+++ b/openssl/src/ssl/mod.rs
@@ -535,9 +535,14 @@ impl<'a> SslContextRef<'a> {
/// Adds a certificate to the certificate chain presented together with the
/// certificate specified using set_certificate()
pub fn add_extra_chain_cert(&mut self, cert: &X509Ref) -> Result<(), ErrorStack> {
- wrap_ssl_result(unsafe {
- ffi::SSL_CTX_add_extra_chain_cert(self.as_ptr(), cert.as_ptr()) as c_int
- })
+ // FIXME this should really just take an X509 by value
+ let der = try!(cert.to_der());
+ let cert = try!(X509::from_der(&der));
+ unsafe {
+ try_ssl!(ffi::SSL_CTX_add_extra_chain_cert(self.as_ptr(), cert.as_ptr()));
+ }
+ mem::forget(cert);
+ Ok(())
}
/// Specifies the file that contains private key
diff --git a/openssl/src/ssl/tests/mod.rs b/openssl/src/ssl/tests/mod.rs
index 2881d4fe..3bbbed03 100644
--- a/openssl/src/ssl/tests/mod.rs
+++ b/openssl/src/ssl/tests/mod.rs
@@ -1081,3 +1081,11 @@ fn default_verify_paths() {
assert!(result.starts_with(b"HTTP/1.0"));
assert!(result.ends_with(b"</HTML>\r\n") || result.ends_with(b"</html>"));
}
+
+#[test]
+fn add_extra_chain_cert() {
+ let cert = include_bytes!("../../../test/cert.pem");
+ let cert = X509::from_pem(cert).unwrap();
+ let mut ctx = SslContext::new(SslMethod::Sslv23).unwrap();
+ ctx.add_extra_chain_cert(&cert).unwrap();
+}