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
impl SslCtx
Sourcepub fn new() -> Result<Self, ErrorStack>
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.
Sourcepub fn new_client() -> Result<Self, ErrorStack>
pub fn new_client() -> Result<Self, ErrorStack>
Create a new TLS context optimised for client connections (TLS_client_method).
§Errors
Sourcepub fn new_server() -> Result<Self, ErrorStack>
pub fn new_server() -> Result<Self, ErrorStack>
Create a new TLS context optimised for server connections (TLS_server_method).
§Errors
Sourcepub fn set_min_proto_version(&self, ver: TlsVersion) -> Result<(), ErrorStack>
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
Sourcepub fn set_max_proto_version(&self, ver: TlsVersion) -> Result<(), ErrorStack>
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
Sourcepub fn set_verify(&self, mode: SslVerifyMode)
pub fn set_verify(&self, mode: SslVerifyMode)
Set the peer certificate verification mode.
Wraps SSL_CTX_set_verify(ctx, mode, NULL).
Sourcepub fn set_cipher_list(&self, list: &CStr) -> Result<(), ErrorStack>
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
Sourcepub fn set_ciphersuites(&self, list: &CStr) -> Result<(), ErrorStack>
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
Sourcepub fn use_certificate(&self, cert: &X509) -> Result<(), ErrorStack>
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
Sourcepub fn use_private_key<T: HasPrivate>(
&self,
key: &Pkey<T>,
) -> Result<(), ErrorStack>
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
Sourcepub fn check_private_key(&self) -> Result<(), ErrorStack>
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.
Sourcepub fn set_default_verify_paths(&self) -> Result<(), ErrorStack>
pub fn set_default_verify_paths(&self) -> Result<(), ErrorStack>
Load the system default CA certificate store for verification.
§Errors
Sourcepub fn disable_session_cache(&self)
pub fn disable_session_cache(&self)
Disable TLS session caching on this context.