Make verification callbacks sound
This commit is contained in:
parent
fc57ec0e43
commit
2216f86bd3
8
lib.rs
8
lib.rs
|
|
@ -111,14 +111,14 @@ extern "C" fn raw_verify(preverify_ok: c_int, x509_ctx: *ffi::X509_STORE_CTX)
|
||||||
|
|
||||||
match verify {
|
match verify {
|
||||||
None => preverify_ok,
|
None => preverify_ok,
|
||||||
Some(verify) => verify(preverify_ok != 0, ctx) as c_int
|
Some(verify) => verify(preverify_ok != 0, &ctx) as c_int
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The signature of functions that can be used to manually verify certificates
|
/// The signature of functions that can be used to manually verify certificates
|
||||||
pub type VerifyCallback = extern "Rust" fn(preverify_ok: bool,
|
pub type VerifyCallback = extern "Rust" fn(preverify_ok: bool,
|
||||||
x509_ctx: X509StoreContext) -> bool;
|
x509_ctx: &X509StoreContext) -> bool;
|
||||||
|
|
||||||
/// An SSL context object
|
/// An SSL context object
|
||||||
pub struct SslContext {
|
pub struct SslContext {
|
||||||
|
|
@ -189,7 +189,7 @@ impl X509StoreContext {
|
||||||
X509ValidationError::from_raw(err)
|
X509ValidationError::from_raw(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_current_cert(&self) -> Option<X509> {
|
pub fn get_current_cert<'a>(&'a self) -> Option<X509<'a>> {
|
||||||
let ptr = unsafe { ffi::X509_STORE_CTX_get_current_cert(self.ctx) };
|
let ptr = unsafe { ffi::X509_STORE_CTX_get_current_cert(self.ctx) };
|
||||||
|
|
||||||
if ptr.is_null() {
|
if ptr.is_null() {
|
||||||
|
|
@ -201,7 +201,7 @@ impl X509StoreContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A public key certificate
|
/// A public key certificate
|
||||||
pub struct X509 {
|
pub struct X509<'ctx> {
|
||||||
priv x509: *ffi::X509
|
priv x509: *ffi::X509
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
14
test.rs
14
test.rs
|
|
@ -47,7 +47,7 @@ fn test_verify_trusted() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_verify_untrusted_callback_override_ok() {
|
fn test_verify_untrusted_callback_override_ok() {
|
||||||
fn callback(_preverify_ok: bool, _x509_ctx: X509StoreContext) -> bool {
|
fn callback(_preverify_ok: bool, _x509_ctx: &X509StoreContext) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
let stream = TcpStream::connect(FromStr::from_str("127.0.0.1:15418").unwrap()).unwrap();
|
let stream = TcpStream::connect(FromStr::from_str("127.0.0.1:15418").unwrap()).unwrap();
|
||||||
|
|
@ -61,7 +61,7 @@ fn test_verify_untrusted_callback_override_ok() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_verify_untrusted_callback_override_bad() {
|
fn test_verify_untrusted_callback_override_bad() {
|
||||||
fn callback(_preverify_ok: bool, _x509_ctx: X509StoreContext) -> bool {
|
fn callback(_preverify_ok: bool, _x509_ctx: &X509StoreContext) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
let stream = TcpStream::connect(FromStr::from_str("127.0.0.1:15418").unwrap()).unwrap();
|
let stream = TcpStream::connect(FromStr::from_str("127.0.0.1:15418").unwrap()).unwrap();
|
||||||
|
|
@ -72,7 +72,7 @@ fn test_verify_untrusted_callback_override_bad() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_verify_trusted_callback_override_ok() {
|
fn test_verify_trusted_callback_override_ok() {
|
||||||
fn callback(_preverify_ok: bool, _x509_ctx: X509StoreContext) -> bool {
|
fn callback(_preverify_ok: bool, _x509_ctx: &X509StoreContext) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
let stream = TcpStream::connect(FromStr::from_str("127.0.0.1:15418").unwrap()).unwrap();
|
let stream = TcpStream::connect(FromStr::from_str("127.0.0.1:15418").unwrap()).unwrap();
|
||||||
|
|
@ -90,7 +90,7 @@ fn test_verify_trusted_callback_override_ok() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_verify_trusted_callback_override_bad() {
|
fn test_verify_trusted_callback_override_bad() {
|
||||||
fn callback(_preverify_ok: bool, _x509_ctx: X509StoreContext) -> bool {
|
fn callback(_preverify_ok: bool, _x509_ctx: &X509StoreContext) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
let stream = TcpStream::connect(FromStr::from_str("127.0.0.1:15418").unwrap()).unwrap();
|
let stream = TcpStream::connect(FromStr::from_str("127.0.0.1:15418").unwrap()).unwrap();
|
||||||
|
|
@ -105,7 +105,7 @@ fn test_verify_trusted_callback_override_bad() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_verify_callback_load_certs() {
|
fn test_verify_callback_load_certs() {
|
||||||
fn callback(_preverify_ok: bool, x509_ctx: X509StoreContext) -> bool {
|
fn callback(_preverify_ok: bool, x509_ctx: &X509StoreContext) -> bool {
|
||||||
assert!(x509_ctx.get_current_cert().is_some());
|
assert!(x509_ctx.get_current_cert().is_some());
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
@ -117,7 +117,7 @@ fn test_verify_callback_load_certs() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_verify_trusted_get_error_ok() {
|
fn test_verify_trusted_get_error_ok() {
|
||||||
fn callback(_preverify_ok: bool, x509_ctx: X509StoreContext) -> bool {
|
fn callback(_preverify_ok: bool, x509_ctx: &X509StoreContext) -> bool {
|
||||||
assert!(x509_ctx.get_error().is_none());
|
assert!(x509_ctx.get_error().is_none());
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
@ -133,7 +133,7 @@ fn test_verify_trusted_get_error_ok() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_verify_trusted_get_error_err() {
|
fn test_verify_trusted_get_error_err() {
|
||||||
fn callback(_preverify_ok: bool, x509_ctx: X509StoreContext) -> bool {
|
fn callback(_preverify_ok: bool, x509_ctx: &X509StoreContext) -> bool {
|
||||||
assert!(x509_ctx.get_error().is_some());
|
assert!(x509_ctx.get_error().is_some());
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue