From 8e2d5242a3f498e3c75a3e45e7fe2255ac96298f Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sat, 12 Oct 2013 21:48:08 -0700 Subject: Start of cert verification --- src/ssl/lib.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/ssl/lib.rs') diff --git a/src/ssl/lib.rs b/src/ssl/lib.rs index 6d08e168..faf9e651 100644 --- a/src/ssl/lib.rs +++ b/src/ssl/lib.rs @@ -22,7 +22,6 @@ pub fn init() { } ffi::SSL_library_init(); - ffi::SSL_load_error_strings(); FINISHED_INIT.store(true, Release); } } @@ -60,6 +59,15 @@ impl SslCtx { ctx: ctx } } + + pub fn set_verify(&mut self, mode: SslVerifyMode) { + unsafe { ffi::SSL_CTX_set_verify(self.ctx, mode as c_int, None) } + } +} + +pub enum SslVerifyMode { + SslVerifyNone = ffi::SSL_VERIFY_NONE, + SslVerifyPeer = ffi::SSL_VERIFY_PEER } #[deriving(Eq, TotalEq, ToStr)] @@ -186,7 +194,7 @@ pub struct SslStream { } impl SslStream { - pub fn new(ctx: SslCtx, stream: S) -> SslStream { + pub fn new(ctx: SslCtx, stream: S) -> Result, uint> { let ssl = Ssl::new(&ctx); let rbio = MemBio::new(); @@ -205,11 +213,15 @@ impl SslStream { stream: stream }; - do stream.in_retry_wrapper |ssl| { + let ret = do stream.in_retry_wrapper |ssl| { ssl.ssl.connect() }; - stream + match ret { + Ok(_) => Ok(stream), + // FIXME + Err(_err) => Err(unsafe { ffi::ERR_get_error() as uint }) + } } fn in_retry_wrapper(&mut self, blk: &fn(&mut SslStream) -> int) -- cgit v1.2.3