From 354a984a7c56346361bcce90a9321acb14d93bab Mon Sep 17 00:00:00 2001 From: Noah <33094578+coolreader18@users.noreply.github.com> Date: Tue, 24 Mar 2020 16:07:45 -0500 Subject: [PATCH] Add SslMethod::tls_{client,server} --- openssl-sys/src/ssl.rs | 8 ++++++++ openssl/src/ssl/mod.rs | 23 +++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/openssl-sys/src/ssl.rs b/openssl-sys/src/ssl.rs index 74604ea8a..94dcf8721 100644 --- a/openssl-sys/src/ssl.rs +++ b/openssl-sys/src/ssl.rs @@ -1089,6 +1089,10 @@ cfg_if! { pub fn TLS_method() -> *const SSL_METHOD; pub fn DTLS_method() -> *const SSL_METHOD; + + pub fn TLS_server_method() -> *const SSL_METHOD; + + pub fn TLS_client_method() -> *const SSL_METHOD; } } else { extern "C" { @@ -1097,6 +1101,10 @@ cfg_if! { pub fn SSLv23_method() -> *const SSL_METHOD; + pub fn SSLv23_client_method() -> *const SSL_METHOD; + + pub fn SSLv23_server_method() -> *const SSL_METHOD; + pub fn TLSv1_method() -> *const SSL_METHOD; pub fn TLSv1_1_method() -> *const SSL_METHOD; diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index 95c9ce1f9..314f51a92 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -323,6 +323,22 @@ impl SslMethod { unsafe { SslMethod(DTLS_method()) } } + /// Support all versions of the TLS protocol, explicitly as a client. + /// + /// This corresponds to `TLS_client_method` on OpenSSL 1.1.0 and + /// `SSLv23_client_method` on OpenSSL 1.0.x. + pub fn tls_client() -> SslMethod { + unsafe { SslMethod(TLS_client_method()) } + } + + /// Support all versions of the TLS protocol, explicitly as a server. + /// + /// This corresponds to `TLS_server_method` on OpenSSL 1.1.0 and + /// `SSLv23_server_method` on OpenSSL 1.0.x. + pub fn tls_server() -> SslMethod { + unsafe { SslMethod(TLS_server_method()) } + } + /// Constructs an `SslMethod` from a pointer to the underlying OpenSSL value. pub unsafe fn from_ptr(ptr: *const ffi::SSL_METHOD) -> SslMethod { SslMethod(ptr) @@ -3899,9 +3915,12 @@ cfg_if! { cfg_if! { if #[cfg(any(ossl110, libressl291))] { - use ffi::{TLS_method, DTLS_method}; + use ffi::{TLS_method, DTLS_method, TLS_client_method, TLS_server_method}; } else { - use ffi::{SSLv23_method as TLS_method, DTLSv1_method as DTLS_method}; + use ffi::{ + SSLv23_method as TLS_method, DTLSv1_method as DTLS_method, SSLv23_client_method as TLS_client_method, + SSLv23_server_method as TLS_server_method, + }; } } cfg_if! { -- GitLab