From a1cfde765a2a63798411ce4d518b8d32c085ffbf Mon Sep 17 00:00:00 2001 From: Benjamin Fry Date: Thu, 23 Mar 2017 22:11:23 -0700 Subject: [PATCH] add cleanup ffi to store context --- openssl-sys/src/lib.rs | 1 + openssl/src/x509/mod.rs | 8 ++++++-- openssl/src/x509/tests.rs | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/openssl-sys/src/lib.rs b/openssl-sys/src/lib.rs index c29b60e8b..3e5b3dd6f 100644 --- a/openssl-sys/src/lib.rs +++ b/openssl-sys/src/lib.rs @@ -2640,6 +2640,7 @@ extern "C" { pub fn X509_STORE_set_default_paths(store: *mut X509_STORE) -> c_int; pub fn X509_STORE_CTX_new() -> *mut X509_STORE_CTX; + pub fn X509_STORE_CTX_cleanup(ctx: *mut X509_STORE_CTX); pub fn X509_STORE_CTX_init(ctx: *mut X509_STORE_CTX, store: *mut X509_STORE, x509: *mut X509, chain: *mut stack_st_X509) -> c_int; pub fn X509_STORE_CTX_free(ctx: *mut X509_STORE_CTX); pub fn X509_STORE_CTX_get_current_cert(ctx: *mut X509_STORE_CTX) -> *mut X509; diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs index 5dd12b0e0..0cfa8ada4 100644 --- a/openssl/src/x509/mod.rs +++ b/openssl/src/x509/mod.rs @@ -117,14 +117,18 @@ impl X509StoreContextRef { /// # Result /// /// The Result must be `Some(None)` to be a valid certificate, otherwise the cert is not valid. - pub fn verify_cert(trust: &store::X509StoreRef, cert: &X509Ref, cert_chain: &StackRef) -> Result, ErrorStack> { + pub fn verify_cert(trust: store::X509Store, cert: X509, cert_chain: Stack) -> Result, ErrorStack> { unsafe { ffi::init(); let context = try!(cvt_p(ffi::X509_STORE_CTX_new()).map(|p| X509StoreContext(p))); try!(cvt(ffi::X509_STORE_CTX_init(context.as_ptr(), trust.as_ptr(), cert.as_ptr(), cert_chain.as_ptr())) .map(|_| ())); try!(cvt(ffi::X509_verify_cert(context.as_ptr())).map(|_| ())); - Ok(context.error()) + + let result = Ok(context.error()); + ffi::X509_STORE_CTX_cleanup(context.as_ptr()); + + result } } diff --git a/openssl/src/x509/tests.rs b/openssl/src/x509/tests.rs index 05baac120..96d457425 100644 --- a/openssl/src/x509/tests.rs +++ b/openssl/src/x509/tests.rs @@ -303,5 +303,5 @@ fn test_verify_cert() { store_bldr.add_cert(ca).unwrap(); let store = store_bldr.build(); - assert!(X509StoreContext::verify_cert(&store, &cert, &Stack::new().unwrap()).unwrap().is_none()); + assert!(X509StoreContext::verify_cert(store, cert, Stack::new().unwrap()).unwrap().is_none()); } -- GitLab