Skip to main content

SslCtx

Struct SslCtx 

Source
pub struct SslCtx { /* private fields */ }
Expand description

TLS context (SSL_CTX*).

Holds shared configuration such as certificates, private keys, and verify settings. Multiple Ssl objects can be created from the same SslCtx.

Cloneable via SSL_CTX_up_ref; wrapping in Arc<SslCtx> is safe.

Implementations§

Source§

impl SslCtx

Source

pub fn new() -> Result<Self, ErrorStack>

Create a new TLS context accepting any role (client or server).

Uses the generic TLS_method(). Call SslCtx::new_client or SslCtx::new_server for role-specific method selection.

§Errors

Returns Err if SSL_CTX_new fails.

Source

pub fn new_client() -> Result<Self, ErrorStack>

Create a new TLS context optimised for client connections (TLS_client_method).

§Errors
Source

pub fn new_server() -> Result<Self, ErrorStack>

Create a new TLS context optimised for server connections (TLS_server_method).

§Errors
Source

pub fn set_min_proto_version(&self, ver: TlsVersion) -> Result<(), ErrorStack>

Set the minimum acceptable TLS protocol version.

Internally calls SSL_CTX_ctrl(ctx, 123 /*SSL_CTRL_SET_MIN_PROTO_VERSION*/, version, NULL).

§Errors
Source

pub fn set_max_proto_version(&self, ver: TlsVersion) -> Result<(), ErrorStack>

Set the maximum acceptable TLS protocol version.

Internally calls SSL_CTX_ctrl(ctx, 124 /*SSL_CTRL_SET_MAX_PROTO_VERSION*/, version, NULL).

§Errors
Source

pub fn set_verify(&self, mode: SslVerifyMode)

Set the peer certificate verification mode.

Wraps SSL_CTX_set_verify(ctx, mode, NULL).

Source

pub fn set_cipher_list(&self, list: &CStr) -> Result<(), ErrorStack>

Set the allowed cipher list (TLS 1.2 and below).

list uses OpenSSL cipher string syntax (e.g. c"HIGH:!aNULL:!MD5").

§Errors
Source

pub fn set_ciphersuites(&self, list: &CStr) -> Result<(), ErrorStack>

Set the allowed TLS 1.3 ciphersuites.

list uses OpenSSL ciphersuite syntax (e.g. c"TLS_AES_256_GCM_SHA384").

§Errors
Source

pub fn use_certificate(&self, cert: &X509) -> Result<(), ErrorStack>

Load a certificate into the context.

For a server, this is the certificate that will be presented to clients.

§Errors
Source

pub fn use_private_key<T: HasPrivate>( &self, key: &Pkey<T>, ) -> Result<(), ErrorStack>

Load a private key into the context.

The key must correspond to the certificate loaded via SslCtx::use_certificate.

§Errors
Source

pub fn check_private_key(&self) -> Result<(), ErrorStack>

Verify that the loaded certificate and private key are consistent.

§Errors

Returns Err if the key/certificate pair is invalid or not loaded.

Source

pub fn set_default_verify_paths(&self) -> Result<(), ErrorStack>

Load the system default CA certificate store for verification.

§Errors
Source

pub fn disable_session_cache(&self)

Disable TLS session caching on this context.

Source

pub fn new_ssl(&self) -> Result<Ssl, ErrorStack>

Create a new Ssl connection object from this context.

§Errors

Returns Err if SSL_new fails.

Trait Implementations§

Source§

impl Clone for SslCtx

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Drop for SslCtx

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for SslCtx

Source§

impl Sync for SslCtx

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.