Skip to content

Commit 5abf943

Browse files
committed
add openssl 3.0 set_dh_auto
1 parent d53c390 commit 5abf943

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

openssl-sys/src/ssl.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ pub const SSL_CTRL_SET_SIGALGS_LIST: c_int = 98;
374374
pub const SSL_CTRL_SET_VERIFY_CERT_STORE: c_int = 106;
375375
#[cfg(ossl300)]
376376
pub const SSL_CTRL_GET_PEER_TMP_KEY: c_int = 109;
377+
#[cfg(ossl300)]
378+
pub const SSL_CTRL_SET_DH_AUTO: c_int = 118;
377379
#[cfg(ossl110)]
378380
pub const SSL_CTRL_GET_EXTMS_SUPPORT: c_int = 122;
379381
#[cfg(any(ossl110, libressl261))]
@@ -388,6 +390,11 @@ pub const SSL_CTRL_GET_MAX_PROTO_VERSION: c_int = 131;
388390
#[cfg(ossl300)]
389391
pub const SSL_CTRL_GET_TMP_KEY: c_int = 133;
390392

393+
#[cfg(ossl300)]
394+
pub unsafe fn SSL_CTX_set_dh_auto(ctx: *mut SSL_CTX, onoff: c_int) -> c_int {
395+
SSL_CTX_ctrl(ctx, SSL_CTRL_SET_DH_AUTO, onoff as c_long, ptr::null_mut()) as c_int
396+
}
397+
391398
pub unsafe fn SSL_CTX_set_tmp_dh(ctx: *mut SSL_CTX, dh: *mut DH) -> c_long {
392399
SSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_DH, 0, dh as *mut c_void)
393400
}
@@ -396,6 +403,11 @@ pub unsafe fn SSL_CTX_set_tmp_ecdh(ctx: *mut SSL_CTX, key: *mut EC_KEY) -> c_lon
396403
SSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_ECDH, 0, key as *mut c_void)
397404
}
398405

406+
#[cfg(ossl300)]
407+
pub unsafe fn SSL_set_dh_auto(ssl: *mut SSL, onoff: c_int) -> c_int {
408+
SSL_ctrl(ssl, SSL_CTRL_SET_DH_AUTO, onoff as c_long, ptr::null_mut()) as c_int
409+
}
410+
399411
pub unsafe fn SSL_set_tmp_dh(ssl: *mut SSL, dh: *mut DH) -> c_long {
400412
SSL_ctrl(ssl, SSL_CTRL_SET_TMP_DH, 0, dh as *mut c_void)
401413
}

openssl/src/ssl/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,20 @@ impl SslContextBuilder {
938938
}
939939
}
940940

941+
/// Configure OpenSSL to use the default built-in DH parameters.
942+
///
943+
/// If “auto” DH parameters are switched on then the parameters will be selected to be
944+
/// consistent with the size of the key associated with the server's certificate.
945+
/// If there is no certificate (e.g. for PSK ciphersuites), then it it will be consistent
946+
/// with the size of the negotiated symmetric cipher key.
947+
///
948+
/// Requires OpenSSL 3.0.0.
949+
#[corresponds(SSL_CTX_set_dh_auto)]
950+
#[cfg(ossl300)]
951+
pub fn set_dh_auto(&mut self, onoff: bool) -> Result<(), ErrorStack> {
952+
unsafe { cvt(ffi::SSL_CTX_set_dh_auto(self.as_ptr(), onoff as c_int)).map(|_| ()) }
953+
}
954+
941955
/// Sets the parameters to be used during ephemeral Diffie-Hellman key exchange.
942956
#[corresponds(SSL_CTX_set_tmp_dh)]
943957
pub fn set_tmp_dh(&mut self, dh: &DhRef<Params>) -> Result<(), ErrorStack> {
@@ -2708,6 +2722,15 @@ impl SslRef {
27082722
}
27092723
}
27102724

2725+
/// Like [`SslContextBuilder::set_dh_auto`].
2726+
///
2727+
/// [`SslContextBuilder::set_dh_auto`]: struct.SslContextBuilder.html#method.set_dh_auto
2728+
#[corresponds(SSL_set_dh_auto)]
2729+
#[cfg(ossl300)]
2730+
pub fn set_dh_auto(&mut self, onoff: bool) -> Result<(), ErrorStack> {
2731+
unsafe { cvt(ffi::SSL_set_dh_auto(self.as_ptr(), onoff as c_int)).map(|_| ()) }
2732+
}
2733+
27112734
/// Like [`SslContextBuilder::set_tmp_dh`].
27122735
///
27132736
/// [`SslContextBuilder::set_tmp_dh`]: struct.SslContextBuilder.html#method.set_tmp_dh

0 commit comments

Comments
 (0)